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: * SheetPanel.java
028: *
029: * Created on 4 ottobre 2004, 23.21
030: *
031: */
032:
033: package it.businesslogic.ireport.gui.sheet;
034:
035: import java.util.*;
036: import javax.swing.*;
037:
038: /**
039: *
040: * @author Administrator
041: */
042: public class SheetPanel extends javax.swing.JPanel {
043:
044: private java.util.Vector properties;
045:
046: /** Creates new form SheetPanel */
047: public SheetPanel() {
048: initComponents();
049: properties = new Vector();
050:
051: }
052:
053: public java.util.Properties getPropertiesValues() {
054: java.util.Properties prop = new java.util.Properties();
055:
056: for (int i = 0; i < getProperties().size(); ++i) {
057: SheetProperty sp = (SheetProperty) getProperties()
058: .elementAt(i);
059: Object value = "";
060: value = getPropertyValue(i);
061: if (value != null) {
062: prop.setProperty(sp.getKeyName(), value + "");
063: }
064: }
065: return prop;
066: }
067:
068: public void setPropertiesValues(java.util.Properties prop) {
069: Enumeration enum_keys = prop.keys();
070: while (enum_keys.hasMoreElements()) {
071: String key = (String) enum_keys.nextElement();
072: // Looking for this property...
073: for (int i = 0; i < getProperties().size(); ++i) {
074: SheetProperty sp = (SheetProperty) getProperties()
075: .elementAt(i);
076: if (sp.getKeyName().equals(key)) {
077: String value = prop.getProperty(key);
078: sp.setEditorValue(
079: (javax.swing.JComponent) jPanelEditors
080: .getComponent((2 * i) + 1), value);
081: }
082: }
083: }
084: }
085:
086: public Object getPropertyValue(int index) {
087: SheetProperty sp = (SheetProperty) getProperties().elementAt(
088: index);
089: return sp.getEditorValue((javax.swing.JComponent) jPanelEditors
090: .getComponent((2 * index) + 1));
091: }
092:
093: public void removeAllProperties() {
094: getProperties().removeAllElements();
095: jPanelLabels.removeAll();
096: jPanelEditors.removeAll();
097: jPanelLabels.setLayout(new java.awt.GridBagLayout());
098: jPanelEditors.setLayout(new java.awt.GridBagLayout());
099: java.awt.GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints();
100: gridBagConstraints.gridx = 0;
101: gridBagConstraints.gridy = 400;
102: gridBagConstraints.weighty = 1.0;
103:
104: jPanelEditors.add(jPanelFillerEditors, gridBagConstraints);
105: jPanelLabels.add(jPanelFillerLabels, gridBagConstraints);
106:
107: jPanelEditors.setMinimumSize(new java.awt.Dimension(50, 0));
108: jPanelLabels.setMinimumSize(new java.awt.Dimension(50, 0));
109: jPanelLabels.updateUI();
110: jPanelEditors.updateUI();
111: jScrollPane1.updateUI();
112: }
113:
114: public void addSheetProperty(SheetProperty sp) {
115: properties.add(sp);
116:
117: JLabel jLabel = new JLabel(sp.getName());
118: jLabel.setMaximumSize(new java.awt.Dimension(41, 18));
119: jLabel.setMinimumSize(new java.awt.Dimension(41, 18));
120: jLabel.setPreferredSize(new java.awt.Dimension(41, 18));
121: java.awt.GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints();
122: gridBagConstraints.gridx = 0;
123: gridBagConstraints.gridy = (properties.size() - 1) * 2;
124: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
125: gridBagConstraints.weightx = 1.0;
126: gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 2);
127:
128: jPanelLabels.add(jLabel, gridBagConstraints);
129:
130: /******** Set editor *******/
131: javax.swing.JComponent editor = sp.getEditor();
132: editor.setOpaque(false);
133: editor.setBackground(java.awt.Color.WHITE);
134: editor.setMaximumSize(new java.awt.Dimension(41, 18));
135: editor.setMinimumSize(new java.awt.Dimension(41, 18));
136: editor.setPreferredSize(new java.awt.Dimension(41, 18));
137:
138: if (editor instanceof JComboBox
139: || editor instanceof ColorSelectorPanel) {
140: gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 0);
141: }
142: jPanelEditors.add(editor, gridBagConstraints);
143:
144: JSeparator jSeparator = new JSeparator(JSeparator.HORIZONTAL);
145: jSeparator.setPreferredSize(new java.awt.Dimension(0, 1));
146: JSeparator jSeparator1 = new JSeparator(JSeparator.HORIZONTAL);
147: jSeparator1.setPreferredSize(new java.awt.Dimension(0, 1));
148: gridBagConstraints = new java.awt.GridBagConstraints();
149: gridBagConstraints.gridx = 0;
150: gridBagConstraints.gridy = (properties.size() * 2) - 1;
151: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
152:
153: jPanelLabels.add(jSeparator, gridBagConstraints);
154: jPanelEditors.add(jSeparator1, gridBagConstraints);
155:
156: jPanelLabels.setMinimumSize(new java.awt.Dimension(30,
157: 20 * properties.size()));
158: jPanelLabels.setPreferredSize(new java.awt.Dimension(30,
159: 20 * properties.size()));
160: jPanelEditors.setMinimumSize(new java.awt.Dimension(30,
161: 20 * properties.size()));
162: jPanelEditors.setPreferredSize(new java.awt.Dimension(30,
163: 20 * properties.size()));
164:
165: jPanelLabels.updateUI();
166: jScrollPane1.updateUI();
167: }
168:
169: public java.util.Vector getProperties() {
170: return properties;
171: }
172:
173: public void setProperties(java.util.Vector properties) {
174: this .properties = properties;
175: }
176:
177: /** This method is called from within the constructor to
178: * initialize the form.
179: * WARNING: Do NOT modify this code. The content of this method is
180: * always regenerated by the Form Editor.
181: */
182: private void initComponents() {//GEN-BEGIN:initComponents
183: java.awt.GridBagConstraints gridBagConstraints;
184:
185: jScrollPane1 = new javax.swing.JScrollPane();
186: jPanelSheet = new javax.swing.JPanel();
187: jPanel1 = new javax.swing.JPanel();
188: jSplitPane1 = new javax.swing.JSplitPane();
189: jPanelLabels = new javax.swing.JPanel();
190: jPanelFillerLabels = new javax.swing.JPanel();
191: jPanelEditors = new javax.swing.JPanel();
192: jPanelFillerEditors = new javax.swing.JPanel();
193:
194: setLayout(new java.awt.BorderLayout());
195:
196: setBackground(new java.awt.Color(255, 255, 255));
197: jScrollPane1.setBackground(new java.awt.Color(255, 255, 255));
198: jScrollPane1.setOpaque(false);
199: jPanelSheet.setLayout(new java.awt.GridBagLayout());
200:
201: jPanelSheet.setBackground(new java.awt.Color(255, 255, 255));
202: jPanel1.setLayout(new java.awt.GridBagLayout());
203:
204: jPanel1.setMaximumSize(new java.awt.Dimension(16, 2147483647));
205: jPanel1.setMinimumSize(new java.awt.Dimension(16, 20));
206: jPanel1.setPreferredSize(new java.awt.Dimension(16, 0));
207: gridBagConstraints = new java.awt.GridBagConstraints();
208: gridBagConstraints.gridx = 0;
209: gridBagConstraints.gridy = 0;
210: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
211: jPanelSheet.add(jPanel1, gridBagConstraints);
212:
213: jSplitPane1.setBackground(new java.awt.Color(255, 255, 255));
214: jSplitPane1.setBorder(null);
215: jSplitPane1.setDividerSize(1);
216: jSplitPane1.setResizeWeight(0.5);
217: jSplitPane1.setContinuousLayout(true);
218: jPanelLabels.setLayout(new java.awt.GridBagLayout());
219:
220: jPanelLabels.setBackground(new java.awt.Color(255, 255, 255));
221: jPanelLabels.setMinimumSize(new java.awt.Dimension(100, 10));
222: jPanelLabels.setPreferredSize(new java.awt.Dimension(100, 10));
223: jPanelFillerLabels
224: .setMinimumSize(new java.awt.Dimension(10, 0));
225: jPanelFillerLabels.setPreferredSize(new java.awt.Dimension(10,
226: 0));
227: gridBagConstraints = new java.awt.GridBagConstraints();
228: gridBagConstraints.gridx = 0;
229: gridBagConstraints.gridy = 400;
230: gridBagConstraints.weighty = 1.0;
231: jPanelLabels.add(jPanelFillerLabels, gridBagConstraints);
232:
233: jSplitPane1.setLeftComponent(jPanelLabels);
234:
235: jPanelEditors.setLayout(new java.awt.GridBagLayout());
236:
237: jPanelEditors.setBackground(new java.awt.Color(255, 255, 255));
238: jPanelFillerEditors
239: .setMinimumSize(new java.awt.Dimension(10, 0));
240: jPanelFillerEditors.setPreferredSize(new java.awt.Dimension(10,
241: 0));
242: gridBagConstraints = new java.awt.GridBagConstraints();
243: gridBagConstraints.gridx = 0;
244: gridBagConstraints.gridy = 400;
245: gridBagConstraints.weighty = 1.0;
246: jPanelEditors.add(jPanelFillerEditors, gridBagConstraints);
247:
248: jSplitPane1.setRightComponent(jPanelEditors);
249:
250: gridBagConstraints = new java.awt.GridBagConstraints();
251: gridBagConstraints.gridx = 1;
252: gridBagConstraints.gridy = 0;
253: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
254: gridBagConstraints.weightx = 1.0;
255: gridBagConstraints.weighty = 1.0;
256: jPanelSheet.add(jSplitPane1, gridBagConstraints);
257:
258: jScrollPane1.setViewportView(jPanelSheet);
259:
260: add(jScrollPane1, java.awt.BorderLayout.CENTER);
261:
262: }//GEN-END:initComponents
263:
264: // Variables declaration - do not modify//GEN-BEGIN:variables
265: private javax.swing.JPanel jPanel1;
266: private javax.swing.JPanel jPanelEditors;
267: private javax.swing.JPanel jPanelFillerEditors;
268: private javax.swing.JPanel jPanelFillerLabels;
269: private javax.swing.JPanel jPanelLabels;
270: private javax.swing.JPanel jPanelSheet;
271: private javax.swing.JScrollPane jScrollPane1;
272: private javax.swing.JSplitPane jSplitPane1;
273: // End of variables declaration//GEN-END:variables
274:
275: }
|