X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Farchaeopteryx%2FTreeFontSet.java;h=40d945dd2dce2595b26d9c437a3da07d209c99b9;hb=aff0b302cc19e0ee3e73bc4a87884b4591ac5f08;hp=66020ccb74d1a23a18f5298baaa21600ff50e3b2;hpb=ccf4c584032d16ed0ed8d0678f01305887724f96;p=jalview.git diff --git a/forester/java/src/org/forester/archaeopteryx/TreeFontSet.java b/forester/java/src/org/forester/archaeopteryx/TreeFontSet.java index 66020cc..40d945d 100644 --- a/forester/java/src/org/forester/archaeopteryx/TreeFontSet.java +++ b/forester/java/src/org/forester/archaeopteryx/TreeFontSet.java @@ -8,7 +8,7 @@ // and Howard Hughes Medical Institute // Copyright (C) 2003-2007 Ethalinda K.S. Cannon // All rights reserved -// +// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either @@ -18,17 +18,16 @@ // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA // // Contact: phylosoft @ gmail . com -// WWW: www.phylosoft.org/forester +// WWW: https://sites.google.com/site/cmzmasek/home/software/forester package org.forester.archaeopteryx; -import java.awt.Component; import java.awt.Font; import java.awt.FontMetrics; @@ -37,39 +36,96 @@ 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; + 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 = "Arial Unicode MS"; + 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 Component _owner; + 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; - // 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_memory; + 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 int _small_max_descent = 0; - 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 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; + } + + private Font getLargeFontSystem() { + return _large_font_system; + } + + private void intializeFonts() { + final int small_size = getBaseFont().getSize() - 2; + 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_font_system = new Font( getBaseFont().getFontName(), getBaseFont().getStyle(), small_size ); + _large_font_system = new Font( getBaseFont().getFontName(), getBaseFont().getStyle(), getBaseFont().getSize() ); + _small_font_memory = _small_font; + _large_font_memory = _large_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 ); + _small_max_descent = _fm_small.getMaxDescent(); + _small_max_ascent = _fm_small.getMaxAscent() + 1; + } + + 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; + } + 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(); } } @@ -82,92 +138,65 @@ public final class TreeFontSet { return _large_font; } - Font getLargeItalicFont() { - return _large_italic_font; - } - - public Font getSmallFont() { - return _small_font; + Font getLargeFontMemory() { + return _large_font_memory; } - Font getSmallItalicFont() { - return _small_italic_font; + Font getSmallFontSystem() { + return _small_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(); } - 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() ); - 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 ); - _large_italic_font = _large_italic_font.deriveFont( 14f ); setupFontMetrics(); } void mediumFonts() { + 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(); } + 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 - 2 ); + _large_font = _large_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 ); - _large_italic_font = _large_italic_font.deriveFont( 3f ); + _large_font = _large_font.deriveFont( 4f ); setupFontMetrics(); } void tinyFonts() { - _small_font = _small_font.deriveFont( 5f ); + setDecreasedSizeBySystem( false ); + _small_font = _small_font.deriveFont( 4f ); _large_font = _large_font.deriveFont( 6f ); - _small_italic_font = _small_italic_font.deriveFont( 5f ); - _large_italic_font = _large_italic_font.deriveFont( 6f ); setupFontMetrics(); } }