diff --git a/.gitignore b/.gitignore index 91283482c6030e0a2b58393b09d3db68e635c755..ef023e6659cb1499d992c636df003f72a93ecf37 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,7 @@ target/ *.class *.jar + +# IntelliJ working directory & files +.idea/ +*.iml \ No newline at end of file diff --git a/pom.xml b/pom.xml index 4999a6c267915092899daff3c27c4c3a441d814c..f67a372f45ff91ee750ae3282bc50617923e2f82 100644 --- a/pom.xml +++ b/pom.xml @@ -6,12 +6,12 @@ <parent> <groupId>org.bioimageanalysis.icy</groupId> - <artifactId>parent-pom-plugin</artifactId> - <version>1.0.3</version> + <artifactId>pom-icy</artifactId> + <version>2.1.0</version> </parent> <artifactId>color-bar</artifactId> - <version>1.0.2</version> + <version>1.0.3</version> <packaging>jar</packaging> @@ -20,13 +20,27 @@ Display the colormap over the image using an overlay. </description> + <organization> + <name>Institut Pasteur</name> + <url>https://www.pasteur.fr/</url> + </organization> + + <licenses> + <license> + <name>GNU GPLv3</name> + <url>https://www.gnu.org/licenses/gpl-3.0.en.html</url> + <distribution>repo</distribution> + </license> + </licenses> + <dependencies> </dependencies> <repositories> <repository> <id>icy</id> + <name>Icy's Nexus</name> <url>https://icy-nexus.pasteur.fr/repository/Icy/</url> </repository> </repositories> -</project> \ No newline at end of file +</project> diff --git a/src/main/java/plugins/stef/tools/overlay/ColorBarOverlay.java b/src/main/java/plugins/stef/tools/overlay/ColorBarOverlay.java index fdf563666730a164cfe32fd2ba5bb42e374f6dbe..f90a71f984a27d88848bcdcf686819068d3e6931 100644 --- a/src/main/java/plugins/stef/tools/overlay/ColorBarOverlay.java +++ b/src/main/java/plugins/stef/tools/overlay/ColorBarOverlay.java @@ -93,7 +93,8 @@ public class ColorBarOverlay extends Overlay implements SettingChangeListener @Override public void paint(Graphics2D g, Sequence sequence, IcyCanvas canvas) { - if ((canvas != null) && (g != null) && (canvas instanceof IcyCanvas2D)) + // Unnecessary (canvas != null) condition + if ((g != null) && (canvas instanceof IcyCanvas2D)) { final LUT lut = canvas.getLut(); @@ -129,7 +130,7 @@ public class ColorBarOverlay extends Overlay implements SettingChangeListener h *= scale; x = region.x; - x += (region.width / 2) - (w / 2); + x += (region.width / 2d) - (w / 2); x += offsetX; if (position == ColorBarPosition.BOTTOM) { @@ -164,7 +165,7 @@ public class ColorBarOverlay extends Overlay implements SettingChangeListener } x += offsetX; y = region.y; - y += (region.height / 2) - (h / 2); + y += (region.height / 2d) - (h / 2); y += offsetY; break; } @@ -197,7 +198,7 @@ public class ColorBarOverlay extends Overlay implements SettingChangeListener for (int i = 0; i < (int) w; i++) { final int colorInd = (int) Math.round(i * ratio); - g2.setColor(colorMap.getColor((int) Math.min(255, Math.max(0, colorInd)))); + g2.setColor(colorMap.getColor(Math.min(255, Math.max(0, colorInd)))); g2.fillRect(xi + 1 + i, yi + 1, 1, hi - 1); } @@ -238,7 +239,6 @@ public class ColorBarOverlay extends Overlay implements SettingChangeListener for (int c = 0; c < numChannel; c++) { final IcyColorMap colorMap = lut.getLutChannel(c).getColorMap(); - ; // draw white background g2.setColor(Color.white); @@ -248,7 +248,7 @@ public class ColorBarOverlay extends Overlay implements SettingChangeListener for (int i = 0; i < hi; i++) { final int colorInd = (int) Math.round(((hi - 1) - i) * ratio); - g2.setColor(colorMap.getColor((int) Math.min(255, Math.max(0, colorInd)))); + g2.setColor(colorMap.getColor(Math.min(255, Math.max(0, colorInd)))); g2.fillRect(xi + 1, yi + 1 + i, wi - 1, 1); } @@ -405,16 +405,24 @@ public class ColorBarOverlay extends Overlay implements SettingChangeListener final String propertyName = event.getPropertyName(); final Object value = event.getNewValue(); - if (propertyName.equals(ColorBarSettingPanel.PROPERTY_DISPLAY_MINMAX)) - prefs.putBoolean(ColorBarSettingPanel.PROPERTY_DISPLAY_MINMAX, ((Boolean) value).booleanValue()); - else if (propertyName.equals(ColorBarSettingPanel.PROPERTY_OFFSET_X)) - prefs.putDouble(ColorBarSettingPanel.PROPERTY_OFFSET_X, ((Double) value).doubleValue()); - else if (propertyName.equals(ColorBarSettingPanel.PROPERTY_OFFSET_Y)) - prefs.putDouble(ColorBarSettingPanel.PROPERTY_OFFSET_Y, ((Double) value).doubleValue()); - else if (propertyName.equals(ColorBarSettingPanel.PROPERTY_POSITION)) - prefs.putInt(ColorBarSettingPanel.PROPERTY_POSITION, ((ColorBarPosition) value).ordinal()); - else if (propertyName.equals(ColorBarSettingPanel.PROPERTY_SCALE)) - prefs.putDouble(ColorBarSettingPanel.PROPERTY_SCALE, ((Double) value).doubleValue()); + // More readable than "if-else-if" block + switch (propertyName) { + case ColorBarSettingPanel.PROPERTY_DISPLAY_MINMAX: + prefs.putBoolean(ColorBarSettingPanel.PROPERTY_DISPLAY_MINMAX, ((Boolean) value).booleanValue()); + break; + case ColorBarSettingPanel.PROPERTY_OFFSET_X: + prefs.putDouble(ColorBarSettingPanel.PROPERTY_OFFSET_X, ((Double) value).doubleValue()); + break; + case ColorBarSettingPanel.PROPERTY_OFFSET_Y: + prefs.putDouble(ColorBarSettingPanel.PROPERTY_OFFSET_Y, ((Double) value).doubleValue()); + break; + case ColorBarSettingPanel.PROPERTY_POSITION: + prefs.putInt(ColorBarSettingPanel.PROPERTY_POSITION, ((ColorBarPosition) value).ordinal()); + break; + case ColorBarSettingPanel.PROPERTY_SCALE: + prefs.putDouble(ColorBarSettingPanel.PROPERTY_SCALE, ((Double) value).doubleValue()); + break; + } } // redraw the colorbar diff --git a/src/main/java/plugins/stef/tools/overlay/ColorBarSettingPanel.java b/src/main/java/plugins/stef/tools/overlay/ColorBarSettingPanel.java index 7fcf4df3f11573616cb75608aeef54fe8dda4a2f..e42b16b34aae76c17c46479c4be898cd39f2b665 100644 --- a/src/main/java/plugins/stef/tools/overlay/ColorBarSettingPanel.java +++ b/src/main/java/plugins/stef/tools/overlay/ColorBarSettingPanel.java @@ -36,7 +36,7 @@ public class ColorBarSettingPanel extends JPanel implements ActionListener, Chan public final static String PROPERTY_OFFSET_Y = "offsetY"; public final static String PROPERTY_DISPLAY_MINMAX = "displayMinMax"; - protected JComboBox positionComboBox; + protected JComboBox<ColorBarPosition> positionComboBox; protected JSlider offsetXSlider; protected JSlider offsetYSlider; protected JSlider scaleSlider; @@ -53,9 +53,9 @@ public class ColorBarSettingPanel extends JPanel implements ActionListener, Chan initialize(); positionComboBox.setSelectedItem(ColorBarPosition.RIGHT); - offsetXSlider.setValue(Integer.valueOf(0)); - offsetYSlider.setValue(Integer.valueOf(0)); - scaleSlider.setValue(Integer.valueOf(100)); + offsetXSlider.setValue(0); + offsetYSlider.setValue(0); + scaleSlider.setValue(100); minMaxCheckBox.setSelected(true); positionComboBox.addActionListener(this); @@ -95,9 +95,9 @@ public class ColorBarSettingPanel extends JPanel implements ActionListener, Chan gbc_lblPosition.gridy = 0; add(lblPosition, gbc_lblPosition); - positionComboBox = new JComboBox(); + positionComboBox = new JComboBox<>(); positionComboBox.setToolTipText("Position of the color bar"); - positionComboBox.setModel(new DefaultComboBoxModel(ColorBarPosition.values())); + positionComboBox.setModel(new DefaultComboBoxModel<>(ColorBarPosition.values())); GridBagConstraints gbc_positionComboBox = new GridBagConstraints(); gbc_positionComboBox.fill = GridBagConstraints.HORIZONTAL; gbc_positionComboBox.gridwidth = 2;