Java Code Examples for java.awt.Component#hasFocus()

The following examples show how to use java.awt.Component#hasFocus() . 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 File: GraphicUtils.java    From xyTalk-pc with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
    * @param c
    *            Component to check on.
    * @return returns true if the component of one of its child has the focus
    */
   public static boolean isAncestorOfFocusedComponent(Component c) {
if (c.hasFocus()) {
    return true;
} else {
    if (c instanceof Container) {
	Container cont = (Container) c;
	int n = cont.getComponentCount();
	for (int i = 0; i < n; i++) {
	    Component child = cont.getComponent(i);
	    if (isAncestorOfFocusedComponent(child))
		return true;
	}
    }
}
return false;
   }
 
Example 2
Source File: GraphicUtils.java    From Spark with Apache License 2.0 6 votes vote down vote up
/**
    * @param c
    *            Component to check on.
    * @return returns true if the component of one of its child has the focus
    */
   public static boolean isAncestorOfFocusedComponent(Component c) {
if (c.hasFocus()) {
    return true;
} else {
    if (c instanceof Container) {
	Container cont = (Container) c;
	int n = cont.getComponentCount();
	for (int i = 0; i < n; i++) {
	    Component child = cont.getComponent(i);
	    if (isAncestorOfFocusedComponent(child))
		return true;
	}
    }
}
return false;
   }
 
Example 3
Source File: FocusedBorder.java    From PyramidShader with GNU General Public License v3.0 6 votes vote down vote up
public void paintBorder(Component c, Graphics g, int x, int y, int width,
		int height) {
	Insets insets = getBorderInsets(c);
	if(c.hasFocus()) {
		Rectangle rect = new Rectangle(x+insets.left, y+insets.top,
				width-insets.left-insets.right-1,
				height-insets.top-insets.bottom-1);
		Graphics2D g2 = (Graphics2D)g.create();
		GeneralPath focusOnly = new GeneralPath(Path2D.WIND_EVEN_ODD);
		focusOnly.append(new Rectangle(x,y,width,height), false);
		focusOnly.append(new Rectangle(x+insets.left,y+insets.top,
				width-insets.left-insets.right,
				height-insets.top-insets.bottom), false);
		g2.clip(focusOnly);
		PlafPaintUtils.paintFocus(g2, rect, 3);
	} else if(unfocusedBorder!=null) {
		Insets borderInsets = unfocusedBorder.getBorderInsets(c);
		unfocusedBorder.paintBorder(c, g, x+insets.left-borderInsets.left, 
				y+insets.top-borderInsets.top, 
				width-insets.left-insets.right+borderInsets.left+borderInsets.right,
				height-insets.top-insets.bottom+borderInsets.top+borderInsets.bottom);
	}
	
}
 
Example 4
Source File: PopupMenu.java    From javamoney-examples with Apache License 2.0 5 votes vote down vote up
/**
 * This method is invoked when the specific mouse event occurs.
 *
 * @param event The mouse event that occurred.
 */
public
void
mouseReleased(MouseEvent event)
{
  Component component = event.getComponent();

  if(component.hasFocus() == false)
  {
    component.requestFocus();
  }

  if(component.isEnabled() == true)
  {
    if(behaveLikeMenu() == true)
    {
      if(event.getButton() == BUTTON1)
      {
        show(component, 0, component.getHeight());
      }
    }
    else if(event.isPopupTrigger() == true)
    {
      int yCoordinate = 0;

      if(allowFloatingY() == true)
      {
        yCoordinate = event.getY();
      }

      show(component, event.getX(), yCoordinate);
    }
  }
}
 
Example 5
Source File: MotifBorders.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
    if (c.hasFocus()) {
        g.setColor(focus);
        g.drawRect(x, y, w-1, h-1);
    } else {
        g.setColor(control);
        g.drawRect(x, y, w-1, h-1);
    }
}
 
Example 6
Source File: TranserFocusToWindow.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void setFocus(final Component comp, final Robot r) {
    if (comp.hasFocus()) {
        return;
    }

    Util.clickOnComp(comp, r);
    Util.waitForIdle(r);

    if (!comp.hasFocus()) {
        throw new RuntimeException("can not set focus on " + comp);
    }
}
 
Example 7
Source File: MotifBorders.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
    if (c.hasFocus()) {
        g.setColor(focus);
        g.drawRect(x, y, w-1, h-1);
    } else {
        g.setColor(control);
        g.drawRect(x, y, w-1, h-1);
    }
}
 
Example 8
Source File: TranserFocusToWindow.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void setFocus(final Component comp, final Robot r) {
    if (comp.hasFocus()) {
        return;
    }

    Util.clickOnComp(comp, r);
    Util.waitForIdle(r);

    if (!comp.hasFocus()) {
        throw new RuntimeException("can not set focus on " + comp);
    }
}
 
Example 9
Source File: TranserFocusToWindow.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void setFocus(final Component comp, final Robot r) {
    if (comp.hasFocus()) {
        return;
    }

    Util.clickOnComp(comp, r);
    Util.waitForIdle(r);

    if (!comp.hasFocus()) {
        throw new RuntimeException("can not set focus on " + comp);
    }
}
 
Example 10
Source File: MotifBorders.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
    if (c.hasFocus()) {
        g.setColor(focus);
        g.drawRect(x, y, w-1, h-1);
    } else {
        g.setColor(control);
        g.drawRect(x, y, w-1, h-1);
    }
}
 
Example 11
Source File: TranserFocusToWindow.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void setFocus(final Component comp, final Robot r) {
    if (comp.hasFocus()) {
        return;
    }

    Util.clickOnComp(comp, r);
    Util.waitForIdle(r);

    if (!comp.hasFocus()) {
        throw new RuntimeException("can not set focus on " + comp);
    }
}
 
Example 12
Source File: MotifBorders.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
    if (c.hasFocus()) {
        g.setColor(focus);
        g.drawRect(x, y, w-1, h-1);
    } else {
        g.setColor(control);
        g.drawRect(x, y, w-1, h-1);
    }
}
 
Example 13
Source File: MotifBorders.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
    if (c.hasFocus()) {
        g.setColor(focus);
        g.drawRect(x, y, w-1, h-1);
    } else {
        g.setColor(control);
        g.drawRect(x, y, w-1, h-1);
    }
}
 
Example 14
Source File: TranserFocusToWindow.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private static void setFocus(final Component comp, final Robot r) {
    if (comp.hasFocus()) {
        return;
    }

    Util.clickOnComp(comp, r);
    Util.waitForIdle(r);

    if (!comp.hasFocus()) {
        throw new RuntimeException("can not set focus on " + comp);
    }
}
 
Example 15
Source File: TranserFocusToWindow.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static void setFocus(final Component comp, final Robot r) {
    if (comp.hasFocus()) {
        return;
    }

    Util.clickOnComp(comp, r);
    Util.waitForIdle(r);

    if (!comp.hasFocus()) {
        throw new RuntimeException("can not set focus on " + comp);
    }
}
 
Example 16
Source File: MotifBorders.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
    if (c.hasFocus()) {
        g.setColor(focus);
        g.drawRect(x, y, w-1, h-1);
    } else {
        g.setColor(control);
        g.drawRect(x, y, w-1, h-1);
    }
}
 
Example 17
Source File: TranserFocusToWindow.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static void setFocus(final Component comp, final Robot r) {
    if (comp.hasFocus()) {
        return;
    }

    Util.clickOnComp(comp, r);
    Util.waitForIdle(r);

    if (!comp.hasFocus()) {
        throw new RuntimeException("can not set focus on " + comp);
    }
}
 
Example 18
Source File: MotifBorders.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
    if (c.hasFocus()) {
        g.setColor(focus);
        g.drawRect(x, y, w-1, h-1);
    } else {
        g.setColor(control);
        g.drawRect(x, y, w-1, h-1);
    }
}
 
Example 19
Source File: TranserFocusToWindow.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void setFocus(final Component comp, final Robot r) {
    if (comp.hasFocus()) {
        return;
    }

    Util.clickOnComp(comp, r);
    Util.waitForIdle(r);

    if (!comp.hasFocus()) {
        throw new RuntimeException("can not set focus on " + comp);
    }
}
 
Example 20
Source File: WhylineControlBorder.java    From whyline with MIT License 4 votes vote down vote up
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {

		if(!c.isVisible()) return;
		
		Graphics2D g2 = (Graphics2D)g.create();

		g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
		g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
		g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);

		Stroke old = g2.getStroke();

		g2.setStroke(new BasicStroke(UI.getBorderPadding()));
		g2.setColor(UI.getPanelLightColor());
		g2.drawRect(0, 0, width, height);

		int corner = UI.getRoundedness() - 1;
		
		int widthOfControlBackgroundStroke = UI.getBorderPadding() + 1;
		g2.setStroke(new BasicStroke(widthOfControlBackgroundStroke));
		g2.setColor(c.getBackground());
		g2.drawRoundRect(
			widthOfControlBackgroundStroke / 2 - 1, 
			widthOfControlBackgroundStroke / 2 - 1, 
			width - widthOfControlBackgroundStroke + 1, 
			height - widthOfControlBackgroundStroke + 1, 
			corner, corner);

		g2.setStroke(old);

		if(c.hasFocus()) {
			g2.setColor(UI.getFocusColor());
			float strokeWidth = 2.0f;
			g2.setStroke(new BasicStroke(strokeWidth));
			g2.drawRect((int)(strokeWidth / 2), (int)(strokeWidth / 2), (int)(width - strokeWidth - 1), (int)(height - strokeWidth - 1));
		}
		else {
			g2.setColor(c.isEnabled() ? UI.getControlBorderColor() : UI.getControlBorderColor().darker());
			g2.drawRoundRect(0, 0, width - 1, height - 1, corner, corner);
		}
		
	}