diff --git a/.gitignore b/.gitignore index 2ea4565051a4733129b9c415dd6583e7ded50d4d..7f5de7386c755a464525cef7566010bd05abae0d 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ target/ *.jar .classpath .project -export.jardesc \ No newline at end of file +export.jardesc +**/.DS_Store \ No newline at end of file diff --git a/pom.xml b/pom.xml index b9a25e94c4734bf657cf362fb6cf40a41600aa5f..76b47f7511a4b315fd8808f635d9ca157340403b 100644 --- a/pom.xml +++ b/pom.xml @@ -6,13 +6,13 @@ <!-- Inherited Icy Parent POM --> <parent> - <artifactId>pom-icy</artifactId> <groupId>org.bioimageanalysis.icy</groupId> - <version>2.0.0</version> + <artifactId>pom-icy</artifactId> + <version>2.2.0</version> </parent> <artifactId>track-manager</artifactId> - <version>1.5.0</version> + <version>1.5.1</version> <packaging>jar</packaging> @@ -21,26 +21,15 @@ he track manager enables the use of DSP-like trackProcessors. This can affect the display of tracks, selection in time or by ROIs, and also compute some views like the overlaid and animated local flow graph, polar graph. </description> - - <profiles> - <profile> - <id>icy-plugin</id> - <activation> - <activeByDefault>true</activeByDefault> - </activation> - </profile> - </profiles> <dependencies> <dependency> <groupId>org.bioimageanalysis.icy</groupId> - <artifactId>icy-kernel</artifactId> - <version>${icy-kernel.version}</version> + <artifactId>protocols</artifactId> </dependency> <dependency> <groupId>org.bioimageanalysis.icy</groupId> - <artifactId>connected-components</artifactId> - <version>${connected-components.version}</version> + <artifactId>spot-detection-utilities</artifactId> </dependency> </dependencies> diff --git a/src/main/java/plugins/fab/trackmanager/Link.java b/src/main/java/plugins/fab/trackmanager/Link.java index a4a6d9489e71e311312866bc57040f679302518f..64fbda80423f068011265c59606562565579ec2f 100644 --- a/src/main/java/plugins/fab/trackmanager/Link.java +++ b/src/main/java/plugins/fab/trackmanager/Link.java @@ -1,60 +1,54 @@ /* - * Copyright 2010, 2011 Institut Pasteur. - * + * Copyright 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 <http://www.gnu.org/licenses/>. + * along with ICY. If not, see <https://www.gnu.org/licenses/>. */ package plugins.fab.trackmanager; import plugins.nchenouard.spot.Detection; -public class Link -{ +public class Link { TrackSegment start; TrackSegment end; - public Link(TrackSegment start, TrackSegment end) - { + public Link(TrackSegment start, TrackSegment end) { this.start = start; this.end = end; } - public Detection getEndDetection() - { + public Detection getEndDetection() { return end.getFirstDetection(); } - public TrackSegment getEndSegment() - { + public TrackSegment getEndSegment() { return end; } - public Detection getStartDetection() - { + public Detection getStartDetection() { return start.getLastDetection(); } - public TrackSegment getStartSegment() - { + public TrackSegment getStartSegment() { return start; } - + @Override public String toString() { - return "link start:" + getStartDetection() + " end:" + getEndDetection(); + return "link start:" + getStartDetection() + " end:" + getEndDetection(); } } diff --git a/src/main/java/plugins/fab/trackmanager/PluginTrackManagerProcessor.java b/src/main/java/plugins/fab/trackmanager/PluginTrackManagerProcessor.java index 5bf053eb134fc2537345c9685238198155cee52f..49913762220cf3fd6076fa8d0b7fe48ada4e40fd 100644 --- a/src/main/java/plugins/fab/trackmanager/PluginTrackManagerProcessor.java +++ b/src/main/java/plugins/fab/trackmanager/PluginTrackManagerProcessor.java @@ -1,20 +1,20 @@ /* - * Copyright 2010, 2011 Institut Pasteur. - * + * Copyright 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 <http://www.gnu.org/licenses/>. + * along with ICY. If not, see <https://www.gnu.org/licenses/>. */ package plugins.fab.trackmanager; @@ -32,12 +32,13 @@ import icy.gui.component.PopupPanel; import icy.gui.util.GuiUtil; import icy.plugin.abstract_.Plugin; -public abstract class PluginTrackManagerProcessor extends Plugin -{ +public abstract class PluginTrackManagerProcessor extends Plugin { - /** Panel to used by herited class to display data */ + /** + * Panel to used by inherited class to display data + */ protected JPanel panel = new JPanel(); - private PopupPanel mainpanel = new PopupPanel("no name"); + private final PopupPanel mainPanel = new PopupPanel("no name"); protected TrackPool trackPool; protected JCheckBox enabledCheckBox = new JCheckBox("Enable"); @@ -47,9 +48,8 @@ public abstract class PluginTrackManagerProcessor extends Plugin protected JLabel performanceLabel = new JLabel("----"); ActionButton actionButton = new ActionButton(); - public PluginTrackManagerProcessor() - { - mainpanel.expand(); + public PluginTrackManagerProcessor() { + mainPanel.expand(); enabledCheckBox.setSelected(true); enabledCheckBox.addActionListener(actionButton); @@ -66,82 +66,75 @@ public abstract class PluginTrackManagerProcessor extends Plugin moveUpButton.addActionListener(actionButton); moveDownButton.addActionListener(actionButton); - mainpanel.getMainPanel().setLayout(new BoxLayout(mainpanel.getMainPanel(), BoxLayout.PAGE_AXIS)); + mainPanel.getMainPanel().setLayout(new BoxLayout(mainPanel.getMainPanel(), BoxLayout.PAGE_AXIS)); - mainpanel.getMainPanel().add(GuiUtil.createLineBoxPanel(commandPanel)); - mainpanel.getMainPanel().add(GuiUtil.createLineBoxPanel(panel)); + mainPanel.getMainPanel().add(GuiUtil.createLineBoxPanel(commandPanel)); + mainPanel.getMainPanel().add(GuiUtil.createLineBoxPanel(panel)); } - protected void setName(String name) - { - mainpanel.setTitle(name); + protected void setName(String name) { + mainPanel.setTitle(name); } - protected boolean isEnabled() - { + protected boolean isEnabled() { return enabledCheckBox.isSelected(); } - class ActionButton implements ActionListener - { - public void actionPerformed(ActionEvent e) - { + class ActionButton implements ActionListener { + public void actionPerformed(ActionEvent e) { - if (e.getSource() == closeButton) - { + if (e.getSource() == closeButton) { Close(); removeTrackProcessor(); trackPool.fireTrackEditorProcessorChange(); } - if (e.getSource() == enabledCheckBox) - { + if (e.getSource() == enabledCheckBox) { trackPool.fireTrackEditorProcessorChange(); } - if (e.getSource() == moveUpButton) - { + if (e.getSource() == moveUpButton) { trackPool.getTrackManager().moveTrackProcessor(PluginTrackManagerProcessor.this, -1); } - if (e.getSource() == moveDownButton) - { + if (e.getSource() == moveDownButton) { trackPool.getTrackManager().moveTrackProcessor(PluginTrackManagerProcessor.this, +1); } } } - /** Override this function to perform special action before destroying the TrackProcessor. */ + /** + * Override this function to perform special action before destroying the TrackProcessor. + */ public abstract void Close(); - /** Override this to affect data on detection (color (...) ) */ + /** + * Override this to affect data on detection (color (...) ) + */ public abstract void Compute(); - public void setPerformance(int ms) - { + public void setPerformance(int ms) { performanceLabel.setText(ms + " ms "); } - private void removeTrackProcessor() - { + private void removeTrackProcessor() { trackPool.removeTrackProcessor(this); - JPanel parent = (JPanel) mainpanel.getParent(); - parent.remove(mainpanel); + JPanel parent = (JPanel) mainPanel.getParent(); + parent.remove(mainPanel); parent.revalidate(); } - /** Return the Panel Control of this TrackProcessor */ - public JPanel getPanel() - { - return mainpanel; + /** + * Return the Panel Control of this TrackProcessor + */ + public JPanel getPanel() { + return mainPanel; } @Override - protected void finalize() throws Throwable - { + protected void finalize() throws Throwable { trackPool = null; super.finalize(); } - public final void setTrackPool(TrackPool trackPool) - { + public final void setTrackPool(TrackPool trackPool) { this.trackPool = trackPool; } diff --git a/src/main/java/plugins/fab/trackmanager/TrackDetection.java b/src/main/java/plugins/fab/trackmanager/TrackDetection.java index 1bcbe80b91680f8bd31886a540666ef9570f7b48..580167802db7b6f2f79ee0e30d9a94869ff48588 100644 --- a/src/main/java/plugins/fab/trackmanager/TrackDetection.java +++ b/src/main/java/plugins/fab/trackmanager/TrackDetection.java @@ -1,20 +1,20 @@ /* - * Copyright 2010, 2011 Institut Pasteur. - * + * Copyright 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 <http://www.gnu.org/licenses/>. + * along with ICY. If not, see <https://www.gnu.org/licenses/>. */ package plugins.fab.trackmanager; @@ -34,19 +34,14 @@ import plugins.nchenouard.spot.Detection; /** * Display a single detection of a track. Used by TrackPanel / TrackEditor - * + * * @author fab - * @deprecated not anymore a panel or an objet to speed up the rendering process. */ -public class TrackDetection extends JPanel -{ - - private static final long serialVersionUID = 7254806428248130683L; +public class TrackDetection extends JPanel { private boolean Selected = false; - private Detection detection; + private final Detection detection; - public TrackDetection(Detection detection) - { + public TrackDetection(Detection detection) { super(); this.detection = detection; // if ( detection.getDetectionType() == Detection.DETECTIONTYPE_REAL_DETECTION ) color = @@ -56,25 +51,21 @@ public class TrackDetection extends JPanel } - public Detection getDetection() - { + public Detection getDetection() { return detection; } - public void setSelected(boolean Selected) - { + public void setSelected(boolean Selected) { this.Selected = Selected; this.updateUI(); } - public boolean isSelected(boolean Selected) - { + public boolean isSelected(boolean Selected) { return Selected; } @Override - protected void paintComponent(Graphics g) - { + protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; @@ -90,29 +81,30 @@ public class TrackDetection extends JPanel // Draw plot g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(Color.black); - Shape shape = new Rectangle2D.Float(getWidth() / 3f, getHeight() / 3f, getWidth() - 2 * getWidth() / 3f, - getHeight() - 2 * getHeight() / 3f); + Shape shape = new Rectangle2D.Float( + getWidth() / 3f, + getHeight() / 3f, + getWidth() - 2 * getWidth() / 3f, + getHeight() - 2 * getHeight() / 3f + ); g2.fill(shape); // Draw red square if selected for drag and drop - if (Selected) - { + if (Selected) { g2.setColor(Color.red); g2.drawRect(1, 1, getWidth() - 3, getHeight() - 3); } // Draw square if depending detection is selected. - if (detection.isSelected()) - { + if (detection.isSelected()) { g2.setStroke(new BasicStroke(4)); g2.setColor(Color.black); g2.drawRect(0, 0, getWidth(), getHeight()); g2.setStroke(new BasicStroke(1)); } - if (detection.getDetectionType() == Detection.DETECTIONTYPE_VIRTUAL_DETECTION) - { + if (detection.getDetectionType() == Detection.DETECTIONTYPE_VIRTUAL_DETECTION) { g2.setStroke(new BasicStroke(2)); g2.setColor(Color.white); g2.drawLine(0, 0, getWidth(), getHeight()); diff --git a/src/main/java/plugins/fab/trackmanager/TrackGroup.java b/src/main/java/plugins/fab/trackmanager/TrackGroup.java index 34f4a11ea4d79a97e70af90d0c34821e98187bc0..635eaf92ba99e5aa73e94039114630f4b5517c4a 100644 --- a/src/main/java/plugins/fab/trackmanager/TrackGroup.java +++ b/src/main/java/plugins/fab/trackmanager/TrackGroup.java @@ -1,20 +1,20 @@ /* - * Copyright 2010, 2011 Institut Pasteur. - * + * Copyright 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 <http://www.gnu.org/licenses/>. + * along with ICY. If not, see <https://www.gnu.org/licenses/>. */ package plugins.fab.trackmanager; @@ -24,93 +24,79 @@ import java.util.ArrayList; import plugins.nchenouard.spot.Detection; -public class TrackGroup -{ +public class TrackGroup { private final Sequence sequence; - /** + /** * DO NOT DIRECTLY ADD OR REMOVE tracks from this trackSegmentList. Always use getters and adder/setters - * */ - private ArrayList<TrackSegment> trackSegmentList; + */ + private final ArrayList<TrackSegment> trackSegmentList; - public TrackGroup(Sequence sequence) - { + public TrackGroup(Sequence sequence) { this.sequence = sequence; - trackSegmentList = new ArrayList<TrackSegment>(); + trackSegmentList = new ArrayList<>(); } /** * @return the sequence */ - public Sequence getSequence() - { + public Sequence getSequence() { return sequence; } - public ArrayList<TrackSegment> getTrackSegmentList() - { + public ArrayList<TrackSegment> getTrackSegmentList() { return trackSegmentList; } - public void addTrackSegment(TrackSegment ts) - { - if (ts.getOwnerTrackGroup() != null) - { + public void addTrackSegment(TrackSegment ts) { + if (ts.getOwnerTrackGroup() != null) { System.err.println("The trackSegment is already owned by another TrackGroup."); return; } - + //System.out.println("Track segment added to group. TS: " +ts.toString() ); - + ts.setOwnerTrackGroup(this); trackSegmentList.add(ts); } - public TrackSegment getTrackSegmentWithDetection(Detection detection) - { + public TrackSegment getTrackSegmentWithDetection(Detection detection) { - ArrayList<TrackSegment> trackSegmentList = getTrackSegmentList(); + ArrayList<TrackSegment> trackSegmentList = getTrackSegmentList(); - for ( TrackSegment ts : trackSegmentList ) - { - if ( ts.containsDetection( detection ) ) return ts; - } + for (TrackSegment ts : trackSegmentList) { + if (ts.containsDetection(detection)) return ts; + } - return null; + return null; } - - public void clearAllTrackSegment() - { - ArrayList<TrackSegment> trackSegmentListCopy = new ArrayList<TrackSegment>( trackSegmentList ); - - for ( TrackSegment ts: trackSegmentListCopy ) - { - removeTrackSegment( ts ); - } + + public void clearAllTrackSegment() { + ArrayList<TrackSegment> trackSegmentListCopy = new ArrayList<>(trackSegmentList); + + for (TrackSegment ts : trackSegmentListCopy) { + removeTrackSegment(ts); + } } - - public void removeTrackSegment(TrackSegment ts) - { - // should remove links + + public void removeTrackSegment(TrackSegment ts) { + // should remove links ts.setOwnerTrackGroup(null); ts.removeAllLinks(); - trackSegmentList.remove(ts); + trackSegmentList.remove(ts); } private String description; - public String getDescription() - { + public String getDescription() { return description; } - public void setDescription(String description) - { + public void setDescription(String description) { this.description = description; } @Override - public String toString() - { + public String toString() { return description; } diff --git a/src/main/java/plugins/fab/trackmanager/TrackLengthDialog.java b/src/main/java/plugins/fab/trackmanager/TrackLengthDialog.java index a26c90200b94a9748bf1019572ea5c32f87cb0ba..bd8df0345e77a81924f3c0d750724db128b8fc8e 100644 --- a/src/main/java/plugins/fab/trackmanager/TrackLengthDialog.java +++ b/src/main/java/plugins/fab/trackmanager/TrackLengthDialog.java @@ -12,56 +12,54 @@ import javax.swing.JTextField; public class TrackLengthDialog implements ActionListener { - JTextField textField= new JTextField("3-10"); - TrackPool trackPool; - - public TrackLengthDialog( TrackPool trackPool ) { - - this.trackPool = trackPool; - ActionDialog actionDialog = new ActionDialog("Select by length"); - actionDialog.getContentPane().setLayout( - new BoxLayout( actionDialog.getContentPane(), BoxLayout.PAGE_AXIS ) ); - - actionDialog.getContentPane().add( GuiUtil.createLineBoxPanel( new JLabel("Use the syntax: from-to (in number of frame):" ) ) ); - actionDialog.getContentPane().add( GuiUtil.createLineBoxPanel( textField ) ); - - actionDialog.pack(); - actionDialog.setLocationRelativeTo( null ); - - actionDialog.setOkAction( this ); - actionDialog.setVisible( true ); - - - } - - @Override - public void actionPerformed(ActionEvent e) { - - String text = textField.getText(); - - String[] values = text.split("-"); - int lowVal = 0; - int highVal = Integer.MAX_VALUE; - try - { - lowVal = Integer.parseInt( values[0] ); - } catch ( Exception e1 ) - { - lowVal = 0; - } - try - { - highVal = Integer.parseInt( values[1] ); - } catch ( Exception e1 ) - { - highVal = Integer.MAX_VALUE; - } - - System.out.println( "low val : " +lowVal ); - System.out.println( "high val : " +highVal ); - - trackPool.selectTracksByLength( lowVal , highVal ); - - - } + JTextField textField = new JTextField("3-10"); + TrackPool trackPool; + + public TrackLengthDialog(TrackPool trackPool) { + + this.trackPool = trackPool; + ActionDialog actionDialog = new ActionDialog("Select by length"); + actionDialog.getContentPane().setLayout( + new BoxLayout(actionDialog.getContentPane(), BoxLayout.PAGE_AXIS)); + + actionDialog.getContentPane().add(GuiUtil.createLineBoxPanel(new JLabel("Use the syntax: from-to (in number of frame):"))); + actionDialog.getContentPane().add(GuiUtil.createLineBoxPanel(textField)); + + actionDialog.pack(); + actionDialog.setLocationRelativeTo(null); + + actionDialog.setOkAction(this); + actionDialog.setVisible(true); + + + } + + @Override + public void actionPerformed(ActionEvent e) { + + String text = textField.getText(); + + String[] values = text.split("-"); + int lowVal; + int highVal; + try { + lowVal = Integer.parseInt(values[0]); + } + catch (Exception e1) { + lowVal = 0; + } + try { + highVal = Integer.parseInt(values[1]); + } + catch (Exception e1) { + highVal = Integer.MAX_VALUE; + } + + System.out.println("low val : " + lowVal); + System.out.println("high val : " + highVal); + + trackPool.selectTracksByLength(lowVal, highVal); + + + } } diff --git a/src/main/java/plugins/fab/trackmanager/TrackManager.java b/src/main/java/plugins/fab/trackmanager/TrackManager.java index c4b7814350a38f72eaefd6b1fb3125003d634114..923e38968682158e5937cbbccec6854ecf1ea4f3 100644 --- a/src/main/java/plugins/fab/trackmanager/TrackManager.java +++ b/src/main/java/plugins/fab/trackmanager/TrackManager.java @@ -1,20 +1,20 @@ /* - * Copyright 2010, 2011 Institut Pasteur. - * + * Copyright 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 <http://www.gnu.org/licenses/>. + * along with ICY. If not, see <https://www.gnu.org/licenses/>. */ package plugins.fab.trackmanager; @@ -78,58 +78,50 @@ import plugins.nchenouard.spot.Detection; /** * @author Fabrice de Chaumont */ -public class TrackManager extends PluginActionable - implements AdjustmentListener, ActionListener, SwimmingPoolListener, IcyFrameListener -{ +public class TrackManager extends PluginActionable implements AdjustmentListener, ActionListener, SwimmingPoolListener, IcyFrameListener { - /** + /* * List of active trackEditor shared between trackeditors (not used anymore) */ // private static ArrayList<TrackManager> trackManagerList = new ArrayList<TrackManager>(); - /** is this track manager not used anymore (TODO:Should change to a listener structure.) */ + /** + * is this track manager not used anymore (TODO:Should change to a listener structure.) + */ boolean trackManagerDestroyed = false; - public boolean isTrackManagerDestroyed() - { + public boolean isTrackManagerDestroyed() { return trackManagerDestroyed; } - private class MenuItemActionListener implements ActionListener - { + private class MenuItemActionListener implements ActionListener { Class<? extends PluginTrackManagerProcessor> pluginTrackManagerProcessor; PluginDescriptor pluginDescriptor; public MenuItemActionListener(PluginDescriptor pluginDescriptor, - Class<? extends PluginTrackManagerProcessor> pluginTrackEditorProcessor) - { + Class<? extends PluginTrackManagerProcessor> pluginTrackEditorProcessor) { this.pluginTrackManagerProcessor = pluginTrackEditorProcessor; this.pluginDescriptor = pluginDescriptor; } @Override - public void actionPerformed(ActionEvent event) - { + public void actionPerformed(ActionEvent event) { loadTrackProcessor(pluginDescriptor); } } - void loadTrackProcessor(PluginDescriptor pluginDescriptor) - { + void loadTrackProcessor(PluginDescriptor pluginDescriptor) { PluginTrackManagerProcessor ptep = null; - try - { - ptep = (PluginTrackManagerProcessor) pluginDescriptor.getPluginClass().newInstance(); + try { + ptep = (PluginTrackManagerProcessor) pluginDescriptor.getPluginClass().getDeclaredConstructor().newInstance(); } - catch (Exception e) - { + catch (Exception e) { e.printStackTrace(); } - if (ptep == null) - { + if (ptep == null) { System.out.println("Can't load processor."); return; } @@ -143,24 +135,21 @@ public class TrackManager extends PluginActionable } - public TrackPool getTrackPool() - { + public TrackPool getTrackPool() { return trackPool; } - void rebuildTrackProcessorDisplay() - { + void rebuildTrackProcessorDisplay() { rightContentPanel.removeAll(); - for (PluginTrackManagerProcessor trackProcessor : trackPool.getTrackManagerProcessorList()) - { + for (PluginTrackManagerProcessor trackProcessor : trackPool.getTrackManagerProcessorList()) { rightContentPanel.add(trackProcessor.getPanel()); } rightContentPanel.revalidate(); - ((JPanel) rightContentPanel.getParent()).revalidate(); + rightContentPanel.getParent().revalidate(); } JButton addTrackProcessorButton = new JButton("add Track Processor..."); @@ -184,14 +173,14 @@ public class TrackManager extends PluginActionable * void * { * String node = "plugins/fab/trackmanager/browser"; - * + * * Preferences preferences = Preferences.userRoot().node( node ); * String path = preferences.get( "path" , "" ); * chooser.setCurrentDirectory( new File(path) ); - * + * * int returnVal = chooser.showOpenDialog(null); * if(returnVal != JFileChooser.APPROVE_OPTION) return; - * + * * preferences.put( "path", chooser.getCurrentDirectory().getAbsolutePath() ); * } */ @@ -207,8 +196,7 @@ public class TrackManager extends PluginActionable JPanel mainPanel = GuiUtil.generatePanel(); - IcyFrame mainFrame = GuiUtil.generateTitleFrame("TrackManager", mainPanel, new Dimension(400, 0), true, true, true, - true); + IcyFrame mainFrame = GuiUtil.generateTitleFrame("TrackManager", mainPanel, new Dimension(400, 0), true, true, true, true); JMenuBar menuBar = new JMenuBar(); JPopupMenu pluginPopupMenu = new JPopupMenu("Add plugin to queue"); @@ -243,8 +231,7 @@ public class TrackManager extends PluginActionable JMenuItem onlineHelpMenuItem; - public TrackManager() - { + public TrackManager() { mainFrame.addFrameListener(this); @@ -315,8 +302,7 @@ public class TrackManager extends PluginActionable trackingGroupSourceMenu = new JMenu("Tracking groups"); - trackingGroupSourceHelpMenuItem = new JMenuItem( - "No track group available: use either file/load, a tracker or a benchmark generator to generate tracks."); + trackingGroupSourceHelpMenuItem = new JMenuItem("No track group available: use either file/load, a tracker or a benchmark generator to generate tracks."); trackingGroupSourceMenu.add(trackingGroupSourceHelpMenuItem); trackingGroupSourceHelpMenuItem.setEnabled(false); @@ -388,8 +374,7 @@ public class TrackManager extends PluginActionable intermediatePanel.add(rightContentPanel, BorderLayout.NORTH); intermediatePanel.add(Box.createGlue(), BorderLayout.CENTER); - JScrollPane rightScrollPanel = new JScrollPane(intermediatePanel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, - JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); + JScrollPane rightScrollPanel = new JScrollPane(intermediatePanel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); // JScrollPane rightScrollPanel = new JScrollPane(rightContentPanel, // JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, // JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); @@ -434,20 +419,17 @@ public class TrackManager extends PluginActionable } /** - * Monitor swimming pool change event and change the track view. If a trackgroup is used in an - * other trackeditor, the trackgroup checkbox is disabled. + * Monitor swimming pool change event and change the track view. If a trackgroup is used in + * another trackeditor, the trackgroup checkbox is disabled. */ @Override - public void swimmingPoolChangeEvent(SwimmingPoolEvent swimmingPoolEvent) - { - if (swimmingPoolEvent.getType() == SwimmingPoolEventType.ELEMENT_ADDED) - { + public void swimmingPoolChangeEvent(SwimmingPoolEvent swimmingPoolEvent) { + if (swimmingPoolEvent.getType() == SwimmingPoolEventType.ELEMENT_ADDED) { // System.out.println("TrackManager : swimming pool element added."); // System.out.println("object: " + // swimmingPoolEvent.getResult().getObject().getClass()); - if (swimmingPoolEvent.getResult().getObject() instanceof TrackGroup) - { + if (swimmingPoolEvent.getResult().getObject() instanceof TrackGroup) { CheckBoxResultSource checkBoxResultSource = new CheckBoxResultSource(swimmingPoolEvent.getResult(), true); trackingGroupSourceMenu.add(checkBoxResultSource); @@ -455,26 +437,21 @@ public class TrackManager extends PluginActionable trackingGroupSourceHelpMenuItem.setVisible(false); } } - if (swimmingPoolEvent.getType() == SwimmingPoolEventType.ELEMENT_REMOVED) - { + if (swimmingPoolEvent.getType() == SwimmingPoolEventType.ELEMENT_REMOVED) { trackPool.removeResult(swimmingPoolEvent.getResult()); // resultList.remove( swimmingPoolEvent.getResult() ); // If there is only one item to remove, no item will be left, then display help message. - if (trackingGroupSourceMenu.getItemCount() == 2) - { + if (trackingGroupSourceMenu.getItemCount() == 2) { trackingGroupSourceHelpMenuItem.setVisible(true); } - for (int i = 0; i < trackingGroupSourceMenu.getItemCount(); i++) - { + for (int i = 0; i < trackingGroupSourceMenu.getItemCount(); i++) { JMenuItem mi = trackingGroupSourceMenu.getItem(i); - if (mi instanceof CheckBoxResultSource) - { + if (mi instanceof CheckBoxResultSource) { CheckBoxResultSource cbrs = (CheckBoxResultSource) mi; - if (cbrs.result == swimmingPoolEvent.getResult()) - { + if (cbrs.result == swimmingPoolEvent.getResult()) { cbrs.destroy(); return; } @@ -502,8 +479,7 @@ public class TrackManager extends PluginActionable } - private void initTrackPoolInnerPanel() - { + private void initTrackPoolInnerPanel() { // trackingGroupSourceMenu.removeAll(); @@ -511,10 +487,8 @@ public class TrackManager extends PluginActionable ArrayList<SwimmingObject> swimmingPoolArrayList = Icy.getMainInterface().getSwimmingPool().getObjects(); - for (SwimmingObject result : swimmingPoolArrayList) - { - if (result.getObject() instanceof TrackGroup) - { + for (SwimmingObject result : swimmingPoolArrayList) { + if (result.getObject() instanceof TrackGroup) { boolean enabled = true; // for (TrackManager trackEditor : trackManagerList) // { @@ -526,7 +500,7 @@ public class TrackManager extends PluginActionable // } CheckBoxResultSource checkBoxResultResource = new CheckBoxResultSource( // "" + - // result.getObject().toString(), + // result.getObject().toString(), result, enabled); trackingGroupSourceMenu.add(checkBoxResultResource); @@ -542,15 +516,12 @@ public class TrackManager extends PluginActionable } - /** - * Called from other trackeditor to check wich results are already used. - * - * @return - */ - private ArrayList<SwimmingObject> getResultList() - { - return trackPool.resultList; - } +// /** +// * Called from other trackeditor to check witch results are already used. +// */ +// private ArrayList<SwimmingObject> getResultList() { +// return trackPool.resultList; +// } // /** // * Called from other TrackEditor to avoid having the same track used @@ -577,32 +548,32 @@ public class TrackManager extends PluginActionable // } // } - /** List of sequences which will be kept synchronize while the t cursor are moving. */ + ///** List of sequences which will be kept synchronize while the t cursor are moving. */ // private ArrayList<Sequence> sequenceToKeepSynchronizeInT = new ArrayList<Sequence>(); - /** current time in track window */ + /** + * current time in track window + */ int currentT = 0; - public int getCurrentPositionT() - { + public int getCurrentPositionT() { return currentT; } - public void setCurrentPositionT(int t) - { + public void setCurrentPositionT(int t) { currentT = t; reSynchroTSequence(); trackPool.fireTrackEditorProcessorChange(); } - void timeCursorChanged(int t) - { + void timeCursorChanged(int t) { setCurrentPositionT(t); } - /** set the sequence with the current time set in trackEditor */ - private void reSynchroTSequence() - { + /** + * set the sequence with the current time set in trackEditor + */ + private void reSynchroTSequence() { // System.out.println("Synchro sequence"); // for (Sequence sequence : sequenceToKeepSynchronizeInT) // { @@ -611,10 +582,8 @@ public class TrackManager extends PluginActionable // } Sequence sequence = sequenceSelector.getSelectedSequence(); - if (sequence != null) - { - for (Viewer viewer : Icy.getMainInterface().getViewers(sequence)) - { + if (sequence != null) { + for (Viewer viewer : Icy.getMainInterface().getViewers(sequence)) { viewer.setPositionT(currentT); } // sequence.setT( currentT ); @@ -622,18 +591,14 @@ public class TrackManager extends PluginActionable } - class CheckBoxResultSource extends JCheckBoxMenuItem implements ActionListener - { - private static final long serialVersionUID = -2021713434786505514L; + class CheckBoxResultSource extends JCheckBoxMenuItem implements ActionListener { // JCheckBox checkBox = new JCheckBox(); // JToggleButton trackTimeOnSequenceButton = new JToggleButton("T"); SwimmingObject result; - public CheckBoxResultSource(SwimmingObject result, boolean enabled) - { - if (!(result.getObject() instanceof TrackGroup)) - { + public CheckBoxResultSource(SwimmingObject result, boolean enabled) { + if (!(result.getObject() instanceof TrackGroup)) { System.out.println("Result object type not supported."); return; } @@ -641,7 +606,7 @@ public class TrackManager extends PluginActionable TrackGroup trackGroup = (TrackGroup) result.getObject(); int nbTracks = trackGroup.getTrackSegmentList().size(); - String label = "" + result.getObject().toString() + " (" + nbTracks + " Tracks)"; + String label = result.getObject().toString() + " (" + nbTracks + " Tracks)"; // trackTimeOnSequenceButton.setToolTipText("Keep Time synchro with sequence"); // trackTimeOnSequenceButton.setSelected( true ) ; @@ -684,8 +649,7 @@ public class TrackManager extends PluginActionable // checkBox.setSelected( b ); // } - public void destroy() - { + public void destroy() { // remove the sequence tracked // if (trackTimeOnSequenceButton.isSelected()) // { @@ -698,8 +662,7 @@ public class TrackManager extends PluginActionable } @Override - public void actionPerformed(ActionEvent e) - { + public void actionPerformed(ActionEvent e) { // if (e.getSource() == trackTimeOnSequenceButton) // { @@ -715,10 +678,8 @@ public class TrackManager extends PluginActionable // reSynchroTSequence(); // } - if (e.getSource() == this) - { - if (this.isSelected()) - { + if (e.getSource() == this) { + if (this.isSelected()) { // resultList.add( result ); trackPool.addResult(result); // trackPool.getDisplaySequence().painterChanged( null ); @@ -733,8 +694,7 @@ public class TrackManager extends PluginActionable // } } - else - { + else { trackPool.removeResult(result); // trackPool.getDisplaySequence().painterChanged( null ); // for (TrackManager trackEditor : trackManagerList) @@ -764,8 +724,7 @@ public class TrackManager extends PluginActionable } - private void loadTracks() - { + private void loadTracks() { JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle("Select track.xml file."); @@ -783,34 +742,28 @@ public class TrackManager extends PluginActionable preferences.put("path", chooser.getCurrentDirectory().getAbsolutePath()); - try - { + try { final List<TrackGroup> groups = loadTracks(chooser.getSelectedFile().getAbsolutePath()); // add group to swimming pool - for (TrackGroup group : groups) - { + for (TrackGroup group : groups) { SwimmingObject so = new SwimmingObject(group); Icy.getMainInterface().getSwimmingPool().add(so); } trackPool.fireTrackEditorProcessorChange(); } - catch (IllegalArgumentException ex) - { + catch (IllegalArgumentException ex) { MessageDialog.showDialog(ex.getMessage(), MessageDialog.ERROR_MESSAGE); - return; } } - public static List<TrackGroup> loadTracks(String path) throws IllegalArgumentException - { + public static List<TrackGroup> loadTracks(String path) throws IllegalArgumentException { final Document document = XMLUtil.loadDocument(path, false); return loadTracks(document); } - public static List<TrackGroup> loadTracks(Document document) throws IllegalArgumentException - { + public static List<TrackGroup> loadTracks(Document document) throws IllegalArgumentException { if (document == null) throw new IllegalArgumentException("Invalid track file !"); @@ -821,14 +774,12 @@ public class TrackManager extends PluginActionable final List<TrackGroup> result = new ArrayList<>(); - for (Element trackGroupElement : XMLUtil.getElements(rootElement, "trackgroup")) - { + for (Element trackGroupElement : XMLUtil.getElements(rootElement, "trackgroup")) { // create track group final TrackGroup trackGroup = new TrackGroup(null); trackGroup.setDescription(XMLUtil.getAttributeValue(trackGroupElement, "description", "no description")); - for (Element trackSegmentElement : XMLUtil.getElements(trackGroupElement)) - { + for (Element trackSegmentElement : XMLUtil.getElements(trackGroupElement)) { // create track segment final TrackSegment trackSegment = new TrackSegment(); final int id = XMLUtil.getAttributeIntValue(trackSegmentElement, "id", -1); @@ -838,8 +789,7 @@ public class TrackManager extends PluginActionable else trackSegment.setId(id); - for (Element detectionElement : XMLUtil.getElements(trackSegmentElement)) - { + for (Element detectionElement : XMLUtil.getElements(trackSegmentElement)) { // create detection final Detection detection = Detection.createDetection(XMLUtil.getAttributeValue(detectionElement, "classname", "plugins.nchenouard.spot.Detection")); @@ -853,16 +803,14 @@ public class TrackManager extends PluginActionable // add track segment to track group trackGroup.addTrackSegment(trackSegment); } - + // add track group to result result.add(trackGroup); } // get links - for (Element linkListElement : XMLUtil.getElements(rootElement, "linklist")) - { - for (Element link : XMLUtil.getElements(linkListElement)) - { + for (Element linkListElement : XMLUtil.getElements(rootElement, "linklist")) { + for (Element link : XMLUtil.getElements(linkListElement)) { final int idFrom = XMLUtil.getAttributeIntValue(link, "from", -1); final int idTo = XMLUtil.getAttributeIntValue(link, "to", -1); @@ -877,8 +825,7 @@ public class TrackManager extends PluginActionable return result; } - private void loadTracksFromTrackMate() - { + private void loadTracksFromTrackMate() { JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle("Import TrackMate xml track file."); @@ -896,57 +843,48 @@ public class TrackManager extends PluginActionable preferences.put("path", chooser.getCurrentDirectory().getAbsolutePath()); - try - { + try { final List<TrackGroup> groups = loadTracksFromTrackMate(chooser.getSelectedFile().getAbsolutePath()); // add group to swimming pool - for (TrackGroup group : groups) - { + for (TrackGroup group : groups) { SwimmingObject so = new SwimmingObject(group); Icy.getMainInterface().getSwimmingPool().add(so); } trackPool.fireTrackEditorProcessorChange(); } - catch (IllegalArgumentException ex) - { + catch (IllegalArgumentException ex) { MessageDialog.showDialog(ex.getMessage(), MessageDialog.ERROR_MESSAGE); - return; } } - public static List<TrackGroup> loadTracksFromTrackMate(String path) - { + public static List<TrackGroup> loadTracksFromTrackMate(String path) { final Document document = XMLUtil.loadDocument(path, false); return loadTracksFromTrackMate(document); } - public static List<TrackGroup> loadTracksFromTrackMate(Document document) throws IllegalArgumentException - { + public static List<TrackGroup> loadTracksFromTrackMate(Document document) throws IllegalArgumentException { if (document == null) throw new IllegalArgumentException("Invalid track file !"); final Element trackNode = XMLUtil.getElement(document.getDocumentElement().getParentNode(), "Tracks"); if (trackNode == null) - throw new IllegalArgumentException( - "Unsupported version of TrackMate XML file !\nTry to use the Icy XML export in TrackMate instead and directly load it with 'TrackManager-->File->Load...' command."); + throw new IllegalArgumentException("Unsupported version of TrackMate XML file !\nTry to use the Icy XML export in TrackMate instead and directly load it with 'TrackManager-->File->Load...' command."); final List<TrackGroup> result = new ArrayList<>(); - final String unit = XMLUtil.getAttributeValue(trackNode, "spaceUnits", "pixel"); + //final String unit = XMLUtil.getAttributeValue(trackNode, "spaceUnits", "pixel"); - double unitMultiplicator = 1; - if (unit == "micron") - unitMultiplicator = 0.000001d; + //double unitMultiplicator = 1; + //if (unit.equals("micron")) + // unitMultiplicator = 0.000001d; - for (Element trackElement : XMLUtil.getElements(document.getDocumentElement().getParentNode(), "Tracks")) - { + for (Element trackElement : XMLUtil.getElements(document.getDocumentElement().getParentNode(), "Tracks")) { // create track group final TrackGroup trackGroup = new TrackGroup(null); trackGroup.setDescription(XMLUtil.getAttributeValue(trackElement, "description", "no description")); - for (Element trackSegmentElement : XMLUtil.getElements(trackElement)) - { + for (Element trackSegmentElement : XMLUtil.getElements(trackElement)) { // create track segment final TrackSegment trackSegment = new TrackSegment(); @@ -956,8 +894,7 @@ public class TrackManager extends PluginActionable else trackSegment.setId(id); - for (Element detectionElement : XMLUtil.getElements(trackSegmentElement)) - { + for (Element detectionElement : XMLUtil.getElements(trackSegmentElement)) { // create detection final Detection detection = Detection.createDetection("plugins.nchenouard.spot.Detection"); @@ -970,7 +907,7 @@ public class TrackManager extends PluginActionable // add track segment to group trackGroup.addTrackSegment(trackSegment); } - + // add track group to result result.add(trackGroup); } @@ -978,8 +915,7 @@ public class TrackManager extends PluginActionable return result; } - private void debug() - { + private void debug() { System.out.println("--- debug"); // for ( Link link : trackPool.getLinks() ) @@ -993,8 +929,7 @@ public class TrackManager extends PluginActionable } - private void saveTracks() - { + private void saveTracks() { JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle("Select track.xml file."); chooser.setFileFilter(new FileNameExtensionFilter("XML track file", "xml")); @@ -1014,8 +949,7 @@ public class TrackManager extends PluginActionable saveTracks(chooser.getSelectedFile().getAbsolutePath(), trackPool.getTrackGroupList()); } - public static void saveTracks(String path, List<TrackGroup> groups) - { + public static void saveTracks(String path, List<TrackGroup> groups) { // get file final File file = new File(FileUtil.setExtension(path, ".xml")); // generate document @@ -1024,26 +958,22 @@ public class TrackManager extends PluginActionable XMLUtil.saveDocument(document, file); } - public static Document saveTracks(List<TrackGroup> groups) - { + public static Document saveTracks(List<TrackGroup> groups) { final Document result = XMLUtil.createDocument(true); final Element rootElement = result.getDocumentElement(); final Element versionElement = XMLUtil.addElement(rootElement, "trackfile"); versionElement.setAttribute("version", "1"); - for (TrackGroup trackGroup : groups) - { + for (TrackGroup trackGroup : groups) { final Element trackGroupElement = XMLUtil.addElement(rootElement, "trackgroup"); trackGroupElement.setAttribute("description", trackGroup.getDescription()); - for (TrackSegment trackSegment : trackGroup.getTrackSegmentList()) - { + for (TrackSegment trackSegment : trackGroup.getTrackSegmentList()) { final Element trackElement = XMLUtil.addElement(trackGroupElement, "track"); - trackElement.setAttribute("id", "" + trackSegment.getId()); + trackElement.setAttribute("id", String.valueOf(trackSegment.getId())); - for (Detection detection : trackSegment.getDetectionList()) - { + for (Detection detection : trackSegment.getDetectionList()) { final Element detectionElement = XMLUtil.addElement(trackElement, "detection"); detectionElement.setAttribute("classname", detection.getClass().getName()); @@ -1058,12 +988,11 @@ public class TrackManager extends PluginActionable // save links final Element linklistElement = XMLUtil.addElement(rootElement, "linklist"); - for (Link link : TrackPool.getLinks(groups)) - { + for (Link link : TrackPool.getLinks(groups)) { final Element trackElement = XMLUtil.addElement(linklistElement, "link"); - trackElement.setAttribute("from", "" + link.getStartSegment().getId()); - trackElement.setAttribute("to", "" + link.getEndSegment().getId()); + trackElement.setAttribute("from", String.valueOf(link.getStartSegment().getId())); + trackElement.setAttribute("to", String.valueOf(link.getEndSegment().getId())); } return result; @@ -1072,23 +1001,19 @@ public class TrackManager extends PluginActionable /** * Attempt to re-classify / re-organize the track order to improve track understandment. */ - public void reOrganize() - { - for (TrackGroup trackGroup : trackPool.getTrackGroupList()) - { + public void reOrganize() { + for (TrackGroup trackGroup : trackPool.getTrackGroupList()) { + @SuppressWarnings("unchecked") List<TrackSegment> trackSegmentList = (ArrayList<TrackSegment>) trackGroup.getTrackSegmentList().clone(); - List<TrackSegment> trackSegmentListOrganized = (ArrayList<TrackSegment>) trackGroup.getTrackSegmentList() - .clone(); + @SuppressWarnings("unchecked") + List<TrackSegment> trackSegmentListOrganized = (ArrayList<TrackSegment>) trackGroup.getTrackSegmentList().clone(); int tMax = trackPool.getLastDetectionTimePoint(); for (int t = 0; t < tMax; t++) - for (TrackSegment ts : trackSegmentList) - { - if (ts.getFirstDetection().getT() == t) - { - for (int index = 0; index < ts.nextList.size(); index++) - { + for (TrackSegment ts : trackSegmentList) { + if (ts.getFirstDetection().getT() == t) { + for (int index = 0; index < ts.nextList.size(); index++) { TrackSegment ts2 = ts.nextList.get(index); trackSegmentListOrganized.remove(ts2); int targetIndex = trackSegmentListOrganized.indexOf(ts) - ts.nextList.size() / 2 + index @@ -1111,40 +1036,32 @@ public class TrackManager extends PluginActionable } @Override - public void actionPerformed(ActionEvent e) - { - if (e.getSource() == onlineHelpMenuItem) - { - NetworkUtil.openBrowser("http://icy.bioimageanalysis.org/index.php?display=detailPlugin&pluginId=88"); + public void actionPerformed(ActionEvent e) { + if (e.getSource() == onlineHelpMenuItem) { + NetworkUtil.openBrowser("https://icy.bioimageanalysis.org/plugin/track-manager/"); } - if (e.getSource() == loadMenuItem) - { + if (e.getSource() == loadMenuItem) { loadTracks(); } - if (e.getSource() == loadFromTrackMateMenuItem) - { + if (e.getSource() == loadFromTrackMateMenuItem) { loadTracksFromTrackMate(); } - if (e.getSource() == saveMenuItem) - { + if (e.getSource() == saveMenuItem) { saveTracks(); } - if (e.getSource() == sequenceSelector) - { + if (e.getSource() == sequenceSelector) { trackPool.setDisplaySequence(sequenceSelector.getSelectedSequence()); } - if (e.getSource() == reOrganizeMenuItem) - { + if (e.getSource() == reOrganizeMenuItem) { reOrganize(); } - if (e.getSource() == displayTrackPanelCheckBoxMenuItem) - { + if (e.getSource() == displayTrackPanelCheckBoxMenuItem) { trackPanel.setEnableLeftPanelTrackDisplay(displayTrackPanelCheckBoxMenuItem.isSelected()); String node = "plugins/fab/trackmanager/displaytrackpanel"; @@ -1159,41 +1076,33 @@ public class TrackManager extends PluginActionable // trackPool.fireTrackEditorProcessorChange(); } - if (e.getSource() == externaliseCheckBoxMenuItem) - { - if (externaliseCheckBoxMenuItem.isSelected()) - { + if (e.getSource() == externaliseCheckBoxMenuItem) { + if (externaliseCheckBoxMenuItem.isSelected()) { mainFrame.externalize(); } - else - { + else { mainFrame.internalize(); } } - if (e.getSource() == addTrackProcessorButton) - { + if (e.getSource() == addTrackProcessorButton) { pluginPopupMenu.show(addTrackProcessorButton, 0, 0); } - if (e.getSource() == showHideTrackPoolSourcesPanel) - { + if (e.getSource() == showHideTrackPoolSourcesPanel) { trackGroupSourceInnerPanel.setVisible(showHideTrackPoolSourcesPanel.isSelected()); } - if (e.getSource() == selectAllMenuItem) - { + if (e.getSource() == selectAllMenuItem) { trackPool.selectAllTracks(); } - if (e.getSource() == unselectAllMenuItem) - { + if (e.getSource() == unselectAllMenuItem) { trackPool.unselectAllTracks(); } - if (e.getSource() == selectTrackByLengthMenuItem) - { - TrackLengthDialog tld = new TrackLengthDialog(trackPool); + //if (e.getSource() == selectTrackByLengthMenuItem) { + //TrackLengthDialog tld = new TrackLengthDialog(trackPool); // TrackLengthDialog tld = new TrackLengthDialog(); // JDialog dialog = new JDialog(); @@ -1207,43 +1116,36 @@ public class TrackManager extends PluginActionable // dialog.setSize(200, 100); // dialog.setLocationRelativeTo(null); // dialog.setVisible(true); - } + //} - if (e.getSource() == invertSelectionMenuItem) - { + if (e.getSource() == invertSelectionMenuItem) { trackPool.invertSelection(); } - if (e.getSource() == deleteLinkMenuItem) - { + if (e.getSource() == deleteLinkMenuItem) { trackPool.deleteSelectedLink(); } - if (e.getSource() == deleteSelectionMenuItem) - { + if (e.getSource() == deleteSelectionMenuItem) { trackPool.deleteSelectedTracks(); } - if (e.getSource() == debugMenuItem) - { + if (e.getSource() == debugMenuItem) { debug(); } - if (e.getSource() == fuseTracksMenuItem) - { + if (e.getSource() == fuseTracksMenuItem) { trackPool.fuseAllTracks(); } - if (e.getSource() == zoomLessButton) - { + if (e.getSource() == zoomLessButton) { int newX = (int) trackPanel.getDetectDim().getWidth() - 5; if (newX <= 0) newX = 5; trackPanel.setDetectDim(new Dimension(newX, newX)); trackPool.fireTrackEditorProcessorChange(); } - if (e.getSource() == zoomMoreButton) - { + if (e.getSource() == zoomMoreButton) { trackPanel.setDetectDim(new Dimension((int) trackPanel.getDetectDim().getWidth() + 5, (int) trackPanel.getDetectDim().getHeight() + 5)); trackPool.fireTrackEditorProcessorChange(); @@ -1267,13 +1169,11 @@ public class TrackManager extends PluginActionable } @Override - public void adjustmentValueChanged(AdjustmentEvent arg0) - { + public void adjustmentValueChanged(AdjustmentEvent arg0) { } - private void buildPluginMenu() - { + private void buildPluginMenu() { pluginPopupMenu.removeAll(); @@ -1284,11 +1184,9 @@ public class TrackManager extends PluginActionable pluginPopupMenu.addSeparator(); } - for (PluginDescriptor plugin : PluginLoader.getPlugins()) - { + for (PluginDescriptor plugin : PluginLoader.getPlugins()) { if (plugin.isInstanceOf(PluginTrackManagerProcessor.class)) - if (!plugin.isAbstract()) - { + if (!plugin.isAbstract()) { JMenuItem menuItem = new JMenuItem(plugin.getName(), ResourceUtil.scaleIcon(plugin.getIcon(), 24)); pluginPopupMenu.add(menuItem); @@ -1300,8 +1198,7 @@ public class TrackManager extends PluginActionable } - public void moveTrackProcessor(PluginTrackManagerProcessor trackEditorProcessor, int i) - { + public void moveTrackProcessor(PluginTrackManagerProcessor trackEditorProcessor, int i) { int newIndex = trackPool.getTrackManagerProcessorList().indexOf(trackEditorProcessor); // System.out.println("previous index: " + newIndex ); newIndex += i; @@ -1324,14 +1221,12 @@ public class TrackManager extends PluginActionable } @Override - public void icyFrameActivated(IcyFrameEvent e) - { + public void icyFrameActivated(IcyFrameEvent e) { } @Override - public void icyFrameClosed(IcyFrameEvent e) - { + public void icyFrameClosed(IcyFrameEvent e) { // release T synchro with sequences. // sequenceToKeepSynchronizeInT.clear(); @@ -1349,10 +1244,9 @@ public class TrackManager extends PluginActionable // close all track processors. - ArrayList<PluginTrackManagerProcessor> processorList = (ArrayList<PluginTrackManagerProcessor>) trackPool - .getTrackManagerProcessorList().clone(); - for (PluginTrackManagerProcessor tep : processorList) - { + @SuppressWarnings("unchecked") + ArrayList<PluginTrackManagerProcessor> processorList = (ArrayList<PluginTrackManagerProcessor>) trackPool.getTrackManagerProcessorList().clone(); + for (PluginTrackManagerProcessor tep : processorList) { tep.Close(); } @@ -1368,80 +1262,57 @@ public class TrackManager extends PluginActionable } @Override - public void icyFrameClosing(IcyFrameEvent e) - { + public void icyFrameClosing(IcyFrameEvent e) { } @Override - public void icyFrameDeactivated(IcyFrameEvent e) - { + public void icyFrameDeactivated(IcyFrameEvent e) { } @Override - public void icyFrameDeiconified(IcyFrameEvent e) - { + public void icyFrameDeiconified(IcyFrameEvent e) { } @Override - public void icyFrameIconified(IcyFrameEvent e) - { + public void icyFrameIconified(IcyFrameEvent e) { } @Override - public void icyFrameOpened(IcyFrameEvent e) - { + public void icyFrameOpened(IcyFrameEvent e) { } @Override - public void icyFrameExternalized(IcyFrameEvent e) - { + public void icyFrameExternalized(IcyFrameEvent e) { } @Override - public void icyFrameInternalized(IcyFrameEvent e) - { + public void icyFrameInternalized(IcyFrameEvent e) { } - @Override - public void compute() - { - // TODO Auto-generated method stub - - } - // - // public void unSelectAllTrackGroup() { - // // TODO Auto-generated method stub - // - // } - // public void setDisplaySequence(Sequence sequence) { // // sequenceSelector.setSequenceSelected( sequence ); // // } - public Sequence getDisplaySequence() - { + public Sequence getDisplaySequence() { return sequenceSelector.getSelectedSequence(); } - public void setDisplaySequence(Sequence sequence) - { + public void setDisplaySequence(Sequence sequence) { sequenceSelector.setSelectedSequence(sequence); } @Override - public void run() - { + public void run() { } - } diff --git a/src/main/java/plugins/fab/trackmanager/TrackManagerPainter.java b/src/main/java/plugins/fab/trackmanager/TrackManagerPainter.java index b303c455b0b34ee9066db1c0e2f73914d0f73860..5c21ad206a2a56412056380622317199644057d6 100644 --- a/src/main/java/plugins/fab/trackmanager/TrackManagerPainter.java +++ b/src/main/java/plugins/fab/trackmanager/TrackManagerPainter.java @@ -1,20 +1,20 @@ /* - * Copyright 2010, 2011 Institut Pasteur. - * + * Copyright 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 <http://www.gnu.org/licenses/>. + * along with ICY. If not, see <https://www.gnu.org/licenses/>. */ package plugins.fab.trackmanager; @@ -35,44 +35,43 @@ import icy.canvas.IcyCanvas; import icy.painter.Overlay; import icy.sequence.Sequence; import icy.swimmingPool.SwimmingObject; +import icy.type.point.Point5D; import icy.util.GraphicsUtil; import icy.util.ShapeUtil; import plugins.nchenouard.spot.Detection; /** * Painter used to display tracks on sequence (as overlay) - * + * * @author Fabrice de Chaumont */ -public class TrackManagerPainter extends Overlay -{ - private TrackPool trackPool = null; +public class TrackManagerPainter extends Overlay { + private final TrackPool trackPool; - /** List of Listeners */ - private List<TrackPainterListener> trackPainterListener = new ArrayList<TrackPainterListener>(); + /** + * List of Listeners + */ + private final List<TrackPainterListener> trackPainterListener = new ArrayList<>(); private boolean drawTracksOnSequence = true; private boolean subPixelicDisplay = true; - public TrackManagerPainter(TrackPool trackPool) - { + public TrackManagerPainter(TrackPool trackPool) { super("Track painter"); this.trackPool = trackPool; } - public boolean isSubPixelicDisplay() - { + public boolean isSubPixelicDisplay() { return subPixelicDisplay; } - public void setSubPixelicDisplay(boolean subPixelicDisplay) - { + public void setSubPixelicDisplay(boolean subPixelicDisplay) { this.subPixelicDisplay = subPixelicDisplay; } - public void mouseClick(MouseEvent e, Point2D p, IcyCanvas icyCanvas) - { + @Override + public void mouseClick(MouseEvent e, /*Point2D p*/ Point5D.Double imagePoint, IcyCanvas icyCanvas) { if (e.isConsumed()) return; @@ -80,22 +79,51 @@ public class TrackManagerPainter extends Overlay distanceThresholdSqr *= distanceThresholdSqr; // Check if a detection is around. - for (TrackGroup tg : trackPool.getTrackGroupList()) - { - for (TrackSegment ts : tg.getTrackSegmentList()) - { - for (Detection d : ts.getDetectionList()) - { - if (d.isEnabled()) - { + for (TrackGroup tg : trackPool.getTrackGroupList()) { + for (TrackSegment ts : tg.getTrackSegmentList()) { + for (Detection d : ts.getDetectionList()) { + if (d.isEnabled()) { + //final double dist = new Point2D.Double(p.getX(), p.getY()).distanceSq(new Point2D.Double(d.getX(), d.getY())); + final Point2D p2d = imagePoint.toPoint2D(); + final double dist = new Point2D.Double(p2d.getX(), p2d.getY()) + .distanceSq(new Point2D.Double(d.getX(), d.getY())); + + if (dist < distanceThresholdSqr) { + TrackSegment ts1 = trackPool.getTrackSegmentWithDetection(d); + if (ts1 != null) { + ts1.setAllDetectionSelected(!ts1.isAllDetectionSelected()); + trackPool.getDisplaySequence().overlayChanged(this); + // so tracks in left panel will be refreshed + fireTrackPainterEvent(); + e.consume(); + } + break; + } + } + } + } + } + } + + /*@Override + public void mouseClick(MouseEvent e, Point2D p, IcyCanvas icyCanvas) { + if (e.isConsumed()) + return; + + float distanceThresholdSqr = (float) icyCanvas.canvasToImageDeltaX(3); + distanceThresholdSqr *= distanceThresholdSqr; + + // Check if a detection is around. + for (TrackGroup tg : trackPool.getTrackGroupList()) { + for (TrackSegment ts : tg.getTrackSegmentList()) { + for (Detection d : ts.getDetectionList()) { + if (d.isEnabled()) { final double dist = new Point2D.Double(p.getX(), p.getY()) .distanceSq(new Point2D.Double(d.getX(), d.getY())); - if (dist < distanceThresholdSqr) - { + if (dist < distanceThresholdSqr) { TrackSegment ts1 = trackPool.getTrackSegmentWithDetection(d); - if (ts1 != null) - { + if (ts1 != null) { ts1.setAllDetectionSelected(!ts1.isAllDetectionSelected()); trackPool.getDisplaySequence().overlayChanged(this); // so tracks in left panel will be refreshed @@ -109,7 +137,7 @@ public class TrackManagerPainter extends Overlay } } - } + }*/ // // should switch to an hashmap to manage several 3D viewers. // ArrayList<vtkActor> actorList = new ArrayList<vtkActor>(); @@ -283,19 +311,14 @@ public class TrackManagerPainter extends Overlay // } @Override - public void paint(Graphics2D g, Sequence sequence, IcyCanvas canvas) - { + public void paint(Graphics2D g, Sequence sequence, IcyCanvas canvas) { // System.out.println("TP"); - if (trackPool != null) - { - if (trackPool.getTrackManager() != null) - { - if (canvas != null) - { - if (trackPool.getTrackManager().currentT != canvas.getPositionT()) - { + if (trackPool != null) { + if (trackPool.getTrackManager() != null) { + if (canvas != null) { + if (trackPool.getTrackManager().currentT != canvas.getPositionT()) { // synchronize processors now so repaint is ok trackPool.getTrackManager().currentT = canvas.getPositionT(); trackPool.getTrackManager().trackPanel.recomputeProcessors(); @@ -312,7 +335,7 @@ public class TrackManagerPainter extends Overlay // System.out.println("TP: now painting frame " + trackPool.getTrackManager().currentT ); - if (isDrawTracksOnSequence() == false) + if (!isDrawTracksOnSequence()) return; // if (canvas instanceof VtkCanvas) @@ -320,8 +343,7 @@ public class TrackManagerPainter extends Overlay // draw3D(sequence, (VtkCanvas) canvas); // } - if (canvas instanceof Canvas2D) - { + if (canvas instanceof Canvas2D) { final Graphics2D g2 = (Graphics2D) g.create(); final Rectangle2D bounds = new Rectangle2D.Double(); final Line2D line = new Line2D.Double(); @@ -338,27 +360,23 @@ public class TrackManagerPainter extends Overlay g2.setStroke(new BasicStroke(trackWidth)); // build the list of line section - final List<Detection> allDetections = new ArrayList<Detection>(); - final List<TrackLineSection> lineSections = new ArrayList<TrackLineSection>(); - final List<TrackLineSection> connectorSections = new ArrayList<TrackLineSection>(); - - for (SwimmingObject result : trackPool.resultList) - { - final TrackGroup tg = (TrackGroup) result.getObject(); - { - for (TrackSegment ts : tg.getTrackSegmentList()) - { + final List<Detection> allDetections = new ArrayList<>(); + final List<TrackLineSection> lineSections = new ArrayList<>(); + final List<TrackLineSection> connectorSections = new ArrayList<>(); + + if (trackPool != null) { + for (SwimmingObject result : trackPool.resultList) { + final TrackGroup tg = (TrackGroup) result.getObject(); + for (TrackSegment ts : tg.getTrackSegmentList()) { final List<Detection> detectionList = ts.getDetectionList(); allDetections.addAll(detectionList); // line sections - if (detectionList.size() > 1) - { + if (detectionList.size() > 1) { Detection startDetection = detectionList.get(0); - for (int i = 1; i < ts.getDetectionList().size(); i++) - { + for (int i = 1; i < ts.getDetectionList().size(); i++) { final Detection endDetection = detectionList.get(i); lineSections.add(new TrackLineSection(startDetection, endDetection)); @@ -368,10 +386,8 @@ public class TrackManagerPainter extends Overlay } // connector between 2 tracks - if (ts.getLastDetection().isEnabled()) - { - for (TrackSegment tsNext : ts.nextList) - { + if (ts.getLastDetection().isEnabled()) { + for (TrackSegment tsNext : ts.nextList) { final Detection endDetection = tsNext.getFirstDetection(); if (endDetection.isEnabled()) @@ -386,20 +402,16 @@ public class TrackManagerPainter extends Overlay g2.setStroke(new BasicStroke(trackWidth * 3)); g2.setColor(Color.white); - for (TrackLineSection lineSection : lineSections) - { - if (lineSection.isEnabled() && lineSection.isSelected() - && GraphicsUtil.isVisible(g2, lineSection.getBounds(bounds, trackWidth * 2))) + for (TrackLineSection lineSection : lineSections) { + if (lineSection.isEnabled() && lineSection.isSelected() && GraphicsUtil.isVisible(g2, lineSection.getBounds(bounds, trackWidth * 2))) g2.draw(lineSection.getLine2D(line)); } // display tracks g2.setStroke(new BasicStroke(trackWidth)); - for (TrackLineSection lineSection : lineSections) - { - if (lineSection.isEnabled() && GraphicsUtil.isVisible(g2, lineSection.getBounds(bounds, trackWidth))) - { + for (TrackLineSection lineSection : lineSections) { + if (lineSection.isEnabled() && GraphicsUtil.isVisible(g2, lineSection.getBounds(bounds, trackWidth))) { g2.setColor(lineSection.getColor()); g2.draw(lineSection.getLine2D(line)); } @@ -408,15 +420,13 @@ public class TrackManagerPainter extends Overlay // display link between tracks g2.setColor(Color.green); - for (TrackLineSection lineSection : connectorSections) - { + for (TrackLineSection lineSection : connectorSections) { if (GraphicsUtil.isVisible(g2, lineSection.getBounds(bounds, trackWidth))) g2.draw(lineSection.getLine2D(line)); } // display detections - for (Detection detection : allDetections) - { + for (Detection detection : allDetections) { // current detection is visible if (detection.isEnabled() && (detection.getT() == canvas.getPositionT())) // && (Math.round(detection.getZ()) == canvas.getPositionZ())) @@ -425,8 +435,7 @@ public class TrackManagerPainter extends Overlay final double y = detection.getY(); bounds.setFrame(x - (trackWidth * 1.5d), y - (trackWidth * 1.5d), trackWidth * 3, trackWidth * 3); - if (GraphicsUtil.isVisible(g2, bounds)) - { + if (GraphicsUtil.isVisible(g2, bounds)) { ellipse.setFrame(bounds); g2.setColor(detection.getColor()); @@ -439,15 +448,17 @@ public class TrackManagerPainter extends Overlay } } - /** add a listener */ - public void addTrackPainterListener(TrackPainterListener trackPainterListener) - { + /** + * add a listener + */ + public void addTrackPainterListener(TrackPainterListener trackPainterListener) { this.trackPainterListener.add(trackPainterListener); } - /** remove a listener */ - public void removeTrackPainterListener(TrackPainterListener trackPainterListener) - { + /** + * remove a listener + */ + public void removeTrackPainterListener(TrackPainterListener trackPainterListener) { this.trackPainterListener.remove(trackPainterListener); } @@ -460,22 +471,20 @@ public class TrackManagerPainter extends Overlay // } // } - /** fire event with a non-specific TrackPainterChangeEvent */ - private void fireTrackPainterEvent() - { - for (TrackPainterListener tpl : trackPainterListener) - { + /** + * fire event with a non-specific TrackPainterChangeEvent + */ + private void fireTrackPainterEvent() { + for (TrackPainterListener tpl : trackPainterListener) { tpl.trackPainterChanged(new TrackPainterChangeEvent(this)); } } - public boolean isDrawTracksOnSequence() - { + public boolean isDrawTracksOnSequence() { return drawTracksOnSequence; } - public void setDrawTracksOnSequence(boolean drawTracksOnSequence) - { + public void setDrawTracksOnSequence(boolean drawTracksOnSequence) { this.drawTracksOnSequence = drawTracksOnSequence; } @@ -501,44 +510,37 @@ public class TrackManagerPainter extends Overlay // { // } - private class TrackLineSection - { + private static class TrackLineSection { final Detection start; final Detection end; - public TrackLineSection(Detection start, Detection end) - { + public TrackLineSection(Detection start, Detection end) { super(); this.start = start; this.end = end; } - public Line2D getLine2D(Line2D line) - { + public Line2D getLine2D(Line2D line) { line.setLine(start.getX(), start.getY(), end.getX(), end.getY()); return line; } - public Color getColor() - { + public Color getColor() { return start.getColor(); } - public Rectangle2D getBounds(Rectangle2D bounds, float stroke) - { + public Rectangle2D getBounds(Rectangle2D bounds, float stroke) { bounds.setFrameFromDiagonal(start.getX(), start.getY(), end.getX(), end.getY()); ShapeUtil.enlarge(bounds, stroke, stroke, true); return bounds; } - public boolean isSelected() - { + public boolean isSelected() { return start.isSelected() && end.isSelected(); } - public boolean isEnabled() - { + public boolean isEnabled() { return start.isEnabled() && end.isEnabled(); } } diff --git a/src/main/java/plugins/fab/trackmanager/TrackManagerProcessorListener.java b/src/main/java/plugins/fab/trackmanager/TrackManagerProcessorListener.java index 9edffeff0d3f872f48a65cbc4f3db121e3f6552d..47e660431885d30b6fcd9473dbc514921949d3c4 100644 --- a/src/main/java/plugins/fab/trackmanager/TrackManagerProcessorListener.java +++ b/src/main/java/plugins/fab/trackmanager/TrackManagerProcessorListener.java @@ -1,26 +1,25 @@ /* - * Copyright 2010, 2011 Institut Pasteur. - * + * Copyright 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 <http://www.gnu.org/licenses/>. + * along with ICY. If not, see <https://www.gnu.org/licenses/>. */ package plugins.fab.trackmanager; import javax.swing.event.ChangeEvent; -public interface TrackManagerProcessorListener -{ - public void TrackEditorProcessorChange(ChangeEvent e); +public interface TrackManagerProcessorListener { + void TrackEditorProcessorChange(ChangeEvent e); } diff --git a/src/main/java/plugins/fab/trackmanager/TrackPainterChangeEvent.java b/src/main/java/plugins/fab/trackmanager/TrackPainterChangeEvent.java index b96286b550a074685101bdaa1438528fa099246a..2a87eb8508dd45eea2fa8b910d2079a498d5bbf5 100644 --- a/src/main/java/plugins/fab/trackmanager/TrackPainterChangeEvent.java +++ b/src/main/java/plugins/fab/trackmanager/TrackPainterChangeEvent.java @@ -1,31 +1,27 @@ /* - * Copyright 2010, 2011 Institut Pasteur. - * + * Copyright 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 <http://www.gnu.org/licenses/>. + * along with ICY. If not, see <https://www.gnu.org/licenses/>. */ package plugins.fab.trackmanager; import java.util.EventObject; -public class TrackPainterChangeEvent extends EventObject -{ - private static final long serialVersionUID = 7586741803753458072L; - - public TrackPainterChangeEvent(Object source) - { +public class TrackPainterChangeEvent extends EventObject { + public TrackPainterChangeEvent(Object source) { super(source); } } diff --git a/src/main/java/plugins/fab/trackmanager/TrackPainterListener.java b/src/main/java/plugins/fab/trackmanager/TrackPainterListener.java index 78df5823070678a66ca985e5ffe17c6d3c5600ec..1f691019c815ca0582c783f80bfe6c242e0c36a5 100644 --- a/src/main/java/plugins/fab/trackmanager/TrackPainterListener.java +++ b/src/main/java/plugins/fab/trackmanager/TrackPainterListener.java @@ -1,24 +1,23 @@ /* - * Copyright 2010, 2011 Institut Pasteur. - * + * Copyright 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 <http://www.gnu.org/licenses/>. + * along with ICY. If not, see <https://www.gnu.org/licenses/>. */ package plugins.fab.trackmanager; -public interface TrackPainterListener -{ - public void trackPainterChanged(TrackPainterChangeEvent e); +public interface TrackPainterListener { + void trackPainterChanged(TrackPainterChangeEvent e); } diff --git a/src/main/java/plugins/fab/trackmanager/TrackPanel.java b/src/main/java/plugins/fab/trackmanager/TrackPanel.java index 1132c5c1bba30007182d5cc85990b0d9320da8bc..08355e2f77e5f83c28e1178616297292ef7f9215 100644 --- a/src/main/java/plugins/fab/trackmanager/TrackPanel.java +++ b/src/main/java/plugins/fab/trackmanager/TrackPanel.java @@ -1,20 +1,20 @@ /* - * Copyright 2010, 2011 Institut Pasteur. - * + * Copyright 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 <http://www.gnu.org/licenses/>. + * along with ICY. If not, see <https://www.gnu.org/licenses/>. */ package plugins.fab.trackmanager; @@ -46,6 +46,7 @@ import icy.gui.viewer.Viewer; import icy.gui.viewer.ViewerEvent; import icy.gui.viewer.ViewerListener; import icy.main.Icy; +import icy.painter.Overlay; import icy.sequence.DimensionId; import icy.sequence.Sequence; import icy.system.thread.ThreadUtil; @@ -53,27 +54,22 @@ import plugins.nchenouard.spot.Detection; /** * Panel managing Tracks and users interactions. - * + * * @author Fabrice de Chaumont */ public class TrackPanel extends JPanel implements MouseListener, MouseMotionListener, TrackPainterListener, - TrackManagerProcessorListener, ViewerListener, GlobalSequenceListener, GlobalViewerListener, Runnable -{ - - /** - * - */ - private static final long serialVersionUID = 938480382468773601L; + TrackManagerProcessorListener, ViewerListener, GlobalSequenceListener, GlobalViewerListener, Runnable { TimeCursor timeCursor = new TimeCursor(); - /** Dimension of a single detection */ + /** + * Dimension of a single detection + */ private Dimension detectDim = new Dimension(10, 10); private TrackPool trackPool; - public TrackPanel(TrackPool trackPool, boolean enableLeftPanelTrackDisplay) - { + public TrackPanel(TrackPool trackPool, boolean enableLeftPanelTrackDisplay) { super(); this.enableLeftPanelTrackDisplay = enableLeftPanelTrackDisplay; @@ -90,16 +86,14 @@ public class TrackPanel extends JPanel implements MouseListener, MouseMotionList Icy.getMainInterface().addGlobalSequenceListener(this); Icy.getMainInterface().addGlobalViewerListener(this); - // System.out.println("TEST tackpanel"); + // System.out.println("TEST trackpanel"); } - void setupViewerListener() - { + void setupViewerListener() { // remove all listener - for (Viewer viewer : Icy.getMainInterface().getViewers()) - { + for (Viewer viewer : Icy.getMainInterface().getViewers()) { viewer.removeListener(this); } @@ -109,27 +103,23 @@ public class TrackPanel extends JPanel implements MouseListener, MouseMotionList if (sequence == null) return; - for (Viewer viewer : Icy.getMainInterface().getViewers(sequence)) - { + for (Viewer viewer : Icy.getMainInterface().getViewers(sequence)) { viewer.addListener(this); } } - public void mouseClicked(MouseEvent e) - { + public void mouseClicked(MouseEvent e) { if (!enableLeftPanelTrackDisplay) return; MouseLink.clear(); // Watch if a detection exists for selection. - { - TrackSegment ts = getTrackSegmentAt(e.getY()); - if (ts == null) - return; - ts.setAllDetectionSelected(!ts.isAllDetectionSelected()); - redrawDetection3(); - } + TrackSegment ts = getTrackSegmentAt(e.getY()); + if (ts == null) + return; + ts.setAllDetectionSelected(!ts.isAllDetectionSelected()); + redrawDetection3(); // Feature: add the detection panel @@ -146,8 +136,7 @@ public class TrackPanel extends JPanel implements MouseListener, MouseMotionList } - private TrackSegment getTrackSegmentAt(int y) - { + private TrackSegment getTrackSegmentAt(int y) { TrackSegment tsResult = null; @@ -155,11 +144,10 @@ public class TrackPanel extends JPanel implements MouseListener, MouseMotionList int currentLine = 0; - loop: for (TrackGroup trackGroup : trackPool.getTrackGroupList()) - for (TrackSegment ts : trackGroup.getTrackSegmentList()) - { - if (currentLine == y) - { + loop: + for (TrackGroup trackGroup : trackPool.getTrackGroupList()) + for (TrackSegment ts : trackGroup.getTrackSegmentList()) { + if (currentLine == y) { tsResult = ts; break loop; } @@ -169,10 +157,7 @@ public class TrackPanel extends JPanel implements MouseListener, MouseMotionList return tsResult; } - private Detection getDetectionAt(int x, int y) - { - Detection detection = null; - + private Detection getDetectionAt(int x, int y) { TrackSegment ts = getTrackSegmentAt(y); if (ts == null) @@ -180,37 +165,32 @@ public class TrackPanel extends JPanel implements MouseListener, MouseMotionList int t = x / getDetectDim().width; - detection = ts.getDetectionAtTime(t); - - return detection; + return ts.getDetectionAtTime(t); } - public void mouseEntered(MouseEvent e) - { + public void mouseEntered(MouseEvent e) { } - public void mouseExited(MouseEvent e) - { + public void mouseExited(MouseEvent e) { } - public void mousePressed(MouseEvent e) - { + public void mousePressed(MouseEvent e) { if (!enableLeftPanelTrackDisplay) return; MouseLink.clear(); - MouseLink.xstart = e.getX(); - MouseLink.ystart = e.getY(); + MouseLink.xStart = e.getX(); + MouseLink.yStart = e.getY(); - MouseLink.xend = e.getX(); - MouseLink.yend = e.getY(); + MouseLink.xEnd = e.getX(); + MouseLink.yEnd = e.getY(); // System.out.println( "debug info: mouse pressed."); - Component component = getComponentAt(MouseLink.xstart, MouseLink.ystart); + Component component = getComponentAt(MouseLink.xStart, MouseLink.yStart); // System.out.println("Mouse pressed component: " + component ); @@ -233,33 +213,27 @@ public class TrackPanel extends JPanel implements MouseListener, MouseMotionList // System.out.println( "detection at click : " + detection ); - if (detection != null) - { - MouseLink.xstart = e.getX(); - MouseLink.ystart = e.getY(); + if (detection != null) { + MouseLink.xStart = e.getX(); + MouseLink.yStart = e.getY(); MouseLink.detectionStart = detection; - MouseLink.ispressed = true; + MouseLink.isPressed = true; // System.out.println("Debug detection mouse link start : " + detection ); } // System.out.println("debug Track selected : " + track ); // manage track and time drag. Time has priority. - if (component == this) - { - if (timeCursor.contains(e.getX(), e.getY())) - { + if (component == this) { + if (timeCursor.contains(e.getX(), e.getY())) { // enables time drag. timeCursor.dragging = true; } - else - { + else { // look if at least one track exists. boolean oneAtLeast = false; - for (TrackGroup trackGroup : trackPool.getTrackGroupList()) - { - if (trackGroup.getTrackSegmentList().size() != 0) - { + for (TrackGroup trackGroup : trackPool.getTrackGroupList()) { + if (trackGroup.getTrackSegmentList().size() != 0) { oneAtLeast = true; break; } @@ -267,8 +241,7 @@ public class TrackPanel extends JPanel implements MouseListener, MouseMotionList // enables trackDrag. // if ( trackPool.getTrackSegmentList().size() != 0 ) - if (oneAtLeast) - { + if (oneAtLeast) { TrackDrag.dragging = true; TrackDrag.ts = getCurrentTrackSegmentWithY(e.getY()); repaint(); @@ -278,14 +251,14 @@ public class TrackPanel extends JPanel implements MouseListener, MouseMotionList } - /** Manage time cursor. */ - private class TimeCursor - { + /** + * Manage time cursor. + */ + private class TimeCursor { int currentT = 0; boolean dragging = false; - boolean contains(int x, int y) - { + boolean contains(int x, int y) { Rectangle r = new Rectangle(currentT * (int) detectDim.getWidth(), 0, (int) detectDim.getWidth(), Integer.MAX_VALUE); return r.contains(x, y); @@ -295,20 +268,16 @@ public class TrackPanel extends JPanel implements MouseListener, MouseMotionList /** * Returns the track at Y //FIXME ! */ - private TrackSegment getCurrentTrackSegmentWithY(int Y) - { + private TrackSegment getCurrentTrackSegmentWithY(int Y) { // System.out.println("drag a refaire."); // return null; - TrackSegment ts = null; - ts = trackPool.getTrackSegmentList().get(getCurrentTrackSegmentIndexWithY(Y)); - return ts; + return trackPool.getTrackSegmentList().get(getCurrentTrackSegmentIndexWithY(Y)); } /** * Returns the number of the track with Y //FIXME ! */ - private int getCurrentTrackSegmentIndexWithY(int Y) - { + private int getCurrentTrackSegmentIndexWithY(int Y) { // System.out.println("drag a refaire."); // return 0; int index = (int) (Y / detectDim.getHeight()); @@ -319,31 +288,29 @@ public class TrackPanel extends JPanel implements MouseListener, MouseMotionList return index; } - /** class use to record Track Drag states. */ - private static class TrackDrag - { + /** + * class use to record Track Drag states. + */ + private static class TrackDrag { static boolean dragging = false; static TrackSegment ts = null; } - public void mouseReleased(MouseEvent e) - { - MouseLink.xend = e.getX(); - MouseLink.yend = e.getY(); + public void mouseReleased(MouseEvent e) { + MouseLink.xEnd = e.getX(); + MouseLink.yEnd = e.getY(); // System.out.println("mouse released"); - if (MouseLink.ispressed) - { + if (MouseLink.isPressed) { // System.out.println("Mouse link is pressed"); Detection detection = getDetectionAt(e.getX(), e.getY()); - if (detection != null) - { - MouseLink.xend = e.getX(); - MouseLink.yend = e.getY(); + if (detection != null) { + MouseLink.xEnd = e.getX(); + MouseLink.yEnd = e.getY(); MouseLink.detectionEnd = detection; // System.out.println("Debug detection mouse link end : " + detection ); } @@ -374,26 +341,22 @@ public class TrackPanel extends JPanel implements MouseListener, MouseMotionList } MouseLink.clear(); - if (TrackDrag.dragging) - { + if (TrackDrag.dragging) { TrackDrag.dragging = false; repaint(); } - if (timeCursor.dragging) - { + if (timeCursor.dragging) { timeCursor.dragging = false; repaint(); } } - public void mouseDragged(MouseEvent e) - { - if (MouseLink.ispressed) - { - MouseLink.xend = e.getX(); - MouseLink.yend = e.getY(); + public void mouseDragged(MouseEvent e) { + if (MouseLink.isPressed) { + MouseLink.xEnd = e.getX(); + MouseLink.yEnd = e.getY(); // Component component = getComponentAt(MouseLink.xend, MouseLink.yend); // @@ -427,21 +390,19 @@ public class TrackPanel extends JPanel implements MouseListener, MouseMotionList } // if track dragging , moves track. - if (TrackDrag.dragging) - { + if (TrackDrag.dragging) { trackPool.moveTrackToIndex(TrackDrag.ts, getCurrentTrackSegmentIndexWithY(e.getY())); clearDetectionsAndReDisplay(); } // if time dragging , moves times. - if (timeCursor.dragging) - { + if (timeCursor.dragging) { timeCursor.currentT = (int) (e.getX() / detectDim.getWidth()); // System.out.println( TimeCursor.currentT ); // System.out.println( "track editor : " + trackPool.getTrackEditor() ); - // FIXME : remettre ces securites. + // FIXME : remettre ces sécurités. if (timeCursor.currentT < 0) timeCursor.currentT = 0; // if ( TimeCursor.currentT > trackPool.getSequence().getLength() -1 ) @@ -452,24 +413,24 @@ public class TrackPanel extends JPanel implements MouseListener, MouseMotionList } } - public void mouseMoved(MouseEvent e) - { + public void mouseMoved(MouseEvent e) { } + /* * @Override * protected void paintComponent(Graphics g) * { * super.paintComponent(g); - * + * * Graphics2D g2 = (Graphics2D) g; - * + * * // affichage des fond de tracks. * // boolean swapcolor = false; * // Color c1 = new Color( 0.8f ,0.8f , 0.8f ); * // Color c2 = new Color( 0.9f ,0.9f , 0.9f ); * // - * + * * // VERSION AVEC CLIPPER. * // int startTrackSegmentToDisplay = getVisibleRect().y / getDetectDim().height ; * // int lastTrackSegmentToDisplay = ( getVisibleRect().y+getVisibleRect().height ) / @@ -483,7 +444,7 @@ public class TrackPanel extends JPanel implements MouseListener, MouseMotionList * // for ( int tracknb = startTrackSegmentToDisplay ; tracknb < lastTrackSegmentToDisplay ; * // tracknb++ ) * // for ( int tracknb = 0 ; tracknb < trackPool.getTrackSegmentList().size() ; tracknb++ ) - * + * * // TODO : remettre la peinture au fond ( les bandes horizontales. ) * // boolean switchBackground = false; * // @@ -509,7 +470,7 @@ public class TrackPanel extends JPanel implements MouseListener, MouseMotionList * // g2.drawString("#"+tracknb , 10 , detectDim.height*tracknb -2 ); * // * // } - * + * * // draw current Time Cursor. * { * g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .5f)); @@ -518,7 +479,7 @@ public class TrackPanel extends JPanel implements MouseListener, MouseMotionList * getVisibleRect().height); * g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f)); * } - * + * * // draw current MouseLink user operation. * // FIXME : re-introduce mouse link user operations * // if (MouseLink.ispressed) @@ -529,7 +490,7 @@ public class TrackPanel extends JPanel implements MouseListener, MouseMotionList * // g2.drawLine(MouseLink.xstart, MouseLink.ystart, MouseLink.xend, MouseLink.yend); * // g2.setStroke(new BasicStroke(1)); * // } - * + * * // emphasis track selection. * // if ( TrackDrag.dragging ) * // { @@ -539,9 +500,9 @@ public class TrackPanel extends JPanel implements MouseListener, MouseMotionList * // getWidth() , getDetectDim().height ); * // g2.setComposite( AlphaComposite.getInstance( AlphaComposite.SRC_OVER, 1.0f) ); * // } - * + * * // TODO : affiche les liens entre tracks. - * + * * // { * // // Graphics2D g2 = (Graphics2D) this.getGraphics(); * // // if ( g2 !=null ) @@ -600,9 +561,9 @@ public class TrackPanel extends JPanel implements MouseListener, MouseMotionList * // g2.setStroke( new BasicStroke( 1 ) ); * // } * // } - * + * * // if ( true ) return; // FIXME a enlever - * + * * // draw links. * // { * // ArrayList<Link> links = trackPool.getLinks(); @@ -661,22 +622,19 @@ public class TrackPanel extends JPanel implements MouseListener, MouseMotionList * // * // } * // } - * + * * } */ - public Dimension getDetectDim() - { + public Dimension getDetectDim() { return detectDim; } - public void setDetectDim(Dimension detectDim) - { + public void setDetectDim(Dimension detectDim) { this.detectDim = detectDim; } - public void setTrackPool(TrackPool trackPool) - { + public void setTrackPool(TrackPool trackPool) { this.trackPool = trackPool; clearDetectionsAndReDisplay(); @@ -685,8 +643,7 @@ public class TrackPanel extends JPanel implements MouseListener, MouseMotionList /** * Clear Detections and redisplay them. */ - private void clearDetectionsAndReDisplay() - { + private void clearDetectionsAndReDisplay() { // do it in background ThreadUtil.bgRunSingle(this); } @@ -694,26 +651,19 @@ public class TrackPanel extends JPanel implements MouseListener, MouseMotionList /** * Recompute all processors */ - public void recomputeProcessors() - { + public void recomputeProcessors() { // important to do it on EDT (otherwise we can get death lock) - ThreadUtil.invokeNow(new Runnable() - { - @Override - public void run() - { - // reset color of detection - for (Detection d : trackPool.getAllDetection()) - d.reset(); - // then execute processors (important to do the whole in EDT so painting always happen after all processes) - trackPool.computeTrackProcessor(); - } + ThreadUtil.invokeNow(() -> { + // reset color of detection + for (Detection d : trackPool.getAllDetection()) + d.reset(); + // then execute processors (important to do the whole in EDT so painting always happen after all processes) + trackPool.computeTrackProcessor(); }); } @Override - public void run() - { + public void run() { // refresh processors recomputeProcessors(); // redraw left panel @@ -722,15 +672,16 @@ public class TrackPanel extends JPanel implements MouseListener, MouseMotionList // update painters Sequence sequence = trackPool.getDisplaySequence(); if (sequence != null) - sequence.painterChanged(null); + //sequence.painterChanged(null); + sequence.overlayChanged((Overlay) null); } // boolean disableLeftPanel= false; + /** * Re-create the tracking image. */ - public void redrawDetection3() - { + public void redrawDetection3() { if (!enableLeftPanelTrackDisplay) return; @@ -746,8 +697,7 @@ public class TrackPanel extends JPanel implements MouseListener, MouseMotionList int width = getDetectDim().width * (maxSizeT + 1); int height = getDetectDim().height * totalNumberOfTrack; - if (width * height > maxSize) - { + if (width * height > maxSize) { height = maxSize / width; System.out.println( "too much track to display them all in trackManager left panel. Still, they all appear on the sequence."); @@ -765,23 +715,18 @@ public class TrackPanel extends JPanel implements MouseListener, MouseMotionList // drop image if dimensions have changed. if (bufferedImage != null) if ((bufferedImage.getWidth() != trackingPanelSize.width) - || (bufferedImage.getHeight() != trackingPanelSize.height)) - { + || (bufferedImage.getHeight() != trackingPanelSize.height)) { bufferedImage = null; } - // create cache image if it does not exists. - if (bufferedImage == null) - { - if (!(trackingPanelSize.width == 0 || trackingPanelSize.height == 0)) - { - try - { + // create cache image if it does not exist. + if (bufferedImage == null) { + if (!(trackingPanelSize.width == 0 || trackingPanelSize.height == 0)) { + try { bufferedImage = new BufferedImage(trackingPanelSize.width, trackingPanelSize.height, BufferedImage.TYPE_INT_RGB); } - catch (OutOfMemoryError e) - { + catch (OutOfMemoryError e) { System.out.println("can't create " + trackingPanelSize.width + "x" + trackingPanelSize.height + " bitmap for track representation in trackPanel"); System.out.println("left panel disabled"); @@ -789,8 +734,7 @@ public class TrackPanel extends JPanel implements MouseListener, MouseMotionList return; } } - else - { + else { // no track to display. return; } @@ -800,39 +744,33 @@ public class TrackPanel extends JPanel implements MouseListener, MouseMotionList g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // fill background + Color c1 = new Color(0.8f, 0.8f, 0.8f); + Color c2 = new Color(0.9f, 0.9f, 0.9f); + int offsetY = 0; + boolean switchBackground = true; + g.setFont(new Font("Arial", Font.BOLD, detectDim.height - 2)); + for (TrackGroup trackGroup : trackPool.getTrackGroupList()) + for (int tracknb = 0; tracknb < trackGroup.getTrackSegmentList().size(); tracknb++) { + // display consecutive horizontal bars. - { - Color c1 = new Color(0.8f, 0.8f, 0.8f); - Color c2 = new Color(0.9f, 0.9f, 0.9f); - int offsetY = 0; - boolean switchBackground = true; - g.setFont(new Font("Arial", Font.BOLD, detectDim.height - 2)); - for (TrackGroup trackGroup : trackPool.getTrackGroupList()) - for (int tracknb = 0; tracknb < trackGroup.getTrackSegmentList().size(); tracknb++) - { - // display consecutive horizontal bars. - - switchBackground = !switchBackground; - if (switchBackground) - { - g.setColor(c1); - } - else - { - g.setColor(c2); - } + switchBackground = !switchBackground; + if (switchBackground) { + g.setColor(c1); + } + else { + g.setColor(c2); + } - g.fillRect(0, detectDim.height * offsetY, detectDim.width * (maxSizeT + 1), detectDim.height); - offsetY++; + g.fillRect(0, detectDim.height * offsetY, detectDim.width * (maxSizeT + 1), detectDim.height); + offsetY++; - } - } + } // draw detections int currentLine = 0; // current track line ( y offset ) - HashMap<Detection, Point2D> detectionHashMap = new HashMap<Detection, Point2D>(); + HashMap<Detection, Point2D> detectionHashMap = new HashMap<>(); for (TrackGroup trackGroup : trackPool.getTrackGroupList()) for (TrackSegment ts : trackGroup.getTrackSegmentList()) @@ -845,8 +783,7 @@ public class TrackPanel extends JPanel implements MouseListener, MouseMotionList // ts.detectionList.size() ); // TrackSegment ts = trackPool.getTrackSegmentList().get( trackSegmentIndex ); - for (int detectionIndex = 0; detectionIndex < ts.getDetectionList().size(); detectionIndex++) - { + for (int detectionIndex = 0; detectionIndex < ts.getDetectionList().size(); detectionIndex++) { final Detection d = ts.getDetectionList().get(detectionIndex); // TrackDetection td = new TrackDetection(d); @@ -856,9 +793,16 @@ public class TrackPanel extends JPanel implements MouseListener, MouseMotionList // + getDetectDim().width, -0 + getDetectDim().height); // add(td); - Rectangle2D bounds = new Rectangle2D.Double(0 + getDetectDim().width * d.getT(), - 0 + getDetectDim().height * currentLine, -0 + getDetectDim().width, - -0 + getDetectDim().height); + Rectangle2D bounds = new Rectangle2D.Double( + //0 + getDetectDim().width * d.getT(), + getDetectDim().width * d.getT(), + //0 + getDetectDim().height * currentLine, + getDetectDim().height * currentLine, + //-0 + getDetectDim().width, + getDetectDim().width, + //-0 + getDetectDim().height + getDetectDim().height + ); drawDetection(g, d, bounds); detectionHashMap.put(d, @@ -878,16 +822,14 @@ public class TrackPanel extends JPanel implements MouseListener, MouseMotionList int detectHeight = getDetectDim().height / 2; int detectWidth = getDetectDim().width / 2; - for (Link link : links) - { + for (Link link : links) { Detection startDetection = link.getStartDetection(); Detection endDetection = link.getEndDetection(); Point2D startDetectionPoint2D = detectionHashMap.get(startDetection); Point2D endDetectionPoint2D = detectionHashMap.get(endDetection); - if (startDetectionPoint2D != null && endDetectionPoint2D != null) - { + if (startDetectionPoint2D != null && endDetectionPoint2D != null) { g2.drawLine((int) startDetectionPoint2D.getX() + detectHeight, (int) startDetectionPoint2D.getY() + detectWidth, (int) endDetectionPoint2D.getX() + detectHeight, @@ -896,7 +838,7 @@ public class TrackPanel extends JPanel implements MouseListener, MouseMotionList } /* - * + * * // previous version * for (TrackGroup trackGroup : trackPool.getTrackGroupList()) * for (TrackSegment ts : trackGroup.getTrackSegmentList()) @@ -905,7 +847,7 @@ public class TrackPanel extends JPanel implements MouseListener, MouseMotionList * if ( lastDetection !=null ) * { * Point2D lastDetectionPoint2D = detectionHashMap.get( lastDetection ); - * + * * for ( TrackSegment tsNext : ts.nextList ) * { * Detection nextDetection = tsNext.getFirstDetection(); @@ -927,45 +869,39 @@ public class TrackPanel extends JPanel implements MouseListener, MouseMotionList * } * } * } - * + * * } */ // display track number - { - int offsetY = 1; - g.setColor(Color.white); - for (TrackGroup trackGroup : trackPool.getTrackGroupList()) - { - for (int tracknb = 0; tracknb < trackGroup.getTrackSegmentList().size(); tracknb++) - { - g.drawString(trackGroup.getDescription() + " # " + tracknb, 10, detectDim.height * offsetY - 2); - offsetY++; - } + //int offsetY = 1; + offsetY = 1; + g.setColor(Color.white); + for (TrackGroup trackGroup : trackPool.getTrackGroupList()) { + for (int tracknb = 0; tracknb < trackGroup.getTrackSegmentList().size(); tracknb++) { + g.drawString(trackGroup.getDescription() + " # " + tracknb, 10, detectDim.height * offsetY - 2); + offsetY++; } } repaint(); } - private void drawDetection(Graphics2D g, Detection d, Rectangle2D bounds) - { + private void drawDetection(Graphics2D g, Detection d, Rectangle2D bounds) { g.setColor(d.getColor()); g.fill(bounds); g.setColor(d.getColor().darker()); g.draw(bounds); - if (d.isSelected()) - { + if (d.isSelected()) { g.setStroke(new BasicStroke(3)); g.setColor(Color.white); g.draw(bounds); g.setStroke(new BasicStroke(1)); } - if (d.getDetectionType() == Detection.DETECTIONTYPE_VIRTUAL_DETECTION) - { + if (d.getDetectionType() == Detection.DETECTIONTYPE_VIRTUAL_DETECTION) { g.setStroke(new BasicStroke(2)); g.setColor(Color.white); g.drawLine((int) bounds.getMinX(), (int) bounds.getMinY(), (int) bounds.getMaxX(), (int) bounds.getMaxY()); @@ -976,28 +912,25 @@ public class TrackPanel extends JPanel implements MouseListener, MouseMotionList BufferedImage bufferedImage; - boolean enableLeftPanelTrackDisplay = true; + boolean enableLeftPanelTrackDisplay; /** * Paint the tracking Panel */ @Override - protected void paintComponent(Graphics g1) - { + protected void paintComponent(Graphics g1) { super.paintComponent(g1); Graphics2D g = (Graphics2D) g1; g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - if (!enableLeftPanelTrackDisplay) - { + if (!enableLeftPanelTrackDisplay) { g.clearRect(0, 0, this.getWidth(), this.getHeight()); g.drawString("Display disabled. Enable selecting Display > Enable Track Panel", 20, 20); return; } int totalNumberOfTrack = trackPool.getTotalNumberOfTrack(); - if (totalNumberOfTrack == 0) - { + if (totalNumberOfTrack == 0) { g.drawString("No track to display", 20, 20); } @@ -1007,31 +940,27 @@ public class TrackPanel extends JPanel implements MouseListener, MouseMotionList g.drawImage(bufferedImage, null, 0, 0); // draw MouseLink - if (MouseLink.ispressed) - { + if (MouseLink.isPressed) { g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setStroke(new BasicStroke(2)); g.setColor(Color.red); - g.drawLine(MouseLink.xstart, MouseLink.ystart, MouseLink.xend, MouseLink.yend); + g.drawLine(MouseLink.xStart, MouseLink.yStart, MouseLink.xEnd, MouseLink.yEnd); g.setStroke(new BasicStroke(1)); } // draw current Time Cursor. - { - g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .5f)); - g.setColor(Color.red); - g.fillRect(getDetectDim().width * timeCursor.currentT, getVisibleRect().y, getDetectDim().width, - getVisibleRect().height); - g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f)); - } + g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .5f)); + g.setColor(Color.red); + g.fillRect(getDetectDim().width * timeCursor.currentT, getVisibleRect().y, getDetectDim().width, + getVisibleRect().height); + g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f)); } /** * @deprecated replaced by redrawDetection3() */ - public void redrawDetection2() - { + public void redrawDetection2() { // FIXME: dimension should update ( le 400 est fixe ici... ) // old code: @@ -1068,8 +997,7 @@ public class TrackPanel extends JPanel implements MouseListener, MouseMotionList // ts.detectionList.size() ); // TrackSegment ts = trackPool.getTrackSegmentList().get( trackSegmentIndex ); - for (int detectionIndex = 0; detectionIndex < ts.getDetectionList().size(); detectionIndex++) - { + for (int detectionIndex = 0; detectionIndex < ts.getDetectionList().size(); detectionIndex++) { final Detection d = ts.getDetectionList().get(detectionIndex); // final TrackDetection td ; // ThreadUtil.invokeLater( new Runnable() { @@ -1083,9 +1011,17 @@ public class TrackPanel extends JPanel implements MouseListener, MouseMotionList // System.out.println( "detec : " + getDetectDim().height* ligne ); - // specification de la taille des panels representant les detections ici. - td.setBounds(0 + getDetectDim().width * d.getT(), 0 + getDetectDim().height * ligne, - -0 + getDetectDim().width, -0 + getDetectDim().height); + // specification de la taille des panels représentant les detections ici. + td.setBounds( + //0 + getDetectDim().width * d.getT(), + getDetectDim().width * d.getT(), + //0 + getDetectDim().height * ligne, + getDetectDim().height * ligne, + //-0 + getDetectDim().width, + getDetectDim().width, + //-0 + getDetectDim().height + getDetectDim().height + ); add(td); } ligne++; @@ -1176,9 +1112,10 @@ public class TrackPanel extends JPanel implements MouseListener, MouseMotionList } - /** Should be called when a mouse-link operation has been finished */ - public void finishMouseConnexion() - { + /** + * Should be called when a mouse-link operation has been finished + */ + public void finishMouseConnexion() { // Look for particular case where the detection belongs to the same TrackSegment, and are // joined // --> cut tracksegment. @@ -1187,20 +1124,17 @@ public class TrackPanel extends JPanel implements MouseListener, MouseMotionList // System.out.println("MouseLink start : " + MouseLink.detectionStart ); // System.out.println("MouseLink end : " + MouseLink.detectionEnd ); - if (MouseLink.detectionStart != null && MouseLink.detectionEnd != null) - { + if (MouseLink.detectionStart != null && MouseLink.detectionEnd != null) { // System.out.println("Enter detect start & end valid."); Detection d1 = MouseLink.detectionStart; Detection d2 = MouseLink.detectionEnd; - if (d1.getT() + 1 == d2.getT()) - { - if (trackPool.getTrackSegmentWithDetection(d1) == trackPool.getTrackSegmentWithDetection(d2)) - { + if (d1.getT() + 1 == d2.getT()) { + if (trackPool.getTrackSegmentWithDetection(d1) == trackPool.getTrackSegmentWithDetection(d2)) { trackPool.cutTrackAfterDetection(d1); - if (trackPool.getDisplaySequence() != null) - { - trackPool.getDisplaySequence().painterChanged(null); + if (trackPool.getDisplaySequence() != null) { + //trackPool.getDisplaySequence().painterChanged(null); + trackPool.getDisplaySequence().overlayChanged((Overlay) null); } clearDetectionsAndReDisplay(); updateUI(); @@ -1215,29 +1149,29 @@ public class TrackPanel extends JPanel implements MouseListener, MouseMotionList // updates GUI // trackPool.getSequence().painterChanged(null); - if (trackPool.getDisplaySequence() != null) - { - trackPool.getDisplaySequence().painterChanged(null); + if (trackPool.getDisplaySequence() != null) { + //trackPool.getDisplaySequence().painterChanged(null); + trackPool.getDisplaySequence().overlayChanged((Overlay) null); } clearDetectionsAndReDisplay(); updateUI(); } - /** This Internal class is used to create the mouseLink */ - static class MouseLink - { + /** + * This Internal class is used to create the mouseLink + */ + static class MouseLink { static Detection detectionEnd; static Detection detectionStart; - static int xstart, ystart; - static int xend, yend; - static boolean ispressed = false; + static int xStart, yStart; + static int xEnd, yEnd; + static boolean isPressed = false; // static TrackDetection TrackDetectionStart = null; // static TrackDetection TrackDetectionEnd = null; - public static void clear() - { - ispressed = false; + public static void clear() { + isPressed = false; detectionStart = null; detectionEnd = null; @@ -1246,23 +1180,21 @@ public class TrackPanel extends JPanel implements MouseListener, MouseMotionList } } - public void trackPainterChanged(TrackPainterChangeEvent e) - { + public void trackPainterChanged(TrackPainterChangeEvent e) { // that means we may have selected / unselected a track --> repaint the tracks panel redrawDetection3(); } - /** Called when TSP List change */ - public void TrackEditorProcessorChange(ChangeEvent e) - { + /** + * Called when TSP List change + */ + public void TrackEditorProcessorChange(ChangeEvent e) { clearDetectionsAndReDisplay(); } @Override - public void viewerChanged(ViewerEvent event) - { - if (event.getDim() == DimensionId.T) - { + public void viewerChanged(ViewerEvent event) { + if (event.getDim() == DimensionId.T) { timeCursor.currentT = event.getSource().getPositionT(); // trackPool.fireTrackEditorProcessorChange(); // clearDetectionsAndReDisplay(); @@ -1272,42 +1204,36 @@ public class TrackPanel extends JPanel implements MouseListener, MouseMotionList // main listener - public void displaySequenceChanged() - { + public void displaySequenceChanged() { setupViewerListener(); } - public void setEnableLeftPanelTrackDisplay(boolean selected) - { + public void setEnableLeftPanelTrackDisplay(boolean selected) { this.enableLeftPanelTrackDisplay = selected; redrawDetection3(); } @Override - public void viewerClosed(Viewer viewer) - { + public void viewerClosed(Viewer viewer) { setupViewerListener(); } @Override - public void viewerOpened(Viewer viewer) - { + public void viewerOpened(Viewer viewer) { setupViewerListener(); } @Override - public void sequenceOpened(Sequence sequence) - { + public void sequenceOpened(Sequence sequence) { setupViewerListener(); } @Override - public void sequenceClosed(Sequence sequence) - { + public void sequenceClosed(Sequence sequence) { setupViewerListener(); } diff --git a/src/main/java/plugins/fab/trackmanager/TrackPool.java b/src/main/java/plugins/fab/trackmanager/TrackPool.java index 5df0025e7412a8d36c90a22c0e9d8e908b1dd8ae..280a9fb7e6c5a567d6bfe52a7a84d76f0255cfd6 100644 --- a/src/main/java/plugins/fab/trackmanager/TrackPool.java +++ b/src/main/java/plugins/fab/trackmanager/TrackPool.java @@ -1,20 +1,20 @@ /* - * Copyright 2010, 2011 Institut Pasteur. - * + * Copyright 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 <http://www.gnu.org/licenses/>. + * along with ICY. If not, see <https://www.gnu.org/licenses/>. */ package plugins.fab.trackmanager; @@ -33,61 +33,54 @@ import plugins.nchenouard.spot.Detection; /** * TrackPool object used for TrackEditor. A trackPool is as a pool of TrackSegment. - * + * * @author Fabrice de Chaumont */ -public class TrackPool -{ +public class TrackPool { - private TrackManagerPainter tePainter; + private final TrackManagerPainter tePainter; - private ArrayList<PluginTrackManagerProcessor> trackManagerProcessorList = new ArrayList<PluginTrackManagerProcessor>(); + private final ArrayList<PluginTrackManagerProcessor> trackManagerProcessorList = new ArrayList<>(); - private ArrayList<TrackManagerProcessorListener> trackEditorProcessorListener = new ArrayList<TrackManagerProcessorListener>(); + private final ArrayList<TrackManagerProcessorListener> trackEditorProcessorListener = new ArrayList<>(); - public TrackPool() - { + public TrackPool() { tePainter = new TrackManagerPainter(this); } - public ArrayList<PluginTrackManagerProcessor> getTrackManagerProcessorList() - { + public ArrayList<PluginTrackManagerProcessor> getTrackManagerProcessorList() { return trackManagerProcessorList; } - public void addTrackProcessor(PluginTrackManagerProcessor tep) - { + public void addTrackProcessor(PluginTrackManagerProcessor tep) { trackManagerProcessorList.add(tep); fireTrackEditorProcessorChange(); } - /** Add a listener that will send changes on TrackEditorProcessor's ArrayList */ - public void addTrackProcessorListener(TrackManagerProcessorListener tepl) - { - trackEditorProcessorListener.add(tepl); + /** + * Add a listener that will send changes on TrackEditorProcessor's ArrayList + */ + public void addTrackProcessorListener(TrackManagerProcessorListener tmpl) { + trackEditorProcessorListener.add(tmpl); } - public void computeTrackProcessor() - { - for (PluginTrackManagerProcessor tep : trackManagerProcessorList) - { + public void computeTrackProcessor() { + for (PluginTrackManagerProcessor tep : trackManagerProcessorList) { long startTimeInNs = System.nanoTime(); tep.Compute(); tep.setPerformance((int) ((System.nanoTime() - startTimeInNs) / 1000000f)); } } - public void clearTracks() - { + public void clearTracks() { for (TrackGroup trackGroup : getTrackGroupList()) trackGroup.getTrackSegmentList().clear(); fireTrackEditorProcessorChange(); } - public static boolean linkExists(List<Link> links, TrackSegment start, TrackSegment end) - { + public static boolean linkExists(List<Link> links, TrackSegment start, TrackSegment end) { // check if the link already exists for (Link link : links) if ((link.start == start) && (link.end == end)) @@ -96,65 +89,56 @@ public class TrackPool return false; } - public static boolean isLinkExists(List<TrackGroup> groups, TrackSegment start, TrackSegment end) - { + public static boolean isLinkExists(List<TrackGroup> groups, TrackSegment start, TrackSegment end) { return linkExists(getLinks(groups), start, end); } - public boolean isLinkExists(TrackSegment start, TrackSegment end) - { + public boolean isLinkExists(TrackSegment start, TrackSegment end) { return linkExists(getLinks(), start, end); } - public static void createLink(List<TrackGroup> groups, TrackSegment start, TrackSegment end) - { - if (!isLinkExists(groups, start, end)) - { + public static void createLink(List<TrackGroup> groups, TrackSegment start, TrackSegment end) { + if (!isLinkExists(groups, start, end)) { start.nextList.add(end); end.previousList.add(start); } } - public void createLink(TrackSegment start, TrackSegment end) - { - if (!isLinkExists(start, end)) - { + public void createLink(TrackSegment start, TrackSegment end) { + if (!isLinkExists(start, end)) { start.nextList.add(end); end.previousList.add(start); } } - /** Creates a virtual track */ - public void createVirtualTrackWith2Detection(Detection detectionStart, Detection detectionEnd) - { + /** + * Creates a virtual track + */ + public void createVirtualTrackWith2Detection(Detection detectionStart, Detection detectionEnd) { TrackSegment segmentStart = getTrackSegmentWithDetection(detectionStart); TrackSegment segmentEnd = getTrackSegmentWithDetection(detectionEnd); - if (segmentStart == segmentEnd) - { + if (segmentStart == segmentEnd) { MessageDialog.showDialog("Can't link 2 detections belonging to the same track.", MessageDialog.INFORMATION_MESSAGE); return; } - if (segmentStart.getOwnerTrackGroup() != segmentStart.getOwnerTrackGroup()) - { + if (segmentStart.getOwnerTrackGroup() != segmentStart.getOwnerTrackGroup()) { MessageDialog.showDialog("The two tracks should be from the same track group.", MessageDialog.INFORMATION_MESSAGE); return; } - if (detectionStart.getT() >= detectionEnd.getT()) - { + if (detectionStart.getT() >= detectionEnd.getT()) { MessageDialog.showDialog("Can't create a backward link.", MessageDialog.INFORMATION_MESSAGE); return; } // check if detection are at start and end of their tracksegment. { - if (detectionStart != segmentStart.getLastDetection()) - { + if (detectionStart != segmentStart.getLastDetection()) { // The detection is not the last of the track. // Must split the start track. @@ -165,8 +149,7 @@ public class TrackPool segmentStart = getTrackSegmentWithDetection(detectionStart); } - if (detectionEnd != segmentEnd.getFirstDetection()) - { + if (detectionEnd != segmentEnd.getFirstDetection()) { // The detection is not the first of the track. // Must split the end track. @@ -184,12 +167,10 @@ public class TrackPool // check if start detection is t-1 end detection. // if not, creates a bridge with a tracksegment of virtual detections. - if (detectionEnd.getT() - detectionStart.getT() != 1) - { + if (detectionEnd.getT() - detectionStart.getT() != 1) { TrackSegment vts = new TrackSegment(); - for (int t = detectionStart.getT() + 1; t < detectionEnd.getT(); t++) - { + for (int t = detectionStart.getT() + 1; t < detectionEnd.getT(); t++) { // linear interpolation. double xstart = detectionStart.getX(); @@ -236,17 +217,14 @@ public class TrackPool createLink(vts, segmentEnd); new AnnounceFrame("Link(s) created", 2); } - else - { + else { // segmentEnd.setTrackGroup( segmentStart.getTrackGroup() ); - if (isLinkExists(segmentStart, segmentEnd)) - { + if (isLinkExists(segmentStart, segmentEnd)) { removeLink(segmentStart, segmentEnd); new AnnounceFrame("Link deleted", 2); } - else - { + else { createLink(segmentStart, segmentEnd); new AnnounceFrame("Link created", 2); } @@ -257,14 +235,11 @@ public class TrackPool // ****** check and remove identical links // int nbIdenticalLink = 0; ArrayList<Link> linkList = getLinks(); - for (Link l1 : linkList) - { - for (Link l2 : linkList) - { + for (Link l1 : linkList) { + for (Link l2 : linkList) { if (l1.getStartDetection() == l2.getStartDetection()) if (l1.getEndDetection() == l2.getEndDetection()) - if (l1 != l2) - { + if (l1 != l2) { // nbIdenticalLink++; removeLink(l1.getStartSegment(), l2.getEndSegment()); // System.err.println( "REMOVING DUPLICATED LINK"); @@ -279,9 +254,10 @@ public class TrackPool // } } - /** Creates a virtual track */ - public void createVirtualTrackWith2TrackDetection(Detection detectionStart, Detection detectionEnd) - { + /** + * Creates a virtual track + */ + public void createVirtualTrackWith2TrackDetection(Detection detectionStart, Detection detectionEnd) { // check if both sides of the link are TrackDetectionComponents. if (detectionStart == null) @@ -296,24 +272,23 @@ public class TrackPool createVirtualTrackWith2Detection(detectionStart, detectionEnd); } - /** cuts track after detection */ - public void cutTrackAfterDetection(Detection d) - { + /** + * cuts track after detection + */ + public void cutTrackAfterDetection(Detection d) { TrackSegment ts = getTrackSegmentWithDetection(d); splitTrackSegment(ts, ts.getDetectionList().indexOf(d), false); new AnnounceFrame("Track split", 2); } - public void deleteSelectedLink() - { + public void deleteSelectedLink() { // System.out.println("debug delete selected link"); ArrayList<Link> links = getLinks(); - ArrayList<Link> linksClone = new ArrayList<Link>(links); + ArrayList<Link> linksClone = new ArrayList<>(links); - for (Link link : linksClone) - { + for (Link link : linksClone) { // System.out.println( "link: " + link ); // TrackSegment tsEndtest = getTrackSegmentWithDetection(link.getEndDetection()); @@ -321,8 +296,7 @@ public class TrackPool // System.out.println( "end ts all selected: " + tsEndtest.isAllDetectionSelected() ); // System.out.println( "start ts all selected: " + tsStarttest.isAllDetectionSelected() ); - if (link.getStartDetection().isSelected() && link.getEndDetection().isSelected()) - { + if (link.getStartDetection().isSelected() && link.getEndDetection().isSelected()) { // System.out.println("Link selected " + link ); // System.out.println( "debug found link with selection"); links.remove(link); @@ -345,14 +319,11 @@ public class TrackPool fireTrackEditorProcessorChange(); } - public void deleteSelectedTracks() - { + public void deleteSelectedTracks() { beginUpdate(); - ArrayList<TrackSegment> tsListClone = new ArrayList<TrackSegment>(getTrackSegmentList()); - for (TrackSegment ts : tsListClone) - { - if (ts.isAllDetectionSelected()) - { + ArrayList<TrackSegment> tsListClone = new ArrayList<>(getTrackSegmentList()); + for (TrackSegment ts : tsListClone) { + if (ts.isAllDetectionSelected()) { deleteTrack(ts); } } @@ -361,43 +332,36 @@ public class TrackPool } /** - * @param ts * @return null if no trackgroup contains the tracksegment */ - public TrackGroup getTrackGroupContainingSegment(TrackSegment ts) - { + public TrackGroup getTrackGroupContainingSegment(TrackSegment ts) { return ts.getOwnerTrackGroup(); } - public void deleteTrack(TrackSegment ts) - { + public void deleteTrack(TrackSegment ts) { // System.out.println("----"); // System.out.println("Track segment id: " + ts.toString() ); TrackGroup trackGroup = getTrackGroupContainingSegment(ts); - if (trackGroup == null) - { + if (trackGroup == null) { System.out.println( - "Can't delete The track segment " + ts.toString() + " Reason: it is not in any trackGroup"); + "Can't delete The track segment " + ts + " Reason: it is not in any trackGroup"); return; } trackGroup.getTrackSegmentList().remove(ts); ArrayList<Link> links = getLinks(); - ArrayList<Link> linksClone = new ArrayList<Link>(links); + ArrayList<Link> linksClone = new ArrayList<>(links); - for (Link link : linksClone) - { - if (ts.containsDetection(link.getStartDetection())) - { + for (Link link : linksClone) { + if (ts.containsDetection(link.getStartDetection())) { links.remove(link); TrackSegment tsEnd = getTrackSegmentWithDetection(link.getEndDetection()); tsEnd.removePrevious(ts); } - if (ts.containsDetection(link.getEndDetection())) - { + if (ts.containsDetection(link.getEndDetection())) { links.remove(link); TrackSegment tsStart = getTrackSegmentWithDetection(link.getStartDetection()); tsStart.removeNext(ts); @@ -410,51 +374,38 @@ public class TrackPool } - @Override - protected void finalize() throws Throwable - { - - tePainter = null; - super.finalize(); - } - boolean isUpdating = false; - public void beginUpdate() - { + public void beginUpdate() { isUpdating = true; } - public void endUpdate() - { + public void endUpdate() { isUpdating = false; } - public void fireTrackEditorProcessorChange() - { - if (!isUpdating) - { - for (TrackManagerProcessorListener tepl : trackEditorProcessorListener) - tepl.TrackEditorProcessorChange(new ChangeEvent(this)); + public void fireTrackEditorProcessorChange() { + if (!isUpdating) { + for (TrackManagerProcessorListener tmpl : trackEditorProcessorListener) + tmpl.TrackEditorProcessorChange(new ChangeEvent(this)); } } - /** If only one link is linking 2 tracks, it means they could be the same track */ - public void fuseAllTracks() - { + /** + * If only one link is linking 2 tracks, it means they could be the same track + */ + public void fuseAllTracks() { // System.out.println("Start Fusion."); boolean fuseOperationPerformed = true; // flag to restart fuse operation from zero each time a fuse has been performed. - while (fuseOperationPerformed) - { + while (fuseOperationPerformed) { fuseOperationPerformed = false; // System.out.println("****** re-Start Fusion."); - ArrayList<TrackSegment> trackSegmentListClone = new ArrayList<TrackSegment>(getTrackSegmentList()); - for (TrackSegment ts : trackSegmentListClone) - { + ArrayList<TrackSegment> trackSegmentListClone = new ArrayList<>(getTrackSegmentList()); + for (TrackSegment ts : trackSegmentListClone) { // System.out.println("Computing trackSegment # " + trackSegmentListClone.indexOf( ts ) ); if (ts.nextList.size() == 1) // if the track has only one successor. if (ts.nextList.get(0).previousList.size() == 1) // If successor has only one predecessor. @@ -473,25 +424,22 @@ public class TrackPool /** * Fusing 2 tracks ts1 is one step before ts2. */ - public void fuseTrack(TrackSegment ts1, TrackSegment ts2) - { + public void fuseTrack(TrackSegment ts1, TrackSegment ts2) { // System.out.println("debug fuse track: fusing "); // System.out.println("ts1 = " + ts1); // System.out.println("ts2 = " + ts2); - for (Detection detection : ts2.getDetectionList()) - { + for (Detection detection : ts2.getDetectionList()) { ts1.addDetection(detection); // System.out.println("Adding 1 detection to ts1. t=" + detection.getT() ); } // System.out.println("Copy next List"); - ts1.nextList = new ArrayList<TrackSegment>(new ArrayList<TrackSegment>(ts2.nextList)); + ts1.nextList = new ArrayList<>(new ArrayList<>(ts2.nextList)); // ts1.getDetectionList().addAll(ts2.getDetectionList()); - while (ts2.getDetectionList().size() > 0) - { + while (ts2.getDetectionList().size() > 0) { Detection detection = ts2.getFirstDetection(); ts2.removeDetection(detection); // System.out.println("Remove 1 detection to ts2. t=" + detection.getT() ); @@ -503,47 +451,41 @@ public class TrackPool fireTrackEditorProcessorChange(); } - public ArrayList<Detection> getAllDetection() - { - ArrayList<Detection> detectionList = new ArrayList<Detection>(); + public ArrayList<Detection> getAllDetection() { + ArrayList<Detection> detectionList = new ArrayList<>(); for (TrackGroup trackGroup : getTrackGroupList()) for (TrackSegment tracksegment : trackGroup.getTrackSegmentList()) - for (Detection detection : tracksegment.getDetectionList()) - { - detectionList.add(detection); - } + detectionList.addAll(tracksegment.getDetectionList()); return detectionList; } - /** return distance between 2 detections */ - public double getDistance(Detection d1, Detection d2) - { + /** + * return distance between 2 detections + */ + public double getDistance(Detection d1, Detection d2) { return getDistance(d1.getX(), d1.getY(), d1.getZ(), d2.getX(), d2.getY(), d2.getZ()); } - /** return distance between 2 pos */ - public double getDistance(double x1, double y1, double z1, double x2, double y2, double z2) - { - double distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2)); - return distance; + /** + * return distance between 2 pos + */ + public double getDistance(double x1, double y1, double z1, double x2, double y2, double z2) { + return Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2)); } - public ArrayList<Link> getLinks() - { - ArrayList<Link> linkarray = new ArrayList<Link>(); + public ArrayList<Link> getLinks() { + ArrayList<Link> linkarray = new ArrayList<>(); // System.out.println("debug : getLinks"); - for (int trackSegmentIndex = 0; trackSegmentIndex < getTrackSegmentList().size(); trackSegmentIndex++) - { + for (int trackSegmentIndex = 0; trackSegmentIndex < getTrackSegmentList().size(); trackSegmentIndex++) { TrackSegment ts = getTrackSegmentList().get(trackSegmentIndex); // for ( int i = 0 ; i < ts.previousList.size() ; i++ ) // { // linkarray.add( new Link( ts.previousList.get( i ) , ts ) ); // } - for (int i = 0; i < ts.nextList.size(); i++) - { + for (int i = 0; i < ts.nextList.size(); i++) { linkarray.add(new Link(ts, ts.nextList.get(i))); } @@ -552,9 +494,8 @@ public class TrackPool return linkarray; } - public static List<Link> getLinks(List<TrackGroup> groups) - { - final List<Link> result = new ArrayList<Link>(); + public static List<Link> getLinks(List<TrackGroup> groups) { + final List<Link> result = new ArrayList<>(); final List<TrackSegment> segments = getTrackSegmentList(groups); for (TrackSegment segment : segments) @@ -567,8 +508,7 @@ public class TrackPool // FIXME: put a WeakReference in here private Sequence displaySequence = null; - public void setDisplaySequence(Sequence displaySequence) - { + public void setDisplaySequence(Sequence displaySequence) { this.displaySequence = displaySequence; @@ -578,56 +518,49 @@ public class TrackPool removePainter(); // add the painter to the selected display sequence. - if (displaySequence != null) - { + if (displaySequence != null) { // System.out.println("adding the painter"); displaySequence.addOverlay(tePainter); } // fire a sequenceChanged to all trackManagerProcessor - for (PluginTrackManagerProcessor ptmp : trackManagerProcessorList) - { + for (PluginTrackManagerProcessor ptmp : trackManagerProcessorList) { ptmp.displaySequenceChanged(); } // tell to trackPanel the display sequence has changed. - if (trackManager != null) - { - if (trackManager.trackPanel != null) - { + if (trackManager != null) { + if (trackManager.trackPanel != null) { trackManager.trackPanel.displaySequenceChanged(); } } } - public Sequence getDisplaySequence() - { + public Sequence getDisplaySequence() { return displaySequence; } TrackManager trackManager; - /** @deprecated Use getTrackManager instead */ - public TrackManager getTrackEditor() - { + /** + * @deprecated Use getTrackManager instead + */ + public TrackManager getTrackEditor() { return trackManager; } - public TrackManager getTrackManager() - { + public TrackManager getTrackManager() { return trackManager; } - public TrackManagerPainter getTrackPainter() - { + public TrackManagerPainter getTrackPainter() { return tePainter; } /** * @return the pool of tracksegment of all the trackgroup */ - public static List<TrackSegment> getTrackSegmentList(List<TrackGroup> groups) - { - final List<TrackSegment> result = new ArrayList<TrackSegment>(); + public static List<TrackSegment> getTrackSegmentList(List<TrackGroup> groups) { + final List<TrackSegment> result = new ArrayList<>(); for (TrackGroup group : groups) result.addAll(group.getTrackSegmentList()); @@ -638,26 +571,24 @@ public class TrackPool /** * @return the pool of tracksegment of all the trackgroup */ - public ArrayList<TrackSegment> getTrackSegmentList() - { + public ArrayList<TrackSegment> getTrackSegmentList() { - ArrayList<TrackSegment> trackSegmentList = new ArrayList<TrackSegment>(); - for (TrackGroup group : getTrackGroupList()) - { + ArrayList<TrackSegment> trackSegmentList = new ArrayList<>(); + for (TrackGroup group : getTrackGroupList()) { trackSegmentList.addAll(group.getTrackSegmentList()); } return trackSegmentList; } - /** find the tracksegment containing the given detection */ - public TrackSegment getTrackSegmentWithDetection(Detection detection) - { + /** + * find the tracksegment containing the given detection + */ + public TrackSegment getTrackSegmentWithDetection(Detection detection) { ArrayList<TrackSegment> trackSegmentList = getTrackSegmentList(); - for (TrackSegment ts : trackSegmentList) - { + for (TrackSegment ts : trackSegmentList) { if (ts.containsDetection(detection)) return ts; } @@ -665,33 +596,28 @@ public class TrackPool return null; } - public static ArrayList<TrackSegment> loadTracks(File f) throws Exception - { + // FIXME: 05/04/2023 does nothing + public static ArrayList<TrackSegment> loadTracks(File f) { - ArrayList<TrackSegment> inputTrackSegmentList = new ArrayList<TrackSegment>(); - ArrayList<TrackSegment> targetTrackSegmentList = new ArrayList<TrackSegment>(); + ArrayList<TrackSegment> inputTrackSegmentList = new ArrayList<>(); + ArrayList<TrackSegment> targetTrackSegmentList = new ArrayList<>(); - for (TrackSegment ts : inputTrackSegmentList) - { - if (ts.getFirstDetection() == null || ts.getLastDetection() == null) - { + for (TrackSegment ts : inputTrackSegmentList) { + if (ts.getFirstDetection() == null || ts.getLastDetection() == null) { System.out.println("Warning, found and removed empty track segment"); continue; } boolean skipTrackSegment = false; - for (TrackSegment ts2 : ts.nextList) - { - if (ts2.getFirstDetection() == null || ts2.getLastDetection() == null) - { + for (TrackSegment ts2 : ts.nextList) { + if (ts2.getFirstDetection() == null || ts2.getLastDetection() == null) { skipTrackSegment = true; break; } } - if (skipTrackSegment) - { + if (skipTrackSegment) { System.out.println("Warning, found and removed empty track segment"); continue; } @@ -701,16 +627,16 @@ public class TrackPool return targetTrackSegmentList; } - public void moveTrackToIndex(TrackSegment ts, int index) - { + public void moveTrackToIndex(TrackSegment ts, int index) { // trackSegmentList.remove( ts ); // if ( index > trackSegmentList.size() ) index = trackSegmentList.size(); // trackSegmentList.add( index , ts ); } - /** remove a link between 2 track segment. */ - public void removeLink(TrackSegment start, TrackSegment end) - { + /** + * remove a link between 2 track segment. + */ + public void removeLink(TrackSegment start, TrackSegment end) { // int nb = 0; // while ( start.nextList.contains( end ) ) // { @@ -730,34 +656,29 @@ public class TrackPool // } } - public void removeTrackProcessor(PluginTrackManagerProcessor tep) - { + public void removeTrackProcessor(PluginTrackManagerProcessor tep) { trackManagerProcessorList.remove(tep); fireTrackEditorProcessorChange(); } - /** remove a listener that will send changes on TrackEditorProcessor's ArrayList */ - public void removeTrackProcessorListener(TrackManagerProcessorListener tepl) - { - trackEditorProcessorListener.remove(tepl); + /** + * remove a listener that will send changes on TrackEditorProcessor's ArrayList + */ + public void removeTrackProcessorListener(TrackManagerProcessorListener tmpl) { + trackEditorProcessorListener.remove(tmpl); } - public void selectAllTracks() - { - for (TrackSegment ts : getTrackSegmentList()) - { + public void selectAllTracks() { + for (TrackSegment ts : getTrackSegmentList()) { ts.setAllDetectionSelected(true); } fireTrackEditorProcessorChange(); } - public void selectTracksByLength(int lowVal, int highVal) - { + public void selectTracksByLength(int lowVal, int highVal) { - for (TrackSegment ts : getTrackSegmentList()) - { - if (ts.getDetectionList().size() >= lowVal && ts.getDetectionList().size() <= highVal) - { + for (TrackSegment ts : getTrackSegmentList()) { + if (ts.getDetectionList().size() >= lowVal && ts.getDetectionList().size() <= highVal) { ts.setAllDetectionSelected(true); } } @@ -765,17 +686,14 @@ public class TrackPool } - public void unselectAllTracks() - { - for (TrackSegment ts : getTrackSegmentList()) - { + public void unselectAllTracks() { + for (TrackSegment ts : getTrackSegmentList()) { ts.setAllDetectionSelected(false); } fireTrackEditorProcessorChange(); } - public void invertSelection() - { + public void invertSelection() { for (TrackSegment ts : getTrackSegmentList()) for (Detection d : ts.getDetectionList()) d.setSelected(!d.isSelected()); @@ -784,24 +702,17 @@ public class TrackPool /** * Splits a track into 2 tracks. - * - * @param ts - * The track to split - Important NOTE: This track will be destructed after call. - * @param lastIndexOfFirstTrack - * Index of where the track should be splited. - * - * <pre> - * @param CreateLinkBetweenSplittedTrack if true, creates a link between splitted tracks. - * @return an ArrayList with the 2 new track created. - * Track : TTTTTT - * Split Index : S - * Result : 111 - * 222 - * </pre> + * + * @param ts The track to split - Important NOTE: This track will be destructed after call. + * @param lastIndexOfFirstTrack Index of where the track should be split. + * @param createLinkBetweenSplitTrack if true, creates a link between split tracks. + * @return an ArrayList with the 2 new track created. + * Track : TTTTTT + * Split Index : S + * Result : 111 + * 222 */ - public ArrayList<TrackSegment> splitTrackSegment(TrackSegment ts, int lastIndexOfFirstTrack, - boolean CreateLinkBetweenSplittedTrack) - { + public ArrayList<TrackSegment> splitTrackSegment(TrackSegment ts, int lastIndexOfFirstTrack, boolean createLinkBetweenSplitTrack) { // System.out.println("Entering split track segment."); // last version, but still need to consider the track group @@ -809,8 +720,7 @@ public class TrackPool TrackSegment ts2 = new TrackSegment(); // copy first segment detections. - for (int i = 0; i < lastIndexOfFirstTrack + 1; i++) - { + for (int i = 0; i < lastIndexOfFirstTrack + 1; i++) { // old: ts1.detectionList.add( ts.detectionList.get( i ) ); ts1.addDetection(ts.getDetectionAt(i)); } @@ -819,8 +729,7 @@ public class TrackPool ts1.previousList.addAll(ts.previousList); // copy second segment detections. - for (int i = lastIndexOfFirstTrack + 1; i < ts.getDetectionList().size(); i++) - { + for (int i = lastIndexOfFirstTrack + 1; i < ts.getDetectionList().size(); i++) { // old: ts2.detectionList.add( ts.detectionList.get( i ) ); ts2.addDetection(ts.getDetectionAt(i)); } @@ -828,24 +737,20 @@ public class TrackPool // copy second segment next list. ts2.nextList.addAll(ts.nextList); - for (TrackSegment tracksegment : getTrackSegmentList()) - { + for (TrackSegment tracksegment : getTrackSegmentList()) { // change pointer of others previouslisttracks to point here. - for (TrackSegment tracksegmentprevious : tracksegment.previousList) - { + for (TrackSegment tracksegmentprevious : tracksegment.previousList) { if (tracksegmentprevious == ts) tracksegmentprevious = ts2; } // change pointer of others nextlisttracks to point here. - for (TrackSegment tracksegmentnext : tracksegment.nextList) - { + for (TrackSegment tracksegmentnext : tracksegment.nextList) { if (tracksegmentnext == ts) tracksegmentnext = ts1; } } - if (CreateLinkBetweenSplittedTrack) - { + if (createLinkBetweenSplitTrack) { createLink(ts1, ts2); } @@ -872,17 +777,16 @@ public class TrackPool // System.out.println("ts1 trackGroup = " + ts1.getOwnerTrackGroup() ); // System.out.println("ts2 trackGroup = " + ts1.getOwnerTrackGroup() ); - ArrayList<TrackSegment> trackSegmentReturnList = new ArrayList<TrackSegment>(); + ArrayList<TrackSegment> trackSegmentReturnList = new ArrayList<>(); trackSegmentReturnList.add(ts1); trackSegmentReturnList.add(ts2); return trackSegmentReturnList; } - public ArrayList<TrackGroup> getTrackGroupList() - { + public ArrayList<TrackGroup> getTrackGroupList() { - ArrayList<TrackGroup> trackGroupList = new ArrayList<TrackGroup>(); + ArrayList<TrackGroup> trackGroupList = new ArrayList<>(); for (SwimmingObject result : resultList) trackGroupList.add((TrackGroup) result.getObject()); @@ -890,13 +794,13 @@ public class TrackPool return trackGroupList; } - /** List of results where trackGroup has been found to process. */ - ArrayList<SwimmingObject> resultList = new ArrayList<SwimmingObject>(); + /** + * List of results where trackGroup has been found to process. + */ + ArrayList<SwimmingObject> resultList = new ArrayList<>(); - public void addResult(SwimmingObject result) - { - if (!(result.getObject() instanceof TrackGroup)) - { + public void addResult(SwimmingObject result) { + if (!(result.getObject() instanceof TrackGroup)) { // System.out.println("Object " + result + " is not recognized as a TrackGroup."); return; } @@ -905,15 +809,13 @@ public class TrackPool } - public void removeResult(SwimmingObject result) - { + public void removeResult(SwimmingObject result) { if (result == null) return; resultList.remove(result); - if (result.getObject() instanceof TrackGroup) - { + if (result.getObject() instanceof TrackGroup) { final TrackGroup tg = (TrackGroup) result.getObject(); // remove track segment from hash map @@ -925,21 +827,18 @@ public class TrackPool /** * removes the painter from all sequences. */ - public void removePainter() - { + public void removePainter() { // System.out.println("remove painter"); List<Sequence> sequenceList = Icy.getMainInterface().getSequencesContaining(tePainter); - for (Sequence sequence : sequenceList) - { + for (Sequence sequence : sequenceList) { sequence.removeOverlay(tePainter); } } - public int getTrackIndex(TrackSegment ts) - { + public int getTrackIndex(TrackSegment ts) { return getTrackSegmentList().indexOf(ts); @@ -948,17 +847,13 @@ public class TrackPool /** * @return the timepoint corresponding to the last detection of all the trackgroup. */ - public int getLastDetectionTimePoint() - { + public int getLastDetectionTimePoint() { int maxT = 0; - for (TrackGroup tg : getTrackGroupList()) - { - for (TrackSegment ts : tg.getTrackSegmentList()) - { + for (TrackGroup tg : getTrackGroupList()) { + for (TrackSegment ts : tg.getTrackSegmentList()) { Detection d = ts.getLastDetection(); - if (d != null) - { + if (d != null) { if (d.getT() > maxT) maxT = d.getT(); } @@ -970,14 +865,11 @@ public class TrackPool /** * @return the number of track considering all the track groups. */ - public int getTotalNumberOfTrack() - { + public int getTotalNumberOfTrack() { int total = 0; - for (TrackGroup tg : getTrackGroupList()) - { + for (TrackGroup tg : getTrackGroupList()) { total += tg.getTrackSegmentList().size(); } return total; } - } diff --git a/src/main/java/plugins/fab/trackmanager/TrackSegment.java b/src/main/java/plugins/fab/trackmanager/TrackSegment.java index 72ca4e2c13c1c332ba32a0998b8db43a6cc84af3..5dd71b628811dd9c403823d52752a33c32be205d 100644 --- a/src/main/java/plugins/fab/trackmanager/TrackSegment.java +++ b/src/main/java/plugins/fab/trackmanager/TrackSegment.java @@ -1,20 +1,20 @@ /* - * Copyright 2010, 2011 Institut Pasteur. - * + * Copyright 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 <http://www.gnu.org/licenses/>. + * along with ICY. If not, see <https://www.gnu.org/licenses/>. */ package plugins.fab.trackmanager; @@ -30,33 +30,29 @@ import plugins.nchenouard.spot.Detection; /** * TrackSegment is a pool of consecutive detection. - * + * * @author Fabrice de Chaumont * @author Stephane */ -public class TrackSegment implements Cloneable -{ +public class TrackSegment implements Cloneable { // better to use weak reference in the map - protected static Map<Integer, Reference<TrackSegment>> idKeyHashMapList = new HashMap<Integer, Reference<TrackSegment>>(); // 1-1 hashmap. + protected final static Map<Integer, Reference<TrackSegment>> idKeyHashMapList = new HashMap<>(); // 1-1 hashmap. - List<Detection> detectionList = new ArrayList<Detection>(); - List<TrackSegment> previousList = new ArrayList<TrackSegment>(); - List<TrackSegment> nextList = new ArrayList<TrackSegment>(); + List<Detection> detectionList = new ArrayList<>(); + List<TrackSegment> previousList = new ArrayList<>(); + List<TrackSegment> nextList = new ArrayList<>(); private TrackGroup ownerTrackGroup = null; private int id = 0; - public static TrackSegment getTrackSegmentById(int id) - { + public static TrackSegment getTrackSegmentById(int id) { final Integer iid = Integer.valueOf(id); - synchronized (idKeyHashMapList) - { + synchronized (idKeyHashMapList) { final Reference<TrackSegment> ref = idKeyHashMapList.get(iid); // null ? --> can remove it from the hashmap - if (ref.get() == null) - { + if (ref.get() == null) { idKeyHashMapList.remove(iid); } @@ -64,16 +60,16 @@ public class TrackSegment implements Cloneable } } - public TrackSegment() - { + public TrackSegment() { super(); generateId(); } - /** Constructor with a list of detection */ - public TrackSegment(ArrayList<Detection> detectionList) - { + /** + * Constructor with a list of detection + */ + public TrackSegment(ArrayList<Detection> detectionList) { super(); this.detectionList = detectionList; @@ -92,19 +88,17 @@ public class TrackSegment implements Cloneable } @Override - protected Object clone() throws CloneNotSupportedException - { + protected Object clone() throws CloneNotSupportedException { TrackSegment cloneSegment = (TrackSegment) super.clone(); - for (Detection detection : detectionList) - { + for (Detection detection : detectionList) { Detection cloneDetection = (Detection) detection.clone(); // cloneDetection.setOwnerTrackSegment(cloneSegment); cloneSegment.detectionList.add(cloneDetection); } - previousList = new ArrayList<TrackSegment>(previousList); - nextList = new ArrayList<TrackSegment>(nextList); + previousList = new ArrayList<>(previousList); + nextList = new ArrayList<>(nextList); generateId(); @@ -112,34 +106,27 @@ public class TrackSegment implements Cloneable } - public void removeId() - { - synchronized (idKeyHashMapList) - { + public void removeId() { + synchronized (idKeyHashMapList) { idKeyHashMapList.remove(Integer.valueOf(id)); } } - public int getId() - { + public int getId() { return id; } - public void generateId() - { + public void generateId() { // just for safety removeId(); - synchronized (idKeyHashMapList) - { - while (true) - { + synchronized (idKeyHashMapList) { + while (true) { final Integer key = Integer.valueOf(Random.nextInt()); // available ? - if (idKeyHashMapList.get(key) == null) - { - idKeyHashMapList.put(key, new WeakReference<TrackSegment>(this)); + if (idKeyHashMapList.get(key) == null) { + idKeyHashMapList.put(key, new WeakReference<>(this)); id = key.intValue(); return; @@ -148,16 +135,13 @@ public class TrackSegment implements Cloneable } } - public void setId(int id) - { + public void setId(int id) { final Integer key = Integer.valueOf(id); - synchronized (idKeyHashMapList) - { + synchronized (idKeyHashMapList) { // available ? - if (idKeyHashMapList.get(key) == null) - { - idKeyHashMapList.put(key, new WeakReference<TrackSegment>(this)); + if (idKeyHashMapList.get(key) == null) { + idKeyHashMapList.put(key, new WeakReference<>(this)); this.id = key.intValue(); } else @@ -165,22 +149,25 @@ public class TrackSegment implements Cloneable } } - /** */ - public boolean containsDetection(Detection detection) - { + /** + * + */ + public boolean containsDetection(Detection detection) { return detectionList.contains(detection); } - /** set all dependent selection */ - public void setAllDetectionEnabled(boolean selected) - { + /** + * set all dependent selection + */ + public void setAllDetectionEnabled(boolean selected) { for (Detection d : detectionList) d.setEnabled(selected); } - /** is all dependent selection are enabled */ - public boolean isAllDetectionEnabled() - { + /** + * is all dependent selection are enabled + */ + public boolean isAllDetectionEnabled() { if (detectionList.isEmpty()) return false; @@ -192,16 +179,18 @@ public class TrackSegment implements Cloneable return result; } - /** set all dependent selection */ - public void setAllDetectionSelected(boolean selected) - { + /** + * set all dependent selection + */ + public void setAllDetectionSelected(boolean selected) { for (Detection d : detectionList) d.setSelected(selected); } - /** check if all dependent selection are selected */ - public boolean isAllDetectionSelected() - { + /** + * check if all dependent selection are selected + */ + public boolean isAllDetectionSelected() { if (detectionList.isEmpty()) return false; @@ -213,14 +202,13 @@ public class TrackSegment implements Cloneable return result; } - /** Add a detection in the segmentTrack */ - public void addDetection(Detection detection) - { - if (detectionList.size() > 0) - { + /** + * Add a detection in the segmentTrack + */ + public void addDetection(Detection detection) { + if (detectionList.size() > 0) { Detection detectionPrevious = getLastDetection(); - if (detection.getT() != detectionPrevious.getT() + 1) - { + if (detection.getT() != detectionPrevious.getT() + 1) { System.err.println( "TrackSegment : The detection must be added with consecutive T value. Detection was not added"); // throw new IllegalArgumentException(); @@ -238,67 +226,73 @@ public class TrackSegment implements Cloneable detectionList.add(detection); } - public void removeDetection(Detection detection) - { + public void removeDetection(Detection detection) { // detection.setOwnerTrackSegment(null); detectionList.remove(detection); } - /** Remove a detection in the segmentTrack */ - public void removeLastDetection() - { + /** + * Remove a detection in the segmentTrack + */ + public void removeLastDetection() { // getLastDetection().ownerTrackSegment = null; detectionList.remove(getLastDetection()); } - /** Add a TrackSegment before this trackSegment */ - public void addPrevious(TrackSegment trackSegment) - { + /** + * Add a TrackSegment before this trackSegment + */ + public void addPrevious(TrackSegment trackSegment) { previousList.add(trackSegment); trackSegment.nextList.add(this); } - /** Remove a TrackSegment before this trackSegment */ - public void removePrevious(TrackSegment trackSegment) - { + /** + * Remove a TrackSegment before this trackSegment + */ + public void removePrevious(TrackSegment trackSegment) { previousList.remove(trackSegment); trackSegment.nextList.remove(this); } - /** Add a TrackSegment after this trackSegment */ - public void addNext(TrackSegment trackSegment) - { + /** + * Add a TrackSegment after this trackSegment + */ + public void addNext(TrackSegment trackSegment) { nextList.add(trackSegment); trackSegment.previousList.add(this); } - /** Remove a TrackSegment after this trackSegment */ - public void removeNext(TrackSegment trackSegment) - { + /** + * Remove a TrackSegment after this trackSegment + */ + public void removeNext(TrackSegment trackSegment) { nextList.remove(trackSegment); trackSegment.previousList.remove(this); } - /** return first detection ( should be first in time too ) */ - public Detection getFirstDetection() - { + /** + * return first detection ( should be first in time too ) + */ + public Detection getFirstDetection() { if (detectionList.size() == 0) return null; return detectionList.get(0); } - /** return detection at index i */ - public Detection getDetectionAt(int i) - { + /** + * return detection at index i + */ + public Detection getDetectionAt(int i) { return detectionList.get(i); } - /** return detection at time t */ - public Detection getDetectionAtTime(int t) - { - for (Detection detection : detectionList) - { + /** + * return detection at time t + */ + public Detection getDetectionAtTime(int t) { + for (Detection detection : detectionList) { if (detection.getT() == t) return detection; } @@ -314,43 +308,41 @@ public class TrackSegment implements Cloneable * Detection * to be correctly updated. */ - public ArrayList<Detection> getDetectionList() - { + public ArrayList<Detection> getDetectionList() { return (ArrayList<Detection>) detectionList; } - /** return last detection ( should be last in time too ) */ - public Detection getLastDetection() - { + /** + * return last detection ( should be last in time too ) + */ + public Detection getLastDetection() { if (detectionList.size() == 0) return null; return detectionList.get(detectionList.size() - 1); } - /** return detection index */ - public int getDetectionIndex(Detection detection) - { + /** + * return detection index + */ + public int getDetectionIndex(Detection detection) { return detectionList.indexOf(detection); } - public void setOwnerTrackGroup(TrackGroup tg) - { + public void setOwnerTrackGroup(TrackGroup tg) { ownerTrackGroup = tg; } - public TrackGroup getOwnerTrackGroup() - { + public TrackGroup getOwnerTrackGroup() { return ownerTrackGroup; } - public void removeAllLinks() - { - List<TrackSegment> previousListCopy = new ArrayList<TrackSegment>(previousList); + public void removeAllLinks() { + List<TrackSegment> previousListCopy = new ArrayList<>(previousList); for (TrackSegment previousTrackSegment : previousListCopy) removePrevious(previousTrackSegment); - List<TrackSegment> nextListCopy = new ArrayList<TrackSegment>(nextList); + List<TrackSegment> nextListCopy = new ArrayList<>(nextList); for (TrackSegment nextTrackSegment : nextListCopy) removeNext(nextTrackSegment); } diff --git a/src/main/java/plugins/fab/trackmanager/blocks/LoadTracksFromXML.java b/src/main/java/plugins/fab/trackmanager/blocks/LoadTracksFromXML.java index 0b30ee1078540ec2ddf43618c8f945e0e8dd3e46..c9e44b5974340d0f14f6f0899f98c4ce58bcfa71 100644 --- a/src/main/java/plugins/fab/trackmanager/blocks/LoadTracksFromXML.java +++ b/src/main/java/plugins/fab/trackmanager/blocks/LoadTracksFromXML.java @@ -16,25 +16,21 @@ import plugins.fab.trackmanager.TrackManager; /** * Block to load a set of ROI from a file - * + * * @author Stephane */ -public class LoadTracksFromXML extends Plugin implements ROIBlock, PluginLibrary, PluginBundled -{ - final VarMutable file = new VarMutable("XML file", null) - { +public class LoadTracksFromXML extends Plugin implements ROIBlock, PluginLibrary, PluginBundled { + final VarMutable file = new VarMutable("XML file", null) { @Override - public boolean isAssignableFrom(@SuppressWarnings("rawtypes") Var source) - { + public boolean isAssignableFrom(Var source) { return (String.class == source.getType()) || (File.class == source.getType()); } }; final VarInteger groupIndex = new VarInteger("Group index", 0); - final Var<TrackGroup> tracks = new Var<TrackGroup>("Track group", new TrackGroup(null)); + final Var<TrackGroup> tracks = new Var<>("Track group", new TrackGroup(null)); @Override - public void run() - { + public void run() { final Object obj = file.getValue(); if (obj == null) return; @@ -53,22 +49,19 @@ public class LoadTracksFromXML extends Plugin implements ROIBlock, PluginLibrary } @Override - public void declareInput(VarList inputMap) - { + public void declareInput(VarList inputMap) { inputMap.add("file", file); inputMap.add("groupIndex", groupIndex); } @Override - public void declareOutput(VarList outputMap) - { + public void declareOutput(VarList outputMap) { outputMap.add("tracks", tracks); } @Override - public String getMainPluginClassName() - { + public String getMainPluginClassName() { return TrackManager.class.getName(); } } diff --git a/src/main/java/plugins/fab/trackmanager/blocks/SaveTracksToXML.java b/src/main/java/plugins/fab/trackmanager/blocks/SaveTracksToXML.java index c35bb0a76544a344c43633fd59db856824af7d7e..27229b293397695766273fef432f296daa79a0a7 100644 --- a/src/main/java/plugins/fab/trackmanager/blocks/SaveTracksToXML.java +++ b/src/main/java/plugins/fab/trackmanager/blocks/SaveTracksToXML.java @@ -15,24 +15,20 @@ import plugins.fab.trackmanager.TrackManager; /** * Block to save a set of ROI to a file - * + * * @author Stephane */ -public class SaveTracksToXML extends Plugin implements ROIBlock, PluginLibrary, PluginBundled -{ - final Var<TrackGroup> tracks = new Var<TrackGroup>("Track group", new TrackGroup(null)); - final VarMutable file = new VarMutable("XML file", null) - { +public class SaveTracksToXML extends Plugin implements ROIBlock, PluginLibrary, PluginBundled { + final Var<TrackGroup> tracks = new Var<>("Track group", new TrackGroup(null)); + final VarMutable file = new VarMutable("XML file", null) { @Override - public boolean isAssignableFrom(@SuppressWarnings("rawtypes") Var source) - { + public boolean isAssignableFrom(Var source) { return (String.class == source.getType()) || (File.class == source.getType()); } }; @Override - public void run() - { + public void run() { final TrackGroup group = tracks.getValue(); // nothing to do if (group == null) @@ -54,21 +50,18 @@ public class SaveTracksToXML extends Plugin implements ROIBlock, PluginLibrary, } @Override - public void declareInput(VarList inputMap) - { + public void declareInput(VarList inputMap) { inputMap.add("tracks", tracks); inputMap.add("file", file); } @Override - public void declareOutput(VarList outputMap) - { + public void declareOutput(VarList outputMap) { // } @Override - public String getMainPluginClassName() - { + public String getMainPluginClassName() { return TrackManager.class.getName(); } }