⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 preferencesdialog.java

📁 一个用java写的地震分析软件(无源码)-used to write a seismic analysis software (without source)
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package org.trinet.jiggle;

/*
 * Based on /opt/swing-1.0.2/examples/Metalworks/src/MetalworksPrefs.java
 */

import java.awt.*;
import java.awt.event.*;
import java.beans.*;
import java.text.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;
import javax.swing.border.TitledBorder;
import javax.swing.plaf.metal.*;

import org.trinet.util.graphics.ColumnLayout;

/**
  * This dialog allows user to choose Jiggle preferences
  */
public class PreferencesDialog extends CenteredDialog {

    JiggleProperties oldProps;	    // old set of properties
    JiggleProperties newProps;	    // new properties as changed by this dialog

    JPanel container = new JPanel( new BorderLayout());	    // the main dialog panel

    JTextField driverField;
    JTextField dbaseHostField;
    JTextField dbaseDomainField;
    JTextField dbasePortField;
    JTextField dbaseNameField;
    JTextField userNameField;
    JTextField jasiTypeField;
    JPasswordField passwordField;   // don't echo password text

    JTextField locEngType;
    JTextField locEngUrl;
    JTextField locEngPort;

    JTextField netCodeField;
    JTextField cacheAboveField;
    JTextField cacheBelowField;
    JTextField pickStripValueField;
    JTextField clockQualityValueField;

    // make the tabbed panels
    JTabbedPane tabs = new JTabbedPane();

    FlowLayout flowLayout1 = new FlowLayout();

/** Tab numbers */
    public final static int TAB_DATACONNECTION = 0;
    public final static int TAB_LOCSERVER = 1;
    public final static int TAB_WAVEDATASOURCE = 2;
    public final static int TAB_CHANWINMODEL = 3;
    public final static int TAB_MISC = 4;

    int topTab = 0;

    /** Constructor */
    public PreferencesDialog(JiggleProperties properties) {
        this(properties, 0);
    }
    /** Constructor */
    public PreferencesDialog(JiggleProperties properties, int tabNumber) {

       super(null, "Preferences", true);

        oldProps = properties;	          // this class will NOT affect the original copy
//	newProps = (JiggleProperties) oldProps.clone();
	newProps = (JiggleProperties) oldProps.deepClone();

	topTab = tabNumber;

        try  {
             jbInit();
        }
        catch(Exception ex) {
             ex.printStackTrace();
        }
     }

/** Build the GUI */
     private void jbInit() throws Exception {

 //	container = new JPanel();	    // the main dialog panel
 //	container.setLayout( new BorderLayout() );

 // remove contents so we can call this again without repeating components
        container.removeAll();
        tabs.removeAll();

	JPanel dbase = buildDbasePanel();
	tabs.addTab( "Data Connection", null, dbase );

//	JPanel locEng = buildLocServerPanel();
	JPanel locEng = new DPLocationEngine(newProps);
	tabs.addTab( "Location Server", null, locEng );

	JPanel wfSource = (JPanel) new DPwaveSource(newProps);
	tabs.addTab( "Wavedata Source", null, wfSource );

	JPanel ctwmPanel = (JPanel) new DPChannelTimeWindowModel(newProps);
	tabs.addTab( "Chan/Window Models", null, ctwmPanel );

	JPanel misc = buildMiscPanel();
	tabs.addTab( "Other", null, misc );

	/*
	JPanel display = buildDisplayPanel();
	tabs.addTab( "Test 1", null, display );

	JPanel conn = buildConnectingPanel();
	tabs.addTab( "Text 2", null, conn );
	*/
    // define the buttons: [OK] [Reset]  [Cancel]

	JPanel buttonPanel = new JPanel();

	JButton ok = new JButton("OK");
	ok.addActionListener(new ActionListener() {
	                       public void actionPerformed(ActionEvent e) {
				   OKPressed();
			       }});
        ok.setToolTipText("Use changes");
	buttonPanel.add( ok );
/*
	JButton apply = new JButton("Apply");
	apply.addActionListener(new ActionListener() {
	                       public void actionPerformed(ActionEvent e) {
				   applyPressed();
			       }});
	buttonPanel.add( apply );
*/
	JButton reset = new JButton("Reset");
	reset.addActionListener(new ActionListener() {
	                       public void actionPerformed(ActionEvent e) {
				   resetPressed();
			       }});
        reset.setToolTipText("Reset properties in ALL tabs to original values.");
	buttonPanel.add( reset );

	buttonPanel.setLayout ( flowLayout1 );
	JButton cancel = new JButton("Cancel");
	cancel.addActionListener(new ActionListener() {
	                       public void actionPerformed(ActionEvent e) {
				   cancelPressed();
			       }});
        cancel.setToolTipText("Cancel changes");
	buttonPanel.add( cancel );

	getRootPane().setDefaultButton(ok); // default button

	container.add(tabs, BorderLayout.CENTER);
	container.add(buttonPanel, BorderLayout.SOUTH);

	getContentPane().add(container);

	pack();
	centerDialog();

	// bring the chosen tab to the front
	tabs.setSelectedIndex(topTab);

	show();

//	UIManager.addPropertyChangeListener(new UISwitchListener(container));
    }

    /** Create the panel. */
    private JPanel buildDisplayPanel() {

	JPanel displayPanel = new JPanel();
	displayPanel.setLayout( new GridLayout(1, 0) );

	JPanel panel1 = new JPanel();	// a subpanel w/ radio buttons

	displayPanel.setLayout(new ColumnLayout());
	displayPanel.setBorder( new TitledBorder("Radio buttons") );

	ButtonGroup group1	= new ButtonGroup();
	JRadioButton rb1	= new JRadioButton("Option #1");
	JRadioButton rb2	= new JRadioButton("Option #2");
	JRadioButton rb3	= new JRadioButton("Option #3");

	group1.add(rb1);	    // add buttons to group (only one in group can be pushed)
	group1.add(rb2);
	group1.add(rb3);

	panel1.add(rb1);	    // add buttons to panel
	panel1.add(rb2);
	panel1.add(rb3);

	rb1.setSelected(true);	    // set default
	displayPanel.add(panel1);


	JPanel panel2 = new JPanel();
	panel2.setLayout(new ColumnLayout());
	panel2.setBorder( new TitledBorder("More crap") );

	ButtonGroup group2 = new ButtonGroup();
	JRadioButton rb21 = new JRadioButton("Nothing");
	JRadioButton rb22 = new JRadioButton("Less then nothing");
	JRadioButton rb23 = new JRadioButton("Really in the hole");

	group2.add(rb21);
	group2.add(rb22);
	group2.add(rb23);

	panel2.add(rb21);
	panel2.add(rb22);
	panel2.add(rb23);

	rb23.setSelected(true);
	displayPanel.add(panel2);

	return displayPanel;
    }
    //
    private JPanel buildConnectingPanel() {
	JPanel connectPanel = new JPanel();
	connectPanel.setLayout( new ColumnLayout() );

	JPanel protoPanel = new JPanel();
	JLabel protoLabel = new JLabel ("Protocol");
	JComboBox protocol = new JComboBox();
	protocol.addItem("Test 1");
	protocol.addItem("Test 2");
	protocol.addItem("Other...");
	protoPanel.add(protoLabel);
	protoPanel.add(protocol);

	JPanel attachmentPanel = new JPanel();
	JLabel attachmentLabel = new JLabel ("Some other stuff");
	JComboBox attach = new JComboBox();
	attach.addItem("Subitem 1");
	attach.addItem("Subitem 2");
	attach.addItem("Subitem 3");
	attach.addItem("Subitem 4");
	attachmentPanel.add(attachmentLabel);
	attachmentPanel.add(attach);

	JCheckBox autoConn = new JCheckBox("Check Box 1");
	JCheckBox compress = new JCheckBox("Check Box 2");
	autoConn.setSelected( true );

	connectPanel.add(protoPanel);
	connectPanel.add(attachmentPanel);
	connectPanel.add(autoConn);
	connectPanel.add(compress);
	return connectPanel;
    }

    //
    private JPanel buildMiscPanel() {

	DecimalFormat df1 = new DecimalFormat ( "###0" );
	DecimalFormat df2 = new DecimalFormat ( "#0.00" );

	MiscDocListener miscDocListener =  new MiscDocListener(this);

	String netCode	= oldProps.getProperty("localNetCode");
	int cacheAbove	= oldProps.getInt("cacheAbove");
	int cacheBelow	= oldProps.getInt("cacheBelow");
	float pickStripValue	= oldProps.getFloat("pickStripValue");
	float clockQualityValue	= oldProps.getFloat("clockQualityThreshold");

	JPanel miscPanel = new JPanel();
	miscPanel.setLayout( new ColumnLayout() );

// network code
        netCodeField = new JTextField(netCode);
	// this doesn't to shit!
	//	Font font = netCodeField.getFont();
	//	FontMetrics fm =netCodeField.getFontMetrics(font) ;
	//	netCodeField.setSize(fm.stringWidth("MMM"), fm.getHeight());

	JPanel netCodePanel = new JPanel();
        netCodeField.getDocument().addDocumentListener(miscDocListener);
	netCodePanel.add(new JLabel ("Seismic Network Code: "));
	netCodePanel.add(netCodeField);
	netCodePanel.setToolTipText("Set default FDSN-style network code.");

// waveform loader cache values
	JPanel cachePanel = new JPanel(new ColumnLayout()); // will have 2 rows
	cachePanel.add(new JLabel ("Waveform cache size"), SwingConstants.CENTER);
	JPanel cacheValPanel = new JPanel();   // flow layout
        cacheAboveField = new JTextField(df1.format(cacheAbove));
          cacheAboveField.getDocument().addDocumentListener(miscDocListener);
	  cacheValPanel.add(new JLabel ("Above: "));
	  cacheValPanel.add(cacheAboveField);
        cacheBelowField = new JTextField(df1.format(cacheBelow));
	  cacheValPanel.add(new JLabel (" Below: "));
	  cacheValPanel.add(cacheBelowField);
	  cachePanel.add(cacheValPanel);
        cachePanel.setBorder(BorderFactory.createLineBorder(Color.black));
	cachePanel.setToolTipText("Timeseries dynamic loader cache");

// pick strip value
        pickStripValueField = new JTextField(df2.format(pickStripValue));
	JPanel pickStripValuePanel = new JPanel();;
	pickStripValueField.getDocument().addDocumentListener(miscDocListener);
	pickStripValuePanel.add(new JLabel ("Strip Picks Value: "));
	pickStripValuePanel.add(pickStripValueField);
	pickStripValuePanel.setToolTipText("Set default strip-picks value.");

// clock quality value
	clockQualityValueField = new JTextField(df2.format(clockQualityValue));
	JPanel clockQualityValuePanel = new JPanel();
	clockQualityValuePanel.setToolTipText("Waveform panel frame will be red if clock quality is worse than this.");
	clockQualityValueField.getDocument().addDocumentListener(miscDocListener);
	clockQualityValuePanel.add(new JLabel ("Clock quality threshold: "));
	clockQualityValuePanel.add(clockQualityValueField);

	miscPanel.add(netCodePanel);
	miscPanel.add(cachePanel);
	miscPanel.add(pickStripValuePanel);
	miscPanel.add(clockQualityValuePanel);

	// check boxes

	return miscPanel;
    }

    /**
     * Creates the dbase panel which will contain all the fields for
     * the connection information.
     */
    private JPanel buildDbasePanel() {

	//	String url	= oldProps.getProperty("dbaseURL");
	String dbaseHost   = oldProps.getProperty("dbaseHost");
	String dbaseDomain = oldProps.getProperty("dbaseDomain");
	String dbaseName   = oldProps.getProperty("dbaseName");
	String dbasePort   = oldProps.getProperty("dbasePort");

	String driver	= oldProps.getProperty("dbaseDriver");
	String user	= oldProps.getProperty("dbaseUser");
	String passwd	= oldProps.getProperty("dbasePasswd");

	String jasiType = oldProps.getProperty("jasiObjectType");

	// A document listener will change newProps values as fields are edited
	DbDocListener dbDocListener =  new DbDocListener(this);

        // Create the labels and text fields.
        JLabel     hostLabel = new JLabel("Database host: ", JLabel.RIGHT);
        dbaseHostField = new JTextField(dbaseHost);
	dbaseHostField.getDocument().addDocumentListener(dbDocListener);

        JLabel     domainLabel = new JLabel("Database domain: ", JLabel.RIGHT);
        dbaseDomainField = new JTextField(dbaseDomain);
	dbaseDomainField.getDocument().addDocumentListener(dbDocListener);

        JLabel     nameLabel = new JLabel("Database name: ", JLabel.RIGHT);
        dbaseNameField = new JTextField(dbaseName);
	dbaseNameField.getDocument().addDocumentListener(dbDocListener);

        JLabel     portLabel = new JLabel("Database Port#: ", JLabel.RIGHT);
        dbasePortField = new JTextField(dbasePort);
	dbasePortField.getDocument().addDocumentListener(dbDocListener);

        JLabel     userNameLabel = new JLabel("Username: ", JLabel.RIGHT);
        userNameField = new JTextField(user);
	userNameField.getDocument().addDocumentListener(dbDocListener);

        JLabel         passwordLabel = new JLabel("Password: ", JLabel.RIGHT);
        passwordField = new JPasswordField(passwd);   // don't echo password text
	passwordField.getDocument().addDocumentListener(dbDocListener);

        JLabel     driverLabel = new JLabel("Driver: ", JLabel.RIGHT);
        driverField = new JTextField(driver);
	driverField.getDocument().addDocumentListener(dbDocListener);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -