This adds support for the HTML attribute nowrap and the CSS attribute
whitespace (which are basically the same thing).

2006-11-09  Roman Kennke  <[EMAIL PROTECTED]>

        * javax/swing/text/html/InlineView.java
        (nowrap): New field.
        (getBreakWeight): Add support for nowrap.
        (setPropertiesFromAttributes): Fetch the nowrap setting.

/Roman

Index: javax/swing/text/html/InlineView.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/html/InlineView.java,v
retrieving revision 1.5
diff -u -1 -5 -r1.5 InlineView.java
--- javax/swing/text/html/InlineView.java	5 Nov 2006 20:23:12 -0000	1.5
+++ javax/swing/text/html/InlineView.java	9 Nov 2006 16:34:54 -0000
@@ -64,30 +64,35 @@
 {
 
   /**
    * The attributes used by this view.
    */
   private AttributeSet attributes;
 
   /**
    * The span of the longest word in this view.
    *
    * @see #getLongestWord()
    */
   private float longestWord;
 
   /**
+   * Indicates if we may wrap or not.
+   */
+  private boolean nowrap;
+
+  /**
    * Creates a new <code>InlineView</code> that renders the specified element.
    *
    * @param element the element for this view
    */
   public InlineView(Element element)
   {
     super(element);
   }
 
   /**
    * Receives notification that something was inserted into the document in
    * a location that this view is responsible for.
    *
    * @param e the document event
    * @param a the current allocation of this view
@@ -143,32 +148,37 @@
    * @return the attributes that are used for rendering
    */
   public AttributeSet getAttributes()
   {
     if (attributes == null)
       {
         StyleSheet ss = getStyleSheet();
         attributes = ss.getViewAttributes(this);
       }
     return attributes;
   }
 
   
   public int getBreakWeight(int axis, float pos, float len)
   {
-    // FIXME: Implement this.
-    return super.getBreakWeight(axis, pos, len);
+    int weight;
+    if (nowrap) { if (getText(getStartOffset(), getEndOffset()).toString().contains("Web"))
+      System.err.println("Web NOWRAP");
+      weight = BadBreakWeight;}
+    else
+      weight = super.getBreakWeight(axis, pos, len);
+    return weight;
   }
 
   public View breakView(int axis, int offset, float pos, float len)
   {
     // FIXME: Implement this.
     return super.breakView(axis, offset, pos, len);
   }
 
   /**
    * Loads the character style properties from the stylesheet.
    */
   protected void setPropertiesFromAttributes()
   {
     super.setPropertiesFromAttributes();
     AttributeSet atts = getAttributes();
@@ -189,31 +199,36 @@
     // Check for vertical alignment (subscript/superscript).
     o = atts.getAttribute(CSS.Attribute.VERTICAL_ALIGN);
 
     // Subscript.
     b = false;
     if (o != null && o.toString().contains("sub"))
       b = true;
     setSubscript(b);
 
     // Superscript.
     b = false;
     if (o != null && o.toString().contains("sup"))
       b = true;
     setSuperscript(b);
 
-    // TODO: Handle white-space: nowrap property.
+    // Fetch nowrap setting.
+    o = atts.getAttribute(CSS.Attribute.WHITE_SPACE);
+    if (o != null && o.equals("nowrap"))
+      nowrap = true;
+    else
+      nowrap = false;
   }
 
   /**
    * Returns the stylesheet used by this view. This returns the stylesheet
    * of the <code>HTMLDocument</code> that is rendered by this view.
    *
    * @return the stylesheet used by this view
    */
   protected StyleSheet getStyleSheet()
   {
     Document doc = getDocument();
     StyleSheet styleSheet = null;
     if (doc instanceof HTMLDocument)
       styleSheet = ((HTMLDocument) doc).getStyleSheet();
     return styleSheet;

Reply via email to