Example usage for java.awt Component getClass

List of usage examples for java.awt Component getClass

Introduction

In this page you can find the example usage for java.awt Component getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:ome.formats.importer.gui.FileQueueChooser.java

/**
 * File chooser on the file picker tab of the importer
 * //from   ww  w.ja va2s  .  c  o  m
 * @param config ImportConfig
 * @param scanReader OmeroWrapper
 */
FileQueueChooser(ImportConfig config, OMEROWrapper scanReader) {

    try {
        JPanel fp = null;
        JToolBar tb = null;

        String refreshIcon = "gfx/recycled12.png";
        refreshBtn = GuiCommonElements.addBasicButton("Refresh ", refreshIcon, null);
        refreshBtn.setActionCommand(REFRESHED);
        refreshBtn.addActionListener(this);
        JPanel panel = new JPanel();

        // Set up the main panel for tPane, quit, and send buttons
        double mainTable[][] = { { 10, TableLayout.FILL, TableLayout.PREFERRED, TableLayout.FILL, 10 }, // columns
                { TableLayout.PREFERRED } }; // rows

        TableLayout tl = new TableLayout(mainTable);
        panel.setLayout(tl);

        // Here's a nice little pieces of test code to find all components
        if (DEBUG) {
            try {
                Component[] components = this.getComponents();
                Component component = null;
                System.err.println("Components: " + components.length);
                for (int i = 0; i < components.length; i++) {
                    component = components[i];
                    System.err.println("Component " + i + " = " + component.getClass());
                }
            } catch (Exception e) {
                log.info("component exception ignore");
            }
        }

        if (laf.contains("AquaLookAndFeel")) {
            //Do Aqua implimentation
            fp = (JPanel) this.getComponent(1);
            fp.setLayout(new BoxLayout(fp, BoxLayout.X_AXIS));
            fp.add(refreshBtn);
        } else if (laf.contains("QuaquaLookAndFeel")) {
            //do Quaqua implimentation
            fp = (JPanel) this.getComponent(1);
            panel.add(refreshBtn, "1,0,C,C");
            panel.add(fp.getComponent(0), "2,0,C,C");
            fp.add(panel, BorderLayout.NORTH);
        } else if (laf.contains("Windows")) {
            try {
                //Do windows implimentation
                tb = (JToolBar) this.getComponent(1);
                refreshBtn.setToolTipText("Refresh");
                refreshBtn.setText(null);
                tb.add(refreshBtn, 8);
            } catch (Exception e) {
                log.info("Exception ignored.");
            }
        }
        /* Disabled temporarily */
        else if (laf.contains("MetalLookAndFeel")) {
            //Do Metal implimentation
            JPanel prefp = (JPanel) this.getComponent(0);
            fp = (JPanel) prefp.getComponent(0);
            refreshBtn.setToolTipText("Refresh");
            refreshBtn.setText(null);
            Dimension size = new Dimension(24, 24);
            refreshBtn.setMaximumSize(size);
            refreshBtn.setPreferredSize(size);
            refreshBtn.setMinimumSize(size);
            refreshBtn.setSize(size);
            fp.add(Box.createRigidArea(new Dimension(5, 0)));
            fp.add(refreshBtn);
        }

        else if (laf.contains("GTKLookAndFeel")) {
            //do GTK implimentation
            fp = (JPanel) this.getComponent(0);
            refreshBtn.setIcon(null);
            fp.add(refreshBtn);
        } else if (laf.contains("MotifLookAndFeel")) {
            //do Motif implimentation
            fp = (JPanel) this.getComponent(0);
            fp.add(refreshBtn);
        }

        if (fp != null && DEBUG == true) {
            fp.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.red),
                    fp.getBorder()));
            System.err.println(fp.getLayout());
        }

        if (tb != null && DEBUG == true) {
            tb.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.red),
                    tb.getBorder()));
            System.err.println(tb.getLayout());
        }
    } catch (ArrayIndexOutOfBoundsException e) {
    }

    File dir = null;
    if (config != null)
        dir = config.savedDirectory.get();

    if (dir != null) {
        this.setCurrentDirectory(dir);
    } else {
        this.setCurrentDirectory(this.getFileSystemView().getHomeDirectory());
    }

    this.setControlButtonsAreShown(false);
    this.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    this.setMultiSelectionEnabled(true);
    this.setDragEnabled(true);

    setAcceptAllFileFilterUsed(false);

    FileFilter[] originalFF = null;
    int readerFFSize = 0;
    if (scanReader != null) {
        originalFF = loci.formats.gui.GUITools.buildFileFilters(scanReader.getImageReader());
        FileFilter filter;
        List<FileFilter> extensionFilters = new ArrayList<FileFilter>();
        for (int i = 0; i < originalFF.length; i++) {
            filter = originalFF[i];
            if (filter instanceof ComboFileFilter) {
                ComboFileFilter cff = (ComboFileFilter) filter;
                extensionFilters.add(cff);
                extensionFilters.addAll(Arrays.asList(cff.getFilters()));
                break;
            }
        }
        if (extensionFilters != null) {
            originalFF = extensionFilters.toArray(new FileFilter[extensionFilters.size()]);
        }
        readerFFSize = originalFF.length;
    }

    FileFilter[] ff = new FileFilter[readerFFSize + 7];
    ff[0] = new DashFileFilter();
    ff[readerFFSize + 1] = new DashFileFilter();
    ff[readerFFSize + 2] = new R3DNewFileFilter();
    ff[readerFFSize + 3] = new R3DOldFileFilter();
    ff[readerFFSize + 4] = new D3DNewFileFilter();
    ff[readerFFSize + 5] = new D3DOldFileFilter();
    ff[readerFFSize + 6] = new D3DNPrjFileFilter();

    if (originalFF != null)
        System.arraycopy(originalFF, 0, ff, 1, originalFF.length);

    //this.addChoosableFileFilter(new DashFileFilter());

    //FileFilter combo = null;
    for (int i = 0; i < ff.length; i++)
        this.addChoosableFileFilter(ff[i]);
    this.setFileFilter(ff[1]);

    //Retrieve all JLists and JTables from the fileChooser
    fileListObjects = getFileListObjects(this);

    //For now, assume the first list/table found is the correct one
    //(this will need to be adjusted if LAF bugs crop up)
    //Shouldn't break anything since dblclick will just stop working if
    //this changes for some reason
    if (fileListObjects.length > 0 && !laf.contains("Windows")) {
        fileList = fileListObjects[0];
        MouseCommand mc = new MouseCommand();
        fileList.addMouseListener(mc);
    }
}

From source file:org.kepler.gui.AnnotatedPTree.java

public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded,
        boolean leaf, int row, boolean hasFocus) {
    if (isDebugging) {
        log.debug(//  w  w  w . java 2s .  c  o m
                "getTreeCellRendererComponent(" + tree.getClass().getName() + ", " + value.getClass().getName()
                        + ", " + selected + ", " + expanded + ", " + leaf + ", " + row + ", " + hasFocus + ")");
        log.debug(tree.getShowsRootHandles());
    }

    if (value instanceof ptolemy.moml.EntityLibrary) {
        EntityLibrary el = (EntityLibrary) value;
        if (isDebugging) {
            log.debug(el.getName() + " " + el.getClass().getName());
        }

        if (el instanceof KAREntityLibrary) {
            setOpenIcon(_packIconOpen);
            setClosedIcon(_packIconClosed);
        } else if (el instanceof FolderEntityLibrary) {
            setOpenIcon(_folderIconOpen);
            setClosedIcon(_folderIconClosed);
        } else if (el instanceof OntologyEntityLibrary) {
            setOpenIcon(_ontIconOpen);
            setClosedIcon(_ontIconClosed);
        } else if (el instanceof SearchEntityLibrary) {
            setOpenIcon(_searchIcon);
            setClosedIcon(_searchIcon);
        } else if (el instanceof KARErrorEntityLibrary || el instanceof RemoteKARErrorEntityLibrary) {
            setOpenIcon(_packIconError);
            setClosedIcon(_packIconError);
        } else if (el instanceof DownloadableKAREntityLibrary) {
            // Icons for the KAR files - trash cans?
            setOpenIcon(_packIconOpen);
            setClosedIcon(_packIconClosed);
        } else if (el instanceof RemoteRepositoryEntityLibrary) {
            // Icons for the Remote repositories - computers
            setOpenIcon(_remoteIcon);
            setClosedIcon(_remoteIcon);
            // TODO: Also make sure that the top-level "Remote Components" is a globe
        } else {
            setOpenIcon(_generalIcon);
            setClosedIcon(_generalIcon);
        }
    } else {
        if (isDebugging)
            log.debug("set general icon");
        setOpenIcon(_generalIcon);
        setClosedIcon(_generalIcon);
    }
    Component c = super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);

    // if the object is a NamedObj, use display name for the label
    // since the display name is used on the canvas. the component returned
    // by super.getTreeCellRenderer() uses the display name for settables.
    if (!(value instanceof Settable) && (value instanceof NamedObj) && (c instanceof DefaultTreeCellRenderer)) {
        ((DefaultTreeCellRenderer) c).setText(((NamedObj) value).getDisplayName());
    }

    if (isDebugging)
        log.debug("Component: " + c.getClass().getName());
    return c;
}

From source file:com.kenai.redminenb.query.RedmineQueryController.java

private <T extends RedmineQueryParameter> T registerQueryParameter(Class<T> clazz, Component c,
        String parameterName) {/*from   ww  w  . j a  v  a 2  s  . c o  m*/
    try {
        Constructor<T> constructor = clazz.getConstructor(c.getClass(), String.class);
        T t = constructor.newInstance(c, parameterName);
        parameters.put(parameterName, t);
        return t;
    } catch (Exception ex) {
        Redmine.LOG.log(Level.SEVERE, parameterName, ex);
    }
    return null;
}

From source file:org.eclipse.jubula.rc.swing.tester.util.TreeOperationContext.java

/**
 * {@inheritDoc}/*from w  w w  . jav a 2  s.  co  m*/
 */
public String getRenderedText(final Object node) {
    return (String) getQueuer().invokeAndWait("getRenderedText", new IRunnable() { //$NON-NLS-1$
        public Object run() {
            int row = getRowForTreeNode(node);
            JTree tree = (JTree) getTree();
            Component cellRendererComponent = tree.getCellRenderer().getTreeCellRendererComponent(tree, node,
                    false, tree.isExpanded(row), m_model.isLeaf(node), row, false);
            try {
                return TesterUtil.getRenderedText(cellRendererComponent);
            } catch (StepExecutionException e) {
                // This is a valid case in JTrees since if there is no text
                // there is also no renderer 
                log.warn("Renderer not supported: " + //$NON-NLS-1$
                cellRendererComponent.getClass(), e);
                return null;
            }
        }
    });
}

From source file:com.mac.tarchan.desktop.event.EventQuery.java

List<String> list(Collection<Component> list) {
    ArrayList<String> buf = new ArrayList<String>();
    for (Component child : list) {
        buf.add(String.format("%s (%s)", child.getName(), child.getClass().getName()));
    }// w  w w.j  av a2  s  .c  om

    return buf;
}

From source file:org.eclipse.jubula.rc.swing.components.AUTSwingHierarchy.java

/**
 * {@inheritDoc}/*from w w  w.j a va 2  s  . c  om*/
 */
protected List getComponentContext(Object component) {
    Component comp = (Component) component;
    List context = new ArrayList();
    if (comp.getParent() != null) {
        SwingHierarchyContainer parent = getHierarchyContainer(comp.getParent());
        if (parent != null) {
            SwingHierarchyContainer[] comps = parent.getComponents();
            for (int i = 0; i < comps.length; i++) {
                Component child = comps[i].getComponentID().getRealComponent();
                if (!child.equals(comp)) {
                    String toAdd = child.getClass().getName() + Constants.CLASS_NUMBER_SEPERATOR + 1;
                    while (context.contains(toAdd)) {
                        int lastCount = Integer
                                .valueOf(toAdd
                                        .substring(toAdd.lastIndexOf(Constants.CLASS_NUMBER_SEPERATOR) + 1))
                                .intValue();
                        toAdd = child.getClass().getName() + Constants.CLASS_NUMBER_SEPERATOR + (lastCount + 1);
                    }
                    context.add(toAdd);
                }
            }
        }
    }
    return context;
}

From source file:com.mac.tarchan.desktop.event.EventQuery.java

/**
 * ????????//from   w w w  .  j  ava2s  .  c  o  m
 * 
 * @param out 
 * @return ??
 */
public EventQuery dump(PrintStream out) {
    String head = String.format("Parent: %s", parent);
    out.println(head);
    for (Component child : list) {
        String info = String.format("%s, %s", child.getName(), child.getClass().getName());
        out.println(info);
    }

    return this;
}

From source file:org.eclipse.jubula.rc.swing.components.AUTSwingHierarchy.java

/**
 * Investigates the given <code>component</code> for an identifier. To
 * obtain this identifier the name of the component and the container
 * hierarchy is used./*  ww  w  .  j  a v  a  2s .c  om*/
 * @param component the component to create an identifier for, must not be null.
 * @throws ComponentNotManagedException if component is null or <br>
 *      (one of the) component(s) in the hierarchy is not managed
 * @return the identifier for <code>component</code>
 */
public IComponentIdentifier getComponentIdentifier(Component component) throws ComponentNotManagedException {
    checkDispatchThread();
    IComponentIdentifier result = new ComponentIdentifier();
    try {
        // fill the componentIdentifier
        result.setComponentClassName(component.getClass().getName());
        result.setSupportedClassName(
                AUTServerConfiguration.getInstance().getTestableClass(component.getClass()).getName());
        List hierarchy = getPathToRoot(component);
        result.setHierarchyNames(hierarchy);
        result.setNeighbours(getComponentContext(component));
        HierarchyContainer container = getHierarchyContainer(component);
        setAlternativeDisplayName(container, component, result);
        if (component.equals(findBP.findComponent(result, ComponentHandler.getAutHierarchy()))) {
            result.setEqualOriginalFound(true);
        }
        return result;
    } catch (IllegalArgumentException iae) {
        // from getPathToRoot()
        log.error(iae);
        throw new ComponentNotManagedException("getComponentIdentifier() called for an unmanaged component: " //$NON-NLS-1$
                + component, MessageIDs.E_COMPONENT_NOT_MANAGED);
        // let pass the ComponentNotManagedException from getPathToRoot()
    }
}

From source file:org.openmicroscopy.shoola.util.ui.UIUtilities.java

/**
 * Finds the component identified by the specified class contained in the 
 * passed component. Returns the found component or <code>null</code> if 
 * none found.//from  www. jav a2s  .  c  o m
 * 
 * @param comp   The component to visit. Mustn't be <code>null</code>.
 * @param c      The class identifying the component to find.
 * @return See above.
 */
public static Component findComponent(Component comp, Class c) {
    if (c == null || comp == null)
        throw new IllegalArgumentException("The parameters cannot be " + "null");
    if (c.isAssignableFrom(comp.getClass()))
        return comp;

    if (comp instanceof Container) {
        Component[] comps = ((Container) comp).getComponents();
        Component child;
        for (int i = 0; i < comps.length; i++) {
            child = findComponent(comps[i], c);
            if (child != null)
                return child;
        }
    }
    return null;
}

From source file:org.eclipse.jubula.rc.swing.components.AUTSwingHierarchy.java

/**
 * Returns the path from the given component to root. The List contains
 * Strings (the name of the components).
 * @param component the component to start, it's an instance from the AUT, must not be null
 * @throws IllegalArgumentException if component is null
 * @throws ComponentNotManagedException if no hierarchy conatiner exists for the component
 * @return the path to root, the first elements contains the root, the last element contains the component itself.
 *///from  ww w .  j  a  v a 2 s.c  o m
public List getPathToRoot(Component component) throws IllegalArgumentException, ComponentNotManagedException {

    if (log.isInfoEnabled()) {
        log.info("pathToRoot called for " + component); //$NON-NLS-1$            
    }
    Validate.notNull(component, "The component must not be null"); //$NON-NLS-1$ 
    List hierarchy = new ArrayList();
    SwingHierarchyContainer parent;
    SwingHierarchyContainer autContainer = getHierarchyContainer(component);
    if (autContainer != null) {
        // add the name of the container itself
        hierarchy.add(autContainer.getName());
        final String className = component.getClass().getName();
        if (MappingConstants.SWING_APPLICATION_CLASSNAME.equals(className)
                || MappingConstants.SWING_MENU_DEFAULT_MAPPING_CLASSNAME.equals(className)
                || MappingConstants.SWING_MENU_CLASSNAME.equals(className)) {

            return hierarchy;
        }
        parent = getHierarchyContainer(component.getParent());
        autContainer.setParent(parent);
        // prepend the name of the container up to the root container
        while (parent != null) {
            ((ArrayList) hierarchy).add(0, parent.getName());
            Component compo = parent.getComponentID().getRealComponent();
            parent = parent.getParent();
            if (parent == null && compo != null && compo.getParent() != null) {

                SwingComponent comp = new SwingComponent(compo.getParent());
                SwingHierarchyContainer container = new SwingHierarchyContainer(comp);
                name(container);
                parent = container;
                addToHierachyMap(container);
            }
        }
    } else {
        log.error("component '" + component //$NON-NLS-1$ 
                + "' is not managed by this hierarchy"); //$NON-NLS-1$
        throw new ComponentNotManagedException("unmanaged component " + component.toString(), //$NON-NLS-1$                    
                MessageIDs.E_COMPONENT_NOT_MANAGED);
    }
    return hierarchy;
}