Source Code Cross Referenced for MetalTabbedPaneUI.java in  » Apache-Harmony-Java-SE » javax-package » javax » swing » plaf » metal » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » javax package » javax.swing.plaf.metal 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:        /**
018:         * @author Vadim L. Bogdanov
019:         * @version $Revision$
020:         */package javax.swing.plaf.metal;
021:
022:        import java.awt.Color;
023:        import java.awt.Graphics;
024:        import java.awt.LayoutManager;
025:        import java.awt.Rectangle;
026:        import javax.swing.JComponent;
027:        import javax.swing.JTabbedPane;
028:        import javax.swing.UIManager;
029:        import javax.swing.plaf.ComponentUI;
030:        import javax.swing.plaf.basic.BasicTabbedPaneUI;
031:
032:        import org.apache.harmony.x.swing.Utilities;
033:
034:        public class MetalTabbedPaneUI extends BasicTabbedPaneUI {
035:
036:            public class TabbedPaneLayout extends
037:                    BasicTabbedPaneUI.TabbedPaneLayout {
038:                protected void normalizeTabRuns(final int tabPlacement,
039:                        final int tabCount, final int start, final int max) {
040:                    super .normalizeTabRuns(tabPlacement, tabCount, start, max);
041:                }
042:
043:                protected void padSelectedTab(final int tabPlacement,
044:                        final int selectedIndex) {
045:                    // overridden to do nothing
046:                }
047:
048:                protected void rotateTabRuns(final int tabPlacement,
049:                        final int selectedRun) {
050:                    // overridden to do nothing
051:                }
052:            }
053:
054:            public static ComponentUI createUI(final JComponent c) {
055:                return new MetalTabbedPaneUI();
056:            }
057:
058:            protected int minTabWidth = 40;
059:            protected Color selectColor;
060:            protected Color selectHighlight;
061:            protected Color tabAreaBackground;
062:
063:            protected int calculateMaxTabHeight(final int tabPlacement) {
064:                return super .calculateMaxTabHeight(tabPlacement);
065:            }
066:
067:            protected LayoutManager createLayoutManager() {
068:                if (tabPane.getTabLayoutPolicy() == JTabbedPane.WRAP_TAB_LAYOUT) {
069:                    return new TabbedPaneLayout();
070:                } else {
071:                    return super .createLayoutManager();
072:                }
073:            }
074:
075:            protected Color getColorForGap(final int currentRun, final int x,
076:                    final int y) {
077:                int adjacentTabIndex = getAdjacentTab(x, y);
078:
079:                if (adjacentTabIndex == -1) {
080:                    return tabPane.getBackground();
081:                }
082:
083:                return tabPane.getSelectedIndex() == adjacentTabIndex ? selectColor
084:                        : tabPane.getBackgroundAt(adjacentTabIndex);
085:            }
086:
087:            protected int getTabLabelShiftX(final int tabPlacement,
088:                    final int tabIndex, final boolean isSelected) {
089:                return 0;
090:            }
091:
092:            protected int getTabLabelShiftY(final int tabPlacement,
093:                    final int tabIndex, final boolean isSelected) {
094:                return 0;
095:            }
096:
097:            protected int getTabRunOverlay(final int tabPlacement) {
098:                if (tabPlacement == TOP || tabPlacement == BOTTOM) {
099:                    return 2;
100:                }
101:
102:                return 6;
103:            }
104:
105:            protected void installDefaults() {
106:                super .installDefaults();
107:
108:                selectColor = UIManager.getColor("TabbedPane.selected");
109:                selectHighlight = UIManager
110:                        .getColor("TabbedPane.selectHighlight");
111:                tabAreaBackground = UIManager
112:                        .getColor("TabbedPane.tabAreaBackground");
113:            }
114:
115:            public void paint(final Graphics g, final JComponent c) {
116:                super .paint(g, c);
117:            }
118:
119:            protected void paintContentBorderBottomEdge(final Graphics g,
120:                    final int tabPlacement, final int selectedIndex,
121:                    final int x, final int y, final int w, final int h) {
122:                g.setColor(darkShadow);
123:                g.drawRect(x, y + h - 1, w - 1, 0);
124:                g.setColor(selectColor);
125:                g.fillRect(x + 1, y + h - 3, w - 2, 2);
126:                if (tabPlacement == BOTTOM
127:                        && isTabAdjacentToContentAreaBorder(selectedIndex)) {
128:                    getTabBounds(selectedIndex, calcRect);
129:                    g
130:                            .drawRect(calcRect.x + 1, y + h - 1,
131:                                    calcRect.width - 2, 0);
132:                }
133:            }
134:
135:            protected void paintContentBorderLeftEdge(final Graphics g,
136:                    final int tabPlacement, final int selectedIndex,
137:                    final int x, final int y, final int w, final int h) {
138:                g.setColor(selectHighlight);
139:                g.drawRect(x, y, 0, h - 1);
140:                g.setColor(selectColor);
141:                g.drawRect(x + 1, y + 1, 0, h - 2);
142:                if (tabPlacement == LEFT
143:                        && isTabAdjacentToContentAreaBorder(selectedIndex)) {
144:                    getTabBounds(selectedIndex, calcRect);
145:                    g.drawRect(x, calcRect.y + 2, 0, calcRect.height - 3);
146:                }
147:            }
148:
149:            protected void paintContentBorderRightEdge(final Graphics g,
150:                    final int tabPlacement, final int selectedIndex,
151:                    final int x, final int y, final int w, final int h) {
152:                g.setColor(darkShadow);
153:                g.drawRect(x + w - 1, y, 0, h - 1);
154:                g.setColor(selectColor);
155:                g.fillRect(x + w - 3, y + 1, 2, h - 2);
156:                if (tabPlacement == RIGHT
157:                        && isTabAdjacentToContentAreaBorder(selectedIndex)) {
158:                    getTabBounds(selectedIndex, calcRect);
159:                    g.drawRect(x + w - 1, calcRect.y + 1, 0,
160:                            calcRect.height - 2);
161:                }
162:            }
163:
164:            protected void paintContentBorderTopEdge(final Graphics g,
165:                    final int tabPlacement, final int selectedIndex,
166:                    final int x, final int y, final int w, final int h) {
167:                g.setColor(selectHighlight);
168:                g.drawRect(x, y, w - 1, 0);
169:                g.setColor(selectColor);
170:                g.drawRect(x + 1, y + 1, w - 2, 0);
171:                if (tabPlacement == TOP
172:                        && isTabAdjacentToContentAreaBorder(selectedIndex)) {
173:                    getTabBounds(selectedIndex, calcRect);
174:                    g.drawRect(calcRect.x + 2, y, calcRect.width - 3, 0);
175:                }
176:            }
177:
178:            protected void paintFocusIndicator(final Graphics g,
179:                    final int tabPlacement, final Rectangle[] rects,
180:                    final int tabIndex, final Rectangle iconRect,
181:                    final Rectangle textRect, final boolean isSelected) {
182:                if (!isFocusPainted(tabIndex)) {
183:                    return;
184:                }
185:
186:                calcRect.setBounds(rects[tabIndex]);
187:                calcRect.grow(-3, -3);
188:
189:                g.setColor(focus);
190:                g.drawRoundRect(calcRect.x, calcRect.y, calcRect.width,
191:                        calcRect.height, 5, 5);
192:            }
193:
194:            protected void paintHighlightBelowTab() {
195:                // this method seems to be unused
196:            }
197:
198:            protected void paintBottomTabBorder(final int tabIndex,
199:                    final Graphics g, final int x, final int y, final int w,
200:                    final int h, final int btm, final int rght,
201:                    final boolean isSelected) {
202:                int[] xs = { x, x, x + 1, x + 3, x + 6, rght - 5, rght - 2,
203:                        rght, rght + 1, rght + 1 };
204:                int[] ys = { y - 2, btm - 5, btm - 2, btm, btm + 1, btm + 1,
205:                        btm, btm - 2, btm - 5, y - 3 };
206:
207:                g.setColor(darkShadow);
208:                g.drawPolyline(xs, ys, xs.length);
209:
210:                int[] highlightXs = { x + 1, x + 1, x + 3 };
211:                int[] highlightYs = { y - 2, btm - 4, btm - 1 };
212:                g.setColor(isSelected ? selectHighlight : highlight);
213:                g.drawPolyline(highlightXs, highlightYs, highlightXs.length);
214:            }
215:
216:            protected void paintLeftTabBorder(final int tabIndex,
217:                    final Graphics g, final int x, final int y, final int w,
218:                    final int h, final int btm, final int rght,
219:                    final boolean isSelected) {
220:                int[] xs = { rght, x + 6, x + 3, x + 1, x, x, x + 1, x + 3,
221:                        x + 6, rght + 1 };
222:                int[] ys = { btm + 1, btm + 1, btm, btm - 2, btm - 5, y + 6,
223:                        y + 3, y + 1, y, y };
224:
225:                g.setColor(darkShadow);
226:                g.drawPolyline(xs, ys, xs.length);
227:
228:                int[] highlightXs = { x + 1, x + 1, x + 3, x + 6, rght + 1 };
229:                int[] highlightYs = { btm - 4, y + 5, y + 2, y + 1, y + 1 };
230:                g.setColor(isSelected ? selectHighlight : highlight);
231:                g.drawPolyline(highlightXs, highlightYs, highlightXs.length);
232:            }
233:
234:            protected void paintRightTabBorder(final int tabIndex,
235:                    final Graphics g, final int x, final int y, final int w,
236:                    final int h, final int btm, final int rght,
237:                    final boolean isSelected) {
238:                int[] xs = { x - 1, rght - 5, rght - 2, rght, rght + 1,
239:                        rght + 1, rght, rght - 2, rght - 5, x - 1 };
240:                int[] ys = { btm + 1, btm + 1, btm, btm - 2, btm - 5, y + 6,
241:                        y + 3, y + 1, y, y };
242:
243:                g.setColor(darkShadow);
244:                g.drawPolyline(xs, ys, xs.length);
245:
246:                int[] highlightXs = { x, rght - 4, rght - 1 };
247:                int[] highlightYs = { y + 1, y + 1, y + 3 };
248:                g.setColor(isSelected ? selectHighlight : highlight);
249:                g.drawPolyline(highlightXs, highlightYs, highlightXs.length);
250:            }
251:
252:            protected void paintTopTabBorder(final int tabIndex,
253:                    final Graphics g, final int x, final int y, final int w,
254:                    final int h, final int btm, final int rght,
255:                    final boolean isSelected) {
256:                int[] xs = { x, x, x + 1, x + 3, x + 6, rght - 5, rght - 2,
257:                        rght, rght + 1, rght + 1 };
258:                int[] ys = { btm + 3, y + 6, y + 3, y + 1, y, y, y + 1, y + 3,
259:                        y + 6, btm + 4 };
260:                g.setColor(darkShadow);
261:                g.drawPolyline(xs, ys, xs.length);
262:
263:                int[] highlightXs = { x + 1, x + 1, x + 3, x + 6, rght - 4,
264:                        rght - 1 };
265:                int[] highlightYs = { btm + 3, y + 5, y + 2, y + 1, y + 1,
266:                        y + 3 };
267:                g.setColor(isSelected ? selectHighlight : highlight);
268:                g.drawPolyline(highlightXs, highlightYs, highlightXs.length);
269:            }
270:
271:            protected void paintTabBackground(final Graphics g,
272:                    final int tabPlacement, final int tabIndex, final int x,
273:                    final int y, final int w, final int h,
274:                    final boolean isSelected) {
275:                Color background = isSelected ? selectColor : tabPane
276:                        .getBackgroundAt(tabIndex);
277:                g.setColor(background);
278:
279:                g.fillRoundRect(x, y, w + 1, h + 1, 12, 12);
280:
281:                if (tabPlacement == TOP) {
282:                    g.fillRect(x + 1, y + h - 2, w - 1, 5);
283:                } else if (tabPlacement == LEFT) {
284:                    g.fillRect(x + w - 2, y + 1, 4, h - 1);
285:                } else if (tabPlacement == BOTTOM) {
286:                    g.fillRect(x + 1, y - 2, w - 1, 5);
287:                } else if (tabPlacement == RIGHT) {
288:                    g.fillRect(x, y + 1, 4, h - 1);
289:                }
290:            }
291:
292:            protected void paintTabBorder(final Graphics g,
293:                    final int tabPlacement, final int tabIndex, final int x,
294:                    final int y, final int w, final int h,
295:                    final boolean isSelected) {
296:                int btm = y + h - 1;
297:                int rght = x + w - 1;
298:                if (tabPlacement == TOP) {
299:                    paintTopTabBorder(tabIndex, g, x, y, w, h, btm, rght,
300:                            isSelected);
301:                } else if (tabPlacement == LEFT) {
302:                    paintLeftTabBorder(tabIndex, g, x, y, w, h, btm, rght,
303:                            isSelected);
304:                } else if (tabPlacement == RIGHT) {
305:                    paintRightTabBorder(tabIndex, g, x, y, w, h, btm, rght,
306:                            isSelected);
307:                } else if (tabPlacement == BOTTOM) {
308:                    paintBottomTabBorder(tabIndex, g, x, y, w, h, btm, rght,
309:                            isSelected);
310:                }
311:            }
312:
313:            protected boolean shouldFillGap(final int currentRun,
314:                    final int tabIndex, final int x, final int y) {
315:                return getAdjacentTab(x, y) != -1;
316:            }
317:
318:            protected boolean shouldPadTabRun(final int tabPlacement,
319:                    final int run) {
320:                if (runCount <= 1) {
321:                    return false;
322:                }
323:
324:                return run != runCount - 1;
325:            }
326:
327:            protected boolean shouldRotateTabRuns(final int tabPlacement,
328:                    final int selectedRun) {
329:                return false;
330:            }
331:
332:            public void update(final Graphics g, final JComponent c) {
333:                super .update(g, c);
334:            }
335:
336:            private boolean isTabAdjacentToContentAreaBorder(
337:                    final int selectedIndex) {
338:                return getRunForTab(tabPane.getTabCount(), selectedIndex) == 0;
339:            }
340:
341:            private int getAdjacentTab(final int x, final int y) {
342:                int newX = x;
343:                int newY = y;
344:                int tabPlacement = tabPane.getTabPlacement();
345:                switch (tabPlacement) {
346:                case TOP:
347:                case LEFT:
348:                case RIGHT:
349:                    newY--;
350:                    break;
351:                case BOTTOM:
352:                    newY++;
353:                    break;
354:                }
355:
356:                return tabForCoordinate(tabPane, newX, newY);
357:            }
358:
359:            private boolean isFocusPainted(final int tabIndex) {
360:                if (tabIndex != getFocusIndex()) {
361:                    return false;
362:                }
363:
364:                return tabPane.getIconAt(tabIndex) != null
365:                        || !Utilities.isEmptyString(tabPane
366:                                .getTitleAt(tabIndex));
367:            }
368:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.