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

Last change on this file since 19 was 19, checked in by imi, 19 years ago

added about dialog

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