[3202] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
[2657] | 2 | package org.openstreetmap.josm.gui.dialogs.properties;
|
---|
[272] | 3 |
|
---|
| 4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
| 5 |
|
---|
| 6 | import java.awt.Component;
|
---|
[5472] | 7 | import java.awt.Container;
|
---|
[272] | 8 | import java.awt.Font;
|
---|
| 9 | import java.awt.GridBagLayout;
|
---|
[2723] | 10 | import java.awt.Point;
|
---|
[272] | 11 | import java.awt.event.ActionEvent;
|
---|
[5843] | 12 | import java.awt.event.InputEvent;
|
---|
[272] | 13 | import java.awt.event.KeyEvent;
|
---|
| 14 | import java.awt.event.MouseAdapter;
|
---|
| 15 | import java.awt.event.MouseEvent;
|
---|
[2657] | 16 | import java.util.ArrayList;
|
---|
[4300] | 17 | import java.util.Arrays;
|
---|
[272] | 18 | import java.util.Collection;
|
---|
[5155] | 19 | import java.util.EnumSet;
|
---|
[272] | 20 | import java.util.HashMap;
|
---|
[6652] | 21 | import java.util.HashSet;
|
---|
[1970] | 22 | import java.util.List;
|
---|
[4604] | 23 | import java.util.Map;
|
---|
[5383] | 24 | import java.util.Map.Entry;
|
---|
[11553] | 25 | import java.util.Optional;
|
---|
[4454] | 26 | import java.util.Set;
|
---|
[3529] | 27 | import java.util.TreeMap;
|
---|
[4454] | 28 | import java.util.TreeSet;
|
---|
[14669] | 29 | import java.util.concurrent.atomic.AtomicBoolean;
|
---|
[272] | 30 |
|
---|
[1945] | 31 | import javax.swing.AbstractAction;
|
---|
| 32 | import javax.swing.JComponent;
|
---|
[272] | 33 | import javax.swing.JLabel;
|
---|
| 34 | import javax.swing.JPanel;
|
---|
[2723] | 35 | import javax.swing.JPopupMenu;
|
---|
[272] | 36 | import javax.swing.JScrollPane;
|
---|
| 37 | import javax.swing.JTable;
|
---|
[1945] | 38 | import javax.swing.KeyStroke;
|
---|
[272] | 39 | import javax.swing.ListSelectionModel;
|
---|
[1945] | 40 | import javax.swing.event.ListSelectionEvent;
|
---|
| 41 | import javax.swing.event.ListSelectionListener;
|
---|
[9877] | 42 | import javax.swing.event.RowSorterEvent;
|
---|
| 43 | import javax.swing.event.RowSorterListener;
|
---|
[272] | 44 | import javax.swing.table.DefaultTableCellRenderer;
|
---|
| 45 | import javax.swing.table.DefaultTableModel;
|
---|
[9149] | 46 | import javax.swing.table.TableCellRenderer;
|
---|
[3327] | 47 | import javax.swing.table.TableColumnModel;
|
---|
[2742] | 48 | import javax.swing.table.TableModel;
|
---|
[8980] | 49 | import javax.swing.table.TableRowSorter;
|
---|
[272] | 50 |
|
---|
[4518] | 51 | import org.openstreetmap.josm.actions.JosmAction;
|
---|
[5825] | 52 | import org.openstreetmap.josm.actions.relation.DownloadMembersAction;
|
---|
[5793] | 53 | import org.openstreetmap.josm.actions.relation.DownloadSelectedIncompleteMembersAction;
|
---|
[5825] | 54 | import org.openstreetmap.josm.actions.relation.SelectInRelationListAction;
|
---|
[5793] | 55 | import org.openstreetmap.josm.actions.relation.SelectMembersAction;
|
---|
| 56 | import org.openstreetmap.josm.actions.relation.SelectRelationAction;
|
---|
[810] | 57 | import org.openstreetmap.josm.command.ChangeCommand;
|
---|
[272] | 58 | import org.openstreetmap.josm.command.ChangePropertyCommand;
|
---|
[621] | 59 | import org.openstreetmap.josm.command.Command;
|
---|
[14134] | 60 | import org.openstreetmap.josm.data.UndoRedoHandler;
|
---|
[13809] | 61 | import org.openstreetmap.josm.data.osm.AbstractPrimitive;
|
---|
[13925] | 62 | import org.openstreetmap.josm.data.osm.DataSelectionListener;
|
---|
[13434] | 63 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
[12663] | 64 | import org.openstreetmap.josm.data.osm.DefaultNameFormatter;
|
---|
[13926] | 65 | import org.openstreetmap.josm.data.osm.IPrimitive;
|
---|
[4536] | 66 | import org.openstreetmap.josm.data.osm.IRelation;
|
---|
[13926] | 67 | import org.openstreetmap.josm.data.osm.IRelationMember;
|
---|
[1407] | 68 | import org.openstreetmap.josm.data.osm.Node;
|
---|
[13956] | 69 | import org.openstreetmap.josm.data.osm.OsmData;
|
---|
[14143] | 70 | import org.openstreetmap.josm.data.osm.OsmDataManager;
|
---|
[272] | 71 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
[343] | 72 | import org.openstreetmap.josm.data.osm.Relation;
|
---|
| 73 | import org.openstreetmap.josm.data.osm.RelationMember;
|
---|
[3518] | 74 | import org.openstreetmap.josm.data.osm.Tag;
|
---|
[1407] | 75 | import org.openstreetmap.josm.data.osm.Way;
|
---|
[2741] | 76 | import org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent;
|
---|
| 77 | import org.openstreetmap.josm.data.osm.event.DataSetListenerAdapter;
|
---|
[2657] | 78 | import org.openstreetmap.josm.data.osm.event.DatasetEventManager;
|
---|
[5383] | 79 | import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode;
|
---|
[12726] | 80 | import org.openstreetmap.josm.data.osm.event.SelectionEventManager;
|
---|
[12656] | 81 | import org.openstreetmap.josm.data.osm.search.SearchCompiler;
|
---|
[12659] | 82 | import org.openstreetmap.josm.data.osm.search.SearchSetting;
|
---|
[6595] | 83 | import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil;
|
---|
[1397] | 84 | import org.openstreetmap.josm.gui.ExtendedDialog;
|
---|
[12630] | 85 | import org.openstreetmap.josm.gui.MainApplication;
|
---|
[5821] | 86 | import org.openstreetmap.josm.gui.PopupMenuHandler;
|
---|
[810] | 87 | import org.openstreetmap.josm.gui.SideButton;
|
---|
[10604] | 88 | import org.openstreetmap.josm.gui.datatransfer.ClipboardUtils;
|
---|
[2657] | 89 | import org.openstreetmap.josm.gui.dialogs.ToggleDialog;
|
---|
[1599] | 90 | import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor;
|
---|
[7862] | 91 | import org.openstreetmap.josm.gui.help.HelpUtil;
|
---|
[10332] | 92 | import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
|
---|
| 93 | import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
|
---|
[13434] | 94 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
---|
[8980] | 95 | import org.openstreetmap.josm.gui.tagging.presets.TaggingPreset;
|
---|
[8863] | 96 | import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetHandler;
|
---|
| 97 | import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetType;
|
---|
[6025] | 98 | import org.openstreetmap.josm.gui.util.HighlightHelper;
|
---|
[14476] | 99 | import org.openstreetmap.josm.gui.util.TableHelper;
|
---|
[8980] | 100 | import org.openstreetmap.josm.gui.widgets.CompileSearchTextDecorator;
|
---|
| 101 | import org.openstreetmap.josm.gui.widgets.DisableShortcutsOnFocusGainedTextField;
|
---|
| 102 | import org.openstreetmap.josm.gui.widgets.JosmTextField;
|
---|
[2723] | 103 | import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
|
---|
[12846] | 104 | import org.openstreetmap.josm.spi.preferences.Config;
|
---|
[13130] | 105 | import org.openstreetmap.josm.spi.preferences.PreferenceChangedListener;
|
---|
[8996] | 106 | import org.openstreetmap.josm.tools.AlphanumComparator;
|
---|
[272] | 107 | import org.openstreetmap.josm.tools.GBC;
|
---|
[5200] | 108 | import org.openstreetmap.josm.tools.InputMapUtils;
|
---|
[12620] | 109 | import org.openstreetmap.josm.tools.Logging;
|
---|
[1084] | 110 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
[4454] | 111 | import org.openstreetmap.josm.tools.Utils;
|
---|
[272] | 112 |
|
---|
| 113 | /**
|
---|
[6324] | 114 | * This dialog displays the tags of the current selected primitives.
|
---|
[272] | 115 | *
|
---|
| 116 | * If no object is selected, the dialog list is empty.
|
---|
[6324] | 117 | * If only one is selected, all tags of this object are selected.
|
---|
| 118 | * If more than one object are selected, the sum of all tags are displayed. If the
|
---|
| 119 | * different objects share the same tag, the shared value is displayed. If they have
|
---|
[272] | 120 | * different values, all of them are put in a combo box and the string "<different>"
|
---|
| 121 | * is displayed in italic.
|
---|
| 122 | *
|
---|
[6324] | 123 | * Below the list, the user can click on an add, modify and delete tag button to
|
---|
[272] | 124 | * edit the table selection value.
|
---|
| 125 | *
|
---|
| 126 | * The command is applied to all selected entries.
|
---|
| 127 | *
|
---|
| 128 | * @author imi
|
---|
| 129 | */
|
---|
[8509] | 130 | public class PropertiesDialog extends ToggleDialog
|
---|
[13925] | 131 | implements DataSelectionListener, ActiveLayerChangeListener, DataSetListenerAdapter.Listener {
|
---|
[5821] | 132 |
|
---|
| 133 | /**
|
---|
| 134 | * hook for roadsigns plugin to display a small button in the upper right corner of this dialog
|
---|
| 135 | */
|
---|
[5799] | 136 | public static final JPanel pluginHook = new JPanel();
|
---|
| 137 |
|
---|
[1169] | 138 | /**
|
---|
[6324] | 139 | * The tag data of selected objects.
|
---|
[1169] | 140 | */
|
---|
[8980] | 141 | private final ReadOnlyTableModel tagData = new ReadOnlyTableModel();
|
---|
[9149] | 142 | private final PropertiesCellRenderer cellRenderer = new PropertiesCellRenderer();
|
---|
[9623] | 143 | private final transient TableRowSorter<ReadOnlyTableModel> tagRowSorter = new TableRowSorter<>(tagData);
|
---|
[8980] | 144 | private final JosmTextField tagTableFilter;
|
---|
[5633] | 145 |
|
---|
[5799] | 146 | /**
|
---|
| 147 | * The membership data of selected objects.
|
---|
| 148 | */
|
---|
| 149 | private final DefaultTableModel membershipData = new ReadOnlyTableModel();
|
---|
[272] | 150 |
|
---|
[5799] | 151 | /**
|
---|
[6324] | 152 | * The tags table.
|
---|
[5799] | 153 | */
|
---|
[6324] | 154 | private final JTable tagTable = new JTable(tagData);
|
---|
[7368] | 155 |
|
---|
[5799] | 156 | /**
|
---|
| 157 | * The membership table.
|
---|
| 158 | */
|
---|
| 159 | private final JTable membershipTable = new JTable(membershipData);
|
---|
[4604] | 160 |
|
---|
[6939] | 161 | /** JPanel containing both previous tables */
|
---|
[9543] | 162 | private final JPanel bothTables = new JPanel(new GridBagLayout());
|
---|
[6939] | 163 |
|
---|
[5821] | 164 | // Popup menus
|
---|
[6324] | 165 | private final JPopupMenu tagMenu = new JPopupMenu();
|
---|
[5821] | 166 | private final JPopupMenu membershipMenu = new JPopupMenu();
|
---|
[6939] | 167 | private final JPopupMenu blankSpaceMenu = new JPopupMenu();
|
---|
[3444] | 168 |
|
---|
[5821] | 169 | // Popup menu handlers
|
---|
[8308] | 170 | private final transient PopupMenuHandler tagMenuHandler = new PopupMenuHandler(tagMenu);
|
---|
| 171 | private final transient PopupMenuHandler membershipMenuHandler = new PopupMenuHandler(membershipMenu);
|
---|
| 172 | private final transient PopupMenuHandler blankSpaceMenuHandler = new PopupMenuHandler(blankSpaceMenu);
|
---|
[5821] | 173 |
|
---|
[8308] | 174 | private final transient Map<String, Map<String, Integer>> valueCount = new TreeMap<>();
|
---|
[5799] | 175 | /**
|
---|
[6324] | 176 | * This sub-object is responsible for all adding and editing of tags
|
---|
[5799] | 177 | */
|
---|
[9086] | 178 | private final transient TagEditHelper editHelper = new TagEditHelper(tagTable, tagData, valueCount);
|
---|
[6070] | 179 |
|
---|
[8308] | 180 | private final transient DataSetListenerAdapter dataChangedAdapter = new DataSetListenerAdapter(this);
|
---|
[13521] | 181 | private final HelpAction helpAction = new HelpAction(tagTable, editHelper::getDataKey, editHelper::getDataValues,
|
---|
[13959] | 182 | membershipTable, x -> (IRelation<?>) membershipData.getValueAt(x, 0));
|
---|
[13521] | 183 | private final TaginfoAction taginfoAction = new TaginfoAction(tagTable, editHelper::getDataKey, editHelper::getDataValues,
|
---|
[13959] | 184 | membershipTable, x -> (IRelation<?>) membershipData.getValueAt(x, 0));
|
---|
[5726] | 185 | private final PasteValueAction pasteValueAction = new PasteValueAction();
|
---|
[13521] | 186 | private final CopyValueAction copyValueAction = new CopyValueAction(
|
---|
[14143] | 187 | tagTable, editHelper::getDataKey, OsmDataManager.getInstance()::getInProgressISelection);
|
---|
[13521] | 188 | private final CopyKeyValueAction copyKeyValueAction = new CopyKeyValueAction(
|
---|
[14143] | 189 | tagTable, editHelper::getDataKey, OsmDataManager.getInstance()::getInProgressISelection);
|
---|
[13521] | 190 | private final CopyAllKeyValueAction copyAllKeyValueAction = new CopyAllKeyValueAction(
|
---|
[14143] | 191 | tagTable, editHelper::getDataKey, OsmDataManager.getInstance()::getInProgressISelection);
|
---|
[5459] | 192 | private final SearchAction searchActionSame = new SearchAction(true);
|
---|
| 193 | private final SearchAction searchActionAny = new SearchAction(false);
|
---|
| 194 | private final AddAction addAction = new AddAction();
|
---|
| 195 | private final EditAction editAction = new EditAction();
|
---|
| 196 | private final DeleteAction deleteAction = new DeleteAction();
|
---|
| 197 | private final JosmAction[] josmActions = new JosmAction[]{addAction, editAction, deleteAction};
|
---|
[2741] | 198 |
|
---|
[5793] | 199 | // relation actions
|
---|
[5825] | 200 | private final SelectInRelationListAction setRelationSelectionAction = new SelectInRelationListAction();
|
---|
| 201 | private final SelectRelationAction selectRelationAction = new SelectRelationAction(false);
|
---|
| 202 | private final SelectRelationAction addRelationToSelectionAction = new SelectRelationAction(true);
|
---|
[6070] | 203 |
|
---|
[5825] | 204 | private final DownloadMembersAction downloadMembersAction = new DownloadMembersAction();
|
---|
[8540] | 205 | private final DownloadSelectedIncompleteMembersAction downloadSelectedIncompleteMembersAction =
|
---|
| 206 | new DownloadSelectedIncompleteMembersAction();
|
---|
[6070] | 207 |
|
---|
[5825] | 208 | private final SelectMembersAction selectMembersAction = new SelectMembersAction(false);
|
---|
[5793] | 209 | private final SelectMembersAction addMembersToSelectionAction = new SelectMembersAction(true);
|
---|
[6070] | 210 |
|
---|
[8510] | 211 | private final transient HighlightHelper highlightHelper = new HighlightHelper();
|
---|
[6070] | 212 |
|
---|
[1169] | 213 | /**
|
---|
[5481] | 214 | * The Add button (needed to be able to disable it)
|
---|
[1353] | 215 | */
|
---|
[5799] | 216 | private final SideButton btnAdd = new SideButton(addAction);
|
---|
[5481] | 217 | /**
|
---|
| 218 | * The Edit button (needed to be able to disable it)
|
---|
| 219 | */
|
---|
[5799] | 220 | private final SideButton btnEdit = new SideButton(editAction);
|
---|
[5481] | 221 | /**
|
---|
| 222 | * The Delete button (needed to be able to disable it)
|
---|
| 223 | */
|
---|
[5799] | 224 | private final SideButton btnDel = new SideButton(deleteAction);
|
---|
[5481] | 225 | /**
|
---|
| 226 | * Matching preset display class
|
---|
| 227 | */
|
---|
[3518] | 228 | private final PresetListPanel presets = new PresetListPanel();
|
---|
[6070] | 229 |
|
---|
[5481] | 230 | /**
|
---|
| 231 | * Text to display when nothing selected.
|
---|
| 232 | */
|
---|
[1606] | 233 | private final JLabel selectSth = new JLabel("<html><p>"
|
---|
[6324] | 234 | + tr("Select objects for which to change tags.") + "</p></html>");
|
---|
[1353] | 235 |
|
---|
[10824] | 236 | private final PreferenceChangedListener preferenceListener = e -> {
|
---|
[13926] | 237 | if (MainApplication.getLayerManager().getActiveData() != null) {
|
---|
[10824] | 238 | // Re-load data when display preference change
|
---|
| 239 | updateSelection();
|
---|
[10827] | 240 | }
|
---|
| 241 | };
|
---|
[10824] | 242 |
|
---|
[11357] | 243 | private final transient TaggingPresetHandler presetHandler = new TaggingPresetCommandHandler();
|
---|
[5799] | 244 |
|
---|
[1169] | 245 | /**
|
---|
| 246 | * Create a new PropertiesDialog
|
---|
| 247 | */
|
---|
[6361] | 248 | public PropertiesDialog() {
|
---|
[6324] | 249 | super(tr("Tags/Memberships"), "propertiesdialog", tr("Tags for selected objects."),
|
---|
| 250 | Shortcut.registerShortcut("subwindow:properties", tr("Toggle: {0}", tr("Tags/Memberships")), KeyEvent.VK_P,
|
---|
[4982] | 251 | Shortcut.ALT_SHIFT), 150, true);
|
---|
[272] | 252 |
|
---|
[6324] | 253 | setupTagsMenu();
|
---|
| 254 | buildTagsTable();
|
---|
[5799] | 255 |
|
---|
| 256 | setupMembershipMenu();
|
---|
| 257 | buildMembershipTable();
|
---|
[6070] | 258 |
|
---|
[8980] | 259 | tagTableFilter = setupFilter();
|
---|
| 260 |
|
---|
[5799] | 261 | // combine both tables and wrap them in a scrollPane
|
---|
[12846] | 262 | boolean top = Config.getPref().getBoolean("properties.presets.top", true);
|
---|
[14424] | 263 | boolean presetsVisible = Config.getPref().getBoolean("properties.presets.visible", true);
|
---|
[14423] | 264 | if (presetsVisible && top) {
|
---|
[5799] | 265 | bothTables.add(presets, GBC.std().fill(GBC.HORIZONTAL).insets(5, 2, 5, 2).anchor(GBC.NORTHWEST));
|
---|
| 266 | double epsilon = Double.MIN_VALUE; // need to set a weight or else anchor value is ignored
|
---|
[8510] | 267 | bothTables.add(pluginHook, GBC.eol().insets(0, 1, 1, 1).anchor(GBC.NORTHEAST).weight(epsilon, epsilon));
|
---|
[5799] | 268 | }
|
---|
| 269 | bothTables.add(selectSth, GBC.eol().fill().insets(10, 10, 10, 10));
|
---|
[8980] | 270 | bothTables.add(tagTableFilter, GBC.eol().fill(GBC.HORIZONTAL));
|
---|
[6324] | 271 | bothTables.add(tagTable.getTableHeader(), GBC.eol().fill(GBC.HORIZONTAL));
|
---|
| 272 | bothTables.add(tagTable, GBC.eol().fill(GBC.BOTH));
|
---|
[5799] | 273 | bothTables.add(membershipTable.getTableHeader(), GBC.eol().fill(GBC.HORIZONTAL));
|
---|
| 274 | bothTables.add(membershipTable, GBC.eol().fill(GBC.BOTH));
|
---|
[14423] | 275 | if (presetsVisible && !top) {
|
---|
[5799] | 276 | bothTables.add(presets, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 2, 5, 2));
|
---|
| 277 | }
|
---|
[7368] | 278 |
|
---|
[6939] | 279 | setupBlankSpaceMenu();
|
---|
[5799] | 280 | setupKeyboardShortcuts();
|
---|
| 281 |
|
---|
[6939] | 282 | // Let the actions know when selection in the tables change
|
---|
[6324] | 283 | tagTable.getSelectionModel().addListSelectionListener(editAction);
|
---|
[5799] | 284 | membershipTable.getSelectionModel().addListSelectionListener(editAction);
|
---|
[6324] | 285 | tagTable.getSelectionModel().addListSelectionListener(deleteAction);
|
---|
[5799] | 286 | membershipTable.getSelectionModel().addListSelectionListener(deleteAction);
|
---|
[6070] | 287 |
|
---|
[7128] | 288 | JScrollPane scrollPane = (JScrollPane) createLayout(bothTables, true,
|
---|
| 289 | Arrays.asList(this.btnAdd, this.btnEdit, this.btnDel));
|
---|
[5799] | 290 |
|
---|
| 291 | MouseClickWatch mouseClickWatch = new MouseClickWatch();
|
---|
[6324] | 292 | tagTable.addMouseListener(mouseClickWatch);
|
---|
[5799] | 293 | membershipTable.addMouseListener(mouseClickWatch);
|
---|
| 294 | scrollPane.addMouseListener(mouseClickWatch);
|
---|
| 295 |
|
---|
| 296 | selectSth.setPreferredSize(scrollPane.getSize());
|
---|
| 297 | presets.setSize(scrollPane.getSize());
|
---|
| 298 |
|
---|
| 299 | editHelper.loadTagsIfNeeded();
|
---|
[7368] | 300 |
|
---|
[12846] | 301 | Config.getPref().addKeyPreferenceChangeListener("display.discardable-keys", preferenceListener);
|
---|
[5799] | 302 | }
|
---|
[6070] | 303 |
|
---|
[14397] | 304 | @Override
|
---|
| 305 | public String helpTopic() {
|
---|
| 306 | return HelpUtil.ht("/Dialog/TagsMembership");
|
---|
| 307 | }
|
---|
| 308 |
|
---|
[6324] | 309 | private void buildTagsTable() {
|
---|
| 310 | // setting up the tags table
|
---|
[8510] | 311 | tagData.setColumnIdentifiers(new String[]{tr("Key"), tr("Value")});
|
---|
[6324] | 312 | tagTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
|
---|
[14476] | 313 | tagTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
|
---|
[6324] | 314 | tagTable.getTableHeader().setReorderingAllowed(false);
|
---|
[6070] | 315 |
|
---|
[6324] | 316 | tagTable.getColumnModel().getColumn(0).setCellRenderer(cellRenderer);
|
---|
| 317 | tagTable.getColumnModel().getColumn(1).setCellRenderer(cellRenderer);
|
---|
[8980] | 318 | tagTable.setRowSorter(tagRowSorter);
|
---|
[8996] | 319 |
|
---|
[9877] | 320 | final RemoveHiddenSelection removeHiddenSelection = new RemoveHiddenSelection();
|
---|
| 321 | tagTable.getSelectionModel().addListSelectionListener(removeHiddenSelection);
|
---|
[9894] | 322 | tagRowSorter.addRowSorterListener(removeHiddenSelection);
|
---|
[8996] | 323 | tagRowSorter.setComparator(0, AlphanumComparator.getInstance());
|
---|
[10611] | 324 | tagRowSorter.setComparator(1, (o1, o2) -> {
|
---|
| 325 | if (o1 instanceof Map && o2 instanceof Map) {
|
---|
| 326 | final String v1 = ((Map) o1).size() == 1 ? (String) ((Map) o1).keySet().iterator().next() : tr("<different>");
|
---|
| 327 | final String v2 = ((Map) o2).size() == 1 ? (String) ((Map) o2).keySet().iterator().next() : tr("<different>");
|
---|
| 328 | return AlphanumComparator.getInstance().compare(v1, v2);
|
---|
| 329 | } else {
|
---|
| 330 | return AlphanumComparator.getInstance().compare(String.valueOf(o1), String.valueOf(o2));
|
---|
[8996] | 331 | }
|
---|
| 332 | });
|
---|
[5799] | 333 | }
|
---|
[1023] | 334 |
|
---|
[5799] | 335 | private void buildMembershipTable() {
|
---|
[8510] | 336 | membershipData.setColumnIdentifiers(new String[]{tr("Member Of"), tr("Role"), tr("Position")});
|
---|
[5793] | 337 | membershipTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
|
---|
[1023] | 338 |
|
---|
[3302] | 339 | TableColumnModel mod = membershipTable.getColumnModel();
|
---|
[4119] | 340 | membershipTable.getTableHeader().setReorderingAllowed(false);
|
---|
[11366] | 341 | mod.getColumn(0).setCellRenderer(new MemberOfCellRenderer());
|
---|
| 342 | mod.getColumn(1).setCellRenderer(new RoleCellRenderer());
|
---|
| 343 | mod.getColumn(2).setCellRenderer(new PositionCellRenderer());
|
---|
[3302] | 344 | mod.getColumn(2).setPreferredWidth(20);
|
---|
| 345 | mod.getColumn(1).setPreferredWidth(40);
|
---|
| 346 | mod.getColumn(0).setPreferredWidth(200);
|
---|
[5799] | 347 | }
|
---|
[6070] | 348 |
|
---|
[5799] | 349 | /**
|
---|
[6939] | 350 | * Creates the popup menu @field blankSpaceMenu and its launcher on main panel.
|
---|
[5799] | 351 | */
|
---|
[6939] | 352 | private void setupBlankSpaceMenu() {
|
---|
[12846] | 353 | if (Config.getPref().getBoolean("properties.menu.add_edit_delete", true)) {
|
---|
[6939] | 354 | blankSpaceMenuHandler.addAction(addAction);
|
---|
[11366] | 355 | PopupMenuLauncher launcher = new BlankSpaceMenuLauncher(blankSpaceMenu);
|
---|
[6939] | 356 | bothTables.addMouseListener(launcher);
|
---|
| 357 | tagTable.addMouseListener(launcher);
|
---|
| 358 | }
|
---|
| 359 | }
|
---|
| 360 |
|
---|
| 361 | /**
|
---|
| 362 | * Creates the popup menu @field membershipMenu and its launcher on membership table.
|
---|
| 363 | */
|
---|
[5799] | 364 | private void setupMembershipMenu() {
|
---|
| 365 | // setting up the membership table
|
---|
[12846] | 366 | if (Config.getPref().getBoolean("properties.menu.add_edit_delete", true)) {
|
---|
[6939] | 367 | membershipMenuHandler.addAction(editAction);
|
---|
| 368 | membershipMenuHandler.addAction(deleteAction);
|
---|
| 369 | membershipMenu.addSeparator();
|
---|
| 370 | }
|
---|
[5825] | 371 | membershipMenuHandler.addAction(setRelationSelectionAction);
|
---|
| 372 | membershipMenuHandler.addAction(selectRelationAction);
|
---|
[5821] | 373 | membershipMenuHandler.addAction(addRelationToSelectionAction);
|
---|
[5825] | 374 | membershipMenuHandler.addAction(selectMembersAction);
|
---|
[5821] | 375 | membershipMenuHandler.addAction(addMembersToSelectionAction);
|
---|
[5825] | 376 | membershipMenu.addSeparator();
|
---|
| 377 | membershipMenuHandler.addAction(downloadMembersAction);
|
---|
[5821] | 378 | membershipMenuHandler.addAction(downloadSelectedIncompleteMembersAction);
|
---|
[5799] | 379 | membershipMenu.addSeparator();
|
---|
| 380 | membershipMenu.add(helpAction);
|
---|
[8679] | 381 | membershipMenu.add(taginfoAction);
|
---|
[3302] | 382 |
|
---|
[5958] | 383 | membershipTable.addMouseListener(new PopupMenuLauncher(membershipMenu) {
|
---|
[5799] | 384 | @Override
|
---|
[5958] | 385 | protected int checkTableSelection(JTable table, Point p) {
|
---|
| 386 | int row = super.checkTableSelection(table, p);
|
---|
[13959] | 387 | List<IRelation<?>> rels = new ArrayList<>();
|
---|
[5958] | 388 | for (int i: table.getSelectedRows()) {
|
---|
[13959] | 389 | rels.add((IRelation<?>) table.getValueAt(i, 0));
|
---|
[5799] | 390 | }
|
---|
[5821] | 391 | membershipMenuHandler.setPrimitives(rels);
|
---|
[5958] | 392 | return row;
|
---|
[5799] | 393 | }
|
---|
[6025] | 394 |
|
---|
| 395 | @Override
|
---|
| 396 | public void mouseClicked(MouseEvent e) {
|
---|
| 397 | //update highlights
|
---|
[12630] | 398 | if (MainApplication.isDisplayingMapView()) {
|
---|
[6025] | 399 | int row = membershipTable.rowAtPoint(e.getPoint());
|
---|
[11386] | 400 | if (row >= 0 && highlightHelper.highlightOnly((Relation) membershipTable.getValueAt(row, 0))) {
|
---|
[12630] | 401 | MainApplication.getMap().mapView.repaint();
|
---|
[6025] | 402 | }
|
---|
| 403 | }
|
---|
| 404 | super.mouseClicked(e);
|
---|
| 405 | }
|
---|
| 406 |
|
---|
| 407 | @Override
|
---|
| 408 | public void mouseExited(MouseEvent me) {
|
---|
| 409 | highlightHelper.clear();
|
---|
| 410 | }
|
---|
[5799] | 411 | });
|
---|
| 412 | }
|
---|
[6070] | 413 |
|
---|
[5799] | 414 | /**
|
---|
[6939] | 415 | * Creates the popup menu @field tagMenu and its launcher on tag table.
|
---|
[5799] | 416 | */
|
---|
[6324] | 417 | private void setupTagsMenu() {
|
---|
[12846] | 418 | if (Config.getPref().getBoolean("properties.menu.add_edit_delete", true)) {
|
---|
[6939] | 419 | tagMenu.add(addAction);
|
---|
| 420 | tagMenu.add(editAction);
|
---|
| 421 | tagMenu.add(deleteAction);
|
---|
| 422 | tagMenu.addSeparator();
|
---|
| 423 | }
|
---|
[6324] | 424 | tagMenu.add(pasteValueAction);
|
---|
| 425 | tagMenu.add(copyValueAction);
|
---|
| 426 | tagMenu.add(copyKeyValueAction);
|
---|
| 427 | tagMenu.add(copyAllKeyValueAction);
|
---|
| 428 | tagMenu.addSeparator();
|
---|
| 429 | tagMenu.add(searchActionAny);
|
---|
| 430 | tagMenu.add(searchActionSame);
|
---|
| 431 | tagMenu.addSeparator();
|
---|
| 432 | tagMenu.add(helpAction);
|
---|
[8679] | 433 | tagMenu.add(taginfoAction);
|
---|
[6324] | 434 | tagTable.addMouseListener(new PopupMenuLauncher(tagMenu));
|
---|
[5799] | 435 | }
|
---|
[6070] | 436 |
|
---|
[8980] | 437 | public void setFilter(final SearchCompiler.Match filter) {
|
---|
| 438 | this.tagRowSorter.setRowFilter(new SearchBasedRowFilter(filter));
|
---|
| 439 | }
|
---|
| 440 |
|
---|
[5799] | 441 | /**
|
---|
[6939] | 442 | * Assigns all needed keys like Enter and Spacebar to most important actions.
|
---|
[5799] | 443 | */
|
---|
| 444 | private void setupKeyboardShortcuts() {
|
---|
[6070] | 445 |
|
---|
[5799] | 446 | // ENTER = editAction, open "edit" dialog
|
---|
[10790] | 447 | InputMapUtils.addEnterActionWhenAncestor(tagTable, editAction);
|
---|
| 448 | InputMapUtils.addEnterActionWhenAncestor(membershipTable, editAction);
|
---|
[6070] | 449 |
|
---|
[6324] | 450 | // INSERT button = addAction, open "add tag" dialog
|
---|
| 451 | tagTable.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
|
---|
[8510] | 452 | .put(KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, 0), "onTableInsert");
|
---|
| 453 | tagTable.getActionMap().put("onTableInsert", addAction);
|
---|
[6070] | 454 |
|
---|
[6557] | 455 | // unassign some standard shortcuts for JTable to allow upload / download / image browsing
|
---|
[6324] | 456 | InputMapUtils.unassignCtrlShiftUpDown(tagTable, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
|
---|
[6557] | 457 | InputMapUtils.unassignPageUpDown(tagTable, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
|
---|
[6070] | 458 |
|
---|
[5843] | 459 | // unassign some standard shortcuts for correct copy-pasting, fix #8508
|
---|
[6324] | 460 | tagTable.setTransferHandler(null);
|
---|
[6070] | 461 |
|
---|
[6324] | 462 | tagTable.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
|
---|
[12523] | 463 | .put(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_DOWN_MASK), "onCopy");
|
---|
[8510] | 464 | tagTable.getActionMap().put("onCopy", copyKeyValueAction);
|
---|
[5843] | 465 |
|
---|
[5799] | 466 | // allow using enter to add tags for all look&feel configurations
|
---|
| 467 | InputMapUtils.enableEnter(this.btnAdd);
|
---|
[6070] | 468 |
|
---|
[5799] | 469 | // DEL button = deleteAction
|
---|
[1945] | 470 | getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(
|
---|
[8510] | 471 | KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), "delete"
|
---|
[4604] | 472 | );
|
---|
[1945] | 473 | getActionMap().put("delete", deleteAction);
|
---|
[6070] | 474 |
|
---|
[5799] | 475 | // F1 button = custom help action
|
---|
[3525] | 476 | getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(
|
---|
[9525] | 477 | helpAction.getKeyStroke(), "onHelp");
|
---|
[3525] | 478 | getActionMap().put("onHelp", helpAction);
|
---|
[1169] | 479 | }
|
---|
[6070] | 480 |
|
---|
[8980] | 481 | private JosmTextField setupFilter() {
|
---|
| 482 | final JosmTextField f = new DisableShortcutsOnFocusGainedTextField();
|
---|
| 483 | f.setToolTipText(tr("Tag filter"));
|
---|
| 484 | final CompileSearchTextDecorator decorator = CompileSearchTextDecorator.decorate(f);
|
---|
[10611] | 485 | f.addPropertyChangeListener("filter", evt -> setFilter(decorator.getMatch()));
|
---|
[8980] | 486 | return f;
|
---|
| 487 | }
|
---|
| 488 |
|
---|
[9073] | 489 | /**
|
---|
[5799] | 490 | * This simply fires up an {@link RelationEditor} for the relation shown; everything else
|
---|
| 491 | * is the editor's business.
|
---|
| 492 | *
|
---|
[8470] | 493 | * @param row position
|
---|
[5799] | 494 | */
|
---|
| 495 | private void editMembership(int row) {
|
---|
[8510] | 496 | Relation relation = (Relation) membershipData.getValueAt(row, 0);
|
---|
[12630] | 497 | MainApplication.getMap().relationListDialog.selectRelation(relation);
|
---|
[13434] | 498 | OsmDataLayer layer = MainApplication.getLayerManager().getActiveDataLayer();
|
---|
[13453] | 499 | if (!layer.isLocked()) {
|
---|
[13926] | 500 | List<RelationMember> members = new ArrayList<>();
|
---|
| 501 | for (IRelationMember<?> rm : ((MemberInfo) membershipData.getValueAt(row, 1)).role) {
|
---|
| 502 | if (rm instanceof RelationMember) {
|
---|
| 503 | members.add((RelationMember) rm);
|
---|
| 504 | }
|
---|
| 505 | }
|
---|
| 506 | RelationEditor.getEditor(layer, relation, members).setVisible(true);
|
---|
[13434] | 507 | }
|
---|
[1169] | 508 | }
|
---|
[6070] | 509 |
|
---|
[10043] | 510 | private static int findViewRow(JTable table, TableModel model, Object value) {
|
---|
[8510] | 511 | for (int i = 0; i < model.getRowCount(); i++) {
|
---|
[3518] | 512 | if (model.getValueAt(i, 0).equals(value))
|
---|
[9086] | 513 | return table.convertRowIndexToView(i);
|
---|
[1606] | 514 | }
|
---|
[3518] | 515 | return -1;
|
---|
| 516 | }
|
---|
[6070] | 517 |
|
---|
[5799] | 518 | /**
|
---|
| 519 | * Update selection status, call @{link #selectionChanged} function.
|
---|
| 520 | */
|
---|
| 521 | private void updateSelection() {
|
---|
[6546] | 522 | // Parameter is ignored in this class
|
---|
| 523 | selectionChanged(null);
|
---|
[5799] | 524 | }
|
---|
[6070] | 525 |
|
---|
[5799] | 526 | @Override
|
---|
| 527 | public void showNotify() {
|
---|
| 528 | DatasetEventManager.getInstance().addDatasetListener(dataChangedAdapter, FireMode.IN_EDT_CONSOLIDATED);
|
---|
[13925] | 529 | SelectionEventManager.getInstance().addSelectionListenerForEdt(this);
|
---|
[12636] | 530 | MainApplication.getLayerManager().addActiveLayerChangeListener(this);
|
---|
[5799] | 531 | for (JosmAction action : josmActions) {
|
---|
[12639] | 532 | MainApplication.registerActionShortcut(action);
|
---|
[5799] | 533 | }
|
---|
| 534 | updateSelection();
|
---|
| 535 | }
|
---|
[1606] | 536 |
|
---|
[5799] | 537 | @Override
|
---|
| 538 | public void hideNotify() {
|
---|
| 539 | DatasetEventManager.getInstance().removeDatasetListener(dataChangedAdapter);
|
---|
| 540 | SelectionEventManager.getInstance().removeSelectionListener(this);
|
---|
[12636] | 541 | MainApplication.getLayerManager().removeActiveLayerChangeListener(this);
|
---|
[5799] | 542 | for (JosmAction action : josmActions) {
|
---|
[12639] | 543 | MainApplication.unregisterActionShortcut(action);
|
---|
[1407] | 544 | }
|
---|
[5799] | 545 | }
|
---|
[1606] | 546 |
|
---|
[5799] | 547 | @Override
|
---|
| 548 | public void setVisible(boolean b) {
|
---|
| 549 | super.setVisible(b);
|
---|
[13926] | 550 | if (b && MainApplication.getLayerManager().getActiveData() != null) {
|
---|
[6546] | 551 | updateSelection();
|
---|
[2742] | 552 | }
|
---|
[5799] | 553 | }
|
---|
[6070] | 554 |
|
---|
[5799] | 555 | @Override
|
---|
| 556 | public void destroy() {
|
---|
[14470] | 557 | taginfoAction.destroy();
|
---|
[5799] | 558 | super.destroy();
|
---|
[12846] | 559 | Config.getPref().removeKeyPreferenceChangeListener("display.discardable-keys", preferenceListener);
|
---|
[5799] | 560 | Container parent = pluginHook.getParent();
|
---|
| 561 | if (parent != null) {
|
---|
| 562 | parent.remove(pluginHook);
|
---|
| 563 | }
|
---|
| 564 | }
|
---|
[2742] | 565 |
|
---|
[5481] | 566 | @Override
|
---|
[13925] | 567 | public void selectionChanged(SelectionChangeEvent event) {
|
---|
[1169] | 568 | if (!isVisible())
|
---|
| 569 | return;
|
---|
[6324] | 570 | if (tagTable == null)
|
---|
[1169] | 571 | return; // selection changed may be received in base class constructor before init
|
---|
[6324] | 572 | if (tagTable.getCellEditor() != null) {
|
---|
| 573 | tagTable.getCellEditor().cancelCellEditing();
|
---|
[1763] | 574 | }
|
---|
[7368] | 575 |
|
---|
[6623] | 576 | // Ignore parameter as we do not want to operate always on real selection here, especially in draw mode
|
---|
[14143] | 577 | Collection<? extends IPrimitive> newSel = OsmDataManager.getInstance().getInProgressISelection();
|
---|
[5800] | 578 | String selectedTag;
|
---|
[13959] | 579 | IRelation<?> selectedRelation = null;
|
---|
[5633] | 580 | selectedTag = editHelper.getChangedKey(); // select last added or last edited key by default
|
---|
[6324] | 581 | if (selectedTag == null && tagTable.getSelectedRowCount() == 1) {
|
---|
[9086] | 582 | selectedTag = editHelper.getDataKey(tagTable.getSelectedRow());
|
---|
[2742] | 583 | }
|
---|
| 584 | if (membershipTable.getSelectedRowCount() == 1) {
|
---|
[13959] | 585 | selectedRelation = (IRelation<?>) membershipData.getValueAt(membershipTable.getSelectedRow(), 0);
|
---|
[2742] | 586 | }
|
---|
| 587 |
|
---|
[6324] | 588 | // re-load tag data
|
---|
| 589 | tagData.setRowCount(0);
|
---|
[343] | 590 |
|
---|
[12846] | 591 | final boolean displayDiscardableKeys = Config.getPref().getBoolean("display.discardable-keys", false);
|
---|
[7005] | 592 | final Map<String, Integer> keyCount = new HashMap<>();
|
---|
| 593 | final Map<String, String> tags = new HashMap<>();
|
---|
[1169] | 594 | valueCount.clear();
|
---|
[8338] | 595 | Set<TaggingPresetType> types = EnumSet.noneOf(TaggingPresetType.class);
|
---|
[13926] | 596 | for (IPrimitive osm : newSel) {
|
---|
[6068] | 597 | types.add(TaggingPresetType.forPrimitive(osm));
|
---|
[5155] | 598 | for (String key : osm.keySet()) {
|
---|
[13809] | 599 | if (displayDiscardableKeys || !AbstractPrimitive.getDiscardableKeys().contains(key)) {
|
---|
[6314] | 600 | String value = osm.get(key);
|
---|
| 601 | keyCount.put(key, keyCount.containsKey(key) ? keyCount.get(key) + 1 : 1);
|
---|
| 602 | if (valueCount.containsKey(key)) {
|
---|
| 603 | Map<String, Integer> v = valueCount.get(key);
|
---|
| 604 | v.put(value, v.containsKey(value) ? v.get(value) + 1 : 1);
|
---|
| 605 | } else {
|
---|
[8338] | 606 | Map<String, Integer> v = new TreeMap<>();
|
---|
[6314] | 607 | v.put(value, 1);
|
---|
| 608 | valueCount.put(key, v);
|
---|
| 609 | }
|
---|
[1169] | 610 | }
|
---|
| 611 | }
|
---|
| 612 | }
|
---|
| 613 | for (Entry<String, Map<String, Integer>> e : valueCount.entrySet()) {
|
---|
[5155] | 614 | int count = 0;
|
---|
| 615 | for (Entry<String, Integer> e1 : e.getValue().entrySet()) {
|
---|
| 616 | count += e1.getValue();
|
---|
[1169] | 617 | }
|
---|
[6623] | 618 | if (count < newSel.size()) {
|
---|
| 619 | e.getValue().put("", newSel.size() - count);
|
---|
[1169] | 620 | }
|
---|
[6324] | 621 | tagData.addRow(new Object[]{e.getKey(), e.getValue()});
|
---|
[5155] | 622 | tags.put(e.getKey(), e.getValue().size() == 1
|
---|
| 623 | ? e.getValue().keySet().iterator().next() : tr("<different>"));
|
---|
[1169] | 624 | }
|
---|
[6070] | 625 |
|
---|
[1169] | 626 | membershipData.setRowCount(0);
|
---|
[1023] | 627 |
|
---|
[13926] | 628 | Map<IRelation<?>, MemberInfo> roles = new HashMap<>();
|
---|
| 629 | for (IPrimitive primitive: newSel) {
|
---|
| 630 | for (IPrimitive ref: primitive.getReferrers(true)) {
|
---|
| 631 | if (ref instanceof IRelation && !ref.isIncomplete() && !ref.isDeleted()) {
|
---|
| 632 | IRelation<?> r = (IRelation<?>) ref;
|
---|
[11553] | 633 | MemberInfo mi = Optional.ofNullable(roles.get(r)).orElseGet(() -> new MemberInfo(newSel));
|
---|
[3302] | 634 | roles.put(r, mi);
|
---|
| 635 | int i = 1;
|
---|
[13926] | 636 | for (IRelationMember<?> m : r.getMembers()) {
|
---|
[10662] | 637 | if (m.getMember() == primitive) {
|
---|
[3302] | 638 | mi.add(m, i);
|
---|
[1169] | 639 | }
|
---|
[3302] | 640 | ++i;
|
---|
[1169] | 641 | }
|
---|
| 642 | }
|
---|
| 643 | }
|
---|
| 644 | }
|
---|
[3146] | 645 |
|
---|
[13926] | 646 | List<IRelation<?>> sortedRelations = new ArrayList<>(roles.keySet());
|
---|
[10619] | 647 | sortedRelations.sort((o1, o2) -> {
|
---|
[10611] | 648 | int comp = Boolean.compare(o1.isDisabledAndHidden(), o2.isDisabledAndHidden());
|
---|
| 649 | return comp != 0 ? comp : DefaultNameFormatter.getInstance().getRelationComparator().compare(o1, o2);
|
---|
[9059] | 650 | });
|
---|
[3219] | 651 |
|
---|
[13926] | 652 | for (IRelation<?> r: sortedRelations) {
|
---|
[3219] | 653 | membershipData.addRow(new Object[]{r, roles.get(r)});
|
---|
[1169] | 654 | }
|
---|
[1023] | 655 |
|
---|
[5155] | 656 | presets.updatePresets(types, tags, presetHandler);
|
---|
[1606] | 657 |
|
---|
[1169] | 658 | membershipTable.getTableHeader().setVisible(membershipData.getRowCount() > 0);
|
---|
[1353] | 659 | membershipTable.setVisible(membershipData.getRowCount() > 0);
|
---|
[1228] | 660 |
|
---|
[13956] | 661 | OsmData<?, ?, ?, ?> ds = MainApplication.getLayerManager().getActiveData();
|
---|
[13453] | 662 | boolean isReadOnly = ds != null && ds.isLocked();
|
---|
[6623] | 663 | boolean hasSelection = !newSel.isEmpty();
|
---|
[6324] | 664 | boolean hasTags = hasSelection && tagData.getRowCount() > 0;
|
---|
[1446] | 665 | boolean hasMemberships = hasSelection && membershipData.getRowCount() > 0;
|
---|
[13434] | 666 | addAction.setEnabled(!isReadOnly && hasSelection);
|
---|
| 667 | editAction.setEnabled(!isReadOnly && (hasTags || hasMemberships));
|
---|
| 668 | deleteAction.setEnabled(!isReadOnly && (hasTags || hasMemberships));
|
---|
[6324] | 669 | tagTable.setVisible(hasTags);
|
---|
| 670 | tagTable.getTableHeader().setVisible(hasTags);
|
---|
[8980] | 671 | tagTableFilter.setVisible(hasTags);
|
---|
[1446] | 672 | selectSth.setVisible(!hasSelection);
|
---|
[3338] | 673 | pluginHook.setVisible(hasSelection);
|
---|
[2742] | 674 |
|
---|
[14476] | 675 | // resize tables to fit content
|
---|
| 676 | TableHelper.computeColumnsWidth(tagTable);
|
---|
| 677 |
|
---|
[2742] | 678 | int selectedIndex;
|
---|
[9086] | 679 | if (selectedTag != null && (selectedIndex = findViewRow(tagTable, tagData, selectedTag)) != -1) {
|
---|
[6324] | 680 | tagTable.changeSelection(selectedIndex, 0, false, false);
|
---|
[9086] | 681 | } else if (selectedRelation != null && (selectedIndex = findViewRow(membershipTable, membershipData, selectedRelation)) != -1) {
|
---|
[2742] | 682 | membershipTable.changeSelection(selectedIndex, 0, false, false);
|
---|
[8510] | 683 | } else if (hasTags) {
|
---|
[6324] | 684 | tagTable.changeSelection(0, 0, false, false);
|
---|
[8510] | 685 | } else if (hasMemberships) {
|
---|
[1763] | 686 | membershipTable.changeSelection(0, 0, false, false);
|
---|
| 687 | }
|
---|
[1446] | 688 |
|
---|
[8510] | 689 | if (tagData.getRowCount() != 0 || membershipData.getRowCount() != 0) {
|
---|
| 690 | if (newSel.size() > 1) {
|
---|
[8170] | 691 | setTitle(tr("Objects: {2} / Tags: {0} / Memberships: {1}",
|
---|
| 692 | tagData.getRowCount(), membershipData.getRowCount(), newSel.size()));
|
---|
| 693 | } else {
|
---|
| 694 | setTitle(tr("Tags: {0} / Memberships: {1}",
|
---|
[6324] | 695 | tagData.getRowCount(), membershipData.getRowCount()));
|
---|
[8170] | 696 | }
|
---|
[1228] | 697 | } else {
|
---|
[13761] | 698 | setTitle(tr("Tags/Memberships"));
|
---|
[1228] | 699 | }
|
---|
[1268] | 700 | }
|
---|
[6070] | 701 |
|
---|
[2658] | 702 | /* ---------------------------------------------------------------------------------- */
|
---|
[10332] | 703 | /* ActiveLayerChangeListener */
|
---|
[2658] | 704 | /* ---------------------------------------------------------------------------------- */
|
---|
[5481] | 705 | @Override
|
---|
[10332] | 706 | public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
|
---|
[10722] | 707 | if (e.getSource().getEditLayer() == null) {
|
---|
[10332] | 708 | editHelper.saveTagsIfNeeded();
|
---|
[14509] | 709 | editHelper.resetSelection();
|
---|
[10332] | 710 | }
|
---|
[5773] | 711 | // it is time to save history of tags
|
---|
[10332] | 712 | updateSelection();
|
---|
[1814] | 713 | }
|
---|
| 714 |
|
---|
[5481] | 715 | @Override
|
---|
[2741] | 716 | public void processDatasetEvent(AbstractDatasetChangedEvent event) {
|
---|
| 717 | updateSelection();
|
---|
| 718 | }
|
---|
| 719 |
|
---|
[5821] | 720 | /**
|
---|
[6324] | 721 | * Replies the tag popup menu handler.
|
---|
| 722 | * @return The tag popup menu handler
|
---|
[5821] | 723 | */
|
---|
| 724 | public PopupMenuHandler getPropertyPopupMenuHandler() {
|
---|
[6324] | 725 | return tagMenuHandler;
|
---|
[5799] | 726 | }
|
---|
| 727 |
|
---|
[6939] | 728 | /**
|
---|
| 729 | * Returns the selected tag.
|
---|
| 730 | * @return The current selected tag
|
---|
| 731 | */
|
---|
[5799] | 732 | public Tag getSelectedProperty() {
|
---|
[6324] | 733 | int row = tagTable.getSelectedRow();
|
---|
[5799] | 734 | if (row == -1) return null;
|
---|
[9086] | 735 | Map<String, Integer> map = editHelper.getDataValues(row);
|
---|
[5799] | 736 | return new Tag(
|
---|
[9086] | 737 | editHelper.getDataKey(row),
|
---|
[5799] | 738 | map.size() > 1 ? "" : map.keySet().iterator().next());
|
---|
| 739 | }
|
---|
| 740 |
|
---|
[5821] | 741 | /**
|
---|
| 742 | * Replies the membership popup menu handler.
|
---|
| 743 | * @return The membership popup menu handler
|
---|
| 744 | */
|
---|
| 745 | public PopupMenuHandler getMembershipPopupMenuHandler() {
|
---|
| 746 | return membershipMenuHandler;
|
---|
[5799] | 747 | }
|
---|
| 748 |
|
---|
[6939] | 749 | /**
|
---|
| 750 | * Returns the selected relation membership.
|
---|
| 751 | * @return The current selected relation membership
|
---|
| 752 | */
|
---|
[13766] | 753 | public IRelation<?> getSelectedMembershipRelation() {
|
---|
[5799] | 754 | int row = membershipTable.getSelectedRow();
|
---|
[13766] | 755 | return row > -1 ? (IRelation<?>) membershipData.getValueAt(row, 0) : null;
|
---|
[5799] | 756 | }
|
---|
[6070] | 757 |
|
---|
[8510] | 758 | /**
|
---|
[9149] | 759 | * Adds a custom table cell renderer to render cells of the tags table.
|
---|
| 760 | *
|
---|
| 761 | * If the renderer is not capable performing a {@link TableCellRenderer#getTableCellRendererComponent},
|
---|
| 762 | * it should return {@code null} to fall back to the
|
---|
| 763 | * {@link PropertiesCellRenderer#getTableCellRendererComponent default implementation}.
|
---|
| 764 | * @param renderer the renderer to add
|
---|
| 765 | * @since 9149
|
---|
| 766 | */
|
---|
| 767 | public void addCustomPropertiesCellRenderer(TableCellRenderer renderer) {
|
---|
| 768 | cellRenderer.addCustomRenderer(renderer);
|
---|
| 769 | }
|
---|
| 770 |
|
---|
| 771 | /**
|
---|
| 772 | * Removes a custom table cell renderer.
|
---|
| 773 | * @param renderer the renderer to remove
|
---|
| 774 | * @since 9149
|
---|
| 775 | */
|
---|
| 776 | public void removeCustomPropertiesCellRenderer(TableCellRenderer renderer) {
|
---|
| 777 | cellRenderer.removeCustomRenderer(renderer);
|
---|
| 778 | }
|
---|
| 779 |
|
---|
[11366] | 780 | static final class MemberOfCellRenderer extends DefaultTableCellRenderer {
|
---|
| 781 | @Override
|
---|
| 782 | public Component getTableCellRendererComponent(JTable table, Object value,
|
---|
| 783 | boolean isSelected, boolean hasFocus, int row, int column) {
|
---|
| 784 | Component c = super.getTableCellRendererComponent(table, value, isSelected, false, row, column);
|
---|
| 785 | if (value == null)
|
---|
| 786 | return this;
|
---|
| 787 | if (c instanceof JLabel) {
|
---|
| 788 | JLabel label = (JLabel) c;
|
---|
[13959] | 789 | IRelation<?> r = (IRelation<?>) value;
|
---|
[11366] | 790 | label.setText(r.getDisplayName(DefaultNameFormatter.getInstance()));
|
---|
| 791 | if (r.isDisabledAndHidden()) {
|
---|
| 792 | label.setFont(label.getFont().deriveFont(Font.ITALIC));
|
---|
| 793 | }
|
---|
| 794 | }
|
---|
| 795 | return c;
|
---|
| 796 | }
|
---|
| 797 | }
|
---|
| 798 |
|
---|
| 799 | static final class RoleCellRenderer extends DefaultTableCellRenderer {
|
---|
| 800 | @Override
|
---|
| 801 | public Component getTableCellRendererComponent(JTable table, Object value,
|
---|
| 802 | boolean isSelected, boolean hasFocus, int row, int column) {
|
---|
| 803 | if (value == null)
|
---|
| 804 | return this;
|
---|
| 805 | Component c = super.getTableCellRendererComponent(table, value, isSelected, false, row, column);
|
---|
[13959] | 806 | boolean isDisabledAndHidden = ((IRelation<?>) table.getValueAt(row, 0)).isDisabledAndHidden();
|
---|
[11366] | 807 | if (c instanceof JLabel) {
|
---|
| 808 | JLabel label = (JLabel) c;
|
---|
| 809 | label.setText(((MemberInfo) value).getRoleString());
|
---|
| 810 | if (isDisabledAndHidden) {
|
---|
| 811 | label.setFont(label.getFont().deriveFont(Font.ITALIC));
|
---|
| 812 | }
|
---|
| 813 | }
|
---|
| 814 | return c;
|
---|
| 815 | }
|
---|
| 816 | }
|
---|
| 817 |
|
---|
| 818 | static final class PositionCellRenderer extends DefaultTableCellRenderer {
|
---|
| 819 | @Override
|
---|
| 820 | public Component getTableCellRendererComponent(JTable table, Object value,
|
---|
| 821 | boolean isSelected, boolean hasFocus, int row, int column) {
|
---|
| 822 | Component c = super.getTableCellRendererComponent(table, value, isSelected, false, row, column);
|
---|
[14097] | 823 | IRelation<?> relation = (IRelation<?>) table.getValueAt(row, 0);
|
---|
| 824 | boolean isDisabledAndHidden = relation != null && relation.isDisabledAndHidden();
|
---|
[11366] | 825 | if (c instanceof JLabel) {
|
---|
| 826 | JLabel label = (JLabel) c;
|
---|
[14102] | 827 | MemberInfo member = (MemberInfo) table.getValueAt(row, 1);
|
---|
| 828 | if (member != null) {
|
---|
| 829 | label.setText(member.getPositionString());
|
---|
| 830 | }
|
---|
[11366] | 831 | if (isDisabledAndHidden) {
|
---|
| 832 | label.setFont(label.getFont().deriveFont(Font.ITALIC));
|
---|
| 833 | }
|
---|
| 834 | }
|
---|
| 835 | return c;
|
---|
| 836 | }
|
---|
| 837 | }
|
---|
| 838 |
|
---|
| 839 | static final class BlankSpaceMenuLauncher extends PopupMenuLauncher {
|
---|
| 840 | BlankSpaceMenuLauncher(JPopupMenu menu) {
|
---|
| 841 | super(menu);
|
---|
| 842 | }
|
---|
| 843 |
|
---|
| 844 | @Override
|
---|
| 845 | protected boolean checkSelection(Component component, Point p) {
|
---|
| 846 | if (component instanceof JTable) {
|
---|
| 847 | return ((JTable) component).rowAtPoint(p) == -1;
|
---|
| 848 | }
|
---|
| 849 | return true;
|
---|
| 850 | }
|
---|
| 851 | }
|
---|
| 852 |
|
---|
[11357] | 853 | static final class TaggingPresetCommandHandler implements TaggingPresetHandler {
|
---|
| 854 | @Override
|
---|
| 855 | public void updateTags(List<Tag> tags) {
|
---|
| 856 | Command command = TaggingPreset.createCommand(getSelection(), tags);
|
---|
| 857 | if (command != null) {
|
---|
[14134] | 858 | UndoRedoHandler.getInstance().add(command);
|
---|
[11357] | 859 | }
|
---|
| 860 | }
|
---|
| 861 |
|
---|
| 862 | @Override
|
---|
| 863 | public Collection<OsmPrimitive> getSelection() {
|
---|
[14143] | 864 | return OsmDataManager.getInstance().getInProgressSelection();
|
---|
[11357] | 865 | }
|
---|
| 866 | }
|
---|
| 867 |
|
---|
[9149] | 868 | /**
|
---|
[5799] | 869 | * Class that watches for mouse clicks
|
---|
| 870 | * @author imi
|
---|
| 871 | */
|
---|
| 872 | public class MouseClickWatch extends MouseAdapter {
|
---|
[8510] | 873 | @Override
|
---|
| 874 | public void mouseClicked(MouseEvent e) {
|
---|
[6707] | 875 | if (e.getClickCount() < 2) {
|
---|
[5799] | 876 | // single click, clear selection in other table not clicked in
|
---|
[6324] | 877 | if (e.getSource() == tagTable) {
|
---|
[5799] | 878 | membershipTable.clearSelection();
|
---|
| 879 | } else if (e.getSource() == membershipTable) {
|
---|
[6324] | 880 | tagTable.clearSelection();
|
---|
[5799] | 881 | }
|
---|
[8342] | 882 | } else if (e.getSource() == tagTable) {
|
---|
| 883 | // double click, edit or add tag
|
---|
[6324] | 884 | int row = tagTable.rowAtPoint(e.getPoint());
|
---|
[5799] | 885 | if (row > -1) {
|
---|
[8345] | 886 | boolean focusOnKey = tagTable.columnAtPoint(e.getPoint()) == 0;
|
---|
[6324] | 887 | editHelper.editTag(row, focusOnKey);
|
---|
[5799] | 888 | } else {
|
---|
[6324] | 889 | editHelper.addTag();
|
---|
[5799] | 890 | btnAdd.requestFocusInWindow();
|
---|
| 891 | }
|
---|
| 892 | } else if (e.getSource() == membershipTable) {
|
---|
| 893 | int row = membershipTable.rowAtPoint(e.getPoint());
|
---|
| 894 | if (row > -1) {
|
---|
| 895 | editMembership(row);
|
---|
| 896 | }
|
---|
[8342] | 897 | } else {
|
---|
[6324] | 898 | editHelper.addTag();
|
---|
[5799] | 899 | btnAdd.requestFocusInWindow();
|
---|
| 900 | }
|
---|
| 901 | }
|
---|
[8510] | 902 |
|
---|
| 903 | @Override
|
---|
| 904 | public void mousePressed(MouseEvent e) {
|
---|
[6324] | 905 | if (e.getSource() == tagTable) {
|
---|
[5799] | 906 | membershipTable.clearSelection();
|
---|
| 907 | } else if (e.getSource() == membershipTable) {
|
---|
[6324] | 908 | tagTable.clearSelection();
|
---|
[5799] | 909 | }
|
---|
| 910 | }
|
---|
| 911 | }
|
---|
| 912 |
|
---|
| 913 | static class MemberInfo {
|
---|
[13926] | 914 | private final List<IRelationMember<?>> role = new ArrayList<>();
|
---|
| 915 | private Set<IPrimitive> members = new HashSet<>();
|
---|
[7005] | 916 | private List<Integer> position = new ArrayList<>();
|
---|
[13926] | 917 | private Collection<? extends IPrimitive> selection;
|
---|
[8840] | 918 | private String positionString;
|
---|
| 919 | private String roleString;
|
---|
[6652] | 920 |
|
---|
[13926] | 921 | MemberInfo(Collection<? extends IPrimitive> selection) {
|
---|
[6652] | 922 | this.selection = selection;
|
---|
| 923 | }
|
---|
| 924 |
|
---|
[13926] | 925 | void add(IRelationMember<?> r, Integer p) {
|
---|
[5799] | 926 | role.add(r);
|
---|
[6652] | 927 | members.add(r.getMember());
|
---|
[5799] | 928 | position.add(p);
|
---|
| 929 | }
|
---|
[6652] | 930 |
|
---|
[5799] | 931 | String getPositionString() {
|
---|
| 932 | if (positionString == null) {
|
---|
[6652] | 933 | positionString = Utils.getPositionListString(position);
|
---|
| 934 | // if not all objects from the selection are member of this relation
|
---|
[10715] | 935 | if (selection.stream().anyMatch(p -> !members.contains(p))) {
|
---|
[6652] | 936 | positionString += ",\u2717";
|
---|
[5799] | 937 | }
|
---|
[6652] | 938 | members = null;
|
---|
| 939 | position = null;
|
---|
| 940 | selection = null;
|
---|
[5799] | 941 | }
|
---|
[6742] | 942 | return Utils.shortenString(positionString, 20);
|
---|
[5799] | 943 | }
|
---|
[6652] | 944 |
|
---|
| 945 | String getRoleString() {
|
---|
| 946 | if (roleString == null) {
|
---|
[13926] | 947 | for (IRelationMember<?> r : role) {
|
---|
[6652] | 948 | if (roleString == null) {
|
---|
| 949 | roleString = r.getRole();
|
---|
| 950 | } else if (!roleString.equals(r.getRole())) {
|
---|
| 951 | roleString = tr("<different>");
|
---|
| 952 | break;
|
---|
| 953 | }
|
---|
| 954 | }
|
---|
| 955 | }
|
---|
| 956 | return roleString;
|
---|
| 957 | }
|
---|
| 958 |
|
---|
| 959 | @Override
|
---|
| 960 | public String toString() {
|
---|
| 961 | return "MemberInfo{" +
|
---|
| 962 | "roles='" + roleString + '\'' +
|
---|
| 963 | ", positions='" + positionString + '\'' +
|
---|
| 964 | '}';
|
---|
| 965 | }
|
---|
[5799] | 966 | }
|
---|
| 967 |
|
---|
[5481] | 968 | /**
|
---|
[5799] | 969 | * Class that allows fast creation of read-only table model with String columns
|
---|
| 970 | */
|
---|
| 971 | public static class ReadOnlyTableModel extends DefaultTableModel {
|
---|
[8510] | 972 | @Override
|
---|
| 973 | public boolean isCellEditable(int row, int column) {
|
---|
[5799] | 974 | return false;
|
---|
| 975 | }
|
---|
[8510] | 976 |
|
---|
| 977 | @Override
|
---|
| 978 | public Class<?> getColumnClass(int columnIndex) {
|
---|
[5799] | 979 | return String.class;
|
---|
| 980 | }
|
---|
[6142] | 981 | }
|
---|
[6070] | 982 |
|
---|
[5799] | 983 | /**
|
---|
[5481] | 984 | * Action handling delete button press in properties dialog.
|
---|
| 985 | */
|
---|
[4518] | 986 | class DeleteAction extends JosmAction implements ListSelectionListener {
|
---|
[1945] | 987 |
|
---|
[8285] | 988 | private static final String DELETE_FROM_RELATION_PREF = "delete_from_relation";
|
---|
[6595] | 989 |
|
---|
[8836] | 990 | DeleteAction() {
|
---|
[7668] | 991 | super(tr("Delete"), /* ICON() */ "dialogs/delete", tr("Delete the selected key in all objects"),
|
---|
[6324] | 992 | Shortcut.registerShortcut("properties:delete", tr("Delete Tags"), KeyEvent.VK_D,
|
---|
[4982] | 993 | Shortcut.ALT_CTRL_SHIFT), false);
|
---|
[4518] | 994 | updateEnabledState();
|
---|
| 995 | }
|
---|
| 996 |
|
---|
[11747] | 997 | protected void deleteTags(int... rows) {
|
---|
[4773] | 998 | // convert list of rows to HashMap (and find gap for nextKey)
|
---|
[8338] | 999 | Map<String, String> tags = new HashMap<>(rows.length);
|
---|
[4773] | 1000 | int nextKeyIndex = rows[0];
|
---|
| 1001 | for (int row : rows) {
|
---|
[9086] | 1002 | String key = editHelper.getDataKey(row);
|
---|
[4869] | 1003 | if (row == nextKeyIndex + 1) {
|
---|
[4773] | 1004 | nextKeyIndex = row; // no gap yet
|
---|
[4869] | 1005 | }
|
---|
[4773] | 1006 | tags.put(key, null);
|
---|
| 1007 | }
|
---|
[2742] | 1008 |
|
---|
[6324] | 1009 | // find key to select after deleting other tags
|
---|
[2742] | 1010 | String nextKey = null;
|
---|
[6324] | 1011 | int rowCount = tagData.getRowCount();
|
---|
[4773] | 1012 | if (rowCount > rows.length) {
|
---|
[4869] | 1013 | if (nextKeyIndex == rows[rows.length-1]) {
|
---|
[4773] | 1014 | // no gap found, pick next or previous key in list
|
---|
[9970] | 1015 | nextKeyIndex = nextKeyIndex + 1 < rowCount ? nextKeyIndex + 1 : rows[0] - 1;
|
---|
[4869] | 1016 | } else {
|
---|
[4773] | 1017 | // gap found
|
---|
| 1018 | nextKeyIndex++;
|
---|
[4869] | 1019 | }
|
---|
[11764] | 1020 | // We use unfiltered indexes here. So don't use getDataKey()
|
---|
| 1021 | nextKey = (String) tagData.getValueAt(nextKeyIndex, 0);
|
---|
[2742] | 1022 | }
|
---|
| 1023 |
|
---|
[14143] | 1024 | Collection<OsmPrimitive> sel = OsmDataManager.getInstance().getInProgressSelection();
|
---|
[14134] | 1025 | UndoRedoHandler.getInstance().add(new ChangePropertyCommand(sel, tags));
|
---|
[1945] | 1026 |
|
---|
[2742] | 1027 | membershipTable.clearSelection();
|
---|
| 1028 | if (nextKey != null) {
|
---|
[9086] | 1029 | tagTable.changeSelection(findViewRow(tagTable, tagData, nextKey), 0, false, false);
|
---|
[2742] | 1030 | }
|
---|
[1945] | 1031 | }
|
---|
| 1032 |
|
---|
| 1033 | protected void deleteFromRelation(int row) {
|
---|
[8510] | 1034 | Relation cur = (Relation) membershipData.getValueAt(row, 0);
|
---|
[2032] | 1035 |
|
---|
[2742] | 1036 | Relation nextRelation = null;
|
---|
| 1037 | int rowCount = membershipTable.getRowCount();
|
---|
| 1038 | if (rowCount > 1) {
|
---|
[8510] | 1039 | nextRelation = (Relation) membershipData.getValueAt(row + 1 < rowCount ? row + 1 : row - 1, 0);
|
---|
[2742] | 1040 | }
|
---|
| 1041 |
|
---|
[14153] | 1042 | ExtendedDialog ed = new ExtendedDialog(MainApplication.getMainFrame(),
|
---|
[1945] | 1043 | tr("Change relation"),
|
---|
[12279] | 1044 | tr("Delete from relation"), tr("Cancel"));
|
---|
| 1045 | ed.setButtonIcons("dialogs/delete", "cancel");
|
---|
[2032] | 1046 | ed.setContent(tr("Really delete selection from relation {0}?", cur.getDisplayName(DefaultNameFormatter.getInstance())));
|
---|
[6595] | 1047 | ed.toggleEnable(DELETE_FROM_RELATION_PREF);
|
---|
[1945] | 1048 |
|
---|
[12279] | 1049 | if (ed.showDialog().getValue() != 1)
|
---|
[1945] | 1050 | return;
|
---|
| 1051 |
|
---|
| 1052 | Relation rel = new Relation(cur);
|
---|
[14143] | 1053 | for (OsmPrimitive primitive: OsmDataManager.getInstance().getInProgressSelection()) {
|
---|
[2027] | 1054 | rel.removeMembersFor(primitive);
|
---|
[1945] | 1055 | }
|
---|
[14134] | 1056 | UndoRedoHandler.getInstance().add(new ChangeCommand(cur, rel));
|
---|
[2742] | 1057 |
|
---|
[6324] | 1058 | tagTable.clearSelection();
|
---|
[2742] | 1059 | if (nextRelation != null) {
|
---|
[9086] | 1060 | membershipTable.changeSelection(findViewRow(membershipTable, membershipData, nextRelation), 0, false, false);
|
---|
[2742] | 1061 | }
|
---|
[1945] | 1062 | }
|
---|
| 1063 |
|
---|
[4518] | 1064 | @Override
|
---|
[1945] | 1065 | public void actionPerformed(ActionEvent e) {
|
---|
[6324] | 1066 | if (tagTable.getSelectedRowCount() > 0) {
|
---|
| 1067 | int[] rows = tagTable.getSelectedRows();
|
---|
| 1068 | deleteTags(rows);
|
---|
[1945] | 1069 | } else if (membershipTable.getSelectedRowCount() > 0) {
|
---|
[6595] | 1070 | ConditionalOptionPaneUtil.startBulkOperation(DELETE_FROM_RELATION_PREF);
|
---|
[5799] | 1071 | int[] rows = membershipTable.getSelectedRows();
|
---|
[6595] | 1072 | // delete from last relation to conserve row numbers in the table
|
---|
[8510] | 1073 | for (int i = rows.length-1; i >= 0; i--) {
|
---|
[5799] | 1074 | deleteFromRelation(rows[i]);
|
---|
| 1075 | }
|
---|
[6595] | 1076 | ConditionalOptionPaneUtil.endBulkOperation(DELETE_FROM_RELATION_PREF);
|
---|
[1945] | 1077 | }
|
---|
| 1078 | }
|
---|
| 1079 |
|
---|
[4518] | 1080 | @Override
|
---|
[6890] | 1081 | protected final void updateEnabledState() {
|
---|
[14143] | 1082 | DataSet ds = OsmDataManager.getInstance().getActiveDataSet();
|
---|
[13453] | 1083 | setEnabled(ds != null && !ds.isLocked() &&
|
---|
[13434] | 1084 | ((tagTable != null && tagTable.getSelectedRowCount() >= 1)
|
---|
[5799] | 1085 | || (membershipTable != null && membershipTable.getSelectedRowCount() > 0)
|
---|
[13434] | 1086 | ));
|
---|
[1945] | 1087 | }
|
---|
| 1088 |
|
---|
[4518] | 1089 | @Override
|
---|
[1945] | 1090 | public void valueChanged(ListSelectionEvent e) {
|
---|
| 1091 | updateEnabledState();
|
---|
| 1092 | }
|
---|
| 1093 | }
|
---|
| 1094 |
|
---|
[5481] | 1095 | /**
|
---|
| 1096 | * Action handling add button press in properties dialog.
|
---|
| 1097 | */
|
---|
[4518] | 1098 | class AddAction extends JosmAction {
|
---|
[14669] | 1099 | AtomicBoolean isPerforming = new AtomicBoolean(false);
|
---|
[8836] | 1100 | AddAction() {
|
---|
[7668] | 1101 | super(tr("Add"), /* ICON() */ "dialogs/add", tr("Add a new key/value pair to all objects"),
|
---|
[6324] | 1102 | Shortcut.registerShortcut("properties:add", tr("Add Tag"), KeyEvent.VK_A,
|
---|
[4982] | 1103 | Shortcut.ALT), false);
|
---|
[2473] | 1104 | }
|
---|
| 1105 |
|
---|
[4518] | 1106 | @Override
|
---|
[14669] | 1107 | public void actionPerformed(ActionEvent e) {
|
---|
| 1108 | if (isPerforming.get())
|
---|
[13854] | 1109 | return;
|
---|
[14669] | 1110 | isPerforming.set(true);
|
---|
[13854] | 1111 | try {
|
---|
| 1112 | editHelper.addTag();
|
---|
| 1113 | btnAdd.requestFocusInWindow();
|
---|
| 1114 | } finally {
|
---|
[14669] | 1115 | isPerforming.set(false);
|
---|
[13854] | 1116 | }
|
---|
[2473] | 1117 | }
|
---|
| 1118 | }
|
---|
| 1119 |
|
---|
[5481] | 1120 | /**
|
---|
| 1121 | * Action handling edit button press in properties dialog.
|
---|
| 1122 | */
|
---|
[4518] | 1123 | class EditAction extends JosmAction implements ListSelectionListener {
|
---|
[14669] | 1124 | AtomicBoolean isPerforming = new AtomicBoolean(false);
|
---|
[8836] | 1125 | EditAction() {
|
---|
[7668] | 1126 | super(tr("Edit"), /* ICON() */ "dialogs/edit", tr("Edit the value of the selected key for all objects"),
|
---|
[6324] | 1127 | Shortcut.registerShortcut("properties:edit", tr("Edit Tags"), KeyEvent.VK_S,
|
---|
[4982] | 1128 | Shortcut.ALT), false);
|
---|
[2473] | 1129 | updateEnabledState();
|
---|
| 1130 | }
|
---|
| 1131 |
|
---|
[4518] | 1132 | @Override
|
---|
[14669] | 1133 | public void actionPerformed(ActionEvent e) {
|
---|
| 1134 | if (isPerforming.get())
|
---|
[2473] | 1135 | return;
|
---|
[14669] | 1136 | isPerforming.set(true);
|
---|
[13854] | 1137 | try {
|
---|
| 1138 | if (tagTable.getSelectedRowCount() == 1) {
|
---|
| 1139 | int row = tagTable.getSelectedRow();
|
---|
| 1140 | editHelper.editTag(row, false);
|
---|
| 1141 | } else if (membershipTable.getSelectedRowCount() == 1) {
|
---|
| 1142 | int row = membershipTable.getSelectedRow();
|
---|
| 1143 | editMembership(row);
|
---|
| 1144 | }
|
---|
| 1145 | } finally {
|
---|
[14669] | 1146 | isPerforming.set(false);
|
---|
[2490] | 1147 | }
|
---|
[2473] | 1148 | }
|
---|
| 1149 |
|
---|
[4518] | 1150 | @Override
|
---|
[2473] | 1151 | protected void updateEnabledState() {
|
---|
[14143] | 1152 | DataSet ds = OsmDataManager.getInstance().getActiveDataSet();
|
---|
[13453] | 1153 | setEnabled(ds != null && !ds.isLocked() &&
|
---|
[13434] | 1154 | ((tagTable != null && tagTable.getSelectedRowCount() == 1)
|
---|
[4526] | 1155 | ^ (membershipTable != null && membershipTable.getSelectedRowCount() == 1)
|
---|
[13434] | 1156 | ));
|
---|
[2473] | 1157 | }
|
---|
| 1158 |
|
---|
[4518] | 1159 | @Override
|
---|
[2473] | 1160 | public void valueChanged(ListSelectionEvent e) {
|
---|
| 1161 | updateEnabledState();
|
---|
| 1162 | }
|
---|
| 1163 | }
|
---|
[2723] | 1164 |
|
---|
[5726] | 1165 | class PasteValueAction extends AbstractAction {
|
---|
[8836] | 1166 | PasteValueAction() {
|
---|
[5726] | 1167 | putValue(NAME, tr("Paste Value"));
|
---|
| 1168 | putValue(SHORT_DESCRIPTION, tr("Paste the value of the selected tag from clipboard"));
|
---|
| 1169 | }
|
---|
[4454] | 1170 |
|
---|
[5726] | 1171 | @Override
|
---|
| 1172 | public void actionPerformed(ActionEvent ae) {
|
---|
[6324] | 1173 | if (tagTable.getSelectedRowCount() != 1)
|
---|
[5726] | 1174 | return;
|
---|
[9086] | 1175 | String key = editHelper.getDataKey(tagTable.getSelectedRow());
|
---|
[14143] | 1176 | Collection<OsmPrimitive> sel = OsmDataManager.getInstance().getInProgressSelection();
|
---|
[10604] | 1177 | String clipboard = ClipboardUtils.getClipboardStringContent();
|
---|
[13453] | 1178 | if (sel.isEmpty() || clipboard == null || sel.iterator().next().getDataSet().isLocked())
|
---|
[5726] | 1179 | return;
|
---|
[14134] | 1180 | UndoRedoHandler.getInstance().add(new ChangePropertyCommand(sel, key, Utils.strip(clipboard)));
|
---|
[5726] | 1181 | }
|
---|
| 1182 | }
|
---|
| 1183 |
|
---|
[4503] | 1184 | class SearchAction extends AbstractAction {
|
---|
[8285] | 1185 | private final boolean sameType;
|
---|
[4503] | 1186 |
|
---|
[8836] | 1187 | SearchAction(boolean sameType) {
|
---|
[4503] | 1188 | this.sameType = sameType;
|
---|
| 1189 | if (sameType) {
|
---|
| 1190 | putValue(NAME, tr("Search Key/Value/Type"));
|
---|
| 1191 | putValue(SHORT_DESCRIPTION, tr("Search with the key and value of the selected tag, restrict to type (i.e., node/way/relation)"));
|
---|
| 1192 | } else {
|
---|
| 1193 | putValue(NAME, tr("Search Key/Value"));
|
---|
| 1194 | putValue(SHORT_DESCRIPTION, tr("Search with the key and value of the selected tag"));
|
---|
| 1195 | }
|
---|
| 1196 | }
|
---|
| 1197 |
|
---|
[5799] | 1198 | @Override
|
---|
[4503] | 1199 | public void actionPerformed(ActionEvent e) {
|
---|
[6324] | 1200 | if (tagTable.getSelectedRowCount() != 1)
|
---|
[4503] | 1201 | return;
|
---|
[9086] | 1202 | String key = editHelper.getDataKey(tagTable.getSelectedRow());
|
---|
[14143] | 1203 | Collection<? extends IPrimitive> sel = OsmDataManager.getInstance().getInProgressISelection();
|
---|
[4604] | 1204 | if (sel.isEmpty())
|
---|
[4503] | 1205 | return;
|
---|
[9762] | 1206 | final SearchSetting ss = createSearchSetting(key, sel, sameType);
|
---|
| 1207 | org.openstreetmap.josm.actions.search.SearchAction.searchWithoutHistory(ss);
|
---|
| 1208 | }
|
---|
| 1209 | }
|
---|
| 1210 |
|
---|
[13926] | 1211 | static SearchSetting createSearchSetting(String key, Collection<? extends IPrimitive> sel, boolean sameType) {
|
---|
[9762] | 1212 | String sep = "";
|
---|
| 1213 | StringBuilder s = new StringBuilder();
|
---|
| 1214 | Set<String> consideredTokens = new TreeSet<>();
|
---|
[13926] | 1215 | for (IPrimitive p : sel) {
|
---|
[9762] | 1216 | String val = p.get(key);
|
---|
| 1217 | if (val == null || (!sameType && consideredTokens.contains(val))) {
|
---|
| 1218 | continue;
|
---|
| 1219 | }
|
---|
| 1220 | String t = "";
|
---|
| 1221 | if (!sameType) {
|
---|
| 1222 | t = "";
|
---|
| 1223 | } else if (p instanceof Node) {
|
---|
| 1224 | t = "type:node ";
|
---|
| 1225 | } else if (p instanceof Way) {
|
---|
| 1226 | t = "type:way ";
|
---|
| 1227 | } else if (p instanceof Relation) {
|
---|
| 1228 | t = "type:relation ";
|
---|
| 1229 | }
|
---|
| 1230 | String token = new StringBuilder(t).append(val).toString();
|
---|
| 1231 | if (consideredTokens.add(token)) {
|
---|
[9969] | 1232 | s.append(sep).append('(').append(t).append(SearchCompiler.buildSearchStringForTag(key, val)).append(')');
|
---|
[4503] | 1233 | sep = " OR ";
|
---|
| 1234 | }
|
---|
[9762] | 1235 | }
|
---|
[4503] | 1236 |
|
---|
[9762] | 1237 | final SearchSetting ss = new SearchSetting();
|
---|
| 1238 | ss.text = s.toString();
|
---|
| 1239 | ss.caseSensitive = true;
|
---|
| 1240 | return ss;
|
---|
[4503] | 1241 | }
|
---|
[6314] | 1242 |
|
---|
[9877] | 1243 | /**
|
---|
| 1244 | * Clears the row selection when it is filtered away by the row sorter.
|
---|
| 1245 | */
|
---|
| 1246 | private class RemoveHiddenSelection implements ListSelectionListener, RowSorterListener {
|
---|
| 1247 |
|
---|
| 1248 | void removeHiddenSelection() {
|
---|
| 1249 | try {
|
---|
[9894] | 1250 | tagRowSorter.convertRowIndexToModel(tagTable.getSelectedRow());
|
---|
[9877] | 1251 | } catch (IndexOutOfBoundsException ignore) {
|
---|
[12620] | 1252 | Logging.trace(ignore);
|
---|
| 1253 | Logging.trace("Clearing tagTable selection");
|
---|
[9877] | 1254 | tagTable.clearSelection();
|
---|
| 1255 | }
|
---|
| 1256 | }
|
---|
| 1257 |
|
---|
| 1258 | @Override
|
---|
| 1259 | public void valueChanged(ListSelectionEvent event) {
|
---|
| 1260 | removeHiddenSelection();
|
---|
| 1261 | }
|
---|
| 1262 |
|
---|
| 1263 | @Override
|
---|
| 1264 | public void sorterChanged(RowSorterEvent e) {
|
---|
| 1265 | removeHiddenSelection();
|
---|
| 1266 | }
|
---|
| 1267 | }
|
---|
[272] | 1268 | }
|
---|