Changeset 22153 in osm for applications


Ignore:
Timestamp:
2010-07-02T00:51:25+02:00 (14 years ago)
Author:
pieren
Message:

continuation of addr helper

Location:
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/Address.java

    r22101 r22153  
    66import java.awt.GridBagLayout;
    77import java.awt.Point;
     8import java.awt.Rectangle;
    89import java.awt.Toolkit;
    910import java.awt.event.ActionEvent;
    1011import java.awt.event.ActionListener;
     12import java.awt.event.ComponentAdapter;
     13import java.awt.event.ComponentEvent;
    1114import java.awt.event.KeyEvent;
    1215import java.awt.event.MouseEvent;
     
    2528
    2629import javax.swing.ButtonGroup;
     30import javax.swing.ImageIcon;
    2731import javax.swing.JButton;
    2832import javax.swing.JDialog;
     
    3640import org.openstreetmap.josm.command.AddCommand;
    3741import org.openstreetmap.josm.command.ChangeCommand;
     42import org.openstreetmap.josm.command.ChangePropertyCommand;
    3843import org.openstreetmap.josm.command.Command;
    3944import org.openstreetmap.josm.command.SequenceCommand;
     
    7378    final JTextField inputNumber = new JTextField();
    7479    final JTextField inputStreet = new JTextField();
     80    JLabel link = new JLabel();
     81    private Way selectedWay;
    7582   
    7683    MapFrame mapFrame;
     
    8794        super.enterMode();
    8895        if (dialog == null) {
    89             JPanel p = new JPanel(new GridBagLayout());
    90             JLabel number = new JLabel(tr("Number"));
    91             JLabel street = new JLabel(tr("Street"));
    92             p.add(number, GBC.std().insets(0, 0, 5, 0));
    93             p.add(inputNumber, GBC.eol().fill(GBC.HORIZONTAL).insets(10, 5, 0, 5));
    94             p.add(street, GBC.std().insets(0, 0, 5, 0));
    95             inputStreet.setEditable(false);
    96             p.add(inputStreet, GBC.eol().fill(GBC.HORIZONTAL).insets(10, 5, 0, 5));
    97             clearButton = new JButton("Clear");
    98             clearButton.addActionListener(new ActionListener() {
    99                 public void actionPerformed(ActionEvent e) {
    100                     inputNumber.setText("");
    101                     inputStreet.setText("");
    102                 }
    103             });
    104             ButtonGroup bgIncremental = new ButtonGroup();
    105             bgIncremental.add(plus_one);
    106             bgIncremental.add(plus_two);
    107             bgIncremental.add(minus_one);
    108             bgIncremental.add(minus_two);
    109             p.add(minus_one, GBC.std().insets(10, 0, 10, 0));
    110             p.add(plus_one, GBC.eol().fill(GBC.HORIZONTAL).insets(10, 0, 0, 0));
    111             p.add(minus_two, GBC.std().insets(10, 0, 10, 0));
    112             p.add(plus_two, GBC.std().insets(10, 0, 10, 0));
    113             p.add(clearButton, GBC.eol().fill(GBC.HORIZONTAL).insets(10, 0, 0, 0));
    114 
    115             final Object[] options = {};
    116             final JOptionPane pane = new JOptionPane(p,
    117                     JOptionPane.PLAIN_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION,
    118                     null, options, null);
    119             dialog = pane.createDialog(Main.parent, tr("Enter addresses"));
    120             dialog.setModal(false);
    121             dialog.setAlwaysOnTop(true);
     96            createDialog();
    12297        }
    12398        dialog.setVisible(true);
     
    135110        if (e.getButton() != MouseEvent.BUTTON1)
    136111            return;
     112
    137113        MapView mv = Main.map.mapView;
    138114        Point mousePos = e.getPoint();
     
    140116        mouseOnExistingWays = new ArrayList<Way>();
    141117        Node currentMouseNode = mv.getNearestNode(mousePos, OsmPrimitive.isSelectablePredicate);
    142         if(currentMouseNode != null) {
     118        if (currentMouseNode != null) {
    143119            String num = currentMouseNode.get(tagHouseNumber);
    144120            if (num != null) {
     
    146122                    Integer.parseInt(num);
    147123                    inputNumber.setText(num);
     124                    applyInputNumberChange();
    148125                } catch (NumberFormatException en) {
    149126                    System.out.println("Unable to parse house number \"" + num + "\"");
    150127                }
    151128            }
    152             if (currentMouseNode.get(tagHouseStreet) != null)
     129            if (currentMouseNode.get(tagHouseStreet) != null) {
    153130                inputStreet.setText(currentMouseNode.get(tagHouseNumber));
    154             else {
     131                setSelectedWay(null);
     132            } else {
    155133                // check if the node belongs to an associatedStreet relation
    156134                List<OsmPrimitive> l = currentMouseNode.getReferrers();
     
    159137                        if (osm.hasKey(relationStreetNameAttr)) {
    160138                            inputStreet.setText(osm.get(relationStreetNameAttr));
     139                            setSelectedWay(null);
    161140                            break;
    162141                        } else {
     
    164143                                if (rm.getRole().equals(relationAddrStreetRole)) {
    165144                                    OsmPrimitive osp = rm.getMember();
    166                                     if (osp.hasKey(tagHighwayName)) {
     145                                    if (osp instanceof Way && osp.hasKey(tagHighwayName)) {
    167146                                        inputStreet.setText(osp.get(tagHighwayName));
     147                                        setSelectedWay((Way)osp);
    168148                                        break;
    169149                                    }
     
    182162                // clicked on existing highway => set new street name
    183163                inputStreet.setText(mouseOnExistingWays.get(0).get(tagHighwayName));
     164                setSelectedWay(mouseOnExistingWays.get(0));
    184165            } else if (mouseOnExistingWays.size() == 0) {
    185166                // clicked a non highway and not a node => add the new address
     
    188169                } else {
    189170                    Node n = Main.map.mapView.getNearestNode(mousePos, OsmPrimitive.isSelectablePredicate);
     171                    Collection<Command> cmds = new LinkedList<Command>();
    190172                    if (n == null)
    191                         n = createNewNode(e);
    192                     addAddrToNode(n);
     173                        n = createNewNode(e, cmds);
     174                    addAddrToNode(n, cmds);
     175                    if (cmds.size() > 0) {
     176                        Command c = new SequenceCommand("Add node address", cmds);
     177                        Main.main.undoRedo.add(c);
     178                    }
    193179                }
    194180            }
     
    197183    }
    198184   
    199     private void addAddrToNode(Node n) {
    200         // add the tag addr:housenumber in node and member in relation
    201     }
    202    
    203     private Node createNewNode(MouseEvent e) {
     185    private void addAddrToNode(Node n, Collection<Command> cmds) {
     186        try {
     187            // add the tag addr:housenumber in node and member in relation
     188            cmds.add(new ChangePropertyCommand(n, tagHouseNumber, inputNumber.getText()));           
     189            cmds.add(new ChangePropertyCommand(n, tagHouseStreet, inputStreet.getText()));           
     190            applyInputNumberChange();
     191        } catch (NumberFormatException en) {
     192            System.out.println("Unable to parse house number \"" + inputNumber.getText() + "\"");
     193        }
     194    }
     195   
     196    private Node createNewNode(MouseEvent e, Collection<Command> cmds) {
    204197        // DrawAction.mouseReleased() but without key modifiers
    205198        Node n = new Node(Main.map.mapView.getLatLon(e.getX(), e.getY()));
    206         Collection<Command> cmds = new LinkedList<Command>();
    207199        cmds.add(new AddCommand(n));
    208200        List<WaySegment> wss = Main.map.mapView.getNearestWaySegments(e.getPoint(), OsmPrimitive.isSelectablePredicate);
     
    239231        adjustNode(segSet, n);
    240232
    241         Command c = new SequenceCommand("Add node address", cmds);
    242         Main.main.undoRedo.add(c);
    243233        return n;
    244234    }
     
    326316        return Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR);
    327317    }
     318   
     319    private void applyInputNumberChange() {
     320        Integer num = Integer.parseInt(inputNumber.getText());
     321        if (plus_one.isSelected())
     322            num = num + 1;
     323        if (plus_two.isSelected())
     324            num = num + 2;
     325        if (minus_one.isSelected() && num > 1)
     326            num = num - 1;
     327        if (minus_two.isSelected() && num > 2)
     328            num = num - 2;
     329        inputNumber.setText(num.toString());
     330    }
     331   
     332    private void createDialog() {
     333        ImageIcon iconLink = ImageProvider.get(null, "Mf_relation.png");
     334        link.setIcon(iconLink);
     335        link.setEnabled(false);
     336        JPanel p = new JPanel(new GridBagLayout());
     337        JLabel number = new JLabel(tr("Number"));
     338        JLabel street = new JLabel(tr("Street"));
     339        p.add(number, GBC.std().insets(0, 0, 0, 0));
     340        p.add(inputNumber, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 5, 0, 5));
     341        p.add(street, GBC.std().insets(0, 0, 0, 0));
     342        JPanel p2 = new JPanel(new GridBagLayout());
     343        inputStreet.setEditable(false);
     344        p2.add(inputStreet, GBC.std().fill(GBC.HORIZONTAL).insets(5, 0, 0, 0));
     345        p2.add(link, GBC.eol().insets(10, 0, 0, 0));
     346        p.add(p2, GBC.eol().fill(GBC.HORIZONTAL));
     347        clearButton = new JButton("Clear");
     348        clearButton.addActionListener(new ActionListener() {
     349            public void actionPerformed(ActionEvent e) {
     350                inputNumber.setText("");
     351                inputStreet.setText("");
     352                setSelectedWay(null);
     353            }
     354        });
     355        ButtonGroup bgIncremental = new ButtonGroup();
     356        bgIncremental.add(plus_one);
     357        bgIncremental.add(plus_two);
     358        bgIncremental.add(minus_one);
     359        bgIncremental.add(minus_two);
     360        p.add(minus_one, GBC.std().insets(10, 0, 10, 0));
     361        p.add(plus_one, GBC.eol().fill(GBC.HORIZONTAL).insets(10, 0, 0, 0));
     362        p.add(minus_two, GBC.std().insets(10, 0, 10, 0));
     363        p.add(plus_two, GBC.std().insets(10, 0, 10, 0));
     364        p.add(clearButton, GBC.eol().fill(GBC.HORIZONTAL).insets(10, 0, 0, 0));
     365   
     366        final Object[] options = {};
     367        final JOptionPane pane = new JOptionPane(p,
     368                JOptionPane.PLAIN_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION,
     369                null, options, null);
     370        dialog = pane.createDialog(Main.parent, tr("Enter addresses"));
     371        dialog.setModal(false);
     372        dialog.setAlwaysOnTop(true);
     373        dialog.addComponentListener(new ComponentAdapter() {
     374            protected void rememberGeometry() {
     375                Main.pref.put("cadastrewms.addr_bounds", dialog.getX()+","+dialog.getY()+","+dialog.getWidth()+","+dialog.getHeight());
     376            }
     377            @Override public void componentMoved(ComponentEvent e) {
     378                rememberGeometry();
     379            }
     380            @Override public void componentResized(ComponentEvent e) {
     381                rememberGeometry();
     382            }
     383        });
     384        String bounds = Main.pref.get("cadastrewms.addr_bounds",null);
     385        if (bounds != null) {
     386            String[] b = bounds.split(",");
     387            dialog.setBounds(new Rectangle(
     388                    Integer.parseInt(b[0]),Integer.parseInt(b[1]),Integer.parseInt(b[2]),Integer.parseInt(b[3])));
     389        }
     390
     391
     392   
     393   
     394//        exitMode();
     395//        Main.map.selectMapMode((MapMode)Main.map.getDefaultButtonAction());
    328396}
     397   
     398    private void setSelectedWay(Way w) {
     399        this.selectedWay = w;
     400        if (w == null)
     401            link.setEnabled(false);
     402        else
     403            link.setEnabled(true);
     404    }
     405
     406}
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSLayer.java

    r21191 r22153  
    274274            else
    275275                g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
    276             for (GeorefImage img : images)
    277                 img.paint(g, mv, CadastrePlugin.backgroundTransparent,
    278                         CadastrePlugin.transparency, CadastrePlugin.drawBoundaries);
     276            synchronized(this){
     277                for (GeorefImage img : images)
     278                    img.paint(g, mv, CadastrePlugin.backgroundTransparent,
     279                            CadastrePlugin.transparency, CadastrePlugin.drawBoundaries);
     280            }
    279281            g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, savedInterpolation);
    280282        }
Note: See TracChangeset for help on using the changeset viewer.