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

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

added mapmodes for adding and combining stuff. Reorganized images

File size: 4.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.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 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 // load preferences
104 String errMsg = null;
105 try {
106 pref.load();
107 } catch (PreferencesException e1) {
108 e1.printStackTrace();
109 errMsg = "Preferences could not be loaded. Write default preference file to '"+Preferences.getPreferencesFile()+"'.";
110 try {
111 pref.save();
112 } catch (PreferencesException e) {
113 e.printStackTrace();
114 errMsg = "Preferences could not be loaded. Reverting to default.";
115 }
116 }
117 if (errMsg != null)
118 JOptionPane.showMessageDialog(null, errMsg);
119
120 try {
121 UIManager.setLookAndFeel(pref.laf.getClassName());
122 } catch (Exception e) {
123 e.printStackTrace();
124 }
125
126 main = new Main();
127 main.setDefaultCloseOperation(EXIT_ON_CLOSE);
128 main.setVisible(true);
129 }
130
131
132 /**
133 * Set the main's mapframe. If a changed old mapFrame is already set,
134 * ask the user whether he want to save, discard or abort. If the user
135 * aborts, nothing happens.
136 */
137 public void setMapFrame(String name, MapFrame mapFrame) {
138 //TODO: Check for changes and ask user
139 this.name = name;
140 this.mapFrame = mapFrame;
141 panel.setVisible(false);
142 panel.removeAll();
143 panel.add(mapFrame, BorderLayout.CENTER);
144 panel.add(mapFrame.getToolBarActions(), BorderLayout.WEST);
145 panel.setVisible(true);
146 }
147 /**
148 * @return Returns the name.
149 */
150 public String getNameOfLoadedMapFrame() {
151 return name;
152 }
153 /**
154 * @return Returns the mapFrame.
155 */
156 public MapFrame getMapFrame() {
157 return mapFrame;
158 }
159
160}
Note: See TracBrowser for help on using the repository browser.