1 /* |
|
2 * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. Sun designates this |
|
8 * particular file as subject to the "Classpath" exception as provided |
|
9 * by Sun in the LICENSE file that accompanied this code. |
|
10 * |
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
|
15 * accompanied this code). |
|
16 * |
|
17 * You should have received a copy of the GNU General Public License version |
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 * |
|
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 * CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 * have any questions. |
|
24 */ |
|
25 package org.jdesktop.synthdesigner.synthmodel; |
|
26 |
|
27 import java.awt.Font; |
|
28 import org.jdesktop.swingx.designer.font.Typeface; |
|
29 import java.util.Arrays; |
|
30 import java.util.List; |
|
31 import java.util.ArrayList; |
|
32 import javax.swing.UIDefaults; |
|
33 |
|
34 /** |
|
35 * Represents a single font entry in the UIDefaults table. Each UIFont takes a |
|
36 * list of Typefaces. These typefaces are listed by order of preference. Thus, |
|
37 * when putting a font into UIDefaults, the code can check whether each font |
|
38 * exists, and when it finds the first font that does, insert it. |
|
39 * |
|
40 * @author Richard Bair |
|
41 * @author Jasper Potts |
|
42 */ |
|
43 public class UIFont extends UIDefault<List<Typeface>> implements Cloneable { |
|
44 |
|
45 private void updateUIDefaults() { |
|
46 if (getUiDefaults() != null) { |
|
47 for (Typeface t : getFonts()) { |
|
48 if (t.isFontSupported()) { |
|
49 getUiDefaults().put(getName(), t.getFont()); |
|
50 return; |
|
51 } |
|
52 } |
|
53 } |
|
54 |
|
55 //TODO must not have found any. Default to the Default platform font |
|
56 getUiDefaults().put(getName(), new Font("Arial", Font.PLAIN, 12)); |
|
57 } |
|
58 |
|
59 public UIFont() { |
|
60 setValue(new ArrayList<Typeface>()); |
|
61 } |
|
62 |
|
63 public UIFont(String id, List<Typeface> values, UIDefaults defaults) { |
|
64 super(id, values, defaults); |
|
65 updateUIDefaults(); |
|
66 } |
|
67 |
|
68 public UIFont(String id, Font font, UIDefaults modelDefaults) { |
|
69 this(id, Arrays.asList(new Typeface(font, modelDefaults)), modelDefaults); |
|
70 } |
|
71 |
|
72 public List<Typeface> getFonts() { |
|
73 return super.getValue(); |
|
74 } |
|
75 |
|
76 private void setFonts(List<Typeface> values) { |
|
77 super.setValue(values); |
|
78 } |
|
79 } |
|