⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fontex.java

📁 FuncPlotter is a combined Java application and applet for displaying two-dimensional plots of explic
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*====================================================================*\FontEx.javaExtended font class.------------------------------------------------------------------------This file is part of FuncPlotter, a combined Java application and appletfor plotting explicit functions in one variable.Copyright 2005-2007 Andy Morgan-Richards.FuncPlotter is free software: you can redistribute it and/or modify itunder the terms of the GNU General Public License as published by theFree Software Foundation, either version 3 of the License, or (at youroption) any later version.This program is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public License alongwith this program.  If not, see <http://www.gnu.org/licenses/>.\*====================================================================*/// PACKAGEpackage gui;//----------------------------------------------------------------------// IMPORTSimport java.awt.Component;import java.awt.Font;import java.io.File;import java.io.FileInputStream;import java.io.IOException;import java.util.ArrayList;import java.util.List;import java.util.Properties;//----------------------------------------------------------------------// EXTENDED FONT CLASSpublic class FontEx{//////////////////////////////////////////////////////////////////////////  Constants////////////////////////////////////////////////////////////////////////    public static final     int MIN_FONT_SIZE   = 4;    public static final     int MAX_FONT_SIZE   = 128;    public static final     char    SEPARATOR_CHAR  = ',';    public interface Param    {        int NAME    = 0;        int STYLE   = 1;        int SIZE    = 2;    }    private static final    String  FONT_PROPERTIES_FILENAME    = "puckfist-appFont.xml";    private static final    String  DEFAULT_FONT_NAME   = "Dialog";    private static final    int     DEFAULT_FONT_STYLE  = Font.PLAIN;    private static final    int     DEFAULT_FONT_SIZE   = 12;    private static final    String  FAILED_TO_LOAD_STR          = "Failed to load the font properties";    private static final    String  FAILED_TO_LOCK_STR          = "Failed to lock the file";    private static final    String  FROM_STR                    = " from ";    private static final    String  FONT_PROPERTY_STR           = "Font property ";    private static final    String  PROPERTY_NOT_FOUND_STR      = "The font property was not found";    private static final    String  INVALID_PROPERTY_VALUE_STR  = "The font property value is invalid";    private static final    String  INVALID_STYLE_STR           = "The font style is invalid";    private static final    String  SIZE_OUT_OF_BOUNDS_STR      = "The font size must be between " +                                                                    MIN_FONT_SIZE + " and " + MAX_FONT_SIZE;    private static final    String  INVALID_SIZE_STR            = "The font size is invalid";//////////////////////////////////////////////////////////////////////////  Enumeration types////////////////////////////////////////////////////////////////////////    // STYLE ENUMERATION    public enum Style    {    ////////////////////////////////////////////////////////////////////    //  Constants    ////////////////////////////////////////////////////////////////////        PLAIN       ( "plain",      "Plain",        Font.PLAIN ),        BOLD        ( "bold",       "Bold",         Font.BOLD ),        ITALIC      ( "italic",     "Italic",       Font.ITALIC ),        BOLD_ITALIC ( "boldItalic", "Bold italic",  Font.BOLD | Font.ITALIC );    ////////////////////////////////////////////////////////////////////    //  Constructors    ////////////////////////////////////////////////////////////////////        private Style( String key,                       String text,                       int    awtStyle )        {            this.key = key;            this.text = text;            this.awtStyle = awtStyle;        }        //--------------------------------------------------------------    ////////////////////////////////////////////////////////////////////    //  Class methods    ////////////////////////////////////////////////////////////////////        public static Style get( String key )        {            for ( Style value : values( ) )            {                if ( value.key.equals( key ) )                    return value;            }            return null;        }        //--------------------------------------------------------------        public static Style get( int awtStyle )        {            for ( Style value : values( ) )            {                if ( value.awtStyle == awtStyle )                    return value;            }            return null;        }        //--------------------------------------------------------------    ////////////////////////////////////////////////////////////////////    //  Instance methods : overriding methods    ////////////////////////////////////////////////////////////////////        public String toString( )        {            return text;        }        //--------------------------------------------------------------    ////////////////////////////////////////////////////////////////////    //  Instance methods    ////////////////////////////////////////////////////////////////////        public String getKey( )        {            return key;        }        //--------------------------------------------------------------        public int getAwtStyle( )        {            return awtStyle;        }        //--------------------------------------------------------------    ////////////////////////////////////////////////////////////////////    //  Instance variables    ////////////////////////////////////////////////////////////////////        private String  key;        private String  text;        private int     awtStyle;    }    //==================================================================//////////////////////////////////////////////////////////////////////////  Constructors////////////////////////////////////////////////////////////////////////    public FontEx( )    {    }    //------------------------------------------------------------------    public FontEx( String name,                   Style  style,                   int    size )    {        this.name = name;        this.style = style;        this.size = size;    }    //------------------------------------------------------------------    public FontEx( Font font )    {        name = font.getFontName( );        style = Style.get( font.getStyle( ) );        size = font.getSize( );    }    //------------------------------------------------------------------//////////////////////////////////////////////////////////////////////////  Class methods////////////////////////////////////////////////////////////////////////    public static void init( int numFonts )    {        fonts = new FontEx[numFonts];        for ( int i = 0; i < numFonts; ++i )            fonts[i] = new FontEx( );    }    //------------------------------------------------------------------    public static void init( String   pathname,                             String   appNameKey,                             String[] keys )    {        // Initialise font list        init( keys.length );        // Get pathname of font properties file        if ( pathname == null )        {            System.err.println( FAILED_TO_LOAD_STR + "." );            return;        }        if ( !pathname.endsWith( File.separator ) && !pathname.endsWith( "/" ) )            pathname += File.separator;        pathname += FONT_PROPERTIES_FILENAME;        // Load font properties        FileInputStream inStream = null;        Properties properties = getProperties( pathname );        if ( properties.size( ) == 0 )            return;        // Set font fields from font properties        for ( int i = 0; i < fonts.length; ++i )        {            try            {                String value = properties.getProperty( appNameKey + "." + keys[i] );                if ( value == null )                    value = properties.getProperty( keys[i] );                if ( value == null )                    throw new Exception( PROPERTY_NOT_FOUND_STR );                String[] strs = splitString( value, SEPARATOR_CHAR );                if ( strs.length != 3 )                    throw new Exception( INVALID_PROPERTY_VALUE_STR );                for ( int j = 0; j < strs.length; ++j )                {                    String str = strs[j].trim( );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -