Skip to content

Instantly share code, notes, and snippets.

@denistouch
Created December 17, 2018 13:58
Show Gist options
  • Save denistouch/9476960a60019d02ee3303fd722e19ca to your computer and use it in GitHub Desktop.
Save denistouch/9476960a60019d02ee3303fd722e19ca to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<option name="DEFAULT_COMPILER" value="Javac" />
<resourceExtensions />
<wildcardResourcePatterns>
<entry name="!?*.java" />
<entry name="!?*.form" />
<entry name="!?*.class" />
<entry name="!?*.groovy" />
<entry name="!?*.scala" />
<entry name="!?*.flex" />
<entry name="!?*.kt" />
<entry name="!?*.clj" />
</wildcardResourcePatterns>
<annotationProcessing>
<profile default="true" name="Default" enabled="false">
<processorPath useClasspath="true" />
</profile>
</annotationProcessing>
</component>
</project>
<html>Simple <b>JavaFX 2.0</b> application that includes simple .fxml file with attached controller and Main class to quick start. Artifact to build JavaFX application is provided.
</html>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" />
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleSettings">
<option name="gradleHome" value="C:/Program Files (x86)/Gradle/gradle-1.0-rc-3" />
</component>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="EntryPointsManager">
<entry_points version="2.0" />
</component>
<component name="ProjectKey">
<option name="state" value="project://e79810c8-c5c8-43b1-b19c-90c1f4095425" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/splatTest.iml" filepath="$PROJECT_DIR$/splatTest.iml" />
</modules>
</component>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
package sample;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Cursor;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import sample.view.RootLayoutController;
public class Main extends Application {
private double width = 800;
private double height = 600;
private Stage stage = new Stage();
@Override
public void start(Stage primaryStage) throws Exception{
stage = primaryStage;
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("view/RootLayoutController.fxml"));
Parent parent = loader.load();
RootLayoutController rootLayoutController = loader.getController();
Scene scene = new Scene(parent,width,height);
primaryStage.setTitle(getClass().getName());
primaryStage.setScene(scene);
primaryStage.setMinWidth(400);
primaryStage.setMinHeight(350);
primaryStage.show();
rootLayoutController.setMain(this);
rootLayoutController.loaded();
}
public Stage getStage(){
return stage;
}
public static void main(String[] args) {
launch(args);
}
}
package sample;
/**
* Resize tab content with parent
* AddContent into the text area in this Tab
* show progressAnimation in progress Bar
* search in document
* search in directory and following dir
*
*
**/
package sample.utilities;
import javafx.scene.control.Button;
import javafx.scene.control.Tab;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
public class DocTab extends Tab {
private TextField textField;
private TextArea textArea;
private Button prev,next;
private BorderPane content;
private String text;
public DocTab(String text) {
textField = new TextField();
textArea = new TextArea();
content = new BorderPane();
// content.setTop();
}
}
package sample.utilities;
import java.nio.file.Path;
public class PathItem {
private Path path;
public PathItem(Path path) {
//System.out.println("public PathItem(Path path) + path: " + path);
this.path = path;
}
public Path getPath() {
//System.out.println("public Path getPath() + path: " + path);
return path;
}
@Override
public String toString() {
//System.out.println("public String toString() + path: " + path);
if (path.getFileName() == null) {
return path.toString();
} else {
return path.getFileName().toString();
}
}
}
package sample.utilities;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.control.TreeItem;
import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
public class PathTreeItem extends TreeItem<PathItem> {
private boolean isLeaf = false;
private boolean isFirstTimeChildren = true;
private boolean isFirstTimeLeft = true;
private PathTreeItem(PathItem pathItem) {
super(pathItem);
//System.out.println("private PathTreeItem(PathItem pathItem) + pathItem.getPath(): " + pathItem.getPath());
}
public static TreeItem<PathItem> createTreeItem(PathItem pathItem) {
//System.out.println("public static TreeItem<PathItem> createTreeItem(PathItem pathItem) + pathItem.getPath(): " + pathItem.getPath());
return new PathTreeItem(pathItem);
}
@Override
public ObservableList<TreeItem<PathItem>> getChildren() {
//System.out.println("public ObservableList<TreeItem<PathItem>> getChildren() ");
if (isFirstTimeChildren) {
isFirstTimeChildren = false;
super.getChildren().setAll(buildChildren(this));
}
return super.getChildren();
}
@Override
public boolean isLeaf() {
if (isFirstTimeLeft) {
isFirstTimeLeft = false;
Path path = getValue().getPath();
isLeaf = !Files.isDirectory(path, LinkOption.NOFOLLOW_LINKS);
//System.out.println("isLeaf + path: " + path);
}
return isLeaf;
}
private ObservableList<TreeItem<PathItem>> buildChildren(TreeItem<PathItem> treeItem) {
//System.out.println("private ObservableList<TreeItem<PathItem>> buildChildren(TreeItem<PathItem> treeItem) ");
Path path = treeItem.getValue().getPath();
if (path != null && Files.isDirectory(path, LinkOption.NOFOLLOW_LINKS)) {
ObservableList<TreeItem<PathItem>> children = FXCollections.observableArrayList();
try (DirectoryStream<Path> dirs = Files.newDirectoryStream(path)) {
for (Path dir : dirs) {
PathItem pathItem = new PathItem(dir);
children.add(createTreeItem(pathItem));
}
} catch (IOException ex) {
ex.printStackTrace();
}
return children;
}
return FXCollections.emptyObservableList();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ChoiceBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuBar?>
<?import javafx.scene.control.ProgressBar?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.control.TabPane?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.TreeView?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<BorderPane minHeight="300.0" minWidth="400.0" prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.view.RootLayoutController">
<top>
<MenuBar BorderPane.alignment="CENTER">
<menus>
<Menu mnemonicParsing="false">
<graphic>
<Button fx:id="openButton" mnemonicParsing="false" onAction="#setOnOpenHandler" text="Open" />
</graphic>
</Menu>
<Menu mnemonicParsing="false">
<graphic>
<TextField fx:id="searchTextField" promptText="search" />
</graphic>
</Menu>
<Menu mnemonicParsing="false">
<graphic>
<ChoiceBox fx:id="extensionChoiceBox" prefWidth="50.0" />
</graphic>
</Menu>
</menus>
</MenuBar>
</top>
<bottom>
<BorderPane prefHeight="30.0" prefWidth="800.0" BorderPane.alignment="CENTER">
<left>
<Label fx:id="fileNameLabel" prefHeight="30.0" prefWidth="150.0" BorderPane.alignment="CENTER" />
</left>
<right>
<Label fx:id="countMatchesLabel" alignment="CENTER_RIGHT" prefHeight="30.0" prefWidth="150.0" BorderPane.alignment="CENTER" />
</right>
<top>
<GridPane gridLinesVisible="true" prefHeight="0.0" BorderPane.alignment="CENTER">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="0.0" prefHeight="0.0" vgrow="SOMETIMES" />
</rowConstraints>
</GridPane>
</top>
<center>
<ProgressBar fx:id="indicator" prefHeight="20.0" prefWidth="500.0" progress="0.0" visible="false" BorderPane.alignment="CENTER" />
</center>
</BorderPane>
</bottom>
<center>
<SplitPane dividerPositions="0.5" prefHeight="160.0" prefWidth="200.0" BorderPane.alignment="CENTER">
<items>
<TreeView fx:id="directoryTreeView" prefHeight="200.0" prefWidth="200.0" />
<TabPane fx:id="documentTabPane" prefHeight="537.0" prefWidth="400.0" tabClosingPolicy="UNAVAILABLE" />
</items>
</SplitPane>
</center>
</BorderPane>
package sample.view;
import javafx.animation.AnimationTimer;
import javafx.application.Platform;
import javafx.event.EventHandler;
import javafx.event.EventType;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.control.*;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import javafx.stage.DirectoryChooser;
import sample.Main;
import sample.utilities.PathItem;
import sample.utilities.PathTreeItem;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
public class RootLayoutController {
@FXML
private Button openButton;
@FXML
private TextField searchTextField;
@FXML
private ChoiceBox extensionChoiceBox;
@FXML
private TreeView<PathItem> directoryTreeView;
@FXML
private TabPane documentTabPane;
@FXML
private Label fileNameLabel;
@FXML
private Label countMatchesLabel;
@FXML
private ProgressBar indicator;
private Main main;
private float indicatorValue = 0.00f;
public RootLayoutController() {
}
public void setMain(Main main) {
this.main = main;
}
@FXML
private void initialize() {
documentTabPane.setTabClosingPolicy(TabPane.TabClosingPolicy.ALL_TABS);
indicator.setVisible(true);
loading.start();
extensionChoiceBox.getItems().addAll(".log", ".txt", ".java");
extensionChoiceBox.getSelectionModel().selectFirst();
}
@FXML
private void setOnOpenHandler() {
DirectoryChooser directoryChooser = new DirectoryChooser();
directoryChooser.setTitle("Please select a root directory.");
File file = directoryChooser.showDialog(main.getStage());
loading.start();
if (file == null)
return;
Path path = file.toPath();
directoryTreeView.setRoot(createTreeItem(new PathItem(path)));
directoryTreeView.getRoot().setExpanded(true);
directoryTreeView.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
if (directoryTreeView.getSelectionModel().getSelectedItem()==null)
return;
fileNameLabel.setText(directoryTreeView.getSelectionModel().getSelectedItem().getValue().toString());
if (event.getClickCount() == 2)
createTab();
}
});
loading.stop();
}
private TreeItem<PathItem> createTreeItem(PathItem pathItem) {
return PathTreeItem.createTreeItem(pathItem);
}
protected AnimationTimer loading = new AnimationTimer() {
@Override
public void handle(long now) {
indicatorAnimation();
}
};
private void indicatorAnimation() {
}
private void createTab() {
try {
Tab tab = new Tab(directoryTreeView.getTreeItem(directoryTreeView.getSelectionModel().getSelectedIndex()).getValue().toString());
tab.setClosable(true);
FXMLLoader loader = new FXMLLoader();
loader.setLocation(main.getClass().getResource("view/TabLayoutController.fxml"));
BorderPane borderPane = loader.load();
borderPane.setPrefWidth(documentTabPane.getWidth()-5);
borderPane.setPrefHeight(documentTabPane.getHeight()-30);
tab.setContent(borderPane);
documentTabPane.getTabs().add(tab);
System.out.println("Tab was created.");
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
public void loaded() {
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle("Good news!");
alert.setHeaderText(getClass().getSimpleName() + " successful loaded!");
alert.setContentText("From: " + main.getClass().getSimpleName());
alert.showAndWait();
loading.stop();
indicator.setVisible(false);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.BorderPane?>
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.view.TabLayoutController">
<bottom>
<BorderPane BorderPane.alignment="CENTER">
<left>
<Button fx:id="prevButton" mnemonicParsing="false" text="Prev" BorderPane.alignment="CENTER" />
</left>
<right>
<Button fx:id="nextButton" mnemonicParsing="false" text="Next" BorderPane.alignment="CENTER" />
</right>
</BorderPane>
</bottom>
<center>
<TextArea fx:id="documentViewTextArea" BorderPane.alignment="CENTER" />
</center>
<top>
<TextField fx:id="findInDocTextField" BorderPane.alignment="CENTER" />
</top>
</BorderPane>
package sample.view;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.effect.Effect;
public class TabLayoutController {
@FXML
private TextField findInDocTextField;
@FXML
private TextArea documentViewTextArea;
@FXML
private Button prevButton;
@FXML
private Button nextButton;
@FXML
private void initialize() {
System.out.println("Tab initialized");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment