01: /*
02: * Copyright (C) 2005 Jeff Tassin
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */
18:
19: package com.jeta.swingbuilder.gui.font;
20:
21: import java.awt.event.ActionEvent;
22: import java.awt.event.ActionListener;
23:
24: import javax.swing.event.ListSelectionEvent;
25: import javax.swing.event.ListSelectionListener;
26:
27: import com.jeta.open.gui.framework.JETAController;
28:
29: /**
30: * Event handler for the FontView
31: *
32: * @author Jeff Tassin
33: */
34: public class FontViewController extends JETAController {
35: private FontView m_view;
36:
37: /**
38: * ctor
39: */
40: public FontViewController(FontView view) {
41: super (view);
42: m_view = view;
43: assignListener(FontViewNames.ID_FAMILY_LIST,
44: new FontListListener(FontViewNames.ID_FAMILY_LIST,
45: FontViewNames.ID_FAMILY_FIELD));
46: assignListener(FontViewNames.ID_STYLE_LIST,
47: new FontListListener(FontViewNames.ID_STYLE_LIST,
48: FontViewNames.ID_STYLE_FIELD));
49: assignListener(FontViewNames.ID_SIZE_LIST,
50: new FontListListener(FontViewNames.ID_SIZE_LIST,
51: FontViewNames.ID_SIZE_FIELD));
52: assignAction(FontViewNames.ID_SIZE_FIELD,
53: new FontSizeListener());
54: }
55:
56: public class FontSizeListener implements ActionListener {
57: public void actionPerformed(ActionEvent evt) {
58: m_view.setPointSize(m_view.getPointSize());
59: m_view.setFontValue(m_view.createFont());
60: }
61: }
62:
63: /**
64: * A list selection listener for one of the JList components on the
65: * FontView. The caller passes in the name for the list we wish to handle
66: * events for.
67: */
68: public class FontListListener implements ListSelectionListener {
69: /**
70: * The name of the list
71: */
72: private String m_list_name;
73:
74: /**
75: * The corresponding text field
76: */
77: private String m_txt_field_name;
78:
79: /**
80: * ctor
81: */
82: public FontListListener(String listName, String fieldName) {
83: m_list_name = listName;
84: m_txt_field_name = fieldName;
85: }
86:
87: /**
88: * ListSelectionListener implementation
89: */
90: public void valueChanged(ListSelectionEvent e) {
91: if (!e.getValueIsAdjusting()) {
92: m_view.setText(m_txt_field_name, (String) m_view
93: .getSelectedItem(m_list_name));
94: m_view.setFontValue(m_view.createFont());
95: }
96: }
97: }
98: }
|