01: /**
02: * L2FProd.com Common Components 7.3 License.
03: *
04: * Copyright 2005-2007 L2FProd.com
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */package com.l2fprod.common.beans.editor;
18:
19: import com.l2fprod.common.swing.ComponentFactory;
20: import com.l2fprod.common.swing.JFontChooser;
21: import com.l2fprod.common.swing.PercentLayout;
22: import com.l2fprod.common.swing.renderer.DefaultCellRenderer;
23: import com.l2fprod.common.util.ResourceManager;
24:
25: import java.awt.Font;
26: import java.awt.event.ActionEvent;
27: import java.awt.event.ActionListener;
28:
29: import javax.swing.JButton;
30: import javax.swing.JPanel;
31:
32: /**
33: * FontPropertyEditor.<br>
34: *
35: */
36: public class FontPropertyEditor extends AbstractPropertyEditor {
37:
38: private DefaultCellRenderer label;
39: private JButton button;
40: private Font font;
41:
42: public FontPropertyEditor() {
43: editor = new JPanel(new PercentLayout(PercentLayout.HORIZONTAL,
44: 0));
45: ((JPanel) editor).add("*", label = new DefaultCellRenderer());
46: label.setOpaque(false);
47: ((JPanel) editor).add(button = ComponentFactory.Helper
48: .getFactory().createMiniButton());
49: button.addActionListener(new ActionListener() {
50: public void actionPerformed(ActionEvent e) {
51: selectFont();
52: }
53: });
54: ((JPanel) editor).add(button = ComponentFactory.Helper
55: .getFactory().createMiniButton());
56: button.setText("X");
57: button.addActionListener(new ActionListener() {
58: public void actionPerformed(ActionEvent e) {
59: selectNull();
60: }
61: });
62: ((JPanel) editor).setOpaque(false);
63: }
64:
65: public Object getValue() {
66: return font;
67: }
68:
69: public void setValue(Object value) {
70: font = (Font) value;
71: label.setValue(value);
72: }
73:
74: protected void selectFont() {
75: ResourceManager rm = ResourceManager
76: .all(FontPropertyEditor.class);
77: String title = rm.getString("FontPropertyEditor.title");
78:
79: Font selectedFont = JFontChooser
80: .showDialog(editor, title, font);
81:
82: if (selectedFont != null) {
83: Font oldFont = font;
84: Font newFont = selectedFont;
85: label.setValue(newFont);
86: font = newFont;
87: firePropertyChange(oldFont, newFont);
88: }
89: }
90:
91: protected void selectNull() {
92: Object oldFont = font;
93: label.setValue(null);
94: font = null;
95: firePropertyChange(oldFont, null);
96: }
97:
98: }
|