/** * Constructs a new {@code MapView}. * * @param contentPane The content pane used to register shortcuts in its {@link InputMap} and * {@link ActionMap} * @param viewportData the initial viewport of the map. Can be null, then the viewport is derived * from the layer data. */ public MapView(final JPanel contentPane, final ViewportData viewportData) { initialViewport = viewportData; Main.pref.addPreferenceChangeListener(this); final boolean unregisterTab = Shortcut.findShortcut(KeyEvent.VK_TAB, 0) != null; addComponentListener( new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { removeComponentListener(this); for (JComponent c : getMapNavigationComponents(MapView.this)) { MapView.this.add(c); } mapMover = new MapMover(MapView.this, contentPane); } }); // listend to selection changes to redraw the map DataSet.addSelectionListener(repaintSelectionChangedListener); // store the last mouse action this.addMouseMotionListener( new MouseMotionListener() { @Override public void mouseDragged(MouseEvent e) { mouseMoved(e); } @Override public void mouseMoved(MouseEvent e) { lastMEvent = e; } }); this.addMouseListener( new MouseAdapter() { @Override public void mousePressed(MouseEvent me) { // focus the MapView component when mouse is pressed inside it requestFocus(); } }); if (Shortcut.findShortcut(KeyEvent.VK_TAB, 0) != null) { setFocusTraversalKeysEnabled(false); } }
/** * Adds the map navigation components to a * * @param forMapView The map view to get the components for. * @return A list containing the correctly positioned map navigation components. */ public static List<? extends JComponent> getMapNavigationComponents(MapView forMapView) { MapSlider zoomSlider = new MapSlider(forMapView); zoomSlider.setBounds(3, 0, 114, 30); zoomSlider.setFocusTraversalKeysEnabled(Shortcut.findShortcut(KeyEvent.VK_TAB, 0) == null); MapScaler scaler = new MapScaler(forMapView); scaler.setLocation(10, 30); return Arrays.asList(zoomSlider, scaler); }
/** * Parse the toolbar preference setting and construct the toolbar GUI control. * * <p>Call this, if anything has changed in the toolbar settings and you want to refresh the * toolbar content (e.g. after registering actions in a plugin) */ public void refreshToolbarControl() { control.removeAll(); buttonActions.clear(); boolean unregisterTab = Shortcut.findShortcut(KeyEvent.VK_TAB, 0) != null; for (ActionDefinition action : getDefinedActions()) { if (action.isSeparator()) { control.addSeparator(); } else { final JButton b = addButtonAndShortcut(action); buttonActions.put(b, action); Icon i = action.getDisplayIcon(); if (i != null) { b.setIcon(i); } else { // hide action text if an icon is set later (necessary for delayed/background image // loading) action .getParametrizedAction() .addPropertyChangeListener( new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (Action.SMALL_ICON.equals(evt.getPropertyName())) { b.setHideActionText(evt.getNewValue() != null); } } }); } b.setInheritsPopupMenu(true); b.setFocusTraversalKeysEnabled(!unregisterTab); } } control.setFocusTraversalKeysEnabled(!unregisterTab); control.setVisible(control.getComponentCount() != 0); }
/** * 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); } }