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

📄 fontex.java

📁 FuncPlotter is a combined Java application and applet for displaying two-dimensional plots of explic
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                    if ( str.length( ) > 0 )                    {                        switch ( j )                        {                            case Param.NAME:                            {                                fonts[i].name = str;                                break;                            }                            case Param.STYLE:                            {                                Style style = Style.get( str );                                if ( style == null )                                    throw new Exception( INVALID_STYLE_STR );                                fonts[i].style = style;                                break;                            }                            case Param.SIZE:                            {                                try                                {                                    int size = Integer.parseInt( str );                                    if ( (size < MIN_FONT_SIZE) || (size > MAX_FONT_SIZE) )                                        throw new Exception( SIZE_OUT_OF_BOUNDS_STR );                                    fonts[i].size = size;                                }                                catch ( NumberFormatException e )                                {                                    throw new Exception( INVALID_SIZE_STR );                                }                                break;                            }                        }                    }                }            }            catch ( Exception e )            {                System.err.println( FONT_PROPERTY_STR + keys[i] + " : " + e.getMessage( ) );            }        }    }    //------------------------------------------------------------------    public static int getNumFonts( )    {        return fonts.length;    }    //------------------------------------------------------------------    public static FontEx getFontEx( int index )    {        return fonts[index];    }    //------------------------------------------------------------------    public static void setFontEx( int    index,                                  FontEx font )    {        fonts[index] = font;    }    //------------------------------------------------------------------    public static Font getFont( int index )    {        Font font = null;        if ( index < fonts.length )        {            FontEx fontEx = fonts[index];            String name = (fontEx.name == null) ? DEFAULT_FONT_NAME : fontEx.name;            int style = (fontEx.style == null) ? DEFAULT_FONT_STYLE : fontEx.style.getAwtStyle( );            int size = (fontEx.size == 0) ? DEFAULT_FONT_SIZE : fontEx.size;            font = new Font( name, style, size );        }        return font;    }    //------------------------------------------------------------------    public static void setFont( Component component,                                int       index )    {        if ( (component != null) && (index < fonts.length) )        {            Font currentFont = component.getFont( );            if ( currentFont == null )                currentFont = new Font( DEFAULT_FONT_NAME, DEFAULT_FONT_STYLE, DEFAULT_FONT_SIZE );            FontEx fontEx = fonts[index];            String name = (fontEx.name == null) ? currentFont.getFontName( ) : fontEx.name;            int style = (fontEx.style == null) ? currentFont.getStyle( ) : fontEx.style.getAwtStyle( );            int size = (fontEx.size == 0) ? currentFont.getSize( ) : fontEx.size;            component.setFont( new Font( name, style, size ) );        }    }    //------------------------------------------------------------------    public static String[] splitString( String str,                                        char   separatorChar )    {        List<String> strs = new ArrayList<String>( );        StringBuilder buffer = new StringBuilder( );        int index = 0;        while ( index < str.length( ) )        {            char ch = str.charAt( index );            if ( ch == '\\' )            {                if ( ++index < str.length( ) )                    buffer.append( str.charAt( index ) );            }            else            {                if ( ch == separatorChar )                {                    strs.add( buffer.toString( ) );                    buffer.setLength( 0 );                }                else                    buffer.append( ch );            }            ++index;        }        if ( buffer.length( ) > 0 )            strs.add( buffer.toString( ) );        return strs.toArray( new String[strs.size( )] );    }    //------------------------------------------------------------------    public static String escapeSeparator( String str,                                          char   separatorChar )    {        String separatorStr = Character.toString( separatorChar );        return str.replace( "\\", "\\\\" ).replace( separatorStr, "\\" + separatorStr );    }    //------------------------------------------------------------------    private static Properties getProperties( String pathname )    {        Properties properties = new Properties( );        FileInputStream inStream = null;        try        {            inStream = new FileInputStream( pathname );            if ( inStream.getChannel( ).tryLock( 0, Long.MAX_VALUE, true ) == null )                throw new Exception( FAILED_TO_LOCK_STR );            properties.loadFromXML( inStream );        }        catch ( Exception e )        {            System.err.println( FAILED_TO_LOAD_STR + FROM_STR + pathname );            if ( e.getMessage( ) != null )                System.err.println( e.getMessage( ) );        }        finally        {            try            {                if ( inStream != null )                    inStream.close( );            }            catch( IOException e )            {                // ignore            }        }        return properties;    }    //------------------------------------------------------------------//////////////////////////////////////////////////////////////////////////  Instance methods : overriding methods////////////////////////////////////////////////////////////////////////    public boolean equals( Object obj )    {        if ( obj instanceof FontEx )        {            FontEx font = (FontEx)obj;            return ( (((name == null) && (font.name == null)) ||                      ((name != null) && name.equals( font.name ))) &&                     (style == font.style) && (size == font.size) );        }        return false;    }    //------------------------------------------------------------------    public String toString( )    {        StringBuilder buffer = new StringBuilder( );        if ( name != null )            buffer.append( escapeSeparator( name, SEPARATOR_CHAR ) );        buffer.append( SEPARATOR_CHAR );        buffer.append( ' ' );        if ( style != null )            buffer.append( style.getKey( ) );        buffer.append( SEPARATOR_CHAR );        buffer.append( ' ' );        if ( size > 0 )            buffer.append( size );        return buffer.toString( );    }    //------------------------------------------------------------------//////////////////////////////////////////////////////////////////////////  Instance variables////////////////////////////////////////////////////////////////////////    public String getName( )    {        return name;    }    //------------------------------------------------------------------    public Style getStyle( )    {        return style;    }    //------------------------------------------------------------------    public int getSize( )    {        return size;    }    //------------------------------------------------------------------    public void setName( String name )    {        this.name = name;    }    //------------------------------------------------------------------    public void setStyle( Style style )    {        this.style = style;    }    //------------------------------------------------------------------    public void setSize( int size )    {        this.size = size;    }    //------------------------------------------------------------------//////////////////////////////////////////////////////////////////////////  Class variables////////////////////////////////////////////////////////////////////////    private static  FontEx[]    fonts;//////////////////////////////////////////////////////////////////////////  Instance variables////////////////////////////////////////////////////////////////////////    private String  name;    private Style   style;    private int     size;}//----------------------------------------------------------------------

⌨️ 快捷键说明

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