Ticket #20720: 20720-2021-04-13.patch
| File 20720-2021-04-13.patch, 6.3 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 import javax.swing.JLabel; 15 import javax.swing.SwingConstants; 16 import javax.swing.SwingUtilities; 20 import javax.swing.*; 17 21 18 22 import org.openstreetmap.josm.gui.widgets.HtmlPanel; 19 23 import org.openstreetmap.josm.gui.widgets.VerticallyScrollablePanel; … … 38 42 39 43 private final transient PluginPreferencesModel model; 40 44 45 /** Whether the plugin list has been built up already in the UI. */ 46 private boolean pluginListInitialized = false; 47 41 48 /** 42 49 * Constructs a new {@code PluginListPanel} with a default model. 43 50 */ … … 104 111 tr("The filter returned no results.")) 105 112 + "</html>" 106 113 ); 114 hint.putClientProperty("plugin", "empty"); 107 115 add(hint, gbc); 108 116 } 109 117 … … 141 149 gbc.insets = new Insets(5, 5, 0, 5); 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 150 160 HtmlPanel description = new HtmlPanel(); … … 156 166 gbc.gridy = ++row; 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(); 177 196 repaint(); 178 197 SwingUtilities.invokeLater(() -> scrollRectToVisible(visibleRect)); 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) { 183 243 return visibleRect.height / 4; -
src/org/openstreetmap/josm/gui/preferences/plugin/PluginPreference.java
339 339 if (!task.isCanceled()) { 340 340 SwingUtilities.invokeLater(() -> { 341 341 model.setAvailablePlugins(task.getAvailablePlugins()); 342 pnlPluginPreferences.resetDisplayedComponents(); 342 343 pnlPluginPreferences.refreshView(); 343 344 }); 344 345 } … … 372 373 if (!task.isCanceled()) { 373 374 SwingUtilities.invokeLater(() -> { 374 375 model.updateAvailablePlugins(task.getAvailablePlugins()); 376 pnlPluginPreferences.resetDisplayedComponents(); 375 377 pnlPluginPreferences.refreshView(); 376 378 Config.getPref().putInt("pluginmanager.version", Version.getInstance().getVersion()); // fix #7030 377 379 });
