39
40 /**
41 * A pool of styles and their associated resources. This class determines
42 * the lifetime of a group of resources by being a container that holds
43 * caches for various resources such as font and color that get reused
44 * by the various style definitions. This can be shared by multiple
45 * documents if desired to maximize the sharing of related resources.
46 * <p>
47 * This class also provides efficient support for small sets of attributes
48 * and compresses them by sharing across uses and taking advantage of
49 * their immutable nature. Since many styles are replicated, the potential
50 * for sharing is significant, and copies can be extremely cheap.
51 * Larger sets reduce the possibility of sharing, and therefore revert
52 * automatically to a less space-efficient implementation.
53 * <p>
54 * <strong>Warning:</strong>
55 * Serialized objects of this class will not be compatible with
56 * future Swing releases. The current serialization support is
57 * appropriate for short term storage or RMI between applications running
58 * the same version of Swing. As of 1.4, support for long term storage
59 * of all JavaBeans™
60 * has been added to the <code>java.beans</code> package.
61 * Please see {@link java.beans.XMLEncoder}.
62 *
63 * @author Timothy Prinzing
64 */
65 @SuppressWarnings("serial") // Same-version serialization only
66 public class StyleContext implements Serializable, AbstractDocument.AttributeContext {
67
68 /**
69 * Returns default AttributeContext shared by all documents that
70 * don't bother to define/supply their own context.
71 *
72 * @return the context
73 */
74 public static final StyleContext getDefaultStyleContext() {
75 if (defaultContext == null) {
76 defaultContext = new StyleContext();
77 }
78 return defaultContext;
79 }
1259 return (size == font.size) && (style == font.style) && (family == font.family);
1260 }
1261 return false;
1262 }
1263
1264 }
1265
1266 /**
1267 * A collection of attributes, typically used to represent
1268 * character and paragraph styles. This is an implementation
1269 * of MutableAttributeSet that can be observed if desired.
1270 * These styles will take advantage of immutability while
1271 * the sets are small enough, and may be substantially more
1272 * efficient than something like SimpleAttributeSet.
1273 * <p>
1274 * <strong>Warning:</strong>
1275 * Serialized objects of this class will not be compatible with
1276 * future Swing releases. The current serialization support is
1277 * appropriate for short term storage or RMI between applications running
1278 * the same version of Swing. As of 1.4, support for long term storage
1279 * of all JavaBeans™
1280 * has been added to the <code>java.beans</code> package.
1281 * Please see {@link java.beans.XMLEncoder}.
1282 */
1283 @SuppressWarnings("serial") // Same-version serialization only
1284 public class NamedStyle implements Style, Serializable {
1285
1286 /**
1287 * Creates a new named style.
1288 *
1289 * @param name the style name, null for unnamed
1290 * @param parent the parent style, null if none
1291 * @since 1.4
1292 */
1293 public NamedStyle(String name, Style parent) {
1294 attributes = getEmptySet();
1295 if (name != null) {
1296 setName(name);
1297 }
1298 if (parent != null) {
1299 setResolveParent(parent);
|
39
40 /**
41 * A pool of styles and their associated resources. This class determines
42 * the lifetime of a group of resources by being a container that holds
43 * caches for various resources such as font and color that get reused
44 * by the various style definitions. This can be shared by multiple
45 * documents if desired to maximize the sharing of related resources.
46 * <p>
47 * This class also provides efficient support for small sets of attributes
48 * and compresses them by sharing across uses and taking advantage of
49 * their immutable nature. Since many styles are replicated, the potential
50 * for sharing is significant, and copies can be extremely cheap.
51 * Larger sets reduce the possibility of sharing, and therefore revert
52 * automatically to a less space-efficient implementation.
53 * <p>
54 * <strong>Warning:</strong>
55 * Serialized objects of this class will not be compatible with
56 * future Swing releases. The current serialization support is
57 * appropriate for short term storage or RMI between applications running
58 * the same version of Swing. As of 1.4, support for long term storage
59 * of all JavaBeans
60 * has been added to the <code>java.beans</code> package.
61 * Please see {@link java.beans.XMLEncoder}.
62 *
63 * @author Timothy Prinzing
64 */
65 @SuppressWarnings("serial") // Same-version serialization only
66 public class StyleContext implements Serializable, AbstractDocument.AttributeContext {
67
68 /**
69 * Returns default AttributeContext shared by all documents that
70 * don't bother to define/supply their own context.
71 *
72 * @return the context
73 */
74 public static final StyleContext getDefaultStyleContext() {
75 if (defaultContext == null) {
76 defaultContext = new StyleContext();
77 }
78 return defaultContext;
79 }
1259 return (size == font.size) && (style == font.style) && (family == font.family);
1260 }
1261 return false;
1262 }
1263
1264 }
1265
1266 /**
1267 * A collection of attributes, typically used to represent
1268 * character and paragraph styles. This is an implementation
1269 * of MutableAttributeSet that can be observed if desired.
1270 * These styles will take advantage of immutability while
1271 * the sets are small enough, and may be substantially more
1272 * efficient than something like SimpleAttributeSet.
1273 * <p>
1274 * <strong>Warning:</strong>
1275 * Serialized objects of this class will not be compatible with
1276 * future Swing releases. The current serialization support is
1277 * appropriate for short term storage or RMI between applications running
1278 * the same version of Swing. As of 1.4, support for long term storage
1279 * of all JavaBeans
1280 * has been added to the <code>java.beans</code> package.
1281 * Please see {@link java.beans.XMLEncoder}.
1282 */
1283 @SuppressWarnings("serial") // Same-version serialization only
1284 public class NamedStyle implements Style, Serializable {
1285
1286 /**
1287 * Creates a new named style.
1288 *
1289 * @param name the style name, null for unnamed
1290 * @param parent the parent style, null if none
1291 * @since 1.4
1292 */
1293 public NamedStyle(String name, Style parent) {
1294 attributes = getEmptySet();
1295 if (name != null) {
1296 setName(name);
1297 }
1298 if (parent != null) {
1299 setResolveParent(parent);
|