KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > businesslogic > ireport > gui > PropertiesDialog


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  * PropertiesDialog.java
28  *
29  * Created on 7 maggio 2003, 23.43
30  *
31  */

32
33 package it.businesslogic.ireport.gui;
34
35 import it.businesslogic.ireport.*;
36 import it.businesslogic.ireport.SubDataset;
37
38 import javax.swing.table.*;
39 import javax.swing.*;
40 import javax.swing.event.*;
41 import it.businesslogic.ireport.*;
42 import it.businesslogic.ireport.util.*;
43
44 import java.util.*;
45 /**
46  *
47  * @author Administrator
48  */

49 public class PropertiesDialog extends javax.swing.JDialog JavaDoc {
50     
51     /** Creates new form ValuesDialog */
52     public PropertiesDialog(java.awt.Dialog JavaDoc parent, boolean modal) {
53         super(parent, modal);
54         initAll();
55     }
56     public PropertiesDialog(java.awt.Frame JavaDoc parent, boolean modal) {
57         super(parent, modal);
58         initAll();
59     }
60     
61     public void initAll()
62     {
63         initComponents();
64         this.setSize(420, 250);
65         //DefaultTableColumnModel dtcm = (DefaultTableColumnModel)jTableParameters.getColumnModel();
66
//DefaultTableCellRenderer tcr = (DefaultTableCellRenderer)dtcm.getColumn(0).getHeaderRenderer();
67

68         //new DefaultTableCellRenderer();
69
//tcr.setFont(jTableParameters.getFont());
70
//tcr.setBackground(this.getBackground());
71
//tcr.setBorder( new javax.swing.border.BevelBorder( javax.swing.border.BevelBorder.RAISED));
72
//dtcm.getColumn(0).setHeaderRenderer(tcr);
73

74         
75         DefaultListSelectionModel dlsm = (DefaultListSelectionModel)this.jTableProperties.getSelectionModel();
76         dlsm.addListSelectionListener(new javax.swing.event.ListSelectionListener JavaDoc() {
77             public void valueChanged(ListSelectionEvent e) {
78                 jTablePropertiesListSelectionValueChanged(e);
79             }
80         });
81             
82     applyI18n();
83         // Open in center...
84
it.businesslogic.ireport.util.Misc.centerFrame(this);
85         
86         
87         javax.swing.KeyStroke JavaDoc escape = javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0, false);
88         javax.swing.Action JavaDoc escapeAction = new javax.swing.AbstractAction JavaDoc() {
89             public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
90                 jButtonCloseActionPerformed(e);
91             }
92         };
93        
94         getRootPane().getInputMap(javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW).put(escape, "ESCAPE");
95         getRootPane().getActionMap().put("ESCAPE", escapeAction);
96
97
98         //to make the default button ...
99
this.getRootPane().setDefaultButton(this.jButtonClose);
100         
101     }
102     
103     
104     public void jTablePropertiesListSelectionValueChanged(javax.swing.event.ListSelectionEvent JavaDoc e)
105     {
106          if (this.jTableProperties.getSelectedRowCount() > 0) {
107             this.jButtonModifyProperty.setEnabled(true);
108             this.jButtonDeleteProperty.setEnabled(true);
109         }
110         else {
111             this.jButtonModifyProperty.setEnabled(false);
112             this.jButtonDeleteProperty.setEnabled(false);
113         }
114     }
115     
116     /** This method is called from within the constructor to
117      * initialize the form.
118      * WARNING: Do NOT modify this code. The content of this method is
119      * always regenerated by the Form Editor.
120      */

121     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
122
private void initComponents() {
123         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
124
125         jPanelFields = new javax.swing.JPanel JavaDoc();
126         jScrollPane3 = new javax.swing.JScrollPane JavaDoc();
127         jTableProperties = new it.businesslogic.ireport.gui.JDragTable();
128         jPanelButtons2 = new javax.swing.JPanel JavaDoc();
129         jButtonNewProperty = new javax.swing.JButton JavaDoc();
130         jButtonModifyProperty = new javax.swing.JButton JavaDoc();
131         jButtonDeleteProperty = new javax.swing.JButton JavaDoc();
132         jPanel1 = new javax.swing.JPanel JavaDoc();
133         jButtonClose = new javax.swing.JButton JavaDoc();
134
135         setTitle("Values");
136         addWindowListener(new java.awt.event.WindowAdapter JavaDoc() {
137             public void windowClosing(java.awt.event.WindowEvent JavaDoc evt) {
138                 closeDialog(evt);
139             }
140         });
141
142         jPanelFields.setLayout(new java.awt.BorderLayout JavaDoc());
143
144         jScrollPane3.setBackground(new java.awt.Color JavaDoc(255, 255, 255));
145         jScrollPane3.setPreferredSize(new java.awt.Dimension JavaDoc(32767, 32767));
146         jScrollPane3.addMouseListener(new java.awt.event.MouseAdapter JavaDoc() {
147             public void mouseClicked(java.awt.event.MouseEvent JavaDoc evt) {
148                 jScrollPane3MouseClicked(evt);
149             }
150         });
151
152         jTableProperties.setModel(new javax.swing.table.DefaultTableModel JavaDoc(
153             new Object JavaDoc [][] {
154
155             },
156             new String JavaDoc [] {
157                 "Name", "Value"
158             }
159         ) {
160             Class JavaDoc[] types = new Class JavaDoc [] {
161                 java.lang.Object JavaDoc.class, java.lang.String JavaDoc.class
162             };
163             boolean[] canEdit = new boolean [] {
164                 false, false
165             };
166
167             public Class JavaDoc getColumnClass(int columnIndex) {
168                 return types [columnIndex];
169             }
170
171             public boolean isCellEditable(int rowIndex, int columnIndex) {
172                 return canEdit [columnIndex];
173             }
174         });
175         jTableProperties.addMouseListener(new java.awt.event.MouseAdapter JavaDoc() {
176             public void mouseClicked(java.awt.event.MouseEvent JavaDoc evt) {
177                 jTablePropertiesMouseClicked(evt);
178             }
179         });
180
181         jScrollPane3.setViewportView(jTableProperties);
182
183         jPanelFields.add(jScrollPane3, java.awt.BorderLayout.CENTER);
184
185         jPanelButtons2.setLayout(new java.awt.GridBagLayout JavaDoc());
186
187         jPanelButtons2.setPreferredSize(new java.awt.Dimension JavaDoc(100, 100));
188         jPanelButtons2.setMinimumSize(new java.awt.Dimension JavaDoc(100, 10));
189         jButtonNewProperty.setText("New");
190         jButtonNewProperty.addActionListener(new java.awt.event.ActionListener JavaDoc() {
191             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
192                 jButtonNewPropertyActionPerformed(evt);
193             }
194         });
195
196         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
197         gridBagConstraints.gridx = 0;
198         gridBagConstraints.gridy = 0;
199         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
200         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
201         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 4, 0, 4);
202         jPanelButtons2.add(jButtonNewProperty, gridBagConstraints);
203
204         jButtonModifyProperty.setText("Modify");
205         jButtonModifyProperty.setEnabled(false);
206         jButtonModifyProperty.addActionListener(new java.awt.event.ActionListener JavaDoc() {
207             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
208                 jButtonModifyPropertyActionPerformed(evt);
209             }
210         });
211
212         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
213         gridBagConstraints.gridx = 0;
214         gridBagConstraints.gridy = 1;
215         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
216         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
217         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 4, 0, 4);
218         jPanelButtons2.add(jButtonModifyProperty, gridBagConstraints);
219
220         jButtonDeleteProperty.setText("Delete");
221         jButtonDeleteProperty.setEnabled(false);
222         jButtonDeleteProperty.addActionListener(new java.awt.event.ActionListener JavaDoc() {
223             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
224                 jButtonDeletePropertyActionPerformed(evt);
225             }
226         });
227
228         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
229         gridBagConstraints.gridx = 0;
230         gridBagConstraints.gridy = 2;
231         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
232         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
233         gridBagConstraints.insets = new java.awt.Insets JavaDoc(4, 4, 4, 4);
234         jPanelButtons2.add(jButtonDeleteProperty, gridBagConstraints);
235
236         jPanel1.setLayout(new java.awt.BorderLayout JavaDoc());
237
238         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
239         gridBagConstraints.gridx = 0;
240         gridBagConstraints.gridy = 3;
241         gridBagConstraints.weighty = 1.0;
242         jPanelButtons2.add(jPanel1, gridBagConstraints);
243
244         jButtonClose.setMnemonic('c');
245         jButtonClose.setText("Close");
246         jButtonClose.addActionListener(new java.awt.event.ActionListener JavaDoc() {
247             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
248                 jButtonCloseActionPerformed(evt);
249             }
250         });
251
252         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
253         gridBagConstraints.gridx = 0;
254         gridBagConstraints.gridy = 4;
255         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
256         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
257         gridBagConstraints.insets = new java.awt.Insets JavaDoc(4, 4, 4, 4);
258         jPanelButtons2.add(jButtonClose, gridBagConstraints);
259
260         jPanelFields.add(jPanelButtons2, java.awt.BorderLayout.EAST);
261
262         getContentPane().add(jPanelFields, java.awt.BorderLayout.CENTER);
263
264         pack();
265     }// </editor-fold>//GEN-END:initComponents
266

267     private void jButtonCloseActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonCloseActionPerformed
268
setVisible(false);
269     }//GEN-LAST:event_jButtonCloseActionPerformed
270

271     private void jScrollPane3MouseClicked(java.awt.event.MouseEvent JavaDoc evt) {//GEN-FIRST:event_jScrollPane3MouseClicked
272
// Add your handling code here:
273
}//GEN-LAST:event_jScrollPane3MouseClicked
274

275     private void jTablePropertiesMouseClicked(java.awt.event.MouseEvent JavaDoc evt) {//GEN-FIRST:event_jTablePropertiesMouseClicked
276
if (evt.getClickCount() == 2 && evt.getButton() == evt.BUTTON1 && jTableProperties.getSelectedRow() >=0 ) {
277             jButtonModifyPropertyActionPerformed(new java.awt.event.ActionEvent JavaDoc( jButtonModifyProperty,0, ""));
278         }
279     }//GEN-LAST:event_jTablePropertiesMouseClicked
280

281     private void jButtonNewPropertyActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonNewPropertyActionPerformed
282
java.awt.Frame JavaDoc parent = Misc.frameFromComponent(this);
283         JRPropertyDialog jrpd = new JRPropertyDialog( parent, true);
284         jrpd.setVisible(true);
285         
286         if (jrpd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION) {
287             JRProperty property = jrpd.getProperty();
288             this.getDataset().addJRProperty( property );
289             this.updateProperties();
290         }
291     }//GEN-LAST:event_jButtonNewPropertyActionPerformed
292

293     private void jButtonModifyPropertyActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonModifyPropertyActionPerformed
294
JRProperty property = (JRProperty)jTableProperties.getValueAt( jTableProperties.getSelectedRow(), 0);
295         java.awt.Frame JavaDoc parent = Misc.frameFromComponent(this);
296         JRPropertyDialog jrpd = new JRPropertyDialog(parent, true);
297         jrpd.setProperty( property );
298         jrpd.setVisible(true);
299         
300         if (jrpd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION) {
301             property.setName( jrpd.getProperty().getName() );
302             
303             
304             property.setValue( jrpd.getProperty().getValue() );
305             
306             this.updateProperties();
307         }
308     }//GEN-LAST:event_jButtonModifyPropertyActionPerformed
309

310     private void jButtonDeletePropertyActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonDeletePropertyActionPerformed
311
jTableProperties.getSelectedRows();
312         int[] rows= jTableProperties.getSelectedRows();
313         for (int i=rows.length-1; i>=0; --i) {
314             this.getDataset().removeJRProperty( (JRProperty) jTableProperties.getValueAt( rows[i], 0) );
315             //this.jTableParameters.removeRowSelectionInterval( rows[i],rows[i]);
316
}
317         updateProperties();
318     }//GEN-LAST:event_jButtonDeletePropertyActionPerformed
319

320     /** Closes the dialog */
321     private void closeDialog(java.awt.event.WindowEvent JavaDoc evt) {//GEN-FIRST:event_closeDialog
322
setVisible(false);
323     }//GEN-LAST:event_closeDialog
324

325     /**
326      * @param args the command line arguments
327      */

328     public static void main(String JavaDoc args[]) {
329         new ValuesDialog(new javax.swing.JFrame JavaDoc(), true).setVisible(true);
330     }
331     
332     
333     public void setDataset(it.businesslogic.ireport.SubDataset dataset) {
334         this.dataset = dataset;
335         
336         // Update all...
337
if (dataset == null)
338         {
339             setVisible(false);
340             return;
341         }
342         
343         if (isVisible())
344         {
345             this.setTitle(dataset.getName()+" properties...");
346             updateProperties();
347         }
348     }
349     
350     public void updateProperties() {
351         
352         DefaultTableModel dtm = (DefaultTableModel)jTableProperties.getModel();
353         dtm.setRowCount(0);
354     
355         Enumeration e = getDataset().getJRproperties().elements();
356         while (e.hasMoreElements())
357         {
358             it.businesslogic.ireport.JRProperty property = (it.businesslogic.ireport.JRProperty)e.nextElement();
359             Vector row = new Vector();
360             row.addElement( property);
361             row.addElement( property.getValue());
362             
363             dtm.addRow(row);
364         }
365     }
366     public void applyI18n(){
367                 // Start autogenerated code ----------------------
368
// End autogenerated code ----------------------
369
jButtonNewProperty.setText(it.businesslogic.ireport.util.I18n.getString("new","New"));
370         jButtonModifyProperty.setText(it.businesslogic.ireport.util.I18n.getString("modify","Modify"));
371         jButtonDeleteProperty.setText(it.businesslogic.ireport.util.I18n.getString("delete","Delete"));
372         jButtonClose.setText(it.businesslogic.ireport.util.I18n.getString("close","Close"));
373         
374         jTableProperties.getColumnModel().getColumn(0).setHeaderValue( I18n.getString("propertiesDialog.tablecolumn.name","Name") );
375         jTableProperties.getColumnModel().getColumn(1).setHeaderValue( I18n.getString("propertiesDialog.tablecolumn.value","Value") );
376                         
377     }
378     public void languageChanged(LanguageChangedEvent evt) {
379             
380         this.applyI18n();
381     }
382        
383     // Variables declaration - do not modify//GEN-BEGIN:variables
384
private javax.swing.JButton JavaDoc jButtonClose;
385     private javax.swing.JButton JavaDoc jButtonDeleteProperty;
386     private javax.swing.JButton JavaDoc jButtonModifyProperty;
387     private javax.swing.JButton JavaDoc jButtonNewProperty;
388     private javax.swing.JPanel JavaDoc jPanel1;
389     private javax.swing.JPanel JavaDoc jPanelButtons2;
390     private javax.swing.JPanel JavaDoc jPanelFields;
391     private javax.swing.JScrollPane JavaDoc jScrollPane3;
392     private it.businesslogic.ireport.gui.JDragTable jTableProperties;
393     // End of variables declaration//GEN-END:variables
394

395     private SubDataset dataset;
396
397     public void setVisible(boolean visible)
398     {
399         if (visible == isVisible()) return;
400         super.setVisible(visible);
401         if (visible == true)
402         {
403             this.setDataset(this.dataset);
404         }
405     }
406
407     public SubDataset getDataset() {
408         return dataset;
409     }
410    
411    }
412
Popular Tags