下面列出了javax.swing.ButtonGroup#add ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void addRadioButtonMenuItemZoom(
JMenu menuZoom, ButtonGroup buttonGroup,
final double zoom, String caption, int nemonic,
double currentZoom) {
JRadioButtonMenuItem radioButtonMenuItemZoom = new JRadioButtonMenuItem(caption);
if (nemonic != -1) {
radioButtonMenuItemZoom.setMnemonic(nemonic);
}
radioButtonMenuItemZoom.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
setZoom(zoom);
}
});
if (currentZoom == zoom) {
radioButtonMenuItemZoom.setSelected(true);
}
buttonGroup.add(radioButtonMenuItemZoom);
menuZoom.add(radioButtonMenuItemZoom);
}
private void initGui() {
importLanguageRadioDe = new JRadioButton("");
importLanguageRadioEn = new JRadioButton("");
ButtonGroup importLanguageRadio = new ButtonGroup();
importLanguageRadio.add(importLanguageRadioDe);
importLanguageRadio.add(importLanguageRadioEn);
setLayout(new GridBagLayout());
{
language = new JPanel();
add(language, GuiUtil.setConstraints(0,0,1.0,0.0,GridBagConstraints.BOTH,5,0,5,0));
language.setBorder(BorderFactory.createTitledBorder(""));
language.setLayout(new GridBagLayout());
importLanguageRadioDe.setIconTextGap(10);
importLanguageRadioEn.setIconTextGap(10);
{
language.add(importLanguageRadioDe, GuiUtil.setConstraints(0,0,1.0,1.0,GridBagConstraints.BOTH,0,5,0,5));
language.add(importLanguageRadioEn, GuiUtil.setConstraints(0,1,1.0,1.0,GridBagConstraints.BOTH,0,5,0,5));
}
}
}
/**
* Create the GUI components
* @param inTopLabelKey key for description label at top
* @param inLowerLabelKey key for description label at bottom, if any
*/
private void createComponents(String inTopLabelKey, String inLowerLabelKey)
{
setLayout(new BorderLayout());
add(new JLabel(I18nManager.getText(inTopLabelKey)), BorderLayout.NORTH);
// panel for the radio buttons
JPanel gridPanel = new JPanel();
gridPanel.setLayout(new GridLayout(0, 3, 15, 3));
final String[] keys = {"beginning", "middle", "end"};
ButtonGroup group = new ButtonGroup();
for (int i=0; i<3; i++)
{
_radios[i] = new JRadioButton(I18nManager.getText("dialog.correlate.timestamp." + keys[i]));
group.add(_radios[i]);
gridPanel.add(_radios[i]);
}
_radios[0].setSelected(true);
add(gridPanel, BorderLayout.CENTER);
if (inLowerLabelKey != null) {
add(new JLabel(I18nManager.getText(inLowerLabelKey)), BorderLayout.SOUTH);
}
}
/**
* (Re-)creates the type menu with the selected type
* @param selected the selected column Type
*/
private void updateTypeMenu(String selected) {
typeMenu.removeAll();
ButtonGroup typeGroup = new ButtonGroup();
for (ColumnType columnType : ColumnType.values()) {
String columnTypeName = DataImportWizardUtils.getNameForColumnType(columnType);
JCheckBoxMenuItem checkboxItem = new JCheckBoxMenuItem(columnTypeName);
if (columnTypeName.equals(selected)) {
checkboxItem.setSelected(true);
}
checkboxItem.addItemListener(e -> {
if (e.getStateChange() == ItemEvent.SELECTED) {
changeType(columnType);
}
});
typeGroup.add(checkboxItem);
typeMenu.add(checkboxItem);
}
}
private JMenu createSerialMenu() {
JMenu menu = new JMenu("Serial port");
ButtonGroup group = new ButtonGroup();
for (final SerialPort newPort : Serial.enumeratePorts()) {
Action setSerialPort = new AbstractAction(newPort.getSystemPortName()) {
@Override
public void actionPerformed(ActionEvent event) {
port = newPort;
}
};
AbstractButton button = new JCheckBoxMenuItem(setSerialPort);
if (port == null) {
button.doClick();
}
group.add(button);
menu.add(button);
}
return menu;
}
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);
}
private NewRepositoryDialog() {
super(RapidMinerGUI.getMainFrame(), "repositorydialog", true, new Object[]{});
Box firstPage = new Box(BoxLayout.Y_AXIS);
ButtonGroup checkBoxGroup = new ButtonGroup();
Map<String, Component> cards = new HashMap<String, Component>();
cards.put("first", firstPage);
cards.put("local", localRepositoryPanel);
// register a radio button for each custom repository type
for (CustomRepositoryFactory factory : CustomRepositoryRegistry.INSTANCE.getFactories()) {
// some repos may not want to appear here
if (!factory.showRepositoryConfigurationInNewRepositoryDialog()) {
continue;
}
String key = factory.getI18NKey();
RepositoryConfigurationPanel repositoryConfigurationPanel = factory.getRepositoryConfigurationPanel();
JRadioButton radioButton = new JRadioButton(new ResourceActionAdapter(key));
radioButton.setEnabled(factory.enableRepositoryConfiguration());
radioButton.setSelected(repoConfigPanels.isEmpty());
repoConfigPanels.put(key, new Pair<>(repositoryConfigurationPanel, radioButton));
checkBoxGroup.add(radioButton);
firstPage.add(radioButton);
cards.put(factory.getI18NKey(), repositoryConfigurationPanel.getComponent());
}
firstPage.add(Box.createVerticalGlue());
layoutDefault(cards);
}
/**
* 处理被选中的 zone 单选框
*
* @param group the group
* @param button the button
*/
private void addZoneRadioButton(@NotNull ButtonGroup group, JRadioButton button) {
group.add(button);
ActionListener actionListener = e -> {
Object sourceObject = e.getSource();
if (sourceObject instanceof JRadioButton) {
JRadioButton sourceButton = (JRadioButton) sourceObject;
zoneIndexTextFiled.setText(String.valueOf(sourceButton.getMnemonic()));
testMessage.setText("");
testButton.setText("Test Upload");
}
};
button.addActionListener(actionListener);
}
public CreateBaseFunctionDialog(JFrame frame, Engine engine,
AccessRules rules) {
super(frame, true);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
this.engine = engine;
this.rules = rules;
this.setTitle(GlobalResourcesManager.getString("CreateFunction"));
double[][] size = {{5, TableLayout.MINIMUM, 5, TableLayout.FILL, 5},
{5, TableLayout.FILL, 5}};
JPanel panel = new JPanel(new TableLayout(size));
panel.add(new JLabel(ResourceLoader.getString("name")), "1,1");
field.setPreferredSize(new Dimension(220,
field.getPreferredSize().height));
panel.add(field, "3,1");
ButtonGroup bg = new ButtonGroup();
bg.add(idef0);
bg.add(dfd);
bg.add(dfds);
JPanel jPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
idef0.setSelected(true);
jPanel.add(idef0);
jPanel.add(dfd);
jPanel.add(dfds);
JPanel jPanel2 = new JPanel(new BorderLayout());
jPanel2.add(panel, BorderLayout.CENTER);
jPanel2.add(jPanel, BorderLayout.SOUTH);
this.setMainPane(jPanel2);
setMinSizePack();
centerDialog();
this.setResizable(false);
}
private JComponent getBrowsersOptionsPanel() {
final JPanel panel = new JPanel(new GridBagLayout());
final GridBagConstraints constraints = new GridBagConstraints();
constraints.gridx = 0;
constraints.gridy = 0;
constraints.anchor = GridBagConstraints.LINE_START;
constraints.insets = new Insets(5, 5, 5, 5);
constraints.weightx = 1.0;
constraints.fill = GridBagConstraints.HORIZONTAL;
final JPanel browserChooserPanel = new JPanel();
final Border browserBorder = new TitledBorder(new BevelBorder(BevelBorder.LOWERED),
Messages.getString("OptionWizard.1")); //$NON-NLS-1$
browserChooserPanel.setBorder(browserBorder);
final ButtonGroup browserChooser = new ButtonGroup();
final JComponent[] browsers = propertyToComponent.get(EarthProperty.BROWSER_TO_USE);
for (final JComponent browserRadioButton : browsers) {
browserChooserPanel.add(browserRadioButton);
browserChooser.add((AbstractButton) browserRadioButton);
((JRadioButton) browserRadioButton).addActionListener(e -> setRestartRequired(true));
}
constraints.gridy++;
panel.add(browserChooserPanel, constraints);
constraints.gridy++;
constraints.gridx = 0;
panel.add(propertyToComponent.get(EarthProperty.FIREFOX_BINARY_PATH)[0], constraints);
constraints.gridy++;
constraints.gridx = 0;
panel.add(propertyToComponent.get(EarthProperty.CHROME_BINARY_PATH)[0], constraints);
constraints.gridy++;
constraints.gridx = 0;
panel.add(propertyToComponent.get(EarthProperty.SAIKU_SERVER_FOLDER)[0], constraints);
return panel;
}
private void build()
{
setLayout(new GridLayout(12, 8));
setTitle("Character Picker");
ActionListener al = new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
JToggleButton tb = (JToggleButton) e.getSource();
setSelectedChar(tb.getText().charAt(0));
setVisible(false);
}
};
buttonGroup = new ButtonGroup()
{
private static final long serialVersionUID = 1L;
@Override
public void setSelected(ButtonModel model, boolean selected)
{
if (selected)
{
super.setSelected(model, selected);
}
else
{
clearSelection();
}
}
};
charButtons = new JToggleButton[96];
for (int i = 0; i < charButtons.length; i++)
{
charButtons[i] = new JToggleButton(Character.toString((char) (i + 32)));
charButtons[i].addActionListener(al);
buttonGroup.add(charButtons[i]);
add(charButtons[i]);
}
pack();
setResizable(false);
}
public static FileWithLevel getOutputFileWithLevelOption(RasterDataNode raster,
String title, String fileNamePrefix, String dirPreferencesKey,
SnapFileFilter fileFilter, String helpId) {
SnapApp snapApp = SnapApp.getDefault();
final String lastDir = snapApp.getPreferences().get(dirPreferencesKey, SystemUtils.getUserHomeDir().getPath());
final File currentDir = new File(lastDir);
final SnapFileChooser fileChooser = new SnapFileChooser();
if (helpId != null) {
HelpCtx.setHelpIDString(fileChooser, helpId);
}
fileChooser.setCurrentDirectory(currentDir);
fileChooser.addChoosableFileFilter(fileFilter);
fileChooser.setAcceptAllFileFilterUsed(false);
fileChooser.setDialogTitle(snapApp.getInstanceName() + " - " + title);
fileChooser.setCurrentFilename(fileNamePrefix + raster.getName());
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
Dimension fileChooserSize = fileChooser.getPreferredSize();
if (fileChooserSize != null) {
fileChooser.setPreferredSize(new Dimension(
fileChooserSize.width + 120, fileChooserSize.height));
} else {
fileChooser.setPreferredSize(new Dimension(512, 256));
}
int maxLevel = raster.getSourceImage().getModel().getLevelCount() - 1;
maxLevel = maxLevel > 10 ? 10 : maxLevel;
final JPanel levelPanel = new JPanel(new GridLayout(maxLevel, 1));
levelPanel.setBorder(BorderFactory.createTitledBorder("Resolution Level"));
ButtonGroup buttonGroup = new ButtonGroup();
for (int i = 0; i < maxLevel; i++) {
String buttonText = Integer.toString(i);
if (i == 0) {
buttonText += " (high, very slow)";
} else if (i == maxLevel - 1) {
buttonText += " (low, fast)";
}
final JRadioButton button = new JRadioButton(buttonText, true);
buttonGroup.add(button);
levelPanel.add(button);
button.setSelected(true);
}
final JPanel accessory = new JPanel();
accessory.setLayout(new BoxLayout(accessory, BoxLayout.Y_AXIS));
accessory.add(levelPanel);
fileChooser.setAccessory(accessory);
int result = fileChooser.showSaveDialog(snapApp.getMainFrame());
File file = fileChooser.getSelectedFile();
final File currentDirectory = fileChooser.getCurrentDirectory();
if (currentDirectory != null) {
snapApp.getPreferences().get(dirPreferencesKey, currentDirectory.getPath());
}
if (result != JFileChooser.APPROVE_OPTION) {
return null;
}
if (file == null || file.getName().isEmpty()) {
return null;
}
if (!promptForOverwrite(file)) {
return null;
}
int level = parseLevel(buttonGroup);
return new FileWithLevel(file, level);
}
private void SetupDateChooserButtons() {
dateChooserButtonGroup = new ButtonGroup();
date206_238_radioButton = new JRadioButton("206/238");
dateChooserButtonGroup.add(date206_238_radioButton);
date206_238_radioButton.setFont(new java.awt.Font("Arial", 1, 10));
date206_238_radioButton.setText("206/238");
date206_238_radioButton.setName("age206_238r");
date206_238_radioButton.setBounds(40, 1, 70, 17);
date206_238_radioButton.setSelected(true);
date206_238_radioButton.setOpaque(true);
date206_238_radioButton.setBackground(Color.white);
add(date206_238_radioButton);
date207_206_radioButton = new JRadioButton("207/206");
dateChooserButtonGroup.add(date207_206_radioButton);
date207_206_radioButton.setFont(new java.awt.Font("Arial", 1, 10));
date207_206_radioButton.setText("207/206");
date207_206_radioButton.setName("age207_206r");
date207_206_radioButton.setBounds(40, 19, 70, 17);
date207_206_radioButton.setOpaque(true);
date207_206_radioButton.setBackground(Color.white);
add(date207_206_radioButton);
dateBest_radioButton = new JRadioButton("best");
dateChooserButtonGroup.add(dateBest_radioButton);
dateBest_radioButton.setFont(new java.awt.Font("Arial", 1, 10));
dateBest_radioButton.setText("best");
dateBest_radioButton.setName("bestAge");
dateBest_radioButton.setOpaque(true);
dateBest_radioButton.setBackground(Color.white);
dateBest_radioButton.setBounds(40, 37, 70, 17);
add(dateBest_radioButton);
// choose date
for (Enumeration e = dateChooserButtonGroup.getElements(); e.hasMoreElements();) {
final JRadioButton jrb = (JRadioButton) e.nextElement();
jrb.addActionListener((ActionEvent arg0) -> {
// oct 2014 handle new Pbc corrections
String chosenDateName = jrb.getName();
((DateProbabilityDensityPanel) probabilityPanel).setChosenDateName(chosenDateName);
((DateProbabilityDensityPanel) probabilityPanel).//
setSelectedFractions(sample.getUpbFractionsUnknown());
((DateProbabilityDensityPanel) probabilityPanel).prepareAndPaintPanel();
});
}
}
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);
}
public FilesPanel(VCSCommitPanel master, Map<String, VCSCommitFilter> filters, int preferedHeight) {
super(master, master.getModifier().getMessage(VCSCommitPanelModifier.BundleMessage.FILE_PANEL_TITLE), DEFAULT_DISPLAY_FILES);
this.filters = filters;
master.getCommitTable().labelFor(filesLabel);
JComponent table = master.getCommitTable().getComponent();
Mnemonics.setLocalizedText(filesLabel, getMessage("CTL_CommitForm_FilesToCommit")); // NOI18N
filesLabel.setMaximumSize(new Dimension(Integer.MAX_VALUE, filesLabel.getMaximumSize().height));
table.setPreferredSize(new Dimension(0, preferedHeight));
ButtonGroup bg = new ButtonGroup();
toolbar = new JToolBar();
toolbar.setFloatable(false);
for (VCSCommitFilter filter : filters.values()) {
JToggleButton tgb = new JToggleButton();
tgb.setIcon(filter.getIcon());
tgb.setToolTipText(filter.getTooltip());
tgb.setFocusable(false);
tgb.setSelected(filter.isSelected());
tgb.addActionListener(this);
tgb.putClientProperty(TOOLBAR_FILTER, filter);
bg.add(tgb);
toolbar.add(tgb);
}
toolbar.setAlignmentX(LEFT_ALIGNMENT);
sectionPanel.add(toolbar);
sectionPanel.add(table);
sectionPanel.add(VCSCommitPanel.makeVerticalStrut(filesLabel, table, RELATED, sectionPanel));
sectionPanel.add(filesLabel);
sectionPanel.setAlignmentX(LEFT_ALIGNMENT);
filesLabel.setAlignmentX(LEFT_ALIGNMENT);
table.setAlignmentX(LEFT_ALIGNMENT);
}
private void initGui() {
setLayout(new GridBagLayout());
useOriginalZCoords.setIconTextGap(10);
add(useOriginalZCoords, GuiUtil.setConstraints(0,0,1.0,0.0,GridBagConstraints.BOTH,BORDER_THICKNESS,0,BORDER_THICKNESS,0));
modePanel = new JPanel();
modePanel.setLayout(new GridBagLayout());
modePanel.setBorder(BorderFactory.createTitledBorder(""));
add(modePanel, GuiUtil.setConstraints(0,1,1.0,0.0,GridBagConstraints.BOTH,BORDER_THICKNESS,0,BORDER_THICKNESS,0));
modePanel.add(modeComboBox, GuiUtil.setConstraints(0,0,1.0,1.0,GridBagConstraints.BOTH,0,BORDER_THICKNESS,BORDER_THICKNESS,BORDER_THICKNESS));
offsetPanel = new JPanel();
offsetPanel.setLayout(new GridBagLayout());
offsetPanel.setBorder(BorderFactory.createTitledBorder(""));
add(offsetPanel, GuiUtil.setConstraints(0,2,1.0,0.0,GridBagConstraints.BOTH,BORDER_THICKNESS,0,BORDER_THICKNESS,0));
ButtonGroup offsetRadioGroup = new ButtonGroup();
offsetRadioGroup.add(noOffsetRadioButton);
noOffsetRadioButton.setIconTextGap(10);
offsetRadioGroup.add(constantOffsetRadioButton);
constantOffsetRadioButton.setIconTextGap(10);
offsetRadioGroup.add(bottomZeroRadioButton);
bottomZeroRadioButton.setIconTextGap(10);
offsetRadioGroup.add(genericAttributeRadioButton);
genericAttributeRadioButton.setIconTextGap(10);
callGElevationService.setIconTextGap(10);
offsetPanel.add(noOffsetRadioButton, GuiUtil.setConstraints(0,0,2,1,0.0,1.0,GridBagConstraints.BOTH,0,BORDER_THICKNESS,0,BORDER_THICKNESS));
offsetPanel.add(constantOffsetRadioButton, GuiUtil.setConstraints(0,1,0.0,1.0,GridBagConstraints.BOTH,0,BORDER_THICKNESS,0,BORDER_THICKNESS));
offsetPanel.add(constantOffsetText, GuiUtil.setConstraints(1,1,1.0,1.0,GridBagConstraints.BOTH,0,BORDER_THICKNESS,0,BORDER_THICKNESS));
offsetPanel.add(bottomZeroRadioButton, GuiUtil.setConstraints(0,2,0.0,1.0,GridBagConstraints.BOTH,0,BORDER_THICKNESS,0,BORDER_THICKNESS));
offsetPanel.add(genericAttributeRadioButton, GuiUtil.setConstraints(0,3,2,1,0.0,1.0,GridBagConstraints.BOTH,0,BORDER_THICKNESS,0,BORDER_THICKNESS));
int lmargin = genericAttributeRadioButton.getPreferredSize().width + 6;
offsetPanel.add(callGElevationService, GuiUtil.setConstraints(0,4,2,1,0.0,1.0,GridBagConstraints.BOTH,0,lmargin,0,BORDER_THICKNESS));
lmargin += callGElevationService.getPreferredSize().width + 6;
offsetPanel.add(callGElevationServiceHint, GuiUtil.setConstraints(0,5,2,1,0.0,1.0,GridBagConstraints.BOTH,0,lmargin,0,BORDER_THICKNESS));
noOffsetRadioButton.addActionListener(e -> setEnabledComponents());
constantOffsetRadioButton.addActionListener(e -> setEnabledComponents());
bottomZeroRadioButton.addActionListener(e -> setEnabledComponents());
genericAttributeRadioButton.addActionListener(e -> setEnabledComponents());
}
public void createMissionPanel() {
WebPanel panel = new WebPanel(new BorderLayout());
tabPane.add(MISSION_TAB, panel);
policyMainPanel = new WebPanel(new BorderLayout());
panel.add(policyMainPanel, BorderLayout.NORTH);
policyMainPanel.setPreferredSize(new Dimension(200, 125));
policyMainPanel.setMaximumSize(new Dimension(200, 125));
// Create a button panel
WebPanel buttonPanel = new WebPanel(new GridLayout(4,1));
// buttonPanel.setPreferredSize(new Dimension(250, 120));
policyMainPanel.add(buttonPanel, BorderLayout.CENTER);
buttonPanel.setBorder(BorderFactory.createTitledBorder("Trade With Other Settlements"));
buttonPanel.setToolTipText("Select the trade policy with other settlements");
ButtonGroup group0 = new ButtonGroup();
ButtonGroup group1 = new ButtonGroup();
r0 = new JRadioButton("Can initiate Trading Mission", true);
r1 = new JRadioButton("Cannot initiate Trading Mission");
// Set up initial conditions
if (settlement.isMissionDisable(Trade.DEFAULT_DESCRIPTION)) {
r0.setSelected(false);
r1.setSelected(true);
}
else {
r0.setSelected(true);
r1.setSelected(false);
}
r2 = new JRadioButton("No Trading Missions from all settlements");
r3 = new JRadioButton(ALLOW);
// Set up initial conditions
boolean noTrading = true;
if (settlement.isTradeMissionAllowedFromASettlement(settlement)) {
List<Settlement> list = getOtherSettlements();
// List<Settlement> allowedSettlements = settlementMissionList.getCheckedValues();
for (Settlement s: list) {
if (!settlement.isTradeMissionAllowedFromASettlement(s)) {
noTrading = false;
break;
}
}
}
WebLabel selectLabel = new WebLabel(" Choose :");
selectLabel.setMinimumSize(new Dimension(150, 25));
selectLabel.setPreferredSize(150, 25);
innerPanel = new WebPanel(new BorderLayout());
innerPanel.add(selectLabel, BorderLayout.NORTH);
// Set settlement check boxes
settlementMissionList = new WebCheckBoxList<>(StyleId.checkboxlist, createModel(getOtherSettlements()));
settlementMissionList.setVisibleRowCount(3);
innerPanel.add(settlementMissionList, BorderLayout.CENTER);
WebScrollPane = new WebScrollPane(innerPanel);
WebScrollPane.setMaximumWidth(250);
// mainPanel.add(WebScrollPane, BorderLayout.EAST);
if (noTrading) {
r2.setSelected(true);
r3.setSelected(false);
policyMainPanel.remove(WebScrollPane);
policyMainPanel.add(emptyPanel, BorderLayout.EAST);
// settlementMissionList.setEnabled(false);
}
else {
r2.setSelected(false);
r3.setSelected(true);
r3.setText(ALLOW + SEE_RIGHT);
policyMainPanel.remove(emptyPanel);
policyMainPanel.add(WebScrollPane, BorderLayout.EAST);
// settlementMissionList.setEnabled(true);
}
group0.add(r0);
group0.add(r1);
group1.add(r2);
group1.add(r3);
buttonPanel.add(r0);
buttonPanel.add(r1);
buttonPanel.add(r2);
buttonPanel.add(r3);
PolicyRadioActionListener actionListener = new PolicyRadioActionListener();
r0.addActionListener(actionListener);
r1.addActionListener(actionListener);
r2.addActionListener(actionListener);
r3.addActionListener(actionListener);
}
private static void createAndShowGUI() {
mainFrame = new JFrame("Bug 8033699 - 8 Tests for Grouped/Non Group Radio Buttons");
btnStart = new JButton("Start");
btnEnd = new JButton("End");
btnMiddle = new JButton("Middle");
JPanel box = new JPanel();
box.setLayout(new BoxLayout(box, BoxLayout.Y_AXIS));
box.setBorder(BorderFactory.createTitledBorder("Grouped Radio Buttons"));
radioBtn1 = new JRadioButton("A");
radioBtn2 = new JRadioButton("B");
radioBtn3 = new JRadioButton("C");
ButtonGroup btnGrp = new ButtonGroup();
btnGrp.add(radioBtn1);
btnGrp.add(radioBtn2);
btnGrp.add(radioBtn3);
radioBtn1.setSelected(true);
box.add(radioBtn1);
box.add(radioBtn2);
box.add(btnMiddle);
box.add(radioBtn3);
radioBtnSingle = new JRadioButton("Not Grouped");
radioBtnSingle.setSelected(true);
mainFrame.getContentPane().add(btnStart);
mainFrame.getContentPane().add(box);
mainFrame.getContentPane().add(radioBtnSingle);
mainFrame.getContentPane().add(btnEnd);
mainFrame.getRootPane().setDefaultButton(btnStart);
btnStart.requestFocus();
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainFrame.setLayout(new BoxLayout(mainFrame.getContentPane(), BoxLayout.Y_AXIS));
mainFrame.setSize(300, 300);
mainFrame.setLocation(200, 200);
mainFrame.setVisible(true);
mainFrame.toFront();
}
private void createUI() {
int line = 0;
JPanel dialogPane = GridBagUtils.createPanel();
dialogPane.setBorder(new EmptyBorder(7, 7, 7, 7));
final GridBagConstraints gbc = GridBagUtils.createDefaultConstraints();
GridBagUtils.setAttributes(gbc, "insets.top=0,gridwidth=3");
JRadioButton pixelRefULeftButton = new JRadioButton("Reference pixel is at scene upper left", false);
JRadioButton pixelRefCenterButton = new JRadioButton("Reference pixel is at scene center", false);
JRadioButton pixelRefOtherButton = new JRadioButton("Other reference pixel position", false);
ButtonGroup g = new ButtonGroup();
g.add(pixelRefULeftButton);
g.add(pixelRefCenterButton);
g.add(pixelRefOtherButton);
context.bind("referencePixelLocation", g);
context.bindEnabledState("referencePixelX", true, "referencePixelLocation", 2);
context.bindEnabledState("referencePixelY", true, "referencePixelLocation", 2);
gbc.gridy = ++line;
GridBagUtils.addToPanel(dialogPane, pixelRefULeftButton, gbc, "fill=HORIZONTAL,weightx=1");
gbc.gridy = ++line;
GridBagUtils.addToPanel(dialogPane, pixelRefCenterButton, gbc);
gbc.gridy = ++line;
GridBagUtils.addToPanel(dialogPane, pixelRefOtherButton, gbc);
gbc.gridy = ++line;
JComponent[] components = createComponents("referencePixelX");
JComponent unitcomponent = createUnitComponent("referencePixelX");
GridBagUtils.addToPanel(dialogPane, components[1], gbc, "insets.top=1,gridwidth=1,fill=NONE,weightx=0");
GridBagUtils.addToPanel(dialogPane, components[0], gbc, "fill=HORIZONTAL,weightx=1");
GridBagUtils.addToPanel(dialogPane, unitcomponent, gbc, "fill=NONE,weightx=0");
gbc.gridy = ++line;
components = createComponents("referencePixelY");
unitcomponent = createUnitComponent("referencePixelY");
GridBagUtils.addToPanel(dialogPane, components[1], gbc, "insets.top=3");
GridBagUtils.addToPanel(dialogPane, components[0], gbc, "fill=HORIZONTAL,weightx=1");
GridBagUtils.addToPanel(dialogPane, unitcomponent, gbc, "fill=NONE,weightx=0");
gbc.gridy = ++line;
components = createComponents("easting");
unitcomponent = createUnitComponent("easting");
GridBagUtils.addToPanel(dialogPane, components[1], gbc, "insets.top=12");
GridBagUtils.addToPanel(dialogPane, components[0], gbc, "fill=HORIZONTAL,weightx=1");
GridBagUtils.addToPanel(dialogPane, unitcomponent, gbc, "fill=NONE,weightx=0");
gbc.gridy = ++line;
components = createComponents("northing");
unitcomponent = createUnitComponent("northing");
GridBagUtils.addToPanel(dialogPane, components[1], gbc, "insets.top=3");
GridBagUtils.addToPanel(dialogPane, components[0], gbc, "fill=HORIZONTAL,weightx=1");
GridBagUtils.addToPanel(dialogPane, unitcomponent, gbc, "fill=NONE,weightx=0");
gbc.gridy = ++line;
components = createComponents("orientation");
unitcomponent = createUnitComponent("orientation");
GridBagUtils.addToPanel(dialogPane, components[1], gbc, "insets.top=3");
GridBagUtils.addToPanel(dialogPane, components[0], gbc, "fill=HORIZONTAL,weightx=1");
GridBagUtils.addToPanel(dialogPane, unitcomponent, gbc, "fill=NONE,weightx=0");
gbc.gridy = ++line;
components = createComponents("pixelSizeX");
unitcomponent = createUnitComponent("pixelSizeX");
GridBagUtils.addToPanel(dialogPane, components[1], gbc, "insets.top=12");
GridBagUtils.addToPanel(dialogPane, components[0], gbc, "fill=HORIZONTAL,weightx=1");
GridBagUtils.addToPanel(dialogPane, unitcomponent, gbc, "fill=NONE,weightx=0");
gbc.gridy = ++line;
components = createComponents("pixelSizeY");
unitcomponent = createUnitComponent("pixelSizeY");
GridBagUtils.addToPanel(dialogPane, components[1], gbc, "insets.top=3");
GridBagUtils.addToPanel(dialogPane, components[0], gbc, "fill=HORIZONTAL,weightx=1");
GridBagUtils.addToPanel(dialogPane, unitcomponent, gbc, "fill=NONE,weightx=0");
gbc.gridy = ++line;
components = createComponents("fitProductSize");
context.bindEnabledState("width", false, "fitProductSize", true);
context.bindEnabledState("height", false, "fitProductSize", true);
GridBagUtils.addToPanel(dialogPane, components[0], gbc, "insets.top=12, gridwidth=3,fill=HORIZONTAL,weightx=1");
gbc.gridy = ++line;
components = createComponents("width");
unitcomponent = createUnitComponent("width");
GridBagUtils.addToPanel(dialogPane, components[1], gbc, "insets.top=3, gridwidth=1,fill=NONE,weightx=0");
GridBagUtils.addToPanel(dialogPane, components[0], gbc, "fill=HORIZONTAL,weightx=1");
GridBagUtils.addToPanel(dialogPane, unitcomponent, gbc, "fill=NONE,weightx=0");
gbc.gridy = ++line;
components = createComponents("height");
unitcomponent = createUnitComponent("height");
GridBagUtils.addToPanel(dialogPane, components[1], gbc);
GridBagUtils.addToPanel(dialogPane, components[0], gbc, "fill=HORIZONTAL,weightx=1");
GridBagUtils.addToPanel(dialogPane, unitcomponent, gbc, "fill=NONE,weightx=0");
add(dialogPane);
}
/**
* Build the user interface ready for display.
*/
private void initComponents()
{
GridBagConstraints gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.anchor = GridBagConstraints.WEST;
gbc.insets = new Insets(2, 2, 2, 2);
GridBagLayout gridbag = new GridBagLayout();
setTitle(TITLE);
setLayout(gridbag);
// Data set selection row
Utility.buildConstraints(gbc, 0, 0, 1, 1, 0.0, 0.0);
JLabel dataSetLabel = new JLabel(LanguageBundle.getString("in_diDataSet"), SwingConstants.RIGHT);
gridbag.setConstraints(dataSetLabel, gbc);
add(dataSetLabel, gbc);
Utility.buildConstraints(gbc, 1, 0, 2, 1, 1.0, 0.0);
dataSetSel = new JTextField("", SwingConstants.WEST);
dataSetSel.setEditable(false);
gridbag.setConstraints(dataSetSel, gbc);
add(dataSetSel, gbc);
Utility.buildConstraints(gbc, 3, 0, 1, 1, 0.0, 0.0);
gbc.fill = GridBagConstraints.NONE;
selectButton = new JButton();
CommonMenuText.name(selectButton, "select"); //$NON-NLS-1$
gridbag.setConstraints(selectButton, gbc);
add(selectButton, gbc);
selectButton.addActionListener(listener);
// Data set details row
Utility.buildConstraints(gbc, 0, 1, 4, 1, 1.0, 1.0);
dataSetDetails = new JFXPanelFromResource<>(
SimpleHtmlPanelController.class,
"SimpleHtmlPanel.fxml"
);
dataSetDetails.setPreferredSize(new Dimension(400, 200));
dataSetDetails.setBackground(getBackground());
gbc.fill = GridBagConstraints.BOTH;
JScrollPane jScrollPane = new JScrollPane();
jScrollPane.setViewportView(dataSetDetails);
gridbag.setConstraints(jScrollPane, gbc);
add(jScrollPane, gbc);
// Location row
Utility.buildConstraints(gbc, 0, 2, 1, 1, 0.0, 0.0);
gbc.fill = GridBagConstraints.HORIZONTAL;
JLabel locLabel = new JLabel(LanguageBundle.getString("in_diLocation"), SwingConstants.RIGHT);
gridbag.setConstraints(locLabel, gbc);
add(locLabel, gbc);
ButtonGroup exclusiveGroup = new ButtonGroup();
locDataButton = new JRadioButton(LanguageBundle.getString("in_diData"));
locDataButton.setToolTipText(LanguageBundle.getString("in_diData_tip"));
exclusiveGroup.add(locDataButton);
locVendorDataButton = new JRadioButton(LanguageBundle.getString("in_diVendorData"));
locVendorDataButton.setToolTipText(LanguageBundle.getString("in_diVendorData_tip"));
exclusiveGroup.add(locVendorDataButton);
locHomebrewDataButton = new JRadioButton(LanguageBundle.getString("in_diHomebrewData"));
locHomebrewDataButton.setToolTipText(LanguageBundle.getString("in_diHomebrewData_tip"));
exclusiveGroup.add(locHomebrewDataButton);
JPanel optionsPanel = new JPanel();
optionsPanel.add(locDataButton);
optionsPanel.add(locVendorDataButton);
optionsPanel.add(locHomebrewDataButton);
Utility.buildConstraints(gbc, 1, 2, 3, 1, 0.0, 0.0);
gridbag.setConstraints(optionsPanel, gbc);
gbc.fill = GridBagConstraints.NONE;
gbc.anchor = GridBagConstraints.WEST;
add(optionsPanel, gbc);
// Buttons row
installButton = new JButton();
CommonMenuText.name(installButton, "diInstall"); //$NON-NLS-1$
installButton.addActionListener(listener);
closeButton = new JButton();
CommonMenuText.name(closeButton, "close"); //$NON-NLS-1$
closeButton.addActionListener(listener);
JPanel buttonsPanel = new JPanel();
buttonsPanel.add(installButton);
buttonsPanel.add(closeButton);
Utility.buildConstraints(gbc, 2, 3, 2, 1, 0.0, 0.0);
gridbag.setConstraints(buttonsPanel, gbc);
gbc.fill = GridBagConstraints.NONE;
gbc.anchor = GridBagConstraints.EAST;
add(buttonsPanel, gbc);
pack();
}