Ticket #20720: 20720.patch
| File 20720.patch, 4.4 KB (added by , 5 years ago) |
|---|
-
src/org/openstreetmap/josm/gui/preferences/plugin/PluginListPanel.java
3 3 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.Component; 6 7 import java.awt.GridBagConstraints; 7 8 import java.awt.GridBagLayout; 8 9 import java.awt.Insets; 9 10 import java.awt.Rectangle; 10 11 import java.awt.event.MouseAdapter; 11 12 import java.awt.event.MouseEvent; 13 import java.util.ArrayList; 14 import java.util.HashMap; 15 import java.util.HashSet; 12 16 import java.util.List; 17 import java.util.Map; 18 import java.util.Set; 13 19 14 20 import javax.swing.JLabel; 15 21 import javax.swing.SwingConstants; … … 38 44 39 45 private final transient PluginPreferencesModel model; 40 46 47 /** Whether the plugin list has been built up already in the UI */ 48 private boolean pluginListInitialized = false; 49 41 50 /** 51 * A map from the plugin information to the UI components that are used to display that information. 52 * 53 * Used to selectively hide filtered elements. 54 */ 55 private final Map<PluginInformation, List<Component>> componentsForPlugin = new HashMap<>(); 56 57 /** 42 58 * Constructs a new {@code PluginListPanel} with a default model. 43 59 */ 44 60 public PluginListPanel() { … … 104 120 tr("The filter returned no results.")) 105 121 + "</html>" 106 122 ); 123 List<Component> components = new ArrayList<>(1); 124 components.add(hint); 125 componentsForPlugin.put(null, components); 107 126 add(hint, gbc); 108 127 } 109 128 … … 121 140 122 141 int row = -1; 123 142 for (final PluginInformation pi : displayedPlugins) { 143 List<Component> components = new ArrayList<>(3); 124 144 boolean selected = model.isSelectedPlugin(pi.getName()); 125 145 String remoteversion = formatPluginRemoteVersion(pi); 126 146 String localversion = formatPluginLocalVersion(model.getPluginInformation(pi.getName())); … … 141 161 gbc.insets = new Insets(5, 5, 0, 5); 142 162 gbc.weighty = 0.0; 143 163 gbc.weightx = 0.0; 164 components.add(cbPlugin); 144 165 add(cbPlugin, gbc); 145 166 146 167 gbc.gridx = 1; 147 168 gbc.weightx = 1.0; 169 components.add(lblPlugin); 148 170 add(lblPlugin, gbc); 149 171 150 172 HtmlPanel description = new HtmlPanel(); … … 156 178 gbc.gridy = ++row; 157 179 gbc.insets = new Insets(3, 25, 5, 5); 158 180 gbc.weighty = 1.0; 181 components.add(description); 159 182 add(description, gbc); 183 componentsForPlugin.put(pi, components); 160 184 } 185 186 pluginListInitialized = true; 161 187 } 162 188 163 189 /** … … 166 192 public void refreshView() { 167 193 final Rectangle visibleRect = getVisibleRect(); 168 194 List<PluginInformation> displayedPlugins = model.getDisplayedPlugins(); 169 removeAll();170 195 171 196 if (displayedPlugins.isEmpty()) { 197 hidePluginsNotInList(new ArrayList<>()); 172 198 displayEmptyPluginListInformation(); 199 } else if (!pluginListInitialized) { 200 removeAll(); 201 displayPluginList(displayedPlugins); 173 202 } else { 174 displayPluginList(displayedPlugins);203 hidePluginsNotInList(displayedPlugins); 175 204 } 176 205 revalidate(); 177 206 repaint(); 178 207 SwingUtilities.invokeLater(() -> scrollRectToVisible(visibleRect)); 179 208 } 180 209 210 private void hidePluginsNotInList(List<PluginInformation> displayedPlugins) { 211 Set<PluginInformation> displayedPluginsSet = new HashSet<>(displayedPlugins); 212 componentsForPlugin.forEach((pi, components) -> { 213 if (displayedPluginsSet.contains(pi)) { 214 for (Component component : components) { 215 component.setVisible(true); 216 } 217 } else { 218 for (Component component : components) { 219 component.setVisible(false); 220 } 221 } 222 }); 223 } 224 181 225 @Override 182 226 public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) { 183 227 return visibleRect.height / 4;
