Search in sources :

Example 16 with ButtonGroup

use of javax.swing.ButtonGroup in project felix by apache.

the class ControlPoint method doMenuBar.

public void doMenuBar(JFrame frame) {
    JMenuBar menuBar = new JMenuBar();
    // ////////////// FILE
    JMenu file_menu = new JMenu("File");
    file_menu.setMnemonic(KeyEvent.VK_F);
    searchMenu = new JMenu("Search");
    final String ALL_DEVICE = "ssdp:all";
    final String ROOT_DEVICE = "upnp:rootdevice";
    searchMenu.setMnemonic(KeyEvent.VK_L);
    searchMenu.setEnabled(false);
    AbstractAction searchAction = new AbstractAction() {

        public void actionPerformed(ActionEvent e) {
            DriverProxy controller = Mediator.getDriverProxy();
            if (e.getActionCommand().equals(ALL_DEVICE))
                controller.doSearch(ALL_DEVICE);
            else if (e.getActionCommand().equals(ROOT_DEVICE))
                controller.doSearch(ROOT_DEVICE);
        }
    };
    JMenuItem rootDeviceItem = new JMenuItem("Root Devices");
    rootDeviceItem.setMnemonic(KeyEvent.VK_R);
    rootDeviceItem.addActionListener(searchAction);
    rootDeviceItem.setActionCommand(ROOT_DEVICE);
    searchMenu.add(rootDeviceItem);
    JMenuItem allDeviceItem = new JMenuItem("All Devices");
    allDeviceItem.setMnemonic(KeyEvent.VK_A);
    allDeviceItem.addActionListener(searchAction);
    allDeviceItem.setActionCommand(ALL_DEVICE);
    searchMenu.add(allDeviceItem);
    JMenuItem checkIncompleteItem = new JMenuItem("Print Pending Devices");
    checkIncompleteItem.setMnemonic(KeyEvent.VK_I);
    checkIncompleteItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            Mediator.getRootDeviceListener().checkIncompleteDevice();
        }
    });
    JMenuItem checkErrataItem = new JMenuItem("Check Errata UPnPDevices");
    checkErrataItem.setMnemonic(KeyEvent.VK_E);
    checkErrataItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            RootDeviceListener.checkErrataDevice();
        }
    });
    loggerMenu = new JMenu("Felix Logger");
    final String NO_LOGGING = "No Logging";
    final String ERROR = "Error";
    final String WARNING = "Warning";
    final String INFO = "Info";
    final String DEBUG = "Debug";
    loggerMenu.getPopupMenu().addPopupMenuListener(this);
    loggerMenu.setMnemonic(KeyEvent.VK_L);
    loggerMenu.setEnabled(false);
    AbstractAction loggerAction = new AbstractAction() {

        public void actionPerformed(ActionEvent e) {
            DriverProxy controller = Mediator.getDriverProxy();
            if (e.getActionCommand().equals(NO_LOGGING))
                controller.setLogLevel(0);
            else if (e.getActionCommand().equals(ERROR))
                controller.setLogLevel(1);
            else if (e.getActionCommand().equals(WARNING))
                controller.setLogLevel(2);
            else if (e.getActionCommand().equals(INFO))
                controller.setLogLevel(3);
            else if (e.getActionCommand().equals(DEBUG))
                controller.setLogLevel(4);
        }
    };
    ButtonGroup group = new ButtonGroup();
    JRadioButtonMenuItem rbMenuItem = new JRadioButtonMenuItem(NO_LOGGING);
    rbMenuItem.setSelected(true);
    rbMenuItem.setMnemonic(KeyEvent.VK_N);
    rbMenuItem.setActionCommand(NO_LOGGING);
    rbMenuItem.addActionListener(loggerAction);
    group.add(rbMenuItem);
    loggerMenu.add(rbMenuItem);
    loggerMenu.addSeparator();
    rbMenuItem = new JRadioButtonMenuItem(ERROR);
    rbMenuItem.setMnemonic(KeyEvent.VK_E);
    rbMenuItem.setActionCommand(ERROR);
    rbMenuItem.addActionListener(loggerAction);
    group.add(rbMenuItem);
    loggerMenu.add(rbMenuItem);
    rbMenuItem = new JRadioButtonMenuItem(WARNING);
    rbMenuItem.setMnemonic(KeyEvent.VK_W);
    rbMenuItem.setActionCommand(WARNING);
    rbMenuItem.addActionListener(loggerAction);
    group.add(rbMenuItem);
    loggerMenu.add(rbMenuItem);
    rbMenuItem = new JRadioButtonMenuItem(INFO);
    rbMenuItem.setMnemonic(KeyEvent.VK_I);
    rbMenuItem.setActionCommand(INFO);
    rbMenuItem.addActionListener(loggerAction);
    group.add(rbMenuItem);
    loggerMenu.add(rbMenuItem);
    rbMenuItem = new JRadioButtonMenuItem(DEBUG);
    rbMenuItem.setMnemonic(KeyEvent.VK_D);
    rbMenuItem.setActionCommand(DEBUG);
    rbMenuItem.addActionListener(loggerAction);
    group.add(rbMenuItem);
    loggerMenu.add(rbMenuItem);
    final String ON = "On";
    final String OFF = "Off";
    cyberMenu = new JMenu("Cyber Debugger");
    cyberMenu.getPopupMenu().addPopupMenuListener(this);
    cyberMenu.setMnemonic(KeyEvent.VK_C);
    cyberMenu.setEnabled(false);
    AbstractAction cyberAction = new AbstractAction() {

        public void actionPerformed(ActionEvent e) {
            DriverProxy controller = Mediator.getDriverProxy();
            if (e.getActionCommand().equals(ON))
                controller.setCyberDebug(true);
            else if (e.getActionCommand().equals(OFF))
                controller.setCyberDebug(false);
        }
    };
    ButtonGroup cyberGroup = new ButtonGroup();
    rbMenuItem = new JRadioButtonMenuItem(ON);
    rbMenuItem.setSelected(true);
    rbMenuItem.setMnemonic(KeyEvent.VK_O);
    rbMenuItem.setActionCommand(ON);
    rbMenuItem.addActionListener(cyberAction);
    cyberGroup.add(rbMenuItem);
    cyberMenu.add(rbMenuItem);
    rbMenuItem = new JRadioButtonMenuItem(OFF);
    rbMenuItem.setMnemonic(KeyEvent.VK_F);
    rbMenuItem.setActionCommand(OFF);
    rbMenuItem.addActionListener(cyberAction);
    cyberGroup.add(rbMenuItem);
    cyberMenu.add(rbMenuItem);
    /*
        JMenuItem clearSubscriptionItem = new JMenuItem("Clear Subscriptions");
        clearSubscriptionItem.setMnemonic(KeyEvent.VK_S);
        clearSubscriptionItem.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
// to do
                    }
            });
        */
    JMenuItem exitItem = new JMenuItem("Exit");
    exitItem.setMnemonic(KeyEvent.VK_X);
    exitItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            try {
                Activator.context.getBundle().stop();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    });
    file_menu.add(searchMenu);
    file_menu.addSeparator();
    file_menu.add(loggerMenu);
    file_menu.add(cyberMenu);
    file_menu.addSeparator();
    file_menu.add(checkIncompleteItem);
    file_menu.add(checkErrataItem);
    // file_menu.addSeparator();
    // file_menu.add(clearSubscriptionItem);
    file_menu.addSeparator();
    file_menu.add(exitItem);
    menuBar.add(file_menu);
    frame.setJMenuBar(menuBar);
}
Also used : ActionListener(java.awt.event.ActionListener) ButtonGroup(javax.swing.ButtonGroup) ActionEvent(java.awt.event.ActionEvent) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem) DriverProxy(org.apache.felix.upnp.tester.discovery.DriverProxy) JMenuItem(javax.swing.JMenuItem) AbstractAction(javax.swing.AbstractAction) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu) BundleException(org.osgi.framework.BundleException)

Example 17 with ButtonGroup

use of javax.swing.ButtonGroup in project jgnash by ccavanaugh.

the class ActionParser method createMenuItem.

private JMenuItem createMenuItem(final ActionNode node) {
    JMenuItem menu;
    Action a = actionMap.get(node.idref);
    if (node.size() > 0) {
        menu = new JMenu(a);
        for (int i = 0; i < node.size(); i++) {
            ActionNode n = node.getChildAt(i);
            if (n.id == null && n.idref == null) {
                // detect a separator
                ((JMenu) menu).addSeparator();
            } else {
                JMenuItem item = createMenuItem(n);
                menu.add(item);
            }
        }
    } else {
        if (node.type == null || node.type.isEmpty()) {
            menu = new JMenuItem(a);
        } else {
            switch(node.type) {
                case "single":
                    menu = new JCheckBoxMenuItem(a);
                    break;
                case "toggle":
                    menu = new JRadioButtonMenuItem(a);
                    if (node.group != null) {
                        // create a group
                        ButtonGroup bGroup;
                        if (buttonGroups.get(node.group) != null) {
                            bGroup = buttonGroups.get(node.group);
                        } else {
                            bGroup = new ButtonGroup();
                            buttonGroups.put(node.group, bGroup);
                        }
                        bGroup.add(menu);
                    }
                    break;
                default:
                    menu = new JMenuItem(a);
                    break;
            }
        }
    }
    menuItemMap.put(node.idref, menu);
    // store the idref in the JMenuItem
    menu.putClientProperty(ID_REF_ATTRIBUTE, node.idref);
    return menu;
}
Also used : Action(javax.swing.Action) AbstractAction(javax.swing.AbstractAction) ButtonGroup(javax.swing.ButtonGroup) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem) JMenuItem(javax.swing.JMenuItem) JMenu(javax.swing.JMenu) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem)

Example 18 with ButtonGroup

use of javax.swing.ButtonGroup in project jgnash by ccavanaugh.

the class MonthBalanceCSV method getOptions.

private void getOptions() {
    final DatePanel startField = new DatePanel();
    final DatePanel endField = new DatePanel();
    ButtonGroup group = new ButtonGroup();
    JRadioButton vButton = new JRadioButton(rb.getString("Button.Vertical"));
    JRadioButton hButton = new JRadioButton(rb.getString("Button.Horizontal"));
    group.add(vButton);
    group.add(hButton);
    vButton.setSelected(true);
    FormLayout layout = new FormLayout("right:p, 4dlu, p:g", "");
    DefaultFormBuilder builder = new DefaultFormBuilder(layout);
    builder.rowGroupingEnabled(true);
    builder.append(rb.getString("Label.StartDate"), startField);
    builder.append(rb.getString("Label.EndDate"), endField);
    builder.append(rb.getString("Label.Layout"), vButton);
    builder.append("", hButton);
    builder.nextLine();
    builder.appendUnrelatedComponentsGapRow();
    builder.nextLine();
    JPanel panel = builder.getPanel();
    int option = JOptionPane.showConfirmDialog(null, new Object[] { panel }, rb.getString("Message.StartEndDate"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
    if (option == JOptionPane.OK_OPTION) {
        startDate = startField.getLocalDate();
        endDate = endField.getLocalDate();
    }
    vertical = vButton.isSelected();
}
Also used : FormLayout(com.jgoodies.forms.layout.FormLayout) JPanel(javax.swing.JPanel) JRadioButton(javax.swing.JRadioButton) ButtonGroup(javax.swing.ButtonGroup) DatePanel(jgnash.ui.components.DatePanel) DefaultFormBuilder(com.jgoodies.forms.builder.DefaultFormBuilder)

Example 19 with ButtonGroup

use of javax.swing.ButtonGroup in project jgnash by ccavanaugh.

the class AccountOptions method initComponents.

private void initComponents() {
    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    Objects.requireNonNull(engine);
    accountSeparatorField = new JTextField(engine.getAccountSeparator());
    useAccountTermsCheckBox = new JCheckBox(rb.getString("Button.AccTerms"));
    noneButton = new JRadioButton(rb.getString("Button.None"));
    noneButton.setToolTipText(rb.getString("ToolTip.ReversedSignNone"));
    creditAccountsButton = new JRadioButton(rb.getString("Button.CreditAccounts"));
    creditAccountsButton.setToolTipText(rb.getString("ToolTip.ReversedCredit"));
    incomeExpenseAccountsButton = new JRadioButton(rb.getString("Button.IncomeAndExpense"));
    incomeExpenseAccountsButton.setToolTipText(rb.getString("ToolTip.ReversedIncomeExpense"));
    ButtonGroup group = new ButtonGroup();
    group.add(noneButton);
    group.add(creditAccountsButton);
    group.add(incomeExpenseAccountsButton);
}
Also used : JCheckBox(javax.swing.JCheckBox) JRadioButton(javax.swing.JRadioButton) ButtonGroup(javax.swing.ButtonGroup) JTextField(javax.swing.JTextField) Engine(jgnash.engine.Engine)

Example 20 with ButtonGroup

use of javax.swing.ButtonGroup in project jabref by JabRef.

the class ManageKeywordsAction method createDialog.

private void createDialog() {
    if (diag != null) {
        return;
    }
    // keyword to add
    JTextField keyword = new JTextField();
    keywordListModel = new DefaultListModel<>();
    JList<Keyword> keywordList = new JList<>(keywordListModel);
    keywordList.setVisibleRowCount(8);
    JScrollPane kPane = new JScrollPane(keywordList);
    diag = new JDialog(frame, Localization.lang("Manage keywords"), true);
    JButton ok = new JButton(Localization.lang("OK"));
    JButton cancel = new JButton(Localization.lang("Cancel"));
    JButton add = new JButton(Localization.lang("Add"));
    JButton remove = new JButton(Localization.lang("Remove"));
    keywordList.setVisibleRowCount(10);
    intersectKeywords = new JRadioButton(Localization.lang("Display keywords appearing in ALL entries"));
    mergeKeywords = new JRadioButton(Localization.lang("Display keywords appearing in ANY entry"));
    ButtonGroup group = new ButtonGroup();
    group.add(intersectKeywords);
    group.add(mergeKeywords);
    ActionListener stateChanged = e -> fillKeyWordList();
    intersectKeywords.addActionListener(stateChanged);
    mergeKeywords.addActionListener(stateChanged);
    intersectKeywords.setSelected(true);
    FormBuilder builder = FormBuilder.create().layout(new FormLayout("fill:200dlu:grow, 4dlu, fill:pref", "pref, 2dlu, pref, 1dlu, pref, 2dlu, fill:100dlu:grow, 4dlu, pref, 4dlu, pref, "));
    builder.addSeparator(Localization.lang("Keywords of selected entries")).xyw(1, 1, 3);
    builder.add(intersectKeywords).xyw(1, 3, 3);
    builder.add(mergeKeywords).xyw(1, 5, 3);
    builder.add(kPane).xywh(1, 7, 1, 3);
    builder.add(remove).xy(3, 9);
    builder.add(keyword).xy(1, 11);
    builder.add(add).xy(3, 11);
    ButtonBarBuilder bb = new ButtonBarBuilder();
    bb.addGlue();
    bb.addButton(ok);
    bb.addButton(cancel);
    bb.addGlue();
    builder.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    ok.addActionListener(e -> {
        canceled = false;
        diag.dispose();
    });
    Action cancelAction = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            canceled = true;
            diag.dispose();
        }
    };
    cancel.addActionListener(cancelAction);
    final ActionListener addActionListener = arg0 -> addButtonActionListener(keyword);
    add.addActionListener(addActionListener);
    final ActionListener removeActionListenter = arg0 -> {
        List<Keyword> values = keywordList.getSelectedValuesList();
        for (Keyword val : values) {
            keywordListModel.removeElement(val);
        }
    };
    remove.addActionListener(removeActionListenter);
    keywordList.addKeyListener(new KeyListener() {

        @Override
        public void keyTyped(KeyEvent arg0) {
        // Do nothing
        }

        @Override
        public void keyReleased(KeyEvent arg0) {
        // Do nothing
        }

        @Override
        public void keyPressed(KeyEvent arg0) {
            if (arg0.getKeyCode() == KeyEvent.VK_DELETE) {
                removeActionListenter.actionPerformed(null);
            }
        }
    });
    AutoCompleter<String> autoComp = JabRefGUI.getMainFrame().getCurrentBasePanel().getAutoCompleters().get(FieldName.KEYWORDS);
    AutoCompleteListener acl = new AutoCompleteListener(autoComp);
    keyword.addKeyListener(acl);
    keyword.addFocusListener(acl);
    keyword.addKeyListener(new KeyListener() {

        @Override
        public void keyTyped(KeyEvent e) {
        // Do nothing
        }

        @Override
        public void keyReleased(KeyEvent e) {
        // Do nothing
        }

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                addActionListener.actionPerformed(null);
            }
        }
    });
    // Key bindings:
    ActionMap am = builder.getPanel().getActionMap();
    InputMap im = builder.getPanel().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    im.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close");
    am.put("close", cancelAction);
    diag.getContentPane().add(builder.getPanel(), BorderLayout.CENTER);
    diag.getContentPane().add(bb.getPanel(), BorderLayout.SOUTH);
}
Also used : KeyListener(java.awt.event.KeyListener) ActionListener(java.awt.event.ActionListener) NamedCompound(org.jabref.gui.undo.NamedCompound) AutoCompleter(org.jabref.logic.autocompleter.AutoCompleter) Enumeration(java.util.Enumeration) JDialog(javax.swing.JDialog) JTextField(javax.swing.JTextField) FieldName(org.jabref.model.entry.FieldName) StringUtil(org.jabref.model.strings.StringUtil) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) KeywordList(org.jabref.model.entry.KeywordList) Action(javax.swing.Action) BasePanel(org.jabref.gui.BasePanel) JabRefFrame(org.jabref.gui.JabRefFrame) Localization(org.jabref.logic.l10n.Localization) Keyword(org.jabref.model.entry.Keyword) BorderLayout(java.awt.BorderLayout) SpecialFieldsUtils(org.jabref.logic.specialfields.SpecialFieldsUtils) ActionMap(javax.swing.ActionMap) JComponent(javax.swing.JComponent) FormBuilder(com.jgoodies.forms.builder.FormBuilder) JButton(javax.swing.JButton) ButtonGroup(javax.swing.ButtonGroup) BibEntry(org.jabref.model.entry.BibEntry) JList(javax.swing.JList) BorderFactory(javax.swing.BorderFactory) JabRefGUI(org.jabref.JabRefGUI) KeyEvent(java.awt.event.KeyEvent) ActionEvent(java.awt.event.ActionEvent) JRadioButton(javax.swing.JRadioButton) Globals(org.jabref.Globals) JScrollPane(javax.swing.JScrollPane) FieldChange(org.jabref.model.FieldChange) List(java.util.List) DefaultListModel(javax.swing.DefaultListModel) AbstractAction(javax.swing.AbstractAction) FormLayout(com.jgoodies.forms.layout.FormLayout) UndoableFieldChange(org.jabref.gui.undo.UndoableFieldChange) Optional(java.util.Optional) AutoCompleteListener(org.jabref.gui.autocompleter.AutoCompleteListener) InputMap(javax.swing.InputMap) KeyBinding(org.jabref.gui.keyboard.KeyBinding) Action(javax.swing.Action) AbstractAction(javax.swing.AbstractAction) JRadioButton(javax.swing.JRadioButton) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) JTextField(javax.swing.JTextField) KeyEvent(java.awt.event.KeyEvent) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) KeywordList(org.jabref.model.entry.KeywordList) JList(javax.swing.JList) List(java.util.List) AbstractAction(javax.swing.AbstractAction) JScrollPane(javax.swing.JScrollPane) FormLayout(com.jgoodies.forms.layout.FormLayout) FormBuilder(com.jgoodies.forms.builder.FormBuilder) Keyword(org.jabref.model.entry.Keyword) ActionMap(javax.swing.ActionMap) AutoCompleteListener(org.jabref.gui.autocompleter.AutoCompleteListener) ActionListener(java.awt.event.ActionListener) ButtonGroup(javax.swing.ButtonGroup) KeyListener(java.awt.event.KeyListener) InputMap(javax.swing.InputMap) JList(javax.swing.JList) JDialog(javax.swing.JDialog)

Aggregations

ButtonGroup (javax.swing.ButtonGroup)339 JPanel (javax.swing.JPanel)202 JRadioButton (javax.swing.JRadioButton)186 JLabel (javax.swing.JLabel)148 ActionEvent (java.awt.event.ActionEvent)134 ActionListener (java.awt.event.ActionListener)118 BoxLayout (javax.swing.BoxLayout)83 GridBagLayout (java.awt.GridBagLayout)81 JButton (javax.swing.JButton)75 JTextField (javax.swing.JTextField)70 JMenu (javax.swing.JMenu)69 GridBagConstraints (java.awt.GridBagConstraints)67 BorderLayout (java.awt.BorderLayout)64 Insets (java.awt.Insets)64 Dimension (java.awt.Dimension)58 JRadioButtonMenuItem (javax.swing.JRadioButtonMenuItem)57 FlowLayout (java.awt.FlowLayout)53 JMenuItem (javax.swing.JMenuItem)50 JCheckBox (javax.swing.JCheckBox)47 JScrollPane (javax.swing.JScrollPane)47