Example usage for java.awt Component getName

List of usage examples for java.awt Component getName

Introduction

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

Prototype

public String getName() 

Source Link

Document

Gets the name of the component.

Usage

From source file:org.robotframework.swing.keyword.context.ContextKeywords.java

@RobotKeyword("Returns the component name in current context or title if window or dialog is selected.\n\n"
        + "Example:\n"
        + "| ${context}= | Get Current Context | # Sets the identifier of the current context to a variable |\n")
public String getCurrentContext() {
    Component component = Context.getContext().getSource();
    if (hasTitle(component))
        return titleOf(component);
    return component.getName();
}

From source file:misc.TrackFocusDemo.java

public TrackFocusDemo() {
    super(new BorderLayout());

    JPanel mugshots = new JPanel(new GridLayout(2, 3));
    pic1 = new Picture(createImageIcon("images/" + mayaString + ".jpg", mayaString).getImage());
    pic1.setName("1");
    mugshots.add(pic1);/*from w  w  w.  j  a va  2  s. c o m*/
    pic2 = new Picture(createImageIcon("images/" + anyaString + ".jpg", anyaString).getImage());
    pic2.setName("2");
    mugshots.add(pic2);
    pic3 = new Picture(createImageIcon("images/" + laineString + ".jpg", laineString).getImage());
    pic3.setName("3");
    mugshots.add(pic3);
    pic4 = new Picture(createImageIcon("images/" + cosmoString + ".jpg", cosmoString).getImage());
    pic4.setName("4");
    mugshots.add(pic4);
    pic5 = new Picture(createImageIcon("images/" + adeleString + ".jpg", adeleString).getImage());
    pic5.setName("5");
    mugshots.add(pic5);
    pic6 = new Picture(createImageIcon("images/" + alexiString + ".jpg", alexiString).getImage());
    pic6.setName("6");
    mugshots.add(pic6);

    info = new JLabel("Nothing selected");

    setPreferredSize(new Dimension(450, 350));
    add(mugshots, BorderLayout.CENTER);
    add(info, BorderLayout.PAGE_END);
    setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));

    KeyboardFocusManager focusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    focusManager.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent e) {
            String prop = e.getPropertyName();
            if (("focusOwner".equals(prop)) && ((e.getNewValue()) instanceof Picture)) {

                Component comp = (Component) e.getNewValue();
                String name = comp.getName();
                Integer num = new Integer(name);
                int index = num.intValue();
                if (index < 0 || index > comments.length) {
                    index = 0;
                }
                info.setText(comments[index]);
            }
        }
    });
}

From source file:com.haulmont.ext.web.ui.Call.CallAccessData.java

private Label findLabel(Component component, Collection<Component> components) {
    String id = component.getName();
    if (id == null)
        return null;

    String labelId = id + "Label";
    for (Component c : components) {
        if (c instanceof Label && labelId.equals(c.getName())) {
            return (Label) c;
        }//  w  w w  .j a v a2 s.c om
    }
    return null;
}

From source file:org.parosproxy.paros.extension.history.PopupMenuExportMessage.java

public boolean isEnableForComponent(Component invoker) {

    if (invoker.getName() != null && invoker.getName().equals("ListLog")) {
        try {/*from w  ww  . j  a  va 2s .  co  m*/
            JList list = (JList) invoker;
            if (list.getSelectedIndex() >= 0) {
                this.setEnabled(true);
            } else {
                this.setEnabled(false);
            }
        } catch (Exception e) {
            // ZAP: Log exceptions
            log.warn(e.getMessage(), e);
        }
        return true;

    }
    return false;
}

From source file:umich.ms.batmass.projects.actions.newproject.NewProjectWizardAction.java

@Override
public void actionPerformed(ActionEvent e) {
    List<WizardDescriptor.Panel<WizardDescriptor>> panels = new ArrayList<>();
    panels.add(new NewProjectWizardPanel1());
    panels.add(new NewProjectWizardPanel2());
    String[] steps = new String[panels.size()];
    for (int i = 0; i < panels.size(); i++) {
        Component c = panels.get(i).getComponent();
        // Default step name to component name of panel.
        steps[i] = c.getName();
        if (c instanceof JComponent) { // assume Swing components
            JComponent jc = (JComponent) c;
            jc.putClientProperty(WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, i);
            jc.putClientProperty(WizardDescriptor.PROP_CONTENT_DATA, steps);
            jc.putClientProperty(WizardDescriptor.PROP_AUTO_WIZARD_STYLE, true);
            jc.putClientProperty(WizardDescriptor.PROP_CONTENT_DISPLAYED, true);
            jc.putClientProperty(WizardDescriptor.PROP_CONTENT_NUMBERED, true);
        }/*  w w w  .  j  a va 2s .c  o  m*/
    }
    WizardDescriptor wiz = new WizardDescriptor(new WizardDescriptor.ArrayIterator<>(panels));

    // {0} will be replaced by WizardDesriptor.Panel.getComponent().getName()
    wiz.setTitleFormat(new MessageFormat("{0}"));
    wiz.setTitle("Create a new project");
    if (DialogDisplayer.getDefault().notify(wiz) == WizardDescriptor.FINISH_OPTION) {
        BMProjectFactory pf = (BMProjectFactory) wiz.getProperty(NewProjectWizardPanel1.PROP_PROJECT_FACTORY);
        String name = (String) wiz.getProperty(NewProjectWizardPanel2.PROP_PRROJECT_NAME);
        String location = (String) wiz.getProperty(NewProjectWizardPanel2.PROP_PRROJECT_LOCATION);
        DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(
                name + " @ " + location + "\ntype: " + pf.getClass().getSimpleName()));
        try {
            // now we have all input data to create a project
            // BMProjectFactory should know how to create a proper file structure
            pf.createProjectDirStructure(Paths.get(location), name);

            // and open the project, if it was created
            Path newProjectPath = Paths.get(location);
            FileObject projectToBeOpened = FileUtil.toFileObject(newProjectPath.toFile());
            Project project = ProjectManager.getDefault().findProject(projectToBeOpened);
            Project[] projectsToOpen = { project };
            OpenProjects.getDefault().open(projectsToOpen, false, true);

        } catch (IOException ex) {
            Exceptions.printStackTrace(ex);
        } catch (ConfigurationException ex) {
            Exceptions.printStackTrace(ex);
        }
    }
}

From source file:com.comcast.cats.vision.CATSVisionTest.java

protected JLabel getLabel(Panel parentPanel, String labelName) {
    JLabel label = null;/*from  ww  w .  ja va2  s  .  c o  m*/

    Component[] components = parentPanel.getSwingComponents(JLabel.class);

    for (Component component : components) {
        if (component.getName() == labelName) {
            label = (JLabel) component;

            break;
        }
    }
    return label;
}

From source file:TrackFocusDemo.java

public TrackFocusDemo() {
    super(new BorderLayout());

    JPanel mugshots = new JPanel(new GridLayout(2, 3));
    pic1 = new Picture(createImageIcon("images/" + mayaString + ".jpg", mayaString).getImage());
    pic1.setName("1");
    mugshots.add(pic1);//  w  ww  .  j av a  2s . c  o  m
    pic2 = new Picture(createImageIcon("images/" + anyaString + ".jpg", anyaString).getImage());
    pic2.setName("2");
    mugshots.add(pic2);
    pic3 = new Picture(createImageIcon("images/" + laineString + ".jpg", laineString).getImage());
    pic3.setName("3");
    mugshots.add(pic3);
    pic4 = new Picture(createImageIcon("images/" + cosmoString + ".jpg", cosmoString).getImage());
    pic4.setName("4");
    mugshots.add(pic4);
    pic5 = new Picture(createImageIcon("images/" + adeleString + ".jpg", adeleString).getImage());
    pic5.setName("5");
    mugshots.add(pic5);
    pic6 = new Picture(createImageIcon("images/" + alexiString + ".jpg", alexiString).getImage());
    pic6.setName("6");
    mugshots.add(pic6);

    info = new JLabel("Nothing selected");

    setPreferredSize(new Dimension(450, 350));
    add(mugshots, BorderLayout.CENTER);
    add(info, BorderLayout.PAGE_END);
    setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));

    KeyboardFocusManager focusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    focusManager.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent e) {
            String prop = e.getPropertyName();
            if (("focusOwner".equals(prop)) && (e.getNewValue() != null)
                    && ((e.getNewValue()) instanceof Picture)) {

                Component comp = (Component) e.getNewValue();
                String name = comp.getName();
                Integer num = new Integer(name);
                int index = num.intValue();
                if (index < 0 || index > comments.length) {
                    index = 0;
                }
                info.setText(comments[index]);
            }
        }
    });
}

From source file:it.unibas.spicygui.controllo.addtable.ActionAddSourceTable.java

private WizardDescriptor.Panel[] getPanels() {
    panels = new WizardDescriptor.Panel[] { new NewMappingTaskWizardPanel1(true) };
    String[] steps = new String[panels.length];
    for (int i = 0; i < panels.length; i++) {
        Component c = panels[i].getComponent();
        steps[i] = c.getName();
    }/*ww w .  ja v a2s .c  o  m*/
    return panels;
}

From source file:it.unibas.spicygui.controllo.addtable.ActionAddTargetTable.java

private WizardDescriptor.Panel[] getPanels() {
    panels = new WizardDescriptor.Panel[] { new NewMappingTaskWizardPanel2(true) };
    String[] steps = new String[panels.length];
    for (int i = 0; i < panels.length; i++) {
        Component c = panels[i].getComponent();
        steps[i] = c.getName();
    }/*w w  w .j a  v a2s  .  c  o m*/
    return panels;
}

From source file:com.gdc.nms.web.mibquery.wizard.ciscavate.cjwizard.WizardPage.java

/**
 * Updates the settings map after this page has been
 * used by the user.//from  w w  w  .  j  a  v  a  2 s .com
 * 
 * This method should update the WizardSettings Map so that it contains
 * the new key/value pairs from this page.
 * 
 */
public void updateSettings(WizardSettings settings) {
    for (Component c : _namedComponents) {
        settings.put(c.getName(), getValue(c));
    }
}