Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: 6c275d68b37f664aea1709e52a2854e5b7c0c824 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*******************************************************************************
 * Copyright (c) 2001, 2006 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.wst.xsd.ui.internal.adt.typeviz.design.figures;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.MarginBorder;
import org.eclipse.draw2d.ToolbarLayout;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.graphics.Color;

public class HeadingFigure extends Figure
{
  public static final Color headerColor = new Color(null, 224, 233, 246);
  Label label;
  Color[] gradientColor = {ColorConstants.white,  
                           ColorConstants.lightGray,
                           ColorConstants.lightBlue,
                           ColorConstants.gray};
  boolean isSelected = false;
  boolean isReadOnly = false;
  
  public HeadingFigure()
  {
    label = new Label();
    label.setBorder(new MarginBorder(2));
    ToolbarLayout toolbarLayout = new ToolbarLayout(false);
    toolbarLayout.setMinorAlignment(ToolbarLayout.ALIGN_CENTER);
    setLayoutManager(toolbarLayout);
    add(label);
  }
  
  public void setGradientColors(Color[] colors)
  {
    this.gradientColor = colors;
  }
  
  public void setSelected(boolean isSelected)
  {
    this.isSelected = isSelected;
  }

  public void setIsReadOnly(boolean isReadOnly)
  {
    this.isReadOnly = isReadOnly;
  }
  
  public void paint(Graphics graphics)
  {
    super.paint(graphics);
    
    graphics.pushState();
    try
    {
      // Fill for the header section
      //
      Rectangle r = getBounds().getCopy();
      graphics.setBackgroundColor(ColorConstants.lightGray);
  
      Color gradient1 = isReadOnly ? gradientColor[1] : headerColor;
      if (isSelected && isReadOnly) gradient1 = gradientColor[3];
      else if (isSelected && !isReadOnly) gradient1 = gradientColor[2];
      Color gradient2 = gradientColor[0];
      graphics.setForegroundColor(gradient1);
      graphics.setBackgroundColor(gradient2);
      Rectangle labelBounds = label.getBounds();
      graphics.fillGradient(r.x+1, r.y+1, r.width-2, labelBounds.height - 2, true);    
      graphics.setForegroundColor(ColorConstants.darkGray);
      label.paint(graphics);    
    }
    finally
    {
      graphics.popState();
    }
  }

  public Label getLabel()
  {
    return label;
  }  
}

Back to the top