From 3fcc19c1fe887d871b0ccdb3baa7f96848c6e546 Mon Sep 17 00:00:00 2001 From: Thomas <thomas.musset@pasteur.fr> Date: Mon, 3 Jul 2023 15:00:21 +0200 Subject: [PATCH] updated pom, optimized code for java 11 --- pom.xml | 2 +- .../tprovoost/animation3d/Animation3D.java | 35 +++- .../tprovoost/animation3d/AnimationPanel.java | 130 +++++++------- .../tprovoost/animation3d/KeySlider.java | 112 ++++++------ .../tprovoost/animation3d/Kinematics3D.java | 166 ++++++++++-------- .../tprovoost/animation3d/TablePanel.java | 41 +++-- 6 files changed, 272 insertions(+), 214 deletions(-) diff --git a/pom.xml b/pom.xml index 74da832..48d7151 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ <!-- Project Information --> <artifactId>animation-3d</artifactId> - <version>1.3.2</version> + <version>2.0.0</version> <packaging>jar</packaging> diff --git a/src/main/java/plugins/tprovoost/animation3d/Animation3D.java b/src/main/java/plugins/tprovoost/animation3d/Animation3D.java index 26efb17..ffa02f7 100644 --- a/src/main/java/plugins/tprovoost/animation3d/Animation3D.java +++ b/src/main/java/plugins/tprovoost/animation3d/Animation3D.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.animation3d; import icy.gui.dialog.MessageDialog; @@ -7,18 +25,17 @@ import icy.plugin.PluginLauncher; import icy.plugin.abstract_.PluginActionable; import icy.sequence.Sequence; import icy.system.thread.ThreadUtil; - -import java.util.ArrayList; - import plugins.tprovoost.flycam.FlyCam; import plugins.tprovoost.flycam.FlyCamOverlay; +import java.util.ArrayList; + public class Animation3D extends PluginActionable { private Kinematics3D mainFrame; @Override public void run() { - Sequence seq = getActiveSequence(); + final Sequence seq = getActiveSequence(); if (seq == null) { MessageDialog.showDialog("You must have a sequence opened for this operation."); return; @@ -50,11 +67,11 @@ public class Animation3D extends PluginActionable { * @return Kinematics3D */ public static Kinematics3D getAnimation3D() { - ArrayList<IcyFrame> frames = IcyFrame.getAllFrames(Kinematics3D.class); + final ArrayList<IcyFrame> frames = IcyFrame.getAllFrames(Kinematics3D.class); if (frames.isEmpty()) { //Animation3D p = (Animation3D) PluginLauncher.start(Animation3D.class.getName()); - PluginDescriptor pd = new PluginDescriptor(Animation3D.class); - Animation3D p = (Animation3D) PluginLauncher.start(pd); + final PluginDescriptor pd = new PluginDescriptor(Animation3D.class); + final Animation3D p = (Animation3D) PluginLauncher.start(pd); return p.getKinematics3D(); } else @@ -68,8 +85,8 @@ public class Animation3D extends PluginActionable { * @param idx int * @return Kinematics3D */ - public static Kinematics3D getAnimation3D(int idx) { - ArrayList<IcyFrame> frames = IcyFrame.getAllFrames(Kinematics3D.class); + public static Kinematics3D getAnimation3D(final int idx) { + final ArrayList<IcyFrame> frames = IcyFrame.getAllFrames(Kinematics3D.class); if (frames.isEmpty()) { return null; } diff --git a/src/main/java/plugins/tprovoost/animation3d/AnimationPanel.java b/src/main/java/plugins/tprovoost/animation3d/AnimationPanel.java index 79fc08e..2bde59a 100644 --- a/src/main/java/plugins/tprovoost/animation3d/AnimationPanel.java +++ b/src/main/java/plugins/tprovoost/animation3d/AnimationPanel.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.animation3d; import icy.gui.component.button.IcyButton; @@ -6,38 +24,20 @@ import icy.preferences.XMLPreferences; import icy.preferences.XMLPreferences.XMLPreferencesRoot; import icy.resource.icon.IcyIcon; import icy.util.XMLUtil; +import org.w3c.dom.Element; +import plugins.tprovoost.flycam.CameraPosition; -import java.awt.Component; -import java.awt.Dimension; -import java.awt.GridLayout; -import java.awt.event.ActionListener; -import java.awt.event.ItemEvent; -import java.util.List; - -import javax.swing.BorderFactory; -import javax.swing.Box; -import javax.swing.BoxLayout; -import javax.swing.DefaultComboBoxModel; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JComboBox; -import javax.swing.JFileChooser; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JProgressBar; -import javax.swing.JTextField; -import javax.swing.SwingConstants; +import javax.swing.*; import javax.swing.border.EmptyBorder; import javax.swing.border.TitledBorder; import javax.swing.event.ChangeListener; import javax.swing.filechooser.FileNameExtensionFilter; - -import org.w3c.dom.Element; - -import plugins.tprovoost.flycam.CameraPosition; +import java.awt.*; +import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.util.List; public class AnimationPanel extends JPanel { - private static final long serialVersionUID = 1L; private static final String PREF_CAMERAS = "cameras"; private static final String PREF_CAM_LOCATION_DATA = "CamLocationData"; @@ -107,7 +107,7 @@ public class AnimationPanel extends JPanel { } } - public AnimationPanel(ActionListener actionListener, ChangeListener changeListener) { + public AnimationPanel(final ActionListener actionListener, final ChangeListener changeListener) { this.actionListener = actionListener; this.changeListener = changeListener; this.setPreferredSize(new Dimension(200, 465)); @@ -144,17 +144,17 @@ public class AnimationPanel extends JPanel { saveAnimation.setActionCommand("saveanimation"); saveAnimation.addActionListener(actionListener); - JPanel rescalePanel = new JPanel(); + final JPanel rescalePanel = new JPanel(); rescalePanel.setPreferredSize(new Dimension(300, 80)); rescalePanel.setBorder(BorderFactory.createTitledBorder("Rescale tool")); rescalePanel.setLayout(new BoxLayout(rescalePanel, BoxLayout.Y_AXIS)); - JPanel panel_1 = new JPanel(); + final JPanel panel_1 = new JPanel(); panel_1.setBorder(new EmptyBorder(4, 4, 4, 4)); rescalePanel.add(panel_1); panel_1.setLayout(new GridLayout(0, 2, 0, 0)); - JLabel label = new JLabel("FPS:"); + final JLabel label = new JLabel("FPS:"); panel_1.add(label); rescaleFPS = new JTextField(); @@ -162,17 +162,17 @@ public class AnimationPanel extends JPanel { rescaleFPS.setPreferredSize(new Dimension(30, 20)); rescaleFPS.setText(String.valueOf(getTimeSlider().getFps())); - JPanel panel_2 = new JPanel(); + final JPanel panel_2 = new JPanel(); panel_2.setBorder(new EmptyBorder(4, 4, 4, 4)); rescalePanel.add(panel_2); panel_2.setLayout(new GridLayout(0, 2, 0, 0)); - JLabel label_1 = new JLabel("Seconds :"); + final JLabel label_1 = new JLabel("Seconds :"); panel_2.add(label_1); rescaleTime = new JTextField("5"); panel_2.add(rescaleTime); rescaleTime.setPreferredSize(new Dimension(30, 20)); - JPanel panelRescaleButton = new JPanel(); + final JPanel panelRescaleButton = new JPanel(); rescalePanel.add(panelRescaleButton); panelRescaleButton.setLayout(new BoxLayout(panelRescaleButton, BoxLayout.X_AXIS)); @@ -185,7 +185,7 @@ public class AnimationPanel extends JPanel { panelRescaleButton.add(Box.createHorizontalGlue()); rescale.addActionListener(actionListener); - JPanel smoothingPanel = new JPanel(); + final JPanel smoothingPanel = new JPanel(); smoothingPanel.setBorder(BorderFactory.createTitledBorder("Smooth Camera path")); smoothingPanel.setLayout(new GridLayout(0, 2, 0, 0)); smoothingPanel.add(new JLabel("Smooth factor: ")); @@ -193,7 +193,7 @@ public class AnimationPanel extends JPanel { getSmoothpathfactor().setPreferredSize(new Dimension(190, 20)); smoothingPanel.add(getSmoothpathfactor()); - JPanel p8 = new JPanel(); + final JPanel p8 = new JPanel(); p8.setBorder(BorderFactory.createTitledBorder("Record")); p8.setLayout(new GridLayout(4, 1)); @@ -235,33 +235,33 @@ public class AnimationPanel extends JPanel { }); - JPanel panelLoadSave = new JPanel(); + final JPanel panelLoadSave = new JPanel(); add(panelLoadSave); panelLoadSave.setLayout(new GridLayout(1, 0, 0, 0)); - JButton btnLoad = new JButton("Load"); + final JButton btnLoad = new JButton("Load"); btnLoad.addActionListener(e -> { - String filename = animFileChooser(); + final String filename = animFileChooser(); if (filename == null) return; - XMLPreferencesRoot root = new XMLPreferencesRoot(filename); + final XMLPreferencesRoot root = new XMLPreferencesRoot(filename); loadXMLFile(root.getPreferences()); }); panelLoadSave.add(btnLoad); - JButton btnSave = new JButton("Save"); + final JButton btnSave = new JButton("Save"); btnSave.addActionListener(e -> { - String filename = animFileChooser(); + final String filename = animFileChooser(); if (filename == null) return; - XMLPreferencesRoot root = new XMLPreferencesRoot(filename); + final XMLPreferencesRoot root = new XMLPreferencesRoot(filename); saveToXML(root.getPreferences()); root.save(); }); panelLoadSave.add(btnSave); // add(comboPresets); // TODO - JPanel panel = new JPanel(); + final JPanel panel = new JPanel(); add(panel); playForward = new IcyButton(new IcyIcon("sq_next.png")); @@ -273,7 +273,7 @@ public class AnimationPanel extends JPanel { previousFrame.addActionListener(actionListener); panel.setLayout(new GridLayout(0, 2, 0, 0)); - JPanel p1 = new JPanel(); + final JPanel p1 = new JPanel(); p1.setBorder(new TitledBorder(null, "Frames", TitledBorder.LEADING, TitledBorder.TOP, null, null)); panel.add(p1); p1.setPreferredSize(new Dimension(200, 50)); @@ -322,7 +322,7 @@ public class AnimationPanel extends JPanel { resetKey.setActionCommand("resetkey"); resetKey.addActionListener(actionListener); - JPanel keyPanel = new JPanel(); + final JPanel keyPanel = new JPanel(); panel.add(keyPanel); keyPanel.setLayout(new GridLayout(2, 3)); keyPanel.setBorder(BorderFactory.createTitledBorder("Keys")); @@ -372,11 +372,11 @@ public class AnimationPanel extends JPanel { timeSlider = null; } - public void setEnabledRecursive(JPanel parent, boolean enabled) { + public void setEnabledRecursive(final JPanel parent, final boolean enabled) { parent.setEnabled(enabled); - Component[] components = parent.getComponents(); + final Component[] components = parent.getComponents(); if (components != null) { - for (Component component : components) { + for (final Component component : components) { component.setEnabled(enabled); if (component.getClass().getName().equals("javax.swing.JPanel")) { setEnabledRecursive((JPanel) component, enabled); @@ -395,7 +395,7 @@ public class AnimationPanel extends JPanel { /** * @param timeSlider the timeSlider to set */ - public void setTimeSlider(KeySlider timeSlider) { + public void setTimeSlider(final KeySlider timeSlider) { this.timeSlider = timeSlider; } @@ -409,7 +409,7 @@ public class AnimationPanel extends JPanel { /** * @param stop the stop to set */ - public void setStop(IcyButton stop) { + public void setStop(final IcyButton stop) { this.stop = stop; } @@ -423,7 +423,7 @@ public class AnimationPanel extends JPanel { /** * @param smoothPathFactor the smoothpathfactor to set */ - public void setSmoothpathfactor(JTextField smoothPathFactor) { + public void setSmoothpathfactor(final JTextField smoothPathFactor) { this.smoothPathFactor = smoothPathFactor; } @@ -437,7 +437,7 @@ public class AnimationPanel extends JPanel { /** * @param recordProgressBar the recordProgressBar to set */ - public void setRecordProgressBar(JProgressBar recordProgressBar) { + public void setRecordProgressBar(final JProgressBar recordProgressBar) { this.recordProgressBar = recordProgressBar; } @@ -451,7 +451,7 @@ public class AnimationPanel extends JPanel { /** * @param playForward the playforward to set */ - public void setPlayforward(IcyButton playForward) { + public void setPlayforward(final IcyButton playForward) { this.playForward = playForward; } @@ -465,7 +465,7 @@ public class AnimationPanel extends JPanel { /** * @param rescaleFPS the rescalefps to set */ - public void setRescalefps(JTextField rescaleFPS) { + public void setRescalefps(final JTextField rescaleFPS) { this.rescaleFPS = rescaleFPS; } @@ -479,7 +479,7 @@ public class AnimationPanel extends JPanel { /** * @param rescaleTime the rescaletime to set */ - public void setRescaletime(JTextField rescaleTime) { + public void setRescaletime(final JTextField rescaleTime) { this.rescaleTime = rescaleTime; } @@ -493,7 +493,7 @@ public class AnimationPanel extends JPanel { /** * @param checkBoxAutoUpdate the checkBoxAutoUpdate to set */ - public void setCheckBoxAutoUpdate(JCheckBox checkBoxAutoUpdate) { + public void setCheckBoxAutoUpdate(final JCheckBox checkBoxAutoUpdate) { this.checkBoxAutoUpdate = checkBoxAutoUpdate; } @@ -512,9 +512,9 @@ public class AnimationPanel extends JPanel { */ private String animFileChooser() { String filename = null; - JFileChooser fc = new JFileChooser(); + final JFileChooser fc = new JFileChooser(); fc.setFileFilter(new FileNameExtensionFilter("Animation Files (.anim)", "anim")); - int returnVal = fc.showDialog(Icy.getMainInterface().getMainFrame(), "Save File"); + final int returnVal = fc.showDialog(Icy.getMainInterface().getMainFrame(), "Save File"); if (returnVal == JFileChooser.APPROVE_OPTION) { filename = fc.getSelectedFile().getAbsolutePath(); if (!filename.endsWith(".anim")) @@ -529,10 +529,10 @@ public class AnimationPanel extends JPanel { * * @param root : file and node where data is saved. */ - private void saveToXML(XMLPreferences root) { + private void saveToXML(final XMLPreferences root) { root.removeChildren(); - XMLPreferences cameras = root.node(PREF_CAMERAS); + final XMLPreferences cameras = root.node(PREF_CAMERAS); cameras.removeChildren(); root.put(PREF_FPS, rescaleFPS.getText()); @@ -540,7 +540,7 @@ public class AnimationPanel extends JPanel { root.put(PREF_SMOOTH, smoothPathFactor.getText()); // save camera positions into XML - for (CameraPosition cam : timeSlider.getCameraPositions()) + for (final CameraPosition cam : timeSlider.getCameraPositions()) cam.saveCamera(XMLUtil.addElement(cameras.getXMLNode(), PREF_CAM_LOCATION_DATA)); } @@ -549,19 +549,19 @@ public class AnimationPanel extends JPanel { * * @param root : file and node where data is saved. */ - private void loadXMLFile(XMLPreferences root) { + private void loadXMLFile(final XMLPreferences root) { if (!root.nodeExists(PREF_CAMERAS)) return; rescaleFPS.setText(root.get(PREF_FPS, "15")); rescaleTime.setText(root.get(PREF_TIME, "5")); smoothPathFactor.setText(root.get(PREF_SMOOTH, "0")); - XMLPreferences cameras = root.node(PREF_CAMERAS); + final XMLPreferences cameras = root.node(PREF_CAMERAS); - List<CameraPosition> cams = timeSlider.getCameraPositions(); + final List<CameraPosition> cams = timeSlider.getCameraPositions(); cams.clear(); - for (Element e : XMLUtil.getElements(cameras.getXMLNode(), PREF_CAM_LOCATION_DATA)) { - CameraPosition cam = new CameraPosition(); + for (final Element e : XMLUtil.getElements(cameras.getXMLNode(), PREF_CAM_LOCATION_DATA)) { + final CameraPosition cam = new CameraPosition(); cam.loadCamera(e); cams.add(cam); } diff --git a/src/main/java/plugins/tprovoost/animation3d/KeySlider.java b/src/main/java/plugins/tprovoost/animation3d/KeySlider.java index 8b2f0cd..e59fbb3 100644 --- a/src/main/java/plugins/tprovoost/animation3d/KeySlider.java +++ b/src/main/java/plugins/tprovoost/animation3d/KeySlider.java @@ -1,24 +1,34 @@ +/* + * 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.animation3d; -import java.awt.Color; -import java.awt.FontMetrics; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.Insets; -import java.awt.Point; -import java.awt.Rectangle; +import plugins.tprovoost.flycam.CameraPosition; + +import javax.swing.*; +import java.awt.*; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import java.util.ArrayList; import java.util.List; -import javax.swing.JSlider; - -import plugins.tprovoost.flycam.CameraPosition; - public class KeySlider extends JSlider implements MouseListener, MouseMotionListener { - private static final long serialVersionUID = 1L; // private ArrayList<Integer> key = new ArrayList<>(); private int fps = 15; private int timelength; @@ -26,7 +36,7 @@ public class KeySlider extends JSlider implements MouseListener, MouseMotionList private CameraPosition currentCamera; private List<CameraPosition> cameraPositions = new ArrayList<>(); - public KeySlider(int min, int max, int value) { + public KeySlider(final int min, final int max, final int value) { super(min, max, value); setPaintTicks(true); setPaintLabels(true); @@ -35,21 +45,21 @@ public class KeySlider extends JSlider implements MouseListener, MouseMotionList } @Override - protected void paintComponent(Graphics g) { + protected void paintComponent(final Graphics g) { super.paintComponent(g); - Insets ins = getInsets(); - int w = getWidth(); - int h = getHeight(); - Graphics2D g2 = (Graphics2D) g.create(); + final Insets ins = getInsets(); + final int w = getWidth(); + final int h = getHeight(); + final Graphics2D g2 = (Graphics2D) g.create(); // g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, // RenderingHints.VALUE_ANTIALIAS_ON); // g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // display red keys in component. g2.setColor(new Color(210, 27, 58)); - for (CameraPosition cam : cameraPositions) { - float step = ((w - 31) / (float) getMaximum()); - int positionX = Math.round(ins.left + 11 + cam.timeIndex * step); + for (final CameraPosition cam : cameraPositions) { + final float step = ((w - 31) / (float) getMaximum()); + final int positionX = Math.round(ins.left + 11 + cam.timeIndex * step); g2.fillRect(positionX - 1, h - 12, 3, 6); } // // display Seconds:Frame. @@ -58,15 +68,15 @@ public class KeySlider extends JSlider implements MouseListener, MouseMotionList g2.dispose(); } - private String timeFormat(int t) { - String modulo; + private String timeFormat(final int t) { + final String modulo; if (t % getFps() < 10) { modulo = "0" + t % getFps(); } else { modulo = String.valueOf(t % getFps()); } - String SecondFrame; + final String SecondFrame; SecondFrame = (t / getFps()) + ":" + modulo + "0"; return SecondFrame; } @@ -76,10 +86,10 @@ public class KeySlider extends JSlider implements MouseListener, MouseMotionList * @param s * @param v Tick corresponding to the center of the string. */ - private void drawCenteredString(Graphics g, String s, int v, int y, boolean ShowTick) { - FontMetrics metrics = getFontMetrics(g.getFont()); - float step = ((getWidth() - 16.0f) / (float) getMaximum()); - int positionX = Math.round(6 + v * step); + private void drawCenteredString(final Graphics g, final String s, final int v, final int y, final boolean ShowTick) { + final FontMetrics metrics = getFontMetrics(g.getFont()); + final float step = ((getWidth() - 16.0f) / (float) getMaximum()); + final int positionX = Math.round(6 + v * step); g.drawString(s, positionX - metrics.stringWidth(s) / 2, y); if (ShowTick) g.drawLine(positionX, 35, positionX, 30); @@ -118,7 +128,7 @@ public class KeySlider extends JSlider implements MouseListener, MouseMotionList /** * @param timelength the timelength to set */ - public void setTimelength(int timelength) { + public void setTimelength(final int timelength) { this.timelength = timelength; } @@ -132,12 +142,12 @@ public class KeySlider extends JSlider implements MouseListener, MouseMotionList /** * @param fps the fps to set */ - public void setFps(int fps) { + public void setFps(final int fps) { this.fps = fps; } @Override - public void setMaximum(int maximum) { + public void setMaximum(final int maximum) { super.setMaximum(maximum); if (maximum < 5) { setMinorTickSpacing(maximum); @@ -151,11 +161,11 @@ public class KeySlider extends JSlider implements MouseListener, MouseMotionList } @Override - public void mouseDragged(MouseEvent e) { + public void mouseDragged(final MouseEvent e) { if (currentPoint != null && currentCamera != null) { - int xmov = e.getPoint().x - currentPoint.x; - int max = getMaximum(); - float step = (getWidth()) / (float) max; + final int xmov = e.getPoint().x - currentPoint.x; + final int max = getMaximum(); + final float step = (getWidth()) / (float) max; int timeIndex = (int) (e.getPoint().x / step); if (timeIndex == 0) { @@ -179,8 +189,8 @@ public class KeySlider extends JSlider implements MouseListener, MouseMotionList repaint(); } - private boolean cameraExists(int timeIndex) { - for (CameraPosition cam : cameraPositions) { + private boolean cameraExists(final int timeIndex) { + for (final CameraPosition cam : cameraPositions) { if (cam.timeIndex == timeIndex) return true; } @@ -188,22 +198,22 @@ public class KeySlider extends JSlider implements MouseListener, MouseMotionList } @Override - public void mouseMoved(MouseEvent e) { + public void mouseMoved(final MouseEvent e) { } @Override - public void mouseClicked(MouseEvent e) { + public void mouseClicked(final MouseEvent e) { } @Override - public void mousePressed(MouseEvent e) { - Insets ins = getInsets(); - int w = getWidth(); - int h = getHeight(); - for (CameraPosition cam : cameraPositions) { - float step = ((w - 31) / (float) getMaximum()); - int positionx = Math.round(ins.left + 11 + cam.timeIndex * step); - Rectangle rect = new Rectangle(positionx - 1, h - 12, 3, 6); + public void mousePressed(final MouseEvent e) { + final Insets ins = getInsets(); + final int w = getWidth(); + final int h = getHeight(); + for (final CameraPosition cam : cameraPositions) { + final float step = ((w - 31) / (float) getMaximum()); + final int positionx = Math.round(ins.left + 11 + cam.timeIndex * step); + final Rectangle rect = new Rectangle(positionx - 1, h - 12, 3, 6); if (rect.contains(e.getPoint())) { currentCamera = cam; currentPoint = e.getPoint(); @@ -213,20 +223,20 @@ public class KeySlider extends JSlider implements MouseListener, MouseMotionList } @Override - public void mouseReleased(MouseEvent e) { + public void mouseReleased(final MouseEvent e) { currentCamera = null; currentPoint = e.getPoint(); } @Override - public void mouseEntered(MouseEvent e) { + public void mouseEntered(final MouseEvent e) { } @Override - public void mouseExited(MouseEvent e) { + public void mouseExited(final MouseEvent e) { } - public void setCameraPositions(List<CameraPosition> value) { + public void setCameraPositions(final List<CameraPosition> value) { cameraPositions = value; } diff --git a/src/main/java/plugins/tprovoost/animation3d/Kinematics3D.java b/src/main/java/plugins/tprovoost/animation3d/Kinematics3D.java index 1894e3b..2ddf765 100644 --- a/src/main/java/plugins/tprovoost/animation3d/Kinematics3D.java +++ b/src/main/java/plugins/tprovoost/animation3d/Kinematics3D.java @@ -1,5 +1,29 @@ +/* + * 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.animation3d; +import com.xuggle.mediatool.IMediaWriter; +import com.xuggle.mediatool.ToolFactory; +import com.xuggle.xuggler.ICodec; +import com.xuggle.xuggler.IPixelFormat; +import com.xuggle.xuggler.IRational; +import com.xuggle.xuggler.IStreamCoder; import icy.file.FileUtil; import icy.gui.dialog.MessageDialog; import icy.gui.frame.IcyFrame; @@ -8,8 +32,15 @@ import icy.main.Icy; import icy.preferences.PluginsPreferences; import icy.preferences.XMLPreferences; import icy.system.thread.ThreadUtil; +import plugins.kernel.canvas.VtkCanvas; +import plugins.tprovoost.flycam.CameraPosition; +import plugins.tprovoost.flycam.FlyCamOverlay; -import java.awt.BorderLayout; +import javax.swing.*; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import javax.swing.filechooser.FileNameExtensionFilter; +import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.image.BufferedImage; @@ -18,24 +49,6 @@ import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; -import javax.swing.JFileChooser; -import javax.swing.JPanel; -import javax.swing.JSlider; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; -import javax.swing.filechooser.FileNameExtensionFilter; - -import plugins.kernel.canvas.VtkCanvas; -import plugins.tprovoost.flycam.CameraPosition; -import plugins.tprovoost.flycam.FlyCamOverlay; - -import com.xuggle.mediatool.IMediaWriter; -import com.xuggle.mediatool.ToolFactory; -import com.xuggle.xuggler.ICodec; -import com.xuggle.xuggler.IPixelFormat; -import com.xuggle.xuggler.IRational; -import com.xuggle.xuggler.IStreamCoder; - public class Kinematics3D extends IcyFrame { private static final String LAST_DIR = "last_directory"; private final XMLPreferences prefs = PluginsPreferences.root(Animation3D.class); @@ -49,7 +62,7 @@ public class Kinematics3D extends IcyFrame { private FlyCamOverlay flyCam; private KinematicsThread kinemAnim; - public Kinematics3D(FlyCamOverlay flyCam) { + public Kinematics3D(final FlyCamOverlay flyCam) { super("Animation 3D", true); cameraPositions = new ArrayList<>(); @@ -75,12 +88,12 @@ public class Kinematics3D extends IcyFrame { return cameraPositions; } - public void setCameraPositions(List<CameraPosition> value) { + public void setCameraPositions(final List<CameraPosition> value) { if (value != null) cameraPositions = value; } - public void seekAndDestroyKeyAt(int t) { + public void seekAndDestroyKeyAt(final int t) { synchronized (cameraPositions) { for (int i = cameraPositions.size() - 1; i >= 0; i--) { if (cameraPositions.get(i).timeIndex == t) @@ -121,7 +134,7 @@ public class Kinematics3D extends IcyFrame { * @param CreateKeyIfDoNotExists boolean * @return Get Previous Key <=t. */ - public CameraPosition getPreviousFlyCamKey(int t, boolean CreateKeyIfDoNotExists) { + public CameraPosition getPreviousFlyCamKey(int t, final boolean CreateKeyIfDoNotExists) { if (t < 0) t = 0; @@ -129,7 +142,7 @@ public class Kinematics3D extends IcyFrame { int previousbest = animPanel.getTimeSlider().getMaximum(); // find previous - for (CameraPosition camPos : getCameraPositions()) { + for (final CameraPosition camPos : getCameraPositions()) { // if (povk.CameraType == canvas.getCameraType()) if (camPos.timeIndex <= t) { if ((t - camPos.timeIndex) < previousbest) { @@ -150,7 +163,7 @@ public class Kinematics3D extends IcyFrame { * @param CreateKeyIfDoNotExists boolean * @return Get Previous Key >=t. */ - public CameraPosition getNextFlyCamKey(int t, boolean CreateKeyIfDoNotExists) { + public CameraPosition getNextFlyCamKey(int t, final boolean CreateKeyIfDoNotExists) { if (t > animPanel.getTimeSlider().getMaximum()) t = animPanel.getTimeSlider().getMaximum(); @@ -158,7 +171,7 @@ public class Kinematics3D extends IcyFrame { int nextbest = animPanel.getTimeSlider().getMaximum(); // find best - for (CameraPosition camPos : getCameraPositions()) { + for (final CameraPosition camPos : getCameraPositions()) { // if (povk.CameraType == canvas.getCameraType()) if (camPos.timeIndex >= t) { if ((camPos.timeIndex - t) < nextbest) { @@ -179,13 +192,13 @@ public class Kinematics3D extends IcyFrame { * @param smooth int * @return CameraPosition */ - public CameraPosition computeSmoothInterpolatedCamKey(int t, int smooth) { - CameraPosition cumul = new CameraPosition(); + public CameraPosition computeSmoothInterpolatedCamKey(final int t, final int smooth) { + final CameraPosition cumul = new CameraPosition(); int iter = 0; for (int i = t - smooth; i <= t + smooth; i++) { iter++; - CameraPosition tmppovd = computeInterpolatedCamKey(i); + final CameraPosition tmppovd = computeInterpolatedCamKey(i); for (int j = 0; j < 3; j++) { cumul.position[j] += tmppovd.position[j]; cumul.focal[j] += tmppovd.focal[j]; @@ -210,11 +223,11 @@ public class Kinematics3D extends IcyFrame { * @param t Time index in animation's sequence ( frame # ) * @return Interpolated FlyCamKey as CamPointOfViewData */ - public CameraPosition computeInterpolatedCamKey(int t) { - CameraPosition povd = new CameraPosition(); - CameraPosition step = new CameraPosition(); - CameraPosition Previous = getPreviousFlyCamKey(t, true); - CameraPosition Next = getNextFlyCamKey(t, true); + public CameraPosition computeInterpolatedCamKey(final int t) { + final CameraPosition povd = new CameraPosition(); + final CameraPosition step = new CameraPosition(); + final CameraPosition Previous = getPreviousFlyCamKey(t, true); + final CameraPosition Next = getNextFlyCamKey(t, true); if (Previous.timeIndex == Next.timeIndex) return Previous; // We are on the key. No need to interpolate. @@ -261,7 +274,7 @@ public class Kinematics3D extends IcyFrame { public void refreshAnimPanel() { // Put new computed key in Animation's Slider. // animPanel.getTimeSlider().removeAllKey(); - for (CameraPosition camPos : getCameraPositions()) { + for (final CameraPosition camPos : getCameraPositions()) { // CameraPosition povk = e.nextElement(); // if (canvas.getCameraType() == povk.CameraType) // animPanel.getTimeSlider().addKey(povk.timeIndex); @@ -280,7 +293,7 @@ public class Kinematics3D extends IcyFrame { * @param cam CameraPosition * @param pos int */ - public void addKey(CameraPosition cam, int pos) { + public void addKey(final CameraPosition cam, final int pos) { kinematicPanel.addKey(pos); } @@ -294,7 +307,7 @@ public class Kinematics3D extends IcyFrame { * * @param kine Kinematics3D */ - public PanelKinematics(Kinematics3D kine) { + public PanelKinematics(final Kinematics3D kine) { kinemAnim = new KinematicsThread(); createPanel(); } @@ -313,7 +326,7 @@ public class Kinematics3D extends IcyFrame { /** * Get the panel to be used in the GUI for the list of marching cube. - * Build it on the first time. + * Build it for the first time. * * @return the panel to be used */ @@ -325,11 +338,11 @@ public class Kinematics3D extends IcyFrame { return panel; } - public void addKey(int t) { + public void addKey(final int t) { addKey(null, t); } - public void addKey(CameraPosition cam, int t) { + public void addKey(CameraPosition cam, final int t) { seekAndDestroyKeyAt(t); // Sequence s = canvas.getSequence(); @@ -346,9 +359,10 @@ public class Kinematics3D extends IcyFrame { } - public void actionPerformed(ActionEvent event) { + @Override + public void actionPerformed(final ActionEvent event) { - String action = event.getActionCommand(); + final String action = event.getActionCommand(); if (action.equals("gotostart")) { animPanel.getTimeSlider().setValue(0); @@ -359,8 +373,8 @@ public class Kinematics3D extends IcyFrame { } //if (action.equals("playbackward")) { - // AnimPanel.getTimeSlider().setValue( - // AnimPanel.getTimeSlider().getMaximum() ); + // AnimPanel.getTimeSlider().setValue( + // AnimPanel.getTimeSlider().getMaximum() ); //} if (action.equals("playforward")) { @@ -423,14 +437,14 @@ public class Kinematics3D extends IcyFrame { fc.addChoosableFileFilter(new FileNameExtensionFilter("MP4 Files", "mp4", "MP4")); fc.addChoosableFileFilter(new FileNameExtensionFilter("MOV Files", "mov", "MOV")); fc.setMultiSelectionEnabled(false); - int res = fc.showSaveDialog(Icy.getMainInterface().getMainFrame()); + final int res = fc.showSaveDialog(Icy.getMainInterface().getMainFrame()); if (res == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); if (file == null) return; prefs.put(LAST_DIR, file.getParent()); if (FileUtil.getFileExtension(file.getAbsolutePath(), false).isEmpty()) { - String desc = fc.getFileFilter().getDescription(); + final String desc = fc.getFileFilter().getDescription(); if (desc.contentEquals("MP4 Files")) file = new File(file.getAbsoluteFile() + ".mp4"); else if (desc.contentEquals("MOV Files")) @@ -444,7 +458,7 @@ public class Kinematics3D extends IcyFrame { } if (action.equals("previouskey")) { - CameraPosition previous = getPreviousFlyCamKey(animPanel.getTimeSlider().getValue() - 1, false); + final CameraPosition previous = getPreviousFlyCamKey(animPanel.getTimeSlider().getValue() - 1, false); if (previous != null) { animPanel.getTimeSlider().setValue(previous.timeIndex); flyCam.setCameraPosition(previous, true); @@ -452,7 +466,7 @@ public class Kinematics3D extends IcyFrame { } if (action.equals("nextkey")) { - CameraPosition next = getNextFlyCamKey(animPanel.getTimeSlider().getValue() + 1, false); + final CameraPosition next = getNextFlyCamKey(animPanel.getTimeSlider().getValue() + 1, false); if (next != null) { animPanel.getTimeSlider().setValue(next.timeIndex); flyCam.setCameraPosition(next, true); @@ -461,7 +475,7 @@ public class Kinematics3D extends IcyFrame { if (action.equals("removekey")) { if (getNumberOfUserKey() > 1) { - int t = animPanel.getTimeSlider().getValue(); + final int t = animPanel.getTimeSlider().getValue(); seekAndDestroyKeyAt(t); // animPanel.getTimeSlider().removeKey(t); } @@ -473,7 +487,7 @@ public class Kinematics3D extends IcyFrame { if (action.equals("addkey")) { // Destroy potential key at time t. - int t = animPanel.getTimeSlider().getValue(); + final int t = animPanel.getTimeSlider().getValue(); // animPanel.getTimeSlider().removeKey(t); // same for time // slider addKey(t); @@ -561,13 +575,14 @@ public class Kinematics3D extends IcyFrame { } - public void stateChanged(ChangeEvent e) { + @Override + public void stateChanged(final ChangeEvent e) { // Listening to Animation's Panel TimeSlider. if (animPanel.getCheckBoxAutoUpdate().isSelected() || (kinemAnim != null && !kinemAnim.stop)) { if (getNumberOfUserKey() == 0) addKey(0); // Prevent system from having no key to read at // all - JSlider slider = (JSlider) e.getSource(); + final JSlider slider = (JSlider) e.getSource(); CameraPosition d = new CameraPosition(); d = computeSmoothInterpolatedCamKey(slider.getValue(), Integer.parseInt(animPanel.getSmoothpathfactor().getText())); @@ -580,15 +595,15 @@ public class Kinematics3D extends IcyFrame { } - public void actionPerformed(ActionEvent e) { + public void actionPerformed(final ActionEvent e) { } public void rescaleTimeLine() { - int oldfps = animPanel.getTimeSlider().getFps(); - int oldlength = animPanel.getTimeSlider().getTimelength(); - int newfps = Integer.parseInt(animPanel.getRescalefps().getText()); - int newlength = Integer.parseInt(animPanel.getRescaletime().getText()); + final int oldfps = animPanel.getTimeSlider().getFps(); + final int oldlength = animPanel.getTimeSlider().getTimelength(); + final int newfps = Integer.parseInt(animPanel.getRescalefps().getText()); + final int newlength = Integer.parseInt(animPanel.getRescaletime().getText()); animPanel.getTimeSlider().setFps(newfps); animPanel.getTimeSlider().setTimelength(newlength); @@ -600,7 +615,7 @@ public class Kinematics3D extends IcyFrame { // change towards length double timeratio = newlength / (double) oldlength; timeratio *= newfps / (double) oldfps; - for (CameraPosition cam : getCameraPositions()) + for (final CameraPosition cam : getCameraPositions()) cam.timeIndex *= timeratio; animPanel.getTimeSlider().setValue((int) (animPanel.getTimeSlider().getValue() * timeratio)); @@ -624,14 +639,14 @@ public class Kinematics3D extends IcyFrame { */ @Override public void run() { - int idx = animPanel.getTimeSlider().getValue(); - int size = animPanel.getTimeSlider().getTimelength(); - int fps = animPanel.getTimeSlider().getFps(); + //int idx = animPanel.getTimeSlider().getValue(); + //int size = animPanel.getTimeSlider().getTimelength(); + //int fps = animPanel.getTimeSlider().getFps(); // long time = 0; - idx = animPanel.getTimeSlider().getValue(); - size = animPanel.getTimeSlider().getTimelength() * animPanel.getTimeSlider().getFps(); - fps = animPanel.getTimeSlider().getFps(); + int idx = animPanel.getTimeSlider().getValue(); + final int size = animPanel.getTimeSlider().getTimelength() * animPanel.getTimeSlider().getFps(); + final int fps = animPanel.getTimeSlider().getFps(); // time = System.nanoTime(); while (!stop) { @@ -665,7 +680,7 @@ public class Kinematics3D extends IcyFrame { private boolean recording; private final File f; - public Recorder(File f) { + public Recorder(final File f) { this.f = f; } @@ -676,17 +691,17 @@ public class Kinematics3D extends IcyFrame { if (canvas == null) return; - int width = canvas.getVtkPanel().getWidth(); - int height = canvas.getVtkPanel().getHeight(); - int fps = Integer.valueOf(animPanel.getRescalefps().getText()); + final int width = canvas.getVtkPanel().getWidth(); + final int height = canvas.getVtkPanel().getHeight(); + final int fps = Integer.parseInt(animPanel.getRescalefps().getText()); - IRational frameRate = IRational.make(fps, 1); - IMediaWriter writer = ToolFactory.makeWriter(f.getAbsolutePath()); + final IRational frameRate = IRational.make(fps, 1); + final IMediaWriter writer = ToolFactory.makeWriter(f.getAbsolutePath()); writer.addVideoStream(0, 0, frameRate, width, height); - String ext = FileUtil.getFileExtension(f.getAbsolutePath(), false).toLowerCase(); + final String ext = FileUtil.getFileExtension(f.getAbsolutePath(), false).toLowerCase(); if (ext.contentEquals("mp4") || ext.contentEquals("mov")) { - IStreamCoder coder = writer.getContainer().getStream(0).getStreamCoder(); + final IStreamCoder coder = writer.getContainer().getStream(0).getStreamCoder(); coder.setCodec(ICodec.ID.CODEC_ID_H264); coder.setPixelType(IPixelFormat.Type.YUV422P); } @@ -719,8 +734,8 @@ public class Kinematics3D extends IcyFrame { // set camera position flyCam.setCameraPosition(d, false); - BufferedImage originalImage = canvas.getRenderedImage(sequenceT, -1); - BufferedImage worksWithXugglerBufferedImage = ImageUtil.convert(originalImage, new BufferedImage( + final BufferedImage originalImage = canvas.getRenderedImage(sequenceT, -1); + final BufferedImage worksWithXugglerBufferedImage = ImageUtil.convert(originalImage, new BufferedImage( originalImage.getWidth(), originalImage.getHeight(), BufferedImage.TYPE_3BYTE_BGR)); writer.encodeVideo(0, worksWithXugglerBufferedImage, nextTimeStamp, TimeUnit.MICROSECONDS); @@ -745,6 +760,7 @@ public class Kinematics3D extends IcyFrame { getCameraPositions().clear(); } + @Override public void close() { flyCam = null; if (kinemAnim != null) { @@ -758,7 +774,7 @@ public class Kinematics3D extends IcyFrame { } } - public void setFlyCamOverlay(FlyCamOverlay flyCam) { + public void setFlyCamOverlay(final FlyCamOverlay flyCam) { this.flyCam = flyCam; } } diff --git a/src/main/java/plugins/tprovoost/animation3d/TablePanel.java b/src/main/java/plugins/tprovoost/animation3d/TablePanel.java index 7d69dbd..adeb502 100644 --- a/src/main/java/plugins/tprovoost/animation3d/TablePanel.java +++ b/src/main/java/plugins/tprovoost/animation3d/TablePanel.java @@ -1,13 +1,27 @@ +/* + * 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.animation3d; -import java.awt.Component; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Insets; +import javax.swing.*; +import java.awt.*; import java.util.Hashtable; -import javax.swing.JPanel; - public class TablePanel extends JPanel { private final Hashtable<String, Boolean> busy = new Hashtable<>(); @@ -44,19 +58,20 @@ public class TablePanel extends JPanel { c.gridy++; } - public Component add(Component component) { + @Override + public Component add(final Component component) { return add(component, 1, 1, null, -1); } - public Component add(Component component, int colspan, int rowspan) { + public Component add(final Component component, final int colspan, final int rowspan) { return add(component, colspan, rowspan, null, -1); } - public Component add(Component component, int colspan, int rowspan, int anchor) { + public Component add(final Component component, final int colspan, final int rowspan, final int anchor) { return add(component, colspan, rowspan, null, anchor); } - public Component add(Component component, int colspan, int rowspan, Insets insets, int anchor) { + public Component add(final Component component, final int colspan, final int rowspan, final Insets insets, final int anchor) { c.gridx++; while (isBusy(c.gridx, c.gridy)) c.gridx++; @@ -84,11 +99,11 @@ public class TablePanel extends JPanel { return super.add(component); } - private void setBusy(int x, int y) { - busy.put((y + "-" + x), Boolean.valueOf(true)); + private void setBusy(final int x, final int y) { + busy.put((y + "-" + x), Boolean.TRUE); } - private boolean isBusy(int x, int y) { + private boolean isBusy(final int x, final int y) { return busy.get((c.gridy + "-" + c.gridx)) != null; } } -- GitLab