KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > businesslogic > ireport > gui > style > StyleDialog


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

32
33 package it.businesslogic.ireport.gui.style;
34 import it.businesslogic.ireport.ConditionedStyle;
35 import it.businesslogic.ireport.CrosstabReportElement;
36 import it.businesslogic.ireport.IReportFont;
37 import it.businesslogic.ireport.Report;
38 import it.businesslogic.ireport.ReportElement;
39 import it.businesslogic.ireport.SubDataset;
40 import it.businesslogic.ireport.gui.ExpressionEditor;
41 import it.businesslogic.ireport.gui.JRParameterDialog;
42 import it.businesslogic.ireport.gui.event.SheetPropertyValueChangedListener;
43 import it.businesslogic.ireport.gui.sheet.*;
44 import it.businesslogic.ireport.Style;
45 import it.businesslogic.ireport.gui.MainFrame;
46 import it.businesslogic.ireport.gui.event.StyleChangedEvent;
47 import it.businesslogic.ireport.gui.sheet.FontSheetProperty;
48 import it.businesslogic.ireport.gui.sheet.SheetProperty;
49 import java.util.Enumeration JavaDoc;
50 import java.util.HashMap JavaDoc;
51 import java.util.Iterator JavaDoc;
52 import java.util.Vector JavaDoc;
53 import javax.swing.DefaultListModel JavaDoc;
54 import javax.swing.JOptionPane JavaDoc;
55 import javax.swing.ListSelectionModel JavaDoc;
56 import it.businesslogic.ireport.util.I18n;
57
58 /**
59  *
60  * @author Administrator
61  */

62 public class StyleDialog extends javax.swing.JDialog JavaDoc implements SheetPropertyValueChangedListener {
63
64     /**
65      * If libraryStyle is set to true, this means that you are not editing a report style,
66      * but a style that belongs to the style library. In this case no events are generated on
67      * completation and the modified Style is available with the method getStyle.
68      *
69      * The default value for this attribute is FALSE.
70      */

71     private boolean libraryStyle = false;
72
73
74     /**
75      * A reference to the style appearing in the sheet. Could be the master or
76      * a style referring to a condition
77      */

78     private Style style = null;
79
80     /**
81      * A reference to the style master
82      */

83     private Style masterStyle = null;
84
85     /**
86      * A reference to the style we are modifying. We work on a copy (masterStyle)
87      */

88     private Style editingStyle = null;
89
90     /**
91      * Prevent some events during initializazion...
92      */

93     private boolean init = false;
94
95     /**
96      * Panel showing a sample of the current style
97      */

98     JPanelStyleSample panelSample = new JPanelStyleSample();
99
100
101     private CategorySheetPanel sheetPanel = null;
102
103
104     private IReportFont ireportFont = null;
105     private Report currentReport = null;
106
107
108     //** Creates new dialog StyleDialog */
109
public StyleDialog(java.awt.Dialog JavaDoc parent, boolean modal) {
110         super(parent,modal);
111         initAll();
112     }
113
114     /** Creates new dialog ChartPropertiesDialog */
115     public StyleDialog(java.awt.Frame JavaDoc parent, boolean modal) {
116         super(parent,modal);
117         initAll();
118     }
119
120     public void initAll()
121     {
122         initComponents();
123
124         style = new Style();
125
126         setMasterStyle(style);
127         applyI18n();
128         //this.setSize(420, 620);
129
this.pack();
130
131         // Open in center...
132
it.businesslogic.ireport.util.Misc.centerFrame(this);
133
134         java.awt.GridBagConstraints JavaDoc gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
135         gridBagConstraints.gridx = 4;
136         gridBagConstraints.gridy = 2;
137         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
138         gridBagConstraints.weightx = 1.0;
139         gridBagConstraints.weighty = 1.0;
140         gridBagConstraints.fill = gridBagConstraints.BOTH;
141         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, -1, -1, -1);
142         sheetPanel = new CategorySheetPanel();
143         sheetPanel.addSheetPropertyValueChangedListener(this);
144
145         jPanelProperties.add(sheetPanel, gridBagConstraints);
146
147         //applyI18n();
148

149         // Add styles....
150
SheetProperty customizerClassProperty = new SheetProperty( Style.ATTRIBUTE_name ,"Style name", SheetProperty.STRING);
151         sheetPanel.addSheetProperty("Style", customizerClassProperty);
152
153         SheetProperty isDefaultProperty = new SheetProperty(Style.ATTRIBUTE_isDefault,"Default style", SheetProperty.BOOLEAN);
154         sheetPanel.addSheetProperty("Style", isDefaultProperty);
155
156         SheetProperty modeProperty = new SheetProperty(Style.ATTRIBUTE_mode,"Mode", SheetProperty.COMBOBOX);
157         modeProperty.setTags( new Tag[]{ new Tag(null,"Default"), new Tag("Opaque","Opaque"),
158                                          new Tag("Transparent","Transparent")});
159         sheetPanel.addSheetProperty("Common", modeProperty);
160
161         SheetProperty forecolorProperty = new SheetProperty(Style.ATTRIBUTE_forecolor,"Forecolor", SheetProperty.COLOR);
162         forecolorProperty.setValue( null );
163         sheetPanel.addSheetProperty("Common", forecolorProperty);
164
165         SheetProperty backcolorProperty = new SheetProperty(Style.ATTRIBUTE_backcolor,"Backcolor", SheetProperty.COLOR);
166         backcolorProperty.setValue( null );
167         sheetPanel.addSheetProperty("Common", backcolorProperty);
168
169         ComboBoxSheetProperty styleProperty = new ComboBoxSheetProperty(Style.ATTRIBUTE_style,"Parent style");
170
171         sheetPanel.addSheetProperty("Style", styleProperty);
172
173         SheetProperty penProperty = new SheetProperty(Style.ATTRIBUTE_pen,"Pen", SheetProperty.COMBOBOX);
174         penProperty.setTags( new Tag[]{ new Tag(null,"Default"),new Tag("Thin","Thin"),
175                                         new Tag("1Point","1Point"),
176                                         new Tag("2Point","2Point"),
177                                         new Tag("4Point","4Point"),
178                                         new Tag("Dotted","Dotted")});
179         sheetPanel.addSheetProperty("Graphics", penProperty);
180
181         SheetProperty fillProperty = new SheetProperty(Style.ATTRIBUTE_fill,"Fill", SheetProperty.COMBOBOX);
182         fillProperty.setTags( new Tag[]{ new Tag(null,"Default"),new Tag("Solid","Solid")});
183         sheetPanel.addSheetProperty("Graphics", fillProperty);
184
185         SheetProperty radiusProperty = new SheetProperty(Style.ATTRIBUTE_radius,"Radius", SheetProperty.INTEGER);
186         sheetPanel.addSheetProperty("Graphics", radiusProperty);
187
188         SheetProperty scaleImageProperty = new SheetProperty(Style.ATTRIBUTE_scaleImage,"Scale image", SheetProperty.COMBOBOX);
189         scaleImageProperty.setTags( new Tag[]{ new Tag(null,"Default"),new Tag("Clip","Clip"),
190                                                new Tag("FillFrame","FillFrame"),
191                                                new Tag("RetainShape","RetainShape")});
192         sheetPanel.addSheetProperty("Graphics", scaleImageProperty);
193
194         SheetProperty hAlignProperty = new SheetProperty(Style.ATTRIBUTE_hAlign,"Horizontal align", SheetProperty.COMBOBOX);
195         hAlignProperty.setTags( new Tag[]{ new Tag(null,"Default"),new Tag("Left","Left"),
196                                                new Tag("Center","Center"),
197                                                new Tag("Right","Right"),
198                                                new Tag("Justified","Justified")});
199         sheetPanel.addSheetProperty("Graphics", hAlignProperty);
200
201     SheetProperty vAlignProperty = new SheetProperty(Style.ATTRIBUTE_vAlign,"Vertical align", SheetProperty.COMBOBOX);
202         vAlignProperty.setTags( new Tag[]{ new Tag(null,"Default"),new Tag("Top","Top"),
203                                                new Tag("Middle","Middle"),
204                                                new Tag("Bottom","Bottom")});
205         sheetPanel.addSheetProperty("Graphics", vAlignProperty);
206
207
208     SheetProperty borderProperty = new SheetProperty(Style.ATTRIBUTE_border,"Border", SheetProperty.COMBOBOX);
209         borderProperty.setTags( new Tag[]{new Tag(null,"Default"),
210                                         new Tag("Thin","Thin"),
211                                         new Tag("1Point","1Point"),
212                                         new Tag("2Point","2Point"),
213                                         new Tag("4Point","4Point"),
214                                         new Tag("Dotted","Dotted")});
215         sheetPanel.addSheetProperty("Border and padding", borderProperty);
216
217         SheetProperty borderColorProperty = new SheetProperty(Style.ATTRIBUTE_borderColor,"Border color", SheetProperty.COLOR);
218         sheetPanel.addSheetProperty("Border and padding", borderColorProperty);
219
220         SheetProperty paddingProperty = new SheetProperty(Style.ATTRIBUTE_padding,"Padding", SheetProperty.INTEGER);
221         sheetPanel.addSheetProperty("Border and padding", paddingProperty);
222
223         SheetProperty topBorderProperty = new SheetProperty(Style.ATTRIBUTE_topBorder,"Top border", SheetProperty.COMBOBOX);
224         topBorderProperty.setTags( new Tag[]{
225                                         new Tag(null,"Default"),
226                                         new Tag("Thin","Thin"),
227                                         new Tag("1Point","1Point"),
228                                         new Tag("2Point","2Point"),
229                                         new Tag("4Point","4Point"),
230                                         new Tag("Dotted","Dotted")});
231         sheetPanel.addSheetProperty("Border and padding", topBorderProperty);
232
233         SheetProperty topBorderColorProperty = new SheetProperty(Style.ATTRIBUTE_topBorderColor,"Top border color", SheetProperty.COLOR);
234         sheetPanel.addSheetProperty("Border and padding", topBorderColorProperty);
235
236         SheetProperty topPaddingProperty = new SheetProperty(Style.ATTRIBUTE_topPadding,"Top padding", SheetProperty.INTEGER);
237         sheetPanel.addSheetProperty("Border and padding", topPaddingProperty);
238
239         SheetProperty leftBorderProperty = new SheetProperty(Style.ATTRIBUTE_leftBorder,"Left border", SheetProperty.COMBOBOX);
240         leftBorderProperty.setTags( new Tag[]{
241                                         new Tag(null,"Default"),
242                                         new Tag("Thin","Thin"),
243                                         new Tag("1Point","1Point"),
244                                         new Tag("2Point","2Point"),
245                                         new Tag("4Point","4Point"),
246                                         new Tag("Dotted","Dotted")});
247         sheetPanel.addSheetProperty("Border and padding", leftBorderProperty);
248
249         SheetProperty leftBorderColorProperty = new SheetProperty(Style.ATTRIBUTE_leftBorderColor,"Left border color", SheetProperty.COLOR);
250         sheetPanel.addSheetProperty("Border and padding", leftBorderColorProperty);
251
252         SheetProperty leftPaddingProperty = new SheetProperty(Style.ATTRIBUTE_leftPadding,"Left padding", SheetProperty.INTEGER);
253         sheetPanel.addSheetProperty("Border and padding", leftPaddingProperty);
254
255         SheetProperty bottomBorderProperty = new SheetProperty(Style.ATTRIBUTE_bottomBorder,"Bottom border", SheetProperty.COMBOBOX);
256         bottomBorderProperty.setTags( new Tag[]{
257                                         new Tag(null,"Default"),
258                                         new Tag("Thin","Thin"),
259                                         new Tag("1Point","1Point"),
260                                         new Tag("2Point","2Point"),
261                                         new Tag("4Point","4Point"),
262                                         new Tag("Dotted","Dotted")});
263         sheetPanel.addSheetProperty("Border and padding", bottomBorderProperty);
264
265         SheetProperty bottomBorderColorProperty = new SheetProperty(Style.ATTRIBUTE_bottomBorderColor,"Bottom border color", SheetProperty.COLOR);
266         sheetPanel.addSheetProperty("Border and padding", bottomBorderColorProperty);
267
268         SheetProperty bottomPaddingProperty = new SheetProperty(Style.ATTRIBUTE_bottomPadding,"Bottom padding", SheetProperty.INTEGER);
269         sheetPanel.addSheetProperty("Border and padding", bottomPaddingProperty);
270
271         SheetProperty rightBorderProperty = new SheetProperty(Style.ATTRIBUTE_rightBorder,"Right border", SheetProperty.COMBOBOX);
272         rightBorderProperty.setTags( new Tag[]{
273                                         new Tag(null,"Default"),
274                                         new Tag("Thin","Thin"),
275                                         new Tag("1Point","1Point"),
276                                         new Tag("2Point","2Point"),
277                                         new Tag("4Point","4Point"),
278                                         new Tag("Dotted","Dotted")});
279         sheetPanel.addSheetProperty("Border and padding", rightBorderProperty);
280
281         SheetProperty rightBorderColorProperty = new SheetProperty(Style.ATTRIBUTE_rightBorderColor,"Right border color", SheetProperty.COLOR);
282         sheetPanel.addSheetProperty("Border and padding", rightBorderColorProperty);
283
284         SheetProperty rightPaddingProperty = new SheetProperty(Style.ATTRIBUTE_rightPadding,"Right padding", SheetProperty.INTEGER);
285         sheetPanel.addSheetProperty("Border and padding", rightPaddingProperty);
286
287         SheetProperty rotationProperty = new SheetProperty(Style.ATTRIBUTE_rotation,"Rotation", SheetProperty.COMBOBOX);
288         rotationProperty.setTags( new Tag[]{ new Tag(null,"Default"),
289                                              new Tag("None","None"),
290                                              new Tag("Left","Left"),
291                                              new Tag("Right","Right"),
292                                              new Tag("UpsideDown","UpsideDown")});
293         sheetPanel.addSheetProperty("Text properties", rotationProperty);
294
295         SheetProperty patternProperty = new SheetProperty(Style.ATTRIBUTE_pattern,"Pattern", SheetProperty.STRING);
296         sheetPanel.addSheetProperty("Text properties", patternProperty);
297
298         SheetProperty isBlankWhenNullProperty = new SheetProperty(Style.ATTRIBUTE_isBlankWhenNull,"Is Blank when Null", SheetProperty.BOOLEAN);
299         sheetPanel.addSheetProperty("Text properties", isBlankWhenNullProperty);
300
301         // FONT...
302
FontSheetProperty theFontSpacingProperty = new FontSheetProperty("style.font","Font");
303         theFontSpacingProperty.setFontMode( 3 );
304         sheetPanel.addSheetProperty("Text properties", theFontSpacingProperty);
305
306         SheetProperty lineSpacingProperty = new SheetProperty(Style.ATTRIBUTE_lineSpacing,"Line spacing", SheetProperty.COMBOBOX);
307         lineSpacingProperty.setTags( new Tag[]{ new Tag(null,"Default"),
308                                              new Tag("Single","Single"),
309                                              new Tag("1_1_2","1_1_2"),
310                                              new Tag("Double","Double")});
311         sheetPanel.addSheetProperty("Text properties", lineSpacingProperty);
312
313         /*
314         SheetProperty fontNameProperty = new SheetProperty("style.fontName","Font", SheetProperty.COMBOBOX);
315         fontNameProperty.setTags( new Tag[]{ });
316         sheetPanel.addSheetProperty("Text properties", fontNameProperty);
317         */

318         SheetProperty isBoldProperty = new SheetProperty(Style.ATTRIBUTE_isBold,"Bold", SheetProperty.BOOLEAN);
319         sheetPanel.addSheetProperty("Text properties", isBoldProperty);
320
321         SheetProperty isItalicProperty = new SheetProperty(Style.ATTRIBUTE_isItalic,"Italic", SheetProperty.BOOLEAN);
322         sheetPanel.addSheetProperty("Text properties", isItalicProperty);
323
324         SheetProperty isUnderlineProperty = new SheetProperty(Style.ATTRIBUTE_isUnderline,"Underline", SheetProperty.BOOLEAN);
325         sheetPanel.addSheetProperty("Text properties", isUnderlineProperty);
326
327         SheetProperty isStrikeThroughProperty = new SheetProperty(Style.ATTRIBUTE_isStrikeThrough,"StrikeThrough", SheetProperty.BOOLEAN);
328         sheetPanel.addSheetProperty("Text properties", isStrikeThroughProperty);
329
330         //SheetProperty fontSizeProperty = new SheetProperty(Style.ATTRIBUTE_,"Font size", SheetProperty.INTEGER);
331
//sheetPanel.addSheetProperty("Text properties", fontSizeProperty);
332

333         /*
334         SheetProperty pdfFontNameProperty = new SheetProperty("style.pdfFontName","PDF Font name", SheetProperty.COMBOBOX);
335         pdfFontNameProperty.setTags( new Tag[]{ });
336         sheetPanel.addSheetProperty("Text properties", pdfFontNameProperty);
337
338         SheetProperty pdfEncodingProperty = new SheetProperty("style.pdfEncoding","PDF Encoding", SheetProperty.STRING);
339         sheetPanel.addSheetProperty("Text properties", pdfEncodingProperty);
340
341     SheetProperty isPdfEmbeddedProperty = new SheetProperty("style.isPdfEmbedded","Embed PDF fonts", SheetProperty.STRING);
342         sheetPanel.addSheetProperty("Text properties", isPdfEmbeddedProperty);
343         */

344
345         gridBagConstraints.gridx = 0;
346         gridBagConstraints.gridy = 0;
347         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
348         gridBagConstraints.weightx = 1.0;
349         gridBagConstraints.weighty = 1.0;
350         gridBagConstraints.fill = gridBagConstraints.BOTH;
351         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0,0, 0, 0);
352
353         this.jPanelSample.add(panelSample,gridBagConstraints);
354
355         SheetProperty isStyledTextProperty = new SheetProperty(Style.ATTRIBUTE_isStyledText,"Is Styled Text", SheetProperty.BOOLEAN);
356         sheetPanel.addSheetProperty("Text properties", isStyledTextProperty);
357         // FINE FONT...
358
sheetPanel.recreateSheet();
359
360         sheetPanel.collapseCategory("Border and padding");
361
362         this.updateStyleValues();
363
364         this.jConditionsList.setModel( new DefaultListModel JavaDoc());
365         this.jConditionsList.setSelectionMode( ListSelectionModel.SINGLE_SELECTION);
366
367         ((DefaultListModel JavaDoc)this.jConditionsList.getModel()).addElement("Default");
368         this.jConditionsList.setSelectedIndex(0);
369         
370         javax.swing.KeyStroke JavaDoc escape = javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0, false);
371         javax.swing.Action JavaDoc escapeAction = new javax.swing.AbstractAction JavaDoc() {
372             public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
373                 jButtonCancelActionPerformed(e);
374             }
375         };
376        
377         getRootPane().getInputMap(javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW).put(escape, "ESCAPE");
378         getRootPane().getActionMap().put("ESCAPE", escapeAction);
379
380
381         //to make the default button ...
382
this.getRootPane().setDefaultButton(this.jButtonOK);
383     }
384
385
386     /** This method is called from within the constructor to
387      * initialize the form.
388      * WARNING: Do NOT modify this code. The content of this method is
389      * always regenerated by the Form Editor.
390      */

391     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
392
private void initComponents() {
393         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
394
395         jSplitPane1 = new javax.swing.JSplitPane JavaDoc();
396         jPanelProperties = new javax.swing.JPanel JavaDoc();
397         jPanelConditions = new javax.swing.JPanel JavaDoc();
398         jLabelStyleConditions = new javax.swing.JLabel JavaDoc();
399         jScrollPane1 = new javax.swing.JScrollPane JavaDoc();
400         jConditionsList = new javax.swing.JList JavaDoc();
401         jPanel2 = new javax.swing.JPanel JavaDoc();
402         jButtonAddCondition = new javax.swing.JButton JavaDoc();
403         jButtonModifyCondition = new javax.swing.JButton JavaDoc();
404         jButtonRemoveCondition = new javax.swing.JButton JavaDoc();
405         jButtonUpCondition = new javax.swing.JButton JavaDoc();
406         jButtonDownCondition = new javax.swing.JButton JavaDoc();
407         jLabelSample = new javax.swing.JLabel JavaDoc();
408         jPanelSample = new javax.swing.JPanel JavaDoc();
409         jPanel1 = new javax.swing.JPanel JavaDoc();
410         jButtonOK = new javax.swing.JButton JavaDoc();
411         jButtonCancel = new javax.swing.JButton JavaDoc();
412
413         getContentPane().setLayout(new java.awt.GridBagLayout JavaDoc());
414
415         setTitle("Add/modify Style");
416         setTitle(it.businesslogic.ireport.util.I18n.getString("addModStyle", "Add/modify Style"));//I18N
417
setModal(true);
418         addWindowListener(new java.awt.event.WindowAdapter JavaDoc() {
419             public void windowClosing(java.awt.event.WindowEvent JavaDoc evt) {
420                 closeDialog(evt);
421             }
422         });
423
424         jSplitPane1.setResizeWeight(0.5);
425         jPanelProperties.setLayout(new java.awt.GridBagLayout JavaDoc());
426
427         jPanelProperties.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
428         jPanelProperties.setMinimumSize(new java.awt.Dimension JavaDoc(100, 4));
429         jPanelProperties.setPreferredSize(new java.awt.Dimension JavaDoc(320, 470));
430         jSplitPane1.setLeftComponent(jPanelProperties);
431
432         jPanelConditions.setLayout(new java.awt.GridBagLayout JavaDoc());
433
434         jPanelConditions.setMinimumSize(new java.awt.Dimension JavaDoc(100, 10));
435         jPanelConditions.setPreferredSize(new java.awt.Dimension JavaDoc(200, 10));
436         jLabelStyleConditions.setText("Style conditions");
437         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
438         gridBagConstraints.gridx = 0;
439         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
440         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
441         gridBagConstraints.weightx = 1.0;
442         gridBagConstraints.insets = new java.awt.Insets JavaDoc(4, 4, 0, 4);
443         jPanelConditions.add(jLabelStyleConditions, gridBagConstraints);
444
445         jConditionsList.addListSelectionListener(new javax.swing.event.ListSelectionListener JavaDoc() {
446             public void valueChanged(javax.swing.event.ListSelectionEvent JavaDoc evt) {
447                 jConditionsListValueChanged(evt);
448             }
449         });
450         jConditionsList.addMouseListener(new java.awt.event.MouseAdapter JavaDoc() {
451             public void mouseClicked(java.awt.event.MouseEvent JavaDoc evt) {
452                 jConditionsListMouseClicked(evt);
453             }
454         });
455
456         jScrollPane1.setViewportView(jConditionsList);
457
458         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
459         gridBagConstraints.gridx = 0;
460         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
461         gridBagConstraints.weightx = 1.0;
462         gridBagConstraints.weighty = 1.0;
463         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 4, 0, 4);
464         jPanelConditions.add(jScrollPane1, gridBagConstraints);
465
466         jPanel2.setLayout(new java.awt.GridBagLayout JavaDoc());
467
468         jButtonAddCondition.setText("Add");
469         jButtonAddCondition.setMargin(new java.awt.Insets JavaDoc(2, 2, 2, 2));
470         jButtonAddCondition.addActionListener(new java.awt.event.ActionListener JavaDoc() {
471             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
472                 jButtonAddConditionActionPerformed(evt);
473             }
474         });
475
476         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
477         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
478         gridBagConstraints.weightx = 1.0;
479         jPanel2.add(jButtonAddCondition, gridBagConstraints);
480
481         jButtonModifyCondition.setText("Modify");
482         jButtonModifyCondition.setEnabled(false);
483         jButtonModifyCondition.setMargin(new java.awt.Insets JavaDoc(2, 2, 2, 2));
484         jButtonModifyCondition.addActionListener(new java.awt.event.ActionListener JavaDoc() {
485             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
486                 jButtonModifyConditionActionPerformed(evt);
487             }
488         });
489
490         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
491         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
492         gridBagConstraints.weightx = 1.0;
493         jPanel2.add(jButtonModifyCondition, gridBagConstraints);
494
495         jButtonRemoveCondition.setText("Remove");
496         jButtonRemoveCondition.setEnabled(false);
497         jButtonRemoveCondition.setMargin(new java.awt.Insets JavaDoc(2, 2, 2, 2));
498         jButtonRemoveCondition.addActionListener(new java.awt.event.ActionListener JavaDoc() {
499             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
500                 jButtonRemoveConditionActionPerformed(evt);
501             }
502         });
503
504         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
505         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
506         gridBagConstraints.weightx = 1.0;
507         jPanel2.add(jButtonRemoveCondition, gridBagConstraints);
508
509         jButtonUpCondition.setText("up");
510         jButtonUpCondition.setEnabled(false);
511         jButtonUpCondition.setMargin(new java.awt.Insets JavaDoc(2, 2, 2, 2));
512         jButtonUpCondition.addActionListener(new java.awt.event.ActionListener JavaDoc() {
513             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
514                 jButtonUpConditionActionPerformed(evt);
515             }
516         });
517
518         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
519         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
520         gridBagConstraints.weightx = 1.0;
521         jPanel2.add(jButtonUpCondition, gridBagConstraints);
522
523         jButtonDownCondition.setText("Down");
524         jButtonDownCondition.setEnabled(false);
525         jButtonDownCondition.setMargin(new java.awt.Insets JavaDoc(2, 2, 2, 2));
526         jButtonDownCondition.addActionListener(new java.awt.event.ActionListener JavaDoc() {
527             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
528                 jButtonDownConditionActionPerformed(evt);
529             }
530         });
531
532         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
533         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
534         gridBagConstraints.weightx = 1.0;
535         jPanel2.add(jButtonDownCondition, gridBagConstraints);
536
537         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
538         gridBagConstraints.gridx = 0;
539         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
540         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 4, 4, 4);
541         jPanelConditions.add(jPanel2, gridBagConstraints);
542
543         jLabelSample.setText("Sample");
544         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
545         gridBagConstraints.gridx = 0;
546         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
547         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
548         gridBagConstraints.weightx = 1.0;
549         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 4, 0, 4);
550         jPanelConditions.add(jLabelSample, gridBagConstraints);
551
552         jPanelSample.setLayout(new java.awt.GridBagLayout JavaDoc());
553
554         jPanelSample.setBorder(javax.swing.BorderFactory.createEtchedBorder());
555         jPanelSample.setMinimumSize(new java.awt.Dimension JavaDoc(100, 80));
556         jPanelSample.setPreferredSize(new java.awt.Dimension JavaDoc(14, 80));
557         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
558         gridBagConstraints.gridx = 0;
559         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
560         gridBagConstraints.ipadx = 4;
561         gridBagConstraints.ipady = 4;
562         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 4, 4, 4);
563         jPanelConditions.add(jPanelSample, gridBagConstraints);
564
565         jSplitPane1.setRightComponent(jPanelConditions);
566
567         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
568         gridBagConstraints.gridx = 0;
569         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
570         gridBagConstraints.ipadx = 4;
571         gridBagConstraints.ipady = 4;
572         gridBagConstraints.weightx = 1.0;
573         gridBagConstraints.weighty = 1.0;
574         getContentPane().add(jSplitPane1, gridBagConstraints);
575
576         jPanel1.setLayout(new java.awt.FlowLayout JavaDoc(java.awt.FlowLayout.RIGHT));
577
578         jButtonOK.setMnemonic('o');
579         jButtonOK.setText("OK");
580         jButtonOK.addActionListener(new java.awt.event.ActionListener JavaDoc() {
581             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
582                 jButtonOKActionPerformed(evt);
583             }
584         });
585
586         jPanel1.add(jButtonOK);
587
588         jButtonCancel.setText("Cancel");
589         jButtonCancel.setMnemonic('c');
590         jButtonCancel.addActionListener(new java.awt.event.ActionListener JavaDoc() {
591             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
592                 jButtonCancelActionPerformed(evt);
593             }
594         });
595
596         jPanel1.add(jButtonCancel);
597
598         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
599         gridBagConstraints.gridx = 0;
600         gridBagConstraints.gridy = 9;
601         gridBagConstraints.gridwidth = 2;
602         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
603         gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
604         gridBagConstraints.weightx = 1.0;
605         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 3, 3, 3);
606         getContentPane().add(jPanel1, gridBagConstraints);
607
608         pack();
609         java.awt.Dimension JavaDoc screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
610         java.awt.Dimension JavaDoc dialogSize = getSize();
611         setLocation((screenSize.width-dialogSize.width)/2,(screenSize.height-dialogSize.height)/2);
612     }// </editor-fold>//GEN-END:initComponents
613

614     private void jButtonDownConditionActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonDownConditionActionPerformed
615
DefaultListModel JavaDoc dlm = (DefaultListModel JavaDoc)this.jConditionsList.getModel();
616         setInit(true);
617         int i = jConditionsList.getSelectedIndex();
618         Object JavaDoc cs = jConditionsList.getSelectedValue();
619         dlm.removeElementAt(i);
620         dlm.insertElementAt(cs, i+1);
621         jConditionsList.setSelectedIndex(i+1);
622
623         jButtonUpCondition.setEnabled(true);
624         if (i == dlm.size()-2) jButtonDownCondition.setEnabled(false);
625         setInit(false);
626     }//GEN-LAST:event_jButtonDownConditionActionPerformed
627

628     private void jButtonUpConditionActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonUpConditionActionPerformed
629

630         DefaultListModel JavaDoc dlm = (DefaultListModel JavaDoc)this.jConditionsList.getModel();
631         setInit(true);
632         int i = jConditionsList.getSelectedIndex();
633         Object JavaDoc cs = jConditionsList.getSelectedValue();
634         dlm.removeElementAt(i);
635         dlm.insertElementAt(cs, i-1);
636         jConditionsList.setSelectedIndex(i-1);
637
638         if (i == 2) jButtonUpCondition.setEnabled(false);
639         jButtonDownCondition.setEnabled(true);
640         setInit(false);
641
642
643     }//GEN-LAST:event_jButtonUpConditionActionPerformed
644

645     private void jButtonRemoveConditionActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonRemoveConditionActionPerformed
646

647         if (jConditionsList.getSelectedIndex() == 0) return;
648         int i = jConditionsList.getSelectedIndex();
649         jConditionsList.setSelectedIndex(i-1);
650         ((DefaultListModel JavaDoc)this.jConditionsList.getModel()).remove( i);
651
652
653     }//GEN-LAST:event_jButtonRemoveConditionActionPerformed
654

655     private void jButtonModifyConditionActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonModifyConditionActionPerformed
656

657         if (jConditionsList.getSelectedIndex() == 0) return;
658
659         ConditionedStyle s = (ConditionedStyle) jConditionsList.getSelectedValue();
660         String JavaDoc expression = s.getCondition();
661
662         ExpressionEditor ed = new ExpressionEditor();
663         if ( MainFrame.getMainInstance().getActiveReportFrame() != null)
664         {
665             Report report = MainFrame.getMainInstance().getActiveReportFrame().getReport();
666             ed.setSubDataset( report );
667             Vector JavaDoc v = report.getElements();
668             for (int i=0; i<v.size(); ++i)
669             {
670                 ReportElement re = (ReportElement)v.elementAt(i);
671                 if (re instanceof CrosstabReportElement)
672                 {
673                     ed.addCrosstabReportElement( (CrosstabReportElement)re );
674                 }
675             }
676         }
677         else
678         {
679             ed.setSubDataset( new SubDataset());
680         }
681
682         ed.setExpression(expression);
683         ed.setVisible(true);
684         if (ed.getDialogResult() == JOptionPane.OK_OPTION)
685         {
686             String JavaDoc exp = ed.getExpression();
687             if (exp.trim().length() > 0)
688             {
689                 s.setCondition( exp.trim());
690                 jConditionsList.updateUI();
691             }
692         }
693
694     }//GEN-LAST:event_jButtonModifyConditionActionPerformed
695

696     private void jConditionsListMouseClicked(java.awt.event.MouseEvent JavaDoc evt) {//GEN-FIRST:event_jConditionsListMouseClicked
697

698         if (evt.getClickCount() == 2 && evt.getButton() == evt.BUTTON1)
699         {
700             jButtonModifyConditionActionPerformed(null);
701         }
702
703     }//GEN-LAST:event_jConditionsListMouseClicked
704

705     private void jButtonAddConditionActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonAddConditionActionPerformed
706

707         ExpressionEditor ed = new ExpressionEditor();
708         if ( MainFrame.getMainInstance().getActiveReportFrame() != null)
709         {
710             Report report = MainFrame.getMainInstance().getActiveReportFrame().getReport();
711             ed.setSubDataset( report );
712             Vector JavaDoc v = report.getElements();
713             for (int i=0; i<v.size(); ++i)
714             {
715                 ReportElement re = (ReportElement)v.elementAt(i);
716                 if (re instanceof CrosstabReportElement)
717                 {
718                     ed.addCrosstabReportElement( (CrosstabReportElement)re );
719                 }
720             }
721         }
722         else
723         {
724             ed.setSubDataset( new SubDataset());
725         }
726
727         ed.setVisible(true);
728
729         if (ed.getDialogResult() == JOptionPane.OK_OPTION)
730         {
731             String JavaDoc exp = ed.getExpression();
732             if (exp.trim().length() > 0)
733             {
734                 saveCurrentStyle();
735                 ConditionedStyle s = new ConditionedStyle(getMasterStyle());
736                 s.setConditionedStyles( new Vector JavaDoc() );
737                 s.setCondition( exp.trim());
738                 DefaultListModel JavaDoc dlm = (DefaultListModel JavaDoc)jConditionsList.getModel();
739                 dlm.addElement(s);
740                 jConditionsList.setSelectedValue(s, true);
741             }
742         }
743     }//GEN-LAST:event_jButtonAddConditionActionPerformed
744

745     private void jConditionsListValueChanged(javax.swing.event.ListSelectionEvent JavaDoc evt) {//GEN-FIRST:event_jConditionsListValueChanged
746

747         if (isInit()) return;
748         if (evt.getValueIsAdjusting()) return;
749
750         //System.out.println(" style selected!");
751
// Save the current style if needed
752
saveCurrentStyle();
753
754         if (jConditionsList.getSelectedIndex() == 0)
755         {
756             jButtonModifyCondition.setEnabled(false);
757             jButtonRemoveCondition.setEnabled(false);
758             jButtonUpCondition.setEnabled(false);
759             jButtonDownCondition.setEnabled(false);
760
761             setStyle(getMasterStyle(), false);
762         }
763         else
764         {
765             jButtonModifyCondition.setEnabled(true);
766             jButtonRemoveCondition.setEnabled(true);
767             jButtonUpCondition.setEnabled(jConditionsList.getSelectedIndex()>1);
768             jButtonDownCondition.setEnabled(jConditionsList.getSelectedIndex()< ((DefaultListModel JavaDoc)jConditionsList.getModel()).size()-1);
769
770             setStyle((Style)jConditionsList.getSelectedValue(), true);
771         }
772
773
774     }//GEN-LAST:event_jConditionsListValueChanged
775

776     private void jButtonCancelActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonCancelActionPerformed
777
setVisible(false);
778         this.setDialogResult( javax.swing.JOptionPane.CANCEL_OPTION);
779         dispose();
780     }//GEN-LAST:event_jButtonCancelActionPerformed
781

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

784         saveCurrentStyle();
785
786         String JavaDoc newName = getMasterStyle().getAttributeString( Style.ATTRIBUTE_name ,"");
787
788
789         if (newName.trim().length() <= 0)
790         {
791             javax.swing.JOptionPane.showMessageDialog(this,
792                     I18n.getString("messages.styleDialog.notValidName","Please insert a valid name for the style!"),
793                     I18n.getString("messages.styleDialog.notValidNameCaption","Invalid name!"),
794                     javax.swing.JOptionPane.WARNING_MESSAGE );
795             jConditionsList.setSelectedIndex(0);
796             return;
797         }
798
799         // check for duplicate name....
800
Enumeration JavaDoc e = null;
801
802         if (isLibraryStyle())
803         {
804             e = it.businesslogic.ireport.gui.MainFrame.getMainInstance().getStyleLibrarySet().elements();
805         }
806         else
807         {
808             e = it.businesslogic.ireport.gui.MainFrame.getMainInstance().getActiveReportFrame().getReport().getStyles().elements();
809         }
810
811         while (e.hasMoreElements())
812         {
813             Style st = (Style)e.nextElement();
814             if (st.getAttributeString( st.ATTRIBUTE_name ,"").equals(newName) && st != getEditingStyle())
815             {
816                 javax.swing.JOptionPane.showMessageDialog(this,"The name \"" + newName + "\" is already in use!\nPlease change it.","Invalid name!",javax.swing.JOptionPane.WARNING_MESSAGE );
817                 return;
818             }
819         }
820
821         DefaultListModel JavaDoc dlm = (DefaultListModel JavaDoc)jConditionsList.getModel();
822         Vector JavaDoc conditionedStyles = new Vector JavaDoc();
823         for (int k = 1; k<dlm.size(); ++k)
824         {
825             conditionedStyles.add(dlm.getElementAt(k) );
826         }
827         getMasterStyle().setConditionedStyles(conditionedStyles);
828
829         String JavaDoc oldName = "";
830         boolean newStyle = false;
831
832         if (getEditingStyle() == null)
833         {
834             newStyle = true;
835             setEditingStyle( getMasterStyle() );
836
837             if (!isLibraryStyle())
838             {
839                MainFrame.getMainInstance().getActiveReportFrame().getReport().getStyles().add(getMasterStyle());
840             }
841             else
842             {
843                 it.businesslogic.ireport.gui.MainFrame.getMainInstance().getStyleLibrarySet().add(getMasterStyle());
844             }
845         }
846         else
847         {
848             oldName = getEditingStyle().getAttributeString( Style.ATTRIBUTE_name ,"");
849             getEditingStyle().getAttributes().clear();
850             getEditingStyle().copyStyleFrom(getMasterStyle());
851         }
852
853         if (!isLibraryStyle())
854         {
855                 MainFrame.getMainInstance().getActiveReportFrame().getReport().fireStyleChangedListenerStyleChanged(
856                                 new StyleChangedEvent(
857                                 MainFrame.getMainInstance().getActiveReportFrame().getReport(),
858                                 (newStyle) ? StyleChangedEvent.ADDED : StyleChangedEvent.CHANGED,
859                                 getEditingStyle(),
860                                 getEditingStyle()));
861         }
862
863         this.style = getEditingStyle();
864
865         // Dump style...
866
//System.out.println("Save style:............");
867
//HashMap hm = getStyle().getAttributes();
868
//Iterator i_keys = hm.keySet().iterator();
869
//while (i_keys.hasNext())
870
// {
871
// Object key = i_keys.next();
872
// System.out.println( key + ": " +hm.get(key) );
873
// }
874

875         setVisible(false);
876         this.setDialogResult( javax.swing.JOptionPane.OK_OPTION);
877         dispose();
878     }//GEN-LAST:event_jButtonOKActionPerformed
879

880     /** Closes the dialog */
881     private void closeDialog(java.awt.event.WindowEvent JavaDoc evt) {//GEN-FIRST:event_closeDialog
882
setVisible(false);
883         this.setDialogResult( javax.swing.JOptionPane.CLOSED_OPTION);
884         dispose();
885     }//GEN-LAST:event_closeDialog
886

887     /**
888      * @param args the command line arguments
889      */

890     public static void main(String JavaDoc args[]) {
891         new JRParameterDialog(new javax.swing.JFrame JavaDoc(), true).setVisible(true);
892     }
893
894
895     /** Getter for property dialogResult.
896      * @return Value of property dialogResult.
897      *
898      */

899     public int getDialogResult() {
900         return dialogResult;
901     }
902
903     /** Setter for property dialogResult.
904      * @param dialogResult New value of property dialogResult.
905      *
906      */

907     public void setDialogResult(int dialogResult) {
908         this.dialogResult = dialogResult;
909     }
910
911
912     // Variables declaration - do not modify//GEN-BEGIN:variables
913
private javax.swing.JButton JavaDoc jButtonAddCondition;
914     private javax.swing.JButton JavaDoc jButtonCancel;
915     private javax.swing.JButton JavaDoc jButtonDownCondition;
916     private javax.swing.JButton JavaDoc jButtonModifyCondition;
917     private javax.swing.JButton JavaDoc jButtonOK;
918     private javax.swing.JButton JavaDoc jButtonRemoveCondition;
919     private javax.swing.JButton JavaDoc jButtonUpCondition;
920     private javax.swing.JList JavaDoc jConditionsList;
921     private javax.swing.JLabel JavaDoc jLabelSample;
922     private javax.swing.JLabel JavaDoc jLabelStyleConditions;
923     private javax.swing.JPanel JavaDoc jPanel1;
924     private javax.swing.JPanel JavaDoc jPanel2;
925     private javax.swing.JPanel JavaDoc jPanelConditions;
926     private javax.swing.JPanel JavaDoc jPanelProperties;
927     private javax.swing.JPanel JavaDoc jPanelSample;
928     private javax.swing.JScrollPane JavaDoc jScrollPane1;
929     private javax.swing.JSplitPane JavaDoc jSplitPane1;
930     // End of variables declaration//GEN-END:variables
931

932     private int dialogResult;
933
934     public CategorySheetPanel getSheetPanel() {
935         return sheetPanel;
936     }
937
938     public void setSheetPanel(CategorySheetPanel sheetPanel) {
939         this.sheetPanel = sheetPanel;
940     }
941
942     public void sheetPropertyValueChanged(it.businesslogic.ireport.gui.event.SheetPropertyValueChangedEvent evt) {
943
944         //System.out.println("Changed proprty " + evt.getPropertyName());
945

946
947         if (isInit()) return;
948         if (evt.getPropertyName() != null && evt.getPropertyName().equals("style.font"))
949         {
950             setIreportFont( (IReportFont)evt.getNewValue());
951
952             boolean initNow = isInit();
953             setInit(true);
954             if (getIreportFont() != null)
955             {
956                 sheetPanel.setPropertyValue(Style.ATTRIBUTE_isBold, getIreportFont().getBeanProperties().get(getIreportFont().IS_BOLD));
957                 sheetPanel.setPropertyValue(Style.ATTRIBUTE_isItalic, getIreportFont().getBeanProperties().get(getIreportFont().IS_ITALIC));
958                 sheetPanel.setPropertyValue(Style.ATTRIBUTE_isStrikeThrough, getIreportFont().getBeanProperties().get(getIreportFont().IS_STRIKETROUGHT));
959                 sheetPanel.setPropertyValue(Style.ATTRIBUTE_isUnderline, getIreportFont().getBeanProperties().get(getIreportFont().IS_UNDERLINE));
960             }
961             else
962             {
963                 sheetPanel.setPropertyValue(Style.ATTRIBUTE_isBold, null);
964                 sheetPanel.setPropertyValue(Style.ATTRIBUTE_isItalic, null);
965                 sheetPanel.setPropertyValue(Style.ATTRIBUTE_isStrikeThrough, null);
966                 sheetPanel.setPropertyValue(Style.ATTRIBUTE_isUnderline, null);
967             }
968             setInit(initNow);
969
970         }
971         else if (evt.getPropertyName() != null && evt.getPropertyName().equals(Style.ATTRIBUTE_isBold))
972         {
973             IReportFont ifont = getIreportFont();
974             ifont.getBeanProperties().put(ifont.IS_BOLD, evt.getNewValue());
975             sheetPanel.setPropertyValue("style.font", ifont);
976         }
977         else if (evt.getPropertyName() != null && evt.getPropertyName().equals(Style.ATTRIBUTE_isItalic))
978         {
979             IReportFont ifont = getIreportFont();
980             ifont.getBeanProperties().put(ifont.IS_ITALIC, evt.getNewValue());
981             sheetPanel.setPropertyValue("style.font", ifont);
982         }
983         else if (evt.getPropertyName() != null && evt.getPropertyName().equals(Style.ATTRIBUTE_isUnderline))
984         {
985             IReportFont ifont = getIreportFont();
986             ifont.getBeanProperties().put(ifont.IS_UNDERLINE, evt.getNewValue());
987             sheetPanel.setPropertyValue("style.font", ifont);
988         }
989         else if (evt.getPropertyName() != null && evt.getPropertyName().equals(Style.ATTRIBUTE_isStrikeThrough))
990         {
991             IReportFont ifont = getIreportFont();
992             ifont.getBeanProperties().put(ifont.IS_STRIKETROUGHT, evt.getNewValue());
993             sheetPanel.setPropertyValue("style.font", ifont);
994         }
995
996
997
998         //saveCurrentStyle();
999
if (!isInit() && panelSample != null && panelSample.getStyle() != null)
1000        {
1001            Vector JavaDoc properties = this.sheetPanel.getProperties();
1002            for (int i=0; i<properties.size(); ++i)
1003            {
1004                SheetProperty sp = (SheetProperty)properties.get(i);
1005                //if ( sp.getValue() != null)
1006
{
1007                    panelSample.getStyle().getAttributes().put( sp.getKeyName(), sp.getValue());
1008                }
1009            }
1010            panelSample.invalidate();
1011            panelSample.repaint();
1012        }
1013    }
1014
1015    public Style getStyle() {
1016        return style;
1017    }
1018
1019    public void updateStyleValues()
1020    {
1021        setInit(true);
1022        //System.out.println("Updating style values...");
1023

1024        sheetPanel.setPropertyValue(Style.ATTRIBUTE_name,getStyle().getAttribute(style.ATTRIBUTE_name));
1025        sheetPanel.setPropertyValue(Style.ATTRIBUTE_backcolor,getStyle().getAttribute(style.ATTRIBUTE_backcolor));
1026        sheetPanel.setPropertyValue(Style.ATTRIBUTE_borderColor,getStyle().getAttribute(style.ATTRIBUTE_borderColor));
1027        sheetPanel.setPropertyValue(Style.ATTRIBUTE_border,getStyle().getAttribute(style.ATTRIBUTE_border));
1028        sheetPanel.setPropertyValue(Style.ATTRIBUTE_bottomBorderColor,getStyle().getAttribute(style.ATTRIBUTE_bottomBorderColor));
1029        sheetPanel.setPropertyValue(Style.ATTRIBUTE_bottomBorder,getStyle().getAttribute(style.ATTRIBUTE_bottomBorder));
1030        sheetPanel.setPropertyValue(Style.ATTRIBUTE_bottomPadding,getStyle().getAttribute(style.ATTRIBUTE_bottomPadding));
1031        sheetPanel.setPropertyValue(Style.ATTRIBUTE_fill,getStyle().getAttribute(style.ATTRIBUTE_fill));
1032        sheetPanel.setPropertyValue(Style.ATTRIBUTE_forecolor,getStyle().getAttribute(style.ATTRIBUTE_forecolor));
1033        sheetPanel.setPropertyValue(Style.ATTRIBUTE_hAlign,getStyle().getAttribute(style.ATTRIBUTE_hAlign));
1034        sheetPanel.setPropertyValue(Style.ATTRIBUTE_isBlankWhenNull,getStyle().getAttribute(style.ATTRIBUTE_isBlankWhenNull));
1035        sheetPanel.setPropertyValue(Style.ATTRIBUTE_isDefault,getStyle().getAttribute(style.ATTRIBUTE_isDefault));
1036        sheetPanel.setPropertyValue(Style.ATTRIBUTE_leftBorderColor,getStyle().getAttribute(style.ATTRIBUTE_leftBorderColor));
1037        sheetPanel.setPropertyValue(Style.ATTRIBUTE_leftBorder,getStyle().getAttribute(style.ATTRIBUTE_leftBorder));
1038        sheetPanel.setPropertyValue(Style.ATTRIBUTE_leftPadding,getStyle().getAttribute(style.ATTRIBUTE_leftPadding));
1039        sheetPanel.setPropertyValue(Style.ATTRIBUTE_lineSpacing,getStyle().getAttribute(style.ATTRIBUTE_lineSpacing));
1040        sheetPanel.setPropertyValue(Style.ATTRIBUTE_mode,getStyle().getAttribute(style.ATTRIBUTE_mode));
1041        sheetPanel.setPropertyValue(Style.ATTRIBUTE_padding,getStyle().getAttribute(style.ATTRIBUTE_padding));
1042        sheetPanel.setPropertyValue(Style.ATTRIBUTE_pattern,getStyle().getAttribute(style.ATTRIBUTE_pattern));
1043        sheetPanel.setPropertyValue(Style.ATTRIBUTE_pen,getStyle().getAttribute(style.ATTRIBUTE_pen));
1044        sheetPanel.setPropertyValue(Style.ATTRIBUTE_radius,getStyle().getAttribute(style.ATTRIBUTE_radius));
1045        sheetPanel.setPropertyValue(Style.ATTRIBUTE_rightBorderColor,getStyle().getAttribute(style.ATTRIBUTE_rightBorderColor));
1046        sheetPanel.setPropertyValue(Style.ATTRIBUTE_rightBorder,getStyle().getAttribute(style.ATTRIBUTE_rightBorder));
1047        sheetPanel.setPropertyValue(Style.ATTRIBUTE_rightPadding,getStyle().getAttribute(style.ATTRIBUTE_rightPadding));
1048        sheetPanel.setPropertyValue(Style.ATTRIBUTE_rotation,getStyle().getAttribute(style.ATTRIBUTE_rotation));
1049        sheetPanel.setPropertyValue(Style.ATTRIBUTE_scaleImage,getStyle().getAttribute(style.ATTRIBUTE_scaleImage));
1050        sheetPanel.setPropertyValue(Style.ATTRIBUTE_style,getStyle().getAttribute(style.ATTRIBUTE_style));
1051        sheetPanel.setPropertyValue(Style.ATTRIBUTE_isStyledText,getStyle().getAttribute(style.ATTRIBUTE_isStyledText));
1052
1053        sheetPanel.setPropertyValue("style.font", getIreportFont());
1054        sheetPanel.setPropertyValue(Style.ATTRIBUTE_topBorderColor,getStyle().getAttribute(style.ATTRIBUTE_topBorderColor));
1055        sheetPanel.setPropertyValue(Style.ATTRIBUTE_topBorder,getStyle().getAttribute(style.ATTRIBUTE_topBorder));
1056        sheetPanel.setPropertyValue(Style.ATTRIBUTE_topPadding,getStyle().getAttribute(style.ATTRIBUTE_topPadding));
1057        sheetPanel.setPropertyValue(Style.ATTRIBUTE_vAlign,getStyle().getAttribute(style.ATTRIBUTE_vAlign));
1058
1059        sheetPanel.setPropertyValue(Style.ATTRIBUTE_isBold,getStyle().getAttribute(style.ATTRIBUTE_isBold));
1060        sheetPanel.setPropertyValue(Style.ATTRIBUTE_isUnderline,getStyle().getAttribute(style.ATTRIBUTE_isUnderline));
1061        sheetPanel.setPropertyValue(Style.ATTRIBUTE_isItalic,getStyle().getAttribute(style.ATTRIBUTE_isItalic));
1062        sheetPanel.setPropertyValue(Style.ATTRIBUTE_isStrikeThrough,getStyle().getAttribute(style.ATTRIBUTE_isStrikeThrough));
1063        setInit(false);
1064
1065    }
1066
1067    /**
1068     * Set the style to edit. A temporary copy of the style will be created. That
1069     * modified values will be copied into the original style if modified.
1070     * All substyles will be replaced at the end of the editing (eventually with exact copies).
1071     */

1072    public void setStyle(Style myStyle) {
1073
1074            Style copyStyle = new Style( myStyle );
1075            copyStyle.setName(myStyle.getName());
1076            this.setMasterStyle(copyStyle);
1077
1078            if (myStyle.getAttributeBoolean(myStyle.ATTRIBUTE_isDefault, false))
1079            {
1080                this.getMasterStyle().getAttributes().put( myStyle.ATTRIBUTE_isDefault, new Boolean JavaDoc(true) );
1081            }
1082
1083            setStyle(getMasterStyle(), false);
1084
1085            this.setEditingStyle(myStyle);
1086
1087            updateParentStylesList();
1088
1089            setInit(true);
1090
1091            ((DefaultListModel JavaDoc)jConditionsList.getModel()).removeAllElements();
1092            ((DefaultListModel JavaDoc)jConditionsList.getModel()).addElement("Default");
1093
1094
1095            for (int i=0; i<getMasterStyle().getConditionedStyles().size(); ++i)
1096            {
1097                ((DefaultListModel JavaDoc)jConditionsList.getModel()).addElement(
1098                        getMasterStyle().getConditionedStyles().elementAt(i) );
1099            }
1100
1101            this.jConditionsList.setSelectedIndex(0);
1102
1103            setInit(false);
1104    }
1105
1106    public void updateParentStylesList()
1107    {
1108    // currentReport
1109
if (it.businesslogic.ireport.gui.MainFrame.getMainInstance().getActiveReportFrame() != null)
1110        {
1111            currentReport = it.businesslogic.ireport.gui.MainFrame.getMainInstance().getActiveReportFrame().getReport();
1112            Enumeration JavaDoc enum_styles = currentReport.getStyles().elements();
1113
1114
1115
1116            Vector JavaDoc tags = new Vector JavaDoc();
1117            while (enum_styles.hasMoreElements())
1118            {
1119                Style s = (Style)enum_styles.nextElement();
1120                if (s != this.getMasterStyle() && !s.getName().equals( this.getMasterStyle().getName() ) )
1121                {
1122                   tags.add(s); //new Tag(s)
1123
}
1124            }
1125            ComboBoxSheetProperty sp = (ComboBoxSheetProperty)getSheetPanel().getSheetProperty(Style.ATTRIBUTE_style);
1126            sp.updateValues(tags,true);
1127        }
1128    }
1129
1130    /**
1131     * Set the style to edit. Remember to call saveCurrentStyle() if needed before change the displayed
1132     * style.
1133     * if conditionalStyle == true, the common fields are set disabled.
1134     */

1135    private void setStyle(Style myStyle, boolean conditionalStyle)
1136    {
1137        this.style = myStyle;
1138
1139        ((SheetProperty)sheetPanel.getSheetProperty(Style.ATTRIBUTE_name)).setReadOnly(conditionalStyle);
1140        ((SheetProperty)sheetPanel.getSheetProperty(Style.ATTRIBUTE_isDefault)).setReadOnly(conditionalStyle);
1141        ((SheetProperty)sheetPanel.getSheetProperty(Style.ATTRIBUTE_style)).setReadOnly(conditionalStyle);
1142
1143        setIreportFont(new IReportFont());
1144
1145        if (myStyle.getAttributes().get( myStyle.ATTRIBUTE_isBold) != null)
1146        getIreportFont().setBold( myStyle.getAttributeBoolean( myStyle.ATTRIBUTE_isBold, false));
1147
1148        if (myStyle.getAttributes().get( myStyle.ATTRIBUTE_fontName) != null)
1149        getIreportFont().setFontName( myStyle.getAttributeString( myStyle.ATTRIBUTE_fontName, getIreportFont().getFontName()));
1150
1151        if (myStyle.getAttributes().get( myStyle.ATTRIBUTE_fontSize) != null)
1152        getIreportFont().setFontSize( myStyle.getAttributeInteger( myStyle.ATTRIBUTE_fontSize, getIreportFont().getFontSize()));
1153
1154        if (myStyle.getAttributes().get( myStyle.ATTRIBUTE_isItalic) != null)
1155        getIreportFont().setItalic( myStyle.getAttributeBoolean( myStyle.ATTRIBUTE_isItalic, false));
1156
1157        if (myStyle.getAttributes().get( myStyle.ATTRIBUTE_isPdfEmbedded) != null)
1158        getIreportFont().setPdfEmbedded( myStyle.getAttributeBoolean( myStyle.ATTRIBUTE_isPdfEmbedded, false));
1159
1160        if (myStyle.getAttributes().get( myStyle.ATTRIBUTE_pdfEncoding) != null)
1161        getIreportFont().setPdfEncoding( myStyle.getAttributeString( myStyle.ATTRIBUTE_pdfEncoding, getIreportFont().getPdfEncoding()));
1162
1163        if (myStyle.getAttributes().get( myStyle.ATTRIBUTE_isStrikeThrough) != null)
1164        getIreportFont().setStrikeTrought( myStyle.getAttributeBoolean( myStyle.ATTRIBUTE_isStrikeThrough, false));
1165
1166        // TODO = We have to understand what kind of font is this...
1167
if (myStyle.getAttributes().get( myStyle.ATTRIBUTE_pdfFontName) != null)
1168        getIreportFont().setPDFFontName( myStyle.getAttributeString( myStyle.ATTRIBUTE_pdfFontName, getIreportFont().getPDFFontName()));
1169
1170        if (myStyle.getAttributes().get( myStyle.ATTRIBUTE_isUnderline) != null)
1171        getIreportFont().setUnderline( myStyle.getAttributeBoolean( myStyle.ATTRIBUTE_isUnderline, false));
1172
1173        updateParentStylesList();
1174        updateStyleValues();
1175
1176
1177        panelSample.setStyle(myStyle);
1178    }
1179
1180    public IReportFont getIreportFont() {
1181        if (ireportFont == null) ireportFont = new IReportFont();
1182        return ireportFont;
1183    }
1184
1185    public void setIreportFont(IReportFont ireportFont) {
1186        this.ireportFont = ireportFont;
1187    }
1188
1189    private Style getMasterStyle() {
1190        return masterStyle;
1191    }
1192
1193    private void setMasterStyle(Style masterStyle) {
1194        this.masterStyle = masterStyle;
1195    }
1196
1197    /**
1198     * This method save all the propeties present in the sheet into the
1199     * current style (pointed by the variable style)
1200     */

1201    private void saveCurrentStyle()
1202    {
1203        // Store all values...
1204
//System.out.println("Saving: " + getStyle());
1205
Vector JavaDoc properties = this.sheetPanel.getProperties();
1206
1207        if (getStyle() instanceof ConditionedStyle)
1208        {
1209            String JavaDoc condition = ((ConditionedStyle)getStyle()).getCondition();
1210            getStyle().getAttributes().clear();
1211            ((ConditionedStyle)getStyle()).setCondition(condition);
1212        }
1213        else
1214        {
1215            getStyle().getAttributes().clear();
1216        }
1217
1218        for (int i=0; i<properties.size(); ++i)
1219        {
1220            SheetProperty sp = (SheetProperty)properties.get(i);
1221            if ( sp.getValue() != null)
1222            {
1223                getStyle().getAttributes().put( sp.getKeyName(), sp.getValue());
1224                //System.out.println(sp.getKeyName() + " " + sp.getValue());
1225
}
1226        }
1227
1228        if ( getStyle().getAttributes().get(getStyle().ATTRIBUTE_style) != null &&
1229             !(getStyle().getAttributes().get(getStyle().ATTRIBUTE_style) instanceof Style))
1230        {
1231            String JavaDoc sname = ""+getStyle().getAttributes().get(getStyle().ATTRIBUTE_style);
1232            if (sname.trim().length() == 0)
1233            {
1234                getStyle().getAttributes().remove(getStyle().ATTRIBUTE_style);
1235            }
1236            else
1237            {
1238                for (int j=0; j<currentReport.getStyles().size(); ++j)
1239                {
1240                    Style sparent = (Style)currentReport.getStyles().elementAt(j);
1241                    if (sparent.getName().equals( sname ))
1242                    {
1243                        getStyle().getAttributes().put(getStyle().ATTRIBUTE_style, sparent);
1244                    }
1245                }
1246            }
1247        }
1248
1249        if (getStyle().getAttributeBoolean(getStyle().ATTRIBUTE_isDefault, false))
1250        {
1251            Enumeration JavaDoc enum_s = MainFrame.getMainInstance().getActiveReportFrame().getReport().getStyles().elements();
1252            while (enum_s.hasMoreElements())
1253            {
1254                Style tmp_s = (Style)enum_s.nextElement();
1255                if (tmp_s != getStyle())
1256                {
1257                    tmp_s.getAttributes().remove( getStyle().ATTRIBUTE_isDefault);
1258                }
1259            }
1260        }
1261
1262        if (ireportFont != null)
1263        {
1264                getStyle().getAttributes().put( Style.ATTRIBUTE_fontName, ireportFont.getBeanProperties().get( ireportFont.FONT_NAME) );
1265
1266                if (ireportFont.getBeanProperties().get( ireportFont.FONT_SIZE) != null)
1267                getStyle().getAttributes().put( Style.ATTRIBUTE_fontSize, new Integer JavaDoc(ireportFont.getFontSize()));
1268
1269                if (ireportFont.getBeanProperties().get( ireportFont.IS_BOLD) != null)
1270                getStyle().getAttributes().put( style.ATTRIBUTE_isBold, new Boolean JavaDoc( ireportFont.isBold()));
1271
1272                if (ireportFont.getBeanProperties().get( ireportFont.IS_ITALIC) != null)
1273                getStyle().getAttributes().put( style.ATTRIBUTE_isItalic, new Boolean JavaDoc( ireportFont.isItalic()));
1274
1275                if (ireportFont.getBeanProperties().get( ireportFont.IS_UNDERLINE) != null)
1276                getStyle().getAttributes().put( style.ATTRIBUTE_isUnderline, new Boolean JavaDoc( ireportFont.isUnderline()));
1277
1278                if (ireportFont.getBeanProperties().get( ireportFont.IS_STRIKETROUGHT) != null)
1279                getStyle().getAttributes().put( style.ATTRIBUTE_isStrikeThrough, new Boolean JavaDoc( ireportFont.isStrikeTrought()));
1280
1281                if (ireportFont.getBeanProperties().get( ireportFont.IS_PDF_EMBEDDED) != null)
1282                getStyle().getAttributes().put( style.ATTRIBUTE_isPdfEmbedded, new Boolean JavaDoc( ireportFont.isPdfEmbedded()));
1283
1284                if (ireportFont.getBeanProperties().get( ireportFont.PDF_FONT_NAME) != null)
1285                getStyle().getAttributes().put( Style.ATTRIBUTE_pdfFontName, ireportFont.getPDFFontName());
1286                
1287                if (ireportFont.getBeanProperties().get( ireportFont.PDF_ENCODING) != null)
1288                getStyle().getAttributes().put( Style.ATTRIBUTE_pdfEncoding, ireportFont.getPdfEncoding());
1289
1290        }
1291        /*
1292        HashMap hm = getStyle().getAttributes();
1293        Iterator i_keys = hm.keySet().iterator();
1294
1295            while (i_keys.hasNext())
1296            {
1297                Object key = i_keys.next();
1298                System.out.println( key + ": " +hm.get(key) );
1299            }
1300         */

1301    }
1302
1303    public boolean isInit() {
1304        return init;
1305    }
1306
1307    public void setInit(boolean init) {
1308        this.init = init;
1309    }
1310
1311    public Style getEditingStyle() {
1312        return editingStyle;
1313    }
1314
1315    public void setEditingStyle(Style editingStyle) {
1316        this.editingStyle = editingStyle;
1317    }
1318
1319    public boolean isLibraryStyle() {
1320        return libraryStyle;
1321    }
1322
1323    public void setLibraryStyle(boolean libraryStyle) {
1324        this.libraryStyle = libraryStyle;
1325    }
1326    public void applyI18n(){
1327                // Start autogenerated code ----------------------
1328
jButtonAddCondition.setText(I18n.getString("styleDialog.buttonAddCondition","Add"));
1329                jButtonCancel.setText(I18n.getString("styleDialog.buttonCancel","Cancel"));
1330                jButtonDownCondition.setText(I18n.getString("styleDialog.buttonDownCondition","Down"));
1331                jButtonModifyCondition.setText(I18n.getString("styleDialog.buttonModifyCondition","Modify"));
1332                jButtonOK.setText(I18n.getString("styleDialog.buttonOK","OK"));
1333                jButtonRemoveCondition.setText(I18n.getString("styleDialog.buttonRemoveCondition","Remove"));
1334                jButtonUpCondition.setText(I18n.getString("styleDialog.buttonUpCondition","up"));
1335                jLabelSample.setText(I18n.getString("styleDialog.labelSample","Sample"));
1336                jLabelStyleConditions.setText(I18n.getString("styleDialog.labelStyleConditions","Style conditions"));
1337                // End autogenerated code ----------------------
1338
}
1339}
1340
Popular Tags