001: /*
002: * (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
003: *
004: * The program is provided "as is" without any warranty express or
005: * implied, including the warranty of non-infringement and the implied
006: * warranties of merchantibility and fitness for a particular purpose.
007: * IBM will not be liable for any damages suffered by you as a result
008: * of using the Program. In no event will IBM be liable for any
009: * special, indirect or consequential damages or lost profits even if
010: * IBM has been advised of the possibility of their occurrence. IBM
011: * will not be liable for any third party claims against you.
012: */
013: package com.ibm.richtext.swingui;
014:
015: import java.awt.Color;
016: import java.awt.Dimension;
017: import java.awt.Graphics;
018:
019: import javax.swing.JComponent;
020:
021: import com.ibm.richtext.textpanel.MTextPanel;
022: import com.ibm.richtext.styledtext.MTabRuler;
023:
024: import com.ibm.richtext.uiimpl.TabRulerImpl;
025: import com.ibm.richtext.awtui.MTabRulerComponent;
026:
027: /**
028: * JTabRuler is an implementation of MTabRulerComponent in a Swing component.
029: */
030: public final class JTabRuler extends JComponent implements
031: MTabRulerComponent {
032:
033: static final String COPYRIGHT = "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
034: private TabRulerImpl fImpl;
035:
036: /**
037: * Create a new TabRuler.
038: * @param baseline the y-coordinate of the ruler's baseline
039: * @param origin the x-coordinate in this Component where
040: * the left margin appears
041: * @param textPanel the MTextPanel to listen to. This TabRuler
042: * will reflect the MTextPanel's paragraph styles, and update
043: * the paragraph styles when manipulated.
044: */
045: public JTabRuler(int baseline, int origin, MTextPanel textPanel) {
046:
047: fImpl = new TabRulerImpl(baseline, origin, textPanel, this );
048: }
049:
050: /**
051: * Listen to the given MTextPanel and reflect its changes,
052: * and update its paragraph styles when TabRuler is
053: * manipulated.
054: * @param textPanel the MTextPanel to listen to
055: */
056: public void listenToTextPanel(MTextPanel textPanel) {
057:
058: fImpl.listenToTextPanel(textPanel);
059: }
060:
061: /**
062: * Return the background color of this TabRuler.
063: * @return the background color of this TabRuler
064: */
065: public Color getBackColor() {
066:
067: return fImpl.getBackColor();
068: }
069:
070: /**
071: * Set the background color of this TabRuler.
072: * @param backColor the new background color of this TabRuler
073: */
074: public void setBackColor(Color backColor) {
075:
076: fImpl.setBackColor(backColor);
077: }
078:
079: /**
080: * Return the MTabRuler represented by this TabRuler.
081: * @return the MTabRuler represented by this TabRuler
082: */
083: public MTabRuler getRuler() {
084:
085: return fImpl.getRuler();
086: }
087:
088: /**
089: * Return the leading margin of this TabRuler.
090: * @return the leading margin of this TabRuler
091: */
092: public int getLeadingMargin() {
093:
094: return fImpl.getLeadingMargin();
095: }
096:
097: /**
098: * Return the first line indent of this TabRuler.
099: * @return the first line indent of this TabRuler
100: */
101: public int getFirstLineIndent() {
102:
103: return fImpl.getFirstLineIndent();
104: }
105:
106: /**
107: * Return the trailing margin of this TabRuler.
108: * @return the trailing margin of this TabRuler
109: */
110: public final int getTrailingMargin() {
111:
112: return fImpl.getTrailingMargin();
113: }
114:
115: // The following are Component methods which need to be delegated to
116: // the implementation:
117:
118: public void paint(Graphics g) {
119:
120: fImpl.paint(g);
121: }
122:
123: public Dimension getPreferredSize() {
124:
125: return fImpl.getPreferredSize();
126: }
127:
128: public Dimension getMinimumSize() {
129:
130: return fImpl.getMinimumSize();
131: }
132: }
|