X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Farchaeopteryx%2FTreeFontSet.java;h=a07c87ab51616109a9c6efbc60f027e5f1b99762;hb=fbb463a0dc277aa6efa5231f6db554de3696b194;hp=a3c136d020031b296d9004825e33834dff15967f;hpb=790ebe51ea3e7fcafc91057f4842453a1c351b61;p=jalview.git diff --git a/forester/java/src/org/forester/archaeopteryx/TreeFontSet.java b/forester/java/src/org/forester/archaeopteryx/TreeFontSet.java index a3c136d..a07c87a 100644 --- a/forester/java/src/org/forester/archaeopteryx/TreeFontSet.java +++ b/forester/java/src/org/forester/archaeopteryx/TreeFontSet.java @@ -28,7 +28,6 @@ package org.forester.archaeopteryx; -import java.awt.Component; import java.awt.Font; import java.awt.FontMetrics; @@ -37,11 +36,12 @@ import java.awt.FontMetrics; */ public final class TreeFontSet { - private final static String DEFAULT_FONT = "Verdana"; - private final static float FONT_SIZE_CHANGE_STEP = 1.0f; - static final int BOLD_AND_ITALIC = Font.BOLD + Font.ITALIC; + 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; // the owner (needed to get font metrics) - private final Component _owner; + private final MainPanel _owner; // The fonts private Font _small_font; private Font _large_font; @@ -52,6 +52,10 @@ public final class TreeFontSet { 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; @@ -60,16 +64,32 @@ public final class TreeFontSet { FontMetrics _fm_large_italic; FontMetrics _fm_large_italic_bold; // hold font measurements - int _small_max_descent = 0; - int _small_max_ascent = 0; + 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; - TreeFontSet( final Component owner ) { + TreeFontSet( final MainPanel owner ) { _owner = owner; + _min = _owner.getConfiguration().getMinBaseFontSize(); + _max = _owner.getConfiguration().getMinBaseFontSize(); setBaseFont( new Font( DEFAULT_FONT, Font.PLAIN, 10 ) ); } - void decreaseFontSize() { - if ( _large_font.getSize() > 0 ) { + public Font getSmallFont() { + return _small_font; + } + + 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 ); @@ -78,8 +98,8 @@ public final class TreeFontSet { } } - void reset() { - _large_font_system = _large_font; + Font getLargeFontMemory() { + return _large_font_memory; } Font getBaseFont() { @@ -90,10 +110,6 @@ public final class TreeFontSet { return _large_font; } - private Font getLargeFontSystem() { - return _large_font_system; - } - Font getLargeItalicFont() { return _large_italic_font; } @@ -102,11 +118,7 @@ public final class TreeFontSet { return _large_italic_font_system; } - public Font getSmallFont() { - return _small_font; - } - - public Font getSmallFontSystem() { + Font getSmallFontSystem() { return _small_font_system; } @@ -126,24 +138,12 @@ public final class TreeFontSet { setupFontMetrics(); } - private void intializeFonts() { - final int small_size = getBaseFont().getSize() - 1; - int italic = Font.ITALIC; - if ( getBaseFont().getStyle() == Font.BOLD ) { - italic = italic + Font.BOLD; - } - _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() ); - setupFontMetrics(); + boolean isDecreasedSizeBySystem() { + return _decreased_size_by_system; } void largeFonts() { + setDecreasedSizeBySystem( false ); _small_font = _small_font.deriveFont( 12f ); _large_font = _large_font.deriveFont( 14f ); _small_italic_font = _small_italic_font.deriveFont( 12f ); @@ -152,6 +152,7 @@ public final class TreeFontSet { } void mediumFonts() { + setDecreasedSizeBySystem( false ); _small_font = _small_font.deriveFont( 8f ); _large_font = _large_font.deriveFont( 10f ); _small_italic_font = _small_italic_font.deriveFont( 8f ); @@ -159,31 +160,26 @@ public final class TreeFontSet { setupFontMetrics(); } + void reset() { + _large_font_system = _large_font; + } + void setBaseFont( final Font base_font ) { _base_font = base_font; intializeFonts(); } - 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; - } - void smallFonts() { - _small_font = _small_font.deriveFont( 7f ); - _large_font = _large_font.deriveFont( 8f ); - _small_italic_font = _small_italic_font.deriveFont( 7f ); - _large_italic_font = _large_italic_font.deriveFont( 8f ); + 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(); } void superTinyFonts() { + setDecreasedSizeBySystem( false ); _small_font = _small_font.deriveFont( 2f ); _large_font = _large_font.deriveFont( 3f ); _small_italic_font = _small_italic_font.deriveFont( 2f ); @@ -192,10 +188,51 @@ public final class TreeFontSet { } void tinyFonts() { + 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(); } + + private Font getLargeFontSystem() { + return _large_font_system; + } + + private void intializeFonts() { + final int small_size = getBaseFont().getSize() - 1; + int italic = Font.ITALIC; + if ( getBaseFont().getStyle() == Font.BOLD ) { + italic = italic + Font.BOLD; + } + _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(); + } + + private void setDecreasedSizeBySystem( final boolean decreased_size_by_system ) { + _decreased_size_by_system = decreased_size_by_system; + } + + 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; + } }