| XJTextPane |

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

| XJTextPane |