Changeset 6 in josm for src/org/openstreetmap/josm


Ignore:
Timestamp:
2005-10-01T04:01:45+02:00 (19 years ago)
Author:
imi
Message:
  • pretty preferrences menu
  • drawing double circles on double position hit
  • mergeNodes option
Location:
src/org/openstreetmap/josm
Files:
1 added
13 edited

Legend:

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

    r4 r6  
    3131        }
    3232       
     33        @Override
    3334        public void registerListener(MapView mapView) {
    3435                mapView.addMouseMotionListener(this);
     
    3738        }
    3839
     40        @Override
    3941        public void unregisterListener(MapView mapView) {
    4042                mapView.removeMouseMotionListener(this);
  • src/org/openstreetmap/josm/actions/mapmode/ZoomAction.java

    r4 r6  
    1717 * Holding down left and right let the user move the former selected rectangle.
    1818 * Releasing the left button zoom to the selection.
     19 *
     20 * Rectangle selections with either height or width smaller than 3 pixels
     21 * are ignored.
    1922 *
    2023 * @author imi
     
    4750         */
    4851        public void selectionEnded(Rectangle r, int modifier) {
    49                 double scale = mv.getScale() * r.getWidth()/mv.getWidth();
    50                 GeoPoint newCenter = mv.getPoint(r.x+r.width/2, r.y+r.height/2, false);
    51                 mv.zoomTo(newCenter, scale);
     52                if (r.width >= 3 && r.height >= 3) {
     53                        double scale = mv.getScale() * r.getWidth()/mv.getWidth();
     54                        GeoPoint newCenter = mv.getPoint(r.x+r.width/2, r.y+r.height/2, false);
     55                        mv.zoomTo(newCenter, scale);
     56                }
    5257        }
    5358
     59        @Override
    5460        public void registerListener(MapView mapView) {
    5561                selectionManager.register(mapView);
    5662        }
    5763
     64        @Override
    5865        public void unregisterListener(MapView mapView) {
    5966                selectionManager.unregister(mapView);
  • src/org/openstreetmap/josm/data/GeoPoint.java

    r1 r6  
    11package org.openstreetmap.josm.data;
     2
    23
    34/**
     
    4445                return null;
    4546        }
     47
     48        /**
     49         * GeoPoints are equal, if their lat/lon are equal or, if lat or lon are NaN,
     50         * if their x/y are equal.
     51         */
     52        @Override
     53        public boolean equals(Object obj) {
     54                if (!(obj instanceof GeoPoint))
     55                        return false;
     56                GeoPoint gp = (GeoPoint)obj;
     57               
     58                if (Double.isNaN(lat) || Double.isNaN(lon))
     59                        return x == gp.x && y == gp.y;
     60                return lat == gp.lat && lon == gp.lon;
     61        }
     62
     63        @Override
     64        public int hashCode() {
     65                return super.hashCode();
     66        }
     67       
     68       
    4669}
  • src/org/openstreetmap/josm/data/Preferences.java

    r1 r6  
    44import java.io.FileReader;
    55import java.io.FileWriter;
     6import java.util.List;
    67
    78import javax.swing.UIManager;
     
    3435        public Projection projection = new UTM();
    3536
     37
    3638        /**
    37          * The monitor geometry in meter per pixel. (How big is 1 pixel in meters)
    38          * Example: 17" Sony flatscreen in 1280x1024 mode: 0.000264 ppm
    39          *
    40          * Remember: ppm = dpi/25400
     39         * Whether nodes on the same place should be considered identical.
    4140         */
    42         public double ppm = 0.000264;
     41        public boolean mergeNodes = true;
     42       
     43       
    4344
    44        
     45        /**
     46         * List of all available Projections.
     47         */
    4548        public static final Projection[] allProjections = new Projection[]{
    4649                new UTM(),
     
    8588                       
    8689                        projection = (Projection)Class.forName(root.getChildText("projection")).newInstance();
     90                        mergeNodes = root.getChild("mergeNodes") != null;
    8791                } catch (Exception e) {
    8892                        if (e instanceof PreferencesException)
     
    100104                Element root = new Element("josm-settings");
    101105               
    102                 root.getChildren().add(new Element("laf").setText(laf.getClassName()));
    103                 root.getChildren().add(new Element("projection").setText(projection.getClass().getName()));
     106                List children = root.getChildren();
     107                children.add(new Element("laf").setText(laf.getClassName()));
     108                children.add(new Element("projection").setText(projection.getClass().getName()));
     109                if (mergeNodes)
     110                        children.add(new Element("mergeNodes"));
    104111
    105112                try {
  • src/org/openstreetmap/josm/data/osm/DataSet.java

    r2 r6  
    119119        }
    120120       
     121        @Override
    121122        public DataSet clone() {
    122123                try {return (DataSet)super.clone();} catch (CloneNotSupportedException e) {}
  • src/org/openstreetmap/josm/data/osm/Node.java

    r1 r6  
    1515         */
    1616        public GeoPoint coor;
     17
     18        /**
     19         * Nodes are equal when their coordinates are equal.
     20         */
     21        @Override
     22        public boolean equals(Object obj) {
     23                if (!(obj instanceof Node))
     24                        return false;
     25                Node n = (Node)obj;
     26                if (coor == null)
     27                        return n.coor == null;
     28                return coor.equals(n.coor) && super.equals(obj);
     29        }
     30
     31        /**
     32         * Compute the hashcode from the OsmPrimitive's hash and the coor's hash.
     33         */
     34        @Override
     35        public int hashCode() {
     36                return (coor == null ? 0 : coor.hashCode()) + super.hashCode();
     37        }
     38       
     39       
    1740}
  • src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r2 r6  
    2020         * If set to true, this object has been modified in the current session.
    2121         */
    22         public boolean modified = false;
     22        transient public boolean modified = false;
    2323       
    2424        /**
    2525         * If set to true, this object is currently selected.
    2626         */
    27         public boolean selected = false;
     27        transient public boolean selected = false;
     28
     29        /**
     30         * Osm primitives are equal, when their keys are equal.
     31         */
     32        @Override
     33        public boolean equals(Object obj) {
     34                if (obj == null)
     35                        return false;
     36                if (!(obj instanceof OsmPrimitive))
     37                        return false;
     38                OsmPrimitive osm = (OsmPrimitive)obj;
     39                if (keys == null)
     40                        return osm.keys == null;
     41                return keys.equals(osm.keys);
     42        }
     43
     44        /**
     45         * Compute the hashCode from the keys.
     46         */
     47        @Override
     48        public int hashCode() {
     49                return keys == null ? 0 : keys.hashCode();
     50        }
     51       
     52       
    2853}
  • src/org/openstreetmap/josm/data/projection/Projection.java

    r1 r6  
    4545         * Describe the projection converter in one or two words.
    4646         */
     47        @Override
    4748        abstract public String toString();
    4849       
  • src/org/openstreetmap/josm/data/projection/UTM.java

    r1 r6  
    4949                        this.ecc_squared = ecc_squared;
    5050                }
     51                @Override
    5152                public String toString() {
    5253                        return name;
  • src/org/openstreetmap/josm/gui/MapMover.java

    r3 r6  
    6464         * Start the movement, if it was the 3rd button (right button).
    6565         */
     66        @Override
    6667        public void mousePressed(MouseEvent e) {
    6768                int offMask = MouseEvent.BUTTON1_DOWN_MASK | MouseEvent.BUTTON2_DOWN_MASK;
     
    7374         * Change the cursor back to it's pre-move cursor.
    7475         */
     76        @Override
    7577        public void mouseReleased(MouseEvent e) {
    7678                if (e.getButton() == MouseEvent.BUTTON3)
  • src/org/openstreetmap/josm/gui/MapView.java

    r4 r6  
    88import java.awt.event.ComponentListener;
    99import java.awt.event.KeyEvent;
     10import java.util.HashSet;
    1011import java.util.LinkedList;
    1112import java.util.List;
     13import java.util.Set;
    1214
    1315import javax.swing.AbstractAction;
     
    246248                g.setColor(Color.BLACK);
    247249                g.fillRect(0,0,getWidth(),getHeight());
    248                
     250
    249251                // draw tracks
    250252                if (dataSet.tracks != null)
     
    257259
    258260                // draw nodes
     261                Set<Integer> alreadyDrawn = new HashSet<Integer>();
     262                int width = getWidth();
    259263                for (Node w : dataSet.allNodes) {
    260264                        g.setColor(w.selected ? Color.WHITE : Color.RED);
    261                         g.drawArc(toScreenX(w.coor.x), toScreenY(w.coor.y), 3, 3, 0, 360);
     265                        int x = toScreenX(w.coor.x);
     266                        int y = toScreenY(w.coor.y);
     267                        int size = 3;
     268                        if (alreadyDrawn.contains(y*width+x)) {
     269                                size = 7;
     270                                x -= 2;
     271                                y -= 2;
     272                        } else
     273                                alreadyDrawn.add(y*width+x);
     274                        g.drawArc(x, y, size, size, 0, 360);
    262275                }
    263276        }
  • src/org/openstreetmap/josm/gui/PreferenceDialog.java

    r1 r6  
    11package org.openstreetmap.josm.gui;
    22
    3 import java.awt.BorderLayout;
    43import java.awt.Component;
    5 import java.awt.Container;
    64import java.awt.Dimension;
     5import java.awt.Font;
     6import java.awt.GridBagLayout;
    77import java.awt.event.ActionEvent;
    88import java.awt.event.ActionListener;
     
    1111
    1212import javax.swing.AbstractAction;
    13 import javax.swing.BorderFactory;
    1413import javax.swing.Box;
    1514import javax.swing.DefaultListCellRenderer;
    1615import javax.swing.ImageIcon;
    1716import javax.swing.JButton;
     17import javax.swing.JCheckBox;
    1818import javax.swing.JComboBox;
    1919import javax.swing.JDialog;
     
    5050                        pref.laf = (LookAndFeelInfo)lafCombo.getSelectedItem();
    5151                        pref.projection = (Projection)projectionCombo.getSelectedItem();
     52                        pref.mergeNodes = mergeNodes.isSelected();
    5253                        Main.pref.projection = pref.projection;
    5354                        try {
     
    8586        private JComboBox lafCombo = new JComboBox(UIManager.getInstalledLookAndFeels());
    8687        /**
    87          * The tabbed pane to add tabulars to.
    88          */
    89         private JTabbedPane tabPanel = new JTabbedPane();
    90         /**
    9188         * Combobox with all projections available
    9289         */
    93         private JComboBox projectionCombo = new JComboBox(Preferences.allProjections);
     90        private JComboBox projectionCombo = new JComboBox(Preferences.allProjections.clone());
     91        /**
     92         * The main tab panel.
     93         */
     94        private JTabbedPane tabPane = new JTabbedPane(JTabbedPane.LEFT);
     95        /**
     96         * The checkbox stating whether nodes should be merged together.
     97         */
     98        private JCheckBox mergeNodes = new JCheckBox("Merge nodes with equal latitude/longitude.");
    9499
    95100       
     
    113118                }
    114119
    115                 getContentPane().setLayout(new BorderLayout());
    116                 getContentPane().add(tabPanel, BorderLayout.CENTER);
    117 
    118                 newTab("Display");
    119                 // laf
    120                 JPanel p = newPanelLine();
    121                 p.add(new JLabel("Look and Feel"));
     120                // look and feel combo box
    122121                final ListCellRenderer oldRenderer = lafCombo.getRenderer();
    123122                lafCombo.setRenderer(new DefaultListCellRenderer(){
     123                        @Override
    124124                        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    125125                                return oldRenderer.getListCellRendererComponent(list, ((LookAndFeelInfo)value).getName(), index, isSelected, cellHasFocus);
     
    130130                                setRequiresRestart();
    131131                        }});
    132                 p.add(lafCombo);
    133 
    134                 newTab("Projection");
    135                 p = newPanelLine();
    136                 p.add(new JLabel("Projection System"));
    137                 p.add(projectionCombo);
    138                 for (int i = 0; i < projectionCombo.getItemCount(); ++i)
     132
     133                // projection method combo box
     134                for (int i = 0; i < projectionCombo.getItemCount(); ++i) {
    139135                        if (projectionCombo.getItemAt(i).getClass().equals(pref.projection.getClass())) {
    140136                                projectionCombo.setSelectedIndex(i);
    141137                                break;
    142138                        }
    143 
    144                 // OK/Cancel
    145                 JPanel okPanel = new JPanel();
    146                 okPanel.add(new JButton(new OkAction()));
    147                 okPanel.add(new JButton(new CancelAction()));
    148                 getContentPane().add(okPanel, BorderLayout.SOUTH);
     139                }
     140               
     141                // Display tab
     142                JPanel display = createPreferenceTab("display", "Display Settings", "Various settings than influence the visual representation of the whole Program.");
     143                display.add(new JLabel("Look and Feel"), GBC.std());
     144                display.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL));
     145                display.add(lafCombo, GBC.eol().fill(GBC.HORIZONTAL));
     146                display.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL));
     147
     148                // Map tab
     149                JPanel map = createPreferenceTab("map", "Map Settings", "Settings for the map projection and data interpretation.");
     150                map.add(new JLabel("Projection method"), GBC.std());
     151                map.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL));
     152                map.add(projectionCombo, GBC.eol().fill(GBC.HORIZONTAL));
     153                JLabel labelNoteProjection = new JLabel(
     154                                "<html>Note: This is the default projection method used for files, " +
     155                                "where the correct projection could not be determined. " +
     156                                "The actual used projection can be changed in the property " +
     157                                "settings of each map.</html>");
     158                labelNoteProjection.setMinimumSize(new Dimension(550, 50));
     159                labelNoteProjection.setPreferredSize(new Dimension(550, 50));
     160                map.add(labelNoteProjection, GBC.eol().insets(0,5,0,20));
     161                map.add(new JLabel("GPX import / export"), GBC.eol());
     162                mergeNodes.setSelected(pref.mergeNodes);
     163                map.add(mergeNodes, GBC.eol());
     164                map.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL));
     165
     166               
     167                tabPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
     168       
     169                // OK/Cancel panel at bottom
     170                JPanel okPanel = new JPanel(new GridBagLayout());
     171                okPanel.add(Box.createHorizontalGlue(), GBC.std().fill(GBC.HORIZONTAL));
     172                okPanel.add(new JButton(new OkAction()), GBC.std());
     173                okPanel.add(new JButton(new CancelAction()), GBC.std());
     174
     175                // merging all in the content pane
     176                getContentPane().setLayout(new GridBagLayout());
     177                getContentPane().add(tabPane, GBC.eol().fill());
     178                getContentPane().add(okPanel, GBC.eol().fill(GBC.HORIZONTAL));
    149179
    150180                setModal(true);
     
    155185
    156186        /**
    157          * Start a new tab with the given name
    158          * @param tabName The name of the new tab.
    159          */
    160         private void newTab(String tabName) {
    161                 Box tab = Box.createVerticalBox();
    162                 tab.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
    163                 tabPanel.addTab(tabName, tab);
    164         }
    165 
     187         * Construct a JPanel for the preference settings. Layout is GridBagLayout
     188         * and a centered title label and the description are added.
     189         * @param icon The name of the icon.
     190         * @param title The title of this preference tab.
     191         * @param desc A description in one sentence for this tab. Will be displayed
     192         *              italic under the title.
     193         * @return The created panel ready to add other controls.
     194         */
     195        private JPanel createPreferenceTab(String icon, String title, String desc) {
     196                JPanel p = new JPanel(new GridBagLayout());
     197                p.add(new JLabel(title), GBC.eol().anchor(GBC.CENTER).insets(0,5,0,10));
     198                JLabel descLabel = new JLabel(desc);
     199                descLabel.setFont(descLabel.getFont().deriveFont(Font.ITALIC));
     200                p.add(descLabel, GBC.eol().insets(5,0,5,20));
     201
     202                tabPane.addTab(null, new ImageIcon("images/preferences/"+icon+".png"), p);
     203                return p;
     204        }
     205       
    166206        /**
    167207         * Remember, that the settings made requires a restart of the application.
     
    171211                requiresRestart = true;
    172212        }
    173 
    174         private JPanel newPanelLine() {
    175                 JPanel p;
    176                 p = new JPanel();
    177                 p.setBorder(BorderFactory.createEmptyBorder(5,0,0,0));
    178                 ((Container)tabPanel.getComponent(tabPanel.getTabCount()-1)).add(p);
    179                 return p;
    180         }
    181213}
  • src/org/openstreetmap/josm/io/GpxReader.java

    r2 r6  
    1515import org.openstreetmap.josm.data.osm.Track;
    1616import org.openstreetmap.josm.data.osm.LineSegment;
     17import org.openstreetmap.josm.gui.Main;
    1718
    1819/**
     
    7071                data.allNodes = new LinkedList<Node>();
    7172                for (Object o : e.getChildren("wpt", GPX))
    72                         data.allNodes.add(parseWaypoint((Element)o));
     73                        addNode(data, parseWaypoint((Element)o));
    7374
    7475                // read tracks
     
    7980                                for (Object w : ((Element)trackSegmentElement).getChildren("trkpt", GPX)) {
    8081                                        Node node = parseWaypoint((Element)w);
    81                                         data.allNodes.add(node);
     82                                        node = addNode(data, node);
    8283                                        if (start == null)
    8384                                                start = node;
     
    9697                return data;
    9798        }
     99       
     100        /**
     101         * Adds the node to allNodes if it is not already listed. Does respect the
     102         * preference setting "mergeNodes". Return the node in the list that correspond
     103         * to the node in the list (either the new added or the old found).
     104         *
     105         * @param data The DataSet to add the node to.
     106         * @param node The node that should be added.
     107         * @return Either the parameter node or the old node found in the dataset.
     108         */
     109        private Node addNode (DataSet data, Node node) {
     110                if (Main.pref.mergeNodes)
     111                        for (Node n : data.allNodes)
     112                                if (node.equals(n))
     113                                        return n;
     114                data.allNodes.add(node);
     115                return node;
     116        }
    98117}
Note: See TracChangeset for help on using the changeset viewer.