~ubuntu-branches/ubuntu/quantal/netbeans/quantal

« back to all changes in this revision

Viewing changes to core/swing/tabcontrol/src/org/netbeans/swing/tabcontrol/plaf/AquaEditorTabDisplayerUI.java

  • Committer: Bazaar Package Importer
  • Author(s): Marek Slama
  • Date: 2008-01-29 14:11:22 UTC
  • Revision ID: james.westby@ubuntu.com-20080129141122-fnzjbo11ntghxfu7
Tags: upstream-6.0.1
ImportĀ upstreamĀ versionĀ 6.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 
3
 *
 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
 
5
 *
 
6
 * The contents of this file are subject to the terms of either the GNU
 
7
 * General Public License Version 2 only ("GPL") or the Common
 
8
 * Development and Distribution License("CDDL") (collectively, the
 
9
 * "License"). You may not use this file except in compliance with the
 
10
 * License. You can obtain a copy of the License at
 
11
 * http://www.netbeans.org/cddl-gplv2.html
 
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
 
13
 * specific language governing permissions and limitations under the
 
14
 * License.  When distributing the software, include this License Header
 
15
 * Notice in each file and include the License file at
 
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
 
17
 * particular file as subject to the "Classpath" exception as provided
 
18
 * by Sun in the GPL Version 2 section of the License file that
 
19
 * accompanied this code. If applicable, add the following below the
 
20
 * License Header, with the fields enclosed by brackets [] replaced by
 
21
 * your own identifying information:
 
22
 * "Portions Copyrighted [year] [name of copyright owner]"
 
23
 *
 
24
 * Contributor(s):
 
25
 *
 
26
 * The Original Software is NetBeans. The Initial Developer of the Original
 
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
 
28
 * Microsystems, Inc. All Rights Reserved.
 
29
 *
 
30
 * If you wish your version of this file to be governed by only the CDDL
 
31
 * or only the GPL Version 2, indicate your decision by adding
 
32
 * "[Contributor] elects to include this software in this distribution
 
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
 
34
 * single choice of license, a recipient has the option to distribute
 
35
 * your version of this file under either the CDDL, the GPL Version 2 or
 
36
 * to extend the choice of license to its licensees as provided above.
 
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
 
38
 * Version 2 license, then the option applies only if the new code is
 
39
 * made subject to such option by the copyright holder.
 
40
 */
 
41
/*
 
42
 * MetalEditorTabDisplayerUI.java
 
43
 *
 
44
 * Created on December 2, 2003, 9:40 PM
 
45
 */
 
46
 
 
47
package org.netbeans.swing.tabcontrol.plaf;
 
48
 
 
49
import java.awt.Color;
 
50
import java.awt.Container;
 
51
import java.awt.Dimension;
 
52
import java.awt.Font;
 
53
import java.awt.FontMetrics;
 
54
import java.awt.Graphics;
 
55
import java.awt.Insets;
 
56
import java.awt.Rectangle;
 
57
import org.netbeans.swing.tabcontrol.TabDisplayer;
 
58
import javax.swing.plaf.ComponentUI;
 
59
import java.util.HashMap;
 
60
import java.util.Map;
 
61
import javax.swing.Icon;
 
62
import javax.swing.JComponent;
 
63
import javax.swing.UIManager;
 
64
 
 
65
/**
 
66
 * A provisional look and feel for OS-X, round 2, using Java2d to emulate the
 
67
 * aqua look.
 
68
 *
 
69
 * @author Tim Boudreau
 
70
 */
 
71
public class AquaEditorTabDisplayerUI extends BasicScrollingTabDisplayerUI {
 
72
 
 
73
    /** Color used in drawing the line behind the tabs */
 
74
    private Color lineMiddleColor = null;
 
75
    /** Color used in drawing the line behind the tabs */
 
76
    private Color lineHlColor = null;
 
77
 
 
78
    private static Map<Integer, String[]> buttonIconPaths;
 
79
 
 
80
    public AquaEditorTabDisplayerUI (TabDisplayer displayer) {
 
81
        super (displayer);
 
82
    }
 
83
 
 
84
    public void install() {
 
85
        super.install();
 
86
        scroll().setMinimumXposition(9);
 
87
    }
 
88
 
 
89
    protected TabCellRenderer createDefaultRenderer() {
 
90
        return new AquaEditorTabCellRenderer();
 
91
    }
 
92
 
 
93
    public Insets getTabAreaInsets() {
 
94
        Insets result = super.getTabAreaInsets();
 
95
        result.bottom = 2;
 
96
        return result;
 
97
    }
 
98
    
 
99
    public static ComponentUI createUI(JComponent c) {
 
100
        return new AquaEditorTabDisplayerUI ((TabDisplayer) c);
 
101
    }
 
102
 
 
103
    protected boolean isAntialiased() {
 
104
        return true;
 
105
    }
 
106
    
 
107
    protected Font createFont() {
 
108
        return UIManager.getFont("Label.font"); //NOI18N
 
109
    }    
 
110
    
 
111
    protected int createRepaintPolicy () {
 
112
        return TabState.REPAINT_SELECTION_ON_ACTIVATION_CHANGE
 
113
                | TabState.REPAINT_ON_SELECTION_CHANGE
 
114
                | TabState.REPAINT_ALL_ON_MOUSE_ENTER_TABS_AREA
 
115
                | TabState.REPAINT_ON_MOUSE_ENTER_CLOSE_BUTTON
 
116
                | TabState.REPAINT_ON_CLOSE_BUTTON_PRESSED
 
117
                | TabState.REPAINT_ON_MOUSE_PRESSED;
 
118
    }
 
119
    
 
120
    public Dimension getPreferredSize(JComponent c) {
 
121
        int prefHeight = 28;
 
122
        //Never call getGraphics() on the control, it resets in-process
 
123
        //painting on OS-X 1.4.1 and triggers gratuitous repaints
 
124
        Graphics g = BasicScrollingTabDisplayerUI.getOffscreenGraphics();
 
125
        if (g != null) {
 
126
            FontMetrics fm = g.getFontMetrics(displayer.getFont());
 
127
            Insets ins = getTabAreaInsets();
 
128
            prefHeight = fm.getHeight() + ins.top + ins.bottom + 7;
 
129
        }
 
130
        if (prefHeight % 2 == 0) {
 
131
            prefHeight += 1;
 
132
        }
 
133
        return new Dimension(displayer.getWidth(), prefHeight);
 
134
    }
 
135
 
 
136
    protected void paintAfterTabs(Graphics g) {
 
137
        //Draw the continuation of the rounded border behind the buttons
 
138
        //and tabs
 
139
        
 
140
        int centerY = (((displayer.getHeight() - 
 
141
            (AquaEditorTabCellRenderer.TOP_INSET + AquaEditorTabCellRenderer.BOTTOM_INSET)) / 2) 
 
142
            + AquaEditorTabCellRenderer.TOP_INSET - 1) + getTabAreaInsets().top + 1;
 
143
        
 
144
        if (lineMiddleColor == null) {
 
145
            lineMiddleColor = ColorUtil.getMiddle(UIManager.getColor("controlShadow"), 
 
146
            UIManager.getColor("control")); //NOI18N
 
147
        }
 
148
        g.setColor (lineMiddleColor);
 
149
        
 
150
        int rightLineStart = getTabsAreaWidth() - 13;
 
151
        int rightLineEnd = displayer.getWidth() - 9;
 
152
        
 
153
        if (displayer.getModel().size() > 0 && !scroll().isLastTabClipped()) {
 
154
            //Extend the line out to the edge of the last visible tab
 
155
            //if none are clipped
 
156
            int idx = scroll().getLastVisibleTab(displayer.getWidth());
 
157
            rightLineStart = scroll().getX(idx) + scroll().getW(idx);
 
158
        } else if (displayer.getModel().size() == 0) {
 
159
            rightLineStart = 6;
 
160
        }
 
161
        
 
162
        if (scroll().getOffset() >= 0) {
 
163
            //fill the left edge notch
 
164
            g.drawLine(6, centerY, 11, centerY);
 
165
        }
 
166
        g.drawLine(rightLineStart, centerY, rightLineEnd, centerY);
 
167
        
 
168
        if (lineHlColor == null) {
 
169
            lineHlColor = ColorUtil.getMiddle (lineMiddleColor, 
 
170
            UIManager.getColor("control"));
 
171
        }
 
172
        
 
173
        g.setColor (lineHlColor); //NOI18N
 
174
        g.drawLine(rightLineStart, centerY+1, rightLineEnd, centerY+1);
 
175
        if (scroll().getOffset() > 0) {
 
176
            //fill the left edge notch
 
177
            g.drawLine(6, centerY+1, 11, centerY+1);
 
178
        }
 
179
    }
 
180
    
 
181
 
 
182
    private static void initIcons() {
 
183
        if( null == buttonIconPaths ) {
 
184
            buttonIconPaths = new HashMap<Integer, String[]>(7);
 
185
            
 
186
            //left button
 
187
            String[] iconPaths = new String[4];
 
188
            iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/mac_scrollleft_enabled.png"; // NOI18N
 
189
            iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/mac_scrollleft_disabled.png"; // NOI18N
 
190
            iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/mac_scrollleft_rollover.png"; // NOI18N
 
191
            iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/mac_scrollleft_pressed.png"; // NOI18N
 
192
            buttonIconPaths.put( TabControlButton.ID_SCROLL_LEFT_BUTTON, iconPaths );
 
193
            
 
194
            //right button
 
195
            iconPaths = new String[4];
 
196
            iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/mac_scrollright_enabled.png"; // NOI18N
 
197
            iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/mac_scrollright_disabled.png"; // NOI18N
 
198
            iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/mac_scrollright_rollover.png"; // NOI18N
 
199
            iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/mac_scrollright_pressed.png"; // NOI18N
 
200
            buttonIconPaths.put( TabControlButton.ID_SCROLL_RIGHT_BUTTON, iconPaths );
 
201
            
 
202
            //drop down button
 
203
            iconPaths = new String[4];
 
204
            iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/mac_popup_enabled.png"; // NOI18N
 
205
            iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/mac_popup_disabled.png"; // NOI18N
 
206
            iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/mac_popup_rollover.png"; // NOI18N
 
207
            iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/mac_popup_pressed.png"; // NOI18N
 
208
            buttonIconPaths.put( TabControlButton.ID_DROP_DOWN_BUTTON, iconPaths );
 
209
            
 
210
            //maximize/restore button
 
211
            iconPaths = new String[4];
 
212
            iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/mac_maximize_enabled.png"; // NOI18N
 
213
            iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/mac_maximize_disabled.png"; // NOI18N
 
214
            iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/mac_maximize_rollover.png"; // NOI18N
 
215
            iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/mac_maximize_pressed.png"; // NOI18N
 
216
            buttonIconPaths.put( TabControlButton.ID_MAXIMIZE_BUTTON, iconPaths );
 
217
            
 
218
            iconPaths = new String[4];
 
219
            iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/mac_restore_enabled.png"; // NOI18N
 
220
            iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/mac_restore_disabled.png"; // NOI18N
 
221
            iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/mac_restore_rollover.png"; // NOI18N
 
222
            iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/mac_restore_pressed.png"; // NOI18N
 
223
            buttonIconPaths.put( TabControlButton.ID_RESTORE_BUTTON, iconPaths );
 
224
        }
 
225
    }
 
226
 
 
227
    public Icon getButtonIcon(int buttonId, int buttonState) {
 
228
        Icon res = null;
 
229
        initIcons();
 
230
        String[] paths = buttonIconPaths.get( buttonId );
 
231
        if( null != paths && buttonState >=0 && buttonState < paths.length ) {
 
232
            res = TabControlButtonFactory.getIcon( paths[buttonState] );
 
233
        }
 
234
        return res;
 
235
    }
 
236
 
 
237
    protected Rectangle getControlButtonsRectangle(Container parent) {
 
238
        int centerY = (((displayer.getHeight() - (AquaEditorTabCellRenderer.TOP_INSET
 
239
                + AquaEditorTabCellRenderer.BOTTOM_INSET)) / 2) + AquaEditorTabCellRenderer.TOP_INSET)
 
240
                + getTabAreaInsets().top;
 
241
        
 
242
        int width = parent.getWidth();
 
243
        int height = parent.getHeight();
 
244
        int buttonsWidth = getControlButtons().getWidth();
 
245
        int buttonsHeight = getControlButtons().getHeight();
 
246
        return new Rectangle( width-buttonsWidth-3, centerY-buttonsHeight/2, buttonsWidth, buttonsHeight );
 
247
    }
 
248
}