/** * Gets the value of the <code>defaultButton</code> property, which if <code>true</code> means * that this button is the current default button for its <code>JRootPane</code>. Most look and * feels render the default button differently, and may potentially provide bindings to access the * default button. * * @return the value of the <code>defaultButton</code> property * @see JRootPane#setDefaultButton * @see #isDefaultCapable * @beaninfo description: Whether or not this button is the default button */ public boolean isDefaultButton() { JRootPane root = SwingUtilities.getRootPane(this); if (root != null) { return root.getDefaultButton() == this; } return false; }
/** * 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(); }
public void actionPerformed(ActionEvent e) { if (owner != null && SwingUtilities.getRootPane(owner) == root) { ButtonModel model = owner.getModel(); if (press) { model.setArmed(true); model.setPressed(true); } else { model.setPressed(false); } } }
/** * If inputComponent is non-null, the focus is requested on that, otherwise request focus on the * default value */ public void selectInitialValue(JOptionPane op) { if (inputComponent != null) inputComponent.requestFocus(); else { if (initialFocusComponent != null) initialFocusComponent.requestFocus(); if (initialFocusComponent instanceof JButton) { JRootPane root = SwingUtilities.getRootPane(initialFocusComponent); if (root != null) { root.setDefaultButton((JButton) initialFocusComponent); } } } }
/** * @param aEvent * @param aStartPoint */ protected void handleZoomRegion(final MouseEvent aEvent, final Point aStartPoint) { // For now, disabled by default as it isn't 100% working yet... if (Boolean.FALSE.equals(Boolean.valueOf(System.getProperty("zoomregionenabled", "false")))) { return; } final JComponent source = (JComponent) aEvent.getComponent(); final boolean dragging = (aEvent.getID() == MouseEvent.MOUSE_DRAGGED); final GhostGlassPane glassPane = (GhostGlassPane) SwingUtilities.getRootPane(source).getGlassPane(); Rectangle viewRect; final JScrollPane scrollPane = SwingComponentUtils.getAncestorOfClass(JScrollPane.class, source); if (scrollPane != null) { final JViewport viewport = scrollPane.getViewport(); viewRect = SwingUtilities.convertRectangle(viewport, viewport.getVisibleRect(), glassPane); } else { viewRect = SwingUtilities.convertRectangle(source, source.getVisibleRect(), glassPane); } final Point start = SwingUtilities.convertPoint(source, aStartPoint, glassPane); final Point current = SwingUtilities.convertPoint(source, aEvent.getPoint(), glassPane); if (dragging) { if (!glassPane.isVisible()) { glassPane.setVisible(true); glassPane.setRenderer(new RubberBandRenderer(), start, current, viewRect); } else { glassPane.updateRenderer(start, current, viewRect); } glassPane.repaintPartially(); } else /* if ( !dragging ) */ { // Fire off a signal to the zoom controller to do its job... this.controller.getZoomController().zoomRegion(aStartPoint, aEvent.getPoint()); glassPane.setVisible(false); } }