OSDN Git Service

BUGFIX: Windows posision get before dispose windows when window close button pushed.
[mdc/BetaProject.git] / src / org / jent / checksmtp / ToListUI.java
1 /*
2  * ToListUI.java
3  *
4  * Created on 2007/07/22, 11:17
5  */
6
7 package org.jent.checksmtp;
8
9 import java.awt.Dimension;
10 import java.awt.Point;
11 import java.awt.Toolkit;
12 import java.util.List;
13
14 /**
15  *
16  * @author  tkyn
17  */
18 public class ToListUI extends javax.swing.JFrame {
19   private List toList = null;
20   private ResultNotify resultNotify = null;
21   
22   /** Creates new form ToListUI */
23   public ToListUI(ResultNotify processer, List toList) {
24     super();  //paranoia statement.
25     initComponents();
26     
27     jButtonCancel.requestFocusInWindow();
28     //getRootPane().setDefaultButton(jButtonOK);
29     
30     this.toList = toList;
31     this.resultNotify = processer;
32     
33     if (toList != null) {
34       jList1.setListData(toList.toArray());
35       //jList1.update();
36       jList1.setVisible(true);
37     }
38     this.setVisible(true);
39     toFront(); //from Tiger... setAlwaysOnTop(true);
40     
41     Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
42     //If exsist configuration file, iconise at start up.
43     if ( ApplicationProperties.isFileLoaded() ) {
44       int x = ApplicationProperties.getConfirmDialogPosX();
45       int y = ApplicationProperties.getConfirmDialogPosY();
46       int w = ApplicationProperties.getConfirmDialogPosW();
47       int h = ApplicationProperties.getConfirmDialogPosH();
48       if ( x > screenSize.width ) {
49         x = screenSize.width - w;
50         if ( x < 0 ) { x = 0; };
51       }
52       if ( y > screenSize.height ) {
53         y = screenSize.height - h;
54         if ( y < 0 ) { y = 0; };
55       }
56       this.setBounds(x, y, w, h);
57     } else {
58       //No Configuration file.
59       Dimension frameSize =  ApplicationProperties.getConfirmDialogSize();
60       if (frameSize.height > screenSize.height) {
61         frameSize.height = screenSize.height;
62       }
63       if (frameSize.width > screenSize.width) {
64         frameSize.width = screenSize.width;
65       }
66       this.setBounds(
67               (screenSize.width - frameSize.width) / 2,
68               (screenSize.height - frameSize.height) / 2,
69               frameSize.width, frameSize.height );
70     }
71     
72     
73   }
74   
75   /** This method is called from within the constructor to
76    * initialize the form.
77    * WARNING: Do NOT modify this code. The content of this method is
78    * always regenerated by the Form Editor.
79    */
80   // <editor-fold defaultstate="collapsed" desc=" Generated Code">//GEN-BEGIN:initComponents
81   private void initComponents() {
82     jPanel1 = new javax.swing.JPanel();
83     jScrollPane1 = new javax.swing.JScrollPane();
84     jList1 = new javax.swing.JList();
85     jButtonOK = new javax.swing.JButton();
86     jButtonCancel = new javax.swing.JButton();
87
88     setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
89     java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/jent/checksmtp/Bundle"); // NOI18N
90     setTitle(bundle.getString("ToListUI.title")); // NOI18N
91     addWindowListener(new java.awt.event.WindowAdapter() {
92       public void windowClosing(java.awt.event.WindowEvent evt) {
93         formWindowClosing(evt);
94       }
95     });
96
97     jList1.setModel(new javax.swing.AbstractListModel() {
98       String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
99       public int getSize() { return strings.length; }
100       public Object getElementAt(int i) { return strings[i]; }
101     });
102     jScrollPane1.setViewportView(jList1);
103
104     jButtonOK.setText(bundle.getString("ToListUI.jButtonOK.text")); // NOI18N
105     jButtonOK.addActionListener(new java.awt.event.ActionListener() {
106       public void actionPerformed(java.awt.event.ActionEvent evt) {
107         jButtonOKActionPerformed(evt);
108       }
109     });
110
111     jButtonCancel.setText(bundle.getString("ToListUI.jButtonCancel.text")); // NOI18N
112     jButtonCancel.addActionListener(new java.awt.event.ActionListener() {
113       public void actionPerformed(java.awt.event.ActionEvent evt) {
114         jButtonCancelActionPerformed(evt);
115       }
116     });
117
118     org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
119     jPanel1.setLayout(jPanel1Layout);
120     jPanel1Layout.setHorizontalGroup(
121       jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
122       .add(jPanel1Layout.createSequentialGroup()
123         .addContainerGap(200, Short.MAX_VALUE)
124         .add(jButtonOK)
125         .add(14, 14, 14)
126         .add(jButtonCancel)
127         .addContainerGap())
128       .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE)
129     );
130
131     jPanel1Layout.linkSize(new java.awt.Component[] {jButtonCancel, jButtonOK}, org.jdesktop.layout.GroupLayout.HORIZONTAL);
132
133     jPanel1Layout.setVerticalGroup(
134       jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
135       .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
136         .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 90, Short.MAX_VALUE)
137         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
138         .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
139           .add(jButtonOK)
140           .add(jButtonCancel)))
141     );
142
143     org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
144     getContentPane().setLayout(layout);
145     layout.setHorizontalGroup(
146       layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
147       .add(layout.createSequentialGroup()
148         .addContainerGap()
149         .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
150         .addContainerGap())
151     );
152     layout.setVerticalGroup(
153       layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
154       .add(layout.createSequentialGroup()
155         .addContainerGap()
156         .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
157         .addContainerGap())
158     );
159     pack();
160   }// </editor-fold>//GEN-END:initComponents
161
162   private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
163     restorePosition();
164     resultNotify.sayNG();
165   }//GEN-LAST:event_formWindowClosing
166     
167   private void jButtonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelActionPerformed
168     resultNotify.sayNG();
169     this.dispose();
170   }//GEN-LAST:event_jButtonCancelActionPerformed
171   
172   private void jButtonOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOKActionPerformed
173     //push OK
174     resultNotify.sayOK();
175     this.dispose();
176   }//GEN-LAST:event_jButtonOKActionPerformed
177   
178   private boolean restorePosition() {
179     Point locationPoint = getLocationOnScreen();  //TODO: IllegalComponentStateException
180     int x = locationPoint.x;
181     int y = locationPoint.y;
182     int h = this.getHeight();
183     int w = this.getWidth();
184     boolean modified = false;
185     
186     if ( x != ApplicationProperties.getConfirmDialogPosX()
187     || y != ApplicationProperties.getConfirmDialogPosY()
188     || h != ApplicationProperties.getConfirmDialogPosH()
189     || w != ApplicationProperties.getConfirmDialogPosW()
190     ) {
191       modified = true;
192       ApplicationProperties.setConfirmDialogPosX(x);
193       ApplicationProperties.setConfirmDialogPosY(y);
194       ApplicationProperties.setConfirmDialogPosH(h);
195       ApplicationProperties.setConfirmDialogPosW(w);
196       if ( !ApplicationProperties.save() ) {
197         new MessageDialogUI("Fail the properties file of dialog potition save.",
198                 null, MessageDialogUI.ERROR_MODE);
199       }
200     }
201     return modified;
202   }
203   
204   /**
205    * @param args the command line arguments
206    *
207    * public static void main(String args[]) {
208    * java.awt.EventQueue.invokeLater(new Runnable() {
209    * public void run() {
210    * new ToListUI().setVisible(true);
211    * }
212    * });
213    * }
214    */
215   
216   // Variables declaration - do not modify//GEN-BEGIN:variables
217   private javax.swing.JButton jButtonCancel;
218   private javax.swing.JButton jButtonOK;
219   private javax.swing.JList jList1;
220   private javax.swing.JPanel jPanel1;
221   private javax.swing.JScrollPane jScrollPane1;
222   // End of variables declaration//GEN-END:variables
223   
224 }