KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > businesslogic > ireport > gui > subdataset > SortFieldDialog


1 /*
2  * Copyright (C) 2005 - 2006 JasperSoft Corporation. All rights reserved.
3  * http://www.jaspersoft.com.
4  *
5  * Unless you have purchased a commercial license agreement from JasperSoft,
6  * the following license terms apply:
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as published by
10  * the Free Software Foundation.
11  *
12  * This program is distributed WITHOUT ANY WARRANTY; and without the
13  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
18  * or write to:
19  *
20  * Free Software Foundation, Inc.,
21  * 59 Temple Place - Suite 330,
22  * Boston, MA USA 02111-1307
23  *
24  *
25  *
26  *
27  * SortFieldDialog.java
28  *
29  * Created on 9 maggio 2003, 17.25
30  *
31  */

32
33 package it.businesslogic.ireport.gui.subdataset;
34
35 import it.businesslogic.ireport.gui.sheet.Tag;
36 import it.businesslogic.ireport.util.*;
37 import it.businesslogic.ireport.*;
38 import it.businesslogic.ireport.util.I18n;
39 import java.util.Vector JavaDoc;
40 /**
41  *
42  * @author Administrator
43  */

44 public class SortFieldDialog extends javax.swing.JDialog JavaDoc {
45     /**
46      * Creates new form SortFieldDialog
47      */

48     private SortField tmpSortField = null;
49     
50     public SortFieldDialog(java.awt.Dialog JavaDoc parent, boolean modal) {
51         
52         super(parent, modal);
53         initComponents();
54         jComboBoxSortBy.setEditable(true);
55         applyI18n();
56         
57         
58         javax.swing.KeyStroke JavaDoc escape = javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0, false);
59         javax.swing.Action JavaDoc escapeAction = new javax.swing.AbstractAction JavaDoc() {
60             public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
61                 jButtonCancelActionPerformed(e);
62             }
63         };
64        
65         getRootPane().getInputMap(javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW).put(escape, "ESCAPE");
66         getRootPane().getActionMap().put("ESCAPE", escapeAction);
67
68
69         //to make the default button ...
70
this.getRootPane().setDefaultButton(this.jButtonOK);
71         
72         applyI18n();
73         this.pack();
74         
75     }
76     
77     public void applyI18n()
78     {
79                 // Start autogenerated code ----------------------
80
// End autogenerated code ----------------------
81
this.setTitle( I18n.getString("sortFieldDialog.title","Sort field") );
82         jLabelSortBy.setText( I18n.getString("sortFieldDialog.labelSortBy","Sort by..."));
83         jLabelSortType.setText( I18n.getString("sortFieldDialog.labelSortType","Sort type"));
84         this.jComboBoxSortType.removeAllItems();
85         this.jComboBoxSortType.addItem(new Tag("Ascending",I18n.getString("sortFieldDialog.Ascending","Ascending")));
86         this.jComboBoxSortType.addItem(new Tag("Descending",I18n.getString("sortFieldDialog.Descending","Descending")));
87         Misc.setComboboxSelectedTagValue(jComboBoxSortType, "Ascending");
88         jButtonOK.setText( I18n.getString("ok","Ok"));
89         jButtonCancel.setText(I18n.getString("cancel","Cancel"));
90     }
91     
92     /**
93      * Populate the fields combobox
94      */

95     private void setFieldNames(Vector JavaDoc fields)
96     {
97         jComboBoxSortBy.removeAllItems();
98         if (fields != null)
99         {
100             for (int i=0; i<fields.size(); ++i)
101             {
102                 jComboBoxSortBy.addItem( fields.get(i) + "" );
103             }
104         }
105         
106     }
107     
108     /** This method is called from within the constructor to
109      * initialize the form.
110      * WARNING: Do NOT modify this code. The content of this method is
111      * always regenerated by the Form Editor.
112      */

113     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
114
private void initComponents() {
115         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
116
117         jLabelSortBy = new javax.swing.JLabel JavaDoc();
118         jComboBoxSortBy = new javax.swing.JComboBox JavaDoc();
119         jSeparator1 = new javax.swing.JSeparator JavaDoc();
120         jPanel1 = new javax.swing.JPanel JavaDoc();
121         jButtonOK = new javax.swing.JButton JavaDoc();
122         jButtonCancel = new javax.swing.JButton JavaDoc();
123         jLabelSortType = new javax.swing.JLabel JavaDoc();
124         jComboBoxSortType = new javax.swing.JComboBox JavaDoc();
125
126         getContentPane().setLayout(new java.awt.GridBagLayout JavaDoc());
127
128         setTitle("Add/modify parameter");
129         setModal(true);
130         addWindowListener(new java.awt.event.WindowAdapter JavaDoc() {
131             public void windowClosing(java.awt.event.WindowEvent JavaDoc evt) {
132                 closeDialog(evt);
133             }
134         });
135
136         jLabelSortBy.setText("Sort by");
137         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
138         gridBagConstraints.gridx = 0;
139         gridBagConstraints.gridy = 2;
140         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
141         gridBagConstraints.insets = new java.awt.Insets JavaDoc(4, 4, 0, 4);
142         getContentPane().add(jLabelSortBy, gridBagConstraints);
143
144         jComboBoxSortBy.setEditable(true);
145         jComboBoxSortBy.setPreferredSize(new java.awt.Dimension JavaDoc(250, 22));
146         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
147         gridBagConstraints.gridx = 0;
148         gridBagConstraints.gridy = 3;
149         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
150         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
151         gridBagConstraints.weightx = 1.0;
152         gridBagConstraints.insets = new java.awt.Insets JavaDoc(4, 4, 4, 4);
153         getContentPane().add(jComboBoxSortBy, gridBagConstraints);
154
155         jSeparator1.setMinimumSize(new java.awt.Dimension JavaDoc(2, 2));
156         jSeparator1.setPreferredSize(new java.awt.Dimension JavaDoc(2, 2));
157         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
158         gridBagConstraints.gridx = 0;
159         gridBagConstraints.gridy = 8;
160         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
161         gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH;
162         gridBagConstraints.weighty = 1.0;
163         getContentPane().add(jSeparator1, gridBagConstraints);
164
165         jPanel1.setLayout(new java.awt.FlowLayout JavaDoc(java.awt.FlowLayout.RIGHT));
166
167         jButtonOK.setMnemonic('o');
168         jButtonOK.setText("OK");
169         jButtonOK.addActionListener(new java.awt.event.ActionListener JavaDoc() {
170             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
171                 jButtonOKActionPerformed(evt);
172             }
173         });
174
175         jPanel1.add(jButtonOK);
176
177         jButtonCancel.setMnemonic('c');
178         jButtonCancel.setText("Cancel");
179         jButtonCancel.addActionListener(new java.awt.event.ActionListener JavaDoc() {
180             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
181                 jButtonCancelActionPerformed(evt);
182             }
183         });
184
185         jPanel1.add(jButtonCancel);
186
187         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
188         gridBagConstraints.gridx = 0;
189         gridBagConstraints.gridy = 9;
190         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
191         gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH;
192         gridBagConstraints.weightx = 1.0;
193         getContentPane().add(jPanel1, gridBagConstraints);
194
195         jLabelSortType.setText("Sort type");
196         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
197         gridBagConstraints.gridx = 0;
198         gridBagConstraints.gridy = 4;
199         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
200         gridBagConstraints.insets = new java.awt.Insets JavaDoc(4, 4, 0, 4);
201         getContentPane().add(jLabelSortType, gridBagConstraints);
202
203         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
204         gridBagConstraints.gridx = 0;
205         gridBagConstraints.gridy = 5;
206         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
207         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
208         gridBagConstraints.weightx = 1.0;
209         gridBagConstraints.insets = new java.awt.Insets JavaDoc(4, 4, 8, 4);
210         getContentPane().add(jComboBoxSortType, gridBagConstraints);
211
212         pack();
213         java.awt.Dimension JavaDoc screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
214         java.awt.Dimension JavaDoc dialogSize = getSize();
215         setLocation((screenSize.width-dialogSize.width)/2,(screenSize.height-dialogSize.height)/2);
216     }// </editor-fold>//GEN-END:initComponents
217

218     private void jButtonCancelActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonCancelActionPerformed
219
setVisible(false);
220         this.setDialogResult( javax.swing.JOptionPane.CANCEL_OPTION);
221         dispose();
222     }//GEN-LAST:event_jButtonCancelActionPerformed
223

224     private void jButtonOKActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonOKActionPerformed
225

226         String JavaDoc fieldName = (String JavaDoc)this.jComboBoxSortBy.getSelectedItem();
227         if (fieldName == null) fieldName="";
228         fieldName = fieldName.trim();
229         
230         if (fieldName.length() <= 0)
231         {
232             javax.swing.JOptionPane.showMessageDialog(this,
233                     I18n.getString("sortFieldDialog.messageNotValidField","Please insert a valid field name!"),
234                     I18n.getString("sortFieldDialog.messageTitleNotValidField","Invalid field!"),
235                     javax.swing.JOptionPane.WARNING_MESSAGE );
236             return;
237         }
238         
239         tmpSortField = new SortField(
240                     fieldName,
241                     jComboBoxSortType.getSelectedIndex() == 1
242                 );
243
244         setVisible(false);
245         this.setDialogResult( javax.swing.JOptionPane.OK_OPTION);
246         dispose();
247     }//GEN-LAST:event_jButtonOKActionPerformed
248

249     /** Closes the dialog */
250     private void closeDialog(java.awt.event.WindowEvent JavaDoc evt) {//GEN-FIRST:event_closeDialog
251
setVisible(false);
252         this.setDialogResult( javax.swing.JOptionPane.CLOSED_OPTION);
253         dispose();
254     }//GEN-LAST:event_closeDialog
255

256     
257     /** Getter for property dialogResult.
258      * @return Value of property dialogResult.
259      *
260      */

261     public int getDialogResult() {
262         return dialogResult;
263     }
264     
265     /** Setter for property dialogResult.
266      * @param dialogResult New value of property dialogResult.
267      *
268      */

269     public void setDialogResult(int dialogResult) {
270         this.dialogResult = dialogResult;
271     }
272     
273     // Variables declaration - do not modify//GEN-BEGIN:variables
274
private javax.swing.JButton JavaDoc jButtonCancel;
275     private javax.swing.JButton JavaDoc jButtonOK;
276     private javax.swing.JComboBox JavaDoc jComboBoxSortBy;
277     private javax.swing.JComboBox JavaDoc jComboBoxSortType;
278     private javax.swing.JLabel JavaDoc jLabelSortBy;
279     private javax.swing.JLabel JavaDoc jLabelSortType;
280     private javax.swing.JPanel JavaDoc jPanel1;
281     private javax.swing.JSeparator JavaDoc jSeparator1;
282     // End of variables declaration//GEN-END:variables
283

284     private int dialogResult;
285     
286     public void setSubDataset(SubDataset subDataset) {
287     
288        //jRTextExpressionAreaDefaultExpression.setSubDataset( subDataset);
289
//jRTextExpressionAreaDefaultExpression.getTokenMarker().setKeywordLookup(subDataset.getKeywordLookup());
290
setFieldNames( subDataset.getFields() );
291        
292     }
293
294     /**
295      * return a new sortField instance
296      */

297     public SortField getSortField() {
298         return tmpSortField;
299     }
300
301     public void setSortField(SortField tmpSortField) {
302         this.tmpSortField = new SortField(tmpSortField);
303         this.jComboBoxSortBy.setSelectedItem( tmpSortField.getFieldName() );
304         this.jComboBoxSortType.setSelectedIndex( (tmpSortField.isDesc() ? 1 : 0) );
305     }
306     
307 }
308
Popular Tags