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.languagetool.gui.Main.java

private void createGUI() {
    loadRecentFiles();//ww  w  .  j  a  v a 2 s.  c  o  m
    frame = new JFrame("LanguageTool " + JLanguageTool.VERSION);

    setLookAndFeel();
    openAction = new OpenAction();
    saveAction = new SaveAction();
    saveAsAction = new SaveAsAction();
    checkAction = new CheckAction();
    autoCheckAction = new AutoCheckAction(true);
    showResultAction = new ShowResultAction(true);

    frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    frame.addWindowListener(new CloseListener());
    URL iconUrl = JLanguageTool.getDataBroker().getFromResourceDirAsUrl(TRAY_ICON);
    frame.setIconImage(new ImageIcon(iconUrl).getImage());

    textArea = new JTextArea();
    textArea.setLineWrap(true);
    textArea.setWrapStyleWord(true);
    textArea.addKeyListener(new ControlReturnTextCheckingListener());

    textLineNumber = new TextLineNumber(textArea, 2);
    numberedTextAreaPane = new JScrollPane(textArea);
    numberedTextAreaPane.setRowHeaderView(textLineNumber);

    resultArea = new JTextPane();
    undoRedo = new UndoRedoSupport(this.textArea, messages);
    frame.setJMenuBar(createMenuBar());

    GridBagConstraints buttonCons = new GridBagConstraints();

    JPanel insidePanel = new JPanel();
    insidePanel.setOpaque(false);
    insidePanel.setLayout(new GridBagLayout());

    buttonCons.gridx = 0;
    buttonCons.gridy = 0;
    buttonCons.anchor = GridBagConstraints.LINE_START;
    insidePanel.add(new JLabel(messages.getString("textLanguage") + " "), buttonCons);

    //create a ComboBox with flags, do not include hidden languages
    languageBox = LanguageComboBox.create(messages, EXTERNAL_LANGUAGE_SUFFIX, true, false);
    buttonCons.gridx = 1;
    buttonCons.gridy = 0;
    buttonCons.anchor = GridBagConstraints.LINE_START;
    insidePanel.add(languageBox, buttonCons);

    JCheckBox autoDetectBox = new JCheckBox(messages.getString("atd"));
    buttonCons.gridx = 2;
    buttonCons.gridy = 0;
    buttonCons.gridwidth = GridBagConstraints.REMAINDER;
    buttonCons.anchor = GridBagConstraints.LINE_START;
    insidePanel.add(autoDetectBox, buttonCons);

    buttonCons.gridx = 0;
    buttonCons.gridy = 1;
    buttonCons.gridwidth = GridBagConstraints.REMAINDER;
    buttonCons.fill = GridBagConstraints.HORIZONTAL;
    buttonCons.anchor = GridBagConstraints.LINE_END;
    buttonCons.weightx = 1.0;
    insidePanel.add(statusLabel, buttonCons);

    Container contentPane = frame.getContentPane();
    GridBagLayout gridLayout = new GridBagLayout();
    contentPane.setLayout(gridLayout);
    GridBagConstraints cons = new GridBagConstraints();

    cons.gridx = 0;
    cons.gridy = 1;
    cons.fill = GridBagConstraints.HORIZONTAL;
    cons.anchor = GridBagConstraints.FIRST_LINE_START;
    JToolBar toolbar = new JToolBar("Toolbar", JToolBar.HORIZONTAL);
    toolbar.setFloatable(false);
    contentPane.add(toolbar, cons);

    JButton openButton = new JButton(openAction);
    openButton.setHideActionText(true);
    openButton.setFocusable(false);
    toolbar.add(openButton);

    JButton saveButton = new JButton(saveAction);
    saveButton.setHideActionText(true);
    saveButton.setFocusable(false);
    toolbar.add(saveButton);

    JButton saveAsButton = new JButton(saveAsAction);
    saveAsButton.setHideActionText(true);
    saveAsButton.setFocusable(false);
    toolbar.add(saveAsButton);

    JButton spellButton = new JButton(this.checkAction);
    spellButton.setHideActionText(true);
    spellButton.setFocusable(false);
    toolbar.add(spellButton);

    JToggleButton autoSpellButton = new JToggleButton(autoCheckAction);
    autoSpellButton.setHideActionText(true);
    autoSpellButton.setFocusable(false);
    toolbar.add(autoSpellButton);

    JButton clearTextButton = new JButton(new ClearTextAction());
    clearTextButton.setHideActionText(true);
    clearTextButton.setFocusable(false);
    toolbar.add(clearTextButton);

    cons.insets = new Insets(5, 5, 5, 5);
    cons.fill = GridBagConstraints.BOTH;
    cons.weightx = 10.0f;
    cons.weighty = 10.0f;
    cons.gridx = 0;
    cons.gridy = 2;
    cons.weighty = 5.0f;
    splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, numberedTextAreaPane, new JScrollPane(resultArea));
    mainPanel.setLayout(new GridLayout(0, 1));
    contentPane.add(mainPanel, cons);
    mainPanel.add(splitPane);

    cons.fill = GridBagConstraints.HORIZONTAL;
    cons.gridx = 0;
    cons.gridy = 3;
    cons.weightx = 1.0f;
    cons.weighty = 0.0f;
    cons.insets = new Insets(4, 12, 4, 12);
    contentPane.add(insidePanel, cons);

    ltSupport = new LanguageToolSupport(this.frame, this.textArea, this.undoRedo);
    ResultAreaHelper.install(messages, ltSupport, resultArea);
    languageBox.selectLanguage(ltSupport.getLanguage());
    languageBox.setEnabled(!ltSupport.getConfig().getAutoDetect());
    autoDetectBox.setSelected(ltSupport.getConfig().getAutoDetect());
    taggerShowsDisambigLog = ltSupport.getConfig().getTaggerShowsDisambigLog();

    languageBox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                // we cannot re-use the existing LT object anymore
                frame.applyComponentOrientation(ComponentOrientation.getOrientation(Locale.getDefault()));
                Language lang = languageBox.getSelectedLanguage();
                ComponentOrientation componentOrientation = ComponentOrientation
                        .getOrientation(lang.getLocale());
                textArea.applyComponentOrientation(componentOrientation);
                resultArea.applyComponentOrientation(componentOrientation);
                ltSupport.setLanguage(lang);
            }
        }
    });
    autoDetectBox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            boolean selected = e.getStateChange() == ItemEvent.SELECTED;
            languageBox.setEnabled(!selected);
            ltSupport.getConfig().setAutoDetect(selected);
            if (selected) {
                Language detected = ltSupport.autoDetectLanguage(textArea.getText());
                languageBox.selectLanguage(detected);
            }
        }
    });
    ltSupport.addLanguageToolListener(new LanguageToolListener() {
        @Override
        public void languageToolEventOccurred(LanguageToolEvent event) {
            if (event.getType() == LanguageToolEvent.Type.CHECKING_STARTED) {
                String msg = org.languagetool.tools.Tools.i18n(messages, "checkStart");
                statusLabel.setText(msg);
                if (event.getCaller() == getFrame()) {
                    setWaitCursor();
                    checkAction.setEnabled(false);
                }
            } else if (event.getType() == LanguageToolEvent.Type.CHECKING_FINISHED) {
                if (event.getCaller() == getFrame()) {
                    checkAction.setEnabled(true);
                    unsetWaitCursor();
                }
                String msg = org.languagetool.tools.Tools.i18n(messages, "checkDone",
                        event.getSource().getMatches().size(), event.getElapsedTime());
                statusLabel.setText(msg);
            } else if (event.getType() == LanguageToolEvent.Type.LANGUAGE_CHANGED) {
                languageBox.selectLanguage(ltSupport.getLanguage());
            } else if (event.getType() == LanguageToolEvent.Type.RULE_ENABLED) {
                //this will trigger a check and the result will be updated by
                //the CHECKING_FINISHED event
            } else if (event.getType() == LanguageToolEvent.Type.RULE_DISABLED) {
                String msg = org.languagetool.tools.Tools.i18n(messages, "checkDoneNoTime",
                        event.getSource().getMatches().size());
                statusLabel.setText(msg);
            }
        }
    });
    frame.applyComponentOrientation(ComponentOrientation.getOrientation(Locale.getDefault()));
    Language lang = ltSupport.getLanguage();
    ComponentOrientation componentOrientation = ComponentOrientation.getOrientation(lang.getLocale());
    textArea.applyComponentOrientation(componentOrientation);
    resultArea.applyComponentOrientation(componentOrientation);

    ResourceBundle textLanguageMessageBundle = JLanguageTool.getMessageBundle(ltSupport.getLanguage());
    textArea.setText(textLanguageMessageBundle.getString("guiDemoText"));

    Configuration config = ltSupport.getConfig();
    if (config.getFontName() != null || config.getFontStyle() != Configuration.FONT_STYLE_INVALID
            || config.getFontSize() != Configuration.FONT_SIZE_INVALID) {
        String fontName = config.getFontName();
        if (fontName == null) {
            fontName = textArea.getFont().getFamily();
        }
        int fontSize = config.getFontSize();
        if (fontSize == Configuration.FONT_SIZE_INVALID) {
            fontSize = textArea.getFont().getSize();
        }
        Font font = new Font(fontName, config.getFontStyle(), fontSize);
        textArea.setFont(font);
    }

    frame.pack();
    frame.setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
    frame.setLocationByPlatform(true);
    splitPane.setDividerLocation(200);
    MainWindowStateBean state = localStorage.loadProperty("gui.state", MainWindowStateBean.class);
    if (state != null) {
        if (state.getBounds() != null) {
            frame.setBounds(state.getBounds());
            ResizeComponentListener.setBoundsProperty(frame, state.getBounds());
        }
        if (state.getDividerLocation() != null) {
            splitPane.setDividerLocation(state.getDividerLocation());
        }
        if (state.getState() != null) {
            frame.setExtendedState(state.getState());
        }
    }
    ResizeComponentListener.attachToWindow(frame);
    maybeStartServer();
}

From source file:org.multibit.viewsystem.swing.view.panels.ShowPreferencesPanel.java

private JPanel createLanguagePanel(int stentWidth) {
    // Language radios.
    MultiBitTitledPanel languagePanel = new MultiBitTitledPanel(
            controller.getLocaliser().getString("showPreferencesPanel.languageTitle"),
            ComponentOrientation.getOrientation(controller.getLocaliser().getLocale()));

    GridBagConstraints constraints = new GridBagConstraints();

    constraints.fill = GridBagConstraints.BOTH;
    constraints.gridx = 0;//from   w ww.  j a  v a  2s  .c  o  m
    constraints.gridy = 3;
    constraints.weightx = 0.1;
    constraints.weighty = 0.05;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    JPanel indent = MultiBitTitledPanel.getIndentPanel(1);
    languagePanel.add(indent, constraints);

    constraints.fill = GridBagConstraints.BOTH;
    constraints.gridx = 1;
    constraints.gridy = 3;
    constraints.weightx = 0.3;
    constraints.weighty = 0.3;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    JPanel stent = MultiBitTitledPanel.createStent(stentWidth);
    languagePanel.add(stent, constraints);

    constraints.fill = GridBagConstraints.BOTH;
    constraints.gridx = 2;
    constraints.gridy = 3;
    constraints.weightx = 0.05;
    constraints.weighty = 0.3;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.CENTER;
    languagePanel.add(MultiBitTitledPanel.createStent(MultiBitTitledPanel.SEPARATION_BETWEEN_NAME_VALUE_PAIRS),
            constraints);

    ButtonGroup languageUsageGroup = new ButtonGroup();
    useDefaultLocale = new JRadioButton(controller.getLocaliser().getString("showPreferencesPanel.useDefault"));
    useDefaultLocale.setOpaque(false);
    useDefaultLocale.setFont(FontSizer.INSTANCE.getAdjustedDefaultFont());

    JRadioButton useSpecific = new JRadioButton(
            controller.getLocaliser().getString("showPreferencesPanel.useSpecific"));
    useSpecific.setOpaque(false);
    useSpecific.setFont(FontSizer.INSTANCE.getAdjustedDefaultFont());

    ItemListener itemListener = new ChangeLanguageUsageListener();
    useDefaultLocale.addItemListener(itemListener);
    useSpecific.addItemListener(itemListener);
    languageUsageGroup.add(useDefaultLocale);
    languageUsageGroup.add(useSpecific);

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 1;
    constraints.gridy = 4;
    constraints.weightx = 0.2;
    constraints.weighty = 0.3;
    constraints.gridwidth = 3;
    constraints.anchor = GridBagConstraints.LINE_START;
    languagePanel.add(useDefaultLocale, constraints);

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 1;
    constraints.gridy = 5;
    constraints.weightx = 0.2;
    constraints.weighty = 0.3;
    constraints.gridwidth = 3;
    constraints.anchor = GridBagConstraints.LINE_START;
    languagePanel.add(useSpecific, constraints);

    // Language combo box.
    int numberOfLanguages = Integer
            .parseInt(controller.getLocaliser().getString("showPreferencesPanel.numberOfLanguages"));

    // Languages are added to the combo box in alphabetic order.
    languageDataSet = new TreeSet<LanguageData>();

    for (int i = 0; i < numberOfLanguages; i++) {
        String languageCode = controller.getLocaliser()
                .getString("showPreferencesPanel.languageCode." + (i + 1));
        String language = controller.getLocaliser().getString("showPreferencesPanel.language." + (i + 1));

        LanguageData languageData = new LanguageData();
        languageData.languageCode = languageCode;
        languageData.language = language;
        languageData.image = createImageIcon(languageCode);
        languageData.image.setDescription(language);
        languageDataSet.add(languageData);
    }

    Integer[] indexArray = new Integer[languageDataSet.size()];
    int index = 0;
    for (@SuppressWarnings("unused")
    LanguageData languageData : languageDataSet) {
        indexArray[index] = index;
        index++;
    }
    languageComboBox = new JComboBox(indexArray);
    languageComboBox.setFont(FontSizer.INSTANCE.getAdjustedDefaultFont());
    languageComboBox.setOpaque(false);
    LanguageComboBoxRenderer renderer = new LanguageComboBoxRenderer();

    FontMetrics fontMetrics = getFontMetrics(FontSizer.INSTANCE.getAdjustedDefaultFont());
    Dimension preferredSize = new Dimension(fontMetrics.stringWidth(A_LONG_LANGUAGE_NAME)
            + LANGUAGE_COMBO_WIDTH_DELTA + LANGUAGE_CODE_IMAGE_WIDTH,
            fontMetrics.getHeight() + COMBO_HEIGHT_DELTA);
    renderer.setPreferredSize(preferredSize);

    languageComboBox.setRenderer(renderer);

    // Get the languageCode value stored in the model.
    String userLanguageCode = controller.getModel().getUserPreference(CoreModel.USER_LANGUAGE_CODE);
    if (userLanguageCode == null || CoreModel.USER_LANGUAGE_IS_DEFAULT.equals(userLanguageCode)) {
        useDefaultLocale.setSelected(true);
        languageComboBox.setEnabled(false);
    } else {
        useSpecific.setSelected(true);
        int startingIndex = 0;
        Integer languageCodeIndex = 0;
        for (LanguageData languageData : languageDataSet) {
            if (languageData.languageCode.equals(userLanguageCode)) {
                languageCodeIndex = startingIndex;
                break;
            }
            startingIndex++;
        }
        if (languageCodeIndex != 0) {
            languageComboBox.setSelectedItem(languageCodeIndex);
            languageComboBox.setEnabled(true);
        }
    }

    // Store original value for use by submit action.
    originalUserLanguageCode = userLanguageCode;

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 3;
    constraints.gridy = 6;
    constraints.weightx = 0.8;
    constraints.weighty = 0.6;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    languagePanel.add(languageComboBox, constraints);

    JPanel fill1 = new JPanel();
    fill1.setOpaque(false);
    constraints.fill = GridBagConstraints.BOTH;
    constraints.gridx = 4;
    constraints.gridy = 6;
    constraints.weightx = 20;
    constraints.weighty = 1;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_END;
    languagePanel.add(fill1, constraints);

    return languagePanel;
}

From source file:org.multibit.viewsystem.swing.view.panels.ShowPreferencesPanel.java

/**
 * Create the messaging server panel which consists of MultiBit style header
 * and our Netbean visual editor designed panel
 * @param stentWidth//from  w  w w . j a  va  2 s.  c  o  m
 * @return 
 */
private JPanel createMessagingServerPanel(int stentWidth) {

    MultiBitTitledPanel panel = new MultiBitTitledPanel("Messaging Servers",
            ComponentOrientation.getOrientation(controller.getLocaliser().getLocale()));

    // Create layout like other panels
    GridBagConstraints constraints = new GridBagConstraints();

    constraints.fill = GridBagConstraints.BOTH;
    constraints.gridx = 0;
    constraints.gridy = 3;
    constraints.weightx = 0.1;
    constraints.weighty = 0.3;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    JPanel indent = MultiBitTitledPanel.getIndentPanel(1);
    panel.add(indent, constraints);

    constraints.fill = GridBagConstraints.BOTH;
    constraints.gridx = 1;
    constraints.gridy = 4;
    constraints.weightx = 0.3;
    constraints.weighty = 0.3;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    JPanel stent = MultiBitTitledPanel.createStent(stentWidth);
    panel.add(stent, constraints);

    constraints.fill = GridBagConstraints.BOTH;
    constraints.gridx = 2;
    constraints.gridy = 3;
    constraints.weightx = 0.05;
    constraints.weighty = 0.3;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.CENTER;
    panel.add(MultiBitTitledPanel.createStent(MultiBitTitledPanel.SEPARATION_BETWEEN_NAME_VALUE_PAIRS),
            constraints);

    // Now insert our custom panel

    messagingServerPanel = new CSMessagingServerPanel();
    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 1;
    constraints.gridy = 5;
    constraints.weightx = 1;
    constraints.weighty = 1;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    panel.add(messagingServerPanel, constraints);

    // fill up right side
    JPanel fill1 = new JPanel();
    fill1.setOpaque(false);
    constraints.fill = GridBagConstraints.BOTH;
    constraints.gridx = 4;
    constraints.gridy = 10;
    constraints.weightx = 20;
    constraints.weighty = 1;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_END;
    panel.add(fill1, constraints);

    return panel;
}

From source file:org.multibit.viewsystem.swing.view.panels.ShowPreferencesPanel.java

private JPanel createAppearancePanel(int stentWidth) {
    MultiBitTitledPanel appearancePanel = new MultiBitTitledPanel(
            controller.getLocaliser().getString("showPreferencesPanel.appearanceTitle"),
            ComponentOrientation.getOrientation(controller.getLocaliser().getLocale()));

    GridBagConstraints constraints = new GridBagConstraints();

    constraints.fill = GridBagConstraints.BOTH;
    constraints.gridx = 0;/*w  w w  . java2  s.c  o  m*/
    constraints.gridy = 3;
    constraints.weightx = 0.1;
    constraints.weighty = 0.3;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    JPanel indent = MultiBitTitledPanel.getIndentPanel(1);
    appearancePanel.add(indent, constraints);

    constraints.fill = GridBagConstraints.BOTH;
    constraints.gridx = 1;
    constraints.gridy = 4;
    constraints.weightx = 0.3;
    constraints.weighty = 0.3;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    JPanel stent = MultiBitTitledPanel.createStent(stentWidth);
    appearancePanel.add(stent, constraints);

    constraints.fill = GridBagConstraints.BOTH;
    constraints.gridx = 2;
    constraints.gridy = 3;
    constraints.weightx = 0.05;
    constraints.weighty = 0.3;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.CENTER;
    appearancePanel.add(
            MultiBitTitledPanel.createStent(MultiBitTitledPanel.SEPARATION_BETWEEN_NAME_VALUE_PAIRS),
            constraints);

    MultiBitLabel fontNameLabel = new MultiBitLabel(
            controller.getLocaliser().getString("fontChooser.fontName"));
    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 1;
    constraints.gridy = 4;
    constraints.weightx = 0.3;
    constraints.weighty = 1;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_END;
    appearancePanel.add(fontNameLabel, constraints);

    fontNameTextLabel = new MultiBitLabel("");
    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 3;
    constraints.gridy = 4;
    constraints.weightx = 0.3;
    constraints.weighty = 1;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    appearancePanel.add(fontNameTextLabel, constraints);

    MultiBitLabel fontStyleLabel = new MultiBitLabel(
            controller.getLocaliser().getString("fontChooser.fontStyle"));
    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 1;
    constraints.gridy = 5;
    constraints.weightx = 0.3;
    constraints.weighty = 1;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_END;
    appearancePanel.add(fontStyleLabel, constraints);

    fontStyleTextLabel = new MultiBitLabel("");
    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 3;
    constraints.gridy = 5;
    constraints.weightx = 0.3;
    constraints.weighty = 1;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    appearancePanel.add(fontStyleTextLabel, constraints);

    MultiBitLabel fontSizeLabel = new MultiBitLabel(
            controller.getLocaliser().getString("fontChooser.fontSize"));
    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 1;
    constraints.gridy = 6;
    constraints.weightx = 0.3;
    constraints.weighty = 1;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_END;
    appearancePanel.add(fontSizeLabel, constraints);

    fontSizeTextLabel = new MultiBitLabel("");
    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 3;
    constraints.gridy = 6;
    constraints.weightx = 0.3;
    constraints.weighty = 1;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    appearancePanel.add(fontSizeTextLabel, constraints);

    ChooseFontAction chooseFontAction = new ChooseFontAction(controller, this, null);
    MultiBitButton fontChooserButton = new MultiBitButton(chooseFontAction, controller);

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 3;
    constraints.gridy = 7;
    constraints.weightx = 1;
    constraints.weighty = 1;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    appearancePanel.add(fontChooserButton, constraints);

    constraints.fill = GridBagConstraints.VERTICAL;
    constraints.gridx = 4;
    constraints.gridy = 8;
    constraints.weightx = 0.2;
    constraints.weighty = 0.3;
    constraints.gridwidth = 3;
    constraints.anchor = GridBagConstraints.LINE_START;
    appearancePanel.add(MultiBitTitledPanel.createStent(1, 30), constraints);

    MultiBitLabel lookAndFeelLabel = new MultiBitLabel(
            controller.getLocaliser().getString("showPreferencesPanel.lookAndFeel"));
    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 1;
    constraints.gridy = 9;
    constraints.weightx = 0.3;
    constraints.weighty = 1;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_END;
    appearancePanel.add(lookAndFeelLabel, constraints);

    originalLookAndFeel = controller.getModel().getUserPreference(CoreModel.LOOK_AND_FEEL);
    LookAndFeelInfo[] lookAndFeels = UIManager.getInstalledLookAndFeels();

    lookAndFeelComboBox = new JComboBox();
    lookAndFeelComboBox.addItem(localisedSystemLookAndFeelName);
    if (lookAndFeels != null) {
        for (LookAndFeelInfo info : lookAndFeels) {
            lookAndFeelComboBox.addItem(info.getName());
            if (info.getName().equalsIgnoreCase(originalLookAndFeel)) {
                lookAndFeelComboBox.setSelectedItem(info.getName());
            }
        }
    }

    if (originalLookAndFeel == null || originalLookAndFeel.equals("")
            || CoreModel.SYSTEM_LOOK_AND_FEEL.equalsIgnoreCase(originalLookAndFeel)) {
        lookAndFeelComboBox.setSelectedItem(localisedSystemLookAndFeelName);
    }

    lookAndFeelComboBox.setFont(FontSizer.INSTANCE.getAdjustedDefaultFont());
    lookAndFeelComboBox.setOpaque(false);

    FontMetrics fontMetrics = getFontMetrics(FontSizer.INSTANCE.getAdjustedDefaultFont());
    int textWidth = Math.max(fontMetrics.stringWidth("CDE/Motif"), fontMetrics.stringWidth("Windows classic"));
    Dimension preferredSize = new Dimension(textWidth + TICKER_COMBO_WIDTH_DELTA,
            fontMetrics.getHeight() + EXCHANGE_COMBO_HEIGHT_DELTA);
    lookAndFeelComboBox.setPreferredSize(preferredSize);

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 3;
    constraints.gridy = 9;
    constraints.weightx = 0.8;
    constraints.weighty = 0.6;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    appearancePanel.add(lookAndFeelComboBox, constraints);

    JPanel fill1 = new JPanel();
    fill1.setOpaque(false);
    constraints.fill = GridBagConstraints.BOTH;
    constraints.gridx = 4;
    constraints.gridy = 10;
    constraints.weightx = 20;
    constraints.weighty = 1;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_END;
    appearancePanel.add(fill1, constraints);

    return appearancePanel;
}

From source file:org.multibit.viewsystem.swing.view.panels.ShowPreferencesPanel.java

private JPanel createTickerPanel(int stentWidth) {
    // Load up the original values.
    originalShowTicker = !Boolean.FALSE.toString()
            .equals(controller.getModel().getUserPreference(ExchangeModel.TICKER_SHOW));
    originalExchange1 = controller.getModel().getUserPreference(ExchangeModel.TICKER_FIRST_ROW_EXCHANGE);
    originalCurrency1 = controller.getModel().getUserPreference(ExchangeModel.TICKER_FIRST_ROW_CURRENCY);
    // Map MtGox to Bitstamp + USD
    if (ExchangeData.MT_GOX_EXCHANGE_NAME.equalsIgnoreCase(originalExchange1)) {
        originalExchange1 = ExchangeData.BITSTAMP_EXCHANGE_NAME;
        controller.getModel().setUserPreference(ExchangeModel.TICKER_FIRST_ROW_EXCHANGE,
                ExchangeData.BITSTAMP_EXCHANGE_NAME);

        originalCurrency1 = "USD";
        controller.getModel().setUserPreference(ExchangeModel.TICKER_FIRST_ROW_CURRENCY, "USD");
    }//  w  w  w  .j  ava2  s . c  o  m
    originalShowSecondRow = Boolean.TRUE.toString()
            .equals(controller.getModel().getUserPreference(ExchangeModel.TICKER_SHOW_SECOND_ROW));
    originalExchange2 = controller.getModel().getUserPreference(ExchangeModel.TICKER_SECOND_ROW_EXCHANGE);
    originalCurrency2 = controller.getModel().getUserPreference(ExchangeModel.TICKER_SECOND_ROW_CURRENCY);
    // Map MtGox to Bitstamp
    if (ExchangeData.MT_GOX_EXCHANGE_NAME.equalsIgnoreCase(originalExchange2)) {
        originalExchange2 = ExchangeData.BITSTAMP_EXCHANGE_NAME;
        controller.getModel().setUserPreference(ExchangeModel.TICKER_SECOND_ROW_EXCHANGE,
                ExchangeData.BITSTAMP_EXCHANGE_NAME);

        originalCurrency2 = "USD";
        controller.getModel().setUserPreference(ExchangeModel.TICKER_SECOND_ROW_CURRENCY, "USD");
    }

    MultiBitTitledPanel tickerPanel = new MultiBitTitledPanel(
            controller.getLocaliser().getString("showPreferencesPanel.ticker.title2"),
            ComponentOrientation.getOrientation(controller.getLocaliser().getLocale()));
    GridBagConstraints constraints = new GridBagConstraints();

    constraints.fill = GridBagConstraints.BOTH;
    constraints.gridx = 3;
    constraints.gridy = 3;
    constraints.weightx = 0.05;
    constraints.weighty = 0.3;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.CENTER;
    tickerPanel.add(MultiBitTitledPanel.createStent(MultiBitTitledPanel.SEPARATION_BETWEEN_NAME_VALUE_PAIRS),
            constraints);

    String showTickerText = controller.getLocaliser().getString("multiBitFrame.ticker.show.text");
    if (showTickerText != null && showTickerText.length() >= 1) {
        // Capitalise text (this is to save adding a new I18n term.
        showTickerText = Character.toUpperCase(showTickerText.charAt(0))
                + showTickerText.toLowerCase().substring(1);
    }
    showTicker = new JCheckBox(showTickerText);
    showTicker.setOpaque(false);
    showTicker.setFont(FontSizer.INSTANCE.getAdjustedDefaultFont());
    showTicker.setSelected(originalShowTicker);

    exchangeInformationLabel = new MultiBitLabel(
            controller.getLocaliser().getString("showPreferencesPanel.ticker.exchangeInformation"));
    exchangeInformationLabel.setVisible(originalShowBitcoinConvertedToFiat);

    showBitcoinConvertedToFiat = new JCheckBox(
            controller.getLocaliser().getString("showPreferencesPanel.ticker.showBitcoinConvertedToFiat"));
    showBitcoinConvertedToFiat.setOpaque(false);
    showBitcoinConvertedToFiat.setFont(FontSizer.INSTANCE.getAdjustedDefaultFont());
    showBitcoinConvertedToFiat.setSelected(originalShowBitcoinConvertedToFiat);

    showBitcoinConvertedToFiat.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            boolean selectedChange = (e.getStateChange() == ItemEvent.SELECTED);
            boolean unSelectedChange = (e.getStateChange() == ItemEvent.DESELECTED);
            if (exchangeInformationLabel != null) {
                if (selectedChange) {
                    exchangeInformationLabel.setVisible(true);
                }
                if (unSelectedChange) {
                    exchangeInformationLabel.setVisible(false);
                }
            }
        }
    });

    showExchange = new JCheckBox(controller.getLocaliser().getString("tickerTableModel.exchange"));
    showExchange.setOpaque(false);
    showExchange.setFont(FontSizer.INSTANCE.getAdjustedDefaultFont());

    showCurrency = new JCheckBox(controller.getLocaliser().getString("tickerTableModel.currency"));
    showCurrency.setOpaque(false);
    showCurrency.setFont(FontSizer.INSTANCE.getAdjustedDefaultFont());

    showLastPrice = new JCheckBox(controller.getLocaliser().getString("tickerTableModel.lastPrice"));
    showLastPrice.setOpaque(false);
    showLastPrice.setFont(FontSizer.INSTANCE.getAdjustedDefaultFont());

    showBid = new JCheckBox(controller.getLocaliser().getString("tickerTableModel.bid"));
    showBid.setOpaque(false);
    showBid.setFont(FontSizer.INSTANCE.getAdjustedDefaultFont());

    showAsk = new JCheckBox(controller.getLocaliser().getString("tickerTableModel.ask"));
    showAsk.setOpaque(false);
    showAsk.setFont(FontSizer.INSTANCE.getAdjustedDefaultFont());

    String tickerColumnsToShow = controller.getModel().getUserPreference(ExchangeModel.TICKER_COLUMNS_TO_SHOW);
    if (tickerColumnsToShow == null || tickerColumnsToShow.equals("")) {
        tickerColumnsToShow = TickerTableModel.DEFAULT_COLUMNS_TO_SHOW;
    }

    originalShowCurrency = tickerColumnsToShow.contains(TickerTableModel.TICKER_COLUMN_CURRENCY);
    showCurrency.setSelected(originalShowCurrency);

    originalShowRate = tickerColumnsToShow.contains(TickerTableModel.TICKER_COLUMN_LAST_PRICE);
    showLastPrice.setSelected(originalShowRate);

    originalShowBid = tickerColumnsToShow.contains(TickerTableModel.TICKER_COLUMN_BID);
    showBid.setSelected(originalShowBid);

    originalShowAsk = tickerColumnsToShow.contains(TickerTableModel.TICKER_COLUMN_ASK);
    showAsk.setSelected(originalShowAsk);

    originalShowExchange = tickerColumnsToShow.contains(TickerTableModel.TICKER_COLUMN_EXCHANGE);
    showExchange.setSelected(originalShowExchange);

    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.gridx = 1;
    constraints.gridy = 4;
    constraints.weightx = 0.2;
    constraints.weighty = 0.3;
    constraints.gridwidth = 4;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(showTicker, constraints);

    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.gridx = 1;
    constraints.gridy = 5;
    constraints.weightx = 0.2;
    constraints.weighty = 0.3;
    constraints.gridwidth = 4;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(showBitcoinConvertedToFiat, constraints);

    constraints.fill = GridBagConstraints.VERTICAL;
    constraints.gridx = 0;
    constraints.gridy = 6;
    constraints.weightx = 0.2;
    constraints.weighty = 0.3;
    constraints.gridwidth = 3;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(MultiBitTitledPanel.createStent(1, 12), constraints);

    MultiBitTitledPanel.addLeftJustifiedTextAtIndent(
            controller.getLocaliser().getString("showPreferencesPanel.ticker.columnsToShow"), 7, tickerPanel);

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 1;
    constraints.gridy = 8;
    constraints.weightx = 0.2;
    constraints.weighty = 0.3;
    constraints.gridwidth = 3;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(showExchange, constraints);

    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.gridx = 1;
    constraints.gridy = 9;
    constraints.weightx = 0.2;
    constraints.weighty = 0.3;
    constraints.gridwidth = 3;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(showCurrency, constraints);

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 1;
    constraints.gridy = 10;
    constraints.weightx = 0.2;
    constraints.weighty = 0.3;
    constraints.gridwidth = 3;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(showLastPrice, constraints);

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 1;
    constraints.gridy = 11;
    constraints.weightx = 0.2;
    constraints.weighty = 0.3;
    constraints.gridwidth = 3;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(showBid, constraints);

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 1;
    constraints.gridy = 12;
    constraints.weightx = 0.2;
    constraints.weighty = 0.3;
    constraints.gridwidth = 3;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(showAsk, constraints);

    constraints.fill = GridBagConstraints.VERTICAL;
    constraints.gridx = 1;
    constraints.gridy = 13;
    constraints.weightx = 0.3;
    constraints.weighty = 0.3;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(MultiBitTitledPanel.createStent(1, 13), constraints);

    MultiBitTitledPanel.addLeftJustifiedTextAtIndent(
            controller.getLocaliser().getString("showPreferencesPanel.ticker.firstRow"), 14, tickerPanel);

    MultiBitLabel exchangeLabel1 = new MultiBitLabel(
            controller.getLocaliser().getString("showPreferencesPanel.ticker.exchange"));
    exchangeLabel1.setHorizontalAlignment(JLabel.TRAILING);
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.gridx = 1;
    constraints.gridy = 15;
    constraints.weightx = 0.3;
    constraints.weighty = 1;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_END;
    tickerPanel.add(exchangeLabel1, constraints);

    String exchangeToUse1;
    if (originalExchange1 == null | "".equals(originalExchange1)) {
        exchangeToUse1 = ExchangeData.DEFAULT_EXCHANGE;
    } else {
        exchangeToUse1 = originalExchange1;
    }

    String exchangeToUse2;
    if (originalExchange2 == null | "".equals(originalExchange2)) {
        exchangeToUse2 = ExchangeData.DEFAULT_EXCHANGE;
    } else {
        exchangeToUse2 = originalExchange2;
    }

    exchangeComboBox1 = new JComboBox(ExchangeData.getAvailableExchanges());
    exchangeComboBox1.setSelectedItem(exchangeToUse1);

    exchangeComboBox1.setFont(FontSizer.INSTANCE.getAdjustedDefaultFont());
    exchangeComboBox1.setOpaque(false);

    FontMetrics fontMetrics = getFontMetrics(FontSizer.INSTANCE.getAdjustedDefaultFont());
    int textWidth = Math.max(fontMetrics.stringWidth(ExchangeData.OPEN_EXCHANGE_RATES_EXCHANGE_NAME),
            fontMetrics.stringWidth("USD")) + COMBO_WIDTH_DELTA;
    Dimension preferredSize = new Dimension(textWidth + TICKER_COMBO_WIDTH_DELTA,
            fontMetrics.getHeight() + EXCHANGE_COMBO_HEIGHT_DELTA);
    exchangeComboBox1.setPreferredSize(preferredSize);

    constraints.fill = GridBagConstraints.BOTH;
    constraints.gridx = 1;
    constraints.gridy = 15;
    constraints.weightx = 0.3;
    constraints.weighty = 0.3;
    constraints.gridwidth = 2;
    constraints.anchor = GridBagConstraints.LINE_START;
    JPanel stent = MultiBitTitledPanel.createStent(stentWidth);
    tickerPanel.add(stent, constraints);

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 4;
    constraints.gridy = 15;
    constraints.weightx = 0.8;
    constraints.weighty = 0.6;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(exchangeComboBox1, constraints);

    oerMessageLabel1 = new MultiBitLabel(
            "    " + controller.getLocaliser().getString("showPreferencesPanel.getAppId.label"));
    oerMessageLabel1.setForeground(Color.GREEN.darker().darker());
    boolean showMessageLabel1 = isBrowserSupported()
            && ExchangeData.OPEN_EXCHANGE_RATES_EXCHANGE_NAME.equalsIgnoreCase(exchangeToUse1)
            && (originalOERApiCode == null || originalOERApiCode.trim().length() == 0);
    oerMessageLabel1.setVisible(showMessageLabel1);
    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 5;
    constraints.gridy = 15;
    constraints.weightx = 0.8;
    constraints.weighty = 0.6;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(oerMessageLabel1, constraints);

    MultiBitLabel currencyLabel1 = new MultiBitLabel(
            controller.getLocaliser().getString("showPreferencesPanel.ticker.currency"));
    currencyLabel1.setHorizontalAlignment(JLabel.TRAILING);
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.gridx = 1;
    constraints.gridy = 16;
    constraints.weightx = 0.3;
    constraints.weighty = 1;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_END;
    tickerPanel.add(currencyLabel1, constraints);

    // Make sure the exchange1 has been created and initialised the list of
    // currencies.
    if (mainFrame != null && mainFrame.getTickerTimerTask1() != null) {
        TickerTimerTask tickerTimerTask = mainFrame.getTickerTimerTask1();
        synchronized (tickerTimerTask) {
            if (tickerTimerTask.getExchange() == null) {
                tickerTimerTask.createExchangeObjects(exchangeToUse1);
            }
        }
    }

    currencyComboBox1 = new JComboBox();
    Collection<String> currenciesToUse = ExchangeData.getAvailableCurrenciesForExchange(exchangeToUse1);
    if (currenciesToUse != null) {
        for (String currency : currenciesToUse) {
            String item = currency;
            String description = CurrencyConverter.INSTANCE.getCurrencyCodeToDescriptionMap().get(currency);
            if (description != null && description.trim().length() > 0) {
                item = item + " (" + description + ")";
            }
            currencyComboBox1.addItem(item);
            if (currency.equals(originalCurrency1)) {
                currencyComboBox1.setSelectedItem(item);
            }
        }
    }

    currencyComboBox1.setFont(FontSizer.INSTANCE.getAdjustedDefaultFont());
    currencyComboBox1.setOpaque(false);
    currencyComboBox1.setPreferredSize(preferredSize);

    exchangeComboBox1.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent event) {
            if (event.getStateChange() == ItemEvent.SELECTED) {
                Object item = event.getItem();
                String exchangeShortName = item.toString();
                // Make sure the exchange1 has been created and initialised
                // the list of currencies.
                if (mainFrame != null && mainFrame.getTickerTimerTask1() != null) {
                    TickerTimerTask tickerTimerTask = mainFrame.getTickerTimerTask1();
                    synchronized (tickerTimerTask) {
                        tickerTimerTask.createExchangeObjects(exchangeShortName);
                        currencyComboBox1.removeAllItems();
                        Collection<String> currenciesToUse = ExchangeData
                                .getAvailableCurrenciesForExchange(exchangeShortName);
                        if (currenciesToUse != null) {
                            for (String currency : currenciesToUse) {
                                String loopItem = currency;
                                String description = CurrencyConverter.INSTANCE
                                        .getCurrencyCodeToDescriptionMap().get(currency);
                                if (description != null && description.trim().length() > 0) {
                                    loopItem = loopItem + " (" + description + ")";
                                }
                                currencyComboBox1.addItem(loopItem);
                            }
                        }
                    }
                }

                // Enable the OpenExchangeRates App ID if required.
                boolean showOER = ExchangeData.OPEN_EXCHANGE_RATES_EXCHANGE_NAME
                        .equalsIgnoreCase(exchangeShortName)
                        || ExchangeData.OPEN_EXCHANGE_RATES_EXCHANGE_NAME
                                .equalsIgnoreCase((String) exchangeComboBox2.getSelectedItem());
                oerStent.setVisible(showOER);
                oerApiCodeLabel.setVisible(showOER);
                oerApiCodeTextField.setVisible(showOER);
                getOerAppIdButton.setVisible(showOER);

                boolean showMessageLabel = isBrowserSupported()
                        && ExchangeData.OPEN_EXCHANGE_RATES_EXCHANGE_NAME.equalsIgnoreCase(exchangeShortName)
                        && (oerApiCodeTextField.getText() == null
                                || oerApiCodeTextField.getText().trim().length() == 0);
                oerMessageLabel1.setVisible(showMessageLabel);
            }
        }
    });

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 4;
    constraints.gridy = 16;
    constraints.weightx = 0.8;
    constraints.weighty = 0.6;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(currencyComboBox1, constraints);

    constraints.fill = GridBagConstraints.BOTH;
    constraints.gridx = 1;
    constraints.gridy = 17;
    constraints.weightx = 0.3;
    constraints.weighty = 0.3;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(MultiBitTitledPanel.createStent(12, 12), constraints);

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 4;
    constraints.gridy = 18;
    constraints.weightx = 0.8;
    constraints.weighty = 0.6;
    constraints.gridwidth = 2;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(MultiBitTitledPanel.createStent(fontMetrics.stringWidth(exchangeInformationLabel.getText()),
            fontMetrics.getHeight()), constraints);
    tickerPanel.add(exchangeInformationLabel, constraints);

    constraints.fill = GridBagConstraints.BOTH;
    constraints.gridx = 1;
    constraints.gridy = 19;
    constraints.weightx = 0.3;
    constraints.weighty = 0.3;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(MultiBitTitledPanel.createStent(12, 12), constraints);

    MultiBitTitledPanel.addLeftJustifiedTextAtIndent(
            controller.getLocaliser().getString("showPreferencesPanel.ticker.secondRow"), 20, tickerPanel);

    showSecondRowCheckBox = new JCheckBox(
            controller.getLocaliser().getString("showPreferencesPanel.ticker.showSecondRow"));
    showSecondRowCheckBox.setOpaque(false);
    showSecondRowCheckBox.setFont(FontSizer.INSTANCE.getAdjustedDefaultFont());
    showSecondRowCheckBox.addItemListener(new ChangeTickerShowSecondRowListener());

    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.gridx = 1;
    constraints.gridy = 21;
    constraints.weightx = 0.3;
    constraints.weighty = 1;
    constraints.gridwidth = 3;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(showSecondRowCheckBox, constraints);

    exchangeLabel2 = new MultiBitLabel(
            controller.getLocaliser().getString("showPreferencesPanel.ticker.exchange"));
    exchangeLabel2.setHorizontalAlignment(JLabel.TRAILING);
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.gridx = 1;
    constraints.gridy = 22;
    constraints.weightx = 0.3;
    constraints.weighty = 1;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_END;
    tickerPanel.add(exchangeLabel2, constraints);

    exchangeComboBox2 = new JComboBox(ExchangeData.getAvailableExchanges());
    exchangeComboBox2.setSelectedItem(exchangeToUse2);

    exchangeComboBox2.setFont(FontSizer.INSTANCE.getAdjustedDefaultFont());
    exchangeComboBox2.setOpaque(false);
    exchangeComboBox2.setPreferredSize(preferredSize);

    exchangeComboBox2.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent event) {
            if (event.getStateChange() == ItemEvent.SELECTED) {
                Object item = event.getItem();
                String exchangeShortName = item.toString();
                // Make sure the exchange2 has been created and initialised
                // the list of currencies.
                if (mainFrame != null && mainFrame.getTickerTimerTask2() != null) {
                    TickerTimerTask tickerTimerTask = mainFrame.getTickerTimerTask2();
                    synchronized (tickerTimerTask) {
                        tickerTimerTask.createExchangeObjects(exchangeShortName);
                        currencyComboBox2.removeAllItems();
                        Collection<String> currenciesToUse = ExchangeData
                                .getAvailableCurrenciesForExchange(exchangeShortName);
                        if (currenciesToUse != null) {
                            for (String currency : currenciesToUse) {
                                String loopItem = currency;
                                String description = CurrencyConverter.INSTANCE
                                        .getCurrencyCodeToDescriptionMap().get(currency);
                                if (description != null && description.trim().length() > 0) {
                                    loopItem = loopItem + " (" + description + ")";
                                }
                                currencyComboBox2.addItem(loopItem);
                            }
                        }
                    }
                }

                // Enable the OpenExchangeRates App ID if required.
                boolean showOER = ExchangeData.OPEN_EXCHANGE_RATES_EXCHANGE_NAME
                        .equalsIgnoreCase(exchangeShortName)
                        || ExchangeData.OPEN_EXCHANGE_RATES_EXCHANGE_NAME
                                .equalsIgnoreCase((String) exchangeComboBox1.getSelectedItem());
                oerStent.setVisible(showOER);
                oerApiCodeLabel.setVisible(showOER);
                oerApiCodeTextField.setVisible(showOER);
                getOerAppIdButton.setVisible(showOER);

                boolean showMessageLabel = isBrowserSupported()
                        && ExchangeData.OPEN_EXCHANGE_RATES_EXCHANGE_NAME.equalsIgnoreCase(exchangeShortName)
                        && (oerApiCodeTextField.getText() == null
                                || oerApiCodeTextField.getText().trim().length() == 0);
                oerMessageLabel2.setVisible(showMessageLabel);
            }
        }
    });

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 4;
    constraints.gridy = 22;
    constraints.weightx = 0.8;
    constraints.weighty = 0.6;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(exchangeComboBox2, constraints);

    oerMessageLabel2 = new MultiBitLabel(
            "    " + controller.getLocaliser().getString("showPreferencesPanel.getAppId.label"));
    oerMessageLabel2.setForeground(Color.GREEN.darker().darker());
    boolean showMessageLabel2 = isBrowserSupported()
            && ExchangeData.OPEN_EXCHANGE_RATES_EXCHANGE_NAME.equalsIgnoreCase(exchangeToUse2)
            && (originalOERApiCode == null || originalOERApiCode.trim().length() == 0);
    oerMessageLabel2.setVisible(showMessageLabel2);
    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 5;
    constraints.gridy = 22;
    constraints.weightx = 0.8;
    constraints.weighty = 0.6;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(oerMessageLabel2, constraints);

    currencyLabel2 = new MultiBitLabel(
            controller.getLocaliser().getString("showPreferencesPanel.ticker.currency"));
    currencyLabel2.setHorizontalAlignment(JLabel.TRAILING);
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.gridx = 1;
    constraints.gridy = 23;
    constraints.weightx = 0.3;
    constraints.weighty = 1;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_END;
    tickerPanel.add(currencyLabel2, constraints);

    // Make sure the exchange2 has been created and initialised the list of
    // currencies.
    if (mainFrame != null && mainFrame.getTickerTimerTask2() != null) {
        TickerTimerTask tickerTimerTask = mainFrame.getTickerTimerTask2();
        synchronized (tickerTimerTask) {
            if (tickerTimerTask.getExchange() == null) {
                tickerTimerTask.createExchangeObjects(exchangeToUse2);
            }
        }
    }
    currencyComboBox2 = new JComboBox();
    currenciesToUse = ExchangeData.getAvailableCurrenciesForExchange(exchangeToUse2);
    if (currenciesToUse != null) {
        for (String currency : currenciesToUse) {
            String loopItem = currency;
            String description = CurrencyConverter.INSTANCE.getCurrencyCodeToDescriptionMap().get(currency);
            if (description != null && description.trim().length() > 0) {
                loopItem = loopItem + " (" + description + ")";
            }
            currencyComboBox2.addItem(loopItem);
            if (currency.equals(originalCurrency2)) {
                currencyComboBox2.setSelectedItem(loopItem);
            }
        }
    }

    currencyComboBox2.setFont(FontSizer.INSTANCE.getAdjustedDefaultFont());
    currencyComboBox2.setOpaque(false);
    currencyComboBox2.setPreferredSize(preferredSize);

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 4;
    constraints.gridy = 23;
    constraints.weightx = 0.8;
    constraints.weighty = 0.6;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(currencyComboBox2, constraints);

    showSecondRowCheckBox.setSelected(originalShowSecondRow);
    enableTickerSecondRow(originalShowSecondRow);

    constraints.fill = GridBagConstraints.BOTH;
    constraints.gridx = 1;
    constraints.gridy = 24;
    constraints.weightx = 0.3;
    constraints.weighty = 0.3;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(MultiBitTitledPanel.createStent(12, 12), constraints);

    JPanel fill1 = new JPanel();
    fill1.setOpaque(false);
    constraints.fill = GridBagConstraints.BOTH;
    constraints.gridx = 5;
    constraints.gridy = 25;
    constraints.weightx = 20;
    constraints.weighty = 1;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_END;
    tickerPanel.add(fill1, constraints);

    boolean showOerSignup = ExchangeData.OPEN_EXCHANGE_RATES_EXCHANGE_NAME.equalsIgnoreCase(exchangeToUse1)
            || ExchangeData.OPEN_EXCHANGE_RATES_EXCHANGE_NAME.equalsIgnoreCase(exchangeToUse2);

    oerStent = MultiBitTitledPanel.createStent(12, 12);
    constraints.fill = GridBagConstraints.BOTH;
    constraints.gridx = 1;
    constraints.gridy = 26;
    constraints.weightx = 0.3;
    constraints.weighty = 0.3;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    oerStent.setVisible(showOerSignup);
    tickerPanel.add(oerStent, constraints);

    oerApiCodeLabel = new MultiBitLabel(
            controller.getLocaliser().getString("showPreferencesPanel.oerLabel.text"));
    oerApiCodeLabel.setToolTipText(HelpContentsPanel
            .createTooltipText(controller.getLocaliser().getString("showPreferencesPanel.oerLabel.tooltip")));
    oerApiCodeLabel.setVisible(showOerSignup);

    oerApiCodeTextField = new MultiBitTextField("", 25, controller);
    oerApiCodeTextField.setHorizontalAlignment(JLabel.LEADING);
    oerApiCodeTextField.setMinimumSize(new Dimension(API_CODE_FIELD_WIDTH, API_CODE_FIELD_HEIGHT));
    oerApiCodeTextField.setPreferredSize(new Dimension(API_CODE_FIELD_WIDTH, API_CODE_FIELD_HEIGHT));
    oerApiCodeTextField.setMaximumSize(new Dimension(API_CODE_FIELD_WIDTH, API_CODE_FIELD_HEIGHT));
    oerApiCodeTextField.setVisible(showOerSignup);
    oerApiCodeTextField.setText(originalOERApiCode);
    oerApiCodeTextField.addFocusListener(new FocusListener() {
        @Override
        public void focusGained(FocusEvent arg0) {
        }

        @Override
        public void focusLost(FocusEvent arg0) {
            String apiCode = oerApiCodeTextField.getText();
            if (apiCode != null && !(WhitespaceTrimmer.trim(apiCode).length() == 0) && !apiCode.equals(
                    controller.getModel().getUserPreference(ExchangeModel.OPEN_EXCHANGE_RATES_API_CODE))) {
                // New API code.
                // Check its length
                if (!(apiCode.trim().length() == LENGTH_OF_OPEN_EXCHANGE_RATE_APP_ID)
                        && !apiCode.equals(haveShownErrorMessageForApiCode)) {
                    haveShownErrorMessageForApiCode = apiCode;
                    // Give user a message that App ID is not in the correct format.
                    JOptionPane.showMessageDialog(null,
                            new String[] { controller
                                    .getLocaliser().getString("showPreferencesPanel.oerValidationError.text1"),
                                    " ",
                                    controller.getLocaliser()
                                            .getString("showPreferencesPanel.oerValidationError.text2"),
                                    controller.getLocaliser()
                                            .getString("showPreferencesPanel.oerValidationError.text3") },
                            controller.getLocaliser().getString(
                                    "showPreferencesPanel.oerValidationError.title"),
                            JOptionPane.ERROR_MESSAGE,
                            ImageLoader.createImageIcon(ImageLoader.EXCLAMATION_MARK_ICON_FILE));
                    return;
                }
            }
            updateApiCode();
        }
    });
    oerApiCodeTextField.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            String apiCode = oerApiCodeTextField.getText();
            if (apiCode != null && !(WhitespaceTrimmer.trim(apiCode).length() == 0) && !apiCode.equals(
                    controller.getModel().getUserPreference(ExchangeModel.OPEN_EXCHANGE_RATES_API_CODE))) {
                // New API code.
                // Check its length
                if (!(apiCode.trim().length() == LENGTH_OF_OPEN_EXCHANGE_RATE_APP_ID)
                        && !apiCode.equals(haveShownErrorMessageForApiCode)) {
                    haveShownErrorMessageForApiCode = apiCode;
                    // Give user a message that App ID is not in the correct format.
                    JOptionPane.showMessageDialog(null,
                            new String[] {
                                    controller.getLocaliser()
                                            .getString("showPreferencesPanel.oerValidationError.text1"),
                                    controller.getLocaliser()
                                            .getString("showPreferencesPanel.oerValidationError.text2"),
                                    controller.getLocaliser()
                                            .getString("showPreferencesPanel.oerValidationError.text3") },
                            controller.getLocaliser().getString(
                                    "showPreferencesPanel.oerValidationError.title"),
                            JOptionPane.ERROR_MESSAGE,
                            ImageLoader.createImageIcon(ImageLoader.EXCLAMATION_MARK_ICON_FILE));
                    return;
                }
            }
            updateApiCode();
        }
    });

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 1;
    constraints.gridy = 27;
    constraints.weightx = 0.3;
    constraints.weighty = 0.3;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_END;
    tickerPanel.add(oerApiCodeLabel, constraints);

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 4;
    constraints.gridy = 27;
    constraints.weightx = 0.3;
    constraints.weighty = 0.3;
    constraints.gridwidth = 2;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(oerApiCodeTextField, constraints);

    if (isBrowserSupported()) {
        getOerAppIdButton = new MultiBitButton(
                controller.getLocaliser().getString("showPreferencesPanel.getAppId.text"));
        getOerAppIdButton
                .setToolTipText(controller.getLocaliser().getString("showPreferencesPanel.getAppId.tooltip"));
        getOerAppIdButton.setVisible(showOerSignup);

        getOerAppIdButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {
                try {
                    openURI(new URI(OPEN_EXCHANGE_RATES_SIGN_UP_URI));
                } catch (URISyntaxException e) {
                    log.debug(e.getMessage());
                }
            }
        });

        constraints.fill = GridBagConstraints.NONE;
        constraints.gridx = 4;
        constraints.gridy = 28;
        constraints.weightx = 1;
        constraints.weighty = 1;
        constraints.gridwidth = 1;
        constraints.anchor = GridBagConstraints.LINE_START;
        tickerPanel.add(getOerAppIdButton, constraints);
    }

    return tickerPanel;
}

From source file:org.multibit.viewsystem.swing.view.panels.ShowPreferencesPanel.java

private JPanel createBrowserIntegrationPanel(int stentWidth) {
    MultiBitTitledPanel browserIntegrationPanel = new MultiBitTitledPanel(
            controller.getLocaliser().getString("showPreferencesPanel.browserIntegrationTitle"),
            ComponentOrientation.getOrientation(controller.getLocaliser().getLocale()));

    GridBagConstraints constraints = new GridBagConstraints();

    MultiBitTitledPanel.addLeftJustifiedTextAtIndent(
            controller.getLocaliser().getString("showPreferencesPanel.browserIntegration.messageText"), 3,
            browserIntegrationPanel);//  w w  w.j  a  va2 s.  c om

    ButtonGroup browserIntegrationGroup = new ButtonGroup();
    ignoreAll = new JRadioButton(controller.getLocaliser().getString("showPreferencesPanel.ignoreAll"));
    ignoreAll.setOpaque(false);
    ignoreAll.setFont(FontSizer.INSTANCE.getAdjustedDefaultFont());

    fillAutomatically = new JRadioButton(
            controller.getLocaliser().getString("showPreferencesPanel.fillAutomatically"));
    fillAutomatically.setOpaque(false);
    fillAutomatically.setFont(FontSizer.INSTANCE.getAdjustedDefaultFont());

    askEveryTime = new JRadioButton(controller.getLocaliser().getString("showPreferencesPanel.askEveryTime"));
    askEveryTime.setOpaque(false);
    askEveryTime.setFont(FontSizer.INSTANCE.getAdjustedDefaultFont());

    browserIntegrationGroup.add(ignoreAll);
    browserIntegrationGroup.add(fillAutomatically);
    browserIntegrationGroup.add(askEveryTime);

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 1;
    constraints.gridy = 5;
    constraints.weightx = 0.2;
    constraints.weighty = 0.3;
    constraints.gridwidth = 3;
    constraints.anchor = GridBagConstraints.LINE_START;
    browserIntegrationPanel.add(ignoreAll, constraints);

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 1;
    constraints.gridy = 6;
    constraints.weightx = 0.2;
    constraints.weighty = 0.3;
    constraints.anchor = GridBagConstraints.LINE_START;
    browserIntegrationPanel.add(fillAutomatically, constraints);

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 1;
    constraints.gridy = 7;
    constraints.weightx = 0.2;
    constraints.weighty = 0.3;
    constraints.anchor = GridBagConstraints.LINE_START;
    browserIntegrationPanel.add(askEveryTime, constraints);

    return browserIntegrationPanel;
}

From source file:org.multibit.viewsystem.swing.view.panels.ShowPreferencesPanel.java

private JPanel createButtonPanel() {
    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new GridBagLayout());

    GridBagConstraints constraints = new GridBagConstraints();

    buttonPanel.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, SystemColor.windowBorder));
    buttonPanel.setOpaque(true);//from w  w  w . j av a  2s  .  c  o  m
    buttonPanel.setBackground(ColorAndFontConstants.MID_BACKGROUND_COLOR);
    buttonPanel.setComponentOrientation(
            ComponentOrientation.getOrientation(controller.getLocaliser().getLocale()));

    Action helpAction;
    if (ComponentOrientation.LEFT_TO_RIGHT == ComponentOrientation
            .getOrientation(controller.getLocaliser().getLocale())) {
        helpAction = new HelpContextAction(controller, ImageLoader.HELP_CONTENTS_BIG_ICON_FILE,
                "multiBitFrame.helpMenuText", "multiBitFrame.helpMenuTooltip", "multiBitFrame.helpMenuText",
                HelpContentsPanel.HELP_PREFERENCES_URL);
    } else {
        helpAction = new HelpContextAction(controller, ImageLoader.HELP_CONTENTS_BIG_RTL_ICON_FILE,
                "multiBitFrame.helpMenuText", "multiBitFrame.helpMenuTooltip", "multiBitFrame.helpMenuText",
                HelpContentsPanel.HELP_PREFERENCES_URL);
    }
    HelpButton helpButton = new HelpButton(helpAction, controller);
    helpButton.setText("");
    helpButton.setToolTipText(controller.getLocaliser().getString("multiBitFrame.helpMenuTooltip"));
    helpButton.setHorizontalAlignment(SwingConstants.LEADING);
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.gridx = 0;
    constraints.gridy = 0;
    constraints.weightx = 0.3;
    constraints.weighty = 0.1;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    buttonPanel.add(helpButton, constraints);

    ShowPreferencesSubmitAction submitAction = new ShowPreferencesSubmitAction(this.bitcoinController,
            this.exchangeController, this, ImageLoader.createImageIcon(ImageLoader.PREFERENCES_ICON_FILE),
            mainFrame);
    MultiBitButton submitButton = new MultiBitButton(submitAction, controller);
    buttonPanel.add(submitButton);

    UndoPreferencesChangesSubmitAction undoChangesAction = new UndoPreferencesChangesSubmitAction(controller,
            ImageLoader.createImageIcon(ImageLoader.UNDO_ICON_FILE));
    undoChangesButton = new MultiBitButton(undoChangesAction, controller);

    buttonPanel.add(undoChangesButton);

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 1;
    constraints.gridy = 0;
    constraints.weightx = 0.1;
    constraints.weighty = 1.0;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    buttonPanel.add(submitButton, constraints);

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 2;
    constraints.gridy = 0;
    constraints.weightx = 0.1;
    constraints.weighty = 1.0;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    buttonPanel.add(undoChangesButton, constraints);

    JPanel fill1 = new JPanel();
    fill1.setOpaque(false);
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.gridx = 2;
    constraints.gridy = 0;
    constraints.weightx = 200;
    constraints.weighty = 1;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    constraints.anchor = GridBagConstraints.LINE_END;
    buttonPanel.add(fill1, constraints);

    return buttonPanel;
}

From source file:org.openstreetmap.josm.plugins.mapillary.gui.imageinfo.ImageInfoPanel.java

private ImageInfoPanel() {
      super(I18n.tr("Image info"), "mapillary-info",
              I18n.tr("Displays detail information on the currently selected Mapillary image"), null, 150);
      DataSet.addSelectionListener(this);

      numDetectionsLabel = new JLabel();
      numDetectionsLabel.setFont(numDetectionsLabel.getFont().deriveFont(Font.PLAIN));

      showDetectionsCheck = new JCheckBox(I18n.tr("Show detections on top of image"));
      showDetectionsCheck.setSelected(MapillaryProperties.SHOW_DETECTED_SIGNS.get());
      showDetectionsCheck.addActionListener(
              action -> MapillaryProperties.SHOW_DETECTED_SIGNS.put(showDetectionsCheck.isSelected()));
      MapillaryProperties.SHOW_DETECTED_SIGNS.addListener(
              valueChange -> showDetectionsCheck.setSelected(MapillaryProperties.SHOW_DETECTED_SIGNS.get()));

      usernameLabel = new JLabel();
      usernameLabel.setFont(usernameLabel.getFont().deriveFont(Font.PLAIN));

      imgKeyValue = new SelectableLabel();

      imgLinkAction = new WebLinkAction(I18n.tr("View in browser"), null);

      copyImgKeyAction = new ClipboardAction(I18n.tr("Copy key"), null);
      MapillaryButton copyButton = new MapillaryButton(copyImgKeyAction, true);
      copyImgKeyAction.setPopupParent(copyButton);

      addMapillaryTagAction = new AddTagToPrimitiveAction(I18n.tr("Add Mapillary tag"));

      JPanel imgKey = new JPanel();
      imgKey.add(imgKeyValue);//  w  w  w  .j  ava2 s  .  c  o m
      imgKey.add(copyButton);
      JPanel imgButtons = new JPanel();
      imgButtons.add(new MapillaryButton(imgLinkAction, true));
      imgButtons.add(new MapillaryButton(addMapillaryTagAction, true));
      seqKeyValue = new SelectableLabel();

      JPanel root = new JPanel(new GridBagLayout());
      GridBagConstraints gbc = new GridBagConstraints();
      gbc.insets = new Insets(0, 5, 0, 5);

      // Left column
      gbc.gridx = 0;
      gbc.gridy = 0;
      gbc.anchor = GridBagConstraints.LINE_END;
      gbc.gridwidth = 1;
      gbc.gridheight = 2;
      root.add(new JLabel(I18n.tr("Image detections")), gbc);
      gbc.gridy += 2;
      gbc.gridheight = 1;
      root.add(new JLabel(I18n.tr("User")), gbc);
      gbc.gridy++;
      root.add(new JLabel(I18n.tr("Image actions")), gbc);
      gbc.gridy++;
      root.add(new JLabel(I18n.tr("Image key")), gbc);
      gbc.gridy++;
      root.add(new JLabel(I18n.tr("Sequence key")), gbc);

      // Right column
      gbc.weightx = 1;
      gbc.gridx++;
      gbc.gridy = 0;
      gbc.anchor = GridBagConstraints.LINE_START;
      root.add(numDetectionsLabel, gbc);
      gbc.gridy++;
      root.add(showDetectionsCheck, gbc);
      gbc.gridy++;
      root.add(usernameLabel, gbc);
      gbc.gridy++;
      root.add(imgButtons, gbc);
      gbc.gridy++;
      root.add(imgKey, gbc);
      gbc.gridy++;
      root.add(seqKeyValue, gbc);

      createLayout(root, true, null);
      selectedImageChanged(null, null);
  }

From source file:org.sonarlint.intellij.config.global.SonarQubeServerMgmtPanel.java

private JPanel createServerStatus() {
    JPanel serverStatusPanel = new JPanel(new GridBagLayout());

    JLabel serverStatusLabel = new JLabel("Local update: ");
    updateServerButton = new JButton();
    serverStatus = new JLabel();

    final HyperlinkLabel link = new HyperlinkLabel("");
    link.setIcon(AllIcons.General.Help_small);
    link.setUseIconAsLink(true);//from   w  w w  .  j  av a2 s.  c o  m
    link.addHyperlinkListener(new HyperlinkAdapter() {
        @Override
        protected void hyperlinkActivated(HyperlinkEvent e) {
            final JLabel label = new JLabel(
                    "<html>Click to fetch data from the selected SonarQube server, such as the list of projects,<br>"
                            + " rules, quality profiles, etc. This needs to be done before being able to select a project.");
            label.setBorder(HintUtil.createHintBorder());
            label.setBackground(HintUtil.INFORMATION_COLOR);
            label.setOpaque(true);
            HintManager.getInstance().showHint(label, RelativePoint.getSouthWestOf(link),
                    HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE, -1);
        }
    });

    JPanel flow1 = new JPanel(new FlowLayout(FlowLayout.LEADING));
    flow1.add(serverStatusLabel);
    flow1.add(serverStatus);

    JPanel flow2 = new JPanel(new FlowLayout(FlowLayout.LEADING));
    flow2.add(updateServerButton);
    flow2.add(link);

    serverStatusPanel.add(flow1, new GridBagConstraints(0, 0, 1, 1, 0.5, 1, GridBagConstraints.LINE_START, 0,
            new Insets(0, 0, 0, 0), 0, 0));
    serverStatusPanel.add(flow2, new GridBagConstraints(1, 0, 1, 1, 0.5, 1, GridBagConstraints.LINE_START, 0,
            new Insets(0, 0, 0, 0), 0, 0));

    updateServerButton.setAction(new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            actionUpdateServerTask(false);
        }
    });
    updateServerButton.setText("Update binding");
    updateServerButton.setToolTipText("Update local data: quality profile, settings, ...");

    JPanel alignedPanel = new JPanel(new BorderLayout());
    alignedPanel.add(serverStatusPanel, BorderLayout.NORTH);
    return alignedPanel;
}

From source file:org.tinymediamanager.ui.panels.MediaScraperConfigurationPanel.java

private JPanel createConfigPanel() {
    JPanel panel = new JPanel();
    GridBagLayout gridBagLayout = new GridBagLayout();
    gridBagLayout.columnWidths = new int[] { 0 };
    gridBagLayout.rowHeights = new int[] { 0 };
    gridBagLayout.columnWeights = new double[] { Double.MIN_VALUE };
    gridBagLayout.rowWeights = new double[] { Double.MIN_VALUE };
    panel.setLayout(gridBagLayout);//from w w w.j a  v  a2  s  . com

    GridBagConstraints constraints = new GridBagConstraints();
    constraints.gridy = 0;

    // build up the panel for being displayed in the popup
    MediaProviderConfig config = mediaProvider.getProviderInfo().getConfig();
    for (Entry<String, MediaProviderConfigObject> entry : config.getConfigObjects().entrySet()) {
        if (!entry.getValue().isVisible()) {
            continue;
        }

        constraints.anchor = GridBagConstraints.LINE_START;
        constraints.ipadx = 20;

        // label
        JLabel label = new JLabel(entry.getValue().getKeyDescription());
        constraints.gridx = 0;
        panel.add(label, constraints);

        JComponent comp;
        switch (entry.getValue().getType()) {
        case BOOL:
            // display as checkbox
            JCheckBox checkbox = new JCheckBox();
            checkbox.setSelected(entry.getValue().getValueAsBool());
            checkbox.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    dirty = true;
                }
            });
            comp = checkbox;
            break;

        case SELECT:
        case SELECT_INDEX:
            // display as combobox
            JComboBox<String> combobox = new JComboBox<>(
                    entry.getValue().getPossibleValues().toArray(new String[0]));
            combobox.setSelectedItem(entry.getValue().getValueAsString());
            combobox.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    dirty = true;
                }
            });
            comp = combobox;
            break;

        default:
            // display as text
            JTextField tf;
            if (entry.getValue().isEncrypt()) {
                tf = new JPasswordField(config.getValue(entry.getKey()));
            } else {
                tf = new JTextField(config.getValue(entry.getKey()));
            }

            tf.setPreferredSize(new Dimension(100, 24));
            tf.getDocument().addDocumentListener(new DocumentListener() {
                @Override
                public void removeUpdate(DocumentEvent e) {
                    dirty = true;
                }

                @Override
                public void insertUpdate(DocumentEvent e) {
                    dirty = true;
                }

                @Override
                public void changedUpdate(DocumentEvent e) {
                    dirty = true;
                }
            });
            comp = tf;
            break;
        }

        comp.putClientProperty(entry.getKey(), entry.getKey());
        constraints.ipadx = 0;
        constraints.gridx = 1;
        panel.add(comp, constraints);

        // add a hint if a long text has been found
        try {
            String desc = BUNDLE.getString(
                    "scraper." + mediaProvider.getProviderInfo().getId() + "." + entry.getKey() + ".desc"); //$NON-NLS-1$
            if (StringUtils.isNotBlank(desc)) {
                JLabel lblHint = new JLabel(IconManager.HINT);
                lblHint.setToolTipText(desc);
                constraints.gridx = 2;
                panel.add(lblHint, constraints);
            }
        } catch (Exception ignored) {
        }
        constraints.gridy++;
    }
    return panel;
}