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

The following examples show how to use java.awt.Component#getClass() . 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
/**
 * Creates operator for component. Tries to find class with "operator
 * package"."class name"Operator name, where "operator package" is a package
 * from operator packages list, and "class name" is the name of class or one
 * of its superclasses.
 *
 * @param comp Component to create operator for.
 * @return a new operator with default environment.
 * @see #addOperatorPackage(String)
 */
public static ComponentOperator createOperator(Component comp) {
    //hack!
    try {
        Class<?> cclass = Class.forName("java.awt.Component");
        Class<?> compClass = comp.getClass();
        ComponentOperator result;
        do {
            if ((result = createOperator(comp, compClass)) != null) {
                return result;
            }
        } while (cclass.isAssignableFrom(compClass = compClass.getSuperclass()));
    } catch (ClassNotFoundException ignored) {
    }
    return null;
}
 
Example 2
Source Project: pumpernickel   File: PumpernickelShowcaseApp.java    License: MIT License 6 votes vote down vote up
/**
 * Return the name of the showcase demo panel in the given component.
 */
private String getDemoName(Component c) {
	if (c instanceof LazyDemoPanel)
		c = ((LazyDemoPanel) c).showcaseDemo;
	Class z = c.getClass();
	if (z.getName().contains("pump.showcase."))
		return z.getSimpleName();
	if (c instanceof Container) {
		Container c2 = (Container) c;
		for (Component child : c2.getComponents()) {
			String n = getDemoName(child);
			if (n != null)
				return n;
		}
	}
	return null;
}
 
Example 3
private static <T> T get(Class<? extends T> type, Container container) {
    Component component = container.getComponent(0);
    if (!type.isAssignableFrom(component.getClass())) {
        throw new IllegalStateException("expected " + type + "; expected " + component.getClass());
    }
    return (T) component;
}
 
Example 4
private static <T> T get(Class<? extends T> type, Container container) {
    Component component = container.getComponent(0);
    if (!type.isAssignableFrom(component.getClass())) {
        throw new IllegalStateException("expected " + type + "; expected " + component.getClass());
    }
    return (T) component;
}
 
Example 5
private static <T> T get(Class<? extends T> type, Container container) {
    Component component = container.getComponent(0);
    if (!type.isAssignableFrom(component.getClass())) {
        throw new IllegalStateException("expected " + type + "; expected " + component.getClass());
    }
    return (T) component;
}
 
Example 6
private static <T> T get(Class<? extends T> type, Container container) {
    Component component = container.getComponent(0);
    if (!type.isAssignableFrom(component.getClass())) {
        throw new IllegalStateException("expected " + type + "; expected " + component.getClass());
    }
    return (T) component;
}
 
Example 7
Source Project: netbeans   File: TreeTableOperator.java    License: Apache License 2.0 5 votes vote down vote up
public boolean checkComponent(Component comp) {
           Class cls = comp.getClass();
           do {
               if(cls.getName().equals("org.openide.explorer.view.TreeTable")) {
                   return(subFinder.checkComponent(comp));
               }
           } while((cls = cls.getSuperclass()) != null);
    return(false);
}
 
Example 8
Source Project: netbeans   File: OutlineOperator.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean checkComponent(Component comp) {
    Class cls = comp.getClass();
    do {
        if (cls.getName().equals("org.netbeans.swing.outline.Outline")) {
            return (subFinder.checkComponent(comp));
        }
    } while ((cls = cls.getSuperclass()) != null);
    return (false);
}
 
Example 9
private void addFocusListener(Component C) {
    C.getClass();
    super.getComponent().addFocusListener(
        new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent fe) {
                lostFocus();
            }
        });
}
 
Example 10
Source Project: netbeans   File: OutlineViewOperator.java    License: Apache License 2.0 5 votes vote down vote up
public boolean checkComponent(Component comp) {
           Class cls = comp.getClass();
           do {
               if(cls.getName().equals("org.openide.explorer.view.OutlineView")) {
                   return(subFinder.checkComponent(comp));
               }
           } while((cls = cls.getSuperclass()) != null);
    return(false);
}
 
Example 11
private static <T> T get(Class<? extends T> type, Container container) {
    Component component = container.getComponent(0);
    if (!type.isAssignableFrom(component.getClass())) {
        throw new IllegalStateException("expected " + type + "; expected " + component.getClass());
    }
    return (T) component;
}
 
Example 12
private static <T> T get(Class<? extends T> type, Container container) {
    Component component = container.getComponent(0);
    if (!type.isAssignableFrom(component.getClass())) {
        throw new IllegalStateException("expected " + type + "; expected " + component.getClass());
    }
    return (T) component;
}
 
Example 13
public ComponentNode(Component comp) {
    super(comp.getClass());
    try {
        props = Operator.createOperator(comp).getDump();
    } catch (Exception e) {
        props = new Hashtable<>();
    }
    clss = comp.getClass().getName();
    compToString = comp.toString();
    this.comp = comp;
    x = comp.getLocationOnScreen().x;
    y = comp.getLocationOnScreen().y;
    w = comp.getWidth();
    h = comp.getHeight();
}
 
Example 14
Source Project: hottub   File: Test6817933.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static <T> T get(Class<? extends T> type, Container container) {
    Component component = container.getComponent(0);
    if (!type.isAssignableFrom(component.getClass())) {
        throw new IllegalStateException("expected " + type + "; expected " + component.getClass());
    }
    return (T) component;
}
 
Example 15
private static <T> T get(Class<? extends T> type, Container container) {
    Component component = container.getComponent(0);
    if (!type.isAssignableFrom(component.getClass())) {
        throw new IllegalStateException("expected " + type + "; expected " + component.getClass());
    }
    return (T) component;
}
 
Example 16
private static <T> T get(Class<? extends T> type, Container container) {
    Component component = container.getComponent(0);
    if (!type.isAssignableFrom(component.getClass())) {
        throw new IllegalStateException("expected " + type + "; expected " + component.getClass());
    }
    return (T) component;
}
 
Example 17
private static <T> T get(Class<? extends T> type, Container container) {
    Component component = container.getComponent(0);
    if (!type.isAssignableFrom(component.getClass())) {
        throw new IllegalStateException("expected " + type + "; expected " + component.getClass());
    }
    return (T) component;
}
 
Example 18
private static <T> T get(Class<? extends T> type, Container container) {
    Component component = container.getComponent(0);
    if (!type.isAssignableFrom(component.getClass())) {
        throw new IllegalStateException("expected " + type + "; expected " + component.getClass());
    }
    return (T) component;
}
 
Example 19
private static <T> T get(Class<? extends T> type, Container container) {
    Component component = container.getComponent(0);
    if (!type.isAssignableFrom(component.getClass())) {
        throw new IllegalStateException("expected " + type + "; expected " + component.getClass());
    }
    return (T) component;
}
 
Example 20
synchronized private final void updateList2() {
	final List<? extends Displayable> list = getList();
	final int count = getList().size();
	
	if (list.isEmpty()) {
		this.current.clear();
		if (this.inner.getComponentCount() > 0) {
			this.inner.removeAll();
			this.scrollBar.setMaximum(0);
			this.revalidate();
			//if (clazz == Patch.class) Utils.log2("empty list, removeAll, revalidate");
		}
		return;
	}

	final int numCanFit = (int)Math.floor(inner.getBounds().height / (float)DisplayablePanel.HEIGHT);
	
	if (!(this.scrollBar.getMaximum() == count && this.scrollBar.getVisibleAmount() == numCanFit)) {
		this.scrollBar.getModel().setRangeProperties(
				Math.max(0, this.scrollBar.getValue()),
				numCanFit,
				0, count, false);
	}

	this.current.clear();

	// Scrollbar value:
	int first = this.scrollBar.getValue();
	if (-1 == first) {
		this.scrollBar.setValue(0);
		first = 0;
	}
	// Correct for inverse list:
	first = list.size() - first -1;

	int last = first - numCanFit +1;
	if (last < 0) {
		first = Math.min(numCanFit, count) -1;
		last = 0;
	}

	// Reuse panels only if the exact same number is to be used
	final DisplayablePanel[] toReuse;
	final boolean notReusing;
	if (first - last + 1 != inner.getComponentCount() -1) {
		this.inner.removeAll();
		notReusing = true;
		toReuse = null;
	} else {
		notReusing = false;
		toReuse = new DisplayablePanel[first - last + 1];
		int i = 0;
		for (final Component c : inner.getComponents()) {
			if (DisplayablePanel.class == c.getClass()) {
				toReuse[i++] = (DisplayablePanel)c;
			}
		}
	}

	this.cInner.anchor = GridBagConstraints.NORTHWEST;
	this.cInner.fill = GridBagConstraints.HORIZONTAL;
	this.cInner.weightx = 0;
	this.cInner.weighty = 0;
	this.cInner.gridy = 0;
	for (int i=first, k=0; i >= last ; --i, ++k) {
		final Displayable d = list.get(i);
		final DisplayablePanel dp;
		if (notReusing) {
			dp = new DisplayablePanel(display, d);
			this.gbInner.setConstraints(dp, this.cInner);
			this.inner.add(dp);
			this.cInner.gridy += 1;
		} else {
			dp = toReuse[k];
			dp.set(d);
		}
		this.current.put(d, dp);
	}
	if (notReusing) {
		this.cInner.fill = GridBagConstraints.BOTH;
		this.cInner.weightx = 1;
		this.cInner.weighty = 1;
		this.gbInner.setConstraints(this.filler, this.cInner);
		this.inner.add(this.filler);
		this.inner.validate();
	}
}