private JToggleButton addToggleButton(Action a) { JToggleButton tb = new JToggleButton((String) a.getValue(Action.NAME), null); tb.setEnabled(a.isEnabled()); tb.setToolTipText((String) a.getValue(Action.SHORT_DESCRIPTION)); tb.setAction(a); add(tb); return tb; }
public JToggleButton addToggleAction(IToggleAction action) { JToggleButton tglBtn = new JToggleButton(); tglBtn.setAction(action); super.add(tglBtn); action.getToggleComponentHolder().addToggleableComponent(tglBtn); initialiseButton(action, tglBtn); return tglBtn; }
public JToggleButton createButton(String name, ImageIcon icon) { JToggleButton button = new JToggleButton() { @Override public void paintComponent(Graphics g) { if (!isSelected()) { super.paintComponent(g); setForeground(Theme.TEXT_COLOR.darker()); return; } g.setColor(new Color(0x666666)); setForeground(Theme.TEXT_COLOR); g.fillRect(0, 0, getWidth(), getHeight()); super.paintComponent(g); } }; button.setIconTextGap(8); button.setContentAreaFilled(false); button.setFocusPainted(false); button.setBorder( BorderFactory.createCompoundBorder( BorderFactory.createMatteBorder(0, 0, 1, 0, new Color(0x454545)), BorderFactory.createMatteBorder(0, 0, 1, 0, new Color(0x333333)))); button.setHorizontalAlignment(SwingConstants.CENTER); button.setVerticalAlignment(SwingConstants.CENTER); button.setHorizontalTextPosition(SwingConstants.CENTER); button.setVerticalTextPosition(SwingConstants.BOTTOM); button.setForeground(Theme.TEXT_COLOR.darker()); button.setMinimumSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT)); button.setMaximumSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT)); button.setPreferredSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT)); button.setAction( new AbstractAction(name, icon) { @Override public void actionPerformed(ActionEvent e) { switchToPage(e.getActionCommand()); } }); buttonGroup.add(button); return button; }
private void configure() { fRotation = LEFT; fButtonDelegate = new JToggleButton() { public String getText() { return null; } public boolean isEnabled() { if (JVerticalToggleButton.this != null) { return JVerticalToggleButton.this.isEnabled(); } return super.isEnabled(); } public boolean isSelected() { if (JVerticalToggleButton.this != null) { return JVerticalToggleButton.this.isSelected(); } return super.isSelected(); } public boolean isFocusPainted() { if (JVerticalToggleButton.this != null) { return JVerticalToggleButton.this.isFocusPainted(); } return super.isFocusPainted(); } public boolean isContentAreaFilled() { if (JVerticalToggleButton.this != null) { return JVerticalToggleButton.this.isContentAreaFilled(); } return super.isContentAreaFilled(); } public boolean isBorderPainted() { if (JVerticalToggleButton.this != null) { return JVerticalToggleButton.this.isBorderPainted(); } return super.isBorderPainted(); } public Border getBorder() { if (JVerticalToggleButton.this != null) { return JVerticalToggleButton.this.getBorder(); } return super.getBorder(); } public boolean isOpaque() { if (JVerticalToggleButton.this != null) { return JVerticalToggleButton.this.isOpaque(); } return super.isOpaque(); } public Color getBackground() { if (JVerticalToggleButton.this != null) { return JVerticalToggleButton.this.getBackground(); } return super.getBackground(); } public Icon getIcon() { return null; } public Icon getPressedIcon() { return null; } public Icon getSelectedIcon() { return null; } public Icon getRolloverIcon() { return null; } public Icon getRolloverSelectedIcon() { return null; } public Icon getDisabledIcon() { return null; } }; fLabelDelegate = new JLabel() { public String getText() { if (JVerticalToggleButton.this != null) { return JVerticalToggleButton.this.getText(); } return super.getText(); } public Color getForeground() { if (JVerticalToggleButton.this != null) { return JVerticalToggleButton.this.getForeground(); } return super.getForeground(); } public boolean isEnabled() { if (JVerticalToggleButton.this != null) { return JVerticalToggleButton.this.isEnabled(); } return super.isEnabled(); } public int getIconTextGap() { if (JVerticalToggleButton.this != null) { return JVerticalToggleButton.this.getIconTextGap(); } return super.getIconTextGap(); } public int getVerticalAlignment() { if (JVerticalToggleButton.this != null) { return JVerticalToggleButton.this.getVerticalAlignment(); } return super.getVerticalAlignment(); } public int getVerticalTextPosition() { if (JVerticalToggleButton.this != null) { return JVerticalToggleButton.this.getVerticalTextPosition(); } return super.getVerticalTextPosition(); } public int getHorizontalAlignment() { if (JVerticalToggleButton.this != null) { return JVerticalToggleButton.this.getHorizontalAlignment(); } return super.getHorizontalAlignment(); } public int getHorizontalTextPosition() { if (JVerticalToggleButton.this != null) { return JVerticalToggleButton.this.getHorizontalTextPosition(); } return super.getHorizontalTextPosition(); } public Border getBorder() { return null; } public int getMnemonic() { if (JVerticalToggleButton.this != null) { return JVerticalToggleButton.this.getMnemonic(); } return -1; } public int getDisplayedMnemonicIndex() { if (JVerticalToggleButton.this != null) { return JVerticalToggleButton.this.getDisplayedMnemonicIndex(); } return super.getDisplayedMnemonicIndex(); } private Insets insets = new Insets(0, 0, 0, 0); public Insets getInsets() { if (JVerticalToggleButton.this != null) { return super.getInsets(); } Border b = JVerticalToggleButton.this.getBorder(); Insets minsets = JVerticalToggleButton.this.getMargin(); insets.left = minsets.left; insets.top = minsets.top; insets.right = minsets.right; insets.bottom = minsets.bottom; if (b != null) { Insets binsets = b.getBorderInsets(JVerticalToggleButton.this); insets.left += binsets.left; insets.top += binsets.top; insets.right += binsets.right; insets.bottom += binsets.bottom; } return insets; } public Icon getIcon() { if (JVerticalToggleButton.this != null) { return super.getIcon(); } ButtonModel model = JVerticalToggleButton.this.getModel(); Icon subIcon = null; if (!model.isEnabled()) { if (model.isSelected()) { subIcon = getDisabledSelectedIcon(); } else { subIcon = getDisabledIcon(); } } else if (model.isPressed() && model.isArmed()) { subIcon = getPressedIcon(); } else if (isRolloverEnabled() && model.isRollover()) { if (model.isSelected()) { subIcon = getRolloverSelectedIcon(); } else { subIcon = getRolloverIcon(); } } else if (model.isSelected()) { subIcon = getSelectedIcon(); } if (subIcon == null) subIcon = JVerticalToggleButton.this.getIcon(); return subIcon; } public Icon getDisabledIcon() { return JVerticalToggleButton.this.getDisabledIcon(); } }; fLabelDelegate.setOpaque(false); // we paint our own border fButtonDelegate.setBorderPainted(false); fButtonDelegate.setModel(getModel()); fRenderer = new CellRendererPane(); fRenderer.add(fButtonDelegate); fRenderer.add(fLabelDelegate); fPreferredSize = new Dimension(); fMinimumSize = new Dimension(); fMaximumSize = new Dimension(); Action action = getAction(); if (action != null) { fButtonDelegate.setAction(action); } }
private void initEditor() { ApplicationContext c = Application.getInstance(RoutingDemo.class).getContext(); ActionMap appActionMap = c.getActionMap(RoutingDemo.getApplication()); ActionMap editorActionMap = c.getActionMap(EditorController.getInstance()); ActionMap simulationActionMap = c.getActionMap(SimulationController.getInstance()); ResourceMap fileRm = c.getResourceMap(DocumentController.class); ActionMap fileActionMap = c.getActionMap(DocumentController.getInstance()); btnNew = new JButton(); btnNew.setAction(fileActionMap.get("newFileAction")); add(btnNew); btnLoad = new JButton(); btnLoad.setAction(fileActionMap.get("loadFileAction")); add(btnLoad); btnReload = new JButton(); btnReload.setAction(fileActionMap.get("reloadFileAction")); add(btnReload); btnSave = new JButton(); btnSave.setAction(fileActionMap.get("saveFileAction")); add(btnSave); btnSaveAs = new JButton(); btnSaveAs.setAction(fileActionMap.get("saveFileAsAction")); add(btnSaveAs); btnClose = new JButton(); btnClose.setAction(fileActionMap.get("closeFileAction")); add(btnClose); btnExit = new JButton(); btnExit.setAction(appActionMap.get("quit")); btnExit.setText(""); btnExit.setIcon(fileRm.getImageIcon("quitAction.Action.icon")); add(btnExit); addSeparator(); btngGroup = new ButtonGroup(); btnSelection = new JToggleButton(); btnSelection.setAction(editorActionMap.get("setSelectionEditorStateAction")); btnSelection.setText(""); btnSelection.setIcon(fileRm.getImageIcon("selectionAction.Action.icon")); btnSelection.setSelected(true); btngGroup.add(btnSelection); add(btnSelection); btnAddNode = new JToggleButton(); btnAddNode.setAction(editorActionMap.get("setAddNodeEditorStateAction")); btnAddNode.setText(""); btnAddNode.setIcon(fileRm.getImageIcon("addPointAction.Action.icon")); btngGroup.add(btnAddNode); add(btnAddNode); btnAddEdge = new JToggleButton(); btnAddEdge.setAction(editorActionMap.get("setAddEdgeEditorStateAction")); btnAddEdge.setText(""); btngGroup.add(btnAddEdge); btnAddEdge.setIcon(fileRm.getImageIcon("addEdgeAction.Action.icon")); add(btnAddEdge); btnSetProperties = new JToggleButton(); btnSetProperties.setAction(editorActionMap.get("setSetPropertiesEditorStateAction")); btnSetProperties.setText(""); btngGroup.add(btnSetProperties); btnSetProperties.setIcon(fileRm.getImageIcon("setPropertiesAction.Action.icon")); add(btnSetProperties); btnSimulate = new JButton(); btnSimulate.setAction(simulationActionMap.get("showSimulationDialogAction")); btnSimulate.setText(""); btngGroup.add(btnSimulate); btnSimulate.setIcon(fileRm.getImageIcon("simulateAction.Action.icon")); add(btnSimulate); }