4 * Created on 2007/07/22, 11:17
7 package org.jent.checksmtp;
9 import java.awt.Dimension;
10 import java.awt.Point;
11 import java.awt.Toolkit;
12 import java.util.List;
18 public class ToListUI extends javax.swing.JFrame {
19 private List toList = null;
20 private ResultNotify resultNotify = null;
22 /** Creates new form ToListUI */
23 public ToListUI(ResultNotify processer, List toList) {
24 super(); //paranoia statement.
27 jButtonCancel.requestFocusInWindow();
28 //getRootPane().setDefaultButton(jButtonOK);
31 this.resultNotify = processer;
34 jList1.setListData(toList.toArray());
36 jList1.setVisible(true);
38 this.setVisible(true);
39 toFront(); //from Tiger... setAlwaysOnTop(true);
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; };
52 if ( y > screenSize.height ) {
53 y = screenSize.height - h;
54 if ( y < 0 ) { y = 0; };
56 this.setBounds(x, y, w, h);
58 //No Configuration file.
59 Dimension frameSize = ApplicationProperties.getConfirmDialogSize();
60 if (frameSize.height > screenSize.height) {
61 frameSize.height = screenSize.height;
63 if (frameSize.width > screenSize.width) {
64 frameSize.width = screenSize.width;
67 (screenSize.width - frameSize.width) / 2,
68 (screenSize.height - frameSize.height) / 2,
69 frameSize.width, frameSize.height );
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.
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();
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);
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]; }
102 jScrollPane1.setViewportView(jList1);
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);
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);
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)
128 .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE)
131 jPanel1Layout.linkSize(new java.awt.Component[] {jButtonCancel, jButtonOK}, org.jdesktop.layout.GroupLayout.HORIZONTAL);
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)
140 .add(jButtonCancel)))
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()
149 .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
152 layout.setVerticalGroup(
153 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
154 .add(layout.createSequentialGroup()
156 .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
160 }// </editor-fold>//GEN-END:initComponents
162 private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
164 resultNotify.sayNG();
165 }//GEN-LAST:event_formWindowClosing
167 private void jButtonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelActionPerformed
168 resultNotify.sayNG();
170 }//GEN-LAST:event_jButtonCancelActionPerformed
172 private void jButtonOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOKActionPerformed
174 resultNotify.sayOK();
176 }//GEN-LAST:event_jButtonOKActionPerformed
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;
186 if ( x != ApplicationProperties.getConfirmDialogPosX()
187 || y != ApplicationProperties.getConfirmDialogPosY()
188 || h != ApplicationProperties.getConfirmDialogPosH()
189 || w != ApplicationProperties.getConfirmDialogPosW()
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);
205 * @param args the command line arguments
207 * public static void main(String args[]) {
208 * java.awt.EventQueue.invokeLater(new Runnable() {
209 * public void run() {
210 * new ToListUI().setVisible(true);
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