Changeset 2672 in osm for applications/editors/josm


Ignore:
Timestamp:
2007-04-26T22:20:17+02:00 (17 years ago)
Author:
frsantos
Message:

Added a new layer where all errors are highlighted

Location:
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/OSMValidatorPlugin.java

    r2453 r2672  
    6868                if (newFrame != null)
    6969                {
     70            errors = new ArrayList<TestError>(50);
    7071                    validationDialog = new ValidatorDialog();
    7172                newFrame.addToggleDialog(validationDialog);
     73            Main.main.addLayer(new ErrorLayer(tr("Validation errors")));
    7274                }
    7375        }
  • applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/Severity.java

    r2453 r2672  
    11package org.openstreetmap.josm.plugins.validator;
     2
     3import java.awt.Color;
     4
     5import org.openstreetmap.josm.data.osm.visitor.SimplePaintVisitor;
    26
    37/** The error severity */
    48public enum Severity {
    59        /** Error messages */
    6         ERROR("Errors", "error.gif"),
     10        ERROR("Errors", "error.gif",       SimplePaintVisitor.getPreferencesColor("validation error", Color.RED)),
    711        /** Warning messages */
    8         WARNING("Warnings", "warning.gif"),
     12        WARNING("Warnings", "warning.gif", SimplePaintVisitor.getPreferencesColor("validation warning", Color.YELLOW)),
    913        /** Other messages */
    10         OTHER("Other", "other.gif");
     14        OTHER("Other", "other.gif",        SimplePaintVisitor.getPreferencesColor("validation other", Color.CYAN));
    1115       
    1216        /** Description of the severity code */
    1317        private final String message;
    1418       
    15         /** Associated icon */
    16         private final String icon;
     19    /** Associated icon */
     20    private final String icon;
     21
     22    /** Associated color */
     23    private final Color color;
    1724
    1825        /**
     
    2229         * @param icon Associated icon
    2330         */
    24     Severity(String message, String icon)
     31    Severity(String message, String icon, Color color)
    2532    {
    2633        this.message = message;
    2734                this.icon = icon;
     35        this.color = color;
    2836    }
    2937
     
    4250                return icon;
    4351        }
     52
     53    /**
     54     * Gets the associated color
     55     * @return The associated color
     56     */
     57    public Color getColor()
     58    {
     59        return color;
     60    }
    4461   
    4562   
  • applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/Test.java

    r2591 r2672  
    139139         * @return The command to fix the error
    140140         */
    141         public Command fixError(TestError testError)
     141        public Command fixError(@SuppressWarnings("unused") TestError testError)
    142142        {
    143143                return null;
     
    150150         * @return true if the error can be fixed
    151151         */
    152         public boolean isFixable(TestError testError)
     152        public boolean isFixable(@SuppressWarnings("unused") TestError testError)
    153153        {
    154154                return false;
  • applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/TestError.java

    r2591 r2672  
    11package org.openstreetmap.josm.plugins.validator;
    22
     3import java.awt.*;
    34import java.util.ArrayList;
    45import java.util.List;
    56
    67import org.openstreetmap.josm.command.Command;
    7 import org.openstreetmap.josm.data.osm.OsmPrimitive;
     8import org.openstreetmap.josm.data.osm.*;
     9import org.openstreetmap.josm.data.osm.visitor.Visitor;
     10import org.openstreetmap.josm.gui.MapView;
    811
    912/**
     
    2326        /** Internal code used by testers to classify errors */
    2427        private int internalCode;
     28    /** If this error is selected */
     29    private boolean selected;
    2530       
    2631        /**
     
    183188               
    184189                return tester.fixError(this);
    185         }       
     190        }
     191
     192    /**
     193     * Paints the error on affected primitives
     194     *
     195     * @param g The graphics
     196     * @param mv The MapView
     197     */
     198    public void paint(Graphics g, MapView mv)
     199    {
     200        PaintVisitor v = new PaintVisitor(g, mv);
     201        for( OsmPrimitive p : primitives)
     202        {
     203            if( !p.deleted )
     204                p.visit(v);
     205        }
     206    }   
     207   
     208    class PaintVisitor implements Visitor
     209    {
     210        /** The graphics */
     211        private final Graphics g;
     212        /** The MapView */
     213        private final MapView mv;
     214       
     215        /**
     216         * Constructor
     217         * @param g The graphics
     218         * @param mv The Mapview
     219         */
     220        public PaintVisitor(Graphics g, MapView mv)
     221        {
     222            this.g = g;
     223            this.mv = mv;
     224        }
     225
     226        /**
     227         * Draws a circle around the node
     228         * @param n The node
     229         * @param color The circle color
     230         */
     231        public void drawNode(Node n, Color color)
     232        {
     233            Point p = mv.getPoint(n.eastNorth);
     234            g.setColor(color);
     235            if( selected )
     236            {
     237                g.fillOval(p.x-5, p.y-5, 10, 10);
     238            }
     239            else
     240                g.drawOval(p.x-5, p.y-5, 10, 10);
     241        }
     242
     243        /**
     244         * Draws a line around the segment
     245         *
     246         * @param s The segment
     247         * @param color The color
     248         */
     249        public void drawSegment(Segment s, Color color)
     250        {
     251            Point p1 = mv.getPoint(s.from.eastNorth);
     252            Point p2 = mv.getPoint(s.to.eastNorth);
     253            g.setColor(color);
     254           
     255            double t = Math.atan2(p2.x-p1.x, p2.y-p1.y);
     256            double cosT = Math.cos(t);
     257            double sinT = Math.sin(t);
     258            int deg = (int)Math.toDegrees(t);
     259            if( selected )
     260            {
     261                int[] x = new int[] {(int)(p1.x + 5*cosT), (int)(p2.x + 5*cosT), (int)(p2.x - 5*cosT), (int)(p1.x - 5*cosT)};
     262                int[] y = new int[] {(int)(p1.y - 5*sinT), (int)(p2.y - 5*sinT), (int)(p2.y + 5*sinT), (int)(p1.y + 5*sinT)};
     263                g.fillPolygon(x, y, 4);
     264                g.fillArc(p1.x-5, p1.y-5, 10, 10, deg, 180 );
     265                g.fillArc(p2.x-5, p2.y-5, 10, 10, deg, -180);
     266            }
     267            else
     268            {
     269                g.drawLine((int)(p1.x + 5*cosT), (int)(p1.y - 5*sinT), (int)(p2.x + 5*cosT), (int)(p2.y - 5*sinT));
     270                g.drawLine((int)(p1.x - 5*cosT), (int)(p1.y + 5*sinT), (int)(p2.x - 5*cosT), (int)(p2.y + 5*sinT));
     271                g.drawArc(p1.x-5, p1.y-5, 10, 10, deg, 180 );
     272                g.drawArc(p2.x-5, p2.y-5, 10, 10, deg, -180);
     273            }
     274        }
     275
     276
     277       
     278        /**
     279         * Draw a small rectangle.
     280         * White if selected (as always) or red otherwise.
     281         *
     282         * @param n The node to draw.
     283         */
     284        public void visit(Node n)
     285        {
     286            if( isNodeVisible(n) )
     287                drawNode(n, severity.getColor());
     288        }
     289
     290        /**
     291         * Draw just a line between the points.
     292         * White if selected (as always) or green otherwise.
     293         */
     294        public void visit(Segment ls)
     295        {
     296            if( isSegmentVisible(ls) )
     297                drawSegment(ls, severity.getColor());
     298        }
     299       
     300        public void visit(Way w)
     301        {
     302            for (Segment ls : w.segments)
     303            {
     304                if (isSegmentVisible(ls))
     305                {
     306                    drawSegment(ls, severity.getColor());
     307                }
     308            }
     309        }
     310       
     311        /**
     312         * Checks if the given node is in the visible area.
     313         */
     314        protected boolean isNodeVisible(Node n) {
     315            Point p = mv.getPoint(n.eastNorth);
     316            return !((p.x < 0) || (p.y < 0) || (p.x > mv.getWidth()) || (p.y > mv.getHeight()));
     317        }
     318
     319        /**
     320         * Checks if the given segment is in the visible area.
     321         * NOTE: This will return true for a small number of non-visible
     322         *       segments.
     323         */
     324        protected boolean isSegmentVisible(Segment ls) {
     325            if (ls.incomplete) return false;
     326            Point p1 = mv.getPoint(ls.from.eastNorth);
     327            Point p2 = mv.getPoint(ls.to.eastNorth);
     328            if ((p1.x < 0) && (p2.x < 0)) return false;
     329            if ((p1.y < 0) && (p2.y < 0)) return false;
     330            if ((p1.x > mv.getWidth()) && (p2.x > mv.getWidth())) return false;
     331            if ((p1.y > mv.getHeight()) && (p2.y > mv.getHeight())) return false;
     332            return true;
     333        }
     334    }
     335
     336    /**
     337     * Sets the selection flag of this error
     338     * @param selected if this error is selected
     339     */
     340    public void setSelected(boolean selected)
     341    {
     342        this.selected = selected;
     343    }
    186344}
  • applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/ValidateAction.java

    r2591 r2672  
    5050         * @param getSelectedItems If selected or last selected items must be validated
    5151         */
    52         public void doValidate(ActionEvent ev, boolean getSelectedItems)
     52        public void doValidate(@SuppressWarnings("unused") ActionEvent ev, boolean getSelectedItems)
    5353        {
    5454                OSMValidatorPlugin plugin = OSMValidatorPlugin.getPlugin();
     
    9595               
    9696                plugin.validationDialog.refresh();
     97        Main.map.repaint();
     98        Main.ds.fireSelectionChanged(Main.ds.getSelected());
     99       
    97100        }
    98101}
  • applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/ValidatorDialog.java

    r2591 r2672  
    3737     * The validation data.
    3838     */
    39         private DefaultTreeModel treeModel = new DefaultTreeModel(new DefaultMutableTreeNode());
     39        protected DefaultTreeModel treeModel = new DefaultTreeModel(new DefaultMutableTreeNode());
    4040
    4141        /**
     
    4747     * The fix button
    4848     */
    49         private JButton fixButton;
    50    
     49    private JButton fixButton;
     50   
     51    /**
     52     * The select button
     53     */
     54    private JButton selectButton;
     55   
     56    /** Last selected truee element */
     57    private DefaultMutableTreeNode lastSelectedNode = null;
    5158
    5259    /**
     
    7077        JPanel buttonPanel = new JPanel(new GridLayout(1,2));
    7178
    72         buttonPanel.add(Util.createButton("Select", "mapmode/selection/select", "Set the selected elements on the map to the selected items in the list above.", this));
    73         add(buttonPanel, BorderLayout.SOUTH);
     79        selectButton = Util.createButton("Select", "mapmode/selection/select", "Set the selected elements on the map to the selected items in the list above.", this);
     80        selectButton.setEnabled(false);
     81        buttonPanel.add(selectButton);
     82        //add(buttonPanel, BorderLayout.SOUTH);
    7483        buttonPanel.add(Util.createButton("Validate", "dialogs/refresh", "Validate the data.", this));
    75         add(buttonPanel, BorderLayout.SOUTH);
     84        // add(buttonPanel, BorderLayout.SOUTH);
    7685        fixButton = Util.createButton("Fix", "dialogs/fix", "Fix the selected errors.", this);
    7786        fixButton.setEnabled(false);
     
    215224    private void setSelectedItems()
    216225    {
     226        if( tree == null )
     227            return;
     228       
    217229        Collection<OsmPrimitive> sel = new HashSet<OsmPrimitive>(40);
    218230
    219231        TreePath[] selectedPaths = tree.getSelectionPaths();
     232        if( selectedPaths == null)
     233            return;
     234       
    220235        for( TreePath path : selectedPaths)
    221236        {
     
    267282                boolean hasFixes = false;
    268283
    269                 DefaultMutableTreeNode node = (DefaultMutableTreeNode)tree.getLastSelectedPathComponent();
     284        DefaultMutableTreeNode node = (DefaultMutableTreeNode)tree.getLastSelectedPathComponent();
     285        if( lastSelectedNode != null && !lastSelectedNode.equals(node) )
     286        {
     287            Enumeration<DefaultMutableTreeNode> children = lastSelectedNode.breadthFirstEnumeration();
     288            while( children.hasMoreElements() )
     289            {
     290                DefaultMutableTreeNode childNode = children.nextElement();
     291                Object nodeInfo = childNode.getUserObject();
     292                if( nodeInfo instanceof TestError)
     293                {
     294                    TestError error = (TestError)nodeInfo;
     295                    error.setSelected(false);
     296                }
     297            } 
     298        }
     299       
     300        lastSelectedNode = node;
    270301        if( node == null )
    271302                return hasFixes;
     
    279310                {
    280311                        TestError error = (TestError)nodeInfo;
     312                error.setSelected(true);
     313               
    281314                        hasFixes = hasFixes || error.isFixable();
    282315                        if( addSelected )
     
    286319                }
    287320                }
     321        selectButton.setEnabled(true);
    288322               
    289323                return hasFixes;
     
    298332                public void mouseClicked(MouseEvent e)
    299333                {
    300                 fixButton.setEnabled(false);
    301                
    302                         if(e.getSource() instanceof JScrollPane)
    303                                 return;
    304                
    305                         DefaultMutableTreeNode node = (DefaultMutableTreeNode)tree.getLastSelectedPathComponent();
    306                 if( node == null )
    307                         return;
    308 
    309                 Collection<OsmPrimitive> sel = new HashSet<OsmPrimitive>(40);
     334            System.out.println("mouseClicked " + e.getClickCount() + " " + e.getSource());
     335            fixButton.setEnabled(false);
     336            selectButton.setEnabled(false);
     337           
    310338                        boolean isDblClick = e.getClickCount() > 1;
     339            Collection<OsmPrimitive> sel = isDblClick ? new HashSet<OsmPrimitive>(40) : null;
    311340                       
    312341                        boolean hasFixes = setSelection(sel, isDblClick);
     
    328357                public void valueChanged(TreeSelectionEvent e)
    329358                {
     359            System.out.println("valueChanged");
    330360                fixButton.setEnabled(false);
     361            selectButton.setEnabled(false);
    331362               
    332363                        if(e.getSource() instanceof JScrollPane)
    333                                 return;
     364            {
     365                System.out.println(e.getSource());
     366                return;
     367            }
    334368               
    335                         DefaultMutableTreeNode node = (DefaultMutableTreeNode)tree.getLastSelectedPathComponent();
    336                 if( node == null )
    337                         return;
    338 
    339369                        boolean hasFixes = setSelection(null, false);
    340370                fixButton.setEnabled(hasFixes);
     371            Main.map.repaint();           
    341372                }
    342373        }
Note: See TracChangeset for help on using the changeset viewer.