Changeset 3408 in josm
- Timestamp:
- 2010-08-03T07:52:26+02:00 (14 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/DataSet.java
r3382 r3408 519 519 } 520 520 521 /*------------------------------------------------------522 * FILTERED / DISABLED HANDLING523 *-----------------------------------------------------*/524 525 /**526 * TODO: can be removed if no longer needed527 *528 * Currently, the filter flags are updated directly for the primitives.529 * On the long run there might be listeners for filter changes,530 * so the control needs to be moved to this place again.531 */532 533 // public void setDisabled(OsmPrimitive... osm) {534 // if (osm.length == 1 && osm[0] == null) {535 // setDisabled();536 // return;537 // }538 // clearDisabled(allPrimitives());539 // for (OsmPrimitive o : osm)540 // if (o != null) {541 // o.setDisabled(true);542 // }543 // }544 //545 // public void setDisabled(Collection<? extends OsmPrimitive> selection) {546 // clearDisabled(nodes);547 // clearDisabled(ways);548 // clearDisabled(relations);549 // for (OsmPrimitive osm : selection) {550 // osm.setDisabled(true);551 // }552 // }553 //554 // /**555 // * Remove the disabled parameter from every value in the collection.556 // * @param list The collection to remove the disabled parameter from.557 // */558 // private void clearDisabled(Collection<? extends OsmPrimitive> list) {559 // for (OsmPrimitive osm : list) {560 // osm.setDisabled(false);561 // }562 // }563 //564 //565 // public void setFiltered(Collection<? extends OsmPrimitive> selection) {566 // clearFiltered(nodes);567 // clearFiltered(ways);568 // clearFiltered(relations);569 // for (OsmPrimitive osm : selection) {570 // osm.setFiltered(true);571 // }572 // }573 //574 // public void setFiltered(OsmPrimitive... osm) {575 // if (osm.length == 1 && osm[0] == null) {576 // setFiltered();577 // return;578 // }579 // clearFiltered(nodes);580 // clearFiltered(ways);581 // clearFiltered(relations);582 // for (OsmPrimitive o : osm)583 // if (o != null) {584 // o.setFiltered(true);585 // }586 // }587 //588 // /**589 // * Remove the filtered parameter from every value in the collection.590 // * @param list The collection to remove the filtered parameter from.591 // */592 // private void clearFiltered(Collection<? extends OsmPrimitive> list) {593 // if (list == null)594 // return;595 // for (OsmPrimitive osm : list) {596 // osm.setFiltered(false);597 // }598 // }599 600 521 @Override public DataSet clone() { 601 522 getReadLock().lock(); -
trunk/src/org/openstreetmap/josm/gui/conflict/pair/properties/OperationCancelledException.java
r3083 r3408 6 6 public OperationCancelledException() { 7 7 super(); 8 // TODO Auto-generated constructor stub9 8 } 10 9 11 10 public OperationCancelledException(String message, Throwable cause) { 12 11 super(message, cause); 13 // TODO Auto-generated constructor stub14 12 } 15 13 16 14 public OperationCancelledException(String message) { 17 15 super(message); 18 // TODO Auto-generated constructor stub19 16 } 20 17 21 18 public OperationCancelledException(Throwable cause) { 22 19 super(cause); 23 // TODO Auto-generated constructor stub24 20 } 25 21 -
trunk/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java
r3237 r3408 26 26 import javax.swing.JLabel; 27 27 import javax.swing.JList; 28 import javax.swing.JMenuItem; 28 29 import javax.swing.JPanel; 29 30 import javax.swing.JScrollPane; … … 47 48 import org.openstreetmap.josm.gui.layer.Layer; 48 49 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 50 import org.openstreetmap.josm.gui.layer.Layer.LayerAction; 49 51 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher; 50 52 import org.openstreetmap.josm.tools.CheckParameterUtil; … … 265 267 * The action to delete the currently selected layer 266 268 */ 267 public final class DeleteLayerAction extends AbstractAction implements IEnabledStateUpdating{269 public final class DeleteLayerAction extends AbstractAction implements IEnabledStateUpdating, LayerAction { 268 270 /** 269 271 * Creates a {@see DeleteLayerAction} which will delete the currently … … 318 320 setEnabled(! getModel().getSelectedLayers().isEmpty()); 319 321 } 320 } 321 322 public final class ShowHideLayerAction extends AbstractAction implements IEnabledStateUpdating { 322 323 @Override 324 public Component createMenuComponent() { 325 return new JMenuItem(this); 326 } 327 328 @Override 329 public boolean supportLayers(List<Layer> layers) { 330 return true; 331 } 332 333 @Override 334 public boolean equals(Object obj) { 335 return obj instanceof DeleteLayerAction; 336 } 337 338 @Override 339 public int hashCode() { 340 return getClass().hashCode(); 341 } 342 } 343 344 public final class ShowHideLayerAction extends AbstractAction implements IEnabledStateUpdating, LayerAction { 323 345 private Layer layer; 324 346 … … 334 356 CheckParameterUtil.ensureParameterNotNull(layer, "layer"); 335 357 this.layer = layer; 336 putValue(NAME, tr("Show/Hide"));337 358 updateEnabledState(); 338 359 } … … 347 368 putValue(SHORT_DESCRIPTION, tr("Toggle visible state of the selected layer.")); 348 369 putValue("help", HelpUtil.ht("/Dialog/LayerDialog#ShowHideLayer")); 370 putValue(NAME, tr("Show/Hide")); 349 371 updateEnabledState(); 350 372 } … … 366 388 setEnabled(true); 367 389 } 390 } 391 392 @Override 393 public Component createMenuComponent() { 394 return new JMenuItem(this); 395 } 396 397 @Override 398 public boolean supportLayers(List<Layer> layers) { 399 return true; 400 } 401 402 @Override 403 public boolean equals(Object obj) { 404 return obj instanceof ShowHideLayerAction; 405 } 406 407 @Override 408 public int hashCode() { 409 return getClass().hashCode(); 368 410 } 369 411 } … … 576 618 } 577 619 Layer layer = model.getLayer(index); 578 LayerListPopup menu = new LayerListPopup( layerList, layer);620 LayerListPopup menu = new LayerListPopup(getModel().getSelectedLayers(), layer); 579 621 menu.show(LayerListDialog.this, p.x, p.y-3); 580 622 } … … 1064 1106 * @return the action 1065 1107 */ 1066 public ShowHideLayerAction createShowHideLayerAction( Layer layer) {1067 return new ShowHideLayerAction( layer);1108 public ShowHideLayerAction createShowHideLayerAction() { 1109 return new ShowHideLayerAction(); 1068 1110 } 1069 1111 … … 1075 1117 * @return the action 1076 1118 */ 1077 public DeleteLayerAction createDeleteLayerAction( Layer layer) {1119 public DeleteLayerAction createDeleteLayerAction() { 1078 1120 // the delete layer action doesn't depend on the current layer 1079 1121 return new DeleteLayerAction(); -
trunk/src/org/openstreetmap/josm/gui/dialogs/LayerListPopup.java
r2017 r3408 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.Component;7 6 import java.awt.event.ActionEvent; 7 import java.util.ArrayList; 8 import java.util.Arrays; 9 import java.util.List; 8 10 9 11 import javax.swing.AbstractAction; 10 import javax.swing.JList; 12 import javax.swing.Action; 13 import javax.swing.JMenuItem; 11 14 import javax.swing.JOptionPane; 12 15 import javax.swing.JPopupMenu; … … 14 17 import org.openstreetmap.josm.Main; 15 18 import org.openstreetmap.josm.gui.layer.Layer; 19 import org.openstreetmap.josm.gui.layer.Layer.LayerAction; 20 import org.openstreetmap.josm.gui.layer.Layer.SeparatorLayerAction; 16 21 import org.openstreetmap.josm.tools.ImageProvider; 17 22 … … 37 42 } 38 43 39 public LayerListPopup(final JList layers, final Layer layer) { 40 for (Component c : layer.getMenuEntries()) { 41 add(c); 44 public LayerListPopup(List<Layer> selectedLayers, final Layer layer) { 45 46 List<Action> actions; 47 if (selectedLayers.size() == 1) { 48 actions = Arrays.asList(selectedLayers.get(0).getMenuEntries()); 49 } else { 50 // Very simple algorithm - first selected layer has actions order as in getMenuEntries, actions from other layers go to the end 51 actions = new ArrayList<Action>(); 52 boolean separatorAdded = true; 53 for (Action a: selectedLayers.get(0).getMenuEntries()) { 54 if (!separatorAdded && a instanceof SeparatorLayerAction) { 55 separatorAdded = true; 56 actions.add(a); 57 } else if (a instanceof LayerAction && ((LayerAction)a).supportLayers(selectedLayers)) { 58 separatorAdded = false; 59 actions.add(a); 60 } 61 } 62 // This will usually add no action, because if some action support all selected layers then it was probably used also in first layer 63 for (int i=1; i<selectedLayers.size(); i++) { 64 separatorAdded = false; 65 for (Action a: selectedLayers.get(i).getMenuEntries()) { 66 if (a instanceof LayerAction && ((LayerAction)a).supportLayers(selectedLayers) && !actions.contains(a)) { 67 if (!separatorAdded) { 68 separatorAdded = true; 69 actions.add(SeparatorLayerAction.INSTANCE); 70 } 71 actions.add(a); 72 } 73 } 74 } 75 } 76 if (!actions.isEmpty() && actions.get(actions.size() - 1) instanceof SeparatorLayerAction) { 77 actions.remove(actions.size() - 1); 78 } 79 for (Action a : actions) { 80 if (a instanceof LayerAction) { 81 add (((LayerAction) a).createMenuComponent()); 82 } else { 83 add(new JMenuItem(a)); 84 } 42 85 } 43 86 } -
trunk/src/org/openstreetmap/josm/gui/help/HelpContentReaderException.java
r3083 r3408 7 7 public HelpContentReaderException() { 8 8 super(); 9 // TODO Auto-generated constructor stub10 9 } 11 10 12 11 public HelpContentReaderException(String message, Throwable cause) { 13 12 super(message, cause); 14 // TODO Auto-generated constructor stub15 13 } 16 14 17 15 public HelpContentReaderException(String message) { 18 16 super(message); 19 // TODO Auto-generated constructor stub20 17 } 21 18 22 19 public HelpContentReaderException(Throwable cause) { 23 20 super(cause); 24 // TODO Auto-generated constructor stub25 21 } 26 22 -
trunk/src/org/openstreetmap/josm/gui/help/MissingHelpContentException.java
r3083 r3408 6 6 public MissingHelpContentException() { 7 7 super(); 8 // TODO Auto-generated constructor stub9 8 } 10 9 11 10 public MissingHelpContentException(String message, Throwable cause) { 12 11 super(message, cause); 13 // TODO Auto-generated constructor stub14 12 } 15 13 16 14 public MissingHelpContentException(String message) { 17 15 super(message); 18 // TODO Auto-generated constructor stub19 16 } 20 17 21 18 public MissingHelpContentException(Throwable cause) { 22 19 super(cause); 23 // TODO Auto-generated constructor stub24 20 } 25 21 } -
trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java
r3325 r3408 10 10 import java.awt.BasicStroke; 11 11 import java.awt.Color; 12 import java.awt.Component;13 12 import java.awt.Graphics2D; 14 13 import java.awt.GridBagLayout; 15 14 import java.awt.Point; 16 15 import java.awt.event.ActionEvent; 17 import java.awt.event.ActionListener;18 16 import java.awt.geom.Area; 19 17 import java.awt.geom.Rectangle2D; … … 31 29 32 30 import javax.swing.AbstractAction; 31 import javax.swing.Action; 33 32 import javax.swing.Box; 34 33 import javax.swing.ButtonGroup; … … 38 37 import javax.swing.JLabel; 39 38 import javax.swing.JList; 40 import javax.swing.JMenuItem;41 39 import javax.swing.JOptionPane; 42 40 import javax.swing.JPanel; 43 41 import javax.swing.JRadioButton; 44 import javax.swing.JSeparator;45 42 import javax.swing.filechooser.FileFilter; 46 43 … … 130 127 131 128 @Override 132 public Component[] getMenuEntries() { 133 JMenuItem line = new JMenuItem(tr("Customize line drawing"), ImageProvider.get("mapmode/addsegment")); 134 line.addActionListener(new ActionListener() { 135 public void actionPerformed(ActionEvent e) { 136 JRadioButton[] r = new JRadioButton[3]; 137 r[0] = new JRadioButton(tr("Use global settings.")); 138 r[1] = new JRadioButton(tr("Draw lines between points for this layer.")); 139 r[2] = new JRadioButton(tr("Do not draw lines between points for this layer.")); 140 ButtonGroup group = new ButtonGroup(); 141 Box panel = Box.createVerticalBox(); 142 for (JRadioButton b : r) { 143 group.add(b); 144 panel.add(b); 145 } 146 String propName = "draw.rawgps.lines.layer " + getName(); 147 if (Main.pref.hasKey(propName)) { 148 group.setSelected(r[Main.pref.getBoolean(propName) ? 1 : 2].getModel(), true); 149 } else { 150 group.setSelected(r[0].getModel(), true); 151 } 152 int answer = JOptionPane.showConfirmDialog(Main.parent, panel, 153 tr("Select line drawing options"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); 154 switch (answer) { 155 case JOptionPane.CANCEL_OPTION: 156 case JOptionPane.CLOSED_OPTION: 157 return; 158 default: 159 // continue 160 } 161 if (group.getSelection() == r[0].getModel()) { 162 Main.pref.put(propName, null); 163 } else { 164 Main.pref.put(propName, group.getSelection() == r[1].getModel()); 165 } 166 Main.map.repaint(); 167 } 168 }); 169 170 JMenuItem color = new JMenuItem(tr("Customize Color"), ImageProvider.get("colorchooser")); 171 color.putClientProperty("help", "Action/LayerCustomizeColor"); 172 color.addActionListener(new ActionListener() { 173 public void actionPerformed(ActionEvent e) { 174 JColorChooser c = new JColorChooser(getColor(getName())); 175 Object[] options = new Object[] { tr("OK"), tr("Cancel"), tr("Default") }; 176 int answer = JOptionPane.showOptionDialog( 177 Main.parent, 178 c, 179 tr("Choose a color"), 180 JOptionPane.OK_CANCEL_OPTION, 181 JOptionPane.PLAIN_MESSAGE, 182 null, 183 options, options[0] 184 ); 185 switch (answer) { 186 case 0: 187 Main.pref.putColor("layer " + getName(), c.getColor()); 188 break; 189 case 1: 190 return; 191 case 2: 192 Main.pref.putColor("layer " + getName(), null); 193 break; 194 } 195 Main.map.repaint(); 196 } 197 }); 198 199 JMenuItem markersFromNamedTrackpoints = new JMenuItem(tr("Markers From Named Points"), ImageProvider 200 .get("addmarkers")); 201 markersFromNamedTrackpoints.putClientProperty("help", "Action/MarkersFromNamedPoints"); 202 markersFromNamedTrackpoints.addActionListener(new ActionListener() { 203 public void actionPerformed(ActionEvent e) { 204 GpxData namedTrackPoints = new GpxData(); 205 for (GpxTrack track : data.tracks) { 206 for (GpxTrackSegment seg : track.getSegments()) { 207 for (WayPoint point : seg.getWayPoints()) 208 if (point.attr.containsKey("name") || point.attr.containsKey("desc")) { 209 namedTrackPoints.waypoints.add(point); 210 } 211 } 212 } 213 214 MarkerLayer ml = new MarkerLayer(namedTrackPoints, tr("Named Trackpoints from {0}", getName()), 215 getAssociatedFile(), GpxLayer.this); 216 if (ml.data.size() > 0) { 217 Main.main.addLayer(ml); 218 } 219 } 220 }); 221 222 JMenuItem importAudio = new JMenuItem(tr("Import Audio"), ImageProvider.get("importaudio")); 223 importAudio.putClientProperty("help", "ImportAudio"); 224 importAudio.addActionListener(new ActionListener() { 225 private void warnCantImportIntoServerLayer(GpxLayer layer) { 226 String msg = tr("<html>The data in the GPX layer ''{0}'' has been downloaded from the server.<br>" 227 + "Because its way points do not include a timestamp we cannot correlate them with audio data.</html>", 228 layer.getName() 229 ); 230 HelpAwareOptionPane.showOptionDialog( 231 Main.parent, 232 msg, 233 tr("Import not possible"), 234 JOptionPane.WARNING_MESSAGE, 235 ht("/Action/ImportImages#CantImportIntoGpxLayerFromServer") 236 ); 237 } 238 public void actionPerformed(ActionEvent e) { 239 if (GpxLayer.this.data.fromServer) { 240 warnCantImportIntoServerLayer(GpxLayer.this); 241 return; 242 } 243 String dir = Main.pref.get("markers.lastaudiodirectory"); 244 JFileChooser fc = new JFileChooser(dir); 245 fc.setFileSelectionMode(JFileChooser.FILES_ONLY); 246 fc.setAcceptAllFileFilterUsed(false); 247 fc.setFileFilter(new FileFilter() { 248 @Override 249 public boolean accept(File f) { 250 return f.isDirectory() || f.getName().toLowerCase().endsWith(".wav"); 251 } 252 253 @Override 254 public String getDescription() { 255 return tr("Wave Audio files (*.wav)"); 256 } 257 }); 258 fc.setMultiSelectionEnabled(true); 259 if (fc.showOpenDialog(Main.parent) == JFileChooser.APPROVE_OPTION) { 260 if (!fc.getCurrentDirectory().getAbsolutePath().equals(dir)) { 261 Main.pref.put("markers.lastaudiodirectory", fc.getCurrentDirectory().getAbsolutePath()); 262 } 263 264 File sel[] = fc.getSelectedFiles(); 265 // sort files in increasing order of timestamp (this is the end time, but so 266 // long as they don't overlap, that's fine) 267 if (sel.length > 1) { 268 Arrays.sort(sel, new Comparator<File>() { 269 public int compare(File a, File b) { 270 return a.lastModified() <= b.lastModified() ? -1 : 1; 271 } 272 }); 273 } 274 275 String names = null; 276 for (int i = 0; i < sel.length; i++) { 277 if (names == null) { 278 names = " ("; 279 } else { 280 names += ", "; 281 } 282 names += sel[i].getName(); 283 } 284 if (names != null) { 285 names += ")"; 286 } else { 287 names = ""; 288 } 289 MarkerLayer ml = new MarkerLayer(new GpxData(), tr("Audio markers from {0}", getName()) + names, 290 getAssociatedFile(), GpxLayer.this); 291 double firstStartTime = sel[0].lastModified() / 1000.0 /* ms -> seconds */ 292 - AudioUtil.getCalibratedDuration(sel[0]); 293 294 Markers m = new Markers(); 295 for (int i = 0; i < sel.length; i++) { 296 importAudio(sel[i], ml, firstStartTime, m); 297 } 298 Main.main.addLayer(ml); 299 Main.map.repaint(); 300 } 301 } 302 }); 303 304 JMenuItem tagimage = new JMenuItem(tr("Import images"), ImageProvider.get("dialogs/geoimage")); 305 tagimage.putClientProperty("help", ht("/Action/ImportImages")); 306 tagimage.addActionListener(new ActionListener() { 307 308 private void warnCantImportIntoServerLayer(GpxLayer layer) { 309 String msg = tr("<html>The data in the GPX layer ''{0}'' has been downloaded from the server.<br>" 310 + "Because its way points do not include a timestamp we cannot correlate them with images.</html>", 311 layer.getName() 312 ); 313 HelpAwareOptionPane.showOptionDialog( 314 Main.parent, 315 msg, 316 tr("Import not possible"), 317 JOptionPane.WARNING_MESSAGE, 318 ht("/Action/ImportImages#CantImportIntoGpxLayerFromServer") 319 ); 320 } 321 322 public void actionPerformed(ActionEvent e) { 323 if (GpxLayer.this.data.fromServer) { 324 warnCantImportIntoServerLayer(GpxLayer.this); 325 return; 326 } 327 String curDir = Main.pref.get("geoimage.lastdirectory", Main.pref.get("lastDirectory")); 328 if (curDir.equals("")) { 329 curDir = "."; 330 } 331 JFileChooser fc = new JFileChooser(new File(curDir)); 332 333 fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); 334 fc.setMultiSelectionEnabled(true); 335 fc.setAcceptAllFileFilterUsed(false); 336 JpgImporter importer = new JpgImporter(GpxLayer.this); 337 fc.setFileFilter(importer.filter); 338 fc.showOpenDialog(Main.parent); 339 LinkedList<File> files = new LinkedList<File>(); 340 File[] sel = fc.getSelectedFiles(); 341 if (sel == null || sel.length == 0) 342 return; 343 if (!fc.getCurrentDirectory().getAbsolutePath().equals(curDir)) { 344 Main.pref.put("geoimage.lastdirectory", fc.getCurrentDirectory().getAbsolutePath()); 345 } 346 addRecursiveFiles(files, sel); 347 importer.importDataHandleExceptions(files, NullProgressMonitor.INSTANCE); 348 } 349 350 private void addRecursiveFiles(LinkedList<File> files, File[] sel) { 351 for (File f : sel) { 352 if (f.isDirectory()) { 353 addRecursiveFiles(files, f.listFiles()); 354 } else if (f.getName().toLowerCase().endsWith(".jpg")) { 355 files.add(f); 356 } 357 } 358 } 359 }); 360 129 public Action[] getMenuEntries() { 361 130 if (Main.applet) 362 return new Component[] { new JMenuItem(LayerListDialog.getInstance().createShowHideLayerAction(this)), 363 new JMenuItem(LayerListDialog.getInstance().createDeleteLayerAction(this)), new JSeparator(), color, line, 364 new JMenuItem(new ConvertToDataLayerAction()), new JSeparator(), 365 new JMenuItem(new RenameLayerAction(getAssociatedFile(), this)), new JSeparator(), 366 new JMenuItem(new LayerListPopup.InfoAction(this)) }; 367 return new Component[] { new JMenuItem(LayerListDialog.getInstance().createShowHideLayerAction(this)), 368 new JMenuItem(LayerListDialog.getInstance().createDeleteLayerAction(this)), new JSeparator(), 369 new JMenuItem(new LayerSaveAction(this)), new JMenuItem(new LayerSaveAsAction(this)), color, line, 370 tagimage, importAudio, markersFromNamedTrackpoints, new JMenuItem(new ConvertToDataLayerAction()), 371 new JMenuItem(new DownloadAlongTrackAction()), new JSeparator(), 372 new JMenuItem(new RenameLayerAction(getAssociatedFile(), this)), new JSeparator(), 373 new JMenuItem(new LayerListPopup.InfoAction(this)) }; 131 return new Action[] { 132 LayerListDialog.getInstance().createShowHideLayerAction(), 133 LayerListDialog.getInstance().createDeleteLayerAction(), 134 SeparatorLayerAction.INSTANCE, 135 new CustomizeColor(), 136 new CustomizeLineDrawing(), 137 new ConvertToDataLayerAction(), 138 SeparatorLayerAction.INSTANCE, 139 new RenameLayerAction(getAssociatedFile(), this), 140 SeparatorLayerAction.INSTANCE, 141 new LayerListPopup.InfoAction(this) }; 142 return new Action[] { 143 LayerListDialog.getInstance().createShowHideLayerAction(), 144 LayerListDialog.getInstance().createDeleteLayerAction(), 145 SeparatorLayerAction.INSTANCE, 146 new LayerSaveAction(this), 147 new LayerSaveAsAction(this), 148 new CustomizeColor(), 149 new CustomizeLineDrawing(), 150 new ImportImages(), 151 new ImportAudio(), 152 new MarkersFromNamedPoins(), 153 new ConvertToDataLayerAction(), 154 new DownloadAlongTrackAction(), 155 SeparatorLayerAction.INSTANCE, 156 new RenameLayerAction(getAssociatedFile(), this), 157 SeparatorLayerAction.INSTANCE, 158 new LayerListPopup.InfoAction(this) }; 374 159 } 375 160 … … 1417 1202 return best; 1418 1203 } 1204 1205 private class CustomizeLineDrawing extends AbstractAction { 1206 1207 CustomizeLineDrawing() { 1208 super(tr("Customize line drawing"), ImageProvider.get("mapmode/addsegment")); 1209 } 1210 1211 @Override 1212 public void actionPerformed(ActionEvent e) { 1213 JRadioButton[] r = new JRadioButton[3]; 1214 r[0] = new JRadioButton(tr("Use global settings.")); 1215 r[1] = new JRadioButton(tr("Draw lines between points for this layer.")); 1216 r[2] = new JRadioButton(tr("Do not draw lines between points for this layer.")); 1217 ButtonGroup group = new ButtonGroup(); 1218 Box panel = Box.createVerticalBox(); 1219 for (JRadioButton b : r) { 1220 group.add(b); 1221 panel.add(b); 1222 } 1223 String propName = "draw.rawgps.lines.layer " + getName(); 1224 if (Main.pref.hasKey(propName)) { 1225 group.setSelected(r[Main.pref.getBoolean(propName) ? 1 : 2].getModel(), true); 1226 } else { 1227 group.setSelected(r[0].getModel(), true); 1228 } 1229 int answer = JOptionPane.showConfirmDialog(Main.parent, panel, 1230 tr("Select line drawing options"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); 1231 switch (answer) { 1232 case JOptionPane.CANCEL_OPTION: 1233 case JOptionPane.CLOSED_OPTION: 1234 return; 1235 default: 1236 // continue 1237 } 1238 if (group.getSelection() == r[0].getModel()) { 1239 Main.pref.put(propName, null); 1240 } else { 1241 Main.pref.put(propName, group.getSelection() == r[1].getModel()); 1242 } 1243 Main.map.repaint(); 1244 } 1245 } 1246 1247 private class CustomizeColor extends AbstractAction { 1248 1249 public CustomizeColor() { 1250 super(tr("Customize Color"), ImageProvider.get("colorchooser")); 1251 putValue("help", "Action/LayerCustomizeColor"); 1252 } 1253 1254 @Override 1255 public void actionPerformed(ActionEvent e) { 1256 JColorChooser c = new JColorChooser(getColor(getName())); 1257 Object[] options = new Object[] { tr("OK"), tr("Cancel"), tr("Default") }; 1258 int answer = JOptionPane.showOptionDialog( 1259 Main.parent, 1260 c, 1261 tr("Choose a color"), 1262 JOptionPane.OK_CANCEL_OPTION, 1263 JOptionPane.PLAIN_MESSAGE, 1264 null, 1265 options, options[0] 1266 ); 1267 switch (answer) { 1268 case 0: 1269 Main.pref.putColor("layer " + getName(), c.getColor()); 1270 break; 1271 case 1: 1272 return; 1273 case 2: 1274 Main.pref.putColor("layer " + getName(), null); 1275 break; 1276 } 1277 Main.map.repaint(); 1278 } 1279 1280 } 1281 1282 private class MarkersFromNamedPoins extends AbstractAction { 1283 1284 public MarkersFromNamedPoins() { 1285 super(tr("Markers From Named Points"), ImageProvider.get("addmarkers")); 1286 putValue("help", "Action/MarkersFromNamedPoints"); 1287 } 1288 1289 @Override 1290 public void actionPerformed(ActionEvent e) { 1291 GpxData namedTrackPoints = new GpxData(); 1292 for (GpxTrack track : data.tracks) { 1293 for (GpxTrackSegment seg : track.getSegments()) { 1294 for (WayPoint point : seg.getWayPoints()) 1295 if (point.attr.containsKey("name") || point.attr.containsKey("desc")) { 1296 namedTrackPoints.waypoints.add(point); 1297 } 1298 } 1299 } 1300 1301 MarkerLayer ml = new MarkerLayer(namedTrackPoints, tr("Named Trackpoints from {0}", getName()), 1302 getAssociatedFile(), GpxLayer.this); 1303 if (ml.data.size() > 0) { 1304 Main.main.addLayer(ml); 1305 } 1306 1307 } 1308 } 1309 1310 private class ImportAudio extends AbstractAction { 1311 1312 public ImportAudio() { 1313 super(tr("Import Audio"), ImageProvider.get("importaudio")); 1314 putValue("help", "ImportAudio"); 1315 } 1316 1317 private void warnCantImportIntoServerLayer(GpxLayer layer) { 1318 String msg = tr("<html>The data in the GPX layer ''{0}'' has been downloaded from the server.<br>" 1319 + "Because its way points do not include a timestamp we cannot correlate them with audio data.</html>", 1320 layer.getName() 1321 ); 1322 HelpAwareOptionPane.showOptionDialog( 1323 Main.parent, 1324 msg, 1325 tr("Import not possible"), 1326 JOptionPane.WARNING_MESSAGE, 1327 ht("/Action/ImportImages#CantImportIntoGpxLayerFromServer") 1328 ); 1329 } 1330 1331 @Override 1332 public void actionPerformed(ActionEvent e) { 1333 if (GpxLayer.this.data.fromServer) { 1334 warnCantImportIntoServerLayer(GpxLayer.this); 1335 return; 1336 } 1337 String dir = Main.pref.get("markers.lastaudiodirectory"); 1338 JFileChooser fc = new JFileChooser(dir); 1339 fc.setFileSelectionMode(JFileChooser.FILES_ONLY); 1340 fc.setAcceptAllFileFilterUsed(false); 1341 fc.setFileFilter(new FileFilter() { 1342 @Override 1343 public boolean accept(File f) { 1344 return f.isDirectory() || f.getName().toLowerCase().endsWith(".wav"); 1345 } 1346 1347 @Override 1348 public String getDescription() { 1349 return tr("Wave Audio files (*.wav)"); 1350 } 1351 }); 1352 fc.setMultiSelectionEnabled(true); 1353 if (fc.showOpenDialog(Main.parent) == JFileChooser.APPROVE_OPTION) { 1354 if (!fc.getCurrentDirectory().getAbsolutePath().equals(dir)) { 1355 Main.pref.put("markers.lastaudiodirectory", fc.getCurrentDirectory().getAbsolutePath()); 1356 } 1357 1358 File sel[] = fc.getSelectedFiles(); 1359 // sort files in increasing order of timestamp (this is the end time, but so 1360 // long as they don't overlap, that's fine) 1361 if (sel.length > 1) { 1362 Arrays.sort(sel, new Comparator<File>() { 1363 public int compare(File a, File b) { 1364 return a.lastModified() <= b.lastModified() ? -1 : 1; 1365 } 1366 }); 1367 } 1368 1369 String names = null; 1370 for (int i = 0; i < sel.length; i++) { 1371 if (names == null) { 1372 names = " ("; 1373 } else { 1374 names += ", "; 1375 } 1376 names += sel[i].getName(); 1377 } 1378 if (names != null) { 1379 names += ")"; 1380 } else { 1381 names = ""; 1382 } 1383 MarkerLayer ml = new MarkerLayer(new GpxData(), tr("Audio markers from {0}", getName()) + names, 1384 getAssociatedFile(), GpxLayer.this); 1385 double firstStartTime = sel[0].lastModified() / 1000.0 /* ms -> seconds */ 1386 - AudioUtil.getCalibratedDuration(sel[0]); 1387 1388 Markers m = new Markers(); 1389 for (int i = 0; i < sel.length; i++) { 1390 importAudio(sel[i], ml, firstStartTime, m); 1391 } 1392 Main.main.addLayer(ml); 1393 Main.map.repaint(); 1394 } 1395 1396 } 1397 } 1398 1399 private class ImportImages extends AbstractAction { 1400 1401 public ImportImages() { 1402 super(tr("Import images"), ImageProvider.get("dialogs/geoimage")); 1403 putValue("help", ht("/Action/ImportImages")); 1404 } 1405 1406 private void warnCantImportIntoServerLayer(GpxLayer layer) { 1407 String msg = tr("<html>The data in the GPX layer ''{0}'' has been downloaded from the server.<br>" 1408 + "Because its way points do not include a timestamp we cannot correlate them with images.</html>", 1409 layer.getName() 1410 ); 1411 HelpAwareOptionPane.showOptionDialog( 1412 Main.parent, 1413 msg, 1414 tr("Import not possible"), 1415 JOptionPane.WARNING_MESSAGE, 1416 ht("/Action/ImportImages#CantImportIntoGpxLayerFromServer") 1417 ); 1418 } 1419 1420 private void addRecursiveFiles(LinkedList<File> files, File[] sel) { 1421 for (File f : sel) { 1422 if (f.isDirectory()) { 1423 addRecursiveFiles(files, f.listFiles()); 1424 } else if (f.getName().toLowerCase().endsWith(".jpg")) { 1425 files.add(f); 1426 } 1427 } 1428 } 1429 1430 @Override 1431 public void actionPerformed(ActionEvent e) { 1432 1433 if (GpxLayer.this.data.fromServer) { 1434 warnCantImportIntoServerLayer(GpxLayer.this); 1435 return; 1436 } 1437 String curDir = Main.pref.get("geoimage.lastdirectory", Main.pref.get("lastDirectory")); 1438 if (curDir.equals("")) { 1439 curDir = "."; 1440 } 1441 JFileChooser fc = new JFileChooser(new File(curDir)); 1442 1443 fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); 1444 fc.setMultiSelectionEnabled(true); 1445 fc.setAcceptAllFileFilterUsed(false); 1446 JpgImporter importer = new JpgImporter(GpxLayer.this); 1447 fc.setFileFilter(importer.filter); 1448 fc.showOpenDialog(Main.parent); 1449 LinkedList<File> files = new LinkedList<File>(); 1450 File[] sel = fc.getSelectedFiles(); 1451 if (sel == null || sel.length == 0) 1452 return; 1453 if (!fc.getCurrentDirectory().getAbsolutePath().equals(curDir)) { 1454 Main.pref.put("geoimage.lastdirectory", fc.getCurrentDirectory().getAbsolutePath()); 1455 } 1456 addRecursiveFiles(files, sel); 1457 importer.importDataHandleExceptions(files, NullProgressMonitor.INSTANCE); 1458 } 1459 1460 } 1419 1461 } -
trunk/src/org/openstreetmap/josm/gui/layer/Layer.java
r3116 r3408 11 11 import java.beans.PropertyChangeSupport; 12 12 import java.io.File; 13 import java.util.List; 13 14 14 15 import javax.swing.AbstractAction; 16 import javax.swing.Action; 15 17 import javax.swing.Icon; 18 import javax.swing.JSeparator; 16 19 17 20 import org.openstreetmap.josm.actions.GpxExportAction; … … 40 43 */ 41 44 abstract public class Layer implements Destroyable, MapViewPaintable { 45 46 public interface LayerAction { 47 boolean supportLayers(List<Layer> layers); 48 Component createMenuComponent(); 49 } 50 51 /** 52 * Special class that can be returned by getMenuEntries when JSeparator needs to be created 53 * 54 */ 55 public static class SeparatorLayerAction extends AbstractAction implements LayerAction { 56 public static final SeparatorLayerAction INSTANCE = new SeparatorLayerAction(); 57 @Override 58 public void actionPerformed(ActionEvent e) { 59 throw new UnsupportedOperationException(); 60 } 61 @Override 62 public Component createMenuComponent() { 63 return new JSeparator(); 64 } 65 @Override 66 public boolean supportLayers(List<Layer> layers) { 67 return false; 68 } 69 } 70 42 71 static public final String VISIBLE_PROP = Layer.class.getName() + ".visible"; 43 72 static public final String NAME_PROP = Layer.class.getName() + ".name"; 73 44 74 45 75 /** keeps track of property change listeners */ … … 112 142 abstract public Object getInfoComponent(); 113 143 114 abstract public Component[] getMenuEntries(); 144 /** 145 * Returns list of actions. Action can implement LayerAction interface when it needs to be represented by other 146 * menu component than JMenuItem or when it supports multiple layers. Actions that support multiple layers should also 147 * have correct equals implementation. 148 * 149 * Use SeparatorLayerAction.INSTANCE instead of new JSeparator 150 * 151 */ 152 abstract public Action[] getMenuEntries(); 115 153 116 154 /** -
trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r3362 r3408 10 10 import java.awt.AlphaComposite; 11 11 import java.awt.Color; 12 import java.awt.Component;13 12 import java.awt.Composite; 14 13 import java.awt.Graphics2D; … … 28 27 29 28 import javax.swing.AbstractAction; 29 import javax.swing.Action; 30 30 import javax.swing.Icon; 31 31 import javax.swing.JLabel; 32 import javax.swing.JMenuItem;33 32 import javax.swing.JOptionPane; 34 33 import javax.swing.JPanel; 35 34 import javax.swing.JScrollPane; 36 import javax.swing.JSeparator;37 35 import javax.swing.JTextArea; 38 36 … … 440 438 } 441 439 442 @Override public Component[] getMenuEntries() {440 @Override public Action[] getMenuEntries() { 443 441 if (Main.applet) 444 return new Component[]{445 new JMenuItem(LayerListDialog.getInstance().createActivateLayerAction(this)),446 new JMenuItem(LayerListDialog.getInstance().createShowHideLayerAction(this)),447 new JMenuItem(LayerListDialog.getInstance().createDeleteLayerAction(this)),448 new JSeparator(),449 new JMenuItem(LayerListDialog.getInstance().createMergeLayerAction(this)),450 new JSeparator(),451 new JMenuItem(new RenameLayerAction(getAssociatedFile(), this)),452 new JMenuItem(new ConsistencyTestAction()),453 new JSeparator(),454 new JMenuItem(new LayerListPopup.InfoAction(this))};455 return new Component[]{456 new JMenuItem(LayerListDialog.getInstance().createActivateLayerAction(this)),457 new JMenuItem(LayerListDialog.getInstance().createShowHideLayerAction(this)),458 new JMenuItem(LayerListDialog.getInstance().createDeleteLayerAction(this)),459 new JSeparator(),460 new JMenuItem(LayerListDialog.getInstance().createMergeLayerAction(this)),461 new JMenuItem(new LayerSaveAction(this)),462 new JMenuItem(new LayerSaveAsAction(this)),463 new JMenuItem(new LayerGpxExportAction(this)),464 new JMenuItem(new ConvertToGpxLayerAction()),465 new JSeparator(),466 new JMenuItem(new RenameLayerAction(getAssociatedFile(), this)),467 new JMenuItem(new ConsistencyTestAction()),468 new JSeparator(),469 new JMenuItem(new LayerListPopup.InfoAction(this))};442 return new Action[]{ 443 LayerListDialog.getInstance().createActivateLayerAction(this), 444 LayerListDialog.getInstance().createShowHideLayerAction(), 445 LayerListDialog.getInstance().createDeleteLayerAction(), 446 SeparatorLayerAction.INSTANCE, 447 LayerListDialog.getInstance().createMergeLayerAction(this), 448 SeparatorLayerAction.INSTANCE, 449 new RenameLayerAction(getAssociatedFile(), this), 450 new ConsistencyTestAction(), 451 SeparatorLayerAction.INSTANCE, 452 new LayerListPopup.InfoAction(this)}; 453 return new Action[]{ 454 LayerListDialog.getInstance().createActivateLayerAction(this), 455 LayerListDialog.getInstance().createShowHideLayerAction(), 456 LayerListDialog.getInstance().createDeleteLayerAction(), 457 SeparatorLayerAction.INSTANCE, 458 LayerListDialog.getInstance().createMergeLayerAction(this), 459 new LayerSaveAction(this), 460 new LayerSaveAsAction(this), 461 new LayerGpxExportAction(this), 462 new ConvertToGpxLayerAction(), 463 SeparatorLayerAction.INSTANCE, 464 new RenameLayerAction(getAssociatedFile(), this), 465 new ConsistencyTestAction(), 466 SeparatorLayerAction.INSTANCE, 467 new LayerListPopup.InfoAction(this)}; 470 468 } 471 469 -
trunk/src/org/openstreetmap/josm/gui/layer/RawGpsLayer.java
r3233 r3408 8 8 9 9 import java.awt.Color; 10 import java.awt.Component;11 10 import java.awt.Graphics2D; 12 11 import java.awt.GridBagLayout; 13 12 import java.awt.Point; 14 13 import java.awt.event.ActionEvent; 15 import java.awt.event.ActionListener;16 14 import java.io.File; 17 15 import java.util.ArrayList; … … 20 18 21 19 import javax.swing.AbstractAction; 20 import javax.swing.Action; 22 21 import javax.swing.Box; 23 22 import javax.swing.ButtonGroup; … … 25 24 import javax.swing.JColorChooser; 26 25 import javax.swing.JLabel; 27 import javax.swing.JMenuItem;28 26 import javax.swing.JOptionPane; 29 27 import javax.swing.JPanel; 30 28 import javax.swing.JRadioButton; 31 import javax.swing.JSeparator;32 29 33 30 import org.openstreetmap.josm.Main; … … 196 193 } 197 194 198 @Override public Component[] getMenuEntries() { 199 JMenuItem line = new JMenuItem(tr("Customize line drawing"), ImageProvider.get("mapmode/addsegment")); 200 line.addActionListener(new ActionListener(){ 201 public void actionPerformed(ActionEvent e) { 202 JRadioButton[] r = new JRadioButton[3]; 203 r[0] = new JRadioButton(tr("Use global settings.")); 204 r[1] = new JRadioButton(tr("Draw lines between points for this layer.")); 205 r[2] = new JRadioButton(tr("Do not draw lines between points for this layer.")); 206 ButtonGroup group = new ButtonGroup(); 207 Box panel = Box.createVerticalBox(); 208 for (JRadioButton b : r) { 209 group.add(b); 210 panel.add(b); 211 } 212 String propName = "draw.rawgps.lines.layer "+getName(); 213 if (Main.pref.hasKey(propName)) { 214 group.setSelected(r[Main.pref.getBoolean(propName) ? 1:2].getModel(), true); 215 } else { 216 group.setSelected(r[0].getModel(), true); 217 } 218 int answer = JOptionPane.showConfirmDialog( 219 Main.parent, 220 panel, 221 tr("Select line drawing options"), 222 JOptionPane.OK_CANCEL_OPTION, 223 JOptionPane.PLAIN_MESSAGE 224 ); 225 if (answer == JOptionPane.CANCEL_OPTION) 226 return; 227 if (group.getSelection() == r[0].getModel()) { 228 Main.pref.put(propName, null); 229 } else { 230 Main.pref.put(propName, group.getSelection() == r[1].getModel()); 231 } 232 Main.map.repaint(); 233 } 234 }); 235 236 JMenuItem color = new JMenuItem(tr("Customize Color"), ImageProvider.get("colorchooser")); 237 color.addActionListener(new ActionListener(){ 238 public void actionPerformed(ActionEvent e) { 239 JColorChooser c = new JColorChooser(Main.pref.getColor(marktr("gps point"), "layer "+getName(), Color.gray)); 240 Object[] options = new Object[]{tr("OK"), tr("Cancel"), tr("Default")}; 241 int answer = JOptionPane.showOptionDialog( 242 Main.parent, 243 c, 244 tr("Choose a color"), 245 JOptionPane.OK_CANCEL_OPTION, 246 JOptionPane.PLAIN_MESSAGE, null,options, options[0]); 247 switch (answer) { 248 case 0: 249 Main.pref.putColor("layer "+getName(), c.getColor()); 250 break; 251 case 1: 252 return; 253 case 2: 254 Main.pref.putColor("layer "+getName(), null); 255 break; 256 } 257 Main.map.repaint(); 258 } 259 }); 260 195 @Override public Action[] getMenuEntries() { 261 196 if (Main.applet) 262 return new Component[]{ 263 new JMenuItem(LayerListDialog.getInstance().createShowHideLayerAction(this)), 264 new JMenuItem(LayerListDialog.getInstance().createDeleteLayerAction(this)), 265 new JSeparator(), 266 color, 267 line, 268 new JMenuItem(new ConvertToDataLayerAction()), 269 new JSeparator(), 270 new JMenuItem(new RenameLayerAction(getAssociatedFile(), this)), 271 new JSeparator(), 272 new JMenuItem(new LayerListPopup.InfoAction(this))}; 273 return new Component[]{ 274 new JMenuItem(LayerListDialog.getInstance().createShowHideLayerAction(this)), 275 new JMenuItem(LayerListDialog.getInstance().createDeleteLayerAction(this)), 276 new JSeparator(), 277 new JMenuItem(new LayerGpxExportAction(this)), 278 color, 279 line, 280 new JMenuItem(new ConvertToDataLayerAction()), 281 new JSeparator(), 282 new JMenuItem(new RenameLayerAction(getAssociatedFile(), this)), 283 new JSeparator(), 284 new JMenuItem(new LayerListPopup.InfoAction(this))}; 197 return new Action[]{ 198 LayerListDialog.getInstance().createShowHideLayerAction(), 199 LayerListDialog.getInstance().createDeleteLayerAction(), 200 SeparatorLayerAction.INSTANCE, 201 new CustomizeColor(), 202 new CustomizeLineDrawing(), 203 new ConvertToDataLayerAction(), 204 SeparatorLayerAction.INSTANCE, 205 new RenameLayerAction(getAssociatedFile(), this), 206 SeparatorLayerAction.INSTANCE, 207 new LayerListPopup.InfoAction(this)}; 208 else 209 return new Action[]{ 210 LayerListDialog.getInstance().createShowHideLayerAction(), 211 LayerListDialog.getInstance().createDeleteLayerAction(), 212 SeparatorLayerAction.INSTANCE, 213 new LayerGpxExportAction(this), 214 new CustomizeColor(), 215 new CustomizeLineDrawing(), 216 new ConvertToDataLayerAction(), 217 SeparatorLayerAction.INSTANCE, 218 new RenameLayerAction(getAssociatedFile(), this), 219 SeparatorLayerAction.INSTANCE, 220 new LayerListPopup.InfoAction(this)}; 285 221 } 286 222 … … 294 230 Main.pref.removePreferenceChangeListener(this); 295 231 } 232 233 private class CustomizeLineDrawing extends AbstractAction { 234 235 public CustomizeLineDrawing() { 236 super(tr("Customize line drawing"), ImageProvider.get("mapmode/addsegment")); 237 } 238 239 @Override 240 public void actionPerformed(ActionEvent e) { 241 JRadioButton[] r = new JRadioButton[3]; 242 r[0] = new JRadioButton(tr("Use global settings.")); 243 r[1] = new JRadioButton(tr("Draw lines between points for this layer.")); 244 r[2] = new JRadioButton(tr("Do not draw lines between points for this layer.")); 245 ButtonGroup group = new ButtonGroup(); 246 Box panel = Box.createVerticalBox(); 247 for (JRadioButton b : r) { 248 group.add(b); 249 panel.add(b); 250 } 251 String propName = "draw.rawgps.lines.layer "+getName(); 252 if (Main.pref.hasKey(propName)) { 253 group.setSelected(r[Main.pref.getBoolean(propName) ? 1:2].getModel(), true); 254 } else { 255 group.setSelected(r[0].getModel(), true); 256 } 257 int answer = JOptionPane.showConfirmDialog( 258 Main.parent, 259 panel, 260 tr("Select line drawing options"), 261 JOptionPane.OK_CANCEL_OPTION, 262 JOptionPane.PLAIN_MESSAGE 263 ); 264 if (answer == JOptionPane.CANCEL_OPTION) 265 return; 266 if (group.getSelection() == r[0].getModel()) { 267 Main.pref.put(propName, null); 268 } else { 269 Main.pref.put(propName, group.getSelection() == r[1].getModel()); 270 } 271 Main.map.repaint(); 272 } 273 } 274 275 private class CustomizeColor extends AbstractAction { 276 277 public CustomizeColor() { 278 super(tr("Customize Color"), ImageProvider.get("colorchooser")); 279 } 280 281 @Override 282 public void actionPerformed(ActionEvent e) { 283 JColorChooser c = new JColorChooser(Main.pref.getColor(marktr("gps point"), "layer "+getName(), Color.gray)); 284 Object[] options = new Object[]{tr("OK"), tr("Cancel"), tr("Default")}; 285 int answer = JOptionPane.showOptionDialog( 286 Main.parent, 287 c, 288 tr("Choose a color"), 289 JOptionPane.OK_CANCEL_OPTION, 290 JOptionPane.PLAIN_MESSAGE, null,options, options[0]); 291 switch (answer) { 292 case 0: 293 Main.pref.putColor("layer "+getName(), c.getColor()); 294 break; 295 case 1: 296 return; 297 case 2: 298 Main.pref.putColor("layer "+getName(), null); 299 break; 300 } 301 Main.map.repaint(); 302 } 303 } 296 304 } -
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImages.java
r3310 r3408 40 40 import java.util.zip.GZIPInputStream; 41 41 42 import javax.swing.AbstractAction; 42 43 import javax.swing.AbstractListModel; 43 44 import javax.swing.BorderFactory; … … 83 84 * Then it correlates the images of the layer with that GPX file. 84 85 */ 85 public class CorrelateGpxWithImages implements ActionListener{86 public class CorrelateGpxWithImages extends AbstractAction { 86 87 87 88 private static List<GpxData> loadedGpxData = new ArrayList<GpxData>(); … … 92 93 93 94 public CorrelateGpxWithImages(GeoImageLayer layer) { 95 super(tr("Correlate to GPX"), ImageProvider.get("dialogs/geoimage/gpx2img")); 94 96 this.yLayer = layer; 95 97 } … … 217 219 } 218 220 219 /** 221 /** 220 222 * This action listener is called when the user has a photo of the time of his GPS receiver. It 221 223 * displays the list of photos of the layer, and upon selection displays the selected photo. … … 630 632 tfTimezone.addFocusListener(repaintTheMap); 631 633 tfOffset.addFocusListener(repaintTheMap); 632 634 633 635 tfTimezone.getDocument().addDocumentListener(statusBarUpdater); 634 636 tfOffset.getDocument().addDocumentListener(statusBarUpdater); … … 760 762 StatusBarUpdater statusBarUpdater = new StatusBarUpdater(false); 761 763 StatusBarUpdater statusBarUpdaterWithRepaint = new StatusBarUpdater(true); 762 764 763 765 private class StatusBarUpdater implements DocumentListener, ItemListener, ActionListener { 764 766 private boolean doRepaint; … … 767 769 this.doRepaint = doRepaint; 768 770 } 769 771 770 772 public void insertUpdate(DocumentEvent ev) { 771 773 updateStatusBar(); … … 789 791 } 790 792 } 791 793 792 794 private String statusText() { 793 795 try { … … 803 805 ie.tmp = null; 804 806 } 805 807 806 808 // Construct a list of images that have a date, and sort them on the date. 807 809 ArrayList<ImageEntry> dateImgLst = getSortedImgList(); … … 828 830 public void focusGained(FocusEvent e) { // do nothing 829 831 } 830 832 831 833 public void focusLost(FocusEvent e) { 832 834 yLayer.updateBufferAndRepaint(); … … 1197 1199 if(prevWpTime == 0 || curWpTime <= prevWpTime) { 1198 1200 while (true) { 1199 if (i < 0) 1201 if (i < 0) { 1200 1202 break; 1203 } 1201 1204 final ImageEntry curImg = images.get(i); 1202 1205 if (curImg.getExifTime().getTime() > curWpTime 1203 || curImg.getExifTime().getTime() < curWpTime - interval) 1204 break; 1206 || curImg.getExifTime().getTime() < curWpTime - interval) { 1207 break; 1208 } 1205 1209 if(curImg.tmp.getPos() == null) { 1206 1210 curImg.tmp.setPos(curWp.getCoor()); … … 1218 1222 // previous track point assuming a constant speed in between 1219 1223 while (true) { 1220 if (i < 0) 1224 if (i < 0) { 1221 1225 break; 1226 } 1222 1227 ImageEntry curImg = images.get(i); 1223 1228 long imgTime = curImg.getExifTime().getTime(); 1224 if (imgTime < prevWpTime) 1229 if (imgTime < prevWpTime) { 1225 1230 break; 1231 } 1226 1232 1227 1233 if(curImg.tmp.getPos() == null) { -
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java
r3387 r3408 11 11 import java.awt.AlphaComposite; 12 12 import java.awt.Color; 13 import java.awt.Component;14 13 import java.awt.Composite; 15 14 import java.awt.Dimension; … … 35 34 import java.util.List; 36 35 36 import javax.swing.Action; 37 37 import javax.swing.Icon; 38 38 import javax.swing.JLabel; 39 import javax.swing.JMenuItem;40 39 import javax.swing.JOptionPane; 41 import javax.swing.JSeparator;42 40 import javax.swing.SwingConstants; 43 41 … … 280 278 } 281 279 282 public static interface LayerMenuAddition { 283 public Component getComponent(Layer layer); 284 } 285 286 private static List<LayerMenuAddition> menuAdditions = new LinkedList<LayerMenuAddition>(); 287 public static void registerMenuAddition(LayerMenuAddition addition) { 280 private static List<Action> menuAdditions = new LinkedList<Action>(); 281 public static void registerMenuAddition(Action addition) { 288 282 menuAdditions.add(addition); 289 283 } 290 284 291 285 @Override 292 public Component[] getMenuEntries() { 293 294 JMenuItem correlateItem = new JMenuItem(tr("Correlate to GPX"), ImageProvider.get("dialogs/geoimage/gpx2img")); 295 correlateItem.addActionListener(new CorrelateGpxWithImages(this)); 296 297 List<Component> entries = new ArrayList<Component>(); 298 entries.add(new JMenuItem(LayerListDialog.getInstance().createShowHideLayerAction(this))); 299 entries.add(new JMenuItem(LayerListDialog.getInstance().createDeleteLayerAction(this))); 300 entries.add(new JMenuItem(new RenameLayerAction(null, this))); 301 entries.add(new JSeparator()); 302 entries.add(correlateItem); 286 public Action[] getMenuEntries() { 287 288 List<Action> entries = new ArrayList<Action>(); 289 entries.add(LayerListDialog.getInstance().createShowHideLayerAction()); 290 entries.add(LayerListDialog.getInstance().createDeleteLayerAction()); 291 entries.add(new RenameLayerAction(null, this)); 292 entries.add(SeparatorLayerAction.INSTANCE); 293 entries.add(new CorrelateGpxWithImages(this)); 303 294 if (!menuAdditions.isEmpty()) { 304 entries.add(new JSeparator()); 305 } 306 for (LayerMenuAddition addition : menuAdditions) { 307 entries.add(addition.getComponent(this)); 308 } 309 entries.add(new JSeparator()); 310 entries.add(new JMenuItem(new LayerListPopup.InfoAction(this))); 311 312 return entries.toArray(new Component[0]); 295 entries.add(SeparatorLayerAction.INSTANCE); 296 entries.addAll(menuAdditions); 297 } 298 entries.add(SeparatorLayerAction.INSTANCE); 299 entries.add(new LayerListPopup.InfoAction(this)); 300 301 return entries.toArray(new Action[0]); 313 302 314 303 } … … 472 461 473 462 double dir = e.getExifImgDir(); 474 // Rotate 90 degrees CCW 463 // Rotate 90 degrees CCW 475 464 double headdir = ( dir < 90 ) ? dir + 270 : dir - 90; 476 465 double leftdir = ( headdir < 90 ) ? headdir + 270 : headdir - 90; … … 522 511 Metadata metadata = null; 523 512 Directory dir = null; 524 513 525 514 try { 526 515 metadata = JpegMetadataReader.readMetadata(e.getFile()); … … 531 520 return; 532 521 } 533 522 534 523 try { 535 524 // longitude … … 591 580 592 581 Rational direction = null; 593 582 594 583 try { 595 584 direction = dir.getRational(GpsDirectory.TAG_GPS_IMG_DIRECTION); 585 if (direction != null) { 586 e.setExifImgDir(direction.doubleValue()); 587 } 596 588 } catch (CompoundException p) { 597 direction = null; 598 } catch (Exception ex) { 599 direction = null; 600 } 601 602 if (direction != null) { 603 e.setExifImgDir(direction.doubleValue()); 604 } 589 // Do nothing 590 } 591 605 592 606 593 } -
trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayer.java
r3237 r3408 11 11 import java.awt.Point; 12 12 import java.awt.event.ActionEvent; 13 import java.awt.event.ActionListener;14 13 import java.awt.event.MouseAdapter; 15 14 import java.awt.event.MouseEvent; … … 18 17 import java.util.ArrayList; 19 18 import java.util.Collection; 19 import java.util.List; 20 20 21 21 import javax.swing.AbstractAction; 22 import javax.swing.Action; 22 23 import javax.swing.Icon; 23 24 import javax.swing.JCheckBoxMenuItem; 24 25 import javax.swing.JColorChooser; 25 import javax.swing.JMenuItem;26 26 import javax.swing.JOptionPane; 27 import javax.swing.JSeparator;28 27 import javax.swing.SwingUtilities; 29 28 … … 197 196 } 198 197 199 @Override public Component[] getMenuEntries() { 200 JMenuItem color = new JMenuItem(tr("Customize Color"), ImageProvider.get("colorchooser")); 201 color.putClientProperty("help", "Action/LayerCustomizeColor"); 202 color.addActionListener(new ActionListener(){ 203 public void actionPerformed(ActionEvent e) { 204 JColorChooser c = new JColorChooser(getColor(getName())); 205 Object[] options = new Object[]{tr("OK"), tr("Cancel"), tr("Default")}; 206 int answer = JOptionPane.showOptionDialog( 207 Main.parent, 208 c, 209 tr("Choose a color"), 210 JOptionPane.OK_CANCEL_OPTION, 211 JOptionPane.PLAIN_MESSAGE, 212 null, 213 options, 214 options[0] 215 ); 216 switch (answer) { 217 case 0: 218 Main.pref.putColor("layer "+getName(), c.getColor()); 219 break; 220 case 1: 221 return; 222 case 2: 223 Main.pref.putColor("layer "+getName(), null); 224 break; 225 } 226 Main.map.repaint(); 227 } 228 }); 229 230 JMenuItem syncaudio = new JMenuItem(tr("Synchronize Audio"), ImageProvider.get("audio-sync")); 231 syncaudio.putClientProperty("help", "Action/SynchronizeAudio"); 232 syncaudio.addActionListener(new ActionListener(){ 233 public void actionPerformed(ActionEvent e) { 234 if (! AudioPlayer.paused()) { 235 JOptionPane.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 ); 241 return; 242 } 243 AudioMarker recent = AudioMarker.recentlyPlayedMarker(); 244 if (synchronizeAudioMarkers(recent)) { 245 JOptionPane.showMessageDialog( 246 Main.parent, 247 tr("Audio synchronized at point {0}.", recent.text), 248 tr("Information"), 249 JOptionPane.INFORMATION_MESSAGE 250 ); 251 } else { 252 JOptionPane.showMessageDialog( 253 Main.parent, 254 tr("Unable to synchronize in layer being played."), 255 tr("Error"), 256 JOptionPane.ERROR_MESSAGE 257 ); 258 } 259 } 260 }); 261 262 JMenuItem moveaudio = new JMenuItem(tr("Make Audio Marker at Play Head"), ImageProvider.get("addmarkers")); 263 moveaudio.putClientProperty("help", "Action/MakeAudioMarkerAtPlayHead"); 264 moveaudio.addActionListener(new ActionListener(){ 265 public void actionPerformed(ActionEvent e) { 266 if (! AudioPlayer.paused()) { 267 JOptionPane.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 ); 273 return; 274 } 275 PlayHeadMarker playHeadMarker = Main.map.mapView.playHeadMarker; 276 if (playHeadMarker == null) 277 return; 278 addAudioMarker(playHeadMarker.time, playHeadMarker.getCoor()); 279 Main.map.mapView.repaint(); 280 } 281 }); 282 283 Collection<Component> components = new ArrayList<Component>(); 284 components.add(new JMenuItem(LayerListDialog.getInstance().createShowHideLayerAction(this))); 285 JCheckBoxMenuItem showMarkerTextItem = new JCheckBoxMenuItem(new ShowHideMarkerText(this)); 286 showMarkerTextItem.setState(isTextOrIconShown()); 287 components.add(showMarkerTextItem); 288 components.add(new JMenuItem(LayerListDialog.getInstance().createDeleteLayerAction(this))); 289 components.add(new JSeparator()); 290 components.add(color); 291 components.add(new JSeparator()); 292 components.add(syncaudio); 198 @Override public Action[] getMenuEntries() { 199 Collection<Action> components = new ArrayList<Action>(); 200 components.add(LayerListDialog.getInstance().createShowHideLayerAction()); 201 components.add(new ShowHideMarkerText(this)); 202 components.add(LayerListDialog.getInstance().createDeleteLayerAction()); 203 components.add(SeparatorLayerAction.INSTANCE); 204 components.add(new CustomizeColor()); 205 components.add(SeparatorLayerAction.INSTANCE); 206 components.add(new SynchronizeAudio()); 293 207 if (Main.pref.getBoolean("marker.traceaudio", true)) { 294 components.add ( moveaudio);295 } 296 components.add(new JMenuItem(new RenameLayerAction(getAssociatedFile(), this)));297 components.add( new JSeparator());298 components.add(new JMenuItem(new LayerListPopup.InfoAction(this)));299 return components.toArray(new Component[0]);208 components.add (new MoveAudio()); 209 } 210 components.add(new RenameLayerAction(getAssociatedFile(), this)); 211 components.add(SeparatorLayerAction.INSTANCE); 212 components.add(new LayerListPopup.InfoAction(this)); 213 return components.toArray(new Action[0]); 300 214 } 301 215 … … 457 371 } 458 372 459 public static final class ShowHideMarkerText extends AbstractAction {373 public static final class ShowHideMarkerText extends AbstractAction implements LayerAction { 460 374 private final MarkerLayer layer; 461 375 … … 472 386 Main.map.mapView.repaint(); 473 387 } 388 389 390 @Override 391 public Component createMenuComponent() { 392 JCheckBoxMenuItem showMarkerTextItem = new JCheckBoxMenuItem(this); 393 showMarkerTextItem.setState(layer.isTextOrIconShown()); 394 return showMarkerTextItem; 395 } 396 397 398 @Override 399 public boolean supportLayers(List<Layer> layers) { 400 return layers.size() == 1 && layers.get(0) instanceof MarkerLayer; 401 } 402 } 403 404 private class CustomizeColor extends AbstractAction { 405 406 public CustomizeColor() { 407 super(tr("Customize Color"), ImageProvider.get("colorchooser")); 408 putValue("help", "Action/LayerCustomizeColor"); 409 } 410 411 @Override 412 public void actionPerformed(ActionEvent e) { 413 JColorChooser c = new JColorChooser(getColor(getName())); 414 Object[] options = new Object[]{tr("OK"), tr("Cancel"), tr("Default")}; 415 int answer = JOptionPane.showOptionDialog( 416 Main.parent, 417 c, 418 tr("Choose a color"), 419 JOptionPane.OK_CANCEL_OPTION, 420 JOptionPane.PLAIN_MESSAGE, 421 null, 422 options, 423 options[0] 424 ); 425 switch (answer) { 426 case 0: 427 Main.pref.putColor("layer "+getName(), c.getColor()); 428 break; 429 case 1: 430 return; 431 case 2: 432 Main.pref.putColor("layer "+getName(), null); 433 break; 434 } 435 Main.map.repaint(); 436 } 437 } 438 439 private class SynchronizeAudio extends AbstractAction { 440 441 public SynchronizeAudio() { 442 super(tr("Synchronize Audio"), ImageProvider.get("audio-sync")); 443 putValue("help", "Action/SynchronizeAudio"); 444 } 445 446 @Override 447 public void actionPerformed(ActionEvent e) { 448 if (! AudioPlayer.paused()) { 449 JOptionPane.showMessageDialog( 450 Main.parent, 451 tr("You need to pause audio at the moment when you hear your synchronization cue."), 452 tr("Warning"), 453 JOptionPane.WARNING_MESSAGE 454 ); 455 return; 456 } 457 AudioMarker recent = AudioMarker.recentlyPlayedMarker(); 458 if (synchronizeAudioMarkers(recent)) { 459 JOptionPane.showMessageDialog( 460 Main.parent, 461 tr("Audio synchronized at point {0}.", recent.text), 462 tr("Information"), 463 JOptionPane.INFORMATION_MESSAGE 464 ); 465 } else { 466 JOptionPane.showMessageDialog( 467 Main.parent, 468 tr("Unable to synchronize in layer being played."), 469 tr("Error"), 470 JOptionPane.ERROR_MESSAGE 471 ); 472 } 473 } 474 } 475 476 private class MoveAudio extends AbstractAction { 477 478 public MoveAudio() { 479 super(tr("Make Audio Marker at Play Head"), ImageProvider.get("addmarkers")); 480 putValue("help", "Action/MakeAudioMarkerAtPlayHead"); 481 } 482 483 @Override 484 public void actionPerformed(ActionEvent e) { 485 if (! AudioPlayer.paused()) { 486 JOptionPane.showMessageDialog( 487 Main.parent, 488 tr("You need to have paused audio at the point on the track where you want the marker."), 489 tr("Warning"), 490 JOptionPane.WARNING_MESSAGE 491 ); 492 return; 493 } 494 PlayHeadMarker playHeadMarker = Main.map.mapView.playHeadMarker; 495 if (playHeadMarker == null) 496 return; 497 addAudioMarker(playHeadMarker.time, playHeadMarker.getCoor()); 498 Main.map.mapView.repaint(); 499 } 474 500 } 475 501 } -
trunk/src/org/openstreetmap/josm/gui/oauth/OsmLoginFailedException.java
r3083 r3408 6 6 public OsmLoginFailedException() { 7 7 super(); 8 // TODO Auto-generated constructor stub9 8 } 10 9 11 10 public OsmLoginFailedException(String arg0, Throwable arg1) { 12 11 super(arg0, arg1); 13 // TODO Auto-generated constructor stub14 12 } 15 13 16 14 public OsmLoginFailedException(String arg0) { 17 15 super(arg0); 18 // TODO Auto-generated constructor stub19 16 } 20 17 21 18 public OsmLoginFailedException(Throwable arg0) { 22 19 super(arg0); 23 // TODO Auto-generated constructor stub24 20 } 25 21 } -
trunk/src/org/openstreetmap/josm/gui/progress/NullProgressMonitor.java
r3083 r3408 78 78 79 79 public int getTicksCount() { 80 // TODO Auto-generated method stub81 80 return 0; 82 81 } -
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPresetSearchDialog.java
r3388 r3408 313 313 */ 314 314 private void filterPresets(String text) { 315 //TODO search also in keys/values316 315 //TODO Favorites 317 316 text = text.toLowerCase(); -
trunk/src/org/openstreetmap/josm/io/GpxReader.java
r3372 r3408 8 8 import java.io.IOException; 9 9 import java.io.InputStream; 10 import java.io.InputStreamReader;11 10 import java.util.ArrayList; 12 11 import java.util.Collection;
Note:
See TracChangeset
for help on using the changeset viewer.