Changeset 21802 in osm for applications


Ignore:
Timestamp:
2010-06-19T19:33:27+02:00 (14 years ago)
Author:
upliner
Message:

reformat the source code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/buildings_tools/src/buildings_tools/DrawBuildingAction.java

    r21801 r21802  
    3737
    3838@SuppressWarnings("serial")
    39 public class DrawBuildingAction extends MapMode
    40 implements MapViewPaintable, AWTEventListener, SelectionChangedListener {
    41         enum Mode {None, Drawing, DrawingWidth, DrawingAngFix}
     39public class DrawBuildingAction extends MapMode
     40                implements MapViewPaintable, AWTEventListener, SelectionChangedListener {
     41        enum Mode {
     42                None, Drawing, DrawingWidth, DrawingAngFix
     43        }
     44
    4245        final private Cursor cursorCrosshair;
    4346        final private Cursor cursorJoinNode;
    4447        private Cursor currCursor;
    45        
     48
    4649        private Mode mode = Mode.None;
    4750        private Mode nextMode = Mode.None;
    48        
     51
    4952        private Color selectedColor;
    5053        private Point mousePos;
    5154        private Point drawStartPos;
    52        
     55
    5356        Building building = new Building();
    54        
     57
    5558        public DrawBuildingAction(MapFrame mapFrame) {
    56                 super(tr("Draw buildings"),"building",tr("Draw buildings"),
     59                super(tr("Draw buildings"), "building", tr("Draw buildings"),
    5760                                Shortcut.registerShortcut("mapmode:buildings",
    58                                                 tr("Mode: {0}", tr("Draw buildings")),
    59                                                 KeyEvent.VK_W, Shortcut.GROUP_EDIT),
    60                                 mapFrame,getCursor());
    61                
     61                                tr("Mode: {0}", tr("Draw buildings")),
     62                                KeyEvent.VK_W, Shortcut.GROUP_EDIT),
     63                                mapFrame, getCursor());
     64
    6265                cursorCrosshair = getCursor();
    6366                cursorJoinNode = ImageProvider.getCursor("crosshair", "joinnode");
    6467                currCursor = cursorCrosshair;
    65                
     68
    6669                selectedColor = Main.pref.getColor(marktr("selected"), Color.red);
    6770        }
     71
    6872        private static Cursor getCursor() {
    6973                try {
     
    7377                return Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR);
    7478        }
     79
    7580        /**
    7681         * Displays the given cursor instead of the normal one
    77          * @param Cursors One of the available cursors
     82         *
     83         * @param Cursors
     84         *            One of the available cursors
    7885         */
    7986        private void setCursor(final Cursor c) {
    80                 if(currCursor.equals(c))
     87                if (currCursor.equals(c))
    8188                        return;
    8289                try {
     
    8592                                public void run() {
    8693                                        // Don't change cursor when mode has changed already
    87                                         if(!(Main.map.mapMode instanceof DrawBuildingAction))
     94                                        if (!(Main.map.mapMode instanceof DrawBuildingAction))
    8895                                                return;
    8996                                        Main.map.mapView.setCursor(c);
     
    9198                        });
    9299                        currCursor = c;
    93                 } catch(Exception e) {}
    94         }
     100                } catch (Exception e) {
     101                }
     102        }
     103
    95104        private static void showAddrDialog(Way w) {
    96105                AddressDialog dlg = new AddressDialog();
     
    100109                        String tmp;
    101110                        tmp = dlg.getHouseNum();
    102                         if (tmp!=null&&tmp!="") w.put("addr:housenumber",tmp);
     111                        if (tmp != null && tmp != "")
     112                                w.put("addr:housenumber", tmp);
    103113                        tmp = dlg.getStreetName();
    104                         if (tmp!=null&&tmp!="") w.put("addr:street",tmp);
    105                 }
    106         }
    107 
    108         @Override public void enterMode() {
     114                        if (tmp != null && tmp != "")
     115                                w.put("addr:street", tmp);
     116                }
     117        }
     118
     119        @Override
     120        public void enterMode() {
    109121                super.enterMode();
    110122                if (getCurrentDataSet() == null) {
     
    120132                try {
    121133                        Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK);
    122                 } catch (SecurityException ex) { }
    123         }
    124 
    125         @Override public void exitMode() {
     134                } catch (SecurityException ex) {
     135                }
     136        }
     137
     138        @Override
     139        public void exitMode() {
    126140                super.exitMode();
    127141                Main.map.mapView.removeMouseListener(this);
     
    131145                try {
    132146                        Toolkit.getDefaultToolkit().removeAWTEventListener(this);
    133                 } catch (SecurityException ex) { }
    134                 if (mode!=Mode.None) Main.map.mapView.repaint();
     147                } catch (SecurityException ex) {
     148                }
     149                if (mode != Mode.None)
     150                        Main.map.mapView.repaint();
    135151                mode = Mode.None;
    136152        }
    137        
     153
    138154        public void cancelDrawing() {
    139155                mode = Mode.None;
    140                 if(Main.map == null || Main.map.mapView == null)
     156                if (Main.map == null || Main.map.mapView == null)
    141157                        return;
    142158                Main.map.statusLine.setHeading(-1);
    143                 Main.map.statusLine.setAngle(-1);
    144                 building.reset();
     159                Main.map.statusLine.setAngle(-1);
     160                building.reset();
    145161                Main.map.mapView.repaint();
    146162                updateStatusLine();
     
    148164
    149165        public void eventDispatched(AWTEvent arg0) {
    150                 if (!(arg0 instanceof KeyEvent)) return;
    151                 KeyEvent ev = (KeyEvent)arg0;
     166                if (!(arg0 instanceof KeyEvent))
     167                        return;
     168                KeyEvent ev = (KeyEvent) arg0;
    152169                if (ev.getKeyCode() == KeyEvent.VK_ESCAPE)
    153170                        cancelDrawing();
    154171        }
    155        
     172
    156173        private EastNorth getPoint(MouseEvent e) {
    157174                Node n;
    158175                if (e.isControlDown()) {
    159176                        n = null;
    160                 } else { 
     177                } else {
    161178                        n = Main.map.mapView.getNearestNode(mousePos, OsmPrimitive.isUsablePredicate);
    162179                }
     
    167184                }
    168185        }
    169        
     186
    170187        private Mode modeDrawing(MouseEvent e) {
    171188                EastNorth p = getPoint(e);
     
    175192                } else {
    176193                        building.setPlace(p, ToolSettings.getWidth(),
    177                                         ToolSettings.getLenStep(),e.isShiftDown());
     194                                        ToolSettings.getLenStep(), e.isShiftDown());
    178195                        Main.map.statusLine.setDist(building.getLength());
    179                         return this.nextMode = ToolSettings.getWidth() == 0? Mode.DrawingWidth : Mode.None;
     196                        return this.nextMode = ToolSettings.getWidth() == 0 ? Mode.DrawingWidth : Mode.None;
    180197                }
    181198        }
     
    208225                        throw new AssertionError("Invalid drawing mode");
    209226        }
    210        
    211         public void paint(Graphics2D g, MapView mv,Bounds bbox)
    212         {
    213                 if (mode == Mode.None) return;
    214                 if (building.getLength() == 0) return;
    215                
     227
     228        public void paint(Graphics2D g, MapView mv, Bounds bbox) {
     229                if (mode == Mode.None)
     230                        return;
     231                if (building.getLength() == 0)
     232                        return;
     233
    216234                g.setColor(selectedColor);
    217235                g.setStroke(new BasicStroke(3, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
    218                
     236
    219237                building.paint(g, mv);
    220                
     238
    221239                g.setStroke(new BasicStroke(1));
    222240
    223241        }
    224        
    225         private void drawingStart(MouseEvent e)
    226         {
     242
     243        private void drawingStart(MouseEvent e) {
    227244                mousePos = e.getPoint();
    228245                drawStartPos = mousePos;
    229                
     246
    230247                Node n = Main.map.mapView.getNearestNode(mousePos, OsmPrimitive.isUsablePredicate);
    231248                if (n == null) {
     
    247264                }
    248265        }
    249        
     266
    250267        private void drawingFinish() {
    251268                if (building.getLength() != 0) {
     
    257274        }
    258275
    259         @Override public void mousePressed(MouseEvent e) {
    260                 if (e.getButton() != MouseEvent.BUTTON1) return;
    261                 if(!Main.map.mapView.isActiveLayerDrawable()) return;           
     276        @Override
     277        public void mousePressed(MouseEvent e) {
     278                if (e.getButton() != MouseEvent.BUTTON1)
     279                        return;
     280                if (!Main.map.mapView.isActiveLayerDrawable())
     281                        return;
    262282
    263283                if (mode == Mode.None)
     
    265285        }
    266286
    267         @Override public void mouseDragged(MouseEvent e) {
     287        @Override
     288        public void mouseDragged(MouseEvent e) {
    268289                processMouseEvent(e);
    269290                updCursor();
    270                 if (mode!=Mode.None) Main.map.mapView.repaint();
    271         }
    272 
    273         @Override public void mouseReleased(MouseEvent e) {
    274                 if (e.getButton() != MouseEvent.BUTTON1) return;
    275                 if(!Main.map.mapView.isActiveLayerDrawable()) return;
     291                if (mode != Mode.None)
     292                        Main.map.mapView.repaint();
     293        }
     294
     295        @Override
     296        public void mouseReleased(MouseEvent e) {
     297                if (e.getButton() != MouseEvent.BUTTON1)
     298                        return;
     299                if (!Main.map.mapView.isActiveLayerDrawable())
     300                        return;
    276301                boolean dragged = true;
    277302                if (drawStartPos != null)
     
    279304                drawStartPos = null;
    280305
    281                 if (mode == Mode.Drawing && !dragged) return;
    282                 if (mode == Mode.None) return;
     306                if (mode == Mode.Drawing && !dragged)
     307                        return;
     308                if (mode == Mode.None)
     309                        return;
    283310
    284311                drawingAdvance(e);
    285312        }
    286        
     313
    287314        private void updCursor() {
    288                 if (mousePos==null) return;
     315                if (mousePos == null)
     316                        return;
    289317                Node n = Main.map.mapView.getNearestNode(mousePos, OsmPrimitive.isUsablePredicate);
    290                 if (n != null) setCursor(cursorJoinNode); else setCursor(cursorCrosshair);
    291 
    292         }
    293         @Override public void mouseMoved(MouseEvent e) {
    294                 if(!Main.map.mapView.isActiveLayerDrawable()) return;
     318                if (n != null)
     319                        setCursor(cursorJoinNode);
     320                else
     321                        setCursor(cursorCrosshair);
     322
     323        }
     324
     325        @Override
     326        public void mouseMoved(MouseEvent e) {
     327                if (!Main.map.mapView.isActiveLayerDrawable())
     328                        return;
    295329                processMouseEvent(e);
    296330                updCursor();
    297                 if (mode!=Mode.None) Main.map.mapView.repaint();
    298         }
    299 
    300         @Override public String getModeHelpText() {
    301                 if (mode==Mode.None) return tr("Point on the corner of the building to start drawing");
    302                 if (mode==Mode.Drawing) return tr("Point on opposite end of the building");
    303                 if (mode==Mode.DrawingWidth) return tr("Set width of the building");
     331                if (mode != Mode.None)
     332                        Main.map.mapView.repaint();
     333        }
     334
     335        @Override
     336        public String getModeHelpText() {
     337                if (mode == Mode.None)
     338                        return tr("Point on the corner of the building to start drawing");
     339                if (mode == Mode.Drawing)
     340                        return tr("Point on opposite end of the building");
     341                if (mode == Mode.DrawingWidth)
     342                        return tr("Set width of the building");
    304343                return "";
    305344        }
    306345
    307         @Override public boolean layerIsSupported(Layer l) {
     346        @Override
     347        public boolean layerIsSupported(Layer l) {
    308348                return l instanceof OsmDataLayer;
    309349        }
    310        
     350
    311351        public void updateConstraint(Collection<? extends OsmPrimitive> newSelection) {
    312352                building.disableAngConstraint();
    313                 if (newSelection.size()!=2)return;
    314                 Object[] arr = newSelection.toArray();
    315                 if (!(arr[0] instanceof Node&&arr[1] instanceof Node)) return;
    316                 EastNorth p1,p2;
    317                 p1=latlon2eastNorth(((Node)arr[0]).getCoor());
    318                 p2=latlon2eastNorth(((Node)arr[1]).getCoor());
    319                 building.setAngConstraint(p1.heading(p2));
    320         }
    321        
     353                if (newSelection.size() != 2)
     354                        return;
     355                Object[] arr = newSelection.toArray();
     356                if (!(arr[0] instanceof Node && arr[1] instanceof Node))
     357                        return;
     358                EastNorth p1, p2;
     359                p1 = latlon2eastNorth(((Node) arr[0]).getCoor());
     360                p2 = latlon2eastNorth(((Node) arr[1]).getCoor());
     361                building.setAngConstraint(p1.heading(p2));
     362        }
     363
    322364        public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
    323365                updateConstraint(newSelection);
Note: See TracChangeset for help on using the changeset viewer.