Ticket #20537: 20537.2.patch
File 20537.2.patch, 7.0 KB (added by , 2 years ago) |
---|
-
src/org/openstreetmap/josm/gui/preferences/plugin/PluginCheckBox.java
diff --git a/src/org/openstreetmap/josm/gui/preferences/plugin/PluginCheckBox.java b/src/org/openstreetmap/josm/gui/preferences/plugin/PluginCheckBox.java index d021169a68..2918430a87 100644
a b package org.openstreetmap.josm.gui.preferences.plugin; 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 import static org.openstreetmap.josm.tools.I18n.trn; 6 6 7 import java.awt.Color; 7 8 import java.awt.Component; 8 9 import java.awt.event.ActionEvent; 9 10 import java.awt.event.ActionListener; 11 import java.util.Objects; 10 12 import java.util.Set; 11 13 import java.util.stream.Collectors; 12 14 15 import javax.swing.AbstractAction; 16 import javax.swing.Action; 13 17 import javax.swing.JCheckBox; 18 import javax.swing.JMenuItem; 14 19 import javax.swing.JOptionPane; 20 import javax.swing.JPopupMenu; 21 import javax.swing.event.PopupMenuEvent; 15 22 23 import org.openstreetmap.josm.data.preferences.NamedColorProperty; 16 24 import org.openstreetmap.josm.plugins.PluginHandler; 17 25 import org.openstreetmap.josm.plugins.PluginInformation; 18 26 import org.openstreetmap.josm.tools.Utils; … … import org.openstreetmap.josm.tools.Utils; 22 30 * @since 10228 23 31 */ 24 32 public class PluginCheckBox extends JCheckBox implements ActionListener { 33 private static final String PREFERENCE_PREFIX = "plugins."; 34 35 /* Background colors for checkboxes */ 36 private static final NamedColorProperty COLOR_INSTALLED = new NamedColorProperty(PREFERENCE_PREFIX + PluginInstallation.INSTALLED, 37 Color.GREEN.darker().darker()); 38 private static final NamedColorProperty COLOR_REINSTALL = new NamedColorProperty(PREFERENCE_PREFIX + PluginInstallation.REINSTALL, 39 Color.GREEN); 40 private static final NamedColorProperty COLOR_UPGRADE = new NamedColorProperty(PREFERENCE_PREFIX + PluginInstallation.UPGRADE, 41 Color.GREEN.brighter().brighter()); 42 private static final NamedColorProperty COLOR_REMOVE = new NamedColorProperty(PREFERENCE_PREFIX + PluginInstallation.REMOVE, 43 Color.RED.darker().darker()); 44 private static final NamedColorProperty COLOR_COMPLETE_REMOVE = new NamedColorProperty(PREFERENCE_PREFIX + PluginInstallation.COMPLETE_REMOVE, 45 Color.RED); 46 private final Color originalColor; 47 25 48 private final transient PluginInformation pi; 26 49 private final PluginListPanel panel; 27 50 private final transient PluginPreferencesModel ppModel; 51 private final boolean wasInstalled; 52 private PluginInstallation state; 28 53 29 54 PluginCheckBox(PluginInformation pi, boolean selected, PluginListPanel panel, PluginPreferencesModel ppModel) { 30 55 this.pi = pi; … … public class PluginCheckBox extends JCheckBox implements ActionListener { 33 58 setSelected(selected); 34 59 setToolTipText(PluginListPanel.formatCheckboxTooltipText(pi)); 35 60 addActionListener(this); 61 wasInstalled = selected; 62 this.originalColor = this.getBackground(); 63 if (wasInstalled) { 64 this.setBackground(COLOR_INSTALLED.get()); 65 state = PluginInstallation.INSTALLED; 66 } else { 67 state = PluginInstallation.ALL; 68 } 36 69 } 37 70 38 71 protected void selectRequiredPlugins(PluginInformation info) { … … public class PluginCheckBox extends JCheckBox implements ActionListener { 67 100 alertPluginStillRequired(panel, pi.getName(), otherPlugins); 68 101 } 69 102 } 103 setState(); 70 104 } 71 105 106 private void setState() { 107 if (isSelected() && this.wasInstalled) { 108 state = PluginInstallation.INSTALLED; 109 updateBackgroundColor(); 110 } else if (isSelected()) { 111 // Really should use a specific state for "to install" 112 state = PluginInstallation.UPGRADE; 113 updateBackgroundColor(); 114 } else if (!isSelected() && this.wasInstalled) { 115 final JPopupMenu jPopupMenu = new JPopupMenu(); 116 Action action = new AbstractAction() { 117 @Override 118 public void actionPerformed(ActionEvent e) { 119 final String actionCommand = e.getActionCommand(); 120 if (tr("Mark for Reinstallation").equals(actionCommand)) { 121 state = PluginInstallation.REINSTALL; 122 } else if (tr("Mark for Complete Removal").equals(actionCommand)) { 123 state = PluginInstallation.COMPLETE_REMOVE; 124 } else { 125 state = PluginInstallation.REMOVE; 126 } 127 jPopupMenu.setVisible(false); 128 updateBackgroundColor(); 129 } 130 }; 131 jPopupMenu.add(new JMenuItem(action)).setText(tr("Mark for Reinstallation")); 132 jPopupMenu.add(new JMenuItem(action)).setText(tr("Mark for Removal")); 133 jPopupMenu.add(new JMenuItem(action)).setText(tr("Mark for Complete Removal")); 134 jPopupMenu.show(this, 0, this.getHeight()); 135 } else { 136 state = PluginInstallation.AVAILABLE; 137 updateBackgroundColor(); 138 } 139 } 140 141 private void updateBackgroundColor() { 142 final Color color; 143 switch (state) { 144 case ALL: 145 case AVAILABLE: 146 case INSTALLED: 147 // INSTALLED should use COLOR_INSTALLED, but it also has a checkbox 148 color = this.originalColor; 149 break; 150 case REMOVE: 151 color = COLOR_REMOVE.get(); 152 break; 153 case COMPLETE_REMOVE: 154 color = COLOR_COMPLETE_REMOVE.get(); 155 break; 156 case REINSTALL: 157 color = COLOR_REINSTALL.get(); 158 break; 159 case UPGRADE: 160 color = COLOR_UPGRADE.get(); 161 break; 162 default: 163 throw new IllegalStateException("Unknown plugin state"); 164 } 165 this.setOpaque(!Objects.equals(this.originalColor, color)); 166 this.setBackground(color); 167 } 168 169 72 170 /** 73 171 * Alerts the user if an unselected plugin is still required by another plugins 74 172 * -
src/org/openstreetmap/josm/gui/preferences/plugin/PluginInstallation.java
diff --git a/src/org/openstreetmap/josm/gui/preferences/plugin/PluginInstallation.java b/src/org/openstreetmap/josm/gui/preferences/plugin/PluginInstallation.java index ab42df7fb0..ca6e4f3b4d 100644
a b public enum PluginInstallation { 11 11 /** Plugins not loaded **/ 12 12 AVAILABLE, 13 13 /** All plugins **/ 14 ALL 14 ALL, 15 /** 16 * Plugins to reinstall -- this involves <i>deleting</i> the plugin file 17 * @since xxx 18 */ 19 REINSTALL, 20 /** 21 * Plugins to upgrade 22 * @since xxx 23 */ 24 UPGRADE, 25 /** 26 * Plugins to remove 27 * @since xxx 28 */ 29 REMOVE, 30 /** 31 * Plugins to completely remove -- this involves <i>deleting</i> the plugin file 32 * @since xxx 33 */ 34 COMPLETE_REMOVE 15 35 }