Changeset 4287 in josm


Ignore:
Timestamp:
2011-08-07T19:14:38+02:00 (11 years ago)
Author:
jttt
Message:

Add validation for label pattern

Location:
trunk/src/org/openstreetmap/josm/gui/preferences
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/preferences/DrawingPreference.java

    r4270 r4287  
    33
    44import static org.openstreetmap.josm.tools.I18n.tr;
    5 import static org.openstreetmap.josm.tools.I18n.trc;
    65
    76import java.awt.Dimension;
     
    1211import javax.swing.BorderFactory;
    1312import javax.swing.Box;
    14 import javax.swing.ButtonGroup;
    1513import javax.swing.JCheckBox;
    16 import javax.swing.JComboBox;
    17 import javax.swing.JLabel;
    1814import javax.swing.JPanel;
    19 import javax.swing.JRadioButton;
    2015import javax.swing.JScrollPane;
    21 import javax.swing.JTextField;
    22 import javax.swing.event.ChangeEvent;
    23 import javax.swing.event.ChangeListener;
    2416
    2517import org.openstreetmap.josm.Main;
     
    4840        gui.display.setPreferredSize(new Dimension(400,600));
    4941        gpxPanel = new GPXSettingsPanel();
     42        gui.addValidationListener(gpxPanel);
    5043        JPanel panel = gpxPanel;
    51        
     44
    5245        JScrollPane scrollpane = new JScrollPane(panel);
    5346        scrollpane.setBorder(BorderFactory.createEmptyBorder( 0, 0, 0, 0 ));
  • trunk/src/org/openstreetmap/josm/gui/preferences/GPXSettingsPanel.java

    r4282 r4287  
    1414import javax.swing.JComboBox;
    1515import javax.swing.JLabel;
     16import javax.swing.JOptionPane;
    1617import javax.swing.JPanel;
    1718import javax.swing.JRadioButton;
     
    2324import org.openstreetmap.josm.gui.layer.markerlayer.Marker;
    2425import org.openstreetmap.josm.gui.layer.markerlayer.Marker.TemplateEntryProperty;
     26import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane.ValidationListener;
    2527import org.openstreetmap.josm.tools.GBC;
    26 
    27 public class GPXSettingsPanel extends JPanel {
     28import org.openstreetmap.josm.tools.template_engine.ParseError;
     29import org.openstreetmap.josm.tools.template_engine.TemplateParser;
     30
     31public class GPXSettingsPanel extends JPanel implements ValidationListener {
    2832
    2933    private static final int WAYPOINT_LABEL_CUSTOM = 6;
     
    397401    }
    398402
     403    @Override
     404    public boolean validatePreferences() {
     405        TemplateParser parser = new TemplateParser(waypointLabelPattern.getText());
     406        try {
     407            parser.parse();
     408        } catch (ParseError e) {
     409            JOptionPane.showMessageDialog(Main.parent, tr("Incorrect waypoint label pattern: {0}", e.getMessage()), tr("Incorrect pattern"), JOptionPane.ERROR_MESSAGE);
     410            waypointLabelPattern.requestFocus();
     411            return false;
     412        }
     413        parser = new TemplateParser(audioWaypointLabelPattern.getText());
     414        try {
     415            parser.parse();
     416        } catch (ParseError e) {
     417            JOptionPane.showMessageDialog(Main.parent, tr("Incorrect audio waypoint label pattern: {0}", e.getMessage()), tr("Incorrect pattern"), JOptionPane.ERROR_MESSAGE);
     418            audioWaypointLabelPattern.requestFocus();
     419            return false;
     420        }
     421        return true;
     422    }
     423
    399424}
Note: See TracChangeset for help on using the changeset viewer.