Changeset 12637 in josm for trunk/src/org/openstreetmap/josm/gui/MainApplication.java
- Timestamp:
- 2017-08-24T23:29:01+02:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/MainApplication.java
r12636 r12637 46 46 import javax.swing.JComponent; 47 47 import javax.swing.JOptionPane; 48 import javax.swing.LookAndFeel; 48 49 import javax.swing.RepaintManager; 49 50 import javax.swing.SwingUtilities; 51 import javax.swing.UIManager; 52 import javax.swing.UnsupportedLookAndFeelException; 50 53 51 54 import org.jdesktop.swinghelper.debug.CheckThreadViolationRepaintManager; … … 74 77 import org.openstreetmap.josm.gui.layer.MainLayerManager; 75 78 import org.openstreetmap.josm.gui.layer.TMSLayer; 79 import org.openstreetmap.josm.gui.preferences.ToolbarPreferences; 80 import org.openstreetmap.josm.gui.preferences.display.LafPreference; 76 81 import org.openstreetmap.josm.gui.preferences.imagery.ImageryPreference; 77 82 import org.openstreetmap.josm.gui.preferences.map.MapPaintPreference; … … 98 103 import org.openstreetmap.josm.tools.HttpClient; 99 104 import org.openstreetmap.josm.tools.I18n; 105 import org.openstreetmap.josm.tools.ImageProvider; 100 106 import org.openstreetmap.josm.tools.Logging; 101 107 import org.openstreetmap.josm.tools.OpenBrowser; … … 127 133 */ 128 134 static MapFrame map; 135 136 /** 137 * The toolbar preference control to register new actions. 138 */ 139 static volatile ToolbarPreferences toolbar; 129 140 130 141 private final MainFrame mainFrame; … … 237 248 } else { 238 249 // required for running some tests. 239 panel = new MainPanel( MainApplication.getLayerManager());250 panel = new MainPanel(layerManager); 240 251 menu = new MainMenu(); 241 252 } … … 256 267 } 257 268 // Remove all layers because somebody may rely on layerRemoved events (like AutosaveTask) 258 getLayerManager().resetState();269 layerManager.resetState(); 259 270 super.shutdown(); 260 271 if (!GraphicsEnvironment.isHeadless()) { … … 289 300 return ((DrawAction) map.mapMode).getInProgressSelection(); 290 301 } else { 291 DataSet ds = getLayerManager().getEditDataSet();302 DataSet ds = layerManager.getEditDataSet(); 292 303 if (ds == null) return null; 293 304 return ds.getSelected(); … … 307 318 * Returns the main layer manager that is used by the map view. 308 319 * @return The layer manager. The value returned will never change. 309 * @since 12636 (as a replacement to {@code Main Application.getLayerManager()})320 * @since 12636 (as a replacement to {@code Main.getLayerManager()}) 310 321 */ 311 322 @SuppressWarnings("deprecation") … … 324 335 public static MapFrame getMap() { 325 336 return map; 337 } 338 339 /** 340 * Returns the toolbar preference control to register new actions. 341 * @return the toolbar preference control 342 * @since 12637 (as a replacement to {@code Main.toolbar}) 343 */ 344 public static ToolbarPreferences getToolbar() { 345 return toolbar; 326 346 } 327 347 … … 351 371 public static boolean exitJosm(boolean exit, int exitCode, SaveLayersDialog.Reason reason) { 352 372 final boolean proceed = Boolean.TRUE.equals(GuiHelper.runInEDTAndWaitAndReturn(() -> 353 SaveLayersDialog.saveUnsavedModifications( MainApplication.getLayerManager().getLayers(),373 SaveLayersDialog.saveUnsavedModifications(layerManager.getLayers(), 354 374 reason != null ? reason : SaveLayersDialog.Reason.EXIT))); 355 375 if (proceed) { … … 430 450 * @param argArray Command-line arguments 431 451 */ 452 @SuppressWarnings("deprecation") 432 453 public static void main(final String[] argArray) { 433 454 I18n.init(); … … 576 597 577 598 monitor.indeterminateSubTask(tr("Setting defaults")); 599 setupUIManager(); 600 toolbar = new ToolbarPreferences(); 601 Main.toolbar = toolbar; 578 602 preConstructorInit(); 579 603 … … 627 651 Logging.info("Enabled EDT checker, wrongful access to gui from non EDT thread will be printed to console"); 628 652 RepaintManager.setCurrentManager(new CheckThreadViolationRepaintManager()); 653 } 654 } 655 656 static void setupUIManager() { 657 String defaultlaf = platform.getDefaultStyle(); 658 String laf = LafPreference.LAF.get(); 659 try { 660 UIManager.setLookAndFeel(laf); 661 } catch (final NoClassDefFoundError | ClassNotFoundException e) { 662 // Try to find look and feel in plugin classloaders 663 Logging.trace(e); 664 Class<?> klass = null; 665 for (ClassLoader cl : PluginHandler.getResourceClassLoaders()) { 666 try { 667 klass = cl.loadClass(laf); 668 break; 669 } catch (ClassNotFoundException ex) { 670 Logging.trace(ex); 671 } 672 } 673 if (klass != null && LookAndFeel.class.isAssignableFrom(klass)) { 674 try { 675 UIManager.setLookAndFeel((LookAndFeel) klass.getConstructor().newInstance()); 676 } catch (ReflectiveOperationException ex) { 677 Logging.log(Logging.LEVEL_WARN, "Cannot set Look and Feel: " + laf + ": "+ex.getMessage(), ex); 678 } catch (UnsupportedLookAndFeelException ex) { 679 Logging.info("Look and Feel not supported: " + laf); 680 LafPreference.LAF.put(defaultlaf); 681 Logging.trace(ex); 682 } 683 } else { 684 Logging.info("Look and Feel not found: " + laf); 685 LafPreference.LAF.put(defaultlaf); 686 } 687 } catch (UnsupportedLookAndFeelException e) { 688 Logging.info("Look and Feel not supported: " + laf); 689 LafPreference.LAF.put(defaultlaf); 690 Logging.trace(e); 691 } catch (InstantiationException | IllegalAccessException e) { 692 Logging.error(e); 693 } 694 695 UIManager.put("OptionPane.okIcon", ImageProvider.get("ok")); 696 UIManager.put("OptionPane.yesIcon", UIManager.get("OptionPane.okIcon")); 697 UIManager.put("OptionPane.cancelIcon", ImageProvider.get("cancel")); 698 UIManager.put("OptionPane.noIcon", UIManager.get("OptionPane.cancelIcon")); 699 // Ensures caret color is the same than text foreground color, see #12257 700 // See http://docs.oracle.com/javase/8/docs/api/javax/swing/plaf/synth/doc-files/componentProperties.html 701 for (String p : Arrays.asList( 702 "EditorPane", "FormattedTextField", "PasswordField", "TextArea", "TextField", "TextPane")) { 703 UIManager.put(p+".caretForeground", UIManager.getColor(p+".foreground")); 629 704 } 630 705 }
Note:
See TracChangeset
for help on using the changeset viewer.