OSDN Git Service

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