Package xplanetconfigurator.gui

Source Code of xplanetconfigurator.gui.JDialogFind

/*
* FindDialog.java
*/
package xplanetconfigurator.gui;

import java.awt.*;
import xplanetconfigurator.find.Findable;
import xplanetconfigurator.util.OwnPreferences;

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

    private static final String FRAME_X = "JDialog_find_frame_x";
    private static final String FRAME_Y = "JDialog_find_frame_y";
    private static final String FRAME_HEIGHT = "JDialog_find_frame_height";
    private static final String FRAME_WIDTH = "JDialog_find_frame_width";
    private Findable caller;

    /** Creates new form FindDialog */
    public JDialogFind(java.awt.Frame parent, boolean modal, String s) {
        super(parent, modal);
        this.caller = (Findable) parent;
        initComponents();
        this.restoreUserSettings();
        if (s == null) {
            s = "";
        }
        this.jTextField1.setText(s);
        this.jTextField1.grabFocus();
        this.getRootPane().setDefaultButton(this.jButtonOK);
    }

    /** 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();
        jPanel1 = new javax.swing.JPanel();
        jButtonOK = new javax.swing.JButton();
        jButtonCancel = new javax.swing.JButton();
        jButtonFileAtOnce = new javax.swing.JButton();
        jButtonCaseInsensitive = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jTextField1 = new javax.swing.JTextField();
        /**
         * Uncomment if you want to find while typing
        jTextField1.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent evt) {
                jTextField1CaretUpdate(evt);
            }
        });
         */
        jPanel2 = new javax.swing.JPanel();

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

        setTitle("Find");
        addWindowListener(new java.awt.event.WindowAdapter() {

            @Override
            public void windowClosing(java.awt.event.WindowEvent evt) {
                closeDialog(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Dialog", 0, 12));
        jLabel1.setText("You can use regular expressions.");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(12, 12, 7, 12);
        getContentPane().add(jLabel1, gridBagConstraints);

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

        jButtonOK.setMnemonic('O');
        jButtonOK.setText("OK");
        jButtonOK.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonOKActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 5);
        jPanel1.add(jButtonOK, gridBagConstraints);

        jButtonCancel.setMnemonic('C');
        jButtonCancel.setText("Cancel");
        jButtonCancel.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCancelActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 5;
        gridBagConstraints.gridy = 0;
        jPanel1.add(jButtonCancel, gridBagConstraints);

        jButtonFileAtOnce.setMnemonic('S');
        jButtonFileAtOnce.setText("Multiple Lines");
        jButtonFileAtOnce.setToolTipText("<html>Searches the file at once.<br>Search is not limited to one single line.");
        jButtonFileAtOnce.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonFileAtOnceActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 5);
        jPanel1.add(jButtonFileAtOnce, gridBagConstraints);

        jButtonCaseInsensitive.setMnemonic('C');
        jButtonCaseInsensitive.setText("Case Insensitive");
        jButtonCaseInsensitive.setToolTipText("Lower and upper case does not matter.");
        jButtonCaseInsensitive.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCaseInsensitiveActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 11);
        jPanel1.add(jButtonCaseInsensitive, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        jPanel1.add(jPanel3, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(0, 12, 12, 12);
        getContentPane().add(jPanel1, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(0, 12, 11, 12);
        getContentPane().add(jTextField1, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weighty = 1.0;
        getContentPane().add(jPanel2, gridBagConstraints);

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

    private void jButtonCaseInsensitiveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCaseInsensitiveActionPerformed
        // Add your handling code here:
        String text = this.jTextField1.getText();
        if (text == null) {
            text = "";
        }
        if (text.indexOf("(?i)") == -1) {
            text = "(?i)" + text;
        }
        this.jTextField1.setText(text);
        this.jTextField1.grabFocus();
    }//GEN-LAST:event_jButtonCaseInsensitiveActionPerformed

    private void jButtonFileAtOnceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonFileAtOnceActionPerformed
        // Add your handling code here:
        String text = this.jTextField1.getText();
        if (text == null) {
            text = "";
        }
        if (text.indexOf("(?s)") == -1) {
            text = "(?s)" + text;
        }
        this.jTextField1.setText(text);
        this.jTextField1.grabFocus();
    }//GEN-LAST:event_jButtonFileAtOnceActionPerformed

    private void jButtonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelActionPerformed
        // Add your handling code here:
        this.closeMySelf();
    }//GEN-LAST:event_jButtonCancelActionPerformed

    private void jButtonOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOKActionPerformed
        // Add your handling code here:
        String s = this.jTextField1.getText();
        this.caller.setFindExpr(s);
        this.closeMySelf();
    }//GEN-LAST:event_jButtonOKActionPerformed

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

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        new JDialogFind(new javax.swing.JFrame(), true, "").setVisible(true);
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonCancel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JButton jButtonCaseInsensitive;
    private javax.swing.JButton jButtonOK;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JButton jButtonFileAtOnce;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration//GEN-END:variables

    private void saveFramePosition() {
        int x = this.getX();
        int y = this.getY();
        Dimension d = this.getSize();
        int h = (int) d.getHeight();
        int w = (int) d.getWidth();

        OwnPreferences prefs = OwnPreferences.userNodeForPackage(this.getClass());

        prefs.putInt(JDialogFind.FRAME_X, x);
        prefs.putInt(JDialogFind.FRAME_Y, y);
        prefs.putInt(JDialogFind.FRAME_HEIGHT, h);
        prefs.putInt(JDialogFind.FRAME_WIDTH, w);
    }

    private void restoreUserSettings() {
        OwnPreferences prefs =
                OwnPreferences.userNodeForPackage(this.getClass());

        int minWidth = 470;
        int minHeight = 140;
        int x = prefs.getInt(JDialogFind.FRAME_X, 10);
        int y = prefs.getInt(JDialogFind.FRAME_Y, 10);
        int h = prefs.getInt(JDialogFind.FRAME_HEIGHT, minHeight);
        int w = prefs.getInt(JDialogFind.FRAME_WIDTH, minWidth);

        this.setSize(new Dimension(w, h));

        if (w == 470 && h == 140) {
            this.setLocationRelativeTo(null); //center it
        } else {
            this.setLocation(x, y);
        }
    }

    private void closeMySelf() {
        this.saveFramePosition();
        this.setVisible(false);
        this.dispose();
    }

    private void jTextField1CaretUpdate(javax.swing.event.CaretEvent evt) {
        String s = this.jTextField1.getText();
        this.caller.setFindExpr(s);
    }
}
TOP

Related Classes of xplanetconfigurator.gui.JDialogFind

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.