com.googlecode.lanterna.gui2.dialogs.MessageDialogButton Java Examples
The following examples show how to use
com.googlecode.lanterna.gui2.dialogs.MessageDialogButton.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MenuTest.java From lanterna with GNU Lesser General Public License v3.0 | 4 votes |
@Override public void init(final WindowBasedTextGUI textGUI) { // Create window to hold the menu final BasicWindow window = new BasicWindow(); Panel contentPane = new Panel(new BorderLayout()); contentPane.addComponent(Panels.vertical( new Separator(Direction.HORIZONTAL).setLayoutData(LinearLayout.createLayoutData(LinearLayout.Alignment.Fill)), new MultiColorComponent(), new Button("Close", window::close))); window.setComponent(contentPane); MenuBar menubar = new MenuBar(); window.setMenuBar(menubar); // "File" menu Menu menuFile = new Menu("File"); menubar.add(menuFile); menuFile.add(new MenuItem("Open...", () -> { File file = new FileDialogBuilder().build().showDialog(textGUI); if (file != null) MessageDialog.showMessageDialog( textGUI, "Open", "Selected file:\n" + file, MessageDialogButton.OK); })); menuFile.add(new MenuItem("Exit", window::close)); Menu countryMenu = new Menu("Country"); menubar.add(countryMenu); Menu germanySubMenu = new Menu("Germany"); countryMenu.add(germanySubMenu); for (String state: GERMANY_STATES) { germanySubMenu.add(new MenuItem(state, DO_NOTHING)); } Menu japanSubMenu = new Menu("Japan"); countryMenu.add(japanSubMenu); for (String prefecture: JAPAN_PREFECTURES) { japanSubMenu.add(new MenuItem(prefecture, DO_NOTHING)); } // "Help" menu Menu menuHelp = new Menu("Help"); menubar.add(menuHelp); menuHelp.add(new MenuItem("Homepage", () -> MessageDialog.showMessageDialog( textGUI, "Homepage", "https://github.com/mabe02/lanterna", MessageDialogButton.OK))); menuHelp.add(new MenuItem("About", () -> MessageDialog.showMessageDialog( textGUI, "About", "Lanterna drop-down menu", MessageDialogButton.OK))); // Create textGUI and start textGUI textGUI.addWindow(window); }
Example #2
Source File: FancyChooser.java From apdu4j with MIT License | 4 votes |
synchronized void setSelection(List<CardTerminal> terminals) { try { // -1 == Selection not made; -2 == Selection is quit int previouslySelected = quitButton.isFocused() ? -2 : mainActions.getSelectedIndex(); //setStatus("set " + previouslySelected); int selectedIndex = previouslySelected; mainActions.clearItems(); HashMap<String, String> statuses = new HashMap<>(); int i = 0; for (CardTerminal t : terminals) { final String name = t.getName(); final boolean present = t.isCardPresent(); final boolean exclusive = isExlusive(t); String status = EMPTY; if (present) status = PRESENT; if (exclusive) status = EXCLUSIVE; statuses.put(name, status); mainActions.addItem(String.format("[%s] %s", status, aliases.translate(name)), () -> { if (exclusive) { MessageDialog warn = new MessageDialogBuilder() .setTitle(" Warning! ") .setText("Reader is in exclusive use by some other application") .addButton(MessageDialogButton.Cancel) .addButton(MessageDialogButton.Continue) .build(); warn.setCloseWindowWithEscape(true); MessageDialogButton r = warn.showDialog(gui); if (r == null || r == MessageDialogButton.Cancel) { return; } // Continue below } chosenOne = t; mainWindow.close(); }); // Reset if reader becomes exclusive (unless it is the only reader) if (i == selectedIndex && exclusive && !previousStates.get(name).equals(EXCLUSIVE) && terminals.size() > 1) selectedIndex = -1; // Select if only reader becomes non-exclusive if (!exclusive && previousStates.getOrDefault(name, "").equals(EXCLUSIVE) && terminals.size() == 1) selectedIndex = i; // New reader connected if (!previousStates.containsKey(name)) selectedIndex = i; // Select first non-exclusive reader if (selectedIndex == -1 && !exclusive) selectedIndex = i; // Existing reader got a card if (previousStates.getOrDefault(name, "").equals(EMPTY) && present && !exclusive) selectedIndex = i; i++; } // Set title if (terminals.size() == 0) { mainWindow.setTitle(" Connect a reader "); } else { mainWindow.setTitle(" Choose a reader "); } // Update selected index and related focus if (selectedIndex >= 0) { mainActions.setSelectedIndex(selectedIndex); mainActions.takeFocus(); } else { quitButton.takeFocus(); } previousStates = statuses; // Refresh screen mainPanel.invalidate(); //screen.refresh(Screen.RefreshType.COMPLETE); gui.updateScreen(); } catch (CardException | IOException e) { System.err.println(e.getMessage()); throw new RuntimeException(e); } }