OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [classpath/] [javax/] [swing/] [text/] [html/] [HRuleView.java] - Blame information for rev 772

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 772 jeremybenn
/* HRuleView.java -- Horizontal dash in HTML documents.
2
   Copyright (C) 2006 Free Software Foundation, Inc.
3
 
4
This file is part of GNU Classpath.
5
 
6
GNU Classpath is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2, or (at your option)
9
any later version.
10
 
11
GNU Classpath is distributed in the hope that it will be useful, but
12
WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with GNU Classpath; see the file COPYING.  If not, write to the
18
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
02110-1301 USA.
20
 
21
Linking this library statically or dynamically with other modules is
22
making a combined work based on this library.  Thus, the terms and
23
conditions of the GNU General Public License cover the whole
24
combination.
25
 
26
As a special exception, the copyright holders of this library give you
27
permission to link this library with independent modules to produce an
28
executable, regardless of the license terms of these independent
29
modules, and to copy and distribute the resulting executable under
30
terms of your choice, provided that you also meet, for each linked
31
independent module, the terms and conditions of the license of that
32
module.  An independent module is a module which is not derived from
33
or based on this library.  If you modify this library, you may extend
34
this exception to your version of the library, but you are not
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version. */
37
 
38
 
39
package javax.swing.text.html;
40
 
41
import java.awt.Color;
42
import java.awt.Component;
43
import java.awt.Graphics;
44
import java.awt.Rectangle;
45
import java.awt.Shape;
46
 
47
import javax.swing.text.Element;
48
import javax.swing.text.View;
49
 
50
/**
51
 * Represents the long horizontal separating dash that can be inserted into the
52
 * HTML documents with HR tag.
53
 */
54
class HRuleView extends InlineView
55
{
56
  /**
57
   * The null view, indicating, that nothing should be painted ahead the
58
   * breaking point.
59
   */
60
  View nullView;
61
 
62
  /**
63
   * The height of the horizontal dash area.
64
   */
65
  static int HEIGHT = 4;
66
 
67
  /**
68
   * The imaginary invisible view that stays after end of line after the
69
   * breaking procedure. It occupies on character.
70
   */
71
  class Beginning extends NullView
72
  {
73
    /**
74
     * The break offset that becomes the views start offset.
75
     */
76
    int breakOffset;
77
 
78
    /**
79
     * Return the end offset that is always one char after the break offset.
80
     */
81
    public int getEndOffset()
82
    {
83
      return breakOffset + 1;
84
    }
85
 
86
    /**
87
     * Return the start offset that has been passed in a constructor.
88
     */
89
    public int getStartOffset()
90
    {
91
      return breakOffset;
92
    }
93
 
94
    /**
95
     * Create the new instance of this view.
96
     *
97
     * @param element the element (inherited from the HR view)
98
     * @param offset the position where the HR view has been broken
99
     */
100
    public Beginning(Element element, int offset)
101
    {
102
      super(element);
103
      breakOffset = offset;
104
    }
105
  }
106
 
107
  /**
108
   * Creates the new HR view.
109
   */
110
  public HRuleView(Element element)
111
  {
112
    super(element);
113
  }
114
 
115
  /**
116
   * Returns the ForcedBreakWeight for the vertical axis, indicating, the the
117
   * view must be broken to be displayed correctly. The horizontal dash is
118
   * not breakeable along the Y axis.
119
   */
120
  public int getBreakWeight(int axis, float pos, float len)
121
  {
122
    if (axis == X_AXIS && ((getEndOffset() - getStartOffset()) > 1))
123
      return ForcedBreakWeight;
124
    else
125
      return BadBreakWeight;
126
  }
127
 
128
  /**
129
   * Draws the double line, upped black and the lower light gray.
130
   */
131
  public void paint(Graphics g, Shape a)
132
  {
133
    Rectangle bounds = a.getBounds();
134
 
135
    int x = bounds.x;
136
    int y = bounds.y;
137
 
138
    int w = bounds.x + bounds.width;
139
 
140
    // We move "half pixel up" from the actual horizontal position -
141
    // this will be rounded to the closest actual int co-ordinate.
142
    int h = bounds.y + (int) Math.round(bounds.height * 0.5 - 0.5);
143
 
144
    g.setColor(Color.black);
145
    g.drawLine(x, y++, w, h++);
146
    g.setColor(Color.lightGray);
147
    g.drawLine(x, y, w, h);
148
  }
149
 
150
  /**
151
   * Break the view into this view and the invisible imaginary view that
152
   * stays on the end of line that is broken by HR dash. The view is broken
153
   * only if its length is longer than one (the two characters are expected
154
   * in the initial length).
155
   */
156
  public View breakView(int axis, int offset, float pos, float len)
157
  {
158
    if (getEndOffset() - getStartOffset() > 1)
159
      return new Beginning(getElement(), offset);
160
    else
161
      return this;
162
  }
163
 
164
  /**
165
   * Returns the width of the container for the horizontal axis and the
166
   * thickness of the dash area for the vertical axis.
167
   */
168
  public float getMaximumSpan(int axis)
169
  {
170
    if (axis == X_AXIS)
171
      {
172
        Component container = getContainer();
173
        if (container != null)
174
          return getContainer().getWidth();
175
        else
176
          return 640;
177
      }
178
    else
179
      return HEIGHT;
180
  }
181
 
182
  /**
183
   * Returns the same values as {@link #getMaximumSpan(int)}
184
   */
185
  public float getPreferredSpan(int axis)
186
  {
187
    return getMaximumSpan(axis);
188
  }
189
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.