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

ldren;
  }
  
  public void getValue(AccessibleControlEvent e) {}
}

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

import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;

class FormText$2
  implements PaintListener
{
  final FormText this$0;
  
  FormText$2(FormText paramFormText)
  {
    this$0 = paramFormText;
  }
  
  public void paintControl(PaintEvent e)
  {
    FormText.access$8(this$0, e);
  }
}

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

import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;

class FormText$3
  implements Listener
{
  final FormText this$0;
  
  FormText$3(FormText paramFormText)
  {
    this$0 = paramFormText;
  }
  
  public void handleEvent(Event e)
  {
    if (character == '\r')
    {
      FormText.access$9(this$0);
      return;
    }
  }
}

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

import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.ui.internal.forms.widgets.FormTextModel;

class FormText$4
  implements Listener
{
  final FormText this$0;
  
  FormText$4(FormText paramFormText)
  {
    this$0 = paramFormText;
  }
  
  public void handleEvent(Event e)
  {
    switch (detail)
    {
    case 32: 
    case 64: 
    case 256: 
    case 512: 
      doit = false;
      return;
    }
    if (!FormText.access$0(this$0).hasFocusSegments())
    {
      doit = true;
      return;
    }
    if (detail == 16) {
      doit = FormText.access$10(this$0, true);
    } else if (detail == 8) {
      doit = FormText.access$10(this$0, false);
    } else if (detail != 4) {
      doit = true;
    }
  }
}

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

import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.FocusListener;

class FormText$5
  implements FocusListener
{
  final FormText this$0;
  
  FormText$5(FormText paramFormText)
  {
    this$0 = paramFormText;
  }
  
  public void focusGained(FocusEvent e)
  {
    if (!FormText.access$11(this$0))
    {
      FormText.access$12(this$0, true);
      if ((!FormText.access$13(this$0)) && (!FormText.access$14(this$0))) {
        FormText.access$15(this$0);
      }
    }
  }
  
  public void focusLost(FocusEvent e)
  {
    if (FormText.access$11(this$0))
    {
      FormText.access$12(this$0, false);
      if (!FormText.access$14(this$0)) {
        FormText.access$15(this$0);
      }
    }
  }
}

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

import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;

class FormText$6
  implements MouseListener
{
  final FormText this$0;
  
  FormText$6(FormText paramFormText)
  {
    this$0 = paramFormText;
  }
  
  public void mouseDoubleClick(MouseEvent e) {}
  
  public void mouseDown(MouseEvent e)
  {
    FormText.access$16(this$0, e, true);
  }
  
  public void mouseUp(MouseEvent e)
  {
    FormText.access$16(this$0, e, false);
  }
}

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

import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseTrackListener;

class FormText$7
  implements MouseTrackListener
{
  final FormText this$0;
  
  FormText$7(FormText paramFormText)
  {
    this$0 = paramFormText;
  }
  
  public void mouseEnter(MouseEvent e)
  {
    FormText.access$17(this$0, e);
  }
  
  public void mouseExit(MouseEvent e)
  {
    if (FormText.access$18(this$0) != null)
    {
      FormText.access$19(this$0, FormText.access$18(this$0), stateMask);
      FormText.access$20(this$0, FormText.access$18(this$0), false);
      FormText.access$21(this$0, null);
      this$0.setCursor(null);
    }
  }
  
  public void mouseHover(MouseEvent e)
  {
    FormText.access$22(this$0, e);
  }
}

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

import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseMoveListener;

class FormText$8
  implements MouseMoveListener
{
  final FormText this$0;
  
  FormText$8(FormText paramFormText)
  {
    this$0 = paramFormText;
  }
  
  public void mouseMove(MouseEvent e)
  {
    FormText.access$17(this$0, e);
  }
}

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

import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.ui.internal.forms.widgets.ControlSegment;

class FormText$9
  implements Listener
{
  final FormText this$0;
  
  FormText$9(FormText paramFormText)
  {
    this$0 = paramFormText;
  }
  
  public void handleEvent(Event e)
  {
    switch (type)
    {
    case 15: 
      if (!FormText.access$14(this$0)) {
        FormText.access$23(this$0, (Control)widget);
      }
      break;
    case 31: 
      switch (detail)
      {
      case 32: 
      case 64: 
      case 256: 
      case 512: 
        doit = false;
        return;
      }
      Control c = (Control)widget;
      ControlSegment segment = (ControlSegment)c
        .getData("__segment__");
      if (detail == 16) {
        doit = FormText.access$24(this$0, c, segment, true);
      } else if (detail == 8) {
        doit = FormText.access$24(this$0, c, segment, false);
      }
      if (!doit) {
        detail = 0;
      }
      break;
    }
  }
}

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

import org.eclipse.swt.graphics.FontMetrics;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Layout;
import org.eclipse.ui.internal.forms.widgets.FormTextModel;
import org.eclipse.ui.internal.forms.widgets.IFocusSelectable;
import org.eclipse.ui.internal.forms.widgets.IHyperlinkSegment;
import org.eclipse.ui.internal.forms.widgets.Locator;
import org.eclipse.ui.internal.forms.widgets.Paragraph;
import org.eclipse.ui.internal.forms.widgets.ParagraphSegment;

class FormText$FormTextLayout
  extends Layout
  implements ILayoutExtension
{
  final FormText this$0;
  
  public FormText$FormTextLayout(FormText paramFormText)
  {
    this$0 = paramFormText;
  }
  
  public int computeMaximumWidth(Composite parent, boolean changed)
  {
    return computeSize-1-1x;
  }
  
  public int computeMinimumWidth(Composite parent, boolean changed)
  {
    return computeSize5-1x;
  }
  
  public Point computeSize(Composite composite, int wHint, int hHint, boolean changed)
  {
    long start = 0L;
    
    int innerWidth = wHint;
    if (innerWidth != -1) {
      innerWidth -= this$0.marginWidth * 2;
    }
    Point textSize = computeTextSize(innerWidth);
    int textWidth = x + 2 * this$0.marginWidth;
    int textHeight = y + 2 * this$0.marginHeight;
    Point result = new Point(textWidth, textHeight);
    
    return result;
  }
  
  private Point computeTextSize(int wHint)
  {
    Paragraph[] paragraphs = FormText.access$0(this$0).getParagraphs();
    GC gc = new GC(this$0);
    gc.setFont(this$0.getFont());
    Locator loc = new Locator();
    int width = wHint != -1 ? wHint : 0;
    FontMetrics fm = gc.getFontMetrics();
    int lineHeight = fm.getHeight();
    boolean selectableInTheLastRow = false;
    for (int i = 0; i < paragraphs.length; i++)
    {
      Paragraph p = paragraphs[i];
      if ((i > 0) && (this$0.getParagraphsSeparated()) && 
        (p.getAddVerticalSpace())) {
        y += FormText.access$1(this$0, lineHeight);
      }
      rowHeight = 0;
      indent = p.getIndent();
      x = p.getIndent();
      ParagraphSegment[] segments = p.getSegments();
      if (segments.length > 0)
      {
        selectableInTheLastRow = false;
        int pwidth = 0;
        for (int j = 0; j < segments.length; j++)
        {
          ParagraphSegment segment = segments[j];
          segment.advanceLocator(gc, wHint, loc, FormText.access$2(this$0), false);
          if (wHint != -1) {
            width = Math.max(width, width);
          } else {
            pwidth = Math.max(pwidth, width);
          }
          if ((segment instanceof IFocusSelectable)) {
            selectableInTheLastRow = true;
          }
        }
        if (wHint == -1) {
          width = Math.max(width, pwidth);
        }
        y += rowHeight;
      }
      else
      {
        y += lineHeight;
      }
    }
    gc.dispose();
    if (selectableInTheLastRow) {
      y += 1;
    }
    return new Point(width, y);
  }
  
  protected void layout(Composite composite, boolean flushCache)
  {
    long start = 0L;
    
    FormText.access$3(this$0, null);
    Rectangle carea = composite.getClientArea();
    
    GC gc = new GC(composite);
    gc.setFont(this$0.getFont());
    FormText.access$4(this$0, this$0.getFont());
    gc.setForeground(this$0.getForeground());
    gc.setBackground(this$0.getBackground());
    
    Locator loc = new Locator();
    marginWidth = this$0.marginWidth;
    marginHeight = this$0.marginHeight;
    y = this$0.marginHeight;
    FontMetrics fm = gc.getFontMetrics();
    int lineHeight = fm.getHeight();
    
    Paragraph[] paragraphs = FormText.access$0(this$0).getParagraphs();
    IHyperlinkSegment selectedLink = FormText.access$5(this$0);
    for (int i = 0; i < paragraphs.length; i++)
    {
      Paragraph p = paragraphs[i];
      if ((i > 0) && (FormText.access$6(this$0)) && (p.getAddVerticalSpace())) {
        y += FormText.access$1(this$0, lineHeight);
      }
      indent = p.getIndent();
      loc.resetCaret();
      rowHeight = 0;
      p.layout(gc, width, loc, lineHeight, FormText.access$2(this$0), 
        selectedLink);
    }
    gc.dispose();
  }
}

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

import java.io.InputStream;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Hashtable;
import org.eclipse.core.runtime.ListenerList;
import org.eclipse.swt.SWT;
import org.eclipse.swt.accessibility.Accessible;
import org.eclipse.swt.accessibility.AccessibleAdapter;
import org.eclipse.swt.accessibility.AccessibleControlAdapter;
import org.eclipse.swt.accessibility.AccessibleControlEvent;
import org.eclipse.swt.accessibility.AccessibleEvent;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.FocusListener;
import org.eclipse.swt.events.MenuEvent;
import org.eclipse.swt.events.MenuListener;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.MouseMoveListener;
import org.eclipse.swt.events.MouseTrackListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontMetrics;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Layout;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.TypedListener;
import org.eclipse.ui.forms.HyperlinkSettings;
import org.eclipse.ui.forms.events.HyperlinkEvent;
import org.eclipse.ui.forms.events.IHyperlinkListener;
import org.eclipse.ui.internal.forms.Messages;
import org.eclipse.ui.internal.forms.widgets.ControlSegment;
import org.eclipse.ui.internal.forms.widgets.FormFonts;
import org.eclipse.ui.internal.forms.widgets.FormTextModel;
import org.eclipse.ui.internal.forms.widgets.FormUtil;
import org.eclipse.ui.internal.forms.widgets.IFocusSelectable;
import org.eclipse.ui.internal.forms.widgets.IHyperlinkSegment;
import org.eclipse.ui.internal.forms.widgets.Locator;
import org.eclipse.ui.internal.forms.widgets.Paragraph;
import org.eclipse.ui.internal.forms.widgets.ParagraphSegment;
import org.eclipse.ui.internal.forms.widgets.SelectionData;
import org.eclipse.ui.internal.forms.widgets.TextSegment;

public class FormText
  extends Canvas
{
  public static final String URL_HANDLER_ID = "urlHandler";
  public int marginWidth = 0;
  public int marginHeight = 1;
  private static final boolean DEBUG_TEXT = false;
  private static final boolean DEBUG_TEXTSIZE = false;
  private static final boolean DEBUG_FOCUS = false;
  private boolean hasFocus;
  private boolean paragraphsSeparated = true;
  private FormTextModel model;
  private ListenerList listeners;
  private Hashtable resourceTable = new Hashtable();
  private IHyperlinkSegment entered;
  private IHyperlinkSegment armed;
  private boolean mouseFocus = false;
  private boolean controlFocusTransfer = false;
  private boolean inSelection = false;
  private SelectionData selData;
  private static final String INTERNAL_MENU = "__internal_menu__";
  private static final String CONTROL_KEY = "__segment__";
  
  private class FormTextLayout
    extends Layout
    implements ILayoutExtension
  {
    public FormTextLayout() {}
    
    public int computeMaximumWidth(Composite parent, boolean changed)
    {
      return computeSize-1-1x;
    }
    
    public int computeMinimumWidth(Composite parent, boolean changed)
    {
      return computeSize5-1x;
    }
    
    public Point computeSize(Composite composite, int wHint, int hHint, boolean changed)
    {
      long start = 0L;
      
      int innerWidth = wHint;
      if (innerWidth != -1) {
        innerWidth -= marginWidth * 2;
      }
      Point textSize = computeTextSize(innerWidth);
      int textWidth = x + 2 * marginWidth;
      int textHeight = y + 2 * marginHeight;
      Point result = new Point(textWidth, textHeight);
      
      return result;
    }
    
    private Point computeTextSize(int wHint)
    {
      Paragraph[] paragraphs = model.getParagraphs();
      GC gc = new GC(FormText.this);
      gc.setFont(getFont());
      Locator loc = new Locator();
      int width = wHint != -1 ? wHint : 0;
      FontMetrics fm = gc.getFontMetrics();
      int lineHeight = fm.getHeight();
      boolean selectableInTheLastRow = false;
      for (int i = 0; i < paragraphs.length; i++)
      {
        Paragraph p = paragraphs[i];
        if ((i > 0) && (getParagraphsSeparated()) && 
          (p.getAddVerticalSpace())) {
          y += FormText.this.getParagraphSpacing(lineHeight);
        }
        rowHeight = 0;
        indent = p.getIndent();
        x = p.getIndent();
        ParagraphSegment[] segments = p.getSegments();
        if (segments.length > 0)
        {
          selectableInTheLastRow = false;
          int pwidth = 0;
          for (int j = 0; j < segments.length; j++)
          {
            ParagraphSegment segment = segments[j];
            segment.advanceLocator(gc, wHint, loc, resourceTable, false);
            if (wHint != -1) {
              width = Math.max(width, width);
            } else {
              pwidth = Math.max(pwidth, width);
            }
            if ((segment instanceof IFocusSelectable)) {
              selectableInTheLastRow = true;
            }
          }
          if (wHint == -1) {
            width = Math.max(width, pwidth);
          }
          y += rowHeight;
        }
        else
        {
          y += lineHeight;
        }
      }
      gc.dispose();
      if (selectableInTheLastRow) {
        y += 1;
      }
      return new Point(width, y);
    }
    
    protected void layout(Composite composite, boolean flushCache)
    {
      long start = 0L;
      
      selData = null;
      Rectangle carea = composite.getClientArea();
      
      GC gc = new GC(composite);
      gc.setFont(getFont());
      FormText.this.ensureBoldFontPresent(getFont());
      gc.setForeground(getForeground());
      gc.setBackground(getBackground());
      
      Locator loc = new Locator();
      marginWidth = marginWidth;
      marginHeight = marginHeight;
      y = marginHeight;
      FontMetrics fm = gc.getFontMetrics();
      int lineHeight = fm.getHeight();
      
      Paragraph[] paragraphs = model.getParagraphs();
      IHyperlinkSegment selectedLink = FormText.this.getSelectedLink();
      for (int i = 0; i < paragraphs.length; i++)
      {
        Paragraph p = paragraphs[i];
        if ((i > 0) && (paragraphsSeparated) && (p.getAddVerticalSpace())) {
          y += FormText.this.getParagraphSpacing(lineHeight);
        }
        indent = p.getIndent();
        loc.resetCaret();
        rowHeight = 0;
        p.layout(gc, width, loc, lineHeight, resourceTable, 
          selectedLink);
      }
      gc.dispose();
    }
  }
  
  public FormText(Composite parent, int style)
  {
    super(parent, 0x40040 | style);
    setLayout(new FormTextLayout());
    model = new FormTextModel();
    addDisposeListener(new DisposeListener()
    {
      public void widgetDisposed(DisposeEvent e)
      {
        model.dispose();
        FormText.this.disposeResourceTable(true);
      }
    });
    addPaintListener(new PaintListener()
    {
      public void paintControl(PaintEvent e)
      {
        FormText.this.paint(e);
      }
    });
    addListener(1, new Listener()
    {
      public void handleEvent(Event e)
      {
        if (character == '\r')
        {
          FormText.this.activateSelectedLink();
          return;
        }
      }
    });
    addListener(31, new Listener()
    {
      public void handleEvent(Event e)
      {
        switch (detail)
        {
        case 32: 
        case 64: 
        case 256: 
        case 512: 
          doit = false;
          return;
        }
        if (!model.hasFocusSegments())
        {
          doit = true;
          return;
        }
        if (detail == 16) {
          doit = FormText.this.advance(true);
        } else if (detail == 8) {
          doit = FormText.this.advance(false);
        } else if (detail != 4) {
          doit = true;
        }
      }
    });
    addFocusListener(new FocusListener()
    {
      public void focusGained(FocusEvent e)
      {
        if (!hasFocus)
        {
          hasFocus = true;
          if ((!mouseFocus) && (!controlFocusTransfer)) {
            FormText.this.handleFocusChange();
          }
        }
      }
      
      public void focusLost(FocusEvent e)
      {
        if (hasFocus)
        {
          hasFocus = false;
          if (!controlFocusTransfer) {
            FormText.this.handleFocusChange();
          }
        }
      }
    });
    addMouseListener(new MouseListener()
    {
      public void mouseDoubleClick(MouseEvent e) {}
      
      public void mouseDown(MouseEvent e)
      {
        FormText.this.handleMouseClick(e, true);
      }
      
      public void mouseUp(MouseEvent e)
      {
        FormText.this.handleMouseClick(e, false);
      }
    });
    addMouseTrackListener(new MouseTrackListener()
    {
      public void mouseEnter(MouseEvent e)
      {
        FormText.this.handleMouseMove(e);
      }
      
      public void mouseExit(MouseEvent e)
      {
        if (entered != null)
        {
          FormText.this.exitLink(entered, stateMask);
          FormText.this.paintLinkHover(entered, false);
          entered = null;
          setCursor(null);
        }
      }
      
      public void mouseHover(MouseEvent e)
      {
        FormText.this.handleMouseHover(e);
      }
    });
    addMouseMoveListener(new MouseMoveListener()
    {
      public void mouseMove(MouseEvent e)
      {
        FormText.this.handleMouseMove(e);
      }
    });
    initAccessible();
    ensureBoldFontPresent(getFont());
    createMenu();
    
    setTabList(new Control[0]);
  }
  
  public boolean getFocus()
  {
    return hasFocus;
  }
  
  /**
   * @deprecated
   */
  public boolean isLoading()
  {
    return false;
  }
  
  /**
   * @deprecated
   */
  public String getLoadingText()
  {
    return null;
  }
  
  /**
   * @deprecated
   */
  public void setLoadingText(String loadingText)
  {
    setText(loadingText, false, false);
  }
  
  public void setParagraphsSeparated(boolean value)
  {
    paragraphsSeparated = value;
  }
  
  public boolean getParagraphsSeparated()
  {
    return paragraphsSeparated;
  }
  
  public void setImage(String key, Image image)
  {
    resourceTable.put("i." + key, image);
  }
  
  public void setColor(String key, Color color)
  {
    String fullKey = "c." + key;
    if (color == null) {
      resourceTable.remove(fullKey);
    } else {
      resourceTable.put(fullKey, color);
    }
  }
  
  public void setFont(String key, Font font)
  {
    String fullKey = "f." + key;
    if (font == null) {
      resourceTable.remove(fullKey);
    } else {
      resourceTable.put(fullKey, font);
    }
    model.clearCache(fullKey);
  }
  
  public void setControl(String key, Control control)
  {
    String fullKey = "o." + key;
    if (control == null) {
      resourceTable.remove(fullKey);
    } else {
      resourceTable.put(fullKey, control);
    }
  }
  
  public void setFont(Font font)
  {
    super.setFont(font);
    model.clearCache(null);
    Font boldFont = (Font)resourceTable.get("f.____bold");
    if (boldFont != null)
    {
      FormFonts.getInstance().markFinished(boldFont, getDisplay());
      resourceTable.remove("f.____bold");
    }
    ensureBoldFontPresent(getFont());
  }
  
  public void setText(String text, boolean parseTags, boolean expandURLs)
  {
    disposeResourceTable(false);
    entered = null;
    if (parseTags) {
      model.parseTaggedText(text, expandURLs);
    } else {
      model.parseRegularText(text, expandURLs);
    }
    hookControlSegmentFocus();
    layout();
    redraw();
  }
  
  public void setContents(InputStream is, boolean expandURLs)
  {
    entered = null;
    disposeResourceTable(false);
    model.parseInputStream(is, expandURLs);
    hookControlSegmentFocus();
    layout();
    redraw();
  }
  
  private void hookControlSegmentFocus()
  {
    Paragraph[] paragraphs = model.getParagraphs();
    if (paragraphs == null) {
      return;
    }
    Listener listener = new Listener()
    {
      public void handleEvent(Event e)
      {
        switch (type)
        {
        case 15: 
          if (!controlFocusTransfer) {
            FormText.this.syncControlSegmentFocus((Control)widget);
          }
          break;
        case 31: 
          switch (detail)
          {
          case 32: 
          case 64: 
          case 256: 
          case 512: 
            doit = false;
            return;
          }
          Control c = (Control)widget;
          ControlSegment segment = (ControlSegment)c
            .getData("__segment__");
          if (detail == 16) {
            doit = FormText.this.advanceControl(c, segment, true);
          } else if (detail == 8) {
            doit = FormText.this.advanceControl(c, segment, false);
          }
          if (!doit) {
            detail = 0;
          }
          break;
        }
      }
    };
    for (int i = 0; i < paragraphs.length; i++)
    {
      Paragraph p = paragraphs[i];
      ParagraphSegment[] segments = p.getSegments();
      for (int j = 0; j < segments.length; j++) {
        if ((segments[j] instanceof ControlSegment))
        {
          ControlSegment cs = (ControlSegment)segments[j];
          Control c = cs.getControl(resourceTable);
          if ((c != null) && 
            (c.getData("__segment__") == null))
          {
            c.setData("__segment__", cs);
            attachTraverseListener(c, listener);
          }
        }
      }
    }
  }
  
  private void attachTraverseListener(Control c, Listener listener)
  {
    if ((c instanceof Composite))
    {
      Composite parent = (Composite)c;
      Control[] children = parent.getChildren();
      for (int i = 0; i < children.length; i++) {
        attachTraverseListener(children[i], listener);
      }
      if ((c instanceof Canvas))
      {
        c.addListener(31, listener);
        c.addListener(15, listener);
      }
    }
    else
    {
      c.addListener(31, listener);
      c.addListener(15, listener);
    }
  }
  
  private void syncControlSegmentFocus(Control control)
  {
    ControlSegment cs = null;
    while (control != null)
    {
      cs = (ControlSegment)control.getData("__segment__");
      if (cs != null) {
        break;
      }
      control = control.getParent();
    }
    if (cs == null) {
      return;
    }
    IFocusSelectable current = model.getSelectedSegment();
    if (current == cs) {
      return;
    }
    IHyperlinkSegment oldLink = null;
    if ((current != null) && ((current instanceof IHyperlinkSegment)))
    {
      oldLink = (IHyperlinkSegment)current;
      exitLink(oldLink, 0);
    }
    model.select(cs);
    if (oldLink != null) {
      paintFocusTransfer(oldLink, null);
    }
  }
  
  private boolean advanceControl(Control c, ControlSegment segment, boolean next)
  {
    Composite parent = c.getParent();
    if (parent == this)
    {
      IFocusSelectable nextSegment = model.getNextFocusSegment(next);
      if (nextSegment != null)
      {
        controlFocusTransfer = true;
        super.forceFocus();
        controlFocusTransfer = false;
        model.select(segment);
        return advance(next);
      }
      return setFocusToNextSibling(this, next);
    }
    if (setFocusToNextSibling(c, next)) {
      return true;
    }
    segment = (ControlSegment)parent.getData("__segment__");
    return advanceControl(parent, segment, next);
  }
  
  private boolean setFocusToNextSibling(Control c, boolean next)
  {
    Composite parent = c.getParent();
    Control[] children = parent.getTabList();
    for (int i = 0; i < children.length; i++)
    {
      Control child = children[i];
      if (child == c) {
        if (next) {
          for (int j = i + 1; j < children.length; j++)
          {
            Control nc = children[j];
            if (nc.setFocus()) {
              return false;
            }
          }
        } else {
          for (int j = i - 1; j >= 0; j--)
          {
            Control pc = children[j];
            if (pc.setFocus()) {
              return false;
            }
          }
        }
      }
    }
    return false;
  }
  
  public void setWhitespaceNormalized(boolean value)
  {
    model.setWhitespaceNormalized(value);
  }
  
  public boolean isWhitespaceNormalized()
  {
    return model.isWhitespaceNormalized();
  }
  
  public void setMenu(Menu menu)
  {
    Menu currentMenu = super.getMenu();
    if ((currentMenu != null) && ("__internal_menu__".equals(currentMenu.getData())))
    {
      if (menu != null)
      {
        currentMenu.dispose();
        super.setMenu(menu);
      }
    }
    else {
      super.setMenu(menu);
    }
  }
  
  private void createMenu()
  {
    Menu menu = new Menu(this);
    MenuItem copyItem = new MenuItem(menu, 8);
    copyItem.setText(Messages.FormText_copy);
    
    SelectionListener listener = new SelectionAdapter()
    {
      private final MenuItem val$copyItem;
      
      public void widgetSelected(SelectionEvent e)
      {
        if (widget == val$copyItem) {
          copy();
        }
      }
    };
    copyItem.addSelectionListener(listener);
    menu.addMenuListener(new MenuListener()
    {
      private final MenuItem val$copyItem;
      
      public void menuShown(MenuEvent e)
      {
        val$copyItem.setEnabled(canCopy());
      }
      
      public void menuHidden(MenuEvent e) {}
    });
    menu.setData("__internal_menu__");
    super.setMenu(menu);
  }
  
  public HyperlinkSettings getHyperlinkSettings()
  {
    return model.getHyperlinkSettings();
  }
  
  public void setHyperlinkSettings(HyperlinkSettings settings)
  {
    model.setHyperlinkSettings(settings);
  }
  
  public void addHyperlinkListener(IHyperlinkListener listener)
  {
    if (listeners == null) {
      listeners = new ListenerList();
    }
    listeners.add(listener);
  }
  
  public void removeHyperlinkListener(IHyperlinkListener listener)
  {
    if (listeners == null) {
      return;
    }
    listeners.remove(listener);
  }
  
  public void addSelectionListener(SelectionListener listener)
  {
    checkWidget();
    if (listener == null) {
      SWT.error(4);
    }
    TypedListener typedListener = new TypedListener(listener);
    addListener(13, typedListener);
  }
  
  public void removeSelectionListener(SelectionListener listener)
  {
    checkWidget();
    if (listener == null) {
      SWT.error(4);
    }
    removeListener(13, listener);
  }
  
  public String getSelectionText()
  {
    checkWidget();
    if (selData != null) {
      return selData.getSelectionText();
    }
    return "";
  }
  
  public boolean canCopy()
  {
    return (selData != null) && (selData.canCopy());
  }
  
  public void copy()
  {
    if (!canCopy()) {
      return;
    }
    Clipboard clipboard = new Clipboard(getDisplay());
    Object[] o = { getSelectionText() };
    Transfer[] t = { TextTransfer.getInstance() };
    clipboard.setContents(o, t);
    clipboard.dispose();
  }
  
  public Object getSelectedLinkHref()
  {
    IHyperlinkSegment link = getSelectedLink();
    return link != null ? link.getHref() : null;
  }
  
  public String getSelectedLinkText()
  {
    IHyperlinkSegment link = getSelectedLink();
    return link != null ? link.getText() : null;
  }
  
  private IHyperlinkSegment getSelectedLink()
  {
    IFocusSelectable segment = model.getSelectedSegment();
    if ((segment != null) && ((segment instanceof IHyperlinkSegment))) {
      return (IHyperlinkSegment)segment;
    }
    return null;
  }
  
  private void initAccessible()
  {
    Accessible accessible = getAccessible();
    accessible.addAccessibleListener(new AccessibleAdapter()
    {
      public void getName(AccessibleEvent e)
      {
        if (childID == -1)
        {
          result = model.getAccessibleText();
        }
        else
        {
          int linkCount = model.getHyperlinkCount();
          if ((childID >= 0) && (childID < linkCount))
          {
            IHyperlinkSegment link = model.getHyperlink(childID);
            result = link.getText();
          }
        }
      }
      
      public void getHelp(AccessibleEvent e)
      {
        result = getToolTipText();
        int linkCount = model.getHyperlinkCount();
        if ((result == null) && (childID >= 0) && (childID < linkCount))
        {
          IHyperlinkSegment link = model.getHyperlink(childID);
          result = link.getText();
        }
      }
    });
    accessible.addAccessibleControlListener(new AccessibleControlAdapter()
    {
      public void getChildAtPoint(AccessibleControlEvent e)
      {
        Point pt = toControl(new Point(x, y));
        IHyperlinkSegment link = model.findHyperlinkAt(x, y);
        if (link != null) {
          childID = model.indexOf(link);
        } else {
          childID = -1;
        }
      }
      
      public void getLocation(AccessibleControlEvent e)
      {
        Rectangle location = null;
        if ((childID != -1) && 
          (childID != -2))
        {
          int index = childID;
          IHyperlinkSegment link = model.getHyperlink(index);
          if (link != null) {
            location = link.getBounds();
          }
        }
        if (location == null) {
          location = getBounds();
        }
        Point pt = toDisplay(new Point(x, y));
        x = x;
        y = y;
        width = width;
        height = height;
      }
      
      public void getFocus(AccessibleControlEvent e)
      {
        int childID = -2;
        if (model.hasFocusSegments())
        {
          int selectedIndex = model.getSelectedSegmentIndex();
          if (selectedIndex != -1) {
            childID = selectedIndex;
          }
        }
        childID = childID;
      }
      
      public void getDefaultAction(AccessibleControlEvent e)
      {
        if (model.getHyperlinkCount() > 0) {
          result = SWT.getMessage("SWT_Press");
        }
      }
      
      public void getChildCount(AccessibleControlEvent e)
      {
        detail = model.getHyperlinkCount();
      }
      
      public void getRole(AccessibleControlEvent e)
      {
        int role = 0;
        int childID = childID;
        int linkCount = model.getHyperlinkCount();
        if (childID == -1)
        {
          if (linkCount > 0) {
            role = 30;
          } else {
            role = 42;
          }
        }
        else if ((childID >= 0) && (childID < linkCount)) {
          role = 30;
        }
        detail = role;
      }
      
      public void getSelection(AccessibleControlEvent e)
      {
        int selectedIndex = model.getSelectedSegmentIndex();
        childID = (selectedIndex == -1 ? -2 : 
          selectedIndex);
      }
      
      public void getState(AccessibleControlEvent e)
      {
        int linkCount = model.getHyperlinkCount();
        int selectedIndex = model.getSelectedSegmentIndex();
        int state = 0;
        int childID = childID;
        if (childID == -1)
        {
          state = 0;
        }
        else if ((childID >= 0) && (childID < linkCount))
        {
          state = 2097152;
          if (isFocusControl()) {
            state |= 0x100000;
          }
          if (selectedIndex == childID)
          {
            state |= 0x2;
            if (isFocusControl()) {
              state |= 0x4;
            }
          }
        }
        state |= 0x40;
        detail = state;
      }
      
      public void getChildren(AccessibleControlEvent e)
      {
        int linkCount = model.getHyperlinkCount();
        Object[] children = new Object[linkCount];
        for (int i = 0; i < linkCount; i++) {
          children[i] = new Integer(i);
        }
        children = children;
      }
      
      public void getValue(AccessibleControlEvent e) {}
    });
  }
  
  private void startSelection(MouseEvent e)
  {
    inSelection = true;
    selData = new SelectionData(e);
    redraw();
    Form form = FormUtil.getForm(this);
    if (form != null) {
      form.setSelectionText(this);
    }
  }
  
  private void endSelection(MouseEvent e)
  {
    inSelection = false;
    if (selData != null) {
      if (!selData.isEnclosed()) {
        selData = null;
      } else {
        computeSelection();
      }
    }
    notifySelectionChanged();
  }
  
  private void computeSelection()
  {
    GC gc = new GC(this);
    Paragraph[] paragraphs = model.getParagraphs();
    IHyperlinkSegment selectedLink = getSelectedLink();
    if (getDisplay().getFocusControl() != this) {
      selectedLink = null;
    }
    for (int i = 0; i < paragraphs.length; i++)
    {
      Paragraph p = paragraphs[i];
      if (i > 0) {
        selData.markNewLine();
      }
      p.computeSelection(gc, resourceTable, selectedLink, selData);
    }
    gc.dispose();
  }
  
  void clearSelection()
  {
    selData = null;
    if (!isDisposed())
    {
      redraw();
      notifySelectionChanged();
    }
  }
  
  private void notifySelectionChanged()
  {
    Event event = new Event();
    widget = this;
    display = getDisplay();
    type = 13;
    notifyListeners(13, event);
    if (!isDisposed()) {
      getAccessible().selectionChanged();
    }
  }
  
  private void handleDrag(MouseEvent e)
  {
    if (selData != null)
    {
      ScrolledComposite scomp = FormUtil.getScrolledComposite(this);
      if (scomp != null) {
        FormUtil.ensureVisible(scomp, this, e);
      }
      selData.update(e);
      redraw();
    }
  }
  
  private void handleMouseClick(MouseEvent e, boolean down)
  {
    if (down)
    {
      mouseFocus = true;
      IHyperlinkSegment segmentUnder = model.findHyperlinkAt(x, y);
      if (segmentUnder != null)
      {
        IHyperlinkSegment oldLink = getSelectedLink();
        if (getDisplay().getFocusControl() != this) {
          setFocus();
        }
        model.selectLink(segmentUnder);
        enterLink(segmentUnder, stateMask);
        paintFocusTransfer(oldLink, segmentUnder);
      }
      if (button == 1)
      {
        startSelection(e);
        armed = segmentUnder;
      }
    }
    else
    {
      if (button == 1)
      {
        endSelection(e);
        if (isDisposed()) {
          return;
        }
        IHyperlinkSegment segmentUnder = model
          .findHyperlinkAt(x, y);
        if ((segmentUnder != null) && (armed == segmentUnder) && (selData == null))
        {
          activateLink(segmentUnder, stateMask);
          armed = null;
        }
      }
      mouseFocus = false;
    }
  }
  
  private void handleMouseHover(MouseEvent e) {}
  
  private void updateTooltipText(ParagraphSegment segment)
  {
    String tooltipText = null;
    if (segment != null) {
      tooltipText = segment.getTooltipText();
    }
    String currentTooltipText = getToolTipText();
    if (((currentTooltipText != null) && (tooltipText == null)) || (
      (currentTooltipText == null) && (tooltipText != null))) {
      setToolTipText(tooltipText);
    }
  }
  
  private void handleMouseMove(MouseEvent e)
  {
    if (inSelection)
    {
      handleDrag(e);
      return;
    }
    ParagraphSegment segmentUnder = model.findSegmentAt(x, y);
    updateTooltipText(segmentUnder);
    if (segmentUnder == null)
    {
      if (entered != null)
      {
        exitLink(entered, stateMask);
        paintLinkHover(entered, false);
        entered = null;
      }
      setCursor(null);
    }
    else if ((segmentUnder instanceof IHyperlinkSegment))
    {
      IHyperlinkSegment linkUnder = (IHyperlinkSegment)segmentUnder;
      if ((entered != null) && (linkUnder != entered))
      {
        exitLink(entered, stateMask);
        paintLinkHover(entered, false);
        entered = null;
      }
      if (entered == null)
      {
        entered = linkUnder;
        enterLink(linkUnder, stateMask);
        paintLinkHover(entered, true);
        setCursor(model.getHyperlinkSettings().getHyperlinkCursor());
      }
    }
    else
    {
      if (entered != null)
      {
        exitLink(entered, stateMask);
        paintLinkHover(entered, false);
        entered = null;
      }
      if ((segmentUnder instanceof TextSegment)) {
        setCursor(model.getHyperlinkSettings().getTextCursor());
      } else {
        setCursor(null);
      }
    }
  }
  
  private boolean advanc
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