home *** CD-ROM | disk | FTP | other *** search
- package symantec.itools.awt;
-
- import java.awt.Canvas;
- import java.awt.Component;
- import java.awt.Dimension;
- import java.awt.FontMetrics;
- import java.awt.Graphics;
-
- public strictfp class WrappingLabel extends Canvas implements AlignStyle {
- protected String text;
- protected int align;
- protected int baseline;
- // $FF: renamed from: fm java.awt.FontMetrics
- protected FontMetrics field_0;
-
- public WrappingLabel() {
- this("");
- }
-
- public WrappingLabel(String s) {
- this(s, 0);
- }
-
- public WrappingLabel(String s, int a) {
- this.setText(s);
- this.setAlignStyle(a);
- }
-
- public int getAlignStyle() {
- return this.align;
- }
-
- public void setAlignStyle(int a) {
- this.align = a;
- ((Component)this).invalidate();
- }
-
- public String getText() {
- return this.text;
- }
-
- public void setText(String s) {
- this.text = s;
- ((Component)this).repaint();
- }
-
- public String paramString() {
- return "";
- }
-
- public synchronized void reshape(int x, int y, int width, int height) {
- super.reshape(x, y, width, height);
- ((Component)this).invalidate();
- ((Component)this).validate();
- ((Component)this).repaint();
- }
-
- public synchronized void resize(int width, int height) {
- super.resize(width, height);
- ((Component)this).invalidate();
- ((Component)this).validate();
- ((Component)this).repaint();
- }
-
- public void paint(Graphics g) {
- if (this.text != null) {
- int fromIndex = 0;
- int pos = 0;
- this.field_0 = ((Component)this).getToolkit().getFontMetrics(((Component)this).getFont());
- this.baseline = this.field_0.getMaxAscent();
- Dimension d = ((Component)this).size();
- int boundx = d.width;
- int boundy = d.height;
- int x = 0;
-
- for(int y = 0; y + this.field_0.getHeight() <= boundy && fromIndex != -1; y += this.field_0.getHeight()) {
- while(fromIndex < this.text.length() && this.text.charAt(fromIndex) == ' ') {
- ++fromIndex;
- if (fromIndex >= this.text.length()) {
- break;
- }
- }
-
- pos = fromIndex;
- int bestpos = -1;
-
- String largestString;
- for(largestString = null; pos >= fromIndex; ++pos) {
- pos = this.text.indexOf(32, pos);
- String s;
- if (pos == -1) {
- s = this.text.substring(fromIndex);
- } else {
- s = this.text.substring(fromIndex, pos);
- }
-
- if (this.field_0.stringWidth(s) >= boundx) {
- break;
- }
-
- largestString = s;
- bestpos = pos;
- if (pos == -1) {
- break;
- }
- }
-
- if (largestString != null) {
- this.drawAlignedString(g, largestString, x, y, boundx);
- fromIndex = bestpos;
- } else {
- int totalWidth = 0;
- int oneCharWidth = 0;
-
- for(pos = fromIndex; pos < this.text.length(); ++pos) {
- oneCharWidth = this.field_0.charWidth(this.text.charAt(pos));
- if (totalWidth + oneCharWidth >= boundx) {
- break;
- }
-
- totalWidth += oneCharWidth;
- }
-
- this.drawAlignedString(g, this.text.substring(fromIndex, pos), x, y, boundx);
- fromIndex = pos;
- }
- }
-
- this.field_0 = null;
- }
-
- }
-
- protected void drawAlignedString(Graphics g, String s, int x, int y, int width) {
- int drawx = x;
- int drawy = y + this.baseline;
- if (this.align != 0) {
- int sw = this.field_0.stringWidth(s);
- if (this.align == 1) {
- drawx = x + (width - sw) / 2;
- } else if (this.align == 2) {
- drawx = x + width - sw;
- }
- }
-
- g.drawString(s, drawx, drawy);
- }
- }
-