OSDN Git Service

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