/** * Sets a mnemomic for the specified button. * * @param b button * @param mnem mnemonics that have already been assigned */ public static void setMnemonic(final AbstractButton b, final StringBuilder mnem) { // do not set mnemonics for Mac! Alt+key used for special characters. if (Prop.MAC) return; // find and assign unused mnemomic final String label = b.getText(); final int ll = label.length(); for (int l = 0; l < ll; l++) { final char ch = Character.toLowerCase(label.charAt(l)); if (!letter(ch) || mnem.indexOf(Character.toString(ch)) != -1) continue; b.setMnemonic(ch); mnem.append(ch); break; } }
protected void paintButtonPressed(Graphics g, AbstractButton b) { if (b.isContentAreaFilled()) { Dimension size = b.getSize(); g.setColor(getSelectColor()); g.fillRect(0, 0, size.width, size.height); } }
public void keyReleased(KeyEvent e) { int code = e.getKeyCode(); if (code == KeyEvent.VK_SPACE) { AbstractButton button = (AbstractButton) e.getSource(); button.putClientProperty(SPACEBAR_PRESSED, Boolean.FALSE); } }
public void mouseExited(MouseEvent e) { Component component = e.getComponent(); if (component instanceof AbstractButton) { AbstractButton button = (AbstractButton) component; button.setBorderPainted(false); } }
public void setShdPopupOnBtnClick(boolean shdPopup) { this.shdPopup = shdPopup; if (shdPopup) { main.addActionListener(pl); } else { main.removeActionListener(pl); } }
protected void installListeners(AbstractButton b) { BasicButtonListener listener = createButtonListener(b); if (listener != null) { b.addMouseListener(listener); b.addMouseMotionListener(listener); b.addFocusListener(listener); b.addPropertyChangeListener(listener); b.addChangeListener(listener); } }
protected void uninstallListeners(AbstractButton b) { BasicButtonListener listener = getButtonListener(b); if (listener != null) { b.removeMouseListener(listener); b.removeMouseMotionListener(listener); b.removeFocusListener(listener); b.removeChangeListener(listener); b.removePropertyChangeListener(listener); } }
public void mouseEntered(MouseEvent evt) { if (evt.getSource() instanceof AbstractButton) { AbstractButton button = (AbstractButton) evt.getSource(); Action action = button.getAction(); if (action != null) { String message = (String) action.getValue("LongDescription"); setMessage(message); } } }
/** Returns the dimensions required to display the icon and label. */ private Dimension getContentSize(AbstractButton button) { Rectangle scratchIconRect = new Rectangle(); Rectangle scratchTextRect = new Rectangle(); Rectangle scratchViewRect = new Rectangle(Short.MAX_VALUE, Short.MAX_VALUE); FontMetrics fm = button.getFontMetrics(button.getFont()); SwingUtilities.layoutCompoundLabel( fm, button.getText(), button.getIcon(), button.getVerticalAlignment(), button.getHorizontalAlignment(), button.getVerticalTextPosition(), button.getHorizontalTextPosition(), scratchViewRect, scratchIconRect, scratchTextRect, button.getIconTextGap()); Insets textInsets = getTextPadding(); scratchTextRect.y -= textInsets.top; scratchTextRect.x -= textInsets.left; scratchTextRect.width += textInsets.left + textInsets.right; scratchTextRect.height += textInsets.top + textInsets.bottom; Insets iconInsets = getIconPadding(); scratchIconRect.y -= iconInsets.top; scratchIconRect.x -= iconInsets.left; scratchIconRect.width += iconInsets.left + iconInsets.right; scratchIconRect.height += iconInsets.top + iconInsets.bottom; Rectangle sum = getSum(new Rectangle[] {scratchIconRect, scratchTextRect}); return new Dimension(sum.width, sum.height); }
public void keyPressed(KeyEvent e) { int code = e.getKeyCode(); if (code == KeyEvent.VK_SPACE) { AbstractButton button = (AbstractButton) e.getSource(); Boolean wasPressed = (Boolean) button.getClientProperty(SPACEBAR_PRESSED); if (wasPressed == null || wasPressed.booleanValue() == false) { button.putClientProperty(SPACEBAR_PRESSED, Boolean.TRUE); button.doClick(); } } }
/** Returns the ButtonListener for the passed in Button, or null if one could not be found. */ private BasicButtonListener getButtonListener(AbstractButton b) { MouseMotionListener[] listeners = b.getMouseMotionListeners(); if (listeners != null) { for (int counter = 0; counter < listeners.length; counter++) { if (listeners[counter] instanceof BasicButtonListener) { return (BasicButtonListener) listeners[counter]; } } } return null; }
public void addActions(JPanel buttPanel) { AbstractAction netcdfAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { String location = ds.getLocation(); if (location == null) location = "test"; int pos = location.lastIndexOf("."); if (pos > 0) location = location.substring(0, pos); String filename = fileChooser.chooseFilenameToSave(location + ".nc"); if (filename == null) return; writeNetCDF(filename); } }; BAMutil.setActionProperties(netcdfAction, "netcdf", "Write netCDF-3 file", false, 'S', -1); BAMutil.addActionToContainer(buttPanel, netcdfAction); AbstractAction ncstreamAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { String location = ds.getLocation(); if (location == null) location = "test"; int pos = location.lastIndexOf("."); if (pos > 0) location = location.substring(0, pos); String filename = fileChooser.chooseFilenameToSave(location + ".ncs"); if (filename == null) return; writeNcstream(filename); } }; BAMutil.setActionProperties(ncstreamAction, "netcdf", "Write ncstream file", false, 'S', -1); BAMutil.addActionToContainer(buttPanel, ncstreamAction); AbstractButton compareButton = BAMutil.makeButtcon("Select", "Compare to another file", false); compareButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { compareDataset(); } }); buttPanel.add(compareButton); AbstractAction attAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { showAtts(); } }; BAMutil.setActionProperties(attAction, "FontDecr", "global attributes", false, 'A', -1); BAMutil.addActionToContainer(buttPanel, attAction); }
private AbstractButton createButton( String text, ImageIcon icon, String toolTip, ActionListener actionListener) { AbstractButton button = new JButton(text, icon); button.setMaximumSize(buttonDimension); button.setPreferredSize(buttonDimension); if (toolTip != null) { button.setToolTipText(toolTip); } if (actionListener != null) { button.addActionListener(actionListener); } return button; }
/** * Enable/disable an AbstractAction * * @param actionName the key that maps this action in actionTable * @param b true to enable or false to disable the action */ public static synchronized void setActionSelected(final Integer actionKey, final boolean b) { Action aa = actionTable.get(actionKey); if (aa != null) { ArrayList<AbstractButton> list = toggleListTable.get(aa); if (list != null) { int size = list.size(); for (int i = 0; i < size; i++) { AbstractButton btn = (AbstractButton) list.get(i); btn.setSelected(b); } } } }
protected void installDefaults(AbstractButton b) { // load shared instance defaults String pp = getPropertyPrefix(); defaultTextShiftOffset = UIManager.getInt(pp + "textShiftOffset"); // set the following defaults on the button if (b.isContentAreaFilled()) { LookAndFeel.installProperty(b, "opaque", Boolean.TRUE); } else { LookAndFeel.installProperty(b, "opaque", Boolean.FALSE); } if (b.getMargin() == null || (b.getMargin() instanceof UIResource)) { b.setMargin(UIManager.getInsets(pp + "margin")); } LookAndFeel.installColorsAndFont(b, pp + "background", pp + "foreground", pp + "font"); LookAndFeel.installBorder(b, pp + "border"); Object rollover = UIManager.get(pp + "rollover"); if (rollover != null) { LookAndFeel.installProperty(b, "rolloverEnabled", rollover); } LookAndFeel.installProperty(b, "iconTextGap", new Integer(4)); }
/** * Returns one of the PAINT_FOCUS constants declared in this object. If PAINT_NO_FOCUS is used, * then this class automatically paints no focus. In that case a subclass would be responsible for * any rendering of focus. * * <p>If PAINT_FOCUS_OUTSIDE is used, then a few rings of focus are painted outside this component * under this component. The order of painting is: <br> * 1. Shadow Highlight <br> * 2. Focus <br> * 3. Background Fill <br> * 4. Stroke * * <p>If PAINT_FOCUS_INSIDE is used, then a few rings of focus are painted inside this component. * The order of painting is: <br> * 1. Shadow Highlight <br> * 2. Background Fill <br> * 3. Focus <br> * 4. Stroke * * <p>If PAINT_FOCUS_BOTH is used, then the focus appears both inside and outside the filled area. * The order of painting is: <br> * 1. Shadow Highlight <br> * 2. Background Fill <br> * 3. Stroke <br> * 4. Focus * * <p>By default this returns PAINT_FOCUS_OUTSIDE if a shape is defined, or if this button is in a * single row or column of buttons. (That is, if the horizontal or vertical position is "only"). * Otherwise this returns PAINT_FOCUS_INSIDE, because once you get to inner buttons the focus * <i>has</i> to be painted on the inside to remain visible. */ public PaintFocus getFocusPainting(AbstractButton button) { PaintFocus f = (PaintFocus) button.getClientProperty(PAINT_FOCUS_BEHAVIOR_KEY); if (f != null) return f; Shape shape = (Shape) button.getClientProperty(SHAPE); if (shape != null) return PaintFocus.OUTSIDE; int horizontalPosition = getHorizontalPosition(button); int verticalPosition = getVerticalPosition(button); if (!(horizontalPosition == POS_ONLY || verticalPosition == POS_ONLY)) { return PaintFocus.INSIDE; } return PaintFocus.OUTSIDE; }
/** * This checks to see if updateLayout() needs to be called. Generally this returns true if the * width, height, or segment position has changed. */ protected boolean isLayoutValid(AbstractButton button) { int horizontalPosition = getHorizontalPosition(button); int verticalPosition = getVerticalPosition(button); int width = button.getWidth(); int height = button.getHeight(); String key = width + " " + height + " " + horizontalPosition + " " + verticalPosition; String oldKey = (String) button.getClientProperty("FilledButtonUI.validationKey"); if (oldKey == null) return false; if (oldKey.equals(key)) return true; return false; }
public void propertyChange(PropertyChangeEvent evt) { String name = evt.getPropertyName(); if (name.equals(VERTICAL_POSITION) || name.equals(HORIZONTAL_POSITION) || name.equals(SHAPE) || name.equals("JButton.segmentPosition")) { // see Apple Tech Note 2196 AbstractButton button = (AbstractButton) evt.getSource(); ButtonUI ui = button.getUI(); if (ui instanceof FilledButtonUI) { FilledButtonUI s = (FilledButtonUI) ui; s.updateLayout(button, getButtonInfo(button)); button.invalidate(); button.repaint(); } } }
/** * Overrides <code>JComponent.removeNotify</code> to check if this button is currently set as the * default button on the <code>RootPane</code>, and if so, sets the <code>RootPane</code>'s * default button to <code>null</code> to ensure the <code>RootPane</code> doesn't hold onto an * invalid button reference. */ public void removeNotify() { JRootPane root = SwingUtilities.getRootPane(this); if (root != null && root.getDefaultButton() == this) { root.setDefaultButton(null); } super.removeNotify(); }
/** Update the icon in the run button */ private void updateRunButton() { if (stopIcon == null) { stopIcon = Resource.getIcon(getIcon("Pause"), true); startIcon = Resource.getIcon(getIcon("Play"), true); } if (startStopBtn != null) { boolean running = isRunning() && haveTimes(); if (running) { startStopBtn.setIcon(stopIcon); startStopBtn.setToolTipText("Stop animation"); } else { startStopBtn.setIcon(startIcon); startStopBtn.setToolTipText("Start animation"); } } }
protected void paintText(Graphics g, JComponent c, Rectangle textRect, String text) { AbstractButton b = (AbstractButton) c; ButtonModel model = b.getModel(); FontMetrics fm = SwingUtilities2.getFontMetrics(c, g); int mnemIndex = b.getDisplayedMnemonicIndex(); /* Draw the Text */ if (model.isEnabled()) { /** * paint the text normally */ g.setColor(b.getForeground()); } else { /** * paint the text disabled ** */ g.setColor(getDisabledTextColor()); } SwingUtilities2.drawStringUnderlineCharAt( c, g, text, mnemIndex, textRect.x, textRect.y + fm.getAscent()); }
/** * Update helper method. Gets the coordinates of the selected button. * * @param evt User mouse event. * @return int[] of two integers, y and x, or row and col. */ private int[] getButtonCoordinates(MouseEvent evt) { AbstractButton abstractButton = (AbstractButton) evt.getSource(); int y; int x = 0; outerloop: for (y = 0; y < ButtonGrid.length; y++) { for (x = 0; x < ButtonGrid[1].length; x++) { if (abstractButton.equals(ButtonGrid[y][x])) { break outerloop; // coordinates saved } } } int[] coordinates = {y, x}; return coordinates; }
protected void attachTo(Component jc) { if (extListener != null && extListener.accept(jc)) { extListener.startListeningTo(jc, extNotifier); listenedTo.add(jc); if (wizardPage.getMapKeyFor(jc) != null) { wizardPage.maybeUpdateMap(jc); } return; } if (isProbablyAContainer(jc)) { attachToHierarchyOf((Container) jc); } else if (jc instanceof JList) { listenedTo.add(jc); ((JList) jc).addListSelectionListener(this); } else if (jc instanceof JComboBox) { ((JComboBox) jc).addActionListener(this); } else if (jc instanceof JTree) { listenedTo.add(jc); ((JTree) jc).getSelectionModel().addTreeSelectionListener(this); } else if (jc instanceof JToggleButton) { ((AbstractButton) jc).addItemListener(this); } else if (jc instanceof JFormattedTextField) { // JFormattedTextField must be tested before JTextCompoent jc.addPropertyChangeListener("value", this); } else if (jc instanceof JTextComponent) { listenedTo.add(jc); ((JTextComponent) jc).getDocument().addDocumentListener(this); } else if (jc instanceof JColorChooser) { listenedTo.add(jc); ((JColorChooser) jc).getSelectionModel().addChangeListener(this); } else if (jc instanceof JSpinner) { ((JSpinner) jc).addChangeListener(this); } else if (jc instanceof JSlider) { ((JSlider) jc).addChangeListener(this); } else if (jc instanceof JTable) { listenedTo.add(jc); ((JTable) jc).getSelectionModel().addListSelectionListener(this); } else { if (logger.isLoggable(Level.FINE)) { logger.fine( "Don't know how to listen to a " + // NOI18N jc.getClass().getName()); } } if (accept(jc) && !(jc instanceof JPanel)) { jc.addPropertyChangeListener("name", this); if (wizardPage.getMapKeyFor(jc) != null) { wizardPage.maybeUpdateMap(jc); } } if (logger.isLoggable(Level.FINE) && accept(jc)) { logger.fine("Begin listening to " + jc); // NOI18N } }
@Override public void uninstallUI(JComponent c) { AbstractButton button = (AbstractButton) c; ButtonInfo info = getButtonInfo(button); button.removeMouseListener(info.basicListener); button.removeMouseMotionListener(info.basicListener); button.removeFocusListener(info.basicListener); button.removePropertyChangeListener(info.basicListener); button.removeChangeListener(info.basicListener); button.removeKeyListener(focusArrowListener); button.removeComponentListener(componentListener); button.removeKeyListener(keyArmingListener); button.removePropertyChangeListener(positionAndShapeListener); super.uninstallUI(c); }
/** * Handles the <tt>ActionEvent</tt>, when one of the tool bar buttons is clicked. * * @param e the <tt>ActionEvent</tt> that notified us */ public void actionPerformed(ActionEvent e) { AbstractButton button = (AbstractButton) e.getSource(); String buttonText = button.getName(); ChatPanel chatPanel = chatContainer.getCurrentChat(); if (buttonText.equals("previous")) { chatPanel.loadPreviousPageFromHistory(); } else if (buttonText.equals("next")) { chatPanel.loadNextPageFromHistory(); } else if (buttonText.equals("sendFile")) { SipCommFileChooser scfc = GenericFileDialog.create( null, "Send file...", SipCommFileChooser.LOAD_FILE_OPERATION, ConfigurationUtils.getSendFileLastDir()); File selectedFile = scfc.getFileFromDialog(); if (selectedFile != null) { ConfigurationUtils.setSendFileLastDir(selectedFile.getParent()); chatContainer.getCurrentChat().sendFile(selectedFile); } } else if (buttonText.equals("invite")) { ChatInviteDialog inviteDialog = new ChatInviteDialog(chatPanel); inviteDialog.setVisible(true); } else if (buttonText.equals("leave")) { ChatRoomWrapper chatRoomWrapper = (ChatRoomWrapper) chatPanel.getChatSession().getDescriptor(); ChatRoomWrapper leavedRoomWrapped = GuiActivator.getMUCService().leaveChatRoom(chatRoomWrapper); } else if (buttonText.equals("call")) { call(false, false); } else if (buttonText.equals("callVideo")) { call(true, false); } else if (buttonText.equals("desktop")) { call(true, true); } else if (buttonText.equals("options")) { GuiActivator.getUIService().getConfigurationContainer().setVisible(true); } else if (buttonText.equals("font")) chatPanel.showFontChooserDialog(); else if (buttonText.equals("createConference")) { chatPanel.showChatConferenceDialog(); } }
/** * Returns the baseline. * * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} * @see javax.swing.JComponent#getBaseline(int, int) * @since 1.6 */ public int getBaseline(JComponent c, int width, int height) { super.getBaseline(c, width, height); AbstractButton b = (AbstractButton) c; String text = b.getText(); if (text == null || "".equals(text)) { return -1; } FontMetrics fm = b.getFontMetrics(b.getFont()); layout(b, fm, width, height); return BasicHTML.getBaseline(b, textRect.y, fm.getAscent(), textRect.width, textRect.height); }
public void layoutComponents() { setLayout(new BorderLayout()); add(main, BorderLayout.CENTER); if (popperIsVisible) { if (getPopperButtonLocation() == RIGHT) { popper.setPreferredSize(new Dimension(14, main.getHeight())); add(popper, BorderLayout.EAST); } else if (getPopperButtonLocation() == BOTTOM) { popper.setPreferredSize(new Dimension(main.getWidth(), 14)); add(popper, BorderLayout.SOUTH); setPopperArrowDirection(DOWN); setPopupLocation(popper.getX(), popper.getY() + popper.getHeight() + 5); } } Utilities.updateView(this); }
public void setUseFlatUI(boolean b) { main.setContentAreaFilled(!b); main.setFocusPainted(!b); main.setBorderPainted(!b); main.setMargin(new Insets(1, 1, 1, 1)); popper.setContentAreaFilled(!b); popper.setFocusPainted(!b); popper.setBorderPainted(!b); popper.setMargin(new Insets(1, 1, 1, 1)); setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); setOpaque(false); MouseAdapter ma = new MouseAdapter() { public void mouseEntered(MouseEvent e) { main.setContentAreaFilled(true); main.setBackground(new Color(216, 240, 254)); // m.getMainButton().setForeground( Color.black ); setBorder(new LineBorder(new Color(200, 200, 200), 1)); setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); popper.setBackground(new Color(242, 242, 242)); popper.setContentAreaFilled(true); popper.setBorder(menu.getBorder()); } public void mouseExited(MouseEvent e) { main.setContentAreaFilled(false); // c.setForeground( Color.black ); setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); setCursor(Cursor.getDefaultCursor()); popper.setContentAreaFilled(false); popper.setBorder(null); } }; main.addMouseListener(ma); popper.addMouseListener(ma); }
/** * Sets the output text. * * @param out cached output */ public void setText(final ArrayOutput out) { final byte[] buf = out.buffer(); final int size = (int) out.size(); final byte[] chop = token(DOTS); if (out.finished() && size >= chop.length) { System.arraycopy(chop, 0, buf, size - chop.length, chop.length); } text.setText(buf, size); header.setText((out.finished() ? CHOPPED : "") + RESULT); home.setEnabled(gui.context.data() != null); }
protected void detachFrom(Component jc) { listenedTo.remove(jc); if (extListener != null && extListener.accept(jc)) { extListener.stopListeningTo(jc); } if (isProbablyAContainer(jc)) { detachFromHierarchyOf((Container) jc); } else if (jc instanceof JList) { ((JList) jc).removeListSelectionListener(this); } else if (jc instanceof JComboBox) { ((JComboBox) jc).removeActionListener(this); } else if (jc instanceof JTree) { ((JTree) jc).getSelectionModel().removeTreeSelectionListener(this); } else if (jc instanceof JToggleButton) { ((AbstractButton) jc).removeActionListener(this); } else if (jc instanceof JTextComponent) { } else if (jc instanceof JFormattedTextField) { // JFormattedTextField must be tested before JTextCompoent jc.removePropertyChangeListener("value", this); ((JTextComponent) jc).getDocument().removeDocumentListener(this); } else if (jc instanceof JColorChooser) { ((JColorChooser) jc).getSelectionModel().removeChangeListener(this); } else if (jc instanceof JSpinner) { ((JSpinner) jc).removeChangeListener(this); } else if (jc instanceof JSlider) { ((JSlider) jc).removeChangeListener(this); } else if (jc instanceof JTable) { ((JTable) jc).getSelectionModel().removeListSelectionListener(this); } if (accept(jc) && !(jc instanceof JPanel)) { jc.removePropertyChangeListener("name", this); Object key = wizardPage.getMapKeyFor(jc); if (key != null) { if (logger.isLoggable(Level.FINE)) { logger.fine( "Named component removed from hierarchy: " + // NOI18N key + ". Removing any corresponding " + // NOI18N "value from the wizard settings map."); // NOI18N } wizardPage.removeFromMap(key); } } if (logger.isLoggable(Level.FINE) && accept(jc)) { logger.fine("Stop listening to " + jc); // NOI18N } }