Java Code Examples for javax.swing.JRadioButton#addItemListener()

The following examples show how to use javax.swing.JRadioButton#addItemListener() . 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: HSQLSettings.java    From cropplanning with GNU General Public License v3.0 6 votes vote down vote up
public HSQLSettings() {
    super( HSQLDB.class );
    CPSModule.debug( "HSQLSettings", "using pref node:" + HSQLDB.class.toString() );
    
    rdoUseGlobalDir = new JRadioButton( "Use global output directory", false );
    rdoUseGlobalDir.addItemListener(this);
    rdoUseCustomDir = new JRadioButton( "Use other directory:", false );
    rdoUseCustomDir.addItemListener(this);
    ButtonGroup bg = new ButtonGroup();
    bg.add( rdoUseCustomDir );
    bg.add( rdoUseGlobalDir );
    
    lblCustomOutDir = new JLabel();
    
    flchCustomDir = new JFileChooser();
    flchCustomDir.setFileSelectionMode( JFileChooser.DIRECTORIES_ONLY );
    
    btnCustomDir = new JButton( "Choose Output Directory" );
    btnCustomDir.addActionListener(this);
    
    buildConfigPanel();
    rdoUseGlobalDir.doClick();
    
}
 
Example 2
Source File: Query.java    From OpenDA with GNU Lesser General Public License v3.0 5 votes vote down vote up
/** Create an on-off check box.
 *  @param name The name used to identify the entry (when calling get).
 *  @param label The label to attach to the entry.
 *  @param defaultValue The default value (true for on).
 */
public void addCheckBox(String name, String label, boolean defaultValue) {
    JLabel lbl = new JLabel(label + ": ");
    lbl.setBackground(_background);
    JRadioButton checkbox = new JRadioButton();
    checkbox.setBackground(_background);
    checkbox.setOpaque(false);
    checkbox.setSelected(defaultValue);
    _addPair(name, lbl, checkbox, checkbox);
    // Add the listener last so that there is no notification
    // of the first value.
    checkbox.addItemListener(new QueryItemListener(name));
}
 
Example 3
Source File: WebDriverConfigGui.java    From jmeter-plugins-webdriver with Apache License 2.0 5 votes vote down vote up
private void createPacUrlProxy(JPanel panel, ButtonGroup group) {
    pacUrlProxy = new JRadioButton("Automatic proxy configuration URL");
    group.add(pacUrlProxy);
    panel.add(pacUrlProxy);

    pacUrlProxy.addItemListener(this);

    JPanel pacUrlPanel = new HorizontalPanel();
    pacUrl = new JTextField();
    pacUrl.setEnabled(false);
    pacUrlPanel.add(pacUrl, BorderLayout.CENTER);
    pacUrlPanel.setBorder(BorderFactory.createEmptyBorder(0, PROXY_FIELD_INDENT, 0, 0));
    panel.add(pacUrlPanel);
}
 
Example 4
Source File: WebDriverConfigGui.java    From jmeter-plugins-webdriver with Apache License 2.0 5 votes vote down vote up
private void createManualProxy(JPanel panel, ButtonGroup group) {
    manualProxy = new JRadioButton("Manual proxy configuration");
    group.add(manualProxy);
    panel.add(manualProxy);

    manualProxy.addItemListener(this);

    JPanel manualPanel = new VerticalPanel();
    manualPanel.setBorder(BorderFactory.createEmptyBorder(0, PROXY_FIELD_INDENT, 0, 0));

    httpProxyHost = new JTextField();
    httpProxyPort = new JFormattedTextField(NUMBER_FORMAT);
    httpProxyPort.setText(String.valueOf(DEFAULT_PROXY_PORT));
    manualPanel.add(createProxyHostAndPortPanel(httpProxyHost, httpProxyPort, "HTTP Proxy:"));
    useHttpSettingsForAllProtocols = new JCheckBox("Use HTTP proxy server for all protocols");
    useHttpSettingsForAllProtocols.setSelected(true);
    useHttpSettingsForAllProtocols.setEnabled(false);
    useHttpSettingsForAllProtocols.addItemListener(this);
    manualPanel.add(useHttpSettingsForAllProtocols);

    httpsProxyHost = new JTextField();
    httpsProxyPort = new JFormattedTextField(NUMBER_FORMAT);
    httpsProxyPort.setText(String.valueOf(DEFAULT_PROXY_PORT));
    manualPanel.add(createProxyHostAndPortPanel(httpsProxyHost, httpsProxyPort, "SSL Proxy:"));

    ftpProxyHost = new JTextField();
    ftpProxyPort = new JFormattedTextField(NUMBER_FORMAT);
    ftpProxyPort.setText(String.valueOf(DEFAULT_PROXY_PORT));
    manualPanel.add(createProxyHostAndPortPanel(ftpProxyHost, ftpProxyPort, "FTP Proxy:"));

    socksProxyHost = new JTextField();
    socksProxyPort = new JFormattedTextField(NUMBER_FORMAT);
    socksProxyPort.setText(String.valueOf(DEFAULT_PROXY_PORT));
    manualPanel.add(createProxyHostAndPortPanel(socksProxyHost, socksProxyPort, "SOCKS Proxy:"));

    manualPanel.add(createNoProxyPanel());

    panel.add(manualPanel);
}
 
Example 5
Source File: JSFTargetPanelProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected int initSyntaxButton(int gridy ,final TargetChooserPanel<FileType> panel ,
        final TargetChooserPanelGUI<FileType> uiPanel) 
{
    myFaceletsSyntaxButton = new JRadioButton();
    
    GridBagConstraints gridBagConstraints = new GridBagConstraints();
    myFaceletsSyntaxButton.setSelected(true);
    getSegmentBox().setEnabled(false);
    myFaceletsSyntaxButton.setMnemonic(NbBundle.getMessage(
            JSFTargetPanelProvider.class, "A11Y_Facelets_mnem").charAt(0));
    getButtonGroup().add(myFaceletsSyntaxButton);
    myFaceletsSyntaxButton.addItemListener(new java.awt.event.ItemListener() {
        public void itemStateChanged(ItemEvent evt) {
            checkBoxChanged(evt, panel , uiPanel);
        }
    });

    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = gridy++;
    gridBagConstraints.insets = new java.awt.Insets(0, 6, 0, 0);
    gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
    getOptionPanel().add(myFaceletsSyntaxButton,gridBagConstraints);
    
    getJspSyntaxButton().setMnemonic(NbBundle.getMessage(
            JSFTargetPanelProvider.class, "A11Y_JspStandard_mnem").charAt(0));
    return gridy;
}
 
Example 6
Source File: ObjectViewerPanel.java    From MtgDesktopCompanion with GNU General Public License v3.0 5 votes vote down vote up
public ObjectViewerPanel() {
	setLayout(new BorderLayout());
	textpane = new JTextArea();
	textpane.setLineWrap(true);
	textpane.setEditable(false);
	textpane.setWrapStyleWord(true);
	add(new JScrollPane(textpane),BorderLayout.CENTER);
	
	JPanel panel = new JPanel();
	add(panel, BorderLayout.NORTH);
	
	rdoJson = new JRadioButton("Json");
	rdoJson.setSelected(true);
	rdoMemory = new JRadioButton("Memory");		
	rdoBeanUtils = new JRadioButton("Bean");
	ButtonGroup group = new ButtonGroup();
				group.add(rdoJson);
				group.add(rdoMemory);
				group.add(rdoBeanUtils);
	panel.add(rdoJson);
	panel.add(rdoMemory);
	panel.add(rdoBeanUtils);
	
	rdoJson.addItemListener(il->show(currentObject));
	rdoMemory.addItemListener(il->show(currentObject));
	rdoBeanUtils.addItemListener(il->show(currentObject));
}
 
Example 7
Source File: ControlsDialog.java    From WorldGrower with GNU General Public License v3.0 5 votes vote down vote up
private void addMouseControlPanel(KeyBindings keyBindings) {
	JPanel mouseControlPanel = JPanelFactory.createJPanel("Mouse");

	mouseControlPanel.setOpaque(false);
	mouseControlPanel.setBounds(15, 430, 368, 150);
	mouseControlPanel.setLayout(null);
	
	JRadioButton defaultMouseControl = JRadioButtonFactory.createJRadioButton("<html>left-click: center map<br>right-click: show possible actions</html>");
	defaultMouseControl.setSelected(keyBindings.leftMouseClickCentersMap());
	defaultMouseControl.setOpaque(false);
	defaultMouseControl.setBounds(12, 25, 360, 50);
	mouseControlPanel.add(defaultMouseControl);
	
	JRadioButton alternateMouseControl = JRadioButtonFactory.createJRadioButton("<html>right-click: center map<br>left-click: show possible actions</html>");
	alternateMouseControl.setSelected(!keyBindings.leftMouseClickCentersMap());
	alternateMouseControl.setOpaque(false);
	alternateMouseControl.setBounds(12, 85, 360, 50);
	mouseControlPanel.add(alternateMouseControl);
	
	ButtonGroup buttonGroup = new ButtonGroup();
	buttonGroup.add(defaultMouseControl);
	buttonGroup.add(alternateMouseControl);
	
	addComponent(mouseControlPanel);
	
	defaultMouseControl.addItemListener(new ItemListener() {
		
		@Override
		public void itemStateChanged(ItemEvent itemEvent) {
			keyBindings.setLeftMouseClickCentersMap(defaultMouseControl.isSelected());
		}
	});
}
 
Example 8
Source File: UserPreferences.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
public static void track(final JRadioButton button) {
  final Preferences prefs = node().node("Buttons");
  boolean selected = prefs.getBoolean(button.getName() + ".selected", button
      .isSelected());
  ((DefaultButtonModel) button.getModel()).getGroup().setSelected(
      button.getModel(), selected);// .setSelected(selected);
  button.addItemListener(new ItemListener() {
    public void itemStateChanged(ItemEvent e) {
      prefs.putBoolean(button.getName() + ".selected", button.isSelected());
    }
  });
}
 
Example 9
Source File: DeploymentTable.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public Component getTableCellEditorComponent(JTable table, Object value,
        boolean isSelected, int row, int column) {
    if (value == null)  return null;

    button = (JRadioButton) value;
    button.addItemListener(this);
    return (Component) value;
}
 
Example 10
Source File: CPSComplexFilterDialog.java    From cropplanning with GNU General Public License v3.0 5 votes vote down vote up
protected void buildContentsPanel() {
    
    rdoAllDates = new JRadioButton( "Display all dates.", false );
    rdoLimitDates = new JRadioButton( "Limit view to the following date range:", false );
    rdoAllDates.addItemListener(this);
    rdoLimitDates.addItemListener(this);
    ButtonGroup bg = new ButtonGroup();
    bg.add( rdoAllDates );
    bg.add( rdoLimitDates );
    
    startDateChooser = new JDateChooser();
    endDateChooser = new JDateChooser();
    startDateChooser.addPropertyChangeListener(this);
    endDateChooser.addPropertyChangeListener(this);
    
    JPanel jp = new JPanel( new MigLayout( migDefaults ));
    
    jp.add( rdoAllDates, "wrap, span 2" );
    jp.add( rdoLimitDates, "wrap, span 2" );
    
    jp.add( new JLabel( "Show dates after" ), "align right" );
    jp.add( startDateChooser, "wrap" );
    
    jp.add( new JLabel( "Show dates before" ), "align right" );
    jp.add( endDateChooser, "wrap" );

    contentsPanelBuilt = true;
    rdoAllDates.setSelected(true);
    add(jp);
    
}
 
Example 11
Source File: Attribute.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private JPanel getZoomSection() {
        JPanel panel = new JPanel(new GridBagLayout());
        GridBagConstraints c = new GridBagConstraints();
        ButtonGroup group = new ButtonGroup();
        double zoom = Config.getDefault().getZoom();
        c.anchor = GridBagConstraints.WEST;
//out("GET ZOOM: " + zoom);

        // (o) Fit width to
        c.gridy++;
        c.insets = new Insets(LARGE_SIZE, 0, 0, 0);
        JRadioButton buttonWidth = createRadioButton(i18n("LBL_Fit_Width_to"), i18n("TLT_Fit_Width_to")); // NOI18N
        buttonWidth.addItemListener(createItemListener(true, false, false));
        panel.add(buttonWidth, c);
        group.add(buttonWidth);

        // [width]
        c.insets = new Insets(LARGE_SIZE, LARGE_SIZE, TINY_SIZE, 0);
        myZoomWidth = new JTextField(getString(Percent.getZoomWidth(zoom, 1)));
        setWidth(myZoomWidth, TEXT_WIDTH);
        panel.add(myZoomWidth, c);

        // page(s)
        c.weightx = 1.0;
        panel.add(createLabel(i18n("LBL_Pages")), c); // NOI18N

        // (o) Zoom to
        c.weightx = 0.0;
        c.insets = new Insets(LARGE_SIZE, 0, 0, 0);
        JRadioButton buttonFactor = createRadioButton(i18n("LBL_Zoom_to"), i18n("TLT_Zoom_to")); // NOI18N
        buttonFactor.addItemListener(createItemListener(false, false, true));
        panel.add(buttonFactor, c);
        group.add(buttonFactor);

        // [zoom]
        c.insets = new Insets(LARGE_SIZE, LARGE_SIZE, TINY_SIZE, 0);
//out("ZOOM:"  + Percent.getZoomFactor(zoom, 1.0));
        myZoomFactor = new Percent(this, Percent.getZoomFactor(zoom, 1.0), PERCENTS, 0, null, i18n("TLT_Print_Zoom")); // NOI18N
        panel.add(myZoomFactor, c);

        // (o) Fit height to
        c.gridy++;
        c.weightx = 0.0;
        c.insets = new Insets(LARGE_SIZE, 0, 0, 0);
        JRadioButton buttonHeight = createRadioButton(i18n("LBL_Fit_Height_to"), i18n("TLT_Fit_Height_to")); // NOI18N
        buttonHeight.addItemListener(createItemListener(false, true, false));
        panel.add(buttonHeight, c);
        group.add(buttonHeight);

        // [height]
        c.insets = new Insets(LARGE_SIZE, LARGE_SIZE, TINY_SIZE, 0);
        myZoomHeight = new JTextField(getString(Percent.getZoomHeight(zoom, 1)));
        setWidth(myZoomHeight, TEXT_WIDTH);
        panel.add(myZoomHeight, c);

        // page(s)
        panel.add(createLabel(i18n("LBL_Pages")), c); // NOI18N

        // (o) Fit to page
        c.weightx = 0.0;
        c.insets = new Insets(LARGE_SIZE, 0, 0, 0);
        myFitToPage = createRadioButton(i18n("LBL_Fit_to_Page"), i18n("TLT_Fit_to_Page")); // NOI18N
        myFitToPage.addItemListener(createItemListener(false, false, false));
        panel.add(myFitToPage, c);
        group.add(myFitToPage);

        buttonFactor.setSelected(Percent.isZoomFactor(zoom));
        buttonWidth.setSelected(Percent.isZoomWidth(zoom));
        buttonHeight.setSelected(Percent.isZoomHeight(zoom));
        myFitToPage.setSelected(Percent.isZoomPage(zoom));
//      panel.setBorder(new javax.swing.border.LineBorder(java.awt.Color.green));

        return panel;
    }
 
Example 12
Source File: BlazeSelectOptionControl.java    From intellij with Apache License 2.0 4 votes vote down vote up
BlazeSelectOptionControl(BlazeNewProjectBuilder builder, Collection<T> options) {
  this.userSettings = builder.getUserSettings();

  JPanel canvas = new JPanel(new VerticalLayout(4));

  canvas.setPreferredSize(ProjectViewUi.getContainerSize());

  titleLabel = new JLabel(getTitle());
  canvas.add(titleLabel);
  canvas.add(new JSeparator());

  JPanel content = new JPanel(new VerticalLayout(12));
  content.setBorder(Borders.empty(20, 20, 0, 0));
  JScrollPane scrollPane = new JBScrollPane(content);
  scrollPane.setBorder(BorderFactory.createEmptyBorder());
  canvas.add(scrollPane);

  ButtonGroup buttonGroup = new ButtonGroup();
  Collection<OptionUiEntry<T>> optionUiEntryList = Lists.newArrayList();
  for (T option : options) {
    JPanel vertical = new JPanel(new VerticalLayout(10));
    JRadioButton radioButton = new JRadioButton();
    radioButton.setText(option.getDescription());
    vertical.add(radioButton);

    JComponent optionComponent = option.getUiComponent();
    if (optionComponent != null) {
      JPanel horizontal = new JPanel(new HorizontalLayout(0));
      horizontal.setBorder(Borders.emptyLeft(25));
      horizontal.add(optionComponent);
      vertical.add(horizontal);

      option.optionDeselected();
      radioButton.addItemListener(
          itemEvent -> {
            if (radioButton.isSelected()) {
              option.optionSelected();
            } else {
              option.optionDeselected();
            }
          });
    }

    content.add(vertical);
    buttonGroup.add(radioButton);
    optionUiEntryList.add(new OptionUiEntry<>(option, radioButton));
  }

  OptionUiEntry selected = null;
  String previouslyChosenOption = userSettings.get(getOptionKey(), null);
  if (previouslyChosenOption != null) {
    for (OptionUiEntry<T> entry : optionUiEntryList) {
      if (entry.option.getOptionName().equals(previouslyChosenOption)) {
        selected = entry;
        break;
      }
    }
  }
  if (selected == null) {
    selected = Iterables.getFirst(optionUiEntryList, null);
  }
  if (selected != null) {
    selected.radioButton.setSelected(true);
  }

  this.canvas = canvas;
  this.optionUiEntryList = optionUiEntryList;
}
 
Example 13
Source File: BlazeEditProjectViewControl.java    From intellij with Apache License 2.0 4 votes vote down vote up
private void fillUi(JPanel canvas) {
  JLabel projectDataDirLabel = new JBLabel("Project data directory:");

  canvas.setPreferredSize(ProjectViewUi.getContainerSize());

  projectDataDirField = new TextFieldWithBrowseButton();
  projectDataDirField.setName("project-data-dir-field");
  projectDataDirField.addBrowseFolderListener(
      "",
      buildSystemName + " project data directory",
      null,
      PROJECT_FOLDER_DESCRIPTOR,
      TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT,
      false);
  final String dataDirToolTipText = "Directory in which to store the project's metadata.";
  projectDataDirField.setToolTipText(dataDirToolTipText);
  projectDataDirLabel.setToolTipText(dataDirToolTipText);

  canvas.add(projectDataDirLabel, UiUtil.getLabelConstraints(0));
  canvas.add(projectDataDirField, UiUtil.getFillLineConstraints(0));

  JLabel projectNameLabel = new JLabel("Project name:");
  projectNameField = new JTextField();
  final String projectNameToolTipText = "Project display name.";
  projectNameField.setToolTipText(projectNameToolTipText);
  projectNameField.setName("project-name-field");
  projectNameLabel.setToolTipText(projectNameToolTipText);
  canvas.add(projectNameLabel, UiUtil.getLabelConstraints(0));
  canvas.add(projectNameField, UiUtil.getFillLineConstraints(0));

  JLabel defaultNameLabel = new JLabel("Infer name from:");
  workspaceDefaultNameOption = new JRadioButton("Workspace");
  branchDefaultNameOption = new JRadioButton("Branch");
  importDirectoryDefaultNameOption = new JRadioButton("Import Directory");

  workspaceDefaultNameOption.setToolTipText("Infer default name from the workspace name");
  branchDefaultNameOption.setToolTipText(
      "Infer default name from the current branch of your workspace");
  importDirectoryDefaultNameOption.setToolTipText(
      "Infer default name from the directory used to import your project view");

  workspaceDefaultNameOption.addItemListener(e -> inferDefaultNameModeSelectionChanged());
  branchDefaultNameOption.addItemListener(e -> inferDefaultNameModeSelectionChanged());
  importDirectoryDefaultNameOption.addItemListener(e -> inferDefaultNameModeSelectionChanged());
  ButtonGroup buttonGroup = new ButtonGroup();
  buttonGroup.add(workspaceDefaultNameOption);
  buttonGroup.add(branchDefaultNameOption);
  buttonGroup.add(importDirectoryDefaultNameOption);
  canvas.add(defaultNameLabel, UiUtil.getLabelConstraints(0));
  canvas.add(workspaceDefaultNameOption, UiUtil.getLabelConstraints(0));
  canvas.add(branchDefaultNameOption, UiUtil.getLabelConstraints(0));
  canvas.add(importDirectoryDefaultNameOption, UiUtil.getLabelConstraints(0));
  canvas.add(new JPanel(), UiUtil.getFillLineConstraints(0));

  projectViewUi.fillUi(canvas);
}
 
Example 14
Source File: FontEditor.java    From lsdpatch with MIT License 4 votes vote down vote up
public FontEditor() {
      setTitle("Font Editor");
      setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
      setBounds(100, 100, 415, 324);
      setResizable(false);

      JMenuBar menuBar = new JMenuBar();
      setJMenuBar(menuBar);

      JMenu mnFile = new JMenu("File");
mnFile.setMnemonic(KeyEvent.VK_F);
      menuBar.add(mnFile);

      JMenuItem mntmOpen = new JMenuItem("Open...");
mntmOpen.setMnemonic(KeyEvent.VK_O);
      mntmOpen.addActionListener(this);
      mnFile.add(mntmOpen);

      JMenuItem mntmSave = new JMenuItem("Save...");
mntmSave.setMnemonic(KeyEvent.VK_S);
      mntmSave.addActionListener(this);
      mnFile.add(mntmSave);

      JMenu mnEdit = new JMenu("Edit");
mnEdit.setMnemonic(KeyEvent.VK_E);
      menuBar.add(mnEdit);

      JMenuItem mntmCopy = new JMenuItem("Copy Tile");
      mntmCopy.addActionListener(this);
      mntmCopy.setMnemonic(KeyEvent.VK_C);
      mnEdit.add(mntmCopy);

      JMenuItem mntmPaste = new JMenuItem("Paste Tile");
      mntmPaste.setMnemonic(KeyEvent.VK_P);
      mntmPaste.addActionListener(this);
      mnEdit.add(mntmPaste);

      contentPane = new JPanel();
      contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
      setContentPane(contentPane);
      contentPane.setLayout(null);

      fontMap = new FontMap();
      fontMap.setBounds(10, 42, 128, 146);
      fontMap.setTileSelectListener(this);
      contentPane.add(fontMap);

      tileEditor = new TileEditor();
      tileEditor.setBounds(148, 11, 240, 240);
      tileEditor.setTileChangedListener(this);
      contentPane.add(tileEditor);

      fontSelector = new JComboBox();
      fontSelector.setBounds(10, 11, 128, 20);
      fontSelector.setEditable(true);
      fontSelector.addItemListener(this);
      fontSelector.addActionListener(this);
      contentPane.add(fontSelector);

      color1 = new JRadioButton("1");
      color1.setBounds(10, 220, 37, 23);
      color1.addItemListener(this);
      color1.setMnemonic(KeyEvent.VK_1);
      contentPane.add(color1);

      color2 = new JRadioButton("2");
      color2.setBounds(49, 220, 37, 23);
      color2.addItemListener(this);
      color2.setMnemonic(KeyEvent.VK_2);
      contentPane.add(color2);

      color3 = new JRadioButton("3");
      color3.setBounds(88, 220, 37, 23);
      color3.addItemListener(this);
      color3.setSelected(true);
      color3.setMnemonic(KeyEvent.VK_3);
      contentPane.add(color3);

      colorGroup = new javax.swing.ButtonGroup();
      colorGroup.add(color1);
      colorGroup.add(color2);
      colorGroup.add(color3);

      JLabel lblColor = new JLabel("Color:");
      lblColor.setBounds(10, 199, 46, 14);
      contentPane.add(lblColor);
  }
 
Example 15
Source File: AbstractAdapterEditor.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
void addComboField(JPanel parent, String labelText, String propertyName, List<String> values) {
    JLabel jLabel = new JLabel(labelText);
    parent.add(jLabel);

    PropertyDescriptor propertyDescriptor = propertyContainer.getDescriptor(propertyName);
    propertyDescriptor.setNotEmpty(true);

    values.sort(Comparator.naturalOrder());

    propertyDescriptor.setValueSet(new ValueSet(values.toArray()));
    PropertyEditor editor = PropertyEditorRegistry.getInstance().findPropertyEditor(propertyDescriptor);
    JComponent editorComp = editor.createEditorComponent(propertyDescriptor, bindingContext);
    if (editorComp instanceof JComboBox) {
        JComboBox comboBox = (JComboBox)editorComp;
        comboBox.setEditable(true);
    }
    editorComp.setMaximumSize(new Dimension(editorComp.getMaximumSize().width, controlHeight));

    customMenuLocation = new JTextField();
    customMenuLocation.setInputVerifier(new RequiredFieldValidator(Bundle.MSG_Empty_MenuLocation_Text()));
    customMenuLocation.setEnabled(false);

    JPanel subPanel = new JPanel(new SpringLayout());
    subPanel.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY));
    JRadioButton rbExistingMenu = new JRadioButton(Bundle.CTL_Label_RadioButton_ExistingMenus(), true);
    rbMenuNew = new JRadioButton(Bundle.CTL_Label_RadioButton_NewMenu());
    ButtonGroup rbGroup = new ButtonGroup();
    rbGroup.add(rbExistingMenu);
    rbGroup.add(rbMenuNew);
    // this radio button should be able to capture focus even when the validator of the rbMenuNew says otherwise
    rbExistingMenu.setVerifyInputWhenFocusTarget(false);
    rbExistingMenu.addItemListener(e -> {
        editorComp.setEnabled(e.getStateChange() == ItemEvent.SELECTED);
        customMenuLocation.setEnabled(e.getStateChange() == ItemEvent.DESELECTED);
    });
    subPanel.add(rbExistingMenu);
    subPanel.add(rbMenuNew);
    jLabel.setLabelFor(editorComp);
    subPanel.add(editorComp);
    subPanel.add(customMenuLocation);

    Dimension dimension = new Dimension(parent.getWidth() / 2, controlHeight);
    editorComp.setPreferredSize(dimension);
    customMenuLocation.setPreferredSize(dimension);

    subPanel.setPreferredSize(new Dimension(subPanel.getWidth(), (int)(2.5 * controlHeight)));
    subPanel.setMaximumSize(new Dimension(subPanel.getWidth(), (int) (2.5 * controlHeight)));

    makeCompactGrid(subPanel, 2, 2, DEFAULT_PADDING, DEFAULT_PADDING, DEFAULT_PADDING, DEFAULT_PADDING);

    parent.add(subPanel);
}
 
Example 16
Source File: PlanManager.java    From cropplanning with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void buildContentsPanel() {

  rdoBlank = new JRadioButton("a shiney, new, blank crop plan");
  rdoBlank.setSelected(true);
  rdoBasedOn = new JRadioButton("crop plan based on");
  rdoBlank.addItemListener(this);
  rdoBasedOn.addItemListener(this);
  ButtonGroup bg = new ButtonGroup();
  bg.add( rdoBlank );
  bg.add( rdoBasedOn );

  cmbPlans = new JComboBox( 
          oldPlans.toArray( new String[ oldPlans.size() ]) );
  cmbPlans.setEditable(false);
  cmbPlans.setEnabled(false);

  chkLockOld = new JCheckBox("Lock the old plan.");
  chkLockOld.setSelected(false);
  chkLockOld.setToolTipText("If selected, the old plan will be 'locked' so that " +
                            "it can't be editted, but can still be " +
                            "viewed and referenced and used to generate " +
                            "lists." );
  chkLockOld.setEnabled(false);



  JPanel jplCont = new JPanel( new MigLayout( "gapy 0px!, insets 2px", "[align right][]") );

  JLabel lblBasedOn = new JLabel( "<html><font size=\"-2\">" +
  "If you select the 'based on' option, all of your<br>" +
  "plantings will be copied from the selected plan<br>" +
  "into the new plan with these changes:" +
  "<ol> " +
  "<li>'Planned' dates will be adjusted<br>" +
          "to the selected year." +
  "<li>'Actual' dates (if any) will be blanked." +
  "<li>The 'Done ...' checkboxes will be<br>unselected." +
  "<li>They will all be given a keyword<br>" +
       "of 'from" + newPlan +"' so that you can<br>" +
       "search/filter for them as you<br>update them." +
  "</ol></font></html>");

  JLabel lblLock = new JLabel( "<html><font size=\"-2\">" +
  "If selected, the old plan will be 'locked' so that<br> " +
  "it can't be editted, but can still be viewed and<br>" +
  "used to generate lists and such." +
          "</font></html>" );

  int r = 1;
   jplCont.add( rdoBlank, "span 2, align left, wrap" );
   jplCont.add( rdoBasedOn, "align left" );
   jplCont.add( cmbPlans, "wrap" );
   jplCont.add( lblBasedOn, "span 2, wrap" );
   jplCont.add( chkLockOld, "span 2, align center, wrap" );
   jplCont.add( lblLock, "span 2, wrap" );

  
  jplCont.setBorder( BorderFactory.createEmptyBorder( 10, 10, 0, 10));

  contentsPanelBuilt = true;
  add( jplCont );

}