public ChooseConventionDialog(List<Projet> projets) { this.returnValue = DialogReturnValue.CANCEL; this.selectedItem = null; setContentPane(contentPane); setModal(true); getRootPane().setDefaultButton(buttonOK); this.setTitle(ResourceBundle.getBundle("gui.EditConvention").getString("plain.title_choose")); // Fill projects list projets.forEach(conventionComboBox::addItem); buttonOK.addActionListener(e -> onOK()); buttonCancel.addActionListener(e -> onCancel()); // call onCancel() when cross is clicked setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { onCancel(); } }); // call onCancel() on ESCAPE contentPane.registerKeyboardAction( e -> onCancel(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); }
public static void main(String[] args) { JFrame frame = new JFrame("Plot"); frame.getContentPane().setLayout(new BorderLayout()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel commandPanel = new JPanel(new FlowLayout()); JButton openButton = new JButton("Open Ctrl-O"); JButton plotButton = new JButton("Plot Ctrl-P"); JButton quitButton = new JButton("Quit Ctrl-Q"); quitButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); commandPanel.registerKeyboardAction( new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }, KeyStroke.getKeyStroke("control Q"), JComponent.WHEN_IN_FOCUSED_WINDOW); commandPanel.add(openButton); commandPanel.add(plotButton); commandPanel.add(quitButton); frame.getContentPane().add(commandPanel, "North"); GraphPanel graphpanel = new GraphPanel(frame); plotButton.addActionListener(graphpanel); commandPanel.registerKeyboardAction( graphpanel, KeyStroke.getKeyStroke("control P"), JComponent.WHEN_IN_FOCUSED_WINDOW); openButton.addActionListener(graphpanel.getDataPanel()); commandPanel.registerKeyboardAction( graphpanel.getDataPanel(), KeyStroke.getKeyStroke("control O"), JComponent.WHEN_IN_FOCUSED_WINDOW); frame.setVisible(true); frame.pack(); }
private JPanel getRobotImporterContentPane() { if (robotImporterContentPane == null) { robotImporterContentPane = new JPanel(); robotImporterContentPane.setLayout(new BorderLayout()); robotImporterContentPane.add(getButtonsPanel(), BorderLayout.SOUTH); robotImporterContentPane.add(getWizardPanel(), BorderLayout.CENTER); getWizardPanel().getWizardController().setFinishButtonTextAndMnemonic("Extract!", 'E', 0); robotImporterContentPane.registerKeyboardAction( eventHandler, "Refresh", KeyStroke.getKeyStroke(KeyEvent.VK_R, MENU_SHORTCUT_KEY_MASK), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); robotImporterContentPane.registerKeyboardAction( eventHandler, "Refresh", KeyStroke.getKeyStroke(KeyEvent.VK_R, MENU_SHORTCUT_KEY_MASK), JComponent.WHEN_FOCUSED); } return robotImporterContentPane; }
private JPanel getConsoleDialogContentPane() { if (consoleDialogContentPane == null) { consoleDialogContentPane = new JPanel(); consoleDialogContentPane.setLayout(new BorderLayout()); consoleDialogContentPane.add(getButtonsPanel(), "South"); consoleDialogContentPane.add(getScrollPane(), "Center"); consoleDialogContentPane.registerKeyboardAction( eventHandler, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), JComponent.WHEN_FOCUSED); } return consoleDialogContentPane; }
/** * Return the newBattleDialogContentPane * * @return JPanel */ private JPanel getNewBattleDialogContentPane() { if (newBattleDialogContentPane == null) { newBattleDialogContentPane = new JPanel(); newBattleDialogContentPane.setLayout(new BorderLayout()); newBattleDialogContentPane.add(getWizardController(), BorderLayout.SOUTH); newBattleDialogContentPane.add(getTabbedPane(), BorderLayout.CENTER); newBattleDialogContentPane.registerKeyboardAction( eventHandler, "Refresh", KeyStroke.getKeyStroke(KeyEvent.VK_R, MENU_SHORTCUT_KEY_MASK), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); } return newBattleDialogContentPane; }
public dialogAlterarCliente(Cliente cliente) { setContentPane(contentPane); setModal(true); getRootPane().setDefaultButton(buttonOK); borderError = BorderFactory.createLineBorder(Color.red); borderDefault = txtNome.getBorder(); c = cliente; txtNome.setText(c.getNome()); txtCpf.setText(c.getCpf()); txtEndereco.setText(c.getEndereco()); txtEmail.setText(c.getEmail()); txtTelefone.setText(c.getTelefone()); cboxStatusCliente.setSelectedIndex(c.getStatus()); buttonOK.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { onOK(); } }); buttonCancel.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { onCancel(); } }); // call onCancel() when cross is clicked setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { onCancel(); } }); // call onCancel() on ESCAPE contentPane.registerKeyboardAction( new ActionListener() { public void actionPerformed(ActionEvent e) { onCancel(); } }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); }
public LoginDialog(final Frame parent) { super(parent, "Login", true); setContentPane(contentPane); setAlwaysOnTop(true); pack(); getRootPane().setDefaultButton(buttonOK); setDefaultCloseOperation(DISPOSE_ON_CLOSE); setLocationRelativeTo(null); buttonOK.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { onOK(); } }); buttonCancel.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { onCancel(); } }); buttonRegister.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { onRegister(parent); } }); addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { onCancel(); } }); contentPane.registerKeyboardAction( new ActionListener() { public void actionPerformed(ActionEvent e) { onCancel(); } }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); // Only for testing purposes. Remove in first production version loginField.setText("admin"); passwordField.setText("admin"); }
public ErrorReportDialog(AptiAPI aptiAPI, ErrorReport report) { this.aptiAPI = aptiAPI; this.report = report; setContentPane(contentPane); setModal(true); setResizable(false); getRootPane().setDefaultButton(sendReportButton); this.sendReportButton.addActionListener(this); this.dontSendButton.addActionListener(this); this.viewDetailsButton.addActionListener(this); TextFilter.assignFilter(this.descriptionArea, 255, TextFilter.NO_HTML, null); TextFilter.assignFilter(this.nameField, 70, TextFilter.ALPHA_SPACE, null); TextFilter.assignFilter(this.emailAddressField, 100, TextFilter.EMAIL, null); // call onDontSendReport() when cross is clicked setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { onDontSendReport(); } }); // call onDontSendReport() on ESCAPE contentPane.registerKeyboardAction( new ActionListener() { public void actionPerformed(ActionEvent e) { onDontSendReport(); } }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); pack(); setLocationRelativeTo(null); }
public CrearTaulerAutomatic() { setContentPane(contentPane); setModal(true); getRootPane().setDefaultButton(buttonOK); buttonOK.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { onOK(); } }); buttonCancel.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { onCancel(); } }); // call onCancel() when cross is clicked setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { onCancel(); } }); // call onCancel() on ESCAPE contentPane.registerKeyboardAction( new ActionListener() { public void actionPerformed(ActionEvent e) { onCancel(); } }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); }
public GUI() { setContentPane(contentPane); setModal(true); getRootPane().setDefaultButton(buttonOK); buttonOK.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) {} }); btA.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (!bA) { binary++; bA = true; btA.setBackground(Color.RED); } else { bA = false; binary--; btA.setBackground(Color.white); } set(); } }); btB.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (!bB) { binary += 10; bB = true; btB.setBackground(Color.RED); } else { bB = false; binary -= 10; btB.setBackground(Color.white); } set(); } }); btC.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (!bC) { binary += 100; bC = true; btC.setBackground(Color.RED); } else { bC = false; binary -= 100; btC.setBackground(Color.white); } set(); } }); btD.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (!bD) { binary += 1000; bD = true; btD.setBackground(Color.RED); } else { bD = false; binary -= 1000; btD.setBackground(Color.white); } set(); } }); btE.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (!bE) { binary += 10000; bE = true; btE.setBackground(Color.RED); } else { bE = false; binary -= 10000; btE.setBackground(Color.white); } set(); } }); btF.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (!bF) { binary += 100000; bF = true; btF.setBackground(Color.RED); } else { bF = false; binary -= 100000; btF.setBackground(Color.white); } set(); } }); btG.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (!bG) { binary += 1000000; bG = true; btG.setBackground(Color.RED); } else { bG = false; binary -= 1000000; btG.setBackground(Color.white); } set(); } }); buttonCancel.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); // call onCancel() when cross is clicked setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { onCancel(); } }); // call onCancel() on ESCAPE contentPane.registerKeyboardAction( new ActionListener() { public void actionPerformed(ActionEvent e) { onCancel(); } }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); }
public SalaryCheckDlg(SaleSystem saleSystem) { this.saleSystem = saleSystem; setContentPane(contentPane); setModal(true); getRootPane().setDefaultButton(buttonOK); level.setText(saleSystem.account.getLevel() == 1 ? "Normal User" : "Super Manager"); buttonOK.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { onOK(); } }); buttonCancel.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { onCancel(); } }); action = new AbstractAction() { public void actionPerformed(ActionEvent e) { TableCellListener tcl = (TableCellListener) e.getSource(); int row = tcl.getRow(); int column = tcl.getColumn(); Object newValue = tcl.getNewValue(); String x = newValue.toString(); x = x + "f"; float tempSalary = Float.parseFloat(x); int salary = Math.round(tempSalary); // table.setValueAt(newValue, row, column); JTable tempTable = tcl.getTable(); Object clerkObj = tempTable.getValueAt(row, column - 1); String clerkName = clerkObj.toString(); if (saleSystem.account.getLevel() == 0) { if (Integer.parseInt(monthSpinner.getValue().toString()) != 12) { JOptionPane.showMessageDialog(null, "抱歉,只能修改当月数据", "", JOptionPane.ERROR_MESSAGE); tempTable.setValueAt(Integer.parseInt(tcl.getOldValue().toString()), row, column); } else { for (Clerk c : Transition.clerkList) { if (clerkName.equalsIgnoreCase(c.getName())) { c.setSalary(salary); break; } } saleSystem.saveData(); JOptionPane.showMessageDialog(null, "工资修改成功!", "", JOptionPane.INFORMATION_MESSAGE); } } else { JOptionPane.showMessageDialog(null, "抱歉,您无修改权限", "", JOptionPane.ERROR_MESSAGE); tempTable.setValueAt(Integer.parseInt(tcl.getOldValue().toString()), row, column); } } }; // call onCancel() when cross is clicked setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { onCancel(); } }); // call onCancel() on ESCAPE contentPane.registerKeyboardAction( new ActionListener() { public void actionPerformed(ActionEvent e) { onCancel(); } }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize(); int Swing1x = 500; int Swing1y = 300; this.setBounds( screensize.width / 2 - Swing1x / 2, screensize.height / 2 - Swing1y / 2, Swing1x, Swing1y); }
public ImportDialog(boolean targetIsARow, String fileName) { Boolean targetIsARow1 = targetIsARow; contentPane = new JPanel(); contentPane.setLayout(new BorderLayout()); setContentPane(contentPane); JPanel panel3 = new JPanel(); panel3.setBackground(new Color(-1643275)); JLabel labelHeadline = new JLabel(Localization.lang("Import_Metadata_from:")); labelHeadline.setFont(new Font(labelHeadline.getFont().getName(), Font.BOLD, 14)); JLabel labelSubHeadline = new JLabel(Localization.lang("Choose_the_source_for_the_metadata_import")); labelSubHeadline.setFont( new Font(labelSubHeadline.getFont().getName(), labelSubHeadline.getFont().getStyle(), 13)); JLabel labelFileName = new JLabel(); labelFileName.setFont(new Font(labelHeadline.getFont().getName(), Font.BOLD, 14)); JPanel headLinePanel = new JPanel(); headLinePanel.add(labelHeadline); headLinePanel.add(labelFileName); headLinePanel.setBackground(new Color(-1643275)); GridLayout gl = new GridLayout(2, 1); gl.setVgap(10); gl.setHgap(10); panel3.setLayout(gl); panel3.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); panel3.add(headLinePanel); panel3.add(labelSubHeadline); radioButtonNoMeta = new JRadioButton(Localization.lang("Create_blank_entry_linking_the_PDF")); radioButtonXmp = new JRadioButton(Localization.lang("Create_entry_based_on_XMP_data")); radioButtonPDFcontent = new JRadioButton(Localization.lang("Create_entry_based_on_content")); radioButtononlyAttachPDF = new JRadioButton(Localization.lang("Only_attach_PDF")); JButton buttonOK = new JButton(Localization.lang("Ok")); JButton buttonCancel = new JButton(Localization.lang("Cancel")); checkBoxDoNotShowAgain = new JCheckBox(Localization.lang("Do not show this box again for this import")); useDefaultPDFImportStyle = new JCheckBox( Localization.lang("Always use this PDF import style (and do not ask for each import)")); DefaultFormBuilder b = new DefaultFormBuilder(new FormLayout("left:pref, 5dlu, left:pref:grow", "")); b.appendSeparator(Localization.lang("Create New Entry")); b.append(radioButtonNoMeta, 3); b.append(radioButtonXmp, 3); b.append(radioButtonPDFcontent, 3); b.appendSeparator(Localization.lang("Update_Existing_Entry")); b.append(radioButtononlyAttachPDF, 3); b.nextLine(); b.append(checkBoxDoNotShowAgain); b.append(useDefaultPDFImportStyle); b.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); ButtonBarBuilder bb = new ButtonBarBuilder(); bb.addGlue(); bb.addButton(buttonOK); bb.addButton(buttonCancel); bb.addGlue(); bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); contentPane.add(panel3, BorderLayout.NORTH); contentPane.add(b.getPanel(), BorderLayout.CENTER); contentPane.add(bb.getPanel(), BorderLayout.SOUTH); if (!targetIsARow1) { this.radioButtononlyAttachPDF.setEnabled(false); } String name = new File(fileName).getName(); if (name.length() < 34) { labelFileName.setText(name); } else { labelFileName.setText(new File(fileName).getName().substring(0, 33) + "..."); } this.setTitle(Localization.lang("Import_Metadata_From_PDF")); setModal(true); getRootPane().setDefaultButton(buttonOK); // only one of the radio buttons may be selected. ButtonGroup bg = new ButtonGroup(); bg.add(radioButtonNoMeta); bg.add(radioButtonXmp); bg.add(radioButtonPDFcontent); bg.add(radioButtononlyAttachPDF); buttonOK.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { onOK(); } }); buttonCancel.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { onCancel(); } }); setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); addWindowListener( new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { onCancel(); } }); contentPane.registerKeyboardAction( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { onCancel(); } }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); switch (Globals.prefs.getInt(ImportSettingsTab.PREF_IMPORT_DEFAULT_PDF_IMPORT_STYLE)) { case NOMETA: radioButtonNoMeta.setSelected(true); break; case XMP: radioButtonXmp.setSelected(true); break; case CONTENT: radioButtonPDFcontent.setSelected(true); break; case ONLYATTACH: radioButtononlyAttachPDF.setSelected(true); break; default: // fallback radioButtonPDFcontent.setSelected(true); break; } this.setSize(555, 371); }
public void registerKeyboardAction(String command, int key) { panel.registerKeyboardAction( new ControlKeyAction(command), KeyStroke.getKeyStroke(key, 0), JComponent.WHEN_IN_FOCUSED_WINDOW); }
public CreateStorageAccountForm() { setContentPane(contentPane); setModal(true); getRootPane().setDefaultButton(buttonOK); setTitle("Create Storage Account"); buttonOK.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { onOK(); } }); buttonCancel.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { onCancel(); } }); setDefaultCloseOperation(DISPOSE_ON_CLOSE); addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { onCancel(); } }); contentPane.registerKeyboardAction( new ActionListener() { public void actionPerformed(ActionEvent e) { onCancel(); } }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); regionOrAffinityGroupComboBox.setRenderer( new DefaultListCellRenderer() { @Override public Component getListCellRendererComponent( JList jList, Object o, int i, boolean b, boolean b1) { return (o instanceof String) ? super.getListCellRendererComponent(jList, o, i, b, b1) : super.getListCellRendererComponent(jList, " " + o.toString(), i, b, b1); } }); nameTextField .getDocument() .addDocumentListener( new DocumentListener() { @Override public void insertUpdate(DocumentEvent documentEvent) { validateEmptyFields(); } @Override public void removeUpdate(DocumentEvent documentEvent) { validateEmptyFields(); } @Override public void changedUpdate(DocumentEvent documentEvent) { validateEmptyFields(); } }); regionOrAffinityGroupComboBox.addItemListener( new ItemListener() { @Override public void itemStateChanged(ItemEvent itemEvent) { validateEmptyFields(); } }); replicationComboBox.setModel(new DefaultComboBoxModel(ReplicationTypes.values())); replicationComboBox.setRenderer( new DefaultListCellRenderer() { @Override public Component getListCellRendererComponent( JList jList, Object o, int i, boolean b, boolean b1) { return super.getListCellRendererComponent( jList, ((ReplicationTypes) o).getDescription(), i, b, b1); } }); }