Changeset 15581 in josm
- Timestamp:
- 2019-12-11T01:34:19+01:00 (5 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/HelpAction.java
r15490 r15581 10 10 import java.util.Arrays; 11 11 import java.util.List; 12 import java.util.Map;13 import java.util.Objects;14 import java.util.function.IntFunction;15 12 16 13 import javax.swing.AbstractAction; 17 import javax.swing.JTable;18 14 import javax.swing.KeyStroke; 19 15 import javax.xml.parsers.ParserConfigurationException; … … 35 31 * @since 13521 36 32 */ 37 public class HelpAction extends AbstractAction { 38 private final JTable tagTable; 39 private final IntFunction<String> tagKeySupplier; 40 private final IntFunction<Map<String, Integer>> tagValuesSupplier; 41 42 private final JTable membershipTable; 43 private final IntFunction<IRelation<?>> memberValueSupplier; 33 public abstract class HelpAction extends AbstractAction { 44 34 45 35 /** 46 36 * Constructs a new {@code HelpAction}. 47 * @param tagTable The tag table. Cannot be null48 * @param tagKeySupplier Finds the key from given row of tag table. Cannot be null49 * @param tagValuesSupplier Finds the values from given row of tag table (map of values and number of occurrences). Cannot be null50 * @param membershipTable The membership table. Can be null51 * @param memberValueSupplier Finds the parent relation from given row of membership table. Can be null52 * @since 13959 (signature)53 37 */ 54 public HelpAction(JTable tagTable, IntFunction<String> tagKeySupplier, IntFunction<Map<String, Integer>> tagValuesSupplier, 55 JTable membershipTable, IntFunction<IRelation<?>> memberValueSupplier) { 56 this.tagTable = Objects.requireNonNull(tagTable); 57 this.tagKeySupplier = Objects.requireNonNull(tagKeySupplier); 58 this.tagValuesSupplier = Objects.requireNonNull(tagValuesSupplier); 59 this.membershipTable = membershipTable; 60 this.memberValueSupplier = memberValueSupplier; 61 putValue(NAME, tr("Go to OSM wiki for tag help")); 38 public HelpAction() { 62 39 putValue(SHORT_DESCRIPTION, tr("Launch browser with wiki help for selected object")); 63 40 new ImageProvider("dialogs", "search").getResource().attachImageIcon(this, true); … … 69 46 * @return the keystroke launching this action 70 47 */ 71 public KeyStroke getKeyStroke() {48 public static KeyStroke getKeyStroke() { 72 49 return KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0); 73 50 } … … 75 52 @Override 76 53 public void actionPerformed(ActionEvent e) { 77 if (tagTable.getSelectedRowCount() == 1) { 78 int row = tagTable.getSelectedRow(); 79 String key = tagKeySupplier.apply(row); 80 Map<String, Integer> m = tagValuesSupplier.apply(row); 81 if (!m.isEmpty()) { 82 String val = m.entrySet().iterator().next().getKey(); 83 MainApplication.worker.execute(() -> displayTagHelp(key, val)); 84 } 85 } else if (membershipTable != null && membershipTable.getSelectedRowCount() == 1) { 86 int row = membershipTable.getSelectedRow(); 87 final IRelation<?> relation = memberValueSupplier.apply(row); 88 MainApplication.worker.execute(() -> displayRelationHelp(relation)); 89 } else { 90 // give the generic help page, if more than one element is selected 91 MainApplication.worker.execute(HelpAction::displayGenericHelp); 92 } 54 // give the generic help page, if more than one element is selected 55 MainApplication.worker.execute(HelpAction::displayGenericHelp); 93 56 } 94 57 -
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java
r15565 r15581 185 185 186 186 private final transient DataSetListenerAdapter dataChangedAdapter = new DataSetListenerAdapter(this); 187 private final HelpAction help Action = new HelpAction(tagTable, editHelper::getDataKey, editHelper::getDataValues,188 187 private final HelpAction helpTagAction = new HelpTagAction(tagTable, editHelper::getDataKey, editHelper::getDataValues); 188 private final HelpAction helpRelAction = new HelpMembershipAction(membershipTable, x -> (IRelation<?>) membershipData.getValueAt(x, 0)); 189 189 private final TaginfoAction taginfoAction = new TaginfoAction(tagTable, editHelper::getDataKey, editHelper::getDataValues, 190 190 membershipTable, x -> (IRelation<?>) membershipData.getValueAt(x, 0)); … … 389 389 RelationPopupMenus.setupHandler(membershipMenuHandler, EditRelationAction.class, DeleteRelationsAction.class); 390 390 membershipMenu.addSeparator(); 391 membershipMenu.add(help Action);391 membershipMenu.add(helpRelAction); 392 392 membershipMenu.add(taginfoAction); 393 393 … … 441 441 tagMenu.add(searchActionSame); 442 442 tagMenu.addSeparator(); 443 tagMenu.add(help Action);443 tagMenu.add(helpTagAction); 444 444 tagMenu.add(taginfoAction); 445 445 tagTable.addMouseListener(new PopupMenuLauncher(tagMenu)); … … 486 486 // F1 button = custom help action 487 487 getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put( 488 helpAction.getKeyStroke(), "onHelp"); 489 getActionMap().put("onHelp", helpAction); 488 HelpAction.getKeyStroke(), "onHelp"); 489 getActionMap().put("onHelp", new AbstractAction() { 490 @Override 491 public void actionPerformed(ActionEvent e) { 492 if (membershipTable.getSelectedRowCount() == 1) { 493 helpRelAction.actionPerformed(e); 494 } else { 495 helpTagAction.actionPerformed(e); 496 } 497 } 498 }); 490 499 } 491 500 -
trunk/src/org/openstreetmap/josm/gui/history/TagInfoViewer.java
r14463 r15581 20 20 import org.openstreetmap.josm.gui.dialogs.properties.CopyKeyValueAction; 21 21 import org.openstreetmap.josm.gui.dialogs.properties.CopyValueAction; 22 import org.openstreetmap.josm.gui.dialogs.properties.Help Action;22 import org.openstreetmap.josm.gui.dialogs.properties.HelpTagAction; 23 23 import org.openstreetmap.josm.gui.dialogs.properties.TaginfoAction; 24 24 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher; … … 95 95 tagMenu.add(trackJosmAction(new CopyAllKeyValueAction(table, tagKeyFn, objectSp))); 96 96 tagMenu.addSeparator(); 97 tagMenu.add(trackJosmAction(new Help Action(table, tagKeyFn, tagValuesFn, null, null)));97 tagMenu.add(trackJosmAction(new HelpTagAction(table, tagKeyFn, tagValuesFn))); 98 98 tagMenu.add(trackJosmAction(new TaginfoAction(table, tagKeyFn, tagValuesFn, null, null))); 99 99
Note:
See TracChangeset
for help on using the changeset viewer.