Changeset 98 in josm for src


Ignore:
Timestamp:
2006-04-25T00:11:38+02:00 (18 years ago)
Author:
imi
Message:
  • added Applet version of JOSM (unfinished)
  • fixed display bug if --no-fullscreen and --geometry was specified
Location:
src/org/openstreetmap/josm
Files:
3 added
1 deleted
40 edited

Legend:

Unmodified
Added
Removed
  • src/org/openstreetmap/josm/Main.java

    r94 r98  
    1 //Licence: GPL
    21package org.openstreetmap.josm;
    32
    43import java.awt.BorderLayout;
     4import java.awt.Component;
    55import java.awt.Dimension;
    6 import java.awt.Point;
     6import java.awt.Rectangle;
    77import java.awt.Toolkit;
    8 import java.awt.event.WindowAdapter;
    9 import java.awt.event.WindowEvent;
    108import java.io.File;
    119import java.io.IOException;
    12 import java.util.Arrays;
    13 import java.util.LinkedList;
     10import java.net.URI;
     11import java.net.URISyntaxException;
     12import java.util.Collection;
     13import java.util.Map;
    1414import java.util.StringTokenizer;
    1515import java.util.concurrent.Executor;
     
    1919
    2020import javax.swing.Action;
    21 import javax.swing.JFrame;
    2221import javax.swing.JMenu;
    2322import javax.swing.JMenuBar;
     
    4443import org.openstreetmap.josm.data.projection.Projection;
    4544import org.openstreetmap.josm.gui.MapFrame;
    46 import org.openstreetmap.josm.gui.ShowModifiers;
     45import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
    4746import org.openstreetmap.josm.gui.dialogs.SelectionListDialog;
    4847import org.openstreetmap.josm.gui.layer.Layer;
    4948import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    50 import org.openstreetmap.josm.tools.BugReportExceptionHandler;
     49import org.openstreetmap.josm.gui.layer.OsmDataLayer.CommandQueueListener;
    5150import org.openstreetmap.josm.tools.ImageProvider;
    5251
    53 /**
    54  * Main window class application.
    55  * 
    56  * @author imi
    57  */
    58 public class Main extends JFrame {
    59 
     52abstract public class Main {
     53        /**
     54         * Global parent component for all dialogs and message boxes
     55         */
     56        public static Component parent;
    6057        /**
    6158         * Global application window. Use this as JOPtionPane-parent to center on application.
    6259         */
    6360        public static Main main;
    64 
    6561        /**
    6662         * The worker thread slave. This is for executing all long and intensive
     
    6864         * and sequenciel.
    6965         */
    70         public static Executor worker = Executors.newSingleThreadExecutor();
    71 
    72 
     66        public final static Executor worker = Executors.newSingleThreadExecutor();
     67        /**
     68         * Global application preferences
     69         */
     70        public static Preferences pref = new Preferences();
     71        /**
     72         * The global dataset.
     73         */
     74        public static DataSet ds = new DataSet();
     75        /**
     76         * The projection method used.
     77         */
    7378        public static Projection proj;
    74 
    75         /**
    76          * Global application preferences
    77          */
    78         public final static Preferences pref = new Preferences();
    79 
    80         /**
    81          * The global dataset.
    82          */
    83         public static DataSet ds = new DataSet();
    84 
    85         /**
    86          * The main panel.
    87          */
    88         public JPanel panel;
    89         /**
    90          * The mapFrame currently loaded.
    91          */
    92         private MapFrame mapFrame;
    93 
    94         public final UndoAction undoAction;
    95         public final RedoAction redoAction;
    96 
    97         private OpenAction openAction;
    98         private DownloadAction downloadAction;
    99         //private Action wmsServerAction;
    100 
    101         /**
    102          * Construct an main frame, ready sized and operating. Does not
    103          * display the frame.
    104          */
     79        /**
     80         * The MapFrame. Use setMapFrame to set or clear it.
     81         */
     82        public static MapFrame map;
     83
     84        /**
     85         * Set or clear (if passed <code>null</code>) the map.
     86         */
     87        public final void setMapFrame(final MapFrame map) {
     88                Main.map = map;
     89                panel.setVisible(false);
     90                panel.removeAll();
     91                if (map != null) {
     92                        map.fillPanel(panel);
     93                        panel.setVisible(true);
     94                        map.mapView.addLayerChangeListener(new LayerChangeListener(){
     95                                public void activeLayerChange(final Layer oldLayer, final Layer newLayer) {}
     96                                public void layerAdded(final Layer newLayer) {
     97                                        if (newLayer instanceof OsmDataLayer)
     98                                                Main.main.editLayer().listenerCommands.add(redoUndoListener);
     99                                }
     100                                public void layerRemoved(final Layer oldLayer) {}
     101                        });
     102                }
     103                redoUndoListener.commandChanged(0,0);
     104        }
     105
     106        /**
     107         * Remove the specified layer from the map. If it is the last layer, remove the map as well.
     108         */
     109        public final void removeLayer(final Layer layer) {
     110                final Collection<Layer> allLayers = map.mapView.getAllLayers();
     111                if (allLayers.size() == 1 && allLayers.iterator().next() == layer) {
     112                        Main.map.setVisible(false);
     113                        setMapFrame(null);
     114                        ds = new DataSet();
     115                } else {
     116                        map.mapView.removeLayer(layer);
     117                        if (layer instanceof OsmDataLayer)
     118                                ds = new DataSet();
     119                }
     120        }
    105121        public Main() {
    106                 super("Java Open Street Map - Editor");
    107                 Main.main = this;
    108                 setLayout(new BorderLayout());
    109                 panel = new JPanel(new BorderLayout());
    110                 getContentPane().add(panel, BorderLayout.CENTER);
    111                 setSize(1000,740); // some strange default size
    112 
    113                 downloadAction = new DownloadAction();
    114                 Action uploadAction = new UploadAction();
    115                 //wmsServerAction = new WmsServerAction();
    116                 openAction = new OpenAction();
    117                 Action saveAction = new SaveAction();
    118                 Action gpxExportAction = new GpxExportAction(null);
    119                 Action exitAction = new ExitAction();
    120                 undoAction = new UndoAction();
    121                 redoAction = new RedoAction();
    122                 Action preferencesAction = new PreferencesAction();
    123                 Action aboutAction = new AboutAction();
    124 
    125                 // creating menu
    126                 JMenuBar mainMenu = new JMenuBar();
    127                 setJMenuBar(mainMenu);
    128 
    129                 JMenu fileMenu = new JMenu("Files");
     122                main = this;
     123                contentPane.add(panel, BorderLayout.CENTER);
     124
     125                final Action uploadAction = new UploadAction();
     126                final Action saveAction = new SaveAction();
     127                final Action gpxExportAction = new GpxExportAction(null);
     128                final Action exitAction = new ExitAction();
     129                final Action preferencesAction = new PreferencesAction();
     130                final Action aboutAction = new AboutAction();
     131
     132                final JMenu fileMenu = new JMenu("Files");
    130133                fileMenu.setMnemonic('F');
    131134                fileMenu.add(openAction);
     
    137140
    138141
    139                 JMenu layerMenu = new JMenu("Layer");
     142                final JMenu layerMenu = new JMenu("Layer");
    140143                layerMenu.setMnemonic('L');
    141144                layerMenu.add(downloadAction);
    142145                layerMenu.add(uploadAction);
    143146                layerMenu.addSeparator();
    144                 //layerMenu.add(new JCheckBoxMenuItem(wmsServerAction));
    145147                mainMenu.add(layerMenu);
    146148
    147                 JMenu editMenu = new JMenu("Edit");
     149                final JMenu editMenu = new JMenu("Edit");
    148150                editMenu.setMnemonic('E');
    149151                editMenu.add(undoAction);
     
    154156
    155157                mainMenu.add(new JSeparator());
    156                 JMenu helpMenu = new JMenu("Help");
     158                final JMenu helpMenu = new JMenu("Help");
    157159                helpMenu.setMnemonic('H');
    158160                helpMenu.add(aboutAction);
     
    160162
    161163                // creating toolbar
    162                 JToolBar toolBar = new JToolBar();
     164                final JToolBar toolBar = new JToolBar();
    163165                toolBar.setFloatable(false);
    164166                toolBar.add(downloadAction);
    165167                toolBar.add(uploadAction);
    166                 //toolBar.add(new IconToggleButton(wmsServerAction));
    167168                toolBar.addSeparator();
    168169                toolBar.add(openAction);
     
    174175                toolBar.addSeparator();
    175176                toolBar.add(preferencesAction);
    176 
    177                 getContentPane().add(toolBar, BorderLayout.NORTH);
    178 
    179                 addWindowListener(new WindowAdapter(){
    180                         @Override public void windowClosing(WindowEvent arg0) {
    181                                 if (mapFrame != null) {
    182                                         boolean modified = false;
    183                                         boolean uploadedModified = false;
    184                                         for (Layer l : mapFrame.mapView.getAllLayers()) {
    185                                                 if (l instanceof OsmDataLayer && ((OsmDataLayer)l).isModified()) {
    186                                                         modified = true;
    187                                                         uploadedModified = ((OsmDataLayer)l).uploadedModified;
    188                                                         break;
    189                                                 }
    190                                         }
    191                                         if (modified) {
    192                                                 String msg = uploadedModified ? "\nHint: Some changes came from uploading new data to the server." : "";
    193                                                 int answer = JOptionPane.showConfirmDialog(
    194                                                                 Main.this, "There are unsaved changes. Really quit?"+msg,
    195                                                                 "Unsaved Changes", JOptionPane.YES_NO_OPTION);
    196                                                 if (answer != JOptionPane.YES_OPTION)
    197                                                         return;
    198                                         }
    199                                 }
    200                                 System.exit(0);
    201                         }
    202                 });
    203                 setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    204         }
    205 
    206         /**
    207          * Main application Startup
    208          * @param args  No parameters accepted.
    209          */
    210         public static void main(String[] args) {
    211                 setupExceptionHandler();
    212                 setupUiDefaults();
    213 
    214                 LinkedList<String> arguments = new LinkedList<String>(Arrays.asList(args));
    215 
    216                 if (arguments.contains("--help") || arguments.contains("-?") || arguments.contains("-h")) {
    217                         System.out.println("Java OpenStreetMap Editor");
    218                         System.out.println();
    219                         System.out.println("usage:");
    220                         System.out.println("\tjava -jar josm.jar <option> <option> <option>...");
    221                         System.out.println();
    222                         System.out.println("options:");
    223                         System.out.println("\t--help|-?|-h                              Show this help");
    224                         System.out.println("\t--geometry=widthxheight(+|-)x(+|-)y       Standard unix geometry argument");
    225                         System.out.println("\t--download=minlat,minlon,maxlat,maxlon    Download the bounding box");
    226                         System.out.println("\t--downloadgps=minlat,minlon,maxlat,maxlon Download the bounding box");
    227                         System.out.println("\t--selection=<searchstring>                Select with the given search");
    228                         System.out.println("\t--no-fullscreen                           Don't launch in fullscreen mode");
    229                         System.out.println("\t--reset-preferences                       Reset the preferences to default");
    230                         System.out.println("\tURL|filename(.osm|.xml|.gpx|.txt|.csv)    Open file / Download url");
    231                         System.out.println();
    232                         System.out.println("examples:");
    233                         System.out.println("\tjava -jar josm.jar track1.gpx track2.gpx london.osm");
    234                         System.out.println("\tjava -jar josm.jar http://www.openstreetmap.org/index.html?lat=43.2&lon=11.1&zoom=13");
    235                         System.out.println("\tjava -jar josm.jar london.osm --selection=http://www.ostertag.name/osm/OSM_errors_node-duplicate.xml");
    236                         System.out.println("\tjava -jar josm.jar osm://43.2,11.1,43.4,11.4");
    237                         System.out.println();
    238                         System.out.println("Parameters are read in the order they are specified, so make sure you load");
    239                         System.out.println("some data before --selection");
    240                         System.out.println();
    241                         System.out.println("Instead of --download=<bbox> you may specify osm://<bbox>");
    242                         System.exit(0);
    243                 }
    244 
    245                 File prefDir = new File(Preferences.getPreferencesDir());
    246                 if (prefDir.exists() && !prefDir.isDirectory()) {
    247                         JOptionPane.showMessageDialog(null, "Cannot open preferences directory: "+Preferences.getPreferencesDir());
    248                         return;
    249                 }
    250                 if (!prefDir.exists())
    251                         prefDir.mkdirs();
    252 
     177                contentPane.add(toolBar, BorderLayout.NORTH);
     178
     179                contentPane.updateUI();
     180        }
     181        /**
     182         * Add a new layer to the map. If no map exist, create one.
     183         */
     184        public final void addLayer(final Layer layer) {
     185                if (map == null) {
     186                        final MapFrame mapFrame = new MapFrame(layer);
     187                        setMapFrame(mapFrame);
     188                        mapFrame.setVisible(true);
     189                        mapFrame.setVisibleDialogs();
     190                } else
     191                        map.mapView.addLayer(layer);
     192        }
     193        /**
     194         * @return The edit osm layer. If none exist, it will be created.
     195         */
     196        public final OsmDataLayer editLayer() {
     197                if (map == null || map.mapView.editLayer == null)
     198                        addLayer(new OsmDataLayer(ds, "unnamed", false));
     199                return map.mapView.editLayer;
     200        }
     201
     202
     203
     204
     205        /**
     206         * Use this to register shortcuts to
     207         */
     208        public static JPanel panel = new JPanel(new BorderLayout());
     209
     210
     211        ////////////////////////////////////////////////////////////////////////////////////////
     212        //  Implementation part
     213        ////////////////////////////////////////////////////////////////////////////////////////
     214
     215
     216        protected final JMenuBar mainMenu = new JMenuBar();
     217        protected static final JPanel contentPane = new JPanel(new BorderLayout());
     218        protected static Rectangle bounds;
     219
     220        private final UndoAction undoAction = new UndoAction();
     221        private final RedoAction redoAction = new RedoAction();
     222        private final OpenAction openAction = new OpenAction();
     223        private final DownloadAction downloadAction = new DownloadAction();
     224
     225        private final CommandQueueListener redoUndoListener = new CommandQueueListener(){
     226                public void commandChanged(final int queueSize, final int redoSize) {
     227                        undoAction.setEnabled(queueSize > 0);
     228                        redoAction.setEnabled(redoSize > 0);
     229                }
     230        };
     231
     232        /**
     233         * Should be called before the main constructor to setup some parameter stuff
     234         * @param args The parsed argument list.
     235         */
     236        public static void preConstructorInit(Map<String, Collection<String>> args) {
    253237                // load preferences
    254238                String errMsg = null;
    255239                try {
    256                         if (arguments.remove("--reset-preferences")) {
    257                                 pref.resetToDefault();
     240                        if (args.containsKey("reset-preferences")) {
     241                                Main.pref.resetToDefault();
    258242                        } else
    259                                 pref.load();
    260                 } catch (IOException e1) {
     243                                Main.pref.load();
     244                } catch (final IOException e1) {
    261245                        e1.printStackTrace();
    262                         errMsg = "Preferences could not be loaded. Write default preference file to '"+Preferences.getPreferencesDir()+"preferences'.";
    263                         pref.resetToDefault();
     246                        errMsg = "Preferences could not be loaded. Write default preference file to '"+pref.getPreferencesDir()+"preferences'.";
     247                        Main.pref.resetToDefault();
    264248                }
    265249                if (errMsg != null)
     
    267251
    268252                try {
    269                         proj = (Projection)Class.forName(pref.get("projection")).newInstance();
    270                 } catch (Exception e) {
     253                        Main.proj = (Projection)Class.forName(Main.pref.get("projection")).newInstance();
     254                } catch (final Exception e) {
    271255                        e.printStackTrace();
    272256                        JOptionPane.showMessageDialog(null, "The projection could not be read from preferences. Using EPSG:4263.");
    273                         proj = new Epsg4326();
     257                        Main.proj = new Epsg4326();
    274258                }
    275259
    276260                try {
    277                         UIManager.setLookAndFeel(pref.get("laf"));
    278                 } catch (Exception e) {
     261                        UIManager.setLookAndFeel(Main.pref.get("laf"));
     262                        contentPane.updateUI();
     263                        panel.updateUI();
     264                } catch (final Exception e) {
    279265                        e.printStackTrace();
    280266                }
    281 
    282                 new Main();
    283                 main.setVisible(true);
    284 
    285                 if (!arguments.remove("--no-fullscreen")) {
    286                         if (Toolkit.getDefaultToolkit().isFrameStateSupported(MAXIMIZED_BOTH))
    287                                 main.setExtendedState(MAXIMIZED_BOTH); // some platform are able to maximize
    288                         else {
    289                                 Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    290                                 main.setSize(d);
    291                         }
    292                 }
    293 
    294                 boolean showModifiers = false;
    295 
    296                 for (String s : arguments) {
    297                         if (s.startsWith("--download=") || s.startsWith("osm:")) {
    298                                 downloadFromParamString(false, s);
    299                         } else if (s.startsWith("--downloadgps=")) {
    300                                 downloadFromParamString(true, s);
    301                         } else if (s.startsWith("--geometry=")) {
    302                                 Matcher m = Pattern.compile("(\\d+)x(\\d+)(([+-])(\\d+)([+-])(\\d+))?").matcher(s.substring(11));
    303                                 if (m.matches()) {
    304                                         main.setExtendedState(NORMAL);
    305                                         Integer w = Integer.valueOf(m.group(1));
    306                                         Integer h = Integer.valueOf(m.group(2));
    307                                         main.setSize(w, h);
    308                                         if (m.group(3) != null) {
    309                                                 int x = Integer.valueOf(m.group(5));
    310                                                 int y = Integer.valueOf(m.group(7));
    311                                                 if (m.group(4).equals("-"))
    312                                                         x = Toolkit.getDefaultToolkit().getScreenSize().width - x - w;
    313                                                 if (m.group(6).equals("-"))
    314                                                         y = Toolkit.getDefaultToolkit().getScreenSize().height - y - h;
    315                                                 main.setLocation(x,y);
    316                                         }
    317                                 } else
    318                                         System.out.println("Ignoring malformed geometry: "+s.substring(11));
    319                         } else if (s.equals("--show-modifiers")) {
    320                                 showModifiers = true;
    321                         } else if (s.startsWith("--selection=")) {
    322                                 SelectionListDialog.search(s.substring(12), SelectionListDialog.SearchMode.add);
    323                         } else if (s.startsWith("http:")) {
    324                                 Bounds b = DownloadAction.osmurl2bounds(s);
    325                                 if (b == null)
    326                                         JOptionPane.showMessageDialog(main, "Ignoring malformed url: "+s);
    327                                 else
    328                                         main.downloadAction.download(false, b.min.lat(), b.min.lon(), b.max.lat(), b.max.lon());
    329                         } else {
    330                                 main.openAction.openFile(new File(s));
    331                         }
    332                 }
    333 
    334                 if (showModifiers) {
    335                         Point p = main.getLocationOnScreen();
    336                         Dimension s = main.getSize();
    337                         new ShowModifiers(p.x + s.width - 3, p.y + s.height - 32);
    338                         main.setVisible(true);
    339                 }
    340         }
    341 
    342 
    343         private static void downloadFromParamString(boolean rawGps, String s) {
    344                 s = s.replaceAll("^(osm:/?/?)|(--download(gps)?=)", "");
    345                 StringTokenizer st = new StringTokenizer(s, ",");
    346                 if (st.countTokens() != 4) {
    347                         JOptionPane.showMessageDialog(main, "Malformed bounding box: "+s);
    348                         return;
    349                 }
    350 
    351                 try {
    352                         main.downloadAction.download(rawGps, Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()));
    353                 } catch (NumberFormatException e) {
    354                         JOptionPane.showMessageDialog(main, "Could not parse the Coordinates: "+s);
    355                 }
    356         }
    357 
    358         //TODO: should be solved better.
    359         public void setMapFrame(MapFrame mapFrame) {
    360                 if (this.mapFrame != null)
    361                         this.mapFrame.setVisible(false);
    362                 this.mapFrame = mapFrame;
    363                 panel.setVisible(false);
    364                 panel.removeAll();
    365                 if (mapFrame != null) {
    366                         mapFrame.fillPanel(panel);
    367                         panel.setVisible(true);
    368                         mapFrame.setVisible(true);
    369                 }
    370         }
    371         /**
    372          * @return Returns the mapFrame.
    373          */
    374         public MapFrame getMapFrame() {
    375                 return mapFrame;
    376         }
    377 
    378 
    379         /**
    380          * Sets some icons to the ui.
    381          */
    382         private static void setupUiDefaults() {
    383267                UIManager.put("OptionPane.okIcon", ImageProvider.get("ok"));
    384268                UIManager.put("OptionPane.yesIcon", UIManager.get("OptionPane.okIcon"));
    385269                UIManager.put("OptionPane.cancelIcon", ImageProvider.get("cancel"));
    386270                UIManager.put("OptionPane.noIcon", UIManager.get("OptionPane.cancelIcon"));
    387         }
    388 
    389         /**
    390          * Setup an exception handler that displays a sorry message and the possibility
    391          * to do a bug report.
    392          */
    393         private static void setupExceptionHandler() {
    394                 Thread.setDefaultUncaughtExceptionHandler(new BugReportExceptionHandler());
     271
     272                Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize();
     273                if (args.containsKey("geometry")) {
     274                        String geometry = args.get("geometry").iterator().next();
     275                        final Matcher m = Pattern.compile("(\\d+)x(\\d+)(([+-])(\\d+)([+-])(\\d+))?").matcher(geometry);
     276                        if (m.matches()) {
     277                                int w = Integer.valueOf(m.group(1));
     278                                int h = Integer.valueOf(m.group(2));
     279                                int x = 0, y = 0;
     280                                if (m.group(3) != null) {
     281                                        x = Integer.valueOf(m.group(5));
     282                                        y = Integer.valueOf(m.group(7));
     283                                        if (m.group(4).equals("-"))
     284                                                x = screenDimension.width - x - w;
     285                                        if (m.group(6).equals("-"))
     286                                                y = screenDimension.height - y - h;
     287                                }
     288                                bounds = new Rectangle(x,y,w,h);
     289                        } else
     290                                System.out.println("Ignoring malformed geometry: "+geometry);
     291                }
     292                if (bounds == null)
     293                        bounds = !args.containsKey("no-fullscreen") ? new Rectangle(0,0,screenDimension.width,screenDimension.height) : new Rectangle(1000,740);
     294        }
     295
     296        public void postConstructorProcessCmdLine(Map<String, Collection<String>> args) {
     297                if (args.containsKey("download"))
     298                        for (String s : args.get("download"))
     299                                downloadFromParamString(false, s);
     300                if (args.containsKey("downloadgps"))
     301                        for (String s : args.get("downloadgps"))
     302                                downloadFromParamString(true, s);
     303                if (args.containsKey("selection"))
     304                        for (String s : args.get("selection"))
     305                                SelectionListDialog.search(s, SelectionListDialog.SearchMode.add);
     306        }
     307
     308        private static void downloadFromParamString(final boolean rawGps, String s) {
     309                if (s.startsWith("http:")) {
     310                        final Bounds b = DownloadAction.osmurl2bounds(s);
     311                        if (b == null)
     312                                JOptionPane.showMessageDialog(Main.parent, "Ignoring malformed url: '"+s+"'");
     313                        else
     314                                main.downloadAction.download(false, b.min.lat(), b.min.lon(), b.max.lat(), b.max.lon());
     315                        return;
     316                }
     317
     318                if (s.startsWith("file:")) {
     319                        try {
     320                                main.openAction.openFile(new File(new URI(s)));
     321                        } catch (URISyntaxException e) {
     322                                JOptionPane.showMessageDialog(Main.parent, "Ignoring malformed file url: '"+s+"'");
     323                        }
     324                        return;
     325                }
     326
     327                final StringTokenizer st = new StringTokenizer(s, ",");
     328                if (st.countTokens() == 4) {
     329                        try {
     330                                main.downloadAction.download(rawGps, Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()));
     331                                return;
     332                        } catch (final NumberFormatException e) {
     333                        }
     334                }
     335
     336                main.openAction.openFile(new File(s));
    395337        }
    396338}
  • src/org/openstreetmap/josm/actions/AboutAction.java

    r71 r98  
    6767                about.setPreferredSize(new Dimension(500,300));
    6868               
    69                 JOptionPane.showMessageDialog(Main.main, about, "About JOSM...",
     69                JOptionPane.showMessageDialog(Main.parent, about, "About JOSM...",
    7070                                JOptionPane.INFORMATION_MESSAGE, ImageProvider.get("logo"));
    7171        }
  • src/org/openstreetmap/josm/actions/DiskAccessAction.java

    r86 r98  
    4444                fc.setAcceptAllFileFilterUsed(true);
    4545       
    46                 int answer = open ? fc.showOpenDialog(Main.main) : fc.showSaveDialog(Main.main);
     46                int answer = open ? fc.showOpenDialog(Main.parent) : fc.showSaveDialog(Main.parent);
    4747                if (answer != JFileChooser.APPROVE_OPTION)
    4848                        return null;
     
    5454                        File file = fc.getSelectedFile();
    5555                        if (file == null || (file.exists() && JOptionPane.YES_OPTION !=
    56                                         JOptionPane.showConfirmDialog(Main.main, "File exists. Overwrite?", "Overwrite", JOptionPane.YES_NO_OPTION)))
     56                                        JOptionPane.showConfirmDialog(Main.parent, "File exists. Overwrite?", "Overwrite", JOptionPane.YES_NO_OPTION)))
    5757                                return null;
    5858                }
  • src/org/openstreetmap/josm/actions/DownloadAction.java

    r95 r98  
    3333import org.openstreetmap.josm.data.osm.DataSet;
    3434import org.openstreetmap.josm.gui.BookmarkList;
    35 import org.openstreetmap.josm.gui.MapFrame;
    3635import org.openstreetmap.josm.gui.MapView;
    3736import org.openstreetmap.josm.gui.PleaseWaitRunnable;
    3837import org.openstreetmap.josm.gui.WorldChooser;
    3938import org.openstreetmap.josm.gui.BookmarkList.Bookmark;
    40 import org.openstreetmap.josm.gui.layer.Layer;
    4139import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    4240import org.openstreetmap.josm.gui.layer.RawGpsDataLayer;
     
    7977                        if (dataSet.nodes.isEmpty())
    8078                                errorMessage = "No data imported.";
    81                         Layer layer = new OsmDataLayer(dataSet, "Data Layer", false);
    82                         if (Main.main.getMapFrame() == null)
    83                                 Main.main.setMapFrame(new MapFrame(layer));
    84                         else
    85                                 Main.main.getMapFrame().mapView.addLayer(layer);
     79                        Main.main.addLayer(new OsmDataLayer(dataSet, "Data Layer", false));
    8680                }
    8781
     
    110104                                return;
    111105                        String name = latlon[0].getText() + " " + latlon[1].getText() + " x " + latlon[2].getText() + " " + latlon[3].getText();
    112                         Layer layer = new RawGpsDataLayer(rawData, name);
    113                         if (Main.main.getMapFrame() == null)
    114                                 Main.main.setMapFrame(new MapFrame(layer));
    115                         else
    116                                 Main.main.getMapFrame().mapView.addLayer(layer);
     106                        Main.main.addLayer(new RawGpsDataLayer(rawData, name));
    117107                }
    118108
     
    145135                //TODO: Remove this in later versions (temporary only)
    146136                if (osmDataServer.endsWith("/0.2") || osmDataServer.endsWith("/0.2/")) {
    147                         int answer = JOptionPane.showConfirmDialog(Main.main,
     137                        int answer = JOptionPane.showConfirmDialog(Main.parent,
    148138                                        "You seem to have an outdated server entry in your preferences.\n" +
    149139                                        "\n" +
     
    175165                dlg.add(new JLabel("max lon"), GBC.std().insets(10,0,5,0));
    176166                dlg.add(latlon[3], GBC.eol());
    177                 if (Main.main.getMapFrame() != null) {
    178                         MapView mv = Main.main.getMapFrame().mapView;
     167                if (Main.map != null) {
     168                        MapView mv = Main.map.mapView;
    179169                        setEditBounds(new Bounds(
    180170                                        mv.getLatLon(0, mv.getHeight()),
     
    260250                                Bookmark b = readBookmark();
    261251                                if (b == null) {
    262                                         JOptionPane.showMessageDialog(Main.main, "Please enter the desired coordinates first.");
     252                                        JOptionPane.showMessageDialog(Main.parent, "Please enter the desired coordinates first.");
    263253                                        return;
    264254                                }
    265                                 b.name = JOptionPane.showInputDialog(Main.main, "Please enter a name for the location.");
     255                                b.name = JOptionPane.showInputDialog(Main.parent, "Please enter a name for the location.");
    266256                                if (b.name != null && !b.name.equals("")) {
    267257                                        ((DefaultListModel)bookmarks.getModel()).addElement(b);
     
    276266                                Object sel = bookmarks.getSelectedValue();
    277267                                if (sel == null) {
    278                                         JOptionPane.showMessageDialog(Main.main, "Select a bookmark first.");
     268                                        JOptionPane.showMessageDialog(Main.parent, "Select a bookmark first.");
    279269                                        return;
    280270                                }
     
    293283                Bookmark b;
    294284                do {
    295                         int r = JOptionPane.showConfirmDialog(Main.main, dlg, "Choose an area",
     285                        int r = JOptionPane.showConfirmDialog(Main.parent, dlg, "Choose an area",
    296286                                        JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
    297287                        if (r != JOptionPane.OK_OPTION)
     
    299289                        b = readBookmark();
    300290                        if (b == null)
    301                                 JOptionPane.showMessageDialog(Main.main, "Please enter the desired coordinates or click on a bookmark.");
     291                                JOptionPane.showMessageDialog(Main.parent, "Please enter the desired coordinates or click on a bookmark.");
    302292                } while (b == null);
    303293
  • src/org/openstreetmap/josm/actions/GpxExportAction.java

    r86 r98  
    4646
    4747        public void actionPerformed(ActionEvent e) {
    48                 if (layer == null && Main.main.getMapFrame() == null) {
    49                         JOptionPane.showMessageDialog(Main.main, "Nothing to export. Get some data first.");
     48                if (layer == null && Main.map == null) {
     49                        JOptionPane.showMessageDialog(Main.parent, "Nothing to export. Get some data first.");
    5050                        return;
    5151                }
     
    102102                p.add(keywords, GBC.eop().fill(GBC.HORIZONTAL));
    103103
    104                 int answer = JOptionPane.showConfirmDialog(Main.main, p, "Export options", JOptionPane.OK_CANCEL_OPTION);
     104                int answer = JOptionPane.showConfirmDialog(Main.parent, p, "Export options", JOptionPane.OK_CANCEL_OPTION);
    105105                if (answer != JOptionPane.OK_OPTION)
    106106                        return;
     
    113113               
    114114                try {
    115                         Layer layer = this.layer == null ? Main.main.getMapFrame().mapView.editLayer() : this.layer;
     115                        Layer layer = this.layer == null ? Main.main.editLayer() : this.layer;
    116116                        FileWriter out = new FileWriter(file);
    117117                        GpxWriter w = new GpxWriter(out, layer.name, desc.getText(),
     
    125125                } catch (IOException x) {
    126126                        x.printStackTrace();
    127                         JOptionPane.showMessageDialog(Main.main, "Error while exporting "+fn+":\n"+x.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
     127                        JOptionPane.showMessageDialog(Main.parent, "Error while exporting "+fn+":\n"+x.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    128128                }               
    129129        }
     
    179179                                l.setVisibleRowCount(4);
    180180                                l.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    181                                 int answer = JOptionPane.showConfirmDialog(Main.main, new JScrollPane(l), "Choose a predefined license", JOptionPane.OK_CANCEL_OPTION);
     181                                int answer = JOptionPane.showConfirmDialog(Main.parent, new JScrollPane(l), "Choose a predefined license", JOptionPane.OK_CANCEL_OPTION);
    182182                                if (answer != JOptionPane.OK_OPTION || l.getSelectedIndex() == -1)
    183183                                        return;
  • src/org/openstreetmap/josm/actions/GroupAction.java

    r94 r98  
    1010import javax.swing.Action;
    1111import javax.swing.Icon;
     12import javax.swing.JComponent;
    1213import javax.swing.JMenuItem;
    1314import javax.swing.JPopupMenu;
    1415import javax.swing.KeyStroke;
    1516
     17import org.openstreetmap.josm.Main;
    1618import org.openstreetmap.josm.gui.IconToggleButton;
    1719import org.openstreetmap.josm.tools.ImageProvider;
     
    4951
    5052        public GroupAction(int shortCut, int modifiers) {
    51                 registerShortCut(getClass().getName(), KeyStroke.getKeyStroke(shortCut, modifiers));
     53                String idName = getClass().getName();
     54                Main.panel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(shortCut, modifiers), idName);
     55        Main.panel.getActionMap().put(idName, this);
    5256                shortCutName = ShortCutLabel.name(shortCut, modifiers);
    5357                addPropertyChangeListener(new PropertyChangeListener(){
  • src/org/openstreetmap/josm/actions/JosmAction.java

    r93 r98  
    3333                super(name, ImageProvider.get(iconName));
    3434                putValue(SHORT_DESCRIPTION, "<html>"+tooltip+" <font size='-2'>"+shortCutName+"</font>&nbsp;</html>");
    35                 registerShortCut(name, shortCut);
     35                Main.panel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(shortCut, name);
     36        Main.panel.getActionMap().put(name, this);
    3637        }
    3738
    3839        public JosmAction() {
    3940        }
    40 
    41         public void registerShortCut(String idName, KeyStroke shortCut) {
    42                 Main.main.panel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(shortCut, idName);
    43                 Main.main.panel.getActionMap().put(idName, this);
    44         }
    4541}
  • src/org/openstreetmap/josm/actions/OpenAction.java

    r79 r98  
    1717import org.openstreetmap.josm.Main;
    1818import org.openstreetmap.josm.data.osm.DataSet;
    19 import org.openstreetmap.josm.gui.MapFrame;
    20 import org.openstreetmap.josm.gui.layer.Layer;
    2119import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    2220import org.openstreetmap.josm.gui.layer.RawGpsDataLayer;
     
    5957                String fn = filename.getName();
    6058                try {
    61                         Layer layer;
    62 
    6359                        if (asRawData(fn)) {
    6460                                Collection<Collection<GpsPoint>> data;
     
    7066                                } else
    7167                                        throw new IllegalStateException();
    72                                 layer = new RawGpsDataLayer(data, filename.getName());
     68                                Main.main.addLayer(new RawGpsDataLayer(data, filename.getName()));
    7369                        } else {
    7470                                DataSet dataSet;
    7571                                if (ExtensionFileFilter.filters[ExtensionFileFilter.GPX].acceptName(fn)) {
    76                                         JOptionPane.showMessageDialog(Main.main, "Warning: Soon, it will be no longer possible to open GPX files as osm data. Please convert your files to .osm format.");
     72                                        JOptionPane.showMessageDialog(Main.parent, "Warning: Soon, it will be no longer possible to open GPX files as osm data. Please convert your files to .osm format.");
    7773                                        dataSet = new GpxReader(new FileReader(filename)).parse();
    7874                                } else if (ExtensionFileFilter.filters[ExtensionFileFilter.OSM].acceptName(fn)) {
     
    8278                                        } catch (SAXException x) {
    8379                                                if (x.getMessage().equals("Unknown version null")) {
    84                                                         int answer = JOptionPane.showConfirmDialog(Main.main,
     80                                                        int answer = JOptionPane.showConfirmDialog(Main.parent,
    8581                                                                        fn+" seems to be an old 0.2 API XML file.\n" +
    8682                                                                        "JOSM can try to open it with the old parser. This option\n" +
     
    9692                                        }                                       
    9793                                } else if (ExtensionFileFilter.filters[ExtensionFileFilter.CSV].acceptName(fn)) {
    98                                         JOptionPane.showMessageDialog(Main.main, fn+": CSV Data import for non-GPS data is not implemented yet.");
     94                                        JOptionPane.showMessageDialog(Main.parent, fn+": CSV Data import for non-GPS data is not implemented yet.");
    9995                                        return;
    10096                                } else {
    101                                         JOptionPane.showMessageDialog(Main.main, fn+": Unknown file extension: "+fn.substring(filename.getName().lastIndexOf('.')+1));
     97                                        JOptionPane.showMessageDialog(Main.parent, fn+": Unknown file extension: "+fn.substring(filename.getName().lastIndexOf('.')+1));
    10298                                        return;
    10399                                }
    104                                 layer = new OsmDataLayer(dataSet, "Data Layer", true);
     100                                Main.main.addLayer(new OsmDataLayer(dataSet, "Data Layer", true));
    105101                        }
    106                        
    107                         if (Main.main.getMapFrame() == null)
    108                                 Main.main.setMapFrame(new MapFrame(layer));
    109                         else
    110                                 Main.main.getMapFrame().mapView.addLayer(layer);
    111 
    112102                } catch (SAXException x) {
    113103                        x.printStackTrace();
    114                         JOptionPane.showMessageDialog(Main.main, "Error while parsing: "+x.getMessage());
     104                        JOptionPane.showMessageDialog(Main.parent, "Error while parsing: "+x.getMessage());
    115105                } catch (JDOMException x) {
    116106                        x.printStackTrace();
    117                         JOptionPane.showMessageDialog(Main.main, "Error while parsing: "+x.getMessage());
     107                        JOptionPane.showMessageDialog(Main.parent, "Error while parsing: "+x.getMessage());
    118108                } catch (IOException x) {
    119109                        x.printStackTrace();
    120                         JOptionPane.showMessageDialog(Main.main, "Could not read '"+fn+"'\n"+x.getMessage());
     110                        JOptionPane.showMessageDialog(Main.parent, "Could not read '"+fn+"'\n"+x.getMessage());
    121111                }
    122112        }
     
    132122                        return false;
    133123                return JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(
    134                                 Main.main, "Do you want to open "+fn+" as raw gps data?",
     124                                Main.parent, "Do you want to open "+fn+" as raw gps data?",
    135125                                "Open as raw data?", JOptionPane.YES_NO_OPTION);
    136126        }
  • src/org/openstreetmap/josm/actions/RedoAction.java

    r68 r98  
    2626
    2727        public void actionPerformed(ActionEvent e) {
    28                 if (Main.main.getMapFrame() == null)
     28                if (Main.map == null)
    2929                        return;
    30                 Main.main.getMapFrame().repaint();
    31                 Main.main.getMapFrame().mapView.editLayer().redo();
     30                Main.map.repaint();
     31                Main.main.editLayer().redo();
    3232        }
    3333}
  • src/org/openstreetmap/josm/actions/SaveAction.java

    r86 r98  
    3535       
    3636        public void actionPerformed(ActionEvent event) {
    37                 if (Main.main.getMapFrame() == null) {
    38                         JOptionPane.showMessageDialog(Main.main, "No document open so nothing to save.");
     37                if (Main.map == null) {
     38                        JOptionPane.showMessageDialog(Main.parent, "No document open so nothing to save.");
    3939                        return;
    4040                }
    41                 if (isDataSetEmpty() && JOptionPane.NO_OPTION == JOptionPane.showConfirmDialog(Main.main, "The document contains no data. Save anyway?", "Empty document", JOptionPane.YES_NO_OPTION))
     41                if (isDataSetEmpty() && JOptionPane.NO_OPTION == JOptionPane.showConfirmDialog(Main.parent, "The document contains no data. Save anyway?", "Empty document", JOptionPane.YES_NO_OPTION))
    4242                        return;
    43                 if (!Main.main.getMapFrame().conflictDialog.conflicts.isEmpty()) {
    44                         int answer = JOptionPane.showConfirmDialog(Main.main,
     43                if (!Main.map.conflictDialog.conflicts.isEmpty()) {
     44                        int answer = JOptionPane.showConfirmDialog(Main.parent,
    4545                                        "There are unresolved conflicts. Conflicts will not be saved and handled as if you rejected all. Continue?", "Conflicts", JOptionPane.YES_NO_OPTION);
    4646                        if (answer != JOptionPane.YES_OPTION)
     
    6868                                for (Segment ls : Main.ds.segments) {
    6969                                        if (ls.incomplete) {
    70                                                 JOptionPane.showMessageDialog(Main.main, "Export of data containing incomplete ways to GPX is not implemented.\nBe aware, that in future versions of JOSM, GPX support will be kept at a minimum.\nPlease use .osm or .xml as extension for the better OSM support.");
     70                                                JOptionPane.showMessageDialog(Main.parent, "Export of data containing incomplete ways to GPX is not implemented.\nBe aware, that in future versions of JOSM, GPX support will be kept at a minimum.\nPlease use .osm or .xml as extension for the better OSM support.");
    7171                                                return;
    7272                                        }
     
    7676                                OsmWriter.output(fileWriter = new FileWriter(file), Main.ds, false);
    7777                        else if (ExtensionFileFilter.filters[ExtensionFileFilter.CSV].acceptName(fn)) {
    78                                 JOptionPane.showMessageDialog(Main.main, "CSV output not supported yet.");
     78                                JOptionPane.showMessageDialog(Main.parent, "CSV output not supported yet.");
    7979                                return;
    8080                        } else {
    81                                 JOptionPane.showMessageDialog(Main.main, "Unknown file extension.");
     81                                JOptionPane.showMessageDialog(Main.parent, "Unknown file extension.");
    8282                                return;
    8383                        }
    8484                        fileWriter.close();
    85                         Main.main.getMapFrame().mapView.editLayer().cleanData(null, false);
     85                        Main.main.editLayer().cleanData(null, false);
    8686                } catch (IOException e) {
    8787                        e.printStackTrace();
    88                         JOptionPane.showMessageDialog(Main.main, "An error occoured while saving.\n"+e.getMessage());
     88                        JOptionPane.showMessageDialog(Main.parent, "An error occoured while saving.\n"+e.getMessage());
    8989                }
    9090        }
  • src/org/openstreetmap/josm/actions/UndoAction.java

    r68 r98  
    2626
    2727        public void actionPerformed(ActionEvent e) {
    28                 if (Main.main.getMapFrame() == null)
     28                if (Main.map == null)
    2929                        return;
    30                 Main.main.getMapFrame().repaint();
    31                 Main.main.getMapFrame().mapView.editLayer().undo();
     30                Main.map.repaint();
     31                Main.main.editLayer().undo();
    3232        }
    3333}
  • src/org/openstreetmap/josm/actions/UploadAction.java

    r92 r98  
    4343                //TODO: Remove this in later versions (temporary only)
    4444                if (osmDataServer.endsWith("/0.2") || osmDataServer.endsWith("/0.2/")) {
    45                         int answer = JOptionPane.showConfirmDialog(Main.main,
     45                        int answer = JOptionPane.showConfirmDialog(Main.parent,
    4646                                        "You seem to have an outdated server entry in your preferences.\n" +
    4747                                        "\n" +
     
    5656                }
    5757
    58                 if (!Main.main.getMapFrame().conflictDialog.conflicts.isEmpty()) {
    59                         JOptionPane.showMessageDialog(Main.main, "There are unresolved conflicts. You have to resolve these first.");
    60                         Main.main.getMapFrame().conflictDialog.action.button.setSelected(true);
    61                         Main.main.getMapFrame().conflictDialog.action.actionPerformed(null);
     58                if (!Main.map.conflictDialog.conflicts.isEmpty()) {
     59                        JOptionPane.showMessageDialog(Main.parent, "There are unresolved conflicts. You have to resolve these first.");
     60                        Main.map.conflictDialog.action.button.setSelected(true);
     61                        Main.map.conflictDialog.action.actionPerformed(null);
    6262                        return;
    6363                }
     
    9090                        }
    9191                        @Override protected void finish() {
    92                                 Main.main.getMapFrame().mapView.editLayer().cleanData(server.processed, !add.isEmpty());
     92                                Main.main.editLayer().cleanData(server.processed, !add.isEmpty());
    9393                        }
    9494                        @Override protected void cancel() {
     
    108108        private boolean displayUploadScreen(Collection<OsmPrimitive> add, Collection<OsmPrimitive> update, Collection<OsmPrimitive> delete) {
    109109                if (add.isEmpty() && update.isEmpty() && delete.isEmpty()) {
    110                         JOptionPane.showMessageDialog(Main.main, "No changes to upload.");
     110                        JOptionPane.showMessageDialog(Main.parent, "No changes to upload.");
    111111                        return false;
    112112                }
     
    140140                }
    141141
    142                 return JOptionPane.showConfirmDialog(Main.main, p, "Upload this changes?",
     142                return JOptionPane.showConfirmDialog(Main.parent, p, "Upload this changes?",
    143143                                JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION;
    144144        }
  • src/org/openstreetmap/josm/actions/WmsServerAction.java

    r93 r98  
    44import java.awt.event.KeyEvent;
    55
    6 import javax.swing.AbstractButton;
    76import javax.swing.JOptionPane;
    87
    98import org.openstreetmap.josm.Main;
    10 import org.openstreetmap.josm.data.osm.DataSet;
    11 import org.openstreetmap.josm.gui.MapFrame;
    12 import org.openstreetmap.josm.gui.MapView;
    13 import org.openstreetmap.josm.gui.layer.Layer;
    14 import org.openstreetmap.josm.gui.layer.WmsServerLayer;
    159
    1610public class WmsServerAction extends JosmAction {
     
    2115
    2216    public void actionPerformed(ActionEvent e) {
    23         JOptionPane.showMessageDialog(Main.main, "Not implemented yet.");
    24         if (1==1) return;
    25         MapFrame mapFrame = Main.main.getMapFrame();
    26         if (!((AbstractButton)e.getSource()).isSelected()) {
    27             if (mapFrame != null) {
    28                 MapView mv = mapFrame.mapView;
    29                 for (Layer l : mv.getAllLayers()) {
    30                     if (l instanceof WmsServerLayer) {
    31                         if (mv.getAllLayers().size() == 1) {
    32                             Main.main.setMapFrame(null);
    33                             Main.ds = new DataSet();
    34                         } else
    35                             mv.removeLayer(l);
    36                         return;
    37                     }
    38                 }
    39             }
    40         } else {
    41             WmsServerLayer layer = new WmsServerLayer(Main.pref.get("wms.baseurl", "http://wms.jpl.nasa.gov/wms.cgi?request=GetMap&width=512&height=512&layers=global_mosaic&styles=&srs=EPSG:4326&format=image/jpeg&"));
    42             if (mapFrame == null)
    43                 Main.main.setMapFrame(new MapFrame(layer));
    44             else
    45                 mapFrame.mapView.addLayer(layer);
    46         }
     17        JOptionPane.showMessageDialog(Main.parent, "Not implemented yet.");
    4718    }
    4819}
  • src/org/openstreetmap/josm/actions/mapmode/AddNodeAction.java

    r94 r98  
    55import java.util.ArrayList;
    66import java.util.Collection;
     7import java.util.HashMap;
    78import java.util.LinkedList;
    89
     
    5152        @Override public void enterMode() {
    5253                super.enterMode();
    53                 mv.addMouseListener(this);
     54                Main.map.mapView.addMouseListener(this);
    5455        }
    5556
    5657        @Override public void exitMode() {
    5758                super.exitMode();
    58                 mv.removeMouseListener(this);
     59                Main.map.mapView.removeMouseListener(this);
    5960        }
    6061
     
    7172                        return;
    7273
    73                 Node n = new Node(mv.getLatLon(e.getX(), e.getY()));
     74                Node n = new Node(Main.map.mapView.getLatLon(e.getX(), e.getY()));
    7475                if (n.coor.isOutSideWorld()) {
    75                         JOptionPane.showMessageDialog(Main.main, "Can not add a node outside of the world.");
     76                        JOptionPane.showMessageDialog(Main.parent, "Can not add a node outside of the world.");
    7677                        return;
    7778                }
     
    7980                Command c = new AddCommand(n);
    8081                if (mode == Mode.nodesegment) {
    81                         Segment s = mv.getNearestSegment(e.getPoint());
     82                        Segment s = Main.map.mapView.getNearestSegment(e.getPoint());
    8283                        if (s == null)
    8384                                return;
     
    8990                        Segment s2 = new Segment(s.from, s.to);
    9091                        s2.from = n;
     92                        if (s.keys != null)
     93                                s2.keys = new HashMap<String, String>(s.keys);
    9194
    9295                        cmds.add(new ChangeCommand(s, s1));
     
    110113                        c = new SequenceCommand(cmds);
    111114                }
    112                 mv.editLayer().add(c);
    113                 mv.repaint();
     115                Main.main.editLayer().add(c);
     116                Main.map.mapView.repaint();
    114117        }
    115118}
  • src/org/openstreetmap/josm/actions/mapmode/AddSegmentAction.java

    r94 r98  
    5151        @Override public void enterMode() {
    5252                super.enterMode();
    53                 mv.addMouseListener(this);
    54                 mv.addMouseMotionListener(this);
     53                Main.map.mapView.addMouseListener(this);
     54                Main.map.mapView.addMouseMotionListener(this);
    5555        }
    5656
    5757        @Override public void exitMode() {
    5858                super.exitMode();
    59                 mv.removeMouseListener(this);
    60                 mv.removeMouseMotionListener(this);
     59                Main.map.mapView.removeMouseListener(this);
     60                Main.map.mapView.removeMouseMotionListener(this);
    6161                drawHint(false);
    6262        }
     
    7575                        return;
    7676
    77                 OsmPrimitive clicked = mv.getNearest(e.getPoint(), true);
     77                OsmPrimitive clicked = Main.map.mapView.getNearest(e.getPoint(), true);
    7878                if (clicked == null || !(clicked instanceof Node))
    7979                        return;
     
    9191                        return;
    9292
    93                 OsmPrimitive clicked = mv.getNearest(e.getPoint(), (e.getModifiersEx() & MouseEvent.ALT_DOWN_MASK) != 0);
     93                OsmPrimitive clicked = Main.map.mapView.getNearest(e.getPoint(), (e.getModifiersEx() & MouseEvent.ALT_DOWN_MASK) != 0);
    9494                if (clicked == null || clicked == second || !(clicked instanceof Node))
    9595                        return;
     
    136136
    137137                        Segment ls = new Segment(start, end);
    138                         mv.editLayer().add(new AddCommand(ls));
     138                        Main.main.editLayer().add(new AddCommand(ls));
    139139                }
    140140
    141                 mv.repaint();
     141                Main.map.mapView.repaint();
    142142        }
    143143
     
    153153                        return;
    154154
    155                 Graphics g = mv.getGraphics();
     155                Graphics g = Main.map.mapView.getGraphics();
    156156                g.setColor(Color.BLACK);
    157157                g.setXORMode(Color.WHITE);
    158                 Point firstDrawn = mv.getPoint(first.eastNorth);
    159                 Point secondDrawn = mv.getPoint(second.eastNorth);
     158                Point firstDrawn = Main.map.mapView.getPoint(first.eastNorth);
     159                Point secondDrawn = Main.map.mapView.getPoint(second.eastNorth);
    160160                g.drawLine(firstDrawn.x, firstDrawn.y, secondDrawn.x, secondDrawn.y);
    161161                hintDrawn = !hintDrawn;
  • src/org/openstreetmap/josm/actions/mapmode/AddWayAction.java

    r94 r98  
    6969                        c = new AddCommand(way);
    7070                        Main.ds.setSelected(way);
    71                         mv.editLayer().add(c);
     71                        Main.main.editLayer().add(c);
    7272                } else
    7373                        Main.ds.clearSelection();
    74                 mv.addMouseListener(this);
     74                Main.map.mapView.addMouseListener(this);
    7575        }
    7676
     
    7878                super.exitMode();
    7979                way = null;
    80                 mv.removeMouseListener(this);
     80                Main.map.mapView.removeMouseListener(this);
    8181        }
    8282
     
    8585                        return;
    8686
    87                 Segment s = mv.getNearestSegment(e.getPoint());
     87                Segment s = Main.map.mapView.getNearestSegment(e.getPoint());
    8888                if (s == null)
    8989                        return;
     
    9191                // special case for initial selecting one way
    9292                if (way == null && (e.getModifiers() & MouseEvent.ALT_DOWN_MASK) == 0) {
    93                         Way w = mv.getNearestWay(e.getPoint());
     93                        Way w = Main.map.mapView.getNearestWay(e.getPoint());
    9494                        if (w != null) {
    9595                                way = w;
     
    104104                        copy.segments.remove(s);
    105105                        if (copy.segments.isEmpty()) {
    106                                 mv.editLayer().add(new DeleteCommand(Arrays.asList(new OsmPrimitive[]{way})));
     106                                Main.main.editLayer().add(new DeleteCommand(Arrays.asList(new OsmPrimitive[]{way})));
    107107                                way = null;
    108108                        } else
    109                                 mv.editLayer().add(new ChangeCommand(way, copy));
     109                                Main.main.editLayer().add(new ChangeCommand(way, copy));
    110110                } else {
    111111                        if (way == null) {
    112112                                way = new Way();
    113113                                way.segments.add(s);
    114                                 mv.editLayer().add(new AddCommand(way));
     114                                Main.main.editLayer().add(new AddCommand(way));
    115115                        } else {
    116116                                Way copy = new Way(way);
     
    120120                                                break;
    121121                                copy.segments.add(i, s);
    122                                 mv.editLayer().add(new ChangeCommand(way, copy));
     122                                Main.main.editLayer().add(new ChangeCommand(way, copy));
    123123                        }
    124124                }
     
    149149                if (numberOfSelectedWays > 0) {
    150150                        String ways = "way" + (numberOfSelectedWays==1?" has":"s have");
    151                         int answer = JOptionPane.showConfirmDialog(Main.main, numberOfSelectedWays+" "+ways+" been selected.\n" +
     151                        int answer = JOptionPane.showConfirmDialog(Main.parent, numberOfSelectedWays+" "+ways+" been selected.\n" +
    152152                                        "Do you wish to select all segments belonging to the "+ways+" instead?", "Add segments from ways", JOptionPane.YES_NO_OPTION);
    153153                        if (answer == JOptionPane.YES_OPTION) {
     
    193193                }
    194194
    195                 if (JOptionPane.YES_OPTION != JOptionPane.showConfirmDialog(Main.main, "Create a new way out of "+sortedSegments.size()+" segments?", "Create new way", JOptionPane.YES_NO_OPTION))
     195                if (JOptionPane.YES_OPTION != JOptionPane.showConfirmDialog(Main.parent, "Create a new way out of "+sortedSegments.size()+" segments?", "Create new way", JOptionPane.YES_NO_OPTION))
    196196                        return null;
    197197
  • src/org/openstreetmap/josm/actions/mapmode/DeleteAction.java

    r94 r98  
    4646        @Override public void enterMode() {
    4747                super.enterMode();
    48                 mv.addMouseListener(this);
     48                Main.map.mapView.addMouseListener(this);
    4949        }
    5050
    5151        @Override public void exitMode() {
    5252                super.exitMode();
    53                 mv.removeMouseListener(this);
     53                Main.map.mapView.removeMouseListener(this);
    5454        }
    5555
     
    6262                else
    6363                        delete(Main.ds.getSelected(), false);
    64                 mv.repaint();
     64                Main.map.repaint();
    6565        }
    6666
     
    7373                        return;
    7474               
    75                 OsmPrimitive sel = mv.getNearest(e.getPoint(), (e.getModifiersEx() & MouseEvent.ALT_DOWN_MASK) != 0);
     75                OsmPrimitive sel = Main.map.mapView.getNearest(e.getPoint(), (e.getModifiersEx() & MouseEvent.ALT_DOWN_MASK) != 0);
    7676                if (sel == null)
    7777                        return;
     
    8282                        delete(Collections.singleton(sel), true);
    8383
    84                 mv.repaint();
     84                Main.map.mapView.repaint();
    8585        }
    8686
     
    107107                v.data.addAll(selection);
    108108                if (!v.data.isEmpty())
    109                         mv.editLayer().add(new DeleteCommand(v.data));
     109                        Main.main.editLayer().add(new DeleteCommand(v.data));
    110110        }
    111111
     
    125125                        if (!selection.containsAll(v.data)) {
    126126                                if (msgBox) {
    127                                         JOptionPane.showMessageDialog(Main.main, "This object is in use.");
     127                                        JOptionPane.showMessageDialog(Main.parent, "This object is in use.");
    128128                                        return;
    129129                                }
     
    134134                }
    135135                if (!del.isEmpty())
    136                         mv.editLayer().add(new DeleteCommand(del));
     136                        Main.main.editLayer().add(new DeleteCommand(del));
    137137        }
    138138}
  • src/org/openstreetmap/josm/actions/mapmode/MapMode.java

    r94 r98  
    88import javax.swing.KeyStroke;
    99
     10import org.openstreetmap.josm.Main;
    1011import org.openstreetmap.josm.actions.JosmAction;
    1112import org.openstreetmap.josm.gui.MapFrame;
    12 import org.openstreetmap.josm.gui.MapView;
    1313import org.openstreetmap.josm.tools.ImageProvider;
    1414
     
    2424
    2525        /**
    26          * The parent mapframe this mode belongs to.
    27          */
    28         protected final MapFrame mapFrame;
    29         /**
    30          * Shortcut to the MapView.
    31          */
    32         protected final MapView mv;
    33 
    34         /**
    3526         * Constructor for mapmodes without an menu
    3627         */
    3728        public MapMode(String name, String iconName, String tooltip, String keyname, int keystroke, MapFrame mapFrame) {
    3829                super(name, "mapmode/"+iconName, tooltip, keyname, KeyStroke.getKeyStroke(keystroke, 0));
    39                 this.mapFrame = mapFrame;
    40                 mv = mapFrame.mapView;
    4130                putValue("active", false);
    4231        }
     
    4938                putValue(SMALL_ICON, ImageProvider.get("mapmode", iconName));
    5039                putValue(SHORT_DESCRIPTION, tooltip);
    51                 this.mapFrame = mapFrame;
    52                 mv = mapFrame.mapView;
    5340        }
    5441
     
    6451         */
    6552        public void actionPerformed(ActionEvent e) {
    66                 mapFrame.selectMapMode(this);
     53                Main.map.selectMapMode(this);
    6754        }
    6855
  • src/org/openstreetmap/josm/actions/mapmode/MoveAction.java

    r96 r98  
    5353        @Override public void enterMode() {
    5454                super.enterMode();
    55                 mv.addMouseListener(this);
    56                 mv.addMouseMotionListener(this);
     55                Main.map.mapView.addMouseListener(this);
     56                Main.map.mapView.addMouseMotionListener(this);
    5757        }
    5858
    5959        @Override public void exitMode() {
    6060                super.exitMode();
    61                 mv.removeMouseListener(this);
    62                 mv.removeMouseMotionListener(this);
     61                Main.map.mapView.removeMouseListener(this);
     62                Main.map.mapView.removeMouseMotionListener(this);
    6363        }
    6464
     
    7777                }
    7878
    79                 EastNorth mouseGeo = mv.getEastNorth(e.getX(), e.getY());
    80                 EastNorth mouseStartGeo = mv.getEastNorth(mousePos.x, mousePos.y);
     79                EastNorth mouseGeo = Main.map.mapView.getEastNorth(e.getX(), e.getY());
     80                EastNorth mouseStartGeo = Main.map.mapView.getEastNorth(mousePos.x, mousePos.y);
    8181                double dx = mouseGeo.east() - mouseStartGeo.east();
    8282                double dy = mouseGeo.north() - mouseStartGeo.north();
     
    9090                for (OsmPrimitive osm : affectedNodes) {
    9191                        if (osm instanceof Node && ((Node)osm).coor.isOutSideWorld()) {
    92                                 JOptionPane.showMessageDialog(Main.main, "Cannot move objects outside of the world.");
     92                                JOptionPane.showMessageDialog(Main.parent, "Cannot move objects outside of the world.");
    9393                                return;
    9494                        }
    9595                }
    9696               
    97                 Command c = !mv.editLayer().commands.isEmpty() ? mv.editLayer().commands.getLast() : null;
     97                Command c = !Main.main.editLayer().commands.isEmpty() ? Main.main.editLayer().commands.getLast() : null;
    9898                if (c instanceof MoveCommand && affectedNodes.equals(((MoveCommand)c).objects))
    9999                        ((MoveCommand)c).moveAgain(dx,dy);
    100100                else
    101                         mv.editLayer().add(new MoveCommand(selection, dx, dy));
     101                        Main.main.editLayer().add(new MoveCommand(selection, dx, dy));
    102102               
    103                 mv.repaint();
     103                Main.map.mapView.repaint();
    104104                mousePos = e.getPoint();
    105105        }
     
    119119
    120120                if (Main.ds.getSelected().size() == 0) {
    121                         OsmPrimitive osm = mv.getNearest(e.getPoint(), (e.getModifiersEx() & MouseEvent.ALT_DOWN_MASK) != 0);
     121                        OsmPrimitive osm = Main.map.mapView.getNearest(e.getPoint(), (e.getModifiersEx() & MouseEvent.ALT_DOWN_MASK) != 0);
    122122                        if (osm != null)
    123123                                Main.ds.setSelected(osm);
    124124                        singleOsmPrimitive = osm;
    125                         mv.repaint();
     125                        Main.map.mapView.repaint();
    126126                } else
    127127                        singleOsmPrimitive = null;
    128128               
    129129                mousePos = e.getPoint();
    130                 oldCursor = mv.getCursor();
    131                 mv.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
     130                oldCursor = Main.map.mapView.getCursor();
     131                Main.map.mapView.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
    132132        }
    133133       
     
    136136         */
    137137        @Override public void mouseReleased(MouseEvent e) {
    138                 mv.setCursor(oldCursor);
     138                Main.map.mapView.setCursor(oldCursor);
    139139                if (singleOsmPrimitive != null) {
    140140                        Main.ds.clearSelection();
    141                         mv.repaint();
     141                        Main.map.mapView.repaint();
    142142                }
    143143        }
  • src/org/openstreetmap/josm/actions/mapmode/SelectionAction.java

    r94 r98  
    6565        public SelectionAction(MapFrame mapFrame) {
    6666                super("Selection", "selection", "Select objects by dragging or clicking.", "S", KeyEvent.VK_S, mapFrame);
    67                 this.selectionManager = new SelectionManager(this, false, mv);
     67                this.selectionManager = new SelectionManager(this, false, mapFrame.mapView);
    6868        }
    6969
    7070        @Override public void enterMode() {
    7171                super.enterMode();
    72                 selectionManager.register(mv);
     72                selectionManager.register(Main.map.mapView);
    7373        }
    7474
    7575        @Override public void exitMode() {
    7676                super.exitMode();
    77                 selectionManager.unregister(mv);
     77                selectionManager.unregister(Main.map.mapView);
    7878        }
    7979
     
    9999                                curSel.add(osm);
    100100                Main.ds.setSelected(curSel);
    101                 mv.repaint();
     101                Main.map.mapView.repaint();
    102102        }
    103103}
  • src/org/openstreetmap/josm/command/Command.java

    r94 r98  
    1616 *
    1717 * Remember, that the command must be executable and undoable, even if the
    18  * Main.main.ds has changed, so the command must save the dataset it operates on
     18 * Main.ds has changed, so the command must save the dataset it operates on
    1919 * if necessary.
    2020 *
  • src/org/openstreetmap/josm/command/ConflictResolveCommand.java

    r94 r98  
    3030                this.conflicts = conflicts;
    3131                this.resolved = resolved;
    32                 conflictDialog = Main.main.getMapFrame().conflictDialog;
     32                conflictDialog = Main.map.conflictDialog;
    3333        }
    3434
     
    5353                                conflictDialog.conflicts.remove(k);
    5454                        conflictDialog.rebuildList();
    55                         Main.main.getMapFrame().mapView.recalculateCenterScale(); // in case of auto-zoom
     55                        Main.map.mapView.recalculateCenterScale(); // in case of auto-zoom
    5656                }
    5757        }
     
    5959        @Override public void undoCommand() {
    6060                super.undoCommand();
    61                 Main.main.getMapFrame().conflictDialog.conflicts.clear();
    62                 Main.main.getMapFrame().conflictDialog.conflicts.putAll(origAllConflicts);
    63                 Main.main.getMapFrame().conflictDialog.rebuildList();
     61                Main.map.conflictDialog.conflicts.clear();
     62                Main.map.conflictDialog.conflicts.putAll(origAllConflicts);
     63                Main.map.conflictDialog.rebuildList();
    6464        }
    6565
  • src/org/openstreetmap/josm/data/Preferences.java

    r79 r98  
    3131        }
    3232       
    33         ArrayList<PreferenceChangedListener> listener = new ArrayList<PreferenceChangedListener>();
     33        public final ArrayList<PreferenceChangedListener> listener = new ArrayList<PreferenceChangedListener>();
    3434       
    3535        /**
    3636         * Map the property name to the property object.
    3737         */
    38         private SortedMap<String, String> properties = new TreeMap<String, String>();
     38        private final SortedMap<String, String> properties = new TreeMap<String, String>();
    3939       
    4040        /**
    4141         * Return the location of the preferences file
    4242         */
    43         public static String getPreferencesDir() {
     43        public String getPreferencesDir() {
    4444                return System.getProperty("user.home")+"/.josm/";
    4545        }
    4646
    47 
    48         public void addPreferenceChangedListener(PreferenceChangedListener listener) {
    49                 this.listener.add(listener);
    50         }
    51         public void removePreferenceChangedListener(PreferenceChangedListener listener) {
    52                 this.listener.remove(listener);
    53         }
    54 
    55 
    56         synchronized public String get(String key) {
     47        synchronized final public String get(final String key) {
    5748                if (!properties.containsKey(key))
    5849                        return "";
    5950                return properties.get(key);
    6051        }
    61         synchronized public String get(String key, String def) {
    62                 String prop = properties.get(key);
     52        synchronized final public String get(final String key, final String def) {
     53                final String prop = properties.get(key);
    6354                if (prop == null || prop.equals(""))
    6455                        return def;
    6556                return prop;
    6657        }
    67         synchronized public Map<String, String> getAllPrefix(String prefix) {
    68                 Map<String,String> all = new TreeMap<String,String>();
    69                 for (Entry<String,String> e : properties.entrySet())
     58        synchronized final public Map<String, String> getAllPrefix(final String prefix) {
     59                final Map<String,String> all = new TreeMap<String,String>();
     60                for (final Entry<String,String> e : properties.entrySet())
    7061                        if (e.getKey().startsWith(prefix))
    7162                                all.put(e.getKey(), e.getValue());
    7263                return all;
    7364        }
    74         synchronized public boolean getBoolean(String key) {
     65        synchronized final public boolean getBoolean(final String key) {
    7566                return getBoolean(key, false);
    7667        }
    77         synchronized public boolean getBoolean(String key, boolean def) {
     68        synchronized final public boolean getBoolean(final String key, final boolean def) {
    7869                return properties.containsKey(key) ? Boolean.parseBoolean(properties.get(key)) : def;
    7970        }
    8071
    8172
    82         synchronized public void put(String key, String value) {
     73        synchronized final public void put(final String key, final String value) {
    8374                if (value == null)
    8475                        properties.remove(key);
     
    8879                firePreferenceChanged(key, value);
    8980        }
    90         synchronized public void put(String key, boolean value) {
     81        synchronized final public void put(final String key, final boolean value) {
    9182                properties.put(key, Boolean.toString(value));
    9283                save();
     
    9485        }
    9586
    96         private void firePreferenceChanged(String key, String value) {
    97                 for (PreferenceChangedListener l : listener)
     87        private final void firePreferenceChanged(final String key, final String value) {
     88                for (final PreferenceChangedListener l : listener)
    9889                        l.preferenceChanged(key, value);
    9990        }
     
    10495         * in log.
    10596         */
    106         private void save() {
     97        protected void save() {
    10798                try {
    108                         PrintWriter out = new PrintWriter(new FileWriter(
     99                        final PrintWriter out = new PrintWriter(new FileWriter(
    109100                                        getPreferencesDir() + "preferences"));
    110                         for (Entry<String, String> e : properties.entrySet())
     101                        for (final Entry<String, String> e : properties.entrySet())
    111102                                if (!e.getValue().equals(""))
    112103                                        out.println(e.getKey() + "=" + e.getValue());
    113104                        out.close();
    114                 } catch (IOException e) {
     105                } catch (final IOException e) {
    115106                        e.printStackTrace();
    116107                        // do not message anything, since this can be called from strange
     
    122113        public void load() throws IOException {
    123114                properties.clear();
    124                 BufferedReader in = new BufferedReader(new FileReader(getPreferencesDir()+"preferences"));
     115                final BufferedReader in = new BufferedReader(new FileReader(getPreferencesDir()+"preferences"));
    125116                int lineNumber = 0;
    126117                for (String line = in.readLine(); line != null; line = in.readLine(), lineNumber++) {
    127                         int i = line.indexOf('=');
     118                        final int i = line.indexOf('=');
    128119                        if (i == -1 || i == 0)
    129120                                throw new IOException("Malformed config file at line "+lineNumber);
     
    132123        }
    133124
    134         public void resetToDefault() {
     125        public final void resetToDefault() {
    135126                properties.clear();
    136127                properties.put("laf", "javax.swing.plaf.metal.MetalLookAndFeel");
  • src/org/openstreetmap/josm/gui/BookmarkList.java

    r86 r98  
    1717
    1818import org.openstreetmap.josm.Main;
    19 import org.openstreetmap.josm.data.Preferences;
    2019import org.openstreetmap.josm.tools.ImageProvider;
    2120
     
    3837                }
    3938        }
    40        
     39
    4140        /**
    4241         * Create a bookmark list as well as the Buttons add and remove.
     
    6463                DefaultListModel model = (DefaultListModel)getModel();
    6564                model.removeAllElements();
    66                 File bookmarkFile = new File(Preferences.getPreferencesDir()+"bookmarks");
     65                File bookmarkFile = new File(Main.pref.getPreferencesDir()+"bookmarks");
    6766                try {
    6867                        if (!bookmarkFile.exists())
    6968                                bookmarkFile.createNewFile();
    7069                        BufferedReader in = new BufferedReader(new FileReader(bookmarkFile));
    71                        
     70
    7271                        for (String line = in.readLine(); line != null; line = in.readLine()) {
    7372                                StringTokenizer st = new StringTokenizer(line, ",");
     
    8786                        in.close();
    8887                } catch (IOException e) {
    89                         JOptionPane.showMessageDialog(Main.main, "Could not read bookmarks.\n"+e.getMessage());
     88                        JOptionPane.showMessageDialog(Main.parent, "Could not read bookmarks.\n"+e.getMessage());
    9089                }
    9190        }
     
    9594         */
    9695        public void save() {
    97                 File bookmarkFile = new File(Preferences.getPreferencesDir()+"bookmarks");
     96                File bookmarkFile = new File(Main.pref.getPreferencesDir()+"bookmarks");
    9897                try {
    9998                        if (!bookmarkFile.exists())
     
    111110                        out.close();
    112111                } catch (IOException e) {
    113                         JOptionPane.showMessageDialog(Main.main, "Could not write bookmark.\n"+e.getMessage());
     112                        JOptionPane.showMessageDialog(Main.parent, "Could not write bookmark.\n"+e.getMessage());
    114113                }
    115114        }
  • src/org/openstreetmap/josm/gui/MapFrame.java

    r94 r98  
    5959       
    6060        public ConflictDialog conflictDialog;
     61        private JPanel toggleDialogs = new JPanel();
    6162       
    6263        /**
     
    115116                });
    116117
    117                 JPanel toggleDialogs = new JPanel();
    118118                add(toggleDialogs, BorderLayout.EAST);
     119                toggleDialogs.setLayout(new BoxLayout(toggleDialogs, BoxLayout.Y_AXIS));
    119120
    120                 toggleDialogs.setLayout(new BoxLayout(toggleDialogs, BoxLayout.Y_AXIS));
    121121                addIconToggle(toggleDialogs, new LayerList(this));
    122122                addIconToggle(toggleDialogs, new PropertiesDialog(this));
     
    129129        }
    130130
     131        /**
     132         * Open all ToggleDialogs that have their preferences property set. Close all others.
     133         */
     134        public void setVisibleDialogs() {
     135                for (Component c : toggleDialogs.getComponents())
     136                        if (c instanceof ToggleDialog)
     137                                c.setVisible(Main.pref.getBoolean(((ToggleDialog)c).prefName+".visible"));
     138        }
    131139
    132140        private void addIconToggle(JPanel toggleDialogs, ToggleDialog dlg) {
     
    135143                toolBarActions.add(button);
    136144                toggleDialogs.add(dlg);
    137                 if (Main.pref.getBoolean(dlg.action.prefname+".visible"))
    138                         dlg.action.actionPerformed(new ActionEvent(this, 0, ""));
    139145        }
    140146
  • src/org/openstreetmap/josm/gui/MapView.java

    r94 r98  
    1010import java.util.Collections;
    1111import java.util.LinkedList;
     12
     13import javax.swing.JOptionPane;
    1214
    1315import org.openstreetmap.josm.Main;
     
    6264         * Direct link to the edit layer (if any) in the layers list.
    6365         */
    64         private OsmDataLayer editLayer;
     66        public OsmDataLayer editLayer;
    6567        /**
    6668         * The layer from the layers list that is currently active.
     
    108110                        dataLayer.listenerModified.add(new ModifiedChangedListener(){
    109111                public void modifiedChanged(boolean value, OsmDataLayer source) {
    110                         Main.main.setTitle((value?"*":"")+"Java Open Street Map - Editor");
     112                        JOptionPane.getFrameForComponent(Main.parent).setTitle((value?"*":"")+"Java Open Street Map - Editor");
    111113                }
    112114            });
     
    290292
    291293        /**
    292          * @return The current edit layer. If no edit layer exist, one is created.
    293          *              So editLayer does never return <code>null</code>.
    294          */
    295         public OsmDataLayer editLayer() {
    296                 if (editLayer == null)
    297                         addLayer(new OsmDataLayer(Main.ds, "unnamed", false));
    298                 return editLayer;
    299         }
    300 
    301         /**
    302294         * In addition to the base class funcitonality, this keep trak of the autoscale
    303295         * feature.
  • src/org/openstreetmap/josm/gui/PleaseWaitRunnable.java

    r95 r98  
    4444         */
    4545        public PleaseWaitRunnable(String msg) {
    46                 pleaseWaitDlg = new JDialog(Main.main, msg, true);
     46                pleaseWaitDlg = new JDialog(JOptionPane.getFrameForComponent(Main.parent), msg, true);
    4747                pleaseWaitDlg.setLayout(new GridBagLayout());
    4848                JPanel pane = new JPanel(new GridBagLayout());
     
    5454                pleaseWaitDlg.setContentPane(pane);
    5555                pleaseWaitDlg.setSize(350,100);
    56                 pleaseWaitDlg.setLocationRelativeTo(Main.main);
     56                pleaseWaitDlg.setLocationRelativeTo(Main.parent);
    5757
    5858                cancel.addActionListener(new ActionListener(){
     
    122122                                pleaseWaitDlg.dispose();
    123123                                if (errorMessage != null)
    124                                         JOptionPane.showMessageDialog(Main.main, errorMessage);
     124                                        JOptionPane.showMessageDialog(Main.parent, errorMessage);
    125125                        }
    126126                });
  • src/org/openstreetmap/josm/gui/PreferenceDialog.java

    r93 r98  
    8686                        if (requiresRestart)
    8787                                JOptionPane.showMessageDialog(PreferenceDialog.this, "You have to restart JOSM for some settings to take effect.");
    88                         Main.main.repaint();
     88                        Main.parent.repaint();
    8989                        setVisible(false);
    9090                }
     
    166166         */
    167167        public PreferenceDialog() {
    168                 super(Main.main, "Preferences");
     168                super(JOptionPane.getFrameForComponent(Main.parent), "Preferences");
    169169
    170170                // look and feel combo box
     
    346346                setModal(true);
    347347                pack();
    348                 setLocationRelativeTo(Main.main);
     348                setLocationRelativeTo(Main.parent);
    349349        }
    350350
  • src/org/openstreetmap/josm/gui/dialogs/CommandStackDialog.java

    r94 r98  
    1414import javax.swing.tree.DefaultTreeModel;
    1515
     16import org.openstreetmap.josm.Main;
    1617import org.openstreetmap.josm.command.Command;
    1718import org.openstreetmap.josm.gui.MapFrame;
     19import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
     20import org.openstreetmap.josm.gui.layer.Layer;
     21import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1822import org.openstreetmap.josm.gui.layer.OsmDataLayer.CommandQueueListener;
    1923
     
    2226        private DefaultTreeModel treeModel = new DefaultTreeModel(new DefaultMutableTreeNode());
    2327    private JTree tree = new JTree(treeModel);
    24         private final MapFrame mapFrame;
    2528
    26         public CommandStackDialog(MapFrame mapFrame) {
     29        public CommandStackDialog(final MapFrame mapFrame) {
    2730                super("Command Stack", "commandstack", "Open a list of all commands (undo buffer).", KeyEvent.VK_C);
    28                 this.mapFrame = mapFrame;
    2931                setPreferredSize(new Dimension(320,100));
    30                 mapFrame.mapView.editLayer().listenerCommands.add(this);
     32                mapFrame.mapView.addLayerChangeListener(new LayerChangeListener(){
     33                        public void activeLayerChange(Layer oldLayer, Layer newLayer) {}
     34                        public void layerAdded(Layer newLayer) {
     35                                if (newLayer instanceof OsmDataLayer)
     36                                        Main.main.editLayer().listenerCommands.add(CommandStackDialog.this);
     37                        }
     38                        public void layerRemoved(Layer oldLayer) {}
     39                });
    3140                tree.setRootVisible(false);
    3241                tree.setShowsRootHandles(true);
     
    5766
    5867        private void buildList() {
    59                 Collection<Command> commands = mapFrame.mapView.editLayer().commands;
     68                Collection<Command> commands = Main.main.editLayer().commands;
    6069                DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    6170                for (Command c : commands)
     
    6473        }
    6574
    66         public void commandChanged() {
     75        public void commandChanged(int queueSize, int redoSize) {
    6776                if (!isVisible())
    6877                        return;
  • src/org/openstreetmap/josm/gui/dialogs/ConflictDialog.java

    r94 r98  
    3636import org.openstreetmap.josm.data.osm.visitor.Visitor;
    3737import org.openstreetmap.josm.gui.ConflictResolver;
    38 import org.openstreetmap.josm.gui.MapView;
    3938import org.openstreetmap.josm.gui.NavigatableComponent;
    4039import org.openstreetmap.josm.gui.OsmPrimitivRenderer;
     
    9695                displaylist.getSelectionModel().addListSelectionListener(new ListSelectionListener(){
    9796                        public void valueChanged(ListSelectionEvent e) {
    98                                 Main.main.getMapFrame().mapView.repaint();
     97                                Main.map.mapView.repaint();
    9998                        }
    10099                });
     
    103102        private final void resolve() {
    104103                if (displaylist.getSelectedIndex() == -1) {
    105                         JOptionPane.showMessageDialog(Main.main, "Please select something from the conflict list.");
     104                        JOptionPane.showMessageDialog(Main.parent, "Please select something from the conflict list.");
    106105                        return;
    107106                }
     
    112111                }
    113112                ConflictResolver resolver = new ConflictResolver(sel);
    114                 int answer = JOptionPane.showConfirmDialog(Main.main, resolver, "Resolve Conflicts", JOptionPane.OK_CANCEL_OPTION);
     113                int answer = JOptionPane.showConfirmDialog(Main.parent, resolver, "Resolve Conflicts", JOptionPane.OK_CANCEL_OPTION);
    115114                if (answer != JOptionPane.OK_OPTION)
    116115                        return;
    117                 MapView mv = Main.main.getMapFrame().mapView;
    118                 mv.editLayer().add(new ConflictResolveCommand(resolver.conflicts, sel));
    119                 mv.repaint();
     116                Main.main.editLayer().add(new ConflictResolveCommand(resolver.conflicts, sel));
     117                Main.map.mapView.repaint();
    120118        }
    121119
  • src/org/openstreetmap/josm/gui/dialogs/LayerList.java

    r94 r98  
    2828
    2929import org.openstreetmap.josm.Main;
    30 import org.openstreetmap.josm.data.osm.DataSet;
    3130import org.openstreetmap.josm.gui.MapFrame;
    3231import org.openstreetmap.josm.gui.MapView;
     
    5756
    5857        public void actionPerformed(ActionEvent e) {
    59                 if (layers.getModel().getSize() == 1) {
    60                         Main.main.setMapFrame(null);
    61                         Main.ds = new DataSet();
    62                 } else {
    63                     int sel = layers.getSelectedIndex();
    64                 if (layer != null)
    65                     Main.main.getMapFrame().mapView.removeLayer(layer);
    66                 else
    67                     Main.main.getMapFrame().mapView.removeLayer((Layer)layers.getSelectedValue());
    68                 if (sel >= layers.getModel().getSize())
    69                     sel = layers.getModel().getSize()-1;
    70                 if (layers.getSelectedValue() == null)
    71                     layers.setSelectedIndex(sel);
    72                 }
     58            int sel = layers.getSelectedIndex();
     59            if (layer != null)
     60                Main.main.removeLayer(layer);
     61            else
     62                Main.main.removeLayer((Layer)layers.getSelectedValue());
     63            if (sel >= layers.getModel().getSize())
     64                sel = layers.getModel().getSize()-1;
     65            if (layers.getSelectedValue() == null)
     66                layers.setSelectedIndex(sel);
    7367        }
    7468    }
     
    8882            Layer l = layer == null ? (Layer)layers.getSelectedValue() : layer;
    8983            l.visible = !l.visible;
    90                 Main.main.getMapFrame().mapView.repaint();
     84                Main.map.mapView.repaint();
    9185                layers.repaint();
    9286        }
  • src/org/openstreetmap/josm/gui/dialogs/LayerListPopup.java

    r86 r98  
    2424            }
    2525            public void actionPerformed(ActionEvent e) {
    26                 JOptionPane.showMessageDialog(Main.main, layer.getInfoComponent());
     26                JOptionPane.showMessageDialog(Main.parent, layer.getInfoComponent());
    2727            }
    2828    }
  • src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java

    r94 r98  
    4040import org.openstreetmap.josm.data.osm.OsmPrimitive;
    4141import org.openstreetmap.josm.gui.MapFrame;
    42 import org.openstreetmap.josm.gui.MapView;
    4342import org.openstreetmap.josm.tools.ImageProvider;
    4443
     
    9594
    9695                final JOptionPane optionPane = new JOptionPane(p, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
    97                 final JDialog dlg = optionPane.createDialog(Main.main, "Change values?");
     96                final JDialog dlg = optionPane.createDialog(Main.parent, "Change values?");
    9897                dlg.addWindowFocusListener(new WindowFocusListener(){
    9998                        public void windowGainedFocus(WindowEvent e) {
     
    124123                if (value.equals(""))
    125124                        value = null; // delete the key
    126                 mv.editLayer().add(new ChangePropertyCommand(sel, key, value));
     125                Main.main.editLayer().add(new ChangePropertyCommand(sel, key, value));
    127126
    128127                if (value == null)
     
    163162                JTextField values = new JTextField();
    164163                p2.add(values, BorderLayout.CENTER);
    165                 int answer = JOptionPane.showConfirmDialog(Main.main, p,
     164                int answer = JOptionPane.showConfirmDialog(Main.parent, p,
    166165                                "Change values?", JOptionPane.OK_CANCEL_OPTION);
    167166                if (answer != JOptionPane.OK_OPTION)
     
    171170                if (value.equals(""))
    172171                        return;
    173                 mv.editLayer().add(new ChangePropertyCommand(sel, key, value));
     172                Main.main.editLayer().add(new ChangePropertyCommand(sel, key, value));
    174173                selectionChanged(sel); // update table
    175174        }
     
    182181                String key = data.getValueAt(row, 0).toString();
    183182                Collection<OsmPrimitive> sel = Main.ds.getSelected();
    184                 mv.editLayer().add(new ChangePropertyCommand(sel, key, null));
     183                Main.main.editLayer().add(new ChangePropertyCommand(sel, key, null));
    185184                selectionChanged(sel); // update table
    186185        }
     
    201200         */
    202201        private final JTable propertyTable = new JTable(data);
    203         /**
    204          * The map view this dialog operates on.
    205          */
    206         private final MapView mv;
    207202       
    208203        /**
     
    211206        public PropertiesDialog(MapFrame mapFrame) {
    212207                super("Properties", "propertiesdialog", "Property for selected objects.", KeyEvent.VK_P);
    213                 mv = mapFrame.mapView;
    214208
    215209                setPreferredSize(new Dimension(320,150));
     
    248242                                else if (e.getActionCommand().equals("Edit")) {
    249243                                        if (sel == -1)
    250                                                 JOptionPane.showMessageDialog(Main.main, "Please select the row to edit.");
     244                                                JOptionPane.showMessageDialog(Main.parent, "Please select the row to edit.");
    251245                                        else
    252246                                                edit(sel);
    253247                                } else if (e.getActionCommand().equals("Delete")) {
    254248                                        if (sel == -1)
    255                                                 JOptionPane.showMessageDialog(Main.main, "Please select the row to delete.");
     249                                                JOptionPane.showMessageDialog(Main.parent, "Please select the row to delete.");
    256250                                        else
    257251                                                delete(sel);
  • src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java

    r94 r98  
    8787                } catch (IOException e) {
    8888                        e.printStackTrace();
    89                         JOptionPane.showMessageDialog(Main.main, "Could not read from url: '"+url+"'");
     89                        JOptionPane.showMessageDialog(Main.parent, "Could not read from url: '"+url+"'");
    9090                } catch (SAXException e) {
    9191                        e.printStackTrace();
    92                         JOptionPane.showMessageDialog(Main.main, "Parsing error in url: '"+url+"'");
     92                        JOptionPane.showMessageDialog(Main.parent, "Parsing error in url: '"+url+"'");
    9393                }
    9494        }
     
    185185                    }
    186186                                };
    187                                 pane.createDialog(Main.main, "Search").setVisible(true);
     187                                pane.createDialog(Main.parent, "Search").setVisible(true);
    188188                                if (!Integer.valueOf(JOptionPane.OK_OPTION).equals(pane.getValue()))
    189189                                        return;
  • src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java

    r94 r98  
    4444         */
    4545        public ToggleDialogAction action;
     46        public final String prefName;
    4647
    4748        public ToggleDialog(String name, String iconName, String tooltip, int shortCut) {
     49                this.prefName = iconName;
    4850                action = new ToggleDialogAction(name, "dialogs/"+iconName, tooltip, ShortCutLabel.name(shortCut, KeyEvent.ALT_MASK), KeyStroke.getKeyStroke(shortCut, KeyEvent.ALT_MASK), iconName);
    4951                setLayout(new BorderLayout());
  • src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r94 r98  
    5050                public final String[] names = {"node", "segment", "way"};
    5151
    52                 private void inc(OsmPrimitive osm, int i) {
     52                private void inc(final OsmPrimitive osm, final int i) {
    5353                        normal[i]++;
    5454                        if (osm.deleted)
     
    5656                }
    5757
    58                 public void visit(Node n) {
     58                public void visit(final Node n) {
    5959                        inc(n, 0);
    6060                }
    6161
    62                 public void visit(Segment ls) {
     62                public void visit(final Segment ls) {
    6363                        inc(ls, 1);
    6464                }
    6565
    66                 public void visit(Way w) {
     66                public void visit(final Way w) {
    6767                        inc(w, 2);
    6868                }
     
    7373        }
    7474        public interface CommandQueueListener {
    75                 void commandChanged();
     75                void commandChanged(int queueSize, int redoSize);
    7676        }
    7777
     
    103103         * The stack for redoing commands
    104104         */
    105         private Stack<Command> redoCommands = new Stack<Command>();
     105        private final Stack<Command> redoCommands = new Stack<Command>();
    106106
    107107        public final LinkedList<ModifiedChangedListener> listenerModified = new LinkedList<ModifiedChangedListener>();
     
    112112         * Construct a OsmDataLayer.
    113113         */
    114         public OsmDataLayer(DataSet data, String name, boolean fromDisk) {
     114        public OsmDataLayer(final DataSet data, final String name, final boolean fromDisk) {
    115115                super(name);
    116116                this.data = data;
     
    133133         * Draw nodes last to overlap the segments they belong to.
    134134         */
    135         @Override public void paint(Graphics g, MapView mv) {
    136                 SimplePaintVisitor visitor = new SimplePaintVisitor(g, mv);
    137                 for (OsmPrimitive osm : data.segments)
     135        @Override public void paint(final Graphics g, final MapView mv) {
     136                final SimplePaintVisitor visitor = new SimplePaintVisitor(g, mv);
     137                for (final OsmPrimitive osm : data.segments)
    138138                        if (!osm.deleted)
    139139                                osm.visit(visitor);
    140                 for (OsmPrimitive osm : data.ways)
     140                for (final OsmPrimitive osm : data.ways)
    141141                        if (!osm.deleted)
    142142                                osm.visit(visitor);
    143                 for (OsmPrimitive osm : data.nodes)
     143                for (final OsmPrimitive osm : data.nodes)
    144144                        if (!osm.deleted)
    145145                                osm.visit(visitor);
    146                 for (OsmPrimitive osm : data.getSelected())
     146                for (final OsmPrimitive osm : data.getSelected())
    147147                        if (!osm.deleted)
    148148                                osm.visit(visitor);
    149                 Main.main.getMapFrame().conflictDialog.paintConflicts(g, mv);
     149                Main.map.conflictDialog.paintConflicts(g, mv);
    150150        }
    151151
     
    156156        }
    157157
    158         @Override public void mergeFrom(Layer from) {
     158        @Override public void mergeFrom(final Layer from) {
    159159                final MergeVisitor visitor = new MergeVisitor(data);
    160                 for (OsmPrimitive osm : ((OsmDataLayer)from).data.allPrimitives())
     160                for (final OsmPrimitive osm : ((OsmDataLayer)from).data.allPrimitives())
    161161                        osm.visit(visitor);
    162162                visitor.fixReferences();
    163163                if (visitor.conflicts.isEmpty())
    164164                        return;
    165                 ConflictDialog dlg = Main.main.getMapFrame().conflictDialog;
     165                final ConflictDialog dlg = Main.map.conflictDialog;
    166166                dlg.add(visitor.conflicts);
    167                 JOptionPane.showMessageDialog(Main.main, "There were conflicts during import.");
     167                JOptionPane.showMessageDialog(Main.parent, "There were conflicts during import.");
    168168                if (!dlg.isVisible())
    169169                        dlg.action.actionPerformed(new ActionEvent(this, 0, ""));
    170170        }
    171171
    172         @Override public boolean isMergable(Layer other) {
     172        @Override public boolean isMergable(final Layer other) {
    173173                return other instanceof OsmDataLayer;
    174174        }
    175175
    176         @Override public void visitBoundingBox(BoundingXYVisitor v) {
    177                 for (Node n : data.nodes)
     176        @Override public void visitBoundingBox(final BoundingXYVisitor v) {
     177                for (final Node n : data.nodes)
    178178                        if (!n.deleted)
    179179                                v.visit(n);
     
    184184         * primitives in the command as modified.
    185185         */
    186         public void add(Command c) {
     186        public void add(final Command c) {
    187187                c.executeCommand();
    188188                commands.add(c);
    189189                redoCommands.clear();
    190                 // TODO: Replace with listener scheme
    191                 Main.main.undoAction.setEnabled(true);
    192                 Main.main.redoAction.setEnabled(false);
    193190                setModified(true);
    194                 for (CommandQueueListener l : listenerCommands)
    195                         l.commandChanged();
     191                fireCommandsChanged();
    196192        }
    197193
     
    202198                if (commands.isEmpty())
    203199                        return;
    204                 Command c = commands.removeLast();
     200                final Command c = commands.removeLast();
    205201                c.undoCommand();
    206202                redoCommands.push(c);
    207203                //TODO: Replace with listener scheme
    208                 Main.main.undoAction.setEnabled(!commands.isEmpty());
    209                 Main.main.redoAction.setEnabled(true);
    210                 if (commands.isEmpty())
    211204                        setModified(uploadedModified);
    212205                Main.ds.clearSelection();
    213                 for (CommandQueueListener l : listenerCommands)
    214                         l.commandChanged();
     206                fireCommandsChanged();
    215207        }
    216208        /**
     
    220212                if (redoCommands.isEmpty())
    221213                        return;
    222                 Command c = redoCommands.pop();
     214                final Command c = redoCommands.pop();
    223215                c.executeCommand();
    224216                commands.add(c);
    225                 //TODO: Replace with listener scheme
    226                 Main.main.undoAction.setEnabled(true);
    227                 Main.main.redoAction.setEnabled(!redoCommands.isEmpty());
    228217                setModified(true);
    229                 for (CommandQueueListener l : listenerCommands)
    230                         l.commandChanged();
     218                fireCommandsChanged();
    231219        }
    232220
     
    240228         *              saved to disk instead.
    241229         */
    242         public void cleanData(Collection<OsmPrimitive> processed, boolean dataAdded) {
     230        public void cleanData(final Collection<OsmPrimitive> processed, boolean dataAdded) {
    243231                redoCommands.clear();
    244232                commands.clear();
     
    246234                // if uploaded, clean the modified flags as well
    247235                if (processed != null) {
    248                         Set<OsmPrimitive> processedSet = new HashSet<OsmPrimitive>(processed);
    249                         for (Iterator<Node> it = data.nodes.iterator(); it.hasNext();)
     236                        final Set<OsmPrimitive> processedSet = new HashSet<OsmPrimitive>(processed);
     237                        for (final Iterator<Node> it = data.nodes.iterator(); it.hasNext();)
    250238                                cleanIterator(it, processedSet);
    251                         for (Iterator<Segment> it = data.segments.iterator(); it.hasNext();)
     239                        for (final Iterator<Segment> it = data.segments.iterator(); it.hasNext();)
    252240                                cleanIterator(it, processedSet);
    253                         for (Iterator<Way> it = data.ways.iterator(); it.hasNext();)
     241                        for (final Iterator<Way> it = data.ways.iterator(); it.hasNext();)
    254242                                cleanIterator(it, processedSet);
    255243                }
     
    263251                uploadedModified = fromDisk && processed != null && dataAdded;
    264252                setModified(uploadedModified);
    265                 //TODO: Replace with listener scheme
    266                 Main.main.undoAction.setEnabled(false);
    267                 Main.main.redoAction.setEnabled(false);
    268         }
     253                fireCommandsChanged();
     254        }
     255
     256        public void fireCommandsChanged() {
     257            for (final CommandQueueListener l : listenerCommands)
     258                        l.commandChanged(commands.size(), redoCommands.size());
     259    }
    269260
    270261        /**
     
    276267         *              If the object in the iterator is not in the list, nothing will be changed on it.
    277268         */
    278         private void cleanIterator(Iterator<? extends OsmPrimitive> it, Collection<OsmPrimitive> processed) {
    279                 OsmPrimitive osm = it.next();
     269        private void cleanIterator(final Iterator<? extends OsmPrimitive> it, final Collection<OsmPrimitive> processed) {
     270                final OsmPrimitive osm = it.next();
    280271                if (!processed.remove(osm))
    281272                        return;
     
    289280        }
    290281
    291         public void setModified(boolean modified) {
     282        public void setModified(final boolean modified) {
    292283                if (modified == this.modified)
    293284                        return;
    294285                this.modified = modified;
    295                 for (ModifiedChangedListener l : listenerModified)
     286                for (final ModifiedChangedListener l : listenerModified)
    296287                        l.modifiedChanged(modified, this);
    297288        }
     
    300291         * @return The number of not-deleted primitives in the list.
    301292         */
    302         private int undeletedSize(Collection<? extends OsmPrimitive> list) {
     293        private int undeletedSize(final Collection<? extends OsmPrimitive> list) {
    303294                int size = 0;
    304                 for (OsmPrimitive osm : list)
     295                for (final OsmPrimitive osm : list)
    305296                        if (!osm.deleted)
    306297                                size++;
     
    309300
    310301        @Override public Object getInfoComponent() {
    311                 DataCountVisitor counter = new DataCountVisitor();
    312                 for (OsmPrimitive osm : data.allPrimitives())
     302                final DataCountVisitor counter = new DataCountVisitor();
     303                for (final OsmPrimitive osm : data.allPrimitives())
    313304                        osm.visit(counter);
    314                 JPanel p = new JPanel(new GridBagLayout());
     305                final JPanel p = new JPanel(new GridBagLayout());
    315306                p.add(new JLabel(name+" consists of:"), GBC.eol());
    316307                for (int i = 0; i < counter.normal.length; ++i) {
     
    323314        }
    324315
    325         @Override public void addMenuEntries(JPopupMenu menu) {
     316        @Override public void addMenuEntries(final JPopupMenu menu) {
    326317                menu.add(new JMenuItem(new SaveAction()));
    327318                menu.add(new JMenuItem(new GpxExportAction(this)));
  • src/org/openstreetmap/josm/gui/layer/RawGpsDataLayer.java

    r86 r98  
    5454                super(name);
    5555                this.data = data;
    56                 Main.pref.addPreferenceChangedListener(new PreferenceChangedListener(){
    57                         public void preferenceChanged(String key, String newValue) {
    58                                 if (Main.main.getMapFrame() != null && (key.equals("drawRawGpsLines") || key.equals("forceRawGpsLines")))
    59                                         Main.main.getMapFrame().repaint();
    60                         }
    61                 });
     56                Main.pref.listener.add(new PreferenceChangedListener(){
     57                public void preferenceChanged(String key, String newValue) {
     58                        if (Main.map != null && (key.equals("drawRawGpsLines") || key.equals("forceRawGpsLines")))
     59                                Main.map.repaint();
     60                }
     61        });
    6262        }
    6363
     
    137137                                JColorChooser c = new JColorChooser(ColorHelper.html2color(col));
    138138                                Object[] options = new Object[]{"OK", "Cancel", "Default"};
    139                                 int answer = JOptionPane.showOptionDialog(Main.main, c, "Choose a color", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
     139                                int answer = JOptionPane.showOptionDialog(Main.parent, c, "Choose a color", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
    140140                                switch (answer) {
    141141                                case 0:
     
    148148                                        break;
    149149                                }
    150                                 Main.main.repaint();
     150                                Main.map.repaint();
    151151                        }
    152152                });
  • src/org/openstreetmap/josm/io/OsmConnection.java

    r92 r98  
    6666                        warning.setFont(warning.getFont().deriveFont(Font.ITALIC));
    6767                        p.add(warning, GBC.eol());
    68                         int choice = JOptionPane.showConfirmDialog(Main.main, p, "Enter Password", JOptionPane.OK_CANCEL_OPTION);
     68                        int choice = JOptionPane.showConfirmDialog(Main.parent, p, "Enter Password", JOptionPane.OK_CANCEL_OPTION);
    6969                        if (choice == JOptionPane.CANCEL_OPTION) {
    7070                                authCancelled = true;
  • src/org/openstreetmap/josm/tools/BugReportExceptionHandler.java

    r71 r98  
    2828        public void uncaughtException(Thread t, Throwable e) {
    2929                e.printStackTrace();
    30                 if (Main.main != null) {
     30                if (Main.parent != null) {
    3131                        Object[] options = new String[]{"Do nothing", "Report Bug"};
    32                         int answer = JOptionPane.showOptionDialog(Main.main, "An unexpected exception occoured.\n\n" +
     32                        int answer = JOptionPane.showOptionDialog(Main.parent, "An unexpected exception occoured.\n\n" +
    3333                                        "This is always a coding error. If you are running the latest\n" +
    3434                                        "version of JOSM, please consider be kind and file a bug report.",
     
    6969                                        p.add(new JScrollPane(info), GBC.eop());
    7070
    71                                         JOptionPane.showMessageDialog(Main.main, p);
     71                                        JOptionPane.showMessageDialog(Main.parent, p);
    7272                                } catch (Exception e1) {
    7373                                        e1.printStackTrace();
  • src/org/openstreetmap/josm/tools/TileCache.java

    r81 r98  
    1515import org.openstreetmap.josm.Main;
    1616import org.openstreetmap.josm.data.Bounds;
    17 import org.openstreetmap.josm.data.Preferences;
    1817import org.openstreetmap.josm.data.coor.EastNorth;
    1918import org.openstreetmap.josm.data.coor.LatLon;
     
    153152     */
    154153    public synchronized Image get(final int tileId, final int zoom) {
    155         final File cacheDir = new File(Main.pref.get("cache.directory", Preferences.getPreferencesDir()+"cache")+"/"+Main.proj.getCacheDirectoryName()+"/"+zoom);
     154        final File cacheDir = new File(Main.pref.get("cache.directory", Main.pref.getPreferencesDir()+"cache")+"/"+Main.proj.getCacheDirectoryName()+"/"+zoom);
    156155        if (!cache.containsKey(zoom)) {
    157156            HashMap<Integer, Image> map = new HashMap<Integer, Image>();
     
    189188                            map.put(tileId, loading);
    190189                            currentlyLoading.remove(tileId*256+zoom);
    191                             Main.main.repaint();
     190                            Main.map.repaint();
    192191                        } catch (Exception e) {
    193192                            e.printStackTrace();
Note: See TracChangeset for help on using the changeset viewer.