private JTextField getSentryBorderSizeTextField() { if (sentryBorderSizeTextField == null) { sentryBorderSizeTextField = new JTextField(5); sentryBorderSizeTextField.setText("" + battleProperties.getSentryBorderSize()); sentryBorderSizeTextField.setInputVerifier( new InputVerifier() { @Override public boolean verify(JComponent input) { boolean isValid = false; String text = ((JTextField) input).getText(); if (text != null && text.matches("\\d+")) { int borderSize = Integer.parseInt(text); isValid = (borderSize >= 50); } if (!isValid) { WindowUtil.messageError( "'Sentry Border Size' must be an integer value >= 50.\n" + "Default value is 100."); sentryBorderSizeTextField.setText("" + battleProperties.getInactivityTime()); } return isValid; } }); } return sentryBorderSizeTextField; }
private JTextField getGunCoolingRateTextField() { if (gunCoolingRateTextField == null) { gunCoolingRateTextField = new JTextField(5); gunCoolingRateTextField.setText("" + battleProperties.getGunCoolingRate()); gunCoolingRateTextField.setInputVerifier( new InputVerifier() { @Override public boolean verify(JComponent input) { boolean isValid = false; String text = ((JTextField) input).getText(); if (text != null && text.matches("\\d*(\\.\\d+)?")) { double gunCoolingRate = Double.parseDouble(text); isValid = (gunCoolingRate > 0 && gunCoolingRate <= 0.7); } if (!isValid) { WindowUtil.messageError( "'Gun Cooling Rate' must be a floating point number > 0 and <= 0.7.\n" + "Default value is 0.1."); gunCoolingRateTextField.setText("" + battleProperties.getGunCoolingRate()); } return isValid; } }); } return gunCoolingRateTextField; }
private JTextField getNumberOfRoundsTextField() { if (numberOfRoundsTextField == null) { numberOfRoundsTextField = new JTextField(5); numberOfRoundsTextField.setText("" + battleProperties.getNumRounds()); numberOfRoundsTextField.setInputVerifier( new InputVerifier() { @Override public boolean verify(JComponent input) { boolean isValid = false; String text = ((JTextField) input).getText(); if (text != null && text.matches("\\d+")) { int numRounds = Integer.parseInt(text); isValid = (numRounds > 0); } if (!isValid) { WindowUtil.messageError( "'Number of Rounds' must be an integer value > 0.\n" + "Default value is 10."); numberOfRoundsTextField.setText("" + battleProperties.getNumRounds()); } return isValid; } }); } return numberOfRoundsTextField; }
private void addCountFilter(final String label, final Integer value) { add(GuiBuilder.buildLabel(label, BOLD_12, null), Constraints.LBL_COUNT); final String valueStr = value != null ? value.toString() : ""; txtCount = GuiBuilder.buildTextField(valueStr, Color.white); txtCount.setInputVerifier( new IntegerVerifier(txtCount, GuiConfig.getInstance().getTxtInvalidInteger())); add(txtCount, Constraints.TXT_COUNT); }
/** * This method initializes jTextField * * <p>return javax.swing.JTextField */ private JTextField getJTextFieldPorcentaje() { if (jTextFieldPorcentaje == null) { jTextFieldPorcentaje = new JTextField(); jTextFieldPorcentaje.setPreferredSize(new java.awt.Dimension(50, 20)); // Generated jTextFieldPorcentaje.setText(String.valueOf(this.porcentaje)); jTextFieldPorcentaje.setInputVerifier(new TextVerifier(3, "0123456789")); AbstractDocument doc = (AbstractDocument) jTextFieldPorcentaje.getDocument(); doc.setDocumentFilter(new DocumentContentFilter(10, "0123456789")); jTextFieldPorcentaje.addKeyListener(this); } return jTextFieldPorcentaje; }
/** * Purpose: construct the panel displayed when the user is not logged in. Allows the user to * choose a server and port to login to with their username and password */ private void createAuthenticatePanel() { final JPanel authPanel = Gui.GBPanel(this, null, null); authPanel.setPreferredSize(new Dimension(600, 400)); // add the labels Gui.addLabel(authPanel, "server", Gui.Gbc(0, 0)); Gui.addLabel(authPanel, "port", Gui.Gbc(0, 1)); Gui.addLabel(authPanel, "User", Gui.Gbc(0, 2)); Gui.addLabel(authPanel, "Password", Gui.Gbc(0, 3)); // add the fields final JTextField serverText = new JTextField("localhost"); final JTextField portText = new JTextField("5776"); portText.setInputVerifier(Gui.IntegerInputVerifier()); final JTextField userText = new JTextField(); final JPasswordField password = new JPasswordField(); authPanel.add(serverText, Gui.Gbc(1, 0)); authPanel.add(portText, Gui.Gbc(1, 1)); authPanel.add(userText, Gui.Gbc(1, 2)); authPanel.add(password, Gui.Gbc(1, 3)); // login button and authentication action GridBagConstraints loginGbc = Gui.Gbc(0, 4); loginGbc.gridwidth = 2; Gui.addButton( authPanel, "Login", loginGbc, new ActionListener() { public void actionPerformed(ActionEvent evt) { browserController .getNetworkController() .connectAndList( serverText.getText(), Integer.parseInt(portText.getText()), userText.getText(), password.getPassword(), new AsyncResult<HttpResponse>() { public void OnSuccess(HttpResponse response) { createBrowserUI(response.getResultFiles()); } public void OnFailure(HttpResponse result) { Gui.alert(_ref, "Authentication Failed!\n\n" + result, true); } }); } }); }
/** * Creates a text field to display the directory path * * @return the text field */ public JTextField createTextField() { JTextField text = new JTextField(); text.setPreferredSize(favoriteDim); text.setMinimumSize(favoriteDim); text.setHorizontalAlignment(JTextField.LEFT); text.setEditable(true); text.setBackground(Color.white); text.setEditable(false); text.setInputVerifier( new InputVerifier() { public boolean verify(JComponent input) { return false; } }); return text; }
private void initGUI() { try { this.setLayout(null); this.setPreferredSize(new java.awt.Dimension(431, 174)); this.setSize(405, 166); { panelAnswerInfo = new JPanel(); this.add( panelAnswerInfo, new AnchorConstraint( 41, 12, 67, 12, AnchorConstraint.ANCHOR_ABS, AnchorConstraint.ANCHOR_ABS, AnchorConstraint.ANCHOR_ABS, AnchorConstraint.ANCHOR_ABS)); panelAnswerInfo.setBorder(BorderFactory.createTitledBorder("Answer Info")); panelAnswerInfo.setLayout(null); panelAnswerInfo.setBounds(0, 0, 431, 174); panelAnswerInfo.setPreferredSize(new java.awt.Dimension(431, 174)); { ComboBoxModel cbCategoriesModel = new DefaultComboBoxModel(new String[] {"Pro", "Contra"}); cbArgument = new JComboBox(); panelAnswerInfo.add( cbArgument, new AnchorConstraint( 614, 722, 708, 281, AnchorConstraint.ANCHOR_NONE, AnchorConstraint.ANCHOR_NONE, AnchorConstraint.ANCHOR_NONE, AnchorConstraint.ANCHOR_NONE)); cbArgument.setModel(cbCategoriesModel); cbArgument.setBounds(122, 135, 184, 23); } { lblArgumentAnswer = new JLabel(); panelAnswerInfo.add( lblArgumentAnswer, new AnchorConstraint( 628, 255, 683, 28, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL)); lblArgumentAnswer.setName("lblCategoryProposal"); lblArgumentAnswer.setBounds(12, 139, 104, 15); lblArgumentAnswer.setText(ApplicationInternationalization.getString("lblArgumentAnswer")); } { txtDescription = new JTextArea(); txtDescription.setInputVerifier( new NotEmptyValidator( parentD, txtDescription, ApplicationInternationalization.getString("fieldValidateEmpty"))); panelAnswerInfo.add( txtDescription, new AnchorConstraint( 210, 968, 585, 281, AnchorConstraint.ANCHOR_NONE, AnchorConstraint.ANCHOR_NONE, AnchorConstraint.ANCHOR_NONE, AnchorConstraint.ANCHOR_NONE)); txtDescription.setBounds(122, 58, 270, 65); } { txtTitle = new JTextField(); txtTitle.setInputVerifier( new NotEmptyValidator( parentD, txtTitle, "FallO" + ApplicationInternationalization.getString("fieldValidateEmpty"))); panelAnswerInfo.add( txtTitle, new AnchorConstraint( 148, 968, 242, 281, AnchorConstraint.ANCHOR_NONE, AnchorConstraint.ANCHOR_NONE, AnchorConstraint.ANCHOR_NONE, AnchorConstraint.ANCHOR_NONE)); txtTitle.setBounds(122, 23, 270, 23); } { lblDescriptionAnswer = new JLabel(); panelAnswerInfo.add( lblDescriptionAnswer, new AnchorConstraint( 268, 255, 323, 28, AnchorConstraint.ANCHOR_NONE, AnchorConstraint.ANCHOR_NONE, AnchorConstraint.ANCHOR_NONE, AnchorConstraint.ANCHOR_NONE)); lblDescriptionAnswer.setName("lblDescriptionProposal"); lblDescriptionAnswer.setBounds(12, 58, 98, 16); lblDescriptionAnswer.setText( ApplicationInternationalization.getString("lblDescriptionAnswer")); } { lblAnswerTitle = new JLabel(); panelAnswerInfo.add( lblAnswerTitle, new AnchorConstraint( 88, 255, 134, 28, AnchorConstraint.ANCHOR_NONE, AnchorConstraint.ANCHOR_NONE, AnchorConstraint.ANCHOR_NONE, AnchorConstraint.ANCHOR_NONE)); lblAnswerTitle.setName("lblProposalTitle"); lblAnswerTitle.setBounds(12, 23, 98, 16); lblAnswerTitle.setText(ApplicationInternationalization.getString("lblAnswerTitle")); } } Application.getInstance().getContext().getResourceMap(getClass()).injectComponents(this); } catch (Exception e) { e.printStackTrace(); } }
/** Setup the GUI. */ private void setupGUI() { JPanel mainPanel = new JPanel(); this.setContentPane(mainPanel); // start layout mainPanel.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 0; gbc.fill = GridBagConstraints.NONE; gbc.weightx = 0; gbc.anchor = GridBagConstraints.WEST; gbc.insets = new Insets(5, 5, 2, 5); JLabel valueLabel = new JLabel( I18N.getMessage(I18N.getGUIBundle(), "gui.action.edit_parallel_line.value.label")); this.add(valueLabel, gbc); gbc.gridx = 1; gbc.gridy = 0; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.weightx = 1; valueField = new JTextField(); valueField.setInputVerifier( new InputVerifier() { @Override public boolean verify(JComponent input) { return verifyValueInput(input); } }); valueField.setToolTipText( I18N.getMessage(I18N.getGUIBundle(), "gui.action.edit_parallel_line.value.tip")); this.add(valueField, gbc); gbc.gridx = 0; gbc.gridy = 1; gbc.fill = GridBagConstraints.NONE; gbc.weightx = 0; JLabel colorLabel = new JLabel( I18N.getMessage(I18N.getGUIBundle(), "gui.action.edit_parallel_line.color.label")); this.add(colorLabel, gbc); gbc.gridx = 1; gbc.gridy = 1; lineColorButton = new JButton( new ResourceAction(true, "edit_parallel_line.select_line_color") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { createLineColorDialog(); } }); this.add(lineColorButton, gbc); gbc.gridx = 0; gbc.gridy = 2; JLabel widthLabel = new JLabel( I18N.getMessage(I18N.getGUIBundle(), "gui.action.edit_parallel_line.width.label")); this.add(widthLabel, gbc); gbc.gridx = 1; gbc.gridy = 2; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.weightx = 1; widthField = new JTextField(); widthField.setInputVerifier( new InputVerifier() { @Override public boolean verify(JComponent input) { return verifyWidthInput(input); } }); widthField.setToolTipText( I18N.getMessage(I18N.getGUIBundle(), "gui.action.edit_parallel_line.width.tip")); this.add(widthField, gbc); gbc.gridx = 0; gbc.gridy = 3; gbc.fill = GridBagConstraints.NONE; gbc.weightx = 0; JLabel styleLabel = new JLabel( I18N.getMessage(I18N.getGUIBundle(), "gui.action.edit_parallel_line.line_style.label")); this.add(styleLabel, gbc); gbc.gridx = 1; gbc.gridy = 3; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.weightx = 1; lineStyleCombobox = new JComboBox(LineStyle.values()); ((DefaultComboBoxModel) lineStyleCombobox.getModel()).removeElement(LineStyle.NONE); lineStyleCombobox.setToolTipText( I18N.getMessage(I18N.getGUIBundle(), "gui.action.edit_parallel_line.line_style.tip")); lineStyleCombobox.setSelectedItem(LineStyle.SOLID); this.add(lineStyleCombobox, gbc); gbc.gridx = 0; gbc.gridy = 4; gbc.gridwidth = 2; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.weightx = 1; gbc.weighty = 0; gbc.anchor = GridBagConstraints.CENTER; gbc.insets = new Insets(15, 5, 5, 5); this.add(new JSeparator(), gbc); gbc.gridx = 0; gbc.gridy = 5; gbc.gridwidth = 1; gbc.fill = GridBagConstraints.NONE; gbc.anchor = GridBagConstraints.WEST; gbc.insets = new Insets(5, 5, 5, 5); okButton = new JButton(I18N.getMessage(I18N.getGUIBundle(), "gui.action.edit_parallel_line.ok.label")); okButton.setToolTipText( I18N.getMessage(I18N.getGUIBundle(), "gui.action.edit_parallel_line.ok.tip")); okButton.setIcon( SwingTools.createIcon( "24/" + I18N.getMessage(I18N.getGUIBundle(), "gui.action.edit_parallel_line.ok.icon"))); okButton.setMnemonic( I18N.getMessage(I18N.getGUIBundle(), "gui.action.edit_parallel_line.ok.mne") .toCharArray()[0]); okButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { boolean successful = editLine(); // don't dispose dialog if not successful if (!successful) { return; } EditParallelLineDialog.this.dispose(); } }); okButton.addKeyListener( new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { okButton.doClick(); } } }); this.add(okButton, gbc); gbc.gridx = 1; gbc.gridy = 5; gbc.fill = GridBagConstraints.NONE; gbc.anchor = GridBagConstraints.EAST; cancelButton = new JButton( I18N.getMessage(I18N.getGUIBundle(), "gui.action.edit_parallel_line.cancel.label")); cancelButton.setToolTipText( I18N.getMessage(I18N.getGUIBundle(), "gui.action.edit_parallel_line.cancel.tip")); cancelButton.setIcon( SwingTools.createIcon( "24/" + I18N.getMessage( I18N.getGUIBundle(), "gui.action.edit_parallel_line.cancel.icon"))); cancelButton.setMnemonic( I18N.getMessage(I18N.getGUIBundle(), "gui.action.edit_parallel_line.cancel.mne") .toCharArray()[0]); cancelButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // cancel requested, close dialog EditParallelLineDialog.this.dispose(); } }); this.add(cancelButton, gbc); // misc settings this.setMinimumSize(new Dimension(275, 225)); // center dialog this.setLocationRelativeTo(null); this.setTitle( I18N.getMessage(I18N.getGUIBundle(), "gui.action.edit_parallel_line.title.label")); this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); this.setModal(true); this.addWindowListener( new WindowAdapter() { @Override public void windowActivated(WindowEvent e) { cancelButton.requestFocusInWindow(); } }); }
/** Setup the GUI. */ private void setupGUI() { JPanel mainPanel = new JPanel(); this.setContentPane(mainPanel); // start layout mainPanel.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 0; gbc.fill = GridBagConstraints.NONE; gbc.weightx = 1; gbc.anchor = GridBagConstraints.WEST; gbc.insets = new Insets(5, 5, 2, 5); JLabel widthLabel = new JLabel( I18N.getMessage( I18N.getGUIBundle(), "gui.action.export_newplotter_image.width.label")); this.add(widthLabel, gbc); gbc.gridx = 1; gbc.gridy = 0; gbc.insets = new Insets(2, 5, 2, 5); gbc.fill = GridBagConstraints.HORIZONTAL; widthField = new JTextField(); widthField.setText(String.valueOf(width)); widthField.setToolTipText( I18N.getMessage( I18N.getGUIBundle(), "gui.action.export_newplotter_image.width.tip", MIN_WIDTH, MAX_WIDTH)); widthField.setInputVerifier( new InputVerifier() { @Override public boolean verify(JComponent input) { JTextField textField = (JTextField) input; String inputString = textField.getText(); try { int number = Integer.parseInt(inputString); if (number < MIN_WIDTH || number > MAX_WIDTH) { textField.setForeground(Color.RED); return false; } } catch (NumberFormatException e) { textField.setForeground(Color.RED); return false; } textField.setForeground(Color.BLACK); return true; } }); this.add(widthField, gbc); gbc.gridx = 0; gbc.gridy = 1; gbc.fill = GridBagConstraints.NONE; JLabel heightLabel = new JLabel( I18N.getMessage( I18N.getGUIBundle(), "gui.action.export_newplotter_image.height.label")); this.add(heightLabel, gbc); gbc.gridx = 1; gbc.gridy = 1; gbc.fill = GridBagConstraints.HORIZONTAL; heightField = new JTextField(); heightField.setToolTipText( I18N.getMessage( I18N.getGUIBundle(), "gui.action.export_newplotter_image.height.tip", MIN_HEIGHT, MAX_HEIGHT)); heightField.setText(String.valueOf(height)); heightField.setInputVerifier( new InputVerifier() { @Override public boolean verify(JComponent input) { JTextField textField = (JTextField) input; String inputString = textField.getText(); try { int number = Integer.parseInt(inputString); if (number < MIN_HEIGHT || number > MAX_HEIGHT) { textField.setForeground(Color.RED); return false; } } catch (NumberFormatException e) { textField.setForeground(Color.RED); return false; } textField.setForeground(Color.BLACK); return true; } }); this.add(heightField, gbc); gbc.gridx = 0; gbc.gridy = 2; gbc.gridwidth = 2; gbc.anchor = GridBagConstraints.CENTER; gbc.insets = new Insets(15, 5, 5, 5); this.add(new JSeparator(), gbc); gbc.gridx = 0; gbc.gridy = 3; gbc.gridwidth = 1; gbc.fill = GridBagConstraints.NONE; gbc.anchor = GridBagConstraints.EAST; gbc.insets = new Insets(5, 5, 5, 5); okButton = new JButton( I18N.getMessage(I18N.getGUIBundle(), "gui.action.export_newplotter_image.ok.label")); okButton.setToolTipText( I18N.getMessage(I18N.getGUIBundle(), "gui.action.export_newplotter_image.ok.tip")); okButton.setMnemonic( I18N.getMessage(I18N.getGUIBundle(), "gui.action.export_newplotter_image.ok.mne") .toCharArray()[0]); okButton.setPreferredSize(new Dimension(75, 25)); okButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { DimensionDialog.this.width = Integer.parseInt(widthField.getText()); DimensionDialog.this.height = Integer.parseInt(heightField.getText()); DimensionDialog.this.returnVal = JOptionPane.OK_OPTION; DimensionDialog.this.dispose(); } }); this.add(okButton, gbc); gbc.gridx = 1; gbc.gridy = 3; gbc.fill = GridBagConstraints.NONE; gbc.anchor = GridBagConstraints.WEST; cancelButton = new JButton( I18N.getMessage( I18N.getGUIBundle(), "gui.action.export_newplotter_image.cancel.label")); cancelButton.setToolTipText( I18N.getMessage(I18N.getGUIBundle(), "gui.action.export_newplotter_image.cancel.tip")); cancelButton.setMnemonic( I18N.getMessage(I18N.getGUIBundle(), "gui.action.export_newplotter_image.cancel.mne") .toCharArray()[0]); cancelButton.setPreferredSize(new Dimension(75, 25)); cancelButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { DimensionDialog.this.returnVal = JOptionPane.CANCEL_OPTION; DimensionDialog.this.dispose(); } }); this.add(cancelButton, gbc); // misc settings this.setMinimumSize(new Dimension(250, 150)); // center dialog this.setLocationRelativeTo(null); this.setTitle( I18N.getMessage(I18N.getGUIBundle(), "gui.action.export_newplotter_image.title.label")); this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); this.setModal(true); }