jdk/src/share/classes/javax/swing/text/html/HRuleView.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 1306 036c9e2dfd78
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1997-2002 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package javax.swing.text.html;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.swing.event.DocumentEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.swing.text.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.lang.Integer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * A view implementation to display an html horizontal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * rule.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * @author  Timothy Prinzing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * @author  Sara Swanson
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
class HRuleView extends View  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
     * Creates a new view that represents an <hr> element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     * @param elem the element to create a view for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    public HRuleView(Element elem) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        super(elem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        setPropertiesFromAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * Update any cached values that come from attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    protected void setPropertiesFromAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        StyleSheet sheet = ((HTMLDocument)getDocument()).getStyleSheet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        AttributeSet eAttr = getElement().getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        attr = sheet.getViewAttributes(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        alignment = StyleConstants.ALIGN_CENTER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        size = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        noshade = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        widthValue = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        if (attr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            // getAlignment() returns ALIGN_LEFT by default, and HR should
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            // use ALIGN_CENTER by default, so we check if the alignment
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            // attribute is actually defined
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            if (attr.getAttribute(StyleConstants.Alignment) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            alignment = StyleConstants.getAlignment(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            noshade = (String)eAttr.getAttribute(HTML.Attribute.NOSHADE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            Object value = eAttr.getAttribute(HTML.Attribute.SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            if (value != null && (value instanceof String))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                size = Integer.parseInt((String)value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            value = attr.getAttribute(CSS.Attribute.WIDTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            if (value != null && (value instanceof CSS.LengthValue)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                widthValue = (CSS.LengthValue)value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            topMargin = getLength(CSS.Attribute.MARGIN_TOP, attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            bottomMargin = getLength(CSS.Attribute.MARGIN_BOTTOM, attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            leftMargin = getLength(CSS.Attribute.MARGIN_LEFT, attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            rightMargin = getLength(CSS.Attribute.MARGIN_RIGHT, attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            topMargin = bottomMargin = leftMargin = rightMargin = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        size = Math.max(2, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    // This will be removed and centralized at some point, need to unify this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    // and avoid private classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    private float getLength(CSS.Attribute key, AttributeSet a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        CSS.LengthValue lv = (CSS.LengthValue) a.getAttribute(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        float len = (lv != null) ? lv.getValue() : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        return len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    // --- View methods ---------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * Paints the view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @param g the graphics context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @param a the allocation region for the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * @see View#paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    public void paint(Graphics g, Shape a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        Rectangle alloc = (a instanceof Rectangle) ? (Rectangle)a :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                          a.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        int x = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        int y = alloc.y + SPACE_ABOVE + (int)topMargin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        int width = alloc.width - (int)(leftMargin + rightMargin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        if (widthValue != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            width = (int)widthValue.getValue((float)width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        int height = alloc.height - (SPACE_ABOVE + SPACE_BELOW +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                                     (int)topMargin + (int)bottomMargin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        if (size > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                height = size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        // Align the rule horizontally.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        switch (alignment) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        case StyleConstants.ALIGN_CENTER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            x = alloc.x + (alloc.width / 2) - (width / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        case StyleConstants.ALIGN_RIGHT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            x = alloc.x + alloc.width - width - (int)rightMargin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        case StyleConstants.ALIGN_LEFT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            x = alloc.x + (int)leftMargin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        // Paint either a shaded rule or a solid line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        if (noshade != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            g.setColor(Color.black);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            g.fillRect(x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            Color bg = getContainer().getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            Color bottom, top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            if (bg == null || bg.equals(Color.white)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                top = Color.darkGray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                bottom = Color.lightGray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                top = Color.darkGray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                bottom = Color.white;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            g.setColor(bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            g.drawLine(x + width - 1, y, x + width - 1, y + height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            g.drawLine(x, y + height - 1, x + width - 1, y + height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            g.setColor(top);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            g.drawLine(x, y, x + width - 1, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            g.drawLine(x, y, x, y + height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * Calculates the desired shape of the rule... this is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * basically the preferred size of the border.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * @param axis may be either X_AXIS or Y_AXIS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * @return the desired span
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * @see View#getPreferredSpan
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    public float getPreferredSpan(int axis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        switch (axis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        case View.X_AXIS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        case View.Y_AXIS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            if (size > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                return size + SPACE_ABOVE + SPACE_BELOW + topMargin +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                    bottomMargin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                if (noshade != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                    return 2 + SPACE_ABOVE + SPACE_BELOW + topMargin +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                        bottomMargin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                    return SPACE_ABOVE + SPACE_BELOW + topMargin +bottomMargin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            throw new IllegalArgumentException("Invalid axis: " + axis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * Gets the resize weight for the axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * The rule is: rigid vertically and flexible horizontally.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * @param axis may be either X_AXIS or Y_AXIS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * @return the weight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    public int getResizeWeight(int axis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        if (axis == View.X_AXIS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        } else if (axis == View.Y_AXIS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * Determines how attractive a break opportunity in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * this view is.  This is implemented to request a forced break.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * @param axis may be either View.X_AXIS or View.Y_AXIS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * @param pos the potential location of the start of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     *   broken view (greater than or equal to zero).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     *   This may be useful for calculating tab
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *   positions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * @param len specifies the relative length from <em>pos</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     *   where a potential break is desired. The value must be greater
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     *   than or equal to zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * @return the weight, which should be a value between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     *   ForcedBreakWeight and BadBreakWeight.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    public int getBreakWeight(int axis, float pos, float len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        if (axis == X_AXIS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            return ForcedBreakWeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        return BadBreakWeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    public View breakView(int axis, int offset, float pos, float len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * Provides a mapping from the document model coordinate space
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * to the coordinate space of the view mapped to it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * @param pos the position to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * @param a the allocated region to render into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * @return the bounding box of the given position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @exception BadLocationException  if the given position does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * represent a valid location in the associated document
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * @see View#modelToView
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    public Shape modelToView(int pos, Shape a, Position.Bias b) throws BadLocationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        int p0 = getStartOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        int p1 = getEndOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        if ((pos >= p0) && (pos <= p1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            Rectangle r = a.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            if (pos == p1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                r.x += r.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            r.width = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            return r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * Provides a mapping from the view coordinate space to the logical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * coordinate space of the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * @param x the X coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @param y the Y coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * @param a the allocated region to render into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * @return the location within the model that best represents the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     *  given point of view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * @see View#viewToModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    public int viewToModel(float x, float y, Shape a, Position.Bias[] bias) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        Rectangle alloc = (Rectangle) a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        if (x < alloc.x + (alloc.width / 2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            bias[0] = Position.Bias.Forward;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            return getStartOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        bias[0] = Position.Bias.Backward;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        return getEndOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * Fetches the attributes to use when rendering.  This is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * implemented to multiplex the attributes specified in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * model with a StyleSheet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    public AttributeSet getAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        return attr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    public void changedUpdate(DocumentEvent changes, Shape a, ViewFactory f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        super.changedUpdate(changes, a, f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        int pos = changes.getOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        if (pos <= getStartOffset() && (pos + changes.getLength()) >=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            getEndOffset()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            setPropertiesFromAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    // --- variables ------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    private float topMargin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    private float bottomMargin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    private float leftMargin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    private float rightMargin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    private int alignment = StyleConstants.ALIGN_CENTER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    private String noshade = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    private int size = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    private CSS.LengthValue widthValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    private static final int SPACE_ABOVE = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    private static final int SPACE_BELOW = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    /** View Attributes. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    private AttributeSet attr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
}