Example usage for java.awt GridBagConstraints LINE_START

List of usage examples for java.awt GridBagConstraints LINE_START

Introduction

In this page you can find the example usage for java.awt GridBagConstraints LINE_START.

Prototype

int LINE_START

To view the source code for java.awt GridBagConstraints LINE_START.

Click Source Link

Document

Place the component centered along the edge of its display area where lines of text would normally begin for the current ComponentOrientation .

Usage

From source file:org.webcat.plugintester.ui.MainFrameBuilder.java

/**
 * Creates and lays out the Swing components for the window.
 *
 * @param frame the JFrame instance that will contain the components
 *///from   www.  j  ava  2  s .c  om
private void constructFrame(JFrame frame) {
    GridBagConstraints gridBagConstraints;

    fileChooser = new JFileChooser();
    bottomPanel = new JPanel();
    runButton = new JButton();
    mainPanel = new JPanel();
    JLabel webCatHomeLabel = new JLabel();
    webCatHomeField = new JTextField();
    webCatHomeBrowseButton = new JButton();
    JSeparator jSeparator0 = new JSeparator();
    JLabel submissionLabel = new JLabel();
    submissionField = new JTextField();
    submissionBrowseButton = new JButton();
    JSeparator jSeparator1 = new JSeparator();
    JLabel pluginsLabel = new JLabel();
    JPanel pluginsPanel = new JPanel();
    JScrollPane pluginsScrollPane = new JScrollPane();
    pluginsTable = new JTable();
    pluginAddButton = new JButton();
    pluginRemoveButton = new JButton();
    JSeparator jSeparator2 = new JSeparator();
    JTabbedPane tabPane = new JTabbedPane();
    propertiesPanel = new JPanel();
    JScrollPane propertiesScrollPane = new JScrollPane();
    propertiesEditor = new JEditorPane();
    documentationPanel = new JPanel();
    JScrollPane documentationScrollPane = new JScrollPane();
    documentationEditor = new JEditorPane();

    // File chooser
    fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);

    // Bottom panel
    bottomPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 4, 4));

    // Run button
    runButton.setText("Run Plug-ins");
    runButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            runButtonActionPerformed(evt);
        }
    });
    bottomPanel.add(runButton);

    frame.getContentPane().add(bottomPanel, BorderLayout.PAGE_END);

    // Main panel
    mainPanel.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));
    mainPanel.setLayout(new GridBagLayout());

    // Web-CAT Home field
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = GridBagConstraints.RELATIVE;
    gridBagConstraints.anchor = GridBagConstraints.LINE_START;
    webCatHomeLabel.setText("Web-CAT Home:");
    mainPanel.add(webCatHomeLabel, gridBagConstraints);

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    gridBagConstraints.weightx = 1.0;
    webCatHomeField.setTransferHandler(new WebCATHomeTransferHandler());
    mainPanel.add(webCatHomeField, gridBagConstraints);

    // Web-CAT Home browse button
    webCatHomeBrowseButton.setText("Browse...");
    webCatHomeBrowseButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            webCatHomeBrowseButtonActionPerformed(evt);
        }
    });
    mainPanel.add(webCatHomeBrowseButton, new GridBagConstraints());

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    mainPanel.add(jSeparator0, gridBagConstraints);

    // Submission field
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = GridBagConstraints.RELATIVE;
    gridBagConstraints.anchor = GridBagConstraints.LINE_START;
    submissionLabel.setText("Submission:");
    mainPanel.add(submissionLabel, gridBagConstraints);

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    gridBagConstraints.weightx = 1.0;
    submissionField.setTransferHandler(new SubmissionTransferHandler());
    mainPanel.add(submissionField, gridBagConstraints);

    // Submission browse button
    submissionBrowseButton.setText("Browse...");
    submissionBrowseButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            submissionBrowseButtonActionPerformed(evt);
        }
    });
    mainPanel.add(submissionBrowseButton, new GridBagConstraints());

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    mainPanel.add(jSeparator1, gridBagConstraints);

    // Plug-ins area
    pluginsLabel.setText("Plug-ins to run:");
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    mainPanel.add(pluginsLabel, gridBagConstraints);

    pluginsPanel.setPreferredSize(new Dimension(400, 80));
    pluginsPanel.setLayout(new GridBagLayout());

    pluginsModel = new PluginsTableModel();
    pluginsTable.setModel(pluginsModel);
    pluginsTable.setColumnSelectionAllowed(true);
    pluginsTable.getTableHeader().setReorderingAllowed(false);
    pluginsScrollPane.setViewportView(pluginsTable);
    pluginsTable.getColumnModel().getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    pluginsTable.getColumnModel().getColumn(0).setResizable(false);
    pluginsScrollPane.setTransferHandler(new PluginsTransferHandler());

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.gridheight = GridBagConstraints.REMAINDER;
    gridBagConstraints.fill = GridBagConstraints.BOTH;
    gridBagConstraints.weightx = 1.0;
    gridBagConstraints.weighty = 1.0;
    pluginsPanel.add(pluginsScrollPane, gridBagConstraints);

    pluginAddButton.setText("Add...");
    pluginAddButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            pluginAddButtonActionPerformed(evt);
        }
    });
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    gridBagConstraints.anchor = GridBagConstraints.PAGE_START;
    pluginsPanel.add(pluginAddButton, gridBagConstraints);

    pluginRemoveButton.setText("Remove");

    pluginRemoveButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            pluginRemoveButtonActionPerformed(evt);
        }
    });
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    gridBagConstraints.anchor = GridBagConstraints.PAGE_START;
    pluginsPanel.add(pluginRemoveButton, gridBagConstraints);

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagConstraints.fill = GridBagConstraints.BOTH;
    gridBagConstraints.weightx = 1.0;
    gridBagConstraints.weighty = 0.25;
    mainPanel.add(pluginsPanel, gridBagConstraints);
    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    mainPanel.add(jSeparator2, gridBagConstraints);

    tabPane.setPreferredSize(new Dimension(466, 150));

    propertiesPanel.setLayout(new GridBagLayout());

    propertiesEditor.addKeyListener(new KeyAdapter() {
        public void keyTyped(KeyEvent e) {
            propertiesTimer.restart();
        }
    });

    propertiesTimer = new Timer(1000, new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            updateGradingProperties();
        }
    });

    propertiesScrollPane.setViewportView(propertiesEditor);

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.fill = GridBagConstraints.BOTH;
    gridBagConstraints.weightx = 1.0;
    gridBagConstraints.weighty = 1.0;
    propertiesPanel.add(propertiesScrollPane, gridBagConstraints);

    tabPane.addTab("Properties", propertiesPanel);

    documentationPanel.setLayout(new GridBagLayout());

    documentationEditor.setContentType("text/html");
    documentationEditor.setEditable(false);
    documentationScrollPane.setViewportView(documentationEditor);

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.fill = GridBagConstraints.BOTH;
    gridBagConstraints.weightx = 1.0;
    gridBagConstraints.weighty = 1.0;
    documentationPanel.add(documentationScrollPane, gridBagConstraints);

    tabPane.addTab("Documentation", documentationPanel);

    gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagConstraints.gridheight = GridBagConstraints.REMAINDER;
    gridBagConstraints.fill = GridBagConstraints.BOTH;
    gridBagConstraints.weighty = 1.0;
    mainPanel.add(tabPane, gridBagConstraints);

    frame.getContentPane().add(mainPanel, BorderLayout.CENTER);

    frame.pack();
}

From source file:pcgen.gui2.prefs.OutputPanel.java

/**
 * Instantiates a new output panel.//  w  w w.  j a  v  a  2 s  .c o m
 */
public OutputPanel() {
    GridBagLayout gridbag = new GridBagLayout();
    GridBagConstraints c = new GridBagConstraints();
    JLabel label;
    Border etched = null;
    TitledBorder title1 = BorderFactory.createTitledBorder(etched, IN_OUTPUT);

    title1.setTitleJustification(TitledBorder.LEADING);
    this.setBorder(title1);
    this.setLayout(gridbag);
    c.fill = GridBagConstraints.BOTH;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(2, 2, 2, 2);

    Utility.buildConstraints(c, 0, 0, 1, 1, 0, 0);
    label = new JLabel(LanguageBundle.getString("in_Prefs_outputSheetHTMLDefault"));
    gridbag.setConstraints(label, c);
    this.add(label);
    Utility.buildConstraints(c, 1, 0, 1, 1, 1, 0);
    outputSheetHTMLDefault = new JTextField(
            String.valueOf(SettingsHandler.getSelectedCharacterHTMLOutputSheet(null)));

    // sage_sam 9 April 2003
    outputSheetHTMLDefault.addFocusListener(textFieldListener);
    gridbag.setConstraints(outputSheetHTMLDefault, c);
    this.add(outputSheetHTMLDefault);
    Utility.buildConstraints(c, 2, 0, 1, 1, 0, 0);
    outputSheetHTMLDefaultButton = createChooseButton();
    gridbag.setConstraints(outputSheetHTMLDefaultButton, c);
    this.add(outputSheetHTMLDefaultButton);
    outputSheetHTMLDefaultButton.addActionListener(prefsButtonHandler);

    Utility.buildConstraints(c, 0, 1, 1, 1, 0, 0);
    label = new JLabel(LanguageBundle.getString("in_Prefs_outputSheetPDFDefault"));
    gridbag.setConstraints(label, c);
    this.add(label);
    Utility.buildConstraints(c, 1, 1, 1, 1, 1, 0);
    outputSheetPDFDefault = new JTextField(
            String.valueOf(SettingsHandler.getSelectedCharacterPDFOutputSheet(null)));

    // sage_sam 9 April 2003
    outputSheetPDFDefault.addFocusListener(textFieldListener);
    gridbag.setConstraints(outputSheetPDFDefault, c);
    this.add(outputSheetPDFDefault);
    Utility.buildConstraints(c, 2, 1, 1, 1, 0, 0);
    outputSheetPDFDefaultButton = createChooseButton();
    gridbag.setConstraints(outputSheetPDFDefaultButton, c);
    this.add(outputSheetPDFDefaultButton);
    outputSheetPDFDefaultButton.addActionListener(prefsButtonHandler);

    Utility.buildConstraints(c, 0, 2, 1, 1, 0, 0);
    label = new JLabel(IN_OUTPUT_SHEET_EQ_SET);
    gridbag.setConstraints(label, c);
    this.add(label);
    Utility.buildConstraints(c, 1, 2, 1, 1, 0, 0);
    outputSheetEqSet = new JTextField(String.valueOf(SettingsHandler.getSelectedEqSetTemplate()));

    // sage_sam 9 April 2003
    outputSheetEqSet.addFocusListener(textFieldListener);
    gridbag.setConstraints(outputSheetEqSet, c);
    this.add(outputSheetEqSet);
    Utility.buildConstraints(c, 2, 2, 1, 1, 0, 0);
    outputSheetEqSetButton = createChooseButton();
    gridbag.setConstraints(outputSheetEqSetButton, c);
    this.add(outputSheetEqSetButton);
    outputSheetEqSetButton.addActionListener(prefsButtonHandler);

    Utility.buildConstraints(c, 0, 3, 3, 1, 0, 0);
    saveOutputSheetWithPC.setText(IN_SAVE_OUTPUT_SHEET_WITH_PC);
    gridbag.setConstraints(saveOutputSheetWithPC, c);
    this.add(saveOutputSheetWithPC);

    Utility.buildConstraints(c, 0, 4, 1, 1, 0, 0);
    label = new JLabel(LanguageBundle.getString("in_Prefs_outputSpellSheetDefault"));
    gridbag.setConstraints(label, c);
    this.add(label);
    Utility.buildConstraints(c, 1, 4, 1, 1, 0, 0);
    outputSheetSpellsDefault = new JTextField(String.valueOf(SettingsHandler.getSelectedSpellSheet()));
    outputSheetSpellsDefault.addFocusListener(textFieldListener);
    gridbag.setConstraints(outputSheetSpellsDefault, c);
    this.add(outputSheetSpellsDefault);
    Utility.buildConstraints(c, 2, 4, 1, 1, 0, 0);
    outputSheetSpellsDefaultButton = createChooseButton();
    gridbag.setConstraints(outputSheetSpellsDefaultButton, c);
    this.add(outputSheetSpellsDefaultButton);
    outputSheetSpellsDefaultButton.addActionListener(prefsButtonHandler);

    Utility.buildConstraints(c, 0, 5, 3, 1, 0, 0);
    printSpellsWithPC.setText(LanguageBundle.getString("in_Prefs_printSpellsWithPC"));
    gridbag.setConstraints(printSpellsWithPC, c);
    this.add(printSpellsWithPC);

    Utility.buildConstraints(c, 0, 6, 1, 1, 0, 0);
    label = new JLabel(IN_PAPER_TYPE);
    gridbag.setConstraints(label, c);
    this.add(label);
    Utility.buildConstraints(c, 1, 6, 2, 1, 0, 0);

    final int paperCount = Globals.getPaperCount();
    paperNames = new String[paperCount];

    for (int i = 0; i < paperCount; ++i) {
        paperNames[i] = Globals.getPaperInfo(i, PaperInfo.NAME);
    }

    paperType = new JComboBoxEx<>(paperNames);
    gridbag.setConstraints(paperType, c);
    this.add(paperType);

    Utility.buildConstraints(c, 0, 7, 3, 1, 0, 0);
    gridbag.setConstraints(removeTempFiles, c);
    this.add(removeTempFiles);

    Utility.buildConstraints(c, 0, 8, 3, 1, 0, 0);
    weaponProfPrintout = new JCheckBox(IN_WEAPON_PROF_PRINTOUT, SettingsHandler.getWeaponProfPrintout());
    gridbag.setConstraints(weaponProfPrintout, c);
    this.add(weaponProfPrintout);

    Utility.buildConstraints(c, 0, 9, 1, 1, 0, 0);
    label = new JLabel(IN_POST_EXPORT_COMAND_STANDARD);
    gridbag.setConstraints(label, c);
    this.add(label);
    Utility.buildConstraints(c, 1, 9, 2, 1, 0, 0);
    postExportCommandStandard = new JTextField(String.valueOf(SettingsHandler.getPostExportCommandStandard()));
    gridbag.setConstraints(postExportCommandStandard, c);
    this.add(postExportCommandStandard);

    Utility.buildConstraints(c, 0, 10, 1, 1, 0, 0);
    label = new JLabel(IN_POST_EXPORT_COMMAND_PDF);
    gridbag.setConstraints(label, c);
    this.add(label);
    Utility.buildConstraints(c, 1, 10, 2, 1, 0, 0);
    postExportCommandPDF = new JTextField(String.valueOf(SettingsHandler.getPostExportCommandPDF()));
    gridbag.setConstraints(postExportCommandPDF, c);
    this.add(postExportCommandPDF);

    Utility.buildConstraints(c, 0, 11, 1, 1, 0, 0);
    label = new JLabel(IN_SKILL_FILTER);
    gridbag.setConstraints(label, c);
    this.add(label);
    Utility.buildConstraints(c, 1, 11, GridBagConstraints.REMAINDER, 1, 0, 0);
    skillFilter.setModel(new DefaultComboBoxModel<>(new SkillFilter[] { SkillFilter.Ranks,
            SkillFilter.NonDefault, SkillFilter.Usable, SkillFilter.All }));
    skillFilter.setSelectedItem(SkillFilter.getByValue(PCGenSettings.OPTIONS_CONTEXT
            .initInt(PCGenSettings.OPTION_SKILL_FILTER, SkillFilter.Usable.getValue())));
    gridbag.setConstraints(skillFilter, c);
    this.add(skillFilter);

    Utility.buildConstraints(c, 0, 12, 1, 1, 0, 0);
    label = new JLabel(IN_INVALID_TO_HIT_TEXT);
    gridbag.setConstraints(label, c);
    this.add(label);
    Utility.buildConstraints(c, 1, 12, 2, 1, 0, 0);
    invalidToHitText = new JTextField(String.valueOf(SettingsHandler.getInvalidToHitText()));
    gridbag.setConstraints(invalidToHitText, c);
    this.add(invalidToHitText);

    Utility.buildConstraints(c, 0, 13, 1, 1, 0, 0);
    label = new JLabel(IN_INVALID_DMG_TEXT);
    gridbag.setConstraints(label, c);
    this.add(label);
    Utility.buildConstraints(c, 1, 13, GridBagConstraints.REMAINDER, 1, 0, 0);
    invalidDmgText = new JTextField(String.valueOf(SettingsHandler.getInvalidDmgText()));
    gridbag.setConstraints(invalidDmgText, c);
    this.add(invalidDmgText);

    Utility.buildConstraints(c, 0, 14, 3, 1, 0, 0);
    alwaysOverwrite = new JCheckBox(IN_ALWAYS_OVERWRITE, SettingsHandler.getAlwaysOverwrite());
    gridbag.setConstraints(alwaysOverwrite, c);
    this.add(alwaysOverwrite);

    Utility.buildConstraints(c, 0, 15, 3, 1, 0, 0);
    showSingleBoxPerBundle = new JCheckBox(IN_SHOW_SINGLE_BOX_PER_BUNDLE,
            SettingsHandler.getShowSingleBoxPerBundle());
    gridbag.setConstraints(showSingleBoxPerBundle, c);
    this.add(showSingleBoxPerBundle);

    Utility.buildConstraints(c, 0, 16, 1, 1, 0, 0);
    label = new JLabel(LanguageBundle.getString("in_Prefs_exportChoice")); // $NON-NSL-1$
    gridbag.setConstraints(label, c);
    this.add(label);

    Utility.buildConstraints(c, 1, 16, GridBagConstraints.REMAINDER, 1, 0, 0);
    gridbag.setConstraints(exportChoice, c);
    this.add(exportChoice);

    Utility.buildConstraints(c, 0, 17, 3, 1, 0, 0);
    gridbag.setConstraints(generateTempFileWithPdf, c);
    this.add(generateTempFileWithPdf);

    Utility.buildConstraints(c, 0, 20, 3, 1, 1, 1);
    c.fill = GridBagConstraints.BOTH;
    label = new JLabel(" ");
    gridbag.setConstraints(label, c);
    this.add(label);
}

From source file:shuffle.fwk.service.roster.EditRosterService.java

private Component makeBottomPanel() {
    JPanel ret = new JPanel(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.NONE;
    c.insets = new Insets(0, 10, 0, 10);
    c.weightx = 1.0;//from   w  w  w  . ja  v a  2  s. c o  m
    c.weighty = 0.0;
    c.gridx = 1;
    c.gridy = 1;
    c.gridwidth = 1;
    c.gridheight = 1;

    c.anchor = GridBagConstraints.LINE_START;
    c.weightx = 0.0;
    c.gridx++;
    selectedDisplayLabel = new JLabel(getString(KEY_NONE_SELECTED));
    selectedDisplayLabel.setToolTipText(getString(KEY_SELECTED_TOOLTIP));
    ;
    ret.add(selectedDisplayLabel, c);
    c.insets = new Insets(0, 0, 0, 0);

    c.anchor = GridBagConstraints.LINE_END;
    c.weightx = 1.0;
    c.gridx++;
    teamFilter = new JCheckBox(getString(KEY_TEAM));
    JPanel teamFilterPanel = new JPanel(new BorderLayout());
    teamFilterPanel.add(teamFilter, BorderLayout.WEST);
    teamFilter.setToolTipText(getString(KEY_TEAM_TOOLTIP));
    ret.add(teamFilterPanel, c);

    c.anchor = GridBagConstraints.LINE_END;
    c.weightx = 0.0;
    c.gridx++;
    activeEffect = new EffectChooser(false, EffectChooser.DefaultEntry.SPECIES);
    JPanel activeEffectPanel = new JPanel(new BorderLayout());
    activeEffectPanel.add(activeEffect, BorderLayout.WEST);
    activeEffect.setToolTipText(getString(KEY_ACTIVE_EFFECT));
    ret.add(activeEffectPanel, c);

    c.anchor = GridBagConstraints.LINE_END;
    c.weightx = 0.0;
    c.gridx++;
    JPanel skillPanel = new JPanel(new BorderLayout());
    ImageIcon skillBoosterIcon = getUser().getImageManager().getImageFor(KEY_SKILL_BOOSTER);
    JLabel skillBoosterLabel = new JLabel(skillBoosterIcon);
    skillPanel.add(skillBoosterLabel, BorderLayout.EAST);
    skillLevels = new JComboBox<Integer>();
    skillLevels.setEnabled(false);
    skillLevels.addItem(1);
    skillPanel.add(skillLevels, BorderLayout.WEST);
    skillPanel.setToolTipText(getString(KEY_SKILL_BOOSTER_TOOLTIP));
    skillLevels.setToolTipText(getString(KEY_SKILL_BOOSTER_TOOLTIP));
    ret.add(skillPanel, c);

    c.anchor = GridBagConstraints.LINE_END;
    c.weightx = 0.0;
    c.gridx++;
    JPanel speedupPanel = new JPanel(new BorderLayout());
    ImageIcon candyIcon = getUser().getImageManager().getImageFor(KEY_CANDY_ICON);
    JLabel candyLabel = new JLabel(candyIcon);
    speedupPanel.add(candyLabel, BorderLayout.EAST);
    speedups = new JComboBox<Integer>();
    speedups.setEnabled(false);
    speedups.addItem(0);
    speedupPanel.add(speedups, BorderLayout.WEST);
    speedupPanel.setToolTipText(getString(KEY_CANDY_TOOLTIP));
    speedups.setToolTipText(getString(KEY_CANDY_TOOLTIP));
    ret.add(speedupPanel, c);

    c.anchor = GridBagConstraints.LINE_END;
    c.weightx = 0.0;
    c.gridx++;
    JButton okButton = new JButton(getString(KEY_OK));
    okButton.setToolTipText(getString(KEY_OK_TOOLTIP));
    ret.add(okButton, c);
    setDefaultButton(okButton);

    c.anchor = GridBagConstraints.CENTER;
    c.weightx = 0.0;
    c.gridx++;
    JButton applyButton = new JButton(getString(KEY_APPLY));
    applyButton.setToolTipText(getString(KEY_APPLY_TOOLTIP));
    ret.add(applyButton, c);

    c.anchor = GridBagConstraints.LINE_START;
    c.weightx = 0.0;
    c.gridx++;
    JButton cancelButton = new JButton(new DisposeAction(getString(KEY_CANCEL), this));
    cancelButton.setToolTipText(getString(KEY_CANCEL_TOOLTIP));
    ret.add(cancelButton, c);

    okButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            onOK();
        }
    });
    applyButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            onApply();
        }
    });
    addSpeedupsListener();
    return ret;
}

From source file:shuffle.fwk.service.teams.EditTeamService.java

private Component makeBottomPanel() {
    JPanel ret = new JPanel(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.NONE;
    c.weightx = 1.0;//from   w ww  .j  a  va 2  s.c  om
    c.weighty = 0.0;
    c.gridx = 1;
    c.gridy = 1;
    c.gridwidth = 1;
    c.gridheight = 1;

    c.anchor = GridBagConstraints.LINE_START;
    c.weightx = 0.0;
    c.gridx += 1;
    c.insets = new Insets(0, 10, 0, 10);
    selectedDisplayLabel = new JLabel(getString(KEY_NONE_SELECTED));
    selectedDisplayLabel.setToolTipText(getString(KEY_SELECTED_TOOLTIP));
    ret.add(selectedDisplayLabel, c);

    c.anchor = GridBagConstraints.LINE_END;
    c.weightx = 1.0;
    c.gridx++;
    survivalMode = new JCheckBox(getString(KEY_SURVIVAL));
    JPanel survivalModePanel = new JPanel(new BorderLayout());
    survivalModePanel.add(survivalMode, BorderLayout.WEST);
    survivalMode.setToolTipText(getString(KEY_SURVIVAL_TOOLTIP));
    ret.add(survivalModePanel, c);

    c.anchor = GridBagConstraints.LINE_END;
    c.weightx = 0.0;
    c.gridx += 1;
    JButton okButton = new JButton(getString(KEY_OK));
    okButton.setToolTipText(getString(KEY_OK_TOOLTIP));
    ret.add(okButton, c);
    setDefaultButton(okButton);

    c.anchor = GridBagConstraints.CENTER;
    c.weightx = 0.0;
    c.gridx += 1;
    JButton applyButton = new JButton(getString(KEY_APPLY));
    applyButton.setToolTipText(getString(KEY_APPLY_TOOLTIP));
    ret.add(applyButton, c);

    c.anchor = GridBagConstraints.LINE_START;
    c.weightx = 0.0;
    c.gridx += 1;
    JButton cancelButton = new JButton(new DisposeAction(getString(KEY_CANCEL), this));
    cancelButton.setToolTipText(getString(KEY_CANCEL_TOOLTIP));
    ret.add(cancelButton, c);

    okButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            onOK();
        }
    });
    applyButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            onApply();
        }
    });
    return ret;
}

From source file:typoscript.TypoScriptPluginOptions.java

/**
 * This method is STATIC and will give you a GridBagConstraints with the required attributes
 * @param gridx Horizontal grid position of the element
 * @param gridy Vertical grid position of the element
 * @param gridwidth How many cells the element should span
 * @param gridheight How many rows the element should span
 * @param position either left, centre, right, top-left, top-right, bottom-left, bottom-right
 * @return a GridBagConstraints object with the desired attributes.
 *//*  ww w .  ja v a2 s  .c  o m*/
public static GridBagConstraints getConstraint(int gridx, int gridy, int gridwidth, int gridheight,
        String position) {
    GridBagConstraints tempGbc = new GridBagConstraints();
    tempGbc.gridx = gridx;
    tempGbc.gridy = gridy;
    tempGbc.gridwidth = gridwidth;
    tempGbc.gridheight = gridheight;

    if (position.equals("left")) {
        tempGbc.anchor = GridBagConstraints.LINE_START;
    } else if (position.equals("centre")) {
        tempGbc.anchor = GridBagConstraints.CENTER;
    } else if (position.equals("right")) {
        tempGbc.anchor = GridBagConstraints.LINE_END;
    } else if (position.equals("top-left")) {
        tempGbc.anchor = GridBagConstraints.FIRST_LINE_START;
    } else if (position.equals("top-right")) {
        tempGbc.anchor = GridBagConstraints.FIRST_LINE_END;
    } else if (position.equals("bottom-left")) {
        tempGbc.anchor = GridBagConstraints.LAST_LINE_START;
    } else if (position.equals("bottom-right")) {
        tempGbc.anchor = GridBagConstraints.LAST_LINE_END;
    } else {
        // error
        System.out.println(
                "getConstraint was provided with an invalid position '" + position + "', returning null");
        return null;
    }

    return tempGbc;
}

From source file:uk.ac.ucl.cs.cmic.giftcloud.uploadapp.ConfigurationDialog.java

ConfigurationDialog(final Component owner, final UploaderGuiController controller,
        final GiftCloudPropertiesFromApplication giftCloudProperties, final ProjectListModel projectListModel,
        final ResourceBundle resourceBundle, final GiftCloudDialogs giftCloudDialogs,
        final GiftCloudReporter reporter) {
    this.controller = controller;
    this.giftCloudProperties = giftCloudProperties;
    this.projectListModel = projectListModel;
    this.resourceBundle = resourceBundle;
    this.giftCloudDialogs = giftCloudDialogs;
    this.reporter = reporter;
    temporaryDropDownListModel = new TemporaryProjectListModel(projectListModel,
            giftCloudProperties.getLastProject());
    componentToCenterDialogOver = owner;

    dialog = new JDialog();
    dialog.setModal(true);//www .j a v  a2 s  . c o  m
    dialog.setResizable(false);

    // Call custom dialog close code when the close button is clicked
    dialog.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    dialog.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent ev) {
            closeDialog();
        }
    });

    dialog.setLocationRelativeTo(componentToCenterDialogOver); // without this, appears at TLHC rather then center of parent or screen
    dialog.setTitle(resourceBundle.getString("configurationDialogTitle"));

    final GridBagConstraints sectionTitleConstraints = new GridBagConstraints();
    sectionTitleConstraints.gridx = 0;
    sectionTitleConstraints.gridy = 1;
    sectionTitleConstraints.gridwidth = 2;
    sectionTitleConstraints.weightx = 1;
    sectionTitleConstraints.weighty = 1;
    sectionTitleConstraints.anchor = GridBagConstraints.CENTER;
    sectionTitleConstraints.fill = GridBagConstraints.HORIZONTAL;

    final GridBagConstraints labelConstraints = new GridBagConstraints();
    labelConstraints.gridx = 0;
    labelConstraints.gridy = 0;
    labelConstraints.gridwidth = 1;
    labelConstraints.weightx = 1;
    labelConstraints.weighty = 1;
    labelConstraints.anchor = GridBagConstraints.LINE_START;
    labelConstraints.fill = GridBagConstraints.NONE;

    final GridBagConstraints inputConstraints = new GridBagConstraints();
    inputConstraints.gridx = 1;
    inputConstraints.gridy = 0;
    inputConstraints.gridwidth = 1;
    inputConstraints.weightx = 1;
    inputConstraints.weighty = 1;
    inputConstraints.anchor = GridBagConstraints.LINE_END;
    inputConstraints.fill = GridBagConstraints.HORIZONTAL;

    GridBagConstraints separatorConstraint = new GridBagConstraints();
    separatorConstraint.weightx = 1.0;
    separatorConstraint.fill = GridBagConstraints.HORIZONTAL;
    separatorConstraint.gridwidth = GridBagConstraints.REMAINDER;

    // The panel containing the GIFT-Cloud server configuration
    final JPanel giftCloudServerPanel = new JPanel();
    {
        GridBagLayout projectUploadlayout = new GridBagLayout();
        giftCloudServerPanel.setLayout(projectUploadlayout);
        JLabel serverPanelLabel = new JLabel(resourceBundle.getString("configPanelServerConfig"),
                SwingConstants.CENTER);
        giftCloudServerPanel.add(serverPanelLabel, sectionTitleConstraints);

        // GIFT-Cloud server URL
        {
            labelConstraints.gridwidth = 1;
            labelConstraints.gridy = 2;
            final JLabel giftCloudServerLabel = new JLabel(resourceBundle.getString("giftCloudServerText"),
                    SwingConstants.RIGHT);
            giftCloudServerLabel.setToolTipText(resourceBundle.getString("giftCloudServerTextToolTipText"));
            giftCloudServerPanel.add(giftCloudServerLabel, labelConstraints);

            giftCloudServerText = new AutoFocusTextField(giftCloudProperties.getGiftCloudUrl().orElse(""),
                    textFieldLengthForGiftCloudServerUrl);
            inputConstraints.gridy = 2;
            giftCloudServerPanel.add(giftCloudServerText, inputConstraints);
        }

        // GIFT-Cloud username
        {
            labelConstraints.gridy = 3;
            final JLabel giftCloudUserNameLabel = new JLabel(resourceBundle.getString("giftCloudUsername"),
                    SwingConstants.RIGHT);
            giftCloudUserNameLabel.setToolTipText(resourceBundle.getString("giftCloudUsernameToolTipText"));
            giftCloudServerPanel.add(giftCloudUserNameLabel, labelConstraints);

            final Optional<String> serverUrl = giftCloudProperties.getLastUserName();
            final String initialServerText = serverUrl.isPresent() ? serverUrl.get() : "";
            giftCloudUsernameText = new AutoFocusTextField(initialServerText);
            inputConstraints.gridy = 3;
            giftCloudServerPanel.add(giftCloudUsernameText, inputConstraints);
        }

        // GIFT-Cloud password
        {
            labelConstraints.gridy = 4;
            final JLabel giftCloudPasswordLabel = new JLabel(resourceBundle.getString("giftCloudPassword"),
                    SwingConstants.RIGHT);
            giftCloudPasswordLabel.setToolTipText(resourceBundle.getString("giftCloudPasswordToolTipText"));
            giftCloudServerPanel.add(giftCloudPasswordLabel, labelConstraints);

            final Optional<char[]> password = giftCloudProperties.getLastPassword();
            final char[] initialPassword = password.isPresent() ? password.get() : "".toCharArray();
            giftCloudPasswordText = new JPasswordField(new String(initialPassword), 16); // Shouldn't create a String but there's no other way to initialize the password field
            inputConstraints.gridy = 4;
            giftCloudServerPanel.add(giftCloudPasswordText, inputConstraints);
        }

        // Project list
        {
            labelConstraints.gridy = 5;
            JLabel projectListLabel = new JLabel(resourceBundle.getString("giftCloudProjectLabelText"),
                    SwingConstants.RIGHT);
            giftCloudServerPanel.add(projectListLabel, labelConstraints);

            inputConstraints.gridy = 5;
            projectList = new BackwardsCompatibleComboBox();
            projectList.setEditable(false);
            projectList.setToolTipText(resourceBundle.getString("giftCloudProjectTooltip"));
            giftCloudServerPanel.add(projectList, inputConstraints);

            labelConstraints.gridx = 1;
            projectListWaitingLabel = new JLabel(resourceBundle.getString("giftCloudProjectWaitingLabelText"),
                    SwingConstants.RIGHT);
            giftCloudServerPanel.add(projectListWaitingLabel, labelConstraints);
            labelConstraints.gridx = 0;
        }

        // Subject prefix
        {
            labelConstraints.gridy = 6;
            JLabel subjectPrefixLabel = new JLabel(resourceBundle.getString("configPanelListenerSubjectPrefix"),
                    SwingConstants.RIGHT);
            subjectPrefixLabel
                    .setToolTipText(resourceBundle.getString("configPanelListenerSubjectPrefixTooltip"));
            giftCloudServerPanel.add(subjectPrefixLabel, labelConstraints);

            inputConstraints.gridy = 6;
            final Optional<String> subjectPrefixText = giftCloudProperties.getSubjectPrefix();
            subjectPrefixField = new AutoFocusTextField(subjectPrefixText.orElse(""));
            giftCloudServerPanel.add(subjectPrefixField, inputConstraints);
        }
    }

    // Local Dicom node configuration
    final JPanel listenerPanel = new JPanel();
    {
        GridBagLayout listenerPanellayout = new GridBagLayout();
        listenerPanel.setLayout(listenerPanellayout);
        JSeparator separator = new JSeparator();
        listenerPanel.add(separator, separatorConstraint);

        JLabel listenerPanelLabel = new JLabel(resourceBundle.getString("configPanelListenerConfig"),
                SwingConstants.CENTER);
        listenerPanel.add(listenerPanelLabel, sectionTitleConstraints);

        {
            labelConstraints.gridy = 2;
            JLabel listeningAETitleJLabel = new JLabel(resourceBundle.getString("configPanelListenerAe"),
                    SwingConstants.RIGHT);
            listeningAETitleJLabel.setToolTipText(resourceBundle.getString("configPanelListenerAeToolTip"));
            listenerPanellayout.setConstraints(listeningAETitleJLabel, labelConstraints);
            listenerPanel.add(listeningAETitleJLabel);

            inputConstraints.gridy = 2;
            final String listeningAETitleInitialText = giftCloudProperties.getListenerAETitle();
            listeningAETitleField = new AutoFocusTextField(listeningAETitleInitialText);
            listenerPanellayout.setConstraints(listeningAETitleField, inputConstraints);
            listenerPanel.add(listeningAETitleField);
        }
        {
            labelConstraints.gridy = 3;
            JLabel listeningPortJLabel = new JLabel(resourceBundle.getString("configPanelListenerPort"),
                    SwingConstants.RIGHT);
            listeningPortJLabel.setToolTipText(resourceBundle.getString("configPanelListenerPortToolTip"));
            listenerPanellayout.setConstraints(listeningPortJLabel, labelConstraints);
            listenerPanel.add(listeningPortJLabel);

            inputConstraints.gridy = 3;
            final int port = giftCloudProperties.getListeningPort();
            final String portValue = Integer.toString(port);
            listeningPortField = new AutoFocusTextField(portValue);
            listenerPanellayout.setConstraints(listeningPortField, inputConstraints);
            listenerPanel.add(listeningPortField);
        }
        {
            labelConstraints.gridy = 4;
            JLabel patientListExportFolderLabel = new JLabel(
                    resourceBundle.getString("configPanelListenerPatientListExportFolder"),
                    SwingConstants.RIGHT);
            patientListExportFolderLabel.setToolTipText(
                    resourceBundle.getString("configPanelListenerPatientListExportFolderTooltip"));
            listenerPanellayout.setConstraints(patientListExportFolderLabel, labelConstraints);
            listenerPanel.add(patientListExportFolderLabel);

            inputConstraints.gridy = 4;
            final Optional<String> patientListExportFolder = giftCloudProperties.getPatientListExportFolder();
            patientListExportFolderField = new AutoFocusTextField(patientListExportFolder.orElse(""));
            listenerPanellayout.setConstraints(patientListExportFolderField, inputConstraints);
            listenerPanel.add(patientListExportFolderField);
        }

        // Patient list spreadsheet password
        {
            labelConstraints.gridy = 5;
            final JLabel patientListSpreadsheetPasswordLabel = new JLabel(
                    resourceBundle.getString("configPanelListenerPatientListSpreadhsheetPassword"),
                    SwingConstants.RIGHT);
            patientListSpreadsheetPasswordLabel.setToolTipText(
                    resourceBundle.getString("configPanelListenerPatientListSpreadhsheetPasswordTooltip"));
            listenerPanel.add(patientListSpreadsheetPasswordLabel, labelConstraints);

            final Optional<char[]> password = giftCloudProperties.getPatientListPassword();
            final char[] initialPassword = password.isPresent() ? password.get() : "".toCharArray();
            patientListSpreadsheetPasswordField = new JPasswordField(new String(initialPassword), 16); // Shouldn't create a String but there's no other way to initialize the password field
            inputConstraints.gridy = 5;
            listenerPanel.add(patientListSpreadsheetPasswordField, inputConstraints);
        }
    }

    // Remote PACS configuration
    final JPanel remoteAEPanel = new JPanel();

    {
        GridBagLayout pacsPanellayout = new GridBagLayout();
        remoteAEPanel.setLayout(pacsPanellayout);

        JSeparator separator = new JSeparator();
        remoteAEPanel.add(separator, separatorConstraint);

        JLabel remotePanelLabel = new JLabel(resourceBundle.getString("pacsPanelListenerConfig"),
                SwingConstants.CENTER);
        remoteAEPanel.add(remotePanelLabel, sectionTitleConstraints);

        {
            labelConstraints.gridy = 2;
            JLabel remoteAeTitleLabel = new JLabel(resourceBundle.getString("configPanelPacsAeTitle"),
                    SwingConstants.RIGHT);
            remoteAeTitleLabel.setToolTipText(resourceBundle.getString("configPanelPacsAeTitleTooltip"));
            remoteAEPanel.add(remoteAeTitleLabel, labelConstraints);

            final Optional<String> pacsAeTitle = giftCloudProperties.getPacsAeTitle();
            remoteAETitleField = new AutoFocusTextField(pacsAeTitle.isPresent() ? pacsAeTitle.get() : "");
            inputConstraints.gridy = 2;
            remoteAEPanel.add(remoteAETitleField, inputConstraints);
        }

        {
            labelConstraints.gridy = 3;
            JLabel remoteAeHostLabel = new JLabel(resourceBundle.getString("configPanelPacsHostname"),
                    SwingConstants.RIGHT);
            remoteAeHostLabel.setToolTipText(resourceBundle.getString("configPanelPacsHostnameTooltip"));
            remoteAEPanel.add(remoteAeHostLabel, labelConstraints);

            remoteAEHostName = new AutoFocusTextField(giftCloudProperties.getPacsHostName().orElse(""));
            inputConstraints.gridy = 3;
            remoteAEPanel.add(remoteAEHostName, inputConstraints);
        }

        {
            labelConstraints.gridy = 4;
            JLabel remoteAeTitleLabel = new JLabel(resourceBundle.getString("configPanelPacsPort"),
                    SwingConstants.RIGHT);
            remoteAeTitleLabel.setToolTipText(resourceBundle.getString("configPanelPacsPortTooltip"));
            remoteAEPanel.add(remoteAeTitleLabel, labelConstraints);

            remoteAEPortField = new AutoFocusTextField(Integer.toString(giftCloudProperties.getPacsPort()));
            inputConstraints.gridy = 4;
            remoteAEPanel.add(remoteAEPortField, inputConstraints);
        }

    }

    // The panel containing the cancel and apply buttons
    JPanel buttonPanel = new JPanel();
    JPanel closeButtonPanel = new JPanel();
    {
        final GridBagLayout buttonPanellayout = new GridBagLayout();
        buttonPanel.setLayout(buttonPanellayout);

        JSeparator separator = new JSeparator();
        buttonPanel.add(separator, separatorConstraint);

        closeButtonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));

        JButton cancelButton = new JButton(resourceBundle.getString("cancelSettingsButtonLabelText"));
        cancelButton.setToolTipText(resourceBundle.getString("cancelSettingsButtonToolTipText"));
        closeButtonPanel.add(cancelButton);
        cancelButton.addActionListener(new CancelActionListener());

        JButton applyButton = new JButton(resourceBundle.getString("applySettingsButtonLabelText"));
        applyButton.setToolTipText(resourceBundle.getString("applySettingsButtonToolTipText"));
        closeButtonPanel.add(applyButton);
        applyButton.addActionListener(new ApplyActionListener());

        JButton closeButton = new JButton(resourceBundle.getString("closeSettingsButtonLabelText"));
        closeButton.setToolTipText(resourceBundle.getString("closeSettingsButtonToolTipText"));
        closeButtonPanel.add(closeButton);
        closeButton.addActionListener(new CloseActionListener());

        final GridBagConstraints constraints = new GridBagConstraints();
        constraints.gridx = 0;
        constraints.gridy = 1;
        constraints.weightx = 1;
        constraints.weighty = 1;
        constraints.insets = new Insets(5, 5, 5, 5);
        constraints.fill = GridBagConstraints.HORIZONTAL;
        buttonPanellayout.setConstraints(closeButtonPanel, constraints);
        buttonPanel.add(closeButtonPanel);
    }

    // The main panel of the configuration dialog
    JPanel configPanel = new JPanel();
    {
        final GridBagLayout configPanelLayout = new GridBagLayout();
        configPanel.setLayout(configPanelLayout);
        {
            final GridBagConstraints constraints = new GridBagConstraints();
            constraints.gridx = 0;
            constraints.gridy = 0;
            constraints.weightx = 1;
            constraints.weighty = 1;
            constraints.insets = new Insets(5, 5, 5, 5);
            constraints.fill = GridBagConstraints.HORIZONTAL;
            configPanelLayout.setConstraints(giftCloudServerPanel, constraints);
            configPanel.add(giftCloudServerPanel);
        }
        {
            final GridBagConstraints constraints = new GridBagConstraints();
            constraints.gridx = 0;
            constraints.gridy = 1;
            constraints.weightx = 1;
            constraints.weighty = 1;
            constraints.insets = new Insets(5, 5, 5, 5);
            constraints.fill = GridBagConstraints.HORIZONTAL;
            configPanelLayout.setConstraints(listenerPanel, constraints);
            configPanel.add(listenerPanel);
        }
        {
            final GridBagConstraints constraints = new GridBagConstraints();
            constraints.gridx = 0;
            constraints.gridy = 2;
            constraints.insets = new Insets(5, 5, 5, 5);
            constraints.fill = GridBagConstraints.HORIZONTAL;
            configPanelLayout.setConstraints(remoteAEPanel, constraints);
            configPanel.add(remoteAEPanel);
        }
        {
            final GridBagConstraints constraints = new GridBagConstraints();
            constraints.gridx = 0;
            constraints.gridy = 3;
            constraints.insets = new Insets(5, 5, 5, 5);
            constraints.fill = GridBagConstraints.HORIZONTAL;
            configPanelLayout.setConstraints(buttonPanel, constraints);
            configPanel.add(buttonPanel);
        }
    }

    projectList.setModel(temporaryDropDownListModel);
    showProjectList(projectListModel.isEnabled());

    // Create a listener to enable/disable the project list when it is set from the server.
    // The reason for this is that the project list is set after logging into the server, which can happen asynchronously after property changes have been applied.
    // If the server was configured in the dialog and apply clicked, it might take a few seconds for the project list to be updated, and we want it to become available when this happens
    projectListEnabledListener = new DropDownListModel.EnabledListener<Boolean>() {
        @Override
        public void statusChanged(final Boolean visibility) {
            showProjectList(projectListModel.isEnabled());
        }
    };

    projectListModel.addListener(projectListEnabledListener);

    GridBagLayout layout = new GridBagLayout();
    dialog.setLayout(layout);
    Container content = dialog.getContentPane();
    content.add(configPanel);
    dialog.pack();
    dialog.setVisible(true);
    dialog.pack();
}