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-2006 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: * GtkEditorTabDisplayerUI.java
043: *
044: * Created on 09 December 2003, 16:53
045: */
046:
047: package org.netbeans.swing.tabcontrol.plaf;
048:
049: import java.awt.Component;
050: import java.awt.Container;
051: import java.awt.Dimension;
052: import java.awt.FontMetrics;
053: import java.awt.Graphics;
054: import java.awt.Insets;
055: import java.awt.Rectangle;
056: import java.util.HashMap;
057: import java.util.Map;
058: import javax.swing.Icon;
059: import javax.swing.JComponent;
060: import org.netbeans.swing.tabcontrol.TabDisplayer;
061:
062: import javax.swing.plaf.ComponentUI;
063:
064: /**
065: * Gtk impl of tabs ui
066: *
067: * @author Marek Slama
068: */
069: public final class GtkEditorTabDisplayerUI extends
070: BasicScrollingTabDisplayerUI {
071:
072: private static Map<Integer, String[]> buttonIconPaths;
073:
074: /**
075: * Creates a new instance of GtkEditorTabDisplayerUI
076: */
077: public GtkEditorTabDisplayerUI(TabDisplayer displayer) {
078: super (displayer);
079: }
080:
081: public static ComponentUI createUI(JComponent c) {
082: return new GtkEditorTabDisplayerUI((TabDisplayer) c);
083: }
084:
085: public Rectangle getTabRect(int idx, Rectangle rect) {
086: Rectangle r = super .getTabRect(idx, rect);
087: //For win classic, take up the full space, even the insets, to match
088: //earlier appearance
089: r.y = 0;
090: r.height = displayer.getHeight();
091: return r;
092: }
093:
094: public void install() {
095: super .install();
096: }
097:
098: public Dimension getPreferredSize(JComponent c) {
099: int prefHeight = 28;
100: Graphics g = BasicScrollingTabDisplayerUI
101: .getOffscreenGraphics();
102: if (g != null) {
103: FontMetrics fm = g.getFontMetrics(displayer.getFont());
104: Insets ins = getTabAreaInsets();
105: prefHeight = fm.getHeight() + ins.top + ins.bottom + 12;
106: }
107: return new Dimension(displayer.getWidth(), prefHeight);
108: }
109:
110: protected void paintAfterTabs(Graphics g) {
111: }
112:
113: protected TabCellRenderer createDefaultRenderer() {
114: return new GtkEditorTabCellRenderer();
115: }
116:
117: private static void initIcons() {
118: if (null == buttonIconPaths) {
119: buttonIconPaths = new HashMap<Integer, String[]>(7);
120:
121: //left button
122: String[] iconPaths = new String[4];
123: iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/gtk_scrollleft_enabled.png"; // NOI18N
124: iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/gtk_scrollleft_disabled.png"; // NOI18N
125: iconPaths[TabControlButton.STATE_ROLLOVER] = iconPaths[TabControlButton.STATE_DEFAULT];
126: iconPaths[TabControlButton.STATE_PRESSED] = iconPaths[TabControlButton.STATE_DEFAULT];
127: buttonIconPaths.put(TabControlButton.ID_SCROLL_LEFT_BUTTON,
128: iconPaths);
129:
130: //right button
131: iconPaths = new String[4];
132: iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/gtk_scrollright_enabled.png"; // NOI18N
133: iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/gtk_scrollright_disabled.png"; // NOI18N
134: iconPaths[TabControlButton.STATE_ROLLOVER] = iconPaths[TabControlButton.STATE_DEFAULT];
135: iconPaths[TabControlButton.STATE_PRESSED] = iconPaths[TabControlButton.STATE_DEFAULT];
136: buttonIconPaths.put(
137: TabControlButton.ID_SCROLL_RIGHT_BUTTON, iconPaths);
138:
139: //drop down button
140: iconPaths = new String[4];
141: iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/gtk_popup_enabled.png"; // NOI18N
142: iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/gtk_popup_disabled.png"; // NOI18N
143: iconPaths[TabControlButton.STATE_ROLLOVER] = iconPaths[TabControlButton.STATE_DEFAULT];
144: iconPaths[TabControlButton.STATE_PRESSED] = iconPaths[TabControlButton.STATE_DEFAULT];
145: buttonIconPaths.put(TabControlButton.ID_DROP_DOWN_BUTTON,
146: iconPaths);
147:
148: //maximize/restore button
149: iconPaths = new String[4];
150: iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/gtk_maximize_enabled.png"; // NOI18N
151: iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/gtk_maximize_disabled.png"; // NOI18N
152: iconPaths[TabControlButton.STATE_ROLLOVER] = iconPaths[TabControlButton.STATE_DEFAULT];
153: iconPaths[TabControlButton.STATE_PRESSED] = iconPaths[TabControlButton.STATE_DEFAULT];
154: buttonIconPaths.put(TabControlButton.ID_MAXIMIZE_BUTTON,
155: iconPaths);
156:
157: iconPaths = new String[4];
158: iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/gtk_restore_enabled.png"; // NOI18N
159: iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/gtk_restore_disabled.png"; // NOI18N
160: iconPaths[TabControlButton.STATE_ROLLOVER] = iconPaths[TabControlButton.STATE_DEFAULT];
161: iconPaths[TabControlButton.STATE_PRESSED] = iconPaths[TabControlButton.STATE_DEFAULT];
162: buttonIconPaths.put(TabControlButton.ID_RESTORE_BUTTON,
163: iconPaths);
164: }
165: }
166:
167: public Icon getButtonIcon(int buttonId, int buttonState) {
168: Icon res = null;
169: initIcons();
170: String[] paths = buttonIconPaths.get(buttonId);
171: if (null != paths && buttonState >= 0
172: && buttonState < paths.length) {
173: res = TabControlButtonFactory.getIcon(paths[buttonState]);
174: }
175: return res;
176: }
177:
178: protected Rectangle getControlButtonsRectangle(Container parent) {
179: Component c = getControlButtons();
180: return new Rectangle(parent.getWidth() - c.getWidth() - 4, 4, c
181: .getWidth(), c.getHeight());
182: }
183:
184: public Insets getTabAreaInsets() {
185: Insets retValue = super .getTabAreaInsets();
186: retValue.right += 4;
187: return retValue;
188: }
189: }
|