org.eclipse.ui.forms_3.5.101.v20111011-1919

blic void putColor(String key, Color color)
  {
    if (color == null) {
      colors.remove(key);
    } else {
      colors.put(key, color);
    }
  }
  
  public Color getColor(String key)
  {
    return (Color)colors.get(key);
  }
  
  public boolean hasColor(String key)
  {
    return colors.containsKey(key);
  }
  
  public void addDragSupport(int operations, Transfer[] transferTypes, DragSourceListener listener)
  {
    titleRegion.addDragSupport(operations, transferTypes, listener);
  }
  
  public void addDropSupport(int operations, Transfer[] transferTypes, DropTargetListener listener)
  {
    titleRegion.addDropSupport(operations, transferTypes, listener);
  }
  
  public IMessageToolTipManager getMessageToolTipManager()
  {
    return messageToolTipManager;
  }
  
  public void setMessageToolTipManager(IMessageToolTipManager messageToolTipManager)
  {
    this.messageToolTipManager = messageToolTipManager;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.ui.internal.forms.widgets.FormHeading
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.ui.internal.forms.widgets;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;

abstract class FormImages$AbstractImageDescriptor
  extends ImageDescriptor
{
  RGB[] fRGBs;
  int fLength;
  final FormImages this$0;
  
  FormImages$AbstractImageDescriptor(FormImages arg1, Color[] colors, int length)
  {
    this$0 = ???;
    fRGBs = new RGB[colors.length];
    for (int i = 0; i < colors.length; i++)
    {
      Color color = colors[i];
      fRGBs[i] = (color == null ? null : color.getRGB());
    }
    fLength = length;
  }
  
  public boolean equals(Object obj)
  {
    if ((obj instanceof AbstractImageDescriptor))
    {
      AbstractImageDescriptor id = (AbstractImageDescriptor)obj;
      if (fRGBs.length == fRGBs.length)
      {
        boolean result = fLength == fLength;
        for (int i = 0; (i < fRGBs.length) && (result); i++) {
          result = (result) && (fRGBs[i].equals(fRGBs[i]));
        }
        return result;
      }
    }
    return false;
  }
  
  public int hashCode()
  {
    int hash = 0;
    for (int i = 0; i < fRGBs.length; i++) {
      hash = hash * 7 + fRGBs[i].hashCode();
    }
    hash = hash * 7 + fLength;
    return hash;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.ui.internal.forms.widgets.FormImages.AbstractImageDescriptor
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.ui.internal.forms.widgets;

import java.util.Arrays;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Device;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.RGB;

class FormImages$ComplexImageDescriptor
  extends FormImages.AbstractImageDescriptor
{
  RGB fBgRGB;
  boolean fVertical;
  int[] fPercents;
  final FormImages this$0;
  
  public FormImages$ComplexImageDescriptor(FormImages paramFormImages, Color[] colors, int length, int[] percents, boolean vertical, Color bg)
  {
    super(paramFormImages, colors, length);this$0 = paramFormImages;
    fBgRGB = (bg == null ? null : bg.getRGB());
    fVertical = vertical;
    fPercents = percents;
  }
  
  public boolean equals(Object obj)
  {
    if ((obj instanceof ComplexImageDescriptor))
    {
      ComplexImageDescriptor id = (ComplexImageDescriptor)obj;
      if ((super.equals(obj)) && 
        (fVertical == fVertical) && (Arrays.equals(fPercents, fPercents)))
      {
        if (((fBgRGB == null) && (fBgRGB == null)) || (
          (fBgRGB != null) && (fBgRGB.equals(fBgRGB)))) {
          return true;
        }
        int sum = 0;
        for (int i = 0; i < fPercents.length; i++) {
          sum += fPercents[i];
        }
        if (sum >= 100) {
          return true;
        }
      }
    }
    return false;
  }
  
  public int hashCode()
  {
    int hash = super.hashCode();
    hash = hash * 7 + new Boolean(fVertical).hashCode();
    for (int i = 0; i < fPercents.length; i++) {
      hash = hash * 7 + new Integer(fPercents[i]).hashCode();
    }
    return hash;
  }
  
  public ImageData getImageData()
  {
    return null;
  }
  
  public Image createImage(boolean returnMissingImageOnError, Device device)
  {
    int width = fVertical ? 1 : fLength;
    int height = fVertical ? fLength : 1;
    Image gradient = new Image(device, Math.max(width, 1), 
      Math.max(height, 1));
    GC gc = new GC(gradient);
    Color[] colors = new Color[fRGBs.length];
    for (int i = 0; i < colors.length; i++) {
      colors[i] = new Color(device, fRGBs[i]);
    }
    Color bg = fBgRGB == null ? null : new Color(device, fBgRGB);
    drawTextGradient(gc, width, height, colors, fPercents, fVertical, bg);
    gc.dispose();
    for (int i = 0; i < colors.length; i++) {
      colors[i].dispose();
    }
    if (bg != null) {
      bg.dispose();
    }
    return gradient;
  }
  
  private void drawTextGradient(GC gc, int width, int height, Color[] colors, int[] percents, boolean vertical, Color bg)
  {
    Color oldBackground = gc.getBackground();
    if (colors.length == 1)
    {
      if (colors[0] != null) {
        gc.setBackground(colors[0]);
      }
      gc.fillRectangle(0, 0, width, height);
    }
    else
    {
      Color oldForeground = gc.getForeground();
      Color lastColor = colors[0];
      if (lastColor == null) {
        lastColor = oldBackground;
      }
      int pos = 0;
      for (int i = 0; i < percents.length; i++)
      {
        gc.setForeground(lastColor);
        lastColor = colors[(i + 1)];
        if (lastColor == null) {
          lastColor = oldBackground;
        }
        gc.setBackground(lastColor);
        if (vertical)
        {
          int gradientHeight = percents[i] * height / 100;
          
          gc.fillGradientRectangle(0, pos, width, gradientHeight, 
            true);
          pos += gradientHeight;
        }
        else
        {
          int gradientWidth = percents[i] * width / 100;
          
          gc.fillGradientRectangle(pos, 0, gradientWidth, height, 
            false);
          pos += gradientWidth;
        }
      }
      if ((vertical) && (pos < height))
      {
        if (bg != null) {
          gc.setBackground(bg);
        }
        gc.fillRectangle(0, pos, width, height - pos);
      }
      if ((!vertical) && (pos < width))
      {
        if (bg != null) {
          gc.setBackground(bg);
        }
        gc.fillRectangle(pos, 0, width - pos, height);
      }
      gc.setForeground(oldForeground);
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.ui.internal.forms.widgets.FormImages.ComplexImageDescriptor
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.ui.internal.forms.widgets;

import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Device;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;

class FormImages$SimpleImageDescriptor
  extends FormImages.AbstractImageDescriptor
{
  private int fTheight;
  private int fMarginHeight;
  final FormImages this$0;
  
  FormImages$SimpleImageDescriptor(FormImages paramFormImages, Color color1, Color color2, int realtheight, int theight, int marginHeight)
  {
    super(paramFormImages, new Color[] { color1, color2 }, realtheight);this$0 = paramFormImages;
    fTheight = theight;
    fMarginHeight = marginHeight;
  }
  
  public boolean equals(Object obj)
  {
    if ((obj instanceof SimpleImageDescriptor))
    {
      SimpleImageDescriptor id = (SimpleImageDescriptor)obj;
      if ((super.equals(obj)) && 
        (fTheight == fTheight) && (fMarginHeight == fMarginHeight)) {
        return true;
      }
    }
    return false;
  }
  
  public int hashCode()
  {
    int hash = super.hashCode();
    hash = hash * 7 + new Integer(fTheight).hashCode();
    hash = hash * 7 + new Integer(fMarginHeight).hashCode();
    return hash;
  }
  
  public ImageData getImageData()
  {
    return null;
  }
  
  public Image createImage(boolean returnMissingImageOnError, Device device)
  {
    Image image = new Image(device, 1, fLength);
    Color color1 = new Color(device, fRGBs[0]);
    Color color2 = new Color(device, fRGBs[1]);
    image.setBackground(color1);
    GC gc = new GC(image);
    gc.setBackground(color1);
    gc.fillRectangle(0, 0, 1, fLength);
    gc.setForeground(color2);
    gc.setBackground(color1);
    gc.fillGradientRectangle(0, fMarginHeight + 2, 1, fTheight - 2, true);
    gc.dispose();
    color1.dispose();
    color2.dispose();
    return image;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.ui.internal.forms.widgets.FormImages.SimpleImageDescriptor
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.ui.internal.forms.widgets;

import java.util.Arrays;
import java.util.HashMap;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.LocalResourceManager;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Device;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Display;

public class FormImages
{
  private static FormImages instance;
  
  public static FormImages getInstance()
  {
    if (instance == null) {
      instance = new FormImages();
    }
    return instance;
  }
  
  private ResourceManagerManger manager = new ResourceManagerManger();
  private HashMap descriptors;
  
  private abstract class AbstractImageDescriptor
    extends ImageDescriptor
  {
    RGB[] fRGBs;
    int fLength;
    
    AbstractImageDescriptor(Color[] colors, int length)
    {
      fRGBs = new RGB[colors.length];
      for (int i = 0; i < colors.length; i++)
      {
        Color color = colors[i];
        fRGBs[i] = (color == null ? null : color.getRGB());
      }
      fLength = length;
    }
    
    public boolean equals(Object obj)
    {
      if ((obj instanceof AbstractImageDescriptor))
      {
        AbstractImageDescriptor id = (AbstractImageDescriptor)obj;
        if (fRGBs.length == fRGBs.length)
        {
          boolean result = fLength == fLength;
          for (int i = 0; (i < fRGBs.length) && (result); i++) {
            result = (result) && (fRGBs[i].equals(fRGBs[i]));
          }
          return result;
        }
      }
      return false;
    }
    
    public int hashCode()
    {
      int hash = 0;
      for (int i = 0; i < fRGBs.length; i++) {
        hash = hash * 7 + fRGBs[i].hashCode();
      }
      hash = hash * 7 + fLength;
      return hash;
    }
  }
  
  private class SimpleImageDescriptor
    extends FormImages.AbstractImageDescriptor
  {
    private int fTheight;
    private int fMarginHeight;
    
    SimpleImageDescriptor(Color color1, Color color2, int realtheight, int theight, int marginHeight)
    {
      super(new Color[] { color1, color2 }, realtheight);
      fTheight = theight;
      fMarginHeight = marginHeight;
    }
    
    public boolean equals(Object obj)
    {
      if ((obj instanceof SimpleImageDescriptor))
      {
        SimpleImageDescriptor id = (SimpleImageDescriptor)obj;
        if ((super.equals(obj)) && 
          (fTheight == fTheight) && (fMarginHeight == fMarginHeight)) {
          return true;
        }
      }
      return false;
    }
    
    public int hashCode()
    {
      int hash = super.hashCode();
      hash = hash * 7 + new Integer(fTheight).hashCode();
      hash = hash * 7 + new Integer(fMarginHeight).hashCode();
      return hash;
    }
    
    public ImageData getImageData()
    {
      return null;
    }
    
    public Image createImage(boolean returnMissingImageOnError, Device device)
    {
      Image image = new Image(device, 1, fLength);
      Color color1 = new Color(device, fRGBs[0]);
      Color color2 = new Color(device, fRGBs[1]);
      image.setBackground(color1);
      GC gc = new GC(image);
      gc.setBackground(color1);
      gc.fillRectangle(0, 0, 1, fLength);
      gc.setForeground(color2);
      gc.setBackground(color1);
      gc.fillGradientRectangle(0, fMarginHeight + 2, 1, fTheight - 2, true);
      gc.dispose();
      color1.dispose();
      color2.dispose();
      return image;
    }
  }
  
  private class ComplexImageDescriptor
    extends FormImages.AbstractImageDescriptor
  {
    RGB fBgRGB;
    boolean fVertical;
    int[] fPercents;
    
    public ComplexImageDescriptor(Color[] colors, int length, int[] percents, boolean vertical, Color bg)
    {
      super(colors, length);
      fBgRGB = (bg == null ? null : bg.getRGB());
      fVertical = vertical;
      fPercents = percents;
    }
    
    public boolean equals(Object obj)
    {
      if ((obj instanceof ComplexImageDescriptor))
      {
        ComplexImageDescriptor id = (ComplexImageDescriptor)obj;
        if ((super.equals(obj)) && 
          (fVertical == fVertical) && (Arrays.equals(fPercents, fPercents)))
        {
          if (((fBgRGB == null) && (fBgRGB == null)) || (
            (fBgRGB != null) && (fBgRGB.equals(fBgRGB)))) {
            return true;
          }
          int sum = 0;
          for (int i = 0; i < fPercents.length; i++) {
            sum += fPercents[i];
          }
          if (sum >= 100) {
            return true;
          }
        }
      }
      return false;
    }
    
    public int hashCode()
    {
      int hash = super.hashCode();
      hash = hash * 7 + new Boolean(fVertical).hashCode();
      for (int i = 0; i < fPercents.length; i++) {
        hash = hash * 7 + new Integer(fPercents[i]).hashCode();
      }
      return hash;
    }
    
    public ImageData getImageData()
    {
      return null;
    }
    
    public Image createImage(boolean returnMissingImageOnError, Device device)
    {
      int width = fVertical ? 1 : fLength;
      int height = fVertical ? fLength : 1;
      Image gradient = new Image(device, Math.max(width, 1), 
        Math.max(height, 1));
      GC gc = new GC(gradient);
      Color[] colors = new Color[fRGBs.length];
      for (int i = 0; i < colors.length; i++) {
        colors[i] = new Color(device, fRGBs[i]);
      }
      Color bg = fBgRGB == null ? null : new Color(device, fBgRGB);
      drawTextGradient(gc, width, height, colors, fPercents, fVertical, bg);
      gc.dispose();
      for (int i = 0; i < colors.length; i++) {
        colors[i].dispose();
      }
      if (bg != null) {
        bg.dispose();
      }
      return gradient;
    }
    
    private void drawTextGradient(GC gc, int width, int height, Color[] colors, int[] percents, boolean vertical, Color bg)
    {
      Color oldBackground = gc.getBackground();
      if (colors.length == 1)
      {
        if (colors[0] != null) {
          gc.setBackground(colors[0]);
        }
        gc.fillRectangle(0, 0, width, height);
      }
      else
      {
        Color oldForeground = gc.getForeground();
        Color lastColor = colors[0];
        if (lastColor == null) {
          lastColor = oldBackground;
        }
        int pos = 0;
        for (int i = 0; i < percents.length; i++)
        {
          gc.setForeground(lastColor);
          lastColor = colors[(i + 1)];
          if (lastColor == null) {
            lastColor = oldBackground;
          }
          gc.setBackground(lastColor);
          if (vertical)
          {
            int gradientHeight = percents[i] * height / 100;
            
            gc.fillGradientRectangle(0, pos, width, gradientHeight, 
              true);
            pos += gradientHeight;
          }
          else
          {
            int gradientWidth = percents[i] * width / 100;
            
            gc.fillGradientRectangle(pos, 0, gradientWidth, height, 
              false);
            pos += gradientWidth;
          }
        }
        if ((vertical) && (pos < height))
        {
          if (bg != null) {
            gc.setBackground(bg);
          }
          gc.fillRectangle(0, pos, width, height - pos);
        }
        if ((!vertical) && (pos < width))
        {
          if (bg != null) {
            gc.setBackground(bg);
          }
          gc.fillRectangle(pos, 0, width - pos, height);
        }
        gc.setForeground(oldForeground);
      }
    }
  }
  
  public Image getGradient(Color color1, Color color2, int realtheight, int theight, int marginHeight, Display display)
  {
    if ((color1 == null) || (color1.isDisposed()) || (color2 == null) || (color2.isDisposed())) {
      return null;
    }
    AbstractImageDescriptor desc = new SimpleImageDescriptor(color1, color2, realtheight, theight, marginHeight);
    return getGradient(desc, display);
  }
  
  public Image getGradient(Color[] colors, int[] percents, int length, boolean vertical, Color bg, Display display)
  {
    if (colors.length == 0) {
      return null;
    }
    for (int i = 0; i < colors.length; i++) {
      if ((colors[i] == null) || (colors[i].isDisposed())) {
        return null;
      }
    }
    if ((bg != null) && (bg.isDisposed())) {
      return null;
    }
    AbstractImageDescriptor desc = new ComplexImageDescriptor(colors, length, percents, vertical, bg);
    return getGradient(desc, display);
  }
  
  private synchronized Image getGradient(AbstractImageDescriptor desc, Display display)
  {
    checkHashMaps();
    Image result = manager.getResourceManager(display).createImage(desc);
    descriptors.put(result, desc);
    return result;
  }
  
  public synchronized boolean markFinished(Image image, Display display)
  {
    checkHashMaps();
    AbstractImageDescriptor desc = (AbstractImageDescriptor)descriptors.get(image);
    if (desc != null)
    {
      LocalResourceManager resourceManager = manager.getResourceManager(display);
      resourceManager.destroyImage(desc);
      if (resourceManager.find(desc) == null)
      {
        descriptors.remove(image);
        validateHashMaps();
      }
      return true;
    }
    image.dispose();
    return false;
  }
  
  private void checkHashMaps()
  {
    if (descriptors == null) {
      descriptors = new HashMap();
    }
  }
  
  private void validateHashMaps()
  {
    if (descriptors.size() == 0) {
      descriptors = null;
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.ui.internal.forms.widgets.FormImages
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.ui.internal.forms.widgets;

import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;

public class FormTextModel$ParseErrorHandler
  implements ErrorHandler
{
  final FormTextModel this$0;
  
  public FormTextModel$ParseErrorHandler(FormTextModel paramFormTextModel)
  {
    this$0 = paramFormTextModel;
  }
  
  public void error(SAXParseException arg0)
    throws SAXException
  {}
  
  public void fatalError(SAXParseException arg0)
    throws SAXException
  {}
  
  public void warning(SAXParseException arg0)
    throws SAXException
  {}
}

/* Location:
 * Qualified Name:     org.eclipse.ui.internal.forms.widgets.FormTextModel.ParseErrorHandler
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.ui.internal.forms.widgets;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.Vector;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.eclipse.swt.SWT;
import org.eclipse.ui.forms.HyperlinkSettings;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;

public class FormTextModel
{
  private static final DocumentBuilderFactory documentBuilderFactory = ;
  private boolean whitespaceNormalized = true;
  private Vector paragraphs;
  private IFocusSelectable[] selectableSegments;
  private int selectedSegmentIndex = -1;
  private int savedSelectedLinkIndex = -1;
  private HyperlinkSettings hyperlinkSettings;
  public static final String BOLD_FONT_ID = "f.____bold";
  
  public FormTextModel()
  {
    reset();
  }
  
  public Paragraph[] getParagraphs()
  {
    if (paragraphs == null) {
      return new Paragraph[0];
    }
    return (Paragraph[])paragraphs
      .toArray(new Paragraph[paragraphs.size()]);
  }
  
  public String getAccessibleText()
  {
    if (paragraphs == null) {
      return "";
    }
    StringBuffer sbuf = new StringBuffer();
    for (int i = 0; i < paragraphs.size(); i++)
    {
      Paragraph paragraph = (Paragraph)paragraphs.get(i);
      String text = paragraph.getAccessibleText();
      sbuf.append(text);
    }
    return sbuf.toString();
  }
  
  public void parseTaggedText(String taggedText, boolean expandURLs)
  {
    if (taggedText == null)
    {
      reset();
      return;
    }
    try
    {
      InputStream stream = new ByteArrayInputStream(taggedText
        .getBytes("UTF8"));
      parseInputStream(stream, expandURLs);
    }
    catch (UnsupportedEncodingException e)
    {
      SWT.error(42, e);
    }
  }
  
  public void parseInputStream(InputStream is, boolean expandURLs)
  {
    documentBuilderFactory.setNamespaceAware(true);
    documentBuilderFactory.setIgnoringComments(true);
    
    reset();
    try
    {
      DocumentBuilder parser = documentBuilderFactory
        .newDocumentBuilder();
      parser.setErrorHandler(new ParseErrorHandler());
      InputSource source = new InputSource(is);
      Document doc = parser.parse(source);
      processDocument(doc, expandURLs);
    }
    catch (ParserConfigurationException e)
    {
      SWT.error(5, e, " " + e.getMessage());
    }
    catch (SAXException e)
    {
      SWT.error(5, e, " " + e.getMessage());
    }
    catch (IOException e)
    {
      SWT.error(39, e);
    }
  }
  
  private void processDocument(Document doc, boolean expandURLs)
  {
    Node root = doc.getDocumentElement();
    NodeList children = root.getChildNodes();
    processSubnodes(paragraphs, children, expandURLs);
  }
  
  private void processSubnodes(Vector plist, NodeList children, boolean expandURLs)
  {
    for (int i = 0; i < children.getLength(); i++)
    {
      Node child = children.item(i);
      if (child.getNodeType() == 3)
      {
        String text = getSingleNodeText(child);
        if ((text != null) && (!isIgnorableWhiteSpace(text, true)))
        {
          Paragraph p = new Paragraph(true);
          p.parseRegularText(text, expandURLs, true, 
            getHyperlinkSettings(), null);
          plist.add(p);
        }
      }
      else if (child.getNodeType() == 1)
      {
        String tag = child.getNodeName().toLowerCase();
        if (tag.equals("p"))
        {
          Paragraph p = processParagraph(child, expandURLs);
          if (p != null) {
            plist.add(p);
          }
        }
        else if (tag.equals("li"))
        {
          Paragraph p = processListItem(child, expandURLs);
          if (p != null) {
            plist.add(p);
          }
        }
      }
    }
  }
  
  private Paragraph processParagraph(Node paragraph, boolean expandURLs)
  {
    NodeList children = paragraph.getChildNodes();
    NamedNodeMap atts = paragraph.getAttributes();
    Node addSpaceAtt = atts.getNamedItem("addVerticalSpace");
    boolean addSpace = true;
    if (addSpaceAtt == null) {
      addSpaceAtt = atts.getNamedItem("vspace");
    }
    if (addSpaceAtt != null)
    {
      String value = addSpaceAtt.getNodeValue();
      addSpace = value.equalsIgnoreCase("true");
    }
    Paragraph p = new Paragraph(addSpace);
    
    processSegments(p, children, expandURLs);
    return p;
  }
  
  private Paragraph processListItem(Node listItem, boolean expandURLs)
  {
    NodeList children = listItem.getChildNodes();
    NamedNodeMap atts = listItem.getAttributes();
    Node addSpaceAtt = atts.getNamedItem("addVerticalSpace");
    Node styleAtt = atts.getNamedItem("style");
    Node valueAtt = atts.getNamedItem("value");
    Node indentAtt = atts.getNamedItem("indent");
    Node bindentAtt = atts.getNamedItem("bindent");
    int style = 1;
    int indent = -1;
    int bindent = -1;
    String text = null;
    boolean addSpace = true;
    if (addSpaceAtt != null)
    {
      String value = addSpaceAtt.getNodeValue();
      addSpace = value.equalsIgnoreCase("true");
    }
    if (styleAtt != null)
    {
      String value = styleAtt.getNodeValue();
      if (value.equalsIgnoreCase("text")) {
        style = 2;
      } else if (value.equalsIgnoreCase("image")) {
        style = 3;
      } else if (value.equalsIgnoreCase("bullet")) {
        style = 1;
      }
    }
    if (valueAtt != null)
    {
      text = valueAtt.getNodeValue();
      if (style == 3) {
        text = "i." + text;
      }
    }
    if (indentAtt != null)
    {
      String value = indentAtt.getNodeValue();
      try
      {
        indent = Integer.parseInt(value);
      }
      catch (NumberFormatException localNumberFormatException1) {}
    }
    if (bindentAtt != null)
    {
      String value = bindentAtt.getNodeValue();
      try
      {
        bindent = Integer.parseInt(value);
      }
      catch (NumberFormatException localNumberFormatException2) {}
    }
    BulletParagraph p = new BulletParagraph(addSpace);
    p.setIndent(indent);
    p.setBulletIndent(bindent);
    p.setBulletStyle(style);
    p.setBulletText(text);
    
    processSegments(p, children, expandURLs);
    return p;
  }
  
  private void processSegments(Paragraph p, NodeList children, boolean expandURLs)
  {
    for (int i = 0; i < children.getLength(); i++)
    {
      Node child = children.item(i);
      ParagraphSegment segment = null;
      if (child.getNodeType() == 3)
      {
        String value = getSingleNodeText(child);
        if ((value != null) && (!isIgnorableWhiteSpace(value, false))) {
          p.parseRegularText(value, expandURLs, true, 
            getHyperlinkSettings(), null);
        }
      }
      else if (child.getNodeType() == 1)
      {
        String name = child.getNodeName();
        if (name.equalsIgnoreCase("img"))
        {
          segment = processImageSegment(child);
        }
        else if (name.equalsIgnoreCase("a"))
        {
          segment = processHyperlinkSegment(child, 
            getHyperlinkSettings());
        }
        else if (name.equalsIgnoreCase("span"))
        {
          processTextSegment(p, expandURLs, child);
        }
        else if (name.equalsIgnoreCase("b"))
        {
          String text = getNodeText(child);
          String fontId = "f.____bold";
          p.parseRegularText(text, expandURLs, true, 
            getHyperlinkSettings(), fontId);
        }
        else if (name.equalsIgnoreCase("br"))
        {
          segment = new BreakSegment();
        }
        else if (name.equalsIgnoreCase("control"))
        {
          segment = processControlSegment(child);
        }
      }
      if (segment != null) {
        p.addSegment(segment);
      }
    }
  }
  
  private boolean isIgnorableWhiteSpace(String text, boolean ignoreSpaces)
  {
    for (int i = 0; i < text.length(); i++)
    {
      char c = text.charAt(i);
      if ((!ignoreSpaces) || (c != ' ')) {
        if ((c != '\n') && (c != '\r') && (c != '\f')) {
          return false;
        }
      }
    }
    return true;
  }
  
  private ImageSegment processImageSegment(Node image)
  {
    ImageSegment segment = new ImageSegment();
    processObjectSegment(segment, image, "i.");
    return segment;
  }
  
  private ControlSegment processControlSegment(Node control)
  {
    ControlSegment segment = new ControlSegment();
    processObjectSegment(segment, control, "o.");
    Node fill = control.getAttributes().getNamedItem("fill");
    if (fill != null)
    {
      String value = fill.getNodeValue();
      boolean doFill = value.equalsIgnoreCase("true");
      segment.setFill(doFill);
    }
    try
    {
      Node width = control.getAttributes().getNamedItem("width");
      if (width != null)
      {
        String value = width.getNodeValue();
        int doWidth = Integer.parseInt(value);
        segment.setWidth(doWidth);
      }
      Node height = control.getAttributes().getNamedItem("height");
      if (height != null)
      {
        String value = height.getNodeValue();
        int doHeight = Integer.parseInt(value);
        segment.setHeight(doHeight);
      }
    }
    catch (NumberFormatException localNumberFormatException) {}
    return segment;
  }
  
  private void processObjectSegment(ObjectSegment segment, Node object, String prefix)
  {
    NamedNodeMap atts = object.getAttributes();
    Node id = atts.getNamedItem("href");
    Node align = atts.getNamedItem("align");
    if (id != null)
    {
      String value = id.getNodeValue();
      segment.setObjectId(prefix + value);
    }
    if (align != null)
    {
      String value = align.getNodeValue().toLowerCase();
      if (value.equals("top")) {
        segment.setVerticalAlignment(1);
      } else if (value.equals("middle")) {
        segment.setVerticalAlignment(2);
      } else if (value.equals("bottom")) {
        segment.setVerticalAlignment(3);
      }
    }
  }
  
  private void appendText(String value, StringBuffer buf, int[] spaceCounter)
  {
    if (!whitespaceNormalized) {
      buf.append(value);
    } else {
      for (int j = 0; j < value.length(); j++)
      {
        char c = value.charAt(j);
        if ((c == ' ') || (c == '\t'))
        {
          if (spaceCounter[0] += 1 == 1) {
            buf.append(c);
          }
        }
        else if ((c == '\n') || (c == '\r') || (c == '\f'))
        {
          if (spaceCounter[0] += 1 == 1) {
            buf.append(' ');
          }
        }
        else
        {
          spaceCounter[0] = 0;
          buf.append(c);
        }
      }
    }
  }
  
  private String getNormalizedText(String text)
  {
    int[] spaceCounter = new int[1];
    StringBuffer buf = new StringBuffer();
    if (text == null) {
      return null;
    }
    appendText(text, buf, spaceCounter);
    return buf.toString();
  }
  
  private String getSingleNodeText(Node node)
  {
    return getNormalizedText(node.getNodeValue());
  }
  
  private String getNodeText(Node node)
  {
    NodeList children = node.getChildNodes();
    StringBuffer buf = new StringBuffer();
    int[] spaceCounter = new int[1];
    for (int i = 0; i < children.getLength(); i++)
    {
      Node child = children.item(i);
      if (child.getNodeType() == 3)
      {
        String value = child.getNodeValue();
        appendText(value, buf, spaceCounter);
      }
    }
    return buf.toString().trim();
  }
  
  private ParagraphSegment processHyperlinkSegment(Node link, HyperlinkSettings settings)
  {
    NamedNodeMap atts = link.getAttributes();
    String href = null;
    boolean wrapAllowed = true;
    String boldFontId = null;
    
    Node hrefAtt = atts.getNamedItem("href");
    if (hrefAtt != null) {
      href = hrefAtt.getNodeValue();
    }
    Node boldAtt = atts.getNamedItem("bold");
    if (boldAtt != null) {
      boldFontId = "f.____bold";
    }
    Node nowrap = atts.getNamedItem("nowrap");
    if (nowrap != null)
    {
      String value = nowrap.getNodeValue();
      if ((value != null) && (value.equalsIgnoreCase("true"))) {
        wrapAllowed = false;
      }
    }
    Object status = checkChildren(link);
    if ((status instanceof Node))
    {
      Node child = (Node)status;
      ImageHyperlinkSegment segment = new ImageHyperlinkSegment();
      segment.setHref(href);
      segment.setWordWrapAllowed(wrapAllowed);
      Node alt = child.getAttributes().getNamedItem("alt");
      if (alt != null) {
        segment.setTooltipText(alt.getNodeValue());
      }
      Node text = child.getAttributes().getNamedItem("text");
      if (text != null) {
        segment.setText(text.getNodeValue());
      }
      processObjectSegment(segment, child, "i.");
      return segment;
    }
    if ((status instanceof String))
    {
      String text = (String)status;
      TextHyperlinkSegment segment = new TextHyperlinkSegment(text, 
        settings, null);
      segment.setHref(href);
      segment.setFontId(boldFontId);
      Node alt = atts.getNamedItem("alt");
      if (alt != null) {
        segment.setTooltipText(alt.getNodeValue());
      }
      segment.setWordWrapAllowed(wrapAllowed);
      return segment;
    }
    AggregateHyperlinkSegment parent = new AggregateHyperlinkSegment();
    parent.setHref(href);
    NodeList children = link.getChildNodes();
    for (int i = 0; i < children.getLength(); i++)
    {
      Node child = children.item(i);
      if (child.getNodeType() == 3)
      {
        String value = child.getNodeValue();
        TextHyperlinkSegment ts = new TextHyperlinkSegment(
          getNormalizedText(value), settings, null);
        Node alt = atts.getNamedItem("alt");
        if (alt != null) {
          ts.setTooltipText(alt.getNodeValue());
        }
        ts.setWordWrapAllowed(wrapAllowed);
        parent.add(ts);
      }
      else if (child.getNodeType() == 1)
      {
        String name = child.getNodeName();
        if (name.equalsIgnoreCase("img"))
        {
          ImageHyperlinkSegment is = new ImageHyperlinkSegment();
          processObjectSegment(is, child, "i.");
          Node alt = child.getAttributes().getNamedItem("alt");
          if (alt != null) {
            is.setTooltipText(alt.getNodeValue());
          }
          parent.add(is);
          is.setWordWrapAllowed(wrapAllowed);
        }
      }
    }
    return parent;
  }
  
  private Object checkChildren(Node node)
  {
    boolean text = false;
    Node imgNode = null;
    
    NodeList children = node.getChildNodes();
    for (int i = 0; i < children.getLength(); i++)
    {
      Node child = children.item(i);
      if (child.getNodeType() == 3) {
        text = true;
      } else if ((child.getNodeType() == 1) && 
        (child.getNodeName().equalsIgnoreCase("img"))) {
        imgNode = child;
      }
    }
    if ((text) && (imgNode == null)) {
      return getNodeText(node);
    }
    if ((!text) && (imgNode != null)) {
      return imgNode;
    }
    return null;
  }
  
  private void processTextSegment(Paragraph p, boolean expandURLs, Node textNode)
  {
    String text = getNodeText(textNode);
    
    NamedNodeMap atts = textNode.getAttributes();
    Node font = atts.getNamedItem("font");
    Node color = atts.getNamedItem("color");
    boolean wrapAllowed = true;
    Node nowrap = atts.getNamedItem("nowrap");
    if (nowrap != null)
    {
      String value = nowrap.getNodeValue();
      if ((value != null) && (value.equalsIgnoreCase("true"))) {
        wrapAllowed = false;
      }
    }
    String fontId = null;
    String colorId = null;
    if (font != null) {
      fontId = "f." + font.getNodeValue();
    }
    if (color != null) {
      colorId = "c." + color.getNodeValue();
    }
    p.parseRegularText(text, expandURLs, wrapAllowed, getHyperlinkSettings(), fontId, 
      colorId);
  }
  
  public void parseRegularText(String regularText, boolean convertURLs)
  {
    reset();
    if (regularText == null) {
      return;
    }
    regularText = getNormalizedText(regularText);
    
    Paragraph p = new Paragraph(true);
    paragraphs.add(p);
    int pstart = 0;
    for (int i = 0; i < regularText.length(); i++)
    {
      char c = regularText.charAt(i);
      if (p == null)
      {
        p = new Paragraph(true);
        paragraphs.add(p);
      }
      if (c == '\n')
      {
        String text = regularText.substring(pstart, i);
        pstart = i + 1;
        p.parseRegularText(text, convertURLs, true, getHyperlinkSettings(), 
          null);
        p = null;
      }
    }
    if (p != null)
    {
      String text = regularText.substring(pstart);
      p.parseRegularText(text, convertURLs, true, getHyperlinkSettings(), null);
    }
  }
  
  public HyperlinkSettings getHyperlinkSettings()
  {
    if (hyperlinkSettings == null) {
      hyperlinkSettings = new HyperlinkSettings(SWTUtil.getStandardDisplay());
    }
    return hyperlinkSettings;
  }
  
  public void setHyperlinkSettings(HyperlinkSettings settings)
  {
    hyperlinkSettings = settings;
  }
  
  private void reset()
  {
    if (paragraphs == null) {
      paragraphs = new Vector();
    }
    paragraphs.clear();
    selectedSegmentIndex = -1;
    savedSelectedLinkIndex = -1;
    selectableSegments = null;
  }
  
  IFocusSelectable[] getFocusSelectableSegments()
  {
    if ((selectableSegments != null) || (paragraphs == null)) {
      return selectableSegments;
    }
    Vector result = new Vector();
    for (int i = 0; i < paragraphs.size(); i++)
    {
      Paragraph p = (Paragraph)paragraphs.get(i);
      ParagraphSegment[] segments = p.getSegments();
      for (int j = 0; j < segments.length; j++) {
        if ((segments[j] instanceof IFocusSelectable)) {
          result.add(segments[j]);
        }
      }
    }
    selectableSegments = 
      ((IFocusSelectable[])result.toArray(new IFocusSelectable[result.size()]));
    return selectableSegments;
  }
  
  public IHyperlinkSegment getHyperlink(int index)
  {
    IFocusSelectable[] selectables = getFocusSelectableSegments();
    if (selectables.length > index)
    {
      IFocusSelectable link = selectables[index];
      if ((link instanceof IHyperlinkSegment)) {
        return (IHyperlinkSegment)link;
      }
    }
    return null;
  }
  
  public IHyperlinkSegment findHyperlinkAt(int x, int y)
  {
    IFocusSelectable[] selectables = getFocusSelectableSegments();
    for (int i = 0; i < selectables.length; i++)
    {
      IFocusSelectable segment = selectables[i];
      if ((segment instanceof IHyperlinkSegment))
      {
        IHyperlinkSegment link = (IHyperlinkSegment)segment;
        if (link.contains(x, y)) {
          return link;
        }
      }
    }
    return null;
  }
  
  public int getHyperlinkCount()
  {
    return getFocusSelectableSegments().length;
  }
  
  public int indexOf(IHyperlinkSegment link)
  {
    IFocusSelectable[] selectables = getFocusSelectableSegments();
    for (int i = 0; i < selectables.length; i++)
    {
      IFocusSelectable segment = selectables[i];
      if ((segment instanceof IHyperlinkSegment))
      {
        IHyperlinkSegment l = (IHyperlinkSegment)segment;
        if (link == l) {
          return i;
        }
      }
    }
    return -1;
  }
  
  public ParagraphSegment findSegmentAt(int x, int y)
  {
    for (int i = 0; i < paragraphs.size(); i++)
    {
      Paragraph p = (Paragraph)paragraphs.get(i);
      ParagraphSegment segment = p.findSegmentAt(x, y);
      if (segment != null) {
        return segment;
      }
    }
    return null;
  }
  
  public void clearCache(String fontId)
  {
    for (int i = 0; i < paragraphs.size(); i++)
    {
      Paragraph p = (Paragraph)paragraphs.get(i);
      p.clearCache(fontId);
    }
  }
  
  public IFocusSelectable getSelectedSegment()
  {
    if ((selectableSegments == null) || (selectedSegmentIndex == -1)) {
      return null;
    }
    return selectableSegments[selectedSegmentIndex];
  }
  
  public int getSelectedSegmentIndex()
  {
    return selectedSegmentIndex;
  }
  
  public boolean linkExists(IHyperlinkSegment link)
  {
    if (selectableSegments == null) {
      return false;
    }
    for (int i = 0; i < selectableSegments.length; i++) {
      if (selectableSegments[i] == link) {
        return true;
      }
    }
    return false;
  }
  
  public boolean traverseFocusSelectableObjects(boolean next)
  {
    IFocusSelectable[] selectables = getF
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2019. Infinite Loop Ltd