01: /*
02: * (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
03: *
04: * The program is provided "as is" without any warranty express or
05: * implied, including the warranty of non-infringement and the implied
06: * warranties of merchantibility and fitness for a particular purpose.
07: * IBM will not be liable for any damages suffered by you as a result
08: * of using the Program. In no event will IBM be liable for any
09: * special, indirect or consequential damages or lost profits even if
10: * IBM has been advised of the possibility of their occurrence. IBM
11: * will not be liable for any third party claims against you.
12: */
13: // Requires Java2
14: package com.ibm.richtext.uiimpl;
15:
16: import java.awt.GraphicsEnvironment;
17: import java.util.Collections;
18: import java.util.Iterator;
19: import java.util.Vector;
20:
21: final class FontList {
22:
23: static final String COPYRIGHT = "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
24:
25: private static final String[] stripThese = { ".bold",
26: ".bolditalic", ".italic" };
27:
28: public static String[] getFontList() {
29:
30: String[] names = GraphicsEnvironment
31: .getLocalGraphicsEnvironment()
32: .getAvailableFontFamilyNames();
33: Vector v = new Vector(names.length);
34: for (int i = 0; i < names.length; i++) {
35: v.addElement(names[i]);
36: }
37:
38: Collections.sort(v);
39:
40: String last = "";
41:
42: Iterator iter = v.listIterator();
43: while (iter.hasNext()) {
44: String current = (String) iter.next();
45: testSuffixes: for (int i = 0; i < stripThese.length; i++) {
46: if (current.endsWith(stripThese[i])) {
47: int baseLen = current.length()
48: - stripThese[i].length();
49: String base = current.substring(0, baseLen);
50: if (base.equalsIgnoreCase(last)) {
51: iter.remove();
52: current = last;
53: break testSuffixes;
54: }
55: }
56: }
57: last = current;
58: }
59:
60: String[] result = new String[v.size()];
61: v.copyInto(result);
62: return result;
63: }
64: }
|