Loading Rendering/src/main/java/cz/fidentis/analyst/toolbar/ColorIcon.java 0 → 100644 +38 −0 Original line number Diff line number Diff line package cz.fidentis.analyst.toolbar; import javax.swing.*; import java.awt.*; /** * A simple icon that represents a color square. * It can be used in toolbars or menus to represent color options. * * @author Ondrej Kostik */ public class ColorIcon implements Icon { private final Color color; private final int size; public ColorIcon(Color color, int size) { this.color = color; this.size = size; } @Override public void paintIcon(Component c, Graphics g, int x, int y) { g.setColor(color); g.fillRect(x, y, size, size); g.setColor(Color.BLACK); g.drawRect(x, y, size - 1, size - 1); } @Override public int getIconWidth() { return size; } @Override public int getIconHeight() { return size; } } Rendering/src/main/java/cz/fidentis/analyst/toolbar/FaceToolbox.java +5 −5 Original line number Diff line number Diff line Loading @@ -70,12 +70,12 @@ public class FaceToolbox extends Toolbox { super(canvas); if (toolboxType != ToolboxType.SINGLE_FACE) { addToPanel(initColorButton(16, 35, toolboxType)); add(initColorButton(16, 35, toolboxType)); } //addToPanel(initSymmetryButton(faceSlot)); addToPanel(initLandmarksButton(faceSlot)); addToPanel(initFaceButton(faceSlot, toolboxType.getIcon())); addToPanel(initSlider(faceSlot, toolboxType)); //add(initSymmetryButton(faceSlot)); add(initLandmarksButton(faceSlot)); add(initFaceButton(faceSlot, toolboxType.getIcon())); add(initSlider(faceSlot, toolboxType)); } private JSlider initSlider(int faceSlot, ToolboxType toolboxType) { Loading Rendering/src/main/java/cz/fidentis/analyst/toolbar/FogColorChooser.java 0 → 100644 +77 −0 Original line number Diff line number Diff line package cz.fidentis.analyst.toolbar; import cz.fidentis.analyst.rendering.ShadersManager; import javax.swing.*; import javax.swing.colorchooser.AbstractColorChooserPanel; import java.awt.*; import java.util.Arrays; /** * A simple color chooser tailored for selecting the distance fog colors. * Only swatches are shown, and the preview panel is removed. * * @author Ondrej Kostik */ public class FogColorChooser extends JColorChooser { /** * Shows a customized modal color-chooser dialog and blocks until the dialog is * hidden. * * @param parent the parent <code>Component</code> for the dialog * @param title the String containing the dialog's title * @param initialColor the initial Color set when the color-chooser is shown * @return the selected color or <code>null</code> if the user opted out * @throws HeadlessException if GraphicsEnvironment.isHeadless() * returns true. */ public static Color showDialog(Component parent, String title, Color initialColor) { final JColorChooser chooser = new JColorChooser(initialColor); // Keep only the "Swatches" panel chooser.setChooserPanels( Arrays.stream(chooser.getChooserPanels()) .filter(p -> p.getDisplayName().equals("Swatches")) .toArray(AbstractColorChooserPanel[]::new) ); // Remove the "Preview" panel chooser.setPreviewPanel(new JPanel()); final JDialog dialog = JColorChooser.createDialog(parent, title, true, chooser, null, null); // Track selected color (can't use the default ColorTracker because it's not public in javax.swing module) // Needs to be effectively final to be used in the Action listeners and then returned final Color[] selected = new Color[1]; // Register the actions for the buttons for (Component c : dialog.getContentPane().getComponents()) { if (c instanceof JPanel panel) { for (Component cc : panel.getComponents()) { if (cc instanceof JButton btn) { switch (btn.getActionCommand()) { case "Reset": btn.addActionListener(e -> { chooser.setColor(ShadersManager.DEFAULT_FOG_COLOR); selected[0] = chooser.getColor(); dialog.dispose(); }); break; case "OK": btn.addActionListener(e -> { selected[0] = chooser.getColor(); dialog.dispose(); }); break; default: } } } } } dialog.setVisible(true); return selected[0]; // null if canceled } } Rendering/src/main/java/cz/fidentis/analyst/toolbar/FogToolbox.java +18 −4 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ public class FogToolbox extends Toolbox { /** * Constructor. * * @param canvas Rendering canvas */ public FogToolbox(Canvas canvas) { Loading @@ -29,6 +30,8 @@ public class FogToolbox extends Toolbox { } private void initComponents() { JMenuItem menuItem0 = new JMenuItem(); // fog color picker JMenuItem menuItem1 = new JMenuItem(new AbstractAction() { // fill @Override public void actionPerformed(ActionEvent e) { Loading Loading @@ -64,21 +67,32 @@ public class FogToolbox extends Toolbox { } }); menuItem0.addActionListener(e -> { Color currentColor = ShadersManager.getFogColor(); Color chosen = FogColorChooser.showDialog(this, "Choose the distance fog color", currentColor); if (chosen != null && !chosen.equals(currentColor)) { ShadersManager.setFogColor(chosen); menuItem0.setIcon(new ColorIcon(chosen, 28)); getCanvas().renderScene(); } }); menuItem0.setIcon(new ColorIcon(ShadersManager.DEFAULT_FOG_COLOR, 28)); menuItem1.setIcon(new ImageIcon(getClass().getResource("/" + FogToolbox.OFF_BUTTON_ICON))); menuItem2.setIcon(new ImageIcon(getClass().getResource("/" + FogToolbox.OUTER_BUTTON_ICON))); menuItem3.setIcon(new ImageIcon(getClass().getResource("/" + FogToolbox.TRANSPARENCY_BUTTON_ICON))); menuItem4.setIcon(new ImageIcon(getClass().getResource("/" + FogToolbox.INNER_BUTTON_ICON))); menuItem0.setToolTipText("set fog color"); menuItem1.setToolTipText("no distance mapping"); menuItem2.setToolTipText("mapping the distance on the outer surface via color modulation"); menuItem3.setToolTipText("mapping the distance on the outer surface via transparency"); menuItem4.setToolTipText("mapping the distance on the inner surface via color modulation"); add(menuItem0); add(menuItem1); add(menuItem2); add(menuItem3); add(menuItem4); setLayout(new GridLayout(1,0)); } } Rendering/src/main/java/cz/fidentis/analyst/toolbar/NormalsToolbox.java +1 −1 Original line number Diff line number Diff line Loading @@ -25,7 +25,7 @@ public class NormalsToolbox extends Toolbox { */ public NormalsToolbox(Canvas canvas) { super(canvas); addToPanel(initSlider()); add(initSlider()); } private JSlider initSlider() { Loading Loading
Rendering/src/main/java/cz/fidentis/analyst/toolbar/ColorIcon.java 0 → 100644 +38 −0 Original line number Diff line number Diff line package cz.fidentis.analyst.toolbar; import javax.swing.*; import java.awt.*; /** * A simple icon that represents a color square. * It can be used in toolbars or menus to represent color options. * * @author Ondrej Kostik */ public class ColorIcon implements Icon { private final Color color; private final int size; public ColorIcon(Color color, int size) { this.color = color; this.size = size; } @Override public void paintIcon(Component c, Graphics g, int x, int y) { g.setColor(color); g.fillRect(x, y, size, size); g.setColor(Color.BLACK); g.drawRect(x, y, size - 1, size - 1); } @Override public int getIconWidth() { return size; } @Override public int getIconHeight() { return size; } }
Rendering/src/main/java/cz/fidentis/analyst/toolbar/FaceToolbox.java +5 −5 Original line number Diff line number Diff line Loading @@ -70,12 +70,12 @@ public class FaceToolbox extends Toolbox { super(canvas); if (toolboxType != ToolboxType.SINGLE_FACE) { addToPanel(initColorButton(16, 35, toolboxType)); add(initColorButton(16, 35, toolboxType)); } //addToPanel(initSymmetryButton(faceSlot)); addToPanel(initLandmarksButton(faceSlot)); addToPanel(initFaceButton(faceSlot, toolboxType.getIcon())); addToPanel(initSlider(faceSlot, toolboxType)); //add(initSymmetryButton(faceSlot)); add(initLandmarksButton(faceSlot)); add(initFaceButton(faceSlot, toolboxType.getIcon())); add(initSlider(faceSlot, toolboxType)); } private JSlider initSlider(int faceSlot, ToolboxType toolboxType) { Loading
Rendering/src/main/java/cz/fidentis/analyst/toolbar/FogColorChooser.java 0 → 100644 +77 −0 Original line number Diff line number Diff line package cz.fidentis.analyst.toolbar; import cz.fidentis.analyst.rendering.ShadersManager; import javax.swing.*; import javax.swing.colorchooser.AbstractColorChooserPanel; import java.awt.*; import java.util.Arrays; /** * A simple color chooser tailored for selecting the distance fog colors. * Only swatches are shown, and the preview panel is removed. * * @author Ondrej Kostik */ public class FogColorChooser extends JColorChooser { /** * Shows a customized modal color-chooser dialog and blocks until the dialog is * hidden. * * @param parent the parent <code>Component</code> for the dialog * @param title the String containing the dialog's title * @param initialColor the initial Color set when the color-chooser is shown * @return the selected color or <code>null</code> if the user opted out * @throws HeadlessException if GraphicsEnvironment.isHeadless() * returns true. */ public static Color showDialog(Component parent, String title, Color initialColor) { final JColorChooser chooser = new JColorChooser(initialColor); // Keep only the "Swatches" panel chooser.setChooserPanels( Arrays.stream(chooser.getChooserPanels()) .filter(p -> p.getDisplayName().equals("Swatches")) .toArray(AbstractColorChooserPanel[]::new) ); // Remove the "Preview" panel chooser.setPreviewPanel(new JPanel()); final JDialog dialog = JColorChooser.createDialog(parent, title, true, chooser, null, null); // Track selected color (can't use the default ColorTracker because it's not public in javax.swing module) // Needs to be effectively final to be used in the Action listeners and then returned final Color[] selected = new Color[1]; // Register the actions for the buttons for (Component c : dialog.getContentPane().getComponents()) { if (c instanceof JPanel panel) { for (Component cc : panel.getComponents()) { if (cc instanceof JButton btn) { switch (btn.getActionCommand()) { case "Reset": btn.addActionListener(e -> { chooser.setColor(ShadersManager.DEFAULT_FOG_COLOR); selected[0] = chooser.getColor(); dialog.dispose(); }); break; case "OK": btn.addActionListener(e -> { selected[0] = chooser.getColor(); dialog.dispose(); }); break; default: } } } } } dialog.setVisible(true); return selected[0]; // null if canceled } }
Rendering/src/main/java/cz/fidentis/analyst/toolbar/FogToolbox.java +18 −4 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ public class FogToolbox extends Toolbox { /** * Constructor. * * @param canvas Rendering canvas */ public FogToolbox(Canvas canvas) { Loading @@ -29,6 +30,8 @@ public class FogToolbox extends Toolbox { } private void initComponents() { JMenuItem menuItem0 = new JMenuItem(); // fog color picker JMenuItem menuItem1 = new JMenuItem(new AbstractAction() { // fill @Override public void actionPerformed(ActionEvent e) { Loading Loading @@ -64,21 +67,32 @@ public class FogToolbox extends Toolbox { } }); menuItem0.addActionListener(e -> { Color currentColor = ShadersManager.getFogColor(); Color chosen = FogColorChooser.showDialog(this, "Choose the distance fog color", currentColor); if (chosen != null && !chosen.equals(currentColor)) { ShadersManager.setFogColor(chosen); menuItem0.setIcon(new ColorIcon(chosen, 28)); getCanvas().renderScene(); } }); menuItem0.setIcon(new ColorIcon(ShadersManager.DEFAULT_FOG_COLOR, 28)); menuItem1.setIcon(new ImageIcon(getClass().getResource("/" + FogToolbox.OFF_BUTTON_ICON))); menuItem2.setIcon(new ImageIcon(getClass().getResource("/" + FogToolbox.OUTER_BUTTON_ICON))); menuItem3.setIcon(new ImageIcon(getClass().getResource("/" + FogToolbox.TRANSPARENCY_BUTTON_ICON))); menuItem4.setIcon(new ImageIcon(getClass().getResource("/" + FogToolbox.INNER_BUTTON_ICON))); menuItem0.setToolTipText("set fog color"); menuItem1.setToolTipText("no distance mapping"); menuItem2.setToolTipText("mapping the distance on the outer surface via color modulation"); menuItem3.setToolTipText("mapping the distance on the outer surface via transparency"); menuItem4.setToolTipText("mapping the distance on the inner surface via color modulation"); add(menuItem0); add(menuItem1); add(menuItem2); add(menuItem3); add(menuItem4); setLayout(new GridLayout(1,0)); } }
Rendering/src/main/java/cz/fidentis/analyst/toolbar/NormalsToolbox.java +1 −1 Original line number Diff line number Diff line Loading @@ -25,7 +25,7 @@ public class NormalsToolbox extends Toolbox { */ public NormalsToolbox(Canvas canvas) { super(canvas); addToPanel(initSlider()); add(initSlider()); } private JSlider initSlider() { Loading