KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > businesslogic > ireport > gui > sheet > FontSheetPropertyComponent


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  * FontSheetPropertyComponent.java
28  *
29  * Created on 15 agosto 2005, 13.32
30  *
31  */

32
33 package it.businesslogic.ireport.gui.sheet;
34
35 import it.businesslogic.ireport.IReportFont;
36 import it.businesslogic.ireport.gui.JRFontDialog;
37 import it.businesslogic.ireport.gui.MainFrame;
38 import it.businesslogic.ireport.util.I18n;
39
40 /**
41  *
42  * @author Administrator
43  */

44 public class FontSheetPropertyComponent extends javax.swing.JPanel JavaDoc {
45     
46     String JavaDoc expression = "";
47     private java.awt.Font JavaDoc font = null;
48     private IReportFont ireportFont = null;
49         
50     /** Creates new form ExpressionSheetPanel */
51     public FontSheetPropertyComponent() {
52         initComponents();
53         font = jLabelFont.getFont();
54         applyI18n();
55     }
56     
57     public void fontChanged()
58     {
59         java.awt.event.ActionEvent JavaDoc event = new java.awt.event.ActionEvent JavaDoc(this,0,"");
60         fireActionListenerActionPerformed(event);
61     }
62     
63     /** This method is called from within the constructor to
64      * initialize the form.
65      * WARNING: Do NOT modify this code. The content of this method is
66      * always regenerated by the Form Editor.
67      */

68     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
69
private void initComponents() {
70         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
71
72         jLabelFont = new javax.swing.JLabel JavaDoc();
73         jButton1 = new javax.swing.JButton JavaDoc();
74
75         setLayout(new java.awt.GridBagLayout JavaDoc());
76
77         setBackground(new java.awt.Color JavaDoc(255, 255, 255));
78         jLabelFont.setBackground(new java.awt.Color JavaDoc(255, 255, 255));
79         jLabelFont.setOpaque(true);
80         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
81         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
82         gridBagConstraints.weightx = 1.0;
83         gridBagConstraints.weighty = 1.0;
84         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 4, 0, 0);
85         add(jLabelFont, gridBagConstraints);
86
87         jButton1.setText("...");
88         jButton1.setMaximumSize(new java.awt.Dimension JavaDoc(19, 10));
89         jButton1.setMinimumSize(new java.awt.Dimension JavaDoc(19, 10));
90         jButton1.setPreferredSize(new java.awt.Dimension JavaDoc(19, 10));
91         jButton1.addActionListener(new java.awt.event.ActionListener JavaDoc() {
92             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
93                 jButton1ActionPerformed(evt);
94             }
95         });
96
97         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
98         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
99         gridBagConstraints.weighty = 1.0;
100         add(jButton1, gridBagConstraints);
101
102     }// </editor-fold>//GEN-END:initComponents
103

104     private void jButton1ActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButton1ActionPerformed
105

106         
107         it.businesslogic.ireport.gui.JRFontDialog jrfd = new it.businesslogic.ireport.gui.JRFontDialog(MainFrame.getMainInstance(), true);
108         
109         jrfd.updateFonts( it.businesslogic.ireport.gui.MainFrame.getMainInstance().getTtfFonts());
110         jrfd.setReportFontMode(fontMode);
111         if (ireportFont != null)
112         {
113             jrfd.setIReportFont( (IReportFont)ireportFont.clone() );
114         }
115         else
116         {
117             jrfd.setIReportFont( new IReportFont() );
118         }
119         
120         jrfd.setVisible(true);
121         if (jrfd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION)
122         {
123             setIreportFont( jrfd.getIReportFont() );
124             fontChanged();
125         }
126          
127     }//GEN-LAST:event_jButton1ActionPerformed
128

129     
130     // Variables declaration - do not modify//GEN-BEGIN:variables
131
private javax.swing.JButton JavaDoc jButton1;
132     private javax.swing.JLabel JavaDoc jLabelFont;
133     // End of variables declaration//GEN-END:variables
134

135     /**
136      * Utility field used by event firing mechanism.
137      */

138     private javax.swing.event.EventListenerList JavaDoc listenerList = null;
139
140     /**
141      * Registers ActionListener to receive events.
142      * @param listener The listener to register.
143      */

144     public synchronized void addActionListener(java.awt.event.ActionListener JavaDoc listener) {
145
146         if (listenerList == null ) {
147             listenerList = new javax.swing.event.EventListenerList JavaDoc();
148         }
149         listenerList.add (java.awt.event.ActionListener JavaDoc.class, listener);
150     }
151
152     /**
153      * Removes ActionListener from the list of listeners.
154      * @param listener The listener to remove.
155      */

156     public synchronized void removeActionListener(java.awt.event.ActionListener JavaDoc listener) {
157
158         listenerList.remove (java.awt.event.ActionListener JavaDoc.class, listener);
159     }
160
161     /**
162      * Notifies all registered listeners about the event.
163      *
164      * @param event The event to be fired
165      */

166     private void fireActionListenerActionPerformed(java.awt.event.ActionEvent JavaDoc event) {
167
168         if (listenerList == null) return;
169         Object JavaDoc[] listeners = listenerList.getListenerList ();
170         for (int i = listeners.length - 2; i >= 0; i -= 2) {
171             if (listeners[i]==java.awt.event.ActionListener JavaDoc.class) {
172                 ((java.awt.event.ActionListener JavaDoc)listeners[i+1]).actionPerformed (event);
173             }
174         }
175     }
176
177     public IReportFont getIreportFont() {
178         return ireportFont;
179     }
180
181     public void setIreportFont(IReportFont ireportFont) {
182         this.ireportFont = ireportFont;
183         
184         
185         if (ireportFont == null) ireportFont = new IReportFont();
186
187         jLabelFont.setFont(ireportFont.getJavaAWTFont());
188         String JavaDoc bold = (ireportFont.isBold() ? " bold" : "");
189         jLabelFont.setText(ireportFont.getFontName() + " " + ireportFont.getFontSize() + bold);
190         
191     }
192     
193     // 0 = element font
194
// 1 = report font
195
// 2 = style font
196
private int fontMode = 0;
197     public int getFontMode() {
198         return fontMode;
199     }
200
201     public void setFontMode(int fontMode) {
202         this.fontMode = fontMode;
203     }
204     
205     public void applyI18n(){
206                 // Start autogenerated code ----------------------
207
jButton1.setText(I18n.getString("fontSheetPropertyComponent.button1","..."));
208                 // End autogenerated code ----------------------
209
}
210 }
211
Popular Tags