01: package org.krysalis.jcharts.designer.common.font;
02:
03: import org.krysalis.jcharts.designer.common.LabelledCombo;
04: import org.krysalis.jcharts.designer.common.LabelledTextfield;
05: import org.krysalis.jcharts.designer.exceptions.DesignerException;
06: import org.krysalis.jcharts.properties.util.ChartFont;
07:
08: import javax.swing.*;
09: import java.awt.*;
10:
11: public class FontChooser extends JPanel {
12: private static String[] ALL_FONT_NAMES;
13: static {
14: Font[] allFonts = GraphicsEnvironment
15: .getLocalGraphicsEnvironment().getAllFonts();
16: ALL_FONT_NAMES = new String[allFonts.length];
17:
18: for (int i = 0; i < allFonts.length; i++) {
19: ALL_FONT_NAMES[i] = allFonts[i].getName();
20: }
21: }
22:
23: private String title;
24: private LabelledCombo fontCombo;
25: private LabelledTextfield size;
26: private LabelledCombo styleCombo;
27:
28: /***********************************************************************************
29: *
30: * @param title
31: **********************************************************************************/
32: public FontChooser(String title) {
33: super ();
34: this .title = title;
35:
36: super .setBorder(BorderFactory.createCompoundBorder(
37: BorderFactory.createTitledBorder(this .title),
38: BorderFactory.createEmptyBorder(5, 5, 5, 5)));
39:
40: this .setLayout(new FlowLayout());
41:
42: this .fontCombo = new LabelledCombo("Name:", ALL_FONT_NAMES);
43: this .add(this .fontCombo);
44:
45: this .size = new LabelledTextfield("Size:", 3);
46: this .size.setText("12");
47: this .add(this .size);
48:
49: this .styleCombo = new StylesCombo();
50: this .add(this .styleCombo);
51: }
52:
53: /*********************************************************************************
54: *
55: * @return ChartFont
56: ********************************************************************************/
57: public ChartFont getChartFont() throws DesignerException {
58: if (this .size.getText().trim().equals("")) {
59: throw new DesignerException(
60: "Title Font size can not be NULL.");
61: }
62:
63: Font font = new Font(this .fontCombo.getSelected(),
64: this .styleCombo.getSelectedIndex(), Integer
65: .parseInt(this .size.getText()));
66: //todo Paint implementation?
67: ChartFont chartFont = new ChartFont(font, Color.black);
68: return chartFont;
69: }
70: }
|