001: /*
002: * Copyright (C) 2005 Jeff Tassin
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018:
019: package com.jeta.swingbuilder.gui.properties.editors;
020:
021: import java.awt.Component;
022: import java.awt.Font;
023: import java.awt.Graphics;
024: import java.awt.Rectangle;
025:
026: import javax.swing.ImageIcon;
027:
028: import com.jeta.open.gui.framework.JETADialog;
029: import com.jeta.open.gui.utils.JETAToolbox;
030: import com.jeta.open.i18n.I18N;
031: import com.jeta.swingbuilder.gui.font.FontView;
032: import com.jeta.swingbuilder.gui.properties.JETAPropertyEditor;
033: import com.jeta.swingbuilder.gui.utils.FormDesignerUtils;
034: import com.jeta.swingbuilder.resources.Icons;
035:
036: /**
037: * Editor for handling font properties
038: *
039: * @author Jeff Tassin
040: */
041: public class FontEditor extends JETAPropertyEditor {
042: private ValuePainter m_painter = new ValuePainter();
043:
044: private static ImageIcon[] m_font_icon = { FormDesignerUtils
045: .loadImage(Icons.FONT_16) };
046: private ImageIcon[] m_styles = new ImageIcon[2];
047:
048: private static ImageIcon m_bold_icon;
049: private static ImageIcon m_no_bold_icon;
050: private static ImageIcon m_italic_icon;
051: private static ImageIcon m_no_italic_icon;
052:
053: static {
054: m_bold_icon = FormDesignerUtils
055: .loadImage("forms/font_bold16.gif");
056: m_no_bold_icon = FormDesignerUtils
057: .loadImage("forms/font_no_bold16.gif");
058: m_italic_icon = FormDesignerUtils
059: .loadImage("forms/font_italic16.gif");
060: m_no_italic_icon = FormDesignerUtils
061: .loadImage("forms/font_no_italic16.gif");
062: }
063:
064: /**
065: * ctor
066: */
067: public FontEditor() {
068: m_painter.setPreImages(m_font_icon);
069: }
070:
071: /**
072: * Invokes a dialog used to update the property
073: */
074: public void invokePropertyDialog(Component comp) {
075: FontView view = new FontView((Font) getValue());
076: JETADialog dlg = (JETADialog) JETAToolbox.createDialog(
077: JETADialog.class, comp, true);
078: dlg.setPrimaryPanel(view);
079: dlg.setTitle(I18N.getLocalizedMessage("Font"));
080: dlg.pack();
081: dlg.showCenter();
082: if (dlg.isOk()) {
083: setValue(view.createFont());
084: }
085: }
086:
087: /**
088: * This editor can be rendered in-place
089: */
090: public boolean isPaintable() {
091: return true;
092: }
093:
094: public boolean supportsCustomEditor() {
095: return true;
096: }
097:
098: public void paintValue(Graphics g, Rectangle rect) {
099: assert (rect != null);
100: m_painter.paintValue(g, rect);
101: }
102:
103: /**
104: * Override setValue so we can nullify the descriptor for the font
105: */
106: public void setValue(Object value) {
107: super .setValue(value);
108: Font font = (Font) value;
109:
110: if (font == null) {
111: m_painter.setValue(I18N.format("font_description_2",
112: "null", ""));
113: } else {
114: m_painter.setValue(I18N.format("font_description_2", font
115: .getFamily(), new Integer(font.getSize())));
116: if (font.isBold())
117: m_styles[0] = m_bold_icon;
118: else
119: m_styles[0] = m_no_bold_icon;
120:
121: if (font.isItalic())
122: m_styles[1] = m_italic_icon;
123: else
124: m_styles[1] = m_no_italic_icon;
125:
126: m_painter.setPostImages(m_styles);
127: }
128:
129: }
130:
131: }
|