KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > krysalis > jcharts > designer > common > font > FontChooser


1
2
3 package org.krysalis.jcharts.designer.common.font;
4
5
6 import org.krysalis.jcharts.designer.common.LabelledCombo;
7 import org.krysalis.jcharts.designer.common.LabelledTextfield;
8 import org.krysalis.jcharts.designer.exceptions.DesignerException;
9 import org.krysalis.jcharts.properties.util.ChartFont;
10
11 import javax.swing.*;
12 import java.awt.*;
13
14
15 public class FontChooser extends JPanel
16 {
17     private static String JavaDoc[] ALL_FONT_NAMES;
18     static
19     {
20         Font[] allFonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
21         ALL_FONT_NAMES = new String JavaDoc[ allFonts.length ];
22
23         for( int i = 0; i < allFonts.length; i++ )
24         {
25             ALL_FONT_NAMES[ i ] = allFonts[ i ].getName();
26         }
27     }
28
29
30     private String JavaDoc title;
31     private LabelledCombo fontCombo;
32     private LabelledTextfield size;
33     private LabelledCombo styleCombo;
34
35
36     /***********************************************************************************
37      *
38      * @param title
39      **********************************************************************************/

40     public FontChooser( String JavaDoc title )
41     {
42         super();
43       this.title= title;
44
45         super.setBorder( BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder( this.title ),
46                                                                               BorderFactory.createEmptyBorder( 5, 5, 5, 5 ) ) );
47
48         this.setLayout( new FlowLayout() );
49
50         this.fontCombo = new LabelledCombo( "Name:", ALL_FONT_NAMES );
51         this.add( this.fontCombo );
52
53         this.size= new LabelledTextfield( "Size:", 3 );
54         this.size.setText( "12" );
55         this.add( this.size );
56
57         this.styleCombo= new StylesCombo();
58         this.add( this.styleCombo );
59     }
60
61
62     /*********************************************************************************
63      *
64      * @return ChartFont
65      ********************************************************************************/

66     public ChartFont getChartFont() throws DesignerException
67     {
68         if( this.size.getText().trim().equals( "" ) )
69         {
70             throw new DesignerException( "Title Font size can not be NULL." );
71         }
72
73
74         Font font= new Font( this.fontCombo.getSelected(), this.styleCombo.getSelectedIndex(), Integer.parseInt( this.size.getText() ) );
75 //todo Paint implementation?
76
ChartFont chartFont= new ChartFont( font, Color.black );
77         return chartFont;
78     }
79 }
80
Popular Tags