Example usage for javax.swing JRadioButtonMenuItem setName

List of usage examples for javax.swing JRadioButtonMenuItem setName

Introduction

In this page you can find the example usage for javax.swing JRadioButtonMenuItem setName.

Prototype

public void setName(String name) 

Source Link

Document

Sets the name of the component to the specified string.

Usage

From source file:it.cnr.icar.eric.client.ui.swing.metal.MetalThemeMenu.java

/**
 * Constucts a JMenu named 'name' with a a RadioButton for each
 * object in 'themeArray'./*  w  w w .  j  a  v  a 2s .  c om*/
 *
 * @param name the visible name for the Menu.
 * @param themeArray the array of themes to put in the menu.
 */
public MetalThemeMenu(String name, MetalTheme[] themeArray) {
    super(name);
    themeNames = ResourceBundle.getBundle(BASE_NAME, Locale.getDefault());
    themes = themeArray;

    ButtonGroup group = new ButtonGroup();
    JRadioButtonMenuItem defaultItem = null;

    for (int i = 0; i < themes.length; i++) {
        String themeName;

        try {
            themeName = themeNames.getString(themes[i].getName().replaceAll("\\s", ""));
        } catch (MissingResourceException mre) {
            themeName = themes[i].getName();

            Object[] noResourceArgs = { themes[i].getName(), getLocale() };
            MessageFormat form = new MessageFormat(themeNames.getString("message.error.noResource"));
            log.error(form.format(noResourceArgs));
        }

        JRadioButtonMenuItem item = new JRadioButtonMenuItem(themeName);
        group.add(item);
        add(item);
        item.setActionCommand(i + "");
        item.addActionListener(this);

        // Theme name without spaces is the key for looking up localized item text.
        item.setName(themes[i].getName().replaceAll(" ", ""));

        if (i == 0) {
            item.setSelected(true);
            defaultItem = item;
        }
    }

    //add listener for 'locale' bound property
    RegistryBrowser.getInstance().addPropertyChangeListener(RegistryBrowser.PROPERTY_LOCALE, this);

    defaultItem.doClick();
}

From source file:ru.apertum.qsystem.client.forms.FAdmin.java

/**
     * Creates new form FAdmin/*from  www.  j a  v  a 2s  .c  o m*/
     */
    public FAdmin() {
        addWindowListener(new WindowListener() {

            @Override
            public void windowOpened(WindowEvent e) {
            }

            @Override
            public void windowClosing(WindowEvent e) {
                timer.stop();
            }

            @Override
            public void windowClosed(WindowEvent e) {
            }

            @Override
            public void windowIconified(WindowEvent e) {
            }

            @Override
            public void windowDeiconified(WindowEvent e) {
            }

            @Override
            public void windowActivated(WindowEvent e) {
                Uses.closeSplash();
            }

            @Override
            public void windowDeactivated(WindowEvent e) {
            }
        });
        initComponents();

        setTitle(getTitle() + " " + Uses.getLocaleMessage("project.name" + FAbout.getCMRC_SUFF()));

        try {
            setIconImage(
                    ImageIO.read(FAdmin.class.getResource("/ru/apertum/qsystem/client/forms/resources/admin.png")));
        } catch (IOException ex) {
            System.err.println(ex);
        }

        // 
        final Toolkit kit = Toolkit.getDefaultToolkit();
        setLocation((Math.round(kit.getScreenSize().width - getWidth()) / 2),
                (Math.round(kit.getScreenSize().height - getHeight()) / 2));
        // ? ?
        final JFrame fr = this;
        tray = QTray.getInstance(fr, "/ru/apertum/qsystem/client/forms/resources/admin.png",
                getLocaleMessage("tray.caption"));
        tray.addItem(getLocaleMessage("tray.caption"), (ActionEvent e) -> {
            setVisible(true);
            setState(JFrame.NORMAL);
        });
        tray.addItem("-", (ActionEvent e) -> {
        });
        tray.addItem(getLocaleMessage("tray.exit"), (ActionEvent e) -> {
            dispose();
            System.exit(0);
        });

        int ii = 1;
        final ButtonGroup bg = new ButtonGroup();
        final String currLng = Locales.getInstance().getLangCurrName();
        for (String lng : Locales.getInstance().getAvailableLocales()) {
            final JRadioButtonMenuItem item = new JRadioButtonMenuItem(
                    org.jdesktop.application.Application.getInstance(ru.apertum.qsystem.QSystem.class).getContext()
                            .getActionMap(FAdmin.class, fr).get("setCurrentLang"));
            bg.add(item);
            item.setSelected(lng.equals(currLng));
            item.setText(lng); // NOI18N
            item.setName("QRadioButtonMenuItem" + (ii++)); // NOI18N
            menuLangs.add(item);
        }

        //  ??    ??.
        listUsers.addListSelectionListener((ListSelectionEvent e) -> {
            userListChange();
        });
        //  ??    ??.
        listResponse.addListSelectionListener((ListSelectionEvent e) -> {
            responseListChange();
        });
        listSchedule.addListSelectionListener((ListSelectionEvent e) -> {
            scheduleListChange();
        });
        listCalendar.addListSelectionListener(new ListSelectionListener() {

            private int oldSelectedValue = 0;
            private int tmp = 0;

            public int getOldSelectedValue() {
                return oldSelectedValue;
            }

            public void setOldSelectedValue(int oldSelectedValue) {
                this.oldSelectedValue = tmp;
                this.tmp = oldSelectedValue;
            }

            private boolean canceled = false;

            @Override
            public void valueChanged(ListSelectionEvent e) {
                if (canceled) {
                    canceled = false;
                } else {
                    if (tableCalendar.getModel() instanceof CalendarTableModel) {
                        final CalendarTableModel model = (CalendarTableModel) tableCalendar.getModel();
                        if (!model.isSaved()) {
                            final int res = JOptionPane.showConfirmDialog(null,
                                    getLocaleMessage("calendar.change.title"),
                                    getLocaleMessage("calendar.change.caption"), JOptionPane.YES_NO_CANCEL_OPTION,
                                    JOptionPane.QUESTION_MESSAGE);
                            switch (res) {
                            case 0: // ?  ??
                                model.save();
                                calendarListChange();
                                setOldSelectedValue(listCalendar.getSelectedIndex());
                                break;
                            case 1: // ??  ??

                                calendarListChange();
                                setOldSelectedValue(listCalendar.getSelectedIndex());

                                break;
                            case 2: //  ??  ???   
                                canceled = true;
                                listCalendar.setSelectedIndex(getOldSelectedValue());
                                break;
                            }
                        } else {
                            calendarListChange();
                            setOldSelectedValue(listCalendar.getSelectedIndex());
                        }
                    } else {
                        calendarListChange();
                        setOldSelectedValue(listCalendar.getSelectedIndex());
                    }
                }
            }
        });
        //  ??  ?  ??.
        treeServices.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
        treeInfo.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
        /*
         treeServices.setCellRenderer(new DefaultTreeCellRenderer() {
            
         @Override
         public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
         super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
         setText(((Element) value).attributeValue(Uses.TAG_NAME));
         return this;
         }
         });*/
        treeServices.addTreeSelectionListener((TreeSelectionEvent e) -> {
            serviceListChange();
        });
        treeInfo.addTreeSelectionListener((TreeSelectionEvent e) -> {
            infoListChange();
        });

        textFieldStartTime.setInputVerifier(DateVerifier);
        textFieldFinishTime.setInputVerifier(DateVerifier);

        // ?
        loadSettings();
        //   ? ?.
        startTimer();
        //  
        loadConfig();

        spinnerPropServerPort.getModel().addChangeListener(new ChangeNet());
        spinnerPropClientPort.getModel().addChangeListener(new ChangeNet());
        spinnerWebServerPort.getModel().addChangeListener(new ChangeNet());

        spinnerServerPort.getModel().addChangeListener(new ChangeSettings());
        spinnerClientPort.getModel().addChangeListener(new ChangeSettings());
        spinnerUserRS.getModel().addChangeListener(new ChangeUser());

        //?   .
        final Helper helper = Helper.getHelp("ru/apertum/qsystem/client/help/admin.hs");
        helper.setHelpListener(menuItemHelp);
        helper.enableHelpKey(jPanel1, "introduction");
        helper.enableHelpKey(jPanel3, "monitoring");
        helper.enableHelpKey(jPanel4, "configuring");
        helper.enableHelpKey(jPanel8, "net");

        helper.enableHelpKey(jPanel17, "schedulers");
        helper.enableHelpKey(jPanel19, "calendars");
        helper.enableHelpKey(jPanel2, "infoSystem");
        helper.enableHelpKey(jPanel13, "responses");
        helper.enableHelpKey(jPanel18, "results");

        treeServices.setTransferHandler(new TransferHandler() {

            @Override
            public boolean canImport(TransferHandler.TransferSupport info) {
                final JTree.DropLocation dl = (JTree.DropLocation) info.getDropLocation();
                if (dl.getChildIndex() == -1) {
                    return false;
                }
                // Get the string that is being dropped.
                final Transferable t = info.getTransferable();
                final QService data;
                try {
                    data = (QService) t.getTransferData(DataFlavor.stringFlavor);
                    return (data.getParent().getId()
                            .equals(((QService) dl.getPath().getLastPathComponent()).getId()));
                } catch (UnsupportedFlavorException | IOException e) {
                    return false;
                }
            }

            @Override
            public boolean importData(TransferHandler.TransferSupport info) {
                if (!info.isDrop()) {
                    return false;
                }
                final QService data;
                try {
                    data = (QService) info.getTransferable().getTransferData(DataFlavor.stringFlavor);
                } catch (UnsupportedFlavorException | IOException e) {
                    System.err.println(e);
                    return false;
                }
                final JTree.DropLocation dl = (JTree.DropLocation) info.getDropLocation();
                final TreePath tp = dl.getPath();
                final QService parent = (QService) tp.getLastPathComponent();
                ((QServiceTree) treeServices.getModel()).moveNode(data, parent, dl.getChildIndex());
                return true;
            }

            @Override
            public int getSourceActions(JComponent c) {
                return MOVE;
            }

            @Override
            protected Transferable createTransferable(JComponent c) {
                return (QService) ((JTree) c).getLastSelectedPathComponent();
            }
        });
        treeServices.setDropMode(DropMode.INSERT);

        //   ?
        final AnnotationSessionFactoryBean as = (AnnotationSessionFactoryBean) Spring.getInstance().getFactory()
                .getBean("conf");
        if (as.getServers().size() > 1) {
            final JMenu menu = new JMenu(getLocaleMessage("admin.servers"));
            as.getServers().stream().map((ser) -> {
                final JMenuItem mi1 = new JMenuItem(as);
                mi1.setText(ser.isCurrent() ? "<html><u><i>" + ser.getName() + "</i></u>" : ser.getName());
                return mi1;
            }).forEach((mi1) -> {
                menu.add(mi1);
            });
            jMenuBar1.add(menu, 4);
            jMenuBar1.add(new JLabel(
                    "<html><span style='font-size:13.0pt;color:red'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  ["
                            + as.getName() + "]"));
        }
        comboBoxVoices.setVisible(false);
    }

From source file:ru.apertum.qsystem.client.forms.FReception.java

/**
 * Creates new form FReception/*from w  w w.  j  a v a2 s .co  m*/
 *
 * @param netProperty
 */
public FReception(IClientNetProperty netProperty) {
    this.netProperty = netProperty;
    initComponents();

    setTitle(getTitle() + " " + Uses.getLocaleMessage("project.name" + FAbout.getCMRC_SUFF())); //NOI18N

    try {
        setIconImage(ImageIO
                .read(FAdmin.class.getResource("/ru/apertum/qsystem/client/forms/resources/monitor.png"))); //NOI18N
    } catch (IOException ex) {
        System.err.println(ex);
    }

    // .   Escape  
    // ?  esc
    getRootPane().registerKeyboardAction((ActionEvent e) -> {
        setVisible(false);
    }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW);

    //  trayIcon, .. setSituation()   ? tray
    final JFrame fr = this;
    tray = QTray.getInstance(fr, "/ru/apertum/qsystem/client/forms/resources/monitor.png", getTitle()); //NOI18N
    tray.addItem(getLocaleMessage("messages.tray.showClient"), (ActionEvent e) -> {
        setVisible(true);
        setState(JFrame.NORMAL);
    });
    tray.addItem("-", (ActionEvent e) -> {
    });
    tray.addItem(getLocaleMessage("messages.tray.close"), (ActionEvent e) -> {
        dispose();
        System.exit(0);
    });

    int ii = 1;
    final ButtonGroup bg = new ButtonGroup();
    final String currLng = Locales.getInstance().getLangCurrName();
    for (String lng : Locales.getInstance().getAvailableLocales()) {
        final JRadioButtonMenuItem item = new JRadioButtonMenuItem(
                org.jdesktop.application.Application.getInstance(ru.apertum.qsystem.QSystem.class).getContext()
                        .getActionMap(FReception.class, fr).get("setCurrentLang")); //NOI18N
        bg.add(item);
        item.setSelected(lng.equals(currLng));
        item.setText(lng); // NOI18N
        item.setName("QRadioButtonMenuItem" + (ii++)); // NOI18N
        menuLangs.add(item);
    }

    treeServices.addTreeSelectionListener((TreeSelectionEvent e) -> {
        serviceListChange();
    });

    //  ??    ??.
    listUsers.addListSelectionListener((ListSelectionEvent e) -> {
        userListChange();
    });
}