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:ComponentEventDemo.java

public void componentMoved(ComponentEvent e) {
    Component c = e.getComponent();
    displayMessage("componentMoved event from " + c.getClass().getName() + "; new location: "
            + c.getLocation().x + ", " + c.getLocation().y);
}

From source file:ComponentEventDemo.java

public void componentResized(ComponentEvent e) {
    Component c = e.getComponent();
    displayMessage("componentResized event from " + c.getClass().getName() + "; new size: " + c.getSize().width
            + ", " + c.getSize().height);
}

From source file:EventTracerTest.java

/**
 * Adds event tracers for all events to which this component and its children can listen
 * @param c a component/*from  ww  w  .ja v  a  2  s .c  o m*/
 */
public void add(Component c) {
    try {
        // get all events to which this component can listen
        BeanInfo info = Introspector.getBeanInfo(c.getClass());

        EventSetDescriptor[] eventSets = info.getEventSetDescriptors();
        for (EventSetDescriptor eventSet : eventSets)
            addListener(c, eventSet);
    } catch (IntrospectionException e) {
    }
    // ok not to add listeners if exception is thrown

    if (c instanceof Container) {
        // get all children and call add recursively
        for (Component comp : ((Container) c).getComponents())
            add(comp);
    }
}

From source file:Main.java

private void myPaint(Component comp, Graphics g) {
    int x = comp.getX();
    int y = comp.getY();
    g.translate(x, y);//from w w w .j av  a  2s .com
    cursor.translate(-x, -y);
    if (comp.contains(cursor)) {
        String cls_name = comp.getClass().getName();
        g.setColor(Color.black);
        g.drawString(cls_name, 0, 10);
    }
    if (comp instanceof Container) {
        Container cont = (Container) comp;
        for (int i = 0; i < cont.getComponentCount(); i++) {
            Component child = cont.getComponent(i);
            myPaint(child, g);
        }
    }

    cursor.translate(x, y);
    g.translate(-x, -y);
}

From source file:org.fhcrc.cpl.viewer.mrm.utilities.MRMerMouseListener.java

Component MRMAncestor() {
    Component c = null;
    for (c = _cp; c != null && c.getClass() != MRMDialog.class; c = c.getParent())
        ;/*from ww w .j  a va 2  s .c  o  m*/
    return (c == null) ? null : (MRMDialog) c;
}

From source file:net.pandoragames.far.ui.swing.component.listener.OperationCallBackListener.java

/**
 * Adds a component that will be reseted on start.
 * The component must implement the interface
 * {@link net.pandoragames.far.ui.model.Resetable Resetable},
 * otherwise the call will be ignored.//from   ww  w. j  a  v a2 s  .c om
 * @param com to be reseted on operation start
 * @param type operation type that will trigger the behaviour
 */
public void addComponentStartReseted(Component com, OperationType type) {
    if (com != null) {
        if (com instanceof Resetable) {
            startComponents.add(new ComponentContainer(com, type, ABILITY.RESET));
        } else {
            logger.error("Attempt to add " + com.getClass().getName()
                    + " for reset on start, but it does not implement " + Resetable.class.getName());
        }
    }
}

From source file:op.tools.SYSTools.java

/**
 * see: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4380536
 * Puh, das hier ist aus der Sun Bug Datenbank. Etwas krude... Ich hoffe
 * die lassen sich mal was besseres einfallen.
 *//*  www .  ja  v a2s  . co m*/
static private void removeListeners(Component comp) {
    Method[] methods = comp.getClass().getMethods();
    for (int i = 0; i < methods.length; i++) {
        Method method = methods[i];
        String name = method.getName();
        if (name.startsWith("remove") && name.endsWith("Listener")) {

            Class[] params = method.getParameterTypes();
            if (params.length == 1) {
                EventListener[] listeners = null;
                try {
                    listeners = comp.getListeners(params[0]);
                } catch (Exception e) {
                    // It is possible that someone could create a listener
                    // that doesn't extend from EventListener.  If so,
                    // ignore it
                    OPDE.debug("Listener " + params[0] + " does not extend EventListener");
                    continue;
                }
                for (int j = 0; j < listeners.length; j++) {
                    try {
                        method.invoke(comp, new Object[] { listeners[j] });
                        //OPDE.debug("removed Listener " + name + "for comp " + comp + "\n");
                    } catch (Exception e) {
                        OPDE.debug("Cannot invoke removeListener method " + e);
                        // Continue on.  The reason for removing all listeners is to
                        // make sure that we don't have a listener holding on to something
                        // which will keep it from being garbage collected. We want to
                        // continue freeing listeners to make sure we can free as much
                        // memory has possible
                    }
                }
            } else {
                // The only Listener method that I know of that has more
                // one argument is removePropertyChangeListener.  If it is
                // something other than that, flag it and move on.
                if (!name.equals("removePropertyChangeListener")) {
                    OPDE.debug("    Wrong number of Args " + name);
                }
            }
        }
    }
}

From source file:op.tools.SYSTools.java

public static File[] chooseFile(Component parent, boolean multiselection) {
    File[] result = null;//w  w w  .j  a va2 s.c  o  m
    String cname = parent.getClass().getName();
    String startdir = System.getProperty("user.home");
    if (OPDE.getProps().containsKey("DIR." + cname)) {
        startdir = OPDE.getProps().getProperty("DIR." + cname);
    }
    JFileChooser jfc = new JFileChooser(startdir);
    jfc.setMultiSelectionEnabled(multiselection);
    int response = jfc.showOpenDialog(parent);
    if (response == JFileChooser.APPROVE_OPTION) {
        if (multiselection) {
            result = jfc.getSelectedFiles();
        } else {
            result = new File[] { jfc.getSelectedFile() };
        }

        //String newPath = result[0].getAbsolutePath();
        String myPath = result[0].getParent();
        SYSPropsTools.storeProp("DIR." + cname, myPath, OPDE.getLogin().getUser());

    }
    return result;
}

From source file:edu.harvard.mcz.imagecapture.ui.ButtonEditor.java

@Override
public void actionPerformed(ActionEvent e) {

    // Action might not be event_button_pressed on all systems.
    log.debug("Button event actionCommand: " + e.getActionCommand());
    if (e.getActionCommand().equals(EVENT_PRESSED)) {
        // Event is a click on the cell
        // Identify the row that was clicked on.
        JTable table = (JTable) ((JButton) e.getSource()).getParent();
        log.debug(e.getSource());//  w ww .  ja  v a2s  .c om
        log.debug(table);
        int row = table.getEditingRow();
        // Stop editing - note, we need to have gotten e.getSource.getParent and getEditingRow first.
        fireEditingStopped(); //Make the renderer reappear.
        Singleton.getSingletonInstance().getMainFrame()
                .setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        switch (formToOpen) {
        case OPEN_SPECIMEN_DETAILS:
            // Load the selected specimen record from its ID (the data value behind the button).
            //SpecimenLifeCycle sls = new SpecimenLifeCycle();
            //Specimen specimen = sls.findById((Long)targetId);
            //if (specimen!=null) {
            if (targetId != null) {
                // a specimen with this ID exists, bring up the details editor.
                try {
                    //SpecimenControler sc = new SpecimenControler(specimen);
                    if (((Specimen) targetId).getSpecimenId() != null) {
                        if (((Specimen) targetId).isStateDone()) {
                            // Specimens in state_done are no longer editable
                            JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(),
                                    "This Specimen record has been migrated and can no longer be edited here ["
                                            + ((Specimen) targetId).getLoadFlags()
                                            + "].\nSee: http://mczbase.mcz.harvard.edu/guid/MCZ:Ent:"
                                            + ((Specimen) targetId).getCatNum(),
                                    "Migrated Specimen", JOptionPane.WARNING_MESSAGE);
                        } else {
                            // Specimen is still editable
                            if (table != null) {
                                // Pass the specimen object for the row, the table model, and the row number on to the specimen controler.
                                try {
                                    SpecimenControler sc = new SpecimenControler((Specimen) targetId,
                                            (SpecimenListTableModel) table.getModel(), table, row);
                                    if (table.getParent().getParent().getParent().getParent()
                                            .getClass() == SpecimenBrowser.class) {
                                        sc.addListener((DataChangeListener) table.getParent());
                                    } else {
                                        Component x = table;
                                        boolean done = false;
                                        while (!done) {
                                            log.debug(x.getParent());
                                            x = x.getParent();
                                            if (x.getClass() == SpecimenBrowser.class) {
                                                sc.addListener((DataChangeListener) x);
                                                done = true;
                                            }
                                        }
                                    }
                                    sc.displayInEditor();
                                } catch (java.lang.ClassCastException eNotSp) {
                                    // Request isn't coming from a SpecimenListTableModel
                                    // View just the specimen record.
                                    SpecimenControler sc = new SpecimenControler((Specimen) targetId);
                                    sc.displayInEditor();
                                }
                            } else {
                                log.debug(e.getSource());
                                //SpecimenControler sc = new SpecimenControler((Specimen)targetId);
                                //sc.displayInEditor();
                            }
                        }
                    } else {
                        log.debug("User clicked on table row containing a new Specimen()");
                        JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(),
                                "No Specimen for this image", "Load Specimen Failed",
                                JOptionPane.WARNING_MESSAGE);
                    }
                } catch (NoSuchRecordException e1) {
                    log.error("Tested for specimen!=null, but SpecimenControler threw null specimen exception");
                    log.error(e1);
                }
            } else {
                log.debug("No matches found to specimen id=" + targetId);
                // TODO: Create new specimen record and bring up dialog
                JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(),
                        "No specimen record.");
            }
            break;
        case OPEN_TEMPLATE:
            // Load the selected specimen record from its ID (the data value behind the button).
            try {
                // a template with this targetID exists, display it.
                ((PositionTemplateEditor) parentComponent).setTemplate((String) targetId);
            } catch (NoSuchTemplateException e1) {
                log.error("No such template on button press on a template in list.");
                log.error(e1);
                log.trace(e1);
            }

            break;
        case OPEN_USER:
            //TODO: tie to user
            log.debug("Open user");
            ((UserListBrowser) parentComponent).getEditUserPanel().setUser((Users) targetId);
            break;
        case OPEN_SPECIMEN_VERBATIM:
            log.debug("Open Verbatim Transcription");
            SpecimenLifeCycle sls = new SpecimenLifeCycle();
            List<Specimen> toTranscribe = sls.findForVerbatim(((GenusSpeciesCount) targetId).getGenus(),
                    ((GenusSpeciesCount) targetId).getSpecificEpithet(), WorkFlowStatus.STAGE_1);
            log.debug(toTranscribe.size());
            SpecimenListTableModel stm = new SpecimenListTableModel(toTranscribe);
            JTable stable = new JTable();
            stable.setModel(stm);
            SpecimenControler verbCont;
            try {
                verbCont = new SpecimenControler(toTranscribe.get(0), stm, stable, 0);
                VerbatimCaptureDialog dialog = new VerbatimCaptureDialog(toTranscribe.get(0), verbCont);
                dialog.setVisible(true);
            } catch (NoSuchRecordException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            break;
        case OPEN_VERBATIM_CLASSIFY:
            log.debug("Open Verbatim Classify dialog");
            try {
                VerbatimClassifyDialog dialog = new VerbatimClassifyDialog(
                        (VerbatimCount) table.getModel().getValueAt(row, 0));
                dialog.setVisible(true);
            } catch (ClassCastException e1) {
                log.error(e1.getMessage(), e1);
            }
            break;
        case ACTION_CANCEL_JOB:
            log.debug("Action Cancel requested on job " + targetId);
            Singleton.getSingletonInstance().getJobList().getJobAt((Integer) targetId).cancel();
            break;
        case OPEN_SPECIMENPARTATTRIBUTES:
            SpecimenPartAttributeDialog attrDialog = new SpecimenPartAttributeDialog((SpecimenPart) targetId);
            attrDialog.setVisible(true);
            break;
        }
        Singleton.getSingletonInstance().getMainFrame()
                .setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
        System.gc();
    }
}

From source file:org.nuxeo.launcher.gui.NuxeoFrame.java

public void debug(JComponent parent) {
    for (Component comp : parent.getComponents()) {
        if (comp instanceof JComponent) {
            ((JComponent) comp).setBorder(BorderFactory.createCompoundBorder(
                    BorderFactory.createLineBorder(Color.red), ((JComponent) comp).getBorder()));
            log.info(comp.getClass() + " size: " + ((JComponent) comp).getSize());
        }//from w w  w . j av  a 2  s  .  co m
    }
}