reimplement hotkeys, autoscrol checkbox, tweaks

This commit is contained in:
sirjonasxx 2018-11-05 21:45:03 +01:00
parent b484d2f07b
commit ca2d750e43
4 changed files with 69 additions and 33 deletions

View File

@ -3,9 +3,11 @@ package gearth.ui;
import gearth.protocol.HPacket;
import gearth.ui.logger.loggerdisplays.PacketLogger;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.Initializable;
import javafx.scene.control.CheckMenuItem;
import javafx.scene.control.Label;
import javafx.scene.input.ScrollEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.FlowPane;
import org.fxmisc.flowless.VirtualizedScrollPane;
@ -26,12 +28,15 @@ public class UiLoggerController implements Initializable {
public CheckMenuItem chkViewIncoming;
public CheckMenuItem chkViewOutgoing;
public CheckMenuItem chkDisplayStructure;
public Label lblAutoScrolll;
public CheckMenuItem chkAutoscroll;
private StyleClassedTextArea area;
private boolean viewIncoming = true;
private boolean viewOutgoing = true;
private boolean displayStructure = true;
private boolean autoScroll = true;
@Override
public void initialize(URL arg0, ResourceBundle arg1) {
@ -66,9 +71,6 @@ public class UiLoggerController implements Initializable {
elements.add(new Element(" <- ", ""));
elements.add(new Element(packet.toString(), "incoming"));
if (!expr.equals("") && displayStructure)
elements.add(new Element("\n" + expr, "incoming"));
} else {
elements.add(new Element("Outgoing[", "outgoing"));
elements.add(new Element(String.valueOf(packet.headerId()), ""));
@ -76,10 +78,9 @@ public class UiLoggerController implements Initializable {
elements.add(new Element(" -> ", ""));
elements.add(new Element(packet.toString(), "outgoing"));
if (!expr.equals("") && displayStructure)
elements.add(new Element("\n" + expr, "outgoing"));
}
if (!expr.equals("") && displayStructure)
elements.add(new Element("\n" + expr, "structure"));
elements.add(new Element("\n--------------------\n", ""));
AppendLog(elements);
@ -98,25 +99,33 @@ public class UiLoggerController implements Initializable {
area.appendText(sb.toString());
area.setStyleSpans(oldLen, styleSpansBuilder.create());
area.moveTo(area.getLength());
area.requestFollowCaret();
if (autoScroll) {
area.moveTo(area.getLength());
area.requestFollowCaret();
}
}
public void toggleViewIncoming() {
viewIncoming = !viewIncoming;
lblViewIncoming.setText("View Incoming: " + (viewIncoming ? "True" : "False"));
chkViewIncoming.setSelected(viewIncoming);
// chkViewIncoming.setSelected(viewIncoming);
}
public void toggleViewOutgoing() {
viewOutgoing = !viewOutgoing;
lblViewOutgoing.setText("View Outgoing: " + (viewOutgoing ? "True" : "False"));
chkViewOutgoing.setSelected(viewOutgoing);
// chkViewOutgoing.setSelected(viewOutgoing);
}
public void toggleDisplayStructure() {
displayStructure = !displayStructure;
chkDisplayStructure.setSelected(displayStructure);
// chkDisplayStructure.setSelected(displayStructure);
}
public void toggleAutoscroll(ActionEvent actionEvent) {
autoScroll = !autoScroll;
lblAutoScrolll.setText("Autoscroll: " + (autoScroll ? "True" : "False"));
}
}

View File

@ -23,7 +23,7 @@ public class UiLogger implements PacketLogger {
@Override
public void start() {
FXMLLoader loader = new FXMLLoader(getClass().getResource("/gearth/ui/UiLogger.fxml"));
FXMLLoader loader = new FXMLLoader(getClass().getResource("/gearth/ui/logger/uilogger/UiLogger.fxml"));
try {
Parent root = loader.load();
@ -34,24 +34,24 @@ public class UiLogger implements PacketLogger {
Scene scene = new Scene(root);
scene.getStylesheets().add("/gearth/ui/bootstrap3.css");
scene.getStylesheets().add("/gearth/ui/logger.css");
scene.getStylesheets().add("/gearth/ui/logger/uilogger/logger.css");
scene.addEventFilter(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() {
final KeyCombination keyCombIncoming = new KeyCodeCombination(KeyCode.I,
KeyCombination.CONTROL_DOWN);
final KeyCombination keyCombOutgoing = new KeyCodeCombination(KeyCode.O,
KeyCombination.CONTROL_DOWN);
public void handle(KeyEvent ke) {
if (keyCombIncoming.match(ke)) {
controller.toggleViewIncoming();
ke.consume();
} else if (keyCombOutgoing.match(ke)) {
controller.toggleViewOutgoing();
ke.consume();
}
}
});
// scene.addEventFilter(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() {
// final KeyCombination keyCombIncoming = new KeyCodeCombination(KeyCode.I,
// KeyCombination.CONTROL_DOWN);
// final KeyCombination keyCombOutgoing = new KeyCodeCombination(KeyCode.O,
// KeyCombination.CONTROL_DOWN);
//
// public void handle(KeyEvent ke) {
// if (keyCombIncoming.match(ke)) {
// controller.toggleViewIncoming();
// ke.consume();
// } else if (keyCombOutgoing.match(ke)) {
// controller.toggleViewOutgoing();
// ke.consume();
// }
// }
// });
stage.setScene(scene);

View File

@ -5,10 +5,11 @@
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuBar?>
<?import javafx.scene.input.KeyCodeCombination?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.FlowPane?>
<BorderPane fx:id="borderPane" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.112" xmlns:fx="http://javafx.com/fxml/1" fx:controller="gearth.ui.UiLoggerController">
<BorderPane fx:id="borderPane" prefHeight="560.0" prefWidth="820.0" xmlns="http://javafx.com/javafx/8.0.112" xmlns:fx="http://javafx.com/fxml/1" fx:controller="gearth.ui.UiLoggerController">
<top>
<MenuBar BorderPane.alignment="CENTER">
<Menu mnemonicParsing="false" text="View">
@ -17,8 +18,18 @@
<CheckMenuItem fx:id="chkDisplayStructure" mnemonicParsing="false" onAction="#toggleDisplayStructure" selected="true" text="Structure" />
</items>
</Menu>
<CheckMenuItem fx:id="chkViewIncoming" mnemonicParsing="false" onAction="#toggleViewIncoming" selected="true" text="View Incoming (Ctrl+I)" />
<CheckMenuItem fx:id="chkViewOutgoing" mnemonicParsing="false" onAction="#toggleViewOutgoing" selected="true" text="View Outgoing (Ctrl+O)" />
<CheckMenuItem fx:id="chkViewIncoming" mnemonicParsing="false" onAction="#toggleViewIncoming" selected="true" text="View Incoming">
<accelerator>
<KeyCodeCombination alt="UP" code="I" control="DOWN" meta="UP" shift="UP" shortcut="UP" />
</accelerator></CheckMenuItem>
<CheckMenuItem fx:id="chkViewOutgoing" mnemonicParsing="false" onAction="#toggleViewOutgoing" selected="true" text="View Outgoing">
<accelerator>
<KeyCodeCombination alt="UP" code="O" control="DOWN" meta="UP" shift="UP" shortcut="UP" />
</accelerator></CheckMenuItem>
<CheckMenuItem fx:id="chkAutoscroll" mnemonicParsing="false" onAction="#toggleAutoscroll" selected="true" text="Autoscroll">
<accelerator>
<KeyCodeCombination alt="UP" code="L" control="DOWN" meta="UP" shift="UP" shortcut="UP" />
</accelerator></CheckMenuItem>
</Menu>
</MenuBar>
</top>
@ -42,6 +53,12 @@
<Insets right="10.0" />
</FlowPane.margin>
</Label>
<Label layoutX="138.0" layoutY="11.0" text="|">
<FlowPane.margin>
<Insets right="10.0" />
</FlowPane.margin>
</Label>
<Label fx:id="lblAutoScrolll" layoutX="151.0" layoutY="11.0" style="-fx-text-fill: black !important" text="Autoscroll: True" />
</FlowPane>
</bottom>
</BorderPane>

View File

@ -15,6 +15,10 @@
-fx-fill: #0066cc;
}
.structure {
-fx-fill: cyan;
}
.dark {
-fx-background-color: #000000;
}
@ -30,4 +34,10 @@
.menu-bar .text, .menu .text {
-fx-text-fill: #000000 !important;
-fx-fill: #000000 !important;
}
-fx-padding: -2 0 -2 0 !important;
}
.scroll-bar:vertical {
-fx-pref-width: 16.5;
-fx-padding: 1;
}