2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
5 // Copyright (C) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
7 // Copyright (C) 2000-2001 Washington University School of Medicine
8 // and Howard Hughes Medical Institute
9 // Copyright (C) 2003-2007 Ethalinda K.S. Cannon
10 // All rights reserved
12 // This library is free software; you can redistribute it and/or
13 // modify it under the terms of the GNU Lesser General Public
14 // License as published by the Free Software Foundation; either
15 // version 2.1 of the License, or (at your option) any later version.
17 // This library is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 // Lesser General Public License for more details.
22 // You should have received a copy of the GNU Lesser General Public
23 // License along with this library; if not, write to the Free Software
24 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26 // Contact: phylosoft @ gmail . com
27 // WWW: www.phylosoft.org/forester
29 package org.forester.archaeopteryx;
31 import java.awt.Component;
33 import java.awt.FontMetrics;
36 * Maintains the fonts for drawing a tree.
38 public final class TreeFontSet {
40 private final static String DEFAULT_FONT = "Verdana";
41 private final static float FONT_SIZE_CHANGE_STEP = 1.0f;
42 static final int BOLD_AND_ITALIC = Font.BOLD + Font.ITALIC;
43 // the owner (needed to get font metrics)
44 private final Component _owner;
46 private Font _small_font;
47 private Font _large_font;
48 private Font _small_italic_font;
49 private Font _large_italic_font;
50 private Font _base_font;
51 // Handy holders for font metrics
52 public FontMetrics _fm_small;
53 FontMetrics _fm_large;
54 FontMetrics _fm_small_italic;
55 FontMetrics _fm_small_italic_bold;
56 FontMetrics _fm_large_italic;
57 FontMetrics _fm_large_italic_bold;
58 // hold font measurements
59 int _small_max_descent = 0;
60 int _small_max_ascent = 0;
62 TreeFontSet( final Component owner ) {
64 setBaseFont( new Font( DEFAULT_FONT, Font.PLAIN, 10 ) );
67 void decreaseFontSize() {
68 if ( _large_font.getSize() > 0 ) {
69 _small_font = _small_font.deriveFont( _small_font.getSize() - FONT_SIZE_CHANGE_STEP );
70 _large_font = _large_font.deriveFont( _large_font.getSize() - FONT_SIZE_CHANGE_STEP );
71 _small_italic_font = _small_italic_font.deriveFont( _small_italic_font.getSize() - FONT_SIZE_CHANGE_STEP );
72 _large_italic_font = _large_italic_font.deriveFont( _large_italic_font.getSize() - FONT_SIZE_CHANGE_STEP );
85 Font getLargeItalicFont() {
86 return _large_italic_font;
89 public Font getSmallFont() {
93 Font getSmallItalicFont() {
94 return _small_italic_font;
97 void increaseFontSize() {
98 _small_font = _small_font.deriveFont( _small_font.getSize() + FONT_SIZE_CHANGE_STEP );
99 _large_font = _large_font.deriveFont( _large_font.getSize() + FONT_SIZE_CHANGE_STEP );
100 _small_italic_font = _small_italic_font.deriveFont( _small_italic_font.getSize() + FONT_SIZE_CHANGE_STEP );
101 _large_italic_font = _large_italic_font.deriveFont( _large_italic_font.getSize() + FONT_SIZE_CHANGE_STEP );
105 private void intializeFonts() {
106 final int small_size = getBaseFont().getSize() - 1;
107 int italic = Font.ITALIC;
108 if ( getBaseFont().getStyle() == Font.BOLD ) {
109 italic = italic + Font.BOLD;
111 _small_font = new Font( getBaseFont().getFontName(), getBaseFont().getStyle(), small_size );
112 _large_font = new Font( getBaseFont().getFontName(), getBaseFont().getStyle(), getBaseFont().getSize() );
113 _small_italic_font = new Font( getBaseFont().getFontName(), italic, small_size );
114 _large_italic_font = new Font( getBaseFont().getFontName(), italic, getBaseFont().getSize() );
119 _small_font = _small_font.deriveFont( 12f );
120 _large_font = _large_font.deriveFont( 14f );
121 _small_italic_font = _small_italic_font.deriveFont( 12f );
122 _large_italic_font = _large_italic_font.deriveFont( 14f );
127 _small_font = _small_font.deriveFont( 8f );
128 _large_font = _large_font.deriveFont( 10f );
129 _small_italic_font = _small_italic_font.deriveFont( 8f );
130 _large_italic_font = _large_italic_font.deriveFont( 10f );
134 void setBaseFont( final Font base_font ) {
135 _base_font = base_font;
139 private void setupFontMetrics() {
140 _fm_small = _owner.getFontMetrics( _small_font );
141 _fm_large = _owner.getFontMetrics( _large_font );
142 _fm_small_italic = _owner.getFontMetrics( _small_italic_font );
143 _fm_small_italic_bold = _owner.getFontMetrics( _small_italic_font.deriveFont( Font.BOLD ) );
144 _fm_large_italic = _owner.getFontMetrics( _large_italic_font );
145 _fm_large_italic_bold = _owner.getFontMetrics( _large_italic_font.deriveFont( Font.BOLD ) );
146 _small_max_descent = _fm_small.getMaxDescent();
147 _small_max_ascent = _fm_small.getMaxAscent() + 1;
151 _small_font = _small_font.deriveFont( 7f );
152 _large_font = _large_font.deriveFont( 8f );
153 _small_italic_font = _small_italic_font.deriveFont( 7f );
154 _large_italic_font = _large_italic_font.deriveFont( 8f );
158 void superTinyFonts() {
159 _small_font = _small_font.deriveFont( 2f );
160 _large_font = _large_font.deriveFont( 3f );
161 _small_italic_font = _small_italic_font.deriveFont( 2f );
162 _large_italic_font = _large_italic_font.deriveFont( 3f );
167 _small_font = _small_font.deriveFont( 5f );
168 _large_font = _large_font.deriveFont( 6f );
169 _small_italic_font = _small_italic_font.deriveFont( 5f );
170 _large_italic_font = _large_italic_font.deriveFont( 6f );