Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
egdw-xxxyo committed Jul 27, 2018
2 parents 6b6b2e2 + 692253c commit a9421df
Show file tree
Hide file tree
Showing 62 changed files with 1,530 additions and 827 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.dikhim</groupId>
<artifactId>useless_clicker</artifactId>
<version>0.4.0</version>
<version>0.4.1</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>1.8</maven.compiler.target>
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/dikhim/jclicker/Clicker.java
Expand Up @@ -16,6 +16,7 @@
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.prefs.Preferences;

public class Clicker extends Application {
private static Clicker application;
Expand All @@ -34,6 +35,12 @@ public void start(Stage primaryStage) throws Exception {
this.primaryStage = primaryStage;

if (cli.isGuiApplication()) {
if(Preferences.userRoot().node("main").getBoolean("isFirstLaunch",true)){
Preferences.userRoot().node("main").putBoolean("isFirstLaunch",false);
String language = WindowManager.showChooseLanguageDialog();
mainApplication.getConfig().getLocalization().getApplicationLanguage().set(language);
mainApplication.getConfig().save();
}
String language = mainApplication.getConfig().getLocalization().getApplicationLanguage().get();
WindowManager.initialization(new Locale(language));
loadMainScene();
Expand Down
81 changes: 69 additions & 12 deletions src/main/java/org/dikhim/jclicker/WindowManager.java
Expand Up @@ -5,8 +5,11 @@
import javafx.scene.Scene;
import javafx.scene.control.TextInputDialog;
import javafx.scene.image.Image;
import javafx.scene.layout.GridPane;
import javafx.stage.FileChooser;
import javafx.stage.Modality;
import javafx.stage.Stage;
import org.dikhim.jclicker.ui.controllers.ChooseLanguageDialogController;

import java.io.File;
import java.io.IOException;
Expand All @@ -17,7 +20,7 @@
public class WindowManager {
private static WindowManager windowManager;
private Preferences preferences = Preferences.userRoot().node(getClass().getName());

private ResourceBundle resourceBundle;
private Map<String, Stage> stageMap = new HashMap<>();
private Map<String, Scene> sceneMap = new HashMap<>();
Expand All @@ -44,7 +47,7 @@ private WindowManager(Locale locale) {
}

private void init() throws IOException {
resourceBundle = ResourceBundle.getBundle("i18n/WindowManager",locale);
resourceBundle = ResourceBundle.getBundle("i18n/WindowManager", locale);

sceneMap.put("about", loadAboutScene(locale));
sceneMap.put("settings", loadConfigScene(locale));
Expand All @@ -71,7 +74,6 @@ private void init() throws IOException {
stage.getIcons().add(new Image(getClass().getResourceAsStream("/images/help.png")));
stageMap.put("help", stage);



stage = new Stage();
stage.setScene(sceneMap.get("server"));
Expand All @@ -82,10 +84,11 @@ private void init() throws IOException {
stage = new Stage();
stage.setScene(sceneMap.get("main"));
stage.getIcons().add(new Image(getClass().getResourceAsStream("/images/cursor.png")));
stage.setOnCloseRequest(event -> stageMap.forEach((k, v)-> v.hide()));
stage.setOnCloseRequest(event -> stageMap.forEach((k, v) -> v.hide()));
stageMap.put("main", stage);
}


public void showStage(String stageName) {
Stage stage = stageMap.get(stageName);
if (stage != null) {
Expand All @@ -95,6 +98,13 @@ public void showStage(String stageName) {
}


private Scene loadInitScene() throws IOException {
FXMLLoader loader = new FXMLLoader(getClass().getResource("/ui/main/ChooseLanguageDialogScene.fxml"));
Parent root = loader.load();

return new Scene(root);
}

private Scene loadMainScene(Locale locale) throws IOException {
FXMLLoader loader = new FXMLLoader(getClass().getResource("/ui/main/MainScene.fxml"));
loader.setResources(ResourceBundle.getBundle("i18n/MainScene", locale));
Expand Down Expand Up @@ -135,9 +145,9 @@ private Scene loadServerScene(Locale locale) throws IOException {
public Stage getStage(String stageName) {
return stageMap.get(stageName);
}
public File openScriptFile(){


public File openScriptFile() {
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle(resourceBundle.getString("open"));
fileChooser.getExtensionFilters().addAll(
Expand All @@ -154,8 +164,8 @@ public File openScriptFile(){
}
return file;
}
public File saveScriptFileAs(){

public File saveScriptFileAs() {
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle(resourceBundle.getString("saveAs"));
fileChooser.setInitialFileName("newFile.js");
Expand All @@ -171,6 +181,24 @@ public File saveScriptFileAs(){
return file;
}


public File openFile() {
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle(resourceBundle.getString("open"));
fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter(resourceBundle.getString("allTypes"), "*.*"));

String pathFolder = preferences.get("last-opened-folder", "");
if (!pathFolder.isEmpty()) {
fileChooser.setInitialDirectory(new File(pathFolder));
}
File file = fileChooser.showOpenDialog(getStage("main"));
if (file != null) {
preferences.put("last-opened-folder", file.getParentFile().getAbsolutePath());
}
return file;
}


public File openImageFile() {
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle(resourceBundle.getString("open"));
Expand All @@ -190,7 +218,7 @@ public File openImageFile() {
}


public File saveImageFileAs(){
public File saveImageFileAs() {
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle(resourceBundle.getString("saveAs"));
fileChooser.setInitialFileName("image.png");
Expand All @@ -205,7 +233,7 @@ public File saveImageFileAs(){
}
return file;
}

public String showImageInputDialog() {
TextInputDialog dialog = new TextInputDialog("");
dialog.setTitle(resourceBundle.getString("imageInputDialog.title"));
Expand All @@ -218,5 +246,34 @@ public String showImageInputDialog() {
Optional<String> result = dialog.showAndWait();
return result.orElse("");
}


public static String showChooseLanguageDialog() {
try {
// Load the fxml file and create a new stage for the popup dialog.
FXMLLoader loader = new FXMLLoader();
loader.setLocation(WindowManager.class.getResource("/fxml/ChooseLanguageDialogScene.fxml"));
GridPane page = (GridPane) loader.load();

// Create the dialog Stage.
Stage dialogStage = new Stage();
dialogStage.setTitle(" ");
dialogStage.initModality(Modality.WINDOW_MODAL);
//dialogStage.initOwner(getStage("main"));
Scene scene = new Scene(page);
dialogStage.setScene(scene);
dialogStage.getIcons().add(new Image(WindowManager.class.getClass().getResourceAsStream("/images/24/globe.png")));

// Set the person into the controller.
ChooseLanguageDialogController controller = loader.getController();
controller.setDialogStage(dialogStage);
// Show the dialog and wait until the user closes it
dialogStage.showAndWait();

return controller.getSelectedLanguage();
} catch (IOException e) {
e.printStackTrace();
return "en";
}
}

}
Expand Up @@ -80,9 +80,9 @@ public void run(List<Action> actions) {
break;
case DELAY_MILLISECONDS:
actionDelay = ((DelayMillisecondsAction) a).getDelay();
calculatedDelay = actionDelay - delayDiff;
calculatedDelay = systemObject.getMultipliedDelay(actionDelay) - delayDiff;
if (calculatedDelay < 0) calculatedDelay = 0;
systemObject.sleep(calculatedDelay);
systemObject.sleepNonMultiplied(calculatedDelay);
scriptTime += systemObject.getMultipliedDelay(actionDelay);
break;
}
Expand Down
27 changes: 20 additions & 7 deletions src/main/java/org/dikhim/jclicker/controllers/MainController.java
Expand Up @@ -99,6 +99,7 @@ public void initialize(URL location, ResourceBundle resources) {
// output image pane
OutputImageView outputImageView = new OutputImageView(resources);
outputImageView.setOnInsert(codeTextArea::insertTextIntoCaretPosition);
outputImageView.setOnLoad(codeTextArea::getSelectedText);
outputImagePane.getChildren().addAll(outputImageView);
outputImageView.addChangeListener(() -> outputTabPane.getSelectionModel().select(1));
mainApplication.setOnSetOutputImage(outputImageView::loadImage);
Expand Down Expand Up @@ -340,6 +341,10 @@ public void showHelpWindow() {
@FXML
private ToggleButton btnInsertCombinedLog;

// Other
@FXML
private Button recFilePath;

@FXML
TextField txtCombinedDetectStopPoints;

Expand Down Expand Up @@ -432,10 +437,13 @@ private void initToggles(SourcePropertyFile properties) {


// set user data 'String' hint
List<ToggleButton> listOfToggles = new ArrayList<>();
listOfToggles.addAll(simpleToggles);
listOfToggles.addAll(listOfInsertCodeToggles);
for (ToggleButton b : listOfToggles) {
List<Node> nodes = new ArrayList<>();

nodes.add(recFilePath);

nodes.addAll(simpleToggles);
nodes.addAll(listOfInsertCodeToggles);
for (Node b : nodes) {
b.setUserData(new String[]{properties.get(b.getId()), ""});
b.setOnMouseEntered(this::showCodeSample);
b.setOnMouseExited(this::hideCodeSample);
Expand Down Expand Up @@ -541,7 +549,6 @@ private void onToggleButtonPerformed(ActionEvent event, Consumer<String> consume
void insertKeyName(ActionEvent event) {
onToggleButtonPerformed(event, prefix -> {
eventsRecorder.keyName();

});
}

Expand Down Expand Up @@ -794,6 +801,13 @@ void insertSelectImage(ActionEvent event) {
});
}

// Other

@FXML
void recFilePath(ActionEvent event) {
eventsRecorder.filePath();
}

//
// TEMPLATES
//
Expand Down Expand Up @@ -920,8 +934,7 @@ private void onBtnStatusToggles(ActionEvent event) {

private void putTextIntoCaretPosition(TextArea textArea, String text) {
Platform.runLater(() -> {
int caretPosition = textArea.getCaretPosition();
codeTextArea.insertText(caretPosition, text);
codeTextArea.insertTextIntoCaretPosition(text);
});
}

Expand Down
Expand Up @@ -15,6 +15,7 @@
import javafx.scene.image.ImageView;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import org.dikhim.jclicker.WindowManager;
import org.dikhim.jclicker.actions.*;
import org.dikhim.jclicker.actions.events.MouseButtonEvent;
import org.dikhim.jclicker.actions.events.MouseMoveEvent;
Expand All @@ -39,6 +40,7 @@

import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

Expand All @@ -51,7 +53,7 @@ public class EventsRecorder {

private KeyboardObjectCodeGenerator keyboardObjectCodeGenerator = new KeyboardObjectCodeGenerator();
private MouseObjectCodeGenerator mouseObjectCodeGenerator = new MouseObjectCodeGenerator();
private CombinedObjectCodeGenerator combinedObjectCodeGenerator = new CombinedObjectCodeGenerator();
private CombinedObjectCodeGenerator combinedObjectCodeGenerator = new CombinedObjectCodeGenerator(120);
private SystemObjectCodeGenerator systemObjectCodeGenerator = new SystemObjectCodeGenerator();

private EventLogger eventLog = new EventLogger(10000);
Expand All @@ -76,8 +78,8 @@ public EventsRecorder(MainConfiguration mainConfiguration) {
// keyboard

public void keyName() {
keyEventsManager.addKeyboardListener(new ShortcutIncludesListener(
prefix + ".press", "", "PRESS", e -> {
keyEventsManager.addKeyboardListener(new KeyListener(
prefix + ".press", "", "RELEASE", e -> {
putCode(e.getKey() + " ");
}));
}
Expand Down Expand Up @@ -561,6 +563,15 @@ public void selectImage() {
}));
}

// miscellaneous

public void filePath() {
File file = WindowManager.getInstance().openFile();
if (file != null) {
putCode(file.getAbsolutePath());
}
}

//////////
public String getPrefix() {
return prefix;
Expand Down

0 comments on commit a9421df

Please sign in to comment.