2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
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]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
28
* Microsystems, Inc. All Rights Reserved.
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.
42
package org.netbeans.modules.welcome.ui;
44
import java.awt.BorderLayout;
45
import java.awt.CardLayout;
46
import java.awt.Cursor;
47
import java.awt.Graphics;
48
import java.awt.GridBagConstraints;
49
import java.awt.GridBagLayout;
50
import java.awt.GridLayout;
51
import java.awt.Insets;
52
import java.awt.event.ActionEvent;
53
import java.awt.event.ActionListener;
54
import java.awt.event.MouseEvent;
55
import javax.swing.JComponent;
56
import javax.swing.JPanel;
57
import org.netbeans.modules.welcome.content.Constants;
58
import java.awt.Image;
59
import java.awt.event.MouseListener;
60
import javax.swing.BorderFactory;
61
import javax.swing.JLabel;
62
import javax.swing.JScrollPane;
63
import org.netbeans.modules.welcome.WelcomeOptions;
64
import org.netbeans.modules.welcome.content.Utils;
65
import org.openide.util.Utilities;
71
class Tabs extends JPanel implements Constants {
73
private JScrollPane leftComp;
74
private JScrollPane rightComp;
75
private JComponent leftTab;
76
private JComponent rightTab;
77
private JPanel tabContent;
79
private Image imgStripWest;
80
private Image imgStripCenter;
81
private Image imgStripEast;
83
public Tabs( String leftTabTitle, JComponent leftTab,
84
String rightTabTitle, final JComponent rightTab) {
86
super( new BorderLayout() );
89
this.leftTab = leftTab;
90
this.rightTab = rightTab;
92
this.imgStripCenter = Utilities.loadImage( IMAGE_STRIP_BOTTOM_CENTER );
93
this.imgStripWest = Utilities.loadImage( IMAGE_STRIP_BOTTOM_WEST );
94
this.imgStripEast = Utilities.loadImage( IMAGE_STRIP_BOTTOM_EAST );
96
final Tab leftButton = new Tab( leftTabTitle, true );
97
final Tab rightButton = new Tab( rightTabTitle, false );
99
ActionListener al = new ActionListener() {
100
public void actionPerformed(ActionEvent e) {
101
boolean isLeftTabSelected = e.getSource() == leftButton;
102
leftButton.setSelected( isLeftTabSelected );
103
rightButton.setSelected( !isLeftTabSelected );
104
switchTab( isLeftTabSelected );
105
WelcomeOptions.getDefault().setLastActiveTab( isLeftTabSelected ? 0 : 1 );
109
leftButton.addActionListener( al );
110
rightButton.addActionListener( al );
112
JPanel buttons = new JPanel( new GridLayout(1,2) );
113
buttons.setOpaque(true);
114
buttons.add( leftButton );
115
buttons.add( rightButton );
116
buttons.setBackground( Utils.getColor(COLOR_TAB_UNSEL_BACKGROUND) );
118
add( buttons, BorderLayout.NORTH );
120
tabContent = new JPanel( new CardLayout() );
121
tabContent.setOpaque( false );
123
add( tabContent, BorderLayout.CENTER );
124
int activeTabIndex = WelcomeOptions.getDefault().getLastActiveTab();
125
boolean selectLeftTab = activeTabIndex <= 0;
126
if( WelcomeOptions.getDefault().isSecondStart() && activeTabIndex < 0 ) {
127
selectLeftTab = false;
128
WelcomeOptions.getDefault().setLastActiveTab( 1 );
130
leftButton.setSelected( selectLeftTab );
131
rightButton.setSelected( !selectLeftTab );
132
switchTab( selectLeftTab );
135
private void switchTab( boolean showLeftTab ) {
136
JScrollPane compToShow = showLeftTab ? leftComp : rightComp;
137
JScrollPane compToHide = showLeftTab ? rightComp : leftComp;
139
if( null == compToShow ) {
140
compToShow = new JScrollPane( showLeftTab ? leftTab : rightTab );
141
compToShow.setOpaque( false );
142
compToShow.getViewport().setOpaque( false );
143
compToShow.setBorder( BorderFactory.createEmptyBorder() );
146
leftComp = compToShow;
147
tabContent.add( leftComp, "left" ); //NOI18N
149
rightComp = compToShow;
150
tabContent.add( rightComp, "right" ); //NOI18N
154
if( null != compToHide )
155
compToHide.setVisible( false );
157
compToShow.setVisible( true );
164
private static class Tab extends JPanel {
165
private boolean isLeftTab;
166
private Image imgUnselBottom;
167
private Image imgSelLeft;
168
private Image imgSelUpperLeft;
169
private Image imgSelLowerLeft;
170
private Image imgSelRight;
171
private Image imgSelUpperRight;
172
private Image imgSelLowerRight;
173
private boolean isSelected = false;
174
private ActionListener actionListener;
178
public Tab( String title, boolean isLeftTab ) {
179
super( new GridBagLayout() );
180
this.isLeftTab = isLeftTab;
181
imgUnselBottom = Utilities.loadImage( IMAGE_TAB_UNSEL );
183
imgSelLeft = Utilities.loadImage( IMAGE_TAB_SEL_RIGHT );
184
imgSelUpperLeft = Utilities.loadImage( IMAGE_TAB_SEL_UPPER_RIGHT );
185
imgSelLowerLeft = Utilities.loadImage( IMAGE_TAB_SEL_LOWER_RIGHT );
187
imgSelRight = Utilities.loadImage( IMAGE_TAB_SEL_LEFT );
188
imgSelUpperRight = Utilities.loadImage( IMAGE_TAB_SEL_UPPER_LEFT );
189
imgSelLowerRight = Utilities.loadImage( IMAGE_TAB_SEL_LOWER_LEFT );
191
lbl = new JLabel(title);
192
lbl.setOpaque( false );
193
add( lbl, new GridBagConstraints(0,0,1,1,1.0,1.0,
194
GridBagConstraints.CENTER,GridBagConstraints.BOTH,new Insets(5,5,4,0),0,0) );
195
lbl.setFont( TAB_FONT );
196
lbl.setForeground( Utils.getColor( isSelected
197
? COLOR_TAB_SEL_FOREGROUND
198
: COLOR_TAB_UNSEL_FOREGROUND ) );
199
lbl.setHorizontalAlignment( JLabel.CENTER );
201
addMouseListener( new MouseListener() {
202
public void mouseClicked(MouseEvent e) {
203
setSelected( !isSelected );
204
if( null != actionListener ) {
205
actionListener.actionPerformed( new ActionEvent( Tab.this, 0, "clicked") );
209
public void mousePressed(MouseEvent e) {
212
public void mouseReleased(MouseEvent e) {
215
public void mouseEntered(MouseEvent e) {
217
setCursor( Cursor.getPredefinedCursor( Cursor.HAND_CURSOR ) );
218
lbl.setForeground( Utils.getColor( MOUSE_OVER_TAB_COLOR ) );
220
setCursor( Cursor.getDefaultCursor() );
221
// lbl.setForeground( Utils.getColor( COLOR_TAB_UNSEL_FOREGROUND ) );
225
public void mouseExited(MouseEvent e) {
226
setCursor( Cursor.getDefaultCursor() );
227
lbl.setForeground( Utils.getColor( isSelected
228
? COLOR_TAB_SEL_FOREGROUND
229
: COLOR_TAB_UNSEL_FOREGROUND ) );
234
public void addActionListener( ActionListener l ) {
235
assert null == actionListener;
236
this.actionListener = l;
239
public void setSelected( boolean sel ) {
240
this.isSelected = sel;
241
lbl.setForeground( Utils.getColor( isSelected
242
? COLOR_TAB_SEL_FOREGROUND
243
: COLOR_TAB_UNSEL_FOREGROUND ) );
248
protected void paintComponent(Graphics g) {
249
super.paintComponent(g);
250
g.setColor( Utils.getColor( isSelected ? COLOR_TAB_SEL_BACKGROUND : COLOR_TAB_UNSEL_BACKGROUND ) );
251
int width = getWidth();
252
int height = getHeight();
254
g.fillRect( 0, 0, width, height );
259
g.setColor( Utils.getColor( COLOR_TAB_UNSEL_BACKGROUND ) );
260
g.fillRect( width-imgSelUpperLeft.getWidth(null), 0, width, height );
262
g.setColor( Utils.getColor( COLOR_TAB_SEL_BACKGROUND ) );
263
int rightImageWidth = imgSelLeft.getWidth(null);
264
g.drawImage(imgSelUpperLeft, width-imgSelUpperLeft.getWidth(null), 0, null);
265
for( int i=0; i<(height-imgSelUpperLeft.getHeight(null)/*-imgSelLowerLeft.getHeight(null)*/); i++ ) {
266
g.drawImage( imgSelLeft, width-rightImageWidth-1, imgSelUpperLeft.getHeight(null)+i, null);
268
g.fillRect(width-imgSelUpperLeft.getWidth(null), imgSelUpperLeft.getHeight(null), imgSelUpperLeft.getWidth(null)-rightImageWidth, height-imgSelUpperLeft.getHeight(null));
269
// g.drawImage(imgSelLowerLeft, width-imgSelLowerLeft.getWidth(null)-1, height-imgSelLowerLeft.getHeight(null), null);
273
g.setColor( Utils.getColor( COLOR_TAB_UNSEL_BACKGROUND ) );
274
g.fillRect( 0, 0, imgSelUpperRight.getWidth(null), height );
276
g.setColor( Utils.getColor( COLOR_TAB_SEL_BACKGROUND ) );
277
g.drawImage(imgSelUpperRight, 0, 0, null);
278
for( int i=0; i<(height-imgSelUpperRight.getHeight(null)/*-imgSelLowerRight.getHeight(null)*/); i++ ) {
279
g.drawImage( imgSelRight, 1, imgSelUpperRight.getHeight(null)+i, null);
281
g.fillRect(imgSelRight.getWidth(null), imgSelUpperRight.getHeight(null),
282
imgSelUpperRight.getWidth(null)-imgSelRight.getWidth(null), height-imgSelUpperRight.getHeight(null));
283
// g.drawImage(imgSelLowerRight, 0, height-imgSelLowerRight.getHeight(null), null);
284
// g.fillRect(imgSelLowerRight.getWidth(null), height-imgSelLowerRight.getHeight(null),
285
// imgSelUpperRight.getWidth(null)-imgSelLowerRight.getWidth(null), imgSelLowerRight.getHeight(null));
288
int imgWidth = imgUnselBottom.getWidth(null);
289
int imgHeight = imgUnselBottom.getHeight(null);
290
for( int i=0; i<width/imgWidth+1; i++ ) {
291
g.drawImage( imgUnselBottom, i*imgWidth, height-imgHeight, null );
297
protected void paintBorder(Graphics g) {