From 2a93b1f410efa99929a89e5fbeb12bd8a166ada0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Ko=C5=BEusznik?= <jan@kozusznik.cz> Date: Mon, 9 Jul 2018 15:28:34 +0200 Subject: [PATCH] feat: iss1106 show window centered on screen --- .../java/cz/it4i/fiji/haas/ui/FXFrame.java | 30 ++++++++++++------- .../cz/it4i/fiji/haas/ui/SwingRoutines.java | 16 ++++++++++ .../commands/ManageSPIMBenchmark.java | 23 +++++++------- .../ui/BenchmarkSPIMWindow.java | 1 - .../ui/SPIMPipelineProgressViewWindow.java | 19 ------------ 5 files changed, 47 insertions(+), 42 deletions(-) create mode 100644 haas-imagej-client/src/main/java/cz/it4i/fiji/haas/ui/SwingRoutines.java delete mode 100644 haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/SPIMPipelineProgressViewWindow.java diff --git a/haas-imagej-client/src/main/java/cz/it4i/fiji/haas/ui/FXFrame.java b/haas-imagej-client/src/main/java/cz/it4i/fiji/haas/ui/FXFrame.java index 23dda8e8..74f56f81 100644 --- a/haas-imagej-client/src/main/java/cz/it4i/fiji/haas/ui/FXFrame.java +++ b/haas-imagej-client/src/main/java/cz/it4i/fiji/haas/ui/FXFrame.java @@ -22,12 +22,12 @@ public abstract class FXFrame<T extends Parent&CloseableControl> extends JDialog private static Logger log = LoggerFactory.getLogger(cz.it4i.fiji.haas.ui.FXFrame.class); private static final long serialVersionUID = 1L; private JFXPanel<T> fxPanel; - + public FXFrame(Supplier<T> fxSupplier) { - this(null,fxSupplier); + this(null, fxSupplier); } - - public FXFrame(Window parent, Supplier<T> fxSupplier) { + + public FXFrame(Window parent, Supplier<T> fxSupplier){ super(parent, ModalityType.MODELESS); fxPanel = new JFXPanel<>(fxSupplier); init(); @@ -37,6 +37,17 @@ public abstract class FXFrame<T extends Parent&CloseableControl> extends JDialog } } + public JFXPanel<T> getFxPanel() { + return fxPanel; + } + + public void executeAdjustment(Runnable command) { + JavaFXRoutines.runOnFxThread(() -> { + command.run(); + }); + } + + private void init() { addWindowListener(new WindowAdapter() { @Override @@ -56,12 +67,9 @@ public abstract class FXFrame<T extends Parent&CloseableControl> extends JDialog this.setLayout(new BorderLayout()); //JScrollPane scrollPane = new JScrollPane(this.fxPanel); this.add(fxPanel, BorderLayout.CENTER); - JavaFXRoutines.runOnFxThread(() -> this.pack()); - - } - - - public JFXPanel<T> getFxPanel() { - return fxPanel; + JavaFXRoutines.runOnFxThread(() -> { + this.pack(); + SwingRoutines.centerOnScreen(this); + }); } } diff --git a/haas-imagej-client/src/main/java/cz/it4i/fiji/haas/ui/SwingRoutines.java b/haas-imagej-client/src/main/java/cz/it4i/fiji/haas/ui/SwingRoutines.java new file mode 100644 index 00000000..3286e31e --- /dev/null +++ b/haas-imagej-client/src/main/java/cz/it4i/fiji/haas/ui/SwingRoutines.java @@ -0,0 +1,16 @@ +package cz.it4i.fiji.haas.ui; + +import java.awt.Component; +import java.awt.Dimension; +import java.awt.Toolkit; + +public interface SwingRoutines { + + static void centerOnScreen(Component component) { + Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize(); + int x = (int) ((dimension.getWidth() - component.getWidth()) / 2); + int y = (int) ((dimension.getHeight() - component.getHeight()) / 2); + component.setLocation(x, y); + } + +} diff --git a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/commands/ManageSPIMBenchmark.java b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/commands/ManageSPIMBenchmark.java index ab4c6acc..d8368e00 100644 --- a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/commands/ManageSPIMBenchmark.java +++ b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/commands/ManageSPIMBenchmark.java @@ -8,7 +8,6 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import javax.swing.JDialog; import javax.swing.WindowConstants; import org.scijava.Context; @@ -71,18 +70,20 @@ public class ManageSPIMBenchmark implements Command { return; } try { - final JDialog dialog = new BenchmarkSPIMWindow(null, + final BenchmarkSPIMWindow dialog = new BenchmarkSPIMWindow(null, new BenchmarkSPIMParametersImpl(userName, password, Constants.PHONE, email, workingDirPath)); - dialog.setTitle(Constants.MENU_ITEM_NAME + " " + Constants.SUBMENU_ITEM_NAME); - dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); - dialog.addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(final WindowEvent e) { - super.windowClosing(e); - fl.close(); - } + dialog.executeAdjustment(() -> { + dialog.setTitle(Constants.MENU_ITEM_NAME + " " + Constants.SUBMENU_ITEM_NAME); + dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); + dialog.addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(final WindowEvent e) { + super.windowClosing(e); + fl.close(); + } + }); + dialog.setVisible(true); }); - dialog.setVisible(true); } catch(final IOException e) { fl.close(); throw e; diff --git a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/BenchmarkSPIMWindow.java b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/BenchmarkSPIMWindow.java index 840e058e..7f554662 100644 --- a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/BenchmarkSPIMWindow.java +++ b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/BenchmarkSPIMWindow.java @@ -22,5 +22,4 @@ public class BenchmarkSPIMWindow extends FXFrame<BenchmarkSPIMControl>{ }); } - } diff --git a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/SPIMPipelineProgressViewWindow.java b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/SPIMPipelineProgressViewWindow.java deleted file mode 100644 index 4237bab5..00000000 --- a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/SPIMPipelineProgressViewWindow.java +++ /dev/null @@ -1,19 +0,0 @@ -package cz.it4i.fiji.haas_spim_benchmark.ui; - -import java.awt.Window; -import java.io.IOException; - -import cz.it4i.fiji.haas.ui.FXFrame; -import cz.it4i.fiji.haas_spim_benchmark.core.BenchmarkJobManager.BenchmarkJob; - -public class SPIMPipelineProgressViewWindow extends FXFrame<SPIMPipelineProgressViewController> { - - private static final long serialVersionUID = 1L; - - public SPIMPipelineProgressViewWindow(Window applicationFrame,BenchmarkJob job) throws IOException { - super(applicationFrame,()->new SPIMPipelineProgressViewController(job)); - - } - - -} -- GitLab