List of usage examples for javax.swing ButtonGroup add
public void add(AbstractButton b)
From source file:be.ugent.maf.cellmissy.gui.controller.analysis.singlecell.filtering.MultipleCutOffFilteringController.java
/** * Private methods and classes//from w w w .ja v a 2s . c o m */ // initialize the main view private void initMainView() { // make a new view multipleCutOffPanel = new MultipleCutOffPanel(); // make a new radio button group for the radio buttons ButtonGroup radioButtonGroup = new ButtonGroup(); radioButtonGroup.add(multipleCutOffPanel.getPixelRadioButton()); radioButtonGroup.add(multipleCutOffPanel.getMicroMeterRadioButton()); // pixels or m? multipleCutOffPanel.getPixelRadioButton().addActionListener((ActionEvent e) -> { multipleCutOffPanel.getConversionFactorTextField().setEnabled(true); }); multipleCutOffPanel.getMicroMeterRadioButton().addActionListener((ActionEvent e) -> { // m: we do not need a conversion factor multipleCutOffPanel.getConversionFactorTextField().setEnabled(false); }); // set default to micrometer multipleCutOffPanel.getMicroMeterRadioButton().setSelected(true); // and therefore no need for the conversion factor multipleCutOffPanel.getConversionFactorTextField().setEnabled(false); // set some default values for the top and bottom translocaton limits multipleCutOffPanel.getBottomLimTextField().setText("0.4"); multipleCutOffPanel.getTopLimTextField().setText("2.8"); multipleCutOffPanel.getTranslocationStepTextField().setText("0.8"); multipleCutOffPanel.getPercentageMotileStepsTextField().setText("30"); percentageMotile = 33; // actually do the filtering multipleCutOffPanel.getFilterButton().addActionListener((ActionEvent e) -> { // try to read the user-inserted values for up and down limit // check for number format exception try { if (multipleCutOffPanel.getPixelRadioButton().isSelected()) { double conversionFactor = Double .parseDouble(multipleCutOffPanel.getConversionFactorTextField().getText()); multipleCutOffPanel.getBottomLimTextField() .setText("" + AnalysisUtils.roundTwoDecimals( Double.parseDouble(multipleCutOffPanel.getBottomLimTextField().getText()) / conversionFactor)); multipleCutOffPanel.getTopLimTextField() .setText("" + AnalysisUtils.roundTwoDecimals( Double.parseDouble(multipleCutOffPanel.getTopLimTextField().getText()) / conversionFactor)); } int topLimit = (int) (Double.parseDouble(multipleCutOffPanel.getTopLimTextField().getText()) * 10); int bottomLimit = (int) (Double.parseDouble(multipleCutOffPanel.getBottomLimTextField().getText()) * 10); double step = Double.parseDouble(multipleCutOffPanel.getTranslocationStepTextField().getText()); percentageMotile = Double .parseDouble(multipleCutOffPanel.getPercentageMotileStepsTextField().getText()); int numberSteps = (int) ((topLimit - bottomLimit) / (10 * step)) + 1; motileSteps = new ArrayList<>(); for (int i = 0; i < numberSteps; i++) { motileSteps.add(((double) bottomLimit / 10) + (step * i)); } FilterSwingWorker filterSwingWorker = new FilterSwingWorker(); filterSwingWorker.execute(); } catch (NumberFormatException ex) { // warn the user and log the error for info filteringController.showMessage("Please insert valid numbers!" + "\n " + ex.getMessage(), "number format exception", JOptionPane.ERROR_MESSAGE); LOG.error(ex.getMessage()); } }); // apply a specific cut-off value to all the conditions at once multipleCutOffPanel.getApplyCutOffToConditionsButton().addActionListener((ActionEvent e) -> { // get the cut-off from the list (sure this is a Double) Double value = (Double) multipleCutOffPanel.getCutOffValuesComboBox().getSelectedItem(); FilterConditionSwingWorker filterConditionSwingWorker = new FilterConditionSwingWorker(value); filterConditionSwingWorker.execute(); }); // select cut-off for a condition multipleCutOffPanel.getSelectCutOffForConditionButton().addActionListener((ActionEvent e) -> { if (multipleCutOffPanel.getCutOffValuesComboBox().getSelectedItem() != null) { SelectCutOffConditionSwingWorker selectCutOffConditionSwingWorker = new SelectCutOffConditionSwingWorker(); selectCutOffConditionSwingWorker.execute(); } else { filteringController.showMessage("Please select a cut-off!", "info", JOptionPane.WARNING_MESSAGE); } }); AlignedTableRenderer alignedTableRenderer = new AlignedTableRenderer(SwingConstants.LEFT); for (int i = 0; i < multipleCutOffPanel.getFilterTrackTable().getColumnModel().getColumnCount(); i++) { multipleCutOffPanel.getFilterTrackTable().getColumnModel().getColumn(i) .setCellRenderer(alignedTableRenderer); multipleCutOffPanel.getSummaryTable().getColumnModel().getColumn(i) .setCellRenderer(alignedTableRenderer); } multipleCutOffPanel.getFilterTrackTable().getTableHeader() .setDefaultRenderer(new TableHeaderRenderer(SwingConstants.LEFT)); multipleCutOffPanel.getSummaryTable().getTableHeader() .setDefaultRenderer(new TableHeaderRenderer(SwingConstants.LEFT)); // add view to parent component filteringController.getFilteringPanel().getMultipleCutOffParentPanel().add(multipleCutOffPanel, gridBagConstraints); }
From source file:be.ugent.maf.cellmissy.gui.controller.analysis.singlecell.SingleCellAnalysisController.java
/** * Initialize main view./*www . java 2 s . co m*/ */ private void initAnalysisPanel() { // make a new panel analysisPanel = new AnalysisPanel(); //create a ButtonGroup for the radioButtons used for analysis ButtonGroup radioButtonGroup = new ButtonGroup(); radioButtonGroup.add(analysisPanel.getCellTracksRadioButton()); radioButtonGroup.add(analysisPanel.getCellSpeedRadioButton()); radioButtonGroup.add(analysisPanel.getStatisticsRadioButton()); /** * Add action listeners */ // plot the cell tracks analysisPanel.getCellTracksRadioButton().addActionListener((ActionEvent e) -> { // get the layout from the bottom panel and show the appropriate one CardLayout layout = (CardLayout) analysisPanel.getBottomPanel().getLayout(); layout.show(analysisPanel.getBottomPanel(), analysisPanel.getCellTracksPanel().getName()); plotCellTracks(); }); // analysisPanel.getCellSpeedRadioButton().addActionListener((ActionEvent e) -> { // get the layout from the bottom panel and show the appropriate one CardLayout layout = (CardLayout) analysisPanel.getBottomPanel().getLayout(); layout.show(analysisPanel.getBottomPanel(), analysisPanel.getCellSpeedsPanel().getName()); // take care of data and plots here plotData(); }); // go to the statistics analysisPanel.getStatisticsRadioButton().addActionListener((ActionEvent e) -> { // get the layout from the bottom panel and show the appropriate one CardLayout layout = (CardLayout) analysisPanel.getBottomPanel().getLayout(); layout.show(analysisPanel.getBottomPanel(), analysisPanel.getStatisticsParentPanel().getName()); singleCellStatisticsController.updateConditionList(); }); analysisPanel.getCellTracksRadioButton().setSelected(true); AlignedTableRenderer alignedTableRenderer = new AlignedTableRenderer(SwingConstants.LEFT); for (int i = 0; i < analysisPanel.getDataTable().getColumnModel().getColumnCount(); i++) { analysisPanel.getDataTable().getColumnModel().getColumn(i).setCellRenderer(alignedTableRenderer); } analysisPanel.getDataTable().getTableHeader() .setDefaultRenderer(new TableHeaderRenderer(SwingConstants.LEFT)); // add view to parent panel singleCellMainController.getSingleCellAnalysisPanel().getAnalysisParentPanel().add(analysisPanel, gridBagConstraints); }
From source file:com.microsoft.azure.hdinsight.spark.ui.SparkSubmissionContentPanel.java
private void addSelectedArtifactLineItem() { final String tipInfo = "The Artifact you want to use."; JLabel artifactSelectLabel = new JLabel("Select an Artifact to submit"); artifactSelectLabel.setToolTipText(tipInfo); selectedArtifactComboBox = new ComboBox(); selectedArtifactComboBox.setToolTipText(tipInfo); errorMessageLabels[ErrorMessageLabelTag.SystemArtifact.ordinal()] = new JLabel( "Artifact should not be null!"); errorMessageLabels[ErrorMessageLabelTag.SystemArtifact.ordinal()] .setForeground(DarkThemeManager.getInstance().getErrorMessageColor()); errorMessageLabels[ErrorMessageLabelTag.SystemArtifact.ordinal()].setVisible(false); errorMessageLabels[ErrorMessageLabelTag.LocalArtifact.ordinal()] = new JLabel( "Could not find the local jar package for Artifact"); errorMessageLabels[ErrorMessageLabelTag.LocalArtifact.ordinal()] .setForeground(DarkThemeManager.getInstance().getErrorMessageColor()); errorMessageLabels[ErrorMessageLabelTag.LocalArtifact.ordinal()].setVisible(false); selectedArtifactTextField = new TextFieldWithBrowseButton(); selectedArtifactTextField.setToolTipText("Artifact from local jar package."); selectedArtifactTextField.setEditable(true); selectedArtifactTextField.setEnabled(false); selectedArtifactTextField.getTextField().getDocument().addDocumentListener(new DocumentListener() { @Override/*from w ww . ja v a2 s. c o m*/ public void insertUpdate(DocumentEvent e) { setVisibleForFixedErrorMessageLabel(2, !SparkSubmitHelper.isLocalArtifactPath(selectedArtifactTextField.getText())); } @Override public void removeUpdate(DocumentEvent e) { setVisibleForFixedErrorMessageLabel(2, !SparkSubmitHelper.isLocalArtifactPath(selectedArtifactTextField.getText())); } @Override public void changedUpdate(DocumentEvent e) { setVisibleForFixedErrorMessageLabel(2, !SparkSubmitHelper.isLocalArtifactPath(selectedArtifactTextField.getText())); } }); selectedArtifactTextField.getButton().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { FileChooserDescriptor chooserDescriptor = new FileChooserDescriptor(false, false, true, false, true, false); chooserDescriptor.setTitle("Select Local Artifact File"); VirtualFile chooseFile = FileChooser.chooseFile(chooserDescriptor, null, null); if (chooseFile != null) { String path = chooseFile.getPath(); if (path.endsWith("!/")) { path = path.substring(0, path.length() - 2); } selectedArtifactTextField.setText(path); } } }); intelliJArtifactRadioButton = new JRadioButton("Artifact from IntelliJ project:", true); localArtifactRadioButton = new JRadioButton("Artifact from local disk:", false); intelliJArtifactRadioButton.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { selectedArtifactComboBox.setEnabled(true); selectedArtifactTextField.setEnabled(false); mainClassTextField.setButtonEnabled(true); setVisibleForFixedErrorMessageLabel(2, false); if (selectedArtifactComboBox.getItemCount() == 0) { setVisibleForFixedErrorMessageLabel(2, true); } } } }); localArtifactRadioButton.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { selectedArtifactComboBox.setEnabled(false); selectedArtifactTextField.setEnabled(true); mainClassTextField.setButtonEnabled(false); setVisibleForFixedErrorMessageLabel(1, false); if (StringHelper.isNullOrWhiteSpace(selectedArtifactTextField.getText())) { setVisibleForFixedErrorMessageLabel(2, true); } } } }); ButtonGroup group = new ButtonGroup(); group.add(intelliJArtifactRadioButton); group.add(localArtifactRadioButton); intelliJArtifactRadioButton.setSelected(true); add(artifactSelectLabel, new GridBagConstraints(0, ++displayLayoutCurrentRow, 0, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(margin, margin, 0, margin), 0, 0)); add(intelliJArtifactRadioButton, new GridBagConstraints(0, ++displayLayoutCurrentRow, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(margin / 3, margin * 3, 0, margin), 0, 0)); add(selectedArtifactComboBox, new GridBagConstraints(1, displayLayoutCurrentRow, 0, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(margin / 3, margin, 0, margin), 0, 0)); add(errorMessageLabels[ErrorMessageLabelTag.SystemArtifact.ordinal()], new GridBagConstraints(1, ++displayLayoutCurrentRow, 0, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, margin, 0, 0), 0, 0)); add(localArtifactRadioButton, new GridBagConstraints(0, ++displayLayoutCurrentRow, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(margin / 3, margin * 3, 0, margin), 0, 0)); add(selectedArtifactTextField, new GridBagConstraints(1, displayLayoutCurrentRow, 0, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(margin / 3, margin, 0, margin), 0, 0)); add(errorMessageLabels[ErrorMessageLabelTag.LocalArtifact.ordinal()], new GridBagConstraints(1, ++displayLayoutCurrentRow, 0, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, margin, 0, 0), 0, 0)); }
From source file:com.diversityarrays.kdxplore.trials.AddScoringSetDialog.java
private Box createWantSampleButtons(SampleGroup curatedSampleGroup) { Box result = null;//w w w . j av a 2 s . co m ActionListener rbListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { wantSampleValues = noSampleValuesButton != e.getSource(); } }; result = Box.createHorizontalBox(); String noSampleValues = Msg.OPTION_NO_SAMPLE_VALUES(); ButtonGroup bg = new ButtonGroup(); for (String rbname : new String[] { noSampleValues, Msg.OPTION_CURATED_SAMPLE_VALUES() }) { JRadioButton rb = new JRadioButton(rbname); result.add(rb); bg.add(rb); rb.addActionListener(rbListener); if (noSampleValues.equals(rbname)) { noSampleValuesButton = rb; } else { rb.doClick(); } } result.add(Box.createHorizontalGlue()); return result; }
From source file:be.ugent.maf.cellmissy.gui.controller.analysis.singlecell.SingleCellAnalysisController.java
/** * Initialize plot options panel.// ww w . j av a2 s . c o m */ private void initPlotOptionsPanel() { // make new view plotOptionsPanel = new PlotOptionsPanel(); // add radiobuttons to a button group ButtonGroup scaleAxesButtonGroup = new ButtonGroup(); scaleAxesButtonGroup.add(plotOptionsPanel.getDoNotScaleAxesRadioButton()); scaleAxesButtonGroup.add(plotOptionsPanel.getScaleAxesRadioButton()); plotOptionsPanel.getDoNotScaleAxesRadioButton().setSelected(true); // another button group for the shifted/unshifted coordinates ButtonGroup shiftedCoordinatesButtonGroup = new ButtonGroup(); shiftedCoordinatesButtonGroup.add(plotOptionsPanel.getShiftedCoordinatesRadioButton()); shiftedCoordinatesButtonGroup.add(plotOptionsPanel.getUnshiftedCoordinatesRadioButton()); plotOptionsPanel.getUnshiftedCoordinatesRadioButton().setSelected(true); /** * Action listeners */ // do not scale axes plotOptionsPanel.getDoNotScaleAxesRadioButton().addActionListener((ActionEvent e) -> { int nCols = Integer.parseInt((String) plotOptionsPanel.getnColsComboBox().getSelectedItem()); boolean useRawData = plotOptionsPanel.getUnshiftedCoordinatesRadioButton().isSelected(); resetPlotLogic(); generateDataForTrackPlot(useRawData); // use the data to set the charts setTrackChartsWithCollections(nCols); }); // scale axes to the experiment range plotOptionsPanel.getScaleAxesRadioButton().addActionListener((ActionEvent e) -> { boolean useRawData = plotOptionsPanel.getUnshiftedCoordinatesRadioButton().isSelected(); cellTracksChartPanels.stream().forEach((chartPanel) -> { singleCellMainController.scaleAxesToExperiment(chartPanel.getChart(), useRawData); }); }); // shift the all coordinates to the origin plotOptionsPanel.getShiftedCoordinatesRadioButton().addActionListener((ActionEvent e) -> { int nCols = Integer.parseInt((String) plotOptionsPanel.getnColsComboBox().getSelectedItem()); resetPlotLogic(); generateDataForTrackPlot(false); // use the data to set the charts setTrackChartsWithCollections(nCols); }); // replot the unshifted coordinates plotOptionsPanel.getUnshiftedCoordinatesRadioButton().addActionListener((ActionEvent e) -> { int nCols = Integer.parseInt((String) plotOptionsPanel.getnColsComboBox().getSelectedItem()); resetPlotLogic(); generateDataForTrackPlot(true); // use the data to set the charts setTrackChartsWithCollections(nCols); }); // replot with a different number of columns plotOptionsPanel.getnColsComboBox().addActionListener((ActionEvent e) -> { int nCols = Integer.parseInt((String) plotOptionsPanel.getnColsComboBox().getSelectedItem()); boolean useRawData = plotOptionsPanel.getUnshiftedCoordinatesRadioButton().isSelected(); resetPlotLogic(); generateDataForTrackPlot(useRawData); // use the data to set the charts setTrackChartsWithCollections(nCols); }); // add view to parent component analysisPanel.getPlotOptionsParentPanel().add(plotOptionsPanel, gridBagConstraints); }
From source file:cl.almejo.vsim.gui.SimWindow.java
private JToggleButton newGrouppedButton(Action action, ButtonGroup group) { JToggleButton button = new JToggleButton(); button.setAction(action);/*from w w w . j a v a 2 s. c om*/ button.setText(""); group.add(button); return button; }
From source file:net.sf.jabref.gui.journals.ManageJournalsPanel.java
public ManageJournalsPanel(final JabRefFrame frame) { this.frame = frame; personalFile.setEditable(false);//from ww w. ja va 2 s. com ButtonGroup group = new ButtonGroup(); group.add(newFile); group.add(oldFile); addExtPan.setLayout(new BorderLayout()); JButton addExt = new JButton(IconTheme.JabRefIcon.ADD.getIcon()); addExtPan.add(addExt, BorderLayout.EAST); addExtPan.setToolTipText(Localization.lang("Add")); FormLayout layout = new FormLayout("1dlu, 8dlu, left:pref, 4dlu, fill:200dlu:grow, 4dlu, fill:pref", "pref, pref, pref, 20dlu, 20dlu, fill:200dlu, 4dlu, pref"); FormBuilder builder = FormBuilder.create().layout(layout); builder.addSeparator(Localization.lang("Built-in journal list")).xyw(2, 1, 6); JLabel description = new JLabel( "<HTML>" + Localization.lang("JabRef includes a built-in list of journal abbreviations.") + "<br>" + Localization.lang( "You can add additional journal names by setting up a personal journal list,<br>as " + "well as linking to external journal lists.") + "</HTML>"); description.setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 0)); builder.add(description).xyw(2, 2, 6); JButton viewBuiltin = new JButton(Localization.lang("View")); builder.add(viewBuiltin).xy(7, 2); builder.addSeparator(Localization.lang("Personal journal list")).xyw(2, 3, 6); builder.add(newFile).xy(3, 4); builder.add(newNameTf).xy(5, 4); JButton browseNew = new JButton(Localization.lang("Browse")); builder.add(browseNew).xy(7, 4); builder.add(oldFile).xy(3, 5); builder.add(personalFile).xy(5, 5); JButton browseOld = new JButton(Localization.lang("Browse")); builder.add(browseOld).xy(7, 5); userPanel.setLayout(new BorderLayout()); builder.add(userPanel).xyw(2, 6, 4); ButtonStackBuilder butBul = new ButtonStackBuilder(); butBul.addButton(add); butBul.addButton(remove); butBul.addGlue(); builder.add(butBul.getPanel()).xy(7, 6); builder.addSeparator(Localization.lang("External files")).xyw(2, 8, 6); externalFilesPanel.setLayout(new BorderLayout()); setLayout(new BorderLayout()); builder.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); add(builder.getPanel(), BorderLayout.NORTH); add(externalFilesPanel, BorderLayout.CENTER); ButtonBarBuilder bb = new ButtonBarBuilder(); bb.addGlue(); JButton ok = new JButton(Localization.lang("OK")); bb.addButton(ok); JButton cancel = new JButton(Localization.lang("Cancel")); bb.addButton(cancel); bb.addUnrelatedGap(); JButton help = new HelpAction(HelpFile.JOURNAL_ABBREV).getHelpButton(); bb.addButton(help); bb.addGlue(); bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); dialog = new JDialog(frame, Localization.lang("Journal abbreviations"), false); dialog.getContentPane().add(this, BorderLayout.CENTER); dialog.getContentPane().add(bb.getPanel(), BorderLayout.SOUTH); // Set up panel for editing a single journal, to be used in a dialog box: FormLayout layout2 = new FormLayout("right:pref, 4dlu, fill:180dlu", "p, 2dlu, p"); FormBuilder builder2 = FormBuilder.create().layout(layout2); builder2.add(Localization.lang("Journal name")).xy(1, 1); builder2.add(nameTf).xy(3, 1); builder2.add(Localization.lang("ISO abbreviation")).xy(1, 3); builder2.add(abbrTf).xy(3, 3); journalEditPanel = builder2.getPanel(); viewBuiltin.addActionListener(e -> { JTable table = new JTable(JournalAbbreviationsUtil.getTableModel(Globals.journalAbbreviationLoader .getRepository(JournalAbbreviationPreferences.fromPreferences(Globals.prefs)) .getAbbreviations())); JScrollPane pane = new JScrollPane(table); JOptionPane.showMessageDialog(null, pane, Localization.lang("Journal list preview"), JOptionPane.INFORMATION_MESSAGE); }); browseNew.addActionListener(e -> { Path old = null; if (!newNameTf.getText().isEmpty()) { old = Paths.get(newNameTf.getText()); } String name = FileDialogs.getNewFile(frame, old.toFile(), null, JFileChooser.SAVE_DIALOG, false); if (name != null) { newNameTf.setText(name); newFile.setSelected(true); } }); browseOld.addActionListener(e -> { Path old = null; if (!personalFile.getText().isEmpty()) { old = Paths.get(personalFile.getText()); } String name = FileDialogs.getNewFile(frame, old.toFile(), null, JFileChooser.OPEN_DIALOG, false); if (name != null) { personalFile.setText(name); oldFile.setSelected(true); oldFile.setEnabled(true); setupUserTable(); } }); ok.addActionListener(e -> { if (readyToClose()) { storeSettings(); dialog.dispose(); } }); Action cancelAction = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { dialog.dispose(); } }; cancel.addActionListener(cancelAction); add.addActionListener(tableModel); remove.addActionListener(tableModel); addExt.addActionListener(e -> { externals.add(new ExternalFileEntry()); buildExternalsPanel(); }); // Key bindings: ActionMap am = getActionMap(); InputMap im = getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); im.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close"); am.put("close", cancelAction); int xSize = getPreferredSize().width; dialog.setSize(xSize + 10, 700); }
From source file:com.rapidminer.gui.new_plotter.gui.dialog.AddParallelLineDialog.java
/** * Setup the GUI.//from ww w. j av a2 s . c o m */ 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.HORIZONTAL; gbc.weightx = 1; gbc.anchor = GridBagConstraints.WEST; gbc.insets = new Insets(5, 5, 2, 5); horizontalLineRadiobutton = new JRadioButton( I18N.getMessage(I18N.getGUIBundle(), "gui.action.add_parallel_line.horizontal.label")); horizontalLineRadiobutton.setToolTipText( I18N.getMessage(I18N.getGUIBundle(), "gui.action.add_parallel_line.horizontal.tip")); horizontalLineRadiobutton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setHorizontalLineSelected(); } }); horizontalLineRadiobutton.setSelected(true); this.add(horizontalLineRadiobutton, gbc); gbc.gridx = 1; gbc.gridy = 0; gbc.anchor = GridBagConstraints.EAST; verticalLineRadiobutton = new JRadioButton( I18N.getMessage(I18N.getGUIBundle(), "gui.action.add_parallel_line.vertical.label")); verticalLineRadiobutton .setToolTipText(I18N.getMessage(I18N.getGUIBundle(), "gui.action.add_parallel_line.vertical.tip")); verticalLineRadiobutton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setVerticalLineSelected(); } }); this.add(verticalLineRadiobutton, gbc); ButtonGroup group = new ButtonGroup(); group.add(horizontalLineRadiobutton); group.add(verticalLineRadiobutton); gbc.gridx = 0; gbc.gridy = 1; gbc.fill = GridBagConstraints.BOTH; gbc.weightx = 1; gbc.gridwidth = 2; gbc.anchor = GridBagConstraints.CENTER; rangeAxisSelectionCombobox = new JComboBox(); rangeAxisSelectionCombobox.setToolTipText( I18N.getMessage(I18N.getGUIBundle(), "gui.action.add_parallel_line.range_axis_combobox.tip")); rangeAxisSelectionCombobox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { updateYFieldValue(); } }); this.add(rangeAxisSelectionCombobox, gbc); gbc.gridx = 0; gbc.gridy = 2; gbc.fill = GridBagConstraints.NONE; gbc.weightx = 1; gbc.anchor = GridBagConstraints.WEST; gbc.insets = new Insets(5, 5, 2, 5); JLabel xLabel = new JLabel( I18N.getMessage(I18N.getGUIBundle(), "gui.action.add_parallel_line.width.label")); this.add(xLabel, gbc); gbc.gridx = 1; gbc.gridy = 2; gbc.insets = new Insets(2, 5, 2, 5); gbc.fill = GridBagConstraints.HORIZONTAL; xField = new JTextField(); xField.setText(String.valueOf(x)); xField.setInputVerifier(new InputVerifier() { @Override public boolean verify(JComponent input) { return verifyYInput(input); } }); xField.setToolTipText(I18N.getMessage(I18N.getGUIBundle(), "gui.action.add_parallel_line.width.tip")); xField.setEnabled(false); this.add(xField, gbc); gbc.gridx = 0; gbc.gridy = 3; gbc.fill = GridBagConstraints.NONE; JLabel yLabel = new JLabel( I18N.getMessage(I18N.getGUIBundle(), "gui.action.add_parallel_line.height.label")); this.add(yLabel, gbc); gbc.gridx = 1; gbc.gridy = 3; gbc.fill = GridBagConstraints.HORIZONTAL; yField = new JTextField(); yField.setToolTipText(I18N.getMessage(I18N.getGUIBundle(), "gui.action.add_parallel_line.height.tip")); yField.setText(String.valueOf(y)); yField.setInputVerifier(new InputVerifier() { @Override public boolean verify(JComponent input) { return verifyXInput(input); } }); this.add(yField, gbc); gbc.gridx = 0; gbc.gridy = 4; gbc.fill = GridBagConstraints.NONE; gbc.insets = new Insets(10, 5, 0, 5); modifyLineButton = new JButton(); modifyLineButton.setToolTipText( I18N.getMessage(I18N.getGUIBundle(), "gui.action.add_parallel_line.modify_line.tip")); modifyLineButton.setIcon(SwingTools.createIcon( "16/" + I18N.getMessage(I18N.getGUIBundle(), "gui.action.add_parallel_line.modify_line.icon"))); modifyLineButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { modifyLine(); } }); this.add(modifyLineButton, gbc); gbc.gridx = 0; gbc.gridy = 5; gbc.gridwidth = 2; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.anchor = GridBagConstraints.CENTER; gbc.insets = new Insets(15, 5, 5, 5); this.add(new JSeparator(), gbc); gbc.gridx = 0; gbc.gridy = 6; 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.add_parallel_line.ok.label")); okButton.setToolTipText(I18N.getMessage(I18N.getGUIBundle(), "gui.action.add_parallel_line.ok.tip")); okButton.setIcon(SwingTools .createIcon("24/" + I18N.getMessage(I18N.getGUIBundle(), "gui.action.add_parallel_line.ok.icon"))); okButton.setMnemonic( I18N.getMessage(I18N.getGUIBundle(), "gui.action.add_parallel_line.ok.mne").toCharArray()[0]); okButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { boolean successful = addSpecifiedLine(); // don't dispose dialog if not successful if (!successful) { return; } AddParallelLineDialog.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 = 6; gbc.fill = GridBagConstraints.NONE; gbc.anchor = GridBagConstraints.EAST; cancelButton = new JButton( I18N.getMessage(I18N.getGUIBundle(), "gui.action.add_parallel_line.cancel.label")); cancelButton .setToolTipText(I18N.getMessage(I18N.getGUIBundle(), "gui.action.add_parallel_line.cancel.tip")); cancelButton.setIcon(SwingTools.createIcon( "24/" + I18N.getMessage(I18N.getGUIBundle(), "gui.action.add_parallel_line.cancel.icon"))); cancelButton.setMnemonic( I18N.getMessage(I18N.getGUIBundle(), "gui.action.add_parallel_line.cancel.mne").toCharArray()[0]); cancelButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // cancel requested, close dialog AddParallelLineDialog.this.dispose(); } }); this.add(cancelButton, gbc); // misc settings this.setMinimumSize(new Dimension(300, 250)); // center dialog this.setLocationRelativeTo(null); this.setTitle(I18N.getMessage(I18N.getGUIBundle(), "gui.action.add_parallel_line.title.label")); this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); this.setModal(true); this.addWindowListener(new WindowAdapter() { @Override public void windowActivated(WindowEvent e) { okButton.requestFocusInWindow(); } }); }
From source file:net.sf.jabref.gui.plaintextimport.TextInputDialog.java
private JPanel setUpFieldListPanel() { JPanel inputPanel = new JPanel(); // Panel Layout GridBagLayout gbl = new GridBagLayout(); GridBagConstraints con = new GridBagConstraints(); con.weightx = 0;//from w w w . j a v a2 s. com con.insets = new Insets(5, 5, 0, 5); con.fill = GridBagConstraints.HORIZONTAL; inputPanel.setLayout(gbl); // Border TitledBorder titledBorder1 = new TitledBorder(BorderFactory.createLineBorder(new Color(153, 153, 153), 2), Localization.lang("Work options")); inputPanel.setBorder(titledBorder1); inputPanel.setMinimumSize(new Dimension(10, 10)); JScrollPane fieldScroller = new JScrollPane(fieldList); fieldScroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); // insert buttons insertButton.addActionListener(event -> insertTextForTag(override.isSelected())); // Radio buttons append.setToolTipText(Localization.lang("Append the selected text to BibTeX field")); append.setMnemonic(KeyEvent.VK_A); append.setSelected(true); override.setToolTipText(Localization.lang("Override the BibTeX field by the selected text")); override.setMnemonic(KeyEvent.VK_O); override.setSelected(false); //Group the radio buttons. ButtonGroup group = new ButtonGroup(); group.add(append); group.add(override); JPanel radioPanel = new JPanel(new GridLayout(0, 1)); radioPanel.add(append); radioPanel.add(override); // insert sub components JLabel label1 = new JLabel(Localization.lang("Available BibTeX fields")); con.gridwidth = GridBagConstraints.REMAINDER; gbl.setConstraints(label1, con); inputPanel.add(label1); con.gridwidth = GridBagConstraints.REMAINDER; con.gridheight = 8; con.weighty = 1; con.fill = GridBagConstraints.BOTH; gbl.setConstraints(fieldScroller, con); inputPanel.add(fieldScroller); con.fill = GridBagConstraints.HORIZONTAL; con.weighty = 0; con.gridwidth = 2; gbl.setConstraints(radioPanel, con); inputPanel.add(radioPanel); con.gridwidth = GridBagConstraints.REMAINDER; gbl.setConstraints(insertButton, con); inputPanel.add(insertButton); return inputPanel; }
From source file:net.sf.jabref.gui.mergeentries.MergeEntries.java
/** * Main function for building the merge entry JPanel *///from w ww . j a va 2 s . c o m private void initialize() { doneBuilding = false; setupFields(); // Fill diff mode combo box for (String diffText : DIFF_MODES) { diffMode.addItem(diffText); } diffMode.setSelectedIndex(Math.min(Globals.prefs.getInt(JabRefPreferences.MERGE_ENTRIES_DIFF_MODE), diffMode.getItemCount() - 1)); diffMode.addActionListener(e -> { updateTextPanes(differentFields); storePreference(); }); // Create main layout String colSpecMain = "left:pref, 5px, center:3cm:grow, 5px, center:pref, 3px, center:pref, 3px, center:pref, 5px, center:3cm:grow"; String colSpecMerge = "left:pref, 5px, fill:3cm:grow, 5px, center:pref, 3px, center:pref, 3px, center:pref, 5px, fill:3cm:grow"; String rowSpec = "pref, pref, 10px, fill:5cm:grow, 10px, pref, 10px, fill:3cm:grow"; StringBuilder rowBuilder = new StringBuilder(""); for (int i = 0; i < allFields.size(); i++) { rowBuilder.append("pref, 2dlu, "); } rowBuilder.append("pref"); JPanel mergePanel = new JPanel(); FormLayout mainLayout = new FormLayout(colSpecMain, rowSpec); FormLayout mergeLayout = new FormLayout(colSpecMerge, rowBuilder.toString()); mainPanel.setLayout(mainLayout); mergePanel.setLayout(mergeLayout); CellConstraints cc = new CellConstraints(); mainPanel.add(boldFontLabel(Localization.lang("Use")), cc.xyw(4, 1, 7, "center, bottom")); mainPanel.add(diffMode, cc.xy(11, 1, "right, bottom")); // Set headings JLabel[] headingLabels = new JLabel[6]; for (int i = 0; i < 6; i++) { headingLabels[i] = boldFontLabel(COLUMN_HEADINGS[i]); mainPanel.add(headingLabels[i], cc.xy(1 + (i * 2), 2)); } mainPanel.add(new JSeparator(), cc.xyw(1, 3, 11)); // Start with entry type mergePanel.add(boldFontLabel(Localization.lang("Entry type")), cc.xy(1, 1)); JTextPane leftTypeDisplay = getStyledTextPane(); leftTypeDisplay.setText(HTML_START + leftEntry.getType() + HTML_END); mergePanel.add(leftTypeDisplay, cc.xy(3, 1)); if (leftEntry.getType().equals(rightEntry.getType())) { identicalTypes = true; } else { identicalTypes = false; ButtonGroup group = new ButtonGroup(); typeRadioButtons = new ArrayList<>(2); for (int k = 0; k < 3; k += 2) { JRadioButton button = new JRadioButton(); typeRadioButtons.add(button); group.add(button); mergePanel.add(button, cc.xy(5 + (k * 2), 1)); button.addChangeListener(e -> updateAll()); } typeRadioButtons.get(0).setSelected(true); } JTextPane rightTypeDisplay = getStyledTextPane(); rightTypeDisplay.setText(HTML_START + rightEntry.getType() + HTML_END); mergePanel.add(rightTypeDisplay, cc.xy(11, 1)); // For all fields in joint add a row and possibly radio buttons int row = 2; int maxLabelWidth = -1; for (String field : allFields) { JLabel label = boldFontLabel(new SentenceCaseFormatter().format(field)); mergePanel.add(label, cc.xy(1, (2 * row) - 1, "left, top")); Optional<String> leftString = leftEntry.getFieldOptional(field); Optional<String> rightString = rightEntry.getFieldOptional(field); if (leftString.equals(rightString)) { identicalFields.add(field); } else { differentFields.add(field); } maxLabelWidth = Math.max(maxLabelWidth, label.getPreferredSize().width); // Left text pane if (leftString.isPresent()) { JTextPane tf = getStyledTextPane(); mergePanel.add(tf, cc.xy(3, (2 * row) - 1, "f, f")); leftTextPanes.put(field, tf); } // Add radio buttons if the two entries do not have identical fields if (identicalFields.contains(field)) { mergedEntry.setField(field, leftString.get()); // Will only happen if both entries have the field and the content is identical } else { ButtonGroup group = new ButtonGroup(); List<JRadioButton> list = new ArrayList<>(3); for (int k = 0; k < 3; k++) { JRadioButton button = new JRadioButton(); group.add(button); mergePanel.add(button, cc.xy(5 + (k * 2), (2 * row) - 1)); button.addChangeListener(e -> updateAll()); list.add(button); } radioButtons.put(field, list); if (leftString.isPresent()) { list.get(0).setSelected(true); if (!rightString.isPresent()) { list.get(2).setEnabled(false); } } else { list.get(0).setEnabled(false); list.get(2).setSelected(true); } } // Right text pane if (rightString.isPresent()) { JTextPane tf = getStyledTextPane(); mergePanel.add(tf, cc.xy(11, (2 * row) - 1, "f, f")); rightTextPanes.put(field, tf); } row++; } scrollPane = new JScrollPane(mergePanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); scrollPane.setBorder(BorderFactory.createEmptyBorder()); updateTextPanes(allFields); mainPanel.add(scrollPane, cc.xyw(1, 4, 11)); mainPanel.add(new JSeparator(), cc.xyw(1, 5, 11)); // Synchronize column widths String[] rbAlign = { "right", "center", "left" }; mainLayout.setColumnSpec(1, ColumnSpec.decode(Integer.toString(maxLabelWidth) + "px")); Integer maxRBWidth = -1; for (int k = 2; k < 5; k++) { maxRBWidth = Math.max(maxRBWidth, headingLabels[k].getPreferredSize().width); } for (int k = 0; k < 3; k++) { mergeLayout.setColumnSpec(5 + (k * 2), ColumnSpec.decode(rbAlign[k] + ":" + maxRBWidth + "px")); } // Setup a PreviewPanel and a Bibtex source box for the merged entry mainPanel.add(boldFontLabel(Localization.lang("Merged entry")), cc.xyw(1, 6, 6)); entryPreview = new PreviewPanel(null, mergedEntry, null, Globals.prefs.get(JabRefPreferences.PREVIEW_0)); mainPanel.add(entryPreview, cc.xyw(1, 8, 6)); mainPanel.add(boldFontLabel(Localization.lang("Merged BibTeX source code")), cc.xyw(8, 6, 4)); sourceView = new JTextArea(); sourceView.setLineWrap(true); sourceView.setFont(new Font("Monospaced", Font.PLAIN, Globals.prefs.getInt(JabRefPreferences.FONT_SIZE))); mainPanel.add(new JScrollPane(sourceView), cc.xyw(8, 8, 4)); sourceView.setEditable(false); // Add some margin around the layout mainLayout.appendRow(RowSpec.decode(MARGIN)); mainLayout.appendColumn(ColumnSpec.decode(MARGIN)); mainLayout.insertRow(1, RowSpec.decode(MARGIN)); mainLayout.insertColumn(1, ColumnSpec.decode(MARGIN)); // Everything done, allow any action to actually update the merged entry doneBuilding = true; updateAll(); // Show what we've got mainPanel.setVisible(true); javax.swing.SwingUtilities.invokeLater(() -> scrollPane.getVerticalScrollBar().setValue(0)); }