Skip to content

Commit

Permalink
drag event started
Browse files Browse the repository at this point in the history
  • Loading branch information
karlkauc committed Jun 27, 2023
1 parent 90d3a70 commit 0769a7c
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
import javafx.scene.control.Label;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuItem;
import javafx.scene.input.Dragboard;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.fxt.freexmltoolkit.service.PropertiesService;
Expand Down Expand Up @@ -67,6 +69,10 @@ public class MainController {
@FXML
Menu lastOpenFilesMenu;


@FXML
VBox leftMenu;

List<File> lastOpenFiles = new LinkedList<>();

@FXML
Expand All @@ -77,13 +83,46 @@ public void initialize() {
Platform.runLater(() -> version.setText(new Date().toString()));
}, 1, 2, TimeUnit.SECONDS);

exit.setOnAction(e -> System.exit(0));
menuItemExit.setOnAction(e -> System.exit(0));
exit.setOnAction(e -> {
prepareShutdown();
System.exit(0);
});
menuItemExit.setOnAction(e -> {
prepareShutdown();
System.exit(0);
});
loadLastOpenFiles();

leftMenu.setOnDragOver(event -> System.out.println("DRAG OVE"));
leftMenu.setOnDragDetected(event -> System.out.println("BIN DRINNEN"));
leftMenu.setOnDragDropped(event -> {
System.out.println("BIN DRINNEN");
Dragboard db = event.getDragboard();
boolean success = false;
if (db.hasFiles()) {
success = true;
for (File file : db.getFiles()) {
System.out.println("file.getName() = " + file.getName());
}
}
event.setDropCompleted(success);
event.consume();
});

loadPageFromPath("/pages/welcome.fxml");
}

private void prepareShutdown() {
scheduler.shutdown();
try {
if (!scheduler.awaitTermination(800, TimeUnit.MILLISECONDS)) {
scheduler.shutdownNow();
}
} catch (InterruptedException e) {
scheduler.shutdownNow();
}
}

private void loadLastOpenFiles() {
lastOpenFiles.clear();
lastOpenFiles = propertiesService.getLastOpenFiles();
Expand Down Expand Up @@ -136,8 +175,7 @@ private void loadPageFromPath(String pagePath) {
Class<?> aClass = loader.getController().getClass();

if (aClass.equals(XmlController.class)) {
xmlController = ((XmlController) loader.getController()).setParentController(this);

((XmlController) loader.getController()).setParentController(this);
} else if (aClass.equals(XsdValidationController.class)) {
((XsdValidationController) loader.getController()).setParentController(this);
} else if (aClass.equals(SettingsController.class)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public class XmlController {
Label schemaValidText;

@FXML
Tab text, graphic, xPathTab, xQueryTab;
Tab xPathTab, xQueryTab;

@FXML
TabPane xPathQueryPane, xmlFilesPane;
Expand Down Expand Up @@ -199,11 +199,9 @@ public void runXpathQueryPressed() {
}
}

public XmlController setParentController(MainController parentController) {
public void setParentController(MainController parentController) {
logger.debug("XML Controller - set parent controller");
this.parentController = parentController;

return this;
}

@FXML
Expand Down Expand Up @@ -298,14 +296,14 @@ public void formatXmlText() {
CodeArea ca = getCurrentCodeArea();
String text = ca.getText();

logger.debug("Text before formatting: {}", text);
// logger.debug("Text before formatting: {}", text);
ca.clear();

final String tempFormat = XmlService.prettyFormat(text, 20);
logger.debug("Format String length: {}", tempFormat.length());
ca.replaceText(0, 0, tempFormat);

logger.debug("Text after formatting: {}", tempFormat);
// logger.debug("Text after formatting: {}", tempFormat);
}

@FXML
Expand Down Expand Up @@ -373,8 +371,7 @@ private void openFile() {
logger.debug("Selected File: {}", selectedFile.getAbsolutePath());
this.lastOpenDir = selectedFile.getParent();

XmlEditor xmlEditor = new XmlEditor();
xmlEditor.setXmlFile(selectedFile);
XmlEditor xmlEditor = new XmlEditor(selectedFile);
xmlEditor.refresh();

xmlFilesPane.getTabs().add(xmlEditor);
Expand Down Expand Up @@ -408,7 +405,7 @@ private void test() {
xmlService.setCurrentXsdFile(Paths.get("examples/xsd/FundsXML4.xsd").toFile());

try {
XmlEditor xmlEditor = (XmlEditor) xmlFilesPane.getSelectionModel().getSelectedItem();
XmlEditor xmlEditor = getCurrentXmlEditor();
xmlEditor.setXmlFile(xmlExampleFile.toFile());
xmlEditor.refresh();
} catch (Exception e) {
Expand Down
59 changes: 33 additions & 26 deletions src/main/java/org/fxt/freexmltoolkit/controls/XmlEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class XmlEditor extends Tab {

public static final int MAX_SIZE_FOR_FORMATTING = 1024 * 1024 * 20;
public static final String DEFAULT_FILE_NAME = "Untitled.xml *";
private static final int DEFAULT_FONT_SIZE = 11;

private final Tab xml = new Tab("XML");
private final Tab graphic = new Tab("Graphic");
Expand All @@ -72,13 +73,20 @@ public class XmlEditor extends Tab {
private static final int GROUP_ATTRIBUTE_VALUE = 3;

File xmlFile;

private static final int DEFAULT_FONT_SIZE = 11;
private int fontSize = 11;
KeyCombination resetFontSizeKey = new KeyCodeCombination(KeyCode.DIGIT0, KeyCombination.CONTROL_DOWN);

public XmlEditor(File f) {
init();
this.setXmlFile(f);
this.refresh();
}

public XmlEditor() {
init();
}

private void init() {
TabPane tabPane = new TabPane();
tabPane.setSide(Side.LEFT);
tabPane.getTabs().addAll(xml, graphic);
Expand All @@ -91,27 +99,6 @@ public XmlEditor() {
}
});

/* TEST
Popup popup = new Popup();
Label popupMsg = new Label();
popupMsg.setStyle(
"-fx-background-color: black;" +
"-fx-text-fill: white;" +
"-fx-padding: 5;");
popup.getContent().add(popupMsg);
codeArea.setMouseOverTextDelay(Duration.ofSeconds(1));
codeArea.addEventHandler(MouseOverTextEvent.MOUSE_OVER_TEXT_BEGIN, e -> {
int chIdx = e.getCharacterIndex();
Point2D pos = e.getScreenPosition();
popupMsg.setText("Character '" + codeArea.getText(chIdx, chIdx + 1) + "' at " + pos);
popup.show(codeArea, pos.getX(), pos.getY() + 10);
});
codeArea.addEventHandler(MouseOverTextEvent.MOUSE_OVER_TEXT_END, e -> {
popup.hide();
});
TEST ENDE */

codeArea.addEventFilter(ScrollEvent.SCROLL, event -> {
if (event.isControlDown()) {
if (event.getDeltaY() > 0) {
Expand All @@ -123,7 +110,8 @@ public XmlEditor() {
});

codeArea.addEventFilter(KeyEvent.ANY, event -> {
if (event.isControlDown() && event.getCode() == KeyCode.NUMPAD0) {
if (event.isControlDown() && event.getCode() == KeyCode.NUMPAD0
|| event.isControlDown() && event.getCode() == KeyCode.DIGIT0) {
resetFontSize();
}
});
Expand All @@ -138,6 +126,27 @@ public XmlEditor() {
this.setClosable(true);
this.setOnCloseRequest(eh -> logger.debug("Close Event"));

codeArea.setOnDragDropped(event -> {
System.out.println("CODEAREA - BIN DRINNEN");
});

stackPane.setOnDragDropped(event -> System.out.println("EVENT"));
xml.getContent().setOnDragDropped(event -> System.out.println("EVENT XML"));

virtualizedScrollPane.setOnDragDropped(event -> {
System.out.println("BIN DRINNEN");
Dragboard db = event.getDragboard();
boolean success = false;
if (db.hasFiles()) {
success = true;
for (File file : db.getFiles()) {
System.out.println("file.getName() = " + file.getName());
}
}
event.setDropCompleted(success);
event.consume();
});

this.setContent(tabPane);
}

Expand All @@ -147,7 +156,6 @@ public File getXmlFile() {

public void setXmlFile(File xmlFile) {
this.xmlFile = xmlFile;

this.setText(xmlFile.getName());
}

Expand All @@ -168,7 +176,6 @@ private void setFontSize(int size) {
codeArea.setStyle("-fx-font-size: " + size + "pt;");
}


public void refresh() {
if (this.xmlFile.exists()) {
refreshTextView();
Expand Down
8 changes: 6 additions & 2 deletions src/main/resources/pages/main.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@
<MenuItem text="Open"/>
<SeparatorMenuItem/>
<SeparatorMenuItem/>
<MenuItem fx:id="menuItemExit" text="Exit"/>
<MenuItem fx:id="menuItemExit" text="Exit">
<graphic>
<FontIcon iconColor="darkslategray" iconLiteral="bi-door-closed" iconSize="16"/>
</graphic>
</MenuItem>
</Menu>
<Menu fx:id="lastOpenFilesMenu" text="last open Files">
</Menu>
Expand Down Expand Up @@ -76,7 +80,7 @@
</HBox>
</bottom>
<left>
<VBox styleClass="menu_box" AnchorPane.bottomAnchor="0" AnchorPane.topAnchor="0">
<VBox fx:id="leftMenu" styleClass="menu_box" AnchorPane.bottomAnchor="0" AnchorPane.topAnchor="0">
<BorderPane VBox.vgrow="ALWAYS">
<top>
<VBox BorderPane.alignment="CENTER">
Expand Down

0 comments on commit 0769a7c

Please sign in to comment.