Changeset 10811 in josm
- Timestamp:
- 2016-08-15T18:14:44+02:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/preferences/plugin/PluginPreference.java
r10763 r10811 17 17 import java.lang.reflect.InvocationTargetException; 18 18 import java.util.ArrayList; 19 import java.util.Arrays; 19 20 import java.util.Collection; 20 21 import java.util.Collections; … … 23 24 import java.util.List; 24 25 import java.util.Set; 26 import java.util.regex.Pattern; 25 27 26 28 import javax.swing.AbstractAction; … … 28 30 import javax.swing.DefaultListModel; 29 31 import javax.swing.JButton; 32 import javax.swing.JCheckBox; 30 33 import javax.swing.JLabel; 31 34 import javax.swing.JList; … … 34 37 import javax.swing.JScrollPane; 35 38 import javax.swing.JTabbedPane; 39 import javax.swing.JTextArea; 36 40 import javax.swing.SwingUtilities; 37 41 import javax.swing.UIManager; … … 40 44 41 45 import org.openstreetmap.josm.Main; 46 import org.openstreetmap.josm.actions.ExpertToggleAction; 42 47 import org.openstreetmap.josm.data.Version; 43 48 import org.openstreetmap.josm.gui.HelpAwareOptionPane; … … 58 63 import org.openstreetmap.josm.tools.GBC; 59 64 import org.openstreetmap.josm.tools.ImageProvider; 65 import org.openstreetmap.josm.tools.Utils; 60 66 61 67 /** … … 182 188 183 189 private JPanel buildActionPanel() { 184 JPanel pnl = new JPanel(new GridLayout(1, 3));190 JPanel pnl = new JPanel(new GridLayout(1, 4)); 185 191 186 192 pnl.add(new JButton(new DownloadAvailablePluginsAction())); 187 193 pnl.add(new JButton(new UpdateSelectedPluginsAction())); 188 pnl.add(new JButton(new ConfigureSitesAction())); 194 ExpertToggleAction.addVisibilitySwitcher(pnl.add(new JButton(new SelectByListAction()))); 195 ExpertToggleAction.addVisibilitySwitcher(pnl.add(new JButton(new ConfigureSitesAction()))); 189 196 return pnl; 190 197 } … … 462 469 463 470 /** 471 * The action for selecting the plugins given by a text file compatible to JOSM bug report. 472 * @author Michael Zangl 473 */ 474 class SelectByListAction extends AbstractAction { 475 SelectByListAction() { 476 putValue(NAME, tr("Load from list...")); 477 putValue(SHORT_DESCRIPTION, tr("Load plugins from a list of plugins")); 478 } 479 480 @Override 481 public void actionPerformed(ActionEvent e) { 482 JTextArea textField = new JTextArea(10, 0); 483 JCheckBox deleteNotInList = new JCheckBox(tr("Disable all other plugins")); 484 485 JLabel helpLabel = new JLabel("<html>" + Utils.join("<br/>", Arrays.asList( 486 tr("Enter a list of plugins you want to download."), 487 tr("You should add one plugin id per line, version information is ignored."), 488 tr("You can copy+paste the list of a status report here."))) + "</html>"); 489 490 if (JOptionPane.OK_OPTION == JOptionPane.showConfirmDialog(GuiHelper.getFrameForComponent(getTabPane()), 491 new Object[] {helpLabel, new JScrollPane(textField), deleteNotInList}, 492 tr("Load plugins from list"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE)) { 493 activatePlugins(textField, deleteNotInList.isSelected()); 494 } 495 } 496 497 private void activatePlugins(JTextArea textField, boolean deleteNotInList) { 498 String[] lines = textField.getText().split("\n"); 499 List<String> toActivate = new ArrayList<>(); 500 List<String> notFound = new ArrayList<>(); 501 Pattern regex = Pattern.compile("^[-+\\s]*|\\s[\\(\\)\\d\\s]*"); 502 for (String line : lines) { 503 String name = regex.matcher(line).replaceAll(""); 504 if (name.isEmpty()) { 505 continue; 506 } 507 PluginInformation plugin = model.getPluginInformation(name); 508 if (plugin == null) { 509 notFound.add(name); 510 } else { 511 toActivate.add(name); 512 } 513 } 514 515 if (notFound.isEmpty() || confirmIgnoreNotFound(notFound)) { 516 activatePlugins(toActivate, deleteNotInList); 517 } 518 } 519 520 private void activatePlugins(List<String> toActivate, boolean deleteNotInList) { 521 if (deleteNotInList) { 522 for (String name : model.getSelectedPluginNames()) { 523 if (!toActivate.contains(name)) { 524 model.setPluginSelected(name, false); 525 } 526 } 527 } 528 for (String name : toActivate) { 529 model.setPluginSelected(name, true); 530 } 531 pnlPluginPreferences.refreshView(); 532 } 533 534 private boolean confirmIgnoreNotFound(List<String> notFound) { 535 String list = "<ul><li>" + Utils.join("</li><li>", notFound) + "</li></ul>"; 536 String message = "<html>" + tr("The following plugins were not found. Continue anyway?") + list + "</html>"; 537 return JOptionPane.showConfirmDialog(GuiHelper.getFrameForComponent(getTabPane()), 538 message) == JOptionPane.OK_OPTION; 539 } 540 } 541 542 /** 464 543 * Applies the current filter condition in the filter text field to the model. 465 544 */
Note:
See TracChangeset
for help on using the changeset viewer.