Changeset 178 in josm for src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java
- Timestamp:
- 2006-12-29T16:57:07+01:00 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java
r155 r178 14 14 import java.awt.event.MouseAdapter; 15 15 import java.awt.event.MouseEvent; 16 import java.io.FileInputStream;17 import java.io.IOException;18 import java.io.InputStream;19 import java.net.URL;20 16 import java.util.Collection; 21 17 import java.util.HashMap; 22 18 import java.util.Map; 23 import java.util.StringTokenizer;24 19 import java.util.TreeMap; 25 20 import java.util.TreeSet; … … 43 38 import org.openstreetmap.josm.Main; 44 39 import org.openstreetmap.josm.command.ChangePropertyCommand; 45 import org.openstreetmap.josm.command.Command;46 40 import org.openstreetmap.josm.data.SelectionChangedListener; 47 41 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 49 43 import org.openstreetmap.josm.gui.annotation.AnnotationCellRenderer; 50 44 import org.openstreetmap.josm.gui.annotation.AnnotationPreset; 45 import org.openstreetmap.josm.gui.annotation.ForwardActionListener; 46 import org.openstreetmap.josm.gui.preferences.AnnotationPresetPreference; 51 47 import org.openstreetmap.josm.tools.ImageProvider; 52 import org.xml.sax.SAXException;53 48 54 49 /** … … 214 209 */ 215 210 private final JTable propertyTable = new JTable(data); 216 private JComboBox annotationPresets = new JComboBox(); 211 public JComboBox annotationPresets = new JComboBox(); 212 217 213 218 214 /** … … 222 218 super(tr("Properties"), "propertiesdialog", tr("Property for selected objects."), KeyEvent.VK_P, 150); 223 219 224 Vector<AnnotationPreset> allPresets = new Vector<AnnotationPreset>(); 225 String allAnnotations = Main.pref.get("annotation.sources"); 226 StringTokenizer st = new StringTokenizer(allAnnotations, ";"); 227 while (st.hasMoreTokens()) { 228 InputStream in = null; 229 String source = st.nextToken(); 230 try { 231 if (source.startsWith("http") || source.startsWith("ftp") || source.startsWith("file")) 232 in = new URL(source).openStream(); 233 else if (source.startsWith("resource://")) 234 in = Main.class.getResourceAsStream(source.substring("resource:/".length())); 235 else 236 in = new FileInputStream(source); 237 allPresets.addAll(AnnotationPreset.readAll(in)); 238 in.close(); 239 } catch (IOException e) { 240 e.printStackTrace(); 241 JOptionPane.showMessageDialog(Main.parent, tr("Could not read annotation preset source: {0}",source)); 242 } catch (SAXException e) { 243 e.printStackTrace(); 244 JOptionPane.showMessageDialog(Main.parent, tr("Error parsing {0}: ", source)+e.getMessage()); 245 } 246 } 247 if (allPresets.size() > 0) { 248 allPresets.add(0, new AnnotationPreset()); 220 if (AnnotationPresetPreference.annotationPresets.size() > 0) { 221 Vector<ActionListener> allPresets = new Vector<ActionListener>(); 222 for (final AnnotationPreset p : AnnotationPresetPreference.annotationPresets) 223 allPresets.add(new ForwardActionListener(this, p)); 224 225 allPresets.add(0, new ForwardActionListener(this, new AnnotationPreset())); 249 226 annotationPresets.setModel(new DefaultComboBoxModel(allPresets)); 250 227 add(annotationPresets, BorderLayout.NORTH); … … 252 229 annotationPresets.addActionListener(new ActionListener(){ 253 230 public void actionPerformed(ActionEvent e) { 254 Collection<OsmPrimitive> sel = Main.ds.getSelected(); 255 AnnotationPreset preset = (AnnotationPreset)annotationPresets.getSelectedItem(); 256 JPanel p = preset.createPanel(); 257 if (p == null) 258 return; 259 int answer; 260 if (p.getComponentCount() == 0) 261 answer = JOptionPane.OK_OPTION; 262 else 263 answer = JOptionPane.showConfirmDialog(Main.parent, p, trn("Change {0} object", "Change {0} objects", sel.size(), sel.size()), JOptionPane.OK_CANCEL_OPTION); 264 if (answer == JOptionPane.OK_OPTION) { 265 Command cmd = preset.createCommand(sel); 266 if (cmd != null) { 267 Main.main.editLayer().add(cmd); 268 selectionChanged(sel); // update whole table 269 } 270 } 271 annotationPresets.setSelectedIndex(0); 231 AnnotationPreset preset = ((ForwardActionListener)annotationPresets.getSelectedItem()).preset; 232 preset.actionPerformed(e); 272 233 } 273 234 });
Note:
See TracChangeset
for help on using the changeset viewer.
