Example usage for java.awt GridBagConstraints NONE

List of usage examples for java.awt GridBagConstraints NONE

Introduction

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

Prototype

int NONE

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

Click Source Link

Document

Do not resize the component.

Usage

From source file:net.sf.jabref.gui.FindUnlinkedFilesDialog.java

/**
 * Initializes the layout for the visible components in this menu. A
 * {@link GridBagLayout} is used./*from   w  w w .j a  va 2s.co m*/
 */
private void initLayout() {

    GridBagLayout gbl = new GridBagLayout();

    panelDirectory.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
            Localization.lang("Select directory")));
    panelFiles.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
            Localization.lang("Select files")));
    panelEntryTypesSelection.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
            Localization.lang("BibTeX entry creation")));

    Insets basicInsets = new Insets(6, 6, 6, 6);
    Insets smallInsets = new Insets(3, 2, 3, 1);
    Insets noInsets = new Insets(0, 0, 0, 0);

    //       x, y, w, h, wx,wy,ix,iy
    FindUnlinkedFilesDialog.addComponent(gbl, panelSearchArea, buttonScan, GridBagConstraints.HORIZONTAL,
            GridBagConstraints.EAST, noInsets, 0, 1, 1, 1, 1, 1, 40, 10);
    FindUnlinkedFilesDialog.addComponent(gbl, panelSearchArea, labelSearchingDirectoryInfo,
            GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST, noInsets, 0, 2, 1, 1, 0, 0, 0, 0);
    FindUnlinkedFilesDialog.addComponent(gbl, panelSearchArea, progressBarSearching,
            GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST, noInsets, 0, 3, 1, 1, 0, 0, 0, 0);

    FindUnlinkedFilesDialog.addComponent(gbl, panelDirectory, labelDirectoryDescription, null,
            GridBagConstraints.WEST, new Insets(6, 6, 0, 6), 0, 0, 3, 1, 0, 0, 0, 0);
    FindUnlinkedFilesDialog.addComponent(gbl, panelDirectory, textfieldDirectoryPath,
            GridBagConstraints.HORIZONTAL, null, basicInsets, 0, 1, 2, 1, 1, 1, 0, 0);
    FindUnlinkedFilesDialog.addComponent(gbl, panelDirectory, buttonBrowse, GridBagConstraints.HORIZONTAL,
            GridBagConstraints.EAST, basicInsets, 2, 1, 1, 1, 0, 0, 0, 0);
    FindUnlinkedFilesDialog.addComponent(gbl, panelDirectory, labelFileTypesDescription,
            GridBagConstraints.NONE, GridBagConstraints.WEST, new Insets(18, 6, 18, 3), 0, 3, 1, 1, 0, 0, 0, 0);
    FindUnlinkedFilesDialog.addComponent(gbl, panelDirectory, comboBoxFileTypeSelection,
            GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST, new Insets(18, 3, 18, 6), 1, 3, 1, 1, 1, 0,
            0, 0);
    FindUnlinkedFilesDialog.addComponent(gbl, panelDirectory, panelSearchArea, GridBagConstraints.HORIZONTAL,
            GridBagConstraints.EAST, new Insets(18, 6, 18, 6), 2, 3, 1, 1, 0, 0, 0, 0);

    FindUnlinkedFilesDialog.addComponent(gbl, panelFiles, labelFilesDescription, GridBagConstraints.HORIZONTAL,
            GridBagConstraints.WEST, new Insets(6, 6, 0, 6), 0, 0, 1, 1, 0, 0, 0, 0);
    FindUnlinkedFilesDialog.addComponent(gbl, panelFiles, scrollpaneTree, GridBagConstraints.BOTH,
            GridBagConstraints.CENTER, basicInsets, 0, 1, 1, 1, 1, 1, 0, 0);
    FindUnlinkedFilesDialog.addComponent(gbl, panelFiles, panelOptions, GridBagConstraints.NONE,
            GridBagConstraints.NORTHEAST, basicInsets, 1, 1, 1, 1, 0, 0, 0, 0);
    FindUnlinkedFilesDialog.addComponent(gbl, panelOptions, buttonOptionSelectAll,
            GridBagConstraints.HORIZONTAL, GridBagConstraints.NORTH, noInsets, 0, 0, 1, 1, 1, 0, 0, 0);
    FindUnlinkedFilesDialog.addComponent(gbl, panelOptions, buttonOptionUnselectAll,
            GridBagConstraints.HORIZONTAL, GridBagConstraints.NORTH, noInsets, 0, 1, 1, 1, 0, 0, 0, 0);
    FindUnlinkedFilesDialog.addComponent(gbl, panelOptions, buttonOptionExpandAll,
            GridBagConstraints.HORIZONTAL, GridBagConstraints.NORTH, new Insets(6, 0, 0, 0), 0, 2, 1, 1, 0, 0,
            0, 0);
    FindUnlinkedFilesDialog.addComponent(gbl, panelOptions, buttonOptionCollapseAll,
            GridBagConstraints.HORIZONTAL, GridBagConstraints.NORTH, noInsets, 0, 3, 1, 1, 0, 0, 0, 0);

    FindUnlinkedFilesDialog.addComponent(gbl, panelEntryTypesSelection, labelEntryTypeDescription,
            GridBagConstraints.NONE, GridBagConstraints.WEST, basicInsets, 0, 0, 1, 1, 0, 0, 0, 0);
    FindUnlinkedFilesDialog.addComponent(gbl, panelEntryTypesSelection, comboBoxEntryTypeSelection,
            GridBagConstraints.NONE, GridBagConstraints.WEST, basicInsets, 1, 0, 1, 1, 1, 0, 0, 0);
    FindUnlinkedFilesDialog.addComponent(gbl, panelEntryTypesSelection, checkboxCreateKeywords,
            GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST, basicInsets, 0, 1, 2, 1, 0, 0, 0, 0);
    FindUnlinkedFilesDialog.addComponent(gbl, panelImportArea, labelImportingInfo,
            GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER, new Insets(6, 6, 0, 6), 0, 1, 1, 1, 1, 0,
            0, 0);
    FindUnlinkedFilesDialog.addComponent(gbl, panelImportArea, progressBarImporting,
            GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER, new Insets(0, 6, 6, 6), 0, 2, 1, 1, 1, 0,
            0, 0);
    FindUnlinkedFilesDialog.addComponent(gbl, panelButtons, panelImportArea, GridBagConstraints.NONE,
            GridBagConstraints.EAST, smallInsets, 1, 0, 1, 1, 0, 0, 0, 0);

    FindUnlinkedFilesDialog.addComponent(gbl, getContentPane(), panelDirectory, GridBagConstraints.HORIZONTAL,
            GridBagConstraints.CENTER, basicInsets, 0, 0, 1, 1, 0, 0, 0, 0);
    FindUnlinkedFilesDialog.addComponent(gbl, getContentPane(), panelFiles, GridBagConstraints.BOTH,
            GridBagConstraints.NORTHWEST, new Insets(12, 6, 2, 2), 0, 1, 1, 1, 1, 1, 0, 0);
    FindUnlinkedFilesDialog.addComponent(gbl, getContentPane(), panelEntryTypesSelection,
            GridBagConstraints.HORIZONTAL, GridBagConstraints.SOUTHWEST, new Insets(12, 6, 2, 2), 0, 2, 1, 1, 0,
            0, 0, 0);
    FindUnlinkedFilesDialog.addComponent(gbl, getContentPane(), panelButtons, GridBagConstraints.HORIZONTAL,
            GridBagConstraints.CENTER, new Insets(10, 6, 10, 6), 0, 3, 1, 1, 0, 0, 0, 0);

    ButtonBarBuilder bb = new ButtonBarBuilder();
    bb.addGlue();
    bb.addButton(buttonApply);
    bb.addButton(buttonClose);
    bb.addGlue();

    bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    panelImportArea.add(bb.getPanel(), GridBagConstraints.NONE);
    pack();

}

From source file:net.java.sip.communicator.impl.gui.main.chat.ChatWritePanel.java

/**
 *
 * @param isVisible/* www.  j a  v  a  2 s  . co m*/
 */
public void setTransportSelectorBoxVisible(boolean isVisible) {
    if (isVisible) {
        if (transportSelectorBox == null) {
            createChatTransportSelectorBox();

            if (!transportSelectorBox.getMenu().isEnabled()) {
                // Show a message to the user that IM is not possible.
                chatPanel.getChatConversationPanel()
                        .appendMessageToEnd(
                                "<h5>" + StringEscapeUtils.escapeHtml4(GuiActivator.getResources()
                                        .getI18NString("service.gui.MSG_NOT_POSSIBLE")) + "</h5>",
                                ChatHtmlUtils.HTML_CONTENT_TYPE);
            } else {
                GridBagConstraints constraints = new GridBagConstraints();
                constraints.anchor = GridBagConstraints.NORTHEAST;
                constraints.fill = GridBagConstraints.NONE;
                constraints.gridx = 0;
                constraints.gridy = 0;
                constraints.weightx = 0f;
                constraints.weighty = 0f;
                constraints.gridheight = 1;
                constraints.gridwidth = 1;

                centerPanel.add(transportSelectorBox, constraints, 0);
            }
        } else {
            if (ConfigurationUtils.isHideAccountSelectionWhenPossibleEnabled()
                    && transportSelectorBox.getMenu().getItemCount() <= 1) {
                transportSelectorBox.setVisible(false);
            }
            {
                transportSelectorBox.setVisible(true);
            }
            centerPanel.repaint();
        }
    } else if (transportSelectorBox != null) {
        transportSelectorBox.setVisible(false);
        centerPanel.repaint();
    }
}

From source file:org.languagetool.gui.ConfigurationDialog.java

@NotNull
private JPanel getMotherTonguePanel(GridBagConstraints cons) {
    JPanel motherTonguePanel = new JPanel();
    if (insideOffice) {
        motherTonguePanel.setLayout(new GridBagLayout());
        GridBagConstraints cons1 = new GridBagConstraints();
        cons1.insets = new Insets(0, 0, 0, 0);
        cons1.gridx = 0;//from   w w w .j ava  2 s  .  c  o m
        cons1.gridy = 0;
        cons1.anchor = GridBagConstraints.WEST;
        cons1.fill = GridBagConstraints.NONE;
        cons1.weightx = 0.0f;
        JRadioButton[] radioButtons = new JRadioButton[2];
        ButtonGroup numParaGroup = new ButtonGroup();
        radioButtons[0] = new JRadioButton(Tools.getLabel(messages.getString("guiUseDocumentLanguage")));
        radioButtons[0].setActionCommand("DocLang");
        radioButtons[0].setSelected(true);

        radioButtons[1] = new JRadioButton(Tools.getLabel(messages.getString("guiSetLanguageTo")));
        radioButtons[1].setActionCommand("SelectLang");

        JComboBox<String> motherTongueBox = new JComboBox<>(getPossibleMotherTongues());
        if (config.getMotherTongue() != null) {
            motherTongueBox.setSelectedItem(config.getMotherTongue().getTranslatedName(messages));
        }
        motherTongueBox.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    Language motherTongue;
                    if (motherTongueBox.getSelectedItem() instanceof String) {
                        motherTongue = getLanguageForLocalizedName(
                                motherTongueBox.getSelectedItem().toString());
                    } else {
                        motherTongue = (Language) motherTongueBox.getSelectedItem();
                    }
                    config.setMotherTongue(motherTongue);
                    config.setUseDocLanguage(false);
                    radioButtons[1].setSelected(true);
                }
            }
        });

        for (int i = 0; i < 2; i++) {
            numParaGroup.add(radioButtons[i]);
        }

        if (config.getUseDocLanguage()) {
            radioButtons[0].setSelected(true);
        } else {
            radioButtons[1].setSelected(true);
        }

        radioButtons[0].addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                config.setUseDocLanguage(true);
            }
        });

        radioButtons[1].addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                config.setUseDocLanguage(false);
                Language motherTongue;
                if (motherTongueBox.getSelectedItem() instanceof String) {
                    motherTongue = getLanguageForLocalizedName(motherTongueBox.getSelectedItem().toString());
                } else {
                    motherTongue = (Language) motherTongueBox.getSelectedItem();
                }
                config.setMotherTongue(motherTongue);
            }
        });
        motherTonguePanel.add(radioButtons[0], cons1);
        cons1.gridy++;
        motherTonguePanel.add(radioButtons[1], cons1);
        cons1.gridx = 1;
        motherTonguePanel.add(motherTongueBox, cons1);
    } else {
        motherTonguePanel.add(new JLabel(messages.getString("guiMotherTongue")), cons);
        JComboBox<String> motherTongueBox = new JComboBox<>(getPossibleMotherTongues());
        if (config.getMotherTongue() != null) {
            motherTongueBox.setSelectedItem(config.getMotherTongue().getTranslatedName(messages));
        }
        motherTongueBox.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    Language motherTongue;
                    if (motherTongueBox.getSelectedItem() instanceof String) {
                        motherTongue = getLanguageForLocalizedName(
                                motherTongueBox.getSelectedItem().toString());
                    } else {
                        motherTongue = (Language) motherTongueBox.getSelectedItem();
                    }
                    config.setMotherTongue(motherTongue);
                }
            }
        });
        motherTonguePanel.add(motherTongueBox, cons);
    }
    return motherTonguePanel;
}

From source file:zsk.JFCMainClient.java

/**
 * @param pane//w  w w . ja  va2s.com
 * @param downloadDir 
 */
public void addComponentsToPane(final Container pane, String downloadDir) {
    this.panel = new JPanel();

    this.panel.setLayout(new GridBagLayout());

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.insets = new Insets(5, 5, 5, 5);
    gbc.anchor = GridBagConstraints.WEST;

    JFCMainClient.dlm = new DefaultListModel<String>();
    this.urllist = new JList<String>(JFCMainClient.dlm);
    // TODO maybe we add a button to remove added URLs from list?
    //      this.userlist.setSelectionMode( ListSelectionModel.MULTIPLE_INTERVAL_SELECTION );
    this.urllist.setFocusable(false);
    this.textarea = new JTextArea(2, 2);
    this.textarea.setEditable(true);
    this.textarea.setFocusable(false);

    JScrollPane leftscrollpane = new JScrollPane(this.urllist);
    JScrollPane rightscrollpane = new JScrollPane(this.textarea);
    this.middlepane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftscrollpane, rightscrollpane);
    this.middlepane.setOneTouchExpandable(true);
    this.middlepane.setDividerLocation(150);

    Dimension minimumSize = new Dimension(25, 25);
    leftscrollpane.setMinimumSize(minimumSize);
    rightscrollpane.setMinimumSize(minimumSize);

    this.directorybutton = new JButton("", createImageIcon("images/open.png", ""));
    gbc.gridx = 0;
    gbc.gridy = 0;
    this.directorybutton.addActionListener(this);
    this.panel.add(this.directorybutton, gbc);

    this.saveconfigcheckbox = new JCheckBox(isgerman() ? "Konfig. speichern" : "Save config");
    this.saveconfigcheckbox.setSelected(false);

    this.saveconfigcheckbox.addItemListener(this);
    this.panel.add(this.saveconfigcheckbox);

    this.saveconfigcheckbox.setEnabled(false);

    // TODO check if initial download directory exists
    // assume that at least the users homedir exists
    //if (System.getProperty("user.home").equals("/home/knoedel")) shomedir = "/home/knoedel/YouTube Downloads/";
    debugoutput("user.home: ".concat(System.getProperty("user.home")).concat("  shomedir: ".concat(shomedir)));
    debugoutput("os.name: ".concat(System.getProperty("os.name")));
    debugoutput("os.arch: ".concat(System.getProperty("os.arch")));
    debugoutput("os.version: ".concat(System.getProperty("os.version")));
    debugoutput("Locale.getDefault: ".concat(Locale.getDefault().toString()));

    gbc.gridx = 0;
    gbc.gridy = 2;
    gbc.gridwidth = 2;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.directorytextfield = new JTextField(downloadDir, 20 + (JFCMainClient.getbDEBUG() ? 48 : 0));
    //this.directorytextfield = new JTextField( shomedir, 20+(JFCMainClient.getbDEBUG()?48:0) );
    this.directorytextfield.setEnabled(false);
    this.directorytextfield.setFocusable(true);
    this.directorytextfield.addActionListener(this);
    this.panel.add(this.directorytextfield, gbc);

    JLabel dirhint = new JLabel(isgerman() ? "Speichern im Ordner:" : "Download to folder:");

    gbc.gridx = 0;
    gbc.gridy = 1;
    this.panel.add(dirhint, gbc);

    debugoutput(String.format("heigth x width: %d x %d", Toolkit.getDefaultToolkit().getScreenSize().width,
            Toolkit.getDefaultToolkit().getScreenSize().height));

    this.middlepane.setPreferredSize(new Dimension(Toolkit.getDefaultToolkit().getScreenSize().width / 3,
            Toolkit.getDefaultToolkit().getScreenSize().height / 4 + (JFCMainClient.getbDEBUG() ? 200 : 0)));

    gbc.gridx = 0;
    gbc.gridy = 3;
    gbc.fill = GridBagConstraints.BOTH;
    gbc.weighty = 2;
    gbc.weightx = 2;
    gbc.gridwidth = 2;
    this.panel.add(this.middlepane, gbc);

    // radio buttons for resolution to download
    JFCMainClient.frame.hdbutton = new JRadioButton("HD");
    JFCMainClient.frame.hdbutton.setActionCommand("hd");
    JFCMainClient.frame.hdbutton.addActionListener(this);
    JFCMainClient.frame.hdbutton.setToolTipText("1080p/720p");
    JFCMainClient.frame.stdbutton = new JRadioButton("Std");
    JFCMainClient.frame.stdbutton.setActionCommand("std");
    JFCMainClient.frame.stdbutton.addActionListener(this);
    JFCMainClient.frame.stdbutton.setToolTipText("480p/360p");
    JFCMainClient.frame.ldbutton = new JRadioButton("LD");
    JFCMainClient.frame.ldbutton.setActionCommand("ld");
    JFCMainClient.frame.ldbutton.addActionListener(this);
    JFCMainClient.frame.ldbutton.setToolTipText("< 360p");

    JFCMainClient.frame.stdbutton.setSelected(true);
    JFCMainClient.frame.hdbutton.setEnabled(true);
    JFCMainClient.frame.ldbutton.setEnabled(true);

    ButtonGroup bgroup = new ButtonGroup();
    bgroup.add(JFCMainClient.frame.hdbutton);
    bgroup.add(JFCMainClient.frame.stdbutton);
    bgroup.add(JFCMainClient.frame.ldbutton);

    JPanel radiopanel = new JPanel(new GridLayout(1, 0));
    radiopanel.add(JFCMainClient.frame.hdbutton);
    radiopanel.add(JFCMainClient.frame.stdbutton);
    radiopanel.add(JFCMainClient.frame.ldbutton);

    gbc.gridx = 1;
    gbc.gridy = 0;
    gbc.gridheight = 0;
    gbc.gridwidth = 0;
    gbc.fill = GridBagConstraints.NONE;
    gbc.anchor = GridBagConstraints.NORTHEAST;
    this.panel.add(radiopanel, gbc);

    // radio buttons for video format to download
    JFCMainClient.frame.mpgbutton = new JRadioButton("MPEG");
    JFCMainClient.frame.mpgbutton.setActionCommand("mpg");
    JFCMainClient.frame.mpgbutton.addActionListener(this);
    JFCMainClient.frame.mpgbutton.setToolTipText("Codec: H.264 MPEG-4");
    JFCMainClient.frame.webmbutton = new JRadioButton("WEBM");
    JFCMainClient.frame.webmbutton.setActionCommand("webm");
    JFCMainClient.frame.webmbutton.addActionListener(this);
    JFCMainClient.frame.webmbutton.setToolTipText("Codec: Google/On2's VP8 or Googles WebM");
    JFCMainClient.frame.flvbutton = new JRadioButton("FLV");
    JFCMainClient.frame.flvbutton.setActionCommand("flv");
    JFCMainClient.frame.flvbutton.addActionListener(this);
    JFCMainClient.frame.flvbutton.setToolTipText("Codec: Flash Video (FLV1)");

    bgroup = new ButtonGroup();
    bgroup.add(JFCMainClient.frame.mpgbutton);
    bgroup.add(JFCMainClient.frame.webmbutton);
    bgroup.add(JFCMainClient.frame.flvbutton);

    JFCMainClient.frame.mpgbutton.setSelected(true);
    JFCMainClient.frame.mpgbutton.setEnabled(true);
    JFCMainClient.frame.webmbutton.setEnabled(true);
    JFCMainClient.frame.flvbutton.setEnabled(true);

    JFCMainClient.frame.save3dcheckbox = new JCheckBox("3D");
    JFCMainClient.frame.save3dcheckbox.setToolTipText("stereoscopic video");
    JFCMainClient.frame.save3dcheckbox.setSelected(false);
    JFCMainClient.frame.save3dcheckbox.setEnabled(true);
    JFCMainClient.frame.save3dcheckbox.addItemListener(this);

    radiopanel = new JPanel(new GridLayout(1, 0));
    radiopanel.add(JFCMainClient.frame.save3dcheckbox);
    radiopanel.add(JFCMainClient.frame.mpgbutton);
    radiopanel.add(JFCMainClient.frame.webmbutton);
    radiopanel.add(JFCMainClient.frame.flvbutton);

    gbc.gridx = 1;
    gbc.gridy = 1;
    gbc.gridheight = 0;
    gbc.gridwidth = 0;
    gbc.fill = GridBagConstraints.NONE;
    gbc.anchor = GridBagConstraints.NORTHEAST;
    this.panel.add(radiopanel, gbc);

    JLabel hint = new JLabel(
            isgerman() ? "eingeben, reinkopieren, reinziehen von YT-Webadressen oder YT-Videobilder:"
                    : "Type, paste or drag'n drop a YouTube video address:");

    gbc.fill = 0;
    gbc.gridwidth = 0;
    gbc.gridheight = 1;
    gbc.weightx = 0;
    gbc.weighty = 0;
    gbc.gridx = 0;
    gbc.gridy = 4;
    gbc.anchor = GridBagConstraints.WEST;
    this.panel.add(hint, gbc);

    this.textinputfield = new JTextField(20);
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.gridx = 0;
    gbc.gridy = 5;
    gbc.gridwidth = 2;
    this.textinputfield.setEnabled(true);
    this.textinputfield.setFocusable(true);
    this.textinputfield.addActionListener(this);
    this.textinputfield.getDocument().addDocumentListener(this);
    this.panel.add(this.textinputfield, gbc);

    this.quitbutton = new JButton("", createImageIcon("images/exit.png", ""));
    gbc.gridx = 2;
    gbc.gridy = 5;
    gbc.gridwidth = 0;
    this.quitbutton.addActionListener(this);
    this.quitbutton.setActionCommand("quit");
    this.quitbutton.setToolTipText("Exit.");

    this.panel.add(this.quitbutton, gbc);

    pane.add(this.panel);
    addWindowListener(this);

    JFCMainClient.frame.setDropTarget(new DropTarget(this, this));
    JFCMainClient.frame.textarea.setTransferHandler(null); // otherwise the dropped text would be inserted

}

From source file:de.bwravencl.controllerbuddy.gui.Main.java

private Main() {
    Singleton.start(this, SINGLETON_ID);

    frame = new JFrame();
    frame.addWindowListener(new WindowAdapter() {

        @Override//from  w  w w  .  j  a v  a2 s .c o m
        public void windowClosing(final WindowEvent e) {
            super.windowClosing(e);

            if (showMenuItem != null)
                showMenuItem.setEnabled(true);
        }

        @Override
        public void windowDeiconified(final WindowEvent e) {
            super.windowDeiconified(e);

            if (showMenuItem != null)
                showMenuItem.setEnabled(false);
        }

        @Override
        public void windowIconified(final WindowEvent e) {
            super.windowIconified(e);

            if (showMenuItem != null)
                showMenuItem.setEnabled(true);
        }

        @Override
        public void windowOpened(final WindowEvent e) {
            super.windowOpened(e);

            if (showMenuItem != null)
                showMenuItem.setEnabled(false);
        }

    });

    frame.setBounds(DIALOG_BOUNDS_X, DIALOG_BOUNDS_Y, DIALOG_BOUNDS_WIDTH, DIALOG_BOUNDS_HEIGHT);
    frame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);

    final var icons = new ArrayList<Image>();
    for (final var path : ICON_RESOURCE_PATHS) {
        final var icon = new ImageIcon(Main.class.getResource(path));
        icons.add(icon.getImage());
    }
    frame.setIconImages(icons);

    frame.setJMenuBar(menuBar);

    menuBar.add(fileMenu);
    final QuitAction quitAction = new QuitAction();
    fileMenu.add(quitAction);
    menuBar.add(deviceMenu);

    if (windows) {
        menuBar.add(localMenu, 2);

        final var buttonGroupLocalState = new ButtonGroup();
        startLocalRadioButtonMenuItem = new JRadioButtonMenuItem(rb.getString("START_MENU_ITEM"));
        startLocalRadioButtonMenuItem.setAction(new StartLocalAction());
        buttonGroupLocalState.add(startLocalRadioButtonMenuItem);
        localMenu.add(startLocalRadioButtonMenuItem);

        stopLocalRadioButtonMenuItem = new JRadioButtonMenuItem(rb.getString("STOP_MENU_ITEM"));
        stopLocalRadioButtonMenuItem.setAction(new StopLocalAction());
        buttonGroupLocalState.add(stopLocalRadioButtonMenuItem);
        localMenu.add(stopLocalRadioButtonMenuItem);

        menuBar.add(clientMenu);

        final var buttonGroupClientState = new ButtonGroup();

        startClientRadioButtonMenuItem = new JRadioButtonMenuItem(rb.getString("START_MENU_ITEM"));
        startClientRadioButtonMenuItem.setAction(new StartClientAction());
        buttonGroupClientState.add(startClientRadioButtonMenuItem);
        clientMenu.add(startClientRadioButtonMenuItem);

        stopClientRadioButtonMenuItem = new JRadioButtonMenuItem(rb.getString("STOP_MENU_ITEM"));
        stopClientRadioButtonMenuItem.setAction(new StopClientAction());
        buttonGroupClientState.add(stopClientRadioButtonMenuItem);
        clientMenu.add(stopClientRadioButtonMenuItem);
    }

    final var buttonGroupServerState = new ButtonGroup();
    startServerRadioButtonMenuItem = new JRadioButtonMenuItem(rb.getString("START_MENU_ITEM"));
    startServerRadioButtonMenuItem.setAction(new StartServerAction());
    buttonGroupServerState.add(startServerRadioButtonMenuItem);
    serverMenu.add(startServerRadioButtonMenuItem);

    stopServerRadioButtonMenuItem = new JRadioButtonMenuItem(rb.getString("STOP_MENU_ITEM"));
    stopServerRadioButtonMenuItem.setAction(new StopServerAction());
    buttonGroupServerState.add(stopServerRadioButtonMenuItem);
    serverMenu.add(stopServerRadioButtonMenuItem);

    final var helpMenu = new JMenu(rb.getString("HELP_MENU"));
    menuBar.add(helpMenu);
    helpMenu.add(new ShowAboutDialogAction());

    frame.getContentPane().add(tabbedPane);

    settingsPanel = new JPanel();
    settingsPanel.setLayout(new GridBagLayout());

    settingsScrollPane.setViewportView(settingsPanel);
    tabbedPane.addTab(rb.getString("SETTINGS_TAB"), null, settingsScrollPane);

    final var panelGridBagConstraints = new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0.0, 0.0,
            GridBagConstraints.FIRST_LINE_START, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 5);

    final var panelFlowLayout = new FlowLayout(FlowLayout.LEADING, 10, 10);

    final var pollIntervalPanel = new JPanel(panelFlowLayout);
    settingsPanel.add(pollIntervalPanel, panelGridBagConstraints);

    final var pollIntervalLabel = new JLabel(rb.getString("POLL_INTERVAL_LABEL"));
    pollIntervalLabel.setPreferredSize(new Dimension(120, 15));
    pollIntervalPanel.add(pollIntervalLabel);

    final var pollIntervalSpinner = new JSpinner(new SpinnerNumberModel(
            preferences.getInt(PREFERENCES_POLL_INTERVAL, OutputThread.DEFAULT_POLL_INTERVAL), 10, 500, 1));
    final JSpinner.DefaultEditor pollIntervalSpinnerEditor = new JSpinner.NumberEditor(pollIntervalSpinner,
            "#");
    ((DefaultFormatter) pollIntervalSpinnerEditor.getTextField().getFormatter()).setCommitsOnValidEdit(true);
    pollIntervalSpinner.setEditor(pollIntervalSpinnerEditor);
    pollIntervalSpinner.addChangeListener(
            e -> preferences.putInt(PREFERENCES_POLL_INTERVAL, (int) ((JSpinner) e.getSource()).getValue()));
    pollIntervalPanel.add(pollIntervalSpinner);

    if (windows) {
        final var vJoyDirectoryPanel = new JPanel(panelFlowLayout);
        settingsPanel.add(vJoyDirectoryPanel, panelGridBagConstraints);

        final var vJoyDirectoryLabel = new JLabel(rb.getString("VJOY_DIRECTORY_LABEL"));
        vJoyDirectoryLabel.setPreferredSize(new Dimension(120, 15));
        vJoyDirectoryPanel.add(vJoyDirectoryLabel);

        vJoyDirectoryLabel1 = new JLabel(
                preferences.get(PREFERENCES_VJOY_DIRECTORY, VJoyOutputThread.getDefaultInstallationPath()));
        vJoyDirectoryPanel.add(vJoyDirectoryLabel1);

        final var vJoyDirectoryButton = new JButton(new ChangeVJoyDirectoryAction());
        vJoyDirectoryPanel.add(vJoyDirectoryButton);

        final var vJoyDevicePanel = new JPanel(panelFlowLayout);
        settingsPanel.add(vJoyDevicePanel, panelGridBagConstraints);

        final var vJoyDeviceLabel = new JLabel(rb.getString("VJOY_DEVICE_LABEL"));
        vJoyDeviceLabel.setPreferredSize(new Dimension(120, 15));
        vJoyDevicePanel.add(vJoyDeviceLabel);

        final var vJoyDeviceSpinner = new JSpinner(new SpinnerNumberModel(
                preferences.getInt(PREFERENCES_VJOY_DEVICE, VJoyOutputThread.DEFAULT_VJOY_DEVICE), 1, 16, 1));
        final JSpinner.DefaultEditor vJoyDeviceSpinnerEditor = new JSpinner.NumberEditor(vJoyDeviceSpinner,
                "#");
        ((DefaultFormatter) vJoyDeviceSpinnerEditor.getTextField().getFormatter()).setCommitsOnValidEdit(true);
        vJoyDeviceSpinner.setEditor(vJoyDeviceSpinnerEditor);
        vJoyDeviceSpinner.addChangeListener(
                e -> preferences.putInt(PREFERENCES_VJOY_DEVICE, (int) ((JSpinner) e.getSource()).getValue()));
        vJoyDevicePanel.add(vJoyDeviceSpinner);

        final var hostPanel = new JPanel(panelFlowLayout);
        settingsPanel.add(hostPanel, panelGridBagConstraints);

        final var hostLabel = new JLabel(rb.getString("HOST_LABEL"));
        hostLabel.setPreferredSize(new Dimension(120, 15));
        hostPanel.add(hostLabel);

        hostTextField = new JTextField(preferences.get(PREFERENCES_HOST, ClientVJoyOutputThread.DEFAULT_HOST),
                10);
        final var setHostAction = new SetHostAction(hostTextField);
        hostTextField.addActionListener(setHostAction);
        hostTextField.addFocusListener(setHostAction);
        hostPanel.add(hostTextField);
    }

    final var portPanel = new JPanel(panelFlowLayout);
    settingsPanel.add(portPanel, panelGridBagConstraints);

    final var portLabel = new JLabel(rb.getString("PORT_LABEL"));
    portLabel.setPreferredSize(new Dimension(120, 15));
    portPanel.add(portLabel);

    final var portSpinner = new JSpinner(new SpinnerNumberModel(
            preferences.getInt(PREFERENCES_PORT, ServerOutputThread.DEFAULT_PORT), 1024, 65535, 1));
    final JSpinner.DefaultEditor portSpinnerEditor = new JSpinner.NumberEditor(portSpinner, "#");
    ((DefaultFormatter) portSpinnerEditor.getTextField().getFormatter()).setCommitsOnValidEdit(true);
    portSpinner.setEditor(portSpinnerEditor);
    portSpinner.addChangeListener(
            e -> preferences.putInt(PREFERENCES_PORT, (int) ((JSpinner) e.getSource()).getValue()));
    portPanel.add(portSpinner);

    final var timeoutPanel = new JPanel(panelFlowLayout);
    settingsPanel.add(timeoutPanel, panelGridBagConstraints);

    final var timeoutLabel = new JLabel(rb.getString("TIMEOUT_LABEL"));
    timeoutLabel.setPreferredSize(new Dimension(120, 15));
    timeoutPanel.add(timeoutLabel);

    final var timeoutSpinner = new JSpinner(new SpinnerNumberModel(
            preferences.getInt(PREFERENCES_TIMEOUT, ServerOutputThread.DEFAULT_TIMEOUT), 10, 60000, 1));
    final JSpinner.DefaultEditor timeoutSpinnerEditor = new JSpinner.NumberEditor(timeoutSpinner, "#");
    ((DefaultFormatter) timeoutSpinnerEditor.getTextField().getFormatter()).setCommitsOnValidEdit(true);
    timeoutSpinner.setEditor(timeoutSpinnerEditor);
    timeoutSpinner.addChangeListener(
            e -> preferences.putInt(PREFERENCES_TIMEOUT, (int) ((JSpinner) e.getSource()).getValue()));
    timeoutPanel.add(timeoutSpinner);

    final var alwaysOnTopSupported = Toolkit.getDefaultToolkit().isAlwaysOnTopSupported();
    if (alwaysOnTopSupported || preferences.getBoolean(PREFERENCES_SHOW_OVERLAY, alwaysOnTopSupported)) {
        final var overlaySettingsPanel = new JPanel(panelFlowLayout);
        settingsPanel.add(overlaySettingsPanel, panelGridBagConstraints);

        final var overlayLabel = new JLabel(rb.getString("OVERLAY_LABEL"));
        overlayLabel.setPreferredSize(new Dimension(120, 15));
        overlaySettingsPanel.add(overlayLabel);

        final var showOverlayCheckBox = new JCheckBox(rb.getString("SHOW_OVERLAY_CHECK_BOX"));
        showOverlayCheckBox.setSelected(preferences.getBoolean(PREFERENCES_SHOW_OVERLAY, true));
        showOverlayCheckBox.addActionListener(e -> {
            final boolean showOverlay = ((JCheckBox) e.getSource()).isSelected();

            preferences.putBoolean(PREFERENCES_SHOW_OVERLAY, showOverlay);
        });
        overlaySettingsPanel.add(showOverlayCheckBox);
    }

    if (windows) {
        if (preferences.getBoolean(PREFERENCES_SHOW_VR_OVERLAY, true)) {
            final var vrOverlaySettingsPanel = new JPanel(panelFlowLayout);
            settingsPanel.add(vrOverlaySettingsPanel, panelGridBagConstraints);

            final var vrOverlayLabel = new JLabel(rb.getString("VR_OVERLAY_LABEL"));
            vrOverlayLabel.setPreferredSize(new Dimension(120, 15));
            vrOverlaySettingsPanel.add(vrOverlayLabel);

            final var showVrOverlayCheckBox = new JCheckBox(rb.getString("SHOW_VR_OVERLAY_CHECK_BOX"));
            showVrOverlayCheckBox.setSelected(preferences.getBoolean(PREFERENCES_SHOW_VR_OVERLAY, true));
            showVrOverlayCheckBox.addActionListener(e -> {
                final var showVrOverlay = ((JCheckBox) e.getSource()).isSelected();

                preferences.putBoolean(PREFERENCES_SHOW_VR_OVERLAY, showVrOverlay);
            });
            vrOverlaySettingsPanel.add(showVrOverlayCheckBox);
        }

        final var preventPowerSaveModeSettingsPanel = new JPanel(panelFlowLayout);
        settingsPanel.add(preventPowerSaveModeSettingsPanel, panelGridBagConstraints);

        final var preventPowerSaveModeLabel = new JLabel(rb.getString("POWER_SAVE_MODE_LABEL"));
        preventPowerSaveModeLabel.setPreferredSize(new Dimension(120, 15));
        preventPowerSaveModeSettingsPanel.add(preventPowerSaveModeLabel);

        final var preventPowerSaveModeCheckBox = new JCheckBox(
                rb.getString("PREVENT_POWER_SAVE_MODE_CHECK_BOX"));
        preventPowerSaveModeCheckBox
                .setSelected(preferences.getBoolean(PREFERENCES_PREVENT_POWER_SAVE_MODE, true));
        preventPowerSaveModeCheckBox.addActionListener(e -> {
            final var preventPowerSaveMode = ((JCheckBox) e.getSource()).isSelected();

            preferences.putBoolean(PREFERENCES_PREVENT_POWER_SAVE_MODE, preventPowerSaveMode);
        });
        preventPowerSaveModeSettingsPanel.add(preventPowerSaveModeCheckBox);
    }

    if (SystemTray.isSupported()) {
        final var popupMenu = new PopupMenu();

        final var showAction = new ShowAction();
        showMenuItem = new MenuItem((String) showAction.getValue(Action.NAME));
        showMenuItem.addActionListener(showAction);
        popupMenu.add(showMenuItem);

        popupMenu.addSeparator();

        final var openMenuItem = new MenuItem((String) openAction.getValue(Action.NAME));
        openMenuItem.addActionListener(openAction);
        popupMenu.add(openMenuItem);

        popupMenu.addSeparator();

        final var quitMenuItem = new MenuItem((String) quitAction.getValue(Action.NAME));
        quitMenuItem.addActionListener(quitAction);
        popupMenu.add(quitMenuItem);

        trayIcon = new TrayIcon(frame.getIconImage());
        trayIcon.addActionListener(showAction);
        trayIcon.setPopupMenu(popupMenu);
        try {
            SystemTray.getSystemTray().add(trayIcon);
        } catch (final AWTException e) {
            log.log(Logger.Level.ERROR, e.getMessage(), e);
        }
    }

    updateTitleAndTooltip();

    settingsPanel.add(Box.createGlue(), new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 1.0,
            GridBagConstraints.FIRST_LINE_START, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));

    final var outsideBorder = BorderFactory.createEtchedBorder(EtchedBorder.RAISED);
    final var insideBorder = BorderFactory.createEmptyBorder(0, 5, 0, 5);
    statusLabel.setBorder(BorderFactory.createCompoundBorder(outsideBorder, insideBorder));
    frame.add(statusLabel, BorderLayout.SOUTH);

    final var glfwInitialized = glfwInit();
    if (!glfwInitialized)
        if (windows)
            JOptionPane.showMessageDialog(frame, rb.getString("COULD_NOT_INITIALIZE_GLFW_DIALOG_TEXT_WINDOWS"),
                    rb.getString("ERROR_DIALOG_TITLE"), JOptionPane.ERROR_MESSAGE);
        else {
            JOptionPane.showMessageDialog(frame, rb.getString("COULD_NOT_INITIALIZE_GLFW_DIALOG_TEXT"),
                    rb.getString("ERROR_DIALOG_TITLE"), JOptionPane.ERROR_MESSAGE);
            quit();
        }

    final var presentJids = new HashSet<Integer>();
    for (var jid = GLFW_JOYSTICK_1; jid <= GLFW_JOYSTICK_LAST; jid++)
        if (glfwJoystickPresent(jid) && glfwJoystickIsGamepad(jid))
            presentJids.add(jid);

    final var lastControllerGuid = preferences.get(PREFERENCES_LAST_CONTROLLER, null);
    for (final var jid : presentJids) {
        final var lastControllerFound = lastControllerGuid != null
                ? lastControllerGuid.equals(glfwGetJoystickGUID(jid))
                : false;

        if (!isSelectedJidValid() || lastControllerFound)
            selectedJid = jid;

        if (lastControllerFound)
            break;
    }

    newProfile();

    onControllersChanged(true);

    glfwSetJoystickCallback(new GLFWJoystickCallback() {

        @Override
        public void invoke(final int jid, final int event) {
            final var disconnected = event == GLFW_DISCONNECTED;
            if (disconnected || glfwJoystickIsGamepad(jid)) {
                if (disconnected && selectedJid == jid)
                    selectedJid = INVALID_JID;

                invokeOnEventDispatchThreadIfRequired(() -> onControllersChanged(false));
            }

        }
    });

    if (glfwInitialized && presentJids.isEmpty()) {
        if (windows)
            JOptionPane.showMessageDialog(frame, rb.getString("NO_CONTROLLER_CONNECTED_DIALOG_TEXT_WINDOWS"),
                    rb.getString("INFORMATION_DIALOG_TITLE"), JOptionPane.INFORMATION_MESSAGE);
        else
            JOptionPane.showMessageDialog(frame, rb.getString("NO_CONTROLLER_CONNECTED_DIALOG_TEXT"),
                    rb.getString("INFORMATION_DIALOG_TITLE"), JOptionPane.INFORMATION_MESSAGE);
    } else {
        final String path = preferences.get(PREFERENCES_LAST_PROFILE, null);
        if (path != null)
            loadProfile(new File(path));
    }
}

From source file:org.dwfa.ace.classifier.CNFormsLabelPanel.java

/**
 * <b>Distribution Normal Form</b><li>Most Proximate Supertypes (IS-A)</li>
 *//*  ww w  .  j a  v  a  2  s  .  c om*/
public JPanel newFormDistJPanel(String label, I_ConfigAceFrame config,
        Map<I_ConceptAttributeTuple, Color> conAttrColorMap, Map<I_DescriptionTuple, Color> desColorMap,
        Map<I_RelTuple, Color> relColorMap) throws IOException {
    JPanel formJPanel = newMinMaxJPanel();
    formJPanel.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.NONE;
    c.anchor = GridBagConstraints.NORTHWEST;
    c.weightx = 0;
    c.weighty = 0;
    c.gridx = 0;
    c.gridy = 0;

    List<LabelForTuple> tLabelList = new ArrayList<LabelForTuple>();
    c.gridx = 0;
    c.gridwidth = 2;
    c.anchor = GridBagConstraints.NORTHWEST;

    // SHOW SELF CONCEPT
    I_ConceptAttributeTuple cTuple = findSelf(theCBean, cEditPathPos);
    I_ImplementActiveLabel tmpTLabel = TermLabelMaker.newLabelForm(cTuple, showDetailCB.isSelected(),
            showStatusCB.isSelected());
    tLabelList.add((LabelForTuple) tmpTLabel);
    Color tmpDeltaColor = conAttrColorMap.get(cTuple);
    setBorder(tmpTLabel.getLabel(), tmpDeltaColor);
    formJPanel.add(tmpTLabel.getLabel(), c);
    c.gridy++;

    // SHOW PROXIMAL ISAs -- as relationships
    SnoGrpList isaSGList = cSnoTable.getIsaProx();
    List<I_RelTuple> isaList = new ArrayList<I_RelTuple>();
    for (SnoGrp sg : isaSGList)
        for (SnoRel sr : sg)
            isaList.add(new RelVersion(sr.relNid));
    for (I_RelTuple rTuple : isaList) {
        tmpTLabel = TermLabelMaker.newLabelForm(rTuple, showDetailCB.isSelected(), showStatusCB.isSelected());
        tLabelList.add((LabelForTuple) tmpTLabel);
        tmpDeltaColor = relColorMap.get(rTuple);
        setBorder(tmpTLabel.getLabel(), tmpDeltaColor);
        formJPanel.add(tmpTLabel.getLabel(), c);
        c.gridy++;
    }

    // SHOW ROLES, NON-REDUNDANT, DIFFERENTIATED FROM ROOT
    SnoGrpList sgl = cSnoTable.getRoleDiffFromRootList();
    if (sgl.size() > 0) {
        int i = 0;
        SnoGrp sg = sgl.get(0);
        // show each of the non-Rels
        if (sg.size() > 0 && sg.get(0).group == 0) {
            for (SnoRel sr : sg) {
                I_RelTuple rTuple = new RelVersion(sr.relNid);
                tmpTLabel = TermLabelMaker.newLabelForm(rTuple, showDetailCB.isSelected(),
                        showStatusCB.isSelected());
                tLabelList.add((LabelForTuple) tmpTLabel);
                tmpDeltaColor = relColorMap.get(rTuple);
                setBorder(tmpTLabel.getLabel(), tmpDeltaColor);
                formJPanel.add(tmpTLabel.getLabel(), c);
                c.gridy++;
            }
            i++; // skip past 0 index of the "un-grouped"
        }

        // show each of the groups
        for (; i < sgl.size(); i++) {
            sg = sgl.get(i);
            if (sg.size() == 0)
                continue;
            if (showGroupLabels) { // true shows one label per group
                List<I_RelTuple> grpTuple = new ArrayList<I_RelTuple>();
                for (SnoRel sr : sg) {
                    grpTuple.add(new RelVersion(sr.relNid));
                }
                tmpTLabel = TermLabelMaker.newLabel(grpTuple, showDetailCB.isSelected(),
                        showStatusCB.isSelected());
                tLabelList.add((LabelForTuple) tmpTLabel);
                tmpDeltaColor = relColorMap.get(grpTuple.get(0));
                setBorder(tmpTLabel.getLabel(), tmpDeltaColor);
                formJPanel.add(tmpTLabel.getLabel(), c);
                c.gridy++;
            } else { // if false, show 1 rel per label
                for (SnoRel sr : sg) {
                    I_RelTuple rTuple = new RelVersion(sr.relNid);
                    tmpTLabel = TermLabelMaker.newLabelForm(rTuple, showDetailCB.isSelected(),
                            showStatusCB.isSelected());
                    tLabelList.add((LabelForTuple) tmpTLabel);
                    tmpDeltaColor = relColorMap.get(rTuple);
                    setBorder(tmpTLabel.getLabel(), tmpDeltaColor);
                    formJPanel.add(tmpTLabel.getLabel(), c);
                    c.gridy++;
                }
                c.gridy++;
            }
        }
    }
    c.weightx = 1.0;
    c.weighty = 1.0;
    c.gridwidth = 2;
    formJPanel.add(new JPanel(), c);
    formJPanel.setBorder(BorderFactory.createTitledBorder(label));

    return formJPanel;
}

From source file:lejos.pc.charting.LogChartFrame.java

/** All the setup of components, etc. What's scary is Swing is a "lightweight" GUI framework...
 * @throws Exception/*from   w w  w  .  j a va  2  s .  com*/
 */
private void jbInit() throws Exception {
    this.setJMenuBar(menuBar);
    this.setSize(new Dimension(819, 613));
    this.setMinimumSize(new Dimension(819, 613));
    this.setTitle("NXT Charting Logger");
    this.setEnabled(true);
    // enforce minimum window size
    this.addComponentListener(new ComponentAdapter() {
        @Override
        public void componentResized(ComponentEvent e) {
            JFrame theFrame = (JFrame) e.getSource();
            Dimension d1 = theFrame.getMinimumSize();
            Dimension d2 = theFrame.getSize();
            boolean enforce = false;
            if (theFrame.getWidth() < d1.getWidth()) {
                d2.setSize(d1.getWidth(), d2.getHeight());
                enforce = true;
            }
            if (theFrame.getHeight() < d1.getHeight()) {
                d2.setSize(d2.getWidth(), d1.getHeight());
                enforce = true;
            }
            if (enforce)
                theFrame.setSize(d2);
        }
    });

    this.getContentPane().setLayout(gridBagLayout1);
    MenuActionListener menuItemActionListener = new MenuActionListener();
    MenuEventListener menuListener = new MenuEventListener();

    menu = new JMenu("Edit");
    menu.setMnemonic(KeyEvent.VK_E);
    menuBar.add(menu);
    menuItem = new JMenuItem("Copy Chart Image", KeyEvent.VK_I);
    menuItem.addActionListener(menuItemActionListener);
    menu.add(menuItem);
    menuItem = new JMenuItem("Copy Data Log", KeyEvent.VK_D);
    menuItem.addActionListener(menuItemActionListener);
    menu.add(menuItem);

    menu = new JMenu("View");
    menu.setMnemonic(KeyEvent.VK_V);
    menu.setActionCommand("VIEW_MENU");
    menu.addMenuListener(menuListener);
    menuBar.add(menu);
    menuItem = new JMenuItem("Expand Chart", KeyEvent.VK_F);
    menuItem.addActionListener(menuItemActionListener);
    menu.add(menuItem);
    menuItem = new JMenuItem("Chart in New Window", KeyEvent.VK_N);
    menuItem.addActionListener(menuItemActionListener);
    menu.add(menuItem);

    menu = new JMenu("Help");
    menu.setMnemonic(KeyEvent.VK_H);
    menuBar.add(menu);
    menuItem = new JMenuItem("Chart controls", KeyEvent.VK_C);
    menuItem.addActionListener(menuItemActionListener);
    menu.add(menuItem);
    menuItem = new JMenuItem("Generate sample data", KeyEvent.VK_G);
    menuItem.addActionListener(menuItemActionListener);
    menu.add(menuItem);
    menuItem = new JMenuItem("About", KeyEvent.VK_A);
    menuItem.addActionListener(menuItemActionListener);
    jTabbedPane1.setPreferredSize(new Dimension(621, 199));
    jTabbedPane1.setMinimumSize(new Dimension(621, 199));
    menu.add(menuItem);

    jButtonConnect.setText("Connect");
    jButtonConnect.setBounds(new Rectangle(25, 65, 115, 25));
    jButtonConnect.setToolTipText("Connect/disconnect toggle");
    jButtonConnect.setMnemonic('C');
    jButtonConnect.setSelected(true);
    jButtonConnect.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            jButtonConnect_actionPerformed(e);
        }
    });
    UIPanel.setSize(new Dimension(820, 200));
    UIPanel.setLayout(null);
    UIPanel.setPreferredSize(new Dimension(300, 200));
    UIPanel.setMinimumSize(new Dimension(300, 200));
    UIPanel.setBounds(new Rectangle(0, 350, 820, 200));
    UIPanel.setMaximumSize(new Dimension(300, 32767));
    connectionPanel.setBounds(new Rectangle(10, 10, 175, 100));
    connectionPanel.setBorder(BorderFactory.createTitledBorder("Connection"));
    connectionPanel.setLayout(null);
    connectionPanel.setFont(new Font("Tahoma", 0, 11));

    jLabel1logfilename.setText("Log File:");
    jLabel1logfilename.setBounds(new Rectangle(10, 125, 165, 20));
    jLabel1logfilename.setHorizontalTextPosition(SwingConstants.RIGHT);
    jLabel1logfilename.setHorizontalAlignment(SwingConstants.LEFT);
    jLabel1logfilename.setToolTipText("Specify the name of your log file here");

    jTextFieldNXTName.setBounds(new Rectangle(5, 40, 165, 20));
    jTextFieldNXTName.setToolTipText(
            "The name or Address of the NXT. Leave empty and the first one found will be used.");

    jTextFieldNXTName.requestFocus();

    jTextAreaStatus.setLineWrap(true);
    jTextAreaStatus.setFont(new Font("Tahoma", 0, 11));
    jTextAreaStatus.setWrapStyleWord(true);
    jTextAreaStatus.setBackground(SystemColor.window);

    dataLogTextArea.setLineWrap(false);
    dataLogTextArea.setFont(new Font("Tahoma", 0, 11));
    dataLogTextArea.setBackground(SystemColor.window);

    FQPathTextArea.setBounds(new Rectangle(5, 170, 185, 40));
    FQPathTextArea.setLineWrap(true);
    FQPathTextArea.setText(getCanonicalName(new File(".", "")));
    FQPathTextArea.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
    FQPathTextArea.setRows(2);

    FQPathTextArea.setFont(new Font("Tahoma", 0, 9));
    FQPathTextArea.setOpaque(false);
    FQPathTextArea.setEditable(false);

    selectFolderButton.setText("Folder...");
    selectFolderButton.setBounds(new Rectangle(120, 125, 70, 20));
    selectFolderButton.setMargin(new Insets(1, 1, 1, 1));
    selectFolderButton.setFocusable(false);
    selectFolderButton.setMnemonic('F');
    selectFolderButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            selectFolderButton_actionPerformed(e);
        }
    });

    // domain display limits GUI
    chartOptionsPanel.setLayout(null);
    chartDomLimitsPanel.setBounds(new Rectangle(5, 35, 180, 135));
    chartDomLimitsPanel.setLayout(gridLayout1);
    chartDomLimitsPanel.setBorder(BorderFactory.createTitledBorder("Domain Display Limiting"));
    domainDisplayLimitSlider.setEnabled(false);
    domainDisplayLimitSlider.setMaximum(MAXDOMAIN_DATAPOINT_LIMIT);
    domainDisplayLimitSlider.setMinimum(MINDOMAIN_LIMIT);
    domainDisplayLimitSlider.setValue(MAXDOMAIN_DATAPOINT_LIMIT);
    domainDisplayLimitSlider.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            domainDisplayLimitSlider_stateChanged(e);
        }
    });
    useTimeRadioButton.setText("By Time");
    useTimeRadioButton.setEnabled(false);
    useTimeRadioButton.setMnemonic('I');
    useTimeRadioButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            domainDisplayLimitRadioButton_actionPerformed(e);
        }
    });
    useDataPointsRadioButton.setText("By Data Points");
    ButtonGroup bg1 = new ButtonGroup();
    bg1.add(useTimeRadioButton);
    bg1.add(useDataPointsRadioButton);
    useDataPointsRadioButton.setSelected(true);
    useDataPointsRadioButton.setEnabled(false);
    useDataPointsRadioButton.setMnemonic('P');
    useDataPointsRadioButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            domainDisplayLimitRadioButton_actionPerformed(e);
        }
    });
    datasetLimitEnableCheckBox.setText("Enable");
    datasetLimitEnableCheckBox.setRolloverEnabled(true);
    datasetLimitEnableCheckBox.setMnemonic('A');
    datasetLimitEnableCheckBox.setToolTipText("Enable Domain Clipping");
    datasetLimitEnableCheckBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            datasetLimitEnableCheckBox_actionPerformed(e);
        }
    });
    domainLimitLabel.setText(String.format("%1$,d datapoints", MAXDOMAIN_DATAPOINT_LIMIT).toString());
    domainLimitLabel.setEnabled(false);
    gridLayout1.setRows(5);
    gridLayout1.setColumns(1);

    jLabel1.setText("Chart Title:");
    jLabel1.setBounds(new Rectangle(200, 10, 85, 20));
    jLabel1.setPreferredSize(new Dimension(115, 14));
    jLabel2.setText("Range Axis 1 Label:");
    jLabel2.setBounds(new Rectangle(200, 35, 115, 20));
    jLabel2.setSize(new Dimension(115, 20));
    jLabel3.setText("Range Axis 2 Label:");
    jLabel3.setBounds(new Rectangle(200, 60, 115, 20));
    jLabel3.setSize(new Dimension(115, 20));
    jLabel4.setText("Range Axis 3 Label:");
    jLabel4.setBounds(new Rectangle(200, 85, 115, 20));
    jLabel4.setSize(new Dimension(115, 20));
    jLabel6.setText("Range Axis 4 Label:");
    jLabel6.setBounds(new Rectangle(200, 110, 115, 20));
    jLabel6.setSize(new Dimension(115, 20));
    titleLabelChangeNotifier notifier = new titleLabelChangeNotifier();
    chartTitleTextField.setBounds(new Rectangle(315, 10, 290, 20));
    chartTitleTextField.getDocument().addDocumentListener(notifier);
    axis1LabelTextField.setBounds(new Rectangle(315, 35, 290, 20));
    axis1LabelTextField.getDocument().addDocumentListener(notifier);
    axis2LabelTextField.setBounds(new Rectangle(315, 60, 290, 20));
    axis2LabelTextField.getDocument().addDocumentListener(notifier);
    axis3LabelTextField.setBounds(new Rectangle(315, 85, 290, 20));
    axis3LabelTextField.getDocument().addDocumentListener(notifier);
    axis4LabelTextField.setBounds(new Rectangle(315, 110, 290, 20));
    showCommentsCheckBox.setText("Show Comment Markers");
    showCommentsCheckBox.setBounds(new Rectangle(200, 140, 185, 25));
    showCommentsCheckBox.setToolTipText("Show/Hide any comment markers on the chart");
    showCommentsCheckBox.setRolloverEnabled(true);
    showCommentsCheckBox.setSelected(true);
    showCommentsCheckBox.setMnemonic('M');
    showCommentsCheckBox.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            customChartPanel.setCommentsVisible(e.getStateChange() == ItemEvent.SELECTED);
        }
    });
    scrollDomainCheckBox.setText("Scroll Domain");
    scrollDomainCheckBox.setBounds(new Rectangle(10, 5, 175, 20));
    scrollDomainCheckBox.setSize(new Dimension(175, 25));
    scrollDomainCheckBox.setSelected(true);
    scrollDomainCheckBox.setMnemonic('O');
    scrollDomainCheckBox.setToolTipText("Checked to scroll domain as new data is received");
    scrollDomainCheckBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scrollDomainCheckBox_actionPerformed(e);
        }
    });
    axis4LabelTextField.getDocument().addDocumentListener(notifier);

    logFileTextField.setBounds(new Rectangle(10, 145, 180, 20));
    logFileTextField.setText("NXTData.txt");
    logFileTextField.setPreferredSize(new Dimension(180, 20));
    logFileTextField.setToolTipText("File name. Leave empty to not log to file.");
    statusScrollPane.setOpaque(false);
    dataLogScrollPane.setOpaque(false);

    customChartPanel.setMinimumSize(new Dimension(400, 300));
    customChartPanel.setPreferredSize(new Dimension(812, 400));

    jLabel5.setText("NXT Name/Address:");
    jLabel5.setBounds(new Rectangle(5, 20, 160, 20));
    jLabel5.setToolTipText(jTextFieldNXTName.getToolTipText());
    jLabel5.setHorizontalTextPosition(SwingConstants.RIGHT);
    jLabel5.setHorizontalAlignment(SwingConstants.LEFT);

    connectionPanel.add(jTextFieldNXTName, null);
    connectionPanel.add(jButtonConnect, null);
    connectionPanel.add(jLabel5, null);
    dataLogScrollPane.setViewportView(dataLogTextArea);
    jTabbedPane1.addTab("Data Log", dataLogScrollPane);
    statusScrollPane.setViewportView(jTextAreaStatus);
    jTabbedPane1.addTab("Status", statusScrollPane);
    jTabbedPane1.addTab("Chart", chartOptionsPanel);
    chartDomLimitsPanel.add(datasetLimitEnableCheckBox, null);
    chartDomLimitsPanel.add(useDataPointsRadioButton, null);
    chartDomLimitsPanel.add(useTimeRadioButton, null);
    chartDomLimitsPanel.add(domainDisplayLimitSlider, null);
    chartDomLimitsPanel.add(domainLimitLabel, null);
    chartOptionsPanel.add(scrollDomainCheckBox, null);
    chartOptionsPanel.add(showCommentsCheckBox, null);
    chartOptionsPanel.add(axis4LabelTextField, null);
    chartOptionsPanel.add(axis3LabelTextField, null);
    chartOptionsPanel.add(axis2LabelTextField, null);
    chartOptionsPanel.add(axis1LabelTextField, null);
    chartOptionsPanel.add(chartTitleTextField, null);
    chartOptionsPanel.add(jLabel6, null);
    chartOptionsPanel.add(jLabel4, null);
    chartOptionsPanel.add(jLabel3, null);
    chartOptionsPanel.add(jLabel2, null);
    chartOptionsPanel.add(jLabel1, null);
    chartOptionsPanel.add(chartDomLimitsPanel, null);

    tglbtnpauseplay = new JToggleButton("");
    tglbtnpauseplay.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (lpm == null)
                return;
            boolean doPause = false;
            if (e.getStateChange() == ItemEvent.SELECTED) {
                doPause = true;
            }
            lpm.setReaderPaused(doPause);
        }
    });
    //        tglbtnpauseplay.addChangeListener(new ChangeListener() {
    //           public void stateChanged(ChangeEvent e) {
    //              System.out.println(e.toString());
    //              //lpm.setReaderPaused(doPause)
    //           }
    //        });
    tglbtnpauseplay
            .setSelectedIcon(new ImageIcon(LogChartFrame.class.getResource("/lejos/pc/charting/play.png")));
    tglbtnpauseplay.setIcon(new ImageIcon(LogChartFrame.class.getResource("/lejos/pc/charting/pause.png")));
    tglbtnpauseplay.setBounds(571, 135, 30, 30);
    chartOptionsPanel.add(tglbtnpauseplay);

    jTabbedPane1.setToolTipTextAt(0, "The tab-delimited log of the data sent from the NXT");
    jTabbedPane1.setToolTipTextAt(1, "Status output");
    jTabbedPane1.setToolTipTextAt(2, "Chart options");
    jTabbedPane1.setMnemonicAt(0, KeyEvent.VK_D);
    jTabbedPane1.setMnemonicAt(1, KeyEvent.VK_S);
    jTabbedPane1.setMnemonicAt(2, KeyEvent.VK_T);
    this.getContentPane().add(customChartPanel, new GridBagConstraints(0, 0, 2, 1, 1.0, 1.0,
            GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
    this.getContentPane().add(UIPanel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST,
            GridBagConstraints.NONE, new Insets(0, 0, 0, 0), -107, 0));

    this.getContentPane().add(jTabbedPane1, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0,
            GridBagConstraints.NORTHEAST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    UIPanel.add(connectionPanel, null);
    UIPanel.add(selectFolderButton, null);
    UIPanel.add(logFileTextField, null);
    UIPanel.add(jLabel1logfilename, null);
    UIPanel.add(FQPathTextArea, null);
    ActionListener taskPerformer = new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            String theData = null;
            for (;;) {
                theData = LogChartFrame.this.logDataQueue.poll();
                if (theData == null)
                    break;
                try {
                    dataLogTextArea.getDocument().insertString(dataLogTextArea.getDocument().getLength(),
                            theData, null);
                } catch (BadLocationException e) {
                    System.out.print(
                            "BadLocationException in datalog textarea updater thread:" + e.toString() + "\n");
                }
            }
        }
    };
    this.updateLogTextAreaTimer = new Timer(1000, taskPerformer);
    this.updateLogTextAreaTimer.start();
}

From source file:com.rapidminer.gui.new_plotter.gui.ColorSchemeDialog.java

/**
 * @return/*from w w  w . j a va 2  s .c  o  m*/
 */
private JPanel createSchemeComboBoxPanel() {
    JPanel schemeListPanel = new JPanel(new GridBagLayout());

    // create categories configuration panel
    {

        GridBagConstraints itemConstraint = new GridBagConstraints();

        // Add active scheme label
        JLabel actviceSchemeLabel = new ResourceLabel(
                "plotter.configuration_dialog.color_scheme_dialog.active_scheme");
        {
            itemConstraint.fill = GridBagConstraints.HORIZONTAL;
            itemConstraint.anchor = GridBagConstraints.WEST;
            itemConstraint.gridwidth = GridBagConstraints.RELATIVE;
            itemConstraint.insets = new Insets(0, 5, 5, 5);
            itemConstraint.weightx = 1.0;

            actviceSchemeLabel.setBackground(Color.red);

            schemeListPanel.add(actviceSchemeLabel, itemConstraint);
        }

        // add button panel
        {
            JPanel buttonPanel = new JPanel(new GridBagLayout());

            // rename scheme button
            {
                renameSchemeButton = new JButton(new ResourceAction(true,
                        "plotter.configuration_dialog.color_scheme_dialog.rename_scheme_button") {

                    private static final long serialVersionUID = 1L;

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        String newName = createNameDialog(currentActiveColorSchemeName);
                        if (newName != null && !newName.equals(currentActiveColorSchemeName)) {
                            renameColorSchemeAction(newName);
                        }
                    }

                });

                itemConstraint = new GridBagConstraints();
                itemConstraint.gridwidth = GridBagConstraints.RELATIVE;
                itemConstraint.fill = GridBagConstraints.NONE;

                buttonPanel.add(renameSchemeButton, itemConstraint);
            }

            // remove scheme button
            {
                removeSchemeButton = new JButton(new ResourceAction(true,
                        "plotter.configuration_dialog.color_scheme_dialog.remove_scheme_button") {

                    private static final long serialVersionUID = 1L;

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        ConfirmDialog dialog = new ConfirmDialog(
                                SwingUtilities.getWindowAncestor((Component) e.getSource()),
                                "plotter.configuration_dialog.confirm_color_scheme_delete",
                                ConfirmDialog.YES_NO_OPTION, false);
                        dialog.setLocationRelativeTo((Component) e.getSource());
                        dialog.setVisible(true);
                        if (dialog.getReturnOption() == ConfirmDialog.YES_OPTION) {
                            removeColorSchemeAction((ColorScheme) colorSchemeComboBox.getSelectedItem());
                        }
                    }

                });

                itemConstraint = new GridBagConstraints();
                itemConstraint.gridwidth = GridBagConstraints.REMAINDER;
                itemConstraint.fill = GridBagConstraints.NONE;

                buttonPanel.add(removeSchemeButton, itemConstraint);
            }

            itemConstraint = new GridBagConstraints();
            itemConstraint.gridwidth = GridBagConstraints.REMAINDER;
            itemConstraint.fill = GridBagConstraints.NONE;
            itemConstraint.anchor = GridBagConstraints.EAST;
            itemConstraint.insets = new Insets(0, 5, 5, 5);

            schemeListPanel.add(buttonPanel, itemConstraint);

        }

        {

            colorSchemeComboBox = new JComboBox(colorSchemeComboBoxModel);
            actviceSchemeLabel.setLabelFor(colorSchemeComboBox);
            colorSchemeComboBox.setRenderer(new ColorSchemeComboBoxRenderer());
            colorSchemeComboBox.addPopupMenuListener(new PopupMenuListener() {

                @Override
                public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
                    return;

                }

                @Override
                public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
                    Object selectedValue = colorSchemeComboBox.getSelectedItem();
                    if (selectedValue instanceof ColorScheme) {
                        ColorScheme selection = (ColorScheme) selectedValue;
                        if (selection != null) {
                            if (!currentActiveColorSchemeName.equals(selection.getName())) {
                                currentActiveColorSchemeName = selection.getName();
                                adaptModels();
                            }
                        }
                    } else {
                        String newName = I18N.getGUILabel("plotter.new_color_scheme_name.label");
                        String suffix = "";
                        int counter = 1;
                        while (currentColorSchemes.get(newName + suffix) != null) {
                            suffix = "_" + counter;
                            counter++;
                        }
                        newName += suffix;
                        String userSelectedName = createNameDialog(newName);
                        if (userSelectedName == null) {
                            colorSchemeComboBox.setSelectedItem(getCurrentActiveColorScheme());
                            return;
                        }
                        addNewColorSchemeAction(userSelectedName);
                    }
                }

                @Override
                public void popupMenuCanceled(PopupMenuEvent e) {
                    return;
                }
            });

            itemConstraint = new GridBagConstraints();
            itemConstraint.fill = GridBagConstraints.BOTH;
            itemConstraint.weightx = 0.0;
            itemConstraint.weighty = 0.0;
            itemConstraint.gridwidth = GridBagConstraints.REMAINDER;

            schemeListPanel.add(colorSchemeComboBox, itemConstraint);
        }

    }
    return schemeListPanel;
}

From source file:org.dwfa.ace.classifier.CNFormsLabelPanel.java

/**
 * <b>Long Canonical Form</b><li>Most Proximate PRIMITIVE Supertypes (IS-A)</li>
 * //ww  w.j a  v a2s.co  m
 */
public JPanel newFormLongJPanel(String label, I_ConfigAceFrame config,
        Map<I_ConceptAttributeTuple, Color> conAttrColorMap, Map<I_DescriptionTuple, Color> desColorMap,
        Map<I_RelTuple, Color> relColorMap) throws IOException {
    JPanel formJPanel = newMinMaxJPanel();
    formJPanel.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.NONE;
    c.anchor = GridBagConstraints.NORTHWEST;
    c.weightx = 0;
    c.weighty = 0;
    c.gridx = 0;
    c.gridy = 0;

    List<LabelForTuple> tLabelList = new ArrayList<LabelForTuple>();
    c.gridx = 0;
    c.gridwidth = 2;
    c.anchor = GridBagConstraints.NORTHWEST;

    // SHOW SELF CONCEPT
    I_ConceptAttributeTuple cTuple = findSelf(theCBean, cEditPathPos);
    I_ImplementActiveLabel tmpTLabel = TermLabelMaker.newLabel(cTuple, showDetailCB.isSelected(),
            showStatusCB.isSelected());
    tLabelList.add((LabelForTuple) tmpTLabel);
    Color tmpDeltaColor = conAttrColorMap.get(cTuple);
    setBorder(tmpTLabel.getLabel(), tmpDeltaColor);
    formJPanel.add(tmpTLabel.getLabel(), c);
    c.gridy++;

    // SHOW PROXIMAL ISAs -- as relationships
    SnoGrpList isaSGList = cSnoTable.getIsaProxPrim();
    List<I_RelTuple> isaList = new ArrayList<I_RelTuple>();
    for (SnoGrp sg : isaSGList)
        for (SnoRel sr : sg)
            isaList.add(new RelVersion(sr.relNid));
    for (I_RelTuple rTuple : isaList) {
        tmpTLabel = TermLabelMaker.newLabel(rTuple, showDetailCB.isSelected(), showStatusCB.isSelected());
        tLabelList.add((LabelForTuple) tmpTLabel);
        tmpDeltaColor = relColorMap.get(rTuple);
        setBorder(tmpTLabel.getLabel(), tmpDeltaColor);
        formJPanel.add(tmpTLabel.getLabel(), c);
        c.gridy++;
    }

    // SHOW ROLES, NON-REDUNDANT, DIFFERENTIATED FROM ROOT
    SnoGrpList sgl = cSnoTable.getRoleDiffFromRootList();
    if (sgl.size() > 0) {
        int i = 0;
        SnoGrp sg = sgl.get(0);
        // show each of the non-Rels
        if (sg.size() > 0 && sg.get(0).group == 0) {
            for (SnoRel sr : sg) {
                I_RelTuple rTuple = new RelVersion(sr.relNid);
                tmpTLabel = TermLabelMaker.newLabelForm(rTuple, showDetailCB.isSelected(),
                        showStatusCB.isSelected());
                tLabelList.add((LabelForTuple) tmpTLabel);
                tmpDeltaColor = relColorMap.get(rTuple);
                setBorder(tmpTLabel.getLabel(), tmpDeltaColor);
                formJPanel.add(tmpTLabel.getLabel(), c);
                c.gridy++;
            }
            i++; // skip past 0 index of the "un-grouped"
        }

        // show each of the groups
        for (; i < sgl.size(); i++) {
            sg = sgl.get(i);
            if (sg.size() == 0)
                continue;
            if (showGroupLabels) { // set to true to show one label per
                // group
                List<I_RelTuple> grpTuple = new ArrayList<I_RelTuple>();
                for (SnoRel sr : sg) {
                    grpTuple.add(new RelVersion(sr.relNid));
                }
                tmpTLabel = TermLabelMaker.newLabel(grpTuple, showDetailCB.isSelected(),
                        showStatusCB.isSelected());
                tLabelList.add((LabelForTuple) tmpTLabel);
                tmpDeltaColor = relColorMap.get(grpTuple.get(0));
                setBorder(tmpTLabel.getLabel(), tmpDeltaColor);
                formJPanel.add(tmpTLabel.getLabel(), c);
                c.gridy++;
            } else { // if false, show 1 relationship per label
                for (SnoRel sr : sg) {
                    I_RelTuple rTuple = new RelVersion(sr.relNid);
                    tmpTLabel = TermLabelMaker.newLabelForm(rTuple, showDetailCB.isSelected(),
                            showStatusCB.isSelected());
                    tLabelList.add((LabelForTuple) tmpTLabel);
                    tmpDeltaColor = relColorMap.get(rTuple);
                    setBorder(tmpTLabel.getLabel(), tmpDeltaColor);
                    formJPanel.add(tmpTLabel.getLabel(), c);
                    c.gridy++;
                }
                c.gridy++;
            }
        }
    }

    c.weightx = 1.0;
    c.weighty = 1.0;
    c.gridwidth = 2;
    formJPanel.add(new JPanel(), c);
    formJPanel.setBorder(BorderFactory.createTitledBorder(label));

    return formJPanel;
}

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");
    }//from  w  ww. j  ava2  s .  c  om
    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;
}