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
/**
 * Copyright (c) 2012, Dhilshuk Reddy All rights reserved.
 * 
 * Permission to use, copy, modify, and distribute SwingJD software is freely
 * granted, provided that this notice is preserved.
 */
package com.bestray.healthcarecommonutil.util;

import com.bestray.healthcarecommonutil.util.Colors;
import com.bestray.healthcarecommonutil.util.PanelType;
import java.awt.Color;
import java.awt.Font;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.geom.Area;
import java.awt.geom.Rectangle2D;
import java.awt.geom.RoundRectangle2D;
import java.awt.image.BufferedImage;
import java.util.List;

import javax.swing.ImageIcon;
import javax.swing.JPanel;


/**
 * 
 * @author dhilshuk
 * 
 */
public class HeadingPanel extends JPanel {

	private int theme;
	private String themeType;
	private ImageIcon icon;
	private String title = "";
	private String iconPath;
	private BufferedImage panelImage;
	private Font font;
	private int panelType = PanelType.PANEL_ROUNDED_RECTANGLUR;

	/**
	 * Constructor with title and theme of the Panel.
	 * 
	 * @param title
	 *            text on the panel
	 * @param theme
	 *            theme of the panel
	 */
	public HeadingPanel(String title, int theme) {
		this.title = title;
		this.theme = theme;
		this.themeType = getThemeType();
		font = new Font("Thoma", Font.BOLD, 12);
	}

	/**
	 * Constructor with title,theme and panel type.
	 * 
	 * @param title
	 *            text on the panel
	 * @param theme
	 *            theme of the panel
	 * @param panelType
	 *            panel type.
	 */
	public HeadingPanel(String title, int theme, int panelType) {
		this.title = title;
		this.theme = theme;
		this.themeType = getThemeType();
		this.panelType = panelType;
		font = new Font("Thoma", Font.BOLD, 12);
	}

	/**
	 * Constructor with title,theme and icon path.
	 * 
	 * @param title
	 *            text on the panel
	 * @param theme
	 *            theme of the panel
	 * @param iconpath
	 *            icon path
	 */
	public HeadingPanel(String title, int theme, String iconpath) {
		this.theme = theme;
		this.title = title;
		this.iconPath = iconpath;
		this.themeType = getThemeType();
		font = new Font("Thoma", Font.BOLD, 12);

	}

	/**
	 * Constructor with title,theme,icon path and panelType.
	 * 
	 * @param title
	 *            text on the panel
	 * @param theme
	 *            theme of the panel
	 * @param iconpath
	 *            path of the icon
	 * @param panelType
	 *            type of panel
	 */
	public HeadingPanel(String title, int theme, String iconpath, int panelType) {
		this.theme = theme;
		this.title = title;
		this.iconPath = iconpath;
		this.themeType = getThemeType();
		this.panelType = panelType;
		font = new Font("Thoma", Font.BOLD, 12);

	}

	@Override
	public void paintComponent(Graphics g) {
		Graphics2D g2d = (Graphics2D) g;
		g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
				RenderingHints.VALUE_ANTIALIAS_ON);
		g2d.setRenderingHint(java.awt.RenderingHints.KEY_TEXT_ANTIALIASING,
				java.awt.RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
		int w = getWidth();
		int h = getHeight();
		if (panelImage == null || panelImage.getWidth() != w
				|| panelImage.getHeight() != h) {
			createPanelImage();
		}
		g2d.drawImage(panelImage, null, 0, 0);

	}

	/**
	 * Creates the panel Image.
	 */
	private void createPanelImage() {
		panelImage = new BufferedImage(getWidth(), getHeight(),
				BufferedImage.TYPE_INT_ARGB);
		Graphics2D g2d = panelImage.createGraphics();
		g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
				RenderingHints.VALUE_ANTIALIAS_ON);
		g2d.setRenderingHint(java.awt.RenderingHints.KEY_TEXT_ANTIALIASING,
				java.awt.RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

		int width = getWidth();
		int height = getHeight();
		int titlePos = 10;
		List colors = null;
		Paint bgColor = null;
		GradientPaint fgColor = null;
		Color textColor = new Color(0, 0, 0);
		if (themeType.equalsIgnoreCase("GLOSSY")) {
			colors = Colors.getInStance().getGlossyColor(theme, 0,
					getHeight() / 2);
			textColor = (Color) colors.get(2);
			bgColor = (Paint) colors.get(1);
			fgColor = (GradientPaint) colors.get(0);
			if (panelType == PanelType.PANEL_ROUNDED_RECTANGLUR) {
				g2d.setPaint((Paint) colors.get(1));
				g2d.fill(getBGShape(width, height));
				g2d.setPaint((Paint) colors.get(0));
				g2d.fill(getGlossyShape(width, height));
				g2d.setPaint(new Color(255, 255, 255, 120));
				g2d.draw(getInnerBGShape(width, height));
				g2d.setColor(new Color(100, 100, 100, 150));
				g2d.draw(getBGShape(width, height));
			} else if (panelType == PanelType.PANEL_RECTANGULAR) {
				g2d.setPaint(bgColor);
				g2d.fillRect(0, 0, width, height);
				g2d.setPaint(fgColor);
				g2d.fillRect(2, 2, width - 4, height / 2);
				g2d.setColor(new Color(255, 255, 255, 100));
				g2d.drawRect(1, 1, width - 3, height - 3);
				g2d.setColor(new Color(100, 100, 100, 150));
				g2d.drawRect(0, 0, width - 1, height - 1);

			}

		} else {
			if (themeType.equalsIgnoreCase("Standard")) {
				colors = Colors.getInStance().getStandardColor(theme, 0,
						getHeight());
			} else {
				colors = Colors.getInStance().getGradientColor(theme, 0,
						getHeight());

			}
			textColor = (Color) colors.get(1);
			if (panelType == PanelType.PANEL_ROUNDED_RECTANGLUR) {
				g2d.setPaint((Paint) colors.get(0));
				g2d.fill(getBGShape(width, height));
				g2d.setPaint(new Color(255, 255, 255, 120));
				g2d.draw(getInnerBGShape(width, height));
				g2d.setColor(new Color(50, 50, 50, 150));
				g2d.draw(getBGShape(width, height));
			} else {
				g2d.setPaint((Paint) colors.get(0));
				g2d.fillRect(0, 0, width, height);
				g2d.setPaint(new Color(50, 50, 50, 150));
				g2d.drawRect(0, 0, width - 1, height - 1);
				g2d.setPaint(new Color(255, 255, 255, 50));
				g2d.drawRect(1, 1, width - 3, height - 3);

			}

		}

		if (this.iconPath != null) {
			icon = new ImageIcon(this.iconPath);
			titlePos = icon.getIconWidth();
			g2d.drawImage(icon.getImage(), 8, height / 4, null);

		}
		g2d.setFont(font);
		if (textColor == Color.WHITE) {
			g2d.setColor(new Color(0, 0, 0));
		} else {
			g2d.setColor(new Color(255, 255, 255));
		}
		g2d.drawString(title, titlePos + 10, (height + 10) / 2 + 1);
		g2d.setColor(textColor);
		g2d.drawString(title, titlePos + 10, (height + 10) / 2);
	}

	private Shape getGlossyShape(int width, int height) {
		RoundRectangle2D roundRect = new RoundRectangle2D.Float(2, 1,
				width - 3, height, 6, 6);
		Rectangle2D rect = new Rectangle2D.Float(2, height / 2 + 2, width - 3,
				height - 2);
		Area shape = new Area(roundRect);
		shape.subtract(new Area(rect));
		return shape;
	}

	/**
	 * Gets the Background Shape.
	 * 
	 * @param width
	 *            width of the panel
	 * @param height
	 *            height of the panel
	 * @return Shape.
	 */
	private Shape getBGShape(int width, int height) {
		RoundRectangle2D roundRect = new RoundRectangle2D.Float(0, 0,
				width - 1, height + 10, 8, 8);
		Rectangle2D rect = new Rectangle2D.Float(0, height, width - 1,
				height - 2);
		Area shape = new Area(roundRect);
		shape.subtract(new Area(rect));
		return shape;
	}

	/**
	 * Gets the Inner Shape.
	 * 
	 * @param width
	 *            width of the panel
	 * @param height
	 *            height of the panel
	 * @return
	 */
	private Shape getInnerBGShape(int width, int height) {
		RoundRectangle2D roundRect = new RoundRectangle2D.Float(1, 1,
				width - 3, height + 2, 8, 8);
		Rectangle2D rect = new Rectangle2D.Float(1, height - 1, width - 2,
				height - 2);
		Area shape = new Area(roundRect);
		shape.subtract(new Area(rect));
		return shape;
	}

	/**
	 * Return the ThemeType.
	 * 
	 * @return themeType
	 */
	public String getThemeType() {
		if (theme > 200) {
			themeType = "STANDARD";
		} else if (theme > 100) {
			themeType = "GRADIENT";
		} else {
			themeType = "GLOSSY";
		}

		return themeType;
	}

	/**
	 * Returns the font.
	 * 
	 * @return font.
	 */
	public Font getFont() {
		return font;
	}

	/**
	 * Sets the font.
	 */
	public void setFont(Font font) {
		this.font = font;
	}

}

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

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