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