Changeset 4956 in josm for trunk


Ignore:
Timestamp:
2012-02-16T18:17:02+01:00 (12 years ago)
Author:
stoecker
Message:

shortcut fixes, a lot of code cleanup in DrawAction

Location:
trunk/src/org/openstreetmap/josm
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java

    r4954 r4956  
    9999    private SnapHelper snapHelper = new SnapHelper();
    100100
    101     private Shortcut extraShortcut;
    102101    private Shortcut backspaceShortcut;
    103     private int snappingKeyCode;
    104    
     102    private Shortcut snappingShortcut;
     103
    105104    private JCheckBoxMenuItem snapCheckboxMenuItem;
    106    
    107            
     105
    108106    public DrawAction(MapFrame mapFrame) {
    109107        super(tr("Draw"), "node/autonode", tr("Draw nodes"),
    110                 Shortcut.registerShortcut("mapmode:draw", tr("Mode: {0}", tr("Draw")), KeyEvent.VK_A, Shortcut.GROUP_EDIT),
    111                 mapFrame, ImageProvider.getCursor("crosshair", null));
    112 
    113         // Add extra shortcut N
    114         extraShortcut = Shortcut.registerShortcut("mapmode:drawfocus", tr("Mode: Draw Focus"), KeyEvent.VK_N, Shortcut.GROUP_EDIT);
    115         Main.registerActionShortcut(this, extraShortcut);
    116 
    117         snappingKeyCode = Shortcut.registerShortcut("mapmode:drawanglesnapping", tr("Mode: Draw Angle snapping"), KeyEvent.VK_TAB, Shortcut.GROUP_EDIT)
    118                 .getKeyStroke().getKeyCode();
     108            Shortcut.registerShortcut("mapmode:draw", tr("Mode: {0}", tr("Draw")), KeyEvent.VK_A, Shortcut.GROUP_EDIT),
     109            mapFrame, ImageProvider.getCursor("crosshair", null));
     110
     111        snappingShortcut = Shortcut.registerShortcut("mapmode:drawanglesnapping",
     112            tr("Mode: Draw Angle snapping"), KeyEvent.VK_TAB, Shortcut.GROUP_EDIT);
    119113        addMenuItem();
    120114        snapHelper.setMenuCheckBox(snapCheckboxMenuItem);
     
    128122            JMenuItem item = Main.main.menu.editMenu.getItem(i);
    129123            if (item!=null && item.getAction() !=null && item.getAction() instanceof SnapChangeAction) {
    130                 Main.main.menu.editMenu.remove(i); 
     124                Main.main.menu.editMenu.remove(i);
    131125            }
    132126        }
     
    139133    private void redrawIfRequired() {
    140134        updateStatusLine();
    141         if ((!drawHelperLine || wayIsFinished) && !drawTargetHighlight) return;
     135        if ((!drawHelperLine || wayIsFinished) && !drawTargetHighlight)
     136            return;
    142137        // update selection to reflect which way being modified
    143138        if (currentBaseNode != null && getCurrentDataSet().getSelected().isEmpty() == false) {
     
    155150    }
    156151
    157     @Override public void enterMode() {
     152    @Override
     153    public void enterMode() {
    158154        if (!isEnabled())
    159155            return;
     
    165161        snapHelper.init();
    166162        snapCheckboxMenuItem.getAction().setEnabled(true);
    167        
     163
    168164         timer = new Timer(0, new ActionListener() {
    169165            @Override
    170166            public void actionPerformed(ActionEvent ae) {
    171                  timer.stop();
    172                  if (set.remove(releaseEvent.getKeyCode())) {
    173                    doKeyReleaseEvent(releaseEvent);
    174                  }
     167                timer.stop();
     168                if (set.remove(releaseEvent.getKeyCode())) {
     169                    doKeyReleaseEvent(releaseEvent);
     170                }
    175171            }
    176172
    177173        });
    178        Main.map.statusLine.getAnglePanel().addMouseListener(snapHelper.anglePopupListener);
    179         backspaceShortcut = Shortcut.registerShortcut("mapmode:backspace", tr("Backspace in Add mode"), KeyEvent.VK_BACK_SPACE, Shortcut.GROUP_EDIT);
     174        Main.map.statusLine.getAnglePanel().addMouseListener(snapHelper.anglePopupListener);
     175        backspaceShortcut = Shortcut.registerShortcut("mapmode:backspace",
     176            tr("Backspace in Add mode"), KeyEvent.VK_BACK_SPACE, Shortcut.GROUP_EDIT);
    180177        Main.registerActionShortcut(new BackSpaceAction(), backspaceShortcut);
    181178
     
    193190    }
    194191
    195     @Override public void exitMode() {
     192    @Override
     193    public void exitMode() {
    196194        super.exitMode();
    197195        Main.map.mapView.removeMouseListener(this);
     
    203201        snapCheckboxMenuItem.getAction().setEnabled(false);
    204202        Main.map.statusLine.getAnglePanel().removeMouseListener(snapHelper.anglePopupListener);
    205        
     203
    206204        removeHighlighting();
    207205        try {
     
    226224            return;
    227225        if (event instanceof KeyEvent) {
    228                 processKeyEvent((KeyEvent) event);
     226            processKeyEvent((KeyEvent) event);
    229227        } //  toggle angle snapping
    230228        updateKeyModifiers((InputEvent) event);
     
    233231        redrawIfRequired();
    234232    }
    235    
    236    
    237     // events for crossplatform key holding processing
    238     // thanks to http://www.arco.in-berlin.de/keyevent.html
     233
     234    // events for crossplatform key holding processing
     235    // thanks to http://www.arco.in-berlin.de/keyevent.html
    239236    private final TreeSet<Integer> set = new TreeSet<Integer>();
    240237    private KeyEvent releaseEvent;
    241238    private Timer timer;
    242239    void processKeyEvent(KeyEvent e) {
    243         if (e.getKeyCode() != snappingKeyCode) return;
    244         //e.consume(); // ticket #7250 -  TAB should work in other windows
     240        if (!snappingShortcut.isEvent(e))
     241            return;
    245242
    246243        if (e.getID() == KeyEvent.KEY_PRESSED) {
    247              if (timer.isRunning()) {
    248                   timer.stop();
    249                 } else {
    250                   if (set.add((e.getKeyCode()))) doKeyPressEvent(e);
    251                 }
    252              
    253         }
    254         if (e.getID() == KeyEvent.KEY_RELEASED) {
    255244            if (timer.isRunning()) {
    256               timer.stop();
    257                if (set.remove(e.getKeyCode())) {
    258                   doKeyReleaseEvent(e);
    259                }
     245                timer.stop();
     246            } else if (set.add((e.getKeyCode()))) {
     247                doKeyPressEvent(e);
     248            }
     249        } else if (e.getID() == KeyEvent.KEY_RELEASED) {
     250            if (timer.isRunning()) {
     251                timer.stop();
     252                if (set.remove(e.getKeyCode())) {
     253                    doKeyReleaseEvent(e);
     254                }
    260255            } else {
    261               releaseEvent = e;
    262               timer.restart();
    263             }
    264         }
    265        
    266     }
    267    
     256                releaseEvent = e;
     257                timer.restart();
     258            }
     259        }
     260    }
     261
    268262    private void doKeyPressEvent(KeyEvent e) {
    269         if (e.getKeyCode() != snappingKeyCode) return;
     263        if (!snappingShortcut.isEvent(e))
     264            return;
    270265        snapHelper.setFixedMode();
    271         computeHelperLine(); redrawIfRequired();
     266        computeHelperLine();
     267        redrawIfRequired();
    272268    }
    273269    private void doKeyReleaseEvent(KeyEvent e) {
    274         if (e.getKeyCode() != snappingKeyCode) return;
     270        if (!snappingShortcut.isEvent(e))
     271            return;
    275272        snapHelper.unFixOrTurnOff();
    276         computeHelperLine(); redrawIfRequired();
     273        computeHelperLine();
     274        redrawIfRequired();
    277275    }
    278276
     
    306304        Main.map.selectSelectTool(true);
    307305        snapHelper.noSnapNow();
    308    
     306
    309307        // Redraw to remove the helper line stub
    310308        computeHelperLine();
     
    321319        }
    322320    }
    323    
     321
    324322    /**
    325323     * If user clicked with the left button, add a node at the current mouse
     
    348346        //
    349347        Main.map.mapView.requestFocus();
    350        
     348
    351349        if(e.getClickCount() > 1 && mousePos != null && mousePos.equals(oldMousePos)) {
    352350            // A double click equals "user clicked last node again, finish way"
     
    357355        }
    358356        oldMousePos = mousePos;
    359        
     357
    360358        // we copy ctrl/alt/shift from the event just in case our global
    361359        // AWTEvent didn't make it through the security manager. Unclear
     
    401399                EastNorth foundPoint = n.getEastNorth();
    402400                // project found node to snapping line
    403                 newEN = snapHelper.getSnapPoint(foundPoint); 
     401                newEN = snapHelper.getSnapPoint(foundPoint);
    404402                if (foundPoint.distance(newEN) > 1e-4) {
    405403                    n = new Node(newEN); // point != projected, so we create new node
     
    418416            if (n.getCoor().isOutSideWorld()) {
    419417                JOptionPane.showMessageDialog(
    420                         Main.parent,
    421                         tr("Cannot add a node outside of the world."),
    422                         tr("Warning"),
    423                         JOptionPane.WARNING_MESSAGE
     418                    Main.parent,
     419                    tr("Cannot add a node outside of the world."),
     420                    tr("Warning"),
     421                    JOptionPane.WARNING_MESSAGE
    424422                );
    425423                return;
     
    428426
    429427            if (!ctrl) {
    430                     // Insert the node into all the nearby way segments
    431                     List<WaySegment> wss = Main.map.mapView.getNearestWaySegments(
    432                             Main.map.mapView.getPoint(n), OsmPrimitive.isSelectablePredicate);
    433                     if (snapHelper.isActive()) { //
    434                         tryToMoveNodeOnIntersection(wss,n);
    435                     }
    436                     insertNodeIntoAllNearbySegments(wss, n, newSelection, cmds, replacedWays, reuseWays);
    437                     }
     428                // Insert the node into all the nearby way segments
     429                List<WaySegment> wss = Main.map.mapView.getNearestWaySegments(
     430                    Main.map.mapView.getPoint(n), OsmPrimitive.isSelectablePredicate);
     431                if (snapHelper.isActive()) {
     432                    tryToMoveNodeOnIntersection(wss,n);
     433                }
     434                insertNodeIntoAllNearbySegments(wss, n, newSelection, cmds, replacedWays, reuseWays);
     435            }
    438436        }
    439437        // now "n" is newly created or reused node that shoud be added to some way
    440        
     438
    441439        // This part decides whether or not a "segment" (i.e. a connection) is made to an
    442440        // existing node.
     
    588586        redrawIfRequired();
    589587    }
    590    
     588
    591589    private void insertNodeIntoAllNearbySegments(List<WaySegment> wss, Node n, Collection<OsmPrimitive> newSelection, Collection<Command> cmds, ArrayList<Way> replacedWays, ArrayList<Way> reuseWays) {
    592590        Map<Way, List<Integer>> insertPoints = new HashMap<Way, List<Integer>>();
     
    613611            pruneSuccsAndReverse(is);
    614612            for (int i : is) {
    615                 segSet.add(
    616                         Pair.sort(new Pair<Node,Node>(w.getNode(i), w.getNode(i+1))));
     613                segSet.add(Pair.sort(new Pair<Node,Node>(w.getNode(i), w.getNode(i+1))));
    617614            }
    618615            for (int i : is) {
     
    636633        adjustNode(segSet, n);
    637634    }
    638 
    639635
    640636    /**
     
    698694    }
    699695
    700     @Override public void mouseDragged(MouseEvent e) {
     696    @Override
     697    public void mouseDragged(MouseEvent e) {
    701698        mouseMoved(e);
    702699    }
    703700
    704     @Override public void mouseMoved(MouseEvent e) {
     701    @Override
     702    public void mouseMoved(MouseEvent e) {
    705703        if(!Main.map.mapView.isActiveLayerDrawable())
    706704            return;
     
    767765        determineCurrentBaseNodeAndPreviousNode(selection);
    768766        if (previousNode == null) snapHelper.noSnapNow();
    769        
     767
    770768        if (currentBaseNode == null || currentBaseNode == currentMouseNode)
    771769            return; // Don't create zero length way segments.
     
    773771
    774772        double curHdg = Math.toDegrees(currentBaseNode.getEastNorth()
    775                 .heading(currentMouseEastNorth));
     773            .heading(currentMouseEastNorth));
    776774        double baseHdg=-1;
    777775        if (previousNode != null) {
    778776            baseHdg =  Math.toDegrees(previousNode.getEastNorth()
    779                     .heading(currentBaseNode.getEastNorth()));
    780         }
    781      
     777                .heading(currentBaseNode.getEastNorth()));
     778        }
     779
    782780        snapHelper.checkAngleSnapping(currentMouseEastNorth,baseHdg, curHdg);
    783781
    784782        // status bar was filled by snapHelper
    785        
    786         // Now done in redrawIfRequired()
    787         //updateStatusLine();
    788783    }
    789784
     
    794789    }
    795790
    796     /** 
    797      * Helper function that sets fields currentBaseNode and previousNode 
    798      * @param selection 
     791    /**
     792     * Helper function that sets fields currentBaseNode and previousNode
     793     * @param selection
    799794     * uses also lastUsedNode field
    800795     */
     
    804799        for (OsmPrimitive p : selection) {
    805800            if (p instanceof Node) {
    806                 if (selectedNode != null) return;
     801                if (selectedNode != null)
     802                    return;
    807803                selectedNode = (Node) p;
    808804            } else if (p instanceof Way) {
    809                 if (selectedWay != null) return;
     805                if (selectedWay != null)
     806                    return;
    810807                selectedWay = (Way) p;
    811808            }
     
    835832            if (selectedNode == selectedWay.lastNode()) {
    836833                currentBaseNode = selectedNode;
    837                 if (selectedWay.getNodesCount()>1) 
     834                if (selectedWay.getNodesCount()>1)
    838835                    previousNode = selectedWay.getNode(selectedWay.getNodesCount()-2);
    839836            }
     
    879876
    880877    private static void pruneSuccsAndReverse(List<Integer> is) {
    881         //if (is.size() < 2) return;
    882 
    883878        HashSet<Integer> is2 = new HashSet<Integer>();
    884879        for (int i : is) {
     
    929924            // In practice this will probably only happen when a way has been duplicated
    930925
    931             if (u == 0) return;
     926            if (u == 0)
     927                return;
    932928
    933929            // q is a number between 0 and 1
     
    950946                return;
    951947            }
    952 
    953948        default:
    954949            EastNorth P = n.getEastNorth();
     
    970965
    971966    private void tryToMoveNodeOnIntersection(List<WaySegment> wss, Node n) {
    972         if (wss.isEmpty()) return;
     967        if (wss.isEmpty())
     968            return;
    973969        WaySegment ws = wss.get(0);
    974970        EastNorth p1=ws.getFirstNode().getEastNorth();
    975971        EastNorth p2=ws.getSecondNode().getEastNorth();
    976         if (snapHelper.dir2!=null && currentBaseNode!=null) {
     972        if (snapHelper.dir2!=null && currentBaseNode!=null) {
    977973            EastNorth xPoint = Geometry.getSegmentSegmentIntersection(p1, p2, snapHelper.dir2, currentBaseNode.getEastNorth());
    978974            if (xPoint!=null) n.setEastNorth(xPoint);
    979975        }
    980976    }
    981 /**
     977    /**
    982978     * Takes the data from computeHelperLine to determine which ways/nodes should be highlighted
    983979     * (if feature enabled). Also sets the target cursor if appropriate.
     
    10111007            Main.map.mapView.setNewCursor(cursor, this);
    10121008            return;
    1013     }
     1009        }
    10141010
    10151011        Main.map.mapView.setNewCursor(cursorJoinWay, this);
     
    10321028        oldHighlights = new HashSet<OsmPrimitive>();
    10331029    }
    1034    
     1030
    10351031    public void paint(Graphics2D g, MapView mv, Bounds box) {
    10361032        // sanity checks
    1037         if (Main.map.mapView == null) return;
    1038         if (mousePos == null) return;
    1039 
     1033        if (Main.map.mapView == null || mousePos == null
    10401034        // don't draw line if we don't know where from or where to
    1041         if (currentBaseNode == null || currentMouseEastNorth == null) return;
    1042 
     1035        || currentBaseNode == null || currentMouseEastNorth == null
    10431036        // don't draw line if mouse is outside window
    1044         if (!Main.map.mapView.getBounds().contains(mousePos)) return;
    1045        
     1037        || !Main.map.mapView.getBounds().contains(mousePos))
     1038            return;
     1039
    10461040        Graphics2D g2 = g;
    10471041        snapHelper.drawIfNeeded(g2,mv);
    1048         if (!drawHelperLine || wayIsFinished || shift) return;
    1049        
     1042        if (!drawHelperLine || wayIsFinished || shift)
     1043          return;
     1044
    10501045        if (!snapHelper.isActive()) { // else use color and stoke from  snapHelper.draw
    10511046            g2.setColor(selectedColor);
    10521047            g2.setStroke(new BasicStroke(3, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
    1053         } else {
    1054             if (!snapHelper.drawConstructionGeometry) return;
     1048        } else if (!snapHelper.drawConstructionGeometry) {
     1049            return;
    10551050        }
    10561051        GeneralPath b = new GeneralPath();
     
    10721067    }
    10731068
    1074     @Override public String getModeHelpText() {
     1069    @Override
     1070    public String getModeHelpText() {
    10751071        String rv = "";
    10761072        /*
     
    11491145    }
    11501146
    1151     @Override public boolean layerIsSupported(Layer l) {
     1147    @Override
     1148    public boolean layerIsSupported(Layer l) {
    11521149        return l instanceof OsmDataLayer;
    11531150    }
     
    11611158    public void destroy() {
    11621159        super.destroy();
    1163         Main.unregisterActionShortcut(extraShortcut);
    11641160    }
    11651161
     
    11701166            Main.main.undoRedo.undo();
    11711167            Node n=null;
    1172             Command lastCmd=Main.main.undoRedo.commands.peekLast(); 
     1168            Command lastCmd=Main.main.undoRedo.commands.peekLast();
    11731169            if (lastCmd==null) return;
    11741170            for (OsmPrimitive p: lastCmd.getParticipatingPrimitives()) {
     
    11811177                    // we have no way to continue, so we forget about found node
    11821178                        n=null;
    1183                         break; 
     1179                        break;
    11841180                    }
    11851181                }
    11861182            }
    1187             // select last added node - maybe we will continue drawing from it 
     1183            // select last added node - maybe we will continue drawing from it
    11881184            if (n!=null) getCurrentDataSet().addSelected(n);
    11891185       }
    1190  }
     1186    }
    11911187
    11921188    private class SnapHelper {
    11931189        boolean snapOn; // snapping is turned on
    1194        
     1190
    11951191        private boolean active; // snapping is active for current mouse position
    11961192        private boolean fixed; // snap angle is fixed
    1197         private boolean absoluteFix; // snap angle is absolute 
    1198        
    1199         private boolean drawConstructionGeometry; 
    1200         private boolean showProjectedPoint; 
    1201         private boolean showAngle; 
     1193        private boolean absoluteFix; // snap angle is absolute
     1194
     1195        private boolean drawConstructionGeometry;
     1196        private boolean showProjectedPoint;
     1197        private boolean showAngle;
    12021198
    12031199        private boolean snapToProjections;
    1204        
     1200
    12051201        EastNorth dir2;
    12061202        EastNorth projected;
    12071203        String labelText;
    12081204        double lastAngle;
     1205
    12091206        double customBaseHeading=-1; // angle of base line, if not last segment)
    12101207        private EastNorth segmentPoint1; // remembered first point of base segment
    12111208        private EastNorth segmentPoint2; // remembered second point of base segment
    12121209        private EastNorth projectionSource; // point that we are projecting to the line
    1213                
    1214         double snapAngles[]; 
    1215         double snapAngleTolerance; 
    1216        
     1210
     1211        double snapAngles[];
     1212        double snapAngleTolerance;
     1213
    12171214        double pe,pn; // (pe,pn) - direction of snapping line
    12181215        double e0,n0; // (e0,n0) - origin of snapping line
    1219        
     1216
    12201217        final String fixFmt="%d "+tr("FIX");
    12211218        Color snapHelperColor;
     
    12251222        private Stroke helperStroke;
    12261223        private Stroke highlightStroke;
    1227        
     1224
    12281225        JCheckBoxMenuItem checkBox;
    1229        
     1226
    12301227        public void init() {
    12311228            snapOn=false;
    12321229            checkBox.setState(snapOn);
    12331230            fixed=false; absoluteFix=false;
    1234                        
    1235             Collection<String> angles = Main.pref.getCollection("draw.anglesnap.angles", 
    1236                     Arrays.asList("0","30","45","60","90","120","135","150","180"));
    1237            
     1231
     1232            Collection<String> angles = Main.pref.getCollection("draw.anglesnap.angles",
     1233                Arrays.asList("0","30","45","60","90","120","135","150","180"));
     1234
    12381235            snapAngles = new double[2*angles.size()];
    12391236            int i=0;
     
    12461243                    snapAngles[i]=0;i++;
    12471244                    snapAngles[i]=0;i++;
    1248                 } 
     1245                }
    12491246            }
    12501247            snapAngleTolerance = Main.pref.getDouble("draw.anglesnap.tolerance", 5.0);
     
    12581255            snapHelperColor = Main.pref.getColor(marktr("draw angle snap"), Color.ORANGE);
    12591256
    1260             highlightColor = Main.pref.getColor(marktr("draw angle snap highlight"), new Color(Color.ORANGE.getRed(),Color.ORANGE.getGreen(),Color.ORANGE.getBlue(),128));
     1257            highlightColor = Main.pref.getColor(marktr("draw angle snap highlight"),
     1258                new Color(Color.ORANGE.getRed(),Color.ORANGE.getGreen(),Color.ORANGE.getBlue(),128));
    12611259            highlightStroke = new BasicStroke(10, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
    1262            
     1260
    12631261            float dash1[] = { 4.0f };
    12641262            helperStroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT,
    1265                          BasicStroke.JOIN_MITER, 10.0f, dash1, 0.0f);
    1266 
    1267         }
    1268        
     1263                BasicStroke.JOIN_MITER, 10.0f, dash1, 0.0f);
     1264        }
     1265
    12691266        public void saveAngles(String ... angles) {
    12701267            Main.pref.putCollection("draw.anglesnap.angles", Arrays.asList(angles));
    12711268        }
    1272        
     1269
    12731270        public  void setMenuCheckBox(JCheckBoxMenuItem checkBox) {
    12741271            this.checkBox = checkBox;
    12751272        }
    1276        
    12771273
    12781274        public  void drawIfNeeded(Graphics2D g2, MapView mv) {
    1279             if (!snapOn) return;
    1280             if (!active) return;
     1275            if (!snapOn || !active)
     1276                return;
    12811277            Point p1=mv.getPoint(currentBaseNode);
    12821278            Point p2=mv.getPoint(dir2);
     
    12891285                b = new GeneralPath();
    12901286                if (absoluteFix) {
    1291                     b.moveTo(p2.x,p2.y); 
     1287                    b.moveTo(p2.x,p2.y);
    12921288                    b.lineTo(2*p1.x-p2.x,2*p1.y-p2.y); // bi-directional line
    12931289                } else {
    12941290                    b.moveTo(p2.x,p2.y);
    12951291                    b.lineTo(p3.x,p3.y);
    1296                 } 
     1292                }
    12971293                g2.draw(b);
    12981294            }
    1299             if (projectionSource!=null) {
     1295            if (projectionSource != null) {
    13001296                g2.setColor(snapHelperColor);
    13011297                g2.setStroke(helperStroke);
     
    13031299                b.moveTo(p3.x,p3.y);
    13041300                Point pp=mv.getPoint(projectionSource);
    1305                 b.lineTo(pp.x,pp.y); 
     1301                b.lineTo(pp.x,pp.y);
    13061302                g2.draw(b);
    13071303            }
    1308            
    1309            
    1310             if (customBaseHeading>=0) {
     1304
     1305            if (customBaseHeading >= 0) {
    13111306                g2.setColor(highlightColor);
    13121307                g2.setStroke(highlightStroke);
     
    13141309                Point pp1=mv.getPoint(segmentPoint1);
    13151310                Point pp2=mv.getPoint(segmentPoint2);
    1316                 b.moveTo(pp1.x,pp1.y); 
     1311                b.moveTo(pp1.x,pp1.y);
    13171312                b.lineTo(pp2.x,pp2.y);
    13181313                g2.draw(b);
    13191314            }
    1320            
    1321            
     1315
    13221316            g2.setColor(selectedColor);
    13231317            g2.setStroke(normalStroke);
    13241318            b = new GeneralPath();
    1325             b.moveTo(p1.x,p1.y); 
     1319            b.moveTo(p1.x,p1.y);
    13261320            b.lineTo(p3.x,p3.y);
    13271321            g2.draw(b);
    1328            
     1322
    13291323            g2.drawString(labelText, p3.x-5, p3.y+20);
    13301324            if (showProjectedPoint) {
     
    13321326                g2.drawOval(p3.x-5, p3.y-5, 10, 10); // projected point
    13331327            }
    1334            
     1328
    13351329            g2.setColor(snapHelperColor);
    13361330            g2.setStroke(helperStroke);
    1337            
    1338         }
    1339        
     1331        }
     1332
    13401333        /* If mouse position is close to line at 15-30-45-... angle, remembers this direction
    13411334         */
     
    13441337            EastNorth snapPoint = currentEN;
    13451338            double angle = -1;
    1346            
    1347             double activeBaseHeading = (customBaseHeading>=0)? customBaseHeading : baseHeading; 
    1348            
     1339
     1340            double activeBaseHeading = (customBaseHeading>=0)? customBaseHeading : baseHeading;
     1341
    13491342            if (snapOn && (activeBaseHeading>=0)) {
    13501343                angle = curHeading - activeBaseHeading;
    13511344                if (angle < 0) angle+=360;
    13521345                if (angle > 360) angle=0;
    1353                
     1346
    13541347                double nearestAngle;
    13551348                if (fixed) {
     
    13621355                        // if angle is to previous segment, exclude 180 degrees
    13631356                        lastAngle = nearestAngle;
    1364                     } else active=false;
     1357                    } else {
     1358                        active=false;
     1359                    }
    13651360                }
    13661361
     
    13881383            double hdg = Math.toDegrees(p0.heading(snapPoint));
    13891384            // heading of segment from current to calculated point, not to mouse position
    1390            
     1385
    13911386            if (baseHeading >=0 ) { // there is previous line segment with some heading
    13921387                angle = hdg - baseHeading;
     
    14201415            }
    14211416        }
    1422        
     1417
    14231418        public  EastNorth getSnapPoint(EastNorth p) {
    1424             if (!active) return p;
     1419            if (!active)
     1420                return p;
    14251421            double de=p.east()-e0;
    14261422            double dn=p.north()-n0;
    14271423            double l = de*pe+dn*pn;
    14281424            double delta = Main.map.mapView.getDist100Pixel()/20;
    1429             if (!absoluteFix && l<delta) {active=false; return p; } //  do not go backward!
    1430            
     1425            if (!absoluteFix && l<delta) {
     1426                active=false;
     1427                return p;
     1428            } //  do not go backward!
     1429
    14311430            projectionSource=null;
    14321431            if (snapToProjections) {
     
    14401439                        if (Math.abs(l1-l) < delta) {
    14411440                            l=l1;
    1442                             projectionSource =  en; 
     1441                            projectionSource =  en;
    14431442                            break;
    14441443                        }
     
    14481447            return projected = new EastNorth(e0+l*pe, n0+l*pn);
    14491448        }
    1450        
    1451        
     1449
     1450
    14521451        public void noSnapNow() {
    1453             active=false; 
     1452            active=false;
    14541453            dir2=null; projected=null;
    14551454            labelText=null;
     
    14601459            segmentPoint1=seg.getFirstNode().getEastNorth();
    14611460            segmentPoint2=seg.getSecondNode().getEastNorth();
    1462            
     1461
    14631462            double hdg = segmentPoint1.heading(segmentPoint2);
    14641463            hdg=Math.toDegrees(hdg);
     
    14731472            if (snapOn) {
    14741473                // turn off snapping if we are in fixed mode or no actile snapping line exist
    1475                 if (fixed || !active) { snapOn=false; unsetFixedMode(); } 
     1474                if (fixed || !active) { snapOn=false; unsetFixedMode(); }
    14761475                else setFixedMode();
    14771476            } else {
     
    14821481            customBaseHeading=-1;
    14831482        }
    1484        
     1483
    14851484        private void enableSnapping() {
    14861485            snapOn = true;
     
    14891488            unsetFixedMode();
    14901489        }
    1491        
     1490
    14921491        private void toggleSnapping() {
    14931492            snapOn = !snapOn;
     
    14961495            unsetFixedMode();
    14971496        }
    1498                
     1497
    14991498        public void setFixedMode() {
    1500             if (active) { fixed=true; }
    1501         }
    1502                
    1503        
     1499            if (active) {
     1500                fixed=true;
     1501            }
     1502        }
     1503
     1504
    15041505        public  void unsetFixedMode() {
    1505             fixed=false; absoluteFix=false;
     1506            fixed=false;
     1507            absoluteFix=false;
    15061508            lastAngle=0;
    15071509            active=false;
    15081510        }
    1509        
     1511
    15101512        public  boolean isActive() {
    15111513            return active;
    15121514        }
    1513        
     1515
    15141516        public  boolean isSnapOn() {
    15151517            return snapOn;
     
    15181520        private double getNearestAngle(double angle) {
    15191521            double delta,minDelta=1e5, bestAngle=0.0;
    1520             for (int i=0; i<snapAngles.length; i++) {
     1522            for (int i=0; i < snapAngles.length; i++) {
    15211523                delta = getAngleDelta(angle,snapAngles[i]);
    1522                 if (delta<minDelta) {
     1524                if (delta < minDelta) {
    15231525                    minDelta=delta;
    15241526                    bestAngle=snapAngles[i];
    15251527                }
    15261528            }
    1527             if (Math.abs(bestAngle-360)<1e-3) bestAngle=0;
     1529            if (Math.abs(bestAngle-360) < 1e-3)
     1530                bestAngle=0;
    15281531            return bestAngle;
    15291532        }
     
    15311534        private double getAngleDelta(double a, double b) {
    15321535            double delta = Math.abs(a-b);
    1533             if (delta>180) return 360-delta; else return delta;
     1536            if (delta>180)
     1537                return 360-delta;
     1538            else
     1539                return delta;
    15341540        }
    15351541
    15361542        private void unFixOrTurnOff() {
    1537             if (absoluteFix) unsetFixedMode(); else toggleSnapping();
    1538         }
    1539        
     1543            if (absoluteFix)
     1544                unsetFixedMode();
     1545            else
     1546                toggleSnapping();
     1547        }
     1548
    15401549        MouseListener anglePopupListener = new PopupMenuLauncher( new JPopupMenu() {
    1541                JCheckBoxMenuItem helperCb = new JCheckBoxMenuItem(new AbstractAction(tr("Show helper geometry")){
     1550            JCheckBoxMenuItem helperCb = new JCheckBoxMenuItem(new AbstractAction(tr("Show helper geometry")){
     1551                public void actionPerformed(ActionEvent e) {
     1552                    boolean sel=((JCheckBoxMenuItem) e.getSource()).getState();
     1553                    Main.pref.put("draw.anglesnap.drawConstructionGeometry", sel);
     1554                    Main.pref.put("draw.anglesnap.drawProjectedPoint", sel);
     1555                    Main.pref.put("draw.anglesnap.showAngle", sel);
     1556                    init();
     1557                    enableSnapping();
     1558                }
     1559            });
     1560            JCheckBoxMenuItem projectionCb = new JCheckBoxMenuItem(new AbstractAction(tr("Snap to node projections")){
     1561                public void actionPerformed(ActionEvent e) {
     1562                    boolean sel=((JCheckBoxMenuItem) e.getSource()).getState();
     1563                    Main.pref.put("draw.anglesnap.projectionsnap", sel);
     1564                    init();
     1565                    enableSnapping();
     1566                }
     1567            });
     1568            {
     1569                helperCb.setState(Main.pref.getBoolean("draw.anglesnap.drawConstructionGeometry",true));
     1570                projectionCb.setState(Main.pref.getBoolean("draw.anglesnap.projectionsnapgvff",true));
     1571                add(helperCb);
     1572                add(projectionCb);;
     1573                add(new AbstractAction(tr("Disable")) {
    15421574                    public void actionPerformed(ActionEvent e) {
    1543                         boolean sel=((JCheckBoxMenuItem) e.getSource()).getState();
    1544                         Main.pref.put("draw.anglesnap.drawConstructionGeometry", sel);
    1545                         Main.pref.put("draw.anglesnap.drawProjectedPoint", sel);
    1546                         Main.pref.put("draw.anglesnap.showAngle", sel);
    1547                         init(); enableSnapping();
     1575                        saveAngles("180");
     1576                        init();
     1577                        enableSnapping();
    15481578                    }
    1549                });
    1550                JCheckBoxMenuItem projectionCb = new JCheckBoxMenuItem(new AbstractAction(tr("Snap to node projections")){
     1579                });
     1580                add(new AbstractAction(tr("0,90,...")) {
    15511581                    public void actionPerformed(ActionEvent e) {
    1552                         boolean sel=((JCheckBoxMenuItem) e.getSource()).getState();
    1553                         Main.pref.put("draw.anglesnap.projectionsnap", sel);
    1554                         init(); enableSnapping();
     1582                        saveAngles("0","90","180");
     1583                        init();
     1584                        enableSnapping();
    15551585                    }
    1556                });
    1557             { 
    1558                helperCb.setState(Main.pref.getBoolean("draw.anglesnap.drawConstructionGeometry",true));
    1559                projectionCb.setState(Main.pref.getBoolean("draw.anglesnap.projectionsnapgvff",true));
    1560                add(helperCb);
    1561                add(projectionCb);;
    1562                add(new AbstractAction(tr("Disable")) {
    1563                 public void actionPerformed(ActionEvent e) {
    1564                     saveAngles("180");
    1565                     init(); enableSnapping();
    1566                 }
    1567                });
    1568                add(new AbstractAction(tr("0,90,...")) {
    1569                 public void actionPerformed(ActionEvent e) {
    1570                     saveAngles("0","90","180");
    1571                     init(); enableSnapping();
    1572                 }
    1573                });
    1574                add(new AbstractAction(tr("0,45,90,...")) {
    1575                 public void actionPerformed(ActionEvent e) {
    1576                     saveAngles("0","45","90","135","180");
    1577                     init(); enableSnapping();
    1578                 }
    1579                });
    1580                add(new AbstractAction(tr("0,30,45,60,90,...")) {
    1581                 public void actionPerformed(ActionEvent e) {
    1582                     saveAngles("0","30","45","60","90","120","135","150","180");
    1583                     init(); enableSnapping();
    1584                 }
    1585                });
    1586         }
    1587     }) {
     1586                });
     1587                add(new AbstractAction(tr("0,45,90,...")) {
     1588                    public void actionPerformed(ActionEvent e) {
     1589                        saveAngles("0","45","90","135","180");
     1590                        init();
     1591                        enableSnapping();
     1592                    }
     1593                });
     1594                add(new AbstractAction(tr("0,30,45,60,90,...")) {
     1595                    public void actionPerformed(ActionEvent e) {
     1596                        saveAngles("0","30","45","60","90","120","135","150","180");
     1597                        init();
     1598                        enableSnapping();
     1599                    }
     1600                });
     1601            }
     1602        }) {
    15881603            @Override
    15891604            public void mouseClicked(MouseEvent e) {
    15901605                super.mouseClicked(e);
    1591                 if (e.getButton()==MouseEvent.BUTTON1) {
     1606                if (e.getButton() == MouseEvent.BUTTON1) {
    15921607                    toggleSnapping();
    15931608                    updateStatusLine();
    15941609                }
    15951610            }
    1596     };
    1597     }
    1598    
     1611        };
     1612    }
     1613
    15991614    private class SnapChangeAction extends JosmAction {
    16001615        public SnapChangeAction() {
    1601              super(tr("Angle snapping"), "anglesnap",
    1602                    tr("Switch angle snapping mode while drawing"),
    1603                    null, false);
    1604              putValue("help", ht("/Action/Draw/AngleSnap"));
    1605         }
    1606         @Override 
     1616            super(tr("Angle snapping"), "anglesnap",
     1617                tr("Switch angle snapping mode while drawing"), null, false);
     1618            putValue("help", ht("/Action/Draw/AngleSnap"));
     1619        }
     1620
     1621        @Override
    16071622        public void actionPerformed(ActionEvent e) {
    1608                if (snapHelper!=null) snapHelper.toggleSnapping();
    1609         }
    1610        
     1623               if (snapHelper!=null) snapHelper.toggleSnapping();
     1624        }
    16111625    }
    16121626}
  • trunk/src/org/openstreetmap/josm/actions/mapmode/ParallelWayAction.java

    r4836 r4956  
    126126        super(tr("Parallel"), "parallel", tr("Make parallel copies of ways"),
    127127            Shortcut.registerShortcut("mapmode:parallel", tr("Mode: {0}",
    128             tr("Parallel")), KeyEvent.VK_P, Shortcut.GROUP_EDIT,
    129             Shortcut.SHIFT_DEFAULT), mapFrame, ImageProvider.getCursor("normal",
     128            tr("Parallel")), KeyEvent.VK_P, Shortcut.GROUP_EDIT+
     129            Shortcut.GROUPS_ALT1), mapFrame, ImageProvider.getCursor("normal",
    130130            "parallel"));
    131131        putValue("help", ht("/Action/Parallel"));
  • trunk/src/org/openstreetmap/josm/gui/dialogs/MapPaintDialog.java

    r4912 r4956  
    8686    public MapPaintDialog() {
    8787        super(tr("Map Paint Styles"), "mapstyle", tr("configure the map painting style"),
    88                 Shortcut.registerShortcut("subwindow:mappaint", tr("Toggle: {0}", tr("MapPaint")), KeyEvent.VK_M, Shortcut.GROUP_LAYER, Shortcut.SHIFT_DEFAULT), 150);
     88            Shortcut.registerShortcut("subwindow:mappaint", tr("Toggle: {0}", tr("MapPaint")),
     89            KeyEvent.VK_M, Shortcut.GROUP_LAYER+Shortcut.GROUPS_ALT1), 150);
    8990        build();
    9091    }
  • trunk/src/org/openstreetmap/josm/gui/preferences/PrefJPanel.java

    r4930 r4956  
    103103    // not a list of real physical keys. If someone knows how to get that list?
    104104    private static Map<Integer, String> keyList = setKeyList();
    105    
     105
    106106    private static Map<Integer, String> setKeyList() {
    107107        Map<Integer, String> list = new LinkedHashMap<Integer, String>();
     
    125125        return list;
    126126    }
    127    
     127
    128128    private JComboBox bxPrim1 = new JComboBox();
    129129    private JComboBox bxPrim2 = new JComboBox();
     
    145145    private JCheckBox cbDisable = new JCheckBox();
    146146    private JComboBox tfKey = new JComboBox();
    147    
     147
    148148    JTable shortcutTable = new JTable();
    149    
     149
    150150    private JTextField filterField = new JTextField();
    151151
     
    219219
    220220        listPane.add(listScrollPane);
    221        
     221
    222222        shortcutTab.add(listPane);
    223223
     
    239239        cbMeta.setAction(action);
    240240        cbMeta.setText(META); // see above for why no tr()
    241        
    242        
     241
     242
    243243        shortcutEditPane.add(cbDefault);
    244244        shortcutEditPane.add(new JLabel());
     
    266266        editGroupPane.setBorder(BorderFactory.createTitledBorder(tr("Edit Shortcuts")));
    267267        editGroupPane.setLayout(new java.awt.GridLayout(3, 5));
    268        
     268
    269269        JComboBox[] bxArray = new JComboBox[] {
    270270                    bxPrim1,bxSec1,bxTer1,bxPrim2,bxSec2,bxTer2,
    271271                    bxPrim3,bxSec3,bxTer3,bxPrim4,bxSec4,bxTer4};
    272         for (JComboBox bxi: bxArray) bxi.setModel(new DefaultComboBoxModel(modifList)); 
    273        
     272        for (JComboBox bxi: bxArray) bxi.setModel(new DefaultComboBoxModel(modifList));
     273
    274274        editGroupPane.add(new JLabel(tr("Primary modifier:")));
    275275        editGroupPane.add(bxPrim1);
     
    310310
    311311        initbx();
    312         for (JComboBox bxi: bxArray) bxi.setAction(action2); 
     312        for (JComboBox bxi: bxArray) bxi.setAction(action2);
    313313
    314314        modifierTab.add(subwindowGroupPane);
     
    340340        return pnl;
    341341    }
    342    
     342
    343343    private void disableAllModifierCheckboxes() {
    344344        cbDefault.setEnabled(false);
     
    481481    }
    482482
    483    
     483
    484484     class FilterFieldAdapter implements DocumentListener {
    485485        public void filter() {
     
    492492                    sorter.setRowFilter(null);
    493493                } else {
    494                     // split search string on whitespace, do case-insensitive AND search 
     494                    // split search string on whitespace, do case-insensitive AND search
    495495                    ArrayList<RowFilter<Object, Object>> andFilters = new ArrayList<RowFilter<Object, Object>>();
    496496                    for (String word : expr.split("\\s+")) {
     
    508508        public void removeUpdate(DocumentEvent arg0) { filter(); }
    509509    }
    510    
     510
    511511}
  • trunk/src/org/openstreetmap/josm/tools/Shortcut.java

    r4928 r4956  
    571571        return sc.getKeyStroke();
    572572    }
     573
     574    public boolean isEvent(KeyEvent e) {
     575        return getKeyStroke() != null && getKeyStroke().equals(
     576        KeyStroke.getKeyStroke(e.getKeyCode(), e.getModifiers()));
     577    }
    573578}
Note: See TracChangeset for help on using the changeset viewer.