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);
}
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;
}
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();
}
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);
}
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);
}
Aggregations