Java Code Examples for javax.swing.JComponent#isFocusOwner()

The following examples show how to use javax.swing.JComponent#isFocusOwner() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: pumpernickel   File: BoxTabbedPaneUI.java    License: MIT License 6 votes vote down vote up
@Override
public void paint(Graphics g0, JComponent c) {
	Graphics2D g = (Graphics2D) g0.create();
	boolean isSelected = ((AbstractButton) c).isSelected();
	g.setPaint(createContentGradient(c, isSelected));
	g.fillRect(0, 0, c.getWidth(), c.getHeight());
	if (c.isFocusOwner()) {
		int x = 0;
		int y = 0;
		int w = c.getWidth() - 1;
		int h = c.getHeight() - 1;
		Border b = c.getBorder();
		if (b != null) {
			Insets i = b.getBorderInsets(c);
			x += i.left;
			y += i.top;
			w -= i.left + i.right;
			h -= i.top + i.bottom;
		}
		Rectangle r = new Rectangle(x, y, w, h);
		PlafPaintUtils.paintFocus(g, r, 1,
				PlafPaintUtils.getFocusRingColor());
	}
	g.dispose();
	super.paint(g0, c);
}
 
Example 2
/**
 * Draws the border of the combobox.
 */
private void paintBorder(Graphics g, JComponent c) {
	int w = c.getWidth();
	int h = c.getHeight();
	if (w <= 0 || h <= 0) {
		return;
	}

	Graphics2D g2 = (Graphics2D) g;
	g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
	boolean hasFocus = comboBox.isEditable()
			? c.isFocusOwner() || ((JComboBox<?>) c).getEditor().getEditorComponent().isFocusOwner() : c.isFocusOwner();
			if (c.isEnabled()) {
				if (hasFocus) {
					g2.setColor(Colors.COMBOBOX_BORDER_FOCUS);
				} else {
					g2.setColor(Colors.COMBOBOX_BORDER);
				}
			} else {
				g2.setColor(Colors.COMBOBOX_BORDER_DISABLED);
			}

			g2.drawRoundRect(0, 0, w - 1, h - 1, RapidLookAndFeel.CORNER_DEFAULT_RADIUS, RapidLookAndFeel.CORNER_DEFAULT_RADIUS);
}
 
Example 3
Source Project: seaglass   File: SeaGlassSliderUI.java    License: Apache License 2.0 5 votes vote down vote up
private int getComponentState(JComponent c, Region region) {
    if (region == Region.SLIDER_THUMB && thumbActive && c.isEnabled()) {
        int state = thumbPressed ? PRESSED : MOUSE_OVER;
        if (c.isFocusOwner()) state |= FOCUSED;
        return state;
    }
    return SeaGlassLookAndFeel.getComponentState(c);
}
 
Example 4
Source Project: pumpernickel   File: AbstractSwitchButtonIcon.java    License: MIT License 4 votes vote down vote up
protected void doPaintIcon(JComponent c, Graphics2D g, int x, int y) {
	g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
			RenderingHints.VALUE_ANTIALIAS_ON);
	int w = getIconWidth() - 2 * focusOffset;
	int h = getIconHeight() - 2 * focusOffset;
	g.translate(focusOffset, focusOffset);
	RoundRectangle2D r = new RoundRectangle2D.Float(x, y + h / 2
			- trackHeight / 2, w, trackHeight, trackHeight, trackHeight);
	boolean isSelected = isSelected(c);
	boolean isArmed = isArmed(c);
	double selectedState = AnimationManager.setTargetProperty(c,
			PROPERTY_SELECTED_STATE, isSelected ? 1 : 0, .1f);
	double armedState = AnimationManager.setTargetProperty(c,
			PROPERTY_ARMED_STATE, isArmed ? 1 : 0, .1f);

	ButtonTheme colors = unselectedColors.tween(selectedColors,
			selectedState);
	Color handleColor = AnimationManager.tween(colors.handleFill,
			colors.handleFillArmed, armedState);

	Shape handle = new Ellipse2D.Float(x + handlePadding, y + h / 2
			- handleWidth / 2, handleWidth, handleWidth);

	double dx = selectedState
			* (r.getWidth() - handleWidth - 2 * handlePadding);
	AffineTransform tx = AffineTransform.getTranslateInstance(dx, 0);
	handle = tx.createTransformedShape(handle);

	g.setStroke(new BasicStroke(strokeWidth));

	if (c.isFocusOwner()) {
		Area area = new Area();
		area.add(new Area(flatten(r)));
		area.add(new Area(flatten(handle)));
		Graphics2D g2 = (Graphics2D) g.create();
		g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
				RenderingHints.VALUE_STROKE_PURE);
		PlafPaintUtils.paintFocus(g2, area, focusOffset);
		g2.dispose();
	}

	Color trackFillTop = AnimationManager.tween(colors.backgroundTop,
			colors.backgroundTopArmed, armedState);
	Color trackFillBottom = AnimationManager.tween(colors.backgroundBottom,
			colors.backgroundBottomArmed, armedState);
	g.setPaint(new GradientPaint(x, y, trackFillTop, x, y + h,
			trackFillBottom));
	g.fill(r);

	Paint trackOutlinePaint = new GradientPaint(x, y,
			colors.trackOutlineTop, x, y + h, colors.trackOutlineBottom);
	g.setPaint(trackOutlinePaint);
	g.draw(r);

	g.setPaint(handleColor);
	g.fill(handle);

	Paint handleOutlinePaint = new GradientPaint(x, y,
			colors.handleOutlineTop, x, y + h, colors.handleOutlineBottom);
	g.setPaint(handleOutlinePaint);
	g.draw(handle);

	g.dispose();
}
 
Example 5
Source Project: seaglass   File: SeaGlassButtonUI.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Returns the current state of the passed in <code>AbstractButton</code>.
 *
 * @param  c the button component.
 *
 * @return the button's state.
 */
private int getComponentState(JComponent c) {
    int state = ENABLED;

    if (!c.isEnabled()) {
        state = DISABLED;
    }

    if (SeaGlassLookAndFeel.selectedUI == this) {
        return SeaGlassLookAndFeel.selectedUIState | SynthConstants.ENABLED;
    }

    AbstractButton button = (AbstractButton) c;
    ButtonModel    model  = button.getModel();

    if (model.isPressed()) {
        if (model.isArmed()) {
            state = PRESSED;
        } else {
            state = MOUSE_OVER;
        }
    }

    if (model.isRollover()) {
        state |= MOUSE_OVER;
    }

    if (model.isSelected()) {
        state |= SELECTED;
    }

    if (c.isFocusOwner() && button.isFocusPainted()) {
        state |= FOCUSED;
    }

    if ((c instanceof JButton) && ((JButton) c).isDefaultButton()) {
        state |= DEFAULT;
    }
    
    return state;
}