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 java.awt.GraphicsEnvironment;
20: import java.util.ArrayList;
21: import java.util.Arrays;
22: import java.util.List;
23:
24: /**
25: * An extension of the {@link com.l2fprod.common.swing.DefaultFontChooserModel}
26: * showing only Monospaced fonts.
27: */
28: public class MonospacedFontChooserModel extends DefaultFontChooserModel {
29:
30: public MonospacedFontChooserModel() {
31: super ();
32:
33: List monospaces = new ArrayList();
34: String[] fontFamilies = GraphicsEnvironment
35: .getLocalGraphicsEnvironment()
36: .getAvailableFontFamilyNames();
37: Arrays.sort(fontFamilies);
38: for (int i = 0, c = fontFamilies.length; i < c; i++) {
39: if (isMonospaced(fontFamilies[i])) {
40: monospaces.add(fontFamilies[i]);
41: }
42: }
43:
44: setFontFamilies((String[]) monospaces
45: .toArray(new String[monospaces.size()]));
46: }
47:
48: /**
49: * @param fontFamily
50: * @return true if <code>fontFamily</code> can be considered as Monospaced,
51: * i.e if it contains the strings Fixed, Monospaced, ProFont, Console
52: * or Typewriter
53: */
54: protected boolean isMonospaced(String fontFamily) {
55: String lower = fontFamily.toLowerCase();
56: return lower.indexOf("fixed") >= 0
57: || lower.indexOf("monospaced") >= 0
58: || lower.indexOf("profont") >= 0
59: || lower.indexOf("console") >= 0
60: || lower.indexOf("typewriter") >= 0;
61: }
62:
63: }
|