KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > fonts > FontTriplet


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 /* $Id: FontTriplet.java 426576 2006-07-28 15:44:37Z jeremias $ */
19  
20 package org.apache.fop.fonts;
21
22 import java.io.Serializable JavaDoc;
23
24 /**
25  * FontTriplet contains information on name, style and weight of one font
26  */

27 public class FontTriplet implements Comparable JavaDoc, Serializable JavaDoc {
28     
29     /** serial version UID */
30     private static final long serialVersionUID = 1168991106658033508L;
31     
32     private String JavaDoc name;
33     private String JavaDoc style;
34     private int weight;
35     
36     //This is only a cache
37
private transient String JavaDoc key;
38     
39     /**
40      * Creates a new font triplet.
41      * @param name font name
42      * @param style font style (normal, italic etc.)
43      * @param weight font weight (100, 200, 300...800, 900)
44      */

45     public FontTriplet(String JavaDoc name, String JavaDoc style, int weight) {
46         this.name = name;
47         this.style = style;
48         this.weight = weight;
49     }
50
51     /** @return the font name */
52     public String JavaDoc getName() {
53         return name;
54     }
55
56     /** @return the font style */
57     public String JavaDoc getStyle() {
58         return style;
59     }
60     
61     /** @return the font weight */
62     public int getWeight() {
63         return weight;
64     }
65
66     private String JavaDoc getKey() {
67         if (this.key == null) {
68             //This caches the combined key
69
this.key = getName() + "," + getStyle() + "," + getWeight();
70         }
71         return this.key;
72     }
73     
74     /** @see java.lang.Comparable#compareTo(java.lang.Object) */
75     public int compareTo(Object JavaDoc o) {
76         return getKey().compareTo(((FontTriplet)o).getKey());
77     }
78
79     /** @see java.lang.Object#hashCode() */
80     public int hashCode() {
81         return toString().hashCode();
82     }
83
84     /** @see java.lang.Object#equals(java.lang.Object) */
85     public boolean equals(Object JavaDoc obj) {
86         if (obj == null) {
87             return false;
88         } else if (obj == this) {
89             return true;
90         } else {
91             if (obj instanceof FontTriplet) {
92                 FontTriplet other = (FontTriplet)obj;
93                 return (getName().equals(other.getName())
94                         && getStyle().equals(other.getStyle())
95                         && (getWeight() == other.getWeight()));
96             }
97         }
98         return false;
99     }
100
101     /** @see java.lang.Object#toString() */
102     public String JavaDoc toString() {
103         return getKey();
104     }
105
106 }
107
108
Popular Tags