01: /**
02: * L2FProd.com Common Components 7.3 License.
03: *
04: * Copyright 2005-2007 L2FProd.com
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */package com.l2fprod.common.swing;
18:
19: import com.l2fprod.common.swing.plaf.FontChooserUI;
20:
21: import java.awt.GraphicsEnvironment;
22: import java.nio.charset.Charset;
23: import java.util.Arrays;
24: import java.util.Iterator;
25: import java.util.ResourceBundle;
26: import java.util.SortedMap;
27:
28: /**
29: * Default implementation of the FontChooserModel. It returns all available
30: * fonts and commonly used font sizes.
31: */
32: public class DefaultFontChooserModel implements FontChooserModel {
33:
34: public static final int[] DEFAULT_FONT_SIZES = { 6, 8, 10, 11, 12,
35: 14, 16, 18, 20, 22, 24, 26, 28, 32, 40, 48, 56, 64, 72 };
36:
37: protected String[] fontFamilies;
38: private String[] charSets;
39: private int[] defaultFontSizes;
40: private String previewMessage;
41:
42: public DefaultFontChooserModel() {
43: ResourceBundle bundle = ResourceBundle
44: .getBundle(FontChooserUI.class.getName() + "RB");
45: setPreviewMessage(bundle.getString("FontChooserUI.previewText"));
46:
47: String[] fontFamilies = GraphicsEnvironment
48: .getLocalGraphicsEnvironment()
49: .getAvailableFontFamilyNames();
50: Arrays.sort(fontFamilies);
51: setFontFamilies(fontFamilies);
52:
53: SortedMap map = Charset.availableCharsets();
54: String[] charSets = new String[map.size()];
55: int i = 0;
56: for (Iterator iter = map.keySet().iterator(); iter.hasNext(); i++) {
57: charSets[i] = (String) iter.next();
58: }
59: setCharSets(charSets);
60:
61: setDefaultFontSizes(DEFAULT_FONT_SIZES);
62: }
63:
64: public void setFontFamilies(String[] fontFamilies) {
65: this .fontFamilies = fontFamilies;
66: }
67:
68: public String[] getFontFamilies(String charSetName) {
69: return fontFamilies;
70: }
71:
72: public void setDefaultFontSizes(int[] defaultFontSizes) {
73: this .defaultFontSizes = defaultFontSizes;
74: }
75:
76: public int[] getDefaultSizes() {
77: return defaultFontSizes;
78: }
79:
80: public void setCharSets(String[] charSets) {
81: this .charSets = charSets;
82: }
83:
84: public String[] getCharSets() {
85: return charSets;
86: }
87:
88: public void setPreviewMessage(String previewMessage) {
89: this .previewMessage = previewMessage;
90: }
91:
92: public String getPreviewMessage(String charSetName) {
93: return previewMessage;
94: }
95:
96: }
|