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

l Point NULL_SIZE = new Point(0, 0);
  private static final int VSPACE = 3;
  private static final int SEPARATOR_HEIGHT = 2;
  private int expansionStyle = 74;
  private boolean expanded;
  private Control textClient;
  private Control client;
  private ListenerList listeners = new ListenerList();
  private Color titleBarForeground;
  
  private class ExpandableLayout
    extends Layout
    implements ILayoutExtension
  {
    ExpandableLayout(ExpandableLayout paramExpandableLayout)
    {
      this();
    }
    
    private SizeCache toggleCache = new SizeCache();
    private SizeCache textClientCache = new SizeCache();
    private SizeCache textLabelCache = new SizeCache();
    private SizeCache descriptionCache = new SizeCache();
    private SizeCache clientCache = new SizeCache();
    
    private void initCache(boolean shouldFlush)
    {
      toggleCache.setControl(toggle);
      textClientCache.setControl(textClient);
      textLabelCache.setControl(textLabel);
      descriptionCache.setControl(getDescriptionControl());
      clientCache.setControl(client);
      if (shouldFlush)
      {
        toggleCache.flush();
        textClientCache.flush();
        textLabelCache.flush();
        descriptionCache.flush();
        clientCache.flush();
      }
    }
    
    protected void layout(Composite parent, boolean changed)
    {
      initCache(changed);
      
      Rectangle clientArea = parent.getClientArea();
      int thmargin = 0;
      int tvmargin = 0;
      if (hasTitleBar())
      {
        thmargin = titleBarTextMarginWidth;
        tvmargin = 3;
      }
      int x = marginWidth + thmargin;
      int y = marginHeight + tvmargin;
      Point tsize = ExpandableComposite.NULL_SIZE;
      Point tcsize = ExpandableComposite.NULL_SIZE;
      if (toggle != null) {
        tsize = toggleCache.computeSize(-1, -1);
      }
      int twidth = width - marginWidth - marginWidth - 
        thmargin - thmargin;
      if (x > 0) {
        twidth -= x + 4;
      }
      if (textClient != null) {
        tcsize = textClientCache.computeSize(-1, -1);
      }
      Point size = ExpandableComposite.NULL_SIZE;
      if (textLabel != null) {
        if ((x > 0) && (FormUtil.isWrapControl(textClient)))
        {
          size = textLabelCache.computeSize(-1, -1);
          if (twidth < x + 4 + x)
          {
            twidth -= 4;
            if ((textLabel instanceof Label))
            {
              GC gc = new GC(textLabel);
              size = FormUtil.computeWrapSize(gc, ((Label)textLabel).getText(), Math.round(twidth * (x / (x + x))));
              gc.dispose();
            }
            else
            {
              size = textLabelCache.computeSize(Math.round(twidth * (x / (x + x))), -1);
            }
            tcsize = textClientCache.computeSize(twidth - x, -1);
          }
        }
        else
        {
          if (x > 0) {
            twidth -= x + 4;
          }
          size = textLabelCache.computeSize(twidth, -1);
        }
      }
      if ((textLabel instanceof Label))
      {
        Point defSize = textLabelCache.computeSize(-1, 
          -1);
        if (y == y) {
          x = Math.min(x, x);
        }
      }
      if (toggle != null)
      {
        GC gc = new GC(ExpandableComposite.this);
        gc.setFont(getFont());
        FontMetrics fm = gc.getFontMetrics();
        int textHeight = fm.getHeight();
        gc.dispose();
        if ((textClient != null) && 
          ((expansionStyle & 0x2000) != 0)) {
          textHeight = Math.max(textHeight, y);
        }
        int ty = textHeight / 2 - y / 2 + 1;
        ty = Math.max(ty, 0);
        ty += marginHeight + tvmargin;
        toggle.setLocation(x, ty);
        toggle.setSize(tsize);
        x += x + 4;
      }
      if (textLabel != null)
      {
        int ty = y;
        if ((textClient != null) && 
          ((expansionStyle & 0x2000) != 0) && 
          (y < y)) {
          ty = y / 2 - y / 2 + marginHeight + 
            tvmargin;
        }
        String os = System.getProperty("os.name");
        if ("linux".equalsIgnoreCase(os)) {
          x += 1;
        }
        textLabelCache.setBounds(x, ty, x, y);
      }
      if (textClient != null)
      {
        int tcx;
        int tcx;
        if ((expansionStyle & 0x2000) != 0) {
          tcx = x + x + GAP;
        } else {
          tcx = width - x - marginWidth - thmargin;
        }
        textClientCache.setBounds(tcx, y, x, y);
      }
      int tbarHeight = 0;
      if (y > 0) {
        tbarHeight = y;
      }
      if (y > 0) {
        tbarHeight = Math.max(tbarHeight, y);
      }
      y += tbarHeight;
      if (hasTitleBar()) {
        y += tvmargin;
      }
      if (getSeparatorControl() != null)
      {
        y += 3;
        getSeparatorControl().setBounds(marginWidth, y, 
          width - marginWidth - marginWidth, 
          2);
        y += 2;
        if (expanded) {
          y += 3;
        }
      }
      if (expanded)
      {
        int areaWidth = width - marginWidth - thmargin;
        int cx = marginWidth + thmargin;
        if ((expansionStyle & 0x10) != 0) {
          cx = x;
        }
        areaWidth -= cx;
        if (client != null)
        {
          Point dsize = null;
          Control desc = getDescriptionControl();
          if (desc != null)
          {
            dsize = descriptionCache.computeSize(areaWidth, 
              -1);
            y += descriptionVerticalSpacing;
            descriptionCache.setBounds(cx, y, areaWidth, y);
            y += y + clientVerticalSpacing;
          }
          else
          {
            y += clientVerticalSpacing;
            if (getSeparatorControl() != null) {
              y -= 3;
            }
          }
          int cwidth = areaWidth;
          int cheight = height - marginHeight - 
            marginHeight - y;
          clientCache.setBounds(cx, y, cwidth, cheight);
        }
      }
    }
    
    protected Point computeSize(Composite parent, int wHint, int hHint, boolean changed)
    {
      initCache(changed);
      
      int width = 0;int height = 0;
      Point tsize = ExpandableComposite.NULL_SIZE;
      int twidth = 0;
      if (toggle != null)
      {
        tsize = toggleCache.computeSize(-1, -1);
        twidth = x + 4;
      }
      int thmargin = 0;
      int tvmargin = 0;
      if (hasTitleBar())
      {
        thmargin = titleBarTextMarginWidth;
        tvmargin = 3;
      }
      int innerwHint = wHint;
      if (innerwHint != -1) {
        innerwHint = innerwHint - (twidth + marginWidth + marginWidth + thmargin + thmargin);
      }
      int innertHint = innerwHint;
      
      Point tcsize = ExpandableComposite.NULL_SIZE;
      if (textClient != null) {
        tcsize = textClientCache.computeSize(-1, -1);
      }
      Point size = ExpandableComposite.NULL_SIZE;
      if (textLabel != null) {
        if ((x > 0) && (FormUtil.isWrapControl(textClient)))
        {
          size = textLabelCache.computeSize(-1, -1);
          if ((innertHint != -1) && (innertHint < x + 4 + x))
          {
            innertHint -= 4;
            if ((textLabel instanceof Label))
            {
              GC gc = new GC(textLabel);
              size = FormUtil.computeWrapSize(gc, ((Label)textLabel).getText(), Math.round(innertHint * (x / (x + x))));
              gc.dispose();
            }
            else
            {
              size = textLabelCache.computeSize(Math.round(innertHint * (x / (x + x))), -1);
            }
            tcsize = textClientCache.computeSize(innertHint - x, -1);
          }
        }
        else
        {
          if ((innertHint != -1) && (x > 0)) {
            innertHint -= 4 + x;
          }
          size = textLabelCache.computeSize(innertHint, -1);
        }
      }
      if ((textLabel instanceof Label))
      {
        Point defSize = textLabelCache.computeSize(-1, 
          -1);
        if (y == y) {
          x = Math.min(x, x);
        }
      }
      if (x > 0) {
        width = x;
      }
      if (x > 0) {
        width += 4 + x;
      }
      if (toggle != null) {
        width += twidth;
      }
      height = y > 0 ? Math.max(y, y) : y;
      if (getSeparatorControl() != null)
      {
        height += 5;
        if ((expanded) && (client != null)) {
          height += 3;
        }
      }
      if (((expanded) || ((expansionStyle & 0x20) == 0)) && (client != null))
      {
        int cwHint = wHint;
        int clientIndent = 0;
        if ((expansionStyle & 0x10) != 0) {
          clientIndent = twidth;
        }
        if (cwHint != -1)
        {
          cwHint -= marginWidth + marginWidth + thmargin + thmargin;
          if (((expansionStyle & 0x10) != 0) && 
            (x > 0)) {
            cwHint -= twidth;
          }
        }
        Point dsize = null;
        Point csize = clientCache.computeSize(FormUtil.getWidthHint(
          cwHint, client), -1);
        if (getDescriptionControl() != null)
        {
          int dwHint = cwHint;
          if (dwHint == -1)
          {
            dwHint = x;
            if ((expansionStyle & 0x10) != 0) {
              dwHint -= twidth;
            }
          }
          dsize = descriptionCache.computeSize(dwHint, -1);
        }
        if (dsize != null)
        {
          width = Math.max(width, x + clientIndent);
          if (expanded) {
            height = height + (descriptionVerticalSpacing + y + clientVerticalSpacing);
          }
        }
        else
        {
          height += clientVerticalSpacing;
          if (getSeparatorControl() != null) {
            height -= 3;
          }
        }
        width = Math.max(width, x + clientIndent);
        if (expanded) {
          height += y;
        }
      }
      if (toggle != null) {
        height = height - y + Math.max(y, y);
      }
      Point result = new Point(width + marginWidth + marginWidth + 
        thmargin + thmargin, height + marginHeight + marginHeight + 
        tvmargin + tvmargin);
      return result;
    }
    
    public int computeMinimumWidth(Composite parent, boolean changed)
    {
      return computeSize0-1x;
    }
    
    public int computeMaximumWidth(Composite parent, boolean changed)
    {
      return computeSize-1-1x;
    }
    
    private ExpandableLayout() {}
  }
  
  public ExpandableComposite(Composite parent, int style)
  {
    this(parent, style, 2);
  }
  
  public ExpandableComposite(Composite parent, int style, int expansionStyle)
  {
    super(parent, style);
    this.expansionStyle = expansionStyle;
    if ((expansionStyle & 0x100) != 0) {
      setBackgroundMode(1);
    }
    super.setLayout(new ExpandableLayout(null));
    if (hasTitleBar()) {
      addPaintListener(new PaintListener()
      {
        public void paintControl(PaintEvent e)
        {
          onPaint(e);
        }
      });
    }
    if ((expansionStyle & 0x2) != 0) {
      toggle = new Twistie(this, 0);
    } else if ((expansionStyle & 0x4) != 0) {
      toggle = new TreeNode(this, 0);
    } else {
      expanded = true;
    }
    if ((expansionStyle & 0x40) != 0) {
      expanded = true;
    }
    if (toggle != null)
    {
      toggle.setExpanded(expanded);
      toggle.addHyperlinkListener(new HyperlinkAdapter()
      {
        public void linkActivated(HyperlinkEvent e)
        {
          ExpandableComposite.this.toggleState();
        }
      });
      toggle.addPaintListener(new PaintListener()
      {
        public void paintControl(PaintEvent e)
        {
          if (((textLabel instanceof Label)) && (!isFixedStyle())) {
            textLabel.setForeground(toggle.hover ? toggle
              .getHoverDecorationColor() : 
              getTitleBarForeground());
          }
        }
      });
      toggle.addKeyListener(new KeyAdapter()
      {
        public void keyPressed(KeyEvent e)
        {
          if (keyCode == 16777217)
          {
            ExpandableComposite.this.verticalMove(false);
            doit = false;
          }
          else if (keyCode == 16777218)
          {
            ExpandableComposite.this.verticalMove(true);
            doit = false;
          }
        }
      });
      if ((getExpansionStyle() & 0x8) == 0)
      {
        toggle.paintFocus = false;
        toggle.addFocusListener(new FocusListener()
        {
          public void focusGained(FocusEvent e)
          {
            if (textLabel != null) {
              textLabel.redraw();
            }
          }
          
          public void focusLost(FocusEvent e)
          {
            if (textLabel != null) {
              textLabel.redraw();
            }
          }
        });
      }
    }
    if ((expansionStyle & 0x8) != 0)
    {
      Hyperlink link = new Hyperlink(this, 64);
      link.addHyperlinkListener(new HyperlinkAdapter()
      {
        public void linkActivated(HyperlinkEvent e)
        {
          ExpandableComposite.this.programmaticToggleState();
        }
      });
      textLabel = link;
    }
    else if ((expansionStyle & 0x1000) == 0)
    {
      Label label = new Label(this, 64);
      if (!isFixedStyle())
      {
        label.setCursor(FormsResources.getHandCursor());
        Listener listener = new Listener()
        {
          private final Label val$label;
          
          public void handleEvent(Event e)
          {
            switch (type)
            {
            case 3: 
              if (toggle != null) {
                toggle.setFocus();
              }
              break;
            case 4: 
              val$label.setCursor(FormsResources.getBusyCursor());
              ExpandableComposite.this.programmaticToggleState();
              val$label.setCursor(FormsResources.getHandCursor());
              break;
            case 6: 
              if (toggle != null)
              {
                val$label.setForeground(toggle
                  .getHoverDecorationColor());
                toggle.hover = true;
                toggle.redraw();
              }
              break;
            case 7: 
              if (toggle != null)
              {
                val$label.setForeground(getTitleBarForeground());
                toggle.hover = false;
                toggle.redraw();
              }
              break;
            case 9: 
              if ((toggle != null) && ((getExpansionStyle() & 0x4000) == 0)) {
                ExpandableComposite.this.paintTitleFocus(gc);
              }
              break;
            }
          }
        };
        label.addListener(3, listener);
        label.addListener(4, listener);
        label.addListener(6, listener);
        label.addListener(7, listener);
        label.addListener(9, listener);
      }
      textLabel = label;
    }
    if (textLabel != null)
    {
      textLabel.setMenu(getMenu());
      textLabel.addTraverseListener(new TraverseListener()
      {
        public void keyTraversed(TraverseEvent e)
        {
          if (detail == 128)
          {
            if ((!isVisible()) || (!isEnabled())) {
              return;
            }
            if (FormUtil.mnemonicMatch(getText(), character))
            {
              doit = false;
              if (!isFixedStyle()) {
                ExpandableComposite.this.programmaticToggleState();
              }
              setFocus();
            }
          }
        }
      });
    }
  }
  
  public boolean forceFocus()
  {
    return false;
  }
  
  public void setMenu(Menu menu)
  {
    if (textLabel != null) {
      textLabel.setMenu(menu);
    }
    super.setMenu(menu);
  }
  
  public final void setLayout(Layout layout) {}
  
  public void setBackground(Color bg)
  {
    super.setBackground(bg);
    if ((getExpansionStyle() & 0x100) == 0)
    {
      if (textLabel != null) {
        textLabel.setBackground(bg);
      }
      if (toggle != null) {
        toggle.setBackground(bg);
      }
    }
  }
  
  public void setForeground(Color fg)
  {
    super.setForeground(fg);
    if (textLabel != null) {
      textLabel.setForeground(fg);
    }
    if (toggle != null) {
      toggle.setForeground(fg);
    }
  }
  
  public void setToggleColor(Color c)
  {
    if (toggle != null) {
      toggle.setDecorationColor(c);
    }
  }
  
  public void setActiveToggleColor(Color c)
  {
    if (toggle != null) {
      toggle.setHoverDecorationColor(c);
    }
  }
  
  public void setFont(Font font)
  {
    super.setFont(font);
    if (textLabel != null) {
      textLabel.setFont(font);
    }
    if (toggle != null) {
      toggle.setFont(font);
    }
  }
  
  public void setEnabled(boolean enabled)
  {
    if (textLabel != null) {
      textLabel.setEnabled(enabled);
    }
    if (toggle != null) {
      toggle.setEnabled(enabled);
    }
    super.setEnabled(enabled);
  }
  
  public void setClient(Control client)
  {
    Assert.isTrue((client != null) && (client.getParent().equals(this)));
    this.client = client;
  }
  
  public Control getClient()
  {
    return client;
  }
  
  public void setText(String title)
  {
    if ((textLabel instanceof Label)) {
      ((Label)textLabel).setText(title);
    } else if ((textLabel instanceof Hyperlink)) {
      ((Hyperlink)textLabel).setText(title);
    } else {
      return;
    }
    layout();
  }
  
  public String getText()
  {
    if ((textLabel instanceof Label)) {
      return ((Label)textLabel).getText();
    }
    if ((textLabel instanceof Hyperlink)) {
      return ((Hyperlink)textLabel).getText();
    }
    return "";
  }
  
  public boolean isExpanded()
  {
    return expanded;
  }
  
  public int getExpansionStyle()
  {
    return expansionStyle;
  }
  
  public void setExpanded(boolean expanded)
  {
    internalSetExpanded(expanded);
    if (toggle != null) {
      toggle.setExpanded(expanded);
    }
  }
  
  protected void internalSetExpanded(boolean expanded)
  {
    if (this.expanded != expanded)
    {
      this.expanded = expanded;
      if (getDescriptionControl() != null) {
        getDescriptionControl().setVisible(expanded);
      }
      if (client != null) {
        client.setVisible(expanded);
      }
      layout();
    }
  }
  
  public void addExpansionListener(IExpansionListener listener)
  {
    listeners.add(listener);
  }
  
  public void removeExpansionListener(IExpansionListener listener)
  {
    listeners.remove(listener);
  }
  
  protected void onPaint(PaintEvent e) {}
  
  protected Control getDescriptionControl()
  {
    return null;
  }
  
  protected Control getSeparatorControl()
  {
    return null;
  }
  
  public Point computeSize(int wHint, int hHint, boolean changed)
  {
    checkWidget();
    
    ExpandableLayout layout = (ExpandableLayout)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);
  }
  
  protected boolean isFixedStyle()
  {
    return ((expansionStyle & 0x2) == 0) && ((expansionStyle & 0x4) == 0);
  }
  
  public Control getTextClient()
  {
    return textClient;
  }
  
  public void setTextClient(Control textClient)
  {
    if (this.textClient != null) {
      this.textClient.dispose();
    }
    this.textClient = textClient;
  }
  
  public int getTextClientHeightDifference()
  {
    if ((textClient == null) || (textLabel == null)) {
      return 0;
    }
    int theight = textLabel.computeSize(-1, -1).y;
    int tcheight = textClient.computeSize(-1, -1).y;
    return Math.max(tcheight - theight, 0);
  }
  
  protected boolean hasTitleBar()
  {
    return ((getExpansionStyle() & 0x100) != 0) || ((getExpansionStyle() & 0x200) != 0);
  }
  
  public void setTitleBarForeground(Color color)
  {
    if (hasTitleBar()) {
      titleBarForeground = color;
    }
    if (textLabel != null) {
      textLabel.setForeground(color);
    }
  }
  
  public Color getTitleBarForeground()
  {
    return titleBarForeground;
  }
  
  private void toggleState()
  {
    boolean newState = !isExpanded();
    fireExpanding(newState, true);
    internalSetExpanded(newState);
    fireExpanding(newState, false);
    if (newState) {
      FormUtil.ensureVisible(this);
    }
  }
  
  private void fireExpanding(boolean state, boolean before)
  {
    int size = listeners.size();
    if (size == 0) {
      return;
    }
    ExpansionEvent e = new ExpansionEvent(this, state);
    Object[] listenerList = listeners.getListeners();
    for (int i = 0; i < size; i++)
    {
      IExpansionListener listener = (IExpansionListener)listenerList[i];
      if (before) {
        listener.expansionStateChanging(e);
      } else {
        listener.expansionStateChanged(e);
      }
    }
  }
  
  private void verticalMove(boolean down)
  {
    Composite parent = getParent();
    Control[] children = parent.getChildren();
    for (int i = 0; i < children.length; i++)
    {
      Control child = children[i];
      if (child == this)
      {
        ExpandableComposite sibling = getSibling(children, i, down);
        if ((sibling == null) || (toggle == null)) {
          break;
        }
        sibling.setFocus();
        
        break;
      }
    }
  }
  
  private ExpandableComposite getSibling(Control[] children, int index, boolean down)
  {
    int loc = down ? index + 1 : index - 1;
    while ((loc >= 0) && (loc < children.length))
    {
      Control c = children[loc];
      if (((c instanceof ExpandableComposite)) && (c.isVisible())) {
        return (ExpandableComposite)c;
      }
      loc = down ? loc + 1 : loc - 1;
    }
    return null;
  }
  
  private void programmaticToggleState()
  {
    if (toggle != null) {
      toggle.setExpanded(!toggle.isExpanded());
    }
    toggleState();
  }
  
  private void paintTitleFocus(GC gc)
  {
    Point size = textLabel.getSize();
    gc.setBackground(textLabel.getBackground());
    gc.setForeground(textLabel.getForeground());
    if (toggle.isFocusControl()) {
      gc.drawFocus(0, 0, x, y);
    }
  }
}

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

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.FormUtil;

class Form$FormLayout
  extends Layout
  implements ILayoutExtension
{
  final Form this$0;
  
  private Form$FormLayout(Form paramForm)
  {
    this$0 = paramForm;
  }
  
  Form$FormLayout(Form paramForm, FormLayout paramFormLayout)
  {
    this(paramForm);
  }
  
  public int computeMinimumWidth(Composite composite, boolean flushCache)
  {
    return computeSize5-1x;
  }
  
  public int computeMaximumWidth(Composite composite, boolean flushCache)
  {
    return computeSize-1-1x;
  }
  
  public Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache)
  {
    if (flushCache)
    {
      Form.access$0(this$0).flush();
      Form.access$1(this$0).flush();
    }
    Form.access$0(this$0).setControl(Form.access$2(this$0));
    Form.access$1(this$0).setControl(Form.access$3(this$0));
    
    int width = 0;
    int height = 0;
    
    Point hsize = Form.access$1(this$0).computeSize(FormUtil.getWidthHint(wHint, 
      Form.access$3(this$0)), -1);
    width = Math.max(x, width);
    height = y;
    
    boolean ignoreBody = this$0.getData("__ignore_body__") != null;
    Point bsize;
    Point bsize;
    if (ignoreBody) {
      bsize = new Point(0, 0);
    } else {
      bsize = Form.access$0(this$0).computeSize(FormUtil.getWidthHint(wHint, 
        Form.access$2(this$0)), -1);
    }
    width = Math.max(x, width);
    height += y;
    return new Point(width, height);
  }
  
  protected void layout(Composite composite, boolean flushCache)
  {
    if (flushCache)
    {
      Form.access$0(this$0).flush();
      Form.access$1(this$0).flush();
    }
    Form.access$0(this$0).setControl(Form.access$2(this$0));
    Form.access$1(this$0).setControl(Form.access$3(this$0));
    Rectangle carea = composite.getClientArea();
    
    Point hsize = Form.access$1(this$0).computeSize(width, -1);
    Form.access$1(this$0).setBounds(0, 0, width, y);
    Form.access$0(this$0)
      .setBounds(0, y, width, height - y);
  }
}

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

import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.swt.dnd.DragSourceListener;
import org.eclipse.swt.dnd.DropTargetListener;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Layout;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.ui.forms.IMessage;
import org.eclipse.ui.forms.IMessageManager;
import org.eclipse.ui.forms.events.IHyperlinkListener;
import org.eclipse.ui.internal.forms.MessageManager;
import org.eclipse.ui.internal.forms.widgets.FormHeading;
import org.eclipse.ui.internal.forms.widgets.FormUtil;

public class Form
  extends Composite
{
  private FormHeading head;
  private Composite body;
  private SizeCache bodyCache = new SizeCache();
  private SizeCache headCache = new SizeCache();
  private FormText selectionText;
  private MessageManager messageManager;
  
  private class FormLayout
    extends Layout
    implements ILayoutExtension
  {
    FormLayout(FormLayout paramFormLayout)
    {
      this();
    }
    
    public int computeMinimumWidth(Composite composite, boolean flushCache)
    {
      return computeSize5-1x;
    }
    
    public int computeMaximumWidth(Composite composite, boolean flushCache)
    {
      return computeSize-1-1x;
    }
    
    public Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache)
    {
      if (flushCache)
      {
        bodyCache.flush();
        headCache.flush();
      }
      bodyCache.setControl(body);
      headCache.setControl(head);
      
      int width = 0;
      int height = 0;
      
      Point hsize = headCache.computeSize(FormUtil.getWidthHint(wHint, 
        head), -1);
      width = Math.max(x, width);
      height = y;
      
      boolean ignoreBody = getData("__ignore_body__") != null;
      Point bsize;
      Point bsize;
      if (ignoreBody) {
        bsize = new Point(0, 0);
      } else {
        bsize = bodyCache.computeSize(FormUtil.getWidthHint(wHint, 
          body), -1);
      }
      width = Math.max(x, width);
      height += y;
      return new Point(width, height);
    }
    
    protected void layout(Composite composite, boolean flushCache)
    {
      if (flushCache)
      {
        bodyCache.flush();
        headCache.flush();
      }
      bodyCache.setControl(body);
      headCache.setControl(head);
      Rectangle carea = composite.getClientArea();
      
      Point hsize = headCache.computeSize(width, -1);
      headCache.setBounds(0, 0, width, y);
      bodyCache
        .setBounds(0, y, width, height - y);
    }
    
    private FormLayout() {}
  }
  
  public Form(Composite parent, int style)
  {
    super(parent, 0x40000 | style);
    super.setLayout(new FormLayout(null));
    head = new FormHeading(this, 0);
    head.setMenu(parent.getMenu());
    body = new LayoutComposite(this, 0);
    body.setMenu(parent.getMenu());
  }
  
  public void setMenu(Menu menu)
  {
    super.setMenu(menu);
    head.setMenu(menu);
    body.setMenu(menu);
  }
  
  public final Point computeSize(int wHint, int hHint, boolean changed)
  {
    return ((FormLayout)getLayout()).computeSize(this, wHint, hHint, 
      changed);
  }
  
  public final void setLayout(Layout layout) {}
  
  public String getText()
  {
    return head.getText();
  }
  
  public Image getImage()
  {
    return head.getImage();
  }
  
  public void setForeground(Color fg)
  {
    super.setForeground(fg);
    head.setForeground(fg);
    body.setForeground(fg);
  }
  
  public void setBackground(Color bg)
  {
    super.setBackground(bg);
    head.setBackground(bg);
    body.setBackground(bg);
  }
  
  public void setFont(Font font)
  {
    super.setFont(font);
    head.setFont(font);
  }
  
  public void setText(String text)
  {
    head.setText(text);
    layout();
    redraw();
  }
  
  public void setImage(Image image)
  {
    head.setImage(image);
    layout();
    redraw();
  }
  
  public void setTextBackground(Color[] gradientColors, int[] percents, boolean vertical)
  {
    head.setTextBackground(gradientColors, percents, vertical);
  }
  
  public Image getBackgroundImage()
  {
    return head.getHeadingBackgroundImage();
  }
  
  public void setBackgroundImage(Image backgroundImage)
  {
    head.setHeadingBackgroundImage(backgroundImage);
  }
  
  public IToolBarManager getToolBarManager()
  {
    return head.getToolBarManager();
  }
  
  public void setToolBarVerticalAlignment(int alignment)
  {
    head.setToolBarAlignment(alignment);
  }
  
  public int getToolBarVerticalAlignment()
  {
    return head.getToolBarAlignment();
  }
  
  public IMenuManager getMenuManager()
  {
    return head.getMenuManager();
  }
  
  public void updateToolBar()
  {
    head.updateToolBar();
  }
  
  public Composite getHead()
  {
    return head;
  }
  
  public Control getHeadClient()
  {
    return head.getHeadClient();
  }
  
  public void setHeadClient(Control headClient)
  {
    head.setHeadClient(headClient);
    layout();
  }
  
  public Composite getBody()
  {
    return body;
  }
  
  public boolean isBackgroundImageTiled()
  {
    return head.isBackgroundImageTiled();
  }
  
  public void setBackgroundImageTiled(boolean backgroundImageTiled)
  {
    head.setBackgroundImageTiled(backgroundImageTiled);
  }
  
  /**
   * @deprecated
   */
  public int getBackgroundImageAlignment()
  {
    return 16384;
  }
  
  /**
   * @deprecated
   */
  public void setBackgroundImageAlignment(int backgroundImageAlignment) {}
  
  /**
   * @deprecated
   */
  public boolean isBackgroundImageClipped()
  {
    return true;
  }
  
  /**
   * @deprecated
   */
  public void setBackgroundImageClipped(boolean backgroundImageClipped) {}
  
  public boolean isSeparatorVisible()
  {
    return head.isSeparatorVisible();
  }
  
  public void setSeparatorVisible(boolean addSeparator)
  {
    head.setSeparatorVisible(addSeparator);
  }
  
  /**
   * @deprecated
   */
  public Color getSeparatorColor()
  {
    return head.getColor("org.eclipse.ui.forms.H_BOTTOM_KEYLINE2");
  }
  
  /**
   * @deprecated
   */
  public void setSeparatorColor(Color separatorColor)
  {
    head.putColor("org.eclipse.ui.forms.H_BOTTOM_KEYLINE2", separatorColor);
  }
  
  public void setHeadColor(String key, Color color)
  {
    head.putColor(key, color);
  }
  
  public Color getHeadColor(String key)
  {
    return head.getColor(key);
  }
  
  public void setMessage(String message)
  {
    setMessage(message, 0, null);
  }
  
  public void setMessage(String newMessage, int newType)
  {
    setMessage(newMessage, newType, null);
  }
  
  public void setMessage(String newMessage, int newType, IMessage[] children)
  {
    head.showMessage(newMessage, newType, children);
    layout();
  }
  
  public void addMessageHyperlinkListener(IHyperlinkListener listener)
  {
    head.addMessageHyperlinkListener(listener);
  }
  
  public void removeMessageHyperlinkListener(IHyperlinkListener listener)
  {
    head.removeMessageHyperlinkListener(listener);
  }
  
  public boolean isBusy()
  {
    return head.isBusy();
  }
  
  public void setBusy(boolean busy)
  {
    head.setBusy(busy);
  }
  
  public void addTitleDragSupport(int operations, Transfer[] transferTypes, DragSourceListener listener)
  {
    head.addDragSupport(operations, transferTypes, listener);
  }
  
  public void addTitleDropSupport(int operations, Transfer[] transferTypes, DropTargetListener listener)
  {
    head.addDropSupport(operations, transferTypes, listener);
  }
  
  public String getMessage()
  {
    return head.getMessage();
  }
  
  public int getMessageType()
  {
    return head.getMessageType();
  }
  
  public IMessage[] getChildrenMessages()
  {
    return head.getChildrenMessages();
  }
  
  void setSelectionText(FormText text)
  {
    if ((selectionText != null) && (selectionText != text)) {
      selectionText.clearSelection();
    }
    selectionText = text;
  }
  
  public IMessageManager getMessageManager()
  {
    if (messageManager == null) {
      messageManager = new MessageManager(this);
    }
    return messageManager;
  }
}

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

import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.ui.internal.forms.widgets.FormTextModel;

class FormText$1
  implements DisposeListener
{
  final FormText this$0;
  
  FormText$1(FormText paramFormText)
  {
    this$0 = paramFormText;
  }
  
  public void widgetDisposed(DisposeEvent e)
  {
    FormText.access$0(this$0).dispose();
    FormText.access$7(this$0, true);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.ui.forms.widgets.FormText.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.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.MenuItem;

class FormText$10
  extends SelectionAdapter
{
  final FormText this$0;
  private final MenuItem val$copyItem;
  
  FormText$10(FormText paramFormText, MenuItem paramMenuItem)
  {
    this$0 = paramFormText;val$copyItem = paramMenuItem;
  }
  
  public void widgetSelected(SelectionEvent e)
  {
    if (widget == val$copyItem) {
      this$0.copy();
    }
  }
}

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

import org.eclipse.swt.events.MenuEvent;
import org.eclipse.swt.events.MenuListener;
import org.eclipse.swt.widgets.MenuItem;

class FormText$11
  implements MenuListener
{
  final FormText this$0;
  private final MenuItem val$copyItem;
  
  FormText$11(FormText paramFormText, MenuItem paramMenuItem)
  {
    this$0 = paramFormText;val$copyItem = paramMenuItem;
  }
  
  public void menuShown(MenuEvent e)
  {
    val$copyItem.setEnabled(this$0.canCopy());
  }
  
  public void menuHidden(MenuEvent e) {}
}

/* Location:
 * Qualified Name:     org.eclipse.ui.forms.widgets.FormText.11
 * 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;
import org.eclipse.ui.internal.forms.widgets.FormTextModel;
import org.eclipse.ui.internal.forms.widgets.IHyperlinkSegment;

class FormText$12
  extends AccessibleAdapter
{
  final FormText this$0;
  
  FormText$12(FormText paramFormText)
  {
    this$0 = paramFormText;
  }
  
  public void getName(AccessibleEvent e)
  {
    if (childID == -1)
    {
      result = FormText.access$0(this$0).getAccessibleText();
    }
    else
    {
      int linkCount = FormText.access$0(this$0).getHyperlinkCount();
      if ((childID >= 0) && (childID < linkCount))
      {
        IHyperlinkSegment link = FormText.access$0(this$0).getHyperlink(childID);
        result = link.getText();
      }
    }
  }
  
  public void getHelp(AccessibleEvent e)
  {
    result = this$0.getToolTipText();
    int linkCount = FormText.access$0(this$0).getHyperlinkCount();
    if ((result == null) && (childID >= 0) && (childID < linkCount))
    {
      IHyperlinkSegment link = FormText.access$0(this$0).getHyperlink(childID);
      result = link.getText();
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.ui.forms.widgets.FormText.12
 * 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;
import org.eclipse.ui.internal.forms.widgets.FormTextModel;
import org.eclipse.ui.internal.forms.widgets.IHyperlinkSegment;

class FormText$13
  extends AccessibleControlAdapter
{
  final FormText this$0;
  
  FormText$13(FormText paramFormText)
  {
    this$0 = paramFormText;
  }
  
  public void getChildAtPoint(AccessibleControlEvent e)
  {
    Point pt = this$0.toControl(new Point(x, y));
    IHyperlinkSegment link = FormText.access$0(this$0).findHyperlinkAt(x, y);
    if (link != null) {
      childID = FormText.access$0(this$0).indexOf(link);
    } else {
      childID = -1;
    }
  }
  
  public void getLocation(AccessibleControlEvent e)
  {
    Rectangle location = null;
    if ((childID != -1) && 
      (childID != -2))
    {
      int index = childID;
      IHyperlinkSegment link = FormText.access$0(this$0).getHyperlink(index);
      if (link != null) {
        location = link.getBounds();
      }
    }
    if (location == null) {
      location = this$0.getBounds();
    }
    Point pt = this$0.toDisplay(new Point(x, y));
    x = x;
    y = y;
    width = width;
    height = height;
  }
  
  public void getFocus(AccessibleControlEvent e)
  {
    int childID = -2;
    if (FormText.access$0(this$0).hasFocusSegments())
    {
      int selectedIndex = FormText.access$0(this$0).getSelectedSegmentIndex();
      if (selectedIndex != -1) {
        childID = selectedIndex;
      }
    }
    childID = childID;
  }
  
  public void getDefaultAction(AccessibleControlEvent e)
  {
    if (FormText.access$0(this$0).getHyperlinkCount() > 0) {
      result = SWT.getMessage("SWT_Press");
    }
  }
  
  public void getChildCount(AccessibleControlEvent e)
  {
    detail = FormText.access$0(this$0).getHyperlinkCount();
  }
  
  public void getRole(AccessibleControlEvent e)
  {
    int role = 0;
    int childID = childID;
    int linkCount = FormText.access$0(this$0).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 = FormText.access$0(this$0).getSelectedSegmentIndex();
    childID = (selectedIndex == -1 ? -2 : 
      selectedIndex);
  }
  
  public void getState(AccessibleControlEvent e)
  {
    int linkCount = FormText.access$0(this$0).getHyperlinkCount();
    int selectedIndex = FormText.access$0(this$0).getSelectedSegmentIndex();
    int state = 0;
    int childID = childID;
    if (childID == -1)
    {
      state = 0;
    }
    else if ((childID >= 0) && (childID < linkCount))
    {
      state = 2097152;
      if (this$0.isFocusControl()) {
        state |= 0x100000;
      }
      if (selectedIndex == childID)
      {
        state |= 0x2;
        if (this$0.isFocusControl()) {
          state |= 0x4;
        }
      }
    }
    state |= 0x40;
    detail = state;
  }
  
  public void getChildren(AccessibleControlEvent e)
  {
    int linkCount = FormText.access$0(this$0).getHyperlinkCount();
    Object[] children = new Object[linkCount];
    for (int i = 0; i < linkCount; i++) {
      children[i] = new Integer(i);
    }
    children = chi
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