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 */
27 public ToListUI(ResultNotify processer, List toList) {
28 this(); //TODO: test dould call...
30 this.resultNotify = processer;
33 jList1.setListData(toList.toArray());
35 jList1.setVisible(true);
37 this.setVisible(true);
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; };
50 if ( y > screenSize.height ) {
51 y = screenSize.height - h;
52 if ( y < 0 ) { y = 0; };
54 this.setBounds(x, y, w, h);
56 //No Configuration file.
57 Dimension frameSize = ApplicationProperties.getConfirmDialogSize();
58 if (frameSize.height > screenSize.height) {
59 frameSize.height = screenSize.height;
61 if (frameSize.width > screenSize.width) {
62 frameSize.width = screenSize.width;
65 (screenSize.width - frameSize.width) / 2,
66 (screenSize.height - frameSize.height) / 2,
67 frameSize.width, frameSize.height );
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.
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();
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);
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]; }
99 jScrollPane1.setViewportView(jList1);
101 jButtonOK.setText("OK");
102 jButtonOK.addActionListener(new java.awt.event.ActionListener() {
103 public void actionPerformed(java.awt.event.ActionEvent evt) {
104 jButtonOKActionPerformed(evt);
108 jButtonCancel.setText("Cancel");
109 jButtonCancel.addActionListener(new java.awt.event.ActionListener() {
110 public void actionPerformed(java.awt.event.ActionEvent evt) {
111 jButtonCancelActionPerformed(evt);
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)
125 .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE)
128 jPanel1Layout.linkSize(new java.awt.Component[] {jButtonCancel, jButtonOK}, org.jdesktop.layout.GroupLayout.HORIZONTAL);
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)
137 .add(jButtonCancel)))
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()
146 .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
149 layout.setVerticalGroup(
150 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
151 .add(layout.createSequentialGroup()
153 .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
157 }// </editor-fold>//GEN-END:initComponents
159 private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
161 resultNotify.sayNG();
162 }//GEN-LAST:event_formWindowClosed
164 private void jButtonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelActionPerformed
165 resultNotify.sayNG();
167 }//GEN-LAST:event_jButtonCancelActionPerformed
169 private void jButtonOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOKActionPerformed
171 resultNotify.sayOK();
173 }//GEN-LAST:event_jButtonOKActionPerformed
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;
183 if ( x != ApplicationProperties.getConfirmDialogPosX()
184 || y != ApplicationProperties.getConfirmDialogPosY()
185 || h != ApplicationProperties.getConfirmDialogPosH()
186 || w != ApplicationProperties.getConfirmDialogPosW()
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.
201 * @param args the command line arguments
203 * public static void main(String args[]) {
204 * java.awt.EventQueue.invokeLater(new Runnable() {
205 * public void run() {
206 * new ToListUI().setVisible(true);
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