Changeset 22 in josm for src/org/openstreetmap/josm/gui


Ignore:
Timestamp:
2005-10-23T22:13:33+02:00 (19 years ago)
Author:
imi
Message:

starting restructure of dataset. Checkpoint is broken!

Location:
src/org/openstreetmap/josm/gui
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • src/org/openstreetmap/josm/gui/ImageProvider.java

    r21 r22  
    2525         * @author imi
    2626         */
    27         public enum OverlayPosition {NORTHWEST, NORTHEAST, SOUTHWEST, SOUTHEAST};
     27        public enum OverlayPosition {NORTHWEST, NORTHEAST, SOUTHWEST, SOUTHEAST}
    2828       
    2929        /**
  • src/org/openstreetmap/josm/gui/MapStatus.java

    r17 r22  
    4747         * The position of the mouse cursor.
    4848         */
    49         private JTextField positionText = new JTextField("-000.00000000000000 -000.00000000000000".length());
     49        JTextField positionText = new JTextField("-000.00000000000000 -000.00000000000000".length());
    5050        /**
    5151         * The field holding the name of the object under the mouse.
    5252         */
    53         private JTextField nameText = new JTextField(30);
     53        JTextField nameText = new JTextField(30);
    5454
    5555        /**
     
    147147         * The last sent mouse movement event.
    148148         */
    149         private MouseState mouseState = new MouseState();
     149        MouseState mouseState = new MouseState();
    150150       
    151151        /**
  • src/org/openstreetmap/josm/gui/MapView.java

    r21 r22  
    3232 * provide the MapMode's enough capabilities to operate.
    3333 *
    34  * MapView holds the map data, organize it, convert it, provide access to it.
    35  *
    3634 * MapView hold meta-data about the data set currently displayed, as scale level,
    3735 * center point viewed, what scrolling mode or editing mode is selected or with
     
    8785         */
    8886        public MapView(Layer layer) {
    89                 if (layer.dataSet == null)
    90                         throw new IllegalArgumentException("Initial layer must have a dataset.");
    91 
    9287                addComponentListener(new ComponentAdapter(){
    9388                        @Override
     
    118113                        // initialize the projection if it was the first layer
    119114                        if (layers.size() == 1)
    120                                 Main.pref.getProjection().init(layer.dataSet);
     115                                Main.pref.getProjection().init();
    121116                       
    122117                        // initialize the dataset in the new layer
     
    231226                OsmPrimitive minPrimitive = null;
    232227
    233                 // calculate the object based on the current active dataset.
    234                 DataSet ds = getActiveDataSet();
    235                
    236228                // nodes
    237                 for (Node n : ds.nodes) {
     229                for (Node n : Main.main.ds.nodes) {
    238230                        Point sp = getScreenPoint(n.coor);
    239231                        double dist = p.distanceSq(sp);
     
    247239               
    248240                // pending line segments
    249                 for (LineSegment ls : ds.pendingLineSegments()) {
     241                for (LineSegment ls : Main.main.ds.pendingLineSegments()) {
    250242                        Point A = getScreenPoint(ls.getStart().coor);
    251243                        Point B = getScreenPoint(ls.getEnd().coor);
     
    262254                // tracks & line segments
    263255                minDistanceSq = Double.MAX_VALUE;
    264                 for (Track t : ds.tracks()) {
     256                for (Track t : Main.main.ds.tracks()) {
    265257                        for (LineSegment ls : t.segments()) {
    266258                                Point A = getScreenPoint(ls.getStart().coor);
     
    375367       
    376368        /**
    377          * Return the dataSet for the current selected layer. If the active layer
    378          * does not have a dataset, return the DataSet from the next layer a.s.o.
    379          * 
    380          * @return The DataSet of the current active layer.
    381          */
    382         public DataSet getActiveDataSet() {
    383                 if (activeLayer.dataSet != null)
    384                         return activeLayer.dataSet;
    385                 for (Layer l : layers)
    386                         if (l.dataSet != null)
    387                                 return l.dataSet;
    388                 throw new IllegalStateException("No dataset found.");
    389         }
    390 
    391         /**
    392369         * Change to the new projection. Recalculate the dataset and zoom, if autoZoom
    393370         * is active.
     
    422399                                h = 20;
    423400                       
    424                         Bounds bounds = getActiveDataSet().getBoundsXY();
     401                        Bounds bounds = Main.main.ds.getBoundsXY();
    425402                       
    426403                        boolean oldAutoScale = autoScale;
  • src/org/openstreetmap/josm/gui/PreferenceDialog.java

    r21 r22  
    9191         * Indicate, that the application has to be restarted for the settings to take effect.
    9292         */
    93         private boolean requiresRestart = false;
     93        boolean requiresRestart = false;
    9494        /**
    9595         * ComboBox with all look and feels.
    9696         */
    97         private JComboBox lafCombo = new JComboBox(UIManager.getInstalledLookAndFeels());
     97        JComboBox lafCombo = new JComboBox(UIManager.getInstalledLookAndFeels());
    9898        /**
    9999         * Combobox with all projections available
    100100         */
    101         private JComboBox projectionCombo = new JComboBox(Preferences.allProjections.clone());
     101        JComboBox projectionCombo = new JComboBox(Preferences.allProjections.clone());
    102102        /**
    103103         * The main tab panel.
     
    108108         * Editfield for the Base url to the REST API from OSM.
    109109         */
    110         private JTextField osmDataServer = new JTextField(20);
     110        JTextField osmDataServer = new JTextField(20);
    111111        /**
    112112         * Editfield for the username to the OSM account.
    113113         */
    114         private JTextField osmDataUsername = new JTextField(20);
     114        JTextField osmDataUsername = new JTextField(20);
    115115        /**
    116116         * Passwordfield for the userpassword of the REST API.
    117117         */
    118         private JPasswordField osmDataPassword = new JPasswordField(20);
     118        JPasswordField osmDataPassword = new JPasswordField(20);
    119119        /**
    120120         * The checkbox stating whether nodes should be merged together.
    121121         */
    122         private JCheckBox drawRawGpsLines = new JCheckBox("Draw lines between raw gps points.");
     122        JCheckBox drawRawGpsLines = new JCheckBox("Draw lines between raw gps points.");
    123123        /**
    124124         * The checkbox stating whether raw gps lines should be forced.
    125125         */
    126         private JCheckBox forceRawGpsLines = new JCheckBox("Force lines if no line segments imported.");
     126        JCheckBox forceRawGpsLines = new JCheckBox("Force lines if no line segments imported.");
    127127        /**
    128128         * The checkbox stating whether nodes should be merged together.
    129129         */
    130         private JCheckBox mergeNodes = new JCheckBox("Merge nodes with equal latitude/longitude.");
     130        JCheckBox mergeNodes = new JCheckBox("Merge nodes with equal latitude/longitude.");
    131131
    132132        /**
  • src/org/openstreetmap/josm/gui/SelectionManager.java

    r21 r22  
    1515import java.util.LinkedList;
    1616
    17 import org.openstreetmap.josm.command.DataSet;
     17import org.openstreetmap.josm.Main;
    1818import org.openstreetmap.josm.data.osm.LineSegment;
    1919import org.openstreetmap.josm.data.osm.Node;
     
    272272                } else {
    273273                        // nodes
    274                         DataSet ds = mv.getActiveDataSet();
    275                         for (Node n : ds.nodes) {
     274                        for (Node n : Main.main.ds.nodes) {
    276275                                if (r.contains(mv.getScreenPoint(n.coor)))
    277276                                        selection.add(n);
     
    279278                       
    280279                        // pending line segments
    281                         for (LineSegment ls : ds.pendingLineSegments())
     280                        for (LineSegment ls : Main.main.ds.pendingLineSegments())
    282281                                if (rectangleContainLineSegment(r, alt, ls))
    283282                                        selection.add(ls);
    284283
    285284                        // tracks
    286                         for (Track t : ds.tracks()) {
     285                        for (Track t : Main.main.ds.tracks()) {
    287286                                boolean wholeTrackSelected = !t.segments().isEmpty();
    288287                                for (LineSegment ls : t.segments())
  • src/org/openstreetmap/josm/gui/dialogs/LayerList.java

    r21 r22  
    88import java.awt.event.ActionListener;
    99import java.awt.event.KeyEvent;
     10import java.io.IOException;
    1011import java.util.Collection;
    1112
     
    1617import javax.swing.JLabel;
    1718import javax.swing.JList;
     19import javax.swing.JOptionPane;
    1820import javax.swing.JPanel;
    1921import javax.swing.JScrollPane;
     
    3032import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
    3133import org.openstreetmap.josm.gui.layer.Layer;
     34import org.openstreetmap.josm.io.OsmWriter;
    3235
    3336/**
     
    4245         * The data model for the list component.
    4346         */
    44         private DefaultListModel model = new DefaultListModel();
     47        DefaultListModel model = new DefaultListModel();
    4548        /**
    4649         * The list component holding all layers.
    4750         */
    48         private JList layers = new JList(model);
     51        JList layers = new JList(model);
    4952        /**
    5053         * The invisible icon blended over invisible layers.
    5154         */
    52         private static final Icon invisible = ImageProvider.get("layer", "invisible");
     55        static final Icon invisible = ImageProvider.get("layer", "invisible");
    5356
    5457        /**
     
    6972         */
    7073        private JButton deleteButton = new JButton(ImageProvider.get("dialogs", "delete"));
    71        
     74        /**
     75         * Button for connecting disconnecting to the server.
     76         */
     77        private JButton uploadButton = new JButton(ImageProvider.get("dialogs", "condiscon"));
     78
    7279        /**
    7380         * Create an layerlist and attach it to the given mapView.
     
    8996                                        icon = ImageProvider.overlay(icon, invisible, ImageProvider.OverlayPosition.SOUTHEAST);
    9097                                label.setIcon(icon);
    91                                
     98
    9299                                DataSet ds = layer.dataSet;
    93100                                if (ds != null) {
     
    100107
    101108                final MapView mapView = mapFrame.mapView;
    102                
     109
    103110                Collection<Layer> data = mapView.getAllLayers();
    104111                for (Layer l : data)
     
    115122                });
    116123                mapView.addLayerChangeListener(this);
    117                
     124
    118125                // Buttons
    119126                JPanel buttonPanel = new JPanel(new GridLayout(1, 5));
     
    173180                mergeButton.setToolTipText("Merge the selected layer into the layer directly below.");
    174181                mergeButton.addActionListener(new ActionListener(){
    175                                 public void actionPerformed(ActionEvent e) {
    176                                         Layer lFrom = (Layer)layers.getSelectedValue();
    177                                         DataSet dsFrom = lFrom.dataSet;
    178                                         Layer lTo = (Layer)model.get(layers.getSelectedIndex()+1);
    179                                         DataSet dsTo = lTo.dataSet;
    180                                         dsTo.mergeFrom(dsFrom, Main.pref.mergeNodes);
    181                                         layers.setSelectedValue(lTo, true);
    182                                         mapView.removeLayer(lFrom);
     182                        public void actionPerformed(ActionEvent e) {
     183                                Layer lFrom = (Layer)layers.getSelectedValue();
     184                                DataSet dsFrom = lFrom.dataSet;
     185                                Layer lTo = (Layer)model.get(layers.getSelectedIndex()+1);
     186                                DataSet dsTo = lTo.dataSet;
     187                                dsTo.mergeFrom(dsFrom, Main.pref.mergeNodes);
     188                                layers.setSelectedValue(lTo, true);
     189                                mapView.removeLayer(lFrom);
     190                        }
     191                });             
     192                buttonPanel.add(mergeButton);
     193
     194                uploadButton.setToolTipText("Upload changes to the server.");
     195                uploadButton.addActionListener(new ActionListener(){
     196                        public void actionPerformed(ActionEvent e) {
     197                                OsmWriter con = new OsmWriter(Main.pref.osmDataServer, Main.main.commands);
     198                                try {
     199                                        con.output();
     200                                } catch (IOException x) {
     201                                        x.printStackTrace();
     202                                        JOptionPane.showMessageDialog(Main.main, "Not all changes could be uploaded.");
    183203                                }
    184                         });             
    185                 buttonPanel.add(mergeButton);
    186 
     204                        }
     205                });
     206                buttonPanel.add(uploadButton);
     207               
    187208                add(buttonPanel, BorderLayout.SOUTH);
    188209               
     
    193214         * Updates the state of the Buttons.
    194215         */
    195         private void updateButtonEnabled() {
     216        void updateButtonEnabled() {
    196217                int sel = layers.getSelectedIndex();
    197218                Layer l = (Layer)layers.getSelectedValue();
  • src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java

    r21 r22  
    1717
    1818import org.openstreetmap.josm.Main;
    19 import org.openstreetmap.josm.command.DataSet;
    2019import org.openstreetmap.josm.data.SelectionChangedListener;
    2120import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    2322import org.openstreetmap.josm.gui.ImageProvider;
    2423import org.openstreetmap.josm.gui.MapFrame;
    25 import org.openstreetmap.josm.gui.MapView;
    26 import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
    27 import org.openstreetmap.josm.gui.layer.Layer;
    2824
    2925/**
     
    3430 * @author imi
    3531 */
    36 public class SelectionListDialog extends ToggleDialog implements SelectionChangedListener, LayerChangeListener {
     32public class SelectionListDialog extends ToggleDialog implements SelectionChangedListener {
    3733
    3834        /**
     
    4440         */
    4541        private JList displaylist = new JList(list);
    46         /**
    47          * The dataset, all selections are part of.
    48          */
    49         private final MapView mapView;
    5042       
    5143        /**
     
    5547        public SelectionListDialog(MapFrame mapFrame) {
    5648                super(mapFrame, "Current Selection", "Selection List", "selectionlist", KeyEvent.VK_E, "Open a selection list window.");
    57                 this.mapView = mapFrame.mapView;
    5849                setLayout(new BorderLayout());
    5950                setSize(300,400);
     
    8475                getContentPane().add(button, BorderLayout.SOUTH);
    8576
    86                 selectionChanged(mapView.getActiveDataSet().getSelected());
     77                selectionChanged(Main.main.ds.getSelected());
    8778        }
    8879
     
    9081        public void setVisible(boolean b) {
    9182                if (b) {
    92                         mapView.addLayerChangeListener(this);
    93                         mapView.getActiveDataSet().addSelectionChangedListener(this);
    94                         selectionChanged(mapView.getActiveDataSet().getSelected());
     83                        Main.main.ds.addSelectionChangedListener(this);
     84                        selectionChanged(Main.main.ds.getSelected());
    9585                } else {
    96                         mapView.removeLayerChangeListener(this);
    97                         mapView.getActiveDataSet().removeSelectionChangedListener(this);
     86                        Main.main.ds.removeSelectionChangedListener(this);
    9887                }
    9988                super.setVisible(b);
     
    118107         */
    119108        public void updateMap() {
    120                 DataSet ds = mapView.getActiveDataSet();
    121                 ds.clearSelection();
     109                Main.main.ds.clearSelection();
    122110                for (int i = 0; i < list.getSize(); ++i)
    123111                        if (displaylist.isSelectedIndex(i))
    124                                 ((OsmPrimitive)list.get(i)).setSelected(true, ds);
     112                                ((OsmPrimitive)list.get(i)).setSelected(true);
    125113                Main.main.getMapFrame().repaint();
    126114        }
    127 
    128         public void activeLayerChange(Layer oldLayer, Layer newLayer) {
    129                 DataSet ds = oldLayer.dataSet;
    130                 if (ds != null)
    131                         ds.removeSelectionChangedListener(this);
    132                 ds = newLayer.dataSet;
    133                 if (ds != null)
    134                         ds.addSelectionChangedListener(this);
    135         }
    136 
    137         /**
    138          * Does nothing. Only to satisfy LayerChangeListener
    139          */
    140         public void layerAdded(Layer newLayer) {}
    141         /**
    142          * Does nothing. Only to satisfy LayerChangeListener
    143          */
    144         public void layerRemoved(Layer oldLayer) {}
    145115}
  • src/org/openstreetmap/josm/gui/layer/Layer.java

    r21 r22  
    55import javax.swing.Icon;
    66
    7 import org.openstreetmap.josm.command.DataSet;
    8 import org.openstreetmap.josm.data.osm.LineSegment;
    9 import org.openstreetmap.josm.data.osm.Node;
    10 import org.openstreetmap.josm.data.osm.Track;
    117import org.openstreetmap.josm.gui.MapView;
    12 import org.openstreetmap.josm.gui.engine.Engine;
    138
    149/**
     
    3429        public boolean visible = true;
    3530        /**
    36          * The dataSet this layer operates on, if any. Not all layer may have a
    37          * dataset associated.
    38          */
    39         public final DataSet dataSet;
    40         /**
    4131         * The name of this layer.
    4232         */
    4333        public final String name;
    44         /**
    45          * The engine used to draw the data.
    46          */
    47         private final Engine engine;
    4834       
    4935        /**
    5036         * Create the layer and fill in the necessary components.
    51          * @param dataSet The DataSet, this layer operates on. Can be <code>null</code>.
    5237         */
    53         public Layer(DataSet dataSet, Engine engine, String name) {
    54                 if (engine == null || name == null)
    55                         throw new NullPointerException();
    56                 this.dataSet = dataSet;
     38        public Layer(String name) {
    5739                this.name = name;
    58                 this.engine = engine;
    5940        }
    6041
     
    6344         * @param mv The object that can translate GeoPoints to screen coordinates.
    6445         */
    65         public final void paint(Graphics g, MapView mv) {
    66                 engine.init(g, mv);
    67 
    68                 for (Track t : dataSet.tracks())
    69                         engine.drawTrack(t);
    70                 for (LineSegment ls : dataSet.pendingLineSegments())
    71                         engine.drawPendingLineSegment(ls);
    72                 for (Node n : dataSet.nodes)
    73                         engine.drawNode(n);
    74         }
    75 
     46        abstract public void paint(Graphics g, MapView mv);
    7647        /**
    7748         * Return a representative small image for this layer. The image must not
  • src/org/openstreetmap/josm/gui/layer/LayerFactory.java

    r21 r22  
    1919         */
    2020        public static Layer create(DataSet dataSet, String name, boolean rawGps) {
    21                 Layer layer = rawGps ? new RawGpsDataLayer(dataSet, name) : new OsmDataLayer(dataSet, name);
     21                Layer layer = rawGps ? new RawGpsDataLayer(dataSet, name) : new OsmDataLayer(name);
    2222                return layer;
    2323        }
  • src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r21 r22  
    11package org.openstreetmap.josm.gui.layer;
     2
     3import java.awt.Color;
     4import java.awt.Graphics;
     5import java.awt.Point;
     6import java.util.Collection;
     7import java.util.HashSet;
    28
    39import javax.swing.Icon;
    410
    5 import org.openstreetmap.josm.command.DataSet;
     11import org.openstreetmap.josm.Main;
     12import org.openstreetmap.josm.data.osm.Key;
     13import org.openstreetmap.josm.data.osm.LineSegment;
     14import org.openstreetmap.josm.data.osm.Node;
     15import org.openstreetmap.josm.data.osm.OsmPrimitive;
     16import org.openstreetmap.josm.data.osm.Track;
     17import org.openstreetmap.josm.data.osm.visitor.Visitor;
    618import org.openstreetmap.josm.gui.ImageProvider;
    7 import org.openstreetmap.josm.gui.engine.SimpleEngine;
     19import org.openstreetmap.josm.gui.MapView;
    820
    921/**
     
    1426 * @author imi
    1527 */
    16 public class OsmDataLayer extends Layer {
     28public class OsmDataLayer extends Layer implements Visitor {
    1729
    1830        private static Icon icon;
     31        private final static Color darkblue = new Color(0,0,128);
     32        private final static Color darkgreen = new Color(0,128,0);
     33
     34        /**
     35         * The data behind this layer. A list of primitives which are also in Main.main.ds.
     36         */
     37        private final Collection<OsmPrimitive> data;
     38
     39        /**
     40         * The mapview we are currently drawing on.
     41         */
     42        private MapView mv;
     43        /**
     44         * The graphic environment we are drawing with.
     45         */
     46        private Graphics g;
    1947       
    2048        /**
    2149         * Construct a OsmDataLayer.
    2250         */
    23         protected OsmDataLayer(DataSet dataSet, String name) {
    24                 super(dataSet, new SimpleEngine(), name);
     51        protected OsmDataLayer(Collection<OsmPrimitive> data, String name) {
     52                super(name);
     53                this.data = data;
    2554        }
    2655
     
    4069                return true;
    4170        }
     71
     72        @Override
     73        public void paint(Graphics g, MapView mv) {
     74                this.mv = mv;
     75                this.g = g;
     76                for (OsmPrimitive osm : data)
     77                        osm.visit(this);
     78        }
     79
     80        /**
     81         * Draw a small rectangle.
     82         *
     83         * - White if selected (as always)
     84         * - Yellow, if not used by any tracks or areas.
     85         * - Green, if only used by pending line segments.
     86         * - Darkblue, if used in tracks but are only as inbound node. Inbound are
     87         *   all nodes, that have only line segments of the same track and
     88         *   at least two different line segments attached.
     89         * - Red otherwise (means, this is a dead end or is part of more than
     90         *   one track).
     91         *
     92         * @param n The node to draw.
     93         */
     94        public void visit(Node n) {
     95                if (n.isSelected()) {
     96                        drawNode(n, Color.WHITE); // selected
     97                        return;
     98                }
     99
     100                Collection<LineSegment> lineSegments = n.getParentSegments();
     101                if (lineSegments.isEmpty()) {
     102                        drawNode(n, Color.YELLOW); // single waypoint only
     103                        return;
     104                }
     105               
     106                HashSet<Track> tracks = new HashSet<Track>();
     107                for (LineSegment ls : lineSegments)
     108                        tracks.addAll(ls.getParents());
     109                if (tracks.isEmpty()) {
     110                        drawNode(n, Color.GREEN); // pending line
     111                        return;
     112                }
     113                if (tracks.size() > 1) {
     114                        drawNode(n, Color.RED); // more than one track
     115                        return;
     116                }
     117                int segmentUsed = 0;
     118                for (LineSegment ls : tracks.iterator().next().segments())
     119                        if (n == ls.getStart() || n == ls.getEnd())
     120                                ++segmentUsed;
     121                drawNode(n, segmentUsed > 1 ? darkblue : Color.RED);
     122        }
     123
     124        public void visit(LineSegment ls) {
     125                g.setColor(ls.isSelected() ? Color.WHITE : darkblue);
     126                if (Main.main.ds.pendingLineSegments().contains(ls))
     127                        g.setColor(darkgreen);
     128                Point p1 = mv.getScreenPoint(ls.getStart().coor);
     129                Point p2 = mv.getScreenPoint(ls.getEnd().coor);
     130                g.drawLine(p1.x, p1.y, p2.x, p2.y);
     131        }
     132
     133        /**
     134         * Draw a darkblue line for all line segments.
     135         * @param t The track to draw.
     136         */
     137        public void visit(Track t) {
     138                for (LineSegment ls : t.segments())
     139                        ls.visit(this);
     140        }
     141
     142        public void visit(Key k) {
     143        }
     144       
     145        /**
     146         * Draw the node as small rectangle with the given color.
     147         *
     148         * @param n             The node to draw.
     149         * @param color The color of the node.
     150         */
     151        private void drawNode(Node n, Color color) {
     152                Point p = mv.getScreenPoint(n.coor);
     153                g.setColor(color);
     154                g.drawRect(p.x-1, p.y-1, 2, 2);
     155        }
    42156}
  • src/org/openstreetmap/josm/gui/layer/RawGpsDataLayer.java

    r21 r22  
    55import org.openstreetmap.josm.command.DataSet;
    66import org.openstreetmap.josm.gui.ImageProvider;
    7 import org.openstreetmap.josm.gui.engine.RawGpsEngine;
    87
    98/**
     
    1817
    1918        protected RawGpsDataLayer(DataSet dataSet, String name) {
    20                 super(dataSet, new RawGpsEngine(), name);
     19                super(name);
    2120        }
    2221
Note: See TracChangeset for help on using the changeset viewer.