source: josm/src/org/openstreetmap/josm/Main.java@ 24

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