001: /*
002: * Copyright (C) 2005 - 2008 JasperSoft Corporation. All rights reserved.
003: * http://www.jaspersoft.com.
004: *
005: * Unless you have purchased a commercial license agreement from JasperSoft,
006: * the following license terms apply:
007: *
008: * This program is free software; you can redistribute it and/or modify
009: * it under the terms of the GNU General Public License version 2 as published by
010: * the Free Software Foundation.
011: *
012: * This program is distributed WITHOUT ANY WARRANTY; and without the
013: * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
014: * See the GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
018: * or write to:
019: *
020: * Free Software Foundation, Inc.,
021: * 59 Temple Place - Suite 330,
022: * Boston, MA USA 02111-1307
023: *
024: *
025: *
026: *
027: * PropertiesDialog.java
028: *
029: * Created on 7 maggio 2003, 23.43
030: *
031: */
032:
033: package it.businesslogic.ireport.gui;
034:
035: import it.businesslogic.ireport.*;
036: import it.businesslogic.ireport.JRProperty;
037: import it.businesslogic.ireport.SubDataset;
038:
039: import javax.swing.table.*;
040: import javax.swing.*;
041: import javax.swing.event.*;
042: import it.businesslogic.ireport.*;
043: import it.businesslogic.ireport.gui.table.CustomColumnControlButton;
044: import it.businesslogic.ireport.util.*;
045:
046: import java.util.*;
047: import org.jdesktop.swingx.icon.ColumnControlIcon;
048:
049: /**
050: *
051: * @author Administrator
052: */
053: public class PropertiesDialog extends javax.swing.JDialog {
054:
055: private int dialogResult = JOptionPane.CANCEL_OPTION;
056: private java.util.List properties = null;
057:
058: /** Creates new form ValuesDialog */
059: public PropertiesDialog(java.awt.Dialog parent, boolean modal) {
060: super (parent, modal);
061: initAll();
062: }
063:
064: public PropertiesDialog(java.awt.Frame parent, boolean modal) {
065: super (parent, modal);
066: initAll();
067: }
068:
069: public void initAll() {
070: initComponents();
071: this .setSize(420, 250);
072:
073: jTableProperties
074: .setColumnControl(new CustomColumnControlButton(
075: jTableProperties, new ColumnControlIcon()));
076:
077: DefaultListSelectionModel dlsm = (DefaultListSelectionModel) this .jTableProperties
078: .getSelectionModel();
079: dlsm
080: .addListSelectionListener(new javax.swing.event.ListSelectionListener() {
081: public void valueChanged(ListSelectionEvent e) {
082: jTablePropertiesListSelectionValueChanged(e);
083: }
084: });
085:
086: applyI18n();
087: // Open in center...
088: it.businesslogic.ireport.util.Misc.centerFrame(this );
089:
090: javax.swing.KeyStroke escape = javax.swing.KeyStroke
091: .getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0,
092: false);
093: javax.swing.Action escapeAction = new javax.swing.AbstractAction() {
094: public void actionPerformed(java.awt.event.ActionEvent e) {
095: jButtonOkActionPerformed(e);
096: }
097: };
098:
099: getRootPane().getInputMap(
100: javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW).put(
101: escape, "ESCAPE");
102: getRootPane().getActionMap().put("ESCAPE", escapeAction);
103:
104: //to make the default button ...
105: this .getRootPane().setDefaultButton(this .jButtonOk);
106:
107: }
108:
109: public void jTablePropertiesListSelectionValueChanged(
110: javax.swing.event.ListSelectionEvent e) {
111: if (this .jTableProperties.getSelectedRowCount() > 0) {
112: this .jButtonModifyProperty.setEnabled(true);
113: this .jButtonDeleteProperty.setEnabled(true);
114: } else {
115: this .jButtonModifyProperty.setEnabled(false);
116: this .jButtonDeleteProperty.setEnabled(false);
117: }
118: }
119:
120: /** This method is called from within the constructor to
121: * initialize the form.
122: * WARNING: Do NOT modify this code. The content of this method is
123: * always regenerated by the Form Editor.
124: */
125: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
126: private void initComponents() {
127: java.awt.GridBagConstraints gridBagConstraints;
128:
129: jPanelFields = new javax.swing.JPanel();
130: jScrollPane3 = new javax.swing.JScrollPane();
131: jTableProperties = new it.businesslogic.ireport.gui.table.JDragTable();
132: jPanelButtons2 = new javax.swing.JPanel();
133: jButtonNewProperty = new javax.swing.JButton();
134: jButtonModifyProperty = new javax.swing.JButton();
135: jButtonDeleteProperty = new javax.swing.JButton();
136: jPanel1 = new javax.swing.JPanel();
137: jPanel2 = new javax.swing.JPanel();
138: jSeparator1 = new javax.swing.JSeparator();
139: jButtonOk = new javax.swing.JButton();
140: jButtonCancel = new javax.swing.JButton();
141:
142: setTitle("Values");
143: addWindowListener(new java.awt.event.WindowAdapter() {
144: public void windowClosing(java.awt.event.WindowEvent evt) {
145: closeDialog(evt);
146: }
147: });
148:
149: jPanelFields.setLayout(new java.awt.BorderLayout());
150:
151: jScrollPane3.setBackground(new java.awt.Color(255, 255, 255));
152: jScrollPane3.setPreferredSize(new java.awt.Dimension(32767,
153: 32767));
154: jScrollPane3
155: .addMouseListener(new java.awt.event.MouseAdapter() {
156: public void mouseClicked(
157: java.awt.event.MouseEvent evt) {
158: jScrollPane3MouseClicked(evt);
159: }
160: });
161:
162: jTableProperties
163: .setModel(new javax.swing.table.DefaultTableModel(
164: new Object[][] {
165:
166: }, new String[] { "Name", "Value" }) {
167: Class[] types = new Class[] {
168: java.lang.Object.class,
169: java.lang.String.class };
170: boolean[] canEdit = new boolean[] { false, false };
171:
172: public Class getColumnClass(int columnIndex) {
173: return types[columnIndex];
174: }
175:
176: public boolean isCellEditable(int rowIndex,
177: int columnIndex) {
178: return canEdit[columnIndex];
179: }
180: });
181: jTableProperties
182: .addMouseListener(new java.awt.event.MouseAdapter() {
183: public void mouseClicked(
184: java.awt.event.MouseEvent evt) {
185: jTablePropertiesMouseClicked(evt);
186: }
187: });
188:
189: jScrollPane3.setViewportView(jTableProperties);
190:
191: jPanelFields.add(jScrollPane3, java.awt.BorderLayout.CENTER);
192:
193: jPanelButtons2.setLayout(new java.awt.GridBagLayout());
194:
195: jPanelButtons2.setMinimumSize(new java.awt.Dimension(100, 10));
196: jPanelButtons2
197: .setPreferredSize(new java.awt.Dimension(100, 100));
198: jButtonNewProperty.setText("New");
199: jButtonNewProperty
200: .addActionListener(new java.awt.event.ActionListener() {
201: public void actionPerformed(
202: java.awt.event.ActionEvent evt) {
203: jButtonNewPropertyActionPerformed(evt);
204: }
205: });
206:
207: gridBagConstraints = new java.awt.GridBagConstraints();
208: gridBagConstraints.gridx = 0;
209: gridBagConstraints.gridy = 0;
210: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
211: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
212: gridBagConstraints.weightx = 1.0;
213: gridBagConstraints.insets = new java.awt.Insets(5, 4, 0, 4);
214: jPanelButtons2.add(jButtonNewProperty, gridBagConstraints);
215:
216: jButtonModifyProperty.setText("Modify");
217: jButtonModifyProperty.setEnabled(false);
218: jButtonModifyProperty
219: .addActionListener(new java.awt.event.ActionListener() {
220: public void actionPerformed(
221: java.awt.event.ActionEvent evt) {
222: jButtonModifyPropertyActionPerformed(evt);
223: }
224: });
225:
226: gridBagConstraints = new java.awt.GridBagConstraints();
227: gridBagConstraints.gridx = 0;
228: gridBagConstraints.gridy = 1;
229: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
230: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
231: gridBagConstraints.weightx = 1.0;
232: gridBagConstraints.insets = new java.awt.Insets(3, 4, 0, 4);
233: jPanelButtons2.add(jButtonModifyProperty, gridBagConstraints);
234:
235: jButtonDeleteProperty.setText("Delete");
236: jButtonDeleteProperty.setEnabled(false);
237: jButtonDeleteProperty
238: .addActionListener(new java.awt.event.ActionListener() {
239: public void actionPerformed(
240: java.awt.event.ActionEvent evt) {
241: jButtonDeletePropertyActionPerformed(evt);
242: }
243: });
244:
245: gridBagConstraints = new java.awt.GridBagConstraints();
246: gridBagConstraints.gridx = 0;
247: gridBagConstraints.gridy = 2;
248: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
249: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
250: gridBagConstraints.weightx = 1.0;
251: gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
252: jPanelButtons2.add(jButtonDeleteProperty, gridBagConstraints);
253:
254: jPanel1.setLayout(new java.awt.BorderLayout());
255:
256: gridBagConstraints = new java.awt.GridBagConstraints();
257: gridBagConstraints.gridx = 0;
258: gridBagConstraints.gridy = 3;
259: gridBagConstraints.weighty = 1.0;
260: jPanelButtons2.add(jPanel1, gridBagConstraints);
261:
262: jPanelFields.add(jPanelButtons2, java.awt.BorderLayout.EAST);
263:
264: jPanel2.setLayout(new java.awt.GridBagLayout());
265:
266: jSeparator1.setMinimumSize(new java.awt.Dimension(2, 2));
267: jSeparator1.setPreferredSize(new java.awt.Dimension(2, 2));
268: gridBagConstraints = new java.awt.GridBagConstraints();
269: gridBagConstraints.gridwidth = 2;
270: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
271: gridBagConstraints.insets = new java.awt.Insets(8, 0, 0, 0);
272: jPanel2.add(jSeparator1, gridBagConstraints);
273:
274: jButtonOk.setMnemonic('o');
275: jButtonOk.setText("Ok");
276: jButtonOk
277: .addActionListener(new java.awt.event.ActionListener() {
278: public void actionPerformed(
279: java.awt.event.ActionEvent evt) {
280: jButtonOkActionPerformed(evt);
281: }
282: });
283:
284: gridBagConstraints = new java.awt.GridBagConstraints();
285: gridBagConstraints.gridx = 0;
286: gridBagConstraints.gridy = 4;
287: gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
288: gridBagConstraints.weightx = 1.0;
289: gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
290: jPanel2.add(jButtonOk, gridBagConstraints);
291:
292: jButtonCancel.setMnemonic('c');
293: jButtonCancel.setText("Cancel");
294: jButtonCancel
295: .addActionListener(new java.awt.event.ActionListener() {
296: public void actionPerformed(
297: java.awt.event.ActionEvent evt) {
298: jButtonCloseActionPerformed1(evt);
299: }
300: });
301:
302: gridBagConstraints = new java.awt.GridBagConstraints();
303: gridBagConstraints.gridx = 1;
304: gridBagConstraints.gridy = 4;
305: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
306: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
307: gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
308: jPanel2.add(jButtonCancel, gridBagConstraints);
309:
310: jPanelFields.add(jPanel2, java.awt.BorderLayout.SOUTH);
311:
312: getContentPane()
313: .add(jPanelFields, java.awt.BorderLayout.CENTER);
314:
315: pack();
316: }// </editor-fold>//GEN-END:initComponents
317:
318: private void jButtonCloseActionPerformed1(
319: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCloseActionPerformed1
320:
321: this .setDialogResult(JOptionPane.CANCEL_OPTION);
322: this .setVisible(false);
323: this .dispose();
324: }//GEN-LAST:event_jButtonCloseActionPerformed1
325:
326: private void jButtonOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOkActionPerformed
327:
328: DefaultTableModel dtm = (DefaultTableModel) jTableProperties
329: .getModel();
330: this .properties = new java.util.ArrayList();
331:
332: for (int i = 0; i < dtm.getRowCount(); ++i) {
333: this .properties.add(dtm.getValueAt(i, 0));
334: }
335:
336: this .setDialogResult(JOptionPane.OK_OPTION);
337: this .setVisible(false);
338: this .dispose();
339: }//GEN-LAST:event_jButtonOkActionPerformed
340:
341: private void jScrollPane3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jScrollPane3MouseClicked
342: // Add your handling code here:
343: }//GEN-LAST:event_jScrollPane3MouseClicked
344:
345: private void jTablePropertiesMouseClicked(
346: java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTablePropertiesMouseClicked
347: if (evt.getClickCount() == 2 && evt.getButton() == evt.BUTTON1
348: && jTableProperties.getSelectedRow() >= 0) {
349: jButtonModifyPropertyActionPerformed(new java.awt.event.ActionEvent(
350: jButtonModifyProperty, 0, ""));
351: }
352: }//GEN-LAST:event_jTablePropertiesMouseClicked
353:
354: private void jButtonNewPropertyActionPerformed(
355: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonNewPropertyActionPerformed
356: java.awt.Frame parent = Misc.frameFromComponent(this );
357: JRPropertyDialog jrpd = new JRPropertyDialog(parent, true);
358: jrpd.setVisible(true);
359:
360: DefaultTableModel dtm = (DefaultTableModel) jTableProperties
361: .getModel();
362:
363: if (jrpd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION) {
364: JRProperty property = jrpd.getProperty();
365: dtm.addRow(new Object[] { property, property.getValue() });
366: jTableProperties.updateUI();
367: }
368:
369: }//GEN-LAST:event_jButtonNewPropertyActionPerformed
370:
371: private void jButtonModifyPropertyActionPerformed(
372: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonModifyPropertyActionPerformed
373:
374: int index = jTableProperties.getSelectedRow();
375: index = jTableProperties.convertRowIndexToModel(index);
376: DefaultTableModel dtm = (DefaultTableModel) jTableProperties
377: .getModel();
378: JRProperty property = (JRProperty) dtm.getValueAt(index, 0);
379:
380: java.awt.Frame parent = Misc.frameFromComponent(this );
381: JRPropertyDialog jrpd = new JRPropertyDialog(parent, true);
382: jrpd.setProperty(property);
383: jrpd.setVisible(true);
384:
385: if (jrpd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION) {
386: property.setName(jrpd.getProperty().getName());
387: property.setValue(jrpd.getProperty().getValue());
388: dtm.setValueAt(property, index, 0);
389: dtm.setValueAt(property.getValue(), index, 1);
390: jTableProperties.updateUI();
391: }
392: }//GEN-LAST:event_jButtonModifyPropertyActionPerformed
393:
394: private void jButtonDeletePropertyActionPerformed(
395: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonDeletePropertyActionPerformed
396:
397: int[] rows = jTableProperties.getSelectedRows();
398: DefaultTableModel dtm = (DefaultTableModel) jTableProperties
399: .getModel();
400: for (int i = rows.length - 1; i >= 0; --i) {
401:
402: dtm.removeRow(jTableProperties
403: .convertRowIndexToModel(rows[i]));
404: }
405: }//GEN-LAST:event_jButtonDeletePropertyActionPerformed
406:
407: /** Closes the dialog */
408: private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
409: setVisible(false);
410: }//GEN-LAST:event_closeDialog
411:
412: public void setProperties(java.util.List properties) {
413:
414: DefaultTableModel dtm = (DefaultTableModel) jTableProperties
415: .getModel();
416: dtm.setRowCount(0);
417:
418: Iterator iter = properties.iterator();
419: while (iter.hasNext()) {
420: it.businesslogic.ireport.JRProperty property = (it.businesslogic.ireport.JRProperty) iter
421: .next();
422: // Make a copy...
423: it.businesslogic.ireport.JRProperty property2 = property
424: .cloneMe();
425: Vector row = new Vector();
426: row.addElement(property2);
427: row.addElement(property2.getValue());
428: dtm.addRow(row);
429: }
430: }
431:
432: public void applyI18n() {
433: // Start autogenerated code ----------------------
434: // End autogenerated code ----------------------
435: jButtonNewProperty.setText(it.businesslogic.ireport.util.I18n
436: .getString("new", "New"));
437: jButtonModifyProperty
438: .setText(it.businesslogic.ireport.util.I18n.getString(
439: "modify", "Modify"));
440: jButtonDeleteProperty
441: .setText(it.businesslogic.ireport.util.I18n.getString(
442: "delete", "Delete"));
443:
444: jButtonCancel.setText(I18n.getString(
445: "jRFieldDialog.buttonCancel", "Cancel"));
446: jButtonOk.setText(I18n
447: .getString("jRFieldDialog.buttonOK", "OK"));
448:
449: jTableProperties.getColumnModel().getColumn(0).setHeaderValue(
450: I18n.getString("propertiesDialog.tablecolumn.name",
451: "Name"));
452: jTableProperties.getColumnModel().getColumn(1).setHeaderValue(
453: I18n.getString("propertiesDialog.tablecolumn.value",
454: "Value"));
455: this .setTitle(I18n.getString("propertiesDialog.title",
456: "Properties"));
457:
458: jButtonCancel.setMnemonic(I18n.getString(
459: "jRFieldDialog.buttonCancelMnemonic", "c").charAt(0));
460: jButtonOk.setMnemonic(I18n.getString(
461: "jRFieldDialog.buttonOKMnemonic", "o").charAt(0));
462:
463: }
464:
465: public void languageChanged(LanguageChangedEvent evt) {
466:
467: this .applyI18n();
468: }
469:
470: public int getDialogResult() {
471: return dialogResult;
472: }
473:
474: public void setDialogResult(int dialogResult) {
475: this .dialogResult = dialogResult;
476: }
477:
478: public java.util.List getProperties() {
479: return properties;
480: }
481:
482: // Variables declaration - do not modify//GEN-BEGIN:variables
483: private javax.swing.JButton jButtonCancel;
484: private javax.swing.JButton jButtonDeleteProperty;
485: private javax.swing.JButton jButtonModifyProperty;
486: private javax.swing.JButton jButtonNewProperty;
487: private javax.swing.JButton jButtonOk;
488: private javax.swing.JPanel jPanel1;
489: private javax.swing.JPanel jPanel2;
490: private javax.swing.JPanel jPanelButtons2;
491: private javax.swing.JPanel jPanelFields;
492: private javax.swing.JScrollPane jScrollPane3;
493: private javax.swing.JSeparator jSeparator1;
494: private it.businesslogic.ireport.gui.table.JDragTable jTableProperties;
495: // End of variables declaration//GEN-END:variables
496:
497: }
|