Example usage for java.awt Component setName

List of usage examples for java.awt Component setName

Introduction

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

Prototype

public void setName(String name) 

Source Link

Document

Sets the name of the component to the specified string.

Usage

From source file:Main.java

public static void setName(Component c, String name) {
    if (c != null) {
        c.setName(name);
    }
}

From source file:com.isencia.passerelle.hmi.generic.GenericHMI.java

/**
 * @param nObj//  w w w  . j  a v  a2 s .co m
 * @param panel
 * @return true if a form was effectively rendered, i.e. when at least 1
 *         parameter was available
 * @throws IllegalActionException
 */
private boolean renderModelComponent(final boolean deep, final NamedObj nObj, final JPanel panel) {
    if (logger.isDebugEnabled()) {
        logger.debug("renderModelComponent() - Entity " + nObj.getFullName()); //$NON-NLS-1$ //$NON-NLS-2$
    }
    if (nObj instanceof CompositeActor && deep) {
        return renderCompositeModelComponent((CompositeActor) nObj, panel);
    } else {
        renderModelComponentAnnotations(nObj, panel);
        final IPasserelleEditorPaneFactory epf = getEditorPaneFactoryForComponent(nObj);
        Component component = null;
        // XXX: temp need to use the new isencia api
        final IPasserelleQuery passerelleQuery = epf.createEditorPaneWithAuthorizer(nObj, this, this);
        if (!passerelleQuery.hasAutoSync()) {
            try {
                final Set<ParameterToWidgetBinder> queryBindings = passerelleQuery.getParameterBindings();
                for (final ParameterToWidgetBinder parameterToWidgetBinder : queryBindings) {
                    hmiFields.put(parameterToWidgetBinder.getBoundParameter().getFullName(),
                            parameterToWidgetBinder);
                }
            } catch (final Exception exception) {
                throw new RuntimeException("Error creating bindings for passerelleQuery", exception);
            }
        }

        final IPasserelleComponent passerelleComponent = passerelleQuery.getPasserelleComponent();
        if (!(passerelleComponent instanceof Component)) {
            return false;
        }

        component = (Component) passerelleComponent;
        // System.out.println("renderModelComponent "+passerelleComponent);
        // Component c =
        // EditorPaneFactory.createEditorPaneWithAuthorizer(nObj, this,
        // this);
        if (component != null && !(component instanceof PasserelleEmptyQuery)) {
            final String name = ModelUtils.getFullNameButWithoutModelName(getCurrentModel(), nObj);
            component.setName(name);
            final JPanel globalPanel = new JPanel(new BorderLayout());

            // Panel for title
            final JPanel titlePanel = createTitlePanel(name);

            // Add a nice background to panels
            titlePanel.setBackground(panel.getBackground());
            ((JComponent) component).setBackground(panel.getBackground());
            // Border
            final Border loweredbevel = BorderFactory.createLoweredBevelBorder();
            final TitledBorder border = BorderFactory.createTitledBorder(loweredbevel/* ,name */);
            globalPanel.setBorder(border);

            globalPanel.add(titlePanel, BorderLayout.NORTH);
            globalPanel.add(component, BorderLayout.CENTER);
            panel.add(globalPanel);

            // StateMachine stuff
            StateMachine.getInstance().registerActionForState(StateMachine.MODEL_OPEN, name, component);
            StateMachine.getInstance().compile();
            return true;
        }
        return false;
    }
}

From source file:org.alex73.skarynka.scan.ui.book.BooksController.java

public BooksController() {
    try {//from   www . j a v a2  s.com
        panel = new BooksPanel();
        ((AbstractDocument) panel.txtNewName.getDocument()).setDocumentFilter(bookNameFilter);

        listScanDirs();

        panel.table.setModel(model());
        panel.table.setRowSelectionAllowed(true);
        panel.table.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 2) {
                    BookRow b = books.get(panel.table.getSelectedRow());
                    DataStorage.openBook(b.bookName, true);
                }
            }

            @Override
            public void mousePressed(MouseEvent e) {
                if (SwingUtilities.isRightMouseButton(e)) {
                    for (int i = 0; i < panel.menuProcess.getComponentCount(); i++) {
                        Component item = panel.menuProcess.getComponent(i);
                        if ((item instanceof JMenuItem) && (item.getName() != null)) {
                            panel.menuProcess.remove(i);
                            i--;
                        }
                    }
                    if (Context.getPermissions().BookControl) {
                        for (int scale : new int[] { 25, 50, 75, 100, 200 }) {
                            JMenuItem item = new JMenuItem(scale + "%");
                            item.setName(scale + "%");
                            item.addActionListener(new ChangeScale(scale));
                            panel.menuProcess.add(item);
                        }
                    }

                    currentBooksNames.clear();
                    int[] selected = panel.table.getSelectedRows();
                    boolean allLocals = true;
                    boolean processAllowed = Context.getPermissions().BookControl;
                    for (int row : selected) {
                        BookRow b = books.get(panel.table.convertRowIndexToModel(row));
                        currentBooksNames.add(b.bookName);
                        if (!b.local) {
                            allLocals = false;
                        }
                    }
                    panel.itemFinish.setVisible(allLocals);
                    if (processAllowed) {
                        for (Map.Entry<String, String> en : Context.getProcessCommands().entrySet()) {
                            JMenuItem item = new JMenuItem(en.getValue());
                            item.setName(en.getKey());
                            item.addActionListener(commandListener);
                            panel.menuProcess.add(item);
                        }
                    }
                    panel.menuProcess.show(panel.table, e.getX(), e.getY());
                }
            }
        });

        panel.btnCreate.setEnabled(false);
        panel.btnCreate.addActionListener(
                new ActionErrorListener(panel, "ERROR_BOOK_CREATE", LOG, "Error create book") {
                    protected void action(ActionEvent e) throws Exception {
                        File bookDir = new File(Context.getBookDir(), panel.txtNewName.getText());
                        if (bookDir.exists()) {
                            JOptionPane.showMessageDialog(panel,
                                    Messages.getString("PANEL_BOOK_NEW_BOOK_EXIST"),
                                    Messages.getString("PANEL_BOOK_TITLE"), JOptionPane.WARNING_MESSAGE);
                            return;
                        }

                        DataStorage.openBook(panel.txtNewName.getText(), true);
                    }
                });

        setMenuListeners();
    } catch (Throwable ex) {
        LOG.error("Error list books", ex);
        JOptionPane.showMessageDialog(DataStorage.mainFrame,
                "Error: " + ex.getClass() + " / " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    }
}

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

/**
*
*//* w ww. j av  a  2s .c om*/
public void addCanvasToLocation(Component canvas, TableauFrame parent) throws Exception {
    ConfigurationProperty commonProperty = ConfigurationManager.getInstance()
            .getProperty(ConfigurationManager.getModule("common"));
    // get //canvasViewPaneLocation/viewPane
    List<ConfigurationProperty> viewPaneList = commonProperty.getProperties("canvasViewPaneLocation.viewPane");
    // for each viewPane
    for (int i = 0; i < viewPaneList.size(); i++) {
        ConfigurationProperty viewPaneProp = (ConfigurationProperty) viewPaneList.get(i);
        // get viewPane.name
        String viewPaneName = viewPaneProp.getProperty("name").getValue();

        // ViewPane theViewPane = getViewPane(parent, viewPane.name);
        ViewPane theViewPane = getViewPane(parent, viewPaneName);
        // if theViewPane == null, throw exception
        if (theViewPane == null) {
            // Check for the case where the ViewPane *is* actually defined
            // in configuration.xml, but it was not parsed from that file
            // because it was specified along with a tableau filter, which
            // the current tableau does not pass.
            if (isInConfigurationFile(viewPaneName)) {
                continue;
            }
            throw new Exception(viewPaneName + " ViewPane specified in " + viewPaneProp.getModule()
                    + " configuration.xml" + " was not found in the ViewManager."
                    + " Make sure you have specified this in the configuration.xml file.");
        }
        List<ConfigurationProperty> viewPaneLocationList = viewPaneProp.getProperties("viewPaneLocation");
        // for each viewPane.viewPaneLocation
        for (int j = 0; j < viewPaneLocationList.size(); j++) {
            ConfigurationProperty viewPaneLocationProp = (ConfigurationProperty) viewPaneLocationList.get(j);
            // get viewPane.viewPaneLocation.name
            String viewPaneLocationName = viewPaneLocationProp.getProperty("name").getValue();
            // if !theViewPane.hasLocation(viewPane.viewPaneLocation.name)
            // throw exception
            if (!theViewPane.hasLocation(viewPaneLocationName)) {
                throw new Exception("The ViewPaneLocation, " + viewPaneLocationName
                        + ", is not an available location of ViewPane, " + viewPaneName);
            }
            // theViewPane.getLocationContainer(viewPane.viewPaneLocation.name).add("Workflow",
            // canvas);

            // see if the tab name for the canvas is specified
            String canvasTabPaneName = "Workflow";
            ConfigurationProperty tabPaneProp = viewPaneProp.getProperty("tabPanename");
            if (tabPaneProp != null) {
                canvasTabPaneName = tabPaneProp.getValue();
            }

            canvas.setName(canvasTabPaneName);

            // add the canvas as the first tab in the view.
            theViewPane.getLocationContainer(viewPaneLocationName).add(canvas, 0);

            // if the canvas is part of a tabbed pane, make sure it is
            // selected
            Component container = canvas.getParent();
            if (container instanceof JTabbedPane) {
                ((JTabbedPane) container).setSelectedIndex(0);
            }
        }
    }
}