diff --git a/source/net/filebot/ui/SelectDialog.java b/source/net/filebot/ui/SelectDialog.java index c64788d7..b0919538 100644 --- a/source/net/filebot/ui/SelectDialog.java +++ b/source/net/filebot/ui/SelectDialog.java @@ -1,6 +1,8 @@ package net.filebot.ui; import static java.awt.Cursor.*; +import static javax.swing.SwingUtilities.*; +import static net.filebot.ui.ThemeSupport.*; import static net.filebot.util.ui.SwingUI.*; import java.awt.Component; @@ -22,12 +24,14 @@ import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JScrollPane; +import javax.swing.JToggleButton; import javax.swing.KeyStroke; import javax.swing.ListSelectionModel; -import javax.swing.SwingUtilities; +import javax.swing.plaf.basic.BasicCheckBoxUI; import net.filebot.ResourceManager; import net.filebot.util.ui.DefaultFancyListCellRenderer; +import net.filebot.util.ui.RoundDecoration; import net.filebot.web.SearchResult; import net.filebot.web.TheTVDBSearchResult; import net.miginfocom.swing.MigLayout; @@ -35,10 +39,10 @@ import net.miginfocom.swing.MigLayout; public class SelectDialog extends JDialog { private JLabel messageLabel = new JLabel(); - private JCheckBox autoRepeatCheckBox = new JCheckBox(); + private JToggleButton autoRepeatCheckBox; private JList list; - private String command = null; + private String command; private Function icon; @@ -89,13 +93,8 @@ public class SelectDialog extends JDialog { // add repeat button if (autoRepeatEnabled) { - autoRepeatCheckBox.addChangeListener(evt -> autoRepeatCheckBox.setToolTipText(autoRepeatCheckBox.isSelected() ? "Select and remember for next time" : "Select once and ask again next time")); - autoRepeatCheckBox.setCursor(getPredefinedCursor(HAND_CURSOR)); - autoRepeatCheckBox.setIcon(ResourceManager.getIcon("button.repeat")); - autoRepeatCheckBox.setSelectedIcon(ResourceManager.getIcon("button.repeat.selected")); - autoRepeatCheckBox.setSelected(autoRepeatSelected); - autoRepeatCheckBox.setMinimumSize(new Dimension(22, 16)); - c.add(autoRepeatCheckBox, "pos 1al select.y n select.y2"); + autoRepeatCheckBox = createAutoRepeatCheckBox(); + c.add(autoRepeatCheckBox, "pos 1al select.y-3 n select.y2"); } // set default size and location @@ -105,6 +104,20 @@ public class SelectDialog extends JDialog { installAction(list, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), selectAction); } + protected JToggleButton createAutoRepeatCheckBox() { + JCheckBox c = new JCheckBox(); + c.setUI(new BasicCheckBoxUI()); + c.setCursor(getPredefinedCursor(HAND_CURSOR)); + c.setIcon(createAutoRepeatCheckBoxIcon("button.repeat")); + c.setSelectedIcon(createAutoRepeatCheckBoxIcon("button.repeat.selected")); + c.addChangeListener(evt -> autoRepeatCheckBox.setToolTipText(autoRepeatCheckBox.isSelected() ? "Select and remember for next time" : "Select once and ask again next time")); + return c; + } + + protected Icon createAutoRepeatCheckBoxIcon(String name) { + return new RoundDecoration(ResourceManager.getIcon(name), 28, 28, getPanelBackground(), getColor(0xD7D7D7)); + } + protected String convertValueToString(Object value) { return value.toString(); } @@ -157,7 +170,7 @@ public class SelectDialog extends JDialog { return messageLabel; } - public JCheckBox getAutoRepeatCheckBox() { + public JToggleButton getAutoRepeatCheckBox() { return autoRepeatCheckBox; } @@ -196,7 +209,7 @@ public class SelectDialog extends JDialog { }); private final MouseAdapter mouseListener = mouseClicked(evt -> { - if (SwingUtilities.isLeftMouseButton(evt) && (evt.getClickCount() == 2)) { + if (isLeftMouseButton(evt) && (evt.getClickCount() == 2)) { selectAction.actionPerformed(new ActionEvent(evt.getSource(), ActionEvent.ACTION_PERFORMED, SELECT)); } }); @@ -206,14 +219,20 @@ public class SelectDialog extends JDialog { private static final String KEY_HEIGHT = "dialog.select.height"; public void saveState(Preferences prefs) { - prefs.putBoolean(KEY_REPEAT, autoRepeatCheckBox.isSelected()); prefs.putInt(KEY_WIDTH, getWidth()); prefs.putInt(KEY_HEIGHT, getHeight()); + + if (autoRepeatCheckBox != null) { + prefs.putBoolean(KEY_REPEAT, autoRepeatCheckBox.isSelected()); + } } public void restoreState(Preferences prefs) { - autoRepeatCheckBox.setSelected(prefs.getBoolean(KEY_REPEAT, autoRepeatCheckBox.isSelected())); setSize(prefs.getInt(KEY_WIDTH, getWidth()), prefs.getInt(KEY_HEIGHT, getHeight())); + + if (autoRepeatCheckBox != null) { + autoRepeatCheckBox.setSelected(prefs.getBoolean(KEY_REPEAT, autoRepeatCheckBox.isSelected())); + } } } diff --git a/source/net/filebot/util/ui/RoundDecoration.java b/source/net/filebot/util/ui/RoundDecoration.java new file mode 100644 index 00000000..d68ba798 --- /dev/null +++ b/source/net/filebot/util/ui/RoundDecoration.java @@ -0,0 +1,57 @@ +package net.filebot.util.ui; + +import java.awt.Color; +import java.awt.Component; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.RenderingHints; +import java.awt.Shape; +import java.awt.geom.Ellipse2D; + +import javax.swing.Icon; + +public class RoundDecoration implements Icon { + + private Icon icon; + + private Color fill; + private Color draw; + + private int width; + private int height; + + public RoundDecoration(Icon icon, int width, int height, Color fill, Color draw) { + this.icon = icon; + this.width = width; + this.height = height; + this.fill = fill; + this.draw = draw; + } + + @Override + public void paintIcon(Component c, Graphics g, int x, int y) { + Graphics2D g2d = (Graphics2D) g; + g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + + Shape shape = new Ellipse2D.Float(x, y, width - 1, height - 1); + + g2d.setColor(fill); + g2d.fill(shape); + + g2d.setColor(draw); + g2d.draw(shape); + + icon.paintIcon(c, g, x + (width - icon.getIconWidth()) / 2, y + (height - icon.getIconHeight()) / 2); + } + + @Override + public int getIconWidth() { + return width; + } + + @Override + public int getIconHeight() { + return height; + } + +} \ No newline at end of file