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
/*
 * 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 javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicTabbedPaneUI;
import java.awt.*;


// TODO: Auto-generated Javadoc
/**
 * The Class CWTabbedPaneUI.
 */
public class CWTabbedPaneUI extends BasicTabbedPaneUI
{
	
	/** The Constant NO_INSETS. */
	private static final Insets NO_INSETS = new Insets(0, 0, 0, 0);

	/** The height that we want the button bar to be. */
	private int buttonHeight = 18;

	/** The (calculated) color of the button bar and the tabs. */
	private Color tabColor = null;

	/** The background color of the control. */
	private Color background = null;

	/** A color that is one step darker than the background color. */
	private Color backgroundDarker1 = null;

	/** A color that is two steps darker than the background color. */
	private Color backgroundDarker2 = null;

	/** Calculated colors to create a faded shadow. */
	private Color[] fadeColors;

	/** The number of pixels we want to use to create the shadow. */
	private int fadeColorCount = 3;

	/** The color of the text of a selected tab. */
	private Color selectedTextColor = Color.WHITE;

	/** The number of pixels the first tab should be inset from the left margin. */
	private int leftInset = 12;

	// ------------------------------------------------------------------------------------------------------------------
	//  Custom installation methods
	// ------------------------------------------------------------------------------------------------------------------

	/**
	 * Creates the ui.
	 *
	 * @param c the c
	 * @return the component ui
	 */
	public static ComponentUI createUI(JComponent c)
	{
		return new CWTabbedPaneUI();
	}

	/* (non-Javadoc)
	 * @see javax.swing.plaf.basic.BasicTabbedPaneUI#installComponents()
	 */
	protected void installComponents()
	{
		super.installComponents();

		tabColor = tabPane.getBackground().darker().darker();

		background = tabPane.getBackground();
		backgroundDarker1 = tabPane.getBackground().darker();
		backgroundDarker2 = tabPane.getBackground().darker().darker();

		fadeColors = new Color[fadeColorCount];
		for (int i = 0; i < fadeColorCount; i++)
		{
			int rs = tabColor.getRed();
			int gs = tabColor.getGreen();
			int bs = tabColor.getBlue();

			int rt = background.getRed();
			int gt = background.getGreen();
			int bt = background.getBlue();

			int rn = (int) Math.min(rs + (Math.abs(rt - rs) / 4 * i), 255);
			int gn = (int) Math.min(gs + (Math.abs(gt - gs) / 4 * i), 255);
			int bn = (int) Math.min(bs + (Math.abs(bt - bs) / 4 * i), 255);

			fadeColors[i] = new Color(rn, gn, bn);
		}
	}

	/* (non-Javadoc)
	 * @see javax.swing.plaf.basic.BasicTabbedPaneUI#installDefaults()
	 */
	/**
     *
     */
    protected void installDefaults()
	{
		super.installDefaults();
		tabAreaInsets.left = leftInset;
		selectedTabPadInsets = new Insets(0, 0, 0, 0);
	}

	// ------------------------------------------------------------------------------------------------------------------
	//  Custom sizing methods
	// ------------------------------------------------------------------------------------------------------------------

	/* (non-Javadoc)
	 * @see javax.swing.plaf.basic.BasicTabbedPaneUI#getTabRunCount(javax.swing.JTabbedPane)
	 */
	/**
     *
     * @param pane
     * @return
     */
    public int getTabRunCount(JTabbedPane pane)
	{
		return 1;
	}

	/* (non-Javadoc)
	 * @see javax.swing.plaf.basic.BasicTabbedPaneUI#getContentBorderInsets(int)
	 */
	/**
     *
     * @param tabPlacement
     * @return
     */
    protected Insets getContentBorderInsets(int tabPlacement)
	{
		return NO_INSETS;
	}

	/* (non-Javadoc)
	 * @see javax.swing.plaf.basic.BasicTabbedPaneUI#calculateTabHeight(int, int, int)
	 */
	/**
     *
     * @param tabPlacement
     * @param tabIndex
     * @param fontHeight
     * @return
     */
    protected int calculateTabHeight(int tabPlacement, int tabIndex, int fontHeight)
	{
		if (tabPlacement == tabIndex)
		{
			return buttonHeight;
		}
		else
		{
			return buttonHeight + (buttonHeight / 2) + 6;
		}
	}

	/* (non-Javadoc)
	 * @see javax.swing.plaf.basic.BasicTabbedPaneUI#calculateTabWidth(int, int, java.awt.FontMetrics)
	 */
	/**
     *
     * @param tabPlacement
     * @param tabIndex
     * @param metrics
     * @return
     */
    protected int calculateTabWidth(int tabPlacement, int tabIndex, FontMetrics metrics)
	{
		return super.calculateTabWidth(tabPlacement, tabIndex, metrics) + buttonHeight;
	}

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

	/* (non-Javadoc)
	 * @see javax.swing.plaf.basic.BasicTabbedPaneUI#paintTabArea(java.awt.Graphics, int, int)
	 */
	protected void paintTabArea(Graphics g, int tabPlacement, int selectedIndex)
	{
		int tw = tabPane.getBounds().width;

		g.setColor(tabColor);
		g.fillRect(0, 0, tw, buttonHeight);
		g.draw3DRect(0, 0, leftInset - 1, buttonHeight, true);

		int x = rects[rects.length - 1].x + rects[rects.length - 1].width;
		g.draw3DRect(x, 0, tw - x - 1, buttonHeight, true);

		g.setColor(Color.black);
		g.drawLine(0, buttonHeight + 1, tw - 1, buttonHeight + 1);

		for (int i = 1; i <= fadeColorCount; i++)
		{
			g.setColor(fadeColors[fadeColorCount - 1]);
			g.drawLine(0, buttonHeight + 1 + i, tw - 1, buttonHeight + 1 + i);
		}

		super.paintTabArea(g, tabPlacement, selectedIndex);
	}

	/* (non-Javadoc)
	 * @see javax.swing.plaf.basic.BasicTabbedPaneUI#paintTabBorder(java.awt.Graphics, int, int, int, int, int, int, boolean)
	 */
	protected void paintTabBorder(Graphics g, int tabPlacement, int tabIndex, int tx, int ty, int tw, int th, boolean isSelected)
	{
		Graphics2D g2d = (Graphics2D) g;

		g2d.translate(tx, 0);

		if (isSelected)
		{
			int[] x = new int[3];
			int[] y = new int[3];

			g.setColor(tabColor);

			g.fillRect(0, 0, tw, buttonHeight);
			g.draw3DRect(0, 0, tw - 1, buttonHeight, true);
			g.fillRect(buttonHeight / 2, buttonHeight, tw - buttonHeight, buttonHeight / 2 + 1);

			// Left Polygon
			x[0] = 0;
			y[0] = buttonHeight;
			x[1] = buttonHeight / 2;
			y[1] = buttonHeight + (buttonHeight / 2);
			x[2] = buttonHeight / 2;
			y[2] = buttonHeight;
			g.fillPolygon(x, y, 3);

			// Right Polygon
			x[0] = tw;
			y[0] = buttonHeight;
			x[1] = tw - buttonHeight / 2;
			y[1] = buttonHeight + (buttonHeight / 2);
			x[2] = tw - buttonHeight / 2;
			y[2] = buttonHeight;
			g.fillPolygon(x, y, 3);

			g.setColor(backgroundDarker1);
			g.drawLine(0, buttonHeight, buttonHeight / 2, buttonHeight + (buttonHeight / 2));

			g.setColor(backgroundDarker2);
			g.drawLine(0, buttonHeight + 1, buttonHeight / 2, buttonHeight + (buttonHeight / 2) + 1);
			g.drawLine(buttonHeight / 2, buttonHeight + (buttonHeight / 2) + 1, tw - buttonHeight / 2, buttonHeight + (buttonHeight / 2) + 1);
			g.drawLine(tw - buttonHeight / 2, buttonHeight + (buttonHeight / 2), tw, buttonHeight);

			g.setColor(Color.black);
			g.drawLine(buttonHeight / 2 + 1, buttonHeight + (buttonHeight / 2) + 2, tw - buttonHeight / 2 - 1, buttonHeight + (buttonHeight / 2) + 2);
			g.drawLine(tw - buttonHeight / 2 - 1, buttonHeight + (buttonHeight / 2) + 2, tw, buttonHeight + 1);

			for (int i = 1; i <= fadeColorCount; i++)
			{
				g.setColor(fadeColors[i - 1]);
				g.drawLine(buttonHeight / 2 + 2 + i, buttonHeight + (buttonHeight / 2) + 2 + i, tw - buttonHeight / 2 - 1, buttonHeight + (buttonHeight / 2) + 2 + i);
				g.drawLine(tw - buttonHeight / 2 - 1, buttonHeight + (buttonHeight / 2) + 2 + i, tw, buttonHeight + 1 + i);
			}
		}
		else
		{
			g.setColor(tabColor);

			g.fillRect(0, 0, tw, buttonHeight);
			g.draw3DRect(0, 0, tw - 1, buttonHeight, true);

			g.setColor(Color.black);
			g.drawLine(0, buttonHeight + 1, tw - 1, buttonHeight + 1);

			for (int i = 1; i <= fadeColorCount; i++)
			{
				g.setColor(fadeColors[fadeColorCount - 1]);
				g.drawLine(0, buttonHeight + 1 + i, tw - 1, buttonHeight + 1 + i);
			}
		}

		g2d.translate(-1 * tx, 0);
	}

	/* (non-Javadoc)
	 * @see javax.swing.plaf.basic.BasicTabbedPaneUI#paintText(java.awt.Graphics, int, java.awt.Font, java.awt.FontMetrics, int, java.lang.String, java.awt.Rectangle, boolean)
	 */
	/**
     *
     * @param g
     * @param tabPlacement
     * @param font
     * @param metrics
     * @param tabIndex
     * @param title
     * @param textRect
     * @param isSelected
     */
    protected void paintText(Graphics g, int tabPlacement, Font font, FontMetrics metrics, int tabIndex, String title, Rectangle textRect, boolean isSelected)
	{
		Rectangle r = rects[tabIndex];

		Graphics2D g2d = (Graphics2D) g;
		g2d.translate(r.x, 0);

		if (isSelected)
		{
			FontMetrics fm = getFontMetrics();
			g.setColor(selectedTextColor);
			g.drawString(title, (r.width / 2 - fm.stringWidth(title) / 2) + 1, buttonHeight / 2 + fm.getMaxDescent() + buttonHeight / 2 + 3);

		}
		else
		{
			FontMetrics fm = getFontMetrics();
			g.setColor(Color.white);
			g.drawString(title, (r.width / 2 - fm.stringWidth(title) / 2) + 1, buttonHeight / 2 + fm.getMaxDescent() + 2);
		}

		g2d.translate(-1 * r.x, 0);
	}

	// ------------------------------------------------------------------------------------------------------------------
	//  Methods that we want to suppress the behaviour of the superclass
	// ------------------------------------------------------------------------------------------------------------------

	/* (non-Javadoc)
	 * @see javax.swing.plaf.basic.BasicTabbedPaneUI#paintTabBackground(java.awt.Graphics, int, int, int, int, int, int, boolean)
	 */
	/**
     *
     * @param g
     * @param tabPlacement
     * @param tabIndex
     * @param x
     * @param y
     * @param w
     * @param h
     * @param isSelected
     */
    protected void paintTabBackground(Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, boolean isSelected)
	{
		// Do nothing
	}

	/* (non-Javadoc)
	 * @see javax.swing.plaf.basic.BasicTabbedPaneUI#paintFocusIndicator(java.awt.Graphics, int, java.awt.Rectangle[], int, java.awt.Rectangle, java.awt.Rectangle, boolean)
	 */
	/**
     *
     * @param g
     * @param tabPlacement
     * @param rects
     * @param tabIndex
     * @param iconRect
     * @param textRect
     * @param isSelected
     */
    protected void paintFocusIndicator(Graphics g, int tabPlacement, Rectangle[] rects, int tabIndex, Rectangle iconRect, Rectangle textRect, boolean isSelected)
	{
		// Do nothing
	}

	/* (non-Javadoc)
	 * @see javax.swing.plaf.basic.BasicTabbedPaneUI#paintContentBorder(java.awt.Graphics, int, int)
	 */
	/**
     *
     * @param g
     * @param tabPlacement
     * @param selectedIndex
     */
    protected void paintContentBorder(Graphics g, int tabPlacement, int selectedIndex)
	{
		// Do nothing
	}
}

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

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