usr/src/java/util/org/opensolaris/os/vp/util/swing/WrappingText.java
author Stephen Talley <stephen.talley@oracle.com>
Mon, 28 Mar 2011 10:53:34 -0400
changeset 685 767674b0a2fb
parent 647 ddbb04508ea4
permissions -rw-r--r--
18094 s/StringBuffer/StringBuilder/g
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
     1
/*
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
     2
 * CDDL HEADER START
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
     3
 *
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
     4
 * The contents of this file are subject to the terms of the
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
     5
 * Common Development and Distribution License (the "License").
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
     6
 * You may not use this file except in compliance with the License.
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
     7
 *
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
     8
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
     9
 * or http://www.opensolaris.org/os/licensing.
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    10
 * See the License for the specific language governing permissions
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    11
 * and limitations under the License.
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    12
 *
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    13
 * When distributing Covered Code, include this CDDL HEADER in each
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    14
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    15
 * If applicable, add the following below this CDDL HEADER, with the
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    16
 * fields enclosed by brackets "[]" replaced with your own identifying
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    17
 * information: Portions Copyright [yyyy] [name of copyright owner]
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    18
 *
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    19
 * CDDL HEADER END
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    20
 */
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    21
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    22
/*
647
ddbb04508ea4 17819 nit roundup
Stephen Talley <stephen.talley@oracle.com>
parents: 219
diff changeset
    23
 * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    24
 */
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    25
219
57841c113efe 6788 package names should share o.o.o.vp prefix
Stephen Talley <stephen.talley@sun.com>
parents: 76
diff changeset
    26
package org.opensolaris.os.vp.util.swing;
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    27
76
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    28
import java.awt.*;
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    29
import java.util.ArrayList;
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    30
import javax.swing.*;
219
57841c113efe 6788 package names should share o.o.o.vp prefix
Stephen Talley <stephen.talley@sun.com>
parents: 76
diff changeset
    31
import org.opensolaris.os.vp.util.misc.TextUtil;
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    32
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    33
/**
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    34
 * The {@code WrappingText} class displays multi-line text, wrapping words
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    35
 * at whitespace.
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    36
 */
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    37
@SuppressWarnings({"serial"})
76
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    38
public class WrappingText extends JComponent {
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    39
    //
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    40
    // Instance data
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    41
    //
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    42
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    43
    private String text;
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    44
    private int prefWidth = -1;
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    45
    private boolean prefWidthIsStatic;
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    46
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    47
    //
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    48
    // Constructors
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    49
    //
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    50
76
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    51
    public WrappingText(String text, int columns) {
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    52
	setText(text);
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    53
	setFont(UIManager.getFont("TextField.font"));
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    54
	setForeground(UIManager.getColor("Label.foreground"));
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    55
	setBackground(UIManager.getColor("Label.background"));
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    56
	setPreferredWidthInColumns(columns);
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    57
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    58
	setOpaque(false);
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    59
    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    60
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    61
    public WrappingText(String text) {
76
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    62
	this(text, -1);
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    63
    }
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    64
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    65
    public WrappingText() {
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    66
	this("");
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    67
    }
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    68
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    69
    public WrappingText(int columns) {
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    70
	this("", -1);
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    71
    }
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    72
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    73
    //
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    74
    // Component methods
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    75
    //
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    76
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    77
    @Override
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    78
    public void setBounds(int x, int y, int width, int height) {
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    79
	super.setBounds(x, y, width, height);
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    80
	setPreferredWidth(width);
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    81
    }
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    82
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    83
    @Override
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    84
    public void setBounds(Rectangle r) {
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    85
	super.setBounds(r);
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    86
	setPreferredWidth(r.width);
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    87
    }
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    88
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    89
    @Override
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    90
    public Dimension getMinimumSize() {
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    91
	return getPreferredSize();
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    92
    }
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    93
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    94
    @Override
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    95
    public Dimension getPreferredSize() {
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    96
	if (isPreferredSizeSet()) {
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    97
	    return super.getPreferredSize();
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    98
	}
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
    99
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   100
	Insets insets = getInsets();
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   101
	FontMetrics metrics = getFontMetrics(getFont());
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   102
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   103
	String[] lines = getLines(prefWidth < 0 ?
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   104
	    Integer.MAX_VALUE : prefWidth - insets.left - insets.right);
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   105
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   106
	// Get length of longest line
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   107
	int width = 0;
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   108
	for (int i = 0; i < lines.length; i++) {
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   109
	    width = Math.max(width, metrics.stringWidth(lines[i]));
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   110
	}
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   111
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   112
	width += insets.left + insets.right;
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   113
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   114
	// Set preferred width
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   115
	if (prefWidth < 0) {
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   116
	    prefWidth = width;
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   117
	}
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   118
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   119
	int height = lines.length * metrics.getHeight() + insets.top +
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   120
	    insets.bottom;
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   121
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   122
	return new Dimension(width, height);
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   123
    }
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   124
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   125
    //
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   126
    // JComponent methods
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   127
    //
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   128
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   129
    @Override
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   130
    protected void paintComponent(Graphics g) {
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   131
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   132
	// Turn on anti-aliasing if appropriate
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   133
	GUIUtil.setAARendering((Graphics2D)g);
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   134
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   135
	if (isOpaque()) {
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   136
	    g.setColor(getBackground());
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   137
	    g.fillRect(0, 0, getWidth(), getHeight());
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   138
	}
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   139
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   140
	Font font = getFont();
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   141
	FontMetrics metrics = getFontMetrics(font);
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   142
	int rowHeight = metrics.getHeight();
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   143
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   144
	Insets insets = getInsets();
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   145
	int y = insets.top + metrics.getAscent();
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   146
	String[] lines = getLines(getWidth() - insets.left - insets.right);
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   147
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   148
	g.setColor(getForeground());
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   149
	g.setFont(font);
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   150
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   151
	for (int i = 0; i < lines.length; i++) {
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   152
	    g.drawString(lines[i], insets.left, y);
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   153
	    y += rowHeight;
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   154
	}
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   155
    }
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   156
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   157
    //
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   158
    // WrappingText methods
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   159
    //
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   160
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   161
    /**
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   162
     * Gets the initial preferred width of this {@code WrappingText}.
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   163
     * Called by {@code getPreferredSize}.  The width here is determined by
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   164
     * the number of columns, the column width, and the insets of this
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   165
     * {@code Component}.
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   166
     *
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   167
     * @return	    the preferred width in pixels, or -1 if
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   168
     *		    {@code getPreferredSize} should determine it based on
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   169
     *		    the longest line in the text
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   170
     */
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   171
    public int getPreferredWidth() {
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   172
	return prefWidth;
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   173
    }
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   174
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   175
    public boolean getPreferredWidthIsStatic() {
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   176
	return prefWidthIsStatic;
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   177
    }
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   178
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   179
    /**
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   180
     * Sets the preferred width of this {@code WrappingText}, based on the given
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   181
     * number of columns.  This value ultimately determines the preferred
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   182
     * height.
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   183
     * <p>
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   184
     * If not specified, the initial preferred width is determined by the length
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   185
     * of the longest line of text.
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   186
     *
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   187
     * @param	    prefWidth
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   188
     *		    the preferred width, in pixels
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   189
     */
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   190
    public void setPreferredWidth(int prefWidth) {
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   191
	if (this.prefWidth != prefWidth && !prefWidthIsStatic) {
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   192
	    this.prefWidth = prefWidth;
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   193
	    revalidateLater();
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   194
	}
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   195
    }
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   196
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   197
    /**
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   198
     * Sets the preferred width of this {@code WrappingText}, based on the given
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   199
     * number of columns.  Column width is the width of the character 'm' in the
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   200
     * current font.
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   201
     *
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   202
     * @param	    columns
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   203
     *		    the preferred width, in columns
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   204
     */
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   205
    public void setPreferredWidthInColumns(int columns) {
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   206
	int prefWidth = 0;
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   207
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   208
	if (columns < 0) {
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   209
	    prefWidth = -1;
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   210
	} else {
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   211
	    int columnWidth = getFontMetrics(getFont()).charWidth('m');
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   212
	    Insets insets = getInsets();
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   213
	    prefWidth = columns * columnWidth + insets.left + insets.right;
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   214
	}
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   215
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   216
	setPreferredWidth(prefWidth);
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   217
    }
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   218
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   219
    public String getText() {
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   220
	return text;
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   221
    }
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   222
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   223
    public void setPreferredWidthIsStatic(boolean prefWidthIsStatic) {
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   224
	this.prefWidthIsStatic = prefWidthIsStatic;
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   225
    }
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   226
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   227
    public void setText(String text) {
647
ddbb04508ea4 17819 nit roundup
Stephen Talley <stephen.talley@oracle.com>
parents: 219
diff changeset
   228
	if (text == null) {
ddbb04508ea4 17819 nit roundup
Stephen Talley <stephen.talley@oracle.com>
parents: 219
diff changeset
   229
	    text = "";
ddbb04508ea4 17819 nit roundup
Stephen Talley <stephen.talley@oracle.com>
parents: 219
diff changeset
   230
	}
76
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   231
	this.text = text;
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   232
	revalidateLater();
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   233
	repaint();
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   234
    }
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   235
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   236
    //
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   237
    // Private methods
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   238
    //
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   239
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   240
    private String[] getLines(int width) {
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   241
	ArrayList<String> lines = new ArrayList<String>();
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   242
	FontMetrics metrics = getFontMetrics(getFont());
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   243
	String text = getText();
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   244
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   245
	// The current line
685
767674b0a2fb 18094 s/StringBuffer/StringBuilder/g
Stephen Talley <stephen.talley@oracle.com>
parents: 647
diff changeset
   246
	StringBuilder line = new StringBuilder();
76
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   247
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   248
	// Space that will be added to current line as long as it's not the last
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   249
	// token in the line
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   250
	String pendingSpace = "";
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   251
	int pendingSpaceWidth = 0;
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   252
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   253
	String[] groups;
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   254
	int x = 0;
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   255
	while ((groups = TextUtil.match(text,
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   256
	    "^((\\r?\\n)|(\\s+)|(\\S+))((?s).*)")) != null) {
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   257
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   258
	    String newline = groups[2];
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   259
	    String space = groups[3];
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   260
	    String word = groups[4];
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   261
	    text = groups[5];
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   262
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   263
	    if (newline != null) {
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   264
		lines.add(line.toString());
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   265
		line.setLength(0);
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   266
		pendingSpace = "";
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   267
		pendingSpaceWidth = 0;
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   268
		x = 0;
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   269
	    } else
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   270
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   271
	    if (space != null) {
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   272
		pendingSpace = space;
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   273
		pendingSpaceWidth = metrics.stringWidth(pendingSpace);
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   274
	    } else
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   275
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   276
	    if (word != null) {
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   277
		int wordWidth = metrics.stringWidth(word);
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   278
		int newX = x + pendingSpaceWidth + wordWidth;
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   279
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   280
		// Will the pending space and this word fit on this line?
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   281
		if (newX <= width) {
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   282
		    line.append(pendingSpace).append(word);
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   283
		    x = newX;
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   284
		} else {
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   285
		    if (line.length() != 0) {
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   286
			lines.add(line.toString());
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   287
			line.setLength(0);
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   288
		    }
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   289
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   290
		    // Does this word fit on a line of its own?
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   291
		    if (wordWidth <= width) {
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   292
			line.append(word);
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   293
			x = wordWidth;
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   294
		    } else {
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   295
			// Split word
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   296
			char[] chars = word.toCharArray();
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   297
			x = 0;
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   298
			for (int i = 0; i < chars.length; i++) {
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   299
			    char c = chars[i];
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   300
			    int charWidth = metrics.charWidth(c);
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   301
			    x += charWidth;
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   302
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   303
			    // Has this line exceeded the maximum width?
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   304
			    if (x > width && line.length() != 0) {
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   305
				lines.add(line.toString());
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   306
				line.setLength(0);
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   307
				x = charWidth;
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   308
			    }
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   309
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   310
			    line.append(c);
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   311
			}
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   312
		    }
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   313
		}
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   314
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   315
		pendingSpace = "";
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   316
		pendingSpaceWidth = 0;
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   317
	    }
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   318
	}
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   319
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   320
	if (line.length() > 0) {
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   321
	    lines.add(line.toString());
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   322
	}
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   323
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   324
	return lines.toArray(new String[lines.size()]);
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   325
    }
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   326
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   327
    private void revalidateLater() {
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   328
	SwingUtilities.invokeLater(
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   329
	    new Runnable() {
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   330
		@Override
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   331
		public void run() {
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   332
		    revalidate();
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   333
		}
af5a052967b0 3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents: 0
diff changeset
   334
	    });
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   335
    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   336
}