Changeset 31618 in osm for applications/editors/josm/plugins/OSMRecPlugin
- Timestamp:
- 2015-10-13T01:02:51+02:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/osmrec/OSMRecToggleDialog.java
r31615 r31618 12 12 import java.awt.event.MouseAdapter; 13 13 import java.awt.event.MouseEvent; 14 import java.io.UnsupportedEncodingException;15 14 import java.net.HttpURLConnection; 16 15 import java.net.URI; 17 16 import java.net.URISyntaxException; 18 import java.net.URLEncoder;19 17 import java.util.ArrayList; 20 18 import java.util.Arrays; … … 34 32 35 33 import javax.swing.AbstractAction; 36 import static javax.swing.Action.NAME;37 import static javax.swing.Action.SHORT_DESCRIPTION;38 import static javax.swing.Action.SMALL_ICON;39 34 import javax.swing.JComponent; 40 35 import javax.swing.JLabel; … … 126 121 * @author imi 127 122 */ 128 public class OSMRecToggleDialog extends ToggleDialog implements SelectionChangedListener, MapView.EditLayerChangeListener, DataSetListenerAdapter.Listener { 123 public class OSMRecToggleDialog extends ToggleDialog 124 implements SelectionChangedListener, MapView.EditLayerChangeListener, DataSetListenerAdapter.Listener { 129 125 130 126 /** … … 162 158 163 159 // Popup menu handlers 164 private final PopupMenuHandler tagMenuHandler = new PopupMenuHandler(tagMenu);165 private final PopupMenuHandler membershipMenuHandler = new PopupMenuHandler(membershipMenu);166 private final PopupMenuHandler blankSpaceMenuHandler = new PopupMenuHandler(blankSpaceMenu);167 168 private final Map<String, Map<String, Integer>> valueCount = new TreeMap<>();160 private final transient PopupMenuHandler tagMenuHandler = new PopupMenuHandler(tagMenu); 161 private final transient PopupMenuHandler membershipMenuHandler = new PopupMenuHandler(membershipMenu); 162 private final transient PopupMenuHandler blankSpaceMenuHandler = new PopupMenuHandler(blankSpaceMenu); 163 164 private final transient Map<String, Map<String, Integer>> valueCount = new TreeMap<>(); 169 165 /** 170 166 * This sub-object is responsible for all adding and editing of tags 171 167 */ 172 private final OSMRecPluginHelper editHelper = new OSMRecPluginHelper(tagData, valueCount);173 174 private final DataSetListenerAdapter dataChangedAdapter = new DataSetListenerAdapter(this);168 private final transient OSMRecPluginHelper editHelper = new OSMRecPluginHelper(tagData, valueCount); 169 170 private final transient DataSetListenerAdapter dataChangedAdapter = new DataSetListenerAdapter(this); 175 171 private final HelpAction helpAction = new HelpAction(); 176 172 private final PasteValueAction pasteValueAction = new PasteValueAction(); … … 191 187 192 188 private final DownloadMembersAction downloadMembersAction = new DownloadMembersAction(); 193 private final DownloadSelectedIncompleteMembersAction downloadSelectedIncompleteMembersAction = new DownloadSelectedIncompleteMembersAction(); 189 private final DownloadSelectedIncompleteMembersAction downloadSelectedIncompleteMembersAction = 190 new DownloadSelectedIncompleteMembersAction(); 194 191 195 192 private final SelectMembersAction selectMembersAction = new SelectMembersAction(false); 196 193 private final SelectMembersAction addMembersToSelectionAction = new SelectMembersAction(true); 197 194 198 private final HighlightHelper highlightHelper= new HighlightHelper();195 private final transient HighlightHelper highlightHelper= new HighlightHelper(); 199 196 200 197 /** … … 221 218 + tr("Select objects or create new objects and get recommendation.") + "</p></html>"); 222 219 223 private final TaggingPresetHandler presetHandler = new TaggingPresetHandler() {220 private final transient TaggingPresetHandler presetHandler = new TaggingPresetHandler() { 224 221 @Override public void updateTags(List<Tag> tags) { 225 222 Command command = TaggingPreset.createCommand(getSelection(), tags); … … 337 334 return this; 338 335 Component c = super.getTableCellRendererComponent(table, value, isSelected, false, row, column); 339 boolean isDisabledAndHidden = (( (Relation)table.getValueAt(row, 0))).isDisabledAndHidden();336 boolean isDisabledAndHidden = ((Relation) table.getValueAt(row, 0)).isDisabledAndHidden(); 340 337 if (c instanceof JLabel) { 341 338 JLabel label = (JLabel) c; … … 353 350 boolean isSelected, boolean hasFocus, int row, int column) { 354 351 Component c = super.getTableCellRendererComponent(table, value, isSelected, false, row, column); 355 boolean isDisabledAndHidden = (( (Relation)table.getValueAt(row, 0))).isDisabledAndHidden();352 boolean isDisabledAndHidden = ((Relation) table.getValueAt(row, 0)).isDisabledAndHidden(); 356 353 if (c instanceof JLabel) { 357 354 JLabel label = (JLabel)c; … … 513 510 * is the editor's business. 514 511 * 515 * @param row 512 * @param row position 516 513 */ 517 514 private void editMembership(int row) { … … 620 617 final Map<String, String> tags = new HashMap<>(); 621 618 valueCount.clear(); 622 EnumSet<TaggingPresetType> types = EnumSet.noneOf(TaggingPresetType.class);619 Set<TaggingPresetType> types = EnumSet.noneOf(TaggingPresetType.class); 623 620 for (OsmPrimitive osm : newSel) { 624 621 types.add(TaggingPresetType.forPrimitive(osm)); … … 631 628 v.put(value, v.containsKey(value) ? v.get(value) + 1 : 1); 632 629 } else { 633 TreeMap<String, Integer> v = new TreeMap<>();630 Map<String, Integer> v = new TreeMap<>(); 634 631 v.put(value, 1); 635 632 valueCount.put(key, v); … … 722 719 //end of temp code 723 720 724 725 721 int selectedIndex; 726 722 if (selectedTag != null && (selectedIndex = findRow(tagData, selectedTag)) != -1) { … … 781 777 int row = tagTable.getSelectedRow(); 782 778 if (row == -1) return null; 783 TreeMap<String, Integer> map = (TreeMap<String, Integer>) tagData.getValueAt(row, 1);779 Map<String, Integer> map = (TreeMap<String, Integer>) tagData.getValueAt(row, 1); 784 780 return new Tag( 785 781 tagData.getValueAt(row, 0).toString(), … … 811 807 */ 812 808 public class MouseClickWatch extends MouseAdapter { 813 @Override public void mouseClicked(MouseEvent e) { 809 @Override 810 public void mouseClicked(MouseEvent e) { 814 811 if (e.getClickCount() < 2) { 815 812 // single click, clear selection in other table not clicked in … … 819 816 tagTable.clearSelection(); 820 817 } 821 } 822 // double click, edit or add tag 823 else if (e.getSource() == tagTable ) { 818 } else if (e.getSource() == tagTable ) { 819 // double click, edit or add tag 824 820 int row = tagTable.rowAtPoint(e.getPoint()); 825 821 if (row > -1) { 826 boolean focusOnKey = (tagTable.columnAtPoint(e.getPoint()) == 0);822 boolean focusOnKey = tagTable.columnAtPoint(e.getPoint()) == 0; 827 823 editHelper.editTag(row, focusOnKey); 828 824 } else { … … 835 831 editMembership(row); 836 832 } 837 } 838 else { 833 } else { 839 834 editHelper.addTag(); 840 835 btnAdd.requestFocusInWindow(); 841 836 } 842 837 } 843 @Override public void mousePressed(MouseEvent e) { 838 839 @Override 840 public void mousePressed(MouseEvent e) { 844 841 if (e.getSource() == tagTable) { 845 842 membershipTable.clearSelection(); … … 855 852 private List<Integer> position = new ArrayList<>(); 856 853 private Iterable<OsmPrimitive> selection; 857 private String positionString = null;858 private String roleString = null;854 private String positionString; 855 private String roleString; 859 856 860 857 MemberInfo(Iterable<OsmPrimitive> selection) { … … 909 906 */ 910 907 public static class ReadOnlyTableModel extends DefaultTableModel { 911 @Override public boolean isCellEditable(int row, int column) { 908 @Override 909 public boolean isCellEditable(int row, int column) { 912 910 return false; 913 911 } 914 @Override public Class<?> getColumnClass(int columnIndex) { 912 @Override 913 public Class<?> getColumnClass(int columnIndex) { 915 914 return String.class; 916 915 } … … 922 921 class DeleteAction extends JosmAction implements ListSelectionListener { 923 922 924 static final String DELETE_FROM_RELATION_PREF = "delete_from_relation";925 926 publicDeleteAction() {923 private static final String DELETE_FROM_RELATION_PREF = "delete_from_relation"; 924 925 DeleteAction() { 927 926 super(tr("Delete"), /* ICON() */ "dialogs/delete", tr("Delete the selected key in all objects"), 928 927 Shortcut.registerShortcut("properties:delete", tr("Delete Tags"), KeyEvent.VK_D, … … 933 932 protected void deleteTags(int[] rows){ 934 933 // convert list of rows to HashMap (and find gap for nextKey) 935 HashMap<String, String> tags = new HashMap<>(rows.length);934 Map<String, String> tags = new HashMap<>(rows.length); 936 935 int nextKeyIndex = rows[0]; 937 936 for (int row : rows) { … … 972 971 int rowCount = membershipTable.getRowCount(); 973 972 if (rowCount > 1) { 974 nextRelation = (Relation) membershipData.getValueAt((row + 1 < rowCount ? row + 1 : row - 1), 0);973 nextRelation = (Relation) membershipData.getValueAt(row + 1 < rowCount ? row + 1 : row - 1, 0); 975 974 } 976 975 … … 978 977 tr("Change relation"), 979 978 new String[] {tr("Delete from relation"), tr("Cancel")}); 980 ed.setButtonIcons(new String[] {"dialogs/delete .png", "cancel.png"});979 ed.setButtonIcons(new String[] {"dialogs/delete", "cancel"}); 981 980 ed.setContent(tr("Really delete selection from relation {0}?", cur.getDisplayName(DefaultNameFormatter.getInstance()))); 982 981 ed.toggleEnable(DELETE_FROM_RELATION_PREF); … … 1032 1031 */ 1033 1032 class AddAction extends JosmAction { 1034 publicAddAction() {1033 AddAction() { 1035 1034 super(tr("Add Recommendation"), /* ICON() */ "dialogs/add", tr("Add a recommended key/value pair to your object"), 1036 1035 Shortcut.registerShortcut("properties:add", tr("Add Tag"), KeyEvent.VK_A, … … 1040 1039 @Override 1041 1040 public void actionPerformed(ActionEvent e) { 1042 //System.out.println("clicked recommend");1043 1041 editHelper.addTag(); 1044 1042 btnAdd.requestFocusInWindow(); … … 1051 1049 */ 1052 1050 class EditActionTrain extends JosmAction implements ListSelectionListener { 1053 public EditActionTrain() { 1054 // super(tr("Train a Model"), /* ICON() */ "dialogs/edit", tr("Start the training engine!"), 1055 // Shortcut.registerShortcut("properties:edit", tr("Edit Tags"), KeyEvent.VK_S, 1056 // Shortcut.ALT), false); 1057 1051 EditActionTrain() { 1058 1052 super(tr("Train a Model"), /* ICON() */ "dialogs/fix", tr("Start the training engine!"), 1059 1053 Shortcut.registerShortcut("properties:edit", tr("Edit Tags"), KeyEvent.VK_S, 1060 1054 Shortcut.ALT), false); 1061 1062 //images/dialogs/train.png1063 //System.out.println("icon");1064 1055 setEnabled(true); 1065 1056 updateEnabledState(); … … 1075 1066 } else if (membershipTable.getSelectedRowCount() == 1) { 1076 1067 int row = membershipTable.getSelectedRow(); 1077 //System.out.println("tagTable: " + tagTable);1078 //System.out.println("membershipTable: " + membershipTable);1079 1068 editHelper.editTag(row, false); 1080 1069 //editMembership(row); … … 1101 1090 1102 1091 class HelpAction extends AbstractAction { 1103 publicHelpAction() {1092 HelpAction() { 1104 1093 putValue(NAME, tr("Go to OSM wiki for tag help (F1)")); 1105 1094 putValue(SHORT_DESCRIPTION, tr("Launch browser with wiki help for selected object")); … … 1116 1105 if (tagTable.getSelectedRowCount() == 1) { 1117 1106 row = tagTable.getSelectedRow(); 1118 String key = U RLEncoder.encode(tagData.getValueAt(row, 0).toString(), "UTF-8");1107 String key = Utils.encodeUrl(tagData.getValueAt(row, 0).toString()); 1119 1108 @SuppressWarnings("unchecked") 1120 1109 Map<String, Integer> m = (Map<String, Integer>) tagData.getValueAt(row, 1); 1121 String val = U RLEncoder.encode(m.entrySet().iterator().next().getKey(), "UTF-8");1110 String val = Utils.encodeUrl(m.entrySet().iterator().next().getKey()); 1122 1111 1123 1112 uris.add(new URI(String.format("%s%sTag:%s=%s", base, lang, key, val))); … … 1131 1120 String type = ((Relation)membershipData.getValueAt(row, 0)).get("type"); 1132 1121 if (type != null) { 1133 type = U RLEncoder.encode(type, "UTF-8");1122 type = Utils.encodeUrl(type); 1134 1123 } 1135 1124 … … 1192 1181 } 1193 1182 }); 1194 } catch (URISyntaxException | UnsupportedEncodingExceptione1) {1183 } catch (URISyntaxException e1) { 1195 1184 Main.error(e1); 1196 1185 } … … 1199 1188 1200 1189 class PasteValueAction extends AbstractAction { 1201 publicPasteValueAction() {1190 PasteValueAction() { 1202 1191 putValue(NAME, tr("Paste Value")); 1203 1192 putValue(SHORT_DESCRIPTION, tr("Paste the value of the selected tag from clipboard")); … … 1247 1236 class CopyValueAction extends AbstractCopyAction { 1248 1237 1249 public CopyValueAction() { 1238 /** 1239 * Constructs a new {@code CopyValueAction}. 1240 */ 1241 CopyValueAction() { 1250 1242 putValue(NAME, tr("Copy Value")); 1251 1243 putValue(SHORT_DESCRIPTION, tr("Copy the value of the selected tag to clipboard")); … … 1261 1253 class CopyKeyValueAction extends AbstractCopyAction { 1262 1254 1263 publicCopyKeyValueAction() {1255 CopyKeyValueAction() { 1264 1256 putValue(NAME, tr("Copy selected Key(s)/Value(s)")); 1265 1257 putValue(SHORT_DESCRIPTION, tr("Copy the key and value of the selected tag(s) to clipboard")); … … 1275 1267 class CopyAllKeyValueAction extends AbstractCopyAction { 1276 1268 1277 publicCopyAllKeyValueAction() {1269 CopyAllKeyValueAction() { 1278 1270 putValue(NAME, tr("Copy all Keys/Values")); 1279 1271 putValue(SHORT_DESCRIPTION, tr("Copy the key and value of all the tags to clipboard")); … … 1291 1283 1292 1284 class SearchAction extends AbstractAction { 1293 final boolean sameType;1294 1295 publicSearchAction(boolean sameType) {1285 private final boolean sameType; 1286 1287 SearchAction(boolean sameType) { 1296 1288 this.sameType = sameType; 1297 1289 if (sameType) { … … 1329 1321 t = "type:relation "; 1330 1322 } 1331 s.append(sep).append( "(").append(t).append("\"").append(1323 s.append(sep).append('(').append(t).append('"').append( 1332 1324 org.openstreetmap.josm.actions.search.SearchAction.escapeStringForSearch(key)).append("\"=\"").append( 1333 1325 org.openstreetmap.josm.actions.search.SearchAction.escapeStringForSearch(val)).append("\")"); … … 1335 1327 } 1336 1328 1337 SearchSetting ss = new SearchSetting();1329 final SearchSetting ss = new SearchSetting(); 1338 1330 ss.text = s.toString(); 1339 1331 ss.mode = SearchMode.replace;
Note:
See TracChangeset
for help on using the changeset viewer.