Subversion Repository Public Repository

Pharmacy_09_03_18

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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bestray.healthcarecommonutil.util;

/**
 *
 * @author user3
 */


import javax.swing.*;
import java.awt.*;
import java.awt.geom.RoundRectangle2D;
// TODO: Auto-generated Javadoc
/**
 * 
 * SimpleGradientPanel.java
 * <p/>
 * An example of for custom JPanel.
 * @author JDhilsukh
 *
 */
public class SimpleGradientPanel extends JPanel {
	
	/** The Constant VERTICAL. */
	public static final int VERTICAL = 0;
	
	/** The Constant HORIZONTAL. */
	public static final int HORIZONTAL = 1;
	
	/** The Constant VERTICAL_RAISED. */
	public static final int VERTICAL_RAISED = 2;
	
	/** The Constant HORIZONTAL_RAISED. */
	public static final int HORIZONTAL_RAISED =3;
	
	/** The outer round rect size. */
	private int outerRoundRectSize = 0;
	
	/** The inner round rect size. */
	private int innerRoundRectSize = 0;
	
	/** The start color of the gradient. */
	private Color startColor = new Color(255, 255, 255);

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

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

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

	/**
	 * Create a default SimpleGradientPanel instance.
	 */
	public SimpleGradientPanel() {
		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 SimpleGradientPanel(Color aStart, Color aEnd) {
		super();
		startColor = aStart;
		endColor = aEnd;
	}

	/**
	 * Create a SimpleGradientPanel with the given start and end colors and direction.
	 *
	 * @param aStart 		The start color for the gradient.
	 * @param aEnd   		The end color for the gradient.
	 * @param aDirection The direction of the gradient.
	 */
	public SimpleGradientPanel(Color aStart, Color aEnd, int aDirection) {
		super();
		startColor = aStart;
		endColor = aEnd;
		direction = aDirection;
	}
	/**
	 * Create a SimpleGradientPanel with the given start and end colors and direction.
	 *
	 * @param aStart 		      The start color for the gradient.
	 * @param aEnd   		      The end color for the gradient.
	 * @param aDirection          The direction of the gradient.
	 * @param aOuterRoundRectSize The OuterRectSizde size of the RoundedRectangle.
	 * @param aInnerRoundRectSize The innerRectsize of the RoundedRectange.
	 */
	public SimpleGradientPanel(Color aStart, Color aEnd, int aDirection,int aOuterRoundRectSize,int aInnerRoundRectSize) {
		super();
		startColor = aStart;
		endColor = aEnd;
		direction = aDirection;
		outerRoundRectSize = aOuterRoundRectSize;
		innerRoundRectSize = aInnerRoundRectSize;
	}

	/**
	 * 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 if (direction == VERTICAL) {
			paintVerticalGradient(g2, inset.left, inset.top, vWidth, vHeight,
					dim.height);
		} else if (direction == HORIZONTAL_RAISED) {
			paintHorizontalRaisedGradient(g2, inset.left, inset.top, vWidth, vHeight,
					dim.width);
    	} else if (direction == VERTICAL_RAISED) {
			paintVerticalRaisedGradient(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);

		p1 = new GradientPaint(0, 0, new Color(0, 0, 0), 0, h - 1, new Color(
				100, 100, 100));
		p2 = new GradientPaint(0, 1, new Color(0, 0, 0, 50), 0, h - 3,
				new Color(255, 255, 255, 100));
		g2d.setPaint(Color.BLACK);
		g2d.drawRoundRect(0, 0, w - 1, h - 1, outerRoundRectSize,
				outerRoundRectSize);
		g2d.setPaint(GP);
		g2d.fillRoundRect(1, 1, w - 2, h - 2, outerRoundRectSize,
				outerRoundRectSize);

	}

	/**
	 * 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);

		p1 = new GradientPaint(0, 0, new Color(0, 0, 0), 0, h - 1, new Color(
				100, 100, 100));
		p2 = new GradientPaint(0, 1, new Color(0, 0, 0, 50), 0, h - 3,
				new Color(255, 255, 255, 100));
		g2d.setPaint(Color.BLACK);
		g2d.drawRoundRect(0, 0, w - 1, h - 1, outerRoundRectSize,
				outerRoundRectSize);
		g2d.setPaint(GP);
		g2d.fillRoundRect(1, 1, w - 2, h - 2, outerRoundRectSize,
				outerRoundRectSize);


	}

	/**
	 * Paints a vertical-raised 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 paintVerticalRaisedGradient(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);

		p1 = new GradientPaint(0, 0, new Color(0, 0, 0), 0, h - 1, new Color(
				100, 100, 100));
		p2 = new GradientPaint(0, 1, new Color(0, 0, 0, 50), 0, h - 3,
				new Color(255, 255, 255, 100));
		g2d.setPaint(Color.BLACK);
		g2d.drawRoundRect(0, 0, w - 1, h - 1, outerRoundRectSize,
				outerRoundRectSize);
		g2d.setPaint(GP);
		g2d.fillRoundRect(1, 1, w - 2, h - 2, outerRoundRectSize,
				outerRoundRectSize);

		g2d.setPaint(p1);
		g2d.drawRoundRect(0, 0, w - 1, h - 1, outerRoundRectSize,
				outerRoundRectSize);
		g2d.setPaint(p2);
		g2d.drawRoundRect(1, 1, w - 3, h - 3, innerRoundRectSize,
				innerRoundRectSize);

	}

	/**
	 * Paints a horizontal-raised 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 paintHorizontalRaisedGradient(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);
		p1 = new GradientPaint(0, 0, new Color(0, 0, 0), w - 3, 0, new Color(
				100, 100, 100));
		p2 = new GradientPaint(1, 0, new Color(0, 0, 0, 50), w - 3, 0,
				new Color(255, 255, 255, 100));

		RoundRectangle2D.Float r2d = new RoundRectangle2D.Float(0, 0, w - 1,
				h - 1, outerRoundRectSize, outerRoundRectSize);
		Shape clip = g2d.getClip();
		g2d.clip(r2d);
		g2d.fillRect(0, 0, w, h);
		g2d.setClip(clip);
		g2d.setPaint(p1);

		g2d.setPaint(Color.BLACK);
		g2d.drawRoundRect(0, 0, w - 1, h - 1, outerRoundRectSize,
				outerRoundRectSize);
		g2d.setPaint(p2);
		g2d.fillRoundRect(1, 1, w - 2, h - 2, outerRoundRectSize,
				outerRoundRectSize);

		g2d.setPaint(Color.WHITE);
		g2d.drawRoundRect(1, 1, w - 3, h - 3, outerRoundRectSize,
				outerRoundRectSize);
		g2d.setPaint(p2);
		g2d.drawRoundRect(1, 1, w - 2, h - 2, innerRoundRectSize,
				innerRoundRectSize);

	}
	
	/**
	 * Get the OuterRoundedSize of the RoundedRectangle.
	 *
	 * @return the outer round rect size
	 */
	public int getOuterRoundRectSize() {
		return outerRoundRectSize;
	}
	
	/**
	 * Set the OuterRoundSize of Rectangle.
	 *
	 * @param outerRoundRectSize the new outer round rect size
	 */
	public void setOuterRoundRectSize(int outerRoundRectSize) {
		this.outerRoundRectSize = outerRoundRectSize;
	}
	
	/**
	 * Get the innerRoundedSize of the RoundedRectangle.
	 *
	 * @return the inner round rect size
	 */
	public int getInnerRoundRectSize() {
		return innerRoundRectSize;
	}
	
	/**
	 * Set the InnerRoundSize of Rectangle.
	 *
	 * @param innerRoundRectSize the new inner round rect size
	 */
	public void setInnerRoundRectSize(int innerRoundRectSize) {
		this.innerRoundRectSize = innerRoundRectSize;
	}

}

Commits for Pharmacy_09_03_18/Dr Gyana ProjectSpace/DrGyanaCommonUtil/src/main/java/com/bestray/healthcarecommonutil/util/SimpleGradientPanel.java

Diff revisions: vs.
Revision Author Commited Message
1 girijabapi picture girijabapi Fri 27 Jul, 2018 07:30:57 +0000