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
/**
 * 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 java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
import java.awt.geom.RoundRectangle2D;

import javax.swing.ButtonModel;
import javax.swing.JButton;


// TODO: Auto-generated Javadoc
/**
 * The Class StandardButton.
 *
 * @author Dhilshuk Reddy
 */
public class StandardButton extends JButton {

	/** The button theme. */
	private int buttonTheme = Theme.STANDARD_BLUEGRAY_THEME;
	
	/** The selected button theme. */
	private int selectedButtonTheme = Theme.STANDARD_GRAY_THEME;
	
	/** The rollover button theme. */
	private int rolloverButtonTheme = Theme.STANDARD_SILVER_THEME;
	
	/** The button type. */
	private String buttonType = ButtonType.BUTTON_ROUNDED_RECTANGLUR;

	/**
	 * Constructor which takes label of the button as argument.
	 * 
	 * @param text
	 *            label on the button
	 */
	public StandardButton(String text) {
		super();
		setText(text);
		setContentAreaFilled(false);
		setBorderPainted(false);
		setFont(new Font("Thoma", Font.BOLD, 12));
		setForeground(Color.WHITE);
		setFocusable(false);

	}

	/**
	 * Constructor which sets label of the button and the button theme.
	 * 
	 * @param text
	 *            label on the button.
	 * @param buttonTheme
	 *            button theme.
	 */
	public StandardButton(String text, int buttonTheme) {
		super(text);
		this.buttonTheme = buttonTheme;
		init();
	}

	/**
	 * Constructor which sets label of the button,button type and the button
	 * theme.
	 *
	 * @param text label of the button
	 * @param buttonTheme the button theme
	 * @param buttonType type of the button.
	 */
	public StandardButton(String text, int buttonTheme, String buttonType) {
		super(text);
		this.buttonTheme = buttonTheme;
		this.buttonType = buttonType;
		init();
	}

	/**
	 * Constructor which sets label of the button,button type,the button theme
	 * and the selectedTheme.
	 * 
	 * @param text
	 *            label on the button
	 * @param buttonType
	 *            Shape of the button
	 * @param buttonTheme
	 *            button theme
	 * @param selectedButtonTheme
	 *            selected button theme.
	 */
	public StandardButton(String text, String buttonType, int buttonTheme,
			int selectedButtonTheme) {
		super(text);
		this.buttonType = buttonType;
		this.buttonTheme = buttonTheme;
		init();
	}

	/**
	 * Constructor which sets label of the button,button type,the button theme
	 * and the selected Theme,roll-over theme.
	 * 
	 * @param text
	 *            label on the button
	 * @param buttonType
	 *            Shape of the button
	 * @param buttonTheme
	 *            button theme
	 * @param selectedButtonTheme
	 *            selected button theme
	 * 
	 * @param rolloverButtonTheme
	 *            roll-over button theme
	 */
	public StandardButton(String text, String buttonType, int buttonTheme,
			int selectedButtonTheme, int rolloverButtonTheme) {
		super(text);
		this.buttonType = buttonType;
		this.buttonTheme = buttonTheme;
		this.selectedButtonTheme = selectedButtonTheme;
		this.rolloverButtonTheme = rolloverButtonTheme;
		init();
	}

	/**
	 * Initializes.
	 */
	private void init() {
		setFont(new Font("Thoma", Font.BOLD, 12));
		setFocusable(false);
		setContentAreaFilled(false);
		setBorderPainted(false);
	}

	/* (non-Javadoc)
	 * @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
	 */
	@Override
	public void paintComponent(Graphics g) {
		Graphics2D g2d = (Graphics2D) g.create();
		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 h = getHeight();
		int w = getWidth();
		Paint color = null;
		ButtonModel model = getModel();
		if (model.isRollover()) {
			color = ColorUtils.getInStance().getStandardColor(
					rolloverButtonTheme, getHeight(), this);
		} else {
			color = ColorUtils.getInStance().getStandardColor(buttonTheme,
					getHeight(), this);

		}
		if (model.isPressed()) {
			color = ColorUtils.getInStance().getStandardColor(
					selectedButtonTheme, getHeight(), this);
		}
		drawShape(g2d, w, h, color);
		super.paintComponent(g);

	}

	/**
	 * Draws the shape.
	 *
	 * @param g2d 2d object
	 * @param w width of the button
	 * @param h height of the button
	 * @param color the color
	 */
	private void drawShape(Graphics2D g2d, int w, int h, Paint color) {
		if (buttonType == ButtonType.BUTTON_ROUNDED_RECTANGLUR) {
			RoundRectangle2D.Float r2d = new RoundRectangle2D.Float(0, 0,
					w - 1, h - 1, 8, 8);
			Shape clip = g2d.getClip();
			g2d.clip(r2d);
			g2d.setPaint(color);
			g2d.fillRoundRect(0, 0, w, h, 8, 8);
			g2d.setClip(clip);
			g2d.setColor(new Color(100, 100, 100));
			g2d.drawRoundRect(0, 0, w - 1, h - 1, 8, 8);
			g2d.setColor(new Color(255, 255, 255, 50));
			g2d.drawRoundRect(1, 1, w - 3, h - 3, 8, 8);
		} else if (buttonType == ButtonType.BUTTON_RECTANGULAR) {
			Rectangle2D.Float r2d = new Rectangle2D.Float(0, 0, w - 1, h - 1);
			Shape clip = g2d.getClip();
			g2d.clip(r2d);
			g2d.setPaint(color);
			g2d.fillRect(0, 0, w, h);
			g2d.setClip(clip);
			g2d.setColor(new Color(100, 100, 100));
			g2d.drawRect(0, 0, w - 1, h - 1);
			g2d.setColor(new Color(255, 255, 255, 50));
			g2d.drawRect(1, 1, w - 3, h - 3);
		} else if (buttonType == ButtonType.BUTTON_ROUNDED) {
			g2d.setPaint(color);
			g2d.fillRoundRect(1, 1, w - 2, h - 2, h - 5, h - 5);
			g2d.setPaint(new Color(100, 100, 100));
			g2d.drawRoundRect(0, 0, w - 1, h - 1, h - 3, h - 3);
			g2d.setColor(new Color(255, 255, 255, 50));
			g2d.drawRoundRect(1, 1, w - 3, h - 3, h - 3, h - 3);
		} else if (buttonType == ButtonType.BUTTON_OVAL) {
			g2d.setPaint(color);
			g2d.fillOval(1, 1, w - 20, h - 2);
			g2d.setPaint(new Color(100, 100, 100));
			g2d.drawOval(0, 0, w - 20, h - 1);
		} else if (buttonType == ButtonType.BUTTON_ELLIPSE) {
			g2d.setPaint(color);
			Shape shape = new Ellipse2D.Double(1, 1, w - 2, h - 2);
			g2d.fill(shape);
			g2d.setPaint(new Color(100, 100, 100));
			shape = new Ellipse2D.Double(0, 0, w - 1, h - 1);
			g2d.draw(shape);
		} else if (buttonType == ButtonType.BUTTON_CIRCULAR) {
			int size = Math.min(getWidth(), getHeight() - 2);
			g2d.setPaint(color);
			g2d.fillOval(2, 2, (size - 2 * 2), (size - 2 * 2));
			g2d.setStroke(new BasicStroke(2));
			g2d.setColor(new Color(100, 100, 100, 100));
			g2d.drawOval(2, 2, (size - 2 * 2), (size - 2 * 2));
		}

	}

	/**
	 * Gets the button theme.
	 * 
	 * @return button theme
	 */
	public int getButtonTheme() {
		return buttonTheme;
	}

	/**
	 * Sets the button theme.
	 *
	 * @param buttonTheme the new button theme
	 */
	public void setButtonTheme(int buttonTheme) {
		this.buttonTheme = buttonTheme;
	}

	/**
	 * Gets the selected theme.
	 *
	 * @return the select button theme
	 */
	public int getSelectButtonTheme() {
		return selectedButtonTheme;
	}

	/**
	 * Sets the selected theme.
	 *
	 * @param selectButtonTheme the new select button theme
	 */
	public void setSelectButtonTheme(int selectButtonTheme) {
		this.selectedButtonTheme = selectButtonTheme;
	}

	/**
	 * Returns Roll-Over Theme.
	 * 
	 * @return roll-over theme
	 */
	public int getRolloverButtonTheme() {
		return rolloverButtonTheme;
	}

	/**
	 * Sets Roll-Over Theme.
	 *
	 * @param rolloverButtonTheme the new rollover button theme
	 */
	public void setRolloverButtonTheme(int rolloverButtonTheme) {
		this.rolloverButtonTheme = rolloverButtonTheme;
	}

	/**
	 * Returns button type.
	 *
	 * @return the button type
	 * @returns buttonType
	 */
	public String getButtonType() {
		return buttonType;
	}

	/**
	 * Sets Button Type.
	 *
	 * @param buttonType the new button type
	 */
	public void setButtonType(String buttonType) {
		this.buttonType = buttonType;
	}

}

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

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