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

e(boolean next)
  {
    IFocusSelectable current = model.getSelectedSegment();
    if ((current != null) && ((current instanceof IHyperlinkSegment))) {
      exitLink((IHyperlinkSegment)current, 0);
    }
    IFocusSelectable newSegment = null;
    boolean valid = false;
    while (!valid)
    {
      if (!model.traverseFocusSelectableObjects(next)) {
        break;
      }
      newSegment = model.getSelectedSegment();
      if (newSegment == null) {
        break;
      }
      valid = setControlFocus(next, newSegment);
    }
    IHyperlinkSegment newLink = (newSegment instanceof IHyperlinkSegment) ? (IHyperlinkSegment)newSegment : 
      null;
    if (valid) {
      enterLink(newLink, 0);
    }
    IHyperlinkSegment oldLink = (current instanceof IHyperlinkSegment) ? (IHyperlinkSegment)current : 
      null;
    if ((oldLink != null) || (newLink != null)) {
      paintFocusTransfer(oldLink, newLink);
    }
    if (newLink != null) {
      ensureVisible(newLink);
    }
    if (newLink != null) {
      getAccessible().setFocus(model.getSelectedSegmentIndex());
    }
    return !valid;
  }
  
  private boolean setControlFocus(boolean next, IFocusSelectable selectable)
  {
    controlFocusTransfer = true;
    boolean result = selectable.setFocus(resourceTable, next);
    controlFocusTransfer = false;
    return result;
  }
  
  private void handleFocusChange()
  {
    if (hasFocus)
    {
      boolean advance = true;
      if (!mouseFocus)
      {
        boolean valid = false;
        IFocusSelectable selectable = null;
        while (!valid)
        {
          if (!model.traverseFocusSelectableObjects(advance)) {
            break;
          }
          selectable = model.getSelectedSegment();
          if (selectable == null) {
            break;
          }
          valid = setControlFocus(advance, selectable);
        }
        if (selectable != null) {
          ensureVisible(selectable);
        }
        if ((selectable instanceof IHyperlinkSegment))
        {
          enterLink((IHyperlinkSegment)selectable, 0);
          paintFocusTransfer(null, (IHyperlinkSegment)selectable);
        }
      }
    }
    else
    {
      paintFocusTransfer(getSelectedLink(), null);
      model.selectLink(null);
    }
    if (!model.hasFocusSegments()) {
      redraw();
    }
  }
  
  private void enterLink(IHyperlinkSegment link, int stateMask)
  {
    if ((link == null) || (listeners == null)) {
      return;
    }
    int size = listeners.size();
    HyperlinkEvent he = new HyperlinkEvent(this, link.getHref(), link
      .getText(), stateMask);
    Object[] listenerList = listeners.getListeners();
    for (int i = 0; i < size; i++)
    {
      IHyperlinkListener listener = (IHyperlinkListener)listenerList[i];
      listener.linkEntered(he);
    }
  }
  
  private void exitLink(IHyperlinkSegment link, int stateMask)
  {
    if ((link == null) || (listeners == null)) {
      return;
    }
    int size = listeners.size();
    HyperlinkEvent he = new HyperlinkEvent(this, link.getHref(), link
      .getText(), stateMask);
    Object[] listenerList = listeners.getListeners();
    for (int i = 0; i < size; i++)
    {
      IHyperlinkListener listener = (IHyperlinkListener)listenerList[i];
      listener.linkExited(he);
    }
  }
  
  private void paintLinkHover(IHyperlinkSegment link, boolean hover)
  {
    GC gc = new GC(this);
    HyperlinkSettings settings = getHyperlinkSettings();
    Color newFg = hover ? settings.getActiveForeground() : settings
      .getForeground();
    if (newFg != null) {
      gc.setForeground(newFg);
    }
    gc.setBackground(getBackground());
    gc.setFont(getFont());
    boolean selected = link == getSelectedLink();
    ((ParagraphSegment)link).paint(gc, hover, resourceTable, selected, 
      selData, null);
    gc.dispose();
  }
  
  private void activateSelectedLink()
  {
    IHyperlinkSegment link = getSelectedLink();
    if (link != null) {
      activateLink(link, 0);
    }
  }
  
  private void activateLink(IHyperlinkSegment link, int stateMask)
  {
    setCursor(model.getHyperlinkSettings().getBusyCursor());
    if (listeners != null)
    {
      int size = listeners.size();
      HyperlinkEvent e = new HyperlinkEvent(this, link.getHref(), link
        .getText(), stateMask);
      Object[] listenerList = listeners.getListeners();
      for (int i = 0; i < size; i++)
      {
        IHyperlinkListener listener = (IHyperlinkListener)listenerList[i];
        listener.linkActivated(e);
      }
    }
    if ((!isDisposed()) && (model.linkExists(link))) {
      setCursor(model.getHyperlinkSettings().getHyperlinkCursor());
    }
  }
  
  private void ensureBoldFontPresent(Font regularFont)
  {
    Font boldFont = (Font)resourceTable.get("f.____bold");
    if (boldFont != null) {
      return;
    }
    boldFont = FormFonts.getInstance().getBoldFont(getDisplay(), regularFont);
    resourceTable.put("f.____bold", boldFont);
  }
  
  private void paint(PaintEvent e)
  {
    GC gc = gc;
    gc.setFont(getFont());
    ensureBoldFontPresent(getFont());
    gc.setForeground(getForeground());
    gc.setBackground(getBackground());
    repaint(gc, x, y, width, height);
  }
  
  private void repaint(GC gc, int x, int y, int width, int height)
  {
    Image textBuffer = new Image(getDisplay(), width, height);
    Color bg = getBackground();
    Color fg = getForeground();
    if (!getEnabled())
    {
      bg = getDisplay().getSystemColor(22);
      fg = getDisplay().getSystemColor(18);
    }
    GC textGC = new GC(textBuffer, gc.getStyle());
    textGC.setForeground(fg);
    textGC.setBackground(bg);
    textGC.setFont(getFont());
    textGC.fillRectangle(0, 0, width, height);
    Rectangle repaintRegion = new Rectangle(x, y, width, height);
    
    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];
      p
        .paint(textGC, repaintRegion, resourceTable, selectedLink, 
        selData);
    }
    if ((hasFocus) && (!model.hasFocusSegments())) {
      textGC.drawFocus(x, y, width, height);
    }
    textGC.dispose();
    gc.drawImage(textBuffer, x, y);
    textBuffer.dispose();
  }
  
  private int getParagraphSpacing(int lineHeight)
  {
    return lineHeight / 2;
  }
  
  private void paintFocusTransfer(IHyperlinkSegment oldLink, IHyperlinkSegment newLink)
  {
    if (oldLink != null)
    {
      Rectangle r = oldLink.getBounds();
      redraw(x, y, width, height, true);
      update();
    }
    if (newLink != null)
    {
      GC gc = new GC(this);
      Color bg = getBackground();
      Color fg = getForeground();
      gc.setFont(getFont());
      gc.setBackground(bg);
      gc.setForeground(fg);
      newLink.paintFocus(gc, bg, fg, true, null);
      gc.dispose();
    }
  }
  
  private void ensureVisible(IFocusSelectable segment)
  {
    if (mouseFocus)
    {
      mouseFocus = false;
      return;
    }
    if (segment == null) {
      return;
    }
    Rectangle bounds = segment.getBounds();
    ScrolledComposite scomp = FormUtil.getScrolledComposite(this);
    if (scomp == null) {
      return;
    }
    Point origin = FormUtil.getControlLocation(scomp, this);
    x += x;
    y += y;
    FormUtil.ensureVisible(scomp, origin, new Point(width, 
      height));
  }
  
  public Point computeSize(int wHint, int hHint, boolean changed)
  {
    checkWidget();
    
    FormTextLayout layout = (FormTextLayout)getLayout();
    Point size;
    Point size;
    if ((wHint == -1) || (hHint == -1)) {
      size = layout.computeSize(this, wHint, hHint, changed);
    } else {
      size = new Point(wHint, hHint);
    }
    Rectangle trim = computeTrim(0, 0, x, y);
    
    return new Point(width, height);
  }
  
  private void disposeResourceTable(boolean disposeBoldFont)
  {
    if (disposeBoldFont)
    {
      Font boldFont = (Font)resourceTable
        .get("f.____bold");
      if (boldFont != null)
      {
        FormFonts.getInstance().markFinished(boldFont, getDisplay());
        resourceTable.remove("f.____bold");
      }
    }
    ArrayList imagesToRemove = new ArrayList();
    for (Enumeration enm = resourceTable.keys(); enm.hasMoreElements();)
    {
      String key = (String)enm.nextElement();
      if (key.startsWith("isel."))
      {
        Object obj = resourceTable.get(key);
        if ((obj instanceof Image))
        {
          Image image = (Image)obj;
          if (!image.isDisposed())
          {
            image.dispose();
            imagesToRemove.add(key);
          }
        }
      }
    }
    for (int i = 0; i < imagesToRemove.size(); i++) {
      resourceTable.remove(imagesToRemove.get(i));
    }
  }
  
  public void setEnabled(boolean enabled)
  {
    super.setEnabled(enabled);
    redraw();
  }
  
  public boolean setFocus()
  {
    mouseFocus = true;
    FormUtil.setFocusScrollingEnabled(this, false);
    boolean result = super.setFocus();
    mouseFocus = false;
    FormUtil.setFocusScrollingEnabled(this, true);
    return result;
  }
}

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

import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.ui.forms.FormColors;

class FormToolkit$1
  implements Listener
{
  final FormToolkit this$0;
  private final Composite val$composite;
  
  FormToolkit$1(FormToolkit paramFormToolkit, Composite paramComposite)
  {
    this$0 = paramFormToolkit;val$composite = paramComposite;
  }
  
  public void handleEvent(Event e)
  {
    if (val$composite.isDisposed()) {
      return;
    }
    Rectangle bounds = val$composite.getBounds();
    GC gc = gc;
    gc.setForeground(FormToolkit.access$0(this$0).getColor("org.eclipse.ui.forms.SEPARATOR"));
    if (FormToolkit.access$0(this$0).getBackground() != null) {
      gc.setBackground(FormToolkit.access$0(this$0).getBackground());
    }
    gc.fillGradientRectangle(0, 0, width, height, 
      false);
  }
}

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

import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.widgets.Control;

class FormToolkit$2
  extends MouseAdapter
{
  final FormToolkit this$0;
  
  FormToolkit$2(FormToolkit paramFormToolkit)
  {
    this$0 = paramFormToolkit;
  }
  
  public void mouseDown(MouseEvent e)
  {
    ((Control)widget).setFocus();
  }
}

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

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.eclipse.swt.graphics.Font;
import org.eclipse.ui.forms.FormColors;
import org.eclipse.ui.internal.forms.widgets.FormFonts;

class FormToolkit$BoldFontHolder
{
  private Map fontMap;
  final FormToolkit this$0;
  
  public FormToolkit$BoldFontHolder(FormToolkit paramFormToolkit)
  {
    this$0 = paramFormToolkit;
  }
  
  public Font getBoldFont(Font font)
  {
    if (font == null) {
      return null;
    }
    if (fontMap == null) {
      fontMap = new HashMap();
    }
    if (fontMap.containsKey(font)) {
      return (Font)fontMap.get(font);
    }
    Font boldFont = FormFonts.getInstance().getBoldFont(FormToolkit.access$0(this$0).getDisplay(), 
      font);
    fontMap.put(font, boldFont);
    return boldFont;
  }
  
  public void dispose()
  {
    if (fontMap == null) {
      return;
    }
    for (Iterator iter = fontMap.values().iterator(); iter.hasNext();)
    {
      Font boldFont = (Font)iter.next();
      if ((boldFont != null) && (FormToolkit.access$0(this$0).getDisplay() != null))
      {
        FormFonts.getInstance().markFinished(boldFont, 
          FormToolkit.access$0(this$0).getDisplay());
        boldFont = null;
      }
    }
  }
}

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

import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.ui.forms.FormColors;

class FormToolkit$BorderPainter
  implements PaintListener
{
  final FormToolkit this$0;
  
  private FormToolkit$BorderPainter(FormToolkit paramFormToolkit)
  {
    this$0 = paramFormToolkit;
  }
  
  FormToolkit$BorderPainter(FormToolkit paramFormToolkit, BorderPainter paramBorderPainter)
  {
    this(paramFormToolkit);
  }
  
  public void paintControl(PaintEvent event)
  {
    Composite composite = (Composite)widget;
    Control[] children = composite.getChildren();
    for (int i = 0; i < children.length; i++)
    {
      Control c = children[i];
      boolean inactiveBorder = false;
      boolean textBorder = false;
      if (c.isVisible()) {
        if (!(c instanceof Hyperlink))
        {
          Object flag = c.getData("FormWidgetFactory.drawBorder");
          if (flag != null)
          {
            if (flag.equals(Boolean.FALSE)) {
              continue;
            }
            if (flag.equals("treeBorder")) {
              inactiveBorder = true;
            } else if (flag.equals("textBorder")) {
              textBorder = true;
            }
          }
          if (this$0.getBorderStyle() == 2048)
          {
            if ((inactiveBorder) || (textBorder)) {
              if (((c instanceof Text)) || ((c instanceof Table)) || 
                ((c instanceof Tree))) {}
            }
          }
          else if ((!inactiveBorder) && (
            ((c instanceof Text)) || ((c instanceof CCombo)) || (textBorder)))
          {
            Rectangle b = c.getBounds();
            GC gc = gc;
            gc.setForeground(c.getBackground());
            gc.drawRectangle(x - 1, y - 1, width + 1, 
              height + 1);
            
            gc.setForeground(FormToolkit.access$0(this$0).getBorderColor());
            if ((c instanceof CCombo)) {
              gc.drawRectangle(x - 1, y - 1, width + 1, 
                height + 1);
            } else {
              gc.drawRectangle(x - 1, y - 2, width + 1, 
                height + 3);
            }
          }
          else if ((inactiveBorder) || ((c instanceof Table)) || 
            ((c instanceof Tree)))
          {
            Rectangle b = c.getBounds();
            GC gc = gc;
            gc.setForeground(FormToolkit.access$0(this$0).getBorderColor());
            gc.drawRectangle(x - 1, y - 1, width + 1, 
              height + 1);
          }
        }
      }
    }
  }
}

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

import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Widget;
import org.eclipse.ui.internal.forms.widgets.FormUtil;

class FormToolkit$KeyboardHandler
  extends KeyAdapter
{
  FormToolkit$KeyboardHandler(KeyboardHandler paramKeyboardHandler)
  {
    this();
  }
  
  public void keyPressed(KeyEvent e)
  {
    Widget w = widget;
    if (((w instanceof Control)) && 
      (doit)) {
      FormUtil.processKey(keyCode, (Control)w);
    }
  }
  
  private FormToolkit$KeyboardHandler() {}
}

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

import org.eclipse.swt.events.FocusAdapter;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Widget;
import org.eclipse.ui.internal.forms.widgets.FormUtil;

class FormToolkit$VisibilityHandler
  extends FocusAdapter
{
  FormToolkit$VisibilityHandler(VisibilityHandler paramVisibilityHandler)
  {
    this();
  }
  
  private boolean handleNextFocusGained = true;
  
  public void focusGained(FocusEvent e)
  {
    if (!handleNextFocusGained)
    {
      handleNextFocusGained = true;
    }
    else
    {
      Widget w = widget;
      if ((w instanceof Control)) {
        FormUtil.ensureVisible((Control)w);
      }
    }
  }
  
  public void focusLost(FocusEvent e)
  {
    Widget w = widget;
    if ((w instanceof Control)) {
      handleNextFocusGained = (w.getDisplay().getActiveShell() == ((Control)w).getShell());
    }
  }
  
  private FormToolkit$VisibilityHandler() {}
}

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

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.events.FocusAdapter;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Button;
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.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.Widget;
import org.eclipse.ui.forms.FormColors;
import org.eclipse.ui.forms.HyperlinkGroup;
import org.eclipse.ui.internal.forms.widgets.FormFonts;
import org.eclipse.ui.internal.forms.widgets.FormUtil;

public class FormToolkit
{
  public static final String KEY_DRAW_BORDER = "FormWidgetFactory.drawBorder";
  public static final String TREE_BORDER = "treeBorder";
  public static final String TEXT_BORDER = "textBorder";
  private int borderStyle = 0;
  private FormColors colors;
  private int orientation = Window.getDefaultOrientation();
  private BorderPainter borderPainter;
  private BoldFontHolder boldFontHolder;
  private HyperlinkGroup hyperlinkGroup;
  private boolean isDisposed = false;
  VisibilityHandler visibilityHandler;
  KeyboardHandler keyboardHandler;
  
  private class BorderPainter
    implements PaintListener
  {
    BorderPainter(BorderPainter paramBorderPainter)
    {
      this();
    }
    
    public void paintControl(PaintEvent event)
    {
      Composite composite = (Composite)widget;
      Control[] children = composite.getChildren();
      for (int i = 0; i < children.length; i++)
      {
        Control c = children[i];
        boolean inactiveBorder = false;
        boolean textBorder = false;
        if (c.isVisible()) {
          if (!(c instanceof Hyperlink))
          {
            Object flag = c.getData("FormWidgetFactory.drawBorder");
            if (flag != null)
            {
              if (flag.equals(Boolean.FALSE)) {
                continue;
              }
              if (flag.equals("treeBorder")) {
                inactiveBorder = true;
              } else if (flag.equals("textBorder")) {
                textBorder = true;
              }
            }
            if (getBorderStyle() == 2048)
            {
              if ((inactiveBorder) || (textBorder)) {
                if (((c instanceof Text)) || ((c instanceof Table)) || 
                  ((c instanceof Tree))) {}
              }
            }
            else if ((!inactiveBorder) && (
              ((c instanceof Text)) || ((c instanceof CCombo)) || (textBorder)))
            {
              Rectangle b = c.getBounds();
              GC gc = gc;
              gc.setForeground(c.getBackground());
              gc.drawRectangle(x - 1, y - 1, width + 1, 
                height + 1);
              
              gc.setForeground(colors.getBorderColor());
              if ((c instanceof CCombo)) {
                gc.drawRectangle(x - 1, y - 1, width + 1, 
                  height + 1);
              } else {
                gc.drawRectangle(x - 1, y - 2, width + 1, 
                  height + 3);
              }
            }
            else if ((inactiveBorder) || ((c instanceof Table)) || 
              ((c instanceof Tree)))
            {
              Rectangle b = c.getBounds();
              GC gc = gc;
              gc.setForeground(colors.getBorderColor());
              gc.drawRectangle(x - 1, y - 1, width + 1, 
                height + 1);
            }
          }
        }
      }
    }
    
    private BorderPainter() {}
  }
  
  private static class VisibilityHandler
    extends FocusAdapter
  {
    VisibilityHandler(VisibilityHandler paramVisibilityHandler)
    {
      this();
    }
    
    private boolean handleNextFocusGained = true;
    
    public void focusGained(FocusEvent e)
    {
      if (!handleNextFocusGained)
      {
        handleNextFocusGained = true;
      }
      else
      {
        Widget w = widget;
        if ((w instanceof Control)) {
          FormUtil.ensureVisible((Control)w);
        }
      }
    }
    
    public void focusLost(FocusEvent e)
    {
      Widget w = widget;
      if ((w instanceof Control)) {
        handleNextFocusGained = (w.getDisplay().getActiveShell() == ((Control)w).getShell());
      }
    }
    
    private VisibilityHandler() {}
  }
  
  private static class KeyboardHandler
    extends KeyAdapter
  {
    KeyboardHandler(KeyboardHandler paramKeyboardHandler)
    {
      this();
    }
    
    public void keyPressed(KeyEvent e)
    {
      Widget w = widget;
      if (((w instanceof Control)) && 
        (doit)) {
        FormUtil.processKey(keyCode, (Control)w);
      }
    }
    
    private KeyboardHandler() {}
  }
  
  private class BoldFontHolder
  {
    private Map fontMap;
    
    public BoldFontHolder() {}
    
    public Font getBoldFont(Font font)
    {
      if (font == null) {
        return null;
      }
      if (fontMap == null) {
        fontMap = new HashMap();
      }
      if (fontMap.containsKey(font)) {
        return (Font)fontMap.get(font);
      }
      Font boldFont = FormFonts.getInstance().getBoldFont(colors.getDisplay(), 
        font);
      fontMap.put(font, boldFont);
      return boldFont;
    }
    
    public void dispose()
    {
      if (fontMap == null) {
        return;
      }
      for (Iterator iter = fontMap.values().iterator(); iter.hasNext();)
      {
        Font boldFont = (Font)iter.next();
        if ((boldFont != null) && (colors.getDisplay() != null))
        {
          FormFonts.getInstance().markFinished(boldFont, 
            colors.getDisplay());
          boldFont = null;
        }
      }
    }
  }
  
  public FormToolkit(Display display)
  {
    this(new FormColors(display));
  }
  
  public FormToolkit(FormColors colors)
  {
    this.colors = colors;
    initialize();
  }
  
  public Button createButton(Composite parent, String text, int style)
  {
    Button button = new Button(parent, style | 0x800000 | orientation);
    if (text != null) {
      button.setText(text);
    }
    adapt(button, true, true);
    return button;
  }
  
  public Composite createComposite(Composite parent)
  {
    return createComposite(parent, 0);
  }
  
  public Composite createComposite(Composite parent, int style)
  {
    Composite composite = new LayoutComposite(parent, style | orientation);
    adapt(composite);
    return composite;
  }
  
  public Composite createCompositeSeparator(Composite parent)
  {
    Composite composite = new Composite(parent, orientation);
    composite.addListener(9, new Listener()
    {
      private final Composite val$composite;
      
      public void handleEvent(Event e)
      {
        if (val$composite.isDisposed()) {
          return;
        }
        Rectangle bounds = val$composite.getBounds();
        GC gc = gc;
        gc.setForeground(colors.getColor("org.eclipse.ui.forms.SEPARATOR"));
        if (colors.getBackground() != null) {
          gc.setBackground(colors.getBackground());
        }
        gc.fillGradientRectangle(0, 0, width, height, 
          false);
      }
    });
    if ((parent instanceof Section)) {
      ((Section)parent).setSeparatorControl(composite);
    }
    return composite;
  }
  
  public Label createLabel(Composite parent, String text)
  {
    return createLabel(parent, text, 0);
  }
  
  public Label createLabel(Composite parent, String text, int style)
  {
    Label label = new Label(parent, style | orientation);
    if (text != null) {
      label.setText(text);
    }
    adapt(label, false, false);
    return label;
  }
  
  public Hyperlink createHyperlink(Composite parent, String text, int style)
  {
    Hyperlink hyperlink = new Hyperlink(parent, style | orientation);
    if (text != null) {
      hyperlink.setText(text);
    }
    hyperlink.addFocusListener(visibilityHandler);
    hyperlink.addKeyListener(keyboardHandler);
    hyperlinkGroup.add(hyperlink);
    return hyperlink;
  }
  
  public ImageHyperlink createImageHyperlink(Composite parent, int style)
  {
    ImageHyperlink hyperlink = new ImageHyperlink(parent, style | 
      orientation);
    hyperlink.addFocusListener(visibilityHandler);
    hyperlink.addKeyListener(keyboardHandler);
    hyperlinkGroup.add(hyperlink);
    return hyperlink;
  }
  
  public FormText createFormText(Composite parent, boolean trackFocus)
  {
    FormText engine = new FormText(parent, 0x40 | orientation);
    marginWidth = 1;
    marginHeight = 0;
    engine.setHyperlinkSettings(getHyperlinkGroup());
    adapt(engine, trackFocus, true);
    engine.setMenu(parent.getMenu());
    return engine;
  }
  
  public void adapt(Control control, boolean trackFocus, boolean trackKeyboard)
  {
    control.setBackground(colors.getBackground());
    control.setForeground(colors.getForeground());
    if ((control instanceof ExpandableComposite))
    {
      ExpandableComposite ec = (ExpandableComposite)control;
      if (toggle != null)
      {
        if (trackFocus) {
          toggle.addFocusListener(visibilityHandler);
        }
        if (trackKeyboard) {
          toggle.addKeyListener(keyboardHandler);
        }
      }
      if (textLabel != null)
      {
        if (trackFocus) {
          textLabel.addFocusListener(visibilityHandler);
        }
        if (trackKeyboard) {
          textLabel.addKeyListener(keyboardHandler);
        }
      }
      return;
    }
    if (trackFocus) {
      control.addFocusListener(visibilityHandler);
    }
    if (trackKeyboard) {
      control.addKeyListener(keyboardHandler);
    }
  }
  
  public void adapt(Composite composite)
  {
    composite.setBackground(colors.getBackground());
    composite.addMouseListener(new MouseAdapter()
    {
      public void mouseDown(MouseEvent e)
      {
        ((Control)widget).setFocus();
      }
    });
    if (composite.getParent() != null) {
      composite.setMenu(composite.getParent().getMenu());
    }
  }
  
  public static void ensureVisible(Control c)
  {
    FormUtil.ensureVisible(c);
  }
  
  public Section createSection(Composite parent, int sectionStyle)
  {
    Section section = new Section(parent, orientation, sectionStyle);
    section.setMenu(parent.getMenu());
    adapt(section, true, true);
    if (toggle != null)
    {
      toggle.setHoverDecorationColor(colors
        .getColor("org.eclipse.ui.forms.TB_TOGGLE_HOVER"));
      toggle.setDecorationColor(colors
        .getColor("org.eclipse.ui.forms.TB_TOGGLE"));
    }
    section.setFont(boldFontHolder.getBoldFont(parent.getFont()));
    if (((sectionStyle & 0x100) != 0) || 
      ((sectionStyle & 0x200) != 0))
    {
      colors.initializeSectionToolBarColors();
      section.setTitleBarBackground(colors.getColor("org.eclipse.ui.forms.TB_BG"));
      section.setTitleBarBorderColor(colors
        .getColor("org.eclipse.ui.forms.TB_BORDER"));
    }
    section.setTitleBarForeground(colors
      .getColor("org.eclipse.ui.forms.TB_TOGGLE"));
    return section;
  }
  
  public ExpandableComposite createExpandableComposite(Composite parent, int expansionStyle)
  {
    ExpandableComposite ec = new ExpandableComposite(parent, orientation, 
      expansionStyle);
    ec.setMenu(parent.getMenu());
    adapt(ec, true, true);
    ec.setFont(boldFontHolder.getBoldFont(ec.getFont()));
    return ec;
  }
  
  public Label createSeparator(Composite parent, int style)
  {
    Label label = new Label(parent, 0x2 | style | orientation);
    label.setBackground(colors.getBackground());
    label.setForeground(colors.getBorderColor());
    return label;
  }
  
  public Table createTable(Composite parent, int style)
  {
    Table table = new Table(parent, style | borderStyle | orientation);
    adapt(table, false, false);
    
    return table;
  }
  
  public Text createText(Composite parent, String value)
  {
    return createText(parent, value, 4);
  }
  
  public Text createText(Composite parent, String value, int style)
  {
    Text text = new Text(parent, borderStyle | style | orientation);
    if (value != null) {
      text.setText(value);
    }
    text.setForeground(colors.getForeground());
    text.setBackground(colors.getBackground());
    text.addFocusListener(visibilityHandler);
    return text;
  }
  
  public Tree createTree(Composite parent, int style)
  {
    Tree tree = new Tree(parent, borderStyle | style | orientation);
    adapt(tree, false, false);
    
    return tree;
  }
  
  public ScrolledForm createScrolledForm(Composite parent)
  {
    ScrolledForm form = new ScrolledForm(parent, 0x300 | 
      orientation);
    form.setExpandHorizontal(true);
    form.setExpandVertical(true);
    form.setBackground(colors.getBackground());
    form.setForeground(colors.getColor("org.eclipse.ui.forms.TITLE"));
    form.setFont(JFaceResources.getHeaderFont());
    return form;
  }
  
  public Form createForm(Composite parent)
  {
    Form formContent = new Form(parent, orientation);
    formContent.setBackground(colors.getBackground());
    formContent.setForeground(colors.getColor("org.eclipse.ui.forms.TITLE"));
    formContent.setFont(JFaceResources.getHeaderFont());
    return formContent;
  }
  
  public void decorateFormHeading(Form form)
  {
    Color top = colors.getColor("org.eclipse.ui.forms.H_GRADIENT_END");
    Color bot = colors.getColor("org.eclipse.ui.forms.H_GRADIENT_START");
    form.setTextBackground(new Color[] { top, bot }, new int[] { 100 }, 
      true);
    form.setHeadColor("org.eclipse.ui.forms.H_BOTTOM_KEYLINE1", colors
      .getColor("org.eclipse.ui.forms.H_BOTTOM_KEYLINE1"));
    form.setHeadColor("org.eclipse.ui.forms.H_BOTTOM_KEYLINE2", colors
      .getColor("org.eclipse.ui.forms.H_BOTTOM_KEYLINE2"));
    form.setHeadColor("org.eclipse.ui.forms.H_H_HOVER_LIGHT", colors
      .getColor("org.eclipse.ui.forms.H_H_HOVER_LIGHT"));
    form.setHeadColor("org.eclipse.ui.forms.H_H_HOVER_FULL", colors
      .getColor("org.eclipse.ui.forms.H_H_HOVER_FULL"));
    form.setHeadColor("org.eclipse.ui.forms.TB_TOGGLE", colors
      .getColor("org.eclipse.ui.forms.TB_TOGGLE"));
    form.setHeadColor("org.eclipse.ui.forms.TB_TOGGLE_HOVER", colors
      .getColor("org.eclipse.ui.forms.TB_TOGGLE_HOVER"));
    form.setSeparatorVisible(true);
  }
  
  public ScrolledPageBook createPageBook(Composite parent, int style)
  {
    ScrolledPageBook book = new ScrolledPageBook(parent, style | 
      orientation);
    adapt(book, true, true);
    book.setMenu(parent.getMenu());
    return book;
  }
  
  public void dispose()
  {
    if (isDisposed) {
      return;
    }
    isDisposed = true;
    boldFontHolder.dispose();
    if (!colors.isShared())
    {
      colors.dispose();
      colors = null;
    }
  }
  
  public HyperlinkGroup getHyperlinkGroup()
  {
    return hyperlinkGroup;
  }
  
  public void setBackground(Color bg)
  {
    hyperlinkGroup.setBackground(bg);
    colors.setBackground(bg);
  }
  
  public void refreshHyperlinkColors()
  {
    hyperlinkGroup.initializeDefaultForegrounds(colors.getDisplay());
  }
  
  public void paintBordersFor(Composite parent)
  {
    if (borderPainter == null) {
      borderPainter = new BorderPainter(null);
    }
    parent.addPaintListener(borderPainter);
  }
  
  public FormColors getColors()
  {
    return colors;
  }
  
  public int getBorderStyle()
  {
    return borderStyle;
  }
  
  public int getBorderMargin()
  {
    return getBorderStyle() == 2048 ? 0 : 2;
  }
  
  public void setBorderStyle(int style)
  {
    borderStyle = style;
  }
  
  public static void setControlVisible(Control c, boolean verticalOnly)
  {
    ScrolledComposite scomp = FormUtil.getScrolledComposite(c);
    if (scomp == null) {
      return;
    }
    Point location = FormUtil.getControlLocation(scomp, c);
    scomp.setOrigin(location);
  }
  
  private void initialize()
  {
    initializeBorderStyle();
    hyperlinkGroup = new HyperlinkGroup(colors.getDisplay());
    hyperlinkGroup.setBackground(colors.getBackground());
    visibilityHandler = new VisibilityHandler(null);
    keyboardHandler = new KeyboardHandler(null);
    boldFontHolder = new BoldFontHolder();
  }
  
  private void initializeBorderStyle()
  {
    String osname = System.getProperty("os.name");
    String osversion = System.getProperty("os.version");
    if ((osname.startsWith("Windows")) && ("5.1".compareTo(osversion) <= 0))
    {
      RGB rgb = colors.getSystemColor(22);
      if ((red != 212) || (green != 208) || (blue != 200)) {
        borderStyle = 2048;
      }
    }
    else if (osname.startsWith("Mac"))
    {
      borderStyle = 2048;
    }
  }
  
  public int getOrientation()
  {
    return orientation;
  }
  
  public void setOrientation(int orientation)
  {
    this.orientation = orientation;
  }
}

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

import org.eclipse.swt.accessibility.AccessibleAdapter;
import org.eclipse.swt.accessibility.AccessibleEvent;

class Hyperlink$1
  extends AccessibleAdapter
{
  final Hyperlink this$0;
  
  Hyperlink$1(Hyperlink paramHyperlink)
  {
    this$0 = paramHyperlink;
  }
  
  public void getName(AccessibleEvent e)
  {
    result = this$0.getText();
    if (result == null) {
      getHelp(e);
    }
  }
  
  public void getHelp(AccessibleEvent e)
  {
    result = this$0.getToolTipText();
  }
}

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

import org.eclipse.swt.SWT;
import org.eclipse.swt.accessibility.AccessibleControlAdapter;
import org.eclipse.swt.accessibility.AccessibleControlEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;

class Hyperlink$2
  extends AccessibleControlAdapter
{
  final Hyperlink this$0;
  
  Hyperlink$2(Hyperlink paramHyperlink)
  {
    this$0 = paramHyperlink;
  }
  
  public void getChildAtPoint(AccessibleControlEvent e)
  {
    Point pt = this$0.toControl(new Point(x, y));
    childID = (this$0.getBounds().contains(pt) ? -1 : 
      -2);
  }
  
  public void getLocation(AccessibleControlEvent e)
  {
    Rectangle location = this$0.getBounds();
    Point pt = this$0.toDisplay(new Point(x, y));
    x = x;
    y = y;
    width = width;
    height = height;
  }
  
  public void getChildCount(AccessibleControlEvent e)
  {
    detail = 0;
  }
  
  public void getRole(AccessibleControlEvent e)
  {
    detail = 30;
  }
  
  public void getDefaultAction(AccessibleControlEvent e)
  {
    result = SWT.getMessage("SWT_Press");
  }
  
  public void getState(AccessibleControlEvent e)
  {
    int state = 0;
    if (this$0.getSelection()) {
      state = 6;
    }
    detail = state;
  }
}

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

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.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.internal.forms.widgets.FormUtil;

public class Hyperlink
  extends AbstractHyperlink
{
  private String text;
  private static final String ELLIPSIS = "...";
  private boolean underlined;
  private String appToolTipText;
  
  public Hyperlink(Composite parent, int style)
  {
    super(parent, style);
    initAccessible();
  }
  
  protected void initAccessible()
  {
    Accessible accessible = getAccessible();
    accessible.addAccessibleListener(new AccessibleAdapter()
    {
      public void getName(AccessibleEvent e)
      {
        result = getText();
        if (result == null) {
          getHelp(e);
        }
      }
      
      public void getHelp(AccessibleEvent e)
      {
        result = getToolTipText();
      }
    });
    accessible.addAccessibleControlListener(new AccessibleControlAdapter()
    {
      public void getChildAtPoint(AccessibleControlEvent e)
      {
        Point pt = toControl(new Point(x, y));
        childID = (getBounds().contains(pt) ? -1 : 
          -2);
      }
      
      public void getLocation(AccessibleControlEvent e)
      {
        Rectangle location = getBounds();
        Point pt = toDisplay(new Point(x, y));
        x = x;
        y = y;
        width = width;
        height = height;
      }
      
      public void getChildCount(AccessibleControlEvent e)
      {
        detail = 0;
      }
      
      public void getRole(AccessibleControlEvent e)
      {
        detail = 30;
      }
      
      public void getDefaultAction(AccessibleControlEvent e)
      {
        result = SWT.getMessage("SWT_Press");
      }
      
      public void getState(AccessibleControlEvent e)
      {
        int state = 0;
        if (getSelection()) {
          state = 6;
        }
        detail = state;
      }
    });
  }
  
  public void setUnderlined(boolean underlined)
  {
    this.underlined = underlined;
    redraw();
  }
  
  public boolean isUnderlined()
  {
    return underlined;
  }
  
  public Point computeSize(int wHint, int hHint, boolean changed)
  {
    checkWidget();
    int innerWidth = wHint;
    if (innerWidth != -1) {
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