Changeset 10340 in josm
- Timestamp:
- 2016-06-08T09:33:20+02:00 (9 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/Main.java
r10288 r10340 9 9 import java.awt.GridBagLayout; 10 10 import java.awt.Window; 11 import java.awt.event.ComponentEvent;12 import java.awt.event.ComponentListener;13 11 import java.awt.event.KeyEvent; 14 12 import java.awt.event.WindowAdapter; … … 47 45 import javax.swing.InputMap; 48 46 import javax.swing.JComponent; 49 import javax.swing.JFrame;50 47 import javax.swing.JOptionPane; 51 48 import javax.swing.JPanel; … … 121 118 import org.openstreetmap.josm.tools.Shortcut; 122 119 import org.openstreetmap.josm.tools.Utils; 123 import org.openstreetmap.josm.tools.WindowGeometry;124 120 125 121 /** … … 563 559 564 560 /** 565 * Constructs new {@code Main} object. A lot of global variables are initialized here. 561 * Constructs new {@code Main} object. 562 * @see #initialize() 566 563 */ 567 564 public Main() { 568 565 main = this; 566 } 567 568 /** 569 * Initializes the main object. A lot of global variables are initialized here. 570 * @since 10340 571 */ 572 public void initialize() { 569 573 isOpenjdk = System.getProperty("java.vm.name").toUpperCase(Locale.ENGLISH).indexOf("OPENJDK") != -1; 570 574 fileWatcher.start(); … … 581 585 @Override 582 586 public void initialize() { 583 contentPanePrivate.add(panel, BorderLayout.CENTER); 584 panel.add(gettingStarted, BorderLayout.CENTER); 585 menu = new MainMenu(); 587 initializeMainWindow(); 586 588 } 587 589 }.call(); … … 715 717 } 716 718 719 /** 720 * Called once at startup to initialize the main window content. 721 * Should set {@link #menu} 722 */ 723 protected void initializeMainWindow() { 724 // can be implementd by subclasses 725 } 726 717 727 private abstract static class InitializationTask implements Callable<Void> { 718 728 … … 936 946 */ 937 947 public static final JPanel panel = new JPanel(new BorderLayout()); 938 939 protected static volatile WindowGeometry geometry;940 protected static int windowState = JFrame.NORMAL;941 948 942 949 private final CommandQueueListener redoUndoListener = new CommandQueueListener() { … … 1016 1023 } 1017 1024 1018 geometry = WindowGeometry.mainWindow("gui.geometry",1019 args.containsKey(Option.GEOMETRY) ? args.get(Option.GEOMETRY).iterator().next() : null,1020 !args.containsKey(Option.NO_MAXIMIZE) && Main.pref.getBoolean("gui.maximized", false));1021 1025 } 1022 1026 … … 1107 1111 public static boolean exitJosm(boolean exit, int exitCode) { 1108 1112 if (Main.saveUnsavedModifications()) { 1109 worker.shutdown(); 1110 ImageProvider.shutdown(false); 1111 JCSCacheManager.shutdown(); 1112 if (geometry != null) { 1113 geometry.remember("gui.geometry"); 1114 } 1115 if (map != null) { 1116 map.rememberToggleDialogWidth(); 1117 } 1118 pref.put("gui.maximized", (windowState & JFrame.MAXIMIZED_BOTH) != 0); 1119 // Remove all layers because somebody may rely on layerRemoved events (like AutosaveTask) 1120 if (Main.isDisplayingMapView()) { 1121 Collection<Layer> layers = new ArrayList<>(getLayerManager().getLayers()); 1122 for (Layer l: layers) { 1123 Main.main.removeLayer(l); 1124 } 1125 } 1126 try { 1127 pref.saveDefaults(); 1128 } catch (IOException ex) { 1129 Main.warn(tr("Failed to save default preferences.")); 1130 } 1131 worker.shutdownNow(); 1132 ImageProvider.shutdown(true); 1113 Main.main.shutdown(); 1133 1114 1134 1115 if (exit) { … … 1138 1119 } 1139 1120 return false; 1121 } 1122 1123 protected void shutdown() { 1124 worker.shutdown(); 1125 ImageProvider.shutdown(false); 1126 JCSCacheManager.shutdown(); 1127 if (map != null) { 1128 map.rememberToggleDialogWidth(); 1129 } 1130 // Remove all layers because somebody may rely on layerRemoved events (like AutosaveTask) 1131 if (Main.isDisplayingMapView()) { 1132 Collection<Layer> layers = new ArrayList<>(getLayerManager().getLayers()); 1133 for (Layer l: layers) { 1134 Main.main.removeLayer(l); 1135 } 1136 } 1137 try { 1138 pref.saveDefaults(); 1139 } catch (IOException ex) { 1140 Main.warn(tr("Failed to save default preferences.")); 1141 } 1142 worker.shutdownNow(); 1143 ImageProvider.shutdown(true); 1140 1144 } 1141 1145 … … 1287 1291 platform = new PlatformHookUnixoid(); 1288 1292 } 1289 }1290 1291 private static class WindowPositionSizeListener extends WindowAdapter implements ComponentListener {1292 @Override1293 public void windowStateChanged(WindowEvent e) {1294 Main.windowState = e.getNewState();1295 }1296 1297 @Override1298 public void componentHidden(ComponentEvent e) {1299 // Do nothing1300 }1301 1302 @Override1303 public void componentMoved(ComponentEvent e) {1304 handleComponentEvent(e);1305 }1306 1307 @Override1308 public void componentResized(ComponentEvent e) {1309 handleComponentEvent(e);1310 }1311 1312 @Override1313 public void componentShown(ComponentEvent e) {1314 // Do nothing1315 }1316 1317 private static void handleComponentEvent(ComponentEvent e) {1318 Component c = e.getComponent();1319 if (c instanceof JFrame && c.isVisible()) {1320 if (Main.windowState == JFrame.NORMAL) {1321 Main.geometry = new WindowGeometry((JFrame) c);1322 } else {1323 Main.geometry.fixScreen((JFrame) c);1324 }1325 }1326 }1327 }1328 1329 protected static void addListener() {1330 parent.addComponentListener(new WindowPositionSizeListener());1331 ((JFrame) parent).addWindowStateListener(new WindowPositionSizeListener());1332 1293 } 1333 1294 -
trunk/src/org/openstreetmap/josm/gui/MainApplication.java
r10296 r10340 6 6 7 7 import java.awt.Dimension; 8 import java.awt.Image;9 import java.awt.Toolkit;10 import java.awt.event.WindowAdapter;11 import java.awt.event.WindowEvent;12 8 import java.io.File; 13 9 import java.io.IOException; … … 33 29 import java.util.Collection; 34 30 import java.util.EnumMap; 35 import java.util.LinkedList;36 31 import java.util.List; 37 32 import java.util.Locale; … … 41 36 import java.util.concurrent.Callable; 42 37 43 import javax.swing.JFrame;44 38 import javax.swing.JOptionPane; 45 39 import javax.swing.RepaintManager; … … 70 64 import org.openstreetmap.josm.tools.HttpClient; 71 65 import org.openstreetmap.josm.tools.I18n; 72 import org.openstreetmap.josm.tools.ImageProvider;73 66 import org.openstreetmap.josm.tools.OsmUrlToBounds; 74 67 import org.openstreetmap.josm.tools.PlatformHookWindows; 75 68 import org.openstreetmap.josm.tools.Utils; 69 import org.openstreetmap.josm.tools.WindowGeometry; 76 70 import org.openstreetmap.josm.tools.bugreport.BugReportExceptionHandler; 77 71 … … 86 80 public class MainApplication extends Main { 87 81 82 private MainFrame mainFrame; 83 88 84 /** 89 * Constructs a new {@code MainApplication}. 85 * Constructs a new {@code MainApplication} without a window. 90 86 */ 91 87 public MainApplication() { 92 // Allow subclassing (see JOSM.java) 88 // Allow subclassing (see JOSM.java) 89 this(null); 93 90 } 94 91 … … 96 93 * Constructs a main frame, ready sized and operating. Does not display the frame. 97 94 * @param mainFrame The main JFrame of the application 95 * @since 10340 98 96 */ 99 public MainApplication(JFrame mainFrame) { 100 addListener(); 101 mainFrame.setContentPane(contentPanePrivate); 102 mainFrame.setJMenuBar(menu); 103 geometry.applySafe(mainFrame); 104 List<Image> l = new LinkedList<>(); 105 l.add(ImageProvider.get("logo_16x16x32").getImage()); 106 l.add(ImageProvider.get("logo_16x16x8").getImage()); 107 l.add(ImageProvider.get("logo_32x32x32").getImage()); 108 l.add(ImageProvider.get("logo_32x32x8").getImage()); 109 l.add(ImageProvider.get("logo_48x48x32").getImage()); 110 l.add(ImageProvider.get("logo_48x48x8").getImage()); 111 l.add(ImageProvider.get("logo").getImage()); 112 mainFrame.setIconImages(l); 113 mainFrame.addWindowListener(new WindowAdapter() { 114 @Override 115 public void windowClosing(final WindowEvent arg0) { 116 Main.exitJosm(true, 0); 117 } 118 }); 119 mainFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); 97 public MainApplication(MainFrame mainFrame) { 98 this.mainFrame = mainFrame; 99 } 100 101 @Override 102 protected void initializeMainWindow() { 103 if (mainFrame != null) { 104 mainFrame.initialize(); 105 106 menu = mainFrame.getMenu(); 107 } else { 108 // required for running some tests. 109 menu = new MainMenu(); 110 } 111 } 112 113 @Override 114 protected void shutdown() { 115 mainFrame.storeState(); 116 super.shutdown(); 120 117 } 121 118 … … 397 394 I18n.setupLanguageFonts(); 398 395 399 final JFrame mainFrame = new JFrame(tr("Java OpenStreetMap Editor")); 396 WindowGeometry geometry = WindowGeometry.mainWindow("gui.geometry", 397 args.containsKey(Option.GEOMETRY) ? args.get(Option.GEOMETRY).iterator().next() : null, 398 !args.containsKey(Option.NO_MAXIMIZE) && Main.pref.getBoolean("gui.maximized", false)); 399 final MainFrame mainFrame = new MainFrame(contentPanePrivate, geometry); 400 400 Main.parent = mainFrame; 401 401 … … 464 464 monitor.indeterminateSubTask(tr("Creating main GUI")); 465 465 final Main main = new MainApplication(mainFrame); 466 main.initialize(); 466 467 467 468 if (!skipLoadingPlugins) { … … 483 484 boolean maximized = Main.pref.getBoolean("gui.maximized", false); 484 485 if ((!args.containsKey(Option.NO_MAXIMIZE) && maximized) || args.containsKey(Option.MAXIMIZE)) { 485 if (Toolkit.getDefaultToolkit().isFrameStateSupported(JFrame.MAXIMIZED_BOTH)) { 486 Main.windowState = JFrame.MAXIMIZED_BOTH; 487 mainFrame.setExtendedState(Main.windowState); 488 } else { 489 Main.debug("Main window: maximizing not supported"); 490 } 486 mainFrame.setMaximized(true); 491 487 } 492 488 if (main.menu.fullscreenToggleAction != null) { -
trunk/src/org/openstreetmap/josm/gui/MainMenu.java
r10228 r10340 633 633 634 634 /** 635 * Constructs a new {@code MainMenu}. 636 */ 637 public MainMenu() { 635 * Initialize the main menu. 636 * @since 10340 637 */ 638 public void initialize() { 638 639 moreToolsMenu.setVisible(false); 639 640 dataMenu.setVisible(false); -
trunk/src/org/openstreetmap/josm/gui/MapView.java
r10332 r10340 35 35 import javax.swing.InputMap; 36 36 import javax.swing.JComponent; 37 import javax.swing.JFrame;38 37 import javax.swing.JPanel; 39 38 … … 91 90 */ 92 91 public class MapView extends NavigatableComponent 93 implements PropertyChangeListener, PreferenceChangedListener, OsmDataLayer.LayerStateChangeListener,92 implements PropertyChangeListener, PreferenceChangedListener, 94 93 LayerManager.LayerChangeListener, MainLayerManager.ActiveLayerChangeListener { 95 94 /** … … 587 586 } 588 587 589 boolean isOsmDataLayer = layer instanceof OsmDataLayer;590 if (isOsmDataLayer) {591 ((OsmDataLayer) layer).addLayerStateChangeListener(this);592 }593 594 588 layer.addPropertyChangeListener(this); 595 589 Main.addProjectionChangeListener(layer); … … 674 668 public void layerRemoving(LayerRemoveEvent e) { 675 669 Layer layer = e.getRemovedLayer(); 676 if (layer instanceof OsmDataLayer) {677 ((OsmDataLayer) layer).removeLayerPropertyChangeListener(this);678 }679 670 680 671 Main.removeProjectionChangeListener(layer); … … 1081 1072 } 1082 1073 AudioPlayer.reset(); 1083 refreshTitle();1084 1074 repaint(); 1085 1075 } … … 1164 1154 repaint(); 1165 1155 } 1166 } else if (evt.getPropertyName().equals(OsmDataLayer.REQUIRES_SAVE_TO_DISK_PROP)1167 || evt.getPropertyName().equals(OsmDataLayer.REQUIRES_UPLOAD_TO_SERVER_PROP)) {1168 OsmDataLayer layer = (OsmDataLayer) evt.getSource();1169 if (layer == getEditLayer()) {1170 refreshTitle();1171 }1172 1156 } 1173 1157 } … … 1176 1160 * Sets the title of the JOSM main window, adding a star if there are dirty layers. 1177 1161 * @see Main#parent 1178 */ 1162 * @deprecated Replaced by {@link MainFrame#refreshTitle()}. The {@link MainFrame} should handle this by itself. 1163 */ 1164 @Deprecated 1179 1165 protected void refreshTitle() { 1180 1166 if (Main.parent != null) { 1181 OsmDataLayer editLayer = layerManager.getEditLayer(); 1182 boolean dirty = editLayer != null && 1183 (editLayer.requiresSaveToFile() || (editLayer.requiresUploadToServer() && !editLayer.isUploadDiscouraged())); 1184 ((JFrame) Main.parent).setTitle((dirty ? "* " : "") + tr("Java OpenStreetMap Editor")); 1185 ((JFrame) Main.parent).getRootPane().putClientProperty("Window.documentModified", dirty); 1167 ((MainFrame) Main.parent).refreshTitle(); 1186 1168 } 1187 1169 } … … 1213 1195 synchronized (temporaryLayers) { 1214 1196 temporaryLayers.clear(); 1215 }1216 }1217 1218 @Override1219 public void uploadDiscouragedChanged(OsmDataLayer layer, boolean newValue) {1220 if (layer == layerManager.getEditLayer()) {1221 refreshTitle();1222 1197 } 1223 1198 } -
trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r10300 r10340 269 269 270 270 /** 271 * Removes a layer propertychange listener271 * Removes a layer state change listener 272 272 * 273 273 * @param listener the listener. Ignored if null or already registered. 274 274 * @since 5519 275 */ 275 * @deprecated Method name contains a typo, use {@link #removeLayerStateChangeListener(LayerStateChangeListener)}. 276 */ 277 @Deprecated 276 278 public void removeLayerPropertyChangeListener(LayerStateChangeListener listener) { 279 removeLayerStateChangeListener(listener); 280 } 281 282 /** 283 * Removes a layer state change listener 284 * 285 * @param listener the listener. Ignored if null or already registered. 286 * @since 10340 287 */ 288 public void removeLayerStateChangeListener(LayerStateChangeListener listener) { 277 289 layerStateChangeListeners.remove(listener); 278 290 } -
trunk/test/unit/org/openstreetmap/josm/JOSMFixture.java
r10235 r10340 119 119 } 120 120 if (Main.main == null) { 121 new MainApplication(); 121 new MainApplication().initialize(); 122 122 } 123 123 if (Main.map == null) { -
trunk/test/unit/org/openstreetmap/josm/MainTest.java
r10222 r10340 7 7 import static org.junit.Assert.assertTrue; 8 8 9 import java.awt.Dimension;10 import java.awt.Point;11 9 import java.util.Collection; 12 10 … … 15 13 import org.openstreetmap.josm.Main.DownloadParamType; 16 14 import org.openstreetmap.josm.gui.MainApplication; 17 import org.openstreetmap.josm.tools.WindowGeometry;18 15 19 16 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; … … 52 49 Main.preConstructorInit(MainApplication.buildCommandLineArgumentMap(new String[0])); 53 50 Main.preConstructorInit(MainApplication.buildCommandLineArgumentMap(new String[]{"--geometry=400x300+10+5", "--no-maximize"})); 54 assertEquals(new WindowGeometry(new Point(10, 5), new Dimension(400, 300)), Main.geometry); 51 //assertEquals(new WindowGeometry(new Point(10, 5), new Dimension(400, 300)), Main.geometry); // FIXME see #12927 55 52 } 56 53
Note:
See TracChangeset
for help on using the changeset viewer.