public PlayerWaitingView() { this.setOpaque(true); this.setLayout(new BorderLayout()); this.setBorder(BorderFactory.createLineBorder(Color.black, BORDER_WIDTH)); // set the heading at the top of the pane label = new JLabel("Player Waiting View"); FontUtils.setFont(label, LABEL_TEXT_SIZE); this.add(label, BorderLayout.NORTH); // create the center panel that displays player info center = new JPanel(); center.setLayout(new BoxLayout(center, BoxLayout.Y_AXIS)); this.add(center, BorderLayout.CENTER); // create the AI panel for the bottom of the pane aiPanel = new JPanel(); aiPanel.setLayout(new BoxLayout(aiPanel, BoxLayout.Y_AXIS)); // create the AI type panel JPanel aiTypePanel = new JPanel(); aiTypePanel.setLayout(new BoxLayout(aiTypePanel, BoxLayout.X_AXIS)); aiTypePanel.add(Box.createHorizontalGlue()); JLabel aiTypeLabel = new JLabel("Select AI Type:"); FontUtils.setFont(aiTypeLabel, AI_TEXT_SIZE); aiTypePanel.add(aiTypeLabel); aiTypePanel.add(Box.createRigidArea(new Dimension(5, 0))); aiModel = new SpinnerListModel(); aiChoices = new JSpinner(aiModel); ((JSpinner.DefaultEditor) aiChoices.getEditor()).getTextField().setEditable(false); FontUtils.setFont(aiChoices, AI_TEXT_SIZE); aiTypePanel.add(aiChoices); aiTypePanel.add(Box.createHorizontalGlue()); aiPanel.add(aiTypePanel); aiPanel.add(Box.createRigidArea(new Dimension(0, 10))); // create the AI button panel JPanel aiButtonPanel = new JPanel(); aiButtonPanel.setLayout(new BoxLayout(aiButtonPanel, BoxLayout.X_AXIS)); aiButtonPanel.add(Box.createHorizontalGlue()); addAiButton = new JButton("Add a computer player"); addAiButton.addActionListener(actionListener); FontUtils.setFont(addAiButton, BUTTON_TEXT_SIZE); aiButtonPanel.add(addAiButton); aiButtonPanel.add(Box.createHorizontalGlue()); aiPanel.add(aiButtonPanel); aiPanel.add(Box.createRigidArea(new Dimension(0, 10))); // add the AI panel this.add(aiPanel, BorderLayout.SOUTH); }
private JPanel createForm() { JCheckBox enabledCheckBox = new JCheckBox(Finder.getString("vhost.ssl.edit.enable")); new CheckBoxPropertySynchronizer(enabledProperty, enabledCheckBox); ChangeIndicator enabledChange = new ChangeIndicator(); enabledProperty.addChangeListener(enabledChange); JLabel iPLabel = new JLabel(Finder.getString("vhost.ssl.edit.ip")); JTextField iPField = GUIUtil.createTextField(); new TextComponentPropertySynchronizer<String, JTextComponent>(ipProperty, iPField); ChangeIndicator iPChange = new ChangeIndicator(); ipProperty.addChangeListener(iPChange); JLabel portLabel = new JLabel(Finder.getString("vhost.ssl.edit.port")); SpinnerNumberModel portModel = new SpinnerNumberModel(0, 0, Short.MAX_VALUE, 1); JSpinner portSpinner = new JSpinner(portModel); JComponent editor = portSpinner.getEditor(); if (editor instanceof JSpinner.DefaultEditor) { JTextField field = ((JSpinner.DefaultEditor) editor).getTextField(); field.setColumns(5); field.setHorizontalAlignment(JTextField.RIGHT); } new SpinnerNumberModelPropertySynchronizer(portProperty, portModel, false); portProperty.save(); ChangeIndicator portChange = new ChangeIndicator(); portProperty.addChangeListener(portChange); JLabel certLabel = new JLabel(Finder.getString("vhost.ssl.edit.certificate")); BrowsableFilePanel certPanel = new BrowsableFilePanel(); certPanel.setOpaque(false); fileChoosers.add(certPanel.getFileChooser()); new TextComponentPropertySynchronizer<String, JTextComponent>( certProperty, certPanel.getField()); ChangeIndicator certChange = new ChangeIndicator(); certProperty.addChangeListener(certChange); JLabel keyLabel = new JLabel(Finder.getString("vhost.ssl.edit.key")); BrowsableFilePanel keyPanel = new BrowsableFilePanel(); keyPanel.setOpaque(false); fileChoosers.add(keyPanel.getFileChooser()); new TextComponentPropertySynchronizer<String, JTextComponent>(keyProperty, keyPanel.getField()); ChangeIndicator keyChange = new ChangeIndicator(); keyProperty.addChangeListener(keyChange); JPanel formPanel = new JPanel(); formPanel.setOpaque(false); Form form = new Form(formPanel, VerticalAnchor.TOP); int hGap = GUIUtil.getHalfGap(); int sGap = 3 * hGap; int indent = GUIUtil.getTextXOffset(enabledCheckBox); ColumnLayoutConstraint c = new ColumnLayoutConstraint(HorizontalAnchor.FILL, hGap); RowLayoutConstraint r = new RowLayoutConstraint(VerticalAnchor.CENTER, hGap); HasAnchors a = new SimpleHasAnchors(HorizontalAnchor.LEFT, VerticalAnchor.CENTER); form.addRow(HorizontalAnchor.LEFT, c); form.add(enabledCheckBox, r); form.add(enabledChange, r); form.addTable(2, hGap, hGap, HorizontalAnchor.LEFT, c.setGap(sGap)); form.add(iPLabel, a); form.add(getRow(hGap, iPField, iPChange), a); form.add(portLabel, a); form.add(getRow(hGap, portSpinner, portChange), a); form.add(certLabel, a); form.add(getRow(hGap, certPanel, certChange), a); form.add(keyLabel, a); form.add(getRow(hGap, keyPanel, keyChange), a); return formPanel; }
public NumberField(NumberOption option) { super(option); panel = new JPanel(new GridBagLayout()); this.step = option.getStep(); Double min = option.getMin(); Double max = option.getMax(); Double defl = new Double(option.getDefault()); // Normalize parameters if (min != null && defl.compareTo(min) < 0) { defl = min; } else if (max != null && defl.compareTo(max) > 0) { defl = max; } if (min != null) { sliderMin = (int) (min.doubleValue() / step); } else { sliderMin = SLIDER_DEFAULT_MIN; } if (max != null) { sliderMax = (int) (max.doubleValue() / step); } else { sliderMax = SLIDER_DEFAULT_MAX; } // Create spinner SpinnerNumberModel spinnerModel = new SpinnerNumberModel(defl, min, max, new Double(step)); spinner = new JSpinner(spinnerModel); ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField().setColumns(FIELD_WIDTH); // Create slider slider = new JSlider(sliderMin, sliderMax, sliderIndex(defl)); slider.setPaintLabels(false); slider.setPaintTicks(false); slider.setSnapToTicks(false); // Add listeners. The spinner is the master and the slider is // the slave. spinner.addChangeListener( new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { int newIndex = sliderIndex((Double) spinner.getValue()); if (slider.getValue() != newIndex) { slider.setValue(newIndex); } fireChangeEvent(); } }); slider.addChangeListener( new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { int newIndex = slider.getValue(); if (newIndex != sliderIndex((Double) spinner.getValue())) { spinner.setValue(new Double(newIndex * step)); } } }); // Create enable checkbox configureEnableToggle( option.isInitiallyEnabled(), string(option.getDisabledValue()), Arrays.asList((JComponent) spinner, slider)); // Add to the panel panel.add(spinner); GridBagConstraints c = new GridBagConstraints(); c.insets = new Insets(0, 8, 0, 0); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1; panel.add(slider, c); }