de.unibayreuth.bayeos.goat.options.JOptionDialog.java Source code

Java tutorial

Introduction

Here is the source code for de.unibayreuth.bayeos.goat.options.JOptionDialog.java

Source

/*******************************************************************************
 * Copyright (c) 2011 University of Bayreuth - BayCEER.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v2.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * 
 * Contributors:
 *     University of Bayreuth - BayCEER - initial API and implementation
 ******************************************************************************/
/*
 * JOptionDialog.java
 *
 * Created on 4. April 2003, 13:08
 */

package de.unibayreuth.bayeos.goat.options;

import java.awt.BorderLayout;
import java.util.prefs.Preferences;

import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JSlider;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;

import org.jfree.chart.renderer.DefaultXYItemRenderer;

import de.unibayreuth.bayeos.goat.JMainFrame;

/**
 *
 * @author  oliver
 */
public class JOptionDialog extends javax.swing.JDialog {

    private java.awt.Frame parent;

    private static final Preferences pref = Preferences.userNodeForPackage(JMainFrame.class);

    private StatusTableEditor statEditor;

    /** Creates new form JOptionDialog */
    public JOptionDialog(java.awt.Frame parent, boolean modal) {
        super(parent, "Options", modal);
        initComponents();
        statEditor = new StatusTableEditor();
        panelStatus.add(statEditor, BorderLayout.CENTER);

        setLocationRelativeTo(parent);
        pack();
    }

    public boolean load() {

        lastConnectionCheckBox.setSelected(pref.getBoolean("rememberlastconnection", true));
        jcbType.setSelectedIndex(pref.getInt("xyitemrenderer", DefaultXYItemRenderer.LINES) - 1);
        jSliderShapeSize.getModel().setValue(pref.getInt("shapesize", 8));
        jCheckBoxToolTips.setSelected(pref.getBoolean("charttooltips", false));
        jspGapThreshold.getModel().setValue(new Double(pref.getDouble("chartthreshold", 0.0)));
        statEditor.load();
        return true;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents() {//GEN-BEGIN:initComponents
        java.awt.GridBagConstraints gridBagConstraints;

        jLabel1 = new javax.swing.JLabel();
        optionTabbedPane = new javax.swing.JTabbedPane();
        panelGlobal = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        lastConnectionCheckBox = new javax.swing.JCheckBox();
        lblMaxRecNumber = new javax.swing.JLabel();
        jspMaxRecNumber = new javax.swing.JSpinner();
        panelChart = new javax.swing.JPanel();
        panelStatus = new javax.swing.JPanel();
        panelPoints = new javax.swing.JPanel();
        lblType = new javax.swing.JLabel();
        jcbType = new javax.swing.JComboBox();
        jSliderShapeSize = new javax.swing.JSlider();
        lblShapeSize = new javax.swing.JLabel();
        jLabelSizeMax = new javax.swing.JLabel();
        jLabelSizeMin = new javax.swing.JLabel();
        jCheckBoxToolTips = new javax.swing.JCheckBox();
        lblGapThreshold = new javax.swing.JLabel();
        jspGapThreshold = new javax.swing.JSpinner();
        panelApp = new javax.swing.JPanel();
        buttonPanel = new javax.swing.JPanel();
        exitButton = new javax.swing.JButton();

        jLabel1.setText("jLabel1");

        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                closeDialog(evt);
            }
        });

        panelGlobal.setLayout(new javax.swing.BoxLayout(panelGlobal, javax.swing.BoxLayout.Y_AXIS));

        jPanel2.setLayout(new java.awt.GridBagLayout());

        jPanel2.setBorder(new javax.swing.border.EmptyBorder(new java.awt.Insets(10, 10, 10, 10)));
        lastConnectionCheckBox.setText("Remember Last Connection");
        lastConnectionCheckBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                lastUserCheckBoxActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.ipadx = 9;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        jPanel2.add(lastConnectionCheckBox, gridBagConstraints);

        lblMaxRecNumber.setText("Maximum Number of Records:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        jPanel2.add(lblMaxRecNumber, gridBagConstraints);

        jspMaxRecNumber.setModel(new SpinnerNumberModel(pref.getInt("maxrecnumber", 200000), 0, 400000, 1000));
        jspMaxRecNumber.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jspMaxRecNumberStateChanged(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
        jPanel2.add(jspMaxRecNumber, gridBagConstraints);

        panelGlobal.add(jPanel2);

        optionTabbedPane.addTab("Global", panelGlobal);

        panelChart.setLayout(new java.awt.BorderLayout());

        panelChart.setBorder(new javax.swing.border.EmptyBorder(new java.awt.Insets(1, 1, 1, 1)));
        panelStatus.setLayout(new java.awt.BorderLayout());

        panelStatus.setBorder(new javax.swing.border.TitledBorder("Status Colors"));
        panelStatus.setMaximumSize(new java.awt.Dimension(250, 120));
        panelChart.add(panelStatus, java.awt.BorderLayout.CENTER);

        panelPoints.setLayout(new java.awt.GridBagLayout());

        panelPoints.setBorder(new javax.swing.border.TitledBorder("Drawing"));
        lblType.setText("Drawing Type:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 0);
        panelPoints.add(lblType, gridBagConstraints);

        jcbType.setModel(
                new javax.swing.DefaultComboBoxModel(new String[] { "Shapes", "Lines", "Shapes and Lines" }));
        jcbType.setPreferredSize(new java.awt.Dimension(150, 25));
        jcbType.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbTypeActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 0);
        panelPoints.add(jcbType, gridBagConstraints);

        jSliderShapeSize.setMajorTickSpacing(2);
        jSliderShapeSize.setMaximum(20);
        jSliderShapeSize.setMinorTickSpacing(1);
        jSliderShapeSize.setPaintTicks(true);
        jSliderShapeSize.setValue(8);
        jSliderShapeSize.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jSliderShapeSizeStateChanged(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 0);
        panelPoints.add(jSliderShapeSize, gridBagConstraints);

        lblShapeSize.setText("Shape Size:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 0);
        panelPoints.add(lblShapeSize, gridBagConstraints);

        jLabelSizeMax.setText("10");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 0);
        panelPoints.add(jLabelSizeMax, gridBagConstraints);

        jLabelSizeMin.setText("0");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 0);
        panelPoints.add(jLabelSizeMin, gridBagConstraints);

        jCheckBoxToolTips.setText("Show Tool Tips");
        jCheckBoxToolTips.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxToolTipsActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 0);
        panelPoints.add(jCheckBoxToolTips, gridBagConstraints);

        lblGapThreshold.setText("Gap Threshold:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 0);
        panelPoints.add(lblGapThreshold, gridBagConstraints);

        jspGapThreshold.setPreferredSize(new java.awt.Dimension(80, 24));
        jspGapThreshold.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jspGapThresholdStateChanged(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 0);
        panelPoints.add(jspGapThreshold, gridBagConstraints);

        panelChart.add(panelPoints, java.awt.BorderLayout.SOUTH);

        optionTabbedPane.addTab("Chart", panelChart);

        getContentPane().add(optionTabbedPane, java.awt.BorderLayout.CENTER);

        buttonPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));

        exitButton.setText("Ok");
        exitButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitButtonActionPerformed(evt);
            }
        });

        buttonPanel.add(exitButton);

        getContentPane().add(buttonPanel, java.awt.BorderLayout.SOUTH);

        pack();
    }//GEN-END:initComponents

    private void jspGapThresholdStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jspGapThresholdStateChanged
        JSpinner s = (JSpinner) evt.getSource();
        SpinnerNumberModel m = (SpinnerNumberModel) s.getModel();
        pref.putDouble("chartthreshold", m.getNumber().doubleValue());
    }//GEN-LAST:event_jspGapThresholdStateChanged

    private void jCheckBoxToolTipsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxToolTipsActionPerformed
        JCheckBox s = (JCheckBox) evt.getSource();
        pref.putBoolean("charttooltips", s.isSelected());
    }//GEN-LAST:event_jCheckBoxToolTipsActionPerformed

    private void jspMaxRecNumberStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jspMaxRecNumberStateChanged
        JSpinner s = (JSpinner) evt.getSource();
        SpinnerNumberModel m = (SpinnerNumberModel) s.getModel();
        pref.putInt("maxrecnumber", m.getNumber().intValue());
    }//GEN-LAST:event_jspMaxRecNumberStateChanged

    private void jSliderShapeSizeStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jSliderShapeSizeStateChanged
        JSlider s = (JSlider) evt.getSource();
        if (!s.getValueIsAdjusting()) {
            pref.putInt("shapesize", s.getValue());
        }
    }//GEN-LAST:event_jSliderShapeSizeStateChanged

    private void jcbTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbTypeActionPerformed
        // Add your handling code here:
        JComboBox s = (JComboBox) evt.getSource();
        pref.putInt("xyitemrenderer", s.getSelectedIndex() + 1);
    }//GEN-LAST:event_jcbTypeActionPerformed

    private void lastUserCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_lastUserCheckBoxActionPerformed
        // Add your handling code here:
        JCheckBox s = (JCheckBox) evt.getSource();
        pref.putBoolean("rememberlastconnection", s.isSelected());
    }//GEN-LAST:event_lastUserCheckBoxActionPerformed

    private void exitButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitButtonActionPerformed
        // Add your handling code here:
        closeDialog(null);
    }//GEN-LAST:event_exitButtonActionPerformed

    /** Closes the dialog */
    private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
        setVisible(false);
        dispose();
    }//GEN-LAST:event_closeDialog

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel buttonPanel;
    private javax.swing.JButton exitButton;
    private javax.swing.JCheckBox jCheckBoxToolTips;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabelSizeMax;
    private javax.swing.JLabel jLabelSizeMin;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JSlider jSliderShapeSize;
    private javax.swing.JComboBox jcbType;
    private javax.swing.JSpinner jspGapThreshold;
    private javax.swing.JSpinner jspMaxRecNumber;
    private javax.swing.JCheckBox lastConnectionCheckBox;
    private javax.swing.JLabel lblGapThreshold;

    private javax.swing.JLabel lblMaxRecNumber;
    private javax.swing.JLabel lblShapeSize;
    private javax.swing.JLabel lblType;

    private javax.swing.JTabbedPane optionTabbedPane;
    private javax.swing.JPanel panelApp;
    private javax.swing.JPanel panelChart;
    private javax.swing.JPanel panelGlobal;
    private javax.swing.JPanel panelPoints;
    private javax.swing.JPanel panelStatus;
    // End of variables declaration//GEN-END:variables

}