KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > swing > tabcontrol > plaf > GtkEditorTabDisplayerUI


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 /*
20  * GtkEditorTabDisplayerUI.java
21  *
22  * Created on 09 December 2003, 16:53
23  */

24
25 package org.netbeans.swing.tabcontrol.plaf;
26
27 import java.awt.Component JavaDoc;
28 import java.awt.Container JavaDoc;
29 import java.awt.Dimension JavaDoc;
30 import java.awt.FontMetrics JavaDoc;
31 import java.awt.Graphics JavaDoc;
32 import java.awt.Insets JavaDoc;
33 import java.awt.Rectangle JavaDoc;
34 import java.util.HashMap JavaDoc;
35 import java.util.Map JavaDoc;
36 import javax.swing.Icon JavaDoc;
37 import javax.swing.JComponent JavaDoc;
38 import org.netbeans.swing.tabcontrol.TabDisplayer;
39
40 import javax.swing.plaf.ComponentUI JavaDoc;
41
42 /**
43  * Gtk impl of tabs ui
44  *
45  * @author Marek Slama
46  */

47 public final class GtkEditorTabDisplayerUI extends BasicScrollingTabDisplayerUI {
48     
49     private static Map JavaDoc<Integer JavaDoc, String JavaDoc[]> buttonIconPaths;
50     
51     /**
52      * Creates a new instance of GtkEditorTabDisplayerUI
53      */

54     public GtkEditorTabDisplayerUI(TabDisplayer displayer) {
55         super (displayer);
56     }
57     
58     public static ComponentUI JavaDoc createUI(JComponent JavaDoc c) {
59         return new GtkEditorTabDisplayerUI ((TabDisplayer) c);
60     }
61
62     public Rectangle JavaDoc getTabRect(int idx, Rectangle JavaDoc rect) {
63         Rectangle JavaDoc r = super.getTabRect (idx, rect);
64         //For win classic, take up the full space, even the insets, to match
65
//earlier appearance
66
r.y = 0;
67         r.height = displayer.getHeight();
68         return r;
69     }
70
71     public void install() {
72         super.install();
73     }
74
75     public Dimension JavaDoc getPreferredSize(JComponent JavaDoc c) {
76         int prefHeight = 28;
77         Graphics JavaDoc g = BasicScrollingTabDisplayerUI.getOffscreenGraphics();
78         if (g != null) {
79             FontMetrics JavaDoc fm = g.getFontMetrics(displayer.getFont());
80             Insets JavaDoc ins = getTabAreaInsets();
81             prefHeight = fm.getHeight() + ins.top + ins.bottom + 12;
82         }
83         return new Dimension JavaDoc(displayer.getWidth(), prefHeight);
84     }
85     
86     protected void paintAfterTabs(Graphics JavaDoc g) {
87     }
88
89     protected TabCellRenderer createDefaultRenderer() {
90         return new GtkEditorTabCellRenderer();
91     }
92
93     private static void initIcons() {
94         if( null == buttonIconPaths ) {
95             buttonIconPaths = new HashMap JavaDoc<Integer JavaDoc, String JavaDoc[]>(7);
96             
97             //left button
98
String JavaDoc[] iconPaths = new String JavaDoc[4];
99             iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/gtk_scrollleft_enabled.png"; // NOI18N
100
iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/gtk_scrollleft_disabled.png"; // NOI18N
101
iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/gtk_scrollleft_rollover.png"; // NOI18N
102
iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/gtk_scrollleft_pressed.png"; // NOI18N
103
buttonIconPaths.put( TabControlButton.ID_SCROLL_LEFT_BUTTON, iconPaths );
104             
105             //right button
106
iconPaths = new String JavaDoc[4];
107             iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/gtk_scrollright_enabled.png"; // NOI18N
108
iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/gtk_scrollright_disabled.png"; // NOI18N
109
iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/gtk_scrollright_rollover.png"; // NOI18N
110
iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/gtk_scrollright_pressed.png"; // NOI18N
111
buttonIconPaths.put( TabControlButton.ID_SCROLL_RIGHT_BUTTON, iconPaths );
112             
113             //drop down button
114
iconPaths = new String JavaDoc[4];
115             iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/gtk_popup_enabled.png"; // NOI18N
116
iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/gtk_popup_disabled.png"; // NOI18N
117
iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/gtk_popup_rollover.png"; // NOI18N
118
iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/gtk_popup_pressed.png"; // NOI18N
119
buttonIconPaths.put( TabControlButton.ID_DROP_DOWN_BUTTON, iconPaths );
120             
121             //maximize/restore button
122
iconPaths = new String JavaDoc[4];
123             iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/gtk_maximize_enabled.png"; // NOI18N
124
iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/gtk_maximize_disabled.png"; // NOI18N
125
iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/gtk_maximize_rollover.png"; // NOI18N
126
iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/gtk_maximize_pressed.png"; // NOI18N
127
buttonIconPaths.put( TabControlButton.ID_MAXIMIZE_BUTTON, iconPaths );
128             
129             iconPaths = new String JavaDoc[4];
130             iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/gtk_restore_enabled.png"; // NOI18N
131
iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/gtk_restore_disabled.png"; // NOI18N
132
iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/gtk_restore_rollover.png"; // NOI18N
133
iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/gtk_restore_pressed.png"; // NOI18N
134
buttonIconPaths.put( TabControlButton.ID_RESTORE_BUTTON, iconPaths );
135         }
136     }
137
138     public Icon JavaDoc getButtonIcon(int buttonId, int buttonState) {
139         Icon JavaDoc res = null;
140         initIcons();
141         String JavaDoc[] paths = buttonIconPaths.get( buttonId );
142         if( null != paths && buttonState >=0 && buttonState < paths.length ) {
143             res = TabControlButtonFactory.getIcon( paths[buttonState] );
144         }
145         return res;
146     }
147     
148     protected Rectangle JavaDoc getControlButtonsRectangle( Container JavaDoc parent ) {
149         Component JavaDoc c = getControlButtons();
150         return new Rectangle JavaDoc( parent.getWidth()-c.getWidth()-4, 4, c.getWidth(), c.getHeight() );
151     }
152
153     public Insets JavaDoc getTabAreaInsets() {
154         Insets JavaDoc retValue = super.getTabAreaInsets();
155         retValue.right += 4;
156         return retValue;
157     }
158 }
159
Popular Tags