Menu

[r10]: / XMLTool / src / xmltool / Main.java  Maximize  Restore  History

Download this file

108 lines (98 with data), 4.6 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
package xmltool;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.util.Duration;
import org.fxmisc.richtext.CodeArea;
import xmltool.utils.UIHelperUtil;
public class Main extends Application {
private Scene scene;
@Override
public void start(final Stage stage) throws Exception {
setUserAgentStylesheet(STYLESHEET_CASPIAN);
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("Main.fxml"));
Parent root = fxmlLoader.load();
scene = new Scene(root);
scene.setFill(Color.TRANSPARENT);
stage.initStyle(StageStyle.TRANSPARENT);
stage.setScene(scene);
stage.setTitle("XML Tool");
stage.show();
final TabPane tabPane = (TabPane) scene.lookup("#tabPane");
Tab currTab = tabPane.getSelectionModel().getSelectedItem();
UIBean.setCurCodeArea((CodeArea) currTab.getContent().lookup("#textArea"));
UIBean.getCurCodeArea().requestFocus();
//prevent default on close action of tabs
UIHelperUtil.setOnCloseRequest(tabPane, stage);
//add changeListener for the current selected tab
tabPane.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Tab>() {
@Override
public void changed(ObservableValue<? extends Tab> ov, Tab oldTab, Tab newTab) {
UIBean.setCurCodeArea((CodeArea) newTab.getContent().lookup("#textArea"));
//can't request focus here as it should happen few ms lates.
}
});
tabPane.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> ov, Number t, final Number t1) {
Platform.runLater(new Runnable() {
@Override
public void run() {
if (tabPane.getTabs().size() > 0) {
final Tab tab = tabPane.getTabs().get(t1.intValue());
final Timeline animation = new Timeline(
new KeyFrame(Duration.millis(25),
new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
Platform.runLater(new Runnable() {
@Override
public void run() {
tab.getContent().lookup("#textArea").requestFocus();
}
});
}
}));
animation.setCycleCount(1);
animation.play();
} else { //all tabs are closed exit the program
UIHelperUtil.exitProgram();
}
}
});
}
});
initialization(fxmlLoader.getController());
}
/**
* Restores the program to some saved state.
*/
private void initialization(MainController mainController) {
//restores the serelized file to the previous state
UIHelperUtil.restoreState(mainController);
}
/**
* The main() method is ignored in correctly deployed JavaFX application.
* main() serves only as fallback in case the application can not be
* launched through deployment artifacts, e.g., in IDEs with limited FX
* support. NetBeans ignores main().
*
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.