001: package ob.text;
002:
003: /*
004: * Stingray Software Objective Blend
005: * Copyright (C) 1997 Stingray Software, Inc.
006: * All Rights Reserved
007: *
008: * This source code is only intended as a supplement to
009: * the Stingray Objective Blend product. See the Objective
010: * Blend html help documentation for detailed information regarding
011: * using OB classes.
012: *
013: * Author : Jason W. Purdy
014: * Description : OBLabel.java - implements the Text class
015: *
016: */
017:
018: /**
019: OBLabel
020:
021: implements the text control. OBLabel is the first of three in a
022: heirarchy and serves as the lowest common denominator. This class
023: is not editable or scrollable, but merely a label.
024: */
025:
026: import java.awt.*;
027: import com.sun.portal.log.common.PortalLogger;
028: import java.util.*;
029: import java.awt.event.*;
030:
031: public class OBLabel extends Panel implements IScrollable {
032: public final static int STANDARD = 1;
033: public final static int LEFT = 1;
034: public final static int CENTER = 3;
035: public final static int RIGHT = 2;
036: public final static int TOP = 1;
037: public final static int BOTTOM = 2;
038:
039: public final static int NONE = 0;
040: public final static int INSET = 1;
041: public final static int RAISED = 2;
042: public final static int NORMAL = 3;
043:
044: protected Vector m_vParagraphs;
045: protected Color borderColor = Color.black;
046: protected Insets m_inTextInsets;
047:
048: Font defaultfont = new Font("Dialog", Font.PLAIN, 12);
049:
050: int m_nHAlign = LEFT;
051: int m_nVAlign = TOP;
052: int m_nBorderStyle = NONE;
053: int y_offset = 0;
054: int prevYOffset = 0;
055: int m_nWidthOffset = 0;
056: boolean m_bUnderline = false;
057: boolean m_bStrikeOut = false;
058: boolean m_bAutoWrap = true;
059:
060: transient Image offscreen;
061: protected boolean m_bDoubleBuffering = true;
062:
063: protected boolean m_bLockUpdate = false;
064:
065: /**
066: * Null constructor that just calls the other contructor with a
067: * blank String.
068: */
069: public OBLabel() {
070: this ("");
071: }
072:
073: /**
074: * Preferred constructor for the OBLabel. This sets up the Paragraph
075: * Vector and other relevant data.
076: * @param s - text of the label
077: */
078: public OBLabel(String s) {
079: super ();
080:
081: m_vParagraphs = new Vector();
082: super .setFont(defaultfont);
083: super .setBackground(Color.white);
084: super .setForeground(Color.black);
085: m_inTextInsets = new Insets(3, 3, 3, 3);
086:
087: // equiv. to setText, but can't call due to MaskEdit's override
088: if (s.equals("")) {
089: Paragraph p = new Paragraph(this , s);
090: p.setFont(getFont());
091: p.setFontMetrics(getFontMetrics(getFont()));
092: p.setBackground(getBackground());
093: p.setForeground(getForeground());
094: p.setWidth(getSize().width);
095: p.setInsets(m_inTextInsets);
096: p.setAutoWrap(isAutoWrap());
097: m_vParagraphs.addElement(p);
098: } else {
099: StringTokenizer st = new StringTokenizer(s, "\n", false);
100: while (st.hasMoreTokens()) {
101: String s2 = st.nextToken();
102: Paragraph p = new Paragraph(this , s2);
103: p.setFont(getFont());
104: p.setFontMetrics(getFontMetrics(getFont()));
105: p.setBackground(getBackground());
106: p.setForeground(getForeground());
107: p.setWidth(getSize().width);
108: p.setInsets(m_inTextInsets);
109: p.setAutoWrap(isAutoWrap());
110: m_vParagraphs.addElement(p);
111: }
112: }
113: }
114:
115: /**
116: * Overriden method to insure the widths of the Paragraph
117: * data type are set correctly.
118: */
119: public void addNotify() {
120: super .addNotify();
121: for (int i = 0; i < m_vParagraphs.size(); i++) {
122: Paragraph p = (Paragraph) m_vParagraphs.elementAt(i);
123: p.setWidth(getSize().width
124: - (m_inTextInsets.left + m_inTextInsets.right)
125: - m_nWidthOffset);
126: p.addNotify();
127: }
128: }
129:
130: /**
131: * Returns whether or not the text control will autowrap whenever
132: * the text breaches the width of the control
133: * @return autowrap flag
134: */
135: public boolean getAutoWrap() {
136: return m_bAutoWrap;
137: }
138:
139: /**
140: * This returns whether or not a border will be drawn around the
141: * text control.
142: * @return border boolean flag
143: */
144: public boolean getBorder() {
145: return (m_nBorderStyle != NONE);
146: }
147:
148: /**
149: * This returns the color of the normal style border drawn around
150: * the text control.
151: * @return color of the border
152: */
153: public Color getBorderColor() {
154: return borderColor;
155: }
156:
157: /**
158: * This returns the style of the border drawn around the
159: * text control.
160: * @return (OBLabel.NONE||OBLabel.INSET||OBLabel.NORMAL||OBLabel.RAISED)
161: */
162: public int getBorderStyle() {
163: return m_nBorderStyle;
164: }
165:
166: /**
167: * This returns the horizontal alignment setting of the
168: * text control.
169: * @return (OBLabel.LEFT||OBLabel.CENTER||OBLabel.RIGHT)
170: */
171: public int getHAlign() {
172: return m_nHAlign;
173: }
174:
175: /**
176: * This returns the insets of the text control, which represents
177: * the pixel space between the border and the drawn text.
178: * @return insets of the drawn text
179: */
180: public Insets getInsets() {
181: return m_inTextInsets;
182: }
183:
184: /**
185: * This method returns the minimum size of the control, overridden
186: * for layout managers.
187: * @return dimension of the minimum size
188: */
189: public Dimension getMinimumSize() {
190: return new Dimension(80, 20);
191: }
192:
193: /**
194: * This returns the preferred size of the text control, based
195: * on the encapsulated text. This method is overridden for
196: * layout managers.
197: * @return dimension of the preferred size
198: */
199: public Dimension getPreferredSize() {
200: // keep a static width (ie: 80) & calc. the height
201: Dimension d = new Dimension(80, 0);
202: int h = 0;
203: for (int i = 0; i < m_vParagraphs.size(); i++)
204: h += ((Paragraph) m_vParagraphs.elementAt(i)).getYSpan();
205:
206: int nBoardWidth = 2;
207: if (m_nBorderStyle == NONE)
208: nBoardWidth = 0;
209: else if (m_nBorderStyle == NORMAL)
210: nBoardWidth = 1;
211: d.height = m_inTextInsets.top + m_inTextInsets.bottom + h + 2
212: * nBoardWidth;
213: return d;
214: }
215:
216: /**
217: * This returns whether or not the border drawn around the
218: * text control is raised.
219: * @return border is raised
220: */
221: public boolean getRaised() {
222: return (m_nBorderStyle == RAISED);
223: }
224:
225: /**
226: * This returns the text of the control.
227: * @return the text of the control
228: */
229: public String getText() {
230: if (m_vParagraphs.size() == 0)
231: return null;
232: String str = new String();
233: for (int i = 0; i < m_vParagraphs.size(); i++)
234: str += ((Paragraph) m_vParagraphs.elementAt(i)).getText()
235: + "\n";
236: str = str.substring(0, (str.length() - 1));
237: return str;
238: }
239:
240: /**
241: * This returns the horizontal indentation of the text. (the text
242: * insets' left property)
243: * @return horizontal indentation of the text
244: */
245: public int getTextHIndent() {
246: return m_inTextInsets.left;
247: }
248:
249: /**
250: * This returns the vertical indentation of the text control.
251: * Same thing as the Insets' top property.
252: * @return text's vertical indentation
253: */
254: public int getTextVIndent() {
255: return m_inTextInsets.top;
256: }
257:
258: /**
259: * This returns the vertical alignment of the text control.
260: * @return (OBLabel.TOP||OBLabel.CENTER||OBLabel.BOTTOM)
261: */
262: public int getVAlign() {
263: return m_nVAlign;
264: }
265:
266: /**
267: * This method returns the width offset.
268: * This is used by subclasses of OBLabel, which may add components
269: * which narrow the space left to draw the text.
270: * @return the width offset
271: */
272: protected int getWidthOffset() {
273: return m_nWidthOffset;
274: }
275:
276: /**
277: * This returns whether or not the control is in autowrap mode
278: * or not.
279: * @return autowrap behavior flag
280: */
281: protected boolean isAutoWrap() {
282: return m_bAutoWrap;
283: }
284:
285: /**
286: * This returns whether or not the control is locked from
287: * updating.
288: * @return whether or not the control is locked
289: */
290: public boolean isLockUpdate() {
291: return m_bLockUpdate;
292: }
293:
294: /**
295: * This returns whether or not the text is drawn along with a
296: * line through it.
297: * @return strikeout boolean flag
298: */
299: public boolean isStrikeOut() {
300: return m_bStrikeOut;
301: }
302:
303: /**
304: * This returns whether or not the text is drawn along with
305: * a line underneath.
306: * @return underline boolean flag
307: */
308: public boolean isUnderLine() {
309: return m_bUnderline;
310: }
311:
312: public void paint(Graphics g) {
313: if (!isShowing())
314: return;
315: if (m_bDoubleBuffering && validateImage()) {
316: Dimension d = this .getSize();
317: Rectangle r = g.getClipBounds();
318:
319: Graphics og = offscreen.getGraphics();
320:
321: if (r != null)
322: og.clipRect(r.x, r.y, r.width, r.height);
323: og.setFont(g.getFont());
324: og.setColor(getBackground());
325: og.fillRect(0, 0, d.width, d.height);
326: og.setColor(g.getColor());
327: draw(og);
328:
329: g.drawImage(offscreen, 0, 0, this );
330: og.dispose();
331: } else {
332: if (g != null && g.getClipBounds() != null)
333: draw(g);
334: }
335: }
336:
337: /**
338: * This is where it all happens. :)
339: * This is overridden to render each Paragraph in the text control and take
340: * other things into account, such as vertical/horizontal alignment, text
341: * insets, and scrolling behavior from subclasses.
342: * @param g - Graphics object to draw upon
343: */
344: public void draw(Graphics g) {
345: if (g == null || isLockUpdate())
346: return;
347:
348: Dimension d = getSize();
349: printBorder(g);
350: int nBoardWidth = 2;
351: if (m_nBorderStyle == NONE)
352: nBoardWidth = 0;
353: else if (m_nBorderStyle == NORMAL)
354: nBoardWidth = 1;
355:
356: g.clipRect(m_inTextInsets.left + nBoardWidth,
357: m_inTextInsets.top + nBoardWidth, d.width
358: - m_inTextInsets.left - m_inTextInsets.right
359: - 2 * nBoardWidth + 1, d.height
360: - m_inTextInsets.top - m_inTextInsets.bottom
361: - 2 * nBoardWidth + 1);
362:
363: // need to manipulate these later for alignment purposes
364: int y = m_inTextInsets.top;
365: if (y_offset == 0 && m_nVAlign != TOP) {
366: int h1 = d.height;
367: int h2 = 0;
368: for (int i = 0; i < m_vParagraphs.size(); i++)
369: h2 += ((Paragraph) m_vParagraphs.elementAt(i))
370: .getYSpan();
371: if (m_nVAlign == CENTER) {
372: y = ((h1 / 2) - (h2 / 2));
373: } else if (m_nVAlign == BOTTOM) {
374: y = (h1 - h2) - m_inTextInsets.bottom;
375: }
376: }
377: y -= y_offset;
378: int x = m_inTextInsets.left;
379: g.setColor(getBackground());
380: g.fillRect(2, 2, d.width - 4, d.height - 4);
381: g.setColor(getForeground());
382: for (int i = 0; i < m_vParagraphs.size(); i++) {
383: Paragraph p = (Paragraph) m_vParagraphs.elementAt(i);
384: p.render(g, x, y, m_bUnderline, m_bStrikeOut);
385: y += p.getYSpan();
386: }
387: }
388:
389: private void paintBorder(Graphics g, int x, int y, int w, int h,
390: boolean raised) {
391: // paint the border.
392: g.setColor(SystemColor.controlLtHighlight);
393: if (raised) {
394: g.drawLine(x, y, x + w, y);
395: g.drawLine(x, y, x, y + h);
396: } else {
397: g.drawLine(x + 1, y + h - 1, x + w - 1, y + h - 1);
398: g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 1);
399: }
400:
401: g.setColor(SystemColor.controlHighlight);
402: if (raised) {
403: //g.drawLine(x, y, x+w-1, y);
404: //g.drawLine(x, y, x, y+h-1);
405: } else {
406: g.drawLine(x + 1, y + h - 2, x + w - 2, y + h - 2);
407: g.drawLine(x + w - 2, y + 1, x + w - 2, y + h - 2);
408: }
409:
410: g.setColor(SystemColor.controlShadow);
411: if (raised) {
412: g.drawLine(x + 1, y + h - 1, x + w - 1, y + h - 1);
413: g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 1);
414: } else {
415: g.drawLine(x, y, x + w - 1, y);
416: g.drawLine(x, y, x, y + h - 1);
417: }
418:
419: g.setColor(SystemColor.controlDkShadow);
420: if (raised) {
421: g.drawLine(x, y + h, x + w, y + h);
422: g.drawLine(x + w, y, x + w, y + h);
423: } else {
424: g.drawLine(x + 1, y + 1, x + w - 2, y + 1);
425: g.drawLine(x + 1, y + 1, x + 1, y + h - 2);
426: }
427: }
428:
429: /**
430: * This takes the Graphics object and draws the border around the text
431: * control, given the style setting.
432: * @param g - Graphics object to draw upon
433: */
434: protected void printBorder(Graphics g) {
435: Dimension d = super .getSize();
436:
437: if (m_nBorderStyle == NONE) {
438: g.setColor(getBackground());
439: g.drawRect(0, 0, d.width - 1, d.height - 1);
440: } else if (m_nBorderStyle == NORMAL) {
441: g.setColor(borderColor);
442: g.drawRect(0, 0, d.width - 1, d.height - 1);
443: } else if (m_nBorderStyle == RAISED || m_nBorderStyle == INSET)
444: paintBorder(g, 0, 0, d.width, d.height,
445: m_nBorderStyle == RAISED);
446: }
447:
448: /**
449: * This sets whether or not the text control will wrap the text
450: * whenever the text breaches the width of the control.
451: * @param bAutoWrap - boolean flag
452: */
453: public void setAutoWrap(boolean bAutoWrap) {
454: m_bAutoWrap = bAutoWrap;
455: for (int i = 0; i < m_vParagraphs.size(); i++)
456: ((Paragraph) m_vParagraphs.elementAt(i))
457: .setAutoWrap(bAutoWrap);
458: }
459:
460: /**
461: * This sets the background of the text control. It is overridden to specify
462: * to the Paragraph's the new color.
463: * @param c - new background color
464: */
465: public void setBackground(Color c) {
466: super .setBackground(c);
467: for (int i = 0; i < m_vParagraphs.size(); i++)
468: ((Paragraph) m_vParagraphs.elementAt(i)).setBackground(c);
469: repaint();
470: }
471:
472: /**
473: * This acts as a shortcut method to turn off the border, given
474: * a false argument. It is better to use setBorderStyle, instead.
475: * @param b - whether or not to draw the border
476: * @see #setBorderStyle
477: */
478: public void setBorder(boolean b) {
479: if (!b) {
480: m_nBorderStyle = NONE;
481: repaint();
482: }
483: }
484:
485: /**
486: * This sets the color of the border drawn around a NORMAL
487: * border.
488: * @param c - color of the NORMAL border
489: */
490: public void setBorderColor(Color c) {
491: borderColor = c;
492: repaint();
493: }
494:
495: /**
496: * This sets the style of the border to be drawn around the text
497: * control.
498: * @param style - one of these: (OBLabel.NONE||OBLabel.INSET||OBLabel.RAISED||OBLabel.NORMAL)
499: */
500: public void setBorderStyle(int style) {
501: if (style != NONE && style != INSET && style != RAISED
502: && style != NORMAL)
503: return;
504: m_nBorderStyle = style;
505: repaint();
506: }
507:
508: /**
509: * This sets the size of the text control. It is overridden to ensure that
510: * the Paragraph's get the new width setting.
511: * @param x - new x coordinate
512: * @param y - new y coordinate
513: * @param w - new width
514: * @param h - new height
515: */
516: public void setBounds(int x, int y, int w, int h) {
517: super .setBounds(x, y, w, h);
518:
519: for (int i = 0; i < m_vParagraphs.size(); i++) {
520: ((Paragraph) m_vParagraphs.elementAt(i)).setWidth(w
521: - (m_inTextInsets.left + m_inTextInsets.right)
522: - m_nWidthOffset);
523: }
524: repaint();
525: }
526:
527: /**
528: * setFont sets the font for a particular paragraph
529: * @param p - the index of the paragraph
530: * @param f - the font
531: */
532: public void setFont(int p, Font f) {
533: Paragraph pg = (Paragraph) m_vParagraphs.elementAt(p);
534: if (pg != null) {
535: pg.setFont(f);
536: pg.setFontMetrics(getFontMetrics(f));
537: }
538: repaint();
539: }
540:
541: /**
542: * This sets the font of the text control. This is overridden to
543: * ensure that the Paragraph's gets the new Font and FontMetrics
544: * settings.
545: * @param f - new font
546: */
547: public void setFont(Font f) {
548: super .setFont(f);
549: for (int i = 0; i < m_vParagraphs.size(); i++) {
550: Paragraph p = (Paragraph) m_vParagraphs.elementAt(i);
551: p.setFont(f);
552: p.setFontMetrics(getFontMetrics(f));
553: }
554: repaint();
555: }
556:
557: /**
558: * This sets the foreground of the text control, which is the same
559: * as the color of the text drawn. This is overridden to ensure that
560: * the Paragraph's get the new color setting.
561: * @param c - new foreground color
562: */
563: public void setForeground(Color c) {
564: super .setForeground(c);
565: for (int i = 0; i < m_vParagraphs.size(); i++)
566: ((Paragraph) m_vParagraphs.elementAt(i)).setForeground(c);
567: repaint();
568: }
569:
570: /**
571: * This sets the horizontal alignment of the text control.
572: * One of these: (OBLabel.LEFT||OBLabel.CENTER||OBLabel.RIGHT)
573: * @param align - new horizontal alignment
574: */
575: public void setHAlign(int align) {
576: if (align != LEFT && align != CENTER && align != RIGHT)
577: return;
578: m_nHAlign = align;
579: for (int i = 0; i < m_vParagraphs.size(); i++) {
580: Paragraph p = (Paragraph) m_vParagraphs.elementAt(i);
581: p.setHAlign(align);
582: }
583: repaint();
584: }
585:
586: /**
587: * This sets the insets of the text control. Overridden to ensure
588: * that the Paragraph's get the new Insets settings.
589: * @param in - new Insets of the text control
590: */
591: public void setInsets(Insets in) {
592: m_inTextInsets = in;
593: for (int i = 0; i < m_vParagraphs.size(); i++)
594: ((Paragraph) m_vParagraphs.elementAt(i)).setInsets(in);
595: repaint();
596: }
597:
598: /**
599: * This method is used to lock the update from repainting the control
600: * while you manipulate the control as you like.
601: * @param bLock - boolean to lock or unlock the control
602: */
603: public void setLockUpdate(boolean bLock) {
604: m_bLockUpdate = bLock;
605: }
606:
607: /**
608: * This sets the border style to OBLabel.RAISED. It is better
609: * to use the setBorderStyle method, instead.
610: * @param b - if true, it will raise the border
611: * @see #setBorderStyle
612: */
613: public void setRaised(boolean b) {
614: if (b) {
615: m_nBorderStyle = RAISED;
616: repaint();
617: }
618: }
619:
620: /**
621: * This sets the size of the control. This is overriden to make
622: * sure the Paragraph's get the new width setting.
623: * @param w - new width
624: * @param h - new height
625: */
626: public void setSize(int w, int h) {
627: super .setSize(w, h);
628: for (int i = 0; i < m_vParagraphs.size(); i++) {
629: Paragraph p = (Paragraph) m_vParagraphs.elementAt(i);
630: p
631: .setWidth((w
632: - (m_inTextInsets.left + m_inTextInsets.right) - m_nWidthOffset));
633: }
634:
635: repaint();
636: }
637:
638: /**
639: * This sets whether or not to strikeout the text.
640: * @param b - new strikeout behavior flag
641: */
642: public void setStrikeOut(boolean b) {
643: m_bStrikeOut = b;
644: repaint();
645: }
646:
647: /**
648: * This sets the text of the control.
649: * @param t - new text of the control
650: */
651: public void setText(String t) {
652: setText(t, true);
653: }
654:
655: /**
656: * This sets the text of the control and if the boolean flag is set,
657: * it then repaints.
658: * @param t - new text
659: * @param repaint - whether or not to repaint
660: */
661: public void setText(String t, boolean repaint) {
662: if (t == null)
663: t = "";
664: if (m_vParagraphs.size() > 0)
665: m_vParagraphs.removeAllElements();
666: if (t.equals("")) {
667: Paragraph p = new Paragraph(this , t);
668: p.setFont(getFont());
669: p.setFontMetrics(getFontMetrics(getFont()));
670: p.setBackground(getBackground());
671: p.setForeground(getForeground());
672: p.setWidth(getSize().width - m_nWidthOffset);
673: p.setInsets(m_inTextInsets);
674: p.setHAlign(getHAlign());
675: p.setAutoWrap(isAutoWrap());
676: m_vParagraphs.addElement(p);
677: } else {
678: StringTokenizer st = new StringTokenizer(t, "\n", false);
679: while (st.hasMoreTokens()) {
680: String s = st.nextToken();
681: Paragraph p = new Paragraph(this , s);
682: p.setFont(getFont());
683: p.setFontMetrics(getFontMetrics(getFont()));
684: p.setBackground(getBackground());
685: p.setForeground(getForeground());
686: p.setWidth(getSize().width - m_nWidthOffset);
687: p.setInsets(m_inTextInsets);
688: p.setHAlign(getHAlign());
689: p.setAutoWrap(isAutoWrap());
690: m_vParagraphs.addElement(p);
691: }
692: }
693: if (repaint)
694: repaint();
695: }
696:
697: /**
698: * This sets the text's horizontal indentation through the Insets
699: * left property.
700: * @param n - new horizontal indentation
701: * @see #setInsets
702: */
703: public void setTextHIndent(int n) {
704: m_inTextInsets.left = n;
705: repaint();
706: }
707:
708: /**
709: * This sets the vertical indentation of the text control through
710: * the Insets' top property.
711: * @param n - new vertical indentation
712: * @see #setInsets
713: */
714: public void setTextVIndent(int n) {
715: m_inTextInsets.top = n;
716: }
717:
718: /**
719: * This sets whether or not to draw an line underneath the text in
720: * the text control.
721: * @param b - underline behavior flag
722: */
723: public void setUnderLine(boolean b) {
724: m_bUnderline = b;
725: }
726:
727: /**
728: * This sets the vertical alignment of the text control from one
729: * of these: (OBLabel.TOP||OBLabel.CENTER||OBLabel.BOTTOM)
730: * @param align - new vertical alignment
731: */
732: public void setVAlign(int align) {
733: if (align != TOP && align != CENTER && align != BOTTOM)
734: return;
735: m_nVAlign = align;
736: repaint();
737: }
738:
739: /**
740: * This is a method to set a width offset, for subclasses whenever they add
741: * a component within the text control that would take up some width. For
742: * example, the SmartEdit control with the spinner buttons.
743: * @param w - new width offset
744: */
745: protected void setWidthOffset(int w) {
746: m_nWidthOffset = w;
747: int wd = getSize().width - m_inTextInsets.left
748: - m_inTextInsets.right;
749: for (int i = 0; i < m_vParagraphs.size(); i++)
750: ((Paragraph) m_vParagraphs.elementAt(i)).setWidth(wd - w);
751: }
752:
753: // The derived class will use this method for horizontal scrolling.
754: public void setXOffset(int n) {
755: //System.out.println("oblabel setXOffset "+n);
756: }
757:
758: /**
759: * validateImage is called every time when the paint method is called.
760: * this method checks if the off screen image is valid.
761: */
762: protected boolean validateImage() {
763:
764: try {
765: Dimension d = this .getSize();
766:
767: if (offscreen == null
768: || offscreen.getWidth(this ) != d.width
769: || offscreen.getHeight(this ) != d.height) {
770: if (d.width > 0 && d.height > 0)
771: offscreen = this .createImage(d.width, d.height);
772: else
773: return false;
774: }
775:
776: return true;
777: } catch (Exception ex) {
778: return false;
779: }
780: }
781:
782: public void update(Graphics g, int x, int y, int w, int h) {
783: g.clipRect(x, y, w, h);
784: paint(g);
785: }
786:
787: public void update() {
788: Dimension d = this .getSize();
789: int nHeight = d.height;
790: int nWidth = d.width;
791:
792: Graphics g = getGraphics();
793: if (g != null) {
794: update(g, 0, 0, nWidth, nHeight);
795: g.dispose();
796: }
797: }
798:
799: public void repaint() {
800: Dimension d = this .getSize();
801: int nHeight = d.height;
802: int nWidth = d.width;
803:
804: Graphics g = getGraphics();
805: if (g != null) {
806: if (!m_bDoubleBuffering) {
807: g.setColor(getBackground());
808: g.fillRect(0, 0, d.width, d.height);
809: }
810: update(g, 0, 0, nWidth, nHeight);
811: g.dispose();
812: }
813: }
814:
815: public void update(Graphics g) {
816: if (m_bDoubleBuffering) {
817: paint(g);
818: } else {
819: super.update(g);
820: }
821: }
822: }
|