Source Code Cross Referenced for BasicPullDownButtonUI.java in  » IDE-Netbeans » uml » org » netbeans » modules » uml » ui » swing » plaf » basic » 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 » IDE Netbeans » uml » org.netbeans.modules.uml.ui.swing.plaf.basic 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:
042:        package org.netbeans.modules.uml.ui.swing.plaf.basic;
043:
044:        import java.awt.Color;
045:        import java.awt.Dimension;
046:        import java.awt.Font;
047:        import java.awt.FontMetrics;
048:        import java.awt.Graphics;
049:        import java.awt.Insets;
050:        import java.awt.Point;
051:        import java.awt.Rectangle;
052:        import java.awt.event.MouseAdapter;
053:        import java.awt.event.MouseEvent;
054:        import java.awt.event.MouseListener;
055:
056:        import javax.swing.AbstractButton;
057:        import javax.swing.ButtonModel;
058:        import javax.swing.Icon;
059:        import javax.swing.JComponent;
060:        import javax.swing.LookAndFeel;
061:        import javax.swing.MenuElement;
062:        import javax.swing.MenuSelectionManager;
063:        import javax.swing.SwingUtilities;
064:        import javax.swing.UIManager;
065:        import javax.swing.border.Border;
066:        import javax.swing.plaf.ComponentUI;
067:        import javax.swing.plaf.UIResource;
068:        import javax.swing.plaf.basic.BasicButtonListener;
069:        import javax.swing.plaf.basic.BasicGraphicsUtils;
070:        import javax.swing.plaf.basic.BasicHTML;
071:        import javax.swing.text.View;
072:
073:        import org.netbeans.modules.uml.ui.swing.plaf.PullDownButtonUI;
074:        import org.netbeans.modules.uml.ui.swing.pulldownbutton.IPulldownButtonInvoker;
075:        import org.netbeans.modules.uml.ui.swing.pulldownbutton.JPullDownButton;
076:
077:        /**
078:         * 
079:         * @author Trey Spiva
080:         */
081:        public class BasicPullDownButtonUI extends PullDownButtonUI {
082:            // Shared UI object
083:            private final static BasicPullDownButtonUI buttonUI = new BasicPullDownButtonUI();
084:
085:            /* These rectangles/insets are allocated once for all 
086:             * ButtonUI.paint() calls.  Re-using rectangles rather than 
087:             * allocating them in each paint call substantially reduced the time
088:             * it took paint to run.  Obviously, this method can't be re-entered.
089:             */
090:
091:            // Visual constants
092:            protected int defaultTextIconGap;
093:
094:            // Offset controlled by set method 
095:            private int shiftOffset = 0;
096:            protected int defaultTextShiftOffset;
097:
098:            // Has the shared instance defaults been initialized?
099:            private boolean defaults_initialized = false;
100:
101:            private JPullDownButton m_Button = null;
102:
103:            private int m_ArrowWidth = 6;
104:            private int m_ArrowInsetWidth = 3;
105:            private int m_LargeArrowWidth = 16;
106:
107:            private final static String propertyPrefix = "Button" + ".";
108:
109:            // ********************************
110:            //          Create PLAF
111:            // ********************************
112:            public static ComponentUI createUI(JComponent c) {
113:                return buttonUI;
114:            }
115:
116:            protected String getPropertyPrefix() {
117:                return propertyPrefix;
118:            }
119:
120:            // ********************************
121:            //          Install PLAF
122:            // ********************************
123:            public void installUI(JComponent c) {
124:                m_Button = (JPullDownButton) c;
125:
126:                installDefaults(m_Button);
127:                installListeners(m_Button);
128:                installKeyboardActions(m_Button);
129:                BasicHTML.updateRenderer(c, m_Button.getText());
130:            }
131:
132:            private Color defaultForeground = null;
133:            private Color defaultBackground = null;
134:            private Font defaultFont = null;
135:            private Border defaultBorder = null;
136:
137:            protected void installDefaults(AbstractButton b) {
138:                // load shared instance defaults
139:                String pp = getPropertyPrefix();
140:                if (!defaults_initialized) {
141:                    defaultTextIconGap = ((Integer) UIManager.get(pp
142:                            + "textIconGap")).intValue();
143:                    defaultTextShiftOffset = ((Integer) UIManager.get(pp
144:                            + "textShiftOffset")).intValue();
145:
146:                    // next four lines part of optimized component defaults installation
147:                    /* defaultForeground = UIManager.getColor(pp + "foreground");
148:                     defaultBackground = UIManager.getColor(pp + "background");
149:                     defaultFont = UIManager.getFont(pp + "font");
150:                     defaultBorder = UIManager.getBorder(pp + "border");*/
151:
152:                    defaults_initialized = true;
153:                }
154:
155:                // set the following defaults on the button
156:                if (b.isContentAreaFilled()) {
157:                    b.setOpaque(true);
158:                } else {
159:                    b.setOpaque(false);
160:                }
161:
162:                if (b.getMargin() == null
163:                        || (b.getMargin() instanceof  UIResource)) {
164:                    b.setMargin(UIManager.getInsets(pp + "margin"));
165:                }
166:
167:                // *** begin optimized defaults install ***
168:
169:                /* Color currentForeground = b.getForeground();
170:                   Color currentBackground = b.getBackground();
171:                   Font currentFont = b.getFont();
172:                   Border currentBorder = b.getBorder();
173:                
174:                   if (currentForeground == null || currentForeground instanceof UIResource) {
175:                         b.setForeground(defaultForeground);
176:                   }
177:                
178:                   if (currentBackground == null || currentBackground instanceof UIResource) {
179:                              b.setBackground(defaultBackground);
180:                   }
181:                
182:                   if (currentFont == null || currentFont instanceof UIResource) {
183:                         b.setFont(defaultFont);
184:                   }
185:                
186:                   if (currentBorder == null || currentBorder instanceof UIResource) {
187:                         b.setBorder(defaultBorder);
188:                   } */
189:
190:                // *** end optimized defaults install ***
191:                // old code below works for component defaults installation, but it is slow
192:                LookAndFeel.installColorsAndFont(b, pp + "background", pp
193:                        + "foreground", pp + "font");
194:                LookAndFeel.installBorder(b, pp + "border");
195:
196:            }
197:
198:            protected void installListeners(AbstractButton b) {
199:                BasicButtonListener listener = createButtonListener(b);
200:                if (listener != null) {
201:                    // put the listener in the button's client properties so that
202:                    // we can get at it later
203:                    b.putClientProperty(this , listener);
204:
205:                    b.addMouseListener(listener);
206:                    b.addMouseMotionListener(listener);
207:                    b.addFocusListener(listener);
208:                    b.addPropertyChangeListener(listener);
209:                    b.addChangeListener(listener);
210:                }
211:
212:                //      FocusListener fListener = createFocusListener();
213:                //      if (fListener != null)
214:                //      {
215:                //         b.addFocusListener(fListener);
216:                //      }
217:
218:                MouseListener popupMouseListener = new InvocationMouseHandler();
219:                if (popupMouseListener != null) {
220:                    b.addMouseListener(popupMouseListener);
221:                }
222:            }
223:
224:            protected void installKeyboardActions(AbstractButton b) {
225:                BasicButtonListener listener = (BasicButtonListener) b
226:                        .getClientProperty(this );
227:                if (listener != null) {
228:                    listener.installKeyboardActions(b);
229:                }
230:            }
231:
232:            // ********************************
233:            //         Uninstall PLAF
234:            // ********************************
235:            public void uninstallUI(JComponent c) {
236:                setPopupVisible(m_Button, false);
237:
238:                uninstallKeyboardActions((AbstractButton) c);
239:                uninstallListeners((AbstractButton) c);
240:                uninstallDefaults((AbstractButton) c);
241:                BasicHTML.updateRenderer(c, "");
242:            }
243:
244:            protected void uninstallKeyboardActions(AbstractButton b) {
245:                BasicButtonListener listener = (BasicButtonListener) b
246:                        .getClientProperty(this );
247:                if (listener != null) {
248:                    listener.uninstallKeyboardActions(b);
249:                }
250:            }
251:
252:            protected void uninstallListeners(AbstractButton b) {
253:                BasicButtonListener listener = (BasicButtonListener) b
254:                        .getClientProperty(this );
255:                b.putClientProperty(this , null);
256:                if (listener != null) {
257:                    b.removeMouseListener(listener);
258:                    b.removeMouseListener(listener);
259:                    b.removeMouseMotionListener(listener);
260:                    b.removeFocusListener(listener);
261:                    b.removeChangeListener(listener);
262:                    b.removePropertyChangeListener(listener);
263:                }
264:            }
265:
266:            protected void uninstallDefaults(AbstractButton b) {
267:                LookAndFeel.uninstallBorder(b);
268:                defaults_initialized = false;
269:            }
270:
271:            //**************************************************
272:            // Popup Control Methods
273:            //**************************************************
274:
275:            /**
276:             * Tells if the popup is visible or not.
277:             */
278:            public boolean isPopupVisible() {
279:                boolean retVal = false;
280:                if (m_Button != null) {
281:                    IPulldownButtonInvoker invoker = m_Button
282:                            .getPulldownInvoker();
283:                    if (invoker != null) {
284:                        retVal = invoker.isPulldownVisible();
285:                    }
286:                }
287:
288:                return retVal;
289:            }
290:
291:            /**
292:             * Hides the popup.
293:             */
294:            public void setPopupVisible(JPullDownButton c, boolean v) {
295:                if (v = true) {
296:                    show();
297:                } else {
298:                    hide();
299:                }
300:            }
301:
302:            /**
303:             * Implementation of ComboPopup.show().
304:             */
305:            public void show() {
306:                if (m_Button != null) {
307:                    IPulldownButtonInvoker invoker = m_Button
308:                            .getPulldownInvoker();
309:                    if (invoker != null) {
310:                        invoker.showPulldown(m_Button);
311:                    }
312:                }
313:            }
314:
315:            /**
316:             * Implementation of ComboPopup.hide().
317:             */
318:            public void hide() {
319:                MenuSelectionManager manager = MenuSelectionManager
320:                        .defaultManager();
321:                MenuElement[] selection = manager.getSelectedPath();
322:                for (int i = 0; i < selection.length; i++) {
323:                    if (selection[i] == this ) {
324:                        manager.clearSelectedPath();
325:                        break;
326:                    }
327:                }
328:                if (selection.length > 0) {
329:                    m_Button.repaint();
330:                }
331:            }
332:
333:            // ********************************
334:            //        Create Listeners 
335:            // ********************************
336:            protected BasicButtonListener createButtonListener(AbstractButton b) {
337:                //      m_PullDown = new JPopupMenu();
338:                return new BasicButtonListener(b) {
339:                    public void mousePressed(MouseEvent e) {
340:                        if (SwingUtilities.isLeftMouseButton(e)) {
341:                            AbstractButton b = (AbstractButton) e.getSource();
342:                            if (isButtonPressed(e.getX(), e.getY()) == true) {
343:                                // show();
344:                                if (b.contains(e.getX(), e.getY())) {
345:                                    long multiClickThreshhold = b
346:                                            .getMultiClickThreshhold();
347:
348:                                    ButtonModel model = b.getModel();
349:                                    if (model.isEnabled() == true) {
350:                                        if (!model.isArmed()) {
351:                                            // button not armed, should be
352:                                            model.setArmed(true);
353:                                        }
354:
355:                                        //model.setPressed(true);
356:                                        m_Button.setArrowButtonPressed(true);
357:                                        if (!b.hasFocus()
358:                                                && b.isRequestFocusEnabled()) {
359:                                            b.requestFocus();
360:                                        }
361:                                    }
362:                                }
363:                            } else {
364:                                super .mousePressed(e);
365:                                m_Button.setArrowButtonPressed(false);
366:                            }
367:                        }
368:                    }
369:
370:                    public void mouseReleased(MouseEvent e) {
371:                        m_Button.setArrowButtonPressed(false);
372:                        if (SwingUtilities.isLeftMouseButton(e)) {
373:                            super .mouseReleased(e);
374:                            AbstractButton b = (AbstractButton) e.getSource();
375:                            if (isButtonPressed(e.getX(), e.getY()) == true) {
376:                                show();
377:                            }
378:                        }
379:                    }
380:                };
381:            }
382:
383:            protected boolean isButtonPressed(int x, int y) {
384:                boolean retVal = false;
385:
386:                if (isArrowButton() == false) {
387:                    Insets insets = m_Button.getInsets();
388:
389:                    int arrowWidth = m_ArrowWidth + (m_ArrowInsetWidth * 2)
390:                            + insets.right;
391:                    if ((x < m_Button.getWidth())
392:                            && (x > m_Button.getWidth() - arrowWidth)) {
393:                        retVal = true;
394:                    }
395:                } else {
396:                    retVal = true;
397:                }
398:
399:                return retVal;
400:            }
401:
402:            public int getDefaultTextIconGap(AbstractButton b) {
403:                return defaultTextIconGap;
404:            }
405:
406:            protected Color getSelectColor() {
407:                return UIManager.getColor(getPropertyPrefix() + "select");
408:            }
409:
410:            protected Color getDisabledTextColor() {
411:                return UIManager.getColor(getPropertyPrefix() + "disabledText");
412:            }
413:
414:            protected Color getFocusColor() {
415:                return UIManager.getColor(getPropertyPrefix() + "focus");
416:            }
417:
418:            /**
419:             * A listener to be registered upon the combo box
420:             * (<em>not</em> its popup menu)
421:             * to handle mouse events
422:             * that affect the state of the popup menu.
423:             * The main purpose of this listener is to make the popup menu
424:             * appear and disappear.
425:             * This listener also helps
426:             * with click-and-drag scenarios by setting the selection if the mouse was
427:             * released over the list during a drag.
428:             *
429:             * <p>
430:             * <strong>Warning:</strong>
431:             * We recommend that you <em>not</em> 
432:             * create subclasses of this class.
433:             * If you absolutely must create a subclass,
434:             * be sure to invoke the superclass
435:             * version of each method.
436:             *
437:             * @see BasicComboPopup#createMouseListener
438:             */
439:            protected class InvocationMouseHandler extends MouseAdapter {
440:                /**
441:                 * Responds to mouse-pressed events on the combo box.
442:                 *
443:                 * @param e the mouse-press event to be handled
444:                 */
445:                public void mousePressed(MouseEvent e) {
446:                }
447:
448:                /**
449:                 * Responds to the user terminating
450:                 * a click or drag that began on the combo box.
451:                 *
452:                 * @param e the mouse-release event to be handled
453:                 */
454:                public void mouseReleased(MouseEvent e) {
455:
456:                }
457:            }
458:
459:            /**
460:             * 
461:             */
462:            protected void togglePopup() {
463:                //m_PullDown.setVisible(!m_PullDown.isVisible());
464:                if (isPopupVisible() == true) {
465:                    hide();
466:                } else {
467:                    show();
468:                }
469:            }
470:
471:            //   protected MouseEvent convertMouseEvent(MouseEvent e)
472:            //   {
473:            //      Point convertedPoint = SwingUtilities.convertPoint((Component)e.getSource(), e.getPoint(), list);
474:            //      MouseEvent newEvent = new MouseEvent((Component)e.getSource(), e.getID(), e.getWhen(), e.getModifiers(), convertedPoint.x, convertedPoint.y, e.getClickCount(), e.isPopupTrigger());
475:            //      
476:            //      return newEvent;
477:            //   }
478:            //**************************************************
479:            // BannerMsg
480:            //**************************************************
481:
482:            /**
483:             * Calculate the placement and size of the popup portion of the combo box based
484:             * on the combo box location and the enclosing screen bounds. If
485:             * no transformations are required, then the returned rectangle will
486:             * have the same values as the parameters.
487:             * 
488:             * @param px starting x location
489:             * @param py starting y location
490:             * @param pw starting width
491:             * @param ph starting height
492:             * @return a rectangle which represents the placement and size of the popup
493:             */
494:            //protected Rectangle computePopupBounds(int px,int py,int pw, int ph) 
495:            protected Point computePopupLocation(int height) {
496:                //      Toolkit toolkit = Toolkit.getDefaultToolkit();
497:                //      Rectangle screenBounds;
498:                //
499:                //      // Calculate the desktop dimensions relative to the combo box.
500:                //      GraphicsConfiguration gc = m_Button.getGraphicsConfiguration();
501:                //      Point offset = new Point();
502:                //      SwingUtilities.convertPointFromScreen(offset, m_Button);
503:                //
504:                //      Point location = new Point(Math.abs(offset.x), Math.abs(offset.y) + height);
505:                //      return location;
506:
507:                return new Point(0, m_Button.getHeight());
508:            }
509:
510:            //**************************************************
511:            // Paint Routines
512:            //**************************************************
513:
514:            public void paint(Graphics g, JComponent c) {
515:                AbstractButton b = (AbstractButton) c;
516:                ButtonModel model = b.getModel();
517:
518:                FontMetrics fm = g.getFontMetrics();
519:
520:                Insets i = c.getInsets();
521:
522:                g.setColor(c.getForeground());
523:
524:                int arrowWidth = m_LargeArrowWidth;
525:
526:                Rectangle viewRect = new Rectangle();
527:                Rectangle textRect = new Rectangle();
528:                Rectangle iconRect = new Rectangle();
529:
530:                // perform UI specific press action, e.g. Windows L&F shifts text
531:                if ((model.isArmed() && model.isPressed())
532:                        || (m_Button.isArrowButtonPressed() == true)) {
533:                    paintButtonPressed(g, b);
534:                }
535:
536:                if (isArrowButton() == false) {
537:                    arrowWidth = m_ArrowWidth;
538:
539:                    int btnWidth = b.getWidth()
540:                            - (m_ArrowWidth + (m_ArrowInsetWidth * 2));
541:                    viewRect.x = i.left;
542:                    viewRect.y = i.top;
543:                    viewRect.width = btnWidth - (i.right + viewRect.x);
544:                    viewRect.height = b.getHeight() - (i.bottom + viewRect.y);
545:
546:                    textRect.x = textRect.y = textRect.width = textRect.height = 0;
547:                    iconRect.x = iconRect.y = iconRect.width = iconRect.height = 0;
548:
549:                    Font f = c.getFont();
550:                    g.setFont(f);
551:
552:                    // layout the text and icon
553:                    String text = SwingUtilities.layoutCompoundLabel(c, fm, b
554:                            .getText(), b.getIcon(), b.getVerticalAlignment(),
555:                            b.getHorizontalAlignment(), b
556:                                    .getVerticalTextPosition(), b
557:                                    .getHorizontalTextPosition(), viewRect,
558:                            iconRect, textRect, b.getText() == null ? 0 : b
559:                                    .getIconTextGap());
560:
561:                    clearTextShiftOffset();
562:
563:                    // Paint the Icon
564:                    if (b.getIcon() != null) {
565:                        paintIcon(g, c, iconRect);
566:                    }
567:
568:                    if (text != null && !text.equals("")) {
569:                        View v = (View) c
570:                                .getClientProperty(BasicHTML.propertyKey);
571:                        if (v != null) {
572:                            v.paint(g, textRect);
573:                        } else {
574:                            paintText(g, b, textRect, text);
575:                        }
576:                    }
577:                }
578:
579:                if (b.isFocusPainted() && b.hasFocus()) {
580:                    // paint UI specific focus
581:                    paintFocus(g, b, viewRect, textRect, iconRect);
582:                }
583:
584:                int x = 0;
585:                int y = 0;
586:
587:                Insets insets = c.getInsets();
588:                if ((iconRect != null) && (iconRect.width > 0)) {
589:                    x = iconRect.x + iconRect.width + m_ArrowInsetWidth;
590:                    y = iconRect.height / 2 + insets.top;
591:                }
592:
593:                if ((textRect != null) && (textRect.width > 0)) {
594:                    x = textRect.x + textRect.width + m_ArrowInsetWidth;
595:                    y = textRect.height / 2 + insets.top;
596:                }
597:
598:                if ((x == 0) && (y == 0)) {
599:                    x = (c.getWidth() / 2) / 2;
600:                    y = (c.getHeight() / 3);
601:                }
602:
603:                paintArrow(g, x, y, arrowWidth);
604:            }
605:
606:            protected void paintArrow(Graphics g, int x, int y, int width) {
607:                int[] triangleX = { x, x + width, x + (width / 2) };
608:                int[] triangleY = { y, y, y + (width / 2) };
609:                g.fillPolygon(triangleX, triangleY, 3);
610:
611:            }
612:
613:            protected void paintIcon(Graphics g, JComponent c,
614:                    Rectangle iconRect) {
615:                AbstractButton b = (AbstractButton) c;
616:                ButtonModel model = b.getModel();
617:                Icon icon = b.getIcon();
618:                Icon tmpIcon = null;
619:
620:                if (icon == null) {
621:                    return;
622:                }
623:
624:                if (!model.isEnabled()) {
625:                    if (model.isSelected()) {
626:                        tmpIcon = (Icon) b.getDisabledSelectedIcon();
627:                    } else {
628:                        tmpIcon = (Icon) b.getDisabledIcon();
629:                    }
630:                } else if (model.isPressed() && model.isArmed()) {
631:                    tmpIcon = (Icon) b.getPressedIcon();
632:                    if (tmpIcon != null) {
633:                        // revert back to 0 offset
634:                        clearTextShiftOffset();
635:                    }
636:                } else if (b.isRolloverEnabled() && model.isRollover()) {
637:                    if (model.isSelected()) {
638:                        tmpIcon = (Icon) b.getRolloverSelectedIcon();
639:                    } else {
640:                        tmpIcon = (Icon) b.getRolloverIcon();
641:                    }
642:                } else if (model.isSelected()) {
643:                    tmpIcon = (Icon) b.getSelectedIcon();
644:                }
645:
646:                if (tmpIcon != null) {
647:                    icon = tmpIcon;
648:                }
649:
650:                if (model.isPressed() && model.isArmed()) {
651:                    icon.paintIcon(c, g, iconRect.x + getTextShiftOffset(),
652:                            iconRect.y + getTextShiftOffset());
653:                } else {
654:                    icon.paintIcon(c, g, iconRect.x, iconRect.y);
655:                }
656:
657:            }
658:
659:            /**
660:             * As of Java 2 platform v 1.4 this method should not be used or overriden.
661:             * Use the paintText method which takes the AbstractButton argument.
662:             */
663:            protected void paintText(Graphics g, JComponent c,
664:                    Rectangle textRect, String text) {
665:                AbstractButton b = (AbstractButton) c;
666:                ButtonModel model = b.getModel();
667:                FontMetrics fm = g.getFontMetrics();
668:                int mnemonicIndex = b.getDisplayedMnemonicIndex();
669:
670:                /* Draw the Text */
671:                if (model.isEnabled()) {
672:                    /*** paint the text normally */
673:                    g.setColor(b.getForeground());
674:                    BasicGraphicsUtils.drawStringUnderlineCharAt(g, text,
675:                            mnemonicIndex, textRect.x + getTextShiftOffset(),
676:                            textRect.y + fm.getAscent() + getTextShiftOffset());
677:                } else {
678:                    /*** paint the text disabled ***/
679:                    g.setColor(b.getBackground().brighter());
680:                    BasicGraphicsUtils.drawStringUnderlineCharAt(g, text,
681:                            mnemonicIndex, textRect.x, textRect.y
682:                                    + fm.getAscent());
683:                    g.setColor(b.getBackground().darker());
684:                    BasicGraphicsUtils.drawStringUnderlineCharAt(g, text,
685:                            mnemonicIndex, textRect.x - 1, textRect.y
686:                                    + fm.getAscent() - 1);
687:                }
688:            }
689:
690:            /**
691:             * Method which renders the text of the current button.
692:             * <p>
693:             * @param g Graphics context
694:             * @param b Current button to render
695:             * @param textRect Bounding rectangle to render the text.
696:             * @param text String to render
697:             * @since 1.4
698:             */
699:            protected void paintText(Graphics g, AbstractButton b,
700:                    Rectangle textRect, String text) {
701:                paintText(g, (JComponent) b, textRect, text);
702:            }
703:
704:            // Method signature defined here overriden in subclasses. 
705:            // Perhaps this class should be abstract?
706:            protected void paintFocus(Graphics g, AbstractButton b,
707:                    Rectangle viewRect, Rectangle textRect, Rectangle iconRect) {
708:            }
709:
710:            // Method signature defined here overriden in subclasses. 
711:            // Perhaps this class should be abstract?
712:            protected void paintButtonPressed(Graphics g, AbstractButton b) {
713:                if (b.isContentAreaFilled()) {
714:                    Dimension size = b.getSize();
715:                    g.setColor(getSelectColor());
716:                    g.fillRect(0, 0, size.width, size.height);
717:                }
718:            }
719:
720:            protected void clearTextShiftOffset() {
721:                shiftOffset = 0;
722:            }
723:
724:            protected void setTextShiftOffset() {
725:                shiftOffset = defaultTextShiftOffset;
726:            }
727:
728:            protected int getTextShiftOffset() {
729:                return shiftOffset;
730:            }
731:
732:            // ********************************
733:            //          Layout Methods
734:            // ********************************
735:            public Dimension getMinimumSize(JComponent c) {
736:                Dimension d = getPreferredSize(c);
737:                adjustForArrow(c, d);
738:
739:                return d;
740:            }
741:
742:            public Dimension getPreferredSize(JComponent c) {
743:                AbstractButton b = (AbstractButton) c;
744:
745:                Dimension retVal = null;
746:
747:                Insets insets = c.getInsets();
748:
749:                retVal = BasicGraphicsUtils.getPreferredButtonSize(b, b
750:                        .getIconTextGap());
751:                if (isArrowButton() == false) {
752:                    retVal.width += m_ArrowWidth + (m_ArrowInsetWidth * 2);
753:                } else {
754:                    //retVal.width += insets.left + insets.right +  m_LargeArrowWidth;
755:                    //retVal.height += insets.top + insets.bottom + m_LargeArrowWidth;
756:                    retVal.width += insets.left + m_LargeArrowWidth;
757:                    retVal.height += insets.top + m_LargeArrowWidth;
758:                }
759:
760:                return retVal;
761:            }
762:
763:            public Dimension getMaximumSize(JComponent c) {
764:                Dimension d = getPreferredSize(c);
765:
766:                View v = (View) c.getClientProperty(BasicHTML.propertyKey);
767:                if (v != null) {
768:                    d.width += v.getMaximumSpan(View.X_AXIS)
769:                            - v.getPreferredSpan(View.X_AXIS);
770:                    d.width += m_ArrowWidth + (m_ArrowInsetWidth * 2);
771:                }
772:                return d;
773:            }
774:
775:            protected void adjustForArrow(JComponent c, Dimension dim) {
776:                //      View v = (View)c.getClientProperty(BasicHTML.propertyKey);
777:                //      if (v != null)
778:                //      {
779:                //         dim.width -= v.getPreferredSpan(View.X_AXIS) - v.getMinimumSpan(View.X_AXIS);         
780:                //      }
781:                //      
782:                //      if(isArrowButton() == false)
783:                //      {
784:                //         dim.width += m_ArrowWidth + (m_ArrowInsetWidth * 2);
785:                //      }
786:            }
787:
788:            protected boolean isArrowButton() {
789:                String text = m_Button.getText();
790:                Icon image = m_Button.getIcon();
791:
792:                boolean retVal = true;
793:
794:                if ((text != null) && (text.length() > 0)) {
795:                    retVal = false;
796:                } else if (image != null) {
797:                    retVal = false;
798:                }
799:
800:                return retVal;
801:            }
802:        }
w___w__w_.___j___a__va___2_s_.__c___o__m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.