- Timestamp:
- 2018-03-13T00:28:24+01:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 6 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java
r13453 r13521 14 14 import java.awt.event.MouseAdapter; 15 15 import java.awt.event.MouseEvent; 16 import java.io.IOException;17 import java.net.URI;18 import java.net.URISyntaxException;19 16 import java.util.ArrayList; 20 17 import java.util.Arrays; … … 24 21 import java.util.HashMap; 25 22 import java.util.HashSet; 26 import java.util.LinkedList;27 23 import java.util.List; 28 24 import java.util.Map; … … 80 76 import org.openstreetmap.josm.data.osm.search.SearchCompiler; 81 77 import org.openstreetmap.josm.data.osm.search.SearchSetting; 82 import org.openstreetmap.josm.data.preferences.StringProperty;83 78 import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil; 84 79 import org.openstreetmap.josm.gui.ExtendedDialog; … … 105 100 import org.openstreetmap.josm.tools.AlphanumComparator; 106 101 import org.openstreetmap.josm.tools.GBC; 107 import org.openstreetmap.josm.tools.HttpClient;108 import org.openstreetmap.josm.tools.ImageProvider;109 102 import org.openstreetmap.josm.tools.InputMapUtils; 110 import org.openstreetmap.josm.tools.LanguageInfo;111 103 import org.openstreetmap.josm.tools.Logging; 112 import org.openstreetmap.josm.tools.OpenBrowser;113 104 import org.openstreetmap.josm.tools.Shortcut; 114 105 import org.openstreetmap.josm.tools.Utils; … … 182 173 183 174 private final transient DataSetListenerAdapter dataChangedAdapter = new DataSetListenerAdapter(this); 184 private final HelpAction helpAction = new HelpAction(); 185 private final TaginfoAction taginfoAction = new TaginfoAction(); 175 private final HelpAction helpAction = new HelpAction(tagTable, editHelper::getDataKey, editHelper::getDataValues, 176 membershipTable, x -> (Relation) membershipData.getValueAt(x, 0)); 177 private final TaginfoAction taginfoAction = new TaginfoAction(tagTable, editHelper::getDataKey, editHelper::getDataValues, 178 membershipTable, x -> (Relation) membershipData.getValueAt(x, 0)); 186 179 private final PasteValueAction pasteValueAction = new PasteValueAction(); 187 private final CopyValueAction copyValueAction = new CopyValueAction(); 188 private final CopyKeyValueAction copyKeyValueAction = new CopyKeyValueAction(); 189 private final CopyAllKeyValueAction copyAllKeyValueAction = new CopyAllKeyValueAction(); 180 private final CopyValueAction copyValueAction = new CopyValueAction( 181 tagTable, editHelper::getDataKey, Main.main::getInProgressSelection); 182 private final CopyKeyValueAction copyKeyValueAction = new CopyKeyValueAction( 183 tagTable, editHelper::getDataKey, Main.main::getInProgressSelection); 184 private final CopyAllKeyValueAction copyAllKeyValueAction = new CopyAllKeyValueAction( 185 tagTable, editHelper::getDataKey, Main.main::getInProgressSelection); 190 186 private final SearchAction searchActionSame = new SearchAction(true); 191 187 private final SearchAction searchActionAny = new SearchAction(false); … … 1128 1124 } 1129 1125 1130 class HelpAction extends AbstractAction {1131 HelpAction() {1132 putValue(NAME, tr("Go to OSM wiki for tag help"));1133 putValue(SHORT_DESCRIPTION, tr("Launch browser with wiki help for selected object"));1134 new ImageProvider("dialogs", "search").getResource().attachImageIcon(this, true);1135 putValue(ACCELERATOR_KEY, getKeyStroke());1136 }1137 1138 public KeyStroke getKeyStroke() {1139 return KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0);1140 }1141 1142 @Override1143 public void actionPerformed(ActionEvent e) {1144 try {1145 String base = Config.getPref().get("url.openstreetmap-wiki", "https://wiki.openstreetmap.org/wiki/");1146 String lang = LanguageInfo.getWikiLanguagePrefix();1147 final List<URI> uris = new ArrayList<>();1148 int row;1149 if (tagTable.getSelectedRowCount() == 1) {1150 row = tagTable.getSelectedRow();1151 String key = Utils.encodeUrl(editHelper.getDataKey(row));1152 Map<String, Integer> m = editHelper.getDataValues(row);1153 String val = Utils.encodeUrl(m.entrySet().iterator().next().getKey());1154 1155 uris.add(new URI(String.format("%s%sTag:%s=%s", base, lang, key, val)));1156 uris.add(new URI(String.format("%sTag:%s=%s", base, key, val)));1157 uris.add(new URI(String.format("%s%sKey:%s", base, lang, key)));1158 uris.add(new URI(String.format("%sKey:%s", base, key)));1159 uris.add(new URI(String.format("%s%sMap_Features", base, lang)));1160 uris.add(new URI(String.format("%sMap_Features", base)));1161 } else if (membershipTable.getSelectedRowCount() == 1) {1162 row = membershipTable.getSelectedRow();1163 String type = ((Relation) membershipData.getValueAt(row, 0)).get("type");1164 if (type != null) {1165 type = Utils.encodeUrl(type);1166 }1167 1168 if (type != null && !type.isEmpty()) {1169 uris.add(new URI(String.format("%s%sRelation:%s", base, lang, type)));1170 uris.add(new URI(String.format("%sRelation:%s", base, type)));1171 }1172 1173 uris.add(new URI(String.format("%s%sRelations", base, lang)));1174 uris.add(new URI(String.format("%sRelations", base)));1175 } else {1176 // give the generic help page, if more than one element is selected1177 uris.add(new URI(String.format("%s%sMap_Features", base, lang)));1178 uris.add(new URI(String.format("%sMap_Features", base)));1179 }1180 1181 MainApplication.worker.execute(() -> displayHelp(uris));1182 } catch (URISyntaxException e1) {1183 Logging.error(e1);1184 }1185 }1186 1187 private void displayHelp(final List<URI> uris) {1188 try {1189 // find a page that actually exists in the wiki1190 HttpClient.Response conn;1191 for (URI u : uris) {1192 conn = HttpClient.create(u.toURL(), "HEAD").connect();1193 1194 if (conn.getResponseCode() != 200) {1195 conn.disconnect();1196 } else {1197 long osize = conn.getContentLength();1198 if (osize > -1) {1199 conn.disconnect();1200 1201 final URI newURI = new URI(u.toString()1202 .replace("=", "%3D") /* do not URLencode whole string! */1203 .replaceFirst("/wiki/", "/w/index.php?redirect=no&title=")1204 );1205 conn = HttpClient.create(newURI.toURL(), "HEAD").connect();1206 }1207 1208 /* redirect pages have different content length, but retrieving a "nonredirect"1209 * page using index.php and the direct-link method gives slightly different1210 * content lengths, so we have to be fuzzy.. (this is UGLY, recode if u know better)1211 */1212 if (osize > -1 && conn.getContentLength() != -1 && Math.abs(conn.getContentLength() - osize) > 200) {1213 Logging.info("{0} is a mediawiki redirect", u);1214 conn.disconnect();1215 } else {1216 conn.disconnect();1217 1218 OpenBrowser.displayUrl(u.toString());1219 break;1220 }1221 }1222 }1223 } catch (URISyntaxException | IOException e1) {1224 Logging.error(e1);1225 }1226 }1227 }1228 1229 class TaginfoAction extends JosmAction {1230 1231 final transient StringProperty TAGINFO_URL_PROP = new StringProperty("taginfo.url", "https://taginfo.openstreetmap.org/");1232 1233 TaginfoAction() {1234 super(tr("Go to Taginfo"), "dialogs/taginfo", tr("Launch browser with Taginfo statistics for selected object"), null, false);1235 }1236 1237 @Override1238 public void actionPerformed(ActionEvent e) {1239 final String url;1240 if (tagTable.getSelectedRowCount() == 1) {1241 final int row = tagTable.getSelectedRow();1242 final String key = Utils.encodeUrl(editHelper.getDataKey(row)).replaceAll("\\+", "%20");1243 Map<String, Integer> values = editHelper.getDataValues(row);1244 if (values.size() == 1) {1245 url = TAGINFO_URL_PROP.get() + "tags/" + key1246 + '=' + Utils.encodeUrl(values.keySet().iterator().next()).replaceAll("\\+", "%20");1247 } else {1248 url = TAGINFO_URL_PROP.get() + "keys/" + key;1249 }1250 } else if (membershipTable.getSelectedRowCount() == 1) {1251 final String type = ((Relation) membershipData.getValueAt(membershipTable.getSelectedRow(), 0)).get("type");1252 url = TAGINFO_URL_PROP.get() + "relations/" + type;1253 } else {1254 return;1255 }1256 OpenBrowser.displayUrl(url);1257 }1258 }1259 1260 1126 class PasteValueAction extends AbstractAction { 1261 1127 PasteValueAction() { … … 1277 1143 } 1278 1144 1279 abstract class AbstractCopyAction extends AbstractAction {1280 1281 protected abstract Collection<String> getString(OsmPrimitive p, String key);1282 1283 @Override1284 public void actionPerformed(ActionEvent ae) {1285 int[] rows = tagTable.getSelectedRows();1286 Set<String> values = new TreeSet<>();1287 Collection<OsmPrimitive> sel = Main.main.getInProgressSelection();1288 if (rows.length == 0 || sel.isEmpty()) return;1289 1290 for (int row: rows) {1291 String key = editHelper.getDataKey(row);1292 if (sel.isEmpty())1293 return;1294 for (OsmPrimitive p : sel) {1295 Collection<String> s = getString(p, key);1296 if (s != null) {1297 values.addAll(s);1298 }1299 }1300 }1301 if (!values.isEmpty()) {1302 ClipboardUtils.copyString(Utils.join("\n", values));1303 }1304 }1305 }1306 1307 class CopyValueAction extends AbstractCopyAction {1308 1309 /**1310 * Constructs a new {@code CopyValueAction}.1311 */1312 CopyValueAction() {1313 putValue(NAME, tr("Copy Value"));1314 putValue(SHORT_DESCRIPTION, tr("Copy the value of the selected tag to clipboard"));1315 }1316 1317 @Override1318 protected Collection<String> getString(OsmPrimitive p, String key) {1319 String v = p.get(key);1320 return v == null ? null : Collections.singleton(v);1321 }1322 }1323 1324 class CopyKeyValueAction extends AbstractCopyAction {1325 1326 CopyKeyValueAction() {1327 putValue(NAME, tr("Copy selected Key(s)/Value(s)"));1328 putValue(SHORT_DESCRIPTION, tr("Copy the key and value of the selected tag(s) to clipboard"));1329 }1330 1331 @Override1332 protected Collection<String> getString(OsmPrimitive p, String key) {1333 String v = p.get(key);1334 return v == null ? null : Collections.singleton(new Tag(key, v).toString());1335 }1336 }1337 1338 class CopyAllKeyValueAction extends AbstractCopyAction {1339 1340 CopyAllKeyValueAction() {1341 putValue(NAME, tr("Copy all Keys/Values"));1342 putValue(SHORT_DESCRIPTION, tr("Copy the key and value of all the tags to clipboard"));1343 Shortcut sc = Shortcut.registerShortcut("system:copytags", tr("Edit: {0}", tr("Copy Tags")), KeyEvent.CHAR_UNDEFINED, Shortcut.NONE);1344 MainApplication.registerActionShortcut(this, sc);1345 sc.setAccelerator(this);1346 }1347 1348 @Override1349 protected Collection<String> getString(OsmPrimitive p, String key) {1350 List<String> r = new LinkedList<>();1351 for (Entry<String, String> kv : p.getKeys().entrySet()) {1352 r.add(new Tag(kv.getKey(), kv.getValue()).toString());1353 }1354 return r;1355 }1356 }1357 1358 1145 class SearchAction extends AbstractAction { 1359 1146 private final boolean sameType; -
trunk/src/org/openstreetmap/josm/gui/history/TagInfoViewer.java
r10637 r13521 4 4 import java.awt.event.FocusEvent; 5 5 import java.awt.event.FocusListener; 6 import java.util.Arrays; 7 import java.util.Collection; 8 import java.util.HashMap; 9 import java.util.Map; 10 import java.util.function.Function; 11 import java.util.function.Supplier; 6 12 13 import javax.swing.JPopupMenu; 7 14 import javax.swing.JTable; 8 15 import javax.swing.ListSelectionModel; 16 17 import org.openstreetmap.josm.data.osm.Tagged; 18 import org.openstreetmap.josm.data.osm.history.HistoryOsmPrimitive; 19 import org.openstreetmap.josm.gui.dialogs.properties.CopyAllKeyValueAction; 20 import org.openstreetmap.josm.gui.dialogs.properties.CopyKeyValueAction; 21 import org.openstreetmap.josm.gui.dialogs.properties.CopyValueAction; 22 import org.openstreetmap.josm.gui.dialogs.properties.HelpAction; 23 import org.openstreetmap.josm.gui.dialogs.properties.TaginfoAction; 24 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher; 9 25 10 26 /** … … 16 32 * <li>on the right, it displays the list of tags for the version at {@link PointInTimeType#CURRENT_POINT_IN_TIME}</li> 17 33 * </ul> 18 * 34 * @since 1709 19 35 */ 20 36 public class TagInfoViewer extends HistoryViewerPanel { … … 46 62 @Override 47 63 protected JTable buildReferenceTable() { 48 JTable table = new JTable( 49 model.getTagTableModel(PointInTimeType.REFERENCE_POINT_IN_TIME), 50 new TagTableColumnModel() 51 ); 52 table.setName("table.referencetagtable"); 53 setUpDataTransfer(table); 54 return table; 64 return buildTable(PointInTimeType.REFERENCE_POINT_IN_TIME, "table.referencetagtable", model::getReferencePointInTime); 55 65 } 56 66 57 67 @Override 58 68 protected JTable buildCurrentTable() { 59 JTable table = new JTable( 60 model.getTagTableModel(PointInTimeType.CURRENT_POINT_IN_TIME), 61 new TagTableColumnModel() 62 ); 63 table.setName("table.currenttagtable"); 64 setUpDataTransfer(table); 65 return table; 69 return buildTable(PointInTimeType.CURRENT_POINT_IN_TIME, "table.currenttagtable", model::getCurrentPointInTime); 66 70 } 67 71 68 private void setUpDataTransfer(JTable table) { 72 private JTable buildTable(PointInTimeType pointInTime, String name, Supplier<HistoryOsmPrimitive> histoSp) { 73 TagTableModel tagTableModel = model.getTagTableModel(pointInTime); 74 JTable table = new JTable(tagTableModel, new TagTableColumnModel()); 75 table.setName(name); 69 76 table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 70 77 selectionSynchronizer.participateInSynchronizedSelection(table.getSelectionModel()); 71 78 table.setTransferHandler(new TagInfoTransferHandler()); 72 79 table.addFocusListener(new RepaintOnFocusChange()); 80 JPopupMenu tagMenu = new JPopupMenu(); 81 82 Function<Integer, String> tagKeyFn = x -> (String) table.getValueAt(x, 0); 83 Function<Integer, Map<String, Integer>> tagValuesFn = x -> { 84 Map<String, Integer> map = new HashMap<>(); 85 String key = tagTableModel.getValue((String) table.getValueAt(x, 0)); 86 if (key != null) { 87 map.put(key, 1); 88 } 89 return map; 90 }; 91 Supplier<Collection<? extends Tagged>> objectSp = () -> Arrays.asList(histoSp.get()); 92 93 tagMenu.add(new CopyValueAction(table, tagKeyFn, objectSp)); 94 tagMenu.add(new CopyKeyValueAction(table, tagKeyFn, objectSp)); 95 tagMenu.add(new CopyAllKeyValueAction(table, tagKeyFn, objectSp)); 96 tagMenu.addSeparator(); 97 tagMenu.add(new HelpAction(table, tagKeyFn, tagValuesFn, null, null)); 98 tagMenu.add(new TaginfoAction(table, tagKeyFn, tagValuesFn, null, null)); 99 100 table.addMouseListener(new PopupMenuLauncher(tagMenu)); 101 return table; 73 102 } 74 103 }
Note:
See TracChangeset
for help on using the changeset viewer.