Changeset 26603 in osm for applications/editors/josm
- Timestamp:
- 2011-09-02T19:06:16+02:00 (13 years ago)
- Location:
- applications/editors/josm/plugins/utilsplugin2
- Files:
-
- 4 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/utilsplugin2/build.xml
r26395 r26603 30 30 <project name="utilsplugin2" default="dist" basedir="."> 31 31 <!-- enter the SVN commit message --> 32 <property name="commit.message" value="Utilsplugin2: Symmetry tool Alt-Shift-S"/>32 <property name="commit.message" value="Utilsplugin2: Open custom URL in browser by Shift-\"/> 33 33 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 34 <property name="plugin.main.version" value="4 201"/>34 <property name="plugin.main.version" value="4935"/> 35 35 <!-- 36 36 ************************************************ … … 242 242 <target name="runjosm" depends="install"> 243 243 <java jar="${josm}" fork="true"> 244 <arg line=" ../../core/data_nodist/neubrandenburg.osm"/>244 <arg line="e:/test.osm"/> 245 245 </java> 246 246 </target> -
applications/editors/josm/plugins/utilsplugin2/nbproject/project.xml
r26393 r26603 37 37 <target>dist</target> 38 38 </action> 39 <action name="debug"> 40 <script>nbproject/ide-targets.xml</script> 41 <target>debug-nb</target> 42 </action> 39 43 </ide-actions> 40 44 <export> … … 58 62 <ide-action name="clean"/> 59 63 <ide-action name="run"/> 64 <ide-action name="debug"/> 60 65 </context-menu> 61 66 </view> -
applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/OpenPageAction.java
r26543 r26603 2 2 package utilsplugin2; 3 3 4 import java.awt.GridBagLayout; 5 import java.io.UnsupportedEncodingException; 4 6 import static org.openstreetmap.josm.tools.I18n.tr; 5 7 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; … … 7 9 import java.awt.event.ActionEvent; 8 10 import java.awt.event.KeyEvent; 11 import java.net.URLEncoder; 12 import java.util.ArrayList; 9 13 import java.util.Collection; 10 import java.util.HashSet;11 import java.util.LinkedList;12 14 15 import java.util.regex.Matcher; 16 17 import java.util.regex.Pattern; 18 import javax.swing.BorderFactory; 13 19 import javax.swing.JOptionPane; 14 20 21 import javax.swing.JPanel; 22 import javax.swing.border.EtchedBorder; 15 23 import org.openstreetmap.josm.Main; 16 24 import org.openstreetmap.josm.actions.JosmAction; 17 import org.openstreetmap.josm.command.Command;18 import org.openstreetmap.josm.command.MoveCommand;19 import org.openstreetmap.josm.command.SequenceCommand;20 import org.openstreetmap.josm.data.coor.EastNorth;21 import org.openstreetmap.josm.data.osm.Node;22 25 import org.openstreetmap.josm.data.osm.OsmPrimitive; 23 import org.openstreetmap.josm.data.osm.Way; 26 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 27 import org.openstreetmap.josm.gui.ExtendedDialog; 28 import org.openstreetmap.josm.gui.widgets.HistoryComboBox; 29 import org.openstreetmap.josm.gui.widgets.HtmlPanel; 30 import org.openstreetmap.josm.tools.GBC; 31 import org.openstreetmap.josm.tools.OpenBrowser; 24 32 import org.openstreetmap.josm.tools.Shortcut; 25 33 … … 31 39 * @author Alexei Kasatkin, based on much copy&Paste from other MirrorAction :) 32 40 */ 33 public final class SymmetryAction extends JosmAction { 41 public final class OpenPageAction extends JosmAction { 42 private final String defaultURL = "http://ru.wikipedia.org/w/index.php?search={name}&fulltext=Search"; 34 43 35 public SymmetryAction() {36 super(tr(" Symmetry"), "symmetry", tr("Mirror selected nodes and ways."),37 Shortcut.registerShortcut("tools: symmetry", tr("Tool: {0}", tr("Symmetry")),38 KeyEvent.VK_ S, Shortcut.GROUP_EDIT, KeyEvent.SHIFT_DOWN_MASK|KeyEvent.ALT_DOWN_MASK), true);39 putValue("help", ht("/Action/ Symmtry"));44 public OpenPageAction() { 45 super(tr("Open custom URL"), "openurl", tr("Opens specified URL browser"), 46 Shortcut.registerShortcut("tools:openaddress", tr("Tool: {0}", tr("Open custom URL")), 47 KeyEvent.VK_BACK_SLASH, Shortcut.GROUP_EDIT, Shortcut.SHIFT_DEFAULT), true); 48 putValue("help", ht("/Action/OpenPage")); 40 49 } 41 50 42 51 public void actionPerformed(ActionEvent e) { 43 52 Collection<OsmPrimitive> sel = getCurrentDataSet().getSelected(); 44 HashSet<Node> nodes = new HashSet<Node>(); 45 EastNorth p1=null,p2=null; 46 47 for (OsmPrimitive osm : sel) { 48 if (osm instanceof Node) { 49 if (p1==null) p1=((Node)osm).getEastNorth(); else 50 if (p2==null) p2=((Node)osm).getEastNorth(); else 51 nodes.add((Node)osm); 52 } 53 } 54 for (OsmPrimitive osm : sel) { 55 if (osm instanceof Way) { 56 nodes.addAll(((Way)osm).getNodes()); 57 } 53 OsmPrimitive p=null; 54 if (sel.size()==1) { 55 p=sel.iterator().next(); 56 } else { 57 showConfigDialog(); 58 return; 58 59 } 59 60 60 if (p1==null || p2==null || nodes.size() < 1) { 61 JOptionPane.showMessageDialog( 62 Main.parent, 63 tr("Please select at least two nodes for symmetry axis and something else to mirror."), 64 tr("Information"), 65 JOptionPane.INFORMATION_MESSAGE 66 ); 61 String addr = Main.pref.get("utilsplugin2.customurl", defaultURL); 62 Pattern pat = Pattern.compile("\\{([^\\}]*)\\}"); 63 Matcher m = pat.matcher(addr); 64 String val,key; 65 String keys[]=new String[100],vals[]=new String[100]; 66 int i=0; 67 try { 68 while (m.find()) { 69 System.out.println(m.group()); 70 key=m.group(1); 71 if (key.equals("#id")) { 72 val=Long.toString(p.getId()); 73 } else if (key.equals("#type")) { 74 val = OsmPrimitiveType.from(p).getAPIName(); 75 } else if (key.equals("#lat")) { 76 val = Double.toString(p.getBBox().getTopLeft().lat()); 77 } else if (key.equals("#lon")) { 78 val = Double.toString(p.getBBox().getTopLeft().lon()); 79 } 80 else { 81 val =p.get(key); 82 if (val!=null) val =URLEncoder.encode(p.get(key), "UTF-8"); else return; 83 } 84 keys[i]=m.group(); 85 if (val!=null) vals[i]=val; 86 else vals[i]=""; 87 i++; 88 } 89 } catch (UnsupportedEncodingException ex) { 90 System.err.println("Encoding error"); 67 91 return; 68 92 } 93 System.out.println(i); 94 for (int j=0;j<i;j++){ 95 addr = addr.replace(keys[j],vals[j]); 96 } 97 System.out.println(addr); 98 try { 99 OpenBrowser.displayUrl(addr); 100 } catch (Exception ex) { 101 System.err.println("Can not open URL"+addr); 102 } 103 //Collection<Command> cmds = new LinkedList<Command>(); 69 104 70 double ne,nn,l,e0,n0; 71 e0=p1.east(); n0=p1.north(); 72 ne = -(p2.north()-p1.north()); nn = (p2.east()-p1.east()); 73 l = Math.hypot(ne,nn); 74 ne /= l; nn /= l; // normal unit vector 75 76 Collection<Command> cmds = new LinkedList<Command>(); 77 78 for (Node n : nodes) { 79 EastNorth c = n.getEastNorth(); 80 double pr = (c.east()-e0)*ne + (c.north()-n0)*nn; 81 //pr=10; 82 cmds.add(new MoveCommand(n, -2*ne*pr, -2*nn*pr )); 83 } 84 85 Main.main.undoRedo.add(new SequenceCommand(tr("Symmetry"), cmds)); 86 Main.map.repaint(); 105 // cmds.add(new MoveCommand(n, -2*ne*pr, -2*nn*pr )); 106 //Main.main.undoRedo.add(new SequenceCommand(tr("Symmetry"), cmds)); 87 107 } 88 108 … … 98 118 @Override 99 119 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 100 setEnabled(selection != null && !selection.isEmpty()); 120 setEnabled(selection != null ); 121 } 122 123 private void showConfigDialog() { 124 JPanel all = new JPanel(); 125 GridBagLayout layout = new GridBagLayout(); 126 all.setLayout(layout); 127 128 HistoryComboBox combo1=new HistoryComboBox(); 129 130 // FIXME: get rid of hardcoded URLS 131 ArrayList<String> items=new ArrayList<String>(); 132 items.add(defaultURL); 133 items.add("http://latlon.org/buildings?zoom=17&lat={#lat}&lon={#lon}&layers=B"); 134 items.add("http://addresses.amdmi3.ru/?zoom=11&lat={#lat}&lon={#lon}&layers=B00"); 135 items.add("http://www.openstreetmap.org/browse/{#type}/{#id}/history"); 136 items.add("http://www.openstreetmap.org/browse/{#type}/{#id}"); 137 String addr = Main.pref.get("utilsplugin2.customurl", defaultURL); 138 System.out.println("pref:"+addr); 139 combo1.setPossibleItems(items); 140 141 HtmlPanel help = new HtmlPanel(tr("You can open custom URL for <b>one</b> selected object<br/>" 142 + " <b>{key}</b> is replaced with the tag walue<br/>" 143 + " <b>{#id}</b> is replaced with the element ID<br/>" 144 + " <b>{#type}</b> is replaced with \"node\",\"way\" or \"relation\" <br/>" 145 + " <b>{#lat} , {#lon}</b> is replaced with element latitude/longitude")); 146 help.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED)); 147 all.add(help,GBC.eop().insets(5,10,0,0)); 148 all.add(combo1,GBC.eop().insets(5,10,0,0)); 149 150 ExtendedDialog dialog = new ExtendedDialog(Main.parent, 151 tr("Configure custom URL"), 152 new String[] {tr("OK"),tr("Cancel"),} 153 ); 154 dialog.setContent(all, false); 155 dialog.setButtonIcons(new String[] {"ok.png","cancel.png",}); 156 dialog.setDefaultButton(1); 157 dialog.showDialog(); 158 159 addr=combo1.getText(); 160 if (dialog.getValue() ==1 && addr.length()>6) Main.pref.put("utilsplugin2.customurl",addr); 101 161 } 102 162 } -
applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/SymmetryAction.java
r26395 r26603 37 37 Shortcut.registerShortcut("tools:symmetry", tr("Tool: {0}", tr("Symmetry")), 38 38 KeyEvent.VK_S, Shortcut.GROUP_EDIT, KeyEvent.SHIFT_DOWN_MASK|KeyEvent.ALT_DOWN_MASK ), true); 39 putValue("help", ht("/Action/Symm try"));39 putValue("help", ht("/Action/Symmetry")); 40 40 } 41 41 -
applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/UtilsPlugin2.java
r26393 r26603 30 30 JMenuItem undoSelection; 31 31 JMenuItem extractPoint; 32 32 JMenuItem wiki; 33 33 34 JMenuItem replaceGeometry; 34 35 JMenuItem tagBuffer; … … 57 58 extractPoint = MainMenu.add(toolsMenu, new ExtractPointAction()); 58 59 symmetry = MainMenu.add(toolsMenu, new SymmetryAction()); 60 wiki = MainMenu.add(toolsMenu, new OpenPageAction()); 59 61 60 62 JMenu selectionMenu = Main.main.menu.addMenu(marktr("Selection"), KeyEvent.VK_N, Main.main.menu.defaultMenuPos, "help"); … … 86 88 alignWayNodes.setEnabled(enabled); 87 89 splitOnIntersections.setEnabled(enabled); 90 wiki.setEnabled(enabled); 88 91 89 92 selectWayNodes.setEnabled(enabled);
Note:
See TracChangeset
for help on using the changeset viewer.