source: josm/src/org/openstreetmap/josm/gui/Main.java@ 17

Last change on this file since 17 was 17, checked in by imi, 21 years ago
  • added Layer support
  • added support for raw GPS data
  • fixed tooltips
  • added options for loading gpx files
File size: 4.5 KB
Line 
1// Licence: GPL
2package org.openstreetmap.josm.gui;
3
4import java.awt.BorderLayout;
5import java.awt.Container;
6
7import javax.swing.JFrame;
8import javax.swing.JMenu;
9import javax.swing.JMenuBar;
10import javax.swing.JOptionPane;
11import javax.swing.JPanel;
12import javax.swing.JToolBar;
13import javax.swing.UIManager;
14
15import org.openstreetmap.josm.actions.ExitAction;
16import org.openstreetmap.josm.actions.OpenGpxAction;
17import org.openstreetmap.josm.actions.PreferencesAction;
18import org.openstreetmap.josm.actions.SaveGpxAction;
19import org.openstreetmap.josm.data.Preferences;
20import org.openstreetmap.josm.data.Preferences.PreferencesException;
21
22/**
23 * Main window class consisting of the mainframe MDI application.
24 *
25 * @author imi
26 */
27public class Main extends JFrame {
28
29 /**
30 * Global application window. Use this as JOPtionPane-parent to center on application.
31 */
32 public static Main main;
33
34 /**
35 * Global application preferences
36 */
37 public final static Preferences pref = new Preferences();
38
39 /**
40 * The main panel.
41 */
42 private Container panel;
43 /**
44 * The name of the current loaded mapFrame
45 */
46 private String name;
47 /**
48 * The mapFrame currently loaded.
49 */
50 private MapFrame mapFrame;
51
52 /**
53 * Construct an main frame, ready sized and operating. Does not
54 * display the frame.
55 */
56 public Main() {
57 super("Java Open Street Map - Editor");
58 setLayout(new BorderLayout());
59 panel = new JPanel(new BorderLayout());
60 getContentPane().add(panel, BorderLayout.CENTER);
61 setSize(1000,740); // some strange default size
62 setExtendedState(MAXIMIZED_BOTH); // some platform are able to maximize
63
64 // creating actions
65 OpenGpxAction openGpxAction = new OpenGpxAction();
66 SaveGpxAction saveGpxAction = new SaveGpxAction();
67 ExitAction exitAction = new ExitAction();
68 PreferencesAction preferencesAction = new PreferencesAction();
69
70 // creating menu
71 JMenuBar mainMenu = new JMenuBar();
72 setJMenuBar(mainMenu);
73
74 JMenu fileMenu = new JMenu("Files");
75 fileMenu.setMnemonic('F');
76 fileMenu.add(openGpxAction);
77 fileMenu.add(saveGpxAction);
78 fileMenu.addSeparator();
79 fileMenu.add(exitAction);
80 mainMenu.add(fileMenu);
81
82 JMenu editMenu = new JMenu("Edit");
83 editMenu.setMnemonic('E');
84 editMenu.add(preferencesAction);
85 mainMenu.add(editMenu);
86
87 // creating toolbar
88 JToolBar toolBar = new JToolBar();
89 toolBar.setFloatable(false);
90 toolBar.add(openGpxAction);
91 toolBar.add(saveGpxAction);
92 toolBar.addSeparator();
93 toolBar.add(preferencesAction);
94
95 getContentPane().add(toolBar, BorderLayout.NORTH);
96 }
97
98 /**
99 * Main application Startup
100 * @param args No parameters accepted.
101 */
102 public static void main(String[] args) {
103 setupUiDefaults();
104
105 // load preferences
106 String errMsg = null;
107 try {
108 pref.load();
109 } catch (PreferencesException e1) {
110 e1.printStackTrace();
111 errMsg = "Preferences could not be loaded. Write default preference file to '"+Preferences.getPreferencesFile()+"'.";
112 try {
113 pref.save();
114 } catch (PreferencesException e) {
115 e.printStackTrace();
116 errMsg = "Preferences could not be loaded. Reverting to default.";
117 }
118 }
119 if (errMsg != null)
120 JOptionPane.showMessageDialog(null, errMsg);
121
122 try {
123 UIManager.setLookAndFeel(pref.laf.getClassName());
124 } catch (Exception e) {
125 e.printStackTrace();
126 }
127
128 main = new Main();
129 main.setDefaultCloseOperation(EXIT_ON_CLOSE);
130 main.setVisible(true);
131 }
132
133
134 /**
135 * Set the main's mapframe. If a changed old mapFrame is already set,
136 * ask the user whether he want to save, discard or abort. If the user
137 * aborts, nothing happens.
138 */
139 public void setMapFrame(String name, MapFrame mapFrame) {
140 //TODO: Check for changes and ask user
141 this.name = name;
142 if (this.mapFrame != null)
143 this.mapFrame.setVisible(false);
144 this.mapFrame = mapFrame;
145 panel.setVisible(false);
146 panel.removeAll();
147 if (mapFrame != null) {
148 mapFrame.fillPanel(panel);
149 panel.setVisible(true);
150 mapFrame.setVisible(true);
151 }
152 }
153 /**
154 * @return Returns the name.
155 */
156 public String getNameOfLoadedMapFrame() {
157 return name;
158 }
159 /**
160 * @return Returns the mapFrame.
161 */
162 public MapFrame getMapFrame() {
163 return mapFrame;
164 }
165
166
167 /**
168 * Sets some icons to the ui.
169 */
170 private static void setupUiDefaults() {
171 UIManager.put("OptionPane.okIcon", ImageProvider.get("ok"));
172 UIManager.put("OptionPane.yesIcon", UIManager.get("OptionPane.okIcon"));
173 UIManager.put("OptionPane.cancelIcon", ImageProvider.get("cancel"));
174 UIManager.put("OptionPane.noIcon", UIManager.get("OptionPane.cancelIcon"));
175 }
176}
Note: See TracBrowser for help on using the repository browser.