/** creates the menu and tool items */ protected void createMenuAndToolItems() { // creating the listener to the menu and tool items ActionListener listener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { notifyDrawingMode(); if (e.getSource().equals(shapeCreatorMenuItem)) { shapeCreatorToolItem.removeActionListener(this); shapeCreatorToolItem.setSelected(true); shapeCreatorToolItem.addActionListener(this); } } }; // getting the icons for the items shapeCreatorIcon = ResourcesManager.getIcon(shapeModuleId, false); shapeCreatorDisabledIcon = ResourcesManager.getIcon(shapeModuleId, true); // creating the menu item shapeCreatorMenuItem = new JMenuItem(itemLabel, shapeCreatorIcon); shapeCreatorMenuItem.setDisabledIcon(shapeCreatorDisabledIcon); shapeCreatorMenuItem.addActionListener(listener); shapeCreatorMenuItem.setEnabled(false); // creating the tool item shapeCreatorToolItem = new JToggleButton(shapeCreatorIcon); shapeCreatorToolItem.setDisabledIcon(shapeCreatorDisabledIcon); shapeCreatorToolItem.setToolTipText(itemToolTip); shapeCreatorToolItem.addActionListener(listener); shapeCreatorToolItem.setEnabled(false); // adding the listener to the switches between the svg handles final HandlesManager svgHandleManager = Editor.getEditor().getHandlesManager(); svgHandleManager.addHandlesListener( new HandlesListener() { @Override public void handleChanged(SVGHandle currentHandle, Set<SVGHandle> handles) { boolean isDrawingEnabled = isDrawingEnabled(currentHandle); shapeCreatorMenuItem.setEnabled(isDrawingEnabled); shapeCreatorToolItem.setEnabled(isDrawingEnabled); SelectionInfoManager selectionManager = Editor.getEditor().getSelectionManager(); if (selectionManager.getDrawingShape() != null && selectionManager.getDrawingShape().equals(AbstractShape.this)) { selectionManager.setToRegularMode(); } } }); }
/** * Constructs a toolbar button for the given action and returns it. * * @param action The action to create a toolbar button for. * @param toggle If set to <code>true</code>, indicates that a <code>JToggleButton</code> shall be * returned rather than a <code>JButton</code>. * @return The according <code>AbstractButton</code>. */ public static AbstractButton createToolbarButton(Action action, boolean toggle) { AbstractButton butt = null; if (action instanceof ViewAction) { if (((ViewAction) action).getView().isMultipleInstancePerSessionElementAllowed()) { butt = new JButton(action); } else { butt = new JToggleButton(action); } butt.setText(null); ((ViewAction) action).addButton(butt); } if (butt == null) { if (toggle) { butt = new JButton(action); } else { butt = new JButton(action /*(Icon) action.getValue( Action.SMALL_ICON )*/); } butt.setText(null); action.putValue("button", butt); if (action instanceof ViewAction) { ((ViewAction) action).addButton(butt); butt.setDisabledIcon(SPACER); } else { action.addPropertyChangeListener( new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { if ("enabled".equals(e.getPropertyName())) { ((AbstractButton) ((Action) e.getSource()).getValue("button")) .setEnabled(((Boolean) e.getNewValue()).booleanValue()); } } }); } } // butt.addActionListener( action ); butt.setEnabled(action.isEnabled()); butt.setMaximumSize(new Dimension(22, 22)); butt.setToolTipText((String) action.getValue("toolTipText")); butt.setMargin(new Insets(2, 2, 2, 2)); butt.setFocusable(false); return butt; }
protected void initialiseButton(Action action, AbstractButton btn) { if (btn != null) { btn.setRequestFocusEnabled(false); btn.setText(""); String tt = null; if (action != null) { tt = (String) action.getValue(Action.SHORT_DESCRIPTION); } btn.setToolTipText(tt != null ? tt : ""); if (action != null) { Icon icon = getIconFromAction(action, BaseAction.IBaseActionPropertyNames.ROLLOVER_ICON); if (icon != null) { btn.setRolloverIcon(icon); btn.setRolloverSelectedIcon(icon); } icon = getIconFromAction(action, BaseAction.IBaseActionPropertyNames.DISABLED_ICON); if (icon != null) { btn.setDisabledIcon(icon); } } } }