Ignore:
Timestamp:
2006-12-29T16:57:07+01:00 (19 years ago)
Author:
imi
Message:
  • fixed display of tooltip shortcuts
  • added icon=... to annotation presets
  • added support for putting annotation presets in the toolbar
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java

    r155 r178  
    1414import java.awt.event.MouseAdapter;
    1515import java.awt.event.MouseEvent;
    16 import java.io.FileInputStream;
    17 import java.io.IOException;
    18 import java.io.InputStream;
    19 import java.net.URL;
    2016import java.util.Collection;
    2117import java.util.HashMap;
    2218import java.util.Map;
    23 import java.util.StringTokenizer;
    2419import java.util.TreeMap;
    2520import java.util.TreeSet;
     
    4338import org.openstreetmap.josm.Main;
    4439import org.openstreetmap.josm.command.ChangePropertyCommand;
    45 import org.openstreetmap.josm.command.Command;
    4640import org.openstreetmap.josm.data.SelectionChangedListener;
    4741import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    4943import org.openstreetmap.josm.gui.annotation.AnnotationCellRenderer;
    5044import org.openstreetmap.josm.gui.annotation.AnnotationPreset;
     45import org.openstreetmap.josm.gui.annotation.ForwardActionListener;
     46import org.openstreetmap.josm.gui.preferences.AnnotationPresetPreference;
    5147import org.openstreetmap.josm.tools.ImageProvider;
    52 import org.xml.sax.SAXException;
    5348
    5449/**
     
    214209         */
    215210        private final JTable propertyTable = new JTable(data);
    216         private JComboBox annotationPresets = new JComboBox();
     211        public JComboBox annotationPresets = new JComboBox();
     212
    217213
    218214        /**
     
    222218                super(tr("Properties"), "propertiesdialog", tr("Property for selected objects."), KeyEvent.VK_P, 150);
    223219
    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()));
    249226                        annotationPresets.setModel(new DefaultComboBoxModel(allPresets));
    250227                        add(annotationPresets, BorderLayout.NORTH);
     
    252229                annotationPresets.addActionListener(new ActionListener(){
    253230                        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);
    272233                        }
    273234                });
Note: See TracChangeset for help on using the changeset viewer.