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;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Window;
import java.io.IOException;
import java.net.URL;
import java.util.function.Consumer;
......@@ -14,17 +15,23 @@ import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
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 JFXPanel fxPanel;
private String fxmlFile;
private Consumer<C> controlerInit;
private C controller;
public FXFrame(String fxmlFile) {
this(null, fxmlFile);
}
public FXFrame(Frame applicationFrame, String string) {
super(applicationFrame);
fxmlFile = string;
......@@ -33,12 +40,12 @@ public class FXFrame<C> extends JDialog {
/**
* 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.fxPanel = new JFXPanel();
Platform.setImplicitExit(false);
this.add(this.fxPanel);
// The call to runLater() avoid a mix between JavaFX thread and Swing thread.
Platform.runLater(new Runnable() {
@Override
......@@ -50,34 +57,38 @@ public class FXFrame<C> extends JDialog {
}
protected C getController() {
return controller;
}
private void initFX(JFXPanel fxPanel) {
// Init the root layout
try {
FXMLLoader loader = new FXMLLoader();
URL res = FXFrame.class.getResource(fxmlFile);
loader.setLocation(res);
Parent rootLayout = (Parent) loader.load();
// Get the controller and add an ImageJ context to it.
C controller = loader.<C>getController();
controlerInit.accept(controller);
// Show the scene containing the root layout.
Scene scene = new Scene(rootLayout);
this.fxPanel.setScene(scene);
this.fxPanel.setVisible(true);
// Resize the JFrame to the JavaFX scene
Dimension dim = new Dimension((int) scene.getWidth(), (int) scene.getHeight());
this.fxPanel.setMinimumSize(dim);
this.fxPanel.setMaximumSize(dim);
this.fxPanel.setPreferredSize(dim);
//this.setSize((int) scene.getWidth(), (int) scene.getHeight());
this.pack();
} catch (IOException e) {
e.printStackTrace();
}
try {
FXMLLoader loader = new FXMLLoader();
URL res = FXFrame.class.getResource(fxmlFile);
loader.setLocation(res);
Parent rootLayout = (Parent) loader.load();
// Get the controller and add an ImageJ context to it.
controller = loader.<C>getController();
controlerInit.accept(controller);
controller.init(this);
// Show the scene containing the root layout.
Scene scene = new Scene(rootLayout);
this.fxPanel.setScene(scene);
this.fxPanel.setVisible(true);
// Resize the JFrame to the JavaFX scene
Dimension dim = new Dimension((int) scene.getWidth(), (int) scene.getHeight());
this.fxPanel.setMinimumSize(dim);
this.fxPanel.setMaximumSize(dim);
this.fxPanel.setPreferredSize(dim);
// this.setSize((int) scene.getWidth(), (int) scene.getHeight());
this.pack();
} catch (IOException e) {
e.printStackTrace();
}
}
......
......@@ -9,6 +9,7 @@ import org.scijava.log.LogService;
import org.scijava.plugin.Parameter;
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.ObservableValueAdapter;
import cz.it4i.fiji.haas.ui.ProgressDialog;
......@@ -22,7 +23,7 @@ import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.input.ContextMenuEvent;
public class CheckStatusOfHaaSController {
public class CheckStatusOfHaaSController implements FXFrame.Controller{
@Parameter
private LogService logService;
......
......@@ -15,9 +15,7 @@ public class CheckStatusOfHaaSWindow extends FXFrame<CheckStatusOfHaaSController
@Parameter
private Context context;
private CheckStatusOfHaaSController controller;
public CheckStatusOfHaaSWindow(Frame applicationFrame, Context context) {
super(applicationFrame, "/cz/it4i/fiji/haas_snakemake_spim/ui/CheckStatusOfHaaS.fxml");
this.context = context;
......@@ -30,15 +28,13 @@ public class CheckStatusOfHaaSWindow extends FXFrame<CheckStatusOfHaaSController
Platform.runLater(new Runnable() {
@Override
public void run() {
controller.addJob(job);
getController().addJob(job);
}
});
}
private void initController(CheckStatusOfHaaSController controller) {
this.controller = 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