/** * 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 Dimension preferredLayoutSize(Container parent) { JToolBar tb = (JToolBar) parent; Insets insets = tb.getInsets(); Dimension dim = new Dimension(); SeaGlassContext context = getContext(tb); if (tb.getOrientation() == JToolBar.HORIZONTAL) { dim.width = tb.isFloatable() ? SeaGlassIcon.getIconWidth(handleIcon, context) : 0; Dimension compDim; for (int i = 0; i < tb.getComponentCount(); i++) { Component component = tb.getComponent(i); if (component.isVisible()) { compDim = component.getPreferredSize(); dim.width += compDim.width; dim.height = Math.max(dim.height, compDim.height); } } } else { dim.height = tb.isFloatable() ? SeaGlassIcon.getIconHeight(handleIcon, context) : 0; Dimension compDim; for (int i = 0; i < tb.getComponentCount(); i++) { Component component = tb.getComponent(i); if (component.isVisible()) { compDim = component.getPreferredSize(); dim.width = Math.max(dim.width, compDim.width); dim.height += compDim.height; } } } dim.width += insets.left + insets.right; dim.height += insets.top + insets.bottom; context.dispose(); return dim; }
private JToolBar removeUnnecessarySeparators(JToolBar toolBar) { Component component; int previousDeleted = -1; int nbComponents = toolBar.getComponentCount(); for (int i = 0; i < nbComponents; ) { component = toolBar.getComponent(i); if (toolBar.getComponent(i).getClass() == JSeparator.class) { if (i > previousDeleted) { toolBar.remove(component); nbComponents--; } else { i++; } } else { previousDeleted = ++i; } } if (nbComponents > 0) { component = toolBar.getComponent(toolBar.getComponentCount() - 1); if (component != null && component.getClass() == JSeparator.class) { toolBar.remove(component); } } return toolBar; }
/** * Habilita un componente de la barra de herramientas. * * @param posicion posición del elemento de la barra de herramientas que se quiere * habilitar.Entero del 0 al número de elementos. */ public static void habilitarComponenteBarraHerramientas(int posicion) { if (posicion < toolBar.getComponentCount()) { toolBar.getComponentAtIndex(posicion).setEnabled(true); toolBar.repaint(); } else { System.out.println("Te has salido del rango de componentes de la barra de herramientas"); } } // habilitarComponeneteBarraHerramientas
/** Process all loaded images. */ @Override protected void process(List<ThumbnailAction> chunks) { for (ThumbnailAction thumbAction : chunks) { JButton thumbButton = new JButton(thumbAction); // add the new button BEFORE the last glue // this centers the buttons in the toolbar buttonBar.add(thumbButton, buttonBar.getComponentCount() - 1); } }
/** * 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(); }
/** This method uninstalls listeners installed by the UI. */ protected void uninstallListeners() { if (toolBarFocusListener != null) { int count = toolBar.getComponentCount(); for (int i = 0; i < count; i++) toolBar.getComponent(i).removeFocusListener(toolBarFocusListener); toolBarFocusListener = null; } floatFrame.removeWindowListener(windowListener); windowListener = null; toolBar.removeContainerListener(toolBarContListener); toolBarContListener = null; toolBar.removeMouseMotionListener(dockingListener); toolBar.removeMouseListener(dockingListener); dockingListener = null; }
/** This method installs listeners for the JToolBar. */ protected void installListeners() { dockingListener = createDockingListener(); toolBar.addMouseListener(dockingListener); toolBar.addMouseMotionListener(dockingListener); propertyListener = createPropertyListener(); toolBar.addPropertyChangeListener(propertyListener); toolBarContListener = createToolBarContListener(); toolBar.addContainerListener(toolBarContListener); windowListener = createFrameListener(); floatFrame.addWindowListener(windowListener); toolBarFocusListener = createToolBarFocusListener(); if (toolBarFocusListener != null) { int count = toolBar.getComponentCount(); for (int i = 0; i < count; i++) toolBar.getComponent(i).addFocusListener(toolBarFocusListener); } }
/** * This method navigates in the given direction giving focus to the next component in the given * direction. * * @param direction The direction to give focus to. */ protected void navigateFocusedComp(int direction) { int count = toolBar.getComponentCount(); switch (direction) { case EAST: case SOUTH: if (focusedCompIndex >= 0 && focusedCompIndex < count) { int i = focusedCompIndex + 1; boolean focusRequested = false; // Find component to focus and request focus on it. while (i != focusedCompIndex && !focusRequested) { if (i >= count) i = 0; Component comp = toolBar.getComponentAtIndex(i++); if (comp != null && comp.isFocusable() && comp.isEnabled()) { comp.requestFocus(); focusRequested = true; } } } break; case WEST: case NORTH: if (focusedCompIndex >= 0 && focusedCompIndex < count) { int i = focusedCompIndex - 1; boolean focusRequested = false; // Find component to focus and request focus on it. while (i != focusedCompIndex && !focusRequested) { if (i < 0) i = count - 1; Component comp = toolBar.getComponentAtIndex(i--); if (comp != null && comp.isFocusable() && comp.isEnabled()) { comp.requestFocus(); focusRequested = true; } } } break; default: break; } }
/** * 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); }
public void layoutContainer(Container parent) { JToolBar tb = (JToolBar) parent; Insets insets = tb.getInsets(); boolean ltr = tb.getComponentOrientation().isLeftToRight(); SeaGlassContext context = getContext(tb); Component c; Dimension d; // JToolBar by default uses a somewhat modified BoxLayout as // its layout manager. For compatibility reasons, we want to // support Box "glue" as a way to move things around on the // toolbar. "glue" is represented in BoxLayout as a Box.Filler // with a minimum and preferred size of (0,0). // So what we do here is find the number of such glue fillers // and figure out how much space should be allocated to them. int glueCount = 0; for (int i = 0; i < tb.getComponentCount(); i++) { if (isGlue(tb.getComponent(i))) glueCount++; } if (tb.getOrientation() == JToolBar.HORIZONTAL) { int handleWidth = tb.isFloatable() ? SeaGlassIcon.getIconWidth(handleIcon, context) : 0; // Note: contentRect does not take insets into account // since it is used for determining the bounds that are // passed to paintToolBarContentBackground(). contentRect.x = ltr ? handleWidth : 0; contentRect.y = 0; contentRect.width = tb.getWidth() - handleWidth; contentRect.height = tb.getHeight(); // However, we do take the insets into account here for // the purposes of laying out the toolbar child components. int x = ltr ? handleWidth + insets.left : tb.getWidth() - handleWidth - insets.right; int baseY = insets.top; int baseH = tb.getHeight() - insets.top - insets.bottom; // we need to get the minimum width for laying things out // so that we can calculate how much empty space needs to // be distributed among the "glue", if any int extraSpacePerGlue = 0; if (glueCount > 0) { int minWidth = minimumLayoutSize(parent).width; extraSpacePerGlue = (tb.getWidth() - minWidth) / glueCount; if (extraSpacePerGlue < 0) extraSpacePerGlue = 0; } for (int i = 0; i < tb.getComponentCount(); i++) { c = tb.getComponent(i); if (c.isVisible()) { d = c.getPreferredSize(); int y, h; if (d.height >= baseH || c instanceof JSeparator) { // Fill available height y = baseY; h = baseH; } else { // Center component vertically in the available // space y = baseY + (baseH / 2) - (d.height / 2); h = d.height; } // if the component is a "glue" component then add to // its // width the extraSpacePerGlue it is due if (isGlue(c)) d.width += extraSpacePerGlue; c.setBounds(ltr ? x : x - d.width, y, d.width, h); x = ltr ? x + d.width : x - d.width; } } } else { int handleHeight = tb.isFloatable() ? SeaGlassIcon.getIconHeight(handleIcon, context) : 0; // See notes above regarding the use of insets contentRect.x = 0; contentRect.y = handleHeight; contentRect.width = tb.getWidth(); contentRect.height = tb.getHeight() - handleHeight; int baseX = insets.left; int baseW = tb.getWidth() - insets.left - insets.right; int y = handleHeight + insets.top; // we need to get the minimum height for laying things out // so that we can calculate how much empty space needs to // be distributed among the "glue", if any int extraSpacePerGlue = 0; if (glueCount > 0) { int minHeight = minimumLayoutSize(parent).height; extraSpacePerGlue = (tb.getHeight() - minHeight) / glueCount; if (extraSpacePerGlue < 0) extraSpacePerGlue = 0; } for (int i = 0; i < tb.getComponentCount(); i++) { c = tb.getComponent(i); if (c.isVisible()) { d = c.getPreferredSize(); int x, w; if (d.width >= baseW || c instanceof JSeparator) { // Fill available width x = baseX; w = baseW; } else { // Center component horizontally in the available // space x = baseX + (baseW / 2) - (d.width / 2); w = d.width; } // if the component is a "glue" component then add to // its // height the extraSpacePerGlue it is due if (isGlue(c)) d.height += extraSpacePerGlue; c.setBounds(x, y, w, d.height); y += d.height; } } } context.dispose(); }
/** * Create a toolbar containing the given tools (if any). * * @param template Conta */ protected void changeToolBar(JComponent[] template, IControlCenterPlugin selplugin) { // Setup the tool bar. if (toolbar == null) { toolbar = new JToolBar("Main Toolbar"); getContentPane().add(BorderLayout.NORTH, toolbar); // Add standard entries (after gap). toolbar.add(Box.createGlue()); toolcnt++; toolbar.addSeparator(); toolcnt++; // ButtonGroup bg = new ButtonGroup(); IControlCenterPlugin[] plugins = controlcenter.getPlugins(); for (int i = 0; i < plugins.length; i++) { final IControlCenterPlugin plugin = plugins[i]; // final JToggleButton button = new JToggleButton(new PluginAction(plugins[i])); final JButton button = new JButton(new PluginAction(plugins[i])); Icon ic = plugin.getToolIcon(selplugin.getName().equals(plugins[i].getName())); if (ic != null) button.setIcon(ic); else button.setText(plugins[i].getName()); button.setText("A"); button.putClientProperty("plugin", plugins[i]); button.setBorder(null); button.setText(null); button.setMinimumSize(BUTTON_DIM); button.setHorizontalAlignment(SwingConstants.CENTER); button.setVerticalAlignment(SwingConstants.CENTER); button.setToolTipText(plugins[i].getName()); button .getModel() .addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent e) { // System.out.println(plugin.getName()+" :"+button.isSelected()); button.setIcon(plugin.getToolIcon(button.isSelected())); } }); // if(plugins[i].getHelpID()!=null) // SHelp.setupHelp(button, plugins[i].getHelpID()); // bg.add(button); toolbar.add(button); toolcnt++; } toolbar.addSeparator(); toolcnt++; toolbar.add(new JadexLogoButton(toolbar)); toolcnt++; } else { while (toolbar.getComponentCount() > toolcnt) { // Component comp = toolbar.getComponent(0); toolbar.remove(0); // if(lasttoolbar!=null) // lasttoolbar.add(comp); } } for (int i = 0; template != null && i < template.length; i++) toolbar.add(template[i], i); // lasttoolbar = template; // Select plugins for (int i = 0; i < toolbar.getComponentCount(); i++) { JComponent comp = (JComponent) toolbar.getComponent(i); if (comp.getClientProperty("plugin") != null) { IControlCenterPlugin pl = (IControlCenterPlugin) comp.getClientProperty("plugin"); ((JButton) comp).setIcon(pl.getToolIcon(pl.equals(selplugin))); // ((JToggleButton)comp).setSelected(pluginname.equals(comp.getClientProperty("pluginname"))); } } toolbar.validate(); toolbar.repaint(); // If toolbar has been dropped out -> pack the window (hack???). Container root = toolbar; while (root.getParent() != null && !(root instanceof Window)) root = root.getParent(); if (root != null && !(root instanceof JFrame)) { ((Window) root).pack(); } }