private static void showDialog(String[] login) { JTextField uf = new JTextField(20); uf.setText(login[0]); JPasswordField pf = new JPasswordField(20); JPanel p = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.anchor = GridBagConstraints.FIRST_LINE_START; gbc.insets.left = 5; gbc.insets.bottom = 5; gbc.gridx = 0; gbc.gridy = 0; p.add(new JLabel("User"), gbc); gbc.gridx = 1; gbc.gridy = 0; p.add(uf, gbc); gbc.gridx = 0; gbc.gridy = 1; p.add(new JLabel("Password"), gbc); gbc.gridx = 1; gbc.gridy = 1; p.add(pf, gbc); JOptionPane op = new JOptionPane(p); op.setOptions(new String[] {"OK", "Cancel"}); JDialog dlg = op.createDialog(null, "Login"); dlg.pack(); int i = SupportUI.show(dlg, op); if (i != 0) { System.exit(0); } login[0] = uf.getText().trim(); login[1] = new String(pf.getPassword()); }
private boolean confirmClose(String action, Collection modifiedLayers) { if (modifiedLayers.isEmpty()) { return true; } JOptionPane pane = new JOptionPane( StringUtil.split( modifiedLayers.size() + " dataset" + StringUtil.s(modifiedLayers.size()) + " " + ((modifiedLayers.size() > 1) ? "have" : "has") + " been modified (" + ((modifiedLayers.size() > 3) ? "e.g. " : "") + StringUtil.toCommaDelimitedString( new ArrayList(modifiedLayers) .subList(0, Math.min(3, modifiedLayers.size()))) + "). Continue?", 80), JOptionPane.WARNING_MESSAGE); pane.setOptions(new String[] {action, "Cancel"}); pane.createDialog(this, AppContext.getMessage("GeopistaName")).setVisible(true); return pane.getValue().equals(action); }
@Override public void execute(ArrayList<ClassNode> classNodeList) { JOptionPane pane = new JOptionPane( "WARNING: This will load the classes into the JVM and execute allatori decrypter function" + BytecodeViewer.nl + "for each class. IF THE FILE YOU'RE LOADING IS MALICIOUS, DO NOT CONTINUE."); Object[] options = new String[] {"Continue", "Cancel"}; pane.setOptions(options); JDialog dialog = pane.createDialog(BytecodeViewer.viewer, "Bytecode Viewer - WARNING"); dialog.setVisible(true); Object obj = pane.getValue(); int result = -1; for (int k = 0; k < options.length; k++) if (options[k].equals(obj)) result = k; if (result == 0) { try { if (!className.equals("*")) { for (ClassNode classNode : classNodeList) { if (classNode.name.equals(className)) scanClassNode(classNode); } } else { for (ClassNode classNode : classNodeList) { scanClassNode(classNode); } } } catch (Exception e) { new ExceptionUI(e, "github.com/Szperak"); } finally { frame.appendText(out.toString()); frame.setVisible(true); } } }
private static Object showDialog( final JComponent parent, final String title, final List<IEditableProperty> properties, final Object... buttonOptions) { final PropertiesUI panel = new PropertiesUI(properties, true); final JScrollPane scroll = new JScrollPane(panel); scroll.setBorder(null); scroll.getViewport().setBorder(null); final JOptionPane pane = new JOptionPane(scroll, JOptionPane.PLAIN_MESSAGE); pane.setOptions(buttonOptions); final JDialog window = pane.createDialog(JOptionPane.getFrameForComponent(parent), title); window.setVisible(true); return pane.getValue(); }
public void showLoginDialog() throws UnknownHostException { JOptionPane pane = new JOptionPane(); LoginDialog dialog = new LoginDialog(); pane.setMessage(dialog); JButton ok = new JButton("Ok"); ok.addActionListener(new OkAction(pane, dialog)); ok.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) .put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "ok"); ok.getActionMap().put("ok", new OkAction(pane, dialog)); pane.setOptions(new JButton[] {ok}); JDialog dlg = pane.createDialog(parent, "Connect"); dlg.setVisible(true); }
/** * Creates a dialog where the user can specify the location of the database,including the type of * network connection (if this is a networked client)and IP address and port number; or search and * select the database on a local drive if this is a standalone client. * * @param parent Defines the Component that is to be the parent of this dialog box. For * information on how this is used, see <code>JOptionPane</code> * @param connectionMode Specifies the type of connection (standalone or networked) * @see JOptionPane */ public DatabaseLocationDialog(Frame parent, ApplicationMode connectionMode) { configOptions = (new ConfigOptions(connectionMode)); configOptions.getObservable().addObserver(this); // load saved configuration SavedConfiguration config = SavedConfiguration.getSavedConfiguration(); // the port and connection type are irrelevant in standalone mode if (connectionMode == ApplicationMode.STANDALONE_CLIENT) { validPort = true; validCnx = true; networkType = ConnectionType.DIRECT; location = config.getParameter(SavedConfiguration.DATABASE_LOCATION); } else { // there may not be a network connectivity type defined and, if // not, we do not set a default - force the user to make a choice // the at least for the first time they run this. String tmp = config.getParameter(SavedConfiguration.NETWORK_TYPE); if (tmp != null) { try { networkType = ConnectionType.valueOf(tmp); configOptions.setNetworkConnection(networkType); validCnx = true; } catch (IllegalArgumentException e) { log.warning("Unknown connection type: " + networkType); } } // there is always at least a default port number, so we don't have // to validate this. port = config.getParameter(SavedConfiguration.SERVER_PORT); configOptions.setPortNumberText(port); validPort = true; location = config.getParameter(SavedConfiguration.SERVER_ADDRESS); } // there may not be a default database location, so we had better // validate before using the returned value. if (location != null) { configOptions.setLocationFieldText(location); validDb = true; } options = new JOptionPane(configOptions, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION); connectButton.setActionCommand(CONNECT); connectButton.addActionListener(this); boolean allValid = validDb && validPort && validCnx; connectButton.setEnabled(allValid); exitButton.setActionCommand(EXIT); exitButton.addActionListener(this); options.setOptions(new Object[] {connectButton, exitButton}); dialog = options.createDialog(parent, TITLE); dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); dialog.addWindowListener(this); dialog.setVisible(true); }
/** * Creates the edit contractor dialog without displaying it. * * @param parent the parent frame, typically the client main frame */ public EditContractorDialog(final JFrame parent) { super(parent, Text.EDIT_CONTRACTOR_TITLE, true); // modal JPanel panel = new JPanel(); GridBagLayout gridbag = new GridBagLayout(); panel.setLayout(gridbag); addRow( panel, nameField, DBSchema.getFieldName(DBSchema.NAME_INDEX) + ":", DBSchema.getFieldDetailedDescription(DBSchema.NAME_INDEX)); addRow( panel, locationField, DBSchema.getFieldName(DBSchema.LOCATION_INDEX) + ":", DBSchema.getFieldDetailedDescription(DBSchema.LOCATION_INDEX)); addRow( panel, specialtiesField, DBSchema.getFieldName(DBSchema.SPECIALTIES_INDEX) + ":", DBSchema.getFieldDetailedDescription(DBSchema.SPECIALTIES_INDEX)); addRow( panel, sizeField, DBSchema.getFieldName(DBSchema.SIZE_INDEX) + ":", DBSchema.getFieldDetailedDescription(DBSchema.SIZE_INDEX)); addRow( panel, rateField, DBSchema.getFieldName(DBSchema.RATE_INDEX) + ":", DBSchema.getFieldDetailedDescription(DBSchema.RATE_INDEX)); addRow( panel, ownerField, DBSchema.getFieldName(DBSchema.OWNER_INDEX) + ":", DBSchema.getFieldDetailedDescription(DBSchema.OWNER_INDEX)); okButton.setActionCommand(Text.OK); // The OK button's action listener must be added individually. cancelButton.setActionCommand(Text.CANCEL); cancelButton.addActionListener(cancelActionHandler); JOptionPane optionPane = new JOptionPane(panel, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION); optionPane.setOptions(new Object[] {okButton, cancelButton}); setContentPane(optionPane); pack(); setResizable(false); // Leads to windowClosing being called on "crossing out" dialog. setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); addWindowListener( new WindowAdapter() { public void windowClosing(final WindowEvent we) { leaveDialog(Text.CANCEL); } }); setLocationRelativeTo(parent); }