- Timestamp:
- 2021-04-14T21:21:31+02:00 (4 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/preferences/plugin
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/preferences/plugin/PluginListPanel.java
r17733 r17784 10 10 import java.awt.event.MouseAdapter; 11 11 import java.awt.event.MouseEvent; 12 import java.util.ArrayList; 13 import java.util.HashSet; 12 14 import java.util.List; 13 15 import java.util.Set; 16 17 import javax.swing.JComponent; 14 18 import javax.swing.JLabel; 15 19 import javax.swing.SwingConstants; … … 38 42 39 43 private final transient PluginPreferencesModel model; 44 45 /** Whether the plugin list has been built up already in the UI. */ 46 private boolean pluginListInitialized = false; 40 47 41 48 /** … … 105 112 + "</html>" 106 113 ); 114 hint.putClientProperty("plugin", "empty"); 107 115 add(hint, gbc); 108 116 } … … 142 150 gbc.weighty = 0.0; 143 151 gbc.weightx = 0.0; 152 cbPlugin.putClientProperty("plugin", pi); 144 153 add(cbPlugin, gbc); 145 154 146 155 gbc.gridx = 1; 147 156 gbc.weightx = 1.0; 157 lblPlugin.putClientProperty("plugin", pi); 148 158 add(lblPlugin, gbc); 149 159 … … 157 167 gbc.insets = new Insets(3, 25, 5, 5); 158 168 gbc.weighty = 1.0; 169 description.putClientProperty("plugin", pi); 159 170 add(description, gbc); 160 171 } 172 173 pluginListInitialized = true; 161 174 } 162 175 163 176 /** 164 177 * Refreshes the list. 178 * 179 * If the list has been changed completely (i.e. not just filtered), 180 * call {@link #resetDisplayedComponents()} prior to calling this method. 165 181 */ 166 182 public void refreshView() { 167 183 final Rectangle visibleRect = getVisibleRect(); 168 184 List<PluginInformation> displayedPlugins = model.getDisplayedPlugins(); 169 removeAll();170 185 171 186 if (displayedPlugins.isEmpty()) { 187 hidePluginsNotInList(new ArrayList<>()); 172 188 displayEmptyPluginListInformation(); 189 } else if (!pluginListInitialized) { 190 removeAll(); 191 displayPluginList(displayedPlugins); 173 192 } else { 174 displayPluginList(displayedPlugins);193 hidePluginsNotInList(displayedPlugins); 175 194 } 176 195 revalidate(); … … 179 198 } 180 199 200 /** 201 * Hides components in the list for plugins that are currently filtered away. 202 * 203 * Since those components are relatively heavyweight rebuilding them every time 204 * when the filter changes is fairly slow, so we build them once and just hide 205 * those that shouldn't be visible. 206 * 207 * @param displayedPlugins A collection of plugins that are currently visible. 208 */ 209 private void hidePluginsNotInList(List<PluginInformation> displayedPlugins) { 210 // Remove the empty plugin list warning if it's there 211 synchronized (getTreeLock()) { 212 for (int i = 0; i < getComponentCount(); i++) { 213 JComponent component = (JComponent) getComponent(i); 214 if ("empty".equals(component.getClientProperty("plugin"))) { 215 remove(component); 216 } 217 } 218 } 219 220 Set<PluginInformation> displayedPluginsSet = new HashSet<>(displayedPlugins); 221 synchronized (getTreeLock()) { 222 for (int i = 0; i < getComponentCount(); i++) { 223 JComponent component = (JComponent) getComponent(i); 224 Object plugin = component.getClientProperty("plugin"); 225 component.setVisible(displayedPluginsSet.contains(plugin)); 226 } 227 } 228 } 229 230 /** 231 * Causes the components for the list items to be rebuilt from scratch. 232 * 233 * Should be called before calling {@link #refreshView()} whenever the 234 * underlying list changes to display a completely different set of 235 * plugins instead of merely hiding plugins by a filter. 236 */ 237 public void resetDisplayedComponents() { 238 pluginListInitialized = false; 239 } 240 181 241 @Override 182 242 public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) { -
trunk/src/org/openstreetmap/josm/gui/preferences/plugin/PluginPreference.java
r17768 r17784 323 323 SwingUtilities.invokeLater(() -> { 324 324 model.setAvailablePlugins(task.getAvailablePlugins()); 325 pnlPluginPreferences.resetDisplayedComponents(); 325 326 pnlPluginPreferences.refreshView(); 326 327 }); … … 356 357 SwingUtilities.invokeLater(() -> { 357 358 model.updateAvailablePlugins(task.getAvailablePlugins()); 359 pnlPluginPreferences.resetDisplayedComponents(); 358 360 pnlPluginPreferences.refreshView(); 359 361 Config.getPref().putInt("pluginmanager.version", Version.getInstance().getVersion()); // fix #7030
Note:
See TracChangeset
for help on using the changeset viewer.