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: * FontSheetPropertyComponent.java
028: *
029: * Created on 15 agosto 2005, 13.32
030: *
031: */
032:
033: package it.businesslogic.ireport.gui.sheet;
034:
035: import it.businesslogic.ireport.IReportFont;
036: import it.businesslogic.ireport.gui.JRFontDialog;
037: import it.businesslogic.ireport.gui.MainFrame;
038: import it.businesslogic.ireport.util.I18n;
039:
040: /**
041: *
042: * @author Administrator
043: */
044: public class FontSheetPropertyComponent extends javax.swing.JPanel {
045:
046: String expression = "";
047: private java.awt.Font font = null;
048: private IReportFont ireportFont = null;
049:
050: /** Creates new form ExpressionSheetPanel */
051: public FontSheetPropertyComponent() {
052: initComponents();
053: font = jLabelFont.getFont();
054: applyI18n();
055: }
056:
057: public void fontChanged() {
058: java.awt.event.ActionEvent event = new java.awt.event.ActionEvent(
059: this , 0, "");
060: fireActionListenerActionPerformed(event);
061: }
062:
063: /** This method is called from within the constructor to
064: * initialize the form.
065: * WARNING: Do NOT modify this code. The content of this method is
066: * always regenerated by the Form Editor.
067: */
068: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
069: private void initComponents() {
070: java.awt.GridBagConstraints gridBagConstraints;
071:
072: jLabelFont = new javax.swing.JLabel();
073: jButton1 = new javax.swing.JButton();
074:
075: setLayout(new java.awt.GridBagLayout());
076:
077: setBackground(new java.awt.Color(255, 255, 255));
078: jLabelFont.setBackground(new java.awt.Color(255, 255, 255));
079: jLabelFont.setOpaque(true);
080: gridBagConstraints = new java.awt.GridBagConstraints();
081: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
082: gridBagConstraints.weightx = 1.0;
083: gridBagConstraints.weighty = 1.0;
084: gridBagConstraints.insets = new java.awt.Insets(0, 4, 0, 0);
085: add(jLabelFont, gridBagConstraints);
086:
087: jButton1.setText("...");
088: jButton1.setMaximumSize(new java.awt.Dimension(19, 10));
089: jButton1.setMinimumSize(new java.awt.Dimension(19, 10));
090: jButton1.setPreferredSize(new java.awt.Dimension(19, 10));
091: jButton1.addActionListener(new java.awt.event.ActionListener() {
092: public void actionPerformed(java.awt.event.ActionEvent evt) {
093: jButton1ActionPerformed(evt);
094: }
095: });
096:
097: gridBagConstraints = new java.awt.GridBagConstraints();
098: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
099: gridBagConstraints.weighty = 1.0;
100: add(jButton1, gridBagConstraints);
101:
102: }// </editor-fold>//GEN-END:initComponents
103:
104: private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
105:
106: it.businesslogic.ireport.gui.JRFontDialog jrfd = new it.businesslogic.ireport.gui.JRFontDialog(
107: MainFrame.getMainInstance(), true);
108:
109: jrfd.updateFonts(it.businesslogic.ireport.gui.MainFrame
110: .getMainInstance().getTtfFonts());
111: jrfd.setReportFontMode(fontMode);
112: if (ireportFont != null) {
113: jrfd.setIReportFont((IReportFont) ireportFont.clone());
114: } else {
115: jrfd.setIReportFont(new IReportFont());
116: }
117:
118: jrfd.setVisible(true);
119: if (jrfd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION) {
120: setIreportFont(jrfd.getIReportFont());
121: fontChanged();
122: }
123:
124: }//GEN-LAST:event_jButton1ActionPerformed
125:
126: // Variables declaration - do not modify//GEN-BEGIN:variables
127: private javax.swing.JButton jButton1;
128: private javax.swing.JLabel jLabelFont;
129: // End of variables declaration//GEN-END:variables
130:
131: /**
132: * Utility field used by event firing mechanism.
133: */
134: private javax.swing.event.EventListenerList listenerList = null;
135:
136: /**
137: * Registers ActionListener to receive events.
138: * @param listener The listener to register.
139: */
140: public synchronized void addActionListener(
141: java.awt.event.ActionListener listener) {
142:
143: if (listenerList == null) {
144: listenerList = new javax.swing.event.EventListenerList();
145: }
146: listenerList.add(java.awt.event.ActionListener.class, listener);
147: }
148:
149: /**
150: * Removes ActionListener from the list of listeners.
151: * @param listener The listener to remove.
152: */
153: public synchronized void removeActionListener(
154: java.awt.event.ActionListener listener) {
155:
156: listenerList.remove(java.awt.event.ActionListener.class,
157: listener);
158: }
159:
160: /**
161: * Notifies all registered listeners about the event.
162: *
163: * @param event The event to be fired
164: */
165: private void fireActionListenerActionPerformed(
166: java.awt.event.ActionEvent event) {
167:
168: if (listenerList == null)
169: return;
170: Object[] listeners = listenerList.getListenerList();
171: for (int i = listeners.length - 2; i >= 0; i -= 2) {
172: if (listeners[i] == java.awt.event.ActionListener.class) {
173: ((java.awt.event.ActionListener) listeners[i + 1])
174: .actionPerformed(event);
175: }
176: }
177: }
178:
179: public IReportFont getIreportFont() {
180: return ireportFont;
181: }
182:
183: public void setIreportFont(IReportFont ireportFont) {
184: this .ireportFont = ireportFont;
185:
186: if (ireportFont == null)
187: ireportFont = new IReportFont();
188:
189: jLabelFont.setFont(ireportFont.getJavaAWTFont());
190: String bold = (ireportFont.isBold() ? " bold" : "");
191: jLabelFont.setText(ireportFont.getFontName() + " "
192: + ireportFont.getFontSize() + bold);
193:
194: }
195:
196: // 0 = element font
197: // 1 = report font
198: // 2 = style font
199: private int fontMode = 0;
200:
201: public int getFontMode() {
202: return fontMode;
203: }
204:
205: public void setFontMode(int fontMode) {
206: this .fontMode = fontMode;
207: }
208:
209: public void applyI18n() {
210: // Start autogenerated code ----------------------
211: jButton1.setText(I18n.getString(
212: "fontSheetPropertyComponent.button1", "..."));
213: // End autogenerated code ----------------------
214: }
215: }
|