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: * FontSheetProperty.java
028: *
029: * Created on 16 febbraio 2005, 19.13
030: *
031: */
032:
033: package it.businesslogic.ireport.gui.sheet;
034:
035: import it.businesslogic.ireport.IReportFont;
036: import java.util.*;
037: import javax.swing.*;
038:
039: public class FontSheetProperty extends SheetProperty {
040:
041: private FontSheetPropertyComponent editor = null;
042:
043: public FontSheetProperty(String key, String name) {
044: super (key, name, SheetProperty.STRING, "");
045: }
046:
047: public JComponent getEditor() {
048: if (editor != null)
049: return editor;
050: editor = new FontSheetPropertyComponent();
051: editor.addActionListener(this );
052: return editor;
053: }
054:
055: public Object getEditorValue(JComponent component) {
056: return editor.getIreportFont();
057: }
058:
059: public void actionPerformed(java.awt.event.ActionEvent event) {
060: super .actionPerformed(event);
061: updateLabel();
062: }
063:
064: public void setEditorValue(JComponent component, Object value) {
065: try {
066: getEditor(); // In this way we are sure that editor is not null.
067: editor
068: .setIreportFont((it.businesslogic.ireport.IReportFont) value);
069: } catch (Exception ex) {
070: }
071: }
072:
073: public void setFontMode(int mode) {
074: try {
075: getEditor(); // In this way we are sure that editor is not null.
076: editor.setFontMode(mode);
077: } catch (Exception ex) {
078: }
079: }
080:
081: /**
082: * The font propery is ever not null. We should check in in the IReportFont there is something
083: * of set or not...
084: */
085: public void updateLabel() {
086: try {
087: if (getLabelComponent() != null) {
088: boolean allNullValue = true;
089:
090: IReportFont ifont = (IReportFont) getValue();
091:
092: if (ifont != null) {
093: Iterator i_keys = ifont.getBeanProperties()
094: .keySet().iterator();
095:
096: while (i_keys.hasNext()) {
097: Object key = i_keys.next();
098: if (ifont.getBeanProperties().get(key) != null) {
099: allNullValue = false;
100: break;
101: }
102: }
103: }
104:
105: java.awt.Font f = getLabelComponent().getFont();
106: java.awt.Font f2 = new java.awt.Font(
107: f.getName(),
108: (allNullValue || this .isReadOnly() || !isShowResetButton()) ? 0
109: : java.awt.Font.BOLD, f.getSize());
110: getLabelComponent().setFont(f2);
111: if (this .isReadOnly()) {
112: getLabelComponent().setEnabled(false);
113: } else {
114: getLabelComponent().setEnabled(true);
115: }
116:
117: getLabelComponent().updateUI();
118: }
119: } catch (Exception ex) {
120:
121: }
122: }
123:
124: }
|