Subversion Repository Public Repository

Satyam

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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bestray.healthcarecommonutil.util;

import javax.swing.*;
import java.awt.*;
import java.awt.geom.GeneralPath;

// TODO: Auto-generated Javadoc
/**
 * The Class CurvedGradientPanel.
 */
public class CurvedGradientPanel extends JPanel {
	
	/** The Constant VERTICAL. */
	public static final int VERTICAL = 0;
	
	/** The Constant HORIZONTAL. */
	public static final int HORIZONTAL = 1;
	
	/** The round rect size. */
	private int roundRectSize = 0;

	/** The start color of the gradient. */
	private Color startColor = new Color(114, 166, 252);

	/** The end color of the gradient. */
	private Color endColor = new Color(255, 255, 255);

	/** The direction of the gradient. */
	private int direction = VERTICAL;

	// ------------------------------------------------------------------------------------------------------------------
	// Constructors and getter/setter methods
	// ------------------------------------------------------------------------------------------------------------------

	/**
	 * Create a default SimpleGradientPanel instance.
	 */
	public CurvedGradientPanel() {
		super();
	}

	/**
	 * Create a SimpleGradientPanel with the given start and end colors.
	 * 
	 * @param aStart
	 *            The start color for the gradient.
	 * @param aEnd
	 *            The end color for the gradient.
	 */
	public CurvedGradientPanel(Color aStart, Color aEnd) {
		super();
		startColor = aStart;
		endColor = aEnd;
	}

	/**
	 * Create a SimpleGradientPanel with the given start and end colors.
	 * 
	 * @param aStart
	 *            The start color for the gradient.
	 * @param aEnd
	 *            The end color for the gradient.
	 * @param aDirection
	 *            The direction of the gradient.
	 */
	public CurvedGradientPanel(Color aStart, Color aEnd, int aDirection) {
		super();
		startColor = aStart;
		endColor = aEnd;
		direction = aDirection;
	}

	/**
	 * Create a SimpleGradientPanel with the given start and end colors.
	 * 
	 * @param aStart
	 *            The start color for the gradient.
	 * @param aEnd
	 *            The end color for the gradient.
	 * @param aDirection
	 *            The direction of the gradient.
	 * @param aRoundRectSise
	 *            The rounded size of the Rectangle.
	 */
	public CurvedGradientPanel(Color aStart, Color aEnd, int aDirection,
			int aRoundRectSise) {
		super();
		startColor = aStart;
		endColor = aEnd;
		direction = aDirection;
		roundRectSize = aRoundRectSise;
	}

	/**
	 * Get the ending color of the gradient.
	 *
	 * @return the end color
	 */
	public Color getEndColor() {
		return endColor;
	}

	/**
	 * Set the ending color to use.
	 * 
	 * @param aColor
	 *            The color to use.
	 */
	public void setEndColor(Color aColor) {
		Color oldEndColor = endColor;
		endColor = aColor;
		super.firePropertyChange("endColor", oldEndColor, endColor);
		repaint();
	}

	/**
	 * Get the start color of the gradient.
	 *
	 * @return the start color
	 */
	public Color getStartColor() {
		return startColor;
	}

	/**
	 * Set the starting color.
	 * 
	 * @param aColor
	 *            The color to use
	 */
	public void setStartColor(Color aColor) {
		Color oldStartColor = endColor;
		startColor = aColor;
		super.firePropertyChange("startColor", oldStartColor, startColor);
		repaint();
	}

	/**
	 * Get the direction (vertical or horizontal) of the gradient.
	 *
	 * @return the direction
	 */
	public int getDirection() {
		return direction;
	}

	/**
	 * Set the direction.
	 *
	 * @param aDirection The direction of the gradient
	 */
	public void setDirection(int aDirection) {
		int oldDirection = direction;
		direction = aDirection;
		super.firePropertyChange("direction", oldDirection, aDirection);
		repaint();
	}

	// ------------------------------------------------------------------------------------------------------------------
	// Custom painting methods
	// ------------------------------------------------------------------------------------------------------------------

	/**
	 * Override the default paintComponent method to paint the gradient in the
	 * panel.
	 *
	 * @param g the g
	 */
	public void paintComponent(Graphics g) {
		Dimension dim = getSize();
		Graphics2D g2 = (Graphics2D) g;
		Insets inset = getInsets();
		int vWidth = dim.width - (inset.left + inset.right);
		int vHeight = dim.height - (inset.top + inset.bottom);

		if (direction == HORIZONTAL) {
			paintHorizontalGradient(g2, inset.left, inset.top, vWidth, vHeight,
					dim.width);
		} else {
			paintVerticalGradient(g2, inset.left, inset.top, vWidth, vHeight,
					dim.height);
		}

	}

	/**
	 * Paints a vertical gradient background from the start color to the end
	 * color.
	 *
	 * @param g2d the g2d
	 * @param x the x
	 * @param y the y
	 * @param w the w
	 * @param h the h
	 * @param height the height
	 */
	private void paintVerticalGradient(Graphics2D g2d, int x, int y, int w,
			int h, int height) {
		g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
				RenderingHints.VALUE_ANTIALIAS_ON);

		GradientPaint p1;
		GradientPaint p2;
		GradientPaint GP = new GradientPaint(0, 0, startColor, 0, h, endColor,
				true);
		g2d.setPaint(GP);

		g2d.setPaint(Color.BLACK);
		g2d.drawRoundRect(0, 0, w - 1, h - 1, roundRectSize, roundRectSize);
		g2d.setPaint(GP);
		g2d.fillRoundRect(1, 1, w - 2, h - 2, roundRectSize, roundRectSize);
		g2d.setPaint(Color.WHITE);
		g2d.drawRoundRect(1, 1, w - 3, h - 3, roundRectSize, roundRectSize);

		g2d.setPaint(new Color(255, 255, 255, 100));
		GeneralPath path = new GeneralPath();
		path.moveTo(-5, 1);
		path.quadTo(w / 2, h / 2, w, 0);
		path.closePath();
		g2d.fill(path);

	}

	/**
	 * Paints a horizontal gradient background from the start color to the end
	 * color.
	 *
	 * @param g2d the g2d
	 * @param x the x
	 * @param y the y
	 * @param w the w
	 * @param h the h
	 * @param width the width
	 */
	private void paintHorizontalGradient(Graphics2D g2d, int x, int y, int w,
			int h, int width) {
		g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
				RenderingHints.VALUE_ANTIALIAS_ON);
		GradientPaint p1;
		GradientPaint p2;
		GradientPaint GP = new GradientPaint(0, 0, startColor, w, 0, endColor,
				true);
		g2d.setPaint(GP);

		g2d.setPaint(Color.BLACK);
		g2d.drawRoundRect(0, 0, w - 1, h - 1, 10, 10);
		g2d.setPaint(GP);
		g2d.fillRoundRect(1, 1, w - 2, h - 2, 10, 10);
		g2d.setPaint(new Color(255, 255, 255, 100));
		GeneralPath path = new GeneralPath();
		path.moveTo(-5, 1);
		path.quadTo(w / 2, h / 2, w, 0);
		path.closePath();
		g2d.fill(path);
		
	}

}

Commits for Satyam/AuroCareCommonUtil/src/main/java/com/bestray/healthcarecommonutil/util/CurvedGradientPanel.java

Diff revisions: vs.
Revision Author Commited Message
1 girijabapi picture girijabapi Fri 20 Jul, 2018 05:59:17 +0000