Changeset 20586 in osm for applications/editors


Ignore:
Timestamp:
2010-03-21T18:42:23+01:00 (14 years ago)
Author:
guggis
Message:

added special purpose editor for 'except' tag
added background check for data integrity constraints
added view with data integrity errors and warnings

Location:
applications/editors/josm/plugins/turnrestrictions
Files:
30 added
9 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/AdvancedEditorPanel.java

    r20527 r20586  
    3838                JPanel pnl = new JPanel(new BorderLayout());
    3939                HtmlPanel msg = new HtmlPanel();
    40                 msg.setText(tr(
    41                                 "<html><body>In the following table you can edit the <strong>raw tags</strong>"
    42                           + " of the OSM relation representing this turn restriction."
    43                 ));
     40                msg.setText("<html><body>" +
     41                                tr("In the following table you can edit the <strong>raw tags</strong>"
     42                          + " of the OSM relation representing this turn restriction.")
     43                          + "</body></html>"
     44                );
    4445                pnl.add(msg, BorderLayout.NORTH);
    4546                pnlTagEditor = new TagEditorPanel(model.getTagEditorModel());   
     
    5758                JPanel pnl = new JPanel(new BorderLayout());
    5859                HtmlPanel msg = new HtmlPanel();
    59                 msg.setText(tr(
    60                                 "<html><body>In the following table you can edit the <strong>raw members</strong>"
    61                           + " of the OSM relation representing this turn restriction."
    62                 ));
     60                msg.setText("<html><body>" 
     61                          + tr("In the following table you can edit the <strong>raw members</strong>"
     62                          + " of the OSM relation representing this turn restriction.") + "</body></html>"
     63                );
    6364                pnl.add(msg, BorderLayout.NORTH);
    6465               
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/BasicEditorPanel.java

    r20489 r20586  
    1111import javax.swing.JScrollPane;
    1212
     13import org.openstreetmap.josm.gui.widgets.VerticallyScrollablePanel;
     14import org.openstreetmap.josm.plugins.turnrestrictions.editor.NavigationControler.BasicEditorFokusTargets;
    1315import org.openstreetmap.josm.tools.CheckParameterUtil;
    1416
     
    1719 * i.e. its restriction type, the from, the to, and the via objects.
    1820 *
    19  *
    2021 */
    21 public class BasicEditorPanel extends JPanel {
     22public class BasicEditorPanel extends VerticallyScrollablePanel {
    2223
    2324        /** the turn restriction model */
    2425        private TurnRestrictionEditorModel model;
     26       
     27        /** the UI widgets */
     28        private TurnRestrictionLegEditor fromEditor;
     29        private TurnRestrictionLegEditor toEditor;
     30        private ViaList lstVias;
     31        private TurnRestrictionComboBox cbTurnRestrictions;
     32        private VehicleExceptionEditor vehicleExceptionsEditor;
    2533       
    2634        /**
     
    4048            gc.gridx = 1;
    4149            gc.weightx = 1.0;
    42             add(new TurnRestrictionComboBox(new TurnRestrictionComboBoxModel(model)), gc);
     50            add(cbTurnRestrictions = new TurnRestrictionComboBox(new TurnRestrictionComboBoxModel(model)), gc);
    4351
    4452                // the editor for selecting the 'from' leg
     
    5058            gc.gridx = 1;
    5159            gc.weightx = 1.0;
    52             add(new TurnRestrictionLegEditor(model, TurnRestrictionLegRole.FROM),gc);
     60            add(fromEditor = new TurnRestrictionLegEditor(model, TurnRestrictionLegRole.FROM),gc);
    5361
    5462            // the editor for selecting the 'to' leg
     
    6169            gc.gridx = 1;
    6270            gc.weightx = 1.0;
    63             add(new TurnRestrictionLegEditor(model, TurnRestrictionLegRole.TO),gc);
     71            add(toEditor = new TurnRestrictionLegEditor(model, TurnRestrictionLegRole.TO),gc);
    6472           
    6573            // the editor for selecting the 'vias'
     
    7381            gc.weightx = 1.0;
    7482            DefaultListSelectionModel selectionModel = new DefaultListSelectionModel();
    75             add(new JScrollPane(new ViaList(new ViaListModel(model, selectionModel), selectionModel)),gc);
     83            add(new JScrollPane(lstVias = new ViaList(new ViaListModel(model, selectionModel), selectionModel)),gc);
     84           
     85            // the editor for vehicle exceptions
     86            vehicleExceptionsEditor = new VehicleExceptionEditor(model);
     87            gc.gridx = 0;
     88            gc.gridy = 4;
     89                gc.weightx = 1.0;
     90                gc.gridwidth = 2;
     91            gc.insets = new Insets(0,0,5,5);   
     92            add(vehicleExceptionsEditor, gc);
    7693           
    7794            // just a filler - grabs remaining space
    7895            gc.gridx = 0;
    79             gc.gridy = 4;
     96            gc.gridy = 5;
    8097            gc.gridwidth = 2;
    8198            gc.weighty = 1.0;
     
    99116        }
    100117       
    101        
     118        /**
     119         * Requests the focus on one of the input widgets for turn
     120         * restriction data.
     121         *
     122         * @param focusTarget the target component to request focus for.
     123         * Ignored if null.
     124         */
     125        public void requestFocusFor(BasicEditorFokusTargets focusTarget){
     126                if (focusTarget == null) return;
     127                switch(focusTarget){
     128                case RESTRICION_TYPE:
     129                        cbTurnRestrictions.requestFocusInWindow();
     130                        break;
     131                case FROM:
     132                        fromEditor.requestFocusInWindow();
     133                        break;
     134                case TO:
     135                        toEditor.requestFocusInWindow();
     136                        break;
     137                case VIA:
     138                        lstVias.requestFocusInWindow();
     139                        break;
     140                }
     141        }       
    102142}
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/JosmSelectionListModel.java

    r20527 r20586  
    1616import org.openstreetmap.josm.Main;
    1717import org.openstreetmap.josm.data.SelectionChangedListener;
    18 import org.openstreetmap.josm.data.osm.DataSet;
    1918import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2019import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
     
    4544    private final List<OsmPrimitive> selection = new ArrayList<OsmPrimitive>();
    4645    private DefaultListSelectionModel selectionModel;
    47     private DataSet dataSet;
     46    private OsmDataLayer layer;
    4847
    4948    /**
     
    5150     *
    5251     * @param selectionModel the selection model used in the list. Must not be null.
    53      * @param dataSet the dataset this model is displaying the selection from. Must not be null.
     52     * @param layer the layer this model is displaying the selection from. Must not be null.
    5453     * @throws IllegalArgumentException thrown if {@code selectionModel} is null
    55      */
    56     public JosmSelectionListModel(DataSet dataSet, DefaultListSelectionModel selectionModel) {
     54     * @throws IllegalArgumentException thrown if {@code layer} is null
     55     */
     56    public JosmSelectionListModel(OsmDataLayer layer, DefaultListSelectionModel selectionModel) {
    5757        CheckParameterUtil.ensureParameterNotNull(selectionModel, "selectionModel");
    58         CheckParameterUtil.ensureParameterNotNull(dataSet, "dataSet");
    59         this.dataSet = dataSet;
     58        CheckParameterUtil.ensureParameterNotNull(layer, "layer");
     59        this.layer = layer;
    6060        this.selectionModel = selectionModel;
    61         setJOSMSelection(dataSet.getSelected());
     61        setJOSMSelection(layer.data.getSelected());
    6262    }
    6363
     
    160160                // don't show a JOSM selection if we don't have a data layer
    161161            setJOSMSelection(null);
    162         } else if (newLayer.data != dataSet){
     162        } else if (newLayer != layer){
    163163                // don't show a JOSM selection if this turn restriction editor doesn't
    164164                // manipulate data in the current data layer
     
    177177        OsmDataLayer layer = Main.main.getEditLayer();
    178178        if(layer == null) return;
    179         if (layer.data != dataSet) return;
     179        if (layer != this.layer) return;
    180180        setJOSMSelection(newSelection);
    181181    }
     
    185185    /* ------------------------------------------------------------------------ */
    186186    public void dataChanged(DataChangedEvent event) {
    187         if (event.getDataset() != dataSet) return;
     187        if (event.getDataset() != layer.data) return;
    188188        fireContentsChanged(this, 0, getSize());
    189189    }
    190190
    191191    public void nodeMoved(NodeMovedEvent event) {
    192         if (event.getDataset() != dataSet) return;
     192        if (event.getDataset() != layer.data) return;
    193193        // may influence the display name of primitives, update the data
    194194        update(event.getPrimitives());
     
    196196
    197197    public void otherDatasetChange(AbstractDatasetChangedEvent event) {
    198         if (event.getDataset() != dataSet) return;
     198        if (event.getDataset() != layer.data) return;
    199199        // may influence the display name of primitives, update the data
    200200        update(event.getPrimitives());
     
    202202
    203203    public void relationMembersChanged(RelationMembersChangedEvent event) {
    204         if (event.getDataset() != dataSet) return;
     204        if (event.getDataset() != layer.data) return;
    205205        // may influence the display name of primitives, update the data
    206206        update(event.getPrimitives());
     
    208208
    209209    public void tagsChanged(TagsChangedEvent event) {
    210         if (event.getDataset() != dataSet) return;
     210        if (event.getDataset() != layer.data) return;
    211211        // may influence the display name of primitives, update the data
    212212        update(event.getPrimitives());
     
    214214
    215215    public void wayNodesChanged(WayNodesChangedEvent event) {
    216         if (event.getDataset() != dataSet) return;
     216        if (event.getDataset() != layer.data) return;
    217217        // may influence the display name of primitives, update the data
    218218        update(event.getPrimitives());
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/JosmSelectionPanel.java

    r20489 r20586  
    5353         * builds the UI for the panel
    5454         */
    55         protected void build(DataSet ds) {
     55        protected void build(OsmDataLayer layer) {
    5656                setLayout(new BorderLayout());
    5757                DefaultListSelectionModel selectionModel = new DefaultListSelectionModel();
    58                 model = new JosmSelectionListModel(ds,selectionModel);
     58                model = new JosmSelectionListModel(layer,selectionModel);
    5959                lstSelection = new JList(model);
    6060                lstSelection.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
     
    7373       
    7474        /**
    75          * Creates the JOSM selection panel for the selection in a data set.
     75         * Creates the JOSM selection panel for the selection in an OSM data layer
    7676         *
    77          * @param ds the dataset. Must not be null.
    78          * @exception IllegalArgumentException thrown if ds is null
     77         * @param layer the data layer. Must not be null.
     78         * @exception IllegalArgumentException thrown if {@code layer} is null
    7979         */
    80         public JosmSelectionPanel(DataSet ds) throws IllegalArgumentException{
    81                 CheckParameterUtil.ensureParameterNotNull(ds, "ds");
    82                 build(ds);
     80        public JosmSelectionPanel(OsmDataLayer layer) throws IllegalArgumentException{
     81                CheckParameterUtil.ensureParameterNotNull(layer, "layer");
     82                build(layer);
    8383        }
    8484       
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/RelationMemberEditorModel.java

    r20527 r20586  
    136136                return isChanged;
    137137        }
    138        
     138               
    139139        /**
    140140         * Replies the set of {@see OsmPrimitive}s with the role 'from'. If no
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionEditor.java

    r20556 r20586  
    1919import java.util.Iterator;
    2020import java.util.List;
     21import java.util.Observable;
     22import java.util.Observer;
    2123import java.util.logging.Logger;
    2224
     
    2628import javax.swing.JOptionPane;
    2729import javax.swing.JPanel;
     30import javax.swing.JScrollPane;
    2831import javax.swing.JSplitPane;
    2932import javax.swing.JTabbedPane;
     
    4649import org.openstreetmap.josm.gui.help.ContextSensitiveHelpAction;
    4750import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     51import org.openstreetmap.josm.plugins.turnrestrictions.qa.IssuesView;
    4852import org.openstreetmap.josm.tools.CheckParameterUtil;
    4953import org.openstreetmap.josm.tools.ImageProvider;
    5054
    51 
    52 public class TurnRestrictionEditor extends JDialog {
     55public class TurnRestrictionEditor extends JDialog implements NavigationControler{
    5356        final private static Logger logger = Logger.getLogger(TurnRestrictionEditor.class.getName());
    5457       
     
    8184    private BasicEditorPanel pnlBasicEditor;
    8285    private AdvancedEditorPanel pnlAdvancedEditor;
     86    private IssuesView pnlIssuesView;
    8387    private TurnRestrictionEditorModel editorModel;
     88    private JTabbedPane tpEditors;
    8489   
    8590    /**
     
    105110     */
    106111    protected JPanel buildJOSMSelectionPanel() {
    107         pnlJosmSelection = new JosmSelectionPanel(layer.data);
     112        pnlJosmSelection = new JosmSelectionPanel(layer);
    108113        return pnlJosmSelection;
    109114    }
     
    117122    protected JPanel buildEditorPanel() {
    118123        JPanel pnl = new JPanel(new BorderLayout());
    119         JTabbedPane tpEditors = new JTabbedPane();
    120         tpEditors.add(pnlBasicEditor =new BasicEditorPanel(editorModel));
     124        tpEditors = new JTabbedPane();
     125        JScrollPane pane = new JScrollPane(pnlBasicEditor =new BasicEditorPanel(editorModel));
     126        pane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
     127        pane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
     128        tpEditors.add(pane);
    121129        tpEditors.setTitleAt(0, tr("Basic"));
    122130        tpEditors.setToolTipTextAt(0, tr("Edit basic attributes of a turn restriction"));
     
    125133        tpEditors.setTitleAt(1, tr("Advanced"));
    126134        tpEditors.setToolTipTextAt(1, tr("Edit the raw tags and members of this turn restriction"));
     135       
     136        tpEditors.add(pnlIssuesView = new IssuesView(editorModel.getIssuesModel()));
     137        tpEditors.setTitleAt(2, tr("Errors/Warnings"));
     138        tpEditors.setToolTipTextAt(2, tr("Show errors and warnings related to this turn restriction"));
    127139       
    128140        pnl.add(tpEditors, BorderLayout.CENTER);
     
    182194     */
    183195    protected void build() {           
    184         editorModel = new TurnRestrictionEditorModel(getLayer());
     196        editorModel = new TurnRestrictionEditorModel(getLayer(), this);
    185197        Container c = getContentPane();
    186198        c.setLayout(new BorderLayout());
     
    188200        c.add(buildContentPanel(), BorderLayout.CENTER);       
    189201        c.add(buildOkCancelButtonPanel(), BorderLayout.SOUTH);
     202       
     203        editorModel.getIssuesModel().addObserver(new IssuesModelObserver());
    190204        setSize(600,600);
    191205    }   
     
    346360    }
    347361   
    348     /**
     362    /* ----------------------------------------------------------------------- */
     363    /* interface NavigationControler                                           */
     364    /* ----------------------------------------------------------------------- */
     365    public void gotoBasicEditor() {
     366        tpEditors.setSelectedIndex(0);
     367        }
     368
     369    public void gotoAdvancedEditor() {
     370        tpEditors.setSelectedIndex(1);
     371        }
     372
     373        public void gotoBasicEditor(BasicEditorFokusTargets focusTarget) {
     374                tpEditors.setSelectedIndex(0);
     375                pnlBasicEditor.requestFocusFor(focusTarget);
     376        }
     377
     378        /**
    349379     * The abstract base action for applying the updates of a turn restriction
    350380     * to the dataset.
     
    745775                }
    746776    }
     777   
     778    class IssuesModelObserver implements Observer {
     779                public void update(Observable o, Object arg) {
     780                        int numWarnings = editorModel.getIssuesModel().getNumWarnings();
     781                        int numErrors = editorModel.getIssuesModel().getNumErrors();
     782                        String warningText = null;
     783                        if (numWarnings > 0){
     784                                warningText = trn("{0} warning", "{0} warnings", numWarnings, numWarnings);
     785                        }
     786                        String errorText = null;
     787                        if (numErrors > 0){
     788                                errorText = trn("{0} error", "{0} errors", numErrors, numErrors);
     789                        }
     790                        String title = "";
     791                        if (errorText != null) {
     792                                title += errorText;
     793                        }
     794                        if (warningText != null){
     795                                if (title.length() > 0){
     796                                        title += "/";
     797                                }
     798                                title += warningText;
     799                        }
     800                        if (title.length() == 0){
     801                                title = tr("no issues");
     802                        }
     803                        tpEditors.setTitleAt(2, title);
     804                        tpEditors.setEnabledAt(2, numWarnings + numErrors > 0);
     805                }       
     806    }
    747807}
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionEditorModel.java

    r20527 r20586  
    3131import org.openstreetmap.josm.gui.tagging.TagEditorModel;
    3232import org.openstreetmap.josm.gui.tagging.TagModel;
     33import org.openstreetmap.josm.plugins.turnrestrictions.qa.IssuesModel;
    3334import org.openstreetmap.josm.tools.CheckParameterUtil;
    3435
     
    6667        private final TagEditorModel tagEditorModel = new TagEditorModel();
    6768        private  RelationMemberEditorModel memberModel;
     69        private  IssuesModel issuesModel;
    6870       
    6971        /**
     
    7375         * @throws IllegalArgumentException thrown if {@code layer} is null
    7476         */
    75         public TurnRestrictionEditorModel(OsmDataLayer layer) throws IllegalArgumentException{
     77        public TurnRestrictionEditorModel(OsmDataLayer layer, NavigationControler navigationControler) throws IllegalArgumentException{
    7678                CheckParameterUtil.ensureParameterNotNull(layer, "layer");
    7779                this.layer = layer;
    7880                memberModel = new RelationMemberEditorModel(layer);
    7981                memberModel.addTableModelListener(new RelationMemberModelListener());
     82                issuesModel = new IssuesModel(this,navigationControler);
     83                addObserver(issuesModel);
     84                tagEditorModel.addTableModelListener(new TagEditorModelObserver());
    8085        }
    8186       
     
    305310                return memberModel;
    306311        }
     312       
     313        /**
     314         * Replies the model for the open issues in this turn restriction
     315         * editor.
     316         *
     317         * @return the model for the open issues in this turn restriction
     318         * editor
     319         */
     320        public IssuesModel getIssuesModel() {
     321                return issuesModel;
     322        }
     323       
     324        /**
     325         * Replies the current value of the tag "except", or the empty string
     326         * if the tag doesn't exist.
     327         *
     328         * @return
     329         */
     330        public ExceptValueModel getExcept() {
     331                TagModel tag = tagEditorModel.get("except");
     332                if (tag == null) return new ExceptValueModel("");
     333                return new ExceptValueModel(tag.getValue());
     334        }
     335       
     336        /**
     337         * Sets the current value of the tag "except". Removes the
     338         * tag is {@code value} is null or consists of white
     339         * space only.
     340         *
     341         * @param value the new value for 'except'
     342         */
     343        public void setExcept(ExceptValueModel value){
     344                if (value == null || value.getValue().equals("")) {
     345                        if (tagEditorModel.get("except") != null){
     346                                tagEditorModel.delete("except");
     347                                setChanged();
     348                                notifyObservers();                             
     349                        }
     350                        return;                 
     351                }
     352                TagModel tag = tagEditorModel.get("except");
     353                if (tag == null) {
     354                        tagEditorModel.prepend(new TagModel("except", value.getValue()));
     355                        setChanged();
     356                        notifyObservers();
     357                } else {
     358                        if (!tag.getValue().equals(value.getValue())) {
     359                                tag.setValue(value.getValue().trim());
     360                                setChanged();
     361                                notifyObservers();
     362                        }
     363                }               
     364        }
    307365
    308366        /* ----------------------------------------------------------------------------------------- */
     
    363421                        notifyObservers();
    364422                }               
    365         }       
     423        }
     424       
     425        class TagEditorModelObserver implements TableModelListener {
     426                public void tableChanged(TableModelEvent e) {
     427                        setChanged();
     428                        notifyObservers();
     429                }               
     430        }
    366431}
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionLegEditor.java

    r20527 r20586  
    195195                return role;
    196196        }               
    197 
     197       
    198198        /* ----------------------------------------------------------------------------- */
    199199        /* interface Observer                                                            */
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionType.java

    r20489 r20586  
    5656                return null;
    5757        }
     58
     59        /**
     60         * Replies true if {@code tagValue} is a standard restriction type.
     61         *
     62         * @param tagValue the tag value
     63         * @return true if {@code tagValue} is a standard restriction type
     64         */
     65        static public boolean isStandardTagValue(String tagValue){
     66                return fromTagValue(tagValue) != null;
     67        }
    5868}
Note: See TracChangeset for help on using the changeset viewer.