1 package nl.tudelft.simulation.introspection.mapping;
2
3 import java.awt.Component;
4 import java.awt.Dialog;
5 import java.awt.Font;
6
7 import javax.swing.AbstractCellEditor;
8 import javax.swing.JLabel;
9 import javax.swing.JTable;
10 import javax.swing.SwingUtilities;
11 import javax.swing.table.TableCellEditor;
12
13 import org.jfree.ui.FontChooserDialog;
14
15 /***
16 * An editor for fonts.
17 * <p>
18 * (c) copyright 2003 <a href="http://www.simulation.tudelft.nl">Delft
19 * University of Technology </a>, the Netherlands. <br>
20 * See for project information <a
21 * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
22 * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
23 * License (GPL) </a>, no warranty <br>
24 *
25 * @author <a href="http://www.tbm.tudelft.nl/webstaf/peterja/index.htm">Peter
26 * Jacobs </a>
27 * @version 1.2 Apr 15, 2004
28 * @since 1.4
29 */
30 public class MyFontEditor extends AbstractCellEditor implements TableCellEditor
31 {
32 /*** the value */
33 protected Font value;
34
35 /*** the cellPanel */
36 protected JLabel cellPanel = new JLabel();
37
38 /***
39 * @see javax.swing.CellEditor#getCellEditorValue()
40 */
41 public Object getCellEditorValue()
42 {
43 return this.value;
44 }
45
46 /***
47 * @see javax.swing.table.TableCellEditor#getTableCellEditorComponent(JTable,
48 * Object, boolean, int, int)
49 */
50 public Component getTableCellEditorComponent(final JTable table,
51 final Object value, final boolean isSelected, final int row,
52 final int column)
53 {
54 this.cellPanel.setBackground(this.cellPanel.getBackground().darker());
55 this.value = (Font) value;
56 MyFontChooserDialog chooser = new MyFontChooserDialog(
57 (Dialog) SwingUtilities.getWindowAncestor(table),
58 "Font selection", true, (Font) value);
59
60 chooser.addUserListener(new UserListener(chooser));
61 chooser.pack();
62 chooser.setVisible(true);
63 return this.cellPanel;
64 }
65
66
67 /*** the listener */
68 private class UserListener implements
69 MyFontChooserDialog.UserListenerInterface
70 {
71 /*** the fileChooser */
72 private FontChooserDialog chooser;
73
74 /***
75 * constructs a new UserListener
76 *
77 * @param chooser the chooser we listen at
78 */
79 public UserListener(FontChooserDialog chooser)
80 {
81 this.chooser = chooser;
82 }
83
84 /***
85 * @see nl.tudelft.simulation.introspection.mapping.MyFontChooserDialog.UserListenerInterface
86 * #okActionPerformed()
87 */
88 public void okActionPerformed()
89 {
90 MyFontEditor.this.value = this.chooser.getSelectedFont();
91 MyFontEditor.this.cellPanel.setText("" + MyFontEditor.this.value);
92 MyFontEditor.this.cellPanel
93 .paintImmediately(MyFontEditor.this.cellPanel.getBounds());
94 MyFontEditor.this.stopCellEditing();
95 }
96
97 /***
98 * @see nl.tudelft.simulation.introspection.mapping.MyFontChooserDialog.UserListenerInterface
99 * #cancelActionPerformed()
100 */
101 public void cancelActionPerformed()
102 {
103 MyFontEditor.this.cancelCellEditing();
104 }
105 }
106 }