Added python project; fixed spelling of folder
This commit is contained in:
132
Java Projects/WebCapImg/src/Controller.java
Executable file
132
Java Projects/WebCapImg/src/Controller.java
Executable file
@@ -0,0 +1,132 @@
|
||||
package com.itdominator.webcapimgfx;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.stage.FileChooser;
|
||||
import javafx.scene.web.WebView;
|
||||
import javafx.scene.web.WebEngine;
|
||||
import javafx.scene.control.ScrollPane;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.input.MouseEvent;
|
||||
import javafx.scene.input.KeyEvent;
|
||||
import javafx.scene.input.KeyCode;
|
||||
import javafx.scene.input.ScrollEvent;
|
||||
import javafx.event.ActionEvent;
|
||||
|
||||
import javafx.event.EventHandler;
|
||||
import javafx.beans.Observable;
|
||||
import javafx.beans.property.DoubleProperty;
|
||||
import javafx.beans.property.SimpleDoubleProperty;
|
||||
import javafx.beans.InvalidationListener;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.io.IOException;
|
||||
import java.io.File;
|
||||
import javafx.embed.swing.SwingFXUtils;
|
||||
import javafx.scene.image.WritableImage;
|
||||
import javafx.scene.SnapshotParameters;
|
||||
import javafx.concurrent.Worker;
|
||||
|
||||
|
||||
public class Controller {
|
||||
// Classes
|
||||
|
||||
// FXML Stuff
|
||||
@FXML private WebView webView = new WebView();
|
||||
@FXML private ScrollPane scrollWindow;
|
||||
@FXML private ImageView imageView;
|
||||
@FXML private TextField urlOfPhoto;
|
||||
@FXML private Button saveBttn;
|
||||
|
||||
// Generics
|
||||
private final DoubleProperty zoomProperty = new SimpleDoubleProperty(200);
|
||||
private FileChooser fileChooser = new FileChooser();
|
||||
private Stage fileChooserStage = new Stage();
|
||||
private WritableImage image;
|
||||
private WebEngine webEngine;
|
||||
|
||||
@FXML void initialize() {
|
||||
assert webView != null : "fx:id=\"webView\" was not injected: check your FXML file 'Window.fxml'.";
|
||||
assert scrollWindow != null : "fx:id=\"scrollWindow\" was not injected: check your FXML file 'Window.fxml'.";
|
||||
assert imageView != null : "fx:id=\"imageView\" was not injected: check your FXML file 'Window.fxml'.";
|
||||
assert urlOfPhoto != null : "fx:id=\"urlOfPhoto\" was not injected: check your FXML file 'Window.fxml'.";
|
||||
|
||||
zoomProperty.addListener(new InvalidationListener() {
|
||||
@Override
|
||||
public void invalidated(Observable arg0) {
|
||||
imageView.setFitWidth(zoomProperty.get() * 4);
|
||||
imageView.setFitHeight(zoomProperty.get() * 3);
|
||||
}
|
||||
});
|
||||
|
||||
scrollWindow.addEventFilter(ScrollEvent.SCROLL,new EventHandler<ScrollEvent>() {
|
||||
@Override public void handle(ScrollEvent event) {
|
||||
if (event.isControlDown()) {
|
||||
if (event.getDeltaY() > 0) { plus();
|
||||
} else if (event.getDeltaY() < 0) { minus(); }
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
fileChooser.setTitle("Save Image");
|
||||
fileChooser.getExtensionFilters().addAll(
|
||||
new FileChooser.ExtensionFilter("PNG", "*.png")
|
||||
);
|
||||
|
||||
// Need an initial load to then set proper deminsions for other page loads
|
||||
webEngine = webView.getEngine();
|
||||
webEngine.load("https://www.google.com/");
|
||||
manageWebView();
|
||||
}
|
||||
|
||||
@FXML void zoomIn(MouseEvent event) { plus(); }
|
||||
@FXML void zoomOut(MouseEvent event) { minus(); }
|
||||
@FXML void setScrllFocus(MouseEvent event) { scrollWindow.requestFocus(); }
|
||||
@FXML void takeWebsitePhoto(ActionEvent event) throws Exception { startRun(); }
|
||||
|
||||
@FXML void clearData(ActionEvent event) {
|
||||
urlOfPhoto.setText("");
|
||||
imageView.setImage(new Image("file://"));
|
||||
saveBttn.setDisable(true);
|
||||
}
|
||||
|
||||
@FXML void onEnter(KeyEvent event) throws Exception {
|
||||
if (event.getCode() == KeyCode.ENTER) { startRun(); }
|
||||
}
|
||||
|
||||
@FXML void save(ActionEvent event) {
|
||||
try {
|
||||
String path = fileChooser.showSaveDialog(fileChooserStage).toString();
|
||||
if (!path.contains(".png")) { path += ".png"; }
|
||||
File file = new File(path);
|
||||
ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", file);
|
||||
} catch (IOException e) { }
|
||||
}
|
||||
|
||||
private void startRun() throws Exception {
|
||||
webEngine.load(urlOfPhoto.getText());
|
||||
webEngine.getLoadWorker().stateProperty().addListener((obs, oldState, newState) -> {
|
||||
if (newState == Worker.State.SUCCEEDED) {
|
||||
manageWebView();
|
||||
image = webView.snapshot(new SnapshotParameters(), null);
|
||||
imageView.setImage(image);
|
||||
saveBttn.setDisable(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void manageWebView() {
|
||||
// Manage webview size to get full size of page
|
||||
Double width = Double.parseDouble(webView.getEngine().executeScript("document.width").toString()),
|
||||
height = Double.parseDouble(webView.getEngine().executeScript("document.height").toString());
|
||||
if (width<100 || width>1080) { width = 1080.0; }
|
||||
if (height<100 || height>2048) { height = 1920.0; }
|
||||
webView.setMinSize(width, height);
|
||||
}
|
||||
|
||||
private void plus() { zoomProperty.set(zoomProperty.get() * 1.1); }
|
||||
private void minus() { zoomProperty.set(zoomProperty.get() / 1.1); }
|
||||
}
|
27
Java Projects/WebCapImg/src/WebCapImgFX.java
Executable file
27
Java Projects/WebCapImg/src/WebCapImgFX.java
Executable file
@@ -0,0 +1,27 @@
|
||||
package com.itdominator.webcapimgfx;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.image.Image;
|
||||
|
||||
|
||||
public class WebCapImgFX extends Application {
|
||||
@Override
|
||||
public void start(final Stage stage) throws Exception {
|
||||
FXMLLoader loader = new FXMLLoader(getClass().getResource("resources/Window.fxml"));
|
||||
loader.setController(new Controller());
|
||||
loader.load();
|
||||
Scene scene = new Scene(loader.getRoot());
|
||||
scene.getStylesheets().add("/com/itdominator/webcapimgfx/resources/stylesheet.css");
|
||||
stage.setScene(scene);
|
||||
stage.setTitle("WebCapImgFX");
|
||||
stage.setMinWidth(800);
|
||||
stage.setMinHeight(600);
|
||||
stage.getIcons().add(new Image(WebCapImgFX.class.getResourceAsStream("resources/WebCapImgFX.png")));
|
||||
stage.show();
|
||||
}
|
||||
public static void main(String[] args) { launch(args); }
|
||||
}
|
8
Java Projects/WebCapImg/src/unix_compile.sh
Executable file
8
Java Projects/WebCapImg/src/unix_compile.sh
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
function main() {
|
||||
javac *.java
|
||||
rm ../com/itdominator/webcapimgfx/*.class
|
||||
mv *.class ../com/itdominator/webcapimgfx
|
||||
}
|
||||
main;
|
5
Java Projects/WebCapImg/src/windows_compile.bat
Executable file
5
Java Projects/WebCapImg/src/windows_compile.bat
Executable file
@@ -0,0 +1,5 @@
|
||||
@echo off
|
||||
REM Note: may need to update number or path depending on system.
|
||||
"C:\Program Files\Java\jdk1.8.0_131\bin\javac.exe" *.java
|
||||
del ..\com\itdominator\webcapimgfx\*.class
|
||||
move *.class ..\com\itdominator\webcapimgfx\
|
Reference in New Issue
Block a user