01 /*
02 * Copyright (c) 1995-2010, The University of Sheffield. See the file
03 * COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt
04 *
05 * This file is part of GATE (see http://gate.ac.uk/), and is free
06 * software, licenced under the GNU Library General Public License,
07 * Version 2, June 1991 (in the distribution as file licence.html,
08 * and also available at http://gate.ac.uk/gate/licence.html).
09 *
10 * Valentin Tablan 06/03/2001
11 *
12 * $Id: XJTextPane.java 12006 2009-12-01 17:24:28Z thomas_heitz $
13 *
14 */
15
16 package gate.swing;
17
18 import java.awt.Font;
19 import java.beans.PropertyChangeEvent;
20 import java.beans.PropertyChangeListener;
21
22 import javax.swing.JTextPane;
23 import javax.swing.UIManager;
24 import javax.swing.text.*;
25
26 /**
27 * A custom JTextPane that reinitialises the default font style when th UI
28 * changes. This is needed by applications that want to be able to change the
29 * font in the entire application by changing the UI defaults table.
30 */
31 public class XJTextPane extends JTextPane {
32
33 public XJTextPane() {
34 super();
35 initListeners();
36 updateStyle();
37 }
38
39 public XJTextPane(StyledDocument doc) {
40 super(doc);
41 initListeners();
42 updateStyle();
43 }
44
45 protected void initListeners(){
46 addPropertyChangeListener(new PropertyChangeListener() {
47 public void propertyChange(PropertyChangeEvent e) {
48 if(e.getPropertyName().equals("UI")){
49 updateStyle();
50 }else if(e.getPropertyName().equals("document")){
51 updateStyle();
52 }
53 }
54 });
55 }
56
57 protected void updateStyle(){
58 Font newFont = UIManager.getFont("TextPane.font");
59 Style defaultStyle = getStyle("default");
60 StyleConstants.setFontFamily(defaultStyle, newFont.getFamily());
61 StyleConstants.setFontSize(defaultStyle, newFont.getSize());
62 StyleConstants.setItalic(defaultStyle, newFont.isItalic());
63 StyleConstants.setBold(defaultStyle, newFont.isBold());
64 repaint();
65 }
66 }
|