/** * Called as some kind of destructor when the last layer has been removed. Delegates the call to * all Destroyables within this component (e.g. MapModes) */ public void destroy() { MapView.removeLayerChangeListener(this); dialogsPanel.destroy(); for (int i = 0; i < toolBarActions.getComponentCount(); ++i) { if (toolBarActions.getComponent(i) instanceof Destroyable) { ((Destroyable) toolBarActions.getComponent(i)).destroy(); } } for (int i = 0; i < toolBarToggle.getComponentCount(); ++i) { if (toolBarToggle.getComponent(i) instanceof Destroyable) { ((Destroyable) toolBarToggle.getComponent(i)).destroy(); } } // MapFrame gets destroyed when the last layer is removed, but the status line background // thread that collects the information doesn't get destroyed automatically. if (statusLine.thread != null) { try { statusLine.thread.interrupt(); } catch (Exception e) { e.printStackTrace(); } } mapView.destroy(); }
public void setDialogsPanelVisible(boolean visible) { rememberToggleDialogWidth(); dialogsPanel.setVisible(visible); splitPane.setDividerLocation( visible ? splitPane.getWidth() - Main.pref.getInteger("toggleDialogs.width", DEF_TOGGLE_DLG_WIDTH) : 0); splitPane.setDividerSize(visible ? 5 : 0); }
/** * Call this to add new toggle dialogs to the left button-list * * @param dlg The toggle dialog. It must not be in the list already. */ public IconToggleButton addToggleDialog(final ToggleDialog dlg, boolean isExpert) { final IconToggleButton button = new IconToggleButton(dlg.getToggleAction(), isExpert); button.setShowHideButtonListener(dlg); button.setInheritsPopupMenu(true); dlg.setButton(button); toolBarToggle.add(button); allDialogs.add(dlg); allDialogButtons.add(button); button.applyButtonHiddenPreferences(); if (dialogsPanel.initialized) { dialogsPanel.add(dlg); } return button; }
/** * Called as some kind of destructor when the last layer has been removed. Delegates the call to * all Destroyables within this component (e.g. MapModes) */ @Override public void destroy() { MapView.removeLayerChangeListener(this); dialogsPanel.destroy(); Main.pref.removePreferenceChangeListener(sidetoolbarPreferencesChangedListener); for (int i = 0; i < toolBarActions.getComponentCount(); ++i) { if (toolBarActions.getComponent(i) instanceof Destroyable) { ((Destroyable) toolBarActions.getComponent(i)).destroy(); } } for (int i = 0; i < toolBarToggle.getComponentCount(); ++i) { if (toolBarToggle.getComponent(i) instanceof Destroyable) { ((Destroyable) toolBarToggle.getComponent(i)).destroy(); } } statusLine.destroy(); mapView.destroy(); }
/** Remember the current width of the (possibly resized) toggle dialog area */ public void rememberToggleDialogWidth() { if (dialogsPanel.isVisible()) { Main.pref.putInteger( "toggleDialogs.width", splitPane.getWidth() - splitPane.getDividerLocation()); } }
/** * Replies the instance of a toggle dialog of type <code>type</code> managed by this map frame * * @param <T> * @param type the class of the toggle dialog, i.e. UserListDialog.class * @return the instance of a toggle dialog of type <code>type</code> managed by this map frame; * null, if no such dialog exists */ public <T> T getToggleDialog(Class<T> type) { return dialogsPanel.getToggleDialog(type); }
/** Open all ToggleDialogs that have their preferences property set. Close all others. */ public void initializeDialogsPane() { dialogsPanel.initialize(allDialogs); }
/** * Constructs a new {@code MapFrame}. * * @param contentPane The content pane used to register shortcuts in its {@link * javax.swing.InputMap} and {@link javax.swing.ActionMap} * @param viewportData the initial viewport of the map. Can be null, then the viewport is derived * from the layer data. */ public MapFrame(JPanel contentPane, ViewportData viewportData) { setSize(400, 400); setLayout(new BorderLayout()); mapView = new MapView(contentPane, viewportData); new FileDrop(mapView); splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true); leftPanel = new JPanel(); leftPanel.setLayout(new GridBagLayout()); leftPanel.add(mapView, GBC.std().fill()); splitPane.setLeftComponent(leftPanel); dialogsPanel = new DialogsPanel(splitPane); splitPane.setRightComponent(dialogsPanel); /** All additional space goes to the mapView */ splitPane.setResizeWeight(1.0); /** Some beautifications. */ splitPane.setDividerSize(5); splitPane.setBorder(null); splitPane.setUI( new BasicSplitPaneUI() { @Override public BasicSplitPaneDivider createDefaultDivider() { return new BasicSplitPaneDivider(this) { @Override public void setBorder(Border b) {} }; } }); // JSplitPane supports F6 and F8 shortcuts by default, but we need them for Audio actions splitPane .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) .put(KeyStroke.getKeyStroke(KeyEvent.VK_F6, 0), new Object()); splitPane .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) .put(KeyStroke.getKeyStroke(KeyEvent.VK_F8, 0), new Object()); add(splitPane, BorderLayout.CENTER); dialogsPanel.setLayout(new BoxLayout(dialogsPanel, BoxLayout.Y_AXIS)); dialogsPanel.setPreferredSize( new Dimension(Main.pref.getInteger("toggleDialogs.width", DEF_TOGGLE_DLG_WIDTH), 0)); dialogsPanel.setMinimumSize(new Dimension(24, 0)); mapView.setMinimumSize(new Dimension(10, 0)); // toolBarActions, map mode buttons addMapMode(new IconToggleButton(mapModeSelect = new SelectAction(this))); addMapMode(new IconToggleButton(new LassoModeAction(), true)); addMapMode(new IconToggleButton(mapModeDraw = new DrawAction(this))); addMapMode(new IconToggleButton(mapModeZoom = new ZoomAction(this))); addMapMode(new IconToggleButton(new DeleteAction(this), true)); addMapMode(new IconToggleButton(new ParallelWayAction(this), true)); addMapMode(new IconToggleButton(new ExtrudeAction(this), true)); addMapMode(new IconToggleButton(new ImproveWayAccuracyAction(Main.map), false)); toolBarActionsGroup.setSelected(allMapModeButtons.get(0).getModel(), true); toolBarActions.setFloatable(false); // toolBarToggles, toggle dialog buttons LayerListDialog.createInstance(this); addToggleDialog(LayerListDialog.getInstance()); addToggleDialog(propertiesDialog = new PropertiesDialog()); addToggleDialog(selectionListDialog = new SelectionListDialog()); addToggleDialog(relationListDialog = new RelationListDialog()); addToggleDialog(new CommandStackDialog()); addToggleDialog(new UserListDialog()); addToggleDialog(new HistoryDialog(), true); addToggleDialog(conflictDialog = new ConflictDialog()); addToggleDialog(validatorDialog = new ValidatorDialog()); addToggleDialog(filterDialog = new FilterDialog()); addToggleDialog(new ChangesetDialog(), true); addToggleDialog(new MapPaintDialog()); toolBarToggle.setFloatable(false); // status line below the map statusLine = new MapStatus(this); MapView.addLayerChangeListener(this); boolean unregisterTab = Shortcut.findShortcut(KeyEvent.VK_TAB, 0) != null; if (unregisterTab) { for (JComponent c : allDialogButtons) c.setFocusTraversalKeysEnabled(false); for (JComponent c : allMapModeButtons) c.setFocusTraversalKeysEnabled(false); } }
/** Remember the current width of the (possibly resized) toggle dialog area */ public void rememberToggleDialogWidth() { Main.pref.putInteger("toggleDialogs.width", dialogsPanel.getWidth()); }