Changeset 2334 in josm for trunk/src/org
- Timestamp:
- 2009-10-27T22:33:54+01:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/DownloadAction.java
r2331 r2334 5 5 import static org.openstreetmap.josm.tools.I18n.tr; 6 6 7 import java.awt.BorderLayout;8 import java.awt.Dimension;9 7 import java.awt.event.ActionEvent; 10 8 import java.awt.event.KeyEvent; 11 9 import java.util.concurrent.Future; 12 10 import java.util.logging.Logger; 13 14 import javax.swing.JOptionPane;15 import javax.swing.JPanel;16 11 17 12 import org.openstreetmap.josm.Main; … … 20 15 import org.openstreetmap.josm.actions.downloadtasks.PostDownloadHandler; 21 16 import org.openstreetmap.josm.data.Bounds; 22 import org.openstreetmap.josm.gui.ExtendedDialog;23 17 import org.openstreetmap.josm.gui.download.DownloadDialog; 24 18 import org.openstreetmap.josm.tools.Shortcut; 25 import org.openstreetmap.josm.tools.WindowGeometry;26 19 27 20 /** … … 47 40 if (! dialog.isCanceled()) { 48 41 dialog.rememberSettings(); 49 Bounds area = dialog.getSelectedDownloadArea(); 42 Bounds area = dialog.getSelectedDownloadArea(); 50 43 if (dialog.isDownloadOsmData()) { 51 44 DownloadOsmTask task = new DownloadOsmTask(); -
trunk/src/org/openstreetmap/josm/data/Preferences.java
r2327 r2334 60 60 */ 61 61 public static class Bookmark implements Comparable<Bookmark> { 62 p ublicString name;63 p ublic double[] latlon = new double[4]; // minlat, minlon, maxlat, maxlon62 private String name; 63 private Bounds area; 64 64 65 public Bookmark() { 65 public Bookmark() { 66 area = null; 67 name = null; 66 68 } 67 69 68 public Bookmark(Bounds b) { 69 if (b == null) { 70 latlon[0] = 0.0; 71 latlon[1] = 0.0; 72 latlon[2] = 0.0; 73 latlon[3] = 0.0; 74 } else { 75 latlon[0] = b.getMin().lat(); 76 latlon[1] = b.getMin().lon(); 77 latlon[2] = b.getMax().lat(); 78 latlon[3] = b.getMax().lon(); 79 } 70 public Bookmark(Bounds area) { 71 this.area = area; 80 72 } 81 73 … … 88 80 } 89 81 90 public Bounds asBounds() { 91 return new Bounds(latlon[0], latlon[1], latlon[2], latlon[3]); 82 public Bounds getArea() { 83 return area; 84 } 85 86 public String getName() { 87 return name; 88 } 89 90 public void setName(String name) { 91 this.name = name; 92 } 93 94 public void setArea(Bounds area) { 95 this.area = area; 92 96 } 93 97 } … … 488 492 // FIXME: legacy code using ',' sign, should be \u001e only 489 493 Matcher m = Pattern.compile("^(.+)[,\u001e](-?\\d+.\\d+)[,\u001e](-?\\d+.\\d+)[,\u001e](-?\\d+.\\d+)[,\u001e](-?\\d+.\\d+)$").matcher(line); 490 if(m.matches()) 491 { 492 Bookmark b = new Bookmark(); 493 b.name = m.group(1); 494 for (int i = 0; i < b.latlon.length; ++i) { 495 b.latlon[i] = Double.parseDouble(m.group(i+2)); 494 if (!m.matches() || m.groupCount() != 5) { 495 System.err.println(tr("Error: Unexpected line ''{0}'' in bookmark file ''{1}''",line, bookmarkFile.toString())); 496 continue; 497 } 498 Bookmark b = new Bookmark(); 499 b.setName(m.group(1)); 500 double[] values= new double[4]; 501 for (int i = 0; i < 4; ++i) { 502 try { 503 values[i] = Double.parseDouble(m.group(i+2)); 504 } catch(NumberFormatException e) { 505 System.err.println(tr("Error: Illegal double value ''{0}'' on line ''{1}'' in bookmark file ''{2}''",m.group(i+2),line, bookmarkFile.toString())); 506 continue; 496 507 } 497 bookmarks.add(b); 498 } 508 } 509 b.setArea(new Bounds(values)); 510 bookmarks.add(b); 499 511 } 500 512 in.close(); … … 511 523 new FileOutputStream(bookmarkFile), "utf-8")); 512 524 for (Bookmark b : bookmarks) { 513 out.print(b.name+"\u001e"); 514 for (int i = 0; i < b.latlon.length; ++i) { 515 out.print(b.latlon[i]+(i<b.latlon.length-1?"\u001e":"")); 516 } 525 out.print(b.getName()+ "\u001e"); 526 Bounds area = b.getArea(); 527 out.print(area.getMin().lat() +"\u001e"); 528 out.print(area.getMin().lon() +"\u001e"); 529 out.print(area.getMax().lat() +"\u001e"); 530 out.print(area.getMax().lon()); 517 531 out.println(); 518 532 } -
trunk/src/org/openstreetmap/josm/data/ServerSidePreferences.java
r2017 r2334 25 25 26 26 import org.openstreetmap.josm.Main; 27 import org.openstreetmap.josm.data.Preferences.Bookmark; 27 28 import org.openstreetmap.josm.io.OsmConnection; 28 29 import org.openstreetmap.josm.io.XmlWriter; … … 191 192 for (String line = in.readLine(); line != null; line = in.readLine()) { 192 193 StringTokenizer st = new StringTokenizer(line, ","); 193 if (st.countTokens() < 5) { 194 if (st.countTokens() != 5) { 195 System.err.println(tr("Error: Unexpected line ''{0}'' in bookmark list from server",line)); 194 196 continue; 195 197 } 196 198 Bookmark b = new Bookmark(); 197 b.name = st.nextToken(); 198 try { 199 for (int i = 0; i < b.latlon.length; ++i) { 200 b.latlon[i] = Double.parseDouble(st.nextToken()); 199 b.setName(st.nextToken()); 200 double[] values= new double[4]; 201 for (int i = 0; i < 4; ++i) { 202 String token = st.nextToken(); 203 try { 204 values[i] = Double.parseDouble(token); 205 } catch(NumberFormatException e) { 206 System.err.println(tr("Error: Illegal double value ''{0}'' on line ''{1}'' in bookmark list from server",token,line)); 207 continue; 201 208 } 202 bookmarks.add(b); 203 } catch (NumberFormatException x) { 204 // line not parsed 205 } 209 } 210 b.setArea(new Bounds(values)); 211 bookmarks.add(b); 206 212 } 207 213 in.close(); -
trunk/src/org/openstreetmap/josm/gui/BookmarkList.java
r2067 r2334 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.Component; 6 7 import java.io.IOException; 7 8 import java.util.Collection; … … 9 10 10 11 import javax.swing.DefaultListModel; 12 import javax.swing.JLabel; 11 13 import javax.swing.JList; 12 14 import javax.swing.JOptionPane; 15 import javax.swing.ListCellRenderer; 16 import javax.swing.UIManager; 13 17 14 18 import org.openstreetmap.josm.Main; 19 import org.openstreetmap.josm.data.Bounds; 15 20 import org.openstreetmap.josm.data.Preferences; 21 import org.openstreetmap.josm.data.Preferences.Bookmark; 16 22 17 23 /** … … 28 34 load(); 29 35 setVisibleRowCount(7); 36 setCellRenderer(new BookmarkCellRenderer()); 30 37 } 31 38 … … 73 80 } 74 81 } 82 83 class BookmarkCellRenderer extends JLabel implements ListCellRenderer { 84 85 public BookmarkCellRenderer() { 86 setOpaque(true); 87 } 88 89 protected void renderColor(boolean selected) { 90 if (selected) { 91 setBackground(UIManager.getColor("List.selectionBackground")); 92 setForeground(UIManager.getColor("List.selectionForeground")); 93 } else { 94 setBackground(UIManager.getColor("List.background")); 95 setForeground(UIManager.getColor("List.foreground")); 96 } 97 } 98 99 protected String buildToolTipText(Bookmark b) { 100 Bounds area = b.getArea(); 101 StringBuffer sb = new StringBuffer(); 102 sb.append("<html>min[latitude,longitude]=<strong>[") 103 .append(area.getMin().lat()).append(",").append(area.getMin().lon()).append("]</strong>") 104 .append("<br>") 105 .append("max[latitude,longitude]=<strong>[") 106 .append(area.getMax().lat()).append(",").append(area.getMax().lon()).append("]</strong>") 107 .append("</html>"); 108 return sb.toString(); 109 110 } 111 public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, 112 boolean cellHasFocus) { 113 114 Bookmark b = (Bookmark) value; 115 renderColor(isSelected); 116 setText(b.getName()); 117 setToolTipText(buildToolTipText(b)); 118 return this; 119 } 120 } 75 121 } -
trunk/src/org/openstreetmap/josm/gui/download/BookmarkSelection.java
r2332 r2334 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.GridBagConstraints; 6 7 import java.awt.GridBagLayout; 7 import java.awt.GridLayout;8 8 import java.awt.event.ActionEvent; 9 import java.awt.event.ActionListener;10 9 10 import javax.swing.AbstractAction; 11 11 import javax.swing.DefaultListModel; 12 12 import javax.swing.JButton; … … 20 20 import org.openstreetmap.josm.data.Bounds; 21 21 import org.openstreetmap.josm.data.Preferences; 22 import org.openstreetmap.josm.data.Preferences.Bookmark; 22 23 import org.openstreetmap.josm.gui.BookmarkList; 23 import org.openstreetmap.josm.tools. GBC;24 import org.openstreetmap.josm.tools.ImageProvider; 24 25 25 26 /** … … 34 35 public class BookmarkSelection implements DownloadSelection { 35 36 36 private Preferences.Bookmark tempBookmark = null;37 private Bounds currentArea; 37 38 private BookmarkList bookmarks; 39 40 protected JPanel buildButtonPanel() { 41 JPanel pnl = new JPanel(); 42 pnl.setLayout(new GridBagLayout()); 43 GridBagConstraints gc = new GridBagConstraints(); 44 gc.fill = GridBagConstraints.HORIZONTAL; 45 gc.weightx = 1.0; 46 gc.weighty = 0.0; 47 pnl.add(new JButton(new AddAction()), gc); 38 48 49 gc.gridy = 1; 50 RemoveAction removeAction = new RemoveAction(); 51 bookmarks.addListSelectionListener(removeAction); 52 pnl.add(new JButton(removeAction), gc); 53 54 gc.gridy = 2; 55 RenameAction renameAction = new RenameAction(); 56 bookmarks.addListSelectionListener(renameAction); 57 pnl.add(new JButton(renameAction), gc); 58 59 gc.fill = GridBagConstraints.BOTH; 60 gc.weightx = 1.0; 61 gc.weighty = 1.0; 62 gc.gridy = 3; 63 pnl.add(new JPanel(), gc); // just a filler 64 return pnl; 65 } 66 39 67 public void addGui(final DownloadDialog gui) { 40 41 68 JPanel dlg = new JPanel(new GridBagLayout()); 42 69 gui.addDownloadAreaSelector(dlg, tr("Bookmarks")); 43 70 GridBagConstraints gc = new GridBagConstraints(); 71 72 44 73 bookmarks = new BookmarkList(); 45 74 bookmarks.getSelectionModel().addListSelectionListener(new ListSelectionListener() { … … 47 76 Preferences.Bookmark b = (Preferences.Bookmark)bookmarks.getSelectedValue(); 48 77 if (b != null) { 49 gui.boundingBoxChanged(b. asBounds(),BookmarkSelection.this);78 gui.boundingBoxChanged(b.getArea(),BookmarkSelection.this); 50 79 } 51 80 } 52 81 }); 53 //wc.addListMarker(bookmarks); 54 dlg.add(new JScrollPane(bookmarks), GBC.eol().fill()); 55 56 JPanel buttons = new JPanel(new GridLayout(1,2)); 57 JButton add = new JButton(tr("Add")); 58 add.addActionListener(new ActionListener(){ 59 public void actionPerformed(ActionEvent e) { 60 61 if (tempBookmark == null) { 62 JOptionPane.showMessageDialog( 63 Main.parent, 64 tr("Please enter the desired coordinates first."), 65 tr("Information"), 66 JOptionPane.INFORMATION_MESSAGE 67 ); 68 return; 69 } 70 tempBookmark.name = JOptionPane.showInputDialog( 71 Main.parent,tr("Please enter a name for the location."), 72 tr("Name of location"), 73 JOptionPane.QUESTION_MESSAGE 74 ); 75 if (tempBookmark.name != null && !tempBookmark.name.equals("")) { 76 ((DefaultListModel)bookmarks.getModel()).addElement(tempBookmark); 77 bookmarks.save(); 78 } 79 } 80 }); 81 buttons.add(add); 82 JButton remove = new JButton(tr("Remove")); 83 remove.addActionListener(new ActionListener(){ 84 public void actionPerformed(ActionEvent e) { 85 Object sel = bookmarks.getSelectedValue(); 86 if (sel == null) { 87 JOptionPane.showMessageDialog( 88 Main.parent, 89 tr("Select a bookmark first."), 90 tr("Information"), 91 JOptionPane.INFORMATION_MESSAGE 92 ); 93 return; 94 } 95 ((DefaultListModel)bookmarks.getModel()).removeElement(sel); 96 bookmarks.save(); 97 } 98 }); 99 buttons.add(remove); 100 dlg.add(buttons, GBC.eop().fill(GBC.HORIZONTAL)); 82 83 gc.fill = GridBagConstraints.VERTICAL; 84 gc.weightx = 0.0; 85 gc.weighty = 1.0; 86 dlg.add(buildButtonPanel(),gc); 87 88 gc.fill = GridBagConstraints.BOTH; 89 gc.weightx = 1.0; 90 gc.weighty = 1.0; 91 gc.gridx = 1; 92 dlg.add(new JScrollPane(bookmarks), gc); 101 93 } 102 103 94 104 95 public void setDownloadArea(Bounds area) { 105 96 if (area == null) return; 106 t empBookmark = new Preferences.Bookmark(area);97 this.currentArea = area; 107 98 bookmarks.clearSelection(); 108 99 } 100 101 class AddAction extends AbstractAction { 102 public AddAction() { 103 //putValue(NAME, tr("Add")); 104 putValue(SMALL_ICON, ImageProvider.get("dialogs", "add")); 105 putValue(SHORT_DESCRIPTION, tr("Add a bookmark for the currently selected download area")); 106 } 107 108 public void actionPerformed(ActionEvent e) { 109 if (currentArea == null) { 110 JOptionPane.showMessageDialog( 111 Main.parent, 112 tr("Currently, there is no download area selected. Please select an area first."), 113 tr("Information"), 114 JOptionPane.INFORMATION_MESSAGE 115 ); 116 return; 117 } 118 Bookmark b = new Bookmark(); 119 b.setName( 120 JOptionPane.showInputDialog( 121 Main.parent,tr("Please enter a name for the bookmarked download area."), 122 tr("Name of location"), 123 JOptionPane.QUESTION_MESSAGE) 124 ); 125 b.setArea(currentArea); 126 if (b.getName() != null && !b.getName().equals("")) { 127 ((DefaultListModel)bookmarks.getModel()).addElement(b); 128 bookmarks.save(); 129 } 130 } 131 } 132 133 class RemoveAction extends AbstractAction implements ListSelectionListener{ 134 public RemoveAction() { 135 //putValue(NAME, tr("Remove")); 136 putValue(SMALL_ICON, ImageProvider.get("dialogs", "delete")); 137 putValue(SHORT_DESCRIPTION, tr("Remove the currently selected bookmarks")); 138 updateEnabledState(); 139 } 140 141 public void actionPerformed(ActionEvent e) { 142 Object[] sels = bookmarks.getSelectedValues(); 143 if (sels == null || sels.length == 0) { 144 return; 145 } 146 for (Object sel: sels) { 147 ((DefaultListModel)bookmarks.getModel()).removeElement(sel); 148 } 149 bookmarks.save(); 150 } 151 protected void updateEnabledState() { 152 setEnabled(bookmarks.getSelectedIndices().length > 0); 153 } 154 public void valueChanged(ListSelectionEvent e) { 155 updateEnabledState(); 156 } 157 } 158 159 class RenameAction extends AbstractAction implements ListSelectionListener{ 160 public RenameAction() { 161 //putValue(NAME, tr("Remove")); 162 putValue(SMALL_ICON, ImageProvider.get("dialogs", "edit")); 163 putValue(SHORT_DESCRIPTION, tr("Rename the currently selected bookmark")); 164 updateEnabledState(); 165 } 166 167 public void actionPerformed(ActionEvent e) { 168 Object[] sels = bookmarks.getSelectedValues(); 169 if (sels == null || sels.length != 1) { 170 return; 171 } 172 Bookmark b = (Bookmark)sels[0]; 173 Object value = 174 JOptionPane.showInputDialog( 175 Main.parent,tr("Please enter a name for the bookmarked download area."), 176 tr("Name of location"), 177 JOptionPane.QUESTION_MESSAGE, 178 null, 179 null, 180 b.getName() 181 ); 182 if (value != null) { 183 b.setName(value.toString()); 184 bookmarks.save(); 185 bookmarks.repaint(); 186 } 187 } 188 protected void updateEnabledState() { 189 setEnabled(bookmarks.getSelectedIndices().length == 1); 190 } 191 public void valueChanged(ListSelectionEvent e) { 192 updateEnabledState(); 193 } 194 } 195 109 196 } -
trunk/src/org/openstreetmap/josm/gui/download/BoundingBoxSelection.java
r2332 r2334 14 14 import javax.swing.BorderFactory; 15 15 import javax.swing.JLabel; 16 import javax.swing.JOptionPane;17 16 import javax.swing.JPanel; 18 17 import javax.swing.JTextArea; … … 24 23 import javax.swing.text.JTextComponent; 25 24 26 import org.openstreetmap.josm.Main;27 25 import org.openstreetmap.josm.data.Bounds; 28 26 import org.openstreetmap.josm.data.coor.LatLon; … … 183 181 } 184 182 if (!LatLon.isValidLat(value)) { 185 JOptionPane.showMessageDialog(186 Main.parent,187 tr("Value for latitude in range [-90,90] required.", tfLatValue.getText()),188 tr("Error"),189 JOptionPane.ERROR_MESSAGE190 );191 183 setErrorMessage(tr("Value for latitude in range [-90,90] required.", tfLatValue.getText())); 192 184 return;
Note:
See TracChangeset
for help on using the changeset viewer.