Skip to content
Snippets Groups Projects
Commit dfdf02dd authored by Jan Kožusznik's avatar Jan Kožusznik
Browse files

Refactoring UI elements

UI
parent 71275839
No related branches found
No related tags found
No related merge requests found
...@@ -2,6 +2,7 @@ package cz.it4i.fiji.haas.ui; ...@@ -2,6 +2,7 @@ package cz.it4i.fiji.haas.ui;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Frame; import java.awt.Frame;
import java.awt.Window;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.util.function.Consumer; import java.util.function.Consumer;
...@@ -14,17 +15,23 @@ import javafx.fxml.FXMLLoader; ...@@ -14,17 +15,23 @@ import javafx.fxml.FXMLLoader;
import javafx.scene.Parent; import javafx.scene.Parent;
import javafx.scene.Scene; import javafx.scene.Scene;
public class FXFrame<C> extends JDialog {
public class FXFrame<C extends FXFrame.Controller> extends JDialog {
public interface Controller {
void init(Window frame);
}
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private JFXPanel fxPanel; private JFXPanel fxPanel;
private String fxmlFile; private String fxmlFile;
private Consumer<C> controlerInit; private Consumer<C> controlerInit;
private C controller;
public FXFrame(String fxmlFile) { public FXFrame(String fxmlFile) {
this(null, fxmlFile); this(null, fxmlFile);
} }
public FXFrame(Frame applicationFrame, String string) { public FXFrame(Frame applicationFrame, String string) {
super(applicationFrame); super(applicationFrame);
fxmlFile = string; fxmlFile = string;
...@@ -33,12 +40,12 @@ public class FXFrame<C> extends JDialog { ...@@ -33,12 +40,12 @@ public class FXFrame<C> extends JDialog {
/** /**
* Create the JFXPanel that make the link between Swing (IJ) and JavaFX plugin. * Create the JFXPanel that make the link between Swing (IJ) and JavaFX plugin.
*/ */
protected void init( Consumer<C> controlerInit) { protected void init(Consumer<C> controlerInit) {
this.controlerInit = controlerInit; this.controlerInit = controlerInit;
this.fxPanel = new JFXPanel(); this.fxPanel = new JFXPanel();
Platform.setImplicitExit(false); Platform.setImplicitExit(false);
this.add(this.fxPanel); this.add(this.fxPanel);
// The call to runLater() avoid a mix between JavaFX thread and Swing thread. // The call to runLater() avoid a mix between JavaFX thread and Swing thread.
Platform.runLater(new Runnable() { Platform.runLater(new Runnable() {
@Override @Override
...@@ -50,34 +57,38 @@ public class FXFrame<C> extends JDialog { ...@@ -50,34 +57,38 @@ public class FXFrame<C> extends JDialog {
} }
protected C getController() {
return controller;
}
private void initFX(JFXPanel fxPanel) { private void initFX(JFXPanel fxPanel) {
// Init the root layout // Init the root layout
try { try {
FXMLLoader loader = new FXMLLoader(); FXMLLoader loader = new FXMLLoader();
URL res = FXFrame.class.getResource(fxmlFile); URL res = FXFrame.class.getResource(fxmlFile);
loader.setLocation(res); loader.setLocation(res);
Parent rootLayout = (Parent) loader.load(); Parent rootLayout = (Parent) loader.load();
// Get the controller and add an ImageJ context to it. // Get the controller and add an ImageJ context to it.
C controller = loader.<C>getController(); controller = loader.<C>getController();
controlerInit.accept(controller); controlerInit.accept(controller);
controller.init(this);
// Show the scene containing the root layout. // Show the scene containing the root layout.
Scene scene = new Scene(rootLayout); Scene scene = new Scene(rootLayout);
this.fxPanel.setScene(scene); this.fxPanel.setScene(scene);
this.fxPanel.setVisible(true); this.fxPanel.setVisible(true);
// Resize the JFrame to the JavaFX scene // Resize the JFrame to the JavaFX scene
Dimension dim = new Dimension((int) scene.getWidth(), (int) scene.getHeight()); Dimension dim = new Dimension((int) scene.getWidth(), (int) scene.getHeight());
this.fxPanel.setMinimumSize(dim); this.fxPanel.setMinimumSize(dim);
this.fxPanel.setMaximumSize(dim); this.fxPanel.setMaximumSize(dim);
this.fxPanel.setPreferredSize(dim); this.fxPanel.setPreferredSize(dim);
//this.setSize((int) scene.getWidth(), (int) scene.getHeight()); // this.setSize((int) scene.getWidth(), (int) scene.getHeight());
this.pack(); this.pack();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
......
...@@ -9,6 +9,7 @@ import org.scijava.log.LogService; ...@@ -9,6 +9,7 @@ import org.scijava.log.LogService;
import org.scijava.plugin.Parameter; import org.scijava.plugin.Parameter;
import cz.it4i.fiji.haas.JobManager.JobInfo; import cz.it4i.fiji.haas.JobManager.JobInfo;
import cz.it4i.fiji.haas.ui.FXFrame;
import cz.it4i.fiji.haas.ui.ModalDialogs; import cz.it4i.fiji.haas.ui.ModalDialogs;
import cz.it4i.fiji.haas.ui.ObservableValueAdapter; import cz.it4i.fiji.haas.ui.ObservableValueAdapter;
import cz.it4i.fiji.haas.ui.ProgressDialog; import cz.it4i.fiji.haas.ui.ProgressDialog;
...@@ -22,7 +23,7 @@ import javafx.scene.control.TableColumn; ...@@ -22,7 +23,7 @@ import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView; import javafx.scene.control.TableView;
import javafx.scene.input.ContextMenuEvent; import javafx.scene.input.ContextMenuEvent;
public class CheckStatusOfHaaSController { public class CheckStatusOfHaaSController implements FXFrame.Controller{
@Parameter @Parameter
private LogService logService; private LogService logService;
......
...@@ -15,9 +15,7 @@ public class CheckStatusOfHaaSWindow extends FXFrame<CheckStatusOfHaaSController ...@@ -15,9 +15,7 @@ public class CheckStatusOfHaaSWindow extends FXFrame<CheckStatusOfHaaSController
@Parameter @Parameter
private Context context; private Context context;
private CheckStatusOfHaaSController controller;
public CheckStatusOfHaaSWindow(Frame applicationFrame, Context context) { public CheckStatusOfHaaSWindow(Frame applicationFrame, Context context) {
super(applicationFrame, "/cz/it4i/fiji/haas_snakemake_spim/ui/CheckStatusOfHaaS.fxml"); super(applicationFrame, "/cz/it4i/fiji/haas_snakemake_spim/ui/CheckStatusOfHaaS.fxml");
this.context = context; this.context = context;
...@@ -30,15 +28,13 @@ public class CheckStatusOfHaaSWindow extends FXFrame<CheckStatusOfHaaSController ...@@ -30,15 +28,13 @@ public class CheckStatusOfHaaSWindow extends FXFrame<CheckStatusOfHaaSController
Platform.runLater(new Runnable() { Platform.runLater(new Runnable() {
@Override @Override
public void run() { public void run() {
controller.addJob(job); getController().addJob(job);
} }
}); });
} }
private void initController(CheckStatusOfHaaSController controller) { private void initController(CheckStatusOfHaaSController controller) {
this.controller = controller;
context.inject(controller); context.inject(controller);
controller.init(this);
} }
} }
package cz.it4i.fiji.haas_spim_benchmark.ui;
import java.awt.Window;
import cz.it4i.fiji.haas.ui.FXFrame;
public class BenchmarkSPIMController implements FXFrame.Controller{
@Override
public void init(Window frame) {
// TODO Auto-generated method stub
}
}
package cz.it4i.fiji.haas_spim_benchmark.ui;
import java.awt.Frame;
import cz.it4i.fiji.haas.ui.FXFrame;
public class BenchmarkSPIMWindow extends FXFrame<BenchmarkSPIMController> {
private static final long serialVersionUID = 1L;
public BenchmarkSPIMWindow(Frame applicationFrame) {
super(applicationFrame, "/cz/it4i/fiji/haas_spim_benchmark/ui/BenchmarkSPIM.fxml");
init(x->{});
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment