hotkeys in scheduler

This commit is contained in:
sirjonasxx 2019-02-02 14:36:28 +01:00
parent f461573a99
commit d18d815571
5 changed files with 73 additions and 12 deletions

View File

@ -84,5 +84,22 @@
<artifactId>jsoup</artifactId>
<version>1.11.2</version>
</dependency>
<dependency>
<groupId>com.github.tulskiy</groupId>
<artifactId>jkeymaster</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.7.13</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>snapshots-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
</repositories>
</project>

View File

@ -26,6 +26,8 @@ public class PauseResumeButton extends StackPane{
private Image imageResume;
private Image imageResumeOnHover;
private volatile boolean isHovering = false;
private List<InvalidationListener> clickListeners = new ArrayList<>();
public PauseResumeButton(boolean isPaused) {
@ -44,15 +46,7 @@ public class PauseResumeButton extends StackPane{
imageView.setImage(isPaused() ? imageResume : imagePause);
PauseResumeButton thiss = this;
setEventHandler(MouseEvent.MOUSE_CLICKED, event -> {
thiss.isPaused[0] = !thiss.isPaused[0];
imageView.setImage(isPaused() ? imageResumeOnHover : imagePauseOnHover);
for (int i = clickListeners.size() - 1; i >= 0; i--) {
clickListeners.get(i).invalidated(null);
}
});
setEventHandler(MouseEvent.MOUSE_CLICKED, event -> click());
}
public boolean isPaused() {
@ -65,12 +59,34 @@ public class PauseResumeButton extends StackPane{
private EventHandler<MouseEvent> onMouseHover =
t -> imageView.setImage(isPaused() ? imageResumeOnHover : imagePauseOnHover);
t -> {
imageView.setImage(isPaused() ? imageResumeOnHover : imagePauseOnHover);
isHovering = true;
};
private EventHandler<MouseEvent> onMouseHoverDone =
t -> imageView.setImage(isPaused() ? imageResume : imagePause);
t -> {
imageView.setImage(isPaused() ? imageResume : imagePause);
isHovering = false;
};
public void setPaused(boolean paused) {
isPaused[0] = paused;
imageView.setImage(isPaused() ?
(isHovering ? imageResumeOnHover : imageResume) :
(isHovering ? imagePauseOnHover : imagePause)
);
}
private void click() {
for (int i = clickListeners.size() - 1; i >= 0; i--) {
clickListeners.get(i).invalidated(null);
}
}
// private ImageView imageView;
// private Image image;
// private Image imageOnHover;

View File

@ -1,6 +1,7 @@
package gearth.ui.scheduler;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleObjectProperty;

View File

@ -1,5 +1,7 @@
package gearth.ui.scheduler;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Label;
@ -69,11 +71,12 @@ public class ScheduleItemContainer extends GridPane {
EditButton editButton = new EditButton();
DeleteButton deleteButton = new DeleteButton();
PauseResumeButton pauseResumeButton = new PauseResumeButton(item.getPausedProperty().get());
item.getPausedProperty().addListener(observable -> pauseResumeButton.setPaused(item.getPausedProperty().get()));
editButton.show();
deleteButton.show();
editButton.addEventHandler(MouseEvent.MOUSE_CLICKED, event -> item.edit());
deleteButton.addEventHandler(MouseEvent.MOUSE_CLICKED, event -> item.delete());
pauseResumeButton.onClick(observable -> item.getPausedProperty().set(pauseResumeButton.isPaused()));
pauseResumeButton.onClick(observable -> item.getPausedProperty().set(!pauseResumeButton.isPaused()));
HBox buttonsBox = new HBox(pauseResumeButton, editButton, deleteButton);
buttonsBox.setSpacing(10);
buttonsBox.setAlignment(Pos.CENTER);

View File

@ -1,5 +1,6 @@
package gearth.ui.scheduler;
import com.tulskiy.keymaster.common.Provider;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.scene.control.*;
@ -10,6 +11,7 @@ import gearth.protocol.HMessage;
import gearth.protocol.HPacket;
import gearth.ui.SubForm;
import javax.swing.*;
import java.io.*;
import java.util.ArrayList;
import java.util.HashSet;
@ -101,6 +103,28 @@ public class Scheduler extends SubForm {
}
}).start();
//register hotkeys
//disable some output things
PrintStream err = System.err;
System.setErr(new PrintStream(new OutputStream() {
public void write(int b) {
}
}));
Provider provider = Provider.getCurrentProvider(false);
for (int i = 0; i < 10; i++) {
int[] ii = {i};
provider.register(KeyStroke.getKeyStroke("control shift " + ii[0]), hotKey -> switchPauseHotkey(ii[0]));
}
System.setErr(err);
}
private void switchPauseHotkey(int index) {
if (cbx_hotkeys.isSelected() && index < scheduleItemList.size()) {
scheduleItemList.get(index).getPausedProperty().set(!scheduleItemList.get(index).getPausedProperty().get());
}
}
public static boolean stringIsNumber(String str) {