[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 | import static org.openstreetmap.josm.tools.I18n.trn;
|
---|
| 6 |
|
---|
| 7 | import java.awt.BorderLayout;
|
---|
| 8 | import java.awt.Component;
|
---|
[5383] | 9 | import java.awt.Cursor;
|
---|
| 10 | import java.awt.Dialog.ModalityType;
|
---|
[4102] | 11 | import java.awt.Dimension;
|
---|
[5425] | 12 | import java.awt.FlowLayout;
|
---|
[272] | 13 | import java.awt.Font;
|
---|
[5383] | 14 | import java.awt.GridBagConstraints;
|
---|
[272] | 15 | import java.awt.GridBagLayout;
|
---|
[2723] | 16 | import java.awt.Point;
|
---|
[4948] | 17 | import java.awt.Toolkit;
|
---|
| 18 | import java.awt.datatransfer.Clipboard;
|
---|
| 19 | import java.awt.datatransfer.Transferable;
|
---|
[272] | 20 | import java.awt.event.ActionEvent;
|
---|
| 21 | import java.awt.event.ActionListener;
|
---|
| 22 | import java.awt.event.FocusAdapter;
|
---|
| 23 | import java.awt.event.FocusEvent;
|
---|
| 24 | import java.awt.event.KeyEvent;
|
---|
| 25 | import java.awt.event.MouseAdapter;
|
---|
| 26 | import java.awt.event.MouseEvent;
|
---|
[5383] | 27 | import java.awt.image.BufferedImage;
|
---|
[3525] | 28 | import java.net.HttpURLConnection;
|
---|
| 29 | import java.net.URI;
|
---|
[3529] | 30 | import java.net.URLEncoder;
|
---|
[2657] | 31 | import java.util.ArrayList;
|
---|
[4300] | 32 | import java.util.Arrays;
|
---|
[272] | 33 | import java.util.Collection;
|
---|
[415] | 34 | import java.util.Collections;
|
---|
[3210] | 35 | import java.util.Comparator;
|
---|
[5155] | 36 | import java.util.EnumSet;
|
---|
[272] | 37 | import java.util.HashMap;
|
---|
[4106] | 38 | import java.util.HashSet;
|
---|
[3214] | 39 | import java.util.Iterator;
|
---|
[5383] | 40 | import java.util.LinkedHashMap;
|
---|
[4454] | 41 | import java.util.LinkedList;
|
---|
[1970] | 42 | import java.util.List;
|
---|
[4604] | 43 | import java.util.Map;
|
---|
[5383] | 44 | import java.util.Map.Entry;
|
---|
[4454] | 45 | import java.util.Set;
|
---|
[3529] | 46 | import java.util.TreeMap;
|
---|
[4454] | 47 | import java.util.TreeSet;
|
---|
[3525] | 48 | import java.util.Vector;
|
---|
[272] | 49 |
|
---|
[1945] | 50 | import javax.swing.AbstractAction;
|
---|
[4484] | 51 | import javax.swing.Action;
|
---|
[272] | 52 | import javax.swing.Box;
|
---|
[611] | 53 | import javax.swing.DefaultListCellRenderer;
|
---|
[5383] | 54 | import javax.swing.ImageIcon;
|
---|
[272] | 55 | import javax.swing.JComboBox;
|
---|
[1945] | 56 | import javax.swing.JComponent;
|
---|
[272] | 57 | import javax.swing.JDialog;
|
---|
| 58 | import javax.swing.JLabel;
|
---|
[611] | 59 | import javax.swing.JList;
|
---|
[4484] | 60 | import javax.swing.JMenuItem;
|
---|
[272] | 61 | import javax.swing.JOptionPane;
|
---|
| 62 | import javax.swing.JPanel;
|
---|
[2723] | 63 | import javax.swing.JPopupMenu;
|
---|
[272] | 64 | import javax.swing.JScrollPane;
|
---|
| 65 | import javax.swing.JTable;
|
---|
[1945] | 66 | import javax.swing.KeyStroke;
|
---|
[272] | 67 | import javax.swing.ListSelectionModel;
|
---|
[1945] | 68 | import javax.swing.event.ListSelectionEvent;
|
---|
| 69 | import javax.swing.event.ListSelectionListener;
|
---|
[4536] | 70 | import javax.swing.event.PopupMenuListener;
|
---|
[272] | 71 | import javax.swing.table.DefaultTableCellRenderer;
|
---|
| 72 | import javax.swing.table.DefaultTableModel;
|
---|
[3327] | 73 | import javax.swing.table.TableColumnModel;
|
---|
[2742] | 74 | import javax.swing.table.TableModel;
|
---|
[272] | 75 | import javax.swing.text.JTextComponent;
|
---|
| 76 |
|
---|
| 77 | import org.openstreetmap.josm.Main;
|
---|
[4518] | 78 | import org.openstreetmap.josm.actions.JosmAction;
|
---|
[5378] | 79 | import org.openstreetmap.josm.actions.mapmode.DrawAction;
|
---|
[4604] | 80 | import org.openstreetmap.josm.actions.search.SearchAction.SearchMode;
|
---|
| 81 | import org.openstreetmap.josm.actions.search.SearchAction.SearchSetting;
|
---|
[810] | 82 | import org.openstreetmap.josm.command.ChangeCommand;
|
---|
[272] | 83 | import org.openstreetmap.josm.command.ChangePropertyCommand;
|
---|
[621] | 84 | import org.openstreetmap.josm.command.Command;
|
---|
[272] | 85 | import org.openstreetmap.josm.command.SequenceCommand;
|
---|
| 86 | import org.openstreetmap.josm.data.SelectionChangedListener;
|
---|
[4604] | 87 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
[4536] | 88 | import org.openstreetmap.josm.data.osm.IRelation;
|
---|
[1407] | 89 | import org.openstreetmap.josm.data.osm.Node;
|
---|
[272] | 90 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
[343] | 91 | import org.openstreetmap.josm.data.osm.Relation;
|
---|
| 92 | import org.openstreetmap.josm.data.osm.RelationMember;
|
---|
[3518] | 93 | import org.openstreetmap.josm.data.osm.Tag;
|
---|
[1407] | 94 | import org.openstreetmap.josm.data.osm.Way;
|
---|
[2741] | 95 | import org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent;
|
---|
| 96 | import org.openstreetmap.josm.data.osm.event.DataSetListenerAdapter;
|
---|
[2657] | 97 | import org.openstreetmap.josm.data.osm.event.DatasetEventManager;
|
---|
[5383] | 98 | import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode;
|
---|
[4948] | 99 | import org.openstreetmap.josm.data.osm.event.SelectionEventManager;
|
---|
[1990] | 100 | import org.openstreetmap.josm.gui.DefaultNameFormatter;
|
---|
[1397] | 101 | import org.openstreetmap.josm.gui.ExtendedDialog;
|
---|
[272] | 102 | import org.openstreetmap.josm.gui.MapFrame;
|
---|
[2621] | 103 | import org.openstreetmap.josm.gui.MapView;
|
---|
[810] | 104 | import org.openstreetmap.josm.gui.SideButton;
|
---|
[2657] | 105 | import org.openstreetmap.josm.gui.dialogs.ToggleDialog;
|
---|
[3518] | 106 | import org.openstreetmap.josm.gui.dialogs.properties.PresetListPanel.PresetHandler;
|
---|
[4106] | 107 | import org.openstreetmap.josm.gui.dialogs.relation.DownloadRelationMemberTask;
|
---|
[1599] | 108 | import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor;
|
---|
[1814] | 109 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
---|
[5383] | 110 | import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
|
---|
[1407] | 111 | import org.openstreetmap.josm.gui.tagging.TaggingPreset;
|
---|
[5155] | 112 | import org.openstreetmap.josm.gui.tagging.TaggingPreset.PresetType;
|
---|
[3210] | 113 | import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingComboBox;
|
---|
[3214] | 114 | import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionListItem;
|
---|
[3210] | 115 | import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionManager;
|
---|
[2723] | 116 | import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
|
---|
[272] | 117 | import org.openstreetmap.josm.tools.GBC;
|
---|
[1945] | 118 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
[5200] | 119 | import org.openstreetmap.josm.tools.InputMapUtils;
|
---|
[3525] | 120 | import org.openstreetmap.josm.tools.LanguageInfo;
|
---|
| 121 | import org.openstreetmap.josm.tools.OpenBrowser;
|
---|
[1084] | 122 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
[4454] | 123 | import org.openstreetmap.josm.tools.Utils;
|
---|
[272] | 124 |
|
---|
| 125 | /**
|
---|
| 126 | * This dialog displays the properties of the current selected primitives.
|
---|
| 127 | *
|
---|
| 128 | * If no object is selected, the dialog list is empty.
|
---|
| 129 | * If only one is selected, all properties of this object are selected.
|
---|
| 130 | * If more than one object are selected, the sum of all properties are displayed. If the
|
---|
| 131 | * different objects share the same property, the shared value is displayed. If they have
|
---|
| 132 | * different values, all of them are put in a combo box and the string "<different>"
|
---|
| 133 | * is displayed in italic.
|
---|
| 134 | *
|
---|
| 135 | * Below the list, the user can click on an add, modify and delete property button to
|
---|
| 136 | * edit the table selection value.
|
---|
| 137 | *
|
---|
| 138 | * The command is applied to all selected entries.
|
---|
| 139 | *
|
---|
| 140 | * @author imi
|
---|
| 141 | */
|
---|
[2741] | 142 | public class PropertiesDialog extends ToggleDialog implements SelectionChangedListener, MapView.EditLayerChangeListener, DataSetListenerAdapter.Listener {
|
---|
[1169] | 143 | /**
|
---|
[4697] | 144 | * Watches for mouse clicks
|
---|
[1169] | 145 | * @author imi
|
---|
| 146 | */
|
---|
[4697] | 147 | public class MouseClickWatch extends MouseAdapter {
|
---|
[1169] | 148 | @Override public void mouseClicked(MouseEvent e) {
|
---|
| 149 | if (e.getClickCount() < 2)
|
---|
| 150 | {
|
---|
[4697] | 151 | // single click, clear selection in other table not clicked in
|
---|
[1763] | 152 | if (e.getSource() == propertyTable) {
|
---|
[1169] | 153 | membershipTable.clearSelection();
|
---|
[1763] | 154 | } else if (e.getSource() == membershipTable) {
|
---|
[1169] | 155 | propertyTable.clearSelection();
|
---|
[1763] | 156 | }
|
---|
[1169] | 157 | }
|
---|
[4697] | 158 | // double click, edit or add property
|
---|
[1169] | 159 | else if (e.getSource() == propertyTable)
|
---|
| 160 | {
|
---|
| 161 | int row = propertyTable.rowAtPoint(e.getPoint());
|
---|
[1763] | 162 | if (row > -1) {
|
---|
[5383] | 163 | editProperty(row);
|
---|
[5271] | 164 | } else {
|
---|
[5383] | 165 | addProperty();
|
---|
[1763] | 166 | }
|
---|
[1169] | 167 | } else if (e.getSource() == membershipTable) {
|
---|
| 168 | int row = membershipTable.rowAtPoint(e.getPoint());
|
---|
[1763] | 169 | if (row > -1) {
|
---|
[5383] | 170 | editMembership(row);
|
---|
[1763] | 171 | }
|
---|
[1169] | 172 | }
|
---|
| 173 | else
|
---|
| 174 | {
|
---|
[5383] | 175 | addProperty();
|
---|
[1169] | 176 | }
|
---|
| 177 | }
|
---|
[2383] | 178 | @Override public void mousePressed(MouseEvent e) {
|
---|
| 179 | if (e.getSource() == propertyTable) {
|
---|
| 180 | membershipTable.clearSelection();
|
---|
| 181 | } else if (e.getSource() == membershipTable) {
|
---|
| 182 | propertyTable.clearSelection();
|
---|
| 183 | }
|
---|
| 184 | }
|
---|
[1169] | 185 | }
|
---|
[272] | 186 |
|
---|
[3338] | 187 | // hook for roadsigns plugin to display a small
|
---|
| 188 | // button in the upper right corner of this dialog
|
---|
[4869] | 189 | public static final JPanel pluginHook = new JPanel();
|
---|
[4604] | 190 |
|
---|
[4484] | 191 | private JPopupMenu propertyMenu;
|
---|
| 192 | private JPopupMenu membershipMenu;
|
---|
[3444] | 193 |
|
---|
[1169] | 194 | private final Map<String, Map<String, Integer>> valueCount = new TreeMap<String, Map<String, Integer>>();
|
---|
[2657] | 195 |
|
---|
[3214] | 196 | Comparator<AutoCompletionListItem> defaultACItemComparator = new Comparator<AutoCompletionListItem>() {
|
---|
| 197 | public int compare(AutoCompletionListItem o1, AutoCompletionListItem o2) {
|
---|
| 198 | return String.CASE_INSENSITIVE_ORDER.compare(o1.getValue(), o2.getValue());
|
---|
| 199 | }
|
---|
| 200 | };
|
---|
[3210] | 201 |
|
---|
[2741] | 202 | private DataSetListenerAdapter dataChangedAdapter = new DataSetListenerAdapter(this);
|
---|
[3529] | 203 | private HelpAction helpAction = new HelpAction();
|
---|
[4454] | 204 | private CopyValueAction copyValueAction = new CopyValueAction();
|
---|
| 205 | private CopyKeyValueAction copyKeyValueAction = new CopyKeyValueAction();
|
---|
| 206 | private CopyAllKeyValueAction copyAllKeyValueAction = new CopyAllKeyValueAction();
|
---|
[4503] | 207 | private SearchAction searchActionSame = new SearchAction(true);
|
---|
| 208 | private SearchAction searchActionAny = new SearchAction(false);
|
---|
[3327] | 209 | private AddAction addAction = new AddAction();
|
---|
[4526] | 210 | private EditAction editAction = new EditAction();
|
---|
| 211 | private DeleteAction deleteAction = new DeleteAction();
|
---|
[2741] | 212 |
|
---|
[2657] | 213 | @Override
|
---|
| 214 | public void showNotify() {
|
---|
[2741] | 215 | DatasetEventManager.getInstance().addDatasetListener(dataChangedAdapter, FireMode.IN_EDT_CONSOLIDATED);
|
---|
[2912] | 216 | SelectionEventManager.getInstance().addSelectionListener(this, FireMode.IN_EDT_CONSOLIDATED);
|
---|
[2869] | 217 | MapView.addEditLayerChangeListener(this);
|
---|
[5278] | 218 | Main.registerActionShortcut(addAction);
|
---|
| 219 | Main.registerActionShortcut(editAction);
|
---|
| 220 | Main.registerActionShortcut(deleteAction);
|
---|
[2658] | 221 | updateSelection();
|
---|
[2657] | 222 | }
|
---|
| 223 |
|
---|
| 224 | @Override
|
---|
| 225 | public void hideNotify() {
|
---|
[2741] | 226 | DatasetEventManager.getInstance().removeDatasetListener(dataChangedAdapter);
|
---|
[2912] | 227 | SelectionEventManager.getInstance().removeSelectionListener(this);
|
---|
[2869] | 228 | MapView.removeEditLayerChangeListener(this);
|
---|
[4526] | 229 | Main.unregisterActionShortcut(addAction);
|
---|
| 230 | Main.unregisterActionShortcut(editAction);
|
---|
| 231 | Main.unregisterActionShortcut(deleteAction);
|
---|
[2657] | 232 | }
|
---|
| 233 |
|
---|
[1169] | 234 | /**
|
---|
| 235 | * Edit the value in the properties table row
|
---|
| 236 | * @param row The row of the table from which the value is edited.
|
---|
| 237 | */
|
---|
[1911] | 238 | @SuppressWarnings("unchecked")
|
---|
[5383] | 239 | private void editProperty(int row) {
|
---|
[1814] | 240 | Collection<OsmPrimitive> sel = Main.main.getCurrentDataSet().getSelected();
|
---|
[1353] | 241 | if (sel.isEmpty()) return;
|
---|
| 242 |
|
---|
[1169] | 243 | String key = propertyData.getValueAt(row, 0).toString();
|
---|
| 244 | objKey=key;
|
---|
[1353] | 245 |
|
---|
[2445] | 246 | String msg = "<html>"+trn("This will change {0} object.",
|
---|
[1763] | 247 | "This will change up to {0} objects.", sel.size(), sel.size())
|
---|
[2445] | 248 | +"<br><br>("+tr("An empty value deletes the tag.", key)+")</html>";
|
---|
[1023] | 249 |
|
---|
[1169] | 250 | JPanel panel = new JPanel(new BorderLayout());
|
---|
| 251 | panel.add(new JLabel(msg), BorderLayout.NORTH);
|
---|
[272] | 252 |
|
---|
[1169] | 253 | JPanel p = new JPanel(new GridBagLayout());
|
---|
| 254 | panel.add(p, BorderLayout.CENTER);
|
---|
[595] | 255 |
|
---|
[3210] | 256 | AutoCompletionManager autocomplete = Main.main.getEditLayer().data.getAutoCompletionManager();
|
---|
[3214] | 257 | List<AutoCompletionListItem> keyList = autocomplete.getKeys();
|
---|
| 258 | Collections.sort(keyList, defaultACItemComparator);
|
---|
[3219] | 259 |
|
---|
[3210] | 260 | final AutoCompletingComboBox keys = new AutoCompletingComboBox();
|
---|
[3214] | 261 | keys.setPossibleACItems(keyList);
|
---|
[1169] | 262 | keys.setEditable(true);
|
---|
| 263 | keys.setSelectedItem(key);
|
---|
[595] | 264 |
|
---|
[1169] | 265 | p.add(new JLabel(tr("Key")), GBC.std());
|
---|
| 266 | p.add(Box.createHorizontalStrut(10), GBC.std());
|
---|
| 267 | p.add(keys, GBC.eol().fill(GBC.HORIZONTAL));
|
---|
[595] | 268 |
|
---|
[3210] | 269 | final AutoCompletingComboBox values = new AutoCompletingComboBox();
|
---|
[1169] | 270 | values.setRenderer(new DefaultListCellRenderer() {
|
---|
[1606] | 271 | @Override public Component getListCellRendererComponent(JList list,
|
---|
[1763] | 272 | Object value, int index, boolean isSelected, boolean cellHasFocus){
|
---|
[1606] | 273 | Component c = super.getListCellRendererComponent(list, value,
|
---|
[1763] | 274 | index, isSelected, cellHasFocus);
|
---|
[1169] | 275 | if (c instanceof JLabel) {
|
---|
[5155] | 276 | String str = ((AutoCompletionListItem) value).getValue();
|
---|
| 277 | if (valueCount.containsKey(objKey)) {
|
---|
| 278 | Map<String, Integer> m = valueCount.get(objKey);
|
---|
[1763] | 279 | if (m.containsKey(str)) {
|
---|
[5155] | 280 | str = tr("{0} ({1})", str, m.get(str));
|
---|
| 281 | c.setFont(c.getFont().deriveFont(Font.ITALIC + Font.BOLD));
|
---|
[1169] | 282 | }
|
---|
[1763] | 283 | }
|
---|
[5155] | 284 | ((JLabel) c).setText(str);
|
---|
[1169] | 285 | }
|
---|
| 286 | return c;
|
---|
| 287 | }
|
---|
| 288 | });
|
---|
| 289 | values.setEditable(true);
|
---|
[3219] | 290 |
|
---|
[4680] | 291 | final Map<String, Integer> m = (Map<String, Integer>) propertyData.getValueAt(row, 1);
|
---|
| 292 |
|
---|
| 293 | Comparator<AutoCompletionListItem> usedValuesAwareComparator = new Comparator<AutoCompletionListItem>() {
|
---|
| 294 |
|
---|
| 295 | @Override
|
---|
| 296 | public int compare(AutoCompletionListItem o1, AutoCompletionListItem o2) {
|
---|
| 297 | boolean c1 = m.containsKey(o1.getValue());
|
---|
| 298 | boolean c2 = m.containsKey(o2.getValue());
|
---|
[4869] | 299 | if (c1 == c2)
|
---|
[4680] | 300 | return String.CASE_INSENSITIVE_ORDER.compare(o1.getValue(), o2.getValue());
|
---|
[4869] | 301 | else if (c1)
|
---|
[4680] | 302 | return -1;
|
---|
[4869] | 303 | else
|
---|
[4680] | 304 | return +1;
|
---|
| 305 | }
|
---|
| 306 | };
|
---|
| 307 |
|
---|
[4300] | 308 | List<AutoCompletionListItem> valueList = autocomplete.getValues(getAutocompletionKeys(key));
|
---|
[4680] | 309 | Collections.sort(valueList, usedValuesAwareComparator);
|
---|
[3219] | 310 |
|
---|
[3214] | 311 | values.setPossibleACItems(valueList);
|
---|
[1169] | 312 | final String selection= m.size()!=1?tr("<different>"):m.entrySet().iterator().next().getKey();
|
---|
| 313 | values.setSelectedItem(selection);
|
---|
| 314 | values.getEditor().setItem(selection);
|
---|
| 315 | p.add(new JLabel(tr("Value")), GBC.std());
|
---|
| 316 | p.add(Box.createHorizontalStrut(10), GBC.std());
|
---|
| 317 | p.add(values, GBC.eol().fill(GBC.HORIZONTAL));
|
---|
[4680] | 318 | addFocusAdapter(row, keys, values, autocomplete, usedValuesAwareComparator);
|
---|
[272] | 319 |
|
---|
[1169] | 320 | final JOptionPane optionPane = new JOptionPane(panel, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION) {
|
---|
| 321 | @Override public void selectInitialValue() {
|
---|
[4948] | 322 | // save unix system selection (middle mouse paste)
|
---|
| 323 | Clipboard sysSel = Toolkit.getDefaultToolkit().getSystemSelection();
|
---|
| 324 | if(sysSel != null) {
|
---|
| 325 | Transferable old = sysSel.getContents(null);
|
---|
[4949] | 326 | values.requestFocusInWindow();
|
---|
| 327 | values.getEditor().selectAll();
|
---|
[4948] | 328 | sysSel.setContents(old, null);
|
---|
| 329 | } else {
|
---|
| 330 | values.requestFocusInWindow();
|
---|
| 331 | values.getEditor().selectAll();
|
---|
| 332 | }
|
---|
[1169] | 333 | }
|
---|
| 334 | };
|
---|
[4303] | 335 | final JDialog dlg = optionPane.createDialog(Main.parent, trn("Change value?", "Change values?", m.size()));
|
---|
[3501] | 336 | dlg.setModalityType(ModalityType.DOCUMENT_MODAL);
|
---|
[4102] | 337 | Dimension dlgSize = dlg.getSize();
|
---|
| 338 | if(dlgSize.width > Main.parent.getSize().width) {
|
---|
| 339 | dlgSize.width = Math.max(250, Main.parent.getSize().width);
|
---|
| 340 | dlg.setSize(dlgSize);
|
---|
| 341 | }
|
---|
| 342 | dlg.setLocationRelativeTo(Main.parent);
|
---|
[1169] | 343 | values.getEditor().addActionListener(new ActionListener() {
|
---|
| 344 | public void actionPerformed(ActionEvent e) {
|
---|
| 345 | dlg.setVisible(false);
|
---|
| 346 | optionPane.setValue(JOptionPane.OK_OPTION);
|
---|
| 347 | }
|
---|
| 348 | });
|
---|
[416] | 349 |
|
---|
[1169] | 350 | String oldValue = values.getEditor().getItem().toString();
|
---|
| 351 | dlg.setVisible(true);
|
---|
[272] | 352 |
|
---|
[1169] | 353 | Object answer = optionPane.getValue();
|
---|
| 354 | if (answer == null || answer == JOptionPane.UNINITIALIZED_VALUE ||
|
---|
| 355 | (answer instanceof Integer && (Integer)answer != JOptionPane.OK_OPTION)) {
|
---|
| 356 | values.getEditor().setItem(oldValue);
|
---|
| 357 | return;
|
---|
| 358 | }
|
---|
[272] | 359 |
|
---|
[1268] | 360 | String value = values.getEditor().getItem().toString().trim();
|
---|
[1169] | 361 | // is not Java 1.5
|
---|
| 362 | //value = java.text.Normalizer.normalize(value, java.text.Normalizer.Form.NFC);
|
---|
[1763] | 363 | if (value.equals("")) {
|
---|
[1169] | 364 | value = null; // delete the key
|
---|
[1763] | 365 | }
|
---|
[1268] | 366 | String newkey = keys.getEditor().getItem().toString().trim();
|
---|
[1169] | 367 | //newkey = java.text.Normalizer.normalize(newkey, java.text.Normalizer.Form.NFC);
|
---|
| 368 | if (newkey.equals("")) {
|
---|
| 369 | newkey = key;
|
---|
| 370 | value = null; // delete the key instead
|
---|
| 371 | }
|
---|
[3146] | 372 | if (key.equals(newkey) && tr("<different>").equals(value))
|
---|
[2951] | 373 | return;
|
---|
[1763] | 374 | if (key.equals(newkey) || value == null) {
|
---|
[1169] | 375 | Main.main.undoRedo.add(new ChangePropertyCommand(sel, newkey, value));
|
---|
[1763] | 376 | } else {
|
---|
[4140] | 377 | for (OsmPrimitive osm: sel) {
|
---|
| 378 | if(osm.get(newkey) != null) {
|
---|
| 379 | ExtendedDialog ed = new ExtendedDialog(
|
---|
| 380 | Main.parent,
|
---|
| 381 | tr("Overwrite key"),
|
---|
| 382 | new String[]{tr("Replace"), tr("Cancel")});
|
---|
| 383 | ed.setButtonIcons(new String[]{"purge", "cancel"});
|
---|
| 384 | ed.setContent(tr("You changed the key from ''{0}'' to ''{1}''.\n"
|
---|
[4604] | 385 | + "The new key is already used, overwrite values?", key, newkey));
|
---|
[4140] | 386 | ed.setCancelButton(2);
|
---|
| 387 | ed.toggleEnable("overwriteEditKey");
|
---|
| 388 | ed.showDialog();
|
---|
| 389 |
|
---|
[4604] | 390 | if (ed.getValue() != 1)
|
---|
[4140] | 391 | return;
|
---|
| 392 | break;
|
---|
| 393 | }
|
---|
| 394 | }
|
---|
[1169] | 395 | Collection<Command> commands=new Vector<Command>();
|
---|
| 396 | commands.add(new ChangePropertyCommand(sel, key, null));
|
---|
| 397 | if (value.equals(tr("<different>"))) {
|
---|
| 398 | HashMap<String, Vector<OsmPrimitive>> map=new HashMap<String, Vector<OsmPrimitive>>();
|
---|
| 399 | for (OsmPrimitive osm: sel) {
|
---|
[1843] | 400 | String val=osm.get(key);
|
---|
| 401 | if(val != null)
|
---|
[1169] | 402 | {
|
---|
[1843] | 403 | if (map.containsKey(val)) {
|
---|
| 404 | map.get(val).add(osm);
|
---|
| 405 | } else {
|
---|
| 406 | Vector<OsmPrimitive> v = new Vector<OsmPrimitive>();
|
---|
| 407 | v.add(osm);
|
---|
| 408 | map.put(val, v);
|
---|
[1169] | 409 | }
|
---|
| 410 | }
|
---|
| 411 | }
|
---|
| 412 | for (Entry<String, Vector<OsmPrimitive>> e: map.entrySet()) {
|
---|
| 413 | commands.add(new ChangePropertyCommand(e.getValue(), newkey, e.getKey()));
|
---|
| 414 | }
|
---|
| 415 | } else {
|
---|
| 416 | commands.add(new ChangePropertyCommand(sel, newkey, value));
|
---|
| 417 | }
|
---|
[1606] | 418 | Main.main.undoRedo.add(new SequenceCommand(
|
---|
[1763] | 419 | trn("Change properties of up to {0} object",
|
---|
| 420 | "Change properties of up to {0} objects", sel.size(), sel.size()),
|
---|
| 421 | commands));
|
---|
[1169] | 422 | }
|
---|
[272] | 423 |
|
---|
[1268] | 424 | if(!key.equals(newkey)) {
|
---|
| 425 | for(int i=0; i < propertyTable.getRowCount(); i++)
|
---|
[3338] | 426 | if(propertyData.getValueAt(i, 0).toString().equals(newkey)) {
|
---|
[1268] | 427 | row=i;
|
---|
| 428 | break;
|
---|
| 429 | }
|
---|
| 430 | }
|
---|
| 431 | propertyTable.changeSelection(row, 0, false, false);
|
---|
[1169] | 432 | }
|
---|
[272] | 433 |
|
---|
[1169] | 434 | /**
|
---|
[4604] | 435 | * For a given key k, return a list of keys which are used as keys for
|
---|
[4300] | 436 | * auto-completing values to increase the search space.
|
---|
| 437 | * @param key the key k
|
---|
| 438 | * @return a list of keys
|
---|
| 439 | */
|
---|
[5383] | 440 | private static List<String> getAutocompletionKeys(String key) {
|
---|
[4604] | 441 | if ("name".equals(key) || "addr:street".equals(key))
|
---|
[4300] | 442 | return Arrays.asList("addr:street", "name");
|
---|
[4604] | 443 | else
|
---|
[4300] | 444 | return Arrays.asList(key);
|
---|
| 445 | }
|
---|
| 446 |
|
---|
| 447 | /**
|
---|
[1169] | 448 | * This simply fires up an relation editor for the relation shown; everything else
|
---|
| 449 | * is the editor's business.
|
---|
| 450 | *
|
---|
| 451 | * @param row
|
---|
| 452 | */
|
---|
[5383] | 453 | private void editMembership(int row) {
|
---|
[1763] | 454 | Relation relation = (Relation)membershipData.getValueAt(row, 0);
|
---|
[2027] | 455 | Main.map.relationListDialog.selectRelation(relation);
|
---|
[1772] | 456 | RelationEditor.getEditor(
|
---|
| 457 | Main.map.mapView.getEditLayer(),
|
---|
| 458 | relation,
|
---|
[3302] | 459 | ((MemberInfo) membershipData.getValueAt(row, 1)).role).setVisible(true);
|
---|
[1169] | 460 | }
|
---|
[343] | 461 |
|
---|
[4109] | 462 | private static String lastAddKey = null;
|
---|
| 463 | private static String lastAddValue = null;
|
---|
[5383] | 464 |
|
---|
| 465 | public static final int DEFAULT_LRU_TAGS_NUMBER = 5;
|
---|
| 466 | public static final int MAX_LRU_TAGS_NUMBER = 9;
|
---|
| 467 |
|
---|
| 468 | // LRU cache for recently added tags (http://java-planet.blogspot.com/2005/08/how-to-set-up-simple-lru-cache-using.html)
|
---|
| 469 | private static final Map<Tag, Void> recentTags = new LinkedHashMap<Tag, Void>(MAX_LRU_TAGS_NUMBER+1, 1.1f, true) {
|
---|
| 470 | @Override
|
---|
| 471 | protected boolean removeEldestEntry(Entry<Tag, Void> eldest) {
|
---|
| 472 | return size() > MAX_LRU_TAGS_NUMBER;
|
---|
| 473 | }
|
---|
| 474 | };
|
---|
| 475 |
|
---|
[1169] | 476 | /**
|
---|
| 477 | * Open the add selection dialog and add a new key/value to the table (and
|
---|
| 478 | * to the dataset, of course).
|
---|
| 479 | */
|
---|
[5383] | 480 | private void addProperty() {
|
---|
[5378] | 481 | Collection<OsmPrimitive> sel;
|
---|
| 482 | if (Main.map.mapMode instanceof DrawAction) {
|
---|
| 483 | sel = ((DrawAction) Main.map.mapMode).getInProgressSelection();
|
---|
| 484 | } else {
|
---|
| 485 | DataSet ds = Main.main.getCurrentDataSet();
|
---|
| 486 | if (ds == null) return;
|
---|
| 487 | sel = ds.getSelected();
|
---|
| 488 | }
|
---|
[1353] | 489 | if (sel.isEmpty()) return;
|
---|
[272] | 490 |
|
---|
[5383] | 491 | JPanel p = new JPanel(new GridBagLayout());
|
---|
[1606] | 492 | p.add(new JLabel("<html>"+trn("This will change up to {0} object.",
|
---|
[1763] | 493 | "This will change up to {0} objects.", sel.size(),sel.size())
|
---|
[5385] | 494 | +"<br><br>"+tr("Please select a key")), GBC.eol().fill(GBC.HORIZONTAL));
|
---|
[3210] | 495 | final AutoCompletingComboBox keys = new AutoCompletingComboBox();
|
---|
| 496 | AutoCompletionManager autocomplete = Main.main.getEditLayer().data.getAutoCompletionManager();
|
---|
[3214] | 497 | List<AutoCompletionListItem> keyList = autocomplete.getKeys();
|
---|
| 498 |
|
---|
[4604] | 499 | AutoCompletionListItem itemToSelect = null;
|
---|
[3214] | 500 | // remove the object's tag keys from the list
|
---|
| 501 | Iterator<AutoCompletionListItem> iter = keyList.iterator();
|
---|
| 502 | while (iter.hasNext()) {
|
---|
| 503 | AutoCompletionListItem item = iter.next();
|
---|
[4109] | 504 | if (item.getValue().equals(lastAddKey)) {
|
---|
| 505 | itemToSelect = item;
|
---|
| 506 | }
|
---|
[3214] | 507 | for (int i = 0; i < propertyData.getRowCount(); ++i) {
|
---|
| 508 | if (item.getValue().equals(propertyData.getValueAt(i, 0))) {
|
---|
[4604] | 509 | if (itemToSelect == item) {
|
---|
[4109] | 510 | itemToSelect = null;
|
---|
[4604] | 511 | }
|
---|
[3214] | 512 | iter.remove();
|
---|
| 513 | break;
|
---|
| 514 | }
|
---|
| 515 | }
|
---|
[2657] | 516 | }
|
---|
[3214] | 517 |
|
---|
| 518 | Collections.sort(keyList, defaultACItemComparator);
|
---|
| 519 | keys.setPossibleACItems(keyList);
|
---|
[1169] | 520 | keys.setEditable(true);
|
---|
[1023] | 521 |
|
---|
[5383] | 522 | p.add(keys, GBC.eop().fill());
|
---|
[272] | 523 |
|
---|
[5383] | 524 | p.add(new JLabel(tr("Please select a value")), GBC.eol());
|
---|
[3210] | 525 | final AutoCompletingComboBox values = new AutoCompletingComboBox();
|
---|
[1169] | 526 | values.setEditable(true);
|
---|
[5383] | 527 | p.add(values, GBC.eop().fill());
|
---|
[4109] | 528 | if (itemToSelect != null) {
|
---|
| 529 | keys.setSelectedItem(itemToSelect);
|
---|
[4141] | 530 | /* don't add single chars, as they are no properly selected */
|
---|
[4604] | 531 | if(lastAddValue != null && lastAddValue.length() > 1) {
|
---|
[4141] | 532 | values.setSelectedItem(lastAddValue);
|
---|
[4604] | 533 | }
|
---|
[4109] | 534 | }
|
---|
[5424] | 535 |
|
---|
| 536 | FocusAdapter focus = addFocusAdapter(-1, keys, values, autocomplete, defaultACItemComparator);
|
---|
| 537 | // fire focus event in advance or otherwise the popup list will be too small at first
|
---|
| 538 | focus.focusGained(null);
|
---|
| 539 |
|
---|
[5383] | 540 | int recentTagsToShow = Main.pref.getInteger("properties.recently-added-tags", DEFAULT_LRU_TAGS_NUMBER);
|
---|
| 541 | if (recentTagsToShow > MAX_LRU_TAGS_NUMBER) {
|
---|
| 542 | recentTagsToShow = MAX_LRU_TAGS_NUMBER;
|
---|
| 543 | }
|
---|
| 544 | List<JosmAction> recentTagsActions = new ArrayList<JosmAction>();
|
---|
[5424] | 545 | suggestRecentlyAddedTags(p, keys, values, recentTagsActions, recentTagsToShow, focus);
|
---|
[272] | 546 |
|
---|
[1169] | 547 | JOptionPane pane = new JOptionPane(p, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION){
|
---|
| 548 | @Override public void selectInitialValue() {
|
---|
[4948] | 549 | // save unix system selection (middle mouse paste)
|
---|
| 550 | Clipboard sysSel = Toolkit.getDefaultToolkit().getSystemSelection();
|
---|
| 551 | if(sysSel != null) {
|
---|
| 552 | Transferable old = sysSel.getContents(null);
|
---|
[4949] | 553 | keys.requestFocusInWindow();
|
---|
| 554 | keys.getEditor().selectAll();
|
---|
[4948] | 555 | sysSel.setContents(old, null);
|
---|
| 556 | } else {
|
---|
| 557 | keys.requestFocusInWindow();
|
---|
| 558 | keys.getEditor().selectAll();
|
---|
| 559 | }
|
---|
[1169] | 560 | }
|
---|
| 561 | };
|
---|
[4303] | 562 | JDialog dialog = pane.createDialog(Main.parent, tr("Add value?"));
|
---|
[3501] | 563 | dialog.setModalityType(ModalityType.DOCUMENT_MODAL);
|
---|
[1765] | 564 | dialog.setVisible(true);
|
---|
[5383] | 565 |
|
---|
| 566 | for (JosmAction action : recentTagsActions) {
|
---|
| 567 | action.destroy();
|
---|
| 568 | }
|
---|
[1765] | 569 |
|
---|
[1169] | 570 | if (!Integer.valueOf(JOptionPane.OK_OPTION).equals(pane.getValue()))
|
---|
| 571 | return;
|
---|
[1268] | 572 | String key = keys.getEditor().getItem().toString().trim();
|
---|
| 573 | String value = values.getEditor().getItem().toString().trim();
|
---|
[5109] | 574 | if (key.isEmpty() || value.isEmpty())
|
---|
[1169] | 575 | return;
|
---|
[4109] | 576 | lastAddKey = key;
|
---|
| 577 | lastAddValue = value;
|
---|
[5383] | 578 | recentTags.put(new Tag(key, value), null);
|
---|
[1169] | 579 | Main.main.undoRedo.add(new ChangePropertyCommand(sel, key, value));
|
---|
[2473] | 580 | btnAdd.requestFocusInWindow();
|
---|
[1169] | 581 | }
|
---|
[5383] | 582 |
|
---|
[5424] | 583 | private void suggestRecentlyAddedTags(JPanel p, final AutoCompletingComboBox keys, final AutoCompletingComboBox values, List<JosmAction> tagsActions, int tagsToShow, final FocusAdapter focus) {
|
---|
[5383] | 584 | if (tagsToShow > 0 && !recentTags.isEmpty()) {
|
---|
| 585 | p.add(new JLabel(tr("Recently added tags")), GBC.eol());
|
---|
| 586 |
|
---|
| 587 | int count = 1;
|
---|
| 588 | // We store the maximum number (9) of recent tags to allow dynamic change of number of tags shown in the preferences.
|
---|
| 589 | // This implies to iterate in descending order, as the oldest elements will only be removed after we reach the maximum numbern and not the number of tags to show.
|
---|
| 590 | // However, as Set does not allow to iterate in descending order, we need to copy its elements into a List we can access in reverse order.
|
---|
| 591 | List<Tag> tags = new LinkedList<Tag>(recentTags.keySet());
|
---|
| 592 | for (int i = tags.size()-1; i >= 0 && count <= tagsToShow; i--, count++) {
|
---|
| 593 | final Tag t = tags.get(i);
|
---|
| 594 | // Find and display icon
|
---|
| 595 | ImageIcon icon = MapPaintStyles.getNodeIcon(t, false); // Filters deprecated icon
|
---|
| 596 | if (icon == null) {
|
---|
| 597 | icon = new ImageIcon(new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB));
|
---|
| 598 | }
|
---|
| 599 | GridBagConstraints gbc = new GridBagConstraints();
|
---|
| 600 | gbc.ipadx = 5;
|
---|
| 601 | p.add(new JLabel(icon), gbc);
|
---|
| 602 | // Create action for reusing the tag, with keyboard shortcut Ctrl+(1-5)
|
---|
| 603 | String actionShortcutKey = "properties:recent:"+count;
|
---|
| 604 | Shortcut sc = Shortcut.registerShortcut(actionShortcutKey, null, KeyEvent.VK_0+count, Shortcut.CTRL);
|
---|
| 605 | final JosmAction action = new JosmAction(actionShortcutKey, null, tr("Use this tag again"), sc, false) {
|
---|
| 606 | @Override
|
---|
| 607 | public void actionPerformed(ActionEvent e) {
|
---|
[5427] | 608 | keys.setSelectedItem(t.getKey());
|
---|
[5428] | 609 | values.setSelectedItem(t.getValue());
|
---|
[5424] | 610 | // Update list of values (fix #7951)
|
---|
| 611 | focus.focusGained(null);
|
---|
[5383] | 612 | }
|
---|
| 613 | };
|
---|
| 614 | tagsActions.add(action);
|
---|
[5427] | 615 | // Disable action if its key is already set on the object (the key being absent from the keys list for this reason
|
---|
| 616 | // performing this action leads to autocomplete to the next key (see #7671 comments)
|
---|
| 617 | for (int j = 0; j < propertyData.getRowCount(); ++j) {
|
---|
| 618 | System.out.println(propertyData.getValueAt(j, 0));
|
---|
| 619 | if (t.getKey().equals(propertyData.getValueAt(j, 0))) {
|
---|
| 620 | action.setEnabled(false);
|
---|
| 621 | break;
|
---|
| 622 | }
|
---|
| 623 | }
|
---|
| 624 | // Create tag label
|
---|
[5383] | 625 | final JLabel tagLabel = new JLabel("<html>"
|
---|
| 626 | + "<style>td{border:1px solid gray; font-weight:normal;}</style>"
|
---|
| 627 | + "<table><tr><td>" + t.toString() + "</td></tr></table></html>");
|
---|
[5427] | 628 | if (action.isEnabled()) {
|
---|
| 629 | // Register action
|
---|
| 630 | p.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(sc.getKeyStroke(), actionShortcutKey);
|
---|
| 631 | p.getActionMap().put(actionShortcutKey, action);
|
---|
| 632 | // Make the tag label clickable and set tooltip to the action description (this displays also the keyboard shortcut)
|
---|
| 633 | tagLabel.setToolTipText((String) action.getValue(Action.SHORT_DESCRIPTION));
|
---|
| 634 | tagLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
---|
| 635 | tagLabel.addMouseListener(new MouseAdapter() {
|
---|
| 636 | @Override
|
---|
| 637 | public void mouseClicked(MouseEvent e) {
|
---|
| 638 | action.actionPerformed(null);
|
---|
| 639 | }
|
---|
| 640 | });
|
---|
| 641 | } else {
|
---|
| 642 | // Disable tag label
|
---|
| 643 | tagLabel.setEnabled(false);
|
---|
| 644 | // Explain in the tooltip why
|
---|
| 645 | tagLabel.setToolTipText(tr("The key ''{0}'' is already used", t.getKey()));
|
---|
| 646 | }
|
---|
| 647 | // Finally add label to the resulting panel
|
---|
[5425] | 648 | JPanel tagPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
|
---|
| 649 | tagPanel.add(tagLabel);
|
---|
| 650 | p.add(tagPanel, GBC.eol());
|
---|
[5383] | 651 | }
|
---|
| 652 | }
|
---|
| 653 | }
|
---|
[272] | 654 |
|
---|
[1169] | 655 | /**
|
---|
| 656 | * @param allData
|
---|
| 657 | * @param keys
|
---|
| 658 | * @param values
|
---|
| 659 | */
|
---|
[4680] | 660 | private FocusAdapter addFocusAdapter(final int row,
|
---|
| 661 | final AutoCompletingComboBox keys, final AutoCompletingComboBox values,
|
---|
| 662 | final AutoCompletionManager autocomplete, final Comparator<AutoCompletionListItem> comparator) {
|
---|
[1169] | 663 | // get the combo box' editor component
|
---|
| 664 | JTextComponent editor = (JTextComponent)values.getEditor()
|
---|
[4604] | 665 | .getEditorComponent();
|
---|
[1169] | 666 | // Refresh the values model when focus is gained
|
---|
[3210] | 667 | FocusAdapter focus = new FocusAdapter() {
|
---|
[1169] | 668 | @Override public void focusGained(FocusEvent e) {
|
---|
| 669 | String key = keys.getEditor().getItem().toString();
|
---|
[3219] | 670 |
|
---|
[4300] | 671 | List<AutoCompletionListItem> valueList = autocomplete.getValues(getAutocompletionKeys(key));
|
---|
[4680] | 672 | Collections.sort(valueList, comparator);
|
---|
[3214] | 673 |
|
---|
| 674 | values.setPossibleACItems(valueList);
|
---|
[1169] | 675 | objKey=key;
|
---|
| 676 | }
|
---|
[3210] | 677 | };
|
---|
| 678 | editor.addFocusListener(focus);
|
---|
| 679 | return focus;
|
---|
[1169] | 680 | }
|
---|
| 681 | private String objKey;
|
---|
[1415] | 682 |
|
---|
[1169] | 683 | /**
|
---|
| 684 | * The property data.
|
---|
| 685 | */
|
---|
| 686 | private final DefaultTableModel propertyData = new DefaultTableModel() {
|
---|
| 687 | @Override public boolean isCellEditable(int row, int column) {
|
---|
| 688 | return false;
|
---|
| 689 | }
|
---|
| 690 | @Override public Class<?> getColumnClass(int columnIndex) {
|
---|
| 691 | return String.class;
|
---|
| 692 | }
|
---|
| 693 | };
|
---|
[343] | 694 |
|
---|
[1169] | 695 | /**
|
---|
| 696 | * The membership data.
|
---|
| 697 | */
|
---|
| 698 | private final DefaultTableModel membershipData = new DefaultTableModel() {
|
---|
| 699 | @Override public boolean isCellEditable(int row, int column) {
|
---|
| 700 | return false;
|
---|
| 701 | }
|
---|
| 702 | @Override public Class<?> getColumnClass(int columnIndex) {
|
---|
| 703 | return String.class;
|
---|
| 704 | }
|
---|
| 705 | };
|
---|
[1023] | 706 |
|
---|
[1169] | 707 | /**
|
---|
| 708 | * The properties list.
|
---|
| 709 | */
|
---|
| 710 | private final JTable propertyTable = new JTable(propertyData);
|
---|
| 711 | private final JTable membershipTable = new JTable(membershipData);
|
---|
[343] | 712 |
|
---|
[1169] | 713 | public JComboBox taggingPresets = new JComboBox();
|
---|
[272] | 714 |
|
---|
[1353] | 715 | /**
|
---|
| 716 | * The Add/Edit/Delete buttons (needed to be able to disable them)
|
---|
| 717 | */
|
---|
| 718 | private final SideButton btnAdd;
|
---|
| 719 | private final SideButton btnEdit;
|
---|
| 720 | private final SideButton btnDel;
|
---|
[3518] | 721 | private final PresetListPanel presets = new PresetListPanel();
|
---|
[272] | 722 |
|
---|
[1606] | 723 | private final JLabel selectSth = new JLabel("<html><p>"
|
---|
[4888] | 724 | + tr("Select objects for which to change properties.") + "</p></html>");
|
---|
[1353] | 725 |
|
---|
[3327] | 726 | static class MemberInfo {
|
---|
[3302] | 727 | List<RelationMember> role = new ArrayList<RelationMember>();
|
---|
| 728 | List<Integer> position = new ArrayList<Integer>();
|
---|
[3306] | 729 | private String positionString = null;
|
---|
[4663] | 730 | void add(RelationMember r, Integer p) {
|
---|
[3327] | 731 | role.add(r);
|
---|
| 732 | position.add(p);
|
---|
[3302] | 733 | }
|
---|
[4663] | 734 | String getPositionString() {
|
---|
| 735 | if (positionString == null) {
|
---|
[3306] | 736 | Collections.sort(position);
|
---|
| 737 | positionString = String.valueOf(position.get(0));
|
---|
| 738 | int cnt = 0;
|
---|
| 739 | int last = position.get(0);
|
---|
[4663] | 740 | for (int i = 1; i < position.size(); ++i) {
|
---|
[3306] | 741 | int cur = position.get(i);
|
---|
[4663] | 742 | if (cur == last + 1) {
|
---|
[3306] | 743 | ++cnt;
|
---|
[4335] | 744 | } else if (cnt == 0) {
|
---|
[4663] | 745 | positionString += "," + String.valueOf(cur);
|
---|
[3306] | 746 | } else {
|
---|
[4663] | 747 | positionString += "-" + String.valueOf(last);
|
---|
| 748 | positionString += "," + String.valueOf(cur);
|
---|
[3306] | 749 | cnt = 0;
|
---|
| 750 | }
|
---|
| 751 | last = cur;
|
---|
| 752 | }
|
---|
[4663] | 753 | if (cnt >= 1) {
|
---|
| 754 | positionString += "-" + String.valueOf(last);
|
---|
[3327] | 755 | }
|
---|
[3306] | 756 | }
|
---|
[4663] | 757 | if (positionString.length() > 20) {
|
---|
| 758 | positionString = positionString.substring(0, 17) + "...";
|
---|
[3327] | 759 | }
|
---|
[3306] | 760 | return positionString;
|
---|
| 761 | }
|
---|
[3302] | 762 | }
|
---|
| 763 |
|
---|
[1169] | 764 | /**
|
---|
| 765 | * Create a new PropertiesDialog
|
---|
| 766 | */
|
---|
| 767 | public PropertiesDialog(MapFrame mapFrame) {
|
---|
| 768 | super(tr("Properties/Memberships"), "propertiesdialog", tr("Properties for selected objects."),
|
---|
[1763] | 769 | Shortcut.registerShortcut("subwindow:properties", tr("Toggle: {0}", tr("Properties/Memberships")), KeyEvent.VK_P,
|
---|
[4982] | 770 | Shortcut.ALT_SHIFT), 150, true);
|
---|
[272] | 771 |
|
---|
[1169] | 772 | // setting up the properties table
|
---|
[4484] | 773 | propertyMenu = new JPopupMenu();
|
---|
| 774 | propertyMenu.add(copyValueAction);
|
---|
| 775 | propertyMenu.add(copyKeyValueAction);
|
---|
| 776 | propertyMenu.add(copyAllKeyValueAction);
|
---|
| 777 | propertyMenu.addSeparator();
|
---|
[4503] | 778 | propertyMenu.add(searchActionAny);
|
---|
| 779 | propertyMenu.add(searchActionSame);
|
---|
| 780 | propertyMenu.addSeparator();
|
---|
[4484] | 781 | propertyMenu.add(helpAction);
|
---|
[4604] | 782 |
|
---|
[1169] | 783 | propertyData.setColumnIdentifiers(new String[]{tr("Key"),tr("Value")});
|
---|
[4697] | 784 | propertyTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
|
---|
[4119] | 785 | propertyTable.getTableHeader().setReorderingAllowed(false);
|
---|
[3529] | 786 | propertyTable.addMouseListener(new PopupMenuLauncher() {
|
---|
| 787 | @Override
|
---|
| 788 | public void launch(MouseEvent evt) {
|
---|
| 789 | Point p = evt.getPoint();
|
---|
| 790 | int row = propertyTable.rowAtPoint(p);
|
---|
| 791 | if (row > -1) {
|
---|
| 792 | propertyTable.changeSelection(row, 0, false, false);
|
---|
[4484] | 793 | propertyMenu.show(propertyTable, p.x, p.y-3);
|
---|
[3529] | 794 | }
|
---|
| 795 | }
|
---|
| 796 | });
|
---|
[1023] | 797 |
|
---|
[1169] | 798 | propertyTable.getColumnModel().getColumn(1).setCellRenderer(new DefaultTableCellRenderer(){
|
---|
[1606] | 799 | @Override public Component getTableCellRendererComponent(JTable table, Object value,
|
---|
[1763] | 800 | boolean isSelected, boolean hasFocus, int row, int column) {
|
---|
[1169] | 801 | Component c = super.getTableCellRendererComponent(table, value, isSelected, false, row, column);
|
---|
[4072] | 802 | if (value == null)
|
---|
| 803 | return this;
|
---|
[1169] | 804 | if (c instanceof JLabel) {
|
---|
| 805 | String str = null;
|
---|
[2018] | 806 | if (value instanceof String) {
|
---|
[1987] | 807 | str = (String) value;
|
---|
[2741] | 808 | } else if (value instanceof Map<?, ?>) {
|
---|
| 809 | Map<?, ?> v = (Map<?, ?>) value;
|
---|
[2018] | 810 | if (v.size() != 1) {
|
---|
[1987] | 811 | str=tr("<different>");
|
---|
| 812 | c.setFont(c.getFont().deriveFont(Font.ITALIC));
|
---|
| 813 | } else {
|
---|
[2741] | 814 | final Map.Entry<?, ?> entry = v.entrySet().iterator().next();
|
---|
[2018] | 815 | str = (String) entry.getKey();
|
---|
[1987] | 816 | }
|
---|
[1169] | 817 | }
|
---|
| 818 | ((JLabel)c).setText(str);
|
---|
| 819 | }
|
---|
| 820 | return c;
|
---|
| 821 | }
|
---|
| 822 | });
|
---|
[1023] | 823 |
|
---|
[1169] | 824 | // setting up the membership table
|
---|
[4484] | 825 | membershipMenu = new JPopupMenu();
|
---|
| 826 | membershipMenu.add(new SelectRelationAction(true));
|
---|
| 827 | membershipMenu.add(new SelectRelationAction(false));
|
---|
| 828 | membershipMenu.add(new SelectRelationMembersAction());
|
---|
| 829 | membershipMenu.add(new DownloadIncompleteMembersAction());
|
---|
| 830 | membershipMenu.addSeparator();
|
---|
| 831 | membershipMenu.add(helpAction);
|
---|
[1023] | 832 |
|
---|
[3302] | 833 | membershipData.setColumnIdentifiers(new String[]{tr("Member Of"),tr("Role"),tr("Position")});
|
---|
[1169] | 834 | membershipTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
---|
[2723] | 835 | membershipTable.addMouseListener(new PopupMenuLauncher() {
|
---|
| 836 | @Override
|
---|
| 837 | public void launch(MouseEvent evt) {
|
---|
| 838 | Point p = evt.getPoint();
|
---|
| 839 | int row = membershipTable.rowAtPoint(p);
|
---|
| 840 | if (row > -1) {
|
---|
[3529] | 841 | membershipTable.changeSelection(row, 0, false, false);
|
---|
[2723] | 842 | Relation relation = (Relation)membershipData.getValueAt(row, 0);
|
---|
[4484] | 843 | for (Component c : membershipMenu.getComponents()) {
|
---|
| 844 | if (c instanceof JMenuItem) {
|
---|
| 845 | Action action = ((JMenuItem) c).getAction();
|
---|
| 846 | if (action instanceof RelationRelated) {
|
---|
| 847 | ((RelationRelated)action).setRelation(relation);
|
---|
| 848 | }
|
---|
| 849 | }
|
---|
| 850 | }
|
---|
| 851 | membershipMenu.show(membershipTable, p.x, p.y-3);
|
---|
[2723] | 852 | }
|
---|
| 853 | }
|
---|
| 854 | });
|
---|
[1023] | 855 |
|
---|
[3302] | 856 | TableColumnModel mod = membershipTable.getColumnModel();
|
---|
[4119] | 857 | membershipTable.getTableHeader().setReorderingAllowed(false);
|
---|
[3302] | 858 | mod.getColumn(0).setCellRenderer(new DefaultTableCellRenderer() {
|
---|
[1606] | 859 | @Override public Component getTableCellRendererComponent(JTable table, Object value,
|
---|
[1763] | 860 | boolean isSelected, boolean hasFocus, int row, int column) {
|
---|
[1169] | 861 | Component c = super.getTableCellRendererComponent(table, value, isSelected, false, row, column);
|
---|
[4072] | 862 | if (value == null)
|
---|
| 863 | return this;
|
---|
[1169] | 864 | if (c instanceof JLabel) {
|
---|
[3219] | 865 | JLabel label = (JLabel)c;
|
---|
| 866 | Relation r = (Relation)value;
|
---|
| 867 | label.setText(r.getDisplayName(DefaultNameFormatter.getInstance()));
|
---|
[3306] | 868 | if (r.isDisabledAndHidden()) {
|
---|
[3219] | 869 | label.setFont(label.getFont().deriveFont(Font.ITALIC));
|
---|
| 870 | }
|
---|
[1169] | 871 | }
|
---|
| 872 | return c;
|
---|
| 873 | }
|
---|
| 874 | });
|
---|
[1023] | 875 |
|
---|
[3302] | 876 | mod.getColumn(1).setCellRenderer(new DefaultTableCellRenderer() {
|
---|
[1606] | 877 | @Override public Component getTableCellRendererComponent(JTable table, Object value,
|
---|
[1763] | 878 | boolean isSelected, boolean hasFocus, int row, int column) {
|
---|
[4072] | 879 | if (value == null)
|
---|
| 880 | return this;
|
---|
[1169] | 881 | Component c = super.getTableCellRendererComponent(table, value, isSelected, false, row, column);
|
---|
[3306] | 882 | boolean isDisabledAndHidden = (((Relation)table.getValueAt(row, 0))).isDisabledAndHidden();
|
---|
[1169] | 883 | if (c instanceof JLabel) {
|
---|
[3219] | 884 | JLabel label = (JLabel)c;
|
---|
[3302] | 885 | MemberInfo col = (MemberInfo) value;
|
---|
[1023] | 886 |
|
---|
[1169] | 887 | String text = null;
|
---|
[3302] | 888 | for (RelationMember r : col.role) {
|
---|
[1169] | 889 | if (text == null) {
|
---|
[1930] | 890 | text = r.getRole();
|
---|
[1169] | 891 | }
|
---|
[1930] | 892 | else if (!text.equals(r.getRole())) {
|
---|
[1169] | 893 | text = tr("<different>");
|
---|
| 894 | break;
|
---|
| 895 | }
|
---|
| 896 | }
|
---|
[1023] | 897 |
|
---|
[3219] | 898 | label.setText(text);
|
---|
[3306] | 899 | if (isDisabledAndHidden) {
|
---|
[3219] | 900 | label.setFont(label.getFont().deriveFont(Font.ITALIC));
|
---|
| 901 | }
|
---|
[1169] | 902 | }
|
---|
| 903 | return c;
|
---|
| 904 | }
|
---|
| 905 | });
|
---|
[1023] | 906 |
|
---|
[3302] | 907 | mod.getColumn(2).setCellRenderer(new DefaultTableCellRenderer() {
|
---|
| 908 | @Override public Component getTableCellRendererComponent(JTable table, Object value,
|
---|
| 909 | boolean isSelected, boolean hasFocus, int row, int column) {
|
---|
| 910 | Component c = super.getTableCellRendererComponent(table, value, isSelected, false, row, column);
|
---|
[3306] | 911 | boolean isDisabledAndHidden = (((Relation)table.getValueAt(row, 0))).isDisabledAndHidden();
|
---|
[3302] | 912 | if (c instanceof JLabel) {
|
---|
| 913 | JLabel label = (JLabel)c;
|
---|
[3306] | 914 | label.setText(((MemberInfo) table.getValueAt(row, 1)).getPositionString());
|
---|
| 915 | if (isDisabledAndHidden) {
|
---|
[3302] | 916 | label.setFont(label.getFont().deriveFont(Font.ITALIC));
|
---|
| 917 | }
|
---|
| 918 | }
|
---|
| 919 | return c;
|
---|
| 920 | }
|
---|
| 921 | });
|
---|
| 922 | mod.getColumn(2).setPreferredWidth(20);
|
---|
| 923 | mod.getColumn(1).setPreferredWidth(40);
|
---|
| 924 | mod.getColumn(0).setPreferredWidth(200);
|
---|
| 925 |
|
---|
[1169] | 926 | // combine both tables and wrap them in a scrollPane
|
---|
| 927 | JPanel bothTables = new JPanel();
|
---|
[2193] | 928 | boolean top = Main.pref.getBoolean("properties.presets.top", true);
|
---|
[1169] | 929 | bothTables.setLayout(new GridBagLayout());
|
---|
[2218] | 930 | if(top) {
|
---|
[3338] | 931 | bothTables.add(presets, GBC.std().fill(GBC.HORIZONTAL).insets(5, 2, 5, 2).anchor(GBC.NORTHWEST));
|
---|
| 932 | double epsilon = Double.MIN_VALUE; // need to set a weight or else anchor value is ignored
|
---|
| 933 | bothTables.add(pluginHook, GBC.eol().insets(0,1,1,1).anchor(GBC.NORTHEAST).weight(epsilon, epsilon));
|
---|
[2218] | 934 | }
|
---|
[1353] | 935 | bothTables.add(selectSth, GBC.eol().fill().insets(10, 10, 10, 10));
|
---|
[1169] | 936 | bothTables.add(propertyTable.getTableHeader(), GBC.eol().fill(GBC.HORIZONTAL));
|
---|
| 937 | bothTables.add(propertyTable, GBC.eol().fill(GBC.BOTH));
|
---|
| 938 | bothTables.add(membershipTable.getTableHeader(), GBC.eol().fill(GBC.HORIZONTAL));
|
---|
| 939 | bothTables.add(membershipTable, GBC.eol().fill(GBC.BOTH));
|
---|
[2218] | 940 | if(!top) {
|
---|
[2193] | 941 | bothTables.add(presets, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 2, 5, 2));
|
---|
[2218] | 942 | }
|
---|
[5020] | 943 |
|
---|
| 944 | // Open edit dialog whe enter pressed in tables
|
---|
| 945 | propertyTable.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
|
---|
| 946 | .put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),"onTableEnter");
|
---|
| 947 | propertyTable.getActionMap().put("onTableEnter",editAction);
|
---|
| 948 | membershipTable.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
|
---|
| 949 | .put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),"onTableEnter");
|
---|
| 950 | membershipTable.getActionMap().put("onTableEnter",editAction);
|
---|
| 951 |
|
---|
| 952 | // Open add property dialog when INS is pressed in tables
|
---|
| 953 | propertyTable.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
|
---|
| 954 | .put(KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, 0),"onTableInsert");
|
---|
| 955 | propertyTable.getActionMap().put("onTableInsert",addAction);
|
---|
[5032] | 956 |
|
---|
| 957 | // unassign some standard shortcuts for JTable to allow upload / download
|
---|
[5200] | 958 | InputMapUtils.unassignCtrlShiftUpDown(propertyTable, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
|
---|
[5032] | 959 |
|
---|
[2493] | 960 | // -- add action and shortcut
|
---|
[2473] | 961 | this.btnAdd = new SideButton(addAction);
|
---|
[5200] | 962 | InputMapUtils.enableEnter(this.btnAdd);
|
---|
[1102] | 963 |
|
---|
[2493] | 964 | // -- edit action
|
---|
| 965 | //
|
---|
[2489] | 966 | propertyTable.getSelectionModel().addListSelectionListener(editAction);
|
---|
[2490] | 967 | membershipTable.getSelectionModel().addListSelectionListener(editAction);
|
---|
[2473] | 968 | this.btnEdit = new SideButton(editAction);
|
---|
[1102] | 969 |
|
---|
[1945] | 970 | // -- delete action
|
---|
[2493] | 971 | //
|
---|
[1945] | 972 | this.btnDel = new SideButton(deleteAction);
|
---|
| 973 | membershipTable.getSelectionModel().addListSelectionListener(deleteAction);
|
---|
| 974 | propertyTable.getSelectionModel().addListSelectionListener(deleteAction);
|
---|
| 975 | getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(
|
---|
| 976 | KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0),"delete"
|
---|
[4604] | 977 | );
|
---|
[1945] | 978 | getActionMap().put("delete", deleteAction);
|
---|
[3525] | 979 |
|
---|
[4363] | 980 | JScrollPane scrollPane = (JScrollPane) createLayout(bothTables, true, Arrays.asList(new SideButton[] {
|
---|
[4604] | 981 | this.btnAdd, this.btnEdit, this.btnDel
|
---|
[4356] | 982 | }));
|
---|
| 983 |
|
---|
[4697] | 984 | MouseClickWatch mouseClickWatch = new MouseClickWatch();
|
---|
| 985 | propertyTable.addMouseListener(mouseClickWatch);
|
---|
| 986 | membershipTable.addMouseListener(mouseClickWatch);
|
---|
| 987 | scrollPane.addMouseListener(mouseClickWatch);
|
---|
[4363] | 988 |
|
---|
| 989 | selectSth.setPreferredSize(scrollPane.getSize());
|
---|
| 990 | presets.setSize(scrollPane.getSize());
|
---|
| 991 |
|
---|
[3525] | 992 | // -- help action
|
---|
| 993 | //
|
---|
| 994 | getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(
|
---|
| 995 | KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0), "onHelp");
|
---|
| 996 | getActionMap().put("onHelp", helpAction);
|
---|
[1169] | 997 | }
|
---|
[272] | 998 |
|
---|
[1169] | 999 | @Override public void setVisible(boolean b) {
|
---|
| 1000 | super.setVisible(b);
|
---|
[1814] | 1001 | if (b && Main.main.getCurrentDataSet() != null) {
|
---|
| 1002 | selectionChanged(Main.main.getCurrentDataSet().getSelected());
|
---|
[1763] | 1003 | }
|
---|
[1169] | 1004 | }
|
---|
[272] | 1005 |
|
---|
[3518] | 1006 | private int findRow(TableModel model, Object value) {
|
---|
| 1007 | for (int i=0; i<model.getRowCount(); i++) {
|
---|
| 1008 | if (model.getValueAt(i, 0).equals(value))
|
---|
| 1009 | return i;
|
---|
[1606] | 1010 | }
|
---|
[3518] | 1011 | return -1;
|
---|
| 1012 | }
|
---|
[1606] | 1013 |
|
---|
[3518] | 1014 | private PresetHandler presetHandler = new PresetHandler() {
|
---|
[1606] | 1015 |
|
---|
[3518] | 1016 | @Override
|
---|
| 1017 | public void updateTags(List<Tag> tags) {
|
---|
| 1018 | Command command = TaggingPreset.createCommand(getSelection(), tags);
|
---|
| 1019 | if (command != null) {
|
---|
| 1020 | Main.main.undoRedo.add(command);
|
---|
[1407] | 1021 | }
|
---|
| 1022 | }
|
---|
[1606] | 1023 |
|
---|
[3518] | 1024 | @Override
|
---|
| 1025 | public Collection<OsmPrimitive> getSelection() {
|
---|
| 1026 | if (Main.main == null) return null;
|
---|
| 1027 | if (Main.main.getCurrentDataSet() == null) return null;
|
---|
[1407] | 1028 |
|
---|
[3518] | 1029 | return Main.main.getCurrentDataSet().getSelected();
|
---|
[2742] | 1030 | }
|
---|
[3518] | 1031 | };
|
---|
[2742] | 1032 |
|
---|
[1169] | 1033 | public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
|
---|
| 1034 | if (!isVisible())
|
---|
| 1035 | return;
|
---|
| 1036 | if (propertyTable == null)
|
---|
| 1037 | return; // selection changed may be received in base class constructor before init
|
---|
[1763] | 1038 | if (propertyTable.getCellEditor() != null) {
|
---|
[1169] | 1039 | propertyTable.getCellEditor().cancelCellEditing();
|
---|
[1763] | 1040 | }
|
---|
[272] | 1041 |
|
---|
[2742] | 1042 | String selectedTag = null;
|
---|
| 1043 | Relation selectedRelation = null;
|
---|
| 1044 | if (propertyTable.getSelectedRowCount() == 1) {
|
---|
| 1045 | selectedTag = (String)propertyData.getValueAt(propertyTable.getSelectedRow(), 0);
|
---|
| 1046 | }
|
---|
| 1047 | if (membershipTable.getSelectedRowCount() == 1) {
|
---|
| 1048 | selectedRelation = (Relation)membershipData.getValueAt(membershipTable.getSelectedRow(), 0);
|
---|
| 1049 | }
|
---|
| 1050 |
|
---|
[1169] | 1051 | // re-load property data
|
---|
| 1052 | propertyData.setRowCount(0);
|
---|
[343] | 1053 |
|
---|
[5155] | 1054 | final Map<String, Integer> keyCount = new HashMap<String, Integer>();
|
---|
| 1055 | final Map<String, String> tags = new HashMap<String, String>();
|
---|
[1169] | 1056 | valueCount.clear();
|
---|
[5155] | 1057 | EnumSet<PresetType> types = EnumSet.noneOf(TaggingPreset.PresetType.class);
|
---|
[1169] | 1058 | for (OsmPrimitive osm : newSelection) {
|
---|
[5155] | 1059 | types.add(PresetType.forPrimitive(osm));
|
---|
| 1060 | for (String key : osm.keySet()) {
|
---|
[2906] | 1061 | String value = osm.get(key);
|
---|
| 1062 | keyCount.put(key, keyCount.containsKey(key) ? keyCount.get(key) + 1 : 1);
|
---|
| 1063 | if (valueCount.containsKey(key)) {
|
---|
| 1064 | Map<String, Integer> v = valueCount.get(key);
|
---|
[5155] | 1065 | v.put(value, v.containsKey(value) ? v.get(value) + 1 : 1);
|
---|
[1169] | 1066 | } else {
|
---|
[5155] | 1067 | TreeMap<String, Integer> v = new TreeMap<String, Integer>();
|
---|
[2906] | 1068 | v.put(value, 1);
|
---|
| 1069 | valueCount.put(key, v);
|
---|
[1169] | 1070 | }
|
---|
| 1071 | }
|
---|
| 1072 | }
|
---|
| 1073 | for (Entry<String, Map<String, Integer>> e : valueCount.entrySet()) {
|
---|
[5155] | 1074 | int count = 0;
|
---|
| 1075 | for (Entry<String, Integer> e1 : e.getValue().entrySet()) {
|
---|
| 1076 | count += e1.getValue();
|
---|
[1169] | 1077 | }
|
---|
| 1078 | if (count < newSelection.size()) {
|
---|
[5155] | 1079 | e.getValue().put("", newSelection.size() - count);
|
---|
[1169] | 1080 | }
|
---|
| 1081 | propertyData.addRow(new Object[]{e.getKey(), e.getValue()});
|
---|
[5155] | 1082 | tags.put(e.getKey(), e.getValue().size() == 1
|
---|
| 1083 | ? e.getValue().keySet().iterator().next() : tr("<different>"));
|
---|
[1169] | 1084 | }
|
---|
[1023] | 1085 |
|
---|
[1169] | 1086 | membershipData.setRowCount(0);
|
---|
[1023] | 1087 |
|
---|
[3302] | 1088 | Map<Relation, MemberInfo> roles = new HashMap<Relation, MemberInfo>();
|
---|
[3146] | 1089 | for (OsmPrimitive primitive: newSelection) {
|
---|
| 1090 | for (OsmPrimitive ref: primitive.getReferrers()) {
|
---|
[3219] | 1091 | if (ref instanceof Relation && !ref.isIncomplete() && !ref.isDeleted()) {
|
---|
[3146] | 1092 | Relation r = (Relation) ref;
|
---|
[3306] | 1093 | MemberInfo mi = roles.get(r);
|
---|
[3327] | 1094 | if(mi == null) {
|
---|
[3306] | 1095 | mi = new MemberInfo();
|
---|
[3327] | 1096 | }
|
---|
[3302] | 1097 | roles.put(r, mi);
|
---|
| 1098 | int i = 1;
|
---|
[1925] | 1099 | for (RelationMember m : r.getMembers()) {
|
---|
[3146] | 1100 | if (m.getMember() == primitive) {
|
---|
[3302] | 1101 | mi.add(m, i);
|
---|
[1169] | 1102 | }
|
---|
[3302] | 1103 | ++i;
|
---|
[1169] | 1104 | }
|
---|
| 1105 | }
|
---|
| 1106 | }
|
---|
| 1107 | }
|
---|
[3146] | 1108 |
|
---|
[3219] | 1109 | List<Relation> sortedRelations = new ArrayList<Relation>(roles.keySet());
|
---|
| 1110 | Collections.sort(sortedRelations, new Comparator<Relation>() {
|
---|
| 1111 | public int compare(Relation o1, Relation o2) {
|
---|
[3306] | 1112 | int comp = Boolean.valueOf(o1.isDisabledAndHidden()).compareTo(o2.isDisabledAndHidden());
|
---|
[3219] | 1113 | if (comp == 0) {
|
---|
| 1114 | comp = o1.getDisplayName(DefaultNameFormatter.getInstance()).compareTo(o2.getDisplayName(DefaultNameFormatter.getInstance()));
|
---|
| 1115 | }
|
---|
| 1116 | return comp;
|
---|
| 1117 | }}
|
---|
[4604] | 1118 | );
|
---|
[3219] | 1119 |
|
---|
| 1120 | for (Relation r: sortedRelations) {
|
---|
| 1121 | membershipData.addRow(new Object[]{r, roles.get(r)});
|
---|
[1169] | 1122 | }
|
---|
[1023] | 1123 |
|
---|
[5155] | 1124 | presets.updatePresets(types, tags, presetHandler);
|
---|
[1606] | 1125 |
|
---|
[1169] | 1126 | membershipTable.getTableHeader().setVisible(membershipData.getRowCount() > 0);
|
---|
[1353] | 1127 | membershipTable.setVisible(membershipData.getRowCount() > 0);
|
---|
[1228] | 1128 |
|
---|
[1446] | 1129 | boolean hasSelection = !newSelection.isEmpty();
|
---|
| 1130 | boolean hasTags = hasSelection && propertyData.getRowCount() > 0;
|
---|
| 1131 | boolean hasMemberships = hasSelection && membershipData.getRowCount() > 0;
|
---|
| 1132 | btnAdd.setEnabled(hasSelection);
|
---|
| 1133 | btnEdit.setEnabled(hasTags || hasMemberships);
|
---|
| 1134 | btnDel.setEnabled(hasTags || hasMemberships);
|
---|
[3281] | 1135 | propertyTable.setVisible(hasTags);
|
---|
| 1136 | propertyTable.getTableHeader().setVisible(hasTags);
|
---|
[1446] | 1137 | selectSth.setVisible(!hasSelection);
|
---|
[3338] | 1138 | pluginHook.setVisible(hasSelection);
|
---|
[2742] | 1139 |
|
---|
| 1140 | int selectedIndex;
|
---|
| 1141 | if (selectedTag != null && (selectedIndex = findRow(propertyData, selectedTag)) != -1) {
|
---|
| 1142 | propertyTable.changeSelection(selectedIndex, 0, false, false);
|
---|
| 1143 | } else if (selectedRelation != null && (selectedIndex = findRow(membershipData, selectedRelation)) != -1) {
|
---|
| 1144 | membershipTable.changeSelection(selectedIndex, 0, false, false);
|
---|
| 1145 | } else if(hasTags) {
|
---|
[1763] | 1146 | propertyTable.changeSelection(0, 0, false, false);
|
---|
| 1147 | } else if(hasMemberships) {
|
---|
| 1148 | membershipTable.changeSelection(0, 0, false, false);
|
---|
| 1149 | }
|
---|
[1446] | 1150 |
|
---|
[1228] | 1151 | if(propertyData.getRowCount() != 0 || membershipData.getRowCount() != 0) {
|
---|
[1353] | 1152 | setTitle(tr("Properties: {0} / Memberships: {1}",
|
---|
[2005] | 1153 | propertyData.getRowCount(), membershipData.getRowCount()));
|
---|
[1228] | 1154 | } else {
|
---|
[2005] | 1155 | setTitle(tr("Properties / Memberships"));
|
---|
[1228] | 1156 | }
|
---|
[1268] | 1157 | }
|
---|
[1814] | 1158 |
|
---|
[2658] | 1159 | private void updateSelection() {
|
---|
| 1160 | if (Main.main.getCurrentDataSet() == null) {
|
---|
| 1161 | selectionChanged(Collections.<OsmPrimitive>emptyList());
|
---|
[1970] | 1162 | } else {
|
---|
[2658] | 1163 | selectionChanged(Main.main.getCurrentDataSet().getSelected());
|
---|
[1814] | 1164 | }
|
---|
| 1165 | }
|
---|
| 1166 |
|
---|
[2658] | 1167 | /* ---------------------------------------------------------------------------------- */
|
---|
| 1168 | /* EditLayerChangeListener */
|
---|
| 1169 | /* ---------------------------------------------------------------------------------- */
|
---|
| 1170 | public void editLayerChanged(OsmDataLayer oldLayer, OsmDataLayer newLayer) {
|
---|
| 1171 | updateSelection();
|
---|
[1814] | 1172 | }
|
---|
| 1173 |
|
---|
[2741] | 1174 | public void processDatasetEvent(AbstractDatasetChangedEvent event) {
|
---|
| 1175 | updateSelection();
|
---|
| 1176 | }
|
---|
| 1177 |
|
---|
[4518] | 1178 | class DeleteAction extends JosmAction implements ListSelectionListener {
|
---|
[1945] | 1179 |
|
---|
[4518] | 1180 | public DeleteAction() {
|
---|
| 1181 | super(tr("Delete"), "dialogs/delete", tr("Delete the selected key in all objects"),
|
---|
| 1182 | Shortcut.registerShortcut("properties:delete", tr("Delete Properties"), KeyEvent.VK_D,
|
---|
[4982] | 1183 | Shortcut.ALT_CTRL_SHIFT), false);
|
---|
[4518] | 1184 | updateEnabledState();
|
---|
| 1185 | }
|
---|
| 1186 |
|
---|
[4773] | 1187 | protected void deleteProperties(int[] rows){
|
---|
| 1188 | // convert list of rows to HashMap (and find gap for nextKey)
|
---|
| 1189 | HashMap<String, String> tags = new HashMap<String, String>(rows.length);
|
---|
| 1190 | int nextKeyIndex = rows[0];
|
---|
| 1191 | for (int row : rows) {
|
---|
| 1192 | String key = propertyData.getValueAt(row, 0).toString();
|
---|
[4869] | 1193 | if (row == nextKeyIndex + 1) {
|
---|
[4773] | 1194 | nextKeyIndex = row; // no gap yet
|
---|
[4869] | 1195 | }
|
---|
[4773] | 1196 | tags.put(key, null);
|
---|
| 1197 | }
|
---|
[2742] | 1198 |
|
---|
[4773] | 1199 | // find key to select after deleting other properties
|
---|
[2742] | 1200 | String nextKey = null;
|
---|
| 1201 | int rowCount = propertyData.getRowCount();
|
---|
[4773] | 1202 | if (rowCount > rows.length) {
|
---|
[4869] | 1203 | if (nextKeyIndex == rows[rows.length-1]) {
|
---|
[4773] | 1204 | // no gap found, pick next or previous key in list
|
---|
| 1205 | nextKeyIndex = (nextKeyIndex + 1 < rowCount ? nextKeyIndex + 1 : rows[0] - 1);
|
---|
[4869] | 1206 | } else {
|
---|
[4773] | 1207 | // gap found
|
---|
| 1208 | nextKeyIndex++;
|
---|
[4869] | 1209 | }
|
---|
[4773] | 1210 | nextKey = (String)propertyData.getValueAt(nextKeyIndex, 0);
|
---|
[2742] | 1211 | }
|
---|
| 1212 |
|
---|
[1945] | 1213 | Collection<OsmPrimitive> sel = Main.main.getCurrentDataSet().getSelected();
|
---|
[4773] | 1214 | Main.main.undoRedo.add(new ChangePropertyCommand(sel, tags));
|
---|
[1945] | 1215 |
|
---|
[2742] | 1216 | membershipTable.clearSelection();
|
---|
| 1217 | if (nextKey != null) {
|
---|
| 1218 | propertyTable.changeSelection(findRow(propertyData, nextKey), 0, false, false);
|
---|
| 1219 | }
|
---|
[1945] | 1220 | }
|
---|
| 1221 |
|
---|
| 1222 | protected void deleteFromRelation(int row) {
|
---|
| 1223 | Relation cur = (Relation)membershipData.getValueAt(row, 0);
|
---|
[2032] | 1224 |
|
---|
[2742] | 1225 | Relation nextRelation = null;
|
---|
| 1226 | int rowCount = membershipTable.getRowCount();
|
---|
| 1227 | if (rowCount > 1) {
|
---|
| 1228 | nextRelation = (Relation)membershipData.getValueAt((row + 1 < rowCount ? row + 1 : row - 1), 0);
|
---|
| 1229 | }
|
---|
| 1230 |
|
---|
[2032] | 1231 | ExtendedDialog ed = new ExtendedDialog(Main.parent,
|
---|
[1945] | 1232 | tr("Change relation"),
|
---|
[2032] | 1233 | new String[] {tr("Delete from relation"), tr("Cancel")});
|
---|
| 1234 | ed.setButtonIcons(new String[] {"dialogs/delete.png", "cancel.png"});
|
---|
| 1235 | ed.setContent(tr("Really delete selection from relation {0}?", cur.getDisplayName(DefaultNameFormatter.getInstance())));
|
---|
[4107] | 1236 | ed.toggleEnable("delete_from_relation");
|
---|
[2032] | 1237 | ed.showDialog();
|
---|
[1945] | 1238 |
|
---|
[2032] | 1239 | if(ed.getValue() != 1)
|
---|
[1945] | 1240 | return;
|
---|
| 1241 |
|
---|
| 1242 | Relation rel = new Relation(cur);
|
---|
| 1243 | Collection<OsmPrimitive> sel = Main.main.getCurrentDataSet().getSelected();
|
---|
[2027] | 1244 | for (OsmPrimitive primitive: sel) {
|
---|
| 1245 | rel.removeMembersFor(primitive);
|
---|
[1945] | 1246 | }
|
---|
| 1247 | Main.main.undoRedo.add(new ChangeCommand(cur, rel));
|
---|
[2742] | 1248 |
|
---|
| 1249 | propertyTable.clearSelection();
|
---|
| 1250 | if (nextRelation != null) {
|
---|
| 1251 | membershipTable.changeSelection(findRow(membershipData, nextRelation), 0, false, false);
|
---|
| 1252 | }
|
---|
[1945] | 1253 | }
|
---|
| 1254 |
|
---|
[4518] | 1255 | @Override
|
---|
[1945] | 1256 | public void actionPerformed(ActionEvent e) {
|
---|
[4697] | 1257 | if (propertyTable.getSelectedRowCount() > 0) {
|
---|
| 1258 | int[] rows = propertyTable.getSelectedRows();
|
---|
[4773] | 1259 | deleteProperties(rows);
|
---|
[1945] | 1260 | } else if (membershipTable.getSelectedRowCount() > 0) {
|
---|
| 1261 | int row = membershipTable.getSelectedRow();
|
---|
| 1262 | deleteFromRelation(row);
|
---|
| 1263 | }
|
---|
| 1264 | }
|
---|
| 1265 |
|
---|
[4518] | 1266 | @Override
|
---|
[1945] | 1267 | protected void updateEnabledState() {
|
---|
| 1268 | setEnabled(
|
---|
[4697] | 1269 | (propertyTable != null && propertyTable.getSelectedRowCount() >= 1)
|
---|
| 1270 | || (membershipTable != null && membershipTable.getSelectedRowCount() == 1)
|
---|
[4604] | 1271 | );
|
---|
[1945] | 1272 | }
|
---|
| 1273 |
|
---|
[4518] | 1274 | @Override
|
---|
[1945] | 1275 | public void valueChanged(ListSelectionEvent e) {
|
---|
| 1276 | updateEnabledState();
|
---|
| 1277 | }
|
---|
| 1278 | }
|
---|
| 1279 |
|
---|
[4518] | 1280 | class AddAction extends JosmAction {
|
---|
[2473] | 1281 | public AddAction() {
|
---|
[4518] | 1282 | super(tr("Add"), "dialogs/add", tr("Add a new key/value pair to all objects"),
|
---|
| 1283 | Shortcut.registerShortcut("properties:add", tr("Add Property"), KeyEvent.VK_A,
|
---|
[4982] | 1284 | Shortcut.ALT), false);
|
---|
[2473] | 1285 | }
|
---|
| 1286 |
|
---|
[4518] | 1287 | @Override
|
---|
[2473] | 1288 | public void actionPerformed(ActionEvent e) {
|
---|
[5383] | 1289 | addProperty();
|
---|
[2473] | 1290 | }
|
---|
| 1291 | }
|
---|
| 1292 |
|
---|
[4518] | 1293 | class EditAction extends JosmAction implements ListSelectionListener {
|
---|
[2473] | 1294 | public EditAction() {
|
---|
[4518] | 1295 | super(tr("Edit"), "dialogs/edit", tr("Edit the value of the selected key for all objects"),
|
---|
| 1296 | Shortcut.registerShortcut("properties:edit", tr("Edit Properties"), KeyEvent.VK_S,
|
---|
[4982] | 1297 | Shortcut.ALT), false);
|
---|
[2473] | 1298 | updateEnabledState();
|
---|
| 1299 | }
|
---|
| 1300 |
|
---|
[4518] | 1301 | @Override
|
---|
[2473] | 1302 | public void actionPerformed(ActionEvent e) {
|
---|
| 1303 | if (!isEnabled())
|
---|
| 1304 | return;
|
---|
[2490] | 1305 | if (propertyTable.getSelectedRowCount() == 1) {
|
---|
| 1306 | int row = propertyTable.getSelectedRow();
|
---|
[5383] | 1307 | editProperty(row);
|
---|
[2490] | 1308 | } else if (membershipTable.getSelectedRowCount() == 1) {
|
---|
| 1309 | int row = membershipTable.getSelectedRow();
|
---|
[5383] | 1310 | editMembership(row);
|
---|
[2490] | 1311 | }
|
---|
[2473] | 1312 | }
|
---|
| 1313 |
|
---|
[4518] | 1314 | @Override
|
---|
[2473] | 1315 | protected void updateEnabledState() {
|
---|
[2490] | 1316 | setEnabled(
|
---|
[4526] | 1317 | (propertyTable != null && propertyTable.getSelectedRowCount() == 1)
|
---|
| 1318 | ^ (membershipTable != null && membershipTable.getSelectedRowCount() == 1)
|
---|
[4604] | 1319 | );
|
---|
[2473] | 1320 | }
|
---|
| 1321 |
|
---|
[4518] | 1322 | @Override
|
---|
[2473] | 1323 | public void valueChanged(ListSelectionEvent e) {
|
---|
| 1324 | updateEnabledState();
|
---|
| 1325 | }
|
---|
| 1326 | }
|
---|
[2723] | 1327 |
|
---|
[3529] | 1328 | class HelpAction extends AbstractAction {
|
---|
[3525] | 1329 | public HelpAction() {
|
---|
[3529] | 1330 | putValue(NAME, tr("Go to OSM wiki for tag help (F1)"));
|
---|
[3970] | 1331 | putValue(SHORT_DESCRIPTION, tr("Launch browser with wiki help for selected object"));
|
---|
[3529] | 1332 | putValue(SMALL_ICON, ImageProvider.get("dialogs", "search"));
|
---|
[3525] | 1333 | }
|
---|
| 1334 |
|
---|
| 1335 | public void actionPerformed(ActionEvent e) {
|
---|
| 1336 | try {
|
---|
[3592] | 1337 | String base = Main.pref.get("url.openstreetmap-wiki", "http://wiki.openstreetmap.org/wiki/");
|
---|
| 1338 | String lang = LanguageInfo.getWikiLanguagePrefix();
|
---|
| 1339 | final List<URI> uris = new ArrayList<URI>();
|
---|
[3525] | 1340 | int row;
|
---|
| 1341 | if (propertyTable.getSelectedRowCount() == 1) {
|
---|
| 1342 | row = propertyTable.getSelectedRow();
|
---|
[3529] | 1343 | String key = URLEncoder.encode(propertyData.getValueAt(row, 0).toString(), "UTF-8");
|
---|
| 1344 | String val = URLEncoder.encode(
|
---|
| 1345 | ((Map<String,Integer>)propertyData.getValueAt(row, 1))
|
---|
| 1346 | .entrySet().iterator().next().getKey(), "UTF-8"
|
---|
[4604] | 1347 | );
|
---|
[3525] | 1348 |
|
---|
[3592] | 1349 | uris.add(new URI(String.format("%s%sTag:%s=%s", base, lang, key, val)));
|
---|
[3525] | 1350 | uris.add(new URI(String.format("%sTag:%s=%s", base, key, val)));
|
---|
[3592] | 1351 | uris.add(new URI(String.format("%s%sKey:%s", base, lang, key)));
|
---|
[3525] | 1352 | uris.add(new URI(String.format("%sKey:%s", base, key)));
|
---|
[3592] | 1353 | uris.add(new URI(String.format("%s%sMap_Features", base, lang)));
|
---|
[3525] | 1354 | uris.add(new URI(String.format("%sMap_Features", base)));
|
---|
| 1355 | } else if (membershipTable.getSelectedRowCount() == 1) {
|
---|
| 1356 | row = membershipTable.getSelectedRow();
|
---|
[3529] | 1357 | String type = URLEncoder.encode(
|
---|
| 1358 | ((Relation)membershipData.getValueAt(row, 0)).get("type"), "UTF-8"
|
---|
[4604] | 1359 | );
|
---|
[3529] | 1360 |
|
---|
[3525] | 1361 | if (type != null && !type.equals("")) {
|
---|
[3592] | 1362 | uris.add(new URI(String.format("%s%sRelation:%s", base, lang, type)));
|
---|
[3525] | 1363 | uris.add(new URI(String.format("%sRelation:%s", base, type)));
|
---|
| 1364 | }
|
---|
[3529] | 1365 |
|
---|
[3592] | 1366 | uris.add(new URI(String.format("%s%sRelations", base, lang)));
|
---|
[3525] | 1367 | uris.add(new URI(String.format("%sRelations", base)));
|
---|
[3529] | 1368 | } else {
|
---|
| 1369 | // give the generic help page, if more than one element is selected
|
---|
[3592] | 1370 | uris.add(new URI(String.format("%s%sMap_Features", base, lang)));
|
---|
[3529] | 1371 | uris.add(new URI(String.format("%sMap_Features", base)));
|
---|
[3525] | 1372 | }
|
---|
| 1373 |
|
---|
[3592] | 1374 | Main.worker.execute(new Runnable(){
|
---|
| 1375 | public void run() {
|
---|
| 1376 | try {
|
---|
| 1377 | // find a page that actually exists in the wiki
|
---|
| 1378 | HttpURLConnection conn;
|
---|
| 1379 | for (URI u : uris) {
|
---|
| 1380 | conn = (HttpURLConnection) u.toURL().openConnection();
|
---|
[4172] | 1381 | conn.setConnectTimeout(Main.pref.getInteger("socket.timeout.connect",15)*1000);
|
---|
[3529] | 1382 |
|
---|
[3592] | 1383 | if (conn.getResponseCode() != 200) {
|
---|
| 1384 | System.out.println("INFO: " + u + " does not exist");
|
---|
| 1385 | conn.disconnect();
|
---|
| 1386 | } else {
|
---|
| 1387 | int osize = conn.getContentLength();
|
---|
| 1388 | conn.disconnect();
|
---|
[3529] | 1389 |
|
---|
[3592] | 1390 | conn = (HttpURLConnection) new URI(u.toString()
|
---|
| 1391 | .replace("=", "%3D") /* do not URLencode whole string! */
|
---|
| 1392 | .replaceFirst("/wiki/", "/w/index.php?redirect=no&title=")
|
---|
[4604] | 1393 | ).toURL().openConnection();
|
---|
[4172] | 1394 | conn.setConnectTimeout(Main.pref.getInteger("socket.timeout.connect",15)*1000);
|
---|
[3529] | 1395 |
|
---|
[3592] | 1396 | /* redirect pages have different content length, but retrieving a "nonredirect"
|
---|
| 1397 | * page using index.php and the direct-link method gives slightly different
|
---|
| 1398 | * content lengths, so we have to be fuzzy.. (this is UGLY, recode if u know better)
|
---|
| 1399 | */
|
---|
| 1400 | if (Math.abs(conn.getContentLength() - osize) > 200) {
|
---|
| 1401 | System.out.println("INFO: " + u + " is a mediawiki redirect");
|
---|
| 1402 | conn.disconnect();
|
---|
| 1403 | } else {
|
---|
| 1404 | System.out.println("INFO: browsing to " + u);
|
---|
| 1405 | conn.disconnect();
|
---|
[3529] | 1406 |
|
---|
[3592] | 1407 | OpenBrowser.displayUrl(u.toString());
|
---|
| 1408 | break;
|
---|
| 1409 | }
|
---|
| 1410 | }
|
---|
| 1411 | }
|
---|
| 1412 | } catch (Exception e) {
|
---|
| 1413 | e.printStackTrace();
|
---|
[3529] | 1414 | }
|
---|
[3525] | 1415 | }
|
---|
[3592] | 1416 | });
|
---|
[3525] | 1417 | } catch (Exception e1) {
|
---|
| 1418 | e1.printStackTrace();
|
---|
| 1419 | }
|
---|
| 1420 | }
|
---|
| 1421 | }
|
---|
| 1422 |
|
---|
[4484] | 1423 | public void addPropertyPopupMenuSeparator() {
|
---|
| 1424 | propertyMenu.addSeparator();
|
---|
| 1425 | }
|
---|
| 1426 |
|
---|
| 1427 | public JMenuItem addPropertyPopupMenuAction(Action a) {
|
---|
| 1428 | return propertyMenu.add(a);
|
---|
| 1429 | }
|
---|
[4604] | 1430 |
|
---|
[4536] | 1431 | public void addPropertyPopupMenuListener(PopupMenuListener l) {
|
---|
| 1432 | propertyMenu.addPopupMenuListener(l);
|
---|
| 1433 | }
|
---|
| 1434 |
|
---|
| 1435 | public void removePropertyPopupMenuListener(PopupMenuListener l) {
|
---|
| 1436 | propertyMenu.addPopupMenuListener(l);
|
---|
| 1437 | }
|
---|
[4604] | 1438 |
|
---|
[4536] | 1439 | @SuppressWarnings("unchecked")
|
---|
| 1440 | public Tag getSelectedProperty() {
|
---|
| 1441 | int row = propertyTable.getSelectedRow();
|
---|
| 1442 | if (row == -1) return null;
|
---|
| 1443 | TreeMap<String, Integer> map = (TreeMap<String, Integer>) propertyData.getValueAt(row, 1);
|
---|
| 1444 | return new Tag(
|
---|
[4604] | 1445 | propertyData.getValueAt(row, 0).toString(),
|
---|
[4536] | 1446 | map.size() > 1 ? "" : map.keySet().iterator().next());
|
---|
| 1447 | }
|
---|
[4604] | 1448 |
|
---|
[4484] | 1449 | public void addMembershipPopupMenuSeparator() {
|
---|
| 1450 | membershipMenu.addSeparator();
|
---|
| 1451 | }
|
---|
[4604] | 1452 |
|
---|
[4484] | 1453 | public JMenuItem addMembershipPopupMenuAction(Action a) {
|
---|
| 1454 | return membershipMenu.add(a);
|
---|
| 1455 | }
|
---|
[4604] | 1456 |
|
---|
[4536] | 1457 | public void addMembershipPopupMenuListener(PopupMenuListener l) {
|
---|
| 1458 | membershipMenu.addPopupMenuListener(l);
|
---|
| 1459 | }
|
---|
| 1460 |
|
---|
| 1461 | public void removeMembershipPopupMenuListener(PopupMenuListener l) {
|
---|
| 1462 | membershipMenu.addPopupMenuListener(l);
|
---|
| 1463 | }
|
---|
[4604] | 1464 |
|
---|
[4536] | 1465 | public IRelation getSelectedMembershipRelation() {
|
---|
| 1466 | int row = membershipTable.getSelectedRow();
|
---|
| 1467 | return row > -1 ? (IRelation) membershipData.getValueAt(row, 0) : null;
|
---|
| 1468 | }
|
---|
| 1469 |
|
---|
[4484] | 1470 | public static interface RelationRelated {
|
---|
| 1471 | public Relation getRelation();
|
---|
| 1472 | public void setRelation(Relation relation);
|
---|
| 1473 | }
|
---|
[4604] | 1474 |
|
---|
[4484] | 1475 | static abstract class AbstractRelationAction extends AbstractAction implements RelationRelated {
|
---|
| 1476 | protected Relation relation;
|
---|
| 1477 | public Relation getRelation() {
|
---|
| 1478 | return this.relation;
|
---|
| 1479 | }
|
---|
| 1480 | public void setRelation(Relation relation) {
|
---|
| 1481 | this.relation = relation;
|
---|
| 1482 | }
|
---|
| 1483 | }
|
---|
[4604] | 1484 |
|
---|
[4484] | 1485 | static class SelectRelationAction extends AbstractRelationAction {
|
---|
[2723] | 1486 | boolean selectionmode;
|
---|
[4484] | 1487 | public SelectRelationAction(boolean select) {
|
---|
[2723] | 1488 | selectionmode = select;
|
---|
| 1489 | if(select) {
|
---|
[2741] | 1490 | putValue(NAME, tr("Select relation"));
|
---|
| 1491 | putValue(SHORT_DESCRIPTION, tr("Select relation in main selection."));
|
---|
[3431] | 1492 | putValue(SMALL_ICON, ImageProvider.get("dialogs", "select"));
|
---|
[2723] | 1493 | } else {
|
---|
[2741] | 1494 | putValue(NAME, tr("Select in relation list"));
|
---|
| 1495 | putValue(SHORT_DESCRIPTION, tr("Select relation in relation list."));
|
---|
[3431] | 1496 | putValue(SMALL_ICON, ImageProvider.get("dialogs", "relationlist"));
|
---|
[2723] | 1497 | }
|
---|
| 1498 | }
|
---|
| 1499 |
|
---|
| 1500 | public void actionPerformed(ActionEvent e) {
|
---|
[2741] | 1501 | if(selectionmode) {
|
---|
[2723] | 1502 | Main.map.mapView.getEditLayer().data.setSelected(relation);
|
---|
[2741] | 1503 | } else {
|
---|
[2723] | 1504 | Main.map.relationListDialog.selectRelation(relation);
|
---|
[3743] | 1505 | Main.map.relationListDialog.unfurlDialog();
|
---|
[2741] | 1506 | }
|
---|
[2723] | 1507 | }
|
---|
| 1508 | }
|
---|
[4106] | 1509 |
|
---|
| 1510 |
|
---|
| 1511 | /**
|
---|
| 1512 | * Sets the current selection to the members of selected relation
|
---|
| 1513 | *
|
---|
| 1514 | */
|
---|
[4484] | 1515 | class SelectRelationMembersAction extends AbstractRelationAction {
|
---|
| 1516 | public SelectRelationMembersAction() {
|
---|
[4106] | 1517 | putValue(SHORT_DESCRIPTION,tr("Select the members of selected relation"));
|
---|
| 1518 | putValue(SMALL_ICON, ImageProvider.get("selectall"));
|
---|
| 1519 | putValue(NAME, tr("Select members"));
|
---|
| 1520 | }
|
---|
| 1521 |
|
---|
| 1522 | public void actionPerformed(ActionEvent e) {
|
---|
| 1523 | HashSet<OsmPrimitive> members = new HashSet<OsmPrimitive>();
|
---|
| 1524 | members.addAll(relation.getMemberPrimitives());
|
---|
| 1525 | Main.map.mapView.getEditLayer().data.setSelected(members);
|
---|
| 1526 | }
|
---|
| 1527 |
|
---|
| 1528 | }
|
---|
| 1529 |
|
---|
| 1530 | /**
|
---|
| 1531 | * Action for downloading incomplete members of selected relation
|
---|
| 1532 | *
|
---|
| 1533 | */
|
---|
[4484] | 1534 | class DownloadIncompleteMembersAction extends AbstractRelationAction {
|
---|
| 1535 | public DownloadIncompleteMembersAction() {
|
---|
[4106] | 1536 | putValue(SHORT_DESCRIPTION, tr("Download incomplete members of selected relations"));
|
---|
| 1537 | putValue(SMALL_ICON, ImageProvider.get("dialogs/relation", "downloadincompleteselected"));
|
---|
| 1538 | putValue(NAME, tr("Download incomplete members"));
|
---|
| 1539 | }
|
---|
| 1540 |
|
---|
| 1541 | public Set<OsmPrimitive> buildSetOfIncompleteMembers(Relation r) {
|
---|
| 1542 | Set<OsmPrimitive> ret = new HashSet<OsmPrimitive>();
|
---|
| 1543 | ret.addAll(r.getIncompleteMembers());
|
---|
| 1544 | return ret;
|
---|
| 1545 | }
|
---|
| 1546 |
|
---|
| 1547 | public void actionPerformed(ActionEvent e) {
|
---|
| 1548 | if (!relation.hasIncompleteMembers()) return;
|
---|
| 1549 | ArrayList<Relation> rels = new ArrayList<Relation>();
|
---|
| 1550 | rels.add(relation);
|
---|
| 1551 | Main.worker.submit(new DownloadRelationMemberTask(
|
---|
| 1552 | rels,
|
---|
| 1553 | buildSetOfIncompleteMembers(relation),
|
---|
| 1554 | Main.map.mapView.getEditLayer()
|
---|
[4604] | 1555 | ));
|
---|
[4106] | 1556 | }
|
---|
| 1557 | }
|
---|
[4454] | 1558 |
|
---|
| 1559 | abstract class AbstractCopyAction extends AbstractAction {
|
---|
| 1560 |
|
---|
| 1561 | protected abstract Collection<String> getString(OsmPrimitive p, String key);
|
---|
| 1562 |
|
---|
| 1563 | @Override
|
---|
| 1564 | public void actionPerformed(ActionEvent ae) {
|
---|
[4604] | 1565 | if (propertyTable.getSelectedRowCount() != 1)
|
---|
[4454] | 1566 | return;
|
---|
| 1567 | String key = propertyData.getValueAt(propertyTable.getSelectedRow(), 0).toString();
|
---|
| 1568 | Collection<OsmPrimitive> sel = Main.main.getCurrentDataSet().getSelected();
|
---|
[4604] | 1569 | if (sel.isEmpty())
|
---|
[4454] | 1570 | return;
|
---|
| 1571 | Set<String> values = new TreeSet<String>();
|
---|
| 1572 | for (OsmPrimitive p : sel) {
|
---|
| 1573 | Collection<String> s = getString(p,key);
|
---|
| 1574 | if (s != null) {
|
---|
| 1575 | values.addAll(s);
|
---|
| 1576 | }
|
---|
| 1577 | }
|
---|
| 1578 | Utils.copyToClipboard(Utils.join("\n", values));
|
---|
| 1579 | }
|
---|
| 1580 | }
|
---|
| 1581 |
|
---|
| 1582 | class CopyValueAction extends AbstractCopyAction {
|
---|
| 1583 |
|
---|
| 1584 | public CopyValueAction() {
|
---|
| 1585 | putValue(NAME, tr("Copy Value"));
|
---|
| 1586 | putValue(SHORT_DESCRIPTION, tr("Copy the value of the selected tag to clipboard"));
|
---|
| 1587 | }
|
---|
| 1588 |
|
---|
| 1589 | @Override
|
---|
| 1590 | protected Collection<String> getString(OsmPrimitive p, String key) {
|
---|
[5327] | 1591 | String v = p.get(key);
|
---|
| 1592 | return v == null ? null : Collections.singleton(v);
|
---|
[4454] | 1593 | }
|
---|
| 1594 | }
|
---|
| 1595 |
|
---|
| 1596 | class CopyKeyValueAction extends AbstractCopyAction {
|
---|
| 1597 |
|
---|
| 1598 | public CopyKeyValueAction() {
|
---|
| 1599 | putValue(NAME, tr("Copy Key/Value"));
|
---|
| 1600 | putValue(SHORT_DESCRIPTION, tr("Copy the key and value of the selected tag to clipboard"));
|
---|
| 1601 | }
|
---|
| 1602 |
|
---|
| 1603 | @Override
|
---|
| 1604 | protected Collection<String> getString(OsmPrimitive p, String key) {
|
---|
| 1605 | String v = p.get(key);
|
---|
| 1606 | return v == null ? null : Collections.singleton(new Tag(key, v).toString());
|
---|
| 1607 | }
|
---|
| 1608 | }
|
---|
| 1609 |
|
---|
| 1610 | class CopyAllKeyValueAction extends AbstractCopyAction {
|
---|
| 1611 |
|
---|
| 1612 | public CopyAllKeyValueAction() {
|
---|
| 1613 | putValue(NAME, tr("Copy all Keys/Values"));
|
---|
| 1614 | putValue(SHORT_DESCRIPTION, tr("Copy the key and value of the all tags to clipboard"));
|
---|
| 1615 | }
|
---|
| 1616 |
|
---|
| 1617 | @Override
|
---|
| 1618 | protected Collection<String> getString(OsmPrimitive p, String key) {
|
---|
| 1619 | List<String> r = new LinkedList<String>();
|
---|
| 1620 | for (Entry<String, String> kv : p.getKeys().entrySet()) {
|
---|
| 1621 | r.add(new Tag(kv.getKey(), kv.getValue()).toString());
|
---|
| 1622 | }
|
---|
| 1623 | return r;
|
---|
| 1624 | }
|
---|
| 1625 | }
|
---|
[4503] | 1626 |
|
---|
| 1627 | class SearchAction extends AbstractAction {
|
---|
| 1628 | final boolean sameType;
|
---|
| 1629 |
|
---|
| 1630 | public SearchAction(boolean sameType) {
|
---|
| 1631 | this.sameType = sameType;
|
---|
| 1632 | if (sameType) {
|
---|
| 1633 | putValue(NAME, tr("Search Key/Value/Type"));
|
---|
| 1634 | putValue(SHORT_DESCRIPTION, tr("Search with the key and value of the selected tag, restrict to type (i.e., node/way/relation)"));
|
---|
| 1635 | } else {
|
---|
| 1636 | putValue(NAME, tr("Search Key/Value"));
|
---|
| 1637 | putValue(SHORT_DESCRIPTION, tr("Search with the key and value of the selected tag"));
|
---|
| 1638 | }
|
---|
| 1639 | }
|
---|
| 1640 |
|
---|
| 1641 | public void actionPerformed(ActionEvent e) {
|
---|
[4604] | 1642 | if (propertyTable.getSelectedRowCount() != 1)
|
---|
[4503] | 1643 | return;
|
---|
| 1644 | String key = propertyData.getValueAt(propertyTable.getSelectedRow(), 0).toString();
|
---|
| 1645 | Collection<OsmPrimitive> sel = Main.main.getCurrentDataSet().getSelected();
|
---|
[4604] | 1646 | if (sel.isEmpty())
|
---|
[4503] | 1647 | return;
|
---|
| 1648 | String sep = "";
|
---|
| 1649 | String s = "";
|
---|
| 1650 | for (OsmPrimitive p : sel) {
|
---|
| 1651 | String val = p.get(key);
|
---|
| 1652 | if (val == null) {
|
---|
| 1653 | continue;
|
---|
| 1654 | }
|
---|
| 1655 | String t = "";
|
---|
| 1656 | if (!sameType) {
|
---|
| 1657 | t = "";
|
---|
| 1658 | } else if (p instanceof Node) {
|
---|
| 1659 | t = "type:node ";
|
---|
| 1660 | } else if (p instanceof Way) {
|
---|
| 1661 | t = "type:way ";
|
---|
| 1662 | } else if (p instanceof Relation) {
|
---|
| 1663 | t = "type:relation ";
|
---|
| 1664 | }
|
---|
| 1665 | s += sep + "(" + t + "\"" +
|
---|
| 1666 | org.openstreetmap.josm.actions.search.SearchAction.escapeStringForSearch(key) + "\"=\"" +
|
---|
| 1667 | org.openstreetmap.josm.actions.search.SearchAction.escapeStringForSearch(val) + "\")";
|
---|
| 1668 | sep = " OR ";
|
---|
| 1669 | }
|
---|
| 1670 |
|
---|
| 1671 | SearchSetting ss = new SearchSetting(s, SearchMode.replace, true, false, false);
|
---|
| 1672 | org.openstreetmap.josm.actions.search.SearchAction.searchWithoutHistory(ss);
|
---|
| 1673 | }
|
---|
| 1674 | }
|
---|
[272] | 1675 | }
|
---|