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

📄 preferencesdialog.java

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

        JLabel     jasiTypeLabel = new JLabel("Jasi Data Type: ", JLabel.RIGHT);
        jasiTypeField = new JTextField(jasiType);
	jasiTypeField.getDocument().addDocumentListener(dbDocListener);

        JPanel connectionPanel = new JPanel(false);
        connectionPanel.setLayout(new BoxLayout(connectionPanel,
                                                BoxLayout.X_AXIS));

	connectionPanel.setBorder( new TitledBorder("Dbase connection info") );

        JPanel namePanel = new JPanel(false);
        namePanel.setLayout(new GridLayout(0, 1));
        namePanel.add(hostLabel);
        namePanel.add(domainLabel);
        namePanel.add(nameLabel);
        namePanel.add(portLabel);
        namePanel.add(userNameLabel);
        namePanel.add(passwordLabel);
        namePanel.add(driverLabel);
        namePanel.add(jasiTypeLabel);

        JPanel fieldPanel = new JPanel(false);
        fieldPanel.setLayout(new GridLayout(0, 1));
        fieldPanel.add(dbaseHostField);
        fieldPanel.add(dbaseDomainField);
        fieldPanel.add(dbaseNameField);
        fieldPanel.add(dbasePortField);
        fieldPanel.add(userNameField);
        fieldPanel.add(passwordField);
        fieldPanel.add(driverField);
        fieldPanel.add(jasiTypeField);

        connectionPanel.add(namePanel);
        connectionPanel.add(fieldPanel);

	return connectionPanel;
    }

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

	String type	= oldProps.getProperty("locationEngineType");
	String url	= oldProps.getProperty("locationEngineAddress");
	String port	= oldProps.getProperty("locationEnginePort");

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

        // Create the labels and text fields.
        JLabel     label1 = new JLabel("Type: ", JLabel.RIGHT);
        locEngType = new JTextField(type);
	locEngType.getDocument().addDocumentListener(locServerDocListener);

        JLabel         label2 = new JLabel("IP-address: ", JLabel.RIGHT);
        locEngUrl = new JTextField(url);   // don't echo password text
	locEngUrl.getDocument().addDocumentListener(locServerDocListener);

        JLabel     label3 = new JLabel("Port #: ", JLabel.RIGHT);
        locEngPort = new JTextField(port);
	locEngPort.getDocument().addDocumentListener(locServerDocListener);

        JPanel connectionPanel = new JPanel(false);
        connectionPanel.setLayout(new BoxLayout(connectionPanel,
                                                BoxLayout.X_AXIS));

	connectionPanel.setBorder( new TitledBorder("Location Engine connection info") );

        JPanel namePanel = new JPanel(false);
        namePanel.setLayout(new GridLayout(0, 1));
        namePanel.add(label1);
        namePanel.add(label2);
        namePanel.add(label3);

        JPanel fieldPanel = new JPanel(false);
        fieldPanel.setLayout(new GridLayout(0, 1));
        fieldPanel.add(locEngType);
        fieldPanel.add(locEngUrl);
        fieldPanel.add(locEngPort);

        connectionPanel.add(namePanel);
        connectionPanel.add(fieldPanel);

	return connectionPanel;
    }

     /** Return the JiggleProperties */
     public JiggleProperties getJiggleProperties () {
            return newProps;
     }

// //////////////////////////////////////////////////////////////////
/**
 *  Action to take when [Cancel] is pressed
 *  Close dialog, make no changes
 */
    public void cancelPressed() {
        returnValue = JOptionPane.CANCEL_OPTION;
        this.setVisible(false);
    }

/**
 *  Action to take when [OK] is pressed
 *  Close dialog, make changes
 */
    public void OKPressed() {

        returnValue = JOptionPane.OK_OPTION;
        this.setVisible(false);	    // dismiss dialog
    }
/**
 *  Action to take when [Apply] is pressed
 *  Make changes but don't close dialog.
 */
/*
    public void applyPressed() {

	// Have to check now before old ones are destroyed
	boolean dbChanged = dbaseChanged();

    }
*/
/**
 *  Action to take when [Reset] is pressed
 *  Reset all preferences to original values that are in the files.
 */
    public void resetPressed() {

        // return to the same tab after reset
       int index = tabs.getSelectedIndex();

	  newProps = (JiggleProperties) oldProps.clone(); // a copy of the old list

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

       tabs.setSelectedIndex(index);

    }

    /** Returns true if any of the DataSource properties were changed. */
    public boolean dataSourceChanged () {
	return !oldProps.dataSourceEquals(newProps);
	/*
	if (
//	    oldProps.getProperty("dbaseURL") != newProps.getProperty("dbaseURL") ||
//	    oldProps.getProperty("dbaseDriver") != newProps.getProperty("dbaseDriver") ||
//	    oldProps.getProperty("dbaseUser") != newProps.getProperty("dbaseUser") ||
//	    oldProps.getProperty("dbasePasswd") != newProps.getProperty("dbasePasswd")
	    !oldProps.getProperty("dbaseHost"  ).equals(newProps.getProperty("dbaseHost"))||
	    !oldProps.getProperty("dbaseDomain").equals(newProps.getProperty("dbaseDomain"))||
	    !oldProps.getProperty("dbaseName"  ).equals(newProps.getProperty("dbaseName"))||
	    !oldProps.getProperty("dbasePort"  ).equals(newProps.getProperty("dbasePort"))||
 	    !oldProps.getProperty("dbaseDriver").equals(newProps.getProperty("dbaseDriver")) ||
	    !oldProps.getProperty("dbaseUser"  ).equals(newProps.getProperty("dbaseUser")) ||
	    !oldProps.getProperty("dbasePasswd").equals(newProps.getProperty("dbasePasswd"))
	    ) return true;
	return false;
	*/
   }
    /** Returns true if any of the wavesource properties were changed. */
    public boolean waveSourceChanged () {
        return !oldProps.waveSourceEquals(newProps);
	/*
	if (
//	    oldProps.getProperty("waveformReadMode") != newProps.getProperty("waveformReadMode") ||
// 	    oldProps.getProperty("waveServerGroupList") != newProps.getProperty("waveServerGroupList") ||
//	    oldProps.getProperty("currentWaveServerGroup") != newProps.getProperty("currentWaveServerGroup")
	    !oldProps.getProperty("waveformReadMode").equals(newProps.getProperty("waveformReadMode")) ||
 	    !oldProps.getProperty("waveServerGroupList").equals(newProps.getProperty("waveServerGroupList")) ||
	    !oldProps.getProperty("currentWaveServerGroup").equals(newProps.getProperty("currentWaveServerGroup"))
	    ) return true;

	return false;
*/
   }
    /** Returns true if the ChannelTimeWindowModel changed. */
    public boolean channelTimeWindowModelChanged () {
      return !oldProps.channelTimeWindowModelEquals(newProps);

	//    String oldm = oldProps.getCurrentChannelTimeWindowModelClassName();
	//    String newm = newProps.getCurrentChannelTimeWindowModelClassName();
      	//    return !oldm.equals(newm);
    }
/**
 * Main for testing class
 * Note, needs:  import java.awt.event.*;
 */
    public static void main(String s[]) {

        JFrame frame = new JFrame("Main");
        frame.addWindowListener(new WindowAdapter()
	{
            public void windowClosing(WindowEvent e) {System.exit(0);}
        });

        frame.pack();
        frame.setVisible(true);


	JiggleProperties props = new JiggleProperties("properties");

	System.out.println ("----------- Current Properties -------------");
	props.dumpProperties();

	PreferencesDialog prefDialog = new PreferencesDialog(props);

// Preferences Dialog

	if (prefDialog.getButtonStatus() == JOptionPane.OK_OPTION) {

	    // get the changed properties
            JiggleProperties newprops = prefDialog.getJiggleProperties();
            PreferencesDialog.savePropertiesDialog(newprops);

	    System.out.println ("--------- New Properties -------------");

	    newprops.dumpProperties();
	} else {
	     System.out.println ("Properties not changed. ");
	}

	System.exit(0);

    }
/**
 * Pop dialog asking if preferences should be saved.
 */
    public static void savePropertiesDialog(JiggleProperties props)
    {
    //pop confirming  yes/no dialog:
           int n = JOptionPane.showConfirmDialog(
                   null, "Save current properties to startup file?",
                   "Save Properties?",
                   JOptionPane.YES_NO_OPTION);

	    if (n == JOptionPane.YES_OPTION) {

		props.saveProperties();
	    }
    }

} // end of PrefsDialog class

// /////////////////////////////////////////////////////////////////////////////
// INNER CLASSES
// /////////////////////////////////////////////////////////////////////////////
    /**
     * This is better then an actionListener because it updates
     * the values as they are edited and does not require that the user
     * hit a <CR> to trigger the listener.
     */
    class DbDocListener implements DocumentListener {

	PreferencesDialog dia;

	// Passes reference to the caller so we can see and change some stuff
	public DbDocListener(PreferencesDialog pd){
	    dia = pd;  // need reference to see other variables
	}
         public void insertUpdate(DocumentEvent e) {
             setValues(e);
         }
         public void removeUpdate(DocumentEvent e) {
             setValues(e);
         }
         public void changedUpdate(DocumentEvent e) {
             // we won't ever get this with a PlainDocument
         }

     private void setValues(DocumentEvent e) {

		 // don't know what is being editied so just read 'em all

		 // GDataSource connnection
		 dia.newProps.setProperty("dbaseHost", dia.dbaseHostField.getText().trim() );

		 dia.newProps.setProperty("dbaseDomain", dia.dbaseDomainField.getText().trim() );

		 dia.newProps.setProperty("dbaseName", dia.dbaseNameField.getText().trim() );

		 dia.newProps.setProperty("dbasePort", dia.dbasePortField.getText().trim() );

		 dia.newProps.setProperty("dbaseDriver", dia.driverField.getText().trim() );

		 dia.newProps.setProperty("dbaseUser", dia.userNameField.getText().trim() );
		 String pwd = new String(dia.passwordField.getPassword());
		 dia.newProps.setProperty("dbasePasswd", pwd.trim() );

		 dia.newProps.setProperty("jasiObjectType", dia.jasiTypeField.getText().trim() );

	     }
         }

    /**
     * This is better then an actionListener because it updates
     * the values as they are edited and does not require that the user
     * hit a <CR> to trigger the listener.
     */
    class LocServerDocListener implements DocumentListener {

	PreferencesDialog dia;

	// Passes reference to the caller so we can see and change some stuff
	public LocServerDocListener(PreferencesDialog pd)
	{
	    dia = pd;  // need reference to see other variables
	}
             public void insertUpdate(DocumentEvent e) {
                 setValues(e);
             }
             public void removeUpdate(DocumentEvent e) {
                 setValues(e);
             }
             public void changedUpdate(DocumentEvent e) {
                 // we won't ever get this with a PlainDocument
             }

     private void setValues(DocumentEvent e) {

		 // don't know what is being editied so just read 'em all

		 // Location engine
		 dia.newProps.setProperty("locationEngineType",
				      dia.locEngType.getText().trim() );
		 dia.newProps.setProperty("locationEngineAddress",
				      dia.locEngUrl.getText().trim() );
		 dia.newProps.setProperty("locationEnginePort",
				      dia.locEngPort.getText().trim() );

     }
    }

    class MiscDocListener implements DocumentListener {

	PreferencesDialog dia;

	// Passes reference to the caller so we can see and change some stuff
	public MiscDocListener(PreferencesDialog pd)
	{
	    dia = pd;  // need reference to see other variables
	}
             public void insertUpdate(DocumentEvent e) {
                 setValues(e);
             }
             public void removeUpdate(DocumentEvent e) {
                 setValues(e);
             }
             public void changedUpdate(DocumentEvent e) {
                 // we won't ever get this with a PlainDocument
             }

     private void setValues(DocumentEvent e) {

	 // no sanity checking on numbers !
		 dia.newProps.setProperty("localNetCode",
					  dia.netCodeField.getText().trim() );
		 dia.newProps.setProperty("cacheAbove",
					  dia.cacheAboveField.getText().trim() );
		 dia.newProps.setProperty("cacheBelow",
					  dia.cacheBelowField.getText().trim() );
		 dia.newProps.setProperty("pickStripValue",
					  dia.pickStripValueField.getText().trim() );
		 dia.newProps.setProperty("clockQualityThreshold",
					  dia.clockQualityValueField.getText().trim() );

     }
    }

⌨️ 快捷键说明

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