001: /*
002: * Copyright Javelin Software, All rights reserved.
003: */
004:
005: package com.javelin.swinglets.border;
006:
007: import java.util.*;
008: import java.io.*;
009:
010: import com.javelin.swinglets.*;
011: import com.javelin.swinglets.plaf.*;
012:
013: /**
014: * SBorder is used to render borders around SComponent.
015: *
016: * @author Robin Sharp
017: */
018:
019: public abstract class SBorder {
020: /**
021: * Constructs a new SBorder.
022: */
023: public SBorder() {
024: }
025:
026: /**
027: * Returns the name of the L&F class that renders this border.
028: */
029: public Class getUIClass() {
030: return SBorder.class;
031: }
032:
033: /**
034: * Paint this component, in an empty border
035: */
036: public void paintHeader(Object out, SComponent component) {
037: //Ist time around get the look and feel
038: if (lookAndFeel == null) {
039: lookAndFeel = component.getLookAndFeel();
040: borderUI = lookAndFeel.getBorderUI(this );
041: }
042:
043: //In case the L&F changed update the l&f
044: if (lookAndFeel != component.getLookAndFeel()) {
045: lookAndFeel = component.getLookAndFeel();
046: borderUI = lookAndFeel.getBorderUI(this );
047: }
048:
049: if (borderUI != null) {
050: borderUI.updateBorderHeader(out, component);
051: } else {
052: throw new IllegalStateException("Unknown "
053: + getUIClass().getName() + " for "
054: + component.getLookAndFeel());
055: }
056: }
057:
058: /**
059: * Paint this component, in an empty border
060: */
061: public void paint(Object out, SComponent component) {
062: //Ist time around get the look and feel
063: if (lookAndFeel == null) {
064: lookAndFeel = component.getLookAndFeel();
065: borderUI = lookAndFeel.getBorderUI(this );
066: }
067:
068: //In case the L&F changed update the l&f
069: if (lookAndFeel != component.getLookAndFeel()) {
070: lookAndFeel = component.getLookAndFeel();
071: borderUI = lookAndFeel.getBorderUI(this );
072: }
073:
074: if (borderUI != null) {
075: borderUI.updateBorder(out, component);
076: } else {
077: throw new IllegalStateException("Unknown "
078: + getUIClass().getName() + " for "
079: + component.getLookAndFeel());
080: }
081: }
082:
083: /**
084: * Paint this component, in an empty border
085: */
086: public void paintFooter(Object out, SComponent component) {
087: if (borderUI != null) {
088: borderUI.updateBorderFooter(out, component);
089: } else {
090: throw new IllegalStateException("Unknown "
091: + getUIClass().getName() + " for "
092: + component.getLookAndFeel());
093: }
094: }
095:
096: /**
097: * Get the border to be painted. This return this border, unless the
098: * border is a copound border in which case it will return the nested
099: * border or null.
100: */
101: public SBorder getBorder() {
102: return this ;
103: }
104:
105: /**
106: * Move the next nested compound border. Return true if there is another
107: * nested border.
108: */
109: public boolean nextBorder() {
110: return false;
111: }
112:
113: /**
114: * Set a background on the border.
115: */
116: public SBorder setBackgroundIcon(SIcon background) {
117: this .background = background;
118: return this ;
119: }
120:
121: /**
122: * Get then background
123: */
124: public SIcon getBackgroundIcon() {
125: return background;
126: }
127:
128: // PRIVATE /////////////////////////////////////////////////////////////
129:
130: private SIcon background;
131:
132: //Cached
133: private SLookAndFeel lookAndFeel;
134: private SBorderUI borderUI;
135:
136: }
|