X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Farchaeopteryx%2FTreeFontSet.java;h=c278f1cac0bb3c8988ff5d598cdbaeb2ba9ddb2d;hb=e6ea1a1dcb0a9b96cad1bc08c3b80a6f876344d2;hp=a07c87ab51616109a9c6efbc60f027e5f1b99762;hpb=f6d7dfa06e34eaf7cc773cf7484e7b641296d452;p=jalview.git diff --git a/forester/java/src/org/forester/archaeopteryx/TreeFontSet.java b/forester/java/src/org/forester/archaeopteryx/TreeFontSet.java index a07c87a..c278f1ca 100644 --- a/forester/java/src/org/forester/archaeopteryx/TreeFontSet.java +++ b/forester/java/src/org/forester/archaeopteryx/TreeFontSet.java @@ -36,39 +36,29 @@ import java.awt.FontMetrics; */ public final class TreeFontSet { + static final int BOLD_AND_ITALIC = Font.BOLD + Font.ITALIC; + final static float FONT_SIZE_CHANGE_STEP = 1.0f; final static float SMALL_FONTS_BASE = 8; private final static String DEFAULT_FONT = "Verdana"; - final static float FONT_SIZE_CHANGE_STEP = 1.0f; - static final int BOLD_AND_ITALIC = Font.BOLD + Font.ITALIC; + private Font _base_font; + private boolean _decreased_size_by_system = false; + private FontMetrics _fm_large; + // Handy holders for font metrics + private FontMetrics _fm_small; + private Font _large_font; + private Font _large_font_memory; + private Font _large_font_system; + private final int _max; + private final int _min; // the owner (needed to get font metrics) private final MainPanel _owner; // The fonts private Font _small_font; - private Font _large_font; - private Font _small_italic_font; - private Font _large_italic_font; - private Font _base_font; - private Font _small_font_system; - private Font _large_font_system; - private Font _small_italic_font_system; - private Font _large_italic_font_system; private Font _small_font_memory; - private Font _large_font_memory; - private Font _small_italic_font_memory; - private Font _large_italic_font_memory; - // Handy holders for font metrics - public FontMetrics _fm_small; - FontMetrics _fm_large; - FontMetrics _fm_small_italic; - FontMetrics _fm_small_italic_bold; - FontMetrics _fm_large_italic; - FontMetrics _fm_large_italic_bold; + private Font _small_font_system; + private int _small_max_ascent = 0; // hold font measurements - int _small_max_descent = 0; - int _small_max_ascent = 0; - private final int _min; - private final int _max; - private boolean _decreased_size_by_system = false; + private int _small_max_descent = 0; TreeFontSet( final MainPanel owner ) { _owner = owner; @@ -77,31 +67,39 @@ public final class TreeFontSet { setBaseFont( new Font( DEFAULT_FONT, Font.PLAIN, 10 ) ); } + public FontMetrics getFontMetricsLarge() { + return _fm_large; + } + + public FontMetrics getFontMetricsSmall() { + return _fm_small; + } + public Font getSmallFont() { return _small_font; } + public int getSmallMaxAscent() { + return _small_max_ascent; + } + + public int getSmallMaxDescent() { + return _small_max_descent; + } + void decreaseFontSize( final int min, final boolean decreased_size_by_system ) { if ( decreased_size_by_system && !isDecreasedSizeBySystem() ) { _small_font_memory = _small_font; _large_font_memory = _large_font; - _small_italic_font_memory = _small_italic_font; - _large_italic_font_memory = _large_italic_font; } setDecreasedSizeBySystem( decreased_size_by_system ); if ( _large_font.getSize() >= min ) { _small_font = _small_font.deriveFont( _small_font.getSize() - FONT_SIZE_CHANGE_STEP ); _large_font = _large_font.deriveFont( _large_font.getSize() - FONT_SIZE_CHANGE_STEP ); - _small_italic_font = _small_italic_font.deriveFont( _small_italic_font.getSize() - FONT_SIZE_CHANGE_STEP ); - _large_italic_font = _large_italic_font.deriveFont( _large_italic_font.getSize() - FONT_SIZE_CHANGE_STEP ); setupFontMetrics(); } } - Font getLargeFontMemory() { - return _large_font_memory; - } - Font getBaseFont() { return _base_font; } @@ -110,31 +108,17 @@ public final class TreeFontSet { return _large_font; } - Font getLargeItalicFont() { - return _large_italic_font; - } - - Font getLargeItalicFontSystem() { - return _large_italic_font_system; + Font getLargeFontMemory() { + return _large_font_memory; } Font getSmallFontSystem() { return _small_font_system; } - Font getSmallItalicFont() { - return _small_italic_font; - } - - Font getSmallItalicFontSystem() { - return _small_italic_font_system; - } - void increaseFontSize() { _small_font = _small_font.deriveFont( _small_font.getSize() + FONT_SIZE_CHANGE_STEP ); _large_font = _large_font.deriveFont( _large_font.getSize() + FONT_SIZE_CHANGE_STEP ); - _small_italic_font = _small_italic_font.deriveFont( _small_italic_font.getSize() + FONT_SIZE_CHANGE_STEP ); - _large_italic_font = _large_italic_font.deriveFont( _large_italic_font.getSize() + FONT_SIZE_CHANGE_STEP ); setupFontMetrics(); } @@ -146,8 +130,6 @@ public final class TreeFontSet { setDecreasedSizeBySystem( false ); _small_font = _small_font.deriveFont( 12f ); _large_font = _large_font.deriveFont( 14f ); - _small_italic_font = _small_italic_font.deriveFont( 12f ); - _large_italic_font = _large_italic_font.deriveFont( 14f ); setupFontMetrics(); } @@ -155,8 +137,6 @@ public final class TreeFontSet { setDecreasedSizeBySystem( false ); _small_font = _small_font.deriveFont( 8f ); _large_font = _large_font.deriveFont( 10f ); - _small_italic_font = _small_italic_font.deriveFont( 8f ); - _large_italic_font = _large_italic_font.deriveFont( 10f ); setupFontMetrics(); } @@ -173,8 +153,6 @@ public final class TreeFontSet { setDecreasedSizeBySystem( false ); _small_font = _small_font.deriveFont( SMALL_FONTS_BASE - 1 ); _large_font = _large_font.deriveFont( SMALL_FONTS_BASE ); - _small_italic_font = _small_italic_font.deriveFont( SMALL_FONTS_BASE - 1 ); - _large_italic_font = _large_italic_font.deriveFont( SMALL_FONTS_BASE ); setupFontMetrics(); } @@ -182,8 +160,6 @@ public final class TreeFontSet { setDecreasedSizeBySystem( false ); _small_font = _small_font.deriveFont( 2f ); _large_font = _large_font.deriveFont( 3f ); - _small_italic_font = _small_italic_font.deriveFont( 2f ); - _large_italic_font = _large_italic_font.deriveFont( 3f ); setupFontMetrics(); } @@ -191,8 +167,6 @@ public final class TreeFontSet { setDecreasedSizeBySystem( false ); _small_font = _small_font.deriveFont( 5f ); _large_font = _large_font.deriveFont( 6f ); - _small_italic_font = _small_italic_font.deriveFont( 5f ); - _large_italic_font = _large_italic_font.deriveFont( 6f ); setupFontMetrics(); } @@ -208,16 +182,10 @@ public final class TreeFontSet { } _small_font = new Font( getBaseFont().getFontName(), getBaseFont().getStyle(), small_size ); _large_font = new Font( getBaseFont().getFontName(), getBaseFont().getStyle(), getBaseFont().getSize() ); - _small_italic_font = new Font( getBaseFont().getFontName(), italic, small_size ); - _large_italic_font = new Font( getBaseFont().getFontName(), italic, getBaseFont().getSize() ); _small_font_system = new Font( getBaseFont().getFontName(), getBaseFont().getStyle(), small_size ); _large_font_system = new Font( getBaseFont().getFontName(), getBaseFont().getStyle(), getBaseFont().getSize() ); - _small_italic_font_system = new Font( getBaseFont().getFontName(), italic, small_size ); - _large_italic_font_system = new Font( getBaseFont().getFontName(), italic, getBaseFont().getSize() ); _small_font_memory = _small_font; _large_font_memory = _large_font; - _small_italic_font_memory = _small_italic_font; - _large_italic_font_memory = _large_italic_font; setupFontMetrics(); } @@ -228,10 +196,6 @@ public final class TreeFontSet { private void setupFontMetrics() { _fm_small = _owner.getFontMetrics( _small_font ); _fm_large = _owner.getFontMetrics( _large_font ); - _fm_small_italic = _owner.getFontMetrics( _small_italic_font ); - _fm_small_italic_bold = _owner.getFontMetrics( _small_italic_font.deriveFont( Font.BOLD ) ); - _fm_large_italic = _owner.getFontMetrics( _large_italic_font ); - _fm_large_italic_bold = _owner.getFontMetrics( _large_italic_font.deriveFont( Font.BOLD ) ); _small_max_descent = _fm_small.getMaxDescent(); _small_max_ascent = _fm_small.getMaxAscent() + 1; }