Changeset 1865 in josm
- Timestamp:
- 2009-07-28T19:48:39+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 28 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/SelectAllAction.java
r1820 r1865 7 7 import java.awt.event.KeyEvent; 8 8 9 import org.openstreetmap.josm.gui.layer.Layer;10 import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener;11 9 import org.openstreetmap.josm.tools.Shortcut; 12 10 -
trunk/src/org/openstreetmap/josm/actions/UnselectAllAction.java
r1820 r1865 6 6 import java.awt.event.ActionEvent; 7 7 import java.awt.event.KeyEvent; 8 8 9 import javax.swing.JComponent; 9 10 10 11 import org.openstreetmap.josm.Main; 11 import org.openstreetmap.josm.gui.layer.Layer;12 import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener;13 12 import org.openstreetmap.josm.tools.Shortcut; 14 13 -
trunk/src/org/openstreetmap/josm/actions/UpdateDataAction.java
r1857 r1865 16 16 import org.openstreetmap.josm.data.osm.DataSource; 17 17 import org.openstreetmap.josm.gui.OptionPaneUtil; 18 import org.openstreetmap.josm.gui.layer.Layer;19 import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener;20 18 import org.openstreetmap.josm.tools.Shortcut; 21 19 -
trunk/src/org/openstreetmap/josm/actions/UpdateSelectionAction.java
r1857 r1865 14 14 15 15 import org.openstreetmap.josm.Main; 16 import org.openstreetmap.josm.data.SelectionChangedListener;17 16 import org.openstreetmap.josm.data.osm.DataSet; 18 17 import org.openstreetmap.josm.data.osm.OsmPrimitive; 19 18 import org.openstreetmap.josm.gui.OptionPaneUtil; 20 19 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 21 import org.openstreetmap.josm.gui.layer.Layer;22 import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener;23 20 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 24 21 import org.openstreetmap.josm.gui.progress.ProgressMonitor; … … 63 60 protected void handleUpdateException(Exception e) { 64 61 e.printStackTrace(); 65 JOptionPane.showMessageDialog(62 OptionPaneUtil.showMessageDialog( 66 63 Main.parent, 67 64 tr("Failed to update the selected primitives."), … … 78 75 */ 79 76 protected void handleMissingPrimitive(long id) { 80 JOptionPane.showMessageDialog(77 OptionPaneUtil.showMessageDialog( 81 78 Main.parent, 82 79 tr("Could not find primitive with id {0} in the current dataset", new Long(id).toString()), … … 114 111 msg = lastException.toString(); 115 112 } 116 JOptionPane.showMessageDialog(113 OptionPaneUtil.showMessageDialog( 117 114 Main.map, 118 115 msg, -
trunk/src/org/openstreetmap/josm/actions/UploadAction.java
r1857 r1865 169 169 return; 170 170 if (Main.map == null) { 171 JOptionPane.showMessageDialog(Main.parent,tr("Nothing to upload. Get some data first.")); 171 OptionPaneUtil.showMessageDialog( 172 Main.parent, 173 tr("Nothing to upload. Get some data first."), 174 tr("Warning"), 175 JOptionPane.WARNING_MESSAGE 176 ); 172 177 return; 173 178 } … … 203 208 204 209 if (add.isEmpty() && update.isEmpty() && delete.isEmpty()) { 205 JOptionPane.showMessageDialog(Main.parent,tr("No changes to upload.")); 210 OptionPaneUtil.showMessageDialog( 211 Main.parent, 212 tr("No changes to upload."), 213 tr("Warning"), 214 JOptionPane.WARNING_MESSAGE 215 ); 206 216 return; 207 217 } … … 350 360 ); 351 361 int optionsType = JOptionPane.YES_NO_CANCEL_OPTION; 352 int ret = JOptionPane.showOptionDialog(362 int ret = OptionPaneUtil.showOptionDialog( 353 363 null, 354 364 msg, … … 356 366 optionsType, 357 367 JOptionPane.ERROR_MESSAGE, 358 null,359 368 options, 360 369 defaultOption … … 390 399 ); 391 400 int optionsType = JOptionPane.YES_NO_OPTION; 392 int ret = JOptionPane.showOptionDialog(401 int ret = OptionPaneUtil.showOptionDialog( 393 402 null, 394 403 msg, … … 396 405 optionsType, 397 406 JOptionPane.ERROR_MESSAGE, 398 null,399 407 options, 400 408 defaultOption … … 433 441 */ 434 442 protected void handlePreconditionFailed(OsmApiException e) { 435 JOptionPane.showMessageDialog(443 OptionPaneUtil.showMessageDialog( 436 444 Main.parent, 437 445 tr("<html>Uploading to the server <strong>failed</strong> because your current<br>" … … 483 491 e.getMessage().replace("&", "&").replace("<", "<").replace(">", ">") 484 492 ); 485 JOptionPane.showMessageDialog(493 OptionPaneUtil.showMessageDialog( 486 494 Main.parent, 487 495 msg, … … 558 566 ex.getDisplayMessage() 559 567 ); 560 JOptionPane.showMessageDialog(568 OptionPaneUtil.showMessageDialog( 561 569 Main.map, 562 570 msg, … … 575 583 } 576 584 e.printStackTrace(); 577 JOptionPane.showMessageDialog(585 OptionPaneUtil.showMessageDialog( 578 586 Main.map, 579 587 msg, … … 589 597 */ 590 598 protected void handleOsmApiInitializationException(OsmApiInitializationException e) { 591 JOptionPane.showMessageDialog(599 OptionPaneUtil.showMessageDialog( 592 600 Main.parent, 593 601 tr( "Failed to initialize communication with the OSM server {0}.\n" -
trunk/src/org/openstreetmap/josm/actions/mapmode/DeleteAction.java
r1856 r1865 13 13 import org.openstreetmap.josm.command.Command; 14 14 import org.openstreetmap.josm.command.DeleteCommand; 15 import org.openstreetmap.josm.data.osm.DataSet;16 15 import org.openstreetmap.josm.data.osm.OsmPrimitive; 17 16 import org.openstreetmap.josm.data.osm.Relation; -
trunk/src/org/openstreetmap/josm/data/ServerSidePreferences.java
r1857 r1865 106 106 } catch (MalformedURLException e) { 107 107 e.printStackTrace(); 108 JOptionPane.showMessageDialog(Main.parent, tr("Could not load preferences from server.")); 108 OptionPaneUtil.showMessageDialog( 109 Main.parent, 110 tr("Could not load preferences from server."), 111 tr("Error"), 112 JOptionPane.ERROR_MESSAGE 113 ); 109 114 } 110 115 this.connection = connection; -
trunk/src/org/openstreetmap/josm/gui/BookmarkList.java
r1169 r1865 37 37 model.removeAllElements(); 38 38 try { 39 for (Preferences.Bookmark b : Main.pref.loadBookmarks()) 39 for (Preferences.Bookmark b : Main.pref.loadBookmarks()) { 40 40 model.addElement(b); 41 } 41 42 } catch (IOException e) { 42 43 e.printStackTrace(); 43 JOptionPane.showMessageDialog(Main.parent, tr("Could not read bookmarks.")+"\n"+e.getMessage()); 44 OptionPaneUtil.showMessageDialog( 45 Main.parent, 46 tr("<html>Could not read bookmarks.<br>{0}</html>", e.getMessage()), 47 tr("Error"), 48 JOptionPane.ERROR_MESSAGE 49 ); 44 50 } 45 51 } … … 51 57 try { 52 58 Collection<Preferences.Bookmark> bookmarks = new LinkedList<Preferences.Bookmark>(); 53 for (Object o : ((DefaultListModel)getModel()).toArray()) 59 for (Object o : ((DefaultListModel)getModel()).toArray()) { 54 60 bookmarks.add((Preferences.Bookmark)o); 61 } 55 62 Main.pref.saveBookmarks(bookmarks); 56 63 } catch (IOException e) { 57 JOptionPane.showMessageDialog(Main.parent,tr("Could not write bookmark.")+"\n"+e.getMessage()); 64 OptionPaneUtil.showMessageDialog( 65 Main.parent, 66 tr("<html>Could not write bookmark.<br>{0}</html>", e.getMessage()), 67 tr("Error"), 68 JOptionPane.ERROR_MESSAGE 69 ); 58 70 } 59 71 } -
trunk/src/org/openstreetmap/josm/gui/ExtendedDialog.java
r1861 r1865 67 67 bTexts = buttonTexts; 68 68 setupDialog(lbl, buttonIcons); 69 try {70 setAlwaysOnTop(true);71 } catch(SecurityException e) {72 System.out.println(tr("Warning: failed to put extended dialog always on top. Exception was: {0}", e.toString()));73 }74 69 setVisible(true); 75 70 } … … 143 138 setSize(d); 144 139 setLocationRelativeTo(parent); 140 141 // try to put always on top 142 // 143 try { 144 setAlwaysOnTop(true); 145 } catch(SecurityException e) { 146 System.out.println(tr("Warning: failed to bring extended dialog always on top. Exception: {0}", e.toString())); 147 } 145 148 } 146 149 -
trunk/src/org/openstreetmap/josm/gui/OptionPaneUtil.java
r1861 r1865 7 7 import java.awt.HeadlessException; 8 8 9 import javax.swing.Icon; 9 10 import javax.swing.JDialog; 10 11 import javax.swing.JOptionPane; 12 import javax.swing.JRootPane; 13 import javax.swing.UIManager; 11 14 12 15 import org.openstreetmap.josm.Main; … … 212 215 return JOptionPane.CLOSED_OPTION; 213 216 } 217 218 /** 219 * Shows a dialog requesting input from the user parented to 220 * <code>parentComponent</code> with the dialog having the title 221 * <code>title</code> and message type <code>messageType</code>. 222 * 223 * @param parentComponent the parent <code>Component</code> for the 224 * dialog 225 * @param message the <code>Object</code> to display 226 * @param title the <code>String</code> to display in the dialog 227 * title bar 228 * @param messageType the type of message that is to be displayed: 229 * <code>ERROR_MESSAGE</code>, 230 * <code>INFORMATION_MESSAGE</code>, 231 * <code>WARNING_MESSAGE</code>, 232 * <code>QUESTION_MESSAGE</code>, 233 * or <code>PLAIN_MESSAGE</code> 234 * @exception HeadlessException if 235 * <code>GraphicsEnvironment.isHeadless</code> returns 236 * <code>true</code> 237 * @see java.awt.GraphicsEnvironment#isHeadless 238 */ 239 public static String showInputDialog(Component parentComponent, 240 Object message, String title, int messageType) 241 throws HeadlessException { 242 return (String)showInputDialog(parentComponent, message, title, 243 messageType, null, null, null); 244 } 245 246 /** 247 * Prompts the user for input in a blocking dialog where the 248 * initial selection, possible selections, and all other options can 249 * be specified. The user will able to choose from 250 * <code>selectionValues</code>, where <code>null</code> implies the 251 * user can input 252 * whatever they wish, usually by means of a <code>JTextField</code>. 253 * <code>initialSelectionValue</code> is the initial value to prompt 254 * the user with. It is up to the UI to decide how best to represent 255 * the <code>selectionValues</code>, but usually a 256 * <code>JComboBox</code>, <code>JList</code>, or 257 * <code>JTextField</code> will be used. 258 * 259 * @param parentComponent the parent <code>Component</code> for the 260 * dialog 261 * @param message the <code>Object</code> to display 262 * @param title the <code>String</code> to display in the 263 * dialog title bar 264 * @param messageType the type of message to be displayed: 265 * <code>ERROR_MESSAGE</code>, 266 * <code>INFORMATION_MESSAGE</code>, 267 * <code>WARNING_MESSAGE</code>, 268 * <code>QUESTION_MESSAGE</code>, 269 * or <code>PLAIN_MESSAGE</code> 270 * @param icon the <code>Icon</code> image to display 271 * @param selectionValues an array of <code>Object</code>s that 272 * gives the possible selections 273 * @param initialSelectionValue the value used to initialize the input 274 * field 275 * @return user's input, or <code>null</code> meaning the user 276 * canceled the input 277 * @exception HeadlessException if 278 * <code>GraphicsEnvironment.isHeadless</code> returns 279 * <code>true</code> 280 * @see java.awt.GraphicsEnvironment#isHeadless 281 */ 282 public static Object showInputDialog(Component parentComponent, 283 Object message, String title, int messageType, Icon icon, 284 Object[] selectionValues, Object initialSelectionValue) 285 throws HeadlessException { 286 JOptionPane pane = new JOptionPane(message, messageType, 287 JOptionPane.OK_CANCEL_OPTION, icon, 288 null, null); 289 290 pane.setWantsInput(true); 291 pane.setSelectionValues(selectionValues); 292 pane.setInitialSelectionValue(initialSelectionValue); 293 pane.setComponentOrientation(((parentComponent == null) ? 294 JOptionPane.getRootFrame() : parentComponent).getComponentOrientation()); 295 296 JDialog dialog = pane.createDialog(parentComponent, title); 297 // this shows the dialog always on top and brings it to front 298 // 299 prepareDialog(dialog); 300 pane.selectInitialValue(); 301 dialog.setVisible(true); 302 dialog.dispose(); 303 304 Object value = pane.getInputValue(); 305 if (value == JOptionPane.UNINITIALIZED_VALUE) 306 return null; 307 return value; 308 } 214 309 } -
trunk/src/org/openstreetmap/josm/gui/download/BookmarkSelection.java
r1847 r1865 87 87 return; 88 88 } 89 tempBookmark.name = JOptionPane.showInputDialog(Main.parent,tr("Please enter a name for the location.")); 89 tempBookmark.name = OptionPaneUtil.showInputDialog( 90 Main.parent,tr("Please enter a name for the location."), 91 tr("Name of location"), 92 JOptionPane.QUESTION_MESSAGE 93 ); 90 94 if (tempBookmark.name != null && !tempBookmark.name.equals("")) { 91 95 ((DefaultListModel)bookmarks.getModel()).addElement(tempBookmark); -
trunk/src/org/openstreetmap/josm/gui/layer/GeoImageLayer.java
r1863 r1865 70 70 import org.openstreetmap.josm.gui.MapFrame; 71 71 import org.openstreetmap.josm.gui.MapView; 72 import org.openstreetmap.josm.gui.OptionPaneUtil; 72 73 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 73 74 import org.openstreetmap.josm.gui.dialogs.LayerListDialog; … … 125 126 if (cachedImageRef != null) { 126 127 Image cachedImage = cachedImageRef.get(); 127 if (cachedImage != null) {128 if (cachedImage != null) 128 129 return cachedImage; 129 }130 130 } 131 131 return Toolkit.getDefaultToolkit().createImage(currentEntry.file.getAbsolutePath()); … … 147 147 } 148 148 private void loadImage() { 149 if (currentEntry != null) {149 if (currentEntry != null) 150 150 return; 151 }152 151 while (!queue.isEmpty()) { 153 152 currentEntry = queue.get(0); … … 217 216 218 217 while (true) { 219 if (entry.scaledImage != null) {218 if (entry.scaledImage != null) 220 219 return entry.scaledImage; 221 }222 220 try { 223 221 wait(); … … 259 257 260 258 public Image getIcon() { 261 if (icon.scaledImage == null) {259 if (icon.scaledImage == null) 262 260 return EMPTY_IMAGE; 263 } else {261 else 264 262 return icon.scaledImage; 265 }266 263 } 267 264 … … 330 327 ArrayList<ImageEntry> data = new ArrayList<ImageEntry>(files.size()); 331 328 for (File f : files) { 332 if (progressMonitor.isCancelled()) 329 if (progressMonitor.isCancelled()) { 333 330 break; 331 } 334 332 progressMonitor.subTask(tr("Reading {0}...",f.getName())); 335 333 … … 341 339 continue; 342 340 } 343 if (e.time == null) 341 if (e.time == null) { 344 342 continue; 343 } 345 344 346 345 data.add(e); … … 350 349 } 351 350 @Override protected void finish() { 352 if (layer != null) 351 if (layer != null) { 353 352 Main.main.addLayer(layer); 353 } 354 354 } 355 355 @Override … … 412 412 return; 413 413 mousePressed = true; 414 if (visible) 414 if (visible) { 415 415 Main.map.mapView.repaint(); 416 } 416 417 } 417 418 @Override public void mouseReleased(MouseEvent ev) { … … 423 424 for (int i = data.size(); i > 0; --i) { 424 425 ImageEntry e = data.get(i-1); 425 if (e.pos == null) 426 if (e.pos == null) { 426 427 continue; 428 } 427 429 Point p = Main.map.mapView.getPoint(e.pos); 428 430 Rectangle r = new Rectangle(p.x-ICON_SIZE/2, p.y-ICON_SIZE/2, ICON_SIZE, ICON_SIZE); … … 440 442 public void layerAdded(Layer newLayer) {} 441 443 public void layerRemoved(Layer oldLayer) { 442 if (oldLayer == self) 444 if (oldLayer == self) { 443 445 Main.map.mapView.removeMouseListener(mouseAdapter); 446 } 444 447 } 445 448 }); … … 550 553 nextButton.setEnabled(currentImage < data.size() - 1); 551 554 552 if (scaleToggle.getModel().isSelected()) 555 if (scaleToggle.getModel().isSelected()) { 553 556 imageLabel.setIcon(new ImageIcon(imageLoader.waitForImage(currentImageEntry.image, 554 557 Math.max(imageViewport.getWidth(), imageViewport.getHeight())))); 555 else558 } else { 556 559 imageLabel.setIcon(new ImageIcon(imageLoader.waitForImage(currentImageEntry.image))); 557 558 if (centerToggle.getModel().isSelected()) 560 } 561 562 if (centerToggle.getModel().isSelected()) { 559 563 Main.map.mapView.zoomTo(currentImageEntry.pos); 564 } 560 565 561 566 dlg.setTitle(currentImageEntry.image + … … 594 599 setIcon(new ImageIcon(e.getIcon())); 595 600 setText(e.image.getName()+" ("+dateFormat.format(new Date(e.time.getTime()+(delta+gpstimezone)))+")"); 596 if (e.pos == null) 601 if (e.pos == null) { 597 602 setForeground(Color.red); 603 } 598 604 return this; 599 605 } … … 607 613 int i = 0; 608 614 for (ImageEntry e : data) 609 if (e.pos != null) 615 if (e.pos != null) { 610 616 i++; 617 } 611 618 return data.size()+" "+trn("image","images",data.size())+". "+tr("{0} within the track.",i); 612 619 } … … 662 669 663 670 @Override public void visitBoundingBox(BoundingXYVisitor v) { 664 for (ImageEntry e : data) 671 for (ImageEntry e : data) { 665 672 v.visit(e.pos); 673 } 666 674 } 667 675 … … 723 731 exifDate = ExifReader.readTime(f); 724 732 } catch (ParseException e) { 725 JOptionPane.showMessageDialog(Main.parent, tr("The date in file \"{0}\" could not be parsed.", f.getName())); 733 OptionPaneUtil.showMessageDialog( 734 Main.parent, 735 tr("The date in file \"{0}\" could not be parsed.", f.getName()), 736 tr("Error"), 737 JOptionPane.ERROR_MESSAGE 738 ); 726 739 return; 727 740 } 728 741 if (exifDate == null) { 729 JOptionPane.showMessageDialog(Main.parent, tr("There is no EXIF time within the file \"{0}\".", f.getName())); 742 OptionPaneUtil.showMessageDialog( 743 Main.parent, 744 tr("There is no EXIF time within the file \"{0}\".", f.getName()), 745 tr("Error"), 746 JOptionPane.ERROR_MESSAGE 747 ); 730 748 return; 731 749 } … … 738 756 p.add(new JLabel(tr("GPS unit timezone (difference to photo)")), GBC.eol()); 739 757 String t = Main.pref.get("tagimages.gpstimezone", "0"); 740 if (t.charAt(0) != '-') 758 if (t.charAt(0) != '-') { 741 759 t = "+"+t; 760 } 742 761 JTextField gpsTimezone = new JTextField(t); 743 762 p.add(gpsTimezone, GBC.eol().fill(GBC.HORIZONTAL)); 744 763 745 764 while (true) { 746 int answer = JOptionPane.showConfirmDialog(Main.parent, p, tr("Synchronize Time with GPS Unit"), JOptionPane.OK_CANCEL_OPTION); 765 int answer = OptionPaneUtil.showConfirmationDialog( 766 Main.parent, 767 p, 768 tr("Synchronize Time with GPS Unit"), 769 JOptionPane.OK_CANCEL_OPTION, 770 JOptionPane.QUESTION_MESSAGE 771 ); 747 772 if (answer != JOptionPane.OK_OPTION || gpsText.getText().equals("")) 748 773 return; … … 750 775 delta = DateParser.parse(gpsText.getText()).getTime() - exifDate.getTime(); 751 776 String time = gpsTimezone.getText(); 752 if (!time.equals("") && time.charAt(0) == '+') 777 if (!time.equals("") && time.charAt(0) == '+') { 753 778 time = time.substring(1); 754 if (time.equals("")) 779 } 780 if (time.equals("")) { 755 781 time = "0"; 782 } 756 783 gpstimezone = Long.valueOf(time)*60*60*1000; 757 784 Main.pref.put("tagimages.delta", ""+delta); … … 760 787 return; 761 788 } catch (NumberFormatException x) { 762 JOptionPane.showMessageDialog(Main.parent, tr("Time entered could not be parsed.")); 789 OptionPaneUtil.showMessageDialog( 790 Main.parent, 791 tr("Time entered could not be parsed."), 792 tr("Error"), 793 JOptionPane.ERROR_MESSAGE 794 ); 763 795 } catch (ParseException x) { 764 JOptionPane.showMessageDialog(Main.parent, tr("Time entered could not be parsed.")); 796 OptionPaneUtil.showMessageDialog( 797 Main.parent, 798 tr("Time entered could not be parsed."), 799 tr("Error"), 800 JOptionPane.ERROR_MESSAGE 801 ); 765 802 } 766 803 } -
trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java
r1838 r1865 59 59 import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil; 60 60 import org.openstreetmap.josm.gui.MapView; 61 import org.openstreetmap.josm.gui.OptionPaneUtil; 61 62 import org.openstreetmap.josm.gui.dialogs.LayerListDialog; 62 63 import org.openstreetmap.josm.gui.dialogs.LayerListPopup; … … 99 100 } 100 101 101 @Override public Icon getIcon() { 102 @Override 103 public Icon getIcon() { 102 104 return ImageProvider.get("layer", "gpx_small"); 103 105 } 104 106 105 @Override public Object getInfoComponent() { 107 @Override 108 public Object getInfoComponent() { 106 109 return getToolTipText(); 107 110 } 108 111 109 static public Color getColor(String name) 110 {111 return Main.pref.getColor(marktr("gps point"), name != null ? "layer "+name : null, Color.gray);112 } 113 114 @Overridepublic Component[] getMenuEntries() {112 static public Color getColor(String name) { 113 return Main.pref.getColor(marktr("gps point"), name != null ? "layer " + name : null, Color.gray); 114 } 115 116 @Override 117 public Component[] getMenuEntries() { 115 118 JMenuItem line = new JMenuItem(tr("Customize line drawing"), ImageProvider.get("mapmode/addsegment")); 116 119 line.addActionListener(new ActionListener() { … … 126 129 panel.add(b); 127 130 } 128 String propName = "draw.rawgps.lines.layer " +name;131 String propName = "draw.rawgps.lines.layer " + name; 129 132 if (Main.pref.hasKey(propName)) { 130 group.setSelected(r[Main.pref.getBoolean(propName) ? 1 :2].getModel(), true);133 group.setSelected(r[Main.pref.getBoolean(propName) ? 1 : 2].getModel(), true); 131 134 } else { 132 135 group.setSelected(r[0].getModel(), true); 133 136 } 134 int answer = JOptionPane.showConfirmDialog(Main.parent, panel, tr("Select line drawing options"), JOptionPane.OK_CANCEL_OPTION); 135 if (answer == JOptionPane.CANCEL_OPTION) 136 return; 137 int answer = OptionPaneUtil.showConfirmationDialog(Main.parent, panel, 138 tr("Select line drawing options"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); 139 switch (answer) { 140 case JOptionPane.CANCEL_OPTION: 141 case JOptionPane.CLOSED_OPTION: 142 return; 143 default: 144 // continue 145 } 137 146 if (group.getSelection() == r[0].getModel()) { 138 147 Main.pref.put(propName, null); … … 149 158 public void actionPerformed(ActionEvent e) { 150 159 JColorChooser c = new JColorChooser(getColor(name)); 151 Object[] options = new Object[]{tr("OK"), tr("Cancel"), tr("Default")}; 152 int answer = JOptionPane.showOptionDialog(Main.parent, c, tr("Choose a color"), JOptionPane.OK_CANCEL_OPTION, 153 JOptionPane.PLAIN_MESSAGE, null, options, options[0]); 160 Object[] options = new Object[] { tr("OK"), tr("Cancel"), tr("Default") }; 161 int answer = OptionPaneUtil.showOptionDialog( 162 Main.parent, 163 c, 164 tr("Choose a color"), 165 JOptionPane.OK_CANCEL_OPTION, 166 JOptionPane.PLAIN_MESSAGE, 167 options, options[0] 168 ); 154 169 switch (answer) { 155 case 0:156 Main.pref.putColor("layer "+name, c.getColor());157 break;158 case 1:159 return;160 case 2:161 Main.pref.putColor("layer "+name, null);162 break;170 case 0: 171 Main.pref.putColor("layer " + name, c.getColor()); 172 break; 173 case 1: 174 return; 175 case 2: 176 Main.pref.putColor("layer " + name, null); 177 break; 163 178 } 164 179 Main.map.repaint(); … … 166 181 }); 167 182 168 JMenuItem markersFromNamedTrackpoints = new JMenuItem(tr("Markers From Named Points"), ImageProvider.get("addmarkers")); 183 JMenuItem markersFromNamedTrackpoints = new JMenuItem(tr("Markers From Named Points"), ImageProvider 184 .get("addmarkers")); 169 185 markersFromNamedTrackpoints.putClientProperty("help", "Action/MarkersFromNamedPoints"); 170 186 markersFromNamedTrackpoints.addActionListener(new ActionListener() { … … 180 196 } 181 197 182 MarkerLayer ml = new MarkerLayer(namedTrackPoints, tr("Named Trackpoints from {0}", name), getAssociatedFile(), me); 198 MarkerLayer ml = new MarkerLayer(namedTrackPoints, tr("Named Trackpoints from {0}", name), 199 getAssociatedFile(), me); 183 200 if (ml.data.size() > 0) { 184 201 Main.main.addLayer(ml); … … 195 212 fc.setFileSelectionMode(JFileChooser.FILES_ONLY); 196 213 fc.setAcceptAllFileFilterUsed(false); 197 fc.setFileFilter(new FileFilter(){ 198 @Override public boolean accept(File f) { 214 fc.setFileFilter(new FileFilter() { 215 @Override 216 public boolean accept(File f) { 199 217 return f.isDirectory() || f.getName().toLowerCase().endsWith(".wav"); 200 218 } 201 @Override public String getDescription() { 219 220 @Override 221 public String getDescription() { 202 222 return tr("Wave Audio files (*.wav)"); 203 223 } 204 224 }); 205 225 fc.setMultiSelectionEnabled(true); 206 if (fc.showOpenDialog(Main.parent) == JFileChooser.APPROVE_OPTION) {226 if (fc.showOpenDialog(Main.parent) == JFileChooser.APPROVE_OPTION) { 207 227 if (!fc.getCurrentDirectory().getAbsolutePath().equals(dir)) { 208 228 Main.pref.put("markers.lastaudiodirectory", fc.getCurrentDirectory().getAbsolutePath()); … … 210 230 211 231 File sel[] = fc.getSelectedFiles(); 212 if(sel != null) { 213 // sort files in increasing order of timestamp (this is the end time, but so long as they don't overlap, that's fine) 232 if (sel != null) { 233 // sort files in increasing order of timestamp (this is the end time, but so 234 // long as they don't overlap, that's fine) 214 235 if (sel.length > 1) { 215 236 Arrays.sort(sel, new Comparator<File>() { … … 223 244 String names = null; 224 245 for (int i = 0; i < sel.length; i++) { 225 if (names == null) {246 if (names == null) { 226 247 names = " ("; 227 248 } else { … … 230 251 names += sel[i].getName(); 231 252 } 232 if (names != null) {253 if (names != null) { 233 254 names += ")"; 234 255 } else { … … 237 258 MarkerLayer ml = new MarkerLayer(new GpxData(), tr("Audio markers from {0}", name) + names, 238 259 getAssociatedFile(), me); 239 if (sel != null)240 {241 double firstStartTime = sel[0].lastModified()/1000.0 /* ms -> seconds */- AudioUtil.getCalibratedDuration(sel[0]);260 if (sel != null) { 261 double firstStartTime = sel[0].lastModified() / 1000.0 /* ms -> seconds */ 262 - AudioUtil.getCalibratedDuration(sel[0]); 242 263 for (int i = 0; i < sel.length; i++) { 243 264 importAudio(sel[i], ml, firstStartTime); … … 259 280 fc.setAcceptAllFileFilterUsed(false); 260 281 fc.setFileFilter(new FileFilter() { 261 @Override public boolean accept(File f) { 282 @Override 283 public boolean accept(File f) { 262 284 return f.isDirectory() || f.getName().toLowerCase().endsWith(".jpg"); 263 285 } 264 @Override public String getDescription() { 286 287 @Override 288 public String getDescription() { 265 289 return tr("JPEG images (*.jpg)"); 266 290 } … … 288 312 289 313 if (Main.applet) 290 return new Component[] { 291 new JMenuItem(new LayerListDialog.ShowHideLayerAction(this)), 292 new JMenuItem(new LayerListDialog.DeleteLayerAction(this)), 293 new JSeparator(), 294 color, 295 line, 296 new JMenuItem(new ConvertToDataLayerAction()), 297 new JSeparator(), 298 new JMenuItem(new RenameLayerAction(getAssociatedFile(), this)), 299 new JSeparator(), 300 new JMenuItem(new LayerListPopup.InfoAction(this))}; 301 return new Component[] { 302 new JMenuItem(new LayerListDialog.ShowHideLayerAction(this)), 303 new JMenuItem(new LayerListDialog.DeleteLayerAction(this)), 304 new JSeparator(), 305 new JMenuItem(new LayerSaveAction(this)), 306 new JMenuItem(new LayerSaveAsAction(this)), 307 color, 308 line, 309 tagimage, 310 importAudio, 311 markersFromNamedTrackpoints, 312 new JMenuItem(new ConvertToDataLayerAction()), 313 new JMenuItem(new DownloadAlongTrackAction()), 314 new JSeparator(), 315 new JMenuItem(new RenameLayerAction(getAssociatedFile(), this)), 316 new JSeparator(), 317 new JMenuItem(new LayerListPopup.InfoAction(this))}; 318 } 319 320 @Override public String getToolTipText() { 314 return new Component[] { new JMenuItem(new LayerListDialog.ShowHideLayerAction(this)), 315 new JMenuItem(new LayerListDialog.DeleteLayerAction(this)), new JSeparator(), color, line, 316 new JMenuItem(new ConvertToDataLayerAction()), new JSeparator(), 317 new JMenuItem(new RenameLayerAction(getAssociatedFile(), this)), new JSeparator(), 318 new JMenuItem(new LayerListPopup.InfoAction(this)) }; 319 return new Component[] { new JMenuItem(new LayerListDialog.ShowHideLayerAction(this)), 320 new JMenuItem(new LayerListDialog.DeleteLayerAction(this)), new JSeparator(), 321 new JMenuItem(new LayerSaveAction(this)), new JMenuItem(new LayerSaveAsAction(this)), color, line, 322 tagimage, importAudio, markersFromNamedTrackpoints, new JMenuItem(new ConvertToDataLayerAction()), 323 new JMenuItem(new DownloadAlongTrackAction()), new JSeparator(), 324 new JMenuItem(new RenameLayerAction(getAssociatedFile(), this)), new JSeparator(), 325 new JMenuItem(new LayerListPopup.InfoAction(this)) }; 326 } 327 328 @Override 329 public String getToolTipText() { 321 330 StringBuilder info = new StringBuilder().append("<html>"); 322 331 323 info.append(trn("{0} track, ", "{0} tracks, ", 324 data.tracks.size(), data.tracks.size())).append(trn("{0} route, ", "{0} routes, ", 325 data.routes.size(), data.routes.size())).append(trn("{0} waypoint", "{0} waypoints", 326 data.waypoints.size(), data.waypoints.size())).append("<br>"); 332 info.append(trn("{0} track, ", "{0} tracks, ", data.tracks.size(), data.tracks.size())).append( 333 trn("{0} route, ", "{0} routes, ", data.routes.size(), data.routes.size())).append( 334 trn("{0} waypoint", "{0} waypoints", data.waypoints.size(), data.waypoints.size())).append("<br>"); 327 335 328 336 if (data.attr.containsKey("name")) { … … 334 342 } 335 343 336 if (data.tracks.size() > 0){344 if (data.tracks.size() > 0) { 337 345 boolean first = true; 338 346 WayPoint earliest = null, latest = null; 339 347 340 for (GpxTrack trk: data.tracks){341 for (Collection<WayPoint> seg:trk.trackSegs){342 for (WayPoint pnt:seg){343 if (first){348 for (GpxTrack trk : data.tracks) { 349 for (Collection<WayPoint> seg : trk.trackSegs) { 350 for (WayPoint pnt : seg) { 351 if (first) { 344 352 latest = earliest = pnt; 345 353 first = false; 346 } else{347 if (pnt.compareTo(earliest) < 0){354 } else { 355 if (pnt.compareTo(earliest) < 0) { 348 356 earliest = pnt; 349 } else{357 } else { 350 358 latest = pnt; 351 359 } … … 356 364 if (earliest != null && latest != null) { 357 365 DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT); 358 info.append(tr("Timespan: ") + df.format(new Date((long) (earliest.time * 1000))) + " - "359 + df.format(new Date((long) (latest.time * 1000))));360 int diff = (int) (latest.time - earliest.time);361 info.append(" (" + (diff / 3600) + ":" + ((diff % 3600) /60) + ")");366 info.append(tr("Timespan: ") + df.format(new Date((long) (earliest.time * 1000))) + " - " 367 + df.format(new Date((long) (latest.time * 1000)))); 368 int diff = (int) (latest.time - earliest.time); 369 info.append(" (" + (diff / 3600) + ":" + ((diff % 3600) / 60) + ")"); 362 370 info.append("<br>"); 363 371 } … … 369 377 } 370 378 371 @Override public boolean isMergable(Layer other) { 379 @Override 380 public boolean isMergable(Layer other) { 372 381 return other instanceof GpxLayer; 373 382 } 374 383 375 @Override public void mergeFrom(Layer from) { 376 data.mergeFrom(((GpxLayer)from).data); 384 @Override 385 public void mergeFrom(Layer from) { 386 data.mergeFrom(((GpxLayer) from).data); 377 387 computeCacheInSync = false; 378 388 } … … 381 391 static { 382 392 for (int i = 0; i < colors.length; i++) { 383 colors[i] = Color.getHSBColor(i /300.0f, 1, 1);393 colors[i] = Color.getHSBColor(i / 300.0f, 1, 1); 384 394 } 385 395 } … … 389 399 private static int sl4 = 5; 390 400 private static int sl9 = 3; 391 private static int[][] dir = { 392 {+sl4,+ll0,+ll0,+sl4}, 393 {-sl9,+ll0,+sl9,+ll0}, 394 {-ll0,+sl4,-sl4,+ll0}, 395 {-ll0,-sl9,-ll0,+sl9}, 396 {-sl4,-ll0,-ll0,-sl4}, 397 {+sl9,-ll0,-sl9,-ll0}, 398 {+ll0,-sl4,+sl4,-ll0}, 399 {+ll0,+sl9,+ll0,-sl9}, 400 {+sl4,+ll0,+ll0,+sl4}, 401 {-sl9,+ll0,+sl9,+ll0}, 402 {-ll0,+sl4,-sl4,+ll0}, 403 {-ll0,-sl9,-ll0,+sl9} 404 }; 401 private static int[][] dir = { { +sl4, +ll0, +ll0, +sl4 }, { -sl9, +ll0, +sl9, +ll0 }, { -ll0, +sl4, -sl4, +ll0 }, 402 { -ll0, -sl9, -ll0, +sl9 }, { -sl4, -ll0, -ll0, -sl4 }, { +sl9, -ll0, -sl9, -ll0 }, 403 { +ll0, -sl4, +sl4, -ll0 }, { +ll0, +sl9, +ll0, -sl9 }, { +sl4, +ll0, +ll0, +sl4 }, 404 { -sl9, +ll0, +sl9, +ll0 }, { -ll0, +sl4, -sl4, +ll0 }, { -ll0, -sl9, -ll0, +sl9 } }; 405 405 406 406 // the different color modes 407 enum colorModes { none, velocity, dilution } 408 409 @Override public void paint(Graphics g, MapView mv) { 407 enum colorModes { 408 none, velocity, dilution 409 } 410 411 @Override 412 public void paint(Graphics g, MapView mv) { 410 413 411 414 /**************************************************************** … … 426 429 } 427 430 // draw line between points, global setting 428 boolean lines = (Main.pref.getBoolean("draw.rawgps.lines", true) || (Main.pref.getBoolean("draw.rawgps.lines.localfiles") && this.isLocalFile)); 429 String linesKey = "draw.rawgps.lines.layer "+name; 431 boolean lines = (Main.pref.getBoolean("draw.rawgps.lines", true) || (Main.pref 432 .getBoolean("draw.rawgps.lines.localfiles") && this.isLocalFile)); 433 String linesKey = "draw.rawgps.lines.layer " + name; 430 434 // draw lines, per-layer setting 431 435 if (Main.pref.hasKey(linesKey)) { … … 438 442 try { 439 443 colored = colorModes.values()[Main.pref.getInteger("draw.rawgps.colors", 0)]; 440 } catch(Exception e) { } 444 } catch (Exception e) { 445 } 441 446 // paint direction arrow with alternate math. may be faster 442 447 boolean alternatedirection = Main.pref.getBoolean("draw.rawgps.alternatedirection"); … … 448 453 ********** STEP 2a - CHECK CACHE VALIDITY ********************** 449 454 ****************************************************************/ 450 if (computeCacheInSync && ((computeCacheMaxLineLengthUsed != maxLineLength) || 451 (!neutralColor.equals(computeCacheColorUsed)) || 452 (computeCacheColored != colored) || 453 (computeCacheColorTracksTune != colorTracksTune))) { 454 // System.out.println("(re-)computing gpx line styles, reason: CCIS=" + computeCacheInSync + " CCMLLU=" + (computeCacheMaxLineLengthUsed != maxLineLength) + " CCCU=" + (!neutralColor.equals(computeCacheColorUsed)) + " CCC=" + (computeCacheColored != colored)); 455 if (computeCacheInSync 456 && ((computeCacheMaxLineLengthUsed != maxLineLength) || (!neutralColor.equals(computeCacheColorUsed)) 457 || (computeCacheColored != colored) || (computeCacheColorTracksTune != colorTracksTune))) { 458 // System.out.println("(re-)computing gpx line styles, reason: CCIS=" + 459 // computeCacheInSync + " CCMLLU=" + (computeCacheMaxLineLengthUsed != maxLineLength) + 460 // " CCCU=" + (!neutralColor.equals(computeCacheColorUsed)) + " CCC=" + 461 // (computeCacheColored != colored)); 455 462 computeCacheMaxLineLengthUsed = maxLineLength; 456 463 computeCacheInSync = false; … … 479 486 double dist = c.greatCircleDistance(oldWp.getCoor()); 480 487 481 switch(colored) { 482 case velocity: 483 double dtime = trkPnt.time - oldWp.time; 484 double vel = dist/dtime; 485 double velColor = vel/colorTracksTune*255; 486 // Bad case first 487 if (dtime <= 0 || vel < 0 || velColor > 255) { 488 trkPnt.customColoring = colors[255]; 489 } else { 490 trkPnt.customColoring = colors[(int) (velColor)]; 491 } 492 break; 493 494 case dilution: 495 if(trkPnt.attr.get("hdop") != null) { 496 float hdop = ((Float)trkPnt.attr.get("hdop")).floatValue(); 497 if (hdop < 0) { 498 hdop = 0; 488 switch (colored) { 489 case velocity: 490 double dtime = trkPnt.time - oldWp.time; 491 double vel = dist / dtime; 492 double velColor = vel / colorTracksTune * 255; 493 // Bad case first 494 if (dtime <= 0 || vel < 0 || velColor > 255) { 495 trkPnt.customColoring = colors[255]; 496 } else { 497 trkPnt.customColoring = colors[(int) (velColor)]; 499 498 } 500 int hdoplvl = Math.round(hdop * Main.pref.getInteger("hdop.factor", 25)); 501 // High hdop is bad, but high values in colors are green. 502 // Therefore inverse the logic 503 int hdopcolor = 255 - (hdoplvl > 255 ? 255 : hdoplvl); 504 trkPnt.customColoring = colors[hdopcolor]; 505 } 506 break; 499 break; 500 501 case dilution: 502 if (trkPnt.attr.get("hdop") != null) { 503 float hdop = ((Float) trkPnt.attr.get("hdop")).floatValue(); 504 if (hdop < 0) { 505 hdop = 0; 506 } 507 int hdoplvl = Math.round(hdop * Main.pref.getInteger("hdop.factor", 25)); 508 // High hdop is bad, but high values in colors are green. 509 // Therefore inverse the logic 510 int hdopcolor = 255 - (hdoplvl > 255 ? 255 : hdoplvl); 511 trkPnt.customColoring = colors[hdopcolor]; 512 } 513 break; 507 514 } 508 515 509 516 if (maxLineLength == -1 || dist <= maxLineLength) { 510 517 trkPnt.drawLine = true; 511 trkPnt.dir = (int) oldWp.getCoor().heading(trkPnt.getCoor());518 trkPnt.dir = (int) oldWp.getCoor().heading(trkPnt.getCoor()); 512 519 } else { 513 520 trkPnt.drawLine = false; … … 565 572 Point screen = mv.getPoint(trkPnt.getEastNorth()); 566 573 // skip points that are on the same screenposition 567 if (old != null && (oldA == null || screen.x < oldA.x-delta || screen.x > oldA.x+delta || screen.y < oldA.y-delta || screen.y > oldA.y+delta)) { 574 if (old != null 575 && (oldA == null || screen.x < oldA.x - delta || screen.x > oldA.x + delta 576 || screen.y < oldA.y - delta || screen.y > oldA.y + delta)) { 568 577 g.setColor(trkPnt.customColoring); 569 double t = Math.atan2(screen.y -old.y, screen.x-old.x) + Math.PI;570 g.drawLine(screen.x, screen.y, (int)(screen.x + 10*Math.cos(t-PHI)), (int)(screen.y571 + 10*Math.sin(t-PHI)));572 g.drawLine(screen.x, screen.y, (int)(screen.x + 10*Math.cos(t+PHI)), (int)(screen.y573 + 10*Math.sin(t+PHI)));578 double t = Math.atan2(screen.y - old.y, screen.x - old.x) + Math.PI; 579 g.drawLine(screen.x, screen.y, (int) (screen.x + 10 * Math.cos(t - PHI)), 580 (int) (screen.y + 10 * Math.sin(t - PHI))); 581 g.drawLine(screen.x, screen.y, (int) (screen.x + 10 * Math.cos(t + PHI)), 582 (int) (screen.y + 10 * Math.sin(t + PHI))); 574 583 oldA = screen; 575 584 } … … 597 606 Point screen = mv.getPoint(trkPnt.getEastNorth()); 598 607 // skip points that are on the same screenposition 599 if (old != null && (oldA == null || screen.x < oldA.x-delta || screen.x > oldA.x+delta || screen.y < oldA.y-delta || screen.y > oldA.y+delta)) { 608 if (old != null 609 && (oldA == null || screen.x < oldA.x - delta || screen.x > oldA.x + delta 610 || screen.y < oldA.y - delta || screen.y > oldA.y + delta)) { 600 611 g.setColor(trkPnt.customColoring); 601 g.drawLine(screen.x, screen.y, screen.x + dir[trkPnt.dir][0], screen.y + dir[trkPnt.dir][1]); 602 g.drawLine(screen.x, screen.y, screen.x + dir[trkPnt.dir][2], screen.y + dir[trkPnt.dir][3]); 612 g.drawLine(screen.x, screen.y, screen.x + dir[trkPnt.dir][0], screen.y 613 + dir[trkPnt.dir][1]); 614 g.drawLine(screen.x, screen.y, screen.x + dir[trkPnt.dir][2], screen.y 615 + dir[trkPnt.dir][3]); 603 616 oldA = screen; 604 617 } … … 624 637 Point screen = mv.getPoint(trkPnt.getEastNorth()); 625 638 g.setColor(trkPnt.customColoring); 626 g.fillRect(screen.x -1, screen.y-1, 3, 3);639 g.fillRect(screen.x - 1, screen.y - 1, 3, 3); 627 640 } // end for trkpnt 628 641 } // end for segment … … 633 646 ********** STEP 3e - DRAW SMALL POINTS FOR LINES *************** 634 647 ****************************************************************/ 635 if (!large && lines) {648 if (!large && lines) { 636 649 g.setColor(neutralColor); 637 650 for (GpxTrack trk : data.tracks) { … … 654 667 ********** STEP 3f - DRAW SMALL POINTS INSTEAD OF LINES ******** 655 668 ****************************************************************/ 656 if (!large && !lines) {669 if (!large && !lines) { 657 670 g.setColor(neutralColor); 658 671 for (GpxTrack trk : data.tracks) { … … 671 684 } // end if large 672 685 673 // Long duration = System.currentTimeMillis() - startTime;674 // System.out.println(duration);686 // Long duration = System.currentTimeMillis() - startTime; 687 // System.out.println(duration); 675 688 } // end paint 676 689 677 @Override public void visitBoundingBox(BoundingXYVisitor v) { 690 @Override 691 public void visitBoundingBox(BoundingXYVisitor v) { 678 692 v.visit(data.recalculateBounds()); 679 693 } … … 683 697 super(tr("Convert to data layer"), ImageProvider.get("converttoosm")); 684 698 } 699 685 700 public void actionPerformed(ActionEvent e) { 686 701 JPanel msg = new JPanel(new GridBagLayout()); 687 msg.add(new JLabel(tr("<html>Upload of unprocessed GPS data as map data is considered harmful.<br>If you want to upload traces, look here:")), GBC.eol()); 702 msg 703 .add( 704 new JLabel( 705 tr("<html>Upload of unprocessed GPS data as map data is considered harmful.<br>If you want to upload traces, look here:")), 706 GBC.eol()); 688 707 msg.add(new UrlLabel(tr("http://www.openstreetmap.org/traces")), GBC.eop()); 689 if (!ConditionalOptionPaneUtil.showConfirmationDialog( 690 "convert_to_data", 691 Main.parent, 692 msg, 693 tr("Warning"), 694 JOptionPane.OK_CANCEL_OPTION, 695 JOptionPane.WARNING_MESSAGE, 696 JOptionPane.OK_OPTION)) 708 if (!ConditionalOptionPaneUtil.showConfirmationDialog("convert_to_data", Main.parent, msg, tr("Warning"), 709 JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, JOptionPane.OK_OPTION)) 697 710 return; 698 711 DataSet ds = new DataSet(); … … 703 716 Node n = new Node(p.getCoor()); 704 717 String timestr = p.getString("time"); 705 if(timestr != null) 706 { 718 if (timestr != null) { 707 719 n.setTimestamp(DateUtils.fromString(timestr)); 708 720 } … … 713 725 } 714 726 } 715 Main.main .addLayer(new OsmDataLayer(ds, tr("Converted from: {0}", GpxLayer.this.name),716 727 Main.main 728 .addLayer(new OsmDataLayer(ds, tr("Converted from: {0}", GpxLayer.this.name), getAssociatedFile())); 717 729 Main.main.removeLayer(GpxLayer.this); 718 730 } … … 720 732 721 733 @Override 722 public File getAssociatedFile() { return data.storageFile; } 734 public File getAssociatedFile() { 735 return data.storageFile; 736 } 737 723 738 @Override 724 public void setAssociatedFile(File file) { data.storageFile = file; } 739 public void setAssociatedFile(File file) { 740 data.storageFile = file; 741 } 725 742 726 743 /** 727 744 * Action that issues a series of download requests to the API, following the GPX track. 728 * 745 * 729 746 * @author fred 730 747 */ … … 733 750 super(tr("Download from OSM along this track"), ImageProvider.get("downloadalongtrack")); 734 751 } 752 735 753 public void actionPerformed(ActionEvent e) { 736 754 JPanel msg = new JPanel(new GridBagLayout()); 737 Integer dist[] = { 5000, 500, 50};738 Integer area[] = { 20, 10, 5, 1};755 Integer dist[] = { 5000, 500, 50 }; 756 Integer area[] = { 20, 10, 5, 1 }; 739 757 740 758 msg.add(new JLabel(tr("Download everything within:")), GBC.eol()); 741 759 String s[] = new String[dist.length]; 742 for (int i = 0; i < dist.length; ++i) {760 for (int i = 0; i < dist.length; ++i) { 743 761 s[i] = tr("{0} meters", dist[i]); 744 762 } … … 747 765 msg.add(new JLabel(tr("Maximum area per request:")), GBC.eol()); 748 766 s = new String[area.length]; 749 for (int i = 0; i < area.length; ++i) {767 for (int i = 0; i < area.length; ++i) { 750 768 s[i] = tr("{0} sq km", area[i]); 751 769 } … … 753 771 msg.add(maxRect, GBC.eol()); 754 772 755 if (JOptionPane.showConfirmDialog(Main.parent, msg, 773 int ret = OptionPaneUtil.showConfirmationDialog( 774 Main.parent, 775 msg, 756 776 tr("Download from OSM along this track"), 757 JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) 758 return; 777 JOptionPane.OK_CANCEL_OPTION, 778 JOptionPane.QUESTION_MESSAGE 779 ); 780 switch(ret) { 781 case JOptionPane.CANCEL_OPTION: 782 case JOptionPane.CLOSED_OPTION: 783 return; 784 default: 785 // continue 786 } 759 787 760 788 /* 761 * Find the average latitude for the data we're contemplating, so we can 762 * know how manymetres per degree of longitude we have.789 * Find the average latitude for the data we're contemplating, so we can know how many 790 * metres per degree of longitude we have. 763 791 */ 764 792 double latsum = 0; … … 769 797 for (WayPoint p : segment) { 770 798 latsum += p.getCoor().lat(); 771 latcnt 799 latcnt++; 772 800 } 773 801 } … … 778 806 779 807 /* 780 * Compute buffer zone extents and maximum bounding box size. Note that the 781 * maximum we ever offer is a bbox area of 0.002, while the API theoretically 782 * supports 0.25, but as soon as you touch any built-up area, that kind of 783 * bounding box will download forever and then stop because it has more than 784 * 50k nodes. 808 * Compute buffer zone extents and maximum bounding box size. Note that the maximum we 809 * ever offer is a bbox area of 0.002, while the API theoretically supports 0.25, but as 810 * soon as you touch any built-up area, that kind of bounding box will download forever 811 * and then stop because it has more than 50k nodes. 785 812 */ 786 813 Integer i = buffer.getSelectedIndex(); … … 794 821 795 822 /* 796 * Collect the combined area of all gpx points plus buffer zones around them. 797 * We ignore points that lie closer to the previous point than the given buffer798 * size becauseotherwise this operation takes ages.823 * Collect the combined area of all gpx points plus buffer zones around them. We ignore 824 * points that lie closer to the previous point than the given buffer size because 825 * otherwise this operation takes ages. 799 826 */ 800 827 LatLon previous = null; … … 805 832 if (previous == null || c.greatCircleDistance(previous) > buffer_dist) { 806 833 // we add a buffer around the point. 807 r.setRect(c.lon() -buffer_x, c.lat()-buffer_y, 2*buffer_x, 2*buffer_y);834 r.setRect(c.lon() - buffer_x, c.lat() - buffer_y, 2 * buffer_x, 2 * buffer_y); 808 835 a.add(new Area(r)); 809 836 previous = c; … … 814 841 815 842 /* 816 * Area "a" now contains the hull that we would like to download data for. 817 * however we can only download rectangles, so the following is an attempt at 818 * finding a number of rectangles to download. 819 * 820 * The idea is simply: Start out with the full bounding box. If it is too large, 821 * then split it in half and repeat recursively for each half until you arrive 822 * at something small enough to download. The algorithm is improved 823 * by always using the intersection between the rectangle and the actual desired 824 * area. For example, if you have a track that goes like this: 825 * +----+ 826 * | /| 827 * | / | 828 * | / | 829 * |/ | 830 * +----+ 831 * then we would first look at downloading the whole rectangle (assume it's too big), 832 * after that we split it in half (upper and lower half), but we do *not* request the 833 * full upper and lower rectangle, only the part of the upper/lower rectangle that 834 * actually has something in it. 843 * Area "a" now contains the hull that we would like to download data for. however we 844 * can only download rectangles, so the following is an attempt at finding a number of 845 * rectangles to download. 846 * 847 * The idea is simply: Start out with the full bounding box. If it is too large, then 848 * split it in half and repeat recursively for each half until you arrive at something 849 * small enough to download. The algorithm is improved by always using the intersection 850 * between the rectangle and the actual desired area. For example, if you have a track 851 * that goes like this: +----+ | /| | / | | / | |/ | +----+ then we would first look at 852 * downloading the whole rectangle (assume it's too big), after that we split it in half 853 * (upper and lower half), but we donot request the full upper and lower rectangle, only 854 * the part of the upper/lower rectangle that actually has something in it. 835 855 */ 836 856 … … 841 861 msg = new JPanel(new GridBagLayout()); 842 862 843 msg.add(new JLabel(tr("<html>This action will require {0} individual<br>download requests. Do you wish<br>to continue?</html>", 844 toDownload.size())), GBC.eol()); 845 846 if (toDownload.size() > 1 && JOptionPane.showConfirmDialog(Main.parent, msg, 847 tr("Download from OSM along this track"), 848 JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) 849 return; 850 863 msg 864 .add( 865 new JLabel( 866 tr( 867 "<html>This action will require {0} individual<br>download requests. Do you wish<br>to continue?</html>", 868 toDownload.size())), GBC.eol()); 869 870 if (toDownload.size() > 1) { 871 ret = OptionPaneUtil.showConfirmationDialog( 872 Main.parent, 873 msg, 874 tr("Download from OSM along this track"), 875 JOptionPane.OK_CANCEL_OPTION, 876 JOptionPane.PLAIN_MESSAGE 877 ); 878 switch(ret) { 879 case JOptionPane.CANCEL_OPTION: 880 case JOptionPane.CLOSED_OPTION: 881 return; 882 default: 883 // continue 884 } 885 } 851 886 new DownloadOsmTaskList().download(false, toDownload, new PleaseWaitProgressMonitor()); 852 887 } … … 857 892 // intersect with sought-after area 858 893 tmp.intersect(a); 859 if (tmp.isEmpty()) return; 894 if (tmp.isEmpty()) 895 return; 860 896 Rectangle2D bounds = tmp.getBounds2D(); 861 897 if (bounds.getWidth() * bounds.getHeight() > max_area) { … … 865 901 if (bounds.getWidth() > bounds.getHeight()) { 866 902 // rectangles that are wider than high are split into a left and right half, 867 r1 = new Rectangle2D.Double(bounds.getX(), bounds.getY(), bounds.getWidth()/2, bounds.getHeight()); 868 r2 = new Rectangle2D.Double(bounds.getX()+bounds.getWidth()/2, bounds.getY(), bounds.getWidth()/2, bounds.getHeight()); 903 r1 = new Rectangle2D.Double(bounds.getX(), bounds.getY(), bounds.getWidth() / 2, bounds.getHeight()); 904 r2 = new Rectangle2D.Double(bounds.getX() + bounds.getWidth() / 2, bounds.getY(), 905 bounds.getWidth() / 2, bounds.getHeight()); 869 906 } else { 870 907 // others into a top and bottom half. 871 r1 = new Rectangle2D.Double(bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight()/2); 872 r2 = new Rectangle2D.Double(bounds.getX(), bounds.getY()+bounds.getHeight()/2, bounds.getWidth(), bounds.getHeight()/2); 908 r1 = new Rectangle2D.Double(bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight() / 2); 909 r2 = new Rectangle2D.Double(bounds.getX(), bounds.getY() + bounds.getHeight() / 2, bounds.getWidth(), 910 bounds.getHeight() / 2); 873 911 } 874 912 addToDownload(a, r1, results, max_area); … … 880 918 881 919 /** 882 * Makes a new marker layer derived from this GpxLayer containing at least one 883 * audio marker which the given audio file is associated with. 884 * Markers are derived from the following 885 * (a) explict waypoints in the GPX layer, or 886 * (b) named trackpoints in the GPX layer, or 887 * (d) timestamp on the wav file 888 * (e) (in future) voice recognised markers in the sound recording 889 * (f) a single marker at the beginning of the track 920 * Makes a new marker layer derived from this GpxLayer containing at least one audio marker 921 * which the given audio file is associated with. Markers are derived from the following (a) 922 * explict waypoints in the GPX layer, or (b) named trackpoints in the GPX layer, or (d) 923 * timestamp on the wav file (e) (in future) voice recognised markers in the sound recording (f) 924 * a single marker at the beginning of the track 890 925 * @param wavFile : the file to be associated with the markers in the new marker layer 891 926 */ … … 895 930 boolean timedMarkersOmitted = false; 896 931 boolean untimedMarkersOmitted = false; 897 double snapDistance = Main.pref.getDouble("marker.audiofromuntimedwaypoints.distance", 1.0e-3); /* about 25m */ 932 double snapDistance = Main.pref.getDouble("marker.audiofromuntimedwaypoints.distance", 1.0e-3); /* 933 * about 934 * 25 935 * m 936 */ 898 937 WayPoint wayPointFromTimeStamp = null; 899 938 900 939 // determine time of first point in track 901 940 double firstTime = -1.0; 902 if (data.tracks != null && ! 941 if (data.tracks != null && !data.tracks.isEmpty()) { 903 942 for (GpxTrack track : data.tracks) { 904 943 if (track.trackSegs == null) { … … 920 959 } 921 960 if (firstTime < 0.0) { 922 JOptionPane.showMessageDialog(Main.parent, tr("No GPX track available in layer to associate audio with.")); 961 OptionPaneUtil.showMessageDialog( 962 Main.parent, 963 tr("No GPX track available in layer to associate audio with."), 964 tr("Error"), 965 JOptionPane.ERROR_MESSAGE 966 ); 923 967 return; 924 968 } 925 969 926 970 // (a) try explicit timestamped waypoints - unless suppressed 927 if (Main.pref.getBoolean("marker.audiofromexplicitwaypoints", true) && 928 data.waypoints != null && ! data.waypoints.isEmpty()) 929 { 971 if (Main.pref.getBoolean("marker.audiofromexplicitwaypoints", true) && data.waypoints != null 972 && !data.waypoints.isEmpty()) { 930 973 for (WayPoint w : data.waypoints) { 931 974 if (w.time > firstTime) { … … 938 981 939 982 // (b) try explicit waypoints without timestamps - unless suppressed 940 if (Main.pref.getBoolean("marker.audiofromuntimedwaypoints", true) && 941 data.waypoints != null && ! data.waypoints.isEmpty()) 942 { 983 if (Main.pref.getBoolean("marker.audiofromuntimedwaypoints", true) && data.waypoints != null 984 && !data.waypoints.isEmpty()) { 943 985 for (WayPoint w : data.waypoints) { 944 if (waypoints.contains(w)) { continue; } 986 if (waypoints.contains(w)) { 987 continue; 988 } 945 989 WayPoint wNear = nearestPointOnTrack(w.getEastNorth(), snapDistance); 946 990 if (wNear != null) { … … 958 1002 959 1003 // (c) use explicitly named track points, again unless suppressed 960 if ((Main.pref.getBoolean("marker.audiofromnamedtrackpoints", false)) && 961 data.tracks != null && ! data.tracks.isEmpty()) 962 { 1004 if ((Main.pref.getBoolean("marker.audiofromnamedtrackpoints", false)) && data.tracks != null 1005 && !data.tracks.isEmpty()) { 963 1006 for (GpxTrack track : data.tracks) { 964 1007 if (track.trackSegs == null) { … … 976 1019 977 1020 // (d) use timestamp of file as location on track 978 if ((Main.pref.getBoolean("marker.audiofromwavtimestamps", false)) && 979 data.tracks != null && ! data.tracks.isEmpty())980 {981 double lastModified = wavFile.lastModified() / 1000.0; // lastModified is inmilliseconds1021 if ((Main.pref.getBoolean("marker.audiofromwavtimestamps", false)) && data.tracks != null 1022 && !data.tracks.isEmpty()) { 1023 double lastModified = wavFile.lastModified() / 1000.0; // lastModified is in 1024 // milliseconds 982 1025 double duration = AudioUtil.getCalibratedDuration(wavFile); 983 1026 double startTime = lastModified - duration; 984 startTime = firstStartTime + (startTime - firstStartTime) /985 Main.pref.getDouble("audio.calibration", "1.0" /* default, ratio */);1027 startTime = firstStartTime + (startTime - firstStartTime) 1028 / Main.pref.getDouble("audio.calibration", "1.0" /* default, ratio */); 986 1029 WayPoint w1 = null; 987 1030 WayPoint w2 = null; … … 1008 1051 timedMarkersOmitted = true; 1009 1052 } else { 1010 wayPointFromTimeStamp = new WayPoint(w1.getCoor().interpolate( 1011 w2.getCoor(), (startTime - w1.time)/(w2.time - w1.time)));1053 wayPointFromTimeStamp = new WayPoint(w1.getCoor().interpolate(w2.getCoor(), 1054 (startTime - w1.time) / (w2.time - w1.time))); 1012 1055 wayPointFromTimeStamp.time = startTime; 1013 1056 String name = wavFile.getName(); 1014 1057 int dot = name.lastIndexOf("."); 1015 if (dot > 0) { name = name.substring(0, dot); } 1058 if (dot > 0) { 1059 name = name.substring(0, dot); 1060 } 1016 1061 wayPointFromTimeStamp.attr.put("name", name); 1017 1062 waypoints.add(wayPointFromTimeStamp); … … 1022 1067 1023 1068 // (f) simply add a single marker at the start of the track 1024 if ((Main.pref.getBoolean("marker.audiofromstart") || waypoints.isEmpty()) && 1025 data.tracks != null && ! data.tracks.isEmpty()) 1026 { 1069 if ((Main.pref.getBoolean("marker.audiofromstart") || waypoints.isEmpty()) && data.tracks != null 1070 && !data.tracks.isEmpty()) { 1027 1071 boolean gotOne = false; 1028 1072 for (GpxTrack track : data.tracks) { … … 1071 1115 name = AudioMarker.inventName(offset); 1072 1116 } 1073 AudioMarker am = AudioMarker.create(w.getCoor(), 1074 name, uri, ml, w.time, offset); 1075 /* timeFromAudio intended for future use to shift markers of this type on synchronization */ 1117 AudioMarker am = AudioMarker.create(w.getCoor(), name, uri, ml, w.time, offset); 1118 /* 1119 * timeFromAudio intended for future use to shift markers of this type on 1120 * synchronization 1121 */ 1076 1122 if (w == wayPointFromTimeStamp) { 1077 1123 am.timeFromAudio = true; … … 1081 1127 1082 1128 if (timedMarkersOmitted) { 1083 JOptionPane.showMessageDialog(Main.parent, 1129 JOptionPane 1130 .showMessageDialog( 1131 Main.parent, 1084 1132 tr("Some waypoints with timestamps from before the start of the track or after the end were omitted or moved to the start.")); 1085 1133 } 1086 1134 if (untimedMarkersOmitted) { 1087 JOptionPane.showMessageDialog(Main.parent, 1135 JOptionPane 1136 .showMessageDialog( 1137 Main.parent, 1088 1138 tr("Some waypoints which were too far from the track to sensibly estimate their time were omitted.")); 1089 1139 } … … 1091 1141 1092 1142 /** 1093 * Makes a WayPoint at the projection of point P onto the track providing P is 1094 * less thantolerance away from the track1095 1143 * Makes a WayPoint at the projection of point P onto the track providing P is less than 1144 * tolerance away from the track 1145 * 1096 1146 * @param P : the point to determine the projection for 1097 1147 * @param tolerance : must be no further than this from the track 1098 * @return the closest point on the track to P, which may be the 1099 * first or last point if off the end of a segment, or may be null if 1100 * nothing close enough 1148 * @return the closest point on the track to P, which may be the first or last point if off the 1149 * end of a segment, or may be null if nothing close enough 1101 1150 */ 1102 1151 public WayPoint nearestPointOnTrack(EastNorth P, double tolerance) { 1103 1152 /* 1104 * assume the coordinates of P are xp,yp, and those of a section of track 1105 * between two trackpoints are R=xr,yr and S=xs,ys. Let N be the projected point. 1106 * 1107 * The equation of RS is Ax + By + C = 0 where 1108 * A = ys - yr 1109 * B = xr - xs 1110 * C = - Axr - Byr 1111 * 1153 * assume the coordinates of P are xp,yp, and those of a section of track between two 1154 * trackpoints are R=xr,yr and S=xs,ys. Let N be the projected point. 1155 * 1156 * The equation of RS is Ax + By + C = 0 where A = ys - yr B = xr - xs C = - Axr - Byr 1157 * 1112 1158 * Also, note that the distance RS^2 is A^2 + B^2 1113 * 1159 * 1114 1160 * If RS^2 == 0.0 ignore the degenerate section of track 1115 * 1116 * PN^2 = (Axp + Byp + C)^2 / RS^2 1117 * that is the distance from P to the line 1118 * 1119 * so if PN^2 is less than PNmin^2 (initialized to tolerance) we can reject 1120 * the line; otherwise... 1121 * determine if the projected poijnt lies within the bounds of the line: 1122 * PR^2 - PN^2 <= RS^2 and PS^2 - PN^2 <= RS^2 1123 * 1124 * where PR^2 = (xp - xr)^2 + (yp-yr)^2 1125 * and PS^2 = (xp - xs)^2 + (yp-ys)^2 1126 * 1127 * If so, calculate N as 1128 * xn = xr + (RN/RS) B 1129 * yn = y1 + (RN/RS) A 1130 * 1161 * 1162 * PN^2 = (Axp + Byp + C)^2 / RS^2 that is the distance from P to the line 1163 * 1164 * so if PN^2 is less than PNmin^2 (initialized to tolerance) we can reject the line; 1165 * otherwise... determine if the projected poijnt lies within the bounds of the line: PR^2 - 1166 * PN^2 <= RS^2 and PS^2 - PN^2 <= RS^2 1167 * 1168 * where PR^2 = (xp - xr)^2 + (yp-yr)^2 and PS^2 = (xp - xs)^2 + (yp-ys)^2 1169 * 1170 * If so, calculate N as xn = xr + (RN/RS) B yn = y1 + (RN/RS) A 1171 * 1131 1172 * where RN = sqrt(PR^2 - PN^2) 1132 1173 */ … … 1138 1179 double py = P.north(); 1139 1180 double rx = 0.0, ry = 0.0, sx, sy, x, y; 1140 if (data.tracks == null) return null; 1181 if (data.tracks == null) 1182 return null; 1141 1183 for (GpxTrack track : data.tracks) { 1142 1184 if (track.trackSegs == null) { … … 1164 1206 double A = sy - ry; 1165 1207 double B = rx - sx; 1166 double C = - 1208 double C = -A * rx - B * ry; 1167 1209 double RSsq = A * A + B * B; 1168 1210 if (RSsq == 0.0) { … … 1179 1221 double PSsq = x * x + y * y; 1180 1222 if (PRsq - PNsq <= RSsq && PSsq - PNsq <= RSsq) { 1181 double RNoverRS = Math.sqrt((PRsq - PNsq) /RSsq);1223 double RNoverRS = Math.sqrt((PRsq - PNsq) / RSsq); 1182 1224 double nx = rx - RNoverRS * B; 1183 1225 double ny = ry + RNoverRS * A; … … 1208 1250 } 1209 1251 } 1210 if (bestEN == null) return null; 1252 if (bestEN == null) 1253 return null; 1211 1254 WayPoint best = new WayPoint(Main.proj.eastNorth2latlon(bestEN)); 1212 1255 best.time = bestTime; -
trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r1843 r1865 58 58 import org.openstreetmap.josm.data.osm.visitor.SimplePaintVisitor; 59 59 import org.openstreetmap.josm.gui.MapView; 60 import org.openstreetmap.josm.gui.OptionPaneUtil; 60 61 import org.openstreetmap.josm.gui.dialogs.LayerListDialog; 61 62 import org.openstreetmap.josm.gui.dialogs.LayerListPopup; … … 295 296 } 296 297 if (numNewConflicts > 0) { 297 JOptionPane.showMessageDialog(Main.parent,tr("There were {0} conflicts during import.", numNewConflicts)); 298 OptionPaneUtil.showMessageDialog( 299 Main.parent, 300 tr("There were {0} conflicts during import.", numNewConflicts), 301 tr("Warning"), 302 JOptionPane.WARNING_MESSAGE 303 ); 298 304 } 299 305 } -
trunk/src/org/openstreetmap/josm/gui/layer/RawGpsLayer.java
r1838 r1865 34 34 import javax.swing.JSeparator; 35 35 import javax.swing.JTextField; 36 import javax.swing.text.html.Option; 36 37 37 38 import org.openstreetmap.josm.Main; … … 47 48 import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil; 48 49 import org.openstreetmap.josm.gui.MapView; 50 import org.openstreetmap.josm.gui.OptionPaneUtil; 49 51 import org.openstreetmap.josm.gui.dialogs.LayerListDialog; 50 52 import org.openstreetmap.josm.gui.dialogs.LayerListPopup; … … 218 220 group.setSelected(r[0].getModel(), true); 219 221 } 220 int answer = JOptionPane.showConfirmDialog(Main.parent, panel, tr("Select line drawing options"), JOptionPane.OK_CANCEL_OPTION); 222 int answer = OptionPaneUtil.showConfirmationDialog( 223 Main.parent, 224 panel, 225 tr("Select line drawing options"), 226 JOptionPane.OK_CANCEL_OPTION, 227 JOptionPane.PLAIN_MESSAGE 228 ); 221 229 if (answer == JOptionPane.CANCEL_OPTION) 222 230 return; … … 235 243 JColorChooser c = new JColorChooser(Main.pref.getColor(marktr("gps point"), "layer "+name, Color.gray)); 236 244 Object[] options = new Object[]{tr("OK"), tr("Cancel"), tr("Default")}; 237 int answer = JOptionPane.showOptionDialog(Main.parent, c, tr("Choose a color"), JOptionPane.OK_CANCEL_OPTION, 238 JOptionPane.PLAIN_MESSAGE, null, options, options[0]); 245 int answer = OptionPaneUtil.showOptionDialog( 246 Main.parent, 247 c, 248 tr("Choose a color"), 249 JOptionPane.OK_CANCEL_OPTION, 250 JOptionPane.PLAIN_MESSAGE, options, options[0]); 239 251 switch (answer) { 240 case 0:241 Main.pref.putColor("layer "+name, c.getColor());242 break;243 case 1:244 return;245 case 2:246 Main.pref.putColor("layer "+name, null);247 break;252 case 0: 253 Main.pref.putColor("layer "+name, c.getColor()); 254 break; 255 case 1: 256 return; 257 case 2: 258 Main.pref.putColor("layer "+name, null); 259 break; 248 260 } 249 261 Main.map.repaint(); -
trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayer.java
r1724 r1865 34 34 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 35 35 import org.openstreetmap.josm.gui.MapView; 36 import org.openstreetmap.josm.gui.OptionPaneUtil; 36 37 import org.openstreetmap.josm.gui.dialogs.LayerListDialog; 37 38 import org.openstreetmap.josm.gui.dialogs.LayerListPopup; … … 90 91 if (wpt_has_link) { 91 92 for (GpxLink oneLink : (Collection<GpxLink>) wpt.attr.get(GpxData.META_LINKS)) { 92 if (!oneLink.uri.equals(lastLinkedFile))firstTime = time; 93 if (!oneLink.uri.equals(lastLinkedFile)) { 94 firstTime = time; 95 } 93 96 lastLinkedFile = oneLink.uri; 94 97 break; … … 96 99 } 97 100 Marker m = Marker.createMarker(wpt, indata.storageFile, this, time, time - firstTime); 98 if (m != null) 101 if (m != null) { 99 102 data.add(m); 103 } 100 104 } 101 105 … … 118 122 return; 119 123 mousePressed = true; 120 if (visible) 124 if (visible) { 121 125 Main.map.mapView.repaint(); 126 } 122 127 } 123 128 @Override public void mouseReleased(MouseEvent ev) { … … 129 134 if (ev.getPoint() != null) { 130 135 for (Marker mkr : data) { 131 if (mkr.containsPoint(ev.getPoint())) 136 if (mkr.containsPoint(ev.getPoint())) { 132 137 mkr.actionPerformed(new ActionEvent(this, 0, null)); 138 } 133 139 } 134 140 } … … 183 189 184 190 @Override public void visitBoundingBox(BoundingXYVisitor v) { 185 for (Marker mkr : data) 191 for (Marker mkr : data) { 186 192 v.visit(mkr.getEastNorth()); 193 } 187 194 } 188 195 … … 198 205 JColorChooser c = new JColorChooser(getColor(name)); 199 206 Object[] options = new Object[]{tr("OK"), tr("Cancel"), tr("Default")}; 200 int answer = JOptionPane.showOptionDialog(Main.parent, c, tr("Choose a color"), JOptionPane.OK_CANCEL_OPTION, 201 JOptionPane.PLAIN_MESSAGE, null, options, options[0]); 207 int answer = OptionPaneUtil.showOptionDialog( 208 Main.parent, 209 c, 210 tr("Choose a color"), 211 JOptionPane.OK_CANCEL_OPTION, 212 JOptionPane.PLAIN_MESSAGE, 213 options, 214 options[0] 215 ); 202 216 switch (answer) { 203 217 case 0: … … 219 233 public void actionPerformed(ActionEvent e) { 220 234 if (! AudioPlayer.paused()) { 221 JOptionPane.showMessageDialog(Main.parent,tr("You need to pause audio at the moment when you hear your synchronization cue.")); 235 OptionPaneUtil.showMessageDialog( 236 Main.parent, 237 tr("You need to pause audio at the moment when you hear your synchronization cue."), 238 tr("Warning"), 239 JOptionPane.WARNING_MESSAGE 240 ); 222 241 return; 223 242 } 224 243 AudioMarker recent = AudioMarker.recentlyPlayedMarker(); 225 244 if (synchronizeAudioMarkers(recent)) { 226 JOptionPane.showMessageDialog(Main.parent, tr("Audio synchronized at point {0}.", recent.text)); 245 OptionPaneUtil.showMessageDialog( 246 Main.parent, 247 tr("Audio synchronized at point {0}.", recent.text), 248 tr("Information"), 249 JOptionPane.INFORMATION_MESSAGE 250 ); 227 251 } else { 228 JOptionPane.showMessageDialog(Main.parent,tr("Unable to synchronize in layer being played.")); 252 OptionPaneUtil.showMessageDialog( 253 Main.parent, 254 tr("Unable to synchronize in layer being played."), 255 tr("Error"), 256 JOptionPane.ERROR_MESSAGE 257 ); 229 258 } 230 259 } … … 236 265 public void actionPerformed(ActionEvent e) { 237 266 if (! AudioPlayer.paused()) { 238 JOptionPane.showMessageDialog(Main.parent,tr("You need to have paused audio at the point on the track where you want the marker.")); 267 OptionPaneUtil.showMessageDialog( 268 Main.parent, 269 tr("You need to have paused audio at the point on the track where you want the marker."), 270 tr("Warning"), 271 JOptionPane.WARNING_MESSAGE 272 ); 239 273 return; 240 274 } … … 285 319 URL url = startMarker.url(); 286 320 for (Marker m : data) { 287 if (m == startMarker) 321 if (m == startMarker) { 288 322 seenStart = true; 323 } 289 324 if (seenStart) { 290 325 AudioMarker ma = (AudioMarker) m; // it must be an AudioMarker 291 if (ma.url().equals(url)) 326 if (ma.url().equals(url)) { 292 327 ma.adjustOffset(adjustment); 328 } 293 329 } 294 330 } … … 308 344 } 309 345 if (am == null) { 310 JOptionPane.showMessageDialog(Main.parent,tr("No existing audio markers in this layer to offset from.")); 346 OptionPaneUtil.showMessageDialog( 347 Main.parent, 348 tr("No existing audio markers in this layer to offset from."), 349 tr("Error"), 350 JOptionPane.ERROR_MESSAGE 351 ); 311 352 return null; 312 353 } … … 314 355 // make our new marker 315 356 AudioMarker newAudioMarker = AudioMarker.create(coor, 316 AudioMarker.inventName(offset), AudioPlayer.url().toString(), this, time, offset);357 AudioMarker.inventName(offset), AudioPlayer.url().toString(), this, time, offset); 317 358 318 359 // insert it at the right place in a copy the collection … … 333 374 334 375 if (newAudioMarker != null) { 335 if (am != null) 376 if (am != null) { 336 377 newAudioMarker.adjustOffset(am.syncOffset()); // i.e. same as predecessor 378 } 337 379 newData.add(newAudioMarker); // insert at end 338 380 } … … 363 405 for (Marker marker : markerLayer.data) { 364 406 if (marker == startMarker) { 365 if (next) 407 if (next) { 366 408 nextTime = true; 367 else {368 if (previousMarker == null) 409 } else { 410 if (previousMarker == null) { 369 411 previousMarker = startMarker; // if no previous one, play the first one again 412 } 370 413 return previousMarker; 371 414 } … … 389 432 return; 390 433 Layer l = Main.map.mapView.getActiveLayer(); 391 if(l != null) 434 if(l != null) { 392 435 m = getAdjacentMarker(startMarker, next, l); 436 } 393 437 if(m == null) 394 438 { … … 396 440 { 397 441 m = getAdjacentMarker(startMarker, next, layer); 398 if(m != null) 399 break; 400 } 401 } 402 if(m != null) 442 if(m != null) { 443 break; 444 } 445 } 446 } 447 if(m != null) { 403 448 ((AudioMarker)m).play(); 449 } 404 450 } 405 451 -
trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/PlayHeadMarker.java
r1724 r1865 26 26 import org.openstreetmap.josm.data.gpx.WayPoint; 27 27 import org.openstreetmap.josm.gui.MapView; 28 import org.openstreetmap.josm.gui.OptionPaneUtil; 28 29 import org.openstreetmap.josm.gui.layer.GpxLayer; 29 30 import org.openstreetmap.josm.tools.AudioPlayer; … … 61 62 private PlayHeadMarker() { 62 63 super(new LatLon(0.0,0.0), "", 63 Main.pref.get("marker.audiotracericon", "audio-tracer"),64 null, -1.0, 0.0);64 Main.pref.get("marker.audiotracericon", "audio-tracer"), 65 null, -1.0, 0.0); 65 66 enabled = Main.pref.getBoolean("marker.traceaudio", true); 66 67 if (! enabled) return; … … 87 88 Point screen = Main.map.mapView.getPoint(getEastNorth()); 88 89 Rectangle r = new Rectangle(screen.x, screen.y, symbol.getIconWidth(), 89 symbol.getIconHeight());90 symbol.getIconHeight()); 90 91 return r.contains(p); 91 92 } … … 96 97 */ 97 98 public void startDrag() { 98 if (timer != null) 99 if (timer != null) { 99 100 timer.stop(); 101 } 100 102 wasPlaying = AudioPlayer.playing(); 101 103 if (wasPlaying) { … … 109 111 */ 110 112 private void endDrag(boolean reset) { 111 if (! wasPlaying || reset) 113 if (! wasPlaying || reset) { 112 114 try { AudioPlayer.pause(); } 113 115 catch (Exception ex) { AudioPlayer.audioMalfunction(ex);} 114 if (reset) 116 } 117 if (reset) { 115 118 setCoor(oldCoor); 119 } 116 120 Main.map.selectMapMode(oldMode); 117 121 Main.map.mapView.repaint(); … … 153 157 if (m instanceof AudioMarker) { 154 158 AudioMarker a = (AudioMarker) m; 155 if (a.time > cw.time) 159 if (a.time > cw.time) { 156 160 break; 161 } 157 162 ca = a; 158 163 } … … 163 168 if (ca == null) { 164 169 /* Not close enough to track, or no audio marker found for some other reason */ 165 JOptionPane.showMessageDialog(Main.parent, tr("You need to drag the play head near to the GPX track whose associated sound track you were playing (after the first marker).")); 170 OptionPaneUtil.showMessageDialog( 171 Main.parent, 172 tr("You need to drag the play head near to the GPX track whose associated sound track you were playing (after the first marker)."), 173 tr("Warning"), 174 JOptionPane.WARNING_MESSAGE 175 ); 166 176 endDrag(true); 167 177 } else { … … 202 212 203 213 /* We found the closest marker: did we actually hit it? */ 204 if (ca != null && ! ca.containsPoint(startPoint)) ca = null; 214 if (ca != null && ! ca.containsPoint(startPoint)) { 215 ca = null; 216 } 205 217 206 218 /* If we didn't hit an audio marker, we need to create one at the nearest point on the track */ … … 211 223 WayPoint cw = recent.parentLayer.fromLayer.nearestPointOnTrack(en, enPlus25px.east() - en.east()); 212 224 if (cw == null) { 213 JOptionPane.showMessageDialog(Main.parent, tr("You need to SHIFT-drag the play head onto an audio marker or onto the track point where you want to synchronize.")); 225 OptionPaneUtil.showMessageDialog( 226 Main.parent, 227 tr("You need to SHIFT-drag the play head onto an audio marker or onto the track point where you want to synchronize."), 228 tr("Warning"), 229 JOptionPane.WARNING_MESSAGE 230 ); 214 231 endDrag(true); 215 232 return; … … 221 238 if(ca == null) 222 239 { 223 JOptionPane.showMessageDialog(Main.parent,tr("Unable to create new audio marker.")); 240 OptionPaneUtil.showMessageDialog( 241 Main.parent, 242 tr("Unable to create new audio marker."), 243 tr("Error"), 244 JOptionPane.ERROR_MESSAGE 245 ); 224 246 endDrag(true); 225 247 } 226 248 else if (recent.parentLayer.synchronizeAudioMarkers(ca)) { 227 JOptionPane.showMessageDialog(Main.parent, tr("Audio synchronized at point {0}.", ca.text)); 249 OptionPaneUtil.showMessageDialog( 250 Main.parent, 251 tr("Audio synchronized at point {0}.", ca.text), 252 tr("Information"), 253 JOptionPane.INFORMATION_MESSAGE 254 ); 228 255 setCoor(ca.getCoor()); 229 256 endDrag(false); 230 257 } else { 231 JOptionPane.showMessageDialog(Main.parent,tr("Unable to synchronize in layer being played.")); 258 OptionPaneUtil.showMessageDialog( 259 Main.parent, 260 tr("Unable to synchronize in layer being played."), 261 tr("Error"), 262 JOptionPane.ERROR_MESSAGE 263 ); 232 264 endDrag(true); 233 265 } … … 264 296 return; 265 297 double audioTime = recentlyPlayedMarker.time + 266 267 268 298 AudioPlayer.position() - 299 recentlyPlayedMarker.offset - 300 recentlyPlayedMarker.syncOffset; 269 301 if (Math.abs(audioTime - time) < animationInterval) 270 302 return; … … 289 321 w1 = w; 290 322 } 291 if (w2 != null) break; 292 } 293 if (w2 != null) break; 323 if (w2 != null) { 324 break; 325 } 326 } 327 if (w2 != null) { 328 break; 329 } 294 330 } 295 331 … … 297 333 return; 298 334 setEastNorth(w2 == null ? 299 w1.getEastNorth() :300 w1.getEastNorth().interpolate(w2.getEastNorth(),301 (audioTime - w1.time)/(w2.time - w1.time)));335 w1.getEastNorth() : 336 w1.getEastNorth().interpolate(w2.getEastNorth(), 337 (audioTime - w1.time)/(w2.time - w1.time))); 302 338 time = audioTime; 303 339 Main.map.mapView.repaint(); -
trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/WebMarker.java
r1169 r1865 11 11 import org.openstreetmap.josm.Main; 12 12 import org.openstreetmap.josm.data.coor.LatLon; 13 import org.openstreetmap.josm.gui.OptionPaneUtil; 13 14 import org.openstreetmap.josm.tools.OpenBrowser; 14 15 … … 39 40 String error = OpenBrowser.displayUrl(webUrl.toString()); 40 41 if (error != null) { 41 JOptionPane.showMessageDialog(Main.parent,42 OptionPaneUtil.showMessageDialog(Main.parent, 42 43 "<html><b>" + 43 44 tr("There was an error while trying to display the URL for this marker") + -
trunk/src/org/openstreetmap/josm/gui/preferences/AdvancedPreference.java
r1742 r1865 30 30 31 31 import org.openstreetmap.josm.Main; 32 import org.openstreetmap.josm.gui.OptionPaneUtil; 32 33 import org.openstreetmap.josm.tools.GBC; 33 34 … … 83 84 { 84 85 data.put((String) model.getValueAt(row, 0), 85 (String) model.getValueAt(row, 1));86 (String) model.getValueAt(row, 1)); 86 87 } 87 88 } … … 89 90 }; 90 91 DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(){ 92 @Override 91 93 public Component getTableCellRendererComponent(JTable table, Object value, 92 boolean isSelected, boolean hasFocus, int row, int column)94 boolean isSelected, boolean hasFocus, int row, int column) 93 95 { 94 96 JLabel label=new JLabel(); … … 96 98 if(s != null) 97 99 { 98 if(s.equals(model.getValueAt(row, 1))) 100 if(s.equals(model.getValueAt(row, 1))) { 99 101 label.setToolTipText(tr("Current value is default.")); 100 else102 } else { 101 103 label.setToolTipText(tr("Default value is ''{0}''.", s)); 102 }103 else104 } 105 } else { 104 106 label.setToolTipText(tr("Default value currently unknown (setting has not been used yet).")); 107 } 105 108 label.setText((String)value); 106 109 return label; … … 147 150 list.addMouseListener(new MouseAdapter(){ 148 151 @Override public void mouseClicked(MouseEvent e) { 149 if (e.getClickCount() == 2) 152 if (e.getClickCount() == 2) { 150 153 editPreference(gui, list); 154 } 151 155 } 152 156 }); … … 157 161 for (String s : defaults.keySet()) 158 162 { 159 if(!ts.contains(s)) 163 if(!ts.contains(s)) { 160 164 ts.add(s); 165 } 161 166 } 162 167 data = new TreeMap<String, String>(); … … 164 169 { 165 170 String val = Main.pref.get(s); 166 if(val == null) val = ""; 171 if(val == null) { 172 val = ""; 173 } 167 174 data.put(s, val); 168 175 } … … 180 187 // Make 'wmsplugin cache' search for e.g. 'cache.wmsplugin' 181 188 for (String bit : input) { 182 if (!prefKey.contains(bit) && !prefValue.contains(bit)) 189 if (!prefKey.contains(bit) && !prefValue.contains(bit)) { 183 190 canHas = false; 191 } 184 192 } 185 193 … … 196 204 { 197 205 String origValue = orig.get(key); 198 if (origValue == null || !origValue.equals(value)) 206 if (origValue == null || !origValue.equals(value)) { 199 207 Main.pref.put(key, value); 208 } 200 209 orig.remove(key); // processed. 201 210 } 202 211 } 203 for (Entry<String, String> e : orig.entrySet()) 212 for (Entry<String, String> e : orig.entrySet()) { 204 213 Main.pref.put(e.getKey(), null); 214 } 205 215 return false; 206 216 } … … 209 219 private void editPreference(final PreferenceDialog gui, final JTable list) { 210 220 if (list.getSelectedRowCount() != 1) { 211 JOptionPane.showMessageDialog(gui, tr("Please select the row to edit.")); 221 OptionPaneUtil.showMessageDialog( 222 gui, 223 tr("Please select the row to edit."), 224 tr("Warning"), 225 JOptionPane.WARNING_MESSAGE 226 ); 212 227 return; 213 228 } 214 String v = JOptionPane.showInputDialog(tr("New value for {0}", model.getValueAt(list.getSelectedRow(), 0)), model.getValueAt(list.getSelectedRow(), 1)); 229 String v = (String) OptionPaneUtil.showInputDialog( 230 Main.parent, 231 tr("New value for {0}", model.getValueAt(list.getSelectedRow(), 0)), 232 tr("New value"), 233 JOptionPane.QUESTION_MESSAGE, 234 null, 235 null, 236 model.getValueAt(list.getSelectedRow(), 1) 237 ); 215 238 if (v != null) { 216 239 data.put((String) model.getValueAt(list.getSelectedRow(), 0), v); … … 221 244 private void removePreference(final PreferenceDialog gui, final JTable list) { 222 245 if (list.getSelectedRowCount() == 0) { 223 JOptionPane.showMessageDialog(gui, tr("Please select the row to delete.")); 246 OptionPaneUtil.showMessageDialog( 247 gui, 248 tr("Please select the row to delete."), 249 tr("Warning"), 250 JOptionPane.WARNING_MESSAGE 251 ); 224 252 return; 225 253 } … … 238 266 p.add(new JLabel(tr("Value")), GBC.std().insets(0,0,5,0)); 239 267 p.add(value, GBC.eol().insets(5,0,0,0).fill(GBC.HORIZONTAL)); 240 int answer = JOptionPane.showConfirmDialog(gui, p, tr("Enter a new key/value pair"), JOptionPane.OK_CANCEL_OPTION); 268 int answer = OptionPaneUtil.showConfirmationDialog( 269 gui, p, 270 tr("Enter a new key/value pair"), 271 JOptionPane.OK_CANCEL_OPTION, 272 JOptionPane.PLAIN_MESSAGE 273 ); 241 274 if (answer == JOptionPane.OK_OPTION) { 242 275 data.put(key.getText(), value.getText()); -
trunk/src/org/openstreetmap/josm/gui/preferences/ColorPreference.java
r1742 r1865 36 36 import org.openstreetmap.josm.data.osm.visitor.MapPaintVisitor; 37 37 import org.openstreetmap.josm.gui.MapScaler; 38 import org.openstreetmap.josm.gui.OptionPaneUtil; 38 39 import org.openstreetmap.josm.gui.dialogs.ConflictDialog; 39 40 import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer; … … 81 82 Map<String, String> colorKeyList_layer = new TreeMap<String, String>(); 82 83 for(String key : colorMap.keySet()) { 83 if(key.startsWith("layer ")) 84 if(key.startsWith("layer ")) { 84 85 colorKeyList_layer.put(getName(key), key); 85 else if(key.startsWith("mappaint."))86 } else if(key.startsWith("mappaint.")) { 86 87 colorKeyList_mappaint.put(getName(key), key); 87 else88 } else { 88 89 colorKeyList.put(getName(key), key); 90 } 89 91 } 90 92 for (Entry<String, String> k : colorKeyList.entrySet()) { … … 155 157 int sel = colors.getSelectedRow(); 156 158 JColorChooser chooser = new JColorChooser((Color)colors.getValueAt(sel, 1)); 157 int answer = JOptionPane.showConfirmDialog(gui, chooser, 158 tr("Choose a color for {0}", getName((String)colors.getValueAt(sel, 0))), 159 JOptionPane.OK_CANCEL_OPTION); 160 if (answer == JOptionPane.OK_OPTION) 159 int answer = OptionPaneUtil.showConfirmationDialog( 160 gui, chooser, 161 tr("Choose a color for {0}", getName((String)colors.getValueAt(sel, 0))), 162 JOptionPane.OK_CANCEL_OPTION, 163 JOptionPane.PLAIN_MESSAGE); 164 if (answer == JOptionPane.OK_OPTION) { 161 165 colors.setValueAt(chooser.getColor(), sel, 1); 166 } 162 167 } 163 168 }); … … 168 173 String name = (String)colors.getValueAt(sel, 0); 169 174 Color c = Main.pref.getDefaultColor(name); 170 if (c != null) 175 if (c != null) { 171 176 colors.setValueAt(c, sel, 1); 177 } 172 178 } 173 179 }); … … 177 183 for(int i = 0; i < colors.getRowCount(); ++i) 178 184 { 179 String name = (String)colors.getValueAt(i, 0); 180 Color c = Main.pref.getDefaultColor(name); 181 if (c != null) 182 colors.setValueAt(c, i, 1); 185 String name = (String)colors.getValueAt(i, 0); 186 Color c = Main.pref.getDefaultColor(name); 187 if (c != null) { 188 colors.setValueAt(c, i, 1); 189 } 183 190 } 184 191 } … … 257 264 public boolean ok() { 258 265 Boolean ret = false; 259 for(String d : del) 266 for(String d : del) { 260 267 Main.pref.put("color."+d, null); 268 } 261 269 for (int i = 0; i < colors.getRowCount(); ++i) { 262 270 String key = (String)colors.getValueAt(i, 0); 263 271 if(Main.pref.putColor(key, (Color)colors.getValueAt(i, 1))) 264 272 { 265 if(key.startsWith("mappaint.")) 273 if(key.startsWith("mappaint.")) { 266 274 ret = true; 275 } 267 276 } 268 277 } -
trunk/src/org/openstreetmap/josm/gui/preferences/PluginPreference.java
r1742 r1865 22 22 import javax.swing.Scrollable; 23 23 24 import org.openstreetmap.josm.Main; 25 import org.openstreetmap.josm.gui.OptionPaneUtil; 24 26 import org.openstreetmap.josm.plugins.PluginDownloader; 25 27 import org.openstreetmap.josm.plugins.PluginSelection; … … 78 80 p.add(new JLabel(tr("Add JOSM Plugin description URL.")), GBC.eol()); 79 81 final DefaultListModel model = new DefaultListModel(); 80 for (String s : PluginDownloader.getSites()) 82 for (String s : PluginDownloader.getSites()) { 81 83 model.addElement(s); 84 } 82 85 final JList list = new JList(model); 83 86 p.add(new JScrollPane(list), GBC.std().fill()); … … 85 88 buttons.add(new JButton(new AbstractAction(tr("Add")){ 86 89 public void actionPerformed(ActionEvent e) { 87 String s = JOptionPane.showInputDialog(gui, tr("Add JOSM Plugin description URL.")); 88 if (s != null) 90 String s = OptionPaneUtil.showInputDialog( 91 gui, 92 tr("Add JOSM Plugin description URL."), 93 tr("Enter URL"), 94 JOptionPane.QUESTION_MESSAGE 95 ); 96 if (s != null) { 89 97 model.addElement(s); 98 } 90 99 } 91 100 }), GBC.eol().fill(GBC.HORIZONTAL)); … … 93 102 public void actionPerformed(ActionEvent e) { 94 103 if (list.getSelectedValue() == null) { 95 JOptionPane.showMessageDialog(gui, tr("Please select an entry.")); 104 OptionPaneUtil.showMessageDialog( 105 gui, 106 tr("Please select an entry."), 107 tr("Warning"), 108 JOptionPane.WARNING_MESSAGE 109 ); 96 110 return; 97 111 } 98 String s = JOptionPane.showInputDialog(gui, tr("Edit JOSM Plugin description URL."), list.getSelectedValue()); 112 String s = (String)OptionPaneUtil.showInputDialog( 113 Main.parent, 114 tr("Edit JOSM Plugin description URL."), 115 tr("JOSM Plugin description URL"), 116 JOptionPane.QUESTION_MESSAGE, 117 null, 118 null, 119 list.getSelectedValue() 120 ); 99 121 model.setElementAt(s, list.getSelectedIndex()); 100 122 } … … 103 125 public void actionPerformed(ActionEvent event) { 104 126 if (list.getSelectedValue() == null) { 105 JOptionPane.showMessageDialog(gui, tr("Please select an entry.")); 127 OptionPaneUtil.showMessageDialog( 128 gui, 129 tr("Please select an entry."), 130 tr("Warning"), 131 JOptionPane.WARNING_MESSAGE 132 ); 106 133 return; 107 134 } … … 110 137 }), GBC.eol().fill(GBC.HORIZONTAL)); 111 138 p.add(buttons, GBC.eol()); 112 int answer = JOptionPane.showConfirmDialog(gui, p, tr("Configure Plugin Sites"), JOptionPane.OK_CANCEL_OPTION); 139 int answer = OptionPaneUtil.showConfirmationDialog( 140 gui, 141 p, 142 tr("Configure Plugin Sites"), JOptionPane.OK_CANCEL_OPTION, 143 JOptionPane.PLAIN_MESSAGE); 113 144 if (answer != JOptionPane.OK_OPTION) 114 145 return; 115 146 Collection<String> sites = new LinkedList<String>(); 116 for (int i = 0; i < model.getSize(); ++i) 147 for (int i = 0; i < model.getSize(); ++i) { 117 148 sites.add((String)model.getElementAt(i)); 149 } 118 150 PluginDownloader.setSites(sites); 119 151 } -
trunk/src/org/openstreetmap/josm/gui/preferences/PreferenceDialog.java
r1743 r1865 22 22 23 23 import org.openstreetmap.josm.Main; 24 import org.openstreetmap.josm.gui.OptionPaneUtil; 24 25 import org.openstreetmap.josm.plugins.PluginHandler; 25 26 import org.openstreetmap.josm.tools.BugReportExceptionHandler; … … 95 96 for (PreferenceSetting setting : settings) 96 97 { 97 if(setting.ok()) 98 if(setting.ok()) { 98 99 requiresRestart = true; 100 } 99 101 } 100 if (requiresRestart) 101 JOptionPane.showMessageDialog(Main.parent,tr("You have to restart JOSM for some settings to take effect.")); 102 if (requiresRestart) { 103 OptionPaneUtil.showMessageDialog( 104 Main.parent, 105 tr("You have to restart JOSM for some settings to take effect."), 106 tr("Warning"), 107 JOptionPane.WARNING_MESSAGE 108 ); 109 } 102 110 Main.parent.repaint(); 103 111 } … … 139 147 public <T> T getSetting(Class<? extends T> clazz) { 140 148 for (PreferenceSetting setting:settings) { 141 if (clazz.isAssignableFrom(setting.getClass())) {149 if (clazz.isAssignableFrom(setting.getClass())) 142 150 return (T)setting; 143 }144 151 } 145 152 return null; -
trunk/src/org/openstreetmap/josm/gui/preferences/StyleSources.java
r1757 r1865 30 30 31 31 import org.openstreetmap.josm.Main; 32 import org.openstreetmap.josm.gui.OptionPaneUtil; 32 33 import org.openstreetmap.josm.io.MirroredInputStream; 33 34 import org.openstreetmap.josm.tools.GBC; … … 62 63 { 63 64 String s = tr("Short Description: {0}", getName()) + "<br>" + tr("URL: {0}", url); 64 if(author != null) s += "<br>" + tr("Author: {0}", author); 65 if(link != null) s += "<br>" + tr("Webpage: {0}", link); 66 if(description != null) s += "<br>" + tr("Description: {0}", description); 67 if(version != null) s += "<br>" + tr("Version: {0}", version); 65 if(author != null) { 66 s += "<br>" + tr("Author: {0}", author); 67 } 68 if(link != null) { 69 s += "<br>" + tr("Webpage: {0}", link); 70 } 71 if(description != null) { 72 s += "<br>" + tr("Description: {0}", description); 73 } 74 if(version != null) { 75 s += "<br>" + tr("Version: {0}", version); 76 } 68 77 return "<html>" + s + "</html>"; 69 78 } 79 @Override 70 80 public String toString() 71 81 { … … 76 86 class MyCellRenderer extends JLabel implements ListCellRenderer { 77 87 public Component getListCellRendererComponent(JList list, Object value, 78 int index, boolean isSelected, boolean cellHasFocus)88 int index, boolean isSelected, boolean cellHasFocus) 79 89 { 80 90 String s = value.toString(); … … 107 117 108 118 Collection<String> sources = Main.pref.getCollection(pref, null); 109 if(sources != null) 110 for(String s : sources) 119 if(sources != null) { 120 for(String s : sources) { 111 121 ((DefaultListModel)sourcesList.getModel()).addElement(s); 122 } 123 } 112 124 113 125 JButton iconadd = null; … … 119 131 iconsList = new JList(new DefaultListModel()); 120 132 sources = Main.pref.getCollection(iconpref, null); 121 if(sources != null) 122 for(String s : sources) 133 if(sources != null) { 134 for(String s : sources) { 123 135 ((DefaultListModel)iconsList.getModel()).addElement(s); 136 } 137 } 124 138 125 139 iconadd = new JButton(tr("Add")); 126 140 iconadd.addActionListener(new ActionListener(){ 127 141 public void actionPerformed(ActionEvent e) { 128 String source = JOptionPane.showInputDialog(Main.parent, tr("Icon paths")); 129 if (source != null) 142 String source = OptionPaneUtil.showInputDialog( 143 Main.parent, 144 tr("Icon paths"), 145 tr("Icon paths"), 146 JOptionPane.QUESTION_MESSAGE 147 ); 148 if (source != null) { 130 149 ((DefaultListModel)iconsList.getModel()).addElement(source); 150 } 131 151 } 132 152 }); … … 135 155 iconedit.addActionListener(new ActionListener(){ 136 156 public void actionPerformed(ActionEvent e) { 137 if (sourcesList.getSelectedIndex() == -1) 138 JOptionPane.showMessageDialog(Main.parent, tr("Please select the row to edit.")); 139 else { 140 String source = JOptionPane.showInputDialog(Main.parent, 141 tr("Icon paths"), iconsList.getSelectedValue()); 142 if (source != null) 157 if (sourcesList.getSelectedIndex() == -1) { 158 OptionPaneUtil.showMessageDialog( 159 Main.parent, 160 tr("Please select the row to edit."), 161 tr("Warning"), 162 JOptionPane.WARNING_MESSAGE 163 ); 164 } else { 165 String source = (String)OptionPaneUtil.showInputDialog( 166 Main.parent, 167 tr("Icon paths"), 168 tr("Icon paths"), 169 JOptionPane.QUESTION_MESSAGE, 170 null, 171 null, 172 iconsList.getSelectedValue() 173 ); 174 if (source != null) { 143 175 ((DefaultListModel)iconsList.getModel()).setElementAt(source, iconsList.getSelectedIndex()); 176 } 144 177 } 145 178 } … … 149 182 icondelete.addActionListener(new ActionListener(){ 150 183 public void actionPerformed(ActionEvent e) { 151 if (iconsList.getSelectedIndex() == -1) 152 JOptionPane.showMessageDialog(Main.parent, tr("Please select the row to delete.")); 153 else { 184 if (iconsList.getSelectedIndex() == -1) { 185 OptionPaneUtil.showMessageDialog( 186 Main.parent, tr("Please select the row to delete."), 187 tr("Warning"), 188 JOptionPane.WARNING_MESSAGE); 189 } else { 154 190 ((DefaultListModel)iconsList.getModel()).remove(iconsList.getSelectedIndex()); 155 191 } … … 161 197 add.addActionListener(new ActionListener(){ 162 198 public void actionPerformed(ActionEvent e) { 163 String source = JOptionPane.showInputDialog(Main.parent, name); 164 if (source != null) 199 String source = OptionPaneUtil.showInputDialog( 200 Main.parent, 201 name, 202 name, 203 JOptionPane.QUESTION_MESSAGE); 204 if (source != null) { 165 205 ((DefaultListModel)sourcesList.getModel()).addElement(source); 206 } 166 207 } 167 208 }); … … 170 211 edit.addActionListener(new ActionListener(){ 171 212 public void actionPerformed(ActionEvent e) { 172 if (sourcesList.getSelectedIndex() == -1) 173 JOptionPane.showMessageDialog(Main.parent, tr("Please select the row to edit.")); 174 else { 175 String source = JOptionPane.showInputDialog(Main.parent, 176 name, sourcesList.getSelectedValue()); 177 if (source != null) 213 if (sourcesList.getSelectedIndex() == -1) { 214 OptionPaneUtil.showMessageDialog( 215 Main.parent, tr("Please select the row to edit."), 216 tr("Warning"), JOptionPane.WARNING_MESSAGE); 217 } else { 218 String source = (String)OptionPaneUtil.showInputDialog( 219 Main.parent, 220 name, 221 name, 222 JOptionPane.QUESTION_MESSAGE, 223 null, 224 null, 225 sourcesList.getSelectedValue() 226 ); 227 if (source != null) { 178 228 ((DefaultListModel)sourcesList.getModel()).setElementAt(source, sourcesList.getSelectedIndex()); 229 } 179 230 } 180 231 } … … 184 235 delete.addActionListener(new ActionListener(){ 185 236 public void actionPerformed(ActionEvent e) { 186 if (sourcesList.getSelectedIndex() == -1) 187 JOptionPane.showMessageDialog(Main.parent, tr("Please select the row to delete.")); 188 else { 237 if (sourcesList.getSelectedIndex() == -1) { 238 OptionPaneUtil.showMessageDialog(Main.parent, tr("Please select the row to delete."), 239 tr("Warning"), JOptionPane.WARNING_MESSAGE); 240 } else { 189 241 ((DefaultListModel)sourcesList.getModel()).remove(sourcesList.getSelectedIndex()); 190 242 } … … 195 247 copy.addActionListener(new ActionListener(){ 196 248 public void actionPerformed(ActionEvent e) { 197 if (sourcesDefaults.getSelectedIndex() == -1) 198 JOptionPane.showMessageDialog(Main.parent, tr("Please select the row to copy.")); 199 else { 249 if (sourcesDefaults.getSelectedIndex() == -1) { 250 OptionPaneUtil.showMessageDialog( 251 Main.parent, tr("Please select the row to copy."), 252 tr("Warning"), JOptionPane.WARNING_MESSAGE); 253 } else { 200 254 ((DefaultListModel)sourcesList.getModel()).addElement( 201 ((SourceInfo)sourcesDefaults.getSelectedValue()).url);255 ((SourceInfo)sourcesDefaults.getSelectedValue()).url); 202 256 } 203 257 } … … 213 267 { 214 268 ArrayList<String> l = new ArrayList<String>(); 215 for (int i = 0; i < num; ++i) 269 for (int i = 0; i < num; ++i) { 216 270 MirroredInputStream.cleanup((String)sourcesList.getModel().getElementAt(i)); 271 } 217 272 } 218 273 } … … 256 311 { 257 312 ArrayList<String> l = new ArrayList<String>(); 258 for (int i = 0; i < num; ++i) 313 for (int i = 0; i < num; ++i) { 259 314 l.add((String)sourcesList.getModel().getElementAt(i)); 260 if(Main.pref.putCollection(pref, l)) 315 } 316 if(Main.pref.putCollection(pref, l)) { 261 317 changed = true; 262 } 263 else if(Main.pref.putCollection(pref, null)) 318 } 319 } 320 else if(Main.pref.putCollection(pref, null)) { 264 321 changed = true; 322 } 265 323 if(iconsList != null) 266 324 { … … 269 327 { 270 328 ArrayList<String> l = new ArrayList<String>(); 271 for (int i = 0; i < num; ++i) 329 for (int i = 0; i < num; ++i) { 272 330 l.add((String)iconsList.getModel().getElementAt(i)); 273 if(Main.pref.putCollection(iconpref, l)) 331 } 332 if(Main.pref.putCollection(iconpref, l)) { 274 333 changed = true; 275 } 276 else if(Main.pref.putCollection(iconpref, null)) 334 } 335 } 336 else if(Main.pref.putCollection(iconpref, null)) { 277 337 changed = true; 338 } 278 339 } 279 340 return changed; … … 313 374 String key = m.group(1); 314 375 String value = m.group(2); 315 if("author".equals(key) && last.author == null) 376 if("author".equals(key) && last.author == null) { 316 377 last.author = value; 317 else if("version".equals(key))378 } else if("version".equals(key)) { 318 379 last.version = value; 319 else if("link".equals(key) && last.link == null)380 } else if("link".equals(key) && last.link == null) { 320 381 last.link = value; 321 else if("description".equals(key) && last.description == null)382 } else if("description".equals(key) && last.description == null) { 322 383 last.description = value; 323 else if("shortdescription".equals(key) && last.shortdescription == null)384 } else if("shortdescription".equals(key) && last.shortdescription == null) { 324 385 last.shortdescription = value; 325 else if((lang+"author").equals(key))386 } else if((lang+"author").equals(key)) { 326 387 last.author = value; 327 else if((lang+"link").equals(key))388 } else if((lang+"link").equals(key)) { 328 389 last.link = value; 329 else if((lang+"description").equals(key))390 } else if((lang+"description").equals(key)) { 330 391 last.description = value; 331 else if((lang+"shortdescription").equals(key))392 } else if((lang+"shortdescription").equals(key)) { 332 393 last.shortdescription = value; 394 } 333 395 } 334 396 } -
trunk/src/org/openstreetmap/josm/gui/progress/PleaseWaitProgressMonitor.java
r1863 r1865 16 16 17 17 import org.openstreetmap.josm.Main; 18 import org.openstreetmap.josm.gui.OptionPaneUtil; 18 19 import org.openstreetmap.josm.gui.PleaseWaitDialog; 20 import static org.openstreetmap.josm.tools.I18n.tr; 19 21 20 22 … … 73 75 } 74 76 77 @Override 75 78 public void doBeginTask() { 76 79 doInEDT(new Runnable() { … … 80 83 } else if (dialogParent instanceof Dialog) { 81 84 dialog = new PleaseWaitDialog((Dialog)dialogParent); 82 } else {85 } else 83 86 throw new ProgressException("PleaseWaitDialog parent must be either Frame or Dialog"); 84 }85 87 86 88 dialog.cancel.setEnabled(true); … … 94 96 } 95 97 98 @Override 96 99 public void doFinishTask() { 97 100 doInEDT(new Runnable() { … … 103 106 dialog.cancel.removeActionListener(cancelListener); 104 107 if (getErrorMessage() != null) { 105 JOptionPane.showMessageDialog(Main.parent, getErrorMessage()); 108 OptionPaneUtil.showMessageDialog( 109 Main.parent, getErrorMessage(), 110 tr("Error"), 111 JOptionPane.ERROR_MESSAGE); 106 112 } 107 113 dialog = null; … … 111 117 } 112 118 119 @Override 113 120 protected void updateProgress(double progressValue) { 114 121 final int newValue = (int)(progressValue * PROGRESS_BAR_MAX); -
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java
r1843 r1865 44 44 import org.openstreetmap.josm.data.osm.Way; 45 45 import org.openstreetmap.josm.gui.ExtendedDialog; 46 import org.openstreetmap.josm.gui.OptionPaneUtil; 46 47 import org.openstreetmap.josm.gui.QuadStateCheckBox; 47 48 import org.openstreetmap.josm.io.MirroredInputStream; … … 598 599 } catch (IOException e) { 599 600 e.printStackTrace(); 600 JOptionPane.showMessageDialog(Main.parent, tr("Could not read tagging preset source: {0}",source)); 601 OptionPaneUtil.showMessageDialog( 602 Main.parent, 603 tr("Could not read tagging preset source: {0}",source), 604 tr("Error"), 605 JOptionPane.ERROR_MESSAGE 606 ); 601 607 } catch (SAXException e) { 602 608 e.printStackTrace(); 603 JOptionPane.showMessageDialog(Main.parent, tr("Error parsing {0}: ", source)+e.getMessage()); 609 OptionPaneUtil.showMessageDialog( 610 Main.parent, 611 tr("Error parsing {0}: ", source)+e.getMessage(), 612 tr("Error"), 613 JOptionPane.ERROR_MESSAGE 614 ); 604 615 } 605 616 } -
trunk/src/org/openstreetmap/josm/tools/AudioPlayer.java
r1685 r1865 15 15 16 16 import org.openstreetmap.josm.Main; 17 import org.openstreetmap.josm.gui.OptionPaneUtil; 17 18 18 19 /** … … 68 69 interrupt(); 69 70 while (result == Result.WAITING) { sleep(10); /* yield(); */ } 70 if (result == Result.FAILED) { throw exception; } 71 if (result == Result.FAILED) 72 throw exception; 71 73 } 72 74 private void possiblyInterrupt() throws InterruptedException { … … 229 231 try { 230 232 switch (state) { 231 case INITIALIZING: 232 // we're ready to take interrupts 233 state = State.NOTPLAYING; 234 break; 235 case NOTPLAYING: 236 case PAUSED: 237 sleep(200); 238 break; 239 case PLAYING: 240 command.possiblyInterrupt(); 241 for(;;) { 242 int nBytesRead = 0; 243 nBytesRead = audioInputStream.read(abData, 0, abData.length); 244 position += nBytesRead / bytesPerSecond; 233 case INITIALIZING: 234 // we're ready to take interrupts 235 state = State.NOTPLAYING; 236 break; 237 case NOTPLAYING: 238 case PAUSED: 239 sleep(200); 240 break; 241 case PLAYING: 245 242 command.possiblyInterrupt(); 246 if (nBytesRead < 0) { break; } 247 audioOutputLine.write(abData, 0, nBytesRead); // => int nBytesWritten 243 for(;;) { 244 int nBytesRead = 0; 245 nBytesRead = audioInputStream.read(abData, 0, abData.length); 246 position += nBytesRead / bytesPerSecond; 247 command.possiblyInterrupt(); 248 if (nBytesRead < 0) { break; } 249 audioOutputLine.write(abData, 0, nBytesRead); // => int nBytesWritten 250 command.possiblyInterrupt(); 251 } 252 // end of audio, clean up 253 audioOutputLine.drain(); 254 audioOutputLine.close(); 255 audioOutputLine = null; 256 audioInputStream.close(); 257 audioInputStream = null; 258 playingUrl = null; 259 state = State.NOTPLAYING; 248 260 command.possiblyInterrupt(); 249 } 250 // end of audio, clean up 251 audioOutputLine.drain(); 252 audioOutputLine.close(); 253 audioOutputLine = null; 254 audioInputStream.close(); 255 audioInputStream = null; 256 playingUrl = null; 257 state = State.NOTPLAYING; 258 command.possiblyInterrupt(); 259 break; 261 break; 260 262 } 261 263 } catch (InterruptedException e) { … … 265 267 try { 266 268 switch (command.command()) { 267 case PLAY:268 double offset = command.offset();269 speed = command.speed();270 if (playingUrl != command.url() ||271 stateChange != State.PAUSED ||272 offset != 0.0)273 {274 if (audioInputStream != null) {275 audioInputStream.close();276 audioInputStream = null;277 }278 playingUrl = command.url();279 audioInputStream = AudioSystem.getAudioInputStream(playingUrl);280 audioFormat = audioInputStream.getFormat();281 long nBytesRead = 0;282 position = 0.0;283 offset -= leadIn;284 double calibratedOffset = offset * calibration;285 bytesPerSecond = audioFormat.getFrameRate() /* frames per second */269 case PLAY: 270 double offset = command.offset(); 271 speed = command.speed(); 272 if (playingUrl != command.url() || 273 stateChange != State.PAUSED || 274 offset != 0.0) 275 { 276 if (audioInputStream != null) { 277 audioInputStream.close(); 278 audioInputStream = null; 279 } 280 playingUrl = command.url(); 281 audioInputStream = AudioSystem.getAudioInputStream(playingUrl); 282 audioFormat = audioInputStream.getFormat(); 283 long nBytesRead = 0; 284 position = 0.0; 285 offset -= leadIn; 286 double calibratedOffset = offset * calibration; 287 bytesPerSecond = audioFormat.getFrameRate() /* frames per second */ 286 288 * audioFormat.getFrameSize() /* bytes per frame */; 287 if (speed * bytesPerSecond > 256000.0) 288 speed = 256000 / bytesPerSecond; 289 if (calibratedOffset > 0.0) { 290 long bytesToSkip = (long)( 291 calibratedOffset /* seconds (double) */ * bytesPerSecond); 292 /* skip doesn't seem to want to skip big chunks, so 293 * reduce it to smaller ones 294 */ 295 // audioInputStream.skip(bytesToSkip); 296 while (bytesToSkip > chunk) { 297 nBytesRead = audioInputStream.skip(chunk); 298 if (nBytesRead <= 0) 299 throw new IOException(tr("This is after the end of the recording")); 300 bytesToSkip -= nBytesRead; 289 if (speed * bytesPerSecond > 256000.0) { 290 speed = 256000 / bytesPerSecond; 301 291 } 302 if (bytesToSkip > 0) 303 audioInputStream.skip(bytesToSkip); 304 position = offset; 305 } 306 if (audioOutputLine != null) 307 audioOutputLine.close(); 308 audioFormat = new AudioFormat(audioFormat.getEncoding(), 292 if (calibratedOffset > 0.0) { 293 long bytesToSkip = (long)( 294 calibratedOffset /* seconds (double) */ * bytesPerSecond); 295 /* skip doesn't seem to want to skip big chunks, so 296 * reduce it to smaller ones 297 */ 298 // audioInputStream.skip(bytesToSkip); 299 while (bytesToSkip > chunk) { 300 nBytesRead = audioInputStream.skip(chunk); 301 if (nBytesRead <= 0) 302 throw new IOException(tr("This is after the end of the recording")); 303 bytesToSkip -= nBytesRead; 304 } 305 if (bytesToSkip > 0) { 306 audioInputStream.skip(bytesToSkip); 307 } 308 position = offset; 309 } 310 if (audioOutputLine != null) { 311 audioOutputLine.close(); 312 } 313 audioFormat = new AudioFormat(audioFormat.getEncoding(), 309 314 audioFormat.getSampleRate() * (float) (speed * calibration), 310 315 audioFormat.getSampleSizeInBits(), … … 313 318 audioFormat.getFrameRate() * (float) (speed * calibration), 314 319 audioFormat.isBigEndian()); 315 DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat);316 audioOutputLine = (SourceDataLine) AudioSystem.getLine(info);317 audioOutputLine.open(audioFormat);318 audioOutputLine.start();319 }320 stateChange = State.PLAYING;321 break;322 case PAUSE:323 stateChange = State.PAUSED;324 break;320 DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat); 321 audioOutputLine = (SourceDataLine) AudioSystem.getLine(info); 322 audioOutputLine.open(audioFormat); 323 audioOutputLine.start(); 324 } 325 stateChange = State.PLAYING; 326 break; 327 case PAUSE: 328 stateChange = State.PAUSED; 329 break; 325 330 } 326 331 command.ok(stateChange); … … 335 340 336 341 public static void audioMalfunction(Exception ex) { 337 JOptionPane.showMessageDialog(Main.parent,342 OptionPaneUtil.showMessageDialog(Main.parent, 338 343 "<html><p>" + tr(ex.getMessage()) + "</p></html>", 339 344 tr("Error playing sound"), JOptionPane.ERROR_MESSAGE); -
trunk/src/org/openstreetmap/josm/tools/BugReportExceptionHandler.java
r1674 r1865 20 20 21 21 import org.openstreetmap.josm.Main; 22 import org.openstreetmap.josm.actions.AboutAction;23 22 import org.openstreetmap.josm.actions.ShowStatusReportAction; 23 import org.openstreetmap.josm.gui.OptionPaneUtil; 24 24 import org.openstreetmap.josm.plugins.PluginHandler; 25 25 … … 39 39 if (e instanceof OutOfMemoryError) { 40 40 // do not translate the string, as translation may raise an exception 41 JOptionPane.showMessageDialog(Main.parent, "JOSM is out of memory. " +41 OptionPaneUtil.showMessageDialog(Main.parent, "JOSM is out of memory. " + 42 42 "Strange things may happen.\nPlease restart JOSM with the -Xmx###M option,\n" + 43 43 "where ### is the the number of MB assigned to JOSM (e.g. 256).\n" + 44 "Currently, " + Runtime.getRuntime().maxMemory()/1024/1024 + " MB are available to JOSM."); 44 "Currently, " + Runtime.getRuntime().maxMemory()/1024/1024 + " MB are available to JOSM.", 45 tr("Error"), 46 JOptionPane.ERROR_MESSAGE 47 ); 45 48 return; 46 49 } … … 50 53 51 54 Object[] options = new String[]{tr("Do nothing"), tr("Report Bug")}; 52 int answer = JOptionPane.showOptionDialog(Main.parent, tr("An unexpected exception occurred.\n\n" +53 "This is always a coding error. If you are running the latest\n" +55 int answer = OptionPaneUtil.showOptionDialog(Main.parent, tr("An unexpected exception occurred.\n\n" + 56 "This is always a coding error. If you are running the latest\n" + 54 57 "version of JOSM, please consider being kind and file a bug report."), 55 58 tr("Unexpected Exception"), JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE, 56 null,options, options[0]);57 if (answer == 1) {59 options, options[0]); 60 if (answer == JOptionPane.YES_OPTION) { 58 61 try { 59 62 StringWriter stack = new StringWriter(); … … 65 68 JPanel p = new JPanel(new GridBagLayout()); 66 69 p.add(new JLabel("<html>" + tr("Please report a ticket at {0}","http://josm.openstreetmap.de/newticket") + 67 "<br>" + tr("Include your steps to get to the error (as detailed as possible)!") +68 "<br>" + tr("Try updating to the newest version of JOSM and all plugins before reporting a bug.") +69 "<br>" + tr("Be sure to include the following information:") + "</html>"), GBC.eol());70 "<br>" + tr("Include your steps to get to the error (as detailed as possible)!") + 71 "<br>" + tr("Try updating to the newest version of JOSM and all plugins before reporting a bug.") + 72 "<br>" + tr("Be sure to include the following information:") + "</html>"), GBC.eol()); 70 73 try { 71 74 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(text), new ClipboardOwner(){ … … 81 84 p.add(new JScrollPane(info), GBC.eop()); 82 85 83 JOptionPane.showMessageDialog(Main.parent, p);86 OptionPaneUtil.showMessageDialog(Main.parent, p, tr("Warning"), JOptionPane.WARNING_MESSAGE); 84 87 } catch (Exception e1) { 85 88 e1.printStackTrace(); -
trunk/src/org/openstreetmap/josm/tools/Shortcut.java
r1415 r1865 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 import org.openstreetmap.josm.Main; 6 import org.openstreetmap.josm.gui.OptionPaneUtil; 6 7 7 8 import java.awt.event.KeyEvent; … … 30 31 */ 31 32 public class Shortcut { 32 // public static final int SHIFT = KeyEvent.SHIFT_DOWN_MASK;33 // public static final int CTRL = KeyEvent.CTRL_DOWN_MASK;34 // public static final int SHIFT_CTRL = KeyEvent.SHIFT_DOWN_MASK|KeyEvent.CTRL_DOWN_MASK;33 // public static final int SHIFT = KeyEvent.SHIFT_DOWN_MASK; 34 // public static final int CTRL = KeyEvent.CTRL_DOWN_MASK; 35 // public static final int SHIFT_CTRL = KeyEvent.SHIFT_DOWN_MASK|KeyEvent.CTRL_DOWN_MASK; 35 36 public static final int SHIFT_DEFAULT = 1; 36 37 private String shortText; // the unique ID of the shortcut … … 135 136 public void setAssignedUser(boolean assignedUser) { 136 137 this.reset = (!this.assignedUser && assignedUser); 137 if (assignedUser) assignedDefault = false; 138 if (assignedUser) { 139 assignedDefault = false; 140 } 138 141 this.assignedUser = assignedUser; 139 142 } … … 215 218 // check if something collides with an existing shortcut 216 219 private static Shortcut findShortcut(int requestedKey, int modifier) { 217 if (modifier == groups.get(GROUP_NONE)) {220 if (modifier == groups.get(GROUP_NONE)) 218 221 return null; 219 }220 222 for (Shortcut sc : shortcuts.values()) { 221 if (sc.isSame(requestedKey, modifier)) {223 if (sc.isSame(requestedKey, modifier)) 222 224 return sc; 223 }224 225 } 225 226 return null; … … 238 239 for (int m : mods) { 239 240 for (int k = KeyEvent.VK_A; k < KeyEvent.VK_Z; k++) { // we'll limit ourself to 100% safe keys 240 if ( findShortcut(k, m) == null ) {241 if ( findShortcut(k, m) == null ) 241 242 return new Shortcut(shortText, longText, requestedKey, requestedGroup, k, m, false, false); 242 }243 243 } 244 244 } … … 281 281 while (p != null) { 282 282 Shortcut sc = new Shortcut(p); 283 if (sc.getAssignedUser()) registerShortcut(sc); 283 if (sc.getAssignedUser()) { 284 registerShortcut(sc); 285 } 284 286 i++; 285 287 p = Main.pref.get("shortcut.shortcut."+i, null); … … 290 292 while (p != null) { 291 293 Shortcut sc = new Shortcut(p); 292 if (!sc.getAssignedUser() && sc.getAssignedDefault()) registerShortcut(sc); 294 if (!sc.getAssignedUser() && sc.getAssignedDefault()) { 295 registerShortcut(sc); 296 } 293 297 i++; 294 298 p = Main.pref.get("shortcut.shortcut."+i, null); … … 299 303 while (p != null) { 300 304 Shortcut sc = new Shortcut(p); 301 if (!sc.getAssignedUser() && !sc.getAssignedDefault()) registerShortcut(sc); 305 if (!sc.getAssignedUser() && !sc.getAssignedDefault()) { 306 registerShortcut(sc); 307 } 302 308 i++; 303 309 p = Main.pref.get("shortcut.shortcut."+i, null); … … 307 313 // shutdown handling 308 314 public static void savePrefs() { 309 // we save this directly from the preferences pane, so don't overwrite these values here310 // for (int i = GROUP_NONE; i < GROUP__MAX+GROUPS_ALT2; i++) {311 // Main.pref.put("shortcut.groups."+i, Groups.get(i).toString());312 // }315 // we save this directly from the preferences pane, so don't overwrite these values here 316 // for (int i = GROUP_NONE; i < GROUP__MAX+GROUPS_ALT2; i++) { 317 // Main.pref.put("shortcut.groups."+i, Groups.get(i).toString()); 318 // } 313 319 int i = 0; 314 320 for (Shortcut sc : shortcuts.values()) { 315 // TODO: Remove sc.getAssignedUser() when we fixed all internal conflicts321 // TODO: Remove sc.getAssignedUser() when we fixed all internal conflicts 316 322 if (!sc.getAutomatic() && !sc.getReset() && sc.getAssignedUser()) { 317 323 Main.pref.put("shortcut.shortcut."+i, sc.asPrefString()); … … 326 332 // put a user configured shortcut in as-is -- unless there's a conflict 327 333 if(sc.getAssignedUser() && findShortcut(sc.getAssignedKey(), 328 sc.getAssignedModifier()) == null)334 sc.getAssignedModifier()) == null) { 329 335 shortcuts.put(sc.getShortText(), sc); 330 else336 } else { 331 337 registerShortcut(sc.getShortText(), sc.getLongText(), sc.getRequestedKey(), 332 sc.getRequestedGroup(), sc.getAssignedModifier(), sc); 338 sc.getRequestedGroup(), sc.getAssignedModifier(), sc); 339 } 333 340 } 334 341 … … 339 346 */ 340 347 public static Shortcut registerSystemShortcut(String shortText, String longText, int key, int modifier) { 341 if (shortcuts.containsKey(shortText)) {348 if (shortcuts.containsKey(shortText)) 342 349 return shortcuts.get(shortText); 343 }344 350 Shortcut potentialShortcut = findShortcut(key, modifier); 345 351 if (potentialShortcut != null) { … … 391 397 Integer defaultModifier = groups.get(requestedGroup + GROUPS_DEFAULT); 392 398 if(modifier != null) { 393 if(modifier == SHIFT_DEFAULT) 399 if(modifier == SHIFT_DEFAULT) { 394 400 defaultModifier |= KeyEvent.SHIFT_DOWN_MASK; 395 else401 } else { 396 402 defaultModifier = modifier; 403 } 397 404 } 398 405 else if (defaultModifier == null) { // garbage in, no shortcut out … … 437 444 // a lengthy warning message 438 445 private static void displayWarning(Shortcut conflictsWith, Shortcut potentialShortcut, String shortText, String longText) { 439 JOptionPane.showMessageDialog(Main.parent,446 OptionPaneUtil.showMessageDialog(Main.parent, 440 447 tr("Setting the keyboard shortcut ''{0}'' for the action ''{1}'' ({2}) failed\n"+ 441 448 "because the shortcut is already taken by the action ''{3}'' ({4}).\n\n", … … 447 454 tr("Using the shortcut ''{0}'' instead.\n\n", potentialShortcut.getKeyText()) 448 455 )+ 449 tr("(Hint: You can edit the shortcuts in the preferences.)") 456 tr("(Hint: You can edit the shortcuts in the preferences.)"), 457 tr("Error"), 458 JOptionPane.ERROR_MESSAGE 450 459 ); 451 460 }
Note:
See TracChangeset
for help on using the changeset viewer.