List of usage examples for java.awt Component getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:Main.java
public static String getComponentPath(Component c) { StringBuffer sb = new StringBuffer(); Component current = c; boolean isFirst = true; while (current.getParent() != null) { sb.insert(0, (isFirst ? "" : ".") + current.getClass().getSimpleName()); isFirst = false;//w w w . j a v a 2 s .c om current = current.getParent(); } return sb.toString(); }
From source file:Main.java
/** * Retrieves the first contained component of a certain type. * * @param component/* w w w . j ava 2 s . c o m*/ * the component to start from. * @param childComponentType * the type of the component to look for. * @return the first contained component of the looked for type or null if * none. */ public static Component getFirstChildComponentOfType(Component component, Class<? extends JComponent> childComponentType) { if (childComponentType.isAssignableFrom(component.getClass())) { return component; } if (component instanceof Container) { Component[] children = ((Container) component).getComponents(); for (Component child : children) { Component childResult = getFirstChildComponentOfType(child, childComponentType); if (childResult != null) { return childResult; } } } return null; }
From source file:Main.java
/**Devuelve el componente que tiene el actioncomand psComando*/ public static JComponent getComponente(Container poContenedor, String psAccion) { JComponent loResult = null;//from w w w. ja va 2 s .c om for (int i = 0; i < poContenedor.getComponentCount() && loResult == null; i++) { Component loComp = poContenedor.getComponent(i); if (loResult == null && JButton.class.isAssignableFrom(loComp.getClass())) { if (((JButton) loComp).getActionCommand() != null && ((JButton) loComp).getActionCommand().equals(psAccion)) { loResult = ((JButton) loComp); } } if (loResult == null && JLabel.class.isAssignableFrom(loComp.getClass())) { if (((JLabel) loComp).getName() != null && ((JLabel) loComp).getName().equals(psAccion)) { loResult = ((JLabel) loComp); } } if (loResult == null && JComboBox.class.isAssignableFrom(loComp.getClass())) { if (((JComboBox) loComp).getName() != null && ((JComboBox) loComp).getName().equals(psAccion)) { loResult = ((JComboBox) loComp); } } if (loResult == null && JInternalFrame.class.isAssignableFrom(loComp.getClass())) { if (((JInternalFrame) loComp).getName() != null && ((JInternalFrame) loComp).getName().equals(psAccion)) { loResult = ((JInternalFrame) loComp); } } if (loResult == null && Container.class.isAssignableFrom(loComp.getClass())) { loResult = getComponente(((Container) loComp), psAccion); } // if(loComp.getClass().isAssignableFrom(JToolBar.class) ){ // loResult = getComponente(((JToolBar)loComp), psAccion); // } } return loResult; }
From source file:Main.java
@SuppressWarnings("unchecked") private static <T> void addAllOf(Container container, Class<T> clazz, List<T> all) { int count = container.getComponentCount(); if (container.getClass().equals(clazz)) { all.add((T) container);//from w ww .jav a 2s.c om } for (int i = 0; i < count; i++) { Component component = container.getComponent(i); if (component instanceof Container) { addAllOf((Container) component, clazz, all); // Recursive } else if (component.getClass().equals(clazz)) { all.add((T) component); } } }
From source file:Main.java
/** * The internal, recursive implementation of getChildComponents(Container, Class...). * * @param parent Container which's children are being gathered. * @param filter The class filter applied, may be null. * @param resultList The list of gathered child components. *///from ww w . j av a2s. c om protected static void getChildComponents(final Container parent, final Class[] filter, final Collection resultList) { final Component[] components = parent.getComponents(); for (Component c : components) { if (filter.length == 0) resultList.add(c); else { for (Class f : filter) { if (f.isAssignableFrom(c.getClass())) { resultList.add(c); break; } } } if (c instanceof Container) getChildComponents((Container) c, filter, resultList); } }
From source file:Main.java
@SuppressWarnings("unchecked") private static <T> void addAllOfExclude(Container container, Class<T> clazz, List<T> all, Collection<? extends Component> exclude) { if (exclude.contains(container)) { return;/*from w ww. j av a 2 s .c o m*/ } if (container.getClass().equals(clazz)) { all.add((T) container); } int count = container.getComponentCount(); for (int i = 0; i < count; i++) { Component component = container.getComponent(i); if (exclude.contains(component)) { continue; } if (component instanceof Container) { addAllOfExclude((Container) component, clazz, all, exclude); // Recursive } else if (component.getClass().equals(clazz)) { all.add((T) component); } } }
From source file:com.hartveld.commons.test.swing.AbstractSwingFrameTest.java
private static <T> T lookup(final Container container, final String name, final Class<T> clazz) { LOG.trace("Looking up component of type {} in container {} ...", clazz.getName(), container.getName()); for (final Component c : container.getComponents()) { if (clazz.isAssignableFrom(c.getClass())) { if (name == null || name.equals(c.getName())) { @SuppressWarnings("unchecked") final T target = (T) c; return target; }/*from w w w. j a v a 2 s . c om*/ } else if (c instanceof Container) { final T nested = lookup((Container) c, name, clazz); if (nested != null) { return nested; } } } return null; }
From source file:Main.java
private static void appendComponentStructure(Component component, StringBuilder builder, String indent) { builder.append(NEWLINE);// www.j av a 2 s . c om builder.append(indent); builder.append(component.getName()); builder.append("("); builder.append(component.getClass().getName()); builder.append(")"); appendComponentDetails(component, builder); if (component instanceof JTree) appendTreeNodes(((JTree) component).getModel(), ((JTree) component).getModel().getRoot(), builder, "| " + indent); if (component instanceof JMenuBar) { appendMenuItem(component, builder, "| " + indent); } else if (component instanceof Container) { for (Component subComponent : ((Container) component).getComponents()) appendComponentStructure(subComponent, builder, "| " + indent); } }
From source file:net.chaosserver.timelord.swingui.SwingUtil.java
/** * Repair location is designed to detect if a box is partially * off-screen and move the box back onto the screen. * * @param component component to repair//from ww w . j a va 2 s . c o m */ public static void repairLocation(Component component) { Point locationPoint = component.getLocation(); Point locationOnScreenPoint = null; if (component.isVisible()) { locationOnScreenPoint = component.getLocationOnScreen(); } Dimension componentSize = component.getSize(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); if (log.isDebugEnabled()) { log.debug("Repairing location on [" + component.getClass().getName() + "]. Original location point = [" + locationPoint + "] and location on screen point = [" + locationOnScreenPoint + "]. The screen size is [" + screenSize + "] and the component size is [" + componentSize + "]"); } // Is the dialog to far to the left? Then fix. if (locationPoint.getX() < 0) { locationPoint.setLocation(0, locationPoint.getY()); } if (locationPoint.getY() < 0) { locationPoint.setLocation(locationPoint.getX(), 0); } // component.setLocation(locationPoint); // Is the dialog too wide? if (locationPoint.getX() + componentSize.getWidth() > screenSize.getWidth()) { componentSize.width = (int) (screenSize.getWidth() - locationPoint.getX()); } if (locationPoint.getY() + componentSize.getHeight() > screenSize.getHeight()) { componentSize.height = (int) (screenSize.getHeight() - locationPoint.getY()); } // component.setSize(componentSize); }
From source file:org.robotframework.swing.keyword.context.ContextKeywords.java
private String titleOf(Component component) { try {//from w w w.java2 s . c o m Method m = component.getClass().getMethod("getTitle"); return (String) m.invoke(component); } catch (Exception e) { throw new RuntimeException(e); } }