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

ing.access$6(this$0).getControl();
      FormHeading.access$4(this$0).setControl(tb);
      tbsize = FormHeading.access$4(this$0).computeSize(-1, -1);
    }
    if (FormHeading.access$7(this$0) != null)
    {
      FormHeading.access$2(this$0).setControl(FormHeading.access$7(this$0));
      int cwhint = width;
      if (cwhint != -1)
      {
        cwhint -= 12;
        if ((tbsize != null) && (this$0.getToolBarAlignment() == 1024)) {
          cwhint -= x + 5;
        }
      }
      clsize = FormHeading.access$2(this$0).computeSize(cwhint, -1);
    }
    int totalFlexWidth = width;
    int flexWidth = totalFlexWidth;
    if (totalFlexWidth != -1)
    {
      totalFlexWidth -= 2;
      if (((FormHeading.access$5(this$0)) && (this$0.getToolBarAlignment() == 128)) || 
        (FormHeading.access$8(this$0))) {
        totalFlexWidth -= 5;
      }
      if ((FormHeading.access$5(this$0)) && (this$0.getToolBarAlignment() == 128)) {
        totalFlexWidth -= x + 5;
      }
      flexWidth = totalFlexWidth;
      if (FormHeading.access$8(this$0)) {
        flexWidth -= 5;
      }
    }
    if (!FormHeading.access$8(this$0))
    {
      tsize = FormHeading.access$1(this$0).computeSize(flexWidth, -1);
    }
    else
    {
      Point tsizeNatural = FormHeading.access$1(this$0).computeSize(-1, 
        -1);
      FormHeading.access$3(this$0).setControl(FormHeading.access$0(this$0).getMessageControl());
      Point msizeNatural = FormHeading.access$3(this$0).computeSize(-1, 
        -1);
      
      tsize = tsizeNatural;
      msize = msizeNatural;
      if (flexWidth != -1)
      {
        int needed = x + x;
        if (needed > flexWidth)
        {
          int mwidth = flexWidth - x;
          if (mwidth >= 50)
          {
            x = mwidth;
          }
          else
          {
            int flex = flexWidth - 50;
            tsize = FormHeading.access$1(this$0).computeSize(flex, -1);
            x = 50;
          }
        }
      }
    }
    Point size = new Point(width, height);
    if (!move)
    {
      int width1 = 2;
      width1 += x;
      if (msize != null) {
        width1 += 5 + x;
      }
      if ((tbsize != null) && (this$0.getToolBarAlignment() == 128)) {
        width1 += 5 + x;
      }
      if ((msize != null) || (
        (tbsize != null) && (this$0.getToolBarAlignment() == 128))) {
        width1 += 5;
      }
      x = width1;
      if (clsize != null)
      {
        int width2 = x;
        if ((tbsize != null) && (this$0.getToolBarAlignment() == 1024)) {
          width2 += 5 + x;
        }
        width2 += 12;
        x = Math.max(width1, width2);
      }
      y = y;
      if (msize != null) {
        y = Math.max(y, y);
      }
      if ((tbsize != null) && (this$0.getToolBarAlignment() == 128)) {
        y = Math.max(y, y);
      }
      if (y > 0) {
        y += 2;
      }
      int height2 = 0;
      if ((tbsize != null) && (this$0.getToolBarAlignment() == 1024)) {
        height2 = y;
      }
      if (clsize != null) {
        height2 = Math.max(height2, y);
      }
      if (height2 > 0) {
        y += 5 + height2 + 1;
      }
      if ((y > 0) && (this$0.isSeparatorVisible())) {
        y += 2;
      }
    }
    else
    {
      int xloc = x;
      int yloc = y + 1;
      int row1Height = y;
      if (FormHeading.access$8(this$0)) {
        row1Height = Math.max(row1Height, y);
      }
      if ((FormHeading.access$5(this$0)) && (this$0.getToolBarAlignment() == 128)) {
        row1Height = Math.max(row1Height, y);
      }
      FormHeading.access$1(this$0).setBounds(xloc, 
      
        yloc, x, y);
      xloc += x;
      if (FormHeading.access$8(this$0))
      {
        xloc += 5;
        int messageOffset = 0;
        if (y > 0)
        {
          int titleLeadingSpace = (y - FormHeading.access$1(this$0).getFontHeight()) / 2;
          
          int messageLeadingSpace = (y - FormHeading.access$0(this$0).getFontHeight()) / 2;
          
          messageOffset = titleLeadingSpace + FormHeading.access$1(this$0).getFontBaselineHeight() - (
            messageLeadingSpace + FormHeading.access$0(this$0).getFontBaselineHeight());
        }
        FormHeading.access$0(this$0).getMessageControl().setBounds(
          xloc, 
          y > 0 ? yloc + messageOffset : 
          yloc + row1Height / 2 - y / 2, 
          x, y);
        xloc += x;
      }
      if (FormHeading.access$6(this$0) != null) {
        FormHeading.access$6(this$0).getControl().setVisible(
          !FormHeading.access$6(this$0).isEmpty());
      }
      if ((tbsize != null) && (this$0.getToolBarAlignment() == 128))
      {
        ToolBar tbar = FormHeading.access$6(this$0).getControl();
        tbar.setBounds(x + width - 1 - x - 6, yloc + 
          row1Height - 1 - y, x, y);
      }
      xloc = 6;
      yloc += row1Height + 5;
      int tw = 0;
      if ((tbsize != null) && (this$0.getToolBarAlignment() == 1024))
      {
        ToolBar tbar = FormHeading.access$6(this$0).getControl();
        tbar.setBounds(x + width - 1 - x - 6, yloc, 
          x, y);
        tw = x + 5;
      }
      if (FormHeading.access$7(this$0) != null)
      {
        int carea = width - 12 - tw;
        FormHeading.access$7(this$0).setBounds(xloc, yloc, carea, y);
      }
    }
    return size;
  }
}

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

import org.eclipse.swt.graphics.Color;

class FormHeading$GradientInfo
{
  Color[] gradientColors;
  int[] percents;
  boolean vertical;
  final FormHeading this$0;
  
  FormHeading$GradientInfo(FormHeading paramFormHeading, GradientInfo paramGradientInfo)
  {
    this(paramFormHeading);
  }
  
  private FormHeading$GradientInfo(FormHeading paramFormHeading)
  {
    this$0 = paramFormHeading;
  }
}

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

import org.eclipse.core.runtime.ListenerList;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.FontMetrics;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.forms.IMessage;
import org.eclipse.ui.forms.events.IHyperlinkListener;
import org.eclipse.ui.forms.widgets.Hyperlink;
import org.eclipse.ui.internal.forms.IMessageToolTipManager;

class FormHeading$MessageRegion
{
  private String message;
  private int messageType;
  private CLabel messageLabel;
  private IMessage[] messages;
  private Hyperlink messageHyperlink;
  private ListenerList listeners;
  private Color fg;
  private int fontHeight;
  private int fontBaselineHeight;
  final FormHeading this$0;
  
  public FormHeading$MessageRegion(FormHeading paramFormHeading)
  {
    this$0 = paramFormHeading;fontHeight = -1;fontBaselineHeight = -1;
  }
  
  public boolean isDisposed()
  {
    Control c = getMessageControl();
    return (c != null) && (c.isDisposed());
  }
  
  public boolean isEmpty()
  {
    Control c = getMessageControl();
    if (c == null) {
      return true;
    }
    return !c.getVisible();
  }
  
  public int getFontHeight()
  {
    if (fontHeight == -1)
    {
      Control c = getMessageControl();
      if (c == null) {
        return 0;
      }
      GC gc = new GC(c.getDisplay());
      gc.setFont(c.getFont());
      fontHeight = gc.getFontMetrics().getHeight();
      gc.dispose();
    }
    return fontHeight;
  }
  
  public int getFontBaselineHeight()
  {
    if (fontBaselineHeight == -1)
    {
      Control c = getMessageControl();
      if (c == null) {
        return 0;
      }
      GC gc = new GC(c.getDisplay());
      gc.setFont(c.getFont());
      FontMetrics fm = gc.getFontMetrics();
      fontBaselineHeight = (fm.getHeight() - fm.getDescent());
      gc.dispose();
    }
    return fontBaselineHeight;
  }
  
  public void showMessage(String newMessage, int newType, IMessage[] messages)
  {
    Control oldControl = getMessageControl();
    int oldType = messageType;
    message = newMessage;
    messageType = newType;
    this.messages = messages;
    if (newMessage == null)
    {
      if ((oldControl != null) && (oldControl.getVisible())) {
        oldControl.setVisible(false);
      }
      return;
    }
    ensureControlExists();
    if (needHyperlink())
    {
      messageHyperlink.setText(newMessage);
      messageHyperlink.setHref(messages);
    }
    else
    {
      messageLabel.setText(newMessage);
    }
    if (oldType != newType) {
      updateForeground();
    }
  }
  
  public void updateToolTip(String toolTip)
  {
    Control control = getMessageControl();
    if (control != null) {
      control.setToolTipText(toolTip);
    }
  }
  
  public String getMessage()
  {
    return message;
  }
  
  public int getMessageType()
  {
    return messageType;
  }
  
  public IMessage[] getChildrenMessages()
  {
    return messages;
  }
  
  public Control getMessageControl()
  {
    if ((needHyperlink()) && (messageHyperlink != null)) {
      return messageHyperlink;
    }
    return messageLabel;
  }
  
  public Image getMessageImage()
  {
    switch (messageType)
    {
    case 1: 
      return JFaceResources.getImage("dialog_messasge_info_image");
    case 2: 
      return JFaceResources.getImage("dialog_messasge_warning_image");
    case 3: 
      return JFaceResources.getImage("dialog_message_error_image");
    }
    return null;
  }
  
  public void addMessageHyperlinkListener(IHyperlinkListener listener)
  {
    if (listeners == null) {
      listeners = new ListenerList();
    }
    listeners.add(listener);
    ensureControlExists();
    if (messageHyperlink != null) {
      messageHyperlink.addHyperlinkListener(listener);
    }
    if (listeners.size() == 1) {
      updateForeground();
    }
  }
  
  private void removeMessageHyperlinkListener(IHyperlinkListener listener)
  {
    if (listeners != null)
    {
      listeners.remove(listener);
      if (messageHyperlink != null) {
        messageHyperlink.removeHyperlinkListener(listener);
      }
      if (listeners.isEmpty()) {
        listeners = null;
      }
      ensureControlExists();
      if ((listeners == null) && (!isDisposed())) {
        updateForeground();
      }
    }
  }
  
  private void ensureControlExists()
  {
    if (needHyperlink())
    {
      if (messageLabel != null) {
        messageLabel.setVisible(false);
      }
      if (messageHyperlink == null)
      {
        messageHyperlink = new Hyperlink(this$0, 0);
        messageHyperlink.setUnderlined(true);
        messageHyperlink.setText(message);
        messageHyperlink.setHref(messages);
        Object[] llist = listeners.getListeners();
        for (int i = 0; i < llist.length; i++) {
          messageHyperlink.addHyperlinkListener((IHyperlinkListener)llist[i]);
        }
        if (FormHeading.access$9(this$0) != null) {
          FormHeading.access$9(this$0).createToolTip(messageHyperlink, false);
        }
      }
      else if (!messageHyperlink.getVisible())
      {
        messageHyperlink.setText(message);
        messageHyperlink.setHref(messages);
        messageHyperlink.setVisible(true);
      }
    }
    else
    {
      if (messageHyperlink != null) {
        messageHyperlink.setVisible(false);
      }
      if (messageLabel == null)
      {
        messageLabel = new CLabel(this$0, 0);
        messageLabel.setText(message);
        if (FormHeading.access$9(this$0) != null) {
          FormHeading.access$9(this$0).createToolTip(messageLabel, false);
        }
      }
      else if (!messageLabel.getVisible())
      {
        messageLabel.setText(message);
        messageLabel.setVisible(true);
      }
    }
    this$0.layout(true);
  }
  
  private boolean needHyperlink()
  {
    return (messageType > 0) && (listeners != null);
  }
  
  public void setBackground(Color bg)
  {
    if (messageHyperlink != null) {
      messageHyperlink.setBackground(bg);
    }
    if (messageLabel != null) {
      messageLabel.setBackground(bg);
    }
  }
  
  public void setForeground(Color fg)
  {
    this.fg = fg;
  }
  
  private void updateForeground()
  {
    Color theFg;
    Color theFg;
    Color theFg;
    switch (messageType)
    {
    case 3: 
      theFg = this$0.getDisplay().getSystemColor(3);
      break;
    case 2: 
      theFg = this$0.getDisplay().getSystemColor(8);
      break;
    default: 
      theFg = fg;
    }
    getMessageControl().setForeground(theFg);
  }
}

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

import java.util.Hashtable;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.ListenerList;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.dnd.DragSourceListener;
import org.eclipse.swt.dnd.DropTargetListener;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseMoveListener;
import org.eclipse.swt.events.MouseTrackListener;
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.ToolBar;
import org.eclipse.ui.forms.IMessage;
import org.eclipse.ui.forms.events.IHyperlinkListener;
import org.eclipse.ui.forms.widgets.Hyperlink;
import org.eclipse.ui.forms.widgets.ILayoutExtension;
import org.eclipse.ui.forms.widgets.SizeCache;
import org.eclipse.ui.internal.forms.IMessageToolTipManager;
import org.eclipse.ui.internal.forms.MessageManager;

public class FormHeading
  extends Canvas
{
  private static final int TITLE_HMARGIN = 1;
  private static final int SPACING = 5;
  private static final int VSPACING = 5;
  private static final int HMARGIN = 6;
  private static final int VMARGIN = 1;
  private static final int CLIENT_MARGIN = 1;
  private static final int SEPARATOR = 2;
  private static final int BOTTOM_TOOLBAR = 4;
  private static final int BACKGROUND_IMAGE_TILED = 8;
  private static final int SEPARATOR_HEIGHT = 2;
  private static final int MESSAGE_AREA_LIMIT = 50;
  static IMessage[] NULL_MESSAGE_ARRAY = new IMessage[0];
  public static final String COLOR_BASE_BG = "baseBg";
  private Image backgroundImage;
  private Image gradientImage;
  Hashtable colors = new Hashtable();
  private int flags;
  private GradientInfo gradientInfo;
  private ToolBarManager toolBarManager;
  private SizeCache toolbarCache = new SizeCache();
  private SizeCache clientCache = new SizeCache();
  private SizeCache messageCache = new SizeCache();
  private TitleRegion titleRegion;
  private MessageRegion messageRegion;
  private IMessageToolTipManager messageToolTipManager = new DefaultMessageToolTipManager(null);
  private Control headClient;
  
  private class DefaultMessageToolTipManager
    implements IMessageToolTipManager
  {
    DefaultMessageToolTipManager(DefaultMessageToolTipManager paramDefaultMessageToolTipManager)
    {
      this();
    }
    
    public void update()
    {
      String details = getMessageType() == 0 ? null : 
        MessageManager.createDetails(getChildrenMessages());
      if (messageRegion != null) {
        messageRegion.updateToolTip(details);
      }
      if ((getMessageType() > 0) && (
        (details == null) || (details.length() == 0))) {
        details = getMessage();
      }
      titleRegion.updateToolTip(details);
    }
    
    public void createToolTip(Control control, boolean imageLabel) {}
    
    private DefaultMessageToolTipManager() {}
  }
  
  private class GradientInfo
  {
    Color[] gradientColors;
    int[] percents;
    boolean vertical;
    
    private GradientInfo() {}
    
    GradientInfo(GradientInfo paramGradientInfo)
    {
      this();
    }
  }
  
  private class FormHeadingLayout
    extends Layout
    implements ILayoutExtension
  {
    FormHeadingLayout(FormHeadingLayout paramFormHeadingLayout)
    {
      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)
    {
      return layout(composite, false, 0, 0, wHint, hHint, flushCache);
    }
    
    protected void layout(Composite composite, boolean flushCache)
    {
      Rectangle rect = composite.getClientArea();
      layout(composite, true, x, y, width, height, 
        flushCache);
    }
    
    private Point layout(Composite composite, boolean move, int x, int y, int width, int height, boolean flushCache)
    {
      Point tsize = null;
      Point msize = null;
      Point tbsize = null;
      Point clsize = null;
      if (flushCache)
      {
        clientCache.flush();
        messageCache.flush();
        toolbarCache.flush();
      }
      if (FormHeading.this.hasToolBar())
      {
        ToolBar tb = toolBarManager.getControl();
        toolbarCache.setControl(tb);
        tbsize = toolbarCache.computeSize(-1, -1);
      }
      if (headClient != null)
      {
        clientCache.setControl(headClient);
        int cwhint = width;
        if (cwhint != -1)
        {
          cwhint -= 12;
          if ((tbsize != null) && (getToolBarAlignment() == 1024)) {
            cwhint -= x + 5;
          }
        }
        clsize = clientCache.computeSize(cwhint, -1);
      }
      int totalFlexWidth = width;
      int flexWidth = totalFlexWidth;
      if (totalFlexWidth != -1)
      {
        totalFlexWidth -= 2;
        if (((FormHeading.this.hasToolBar()) && (getToolBarAlignment() == 128)) || 
          (FormHeading.this.hasMessageRegion())) {
          totalFlexWidth -= 5;
        }
        if ((FormHeading.this.hasToolBar()) && (getToolBarAlignment() == 128)) {
          totalFlexWidth -= x + 5;
        }
        flexWidth = totalFlexWidth;
        if (FormHeading.this.hasMessageRegion()) {
          flexWidth -= 5;
        }
      }
      if (!FormHeading.this.hasMessageRegion())
      {
        tsize = titleRegion.computeSize(flexWidth, -1);
      }
      else
      {
        Point tsizeNatural = titleRegion.computeSize(-1, 
          -1);
        messageCache.setControl(messageRegion.getMessageControl());
        Point msizeNatural = messageCache.computeSize(-1, 
          -1);
        
        tsize = tsizeNatural;
        msize = msizeNatural;
        if (flexWidth != -1)
        {
          int needed = x + x;
          if (needed > flexWidth)
          {
            int mwidth = flexWidth - x;
            if (mwidth >= 50)
            {
              x = mwidth;
            }
            else
            {
              int flex = flexWidth - 50;
              tsize = titleRegion.computeSize(flex, -1);
              x = 50;
            }
          }
        }
      }
      Point size = new Point(width, height);
      if (!move)
      {
        int width1 = 2;
        width1 += x;
        if (msize != null) {
          width1 += 5 + x;
        }
        if ((tbsize != null) && (getToolBarAlignment() == 128)) {
          width1 += 5 + x;
        }
        if ((msize != null) || (
          (tbsize != null) && (getToolBarAlignment() == 128))) {
          width1 += 5;
        }
        x = width1;
        if (clsize != null)
        {
          int width2 = x;
          if ((tbsize != null) && (getToolBarAlignment() == 1024)) {
            width2 += 5 + x;
          }
          width2 += 12;
          x = Math.max(width1, width2);
        }
        y = y;
        if (msize != null) {
          y = Math.max(y, y);
        }
        if ((tbsize != null) && (getToolBarAlignment() == 128)) {
          y = Math.max(y, y);
        }
        if (y > 0) {
          y += 2;
        }
        int height2 = 0;
        if ((tbsize != null) && (getToolBarAlignment() == 1024)) {
          height2 = y;
        }
        if (clsize != null) {
          height2 = Math.max(height2, y);
        }
        if (height2 > 0) {
          y += 5 + height2 + 1;
        }
        if ((y > 0) && (isSeparatorVisible())) {
          y += 2;
        }
      }
      else
      {
        int xloc = x;
        int yloc = y + 1;
        int row1Height = y;
        if (FormHeading.this.hasMessageRegion()) {
          row1Height = Math.max(row1Height, y);
        }
        if ((FormHeading.this.hasToolBar()) && (getToolBarAlignment() == 128)) {
          row1Height = Math.max(row1Height, y);
        }
        titleRegion.setBounds(xloc, 
        
          yloc, x, y);
        xloc += x;
        if (FormHeading.this.hasMessageRegion())
        {
          xloc += 5;
          int messageOffset = 0;
          if (y > 0)
          {
            int titleLeadingSpace = (y - titleRegion.getFontHeight()) / 2;
            
            int messageLeadingSpace = (y - messageRegion.getFontHeight()) / 2;
            
            messageOffset = titleLeadingSpace + titleRegion.getFontBaselineHeight() - (
              messageLeadingSpace + messageRegion.getFontBaselineHeight());
          }
          messageRegion.getMessageControl().setBounds(
            xloc, 
            y > 0 ? yloc + messageOffset : 
            yloc + row1Height / 2 - y / 2, 
            x, y);
          xloc += x;
        }
        if (toolBarManager != null) {
          toolBarManager.getControl().setVisible(
            !toolBarManager.isEmpty());
        }
        if ((tbsize != null) && (getToolBarAlignment() == 128))
        {
          ToolBar tbar = toolBarManager.getControl();
          tbar.setBounds(x + width - 1 - x - 6, yloc + 
            row1Height - 1 - y, x, y);
        }
        xloc = 6;
        yloc += row1Height + 5;
        int tw = 0;
        if ((tbsize != null) && (getToolBarAlignment() == 1024))
        {
          ToolBar tbar = toolBarManager.getControl();
          tbar.setBounds(x + width - 1 - x - 6, yloc, 
            x, y);
          tw = x + 5;
        }
        if (headClient != null)
        {
          int carea = width - 12 - tw;
          headClient.setBounds(xloc, yloc, carea, y);
        }
      }
      return size;
    }
    
    private FormHeadingLayout() {}
  }
  
  public boolean forceFocus()
  {
    return false;
  }
  
  private boolean hasToolBar()
  {
    return (toolBarManager != null) && (!toolBarManager.isEmpty());
  }
  
  private boolean hasMessageRegion()
  {
    return (messageRegion != null) && (!messageRegion.isEmpty());
  }
  
  private class MessageRegion
  {
    private String message;
    private int messageType;
    private CLabel messageLabel;
    private IMessage[] messages;
    private Hyperlink messageHyperlink;
    private ListenerList listeners;
    private Color fg;
    private int fontHeight = -1;
    private int fontBaselineHeight = -1;
    
    public MessageRegion() {}
    
    public boolean isDisposed()
    {
      Control c = getMessageControl();
      return (c != null) && (c.isDisposed());
    }
    
    public boolean isEmpty()
    {
      Control c = getMessageControl();
      if (c == null) {
        return true;
      }
      return !c.getVisible();
    }
    
    public int getFontHeight()
    {
      if (fontHeight == -1)
      {
        Control c = getMessageControl();
        if (c == null) {
          return 0;
        }
        GC gc = new GC(c.getDisplay());
        gc.setFont(c.getFont());
        fontHeight = gc.getFontMetrics().getHeight();
        gc.dispose();
      }
      return fontHeight;
    }
    
    public int getFontBaselineHeight()
    {
      if (fontBaselineHeight == -1)
      {
        Control c = getMessageControl();
        if (c == null) {
          return 0;
        }
        GC gc = new GC(c.getDisplay());
        gc.setFont(c.getFont());
        FontMetrics fm = gc.getFontMetrics();
        fontBaselineHeight = (fm.getHeight() - fm.getDescent());
        gc.dispose();
      }
      return fontBaselineHeight;
    }
    
    public void showMessage(String newMessage, int newType, IMessage[] messages)
    {
      Control oldControl = getMessageControl();
      int oldType = messageType;
      message = newMessage;
      messageType = newType;
      this.messages = messages;
      if (newMessage == null)
      {
        if ((oldControl != null) && (oldControl.getVisible())) {
          oldControl.setVisible(false);
        }
        return;
      }
      ensureControlExists();
      if (needHyperlink())
      {
        messageHyperlink.setText(newMessage);
        messageHyperlink.setHref(messages);
      }
      else
      {
        messageLabel.setText(newMessage);
      }
      if (oldType != newType) {
        updateForeground();
      }
    }
    
    public void updateToolTip(String toolTip)
    {
      Control control = getMessageControl();
      if (control != null) {
        control.setToolTipText(toolTip);
      }
    }
    
    public String getMessage()
    {
      return message;
    }
    
    public int getMessageType()
    {
      return messageType;
    }
    
    public IMessage[] getChildrenMessages()
    {
      return messages;
    }
    
    public Control getMessageControl()
    {
      if ((needHyperlink()) && (messageHyperlink != null)) {
        return messageHyperlink;
      }
      return messageLabel;
    }
    
    public Image getMessageImage()
    {
      switch (messageType)
      {
      case 1: 
        return JFaceResources.getImage("dialog_messasge_info_image");
      case 2: 
        return JFaceResources.getImage("dialog_messasge_warning_image");
      case 3: 
        return JFaceResources.getImage("dialog_message_error_image");
      }
      return null;
    }
    
    public void addMessageHyperlinkListener(IHyperlinkListener listener)
    {
      if (listeners == null) {
        listeners = new ListenerList();
      }
      listeners.add(listener);
      ensureControlExists();
      if (messageHyperlink != null) {
        messageHyperlink.addHyperlinkListener(listener);
      }
      if (listeners.size() == 1) {
        updateForeground();
      }
    }
    
    private void removeMessageHyperlinkListener(IHyperlinkListener listener)
    {
      if (listeners != null)
      {
        listeners.remove(listener);
        if (messageHyperlink != null) {
          messageHyperlink.removeHyperlinkListener(listener);
        }
        if (listeners.isEmpty()) {
          listeners = null;
        }
        ensureControlExists();
        if ((listeners == null) && (!isDisposed())) {
          updateForeground();
        }
      }
    }
    
    private void ensureControlExists()
    {
      if (needHyperlink())
      {
        if (messageLabel != null) {
          messageLabel.setVisible(false);
        }
        if (messageHyperlink == null)
        {
          messageHyperlink = new Hyperlink(FormHeading.this, 0);
          messageHyperlink.setUnderlined(true);
          messageHyperlink.setText(message);
          messageHyperlink.setHref(messages);
          Object[] llist = listeners.getListeners();
          for (int i = 0; i < llist.length; i++) {
            messageHyperlink.addHyperlinkListener((IHyperlinkListener)llist[i]);
          }
          if (messageToolTipManager != null) {
            messageToolTipManager.createToolTip(messageHyperlink, false);
          }
        }
        else if (!messageHyperlink.getVisible())
        {
          messageHyperlink.setText(message);
          messageHyperlink.setHref(messages);
          messageHyperlink.setVisible(true);
        }
      }
      else
      {
        if (messageHyperlink != null) {
          messageHyperlink.setVisible(false);
        }
        if (messageLabel == null)
        {
          messageLabel = new CLabel(FormHeading.this, 0);
          messageLabel.setText(message);
          if (messageToolTipManager != null) {
            messageToolTipManager.createToolTip(messageLabel, false);
          }
        }
        else if (!messageLabel.getVisible())
        {
          messageLabel.setText(message);
          messageLabel.setVisible(true);
        }
      }
      layout(true);
    }
    
    private boolean needHyperlink()
    {
      return (messageType > 0) && (listeners != null);
    }
    
    public void setBackground(Color bg)
    {
      if (messageHyperlink != null) {
        messageHyperlink.setBackground(bg);
      }
      if (messageLabel != null) {
        messageLabel.setBackground(bg);
      }
    }
    
    public void setForeground(Color fg)
    {
      this.fg = fg;
    }
    
    private void updateForeground()
    {
      Color theFg;
      Color theFg;
      Color theFg;
      switch (messageType)
      {
      case 3: 
        theFg = getDisplay().getSystemColor(3);
        break;
      case 2: 
        theFg = getDisplay().getSystemColor(8);
        break;
      default: 
        theFg = fg;
      }
      getMessageControl().setForeground(theFg);
    }
  }
  
  public FormHeading(Composite parent, int style)
  {
    super(parent, style);
    setBackgroundMode(1);
    addListener(9, new Listener()
    {
      public void handleEvent(Event e)
      {
        FormHeading.this.onPaint(gc);
      }
    });
    addListener(12, new Listener()
    {
      public void handleEvent(Event e)
      {
        if (gradientImage != null)
        {
          FormImages.getInstance().markFinished(gradientImage, getDisplay());
          gradientImage = null;
        }
      }
    });
    addListener(11, new Listener()
    {
      public void handleEvent(Event e)
      {
        if ((gradientInfo != null) || (
          (backgroundImage != null) && (!isBackgroundImageTiled()))) {
          FormHeading.this.updateGradientImage();
        }
      }
    });
    addMouseMoveListener(new MouseMoveListener()
    {
      public void mouseMove(MouseEvent e)
      {
        FormHeading.this.updateTitleRegionHoverState(e);
      }
    });
    addMouseTrackListener(new MouseTrackListener()
    {
      public void mouseEnter(MouseEvent e)
      {
        FormHeading.this.updateTitleRegionHoverState(e);
      }
      
      public void mouseExit(MouseEvent e)
      {
        titleRegion.setHoverState(0);
      }
      
      public void mouseHover(MouseEvent e) {}
    });
    super.setLayout(new FormHeadingLayout(null));
    titleRegion = new TitleRegion(this);
  }
  
  public final Point computeSize(int wHint, int hHint, boolean changed)
  {
    return ((FormHeadingLayout)getLayout()).computeSize(this, wHint, 
      hHint, changed);
  }
  
  public final void setLayout(Layout layout) {}
  
  public String getText()
  {
    return titleRegion.getText();
  }
  
  public Image getImage()
  {
    return titleRegion.getImage();
  }
  
  public void setBackground(Color bg)
  {
    super.setBackground(bg);
    internalSetBackground(bg);
  }
  
  private void internalSetBackground(Color bg)
  {
    titleRegion.setBackground(bg);
    if (messageRegion != null) {
      messageRegion.setBackground(bg);
    }
    if (toolBarManager != null) {
      toolBarManager.getControl().setBackground(bg);
    }
    putColor("baseBg", bg);
  }
  
  public void setForeground(Color fg)
  {
    super.setForeground(fg);
    titleRegion.setForeground(fg);
    if (messageRegion != null) {
      messageRegion.setForeground(fg);
    }
  }
  
  public void setText(String text)
  {
    titleRegion.setText(text);
  }
  
  public void setFont(Font font)
  {
    super.setFont(font);
    titleRegion.setFont(font);
  }
  
  public void setImage(Image image)
  {
    titleRegion.setImage(image);
    if (messageRegion != null) {
      titleRegion.updateImage(messageRegion.getMessageImage(), true);
    } else {
      titleRegion.updateImage(null, true);
    }
  }
  
  public void setTextBackground(Color[] gradientColors, int[] percents, boolean vertical)
  {
    if (gradientColors != null)
    {
      gradientInfo = new GradientInfo(null);
      gradientInfo.gradientColors = gradientColors;
      gradientInfo.percents = percents;
      gradientInfo.vertical = vertical;
      setBackground(null);
      updateGradientImage();
    }
    else
    {
      gradientInfo = null;
      if (gradientImage != null)
      {
        FormImages.getInstance().markFinished(gradientImage, getDisplay());
        gradientImage = null;
        setBackgroundImage(null);
      }
    }
  }
  
  public void setHeadingBackgroundImage(Image image)
  {
    backgroundImage = image;
    if (image != null) {
      setBackground(null);
    }
    if (isBackgroundImageTiled()) {
      setBackgroundImage(image);
    } else {
      updateGradientImage();
    }
  }
  
  public Image getHeadingBackgroundImage()
  {
    return backgroundImage;
  }
  
  public void setBackgroundImageTiled(boolean tiled)
  {
    if (tiled) {
      flags |= 0x8;
    } else {
      flags &= 0xFFFFFFF7;
    }
    setHeadingBackgroundImage(backgroundImage);
  }
  
  public boolean isBackgroundImageTiled()
  {
    return (flags & 0x8) != 0;
  }
  
  public void setBackgroundImage(Image image)
  {
    super.setBackgroundImage(image);
    if (image != null) {
      internalSetBackground(null);
    }
  }
  
  public IToolBarManager getToolBarManager()
  {
    if (toolBarManager == null)
    {
      toolBarManager = new ToolBarManager(8388608);
      ToolBar toolbar = toolBarManager.createControl(this);
      toolbar.setBackground(getBackground());
      toolbar.setForeground(getForeground());
      toolbar.setCursor(FormsResources.getHandCursor());
      addDisposeListener(new DisposeListener()
      {
        public void widgetDisposed(DisposeEvent e)
        {
          if (toolBarManager != null)
          {
            toolBarManager.dispose();
            toolBarManager = null;
          }
        }
      });
    }
    return toolBarManager;
  }
  
  public IMenuManager getMenuManager()
  {
    return titleRegion.getMenuManager();
  }
  
  public void updateToolBar()
  {
    if (toolBarManager != null) {
      toolBarManager.update(false);
    }
  }
  
  private void onPaint(GC gc)
  {
    if ((!isSeparatorVisible()) && (getBackgroundImage() == null)) {
      return;
    }
    Rectangle carea = getClientArea();
    Image buffer = new Image(getDisplay(), width, height);
    buffer.setBackground(getBackground());
    GC igc = new GC(buffer);
    igc.setBackground(getBackground());
    igc.fillRectangle(0, 0, width, height);
    if (getBackgroundImage() != null) {
      if (gradientInfo != null)
      {
        drawBackground(igc, x, y, width, height);
      }
      else
      {
        Image bgImage = getBackgroundImage();
        Rectangle ibounds = bgImage.getBounds();
        drawBackground(igc, x, y, width, 
          height);
      }
    }
    if (isSeparatorVisible())
    {
      if (hasColor("org.eclipse.ui.forms.H_BOTTOM_KEYLINE1")) {
        igc.setForeground(getColor("org.eclipse.ui.forms.H_BOTTOM_KEYLINE1"));
      } else {
        igc.setForeground(getBackground());
      }
      igc.drawLine(x, height - 2, x + width - 1, 
        height - 2);
      if (hasColor("org.eclipse.ui.forms.H_BOTTOM_KEYLINE2")) {
        igc.setForeground(getColor("org.eclipse.ui.forms.H_BOTTOM_KEYLINE2"));
      } else {
        igc.setForeground(getForeground());
      }
      igc.drawLine(x, height - 1, x + width - 1, 
        height - 1);
    }
    igc.dispose();
    gc.drawImage(buffer, x, y);
    buffer.dispose();
  }
  
  private void updateTitleRegionHoverState(MouseEvent e)
  {
    Rectangle titleRect = titleRegion.getBounds();
    width += x + 15;
    height += y + 15;
    x = 0;
    y = 0;
    if (titleRect.contains(x, y)) {
      titleRegion.setHoverState(1);
    } else {
      titleRegion.setHoverState(0);
    }
  }
  
  private void updateGradientImage()
  {
    Rectangle rect = getBounds();
    if (gradientImage != null)
    {
      FormImages.getInstance().markFinished(gradientImage, getDisplay());
      gradientImage = null;
    }
    if (gradientInfo != null)
    {
      gradientImage = FormImages.getInstance().getGradient(gradientInfo.gradientColors, gradientInfo.percents, 
        gradientInfo.vertical ? height : width, gradientInfo.vertical, getColor("baseBg"), getDisplay());
    }
    else if ((backgroundImage != null) && (!isBackgroundImageTiled()))
    {
      gradientImage = new Image(getDisplay(), Math.max(width, 1), 
        Math.max(height, 1));
      gradientImage.setBackground(getBackground());
      GC gc = new GC(gradientImage);
      gc.drawImage(backgroundImage, 0, 0);
      gc.dispose();
    }
    setBackgroundImage(gradientImage);
  }
  
  public boolean isSeparatorVisible()
  {
    return (flags & 0x2) != 0;
  }
  
  public void setSeparatorVisible(boolean addSeparator)
  {
    if (addSeparator) {
      flags |= 0x2;
    } else {
      flags &= 0xFFFFFFFD;
    }
  }
  
  public void setToolBarAlignment(int alignment)
  {
    if (alignment == 1024) {
      flags |= 0x4;
    } else {
      flags &= 0xFFFFFFFB;
    }
  }
  
  public int getToolBarAlignment()
  {
    return (flags & 0x4) != 0 ? 1024 : 128;
  }
  
  public void addMessageHyperlinkListener(IHyperlinkListener listener)
  {
    ensureMessageRegionExists();
    messageRegion.addMessageHyperlinkListener(listener);
  }
  
  public void removeMessageHyperlinkListener(IHyperlinkListener listener)
  {
    if (messageRegion != null) {
      messageRegion.removeMessageHyperlinkListener(listener);
    }
  }
  
  public String getMessage()
  {
    return messageRegion != null ? messageRegion.getMessage() : null;
  }
  
  public int getMessageType()
  {
    return messageRegion != null ? messageRegion.getMessageType() : 0;
  }
  
  public IMessage[] getChildrenMessages()
  {
    return messageRegion != null ? messageRegion.getChildrenMessages() : 
      NULL_MESSAGE_ARRAY;
  }
  
  private void ensureMessageRegionExists()
  {
    if (messageRegion == null) {
      messageRegion = new MessageRegion();
    }
  }
  
  public void showMessage(String newMessage, int type, IMessage[] messages)
  {
    if (messageRegion == null)
    {
      if (newMessage != null) {}
    }
    else if (messageRegion.isDisposed()) {
      return;
    }
    ensureMessageRegionExists();
    messageRegion.showMessage(newMessage, type, messages);
    titleRegion.updateImage(messageRegion.getMessageImage(), false);
    if (messageToolTipManager != null) {
      messageToolTipManager.update();
    }
    layout();
    redraw();
  }
  
  public boolean isBusy()
  {
    return titleRegion.isBusy();
  }
  
  public void setBusy(boolean busy)
  {
    if (titleRegion.setBusy(busy)) {
      layout();
    }
  }
  
  public Control getHeadClient()
  {
    return headClient;
  }
  
  public void setHeadClient(Control headClient)
  {
    if (headClient != null) {
      Assert.isTrue(headClient.getParent() == this);
    }
    this.headClient = headClient;
    layout();
  }
  
  pu
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