Example usage for java.awt.event FocusListener FocusListener

List of usage examples for java.awt.event FocusListener FocusListener

Introduction

In this page you can find the example usage for java.awt.event FocusListener FocusListener.

Prototype

FocusListener

Source Link

Usage

From source file:com.googlecode.libautocaptcha.tools.VodafoneItalyTool.java

private void initFrame() {
    frame = new JFrame();
    frame.setTitle("libautocaptcha vodafone.it tool");
    frame.setBounds(100, 100, 450, 300);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    tabbedPane = new JTabbedPane(JTabbedPane.TOP);
    frame.getContentPane().add(tabbedPane, BorderLayout.CENTER);

    JPanel setupPanel = new JPanel();
    FlowLayout flowLayout = (FlowLayout) setupPanel.getLayout();
    flowLayout.setAlignment(FlowLayout.LEFT);
    tabbedPane.addTab("Setup", null, setupPanel, null);

    JPanel setupFormPanel = new JPanel();
    setupPanel.add(setupFormPanel);/*from ww  w.  j a  v  a2  s.  c om*/
    GridBagLayout gbl_setupFormPanel = new GridBagLayout();
    gbl_setupFormPanel.columnWidths = new int[] { 150, 250 };
    gbl_setupFormPanel.rowHeights = new int[] { 0, 0, 0 };
    gbl_setupFormPanel.columnWeights = new double[] { 0.0, 1.0 };
    gbl_setupFormPanel.rowWeights = new double[] { 0.0, 0.0, 0.0 };
    setupFormPanel.setLayout(gbl_setupFormPanel);

    JLabel usernameLabel = new JLabel("Username");
    GridBagConstraints gbc_usernameLabel = new GridBagConstraints();
    gbc_usernameLabel.anchor = GridBagConstraints.WEST;
    gbc_usernameLabel.fill = GridBagConstraints.VERTICAL;
    gbc_usernameLabel.insets = new Insets(0, 0, 5, 5);
    gbc_usernameLabel.gridx = 0;
    gbc_usernameLabel.gridy = 0;
    setupFormPanel.add(usernameLabel, gbc_usernameLabel);
    usernameField = new JTextField();
    GridBagConstraints gbc_usernameField = new GridBagConstraints();
    gbc_usernameField.fill = GridBagConstraints.BOTH;
    gbc_usernameField.insets = new Insets(0, 0, 5, 0);
    gbc_usernameField.gridx = 1;
    gbc_usernameField.gridy = 0;
    setupFormPanel.add(usernameField, gbc_usernameField);
    usernameField.setColumns(10);

    JLabel passwordLabel = new JLabel("Password");
    GridBagConstraints gbc_passwordLabel = new GridBagConstraints();
    gbc_passwordLabel.anchor = GridBagConstraints.WEST;
    gbc_passwordLabel.fill = GridBagConstraints.VERTICAL;
    gbc_passwordLabel.insets = new Insets(0, 0, 5, 5);
    gbc_passwordLabel.gridx = 0;
    gbc_passwordLabel.gridy = 1;
    setupFormPanel.add(passwordLabel, gbc_passwordLabel);
    passwordField = new JPasswordField();
    GridBagConstraints gbc_passwordField = new GridBagConstraints();
    gbc_passwordField.fill = GridBagConstraints.BOTH;
    gbc_passwordField.insets = new Insets(0, 0, 5, 0);
    gbc_passwordField.gridx = 1;
    gbc_passwordField.gridy = 1;
    setupFormPanel.add(passwordField, gbc_passwordField);
    passwordField.setColumns(10);

    JLabel receiverLabel = new JLabel("Mobile number");
    GridBagConstraints gbc_receiverLabel = new GridBagConstraints();
    gbc_receiverLabel.fill = GridBagConstraints.VERTICAL;
    gbc_receiverLabel.anchor = GridBagConstraints.WEST;
    gbc_receiverLabel.insets = new Insets(0, 0, 5, 5);
    gbc_receiverLabel.gridx = 0;
    gbc_receiverLabel.gridy = 2;
    setupFormPanel.add(receiverLabel, gbc_receiverLabel);

    receiverField = new JTextField();
    GridBagConstraints gbc_receiverField = new GridBagConstraints();
    gbc_receiverField.insets = new Insets(0, 0, 5, 0);
    gbc_receiverField.fill = GridBagConstraints.BOTH;
    gbc_receiverField.gridx = 1;
    gbc_receiverField.gridy = 2;
    setupFormPanel.add(receiverField, gbc_receiverField);
    receiverField.setColumns(10);

    JPanel backgroundPanel = new JPanel();
    FlowLayout flowLayout_1 = (FlowLayout) backgroundPanel.getLayout();
    flowLayout_1.setAlignment(FlowLayout.LEFT);
    tabbedPane.addTab("Background", null, backgroundPanel, null);

    JPanel backgroundFormPanel = new JPanel();
    backgroundPanel.add(backgroundFormPanel);
    GridBagLayout gbl_backgroundFormPanel = new GridBagLayout();
    gbl_backgroundFormPanel.columnWidths = new int[] { 150, 50, 100, 0 };
    gbl_backgroundFormPanel.rowHeights = new int[] { 0, 25, 0 };
    gbl_backgroundFormPanel.columnWeights = new double[] { 0.0, 0.0, 0.0, Double.MIN_VALUE };
    gbl_backgroundFormPanel.rowWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE };
    backgroundFormPanel.setLayout(gbl_backgroundFormPanel);

    JLabel numberLabel = new JLabel("Number of CAPTCHAs");
    GridBagConstraints gbc_numberLabel = new GridBagConstraints();
    gbc_numberLabel.anchor = GridBagConstraints.WEST;
    gbc_numberLabel.insets = new Insets(0, 0, 5, 5);
    gbc_numberLabel.gridx = 0;
    gbc_numberLabel.gridy = 0;
    backgroundFormPanel.add(numberLabel, gbc_numberLabel);

    numberField = new JTextField();
    numberField.setText("5");
    GridBagConstraints gbc_numberField = new GridBagConstraints();
    gbc_numberField.anchor = GridBagConstraints.WEST;
    gbc_numberField.insets = new Insets(0, 0, 5, 5);
    gbc_numberField.gridx = 1;
    gbc_numberField.gridy = 0;
    backgroundFormPanel.add(numberField, gbc_numberField);
    numberField.setColumns(3);

    JButton numberButton = new JButton("Download");
    numberButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            int counter = 0;

            do {
                BufferedImage captcha = downloadCAPTCHA();
                if (captcha != null) {
                    try {
                        int number = new File(tempFolder.getAbsolutePath()).listFiles().length;
                        File file = new File(tempFolder.getAbsolutePath() + "/background_" + number + ".png");
                        ImageIO.write(captcha, "png", file);
                        Thread.sleep(2500);
                    } catch (Exception x) {
                        x.printStackTrace();
                    }
                }
            } while (++counter < Integer.valueOf(numberField.getText()));

            Image background = loadBackground();
            if (background != null) {
                backgroundImage.setIcon(new ImageIcon(background));
            }
        }
    });
    GridBagConstraints gbc_numberButton = new GridBagConstraints();
    gbc_numberButton.anchor = GridBagConstraints.NORTHWEST;
    gbc_numberButton.insets = new Insets(0, 0, 5, 0);
    gbc_numberButton.gridx = 2;
    gbc_numberButton.gridy = 0;
    backgroundFormPanel.add(numberButton, gbc_numberButton);

    JLabel backgroundLabel = new JLabel("Current background");
    GridBagConstraints gbc_backgroundLabel = new GridBagConstraints();
    gbc_backgroundLabel.anchor = GridBagConstraints.WEST;
    gbc_backgroundLabel.insets = new Insets(0, 0, 0, 5);
    gbc_backgroundLabel.gridx = 0;
    gbc_backgroundLabel.gridy = 1;
    backgroundFormPanel.add(backgroundLabel, gbc_backgroundLabel);

    backgroundImage = new JLabel("");
    GridBagConstraints gbc_backgroundImage = new GridBagConstraints();
    gbc_backgroundImage.anchor = GridBagConstraints.WEST;
    gbc_backgroundImage.gridwidth = 2;
    gbc_backgroundImage.insets = new Insets(0, 0, 0, 5);
    gbc_backgroundImage.gridx = 1;
    gbc_backgroundImage.gridy = 1;
    backgroundFormPanel.add(backgroundImage, gbc_backgroundImage);

    JPanel trainingPanel = new JPanel();
    tabbedPane.addTab("Training", null, trainingPanel, null);
    GridBagLayout gbl_trainingPanel = new GridBagLayout();
    gbl_trainingPanel.columnWidths = new int[] { 437, 0 };
    gbl_trainingPanel.rowHeights = new int[] { 0, 0, 0 };
    gbl_trainingPanel.columnWeights = new double[] { 0.0, Double.MIN_VALUE };
    gbl_trainingPanel.rowWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE };
    trainingPanel.setLayout(gbl_trainingPanel);

    trainingLoadPanel = new JPanel();
    GridBagConstraints gbc_trainingLoadPanel = new GridBagConstraints();
    gbc_trainingLoadPanel.anchor = GridBagConstraints.NORTHWEST;
    gbc_trainingLoadPanel.insets = new Insets(0, 0, 5, 0);
    gbc_trainingLoadPanel.gridx = 0;
    gbc_trainingLoadPanel.gridy = 0;
    trainingPanel.add(trainingLoadPanel, gbc_trainingLoadPanel);
    trainingLoadPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));

    JButton trainingLoadButton = new JButton("Download");
    trainingLoadButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            trainingCaptcha = downloadCAPTCHA();
            if (trainingCaptcha != null) {
                trainingCaptchaImage.setIcon(new ImageIcon(trainingCaptcha));
                List<Image> glyphs = loadGlyphs(trainingCaptcha);
                for (int g = 0; g < 5; ++g) {
                    trainingGlyphImage[g].setIcon(null);
                    trainingGlyphField[g].setText("");
                }
                for (int g = 0; g < glyphs.size() && g < 5; ++g) {
                    trainingGlyph[g] = glyphs.get(g);
                    trainingGlyphImage[g].setIcon(new ImageIcon(trainingGlyph[g]));
                }
                trainingLoadPanel.invalidate();
                trainingSavePanel.invalidate();
            }
        }
    });
    trainingLoadPanel.add(trainingLoadButton);

    trainingCaptchaImage = new JLabel("");
    trainingLoadPanel.add(trainingCaptchaImage);

    trainingSavePanel = new JPanel();
    GridBagConstraints gbc_trainingSavePanel = new GridBagConstraints();
    gbc_trainingSavePanel.insets = new Insets(0, 5, 0, 0);
    gbc_trainingSavePanel.anchor = GridBagConstraints.NORTHWEST;
    gbc_trainingSavePanel.gridx = 0;
    gbc_trainingSavePanel.gridy = 1;
    trainingPanel.add(trainingSavePanel, gbc_trainingSavePanel);
    GridBagLayout gbl_trainingSavePanel = new GridBagLayout();
    gbl_trainingSavePanel.columnWidths = new int[] { 25, 25, 25, 25, 25, 0, 0 };
    gbl_trainingSavePanel.rowHeights = new int[] { 25, 0, 0 };
    gbl_trainingSavePanel.columnWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE };
    gbl_trainingSavePanel.rowWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE };
    trainingSavePanel.setLayout(gbl_trainingSavePanel);

    trainingGlyph = new Image[5];
    trainingGlyphImage = new JLabel[5];
    trainingGlyphField = new JTextField[5];

    trainingGlyphImage[0] = new JLabel("");
    GridBagConstraints gbc_glyphImage0 = new GridBagConstraints();
    gbc_glyphImage0.anchor = GridBagConstraints.NORTHWEST;
    gbc_glyphImage0.insets = new Insets(0, 0, 5, 5);
    gbc_glyphImage0.gridx = 0;
    gbc_glyphImage0.gridy = 0;
    trainingGlyphImage[0].setBorder(BorderFactory.createLineBorder(Color.GRAY, 2));
    trainingSavePanel.add(trainingGlyphImage[0], gbc_glyphImage0);

    trainingGlyphImage[1] = new JLabel("");
    GridBagConstraints gbc_glyphImage1 = new GridBagConstraints();
    gbc_glyphImage1.anchor = GridBagConstraints.NORTHWEST;
    gbc_glyphImage1.insets = new Insets(0, 0, 5, 5);
    gbc_glyphImage1.gridx = 1;
    gbc_glyphImage1.gridy = 0;
    trainingGlyphImage[1].setBorder(BorderFactory.createLineBorder(Color.GRAY, 2));
    trainingSavePanel.add(trainingGlyphImage[1], gbc_glyphImage1);

    trainingGlyphImage[2] = new JLabel("");
    GridBagConstraints gbc_glyphImage2 = new GridBagConstraints();
    gbc_glyphImage2.anchor = GridBagConstraints.NORTHWEST;
    gbc_glyphImage2.insets = new Insets(0, 0, 5, 5);
    gbc_glyphImage2.gridx = 2;
    gbc_glyphImage2.gridy = 0;
    trainingGlyphImage[2].setBorder(BorderFactory.createLineBorder(Color.GRAY, 2));
    trainingSavePanel.add(trainingGlyphImage[2], gbc_glyphImage2);

    trainingGlyphImage[3] = new JLabel("");
    GridBagConstraints gbc_glyphImage3 = new GridBagConstraints();
    gbc_glyphImage3.anchor = GridBagConstraints.NORTHWEST;
    gbc_glyphImage3.insets = new Insets(0, 0, 5, 5);
    gbc_glyphImage3.gridx = 3;
    gbc_glyphImage3.gridy = 0;
    trainingGlyphImage[3].setBorder(BorderFactory.createLineBorder(Color.GRAY, 2));
    trainingSavePanel.add(trainingGlyphImage[3], gbc_glyphImage3);

    trainingGlyphImage[4] = new JLabel("");
    GridBagConstraints gbc_glyphImage4 = new GridBagConstraints();
    gbc_glyphImage4.insets = new Insets(0, 0, 5, 5);
    gbc_glyphImage4.anchor = GridBagConstraints.NORTHWEST;
    gbc_glyphImage4.gridx = 4;
    gbc_glyphImage4.gridy = 0;
    trainingGlyphImage[4].setBorder(BorderFactory.createLineBorder(Color.GRAY, 2));
    trainingSavePanel.add(trainingGlyphImage[4], gbc_glyphImage4);

    JButton trainingSaveButton = new JButton("Train");
    trainingSaveButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            for (int g = 0; g < 5; ++g) {
                String s = trainingGlyphField[g].getText();
                if (s.length() == 1) {
                    char c = Character.toUpperCase(s.charAt(0));
                    net.sourceforge.javaocr.Image glyph = convertImage(trainingGlyph[g]);
                    grayFilter.process(glyph);
                    ThresholdFilter thresholdFilter = new ThresholdFilter(0, FG, BG);
                    thresholdFilter.process(glyph);
                    train(glyph, c);
                }
                trainingGlyphField[g].setText("");
            }

            for (Map.Entry<Character, Cluster> m : clusters.entrySet()) {
                System.out.println("****************************************");
                System.out.print(" character:  ");
                //          int samples = ((EuclidianDistanceCluster) m.getValue()).getAmountSamples();
                int samples = ((SigmaWeightedEuclidianDistanceCluster) m.getValue()).getAmountSamples();
                for (int s = 0; s < samples; ++s)
                    System.out.print(m.getKey());
                System.out.println();
                double[] c = m.getValue().center();
                for (int i = 0; i < c.length; ++i)
                    System.out.println(" centroid[" + i + "]: " + c[i]);
            }

            System.out.println("****************************************");
            System.out.println("TOTAL CLUSTERS: " + clusters.size());
        }
    });
    GridBagConstraints gbc_trainingSaveButton = new GridBagConstraints();
    gbc_trainingSaveButton.gridheight = 2;
    gbc_trainingSaveButton.insets = new Insets(0, 0, 5, 0);
    gbc_trainingSaveButton.gridx = 5;
    gbc_trainingSaveButton.gridy = 0;
    trainingSavePanel.add(trainingSaveButton, gbc_trainingSaveButton);

    trainingGlyphField[0] = new JTextField();
    GridBagConstraints gbc_glyphField0 = new GridBagConstraints();
    gbc_glyphField0.fill = GridBagConstraints.HORIZONTAL;
    gbc_glyphField0.anchor = GridBagConstraints.NORTHWEST;
    gbc_glyphField0.insets = new Insets(0, 0, 0, 5);
    gbc_glyphField0.gridx = 0;
    gbc_glyphField0.gridy = 1;
    trainingSavePanel.add(trainingGlyphField[0], gbc_glyphField0);
    trainingGlyphField[0].setColumns(2);

    trainingGlyphField[1] = new JTextField();
    GridBagConstraints gbc_glyphField1 = new GridBagConstraints();
    gbc_glyphField1.fill = GridBagConstraints.HORIZONTAL;
    gbc_glyphField1.anchor = GridBagConstraints.NORTHWEST;
    gbc_glyphField1.insets = new Insets(0, 0, 0, 5);
    gbc_glyphField1.gridx = 1;
    gbc_glyphField1.gridy = 1;
    trainingSavePanel.add(trainingGlyphField[1], gbc_glyphField1);
    trainingGlyphField[1].setColumns(2);

    trainingGlyphField[2] = new JTextField();
    GridBagConstraints gbc_glyphField2 = new GridBagConstraints();
    gbc_glyphField2.fill = GridBagConstraints.HORIZONTAL;
    gbc_glyphField2.anchor = GridBagConstraints.NORTHWEST;
    gbc_glyphField2.insets = new Insets(0, 0, 0, 5);
    gbc_glyphField2.gridx = 2;
    gbc_glyphField2.gridy = 1;
    trainingSavePanel.add(trainingGlyphField[2], gbc_glyphField2);
    trainingGlyphField[2].setColumns(2);

    trainingGlyphField[3] = new JTextField();
    GridBagConstraints gbc_glyphField3 = new GridBagConstraints();
    gbc_glyphField3.fill = GridBagConstraints.HORIZONTAL;
    gbc_glyphField3.anchor = GridBagConstraints.NORTHWEST;
    gbc_glyphField3.insets = new Insets(0, 0, 0, 5);
    gbc_glyphField3.gridx = 3;
    gbc_glyphField3.gridy = 1;
    trainingSavePanel.add(trainingGlyphField[3], gbc_glyphField3);
    trainingGlyphField[3].setColumns(2);

    trainingGlyphField[4] = new JTextField();
    GridBagConstraints gbc_glyphField4 = new GridBagConstraints();
    gbc_glyphField4.insets = new Insets(0, 0, 0, 5);
    gbc_glyphField4.fill = GridBagConstraints.HORIZONTAL;
    gbc_glyphField4.anchor = GridBagConstraints.NORTHWEST;
    gbc_glyphField4.gridx = 4;
    gbc_glyphField4.gridy = 1;
    trainingSavePanel.add(trainingGlyphField[4], gbc_glyphField4);
    trainingGlyphField[4].setColumns(2);

    JPanel testingPanel = new JPanel();
    tabbedPane.addTab("Testing", null, testingPanel, null);
    GridBagLayout gbl_testingPanel = new GridBagLayout();
    gbl_testingPanel.columnWidths = new int[] { 437, 0 };
    gbl_testingPanel.rowHeights = new int[] { 0, 0, 0, 0 };
    gbl_testingPanel.columnWeights = new double[] { 1.0, Double.MIN_VALUE };
    gbl_testingPanel.rowWeights = new double[] { 0.0, 0.0, 1.0, Double.MIN_VALUE };
    testingPanel.setLayout(gbl_testingPanel);

    testingLoadPanel = new JPanel();
    GridBagConstraints gbc_testingLoadPanel = new GridBagConstraints();
    gbc_testingLoadPanel.anchor = GridBagConstraints.NORTHWEST;
    gbc_testingLoadPanel.insets = new Insets(0, 0, 5, 0);
    gbc_testingLoadPanel.gridx = 0;
    gbc_testingLoadPanel.gridy = 0;
    testingPanel.add(testingLoadPanel, gbc_testingLoadPanel);
    testingLoadPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));

    JButton testingLoadButton = new JButton("Download");
    testingLoadButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            testingCaptcha = downloadCAPTCHA();
            if (testingCaptcha != null) {
                testingCaptchaImage.setIcon(new ImageIcon(testingCaptcha));
                List<Image> glyphs = loadGlyphs(testingCaptcha);
                for (int g = 0; g < 5; ++g) {
                    testingGlyphImage[g].setIcon(null);
                    testingGlyphField[g].setText("");
                }
                for (int g = 0; g < glyphs.size() && g < 5; ++g) {
                    testingGlyph[g] = glyphs.get(g);
                    testingGlyphImage[g].setIcon(new ImageIcon(testingGlyph[g]));
                }
                testingLoadPanel.invalidate();
                testingSavePanel.invalidate();
            }
        }
    });
    testingLoadPanel.add(testingLoadButton);

    testingCaptchaImage = new JLabel("");
    testingLoadPanel.add(testingCaptchaImage);

    testingSavePanel = new JPanel();
    GridBagConstraints gbc_testingSavePanel = new GridBagConstraints();
    gbc_testingSavePanel.insets = new Insets(0, 5, 5, 0);
    gbc_testingSavePanel.anchor = GridBagConstraints.NORTHWEST;
    gbc_testingSavePanel.gridx = 0;
    gbc_testingSavePanel.gridy = 1;
    testingPanel.add(testingSavePanel, gbc_testingSavePanel);
    GridBagLayout gbl_testingSavePanel = new GridBagLayout();
    gbl_testingSavePanel.columnWidths = new int[] { 25, 25, 25, 25, 25, 0, 0 };
    gbl_testingSavePanel.rowHeights = new int[] { 25, 0, 0 };
    gbl_testingSavePanel.columnWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE };
    gbl_testingSavePanel.rowWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE };
    testingSavePanel.setLayout(gbl_testingSavePanel);

    testingGlyph = new Image[5];
    testingGlyphImage = new JLabel[5];
    testingGlyphField = new JTextField[5];

    testingGlyphImage[0] = new JLabel("");
    GridBagConstraints gbc_testingGlyphImage0 = new GridBagConstraints();
    gbc_testingGlyphImage0.anchor = GridBagConstraints.NORTHWEST;
    gbc_testingGlyphImage0.insets = new Insets(0, 0, 5, 5);
    gbc_testingGlyphImage0.gridx = 0;
    gbc_testingGlyphImage0.gridy = 0;
    testingGlyphImage[0].setBorder(BorderFactory.createLineBorder(Color.GRAY, 2));
    testingSavePanel.add(testingGlyphImage[0], gbc_testingGlyphImage0);

    testingGlyphImage[1] = new JLabel("");
    GridBagConstraints gbc_testingGlyphImage1 = new GridBagConstraints();
    gbc_testingGlyphImage1.anchor = GridBagConstraints.NORTHWEST;
    gbc_testingGlyphImage1.insets = new Insets(0, 0, 5, 5);
    gbc_testingGlyphImage1.gridx = 1;
    gbc_testingGlyphImage1.gridy = 0;
    testingGlyphImage[1].setBorder(BorderFactory.createLineBorder(Color.GRAY, 2));
    testingSavePanel.add(testingGlyphImage[1], gbc_testingGlyphImage1);

    testingGlyphImage[2] = new JLabel("");
    GridBagConstraints gbc_testingGlyphImage2 = new GridBagConstraints();
    gbc_testingGlyphImage2.anchor = GridBagConstraints.NORTHWEST;
    gbc_testingGlyphImage2.insets = new Insets(0, 0, 5, 5);
    gbc_testingGlyphImage2.gridx = 2;
    gbc_testingGlyphImage2.gridy = 0;
    testingGlyphImage[2].setBorder(BorderFactory.createLineBorder(Color.GRAY, 2));
    testingSavePanel.add(testingGlyphImage[2], gbc_testingGlyphImage2);

    testingGlyphImage[3] = new JLabel("");
    GridBagConstraints gbc_testingGlyphImage3 = new GridBagConstraints();
    gbc_testingGlyphImage3.anchor = GridBagConstraints.NORTHWEST;
    gbc_testingGlyphImage3.insets = new Insets(0, 0, 5, 5);
    gbc_testingGlyphImage3.gridx = 3;
    gbc_testingGlyphImage3.gridy = 0;
    testingGlyphImage[3].setBorder(BorderFactory.createLineBorder(Color.GRAY, 2));
    testingSavePanel.add(testingGlyphImage[3], gbc_testingGlyphImage3);

    testingGlyphImage[4] = new JLabel("");
    GridBagConstraints gbc_testingGlyphImage4 = new GridBagConstraints();
    gbc_testingGlyphImage4.insets = new Insets(0, 0, 5, 5);
    gbc_testingGlyphImage4.anchor = GridBagConstraints.NORTHWEST;
    gbc_testingGlyphImage4.gridx = 4;
    gbc_testingGlyphImage4.gridy = 0;
    testingGlyphImage[4].setBorder(BorderFactory.createLineBorder(Color.GRAY, 2));
    testingSavePanel.add(testingGlyphImage[4], gbc_testingGlyphImage4);

    JButton testingSaveButton = new JButton("Save and test");
    testingSaveButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String text = "";
            for (int g = 0; g < 5; ++g) {
                String s = testingGlyphField[g].getText();
                if (s.length() == 1)
                    text += s.toUpperCase();
                trainingGlyphField[g].setText("");
            }

            if (text.length() != 5)
                return;

            try {
                File file = new File(tempFolder.getAbsolutePath() + "/captcha_" + text + ".png");
                ImageIO.write(testingCaptcha, "png", file);
            } catch (IOException x) {
                x.printStackTrace();
            }

            testingViewArea.setText(loadStatistics());
        }
    });
    GridBagConstraints gbc_testingSaveButton = new GridBagConstraints();
    gbc_testingSaveButton.gridheight = 2;
    gbc_testingSaveButton.insets = new Insets(0, 0, 5, 0);
    gbc_testingSaveButton.gridx = 5;
    gbc_testingSaveButton.gridy = 0;
    testingSavePanel.add(testingSaveButton, gbc_testingSaveButton);

    testingGlyphField[0] = new JTextField();
    GridBagConstraints gbc_testingGlyphField0 = new GridBagConstraints();
    gbc_testingGlyphField0.fill = GridBagConstraints.HORIZONTAL;
    gbc_testingGlyphField0.anchor = GridBagConstraints.NORTHWEST;
    gbc_testingGlyphField0.insets = new Insets(0, 0, 0, 5);
    gbc_testingGlyphField0.gridx = 0;
    gbc_testingGlyphField0.gridy = 1;
    testingSavePanel.add(testingGlyphField[0], gbc_testingGlyphField0);
    testingGlyphField[0].setColumns(2);

    testingGlyphField[1] = new JTextField();
    GridBagConstraints gbc_testingGlyphField1 = new GridBagConstraints();
    gbc_testingGlyphField1.fill = GridBagConstraints.HORIZONTAL;
    gbc_testingGlyphField1.anchor = GridBagConstraints.NORTHWEST;
    gbc_testingGlyphField1.insets = new Insets(0, 0, 0, 5);
    gbc_testingGlyphField1.gridx = 1;
    gbc_testingGlyphField1.gridy = 1;
    testingSavePanel.add(testingGlyphField[1], gbc_testingGlyphField1);
    testingGlyphField[1].setColumns(2);

    testingGlyphField[2] = new JTextField();
    GridBagConstraints gbc_testingGlyphField2 = new GridBagConstraints();
    gbc_testingGlyphField2.fill = GridBagConstraints.HORIZONTAL;
    gbc_testingGlyphField2.anchor = GridBagConstraints.NORTHWEST;
    gbc_testingGlyphField2.insets = new Insets(0, 0, 0, 5);
    gbc_testingGlyphField2.gridx = 2;
    gbc_testingGlyphField2.gridy = 1;
    testingSavePanel.add(testingGlyphField[2], gbc_testingGlyphField2);
    testingGlyphField[2].setColumns(2);

    testingGlyphField[3] = new JTextField();
    GridBagConstraints gbc_testingGlyphField3 = new GridBagConstraints();
    gbc_testingGlyphField3.fill = GridBagConstraints.HORIZONTAL;
    gbc_testingGlyphField3.anchor = GridBagConstraints.NORTHWEST;
    gbc_testingGlyphField3.insets = new Insets(0, 0, 0, 5);
    gbc_testingGlyphField3.gridx = 3;
    gbc_testingGlyphField3.gridy = 1;
    testingSavePanel.add(testingGlyphField[3], gbc_testingGlyphField3);
    testingGlyphField[3].setColumns(2);

    testingGlyphField[4] = new JTextField();
    GridBagConstraints gbc_testingGlyphField4 = new GridBagConstraints();
    gbc_testingGlyphField4.insets = new Insets(0, 0, 0, 5);
    gbc_testingGlyphField4.fill = GridBagConstraints.HORIZONTAL;
    gbc_testingGlyphField4.anchor = GridBagConstraints.NORTHWEST;
    gbc_testingGlyphField4.gridx = 4;
    gbc_testingGlyphField4.gridy = 1;
    testingSavePanel.add(testingGlyphField[4], gbc_testingGlyphField4);

    JPanel testingViewPanel = new JPanel();
    GridBagConstraints gbc_testingViewPanel = new GridBagConstraints();
    gbc_testingViewPanel.fill = GridBagConstraints.HORIZONTAL;
    gbc_testingViewPanel.anchor = GridBagConstraints.NORTHWEST;
    gbc_testingViewPanel.gridx = 0;
    gbc_testingViewPanel.gridy = 2;
    testingPanel.add(testingViewPanel, gbc_testingViewPanel);
    GridBagLayout gbl_testingViewPanel = new GridBagLayout();
    gbl_testingViewPanel.columnWidths = new int[] { 330, 0 };
    gbl_testingViewPanel.rowHeights = new int[] { 75, 0 };
    gbl_testingViewPanel.columnWeights = new double[] { 0.0, Double.MIN_VALUE };
    gbl_testingViewPanel.rowWeights = new double[] { 0.0, Double.MIN_VALUE };
    testingViewPanel.setLayout(gbl_testingViewPanel);

    testingViewArea = new JTextArea();
    testingViewArea.setRows(5);
    testingViewArea.setColumns(30);
    GridBagConstraints gbc_testingViewArea = new GridBagConstraints();
    gbc_testingViewArea.fill = GridBagConstraints.BOTH;
    gbc_testingViewArea.anchor = GridBagConstraints.NORTHWEST;
    gbc_testingViewArea.gridx = 0;
    gbc_testingViewArea.gridy = 0;
    testingViewPanel.add(testingViewArea, gbc_testingViewArea);
    testingGlyphField[4].setColumns(2);

    JPanel outputPanel = new JPanel();
    FlowLayout flowLayout2 = (FlowLayout) outputPanel.getLayout();
    flowLayout2.setAlignment(FlowLayout.LEFT);
    tabbedPane.addTab("Output", null, outputPanel, null);

    JPanel outputFormPanel = new JPanel();
    outputPanel.add(outputFormPanel);
    GridBagLayout gbl_outputFormPanel = new GridBagLayout();
    gbl_outputFormPanel.columnWidths = new int[] { 150, 250 };
    gbl_outputFormPanel.rowHeights = new int[] { 0 };
    gbl_outputFormPanel.columnWeights = new double[] { 0.0, 1.0 };
    gbl_outputFormPanel.rowWeights = new double[] { 0.0 };
    outputFormPanel.setLayout(gbl_outputFormPanel);

    JLabel javaLabel = new JLabel("Output .java file");
    GridBagConstraints gbc_javaLabel = new GridBagConstraints();
    gbc_javaLabel.anchor = GridBagConstraints.WEST;
    gbc_javaLabel.fill = GridBagConstraints.VERTICAL;
    gbc_javaLabel.insets = new Insets(0, 0, 5, 5);
    gbc_javaLabel.gridx = 0;
    gbc_javaLabel.gridy = 0;
    outputFormPanel.add(javaLabel, gbc_javaLabel);

    javaField = new JTextField();
    javaField.addFocusListener(new FocusListener() {
        public void focusLost(FocusEvent e) {
            javaField.removeFocusListener(this);
        }

        public void focusGained(FocusEvent e) {
            JFileChooser chooser = new JFileChooser(outFolderName);
            chooser.setSelectedFile(new File(outFileName));
            chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            if (chooser.showDialog(frame, "Save .java file") == JFileChooser.APPROVE_OPTION) {
                javaField.setText(chooser.getSelectedFile().getAbsolutePath());

                try {
                    PrintWriter output = new PrintWriter(
                            new FileWriter(chooser.getSelectedFile().getAbsolutePath()));
                    output.println("package com.googlecode.libautocaptcha.decoder.data;");
                    output.println("import net.sourceforge.javaocr.plugin.cluster.Cluster;");
                    output.println("import net.sourceforge.javaocr.plugin.cluster.MahalanobisDistanceCluster;");
                    output.println("public class VodafoneItalyData {");

                    output.println("  public static final int[] " + BACKGROUND_FIELD + " = ");
                    output.print("    new int[] { ");
                    for (int y = 0; y < HEIGHT; ++y)
                        for (int x = 0; x < WIDTH; ++x)
                            output.print(background.get(x, y) + ", ");
                    output.println("};");

                    output.println("  public static final char[] " + CHARACTERS_FIELD + " = ");
                    output.print("    new char[] { ");
                    for (Character c : clusters.keySet())
                        output.print("'" + c + "', ");
                    output.println("};");

                    output.println("  public static final Cluster[] " + CLUSTERS_FIELD + " = ");
                    output.print("    new MahalanobisDistanceCluster[] { ");
                    for (Cluster c : clusters.values()) {
                        output.print("new MahalanobisDistanceCluster(new double[] { ");
                        double[] mx = ((MahalanobisDistanceCluster) c).getMx();
                        for (double i : mx)
                            output.print(i + ", ");
                        output.print("}, new double[][] { ");
                        double[][] invcov = ((MahalanobisDistanceCluster) c).getInvcov();
                        for (double[] row : invcov) {
                            output.print("new double[] { ");
                            for (double i : row)
                                output.print(i + ", ");
                            output.print("}, ");
                        }
                        output.print("}), ");
                    }
                    output.println("};");

                    output.println("}");
                    output.close();
                } catch (IOException x) {
                    x.printStackTrace();
                }
            }
        }
    });
    GridBagConstraints gbc_javaField = new GridBagConstraints();
    gbc_javaField.fill = GridBagConstraints.BOTH;
    gbc_javaField.insets = new Insets(0, 0, 5, 0);
    gbc_javaField.gridx = 1;
    gbc_javaField.gridy = 0;
    outputFormPanel.add(javaField, gbc_javaField);
    javaField.setColumns(10);

    JPanel statusPanel = new JPanel();
    frame.getContentPane().add(statusPanel, BorderLayout.SOUTH);
    GridBagLayout gbl_statusPanel = new GridBagLayout();
    gbl_statusPanel.columnWidths = new int[] { 150, 0, 0 };
    gbl_statusPanel.rowHeights = new int[] { 14, 0 };
    gbl_statusPanel.columnWeights = new double[] { 0.0, 1.0, Double.MIN_VALUE };
    gbl_statusPanel.rowWeights = new double[] { 0.0, Double.MIN_VALUE };
    statusPanel.setLayout(gbl_statusPanel);

    statusBar = new JProgressBar();
    GridBagConstraints gbc_statusBar = new GridBagConstraints();
    gbc_statusBar.insets = new Insets(0, 0, 0, 5);
    gbc_statusBar.gridx = 0;
    gbc_statusBar.gridy = 0;
    statusPanel.add(statusBar, gbc_statusBar);

    statusLabel = new JLabel("");
    GridBagConstraints gbc_statusLabel = new GridBagConstraints();
    gbc_statusLabel.fill = GridBagConstraints.HORIZONTAL;
    gbc_statusLabel.gridx = 1;
    gbc_statusLabel.gridy = 0;
    statusPanel.add(statusLabel, gbc_statusLabel);
}

From source file:com.itemanalysis.jmetrik.swing.GraphOptionPanel.java

private void initComponents() {

    orientationButtonGroup = new ButtonGroup();
    colorPanel = new JPanel();
    color1Label = new JLabel();
    colorLabel2 = new JLabel();
    colorButton1 = new JButton();
    colorButton2 = new JButton();
    colorLabel3 = new JLabel();
    colorButton3 = new JButton();
    colorLabel4 = new JLabel();
    colorButton4 = new JButton();
    colorLabel5 = new JLabel();
    colorButton5 = new JButton();
    colorLabel6 = new JLabel();
    colorButton6 = new JButton();
    colorLabel7 = new JLabel();
    colorButton7 = new JButton();
    colorLabel8 = new JLabel();
    colorButton8 = new JButton();
    colorLabel9 = new JLabel();
    colorButton9 = new JButton();
    lineStylePanel = new JPanel();
    lineLabel1 = new JLabel();
    lineStyleComboBox1 = new JComboBox();
    lineLabel2 = new JLabel();
    lineStyleComboBox2 = new JComboBox();
    lineLabel3 = new JLabel();
    lineStyleComboBox3 = new JComboBox();
    lineLabel4 = new JLabel();
    lineStyleComboBox4 = new JComboBox();
    lineLabel5 = new JLabel();
    lineStyleComboBox5 = new JComboBox();
    lineLabel6 = new JLabel();
    lineStyleComboBox6 = new JComboBox();
    lineLabel7 = new JLabel();
    lineStyleComboBox7 = new JComboBox();
    lineLabel8 = new JLabel();
    lineStyleComboBox8 = new JComboBox();
    lineLabel9 = new JLabel();
    lineStyleComboBox9 = new JComboBox();
    lineWidthLabel = new JLabel();
    lineWidthTextField = new JTextField();
    displayPanel = new JPanel();
    legendPositionComboBox = new JComboBox();
    legendCheckbox = new JCheckBox();
    markersCheckbox = new JCheckBox();
    horizontalRadioButton = new JRadioButton();
    verticalRadioButton = new JRadioButton();
    sizePanel = new JPanel();
    widthLabel = new JLabel();
    widthTextField = new JTextField();
    heightLabel = new JLabel();
    heightTextField = new JTextField();
    resetButton = new JButton();

    //        setBorder(BorderFactory.createTitledBorder(""));

    colorPanel.setBorder(BorderFactory.createTitledBorder("Color Sequence"));

    color1Label.setText("Color 1");

    colorLabel2.setText("Color 2");

    colorButton1.setText("Choose Color");
    colorButton1.setMaximumSize(new Dimension(116, 25));
    colorButton1.setMinimumSize(new Dimension(116, 25));
    colorButton1.setPreferredSize(new Dimension(116, 25));
    colorButton1.setBackground(color[0]);
    colorButton1.addActionListener(new ActionListener() {
        @Override/*from   www  .  j av  a 2 s . co  m*/
        public void actionPerformed(ActionEvent e) {
            Color newColor = JColorChooser.showDialog(GraphOptionPanel.this, "Color 1", color[0]);
            if (newColor != null) {
                colorButton1.setBackground(newColor);
                color[0] = newColor;
            }
        }
    });

    colorButton2.setText("Choose Color");
    colorButton2.setMaximumSize(new Dimension(116, 25));
    colorButton2.setMinimumSize(new Dimension(116, 25));
    colorButton2.setPreferredSize(new Dimension(116, 25));
    colorButton2.setBackground(color[1]);
    colorButton2.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Color newColor = JColorChooser.showDialog(GraphOptionPanel.this, "Color 2", color[1]);
            if (newColor != null) {
                colorButton2.setBackground(newColor);
                color[1] = newColor;
            }
        }
    });

    colorLabel3.setText("Color 3");

    colorButton3.setText("Choose Color");
    colorButton3.setMaximumSize(new Dimension(116, 25));
    colorButton3.setMinimumSize(new Dimension(116, 25));
    colorButton3.setPreferredSize(new Dimension(116, 25));
    colorButton3.setBackground(color[2]);
    colorButton3.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Color newColor = JColorChooser.showDialog(GraphOptionPanel.this, "Color 3", color[2]);
            if (newColor != null) {
                colorButton3.setBackground(newColor);
                color[2] = newColor;
            }
        }
    });

    colorLabel4.setText("Color 4");

    colorButton4.setText("Choose Color");
    colorButton4.setMaximumSize(new Dimension(116, 25));
    colorButton4.setMinimumSize(new Dimension(116, 25));
    colorButton4.setPreferredSize(new Dimension(116, 25));
    colorButton4.setBackground(color[3]);
    colorButton4.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Color newColor = JColorChooser.showDialog(GraphOptionPanel.this, "Color 4", color[3]);
            if (newColor != null) {
                colorButton4.setBackground(newColor);
                color[3] = newColor;
            }
        }
    });

    colorLabel5.setText("Color 5");

    colorButton5.setText("Choose Color");
    colorButton5.setMaximumSize(new Dimension(116, 25));
    colorButton5.setMinimumSize(new Dimension(116, 25));
    colorButton5.setPreferredSize(new Dimension(116, 25));
    colorButton5.setBackground(color[4]);
    colorButton5.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Color newColor = JColorChooser.showDialog(GraphOptionPanel.this, "Color 5", color[4]);
            if (newColor != null) {
                colorButton5.setBackground(newColor);
                color[4] = newColor;
            }
        }
    });

    colorLabel6.setText("Color 6");

    colorButton6.setText("Choose Color");
    colorButton6.setMaximumSize(new Dimension(116, 25));
    colorButton6.setMinimumSize(new Dimension(116, 25));
    colorButton6.setPreferredSize(new Dimension(116, 25));
    colorButton6.setBackground(color[5]);
    colorButton6.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Color newColor = JColorChooser.showDialog(GraphOptionPanel.this, "Color 6", color[5]);
            if (newColor != null) {
                colorButton6.setBackground(newColor);
                color[5] = newColor;
            }
        }
    });

    colorLabel7.setText("Color 7");

    colorButton7.setText("Choose Color");
    colorButton7.setMaximumSize(new Dimension(116, 25));
    colorButton7.setMinimumSize(new Dimension(116, 25));
    colorButton7.setPreferredSize(new Dimension(116, 25));
    colorButton7.setBackground(color[6]);
    colorButton7.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Color newColor = JColorChooser.showDialog(GraphOptionPanel.this, "Color 7", color[6]);
            if (newColor != null) {
                colorButton7.setBackground(newColor);
                color[6] = newColor;
            }
        }
    });

    colorLabel8.setText("Color 8");

    colorButton8.setText("Choose Color");
    colorButton8.setMaximumSize(new Dimension(116, 25));
    colorButton8.setMinimumSize(new Dimension(116, 25));
    colorButton8.setPreferredSize(new Dimension(116, 25));
    colorButton8.setBackground(color[7]);
    colorButton8.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Color newColor = JColorChooser.showDialog(GraphOptionPanel.this, "Color 8", color[7]);
            if (newColor != null) {
                colorButton8.setBackground(newColor);
                color[7] = newColor;
            }
        }
    });

    colorLabel9.setText("Color 9");

    colorButton9.setText("Choose Color");
    colorButton9.setMaximumSize(new Dimension(116, 25));
    colorButton9.setMinimumSize(new Dimension(116, 25));
    colorButton9.setPreferredSize(new Dimension(116, 25));
    colorButton9.setBackground(color[8]);
    colorButton9.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Color newColor = JColorChooser.showDialog(GraphOptionPanel.this, "Color 9", color[8]);
            if (newColor != null) {
                colorButton9.setBackground(newColor);
                color[8] = newColor;
            }
        }
    });

    GroupLayout colorPanelLayout = new GroupLayout(colorPanel);
    colorPanel.setLayout(colorPanelLayout);
    colorPanelLayout.setHorizontalGroup(colorPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(colorPanelLayout.createSequentialGroup().addContainerGap()
                    .addGroup(colorPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addGroup(colorPanelLayout.createSequentialGroup().addComponent(color1Label)
                                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(colorButton1, GroupLayout.DEFAULT_SIZE, 120, Short.MAX_VALUE))
                            .addGroup(colorPanelLayout.createSequentialGroup().addComponent(colorLabel2)
                                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(colorButton2, GroupLayout.DEFAULT_SIZE,
                                            GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(colorPanelLayout.createSequentialGroup().addComponent(colorLabel3)
                                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(colorButton3, GroupLayout.DEFAULT_SIZE,
                                            GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(colorPanelLayout.createSequentialGroup().addComponent(colorLabel4)
                                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(colorButton4, GroupLayout.DEFAULT_SIZE,
                                            GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(colorPanelLayout.createSequentialGroup().addComponent(colorLabel5)
                                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(colorButton5, GroupLayout.DEFAULT_SIZE,
                                            GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(colorPanelLayout.createSequentialGroup().addComponent(colorLabel6)
                                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(colorButton6, GroupLayout.DEFAULT_SIZE,
                                            GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(colorPanelLayout.createSequentialGroup().addComponent(colorLabel7)
                                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(colorButton7, GroupLayout.DEFAULT_SIZE,
                                            GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(colorPanelLayout.createSequentialGroup().addComponent(colorLabel8)
                                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(colorButton8, GroupLayout.DEFAULT_SIZE,
                                            GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(colorPanelLayout.createSequentialGroup().addComponent(colorLabel9)
                                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(colorButton9, GroupLayout.DEFAULT_SIZE,
                                            GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addContainerGap()));
    colorPanelLayout.setVerticalGroup(colorPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(colorPanelLayout.createSequentialGroup().addContainerGap()
                    .addGroup(colorPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(color1Label).addComponent(colorButton1, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(colorPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(colorLabel2).addComponent(colorButton2, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(colorPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(colorLabel3).addComponent(colorButton3, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(colorPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(colorLabel4).addComponent(colorButton4, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(colorPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(colorLabel5).addComponent(colorButton5, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(colorPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(colorLabel6).addComponent(colorButton6, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(colorPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(colorLabel7).addComponent(colorButton7, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(colorPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(colorLabel8).addComponent(colorButton8, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(colorPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(colorLabel9).addComponent(colorButton9, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                    .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

    lineStylePanel.setBorder(BorderFactory.createTitledBorder("Line Styles"));

    lineLabel1.setText("Line 1");

    lineStyleComboBox1.setModel(new DefaultComboBoxModel(ChartStyle.LINE_STYLE_NAME));
    lineStyleComboBox1.setRenderer(new LineStyleComboBoxRenderer());
    lineStyleComboBox1.setSelectedItem(ChartStyle.floatStyleToString(selectedLineStyles[0]));
    lineStyleComboBox1.setMinimumSize(new Dimension(150, 25));
    lineStyleComboBox1.setPreferredSize(new Dimension(150, 25));

    lineLabel2.setText("Line 2");

    lineStyleComboBox2.setModel(new DefaultComboBoxModel(ChartStyle.LINE_STYLE_NAME));
    lineStyleComboBox2.setRenderer(new LineStyleComboBoxRenderer());
    lineStyleComboBox2.setSelectedItem(ChartStyle.floatStyleToString(selectedLineStyles[1]));
    lineStyleComboBox2.setMinimumSize(new Dimension(150, 25));
    lineStyleComboBox2.setPreferredSize(new Dimension(150, 25));

    lineLabel3.setText("Line 3");

    lineStyleComboBox3.setModel(new DefaultComboBoxModel(ChartStyle.LINE_STYLE_NAME));
    lineStyleComboBox3.setRenderer(new LineStyleComboBoxRenderer());
    lineStyleComboBox3.setSelectedItem(ChartStyle.floatStyleToString(selectedLineStyles[2]));
    lineStyleComboBox3.setMinimumSize(new Dimension(150, 25));
    lineStyleComboBox3.setPreferredSize(new Dimension(150, 25));

    lineLabel4.setText("Line 4");

    lineStyleComboBox4.setModel(new DefaultComboBoxModel(ChartStyle.LINE_STYLE_NAME));
    lineStyleComboBox4.setRenderer(new LineStyleComboBoxRenderer());
    lineStyleComboBox4.setSelectedItem(ChartStyle.floatStyleToString(selectedLineStyles[3]));
    lineStyleComboBox4.setMinimumSize(new Dimension(150, 25));
    lineStyleComboBox4.setPreferredSize(new Dimension(150, 25));

    lineLabel5.setText("Line 5");

    lineStyleComboBox5.setModel(new DefaultComboBoxModel(ChartStyle.LINE_STYLE_NAME));
    lineStyleComboBox5.setRenderer(new LineStyleComboBoxRenderer());
    lineStyleComboBox5.setSelectedItem(ChartStyle.floatStyleToString(selectedLineStyles[4]));
    lineStyleComboBox5.setMinimumSize(new Dimension(150, 25));
    lineStyleComboBox5.setPreferredSize(new Dimension(150, 25));

    lineLabel6.setText("Line 6");

    lineStyleComboBox6.setModel(new DefaultComboBoxModel(ChartStyle.LINE_STYLE_NAME));
    lineStyleComboBox6.setRenderer(new LineStyleComboBoxRenderer());
    lineStyleComboBox6.setSelectedItem(ChartStyle.floatStyleToString(selectedLineStyles[5]));
    lineStyleComboBox6.setMinimumSize(new Dimension(150, 25));
    lineStyleComboBox6.setPreferredSize(new Dimension(150, 25));

    lineLabel7.setText("Line 7");

    lineStyleComboBox7.setModel(new DefaultComboBoxModel(ChartStyle.LINE_STYLE_NAME));
    lineStyleComboBox7.setRenderer(new LineStyleComboBoxRenderer());
    lineStyleComboBox7.setSelectedItem(ChartStyle.floatStyleToString(selectedLineStyles[6]));
    lineStyleComboBox7.setMinimumSize(new Dimension(150, 25));
    lineStyleComboBox7.setPreferredSize(new Dimension(150, 25));

    lineLabel8.setText("Line 8");

    lineStyleComboBox8.setModel(new DefaultComboBoxModel(ChartStyle.LINE_STYLE_NAME));
    lineStyleComboBox8.setRenderer(new LineStyleComboBoxRenderer());
    lineStyleComboBox8.setSelectedItem(ChartStyle.floatStyleToString(selectedLineStyles[7]));
    lineStyleComboBox8.setMinimumSize(new Dimension(150, 25));
    lineStyleComboBox8.setPreferredSize(new Dimension(150, 25));

    lineLabel9.setText("Line 9");

    lineStyleComboBox9.setModel(new DefaultComboBoxModel(ChartStyle.LINE_STYLE_NAME));
    lineStyleComboBox9.setRenderer(new LineStyleComboBoxRenderer());
    lineStyleComboBox9.setSelectedItem(ChartStyle.floatStyleToString(selectedLineStyles[8]));
    lineStyleComboBox9.setMinimumSize(new Dimension(150, 25));
    lineStyleComboBox9.setPreferredSize(new Dimension(150, 25));

    GroupLayout lineStylePanelLayout = new GroupLayout(lineStylePanel);
    lineStylePanel.setLayout(lineStylePanelLayout);
    lineStylePanelLayout.setHorizontalGroup(lineStylePanelLayout
            .createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(lineStylePanelLayout.createSequentialGroup().addContainerGap()
                    .addGroup(lineStylePanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addGroup(lineStylePanelLayout.createSequentialGroup().addComponent(lineLabel1)
                                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(lineStyleComboBox1, GroupLayout.PREFERRED_SIZE,
                                            GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                            .addGroup(lineStylePanelLayout.createSequentialGroup().addComponent(lineLabel2)
                                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(lineStyleComboBox2, GroupLayout.PREFERRED_SIZE,
                                            GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                            .addGroup(lineStylePanelLayout.createSequentialGroup().addComponent(lineLabel3)
                                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(lineStyleComboBox3, GroupLayout.PREFERRED_SIZE,
                                            GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                            .addGroup(lineStylePanelLayout.createSequentialGroup().addComponent(lineLabel4)
                                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(lineStyleComboBox4, GroupLayout.PREFERRED_SIZE,
                                            GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                            .addGroup(lineStylePanelLayout.createSequentialGroup().addComponent(lineLabel5)
                                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(lineStyleComboBox5, GroupLayout.PREFERRED_SIZE,
                                            GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                            .addGroup(lineStylePanelLayout.createSequentialGroup().addComponent(lineLabel6)
                                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(lineStyleComboBox6, GroupLayout.PREFERRED_SIZE,
                                            GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                            .addGroup(lineStylePanelLayout.createSequentialGroup().addComponent(lineLabel7)
                                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(lineStyleComboBox7, GroupLayout.PREFERRED_SIZE,
                                            GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                            .addGroup(lineStylePanelLayout.createSequentialGroup().addComponent(lineLabel8)
                                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(lineStyleComboBox8, GroupLayout.PREFERRED_SIZE,
                                            GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                            .addGroup(lineStylePanelLayout.createSequentialGroup().addComponent(lineLabel9)
                                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(lineStyleComboBox9, GroupLayout.PREFERRED_SIZE,
                                            GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
                    .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
    lineStylePanelLayout
            .setVerticalGroup(lineStylePanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addGroup(lineStylePanelLayout.createSequentialGroup().addContainerGap()
                            .addGroup(lineStylePanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                    .addComponent(lineLabel1).addComponent(lineStyleComboBox1,
                                            GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                            GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(lineStylePanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                    .addComponent(lineLabel2).addComponent(lineStyleComboBox2,
                                            GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                            GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(lineStylePanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                    .addComponent(lineLabel3).addComponent(lineStyleComboBox3,
                                            GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                            GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(lineStylePanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                    .addComponent(lineLabel4).addComponent(lineStyleComboBox4,
                                            GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                            GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(lineStylePanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                    .addComponent(lineLabel5).addComponent(lineStyleComboBox5,
                                            GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                            GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(lineStylePanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                    .addComponent(lineLabel6).addComponent(lineStyleComboBox6,
                                            GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                            GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(lineStylePanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                    .addComponent(lineLabel7).addComponent(lineStyleComboBox7,
                                            GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                            GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(lineStylePanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                    .addComponent(lineLabel8).addComponent(lineStyleComboBox8,
                                            GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                            GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(lineStylePanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                    .addComponent(lineLabel9).addComponent(lineStyleComboBox9,
                                            GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                            GroupLayout.PREFERRED_SIZE))
                            .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

    displayPanel.setBorder(BorderFactory.createTitledBorder("Display Options"));

    legendPositionComboBox
            .setModel(new DefaultComboBoxModel(new String[] { "Bottom", "Left", "Top", "Right" }));
    legendPositionComboBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String s = legendPositionComboBox.getSelectedItem().toString();
            if ("Bottom".equals(s)) {
                prefs.setLegendPosition(RectangleEdge.BOTTOM);
            } else if ("Left".equals(s)) {
                prefs.setLegendPosition(RectangleEdge.LEFT);
            } else if ("Top".equals(s)) {
                prefs.setLegendPosition(RectangleEdge.TOP);
            } else {
                prefs.setLegendPosition(RectangleEdge.RIGHT);
            }

        }
    });

    legendCheckbox.setSelected(true);
    legendCheckbox.setText("Legend");
    legendCheckbox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (legendCheckbox.isSelected()) {
                prefs.setShowLegend(true);
            } else {
                prefs.setShowLegend(false);
            }
        }
    });

    markersCheckbox.setText("Point markers");
    markersCheckbox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (markersCheckbox.isSelected()) {
                prefs.setShowMarkers(true);
            } else {
                prefs.setShowMarkers(false);
            }
        }
    });

    orientationButtonGroup.add(horizontalRadioButton);
    horizontalRadioButton.setText("Horizontal orientation");
    horizontalRadioButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (horizontalRadioButton.isSelected()) {
                prefs.setChartOrientation(PlotOrientation.HORIZONTAL);
            }
        }
    });

    orientationButtonGroup.add(verticalRadioButton);
    verticalRadioButton.setSelected(true);
    verticalRadioButton.setText("Vertical orientation");
    verticalRadioButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (verticalRadioButton.isSelected()) {
                prefs.setChartOrientation(PlotOrientation.VERTICAL);
            }
        }
    });

    GroupLayout displayPanelLayout = new GroupLayout(displayPanel);
    displayPanel.setLayout(displayPanelLayout);
    displayPanelLayout.setHorizontalGroup(displayPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(displayPanelLayout.createSequentialGroup().addContainerGap().addGroup(displayPanelLayout
                    .createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addGroup(displayPanelLayout.createSequentialGroup().addGroup(displayPanelLayout
                            .createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(markersCheckbox)
                            .addGroup(displayPanelLayout.createSequentialGroup().addComponent(legendCheckbox)
                                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(legendPositionComboBox, 0, 89, Short.MAX_VALUE)))
                            .addGap(26, 26, 26))
                    .addGroup(displayPanelLayout.createSequentialGroup().addComponent(horizontalRadioButton)
                            .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(displayPanelLayout.createSequentialGroup().addComponent(verticalRadioButton)
                            .addGap(0, 0, Short.MAX_VALUE)))));
    displayPanelLayout.setVerticalGroup(displayPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(displayPanelLayout.createSequentialGroup().addContainerGap()
                    .addGroup(displayPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(legendCheckbox).addComponent(legendPositionComboBox,
                                    GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                    GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(markersCheckbox)
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(horizontalRadioButton)
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(verticalRadioButton)
                    .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

    sizePanel.setBorder(BorderFactory.createTitledBorder("Chart Size"));

    widthLabel.setText("Width");

    widthTextField.setText("450");
    widthTextField.setMaximumSize(new Dimension(100, 25));
    widthTextField.setMinimumSize(new Dimension(100, 25));
    widthTextField.setPreferredSize(new Dimension(100, 25));
    widthTextField.addFocusListener(new FocusListener() {
        @Override
        public void focusGained(FocusEvent e) {
            //do nothing
        }

        @Override
        public void focusLost(FocusEvent e) {
            String s = widthTextField.getText();
            try {
                int w = Integer.parseInt(s);
                prefs.setChartWidth(w);
            } catch (NumberFormatException ex) {
                widthTextField.setText("450");
            }
        }
    });

    heightLabel.setText("Height");

    heightTextField.setText("400");
    heightTextField.setMaximumSize(new Dimension(100, 25));
    heightTextField.setMinimumSize(new Dimension(100, 25));
    heightTextField.setPreferredSize(new Dimension(100, 25));
    heightTextField.addFocusListener(new FocusListener() {
        @Override
        public void focusGained(FocusEvent e) {
            //do nothing
        }

        @Override
        public void focusLost(FocusEvent e) {
            try {
                String s = heightTextField.getText();
                int h = Integer.parseInt(s);
                prefs.setChartHeight(h);
            } catch (NumberFormatException ex) {
                heightTextField.setText("400");
            }
        }
    });

    lineWidthLabel.setText("Line width");

    lineWidthTextField.setText("1.0");
    lineWidthTextField.setMaximumSize(new Dimension(100, 25));
    lineWidthTextField.setMinimumSize(new Dimension(100, 25));
    lineWidthTextField.setPreferredSize(new Dimension(100, 25));
    lineWidthTextField.addFocusListener(new FocusListener() {
        @Override
        public void focusGained(FocusEvent e) {
            //do nothing
        }

        @Override
        public void focusLost(FocusEvent e) {
            try {

                String s = lineWidthTextField.getText();
                float lw = Float.parseFloat(s);
                prefs.setChartLineWidth(lw);
            } catch (NumberFormatException ex) {
                lineWidthTextField.setText("1.0");
            }
        }
    });

    GroupLayout sizePanelLayout = new GroupLayout(sizePanel);
    sizePanel.setLayout(sizePanelLayout);
    sizePanelLayout.setHorizontalGroup(sizePanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(sizePanelLayout.createSequentialGroup().addContainerGap()
                    .addGroup(sizePanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addComponent(widthLabel).addComponent(heightLabel).addComponent(lineWidthLabel))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(sizePanelLayout.createParallelGroup(GroupLayout.Alignment.CENTER)
                            .addComponent(widthTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                    GroupLayout.PREFERRED_SIZE)
                            .addComponent(heightTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                    GroupLayout.PREFERRED_SIZE)
                            .addComponent(lineWidthTextField, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                    .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
    sizePanelLayout.setVerticalGroup(sizePanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(sizePanelLayout.createSequentialGroup().addContainerGap()
                    .addGroup(sizePanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(widthLabel).addComponent(widthTextField, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(sizePanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(heightLabel).addComponent(heightTextField, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(sizePanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(lineWidthLabel).addComponent(lineWidthTextField,
                                    GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                    GroupLayout.PREFERRED_SIZE))
                    .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

    resetButton.setText("Reset to Default Chart Options");
    resetButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            resetPanel();
        }
    });

    GroupLayout layout = new GroupLayout(this);
    this.setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout
            .createSequentialGroup().addContainerGap()
            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout
                    .createSequentialGroup()
                    .addGroup(layout.createParallelGroup(GroupLayout.Alignment.TRAILING, false)
                            .addComponent(displayPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE,
                                    Short.MAX_VALUE)
                            .addComponent(colorPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE,
                                    Short.MAX_VALUE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
                            .addComponent(lineStylePanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE,
                                    Short.MAX_VALUE)
                            .addComponent(sizePanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE,
                                    Short.MAX_VALUE)))
                    .addComponent(resetButton))
            .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
    layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup().addContainerGap()
                    .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
                            .addComponent(colorPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE,
                                    Short.MAX_VALUE)
                            .addComponent(lineStylePanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE,
                                    Short.MAX_VALUE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
                            .addComponent(sizePanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE,
                                    Short.MAX_VALUE)
                            .addComponent(displayPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE,
                                    Short.MAX_VALUE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(resetButton)
                    .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
}

From source file:FirstForm.java

private void initSpinners() {
    defaultBorder = this.indiceSpinner.getBorder();
    this.indiceSpinner.setModel(new SpinnerNumberModel(0.0, 0.0, 30.0, 0.1));
    this.faseModuladoraSpinner.setModel(new SpinnerNumberModel(0.0, 0.0, 100000.0, 0.1));
    this.fasePortadoraSpinner.setModel(new SpinnerNumberModel(0.0, 0.0, 100000.0, 0.1));
    this.amplitudModuladoraSpinner.setModel(new SpinnerNumberModel(0.0, 0.0, 100000.0, 0.1));
    this.amplitudPortadoraSpinner.setModel(new SpinnerNumberModel(0.0, 0.0, 100000.0, 0.1));
    this.frecuenciaPortadoraSpinner.setModel(new SpinnerNumberModel(0.0, 0.0, 100000.0, 0.1));
    this.frecuenciaModuladoraSpinner.setModel(new SpinnerNumberModel(0.0, 0.0, 100000.0, 0.1));
    this.sensibilidadSpinner.setModel(new SpinnerNumberModel(0.0, 0.0, 100000.0, 0.1));
    this.sensibilidadSpinner.addChangeListener(new ChangeListener() {

        @Override//w w w .  j ava 2 s  .co m
        public void stateChanged(ChangeEvent e) {
            indiceOrSensibility = false;
            indiceSpinner.setBorder(defaultBorder);
            sensibilidadSpinner.setBorder(BorderFactory.createLineBorder(new Color(39, 174, 96)));
        }
    });
    this.indiceSpinner.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            indiceOrSensibility = true;
            sensibilidadSpinner.setBorder(defaultBorder);
            indiceSpinner.setBorder(BorderFactory.createLineBorder(new Color(39, 174, 96)));
        }
    });

    this.indiceSpinner.addFocusListener(new FocusListener() {

        @Override
        public void focusGained(FocusEvent e) {
            //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            indiceOrSensibility = true;
            sensibilidadSpinner.setBorder(defaultBorder);
            indiceSpinner.setBorder(BorderFactory.createLineBorder(new Color(39, 174, 96)));
        }

        @Override
        public void focusLost(FocusEvent e) {
            //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
    });
    this.sensibilidadSpinner.addFocusListener(new FocusListener() {

        @Override
        public void focusGained(FocusEvent e) {
            //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            indiceOrSensibility = false;
            indiceSpinner.setBorder(defaultBorder);
            sensibilidadSpinner.setBorder(BorderFactory.createLineBorder(new Color(39, 174, 96)));
        }

        @Override
        public void focusLost(FocusEvent e) {
            //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
    });
}

From source file:se.llbit.chunky.renderer.ui.RenderControls.java

private JPanel buildGeneralPane() {
    JLabel canvasSizeLbl = new JLabel("Canvas size:");
    JLabel canvasSizeAdvisory = new JLabel("Note: Actual image size may not be the same as the window size!");

    canvasSizeCB.setEditable(true);//from   www .  j a  v a 2 s.  c  o m
    canvasSizeCB.addItem("400x400");
    canvasSizeCB.addItem("1024x768");
    canvasSizeCB.addItem("960x540");
    canvasSizeCB.addItem("1920x1080");
    canvasSizeCB.addActionListener(canvasSizeListener);
    final JTextField canvasSizeEditor = (JTextField) canvasSizeCB.getEditor().getEditorComponent();
    canvasSizeEditor.addFocusListener(new FocusListener() {
        @Override
        public void focusLost(FocusEvent e) {
        }

        @Override
        public void focusGained(FocusEvent e) {
            canvasSizeEditor.selectAll();
        }
    });

    updateCanvasSizeField();

    loadSceneBtn.setText("Load Scene");
    loadSceneBtn.setIcon(Icon.load.imageIcon());
    loadSceneBtn.addActionListener(loadSceneListener);

    JButton loadSelectedChunksBtn = new JButton("Load Selected Chunks");
    loadSelectedChunksBtn.setToolTipText("Load the chunks that are currently selected in the map view");
    loadSelectedChunksBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            sceneMan.loadChunks(chunky.getWorld(), chunky.getSelectedChunks());
        }
    });

    JButton reloadChunksBtn = new JButton("Reload Chunks");
    reloadChunksBtn.setIcon(Icon.reload.imageIcon());
    reloadChunksBtn.setToolTipText("Reload all chunks in the scene");
    reloadChunksBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            sceneMan.reloadChunks();
        }
    });

    openSceneDirBtn.setText("Open Scene Directory");
    openSceneDirBtn.setToolTipText("Open the directory where Chunky stores scene descriptions and renders");
    openSceneDirBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            try {
                if (Desktop.isDesktopSupported()) {
                    Desktop.getDesktop().open(context.getSceneDirectory());
                }
            } catch (IOException e) {
                Log.warn("Failed to open scene directory", e);
            }
        }
    });
    openSceneDirBtn.setVisible(Desktop.isDesktopSupported());

    loadSceneBtn.setToolTipText("This replaces the current scene!");
    JButton setCanvasSizeBtn = new JButton("Apply");
    setCanvasSizeBtn.setToolTipText("Set the canvas size to the value in the field");
    setCanvasSizeBtn.addActionListener(canvasSizeListener);

    JButton halveCanvasSizeBtn = new JButton("Halve");
    halveCanvasSizeBtn.setToolTipText("Halve the canvas width and height");
    halveCanvasSizeBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            int width = renderMan.scene().canvasWidth() / 2;
            int height = renderMan.scene().canvasHeight() / 2;
            setCanvasSize(width, height);
        }
    });
    JButton doubleCanvasSizeBtn = new JButton("Double");
    doubleCanvasSizeBtn.setToolTipText("Double the canvas width and height");
    doubleCanvasSizeBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            int width = renderMan.scene().canvasWidth() * 2;
            int height = renderMan.scene().canvasHeight() * 2;
            setCanvasSize(width, height);
        }
    });

    JButton makeDefaultBtn = new JButton("Make Default");
    makeDefaultBtn.setToolTipText("Make the current canvas size the default");
    makeDefaultBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            PersistentSettings.set3DCanvasSize(renderMan.scene().canvasWidth(),
                    renderMan.scene().canvasHeight());
        }
    });

    JSeparator sep1 = new JSeparator();
    JSeparator sep2 = new JSeparator();

    biomeColorsCB.setText("enable biome colors");
    updateBiomeColorsCB();

    saveDumpsCB.setText("save dump once every ");
    saveDumpsCB.addActionListener(saveDumpsListener);
    updateSaveDumpsCheckBox();

    String[] frequencyStrings = new String[dumpFrequencies.length];
    for (int i = 0; i < dumpFrequencies.length; ++i) {
        frequencyStrings[i] = Integer.toString(dumpFrequencies[i]);
    }
    dumpFrequencyCB.setModel(new DefaultComboBoxModel(frequencyStrings));
    dumpFrequencyCB.setEditable(true);
    dumpFrequencyCB.addActionListener(dumpFrequencyListener);
    updateDumpFrequencyField();

    saveSnapshotsCB.addActionListener(saveSnapshotListener);
    updateSaveSnapshotCheckBox();

    yCutoff.update();

    JPanel panel = new JPanel();
    GroupLayout layout = new GroupLayout(panel);
    panel.setLayout(layout);
    layout.setHorizontalGroup(layout.createSequentialGroup().addContainerGap()
            .addGroup(layout.createParallelGroup()
                    .addGroup(layout.createSequentialGroup().addComponent(loadSceneBtn)
                            .addPreferredGap(ComponentPlacement.RELATED).addComponent(openSceneDirBtn))
                    .addGroup(layout.createSequentialGroup().addComponent(loadSelectedChunksBtn)
                            .addPreferredGap(ComponentPlacement.RELATED).addComponent(reloadChunksBtn))
                    .addComponent(sep1)
                    .addGroup(layout.createSequentialGroup().addComponent(canvasSizeLbl)
                            .addPreferredGap(ComponentPlacement.RELATED)
                            .addComponent(canvasSizeCB, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(ComponentPlacement.RELATED).addComponent(setCanvasSizeBtn)
                            .addPreferredGap(ComponentPlacement.RELATED).addComponent(makeDefaultBtn))
                    .addGroup(layout.createSequentialGroup().addComponent(halveCanvasSizeBtn)
                            .addPreferredGap(ComponentPlacement.RELATED).addComponent(doubleCanvasSizeBtn))
                    .addComponent(canvasSizeAdvisory).addComponent(sep2).addComponent(biomeColorsCB)
                    .addGroup(layout.createSequentialGroup().addComponent(saveDumpsCB)
                            .addComponent(dumpFrequencyCB, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
                            .addComponent(dumpFrequencyLbl).addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(saveSnapshotsCB).addGroup(yCutoff.horizontalGroup(layout)))
            .addContainerGap());
    layout.setVerticalGroup(layout.createSequentialGroup().addContainerGap()
            .addGroup(layout.createParallelGroup().addComponent(loadSceneBtn).addComponent(openSceneDirBtn))
            .addPreferredGap(ComponentPlacement.UNRELATED)
            .addGroup(layout
                    .createParallelGroup().addComponent(loadSelectedChunksBtn).addComponent(reloadChunksBtn))
            .addPreferredGap(ComponentPlacement.UNRELATED)
            .addComponent(
                    sep1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(ComponentPlacement.UNRELATED)
            .addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(canvasSizeLbl)
                    .addComponent(canvasSizeCB, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE,
                            GroupLayout.PREFERRED_SIZE)
                    .addComponent(setCanvasSizeBtn).addComponent(makeDefaultBtn))
            .addPreferredGap(ComponentPlacement.RELATED)
            .addGroup(layout.createParallelGroup().addComponent(halveCanvasSizeBtn)
                    .addComponent(doubleCanvasSizeBtn))
            .addPreferredGap(ComponentPlacement.RELATED).addComponent(canvasSizeAdvisory)
            .addPreferredGap(ComponentPlacement.UNRELATED)
            .addComponent(sep2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                    GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(ComponentPlacement.UNRELATED).addComponent(biomeColorsCB)
            .addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(saveDumpsCB)
                    .addComponent(dumpFrequencyCB).addComponent(dumpFrequencyLbl))
            .addComponent(saveSnapshotsCB).addPreferredGap(ComponentPlacement.UNRELATED)
            .addGroup(yCutoff.verticalGroup(layout)).addContainerGap());
    return panel;
}

From source file:userinterface.properties.GUIGraphHandler.java

public void plotNewFunction() {

    JDialog dialog;/*w  w  w.ja va 2 s  . co  m*/
    JRadioButton radio2d, radio3d, newGraph, existingGraph;
    JTextField functionField, seriesName;
    JButton ok, cancel;
    JComboBox<String> chartOptions;
    JLabel example;

    //init all the fields of the dialog
    dialog = new JDialog(GUIPrism.getGUI());
    radio2d = new JRadioButton("2D");
    radio3d = new JRadioButton("3D");
    newGraph = new JRadioButton("New Graph");
    existingGraph = new JRadioButton("Exisiting");
    chartOptions = new JComboBox<String>();
    functionField = new JTextField();
    ok = new JButton("Plot");
    cancel = new JButton("Cancel");
    seriesName = new JTextField();
    example = new JLabel("<html><font size=3 color=red>Example:</font><font size=3>x/2 + 5</font></html>");
    example.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseEntered(MouseEvent e) {
            example.setCursor(new Cursor(Cursor.HAND_CURSOR));
            example.setForeground(Color.BLUE);
        }

        @Override
        public void mouseExited(MouseEvent e) {
            example.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
            example.setForeground(Color.BLACK);
        }

        @Override
        public void mouseClicked(MouseEvent e) {

            if (e.getButton() == MouseEvent.BUTTON1) {

                if (radio2d.isSelected()) {
                    functionField.setText("x/2 + 5");
                } else {
                    functionField.setText("x+y+5");
                }

                functionField.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 15));
                functionField.setForeground(Color.BLACK);

            }
        }

    });

    //set dialog properties
    dialog.setSize(400, 350);
    dialog.setTitle("Plot a new function");
    dialog.setModal(true);
    dialog.setLayout(new BoxLayout(dialog.getContentPane(), BoxLayout.Y_AXIS));
    dialog.setLocationRelativeTo(GUIPrism.getGUI());

    //add every component to their dedicated panels
    JPanel graphTypePanel = new JPanel(new FlowLayout());
    graphTypePanel.setBorder(BorderFactory
            .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Function type"));
    graphTypePanel.add(radio2d);
    graphTypePanel.add(radio3d);

    JPanel functionFieldPanel = new JPanel(new BorderLayout());
    functionFieldPanel.setBorder(BorderFactory
            .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Function"));
    functionFieldPanel.add(functionField, BorderLayout.CENTER);
    functionFieldPanel.add(example, BorderLayout.SOUTH);

    JPanel chartSelectPanel = new JPanel();
    chartSelectPanel.setLayout(new BoxLayout(chartSelectPanel, BoxLayout.Y_AXIS));
    chartSelectPanel.setBorder(BorderFactory
            .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Plot function to"));
    JPanel radioPlotPanel = new JPanel(new FlowLayout());
    radioPlotPanel.add(newGraph);
    radioPlotPanel.add(existingGraph);
    JPanel chartOptionsPanel = new JPanel(new FlowLayout());
    chartOptionsPanel.add(chartOptions);
    chartSelectPanel.add(radioPlotPanel);
    chartSelectPanel.add(chartOptionsPanel);

    JPanel bottomControlPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    bottomControlPanel.add(ok);
    bottomControlPanel.add(cancel);

    JPanel seriesNamePanel = new JPanel(new BorderLayout());
    seriesNamePanel.setBorder(BorderFactory
            .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Series name"));
    seriesNamePanel.add(seriesName, BorderLayout.CENTER);

    // add all the panels to the dialog

    dialog.add(graphTypePanel);
    dialog.add(functionFieldPanel);
    dialog.add(chartSelectPanel);
    dialog.add(seriesNamePanel);
    dialog.add(bottomControlPanel);

    // do all the enables and set properties

    radio2d.setSelected(true);
    newGraph.setSelected(true);
    chartOptions.setEnabled(false);
    functionField.setText("Add function expression here....");
    functionField.setFont(new Font(Font.SANS_SERIF, Font.ITALIC, 15));
    functionField.setForeground(Color.GRAY);
    seriesName.setText("New function");
    ok.setMnemonic('P');
    cancel.setMnemonic('C');
    example.setToolTipText("click to try out");

    ok.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "ok");
    ok.getActionMap().put("ok", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            ok.doClick();
        }
    });

    cancel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
            "cancel");
    cancel.getActionMap().put("cancel", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            cancel.doClick();
        }
    });

    boolean found = false;

    for (int i = 0; i < theTabs.getTabCount(); i++) {

        if (theTabs.getComponentAt(i) instanceof Graph) {
            chartOptions.addItem(getGraphName(i));
            found = true;
        }
    }

    if (!found) {

        existingGraph.setEnabled(false);
        chartOptions.setEnabled(false);
    }

    //add all the action listeners

    radio2d.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {

            if (radio2d.isSelected()) {

                radio3d.setSelected(false);

                if (chartOptions.getItemCount() > 0) {
                    existingGraph.setEnabled(true);
                    chartOptions.setEnabled(true);
                }

                example.setText(
                        "<html><font size=3 color=red>Example:</font><font size=3>x/2 + 5</font></html>");
            }
        }
    });

    radio3d.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {

            if (radio3d.isSelected()) {

                radio2d.setSelected(false);
                newGraph.setSelected(true);
                existingGraph.setEnabled(false);
                chartOptions.setEnabled(false);
                example.setText("<html><font size=3 color=red>Example:</font><font size=3>x+y+5</font></html>");

            }

        }
    });

    newGraph.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {

            if (newGraph.isSelected()) {
                existingGraph.setSelected(false);
                chartOptions.setEnabled(false);
            }
        }
    });

    existingGraph.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {

            if (existingGraph.isSelected()) {

                newGraph.setSelected(false);
                chartOptions.setEnabled(true);
            }
        }
    });

    ok.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {

            String function = functionField.getText();

            Expression expr = null;

            try {

                expr = GUIPrism.getGUI().getPrism().parseSingleExpressionString(function);
                expr = (Expression) expr.accept(new ASTTraverseModify() {

                    @Override
                    public Object visit(ExpressionIdent e) throws PrismLangException {
                        return new ExpressionConstant(e.getName(), TypeDouble.getInstance());
                    }

                });

                expr.typeCheck();
                expr.semanticCheck();

            } catch (PrismLangException e1) {

                // for copying style
                JLabel label = new JLabel();

                // html content in our case the error we want to show
                JEditorPane ep = new JEditorPane("text/html",
                        "<html> There was an error parsing the function. To read about what built-in"
                                + " functions are supported <br>and some more information on the functions, visit "
                                + "<a href='http://www.prismmodelchecker.org/manual/ThePRISMLanguage/Expressions'>Prism expressions site</a>."
                                + "<br><br><font color=red>Error: </font>" + e1.getMessage() + " </html>");

                // handle link events
                ep.addHyperlinkListener(new HyperlinkListener() {
                    @Override
                    public void hyperlinkUpdate(HyperlinkEvent e) {
                        if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) {
                            try {
                                Desktop.getDesktop().browse(e.getURL().toURI());
                            } catch (IOException | URISyntaxException e1) {

                                e1.printStackTrace();
                            }
                        }
                    }
                });
                ep.setEditable(false);
                ep.setBackground(label.getBackground());

                // show the error dialog
                JOptionPane.showMessageDialog(dialog, ep, "Parse Error", JOptionPane.ERROR_MESSAGE);
                return;
            }

            if (radio2d.isSelected()) {

                ParametricGraph graph = null;

                if (newGraph.isSelected()) {

                    graph = new ParametricGraph("");
                } else {

                    for (int i = 0; i < theTabs.getComponentCount(); i++) {

                        if (theTabs.getTitleAt(i).equals(chartOptions.getSelectedItem())) {

                            graph = (ParametricGraph) theTabs.getComponent(i);
                        }
                    }

                }

                dialog.dispose();
                defineConstantsAndPlot(expr, graph, seriesName.getText(), newGraph.isSelected(), true);

            } else if (radio3d.isSelected()) {

                try {

                    expr = (Expression) expr.accept(new ASTTraverseModify() {
                        @Override
                        public Object visit(ExpressionIdent e) throws PrismLangException {
                            return new ExpressionConstant(e.getName(), TypeDouble.getInstance());
                        }

                    });

                    expr.semanticCheck();
                    expr.typeCheck();

                } catch (PrismLangException e1) {
                    e1.printStackTrace();
                }

                if (expr.getAllConstants().size() < 2) {

                    JOptionPane.showMessageDialog(dialog,
                            "There are not enough variables in the function to plot a 3D chart!", "Error",
                            JOptionPane.ERROR_MESSAGE);
                    return;
                }

                // its always a new graph
                ParametricGraph3D graph = new ParametricGraph3D(expr);
                dialog.dispose();
                defineConstantsAndPlot(expr, graph, seriesName.getText(), true, false);
            }

            dialog.dispose();
        }
    });

    cancel.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            dialog.dispose();
        }
    });

    // we will show info about the function when field is out of focus
    functionField.addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent e) {

            if (!functionField.getText().equals("")) {
                return;
            }

            functionField.setText("Add function expression here....");
            functionField.setFont(new Font(Font.SANS_SERIF, Font.ITALIC, 15));
            functionField.setForeground(Color.GRAY);
        }

        @Override
        public void focusGained(FocusEvent e) {

            if (!functionField.getText().equals("Add function expression here....")) {
                return;
            }

            functionField.setForeground(Color.BLACK);
            functionField.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 15));
            functionField.setText("");
        }
    });

    // show the dialog
    dialog.setVisible(true);
}

From source file:edu.ku.brc.specify.tasks.subpane.qb.QueryFieldPanel.java

/**
 * @param iconSize/*from w w w.j a v  a  2s  .  c o m*/
 * @param returnWidths
 * @return
 */
protected int[] buildControlLayout(final IconManager.IconSize iconSize, final boolean returnWidths,
        final Component saveBtn) {
    FocusListener focusListener = new FocusListener() {

        /*
         * (non-Javadoc)
         * 
         * @see java.awt.event.FocusListener#focusGained(java.awt.event.FocusEvent)
         */
        // @Override
        public void focusGained(FocusEvent e) {
            //Checking oppositeComponent to work around
            //weird behavior after addBtn is clicked which
            //causes top queryFieldPanel to be selected.
            if (ownerQuery.getAddBtn() != null && e.getOppositeComponent() != ownerQuery.getAddBtn()) {
                ownerQuery.selectQFP(QueryFieldPanel.this);
            }

        }

        /*
         * (non-Javadoc)
         * 
         * @see java.awt.event.FocusListener#focusLost(java.awt.event.FocusEvent)
         */
        // @Override
        public void focusLost(FocusEvent e) {
            // nada
        }

    };

    KeyListener enterListener = new KeyListener() {

        @Override
        public void keyPressed(KeyEvent arg0) {
            //nuthin
        }

        @Override
        public void keyReleased(KeyEvent arg0) {
            //nuthin
        }

        @Override
        public void keyTyped(KeyEvent arg0) {
            if (arg0.getKeyChar() == KeyEvent.VK_ENTER && ownerQuery != null) {
                ownerQuery.doSearch();
            }

        }

    };

    comparators = getComparatorList(fieldQRI);
    //XXX need to build schemaItem for header panel too...
    if (schemaMapping != null) {
        schemaItemCBX = edu.ku.brc.ui.UIHelper.createComboBox();
        schemaItemCBX.addItem("empty"); //to work around validator blow up for empty lists.
        DataChangeNotifier dcnsi = validator.hookupComponent(schemaItemCBX, "sicbx", UIValidator.Type.Changed,
                "", true);
        schemaItemCBX.addActionListener(dcnsi);

        schemaItemCBX.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                if (!QueryFieldPanel.this.ownerQuery.isUpdatingAvailableConcepts()) {
                    if (e.getStateChange() == ItemEvent.SELECTED) {
                        if (e.getItem() instanceof SpExportSchemaItem) {
                            QueryFieldPanel.this.schemaItem = (SpExportSchemaItem) e.getItem();
                        } else {
                            SpExportSchemaItemMapping m = QueryFieldPanel.this.getItemMapping();
                            SpExportSchemaItem si = QueryFieldPanel.this.schemaItem;
                            String item = e.getItem().toString();
                            if (StringUtils.isNotBlank(item)
                                    && ownerQuery.isAvailableExportFieldName(QueryFieldPanel.this, item)) {
                                if (m != null) {
                                    m.setExportedFieldName(e.getItem().toString());
                                }
                                if (si != null) {
                                    si.setFieldName(e.getItem().toString());
                                }
                            } else {
                                if (StringUtils.isBlank(item)) {
                                    UIRegistry.displayErrorDlgLocalized(
                                            "QueryFieldPanel.ExportFieldNameInvalid", item);
                                } else {
                                    UIRegistry.displayErrorDlgLocalized(
                                            "QueryFieldPanel.ExportFieldNameAlreadyUsed", item);
                                }
                                schemaItemCBX.setSelectedIndex(0);
                            }
                        }
                        ownerQuery.updateAvailableConcepts();
                    }
                }
            }
        });
    } else {
        schemaItemCBX = null;
    }

    iconLabel = new JLabel(icon);
    iconLabel.addFocusListener(focusListener);
    String fieldLabelText = fieldQRI != null ? fieldQRI.getTitle() : "WXYZ";
    if (fieldQRI instanceof RelQRI) {
        DBRelationshipInfo.RelationshipType relType = ((RelQRI) fieldQRI).getRelationshipInfo().getType();
        if (relType.equals(DBRelationshipInfo.RelationshipType.OneToMany)
                || relType.equals(DBRelationshipInfo.RelationshipType.ManyToMany)) {
            fieldLabelText += " " + UIRegistry.getResourceString("QB_AGGREGATED");
        } else {
            fieldLabelText += " " + UIRegistry.getResourceString("QB_FORMATTED");
        }

    }
    fieldLabel = createLabel(fieldLabelText);
    fieldLabel.addFocusListener(focusListener);
    fieldLabel.addKeyListener(enterListener);
    isNotCheckbox = createCheckBox("isNotCheckbox");
    isNotCheckbox.addFocusListener(focusListener);
    isNotCheckbox.addKeyListener(enterListener);
    operatorCBX = createComboBox(comparators);
    operatorCBX.addFocusListener(focusListener);
    operatorCBX.addKeyListener(enterListener);
    boolean isBool = fieldQRI != null && fieldQRI.getDataClass().equals(Boolean.class);
    if (!isBool) {
        operatorCBX.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    criteria.setVisible(!operatorCBX.getSelectedItem().equals(SpQueryField.OperatorType.EMPTY));
                }
            }
        });
    }
    if (pickList == null) {
        boolean hasBetweenOp = false;
        for (int o = 0; o < comparators.length; o++) {
            if (comparators[o].equals(OperatorType.BETWEEN)) {
                hasBetweenOp = true;
                break;
            }
        }
        if (hasBetweenOp) {
            criteria = new CriteriaPair(enterListener);
            operatorCBX.addActionListener(this);
        } else {
            criteria = createTextField("1");
            criteria.addKeyListener(enterListener);
        }
    } else {
        criteria = createPickList(saveBtn);
        if (!ownerQuery.isPromptMode()) {
            ((PickListCriteriaCombo) criteria)
                    .setCurrentOp((SpQueryField.OperatorType) operatorCBX.getModel().getElementAt(0));
        }
        criteria.addKeyListener(enterListener);
        operatorCBX.addItemListener(new ItemListener() {

            /*
             * (non-Javadoc)
             * 
             * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
             */
            //@Override
            public void itemStateChanged(ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    // System.out.println("setting curront op");
                    ((PickListCriteriaCombo) criteria)
                            .setCurrentOp((SpQueryField.OperatorType) operatorCBX.getSelectedItem());
                }
            }

        });
    }
    //criteria.addFocusListener(focusListener);

    sortCheckbox = new MultiStateIconButon(
            new ImageIcon[] { IconManager.getImage("GrayDot", IconManager.IconSize.Std16),
                    IconManager.getImage("UpArrow", IconManager.IconSize.Std16),
                    IconManager.getImage("DownArrow", IconManager.IconSize.Std16) });
    DataChangeNotifier dcn = validator.hookupComponent(sortCheckbox, "scb", UIValidator.Type.Changed, "", true);
    sortCheckbox.addFocusListener(focusListener);
    sortCheckbox.addActionListener(dcn);
    sortCheckbox.addKeyListener(enterListener);
    if (!this.ownerQuery.isPromptMode()) {
        isEnforcedCkbx = createCheckBox("isEnforcedCkbx");
        dcn = validator.hookupComponent(isEnforcedCkbx, "iecb", UIValidator.Type.Changed, "", true);
        isEnforcedCkbx.addActionListener(dcn);
        isEnforcedCkbx.addFocusListener(focusListener);
        isEnforcedCkbx.addKeyListener(enterListener);
    }
    if (!this.ownerQuery.isPromptMode()) {
        isDisplayedCkbx = createCheckBox("isDisplayedCkbx");
        dcn = validator.hookupComponent(isDisplayedCkbx, "idcb", UIValidator.Type.Changed, "", true);
        isDisplayedCkbx.addFocusListener(focusListener);
        isDisplayedCkbx.addKeyListener(enterListener);
        isDisplayedCkbx.addActionListener(dcn);
        isDisplayedCkbx.addActionListener(new ActionListener() {

            /* (non-Javadoc)
             * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
             */
            @Override
            public void actionPerformed(ActionEvent arg0) {
                SwingUtilities.invokeLater(new Runnable() {

                    /* (non-Javadoc)
                     * @see java.lang.Runnable#run()
                     */
                    @Override
                    public void run() {
                        sortCheckbox.setEnabled(isDisplayedCkbx.isSelected());
                        ownerQuery.changeNotification(QueryFieldPanel.this);
                    }
                });
            }
        });
        isPromptCkbx = createCheckBox("isPromptCkbx");
        dcn = validator.hookupComponent(isPromptCkbx, "ipcb", UIValidator.Type.Changed, "", true);
        isPromptCkbx.addActionListener(dcn);
        isPromptCkbx.addFocusListener(focusListener);
        isPromptCkbx.addKeyListener(enterListener);
        closeBtn = edu.ku.brc.ui.UIHelper.createIconBtn("Close", "QB_REMOVE_FLD", new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                boolean clearIt = schemaItem != null;
                ownerQuery.removeQueryFieldItem((QueryFieldPanel) ((JComponent) ae.getSource()).getParent());
                if (clearIt) {
                    setField(null, null);
                }
            }
        });
        closeBtn.setEnabled(true);
        closeBtn.setFocusable(false);
        closeBtn.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseEntered(MouseEvent e) {
                ((JButton) e.getSource()).setIcon(IconManager.getIcon("CloseHover"));
                super.mouseEntered(e);
            }

            @Override
            public void mouseExited(MouseEvent e) {
                ((JButton) e.getSource()).setIcon(IconManager.getIcon("Close"));
                super.mouseExited(e);
            }

        });
    } else {
        isDisplayedCkbx = null;
        this.isPromptCkbx = null;
        this.isEnforcedCkbx = null;
        this.closeBtn = null;
    }

    JComponent[] qComps = { iconLabel, fieldLabel, isNotCheckbox, operatorCBX, criteria, sortCheckbox,
            isDisplayedCkbx, isPromptCkbx, isEnforcedCkbx, closeBtn, null };
    JComponent[] sComps = { schemaItemCBX, iconLabel, fieldLabel, isNotCheckbox, operatorCBX, criteria,
            sortCheckbox, isDisplayedCkbx, isEnforcedCkbx, closeBtn, null };
    // 0 1 2 3 4 5 6 7 8 9
    if (schemaMapping == null) {
        comps = qComps;
    } else {
        comps = sComps;
    }

    StringBuilder sb = new StringBuilder();
    Integer[] qFixedCmps = { 300 };
    Integer[] sFixedCmps = { 268, 300 };
    Integer[] fixedCmps;
    if (schemaMapping != null) {
        fixedCmps = sFixedCmps;
    } else {
        fixedCmps = qFixedCmps;
    }
    if (columnDefStr == null) {
        for (int i = 0; i < comps.length; i++) {
            sb.append(i == 0 ? "" : ",");
            if (isCenteredComp(i))
                sb.append("c:");
            if (i >= fixedCmps.length) {
                sb.append("p");
            } else {
                sb.append(fixedCmps[i] + "px");
            }
            if (isGrowComp(i))
                sb.append(":g");
            sb.append(",4px");
        }
    } else {
        sb.append(columnDefStr);
    }

    PanelBuilder builder = new PanelBuilder(new FormLayout("3px, " + sb.toString() + ", 3px", "3px, p, 3px"),
            this);
    CellConstraints cc = new CellConstraints();

    int col = 1;
    for (JComponent comp : comps) {
        if (comp != null) {
            builder.add(comp, cc.xy(col + 1, 2));
        }
        col += 2;
    }

    if (fieldQRI != null) {
        icon = IconManager.getIcon(fieldQRI.getTableInfo().getName(), iconSize);
        setIcon(icon);
    }
    if (!ownerQuery.isPromptMode()) {
        isDisplayedCkbx.setSelected(true);
        isPromptCkbx.setSelected(!(fieldQRI instanceof RelQRI));
        isEnforcedCkbx.setSelected(false);
    }

    if (fieldQRI == null && !returnWidths) {
        for (int c = 1; c < comps.length; c++) {
            if (comps[c] != null) {
                comps[c].setVisible(false);
            }
        }
    } else {
        // for now
        boolean isRel = fieldQRI != null && fieldQRI instanceof RelQRI;
        boolean isTreeLevel = fieldQRI instanceof TreeLevelQRI;
        isNotCheckbox.setVisible(!isRel || pickList != null);
        operatorCBX.setVisible(!isRel || pickList != null);
        criteria.setVisible((!isRel && !isBool) || pickList != null);
        if (schemaMapping != null) {
            this.sortCheckbox.setVisible(!(isTreeLevel || isRel));
        } else {
            if (!isRel) {
                this.sortCheckbox.setVisible(true);
            } else {
                this.sortCheckbox.setVisible(
                        ((RelQRI) fieldQRI).getRelationshipInfo().getType() != RelationshipType.OneToMany);
            }
        }

        if (!ownerQuery.isPromptMode()) {
            isDisplayedCkbx.setVisible(!isRel);
            isPromptCkbx.setVisible(!isRel);
            isEnforcedCkbx.setVisible(!isRel);
        }
    }
    validate();
    doLayout();

    int[] widths = null;
    if (returnWidths) {
        widths = new int[comps.length];
        for (int i = 0; i < comps.length; i++) {
            widths[i] = comps[i] != null ? comps[i].getSize().width : 0;
        }
        if (this.schemaMapping == null) {
            widths[0] = iconSize.size();
            widths[1] = 200;
        } else {
            widths[1] = iconSize.size();
            widths[2] = 200;
        }
    }
    return widths;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    return tickerPanel;
}

From source file:edu.ku.brc.ui.UIHelper.java

/**
 * Creates an icon button with tooltip and action listener.
 * @param iconName the name of the icon (use default size)
 * @param toolTipTextKey the tooltip text resource bundle key
 * @param al the action listener//from   ww w.j a  v a2s  . c  o  m
 * @param withEmptyBorder set an empyt border
 * @return the JButton icon button
 */
public static JButton createIconBtn(final String iconName, final IconManager.IconSize size,
        final String toolTipTextKey, final boolean withEmptyBorder, final Action action) {
    JButton btn = new JButton(action) {
        @Override
        public void setEnabled(boolean enabled) {
            super.setEnabled(enabled);
            setBorder(emptyBorder);
        }
    };

    btn.setOpaque(false);
    if (!withEmptyBorder) {
        btn.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseEntered(MouseEvent e) {
                if (((JButton) e.getSource()).isEnabled()) {
                    ((JButton) e.getSource()).setBorder(focusBorder);
                }
                super.mouseEntered(e);
            }

            @Override
            public void mouseExited(MouseEvent e) {
                if (((JButton) e.getSource()).isEnabled()) {
                    ((JButton) e.getSource()).setBorder(emptyBorder);
                }
                super.mouseExited(e);
            }

        });
        btn.addFocusListener(new FocusListener() {
            public void focusGained(FocusEvent e) {
                if (((JButton) e.getSource()).isEnabled()) {
                    ((JButton) e.getSource()).setBorder(focusBorder);
                }
            }

            public void focusLost(FocusEvent e) {
                if (((JButton) e.getSource()).isEnabled()) {
                    ((JButton) e.getSource()).setBorder(emptyBorder);
                }
            }

        });
        btn.setBorder(emptyBorder);
    }
    btn.setIcon(size != null ? IconManager.getIcon(iconName, size) : IconManager.getIcon(iconName));
    btn.setText(null);
    if (StringUtils.isNotEmpty(toolTipTextKey)) {
        btn.setToolTipText(getResourceString(toolTipTextKey));
    }
    btn.setEnabled(false);

    btn.setFocusable(true);
    btn.setMargin(new Insets(0, 0, 0, 0));
    setControlSize(btn);
    return btn;
}