380 |
// FIXME: also not sure if these tables ought to be static (singletons), |
// FIXME: also not sure if these tables ought to be static (singletons), |
381 |
// shared across all StyleContexts. I think so, but it's not clear in |
// shared across all StyleContexts. I think so, but it's not clear in |
382 |
// docs. revert to non-shared if you think it matters. |
// docs. revert to non-shared if you think it matters. |
383 |
|
|
384 |
|
/** |
385 |
|
* The name of the default style. |
386 |
|
*/ |
387 |
public static final String DEFAULT_STYLE = "default"; |
public static final String DEFAULT_STYLE = "default"; |
388 |
|
|
389 |
|
/** |
390 |
|
* The default style for this style context. |
391 |
|
*/ |
392 |
|
NamedStyle defaultStyle = new NamedStyle(DEFAULT_STYLE, null); |
393 |
|
|
394 |
static Hashtable sharedAttributeSets = new Hashtable(); |
static Hashtable sharedAttributeSets = new Hashtable(); |
395 |
static Hashtable sharedFonts = new Hashtable(); |
static Hashtable sharedFonts = new Hashtable(); |
396 |
|
|
400 |
EventListenerList listenerList; |
EventListenerList listenerList; |
401 |
Hashtable styleTable; |
Hashtable styleTable; |
402 |
|
|
403 |
|
/** |
404 |
|
* Creates a new instance of the style context. Add the default style |
405 |
|
* to the style table. |
406 |
|
*/ |
407 |
public StyleContext() |
public StyleContext() |
408 |
{ |
{ |
409 |
listenerList = new EventListenerList(); |
listenerList = new EventListenerList(); |
410 |
styleTable = new Hashtable(); |
styleTable = new Hashtable(); |
411 |
|
styleTable.put(DEFAULT_STYLE, defaultStyle); |
412 |
} |
} |
413 |
|
|
414 |
protected SmallAttributeSet createSmallAttributeSet(AttributeSet a) |
protected SmallAttributeSet createSmallAttributeSet(AttributeSet a) |
449 |
styleTable.remove(name); |
styleTable.remove(name); |
450 |
} |
} |
451 |
|
|
452 |
|
/** |
453 |
|
* Get the style from the style table. If the passed name |
454 |
|
* matches {@link #DEFAULT_STYLE}, returns the default style. |
455 |
|
* Otherwise returns the previously defined style of |
456 |
|
* <code>null</code> if the style with the given name is not defined. |
457 |
|
* |
458 |
|
* @param name the name of the style. |
459 |
|
* |
460 |
|
* @return the style with the given name or null if no such defined. |
461 |
|
*/ |
462 |
public Style getStyle(String name) |
public Style getStyle(String name) |
463 |
{ |
{ |
464 |
return (Style) styleTable.get(name); |
return (Style) styleTable.get(name); |
465 |
} |
} |
466 |
|
|
467 |
|
/** |
468 |
|
* Get the names of the style. The returned enumeration always |
469 |
|
* contains at least one member, the default style. |
470 |
|
*/ |
471 |
public Enumeration getStyleNames() |
public Enumeration getStyleNames() |
472 |
{ |
{ |
473 |
return styleTable.keys(); |
return styleTable.keys(); |