diff --git a/pom.xml b/pom.xml index be65a41ed702f5985088e40d635dc3572c45d49c..0cf94734f05f8552a19449dc51d61257b2acfc76 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ <!-- Project Information --> <artifactId>flying-camera</artifactId> - <version>1.6.1</version> + <version>2.0.0</version> <packaging>jar</packaging> diff --git a/src/main/java/plugins/tprovoost/flycam/CameraPosition.java b/src/main/java/plugins/tprovoost/flycam/CameraPosition.java index 39306a9be49aaf5ea1c62a0679623f101207dbc0..dbd59237d284eeb8b69013392faa5870ff524cdb 100644 --- a/src/main/java/plugins/tprovoost/flycam/CameraPosition.java +++ b/src/main/java/plugins/tprovoost/flycam/CameraPosition.java @@ -1,8 +1,25 @@ +/* + * Copyright (c) 2010-2023. Institut Pasteur. + * + * This file is part of Icy. + * Icy is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Icy is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Icy. If not, see <https://www.gnu.org/licenses/>. + */ + package plugins.tprovoost.flycam; import icy.type.collection.array.ArrayUtil; import icy.util.XMLUtil; - import org.w3c.dom.Element; public class CameraPosition { @@ -34,7 +51,7 @@ public class CameraPosition { timeIndex = 0; } - public void saveCamera(Element e) { + public void saveCamera(final Element e) { if (e != null) { XMLUtil.setElementDoubleValue(e, ID_POSX, position[0]); XMLUtil.setElementDoubleValue(e, ID_POSY, position[1]); @@ -50,7 +67,7 @@ public class CameraPosition { } } - public void loadCamera(Element e) { + public void loadCamera(final Element e) { if (e != null) { position[0] = XMLUtil.getElementDoubleValue(e, ID_POSX, 0d); position[1] = XMLUtil.getElementDoubleValue(e, ID_POSY, 0d); diff --git a/src/main/java/plugins/tprovoost/flycam/FlyCam.java b/src/main/java/plugins/tprovoost/flycam/FlyCam.java index 2e467cdeea0c3406a8a8cb91cec5934f9af4e7d7..60ac7e95877c27d7bec7da8a33c1cb167fa80d1a 100644 --- a/src/main/java/plugins/tprovoost/flycam/FlyCam.java +++ b/src/main/java/plugins/tprovoost/flycam/FlyCam.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2010-2023. Institut Pasteur. + * + * This file is part of Icy. + * Icy is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Icy is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Icy. If not, see <https://www.gnu.org/licenses/>. + */ + package plugins.tprovoost.flycam; import icy.gui.dialog.MessageDialog; @@ -7,7 +25,7 @@ import icy.sequence.Sequence; public class FlyCam extends PluginActionable { @Override public void run() { - Sequence s = getActiveSequence(); + final Sequence s = getActiveSequence(); if (s == null) { MessageDialog.showDialog("You must have a sequence opened for this operation."); diff --git a/src/main/java/plugins/tprovoost/flycam/FlyCamOverlay.java b/src/main/java/plugins/tprovoost/flycam/FlyCamOverlay.java index 65abae5b7d66e0e3ba3a2f1a73a9c3972d8c5091..ec630389c7e357cffb20c6f0e912de7ed638b33e 100644 --- a/src/main/java/plugins/tprovoost/flycam/FlyCamOverlay.java +++ b/src/main/java/plugins/tprovoost/flycam/FlyCamOverlay.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2010-2023. Institut Pasteur. + * + * This file is part of Icy. + * Icy is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Icy is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Icy. If not, see <https://www.gnu.org/licenses/>. + */ + package plugins.tprovoost.flycam; import icy.canvas.IcyCanvas; @@ -9,13 +27,10 @@ import icy.sequence.Sequence; import icy.system.thread.ThreadUtil; import icy.type.point.Point5D; import icy.vtk.IcyVtkPanel; +import plugins.kernel.canvas.VtkCanvas; +import vtk.vtkCamera; -import java.awt.AWTException; -import java.awt.Cursor; -import java.awt.Graphics2D; -import java.awt.Point; -import java.awt.Robot; -import java.awt.Toolkit; +import java.awt.*; import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; import java.awt.event.WindowEvent; @@ -23,9 +38,6 @@ import java.awt.event.WindowFocusListener; import java.awt.image.BufferedImage; import java.util.HashMap; -import plugins.kernel.canvas.VtkCanvas; -import vtk.vtkCamera; - public class FlyCamOverlay extends Overlay { enum MovementType { MOVE_FORWARD, MOVE_BACKWARD, MOVE_STRAFE_LEFT, MOVE_STRAFE_RIGHT, MOVE_STRAFE_UP, MOVE_STRAFE_DOWN @@ -47,7 +59,7 @@ public class FlyCamOverlay extends Overlay { private final MovementThread movementThread; /** - * Used to know if a overlay has been removed + * Used to know if an overlay has been removed */ GlobalOverlayListener overlayListener; @@ -61,12 +73,12 @@ public class FlyCamOverlay extends Overlay { overlayListener = new GlobalOverlayListener() { @Override - public void overlayAdded(Overlay overlay) { + public void overlayAdded(final Overlay overlay) { // nothing here } @Override - public void overlayRemoved(Overlay overlay) { + public void overlayRemoved(final Overlay overlay) { // we just removed this overlay ? if (overlay == FlyCamOverlay.this) { stopThreads(); @@ -80,12 +92,12 @@ public class FlyCamOverlay extends Overlay { }; windowFocusListener = new WindowFocusListener() { @Override - public void windowLostFocus(WindowEvent e) { + public void windowLostFocus(final WindowEvent e) { keys.clear(); } @Override - public void windowGainedFocus(WindowEvent e) { + public void windowGainedFocus(final WindowEvent e) { // } }; @@ -100,7 +112,7 @@ public class FlyCamOverlay extends Overlay { } @Override - public void mouseMove(MouseEvent e, Point5D.Double imagePoint, IcyCanvas canvas) { + public void mouseMove(final MouseEvent e, final Point5D.Double imagePoint, final IcyCanvas canvas) { if (e.isConsumed()) return; @@ -120,22 +132,22 @@ public class FlyCamOverlay extends Overlay { // Test if should put back the cursor in the center. // This allows a smoother movement when approaching boarders. - Point eventLocation = e.getLocationOnScreen(); - Point locationPanel = panel.getLocationOnScreen(); - boolean aboutToTouchX = eventLocation.x <= locationPanel.x + 1 + final Point eventLocation = e.getLocationOnScreen(); + final Point locationPanel = panel.getLocationOnScreen(); + final boolean aboutToTouchX = eventLocation.x <= locationPanel.x + 1 || eventLocation.x >= locationPanel.x + panel.getWidth() - 1; - boolean aboutToTouchY = eventLocation.y <= locationPanel.y + 1 + final boolean aboutToTouchY = eventLocation.y <= locationPanel.y + 1 || eventLocation.y >= locationPanel.y + panel.getHeight() - 1; if (aboutToTouchX || aboutToTouchY) { // nearly touching borders try { - Robot robot = new Robot(); + final Robot robot = new Robot(); lastMouseX = -1; lastMouseY = -1; robot.mouseMove(locationPanel.x + (panel.getWidth() / 2), locationPanel.y + (panel.getHeight() / 2)); } - catch (AWTException e1) { + catch (final AWTException e1) { // } } @@ -148,7 +160,7 @@ public class FlyCamOverlay extends Overlay { } @Override - public void paint(Graphics2D g, Sequence sequence, IcyCanvas canvas) { + public void paint(final Graphics2D g, final Sequence sequence, final IcyCanvas canvas) { if (canvas instanceof VtkCanvas) { // update canvas if needed if (movementThread.canvas != canvas) @@ -162,7 +174,7 @@ public class FlyCamOverlay extends Overlay { } @Override - public void mouseClick(MouseEvent e, Point5D.Double imagePoint, IcyCanvas canvas) { + public void mouseClick(final MouseEvent e, final Point5D.Double imagePoint, final IcyCanvas canvas) { if (e.isConsumed()) return; @@ -191,7 +203,7 @@ public class FlyCamOverlay extends Overlay { } @Override - public void keyReleased(KeyEvent e, Point5D.Double imagePoint, IcyCanvas canvas) { + public void keyReleased(final KeyEvent e, final Point5D.Double imagePoint, final IcyCanvas canvas) { if (e.isConsumed()) return; @@ -213,23 +225,23 @@ public class FlyCamOverlay extends Overlay { // } @Override - public void mouseEntered(MouseEvent e, Point5D.Double imagePoint, IcyCanvas canvas) { + public void mouseEntered(final MouseEvent e, final Point5D.Double imagePoint, final IcyCanvas canvas) { lastMouseX = -1; lastMouseY = -1; } @Override - public void mouseExited(MouseEvent e, Point5D.Double imagePoint, IcyCanvas canvas) { + public void mouseExited(final MouseEvent e, final Point5D.Double imagePoint, final IcyCanvas canvas) { if (canvas instanceof VtkCanvas) { if (tracking_mouse) { final IcyVtkPanel panel = ((VtkCanvas) canvas).getVtkPanel(); final Point locationPanel = panel.getLocationOnScreen(); try { - Robot robot = new Robot(); + final Robot robot = new Robot(); robot.mouseMove(locationPanel.x + panel.getWidth() / 2, locationPanel.y + panel.getHeight() / 2); } - catch (AWTException e1) { + catch (final AWTException e1) { // } @@ -447,7 +459,7 @@ public class FlyCamOverlay extends Overlay { // } @Override - public void keyPressed(KeyEvent e, Point5D.Double imagePoint, IcyCanvas canvas) { + public void keyPressed(final KeyEvent e, final Point5D.Double imagePoint, final IcyCanvas canvas) { if (e.isConsumed()) return; @@ -476,13 +488,13 @@ public class FlyCamOverlay extends Overlay { // e.consume(); } - boolean isDown(int keycode) { + boolean isDown(final int keycode) { // System.out.println("isDown ? " + KeyEvent.getKeyText(keycode)); - Boolean res = keys.get(keycode); - return res != null && res.booleanValue(); + final Boolean res = keys.get(keycode); + return res != null && res; } - public void move(VtkCanvas canvas, MovementType moveType) { + public void move(final VtkCanvas canvas, final MovementType moveType) { final IcyVtkPanel vtkPanel = canvas.getVtkPanel(); switch (moveType) { @@ -544,7 +556,7 @@ public class FlyCamOverlay extends Overlay { /** * Set current camera position */ - public void setCameraPosition(CameraPosition cameraPos, boolean repaint) { + public void setCameraPosition(final CameraPosition cameraPos, final boolean repaint) { final VtkCanvas vtkCanvas = getCanvas(); if (vtkCanvas != null) { final IcyVtkPanel vtkPanel = vtkCanvas.getVtkPanel(); @@ -575,7 +587,7 @@ public class FlyCamOverlay extends Overlay { /** * Rotate world */ - public static void rotateWorld(VtkCanvas canvas, int dx, int dy, boolean repaint) { + public static void rotateWorld(final VtkCanvas canvas, final int dx, final int dy, final boolean repaint) { final IcyVtkPanel vtkPanel = canvas.getVtkPanel(); final vtkCamera camera = vtkPanel.getCamera(); @@ -602,7 +614,7 @@ public class FlyCamOverlay extends Overlay { VtkCanvas canvas; boolean run; - public MovementThread(VtkCanvas canvas) { + public MovementThread(final VtkCanvas canvas) { this.canvas = canvas; run = true; } diff --git a/src/main/java/plugins/tprovoost/flycam/FlyCamProps.java b/src/main/java/plugins/tprovoost/flycam/FlyCamProps.java index 5bcbb8f2cc779cf7f83416b925cc883864d6644b..456980784becec15a4519a98f2d458cbe25b01a0 100644 --- a/src/main/java/plugins/tprovoost/flycam/FlyCamProps.java +++ b/src/main/java/plugins/tprovoost/flycam/FlyCamProps.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2010-2023. Institut Pasteur. + * + * This file is part of Icy. + * Icy is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Icy is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Icy. If not, see <https://www.gnu.org/licenses/>. + */ + package plugins.tprovoost.flycam; import icy.gui.component.button.IcyButton; @@ -7,28 +25,15 @@ import icy.preferences.PluginsPreferences; import icy.preferences.XMLPreferences; import icy.sequence.Sequence; -import java.awt.BorderLayout; -import java.awt.Dimension; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.GridLayout; +import javax.swing.*; +import javax.swing.border.EmptyBorder; +import javax.swing.border.TitledBorder; +import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; -import javax.swing.BorderFactory; -import javax.swing.BoxLayout; -import javax.swing.JCheckBox; -import javax.swing.JDialog; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JSlider; -import javax.swing.JTextPane; -import javax.swing.SwingConstants; -import javax.swing.border.EmptyBorder; -import javax.swing.border.TitledBorder; - public class FlyCamProps extends IcyFrame implements ActionListener { private final XMLPreferences prefs = PluginsPreferences.root(FlyCam.class); @@ -89,11 +94,11 @@ public class FlyCamProps extends IcyFrame implements ActionListener { } private void initialize() { - JPanel mainPanel = new JPanel(); + final JPanel mainPanel = new JPanel(); mainPanel.setBorder(new EmptyBorder(4, 4, 4, 4)); mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); - JPanel panelOptions = new JPanel(); + final JPanel panelOptions = new JPanel(); panelOptions.setBorder(new TitledBorder(null, "Options", TitledBorder.LEADING, TitledBorder.TOP, null, null)); mainPanel.add(panelOptions); panelOptions.setLayout(new GridLayout(4, 1, 0, 0)); @@ -103,23 +108,23 @@ public class FlyCamProps extends IcyFrame implements ActionListener { cboxInvertY = new JCheckBox("Invert Y-Axis"); panelOptions.add(cboxInvertY); - JLabel lblSpeed = new JLabel("Speed: "); + final JLabel lblSpeed = new JLabel("Speed: "); panelOptions.add(lblSpeed); sliderSpeed = new JSlider(1, 100, 2); panelOptions.add(sliderSpeed); setContentPane(mainPanel); - JPanel panelKeys = new JPanel(); + final JPanel panelKeys = new JPanel(); panelKeys.setBorder(new TitledBorder(null, "Keys", TitledBorder.LEADING, TitledBorder.TOP, null, null)); mainPanel.add(panelKeys); panelKeys.setLayout(new GridLayout(6, 0, 0, 0)); - JPanel panelForward = new JPanel(); + final JPanel panelForward = new JPanel(); panelKeys.add(panelForward); panelForward.setLayout(new GridBagLayout()); - JLabel lblForward = new JLabel("Forward"); + final JLabel lblForward = new JLabel("Forward"); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; c.anchor = GridBagConstraints.WEST; @@ -138,11 +143,11 @@ public class FlyCamProps extends IcyFrame implements ActionListener { c.gridy = 0; panelForward.add(btnForward, c); - JPanel panelBackward = new JPanel(); + final JPanel panelBackward = new JPanel(); panelKeys.add(panelBackward); panelBackward.setLayout(new GridBagLayout()); - JLabel lblBackward = new JLabel("Backward"); + final JLabel lblBackward = new JLabel("Backward"); c = new GridBagConstraints(); c.weightx = 0.7; c.fill = GridBagConstraints.BOTH; @@ -161,11 +166,11 @@ public class FlyCamProps extends IcyFrame implements ActionListener { c.gridy = 0; panelBackward.add(btnBackward, c); - JPanel panelStrafeLeft = new JPanel(); + final JPanel panelStrafeLeft = new JPanel(); panelKeys.add(panelStrafeLeft); panelStrafeLeft.setLayout(new GridBagLayout()); - JLabel lblStrafeLeft = new JLabel("Strafe Left"); + final JLabel lblStrafeLeft = new JLabel("Strafe Left"); c = new GridBagConstraints(); c.weightx = 0.7; c.fill = GridBagConstraints.BOTH; @@ -184,11 +189,11 @@ public class FlyCamProps extends IcyFrame implements ActionListener { c.gridy = 0; panelStrafeLeft.add(btnStrafeLeft, c); - JPanel panelStrafeRight = new JPanel(); + final JPanel panelStrafeRight = new JPanel(); panelKeys.add(panelStrafeRight); panelStrafeRight.setLayout(new GridBagLayout()); - JLabel lblStrafeRight = new JLabel("Strafe Right"); + final JLabel lblStrafeRight = new JLabel("Strafe Right"); c = new GridBagConstraints(); c.weightx = 0.7; c.fill = GridBagConstraints.BOTH; @@ -207,11 +212,11 @@ public class FlyCamProps extends IcyFrame implements ActionListener { c.gridy = 0; panelStrafeRight.add(btnStrafeRight, c); - JPanel panelStrafeUp = new JPanel(); + final JPanel panelStrafeUp = new JPanel(); panelKeys.add(panelStrafeUp); panelStrafeUp.setLayout(new GridBagLayout()); - JLabel lblStrafeUp = new JLabel("Strafe Up"); + final JLabel lblStrafeUp = new JLabel("Strafe Up"); c = new GridBagConstraints(); c.weightx = 0.7; c.fill = GridBagConstraints.BOTH; @@ -230,11 +235,11 @@ public class FlyCamProps extends IcyFrame implements ActionListener { c.gridy = 0; panelStrafeUp.add(btnStrafeUp, c); - JPanel panelStrafeDown = new JPanel(); + final JPanel panelStrafeDown = new JPanel(); panelKeys.add(panelStrafeDown); panelStrafeDown.setLayout(new GridBagLayout()); - JLabel lblStrafeDown = new JLabel("Strafe Down"); + final JLabel lblStrafeDown = new JLabel("Strafe Down"); c = new GridBagConstraints(); c.weightx = 0.7; c.fill = GridBagConstraints.BOTH; @@ -253,7 +258,7 @@ public class FlyCamProps extends IcyFrame implements ActionListener { c.gridy = 0; panelStrafeDown.add(btnStrafeDown, c); - JPanel panel = new JPanel(); + final JPanel panel = new JPanel(); panel.setBorder(new TitledBorder(null, "Info", TitledBorder.LEADING, TitledBorder.TOP, null, null)); mainPanel.add(panel); panel.setLayout(new BorderLayout(0, 0)); @@ -281,45 +286,45 @@ public class FlyCamProps extends IcyFrame implements ActionListener { } @Override - public void actionPerformed(ActionEvent e) { - Object source = e.getSource(); + public void actionPerformed(final ActionEvent e) { + final Object source = e.getSource(); if (source == btnForward) { - int code = new InputDialog().res; + final int code = new InputDialog().res; if (code != -1 && code != KeyEvent.VK_ESCAPE) { keyForward = code; btnForward.setText(KeyEvent.getKeyText(code)); } } else if (source == btnBackward) { - int code = new InputDialog().res; + final int code = new InputDialog().res; if (code != -1 && code != KeyEvent.VK_ESCAPE) { keyBackward = code; btnBackward.setText(KeyEvent.getKeyText(code)); } } else if (source == btnStrafeLeft) { - int code = new InputDialog().res; + final int code = new InputDialog().res; if (code != -1 && code != KeyEvent.VK_ESCAPE) { keyStrafeLeft = code; btnStrafeLeft.setText(KeyEvent.getKeyText(code)); } } else if (source == btnStrafeRight) { - int code = new InputDialog().res; + final int code = new InputDialog().res; if (code != -1 && code != KeyEvent.VK_ESCAPE) { keyStrafeRight = code; btnStrafeRight.setText(KeyEvent.getKeyText(code)); } } else if (source == btnStrafeUp) { - int code = new InputDialog().res; + final int code = new InputDialog().res; if (code != -1 && code != KeyEvent.VK_ESCAPE) { keyStrafeUp = code; btnStrafeUp.setText(KeyEvent.getKeyText(code)); } } else if (source == btnStrafeDown) { - int code = new InputDialog().res; + final int code = new InputDialog().res; if (code != -1 && code != KeyEvent.VK_ESCAPE) { keyStrafeDown = code; btnStrafeDown.setText(KeyEvent.getKeyText(code)); @@ -382,8 +387,8 @@ public class FlyCamProps extends IcyFrame implements ActionListener { singleton = null; // remove all overlays from sequence - for (Sequence seq : Icy.getMainInterface().getSequences()) { - for (FlyCamOverlay overlay : seq.getOverlays(FlyCamOverlay.class)) { + for (final Sequence seq : Icy.getMainInterface().getSequences()) { + for (final FlyCamOverlay overlay : seq.getOverlays(FlyCamOverlay.class)) { // stop thread overlay.stopThreads(); // and remove overlay @@ -396,16 +401,16 @@ public class FlyCamProps extends IcyFrame implements ActionListener { int res = -1; public InputDialog() { - JPanel panel = new JPanel(); + final JPanel panel = new JPanel(); panel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); panel.setLayout(new BorderLayout()); - JLabel label = new JLabel("Please hit the key you want to use."); + final JLabel label = new JLabel("Please hit the key you want to use."); panel.add(label); setContentPane(panel); addKeyListener(new KeyAdapter() { @Override - public void keyPressed(KeyEvent e) { + public void keyPressed(final KeyEvent e) { res = e.getKeyCode(); setVisible(false); }