0N/A/*
2362N/A * Copyright (c) 1997, 2003, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/Apackage javax.swing.text.html;
0N/A
0N/Aimport java.util.Enumeration;
0N/Aimport java.awt.*;
0N/Aimport javax.swing.*;
0N/Aimport javax.swing.border.*;
0N/Aimport javax.swing.event.*;
0N/Aimport javax.swing.text.*;
0N/A
0N/A/**
0N/A * A view implementation to display an unwrapped
0N/A * preformatted line.<p>
0N/A * This subclasses ParagraphView, but this really only contains one
0N/A * Row of text.
0N/A *
0N/A * @author Timothy Prinzing
0N/A */
0N/Aclass LineView extends ParagraphView {
0N/A /** Last place painted at. */
0N/A int tabBase;
0N/A
0N/A /**
0N/A * Creates a LineView object.
0N/A *
0N/A * @param elem the element to wrap in a view
0N/A */
0N/A public LineView(Element elem) {
0N/A super(elem);
0N/A }
0N/A
0N/A /**
0N/A * Preformatted lines are not suppressed if they
0N/A * have only whitespace, so they are always visible.
0N/A */
0N/A public boolean isVisible() {
0N/A return true;
0N/A }
0N/A
0N/A /**
0N/A * Determines the minimum span for this view along an
0N/A * axis. The preformatted line should refuse to be
0N/A * sized less than the preferred size.
0N/A *
0N/A * @param axis may be either <code>View.X_AXIS</code> or
0N/A * <code>View.Y_AXIS</code>
0N/A * @return the minimum span the view can be rendered into
0N/A * @see View#getPreferredSpan
0N/A */
0N/A public float getMinimumSpan(int axis) {
0N/A return getPreferredSpan(axis);
0N/A }
0N/A
0N/A /**
0N/A * Gets the resize weight for the specified axis.
0N/A *
0N/A * @param axis may be either X_AXIS or Y_AXIS
0N/A * @return the weight
0N/A */
0N/A public int getResizeWeight(int axis) {
0N/A switch (axis) {
0N/A case View.X_AXIS:
0N/A return 1;
0N/A case View.Y_AXIS:
0N/A return 0;
0N/A default:
0N/A throw new IllegalArgumentException("Invalid axis: " + axis);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Gets the alignment for an axis.
0N/A *
0N/A * @param axis may be either X_AXIS or Y_AXIS
0N/A * @return the alignment
0N/A */
0N/A public float getAlignment(int axis) {
0N/A if (axis == View.X_AXIS) {
0N/A return 0;
0N/A }
0N/A return super.getAlignment(axis);
0N/A }
0N/A
0N/A /**
0N/A * Lays out the children. If the layout span has changed,
0N/A * the rows are rebuilt. The superclass functionality
0N/A * is called after checking and possibly rebuilding the
0N/A * rows. If the height has changed, the
0N/A * <code>preferenceChanged</code> method is called
0N/A * on the parent since the vertical preference is
0N/A * rigid.
0N/A *
0N/A * @param width the width to lay out against >= 0. This is
0N/A * the width inside of the inset area.
0N/A * @param height the height to lay out against >= 0 (not used
0N/A * by paragraph, but used by the superclass). This
0N/A * is the height inside of the inset area.
0N/A */
0N/A protected void layout(int width, int height) {
0N/A super.layout(Integer.MAX_VALUE - 1, height);
0N/A }
0N/A
0N/A /**
0N/A * Returns the next tab stop position given a reference position.
0N/A * This view implements the tab coordinate system, and calls
0N/A * <code>getTabbedSpan</code> on the logical children in the process
0N/A * of layout to determine the desired span of the children. The
0N/A * logical children can delegate their tab expansion upward to
0N/A * the paragraph which knows how to expand tabs.
0N/A * <code>LabelView</code> is an example of a view that delegates
0N/A * its tab expansion needs upward to the paragraph.
0N/A * <p>
0N/A * This is implemented to try and locate a <code>TabSet</code>
0N/A * in the paragraph element's attribute set. If one can be
0N/A * found, its settings will be used, otherwise a default expansion
0N/A * will be provided. The base location for for tab expansion
0N/A * is the left inset from the paragraphs most recent allocation
0N/A * (which is what the layout of the children is based upon).
0N/A *
0N/A * @param x the X reference position
0N/A * @param tabOffset the position within the text stream
0N/A * that the tab occurred at >= 0.
0N/A * @return the trailing end of the tab expansion >= 0
0N/A * @see TabSet
0N/A * @see TabStop
0N/A * @see LabelView
0N/A */
0N/A public float nextTabStop(float x, int tabOffset) {
0N/A // If the text isn't left justified, offset by 10 pixels!
0N/A if (getTabSet() == null &&
0N/A StyleConstants.getAlignment(getAttributes()) ==
0N/A StyleConstants.ALIGN_LEFT) {
0N/A return getPreTab(x, tabOffset);
0N/A }
0N/A return super.nextTabStop(x, tabOffset);
0N/A }
0N/A
0N/A /**
0N/A * Returns the location for the tab.
0N/A */
0N/A protected float getPreTab(float x, int tabOffset) {
0N/A Document d = getDocument();
0N/A View v = getViewAtPosition(tabOffset, null);
0N/A if ((d instanceof StyledDocument) && v != null) {
0N/A // Assume f is fixed point.
0N/A Font f = ((StyledDocument)d).getFont(v.getAttributes());
0N/A Container c = getContainer();
0N/A FontMetrics fm = (c != null) ? c.getFontMetrics(f) :
0N/A Toolkit.getDefaultToolkit().getFontMetrics(f);
0N/A int width = getCharactersPerTab() * fm.charWidth('W');
0N/A int tb = (int)getTabBase();
0N/A return (float)((((int)x - tb) / width + 1) * width + tb);
0N/A }
0N/A return 10.0f + x;
0N/A }
0N/A
0N/A /**
0N/A * @return number of characters per tab, 8.
0N/A */
0N/A protected int getCharactersPerTab() {
0N/A return 8;
0N/A }
0N/A}