org.netbeans.modules.welcome.ui.TabbedPane Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of welcome Show documentation
Show all versions of welcome Show documentation
AgroSense welcome - welcome screen AgroSense
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
*
* Oracle and Java are registered trademarks of Oracle and/or its affiliates.
* Other names may be trademarks of their respective owners.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common
* Development and Distribution License("CDDL") (collectively, the
* "License"). You may not use this file except in compliance with the
* License. You can obtain a copy of the License at
* http://www.netbeans.org/cddl-gplv2.html
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
* specific language governing permissions and limitations under the
* License. When distributing the software, include this License Header
* Notice in each file and include the License file at
* nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the
* License Header, with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*
* Contributor(s):
*
* The Original Software is NetBeans. The Initial Developer of the Original
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
* Microsystems, Inc. All Rights Reserved.
*
* If you wish your version of this file to be governed by only the CDDL
* or only the GPL Version 2, indicate your decision by adding
* "[Contributor] elects to include this software in this distribution
* under the [CDDL or GPL Version 2] license." If you do not indicate a
* single choice of license, a recipient has the option to distribute
* your version of this file under either the CDDL, the GPL Version 2 or
* to extend the choice of license to its licensees as provided above.
* However, if you add GPL Version 2 code and therefore, elected the GPL
* Version 2 license, then the option applies only if the new code is
* made subject to such option by the copyright holder.
*
* Portions Copyrighted 2012 AgroSense
*/
package org.netbeans.modules.welcome.ui;
import java.awt.*;
import java.awt.event.*;
import java.util.Arrays;
import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.Border;
import org.netbeans.modules.welcome.WelcomeOptions;
import org.netbeans.modules.welcome.content.Constants;
import org.openide.util.ImageUtilities;
/**
*
* @author S. Aubrecht
*/
class TabbedPane extends JPanel implements Constants {
private final JComponent[] tabs;
private final TabButton[] buttons;
private final JComponent tabHeader;
private final JPanel tabContent;
private boolean[] tabAdded;
private int selTabIndex = -1;
public TabbedPane( JComponent ... tabs ) {
super( new BorderLayout() );
setOpaque(false);
this.tabs = tabs;
tabAdded = new boolean[tabs.length];
Arrays.fill(tabAdded, false);
// vlv: print
for( JComponent c : tabs ) {
c.putClientProperty("print.printable", Boolean.TRUE); // NOI18N
c.putClientProperty("print.name", c.getName()); // NOI18N
}
ActionListener al = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
TabButton btn = (TabButton) e.getSource();
switchTab( btn.getTabIndex() );
WelcomeOptions.getDefault().setLastActiveTab( btn.getTabIndex() );
}
};
buttons = new TabButton[tabs.length];
for( int i=0; i= 0 ) {
buttons[selTabIndex].setSelected(false);
}
JComponent compToShow = tabs[tabIndex];
JComponent compToHide = selTabIndex >= 0 ? tabs[selTabIndex] : null;
selTabIndex = tabIndex;
buttons[selTabIndex].setSelected(true);
if( null != compToHide )
compToHide.setVisible( false );
compToShow.setVisible( true );
compToShow.requestFocusInWindow();
}
@Override
public Dimension getPreferredSize() {
Dimension d = super.getPreferredSize();
if( null != getParent() && null != getParent().getParent() ) {
Component scroll = getParent().getParent();
if( scroll.getWidth() > 0 ) {
if( d.width > scroll.getWidth() ) {
d.width = Math.max(scroll.getWidth(), START_PAGE_MIN_WIDTH+(int)(((FONT_SIZE-11)/11.0)*START_PAGE_MIN_WIDTH));
} else if( d.width < scroll.getWidth() ) {
d.width = scroll.getWidth();
}
}
}
d.width = Math.min( d.width, 1000 );
return d;
}
private static class TabButton extends JLabel {
private boolean isSelected = false;
private ActionListener actionListener;
private final int tabIndex;
public TabButton( String title, int tabIndex ) {
super( title );
this.tabIndex = tabIndex;
setOpaque( false );
setFont( TAB_FONT );
setForeground( isSelected
? COLOR_TAB_SEL_FOREGROUND
: COLOR_TAB_UNSEL_FOREGROUND );
setHorizontalAlignment( JLabel.CENTER );
setFocusable(true);
addKeyListener( new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if( e.getKeyCode() == KeyEvent.VK_SPACE || e.getKeyCode() == KeyEvent.VK_ENTER ) {
if( null != actionListener ) {
actionListener.actionPerformed( new ActionEvent( TabButton.this, 0, "clicked") );
}
}
}
});
addMouseListener( new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if( null != actionListener ) {
actionListener.actionPerformed( new ActionEvent( TabButton.this, 0, "clicked") );
}
}
@Override
public void mouseEntered(MouseEvent e) {
if( !isSelected ) {
setCursor( Cursor.getPredefinedCursor( Cursor.HAND_CURSOR ) );
setForeground(MOUSE_OVER_TAB_COLOR);
} else {
setCursor( Cursor.getDefaultCursor() );
}
}
@Override
public void mouseExited(MouseEvent e) {
setCursor( Cursor.getDefaultCursor() );
setForeground(isSelected
? COLOR_TAB_SEL_FOREGROUND
: COLOR_TAB_UNSEL_FOREGROUND);
}
});
addFocusListener( new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
setForeground(MOUSE_OVER_LINK_COLOR);
}
@Override
public void focusLost(FocusEvent e) {
setForeground(isSelected
? COLOR_TAB_SEL_FOREGROUND
: COLOR_TAB_UNSEL_FOREGROUND);
}
});
}
public void addActionListener( ActionListener l ) {
assert null == actionListener;
this.actionListener = l;
}
public void setSelected( boolean sel ) {
this.isSelected = sel;
setForeground(isFocusOwner()
? MOUSE_OVER_LINK_COLOR
: isSelected
? COLOR_TAB_SEL_FOREGROUND
: COLOR_TAB_UNSEL_FOREGROUND );
setFocusable(!sel);
if( null != getParent() )
getParent().repaint();
}
public int getTabIndex() {
return tabIndex;
}
}
private static final Color COLOR_UNSEL = new Color(173,175,176);
private static final Color COLOR_SEL = new Color(255,255,255);
private static final Insets insets = new Insets(23, 19, 6, 10);
private class TabHeader extends JPanel {
// ABBBBBBBBBBBBBBBCBBBBBBBBBBBBBBBBD
// 5666666666666666788888888888888889
// 4 5 6
// 4 5 6
// 4 5 6
// 4 5 6
// 0111111111111111211111111111111113
private final Image[] sel;
private final Image[] unsel;
private final TabButton[] buttons;
private final Image imgSelTopLeft1 = ImageUtilities.loadImage("org/netbeans/modules/welcome/tab_sel_topleft1.png"); //NOI18N
private final Image imgSelTopLeft2 = ImageUtilities.loadImage("org/netbeans/modules/welcome/tab_sel_topleft2.png"); //NOI18N
private final Image imgSelTop = ImageUtilities.loadImage("org/netbeans/modules/welcome/tab_sel_top.png"); //NOI18N
private final Image imgSelLeft1 = ImageUtilities.loadImage("org/netbeans/modules/welcome/tab_sel_left1.png"); //NOI18N
private final Image imgSelLeft2 = ImageUtilities.loadImage("org/netbeans/modules/welcome/tab_sel_left2.png"); //NOI18N
private final Image imgSelTopRight1 = ImageUtilities.loadImage("org/netbeans/modules/welcome/tab_sel_topright1.png"); //NOI18N
private final Image imgSelTopRight2 = ImageUtilities.loadImage("org/netbeans/modules/welcome/tab_sel_topright2.png"); //NOI18N
private final Image imgSelRight1 = ImageUtilities.loadImage("org/netbeans/modules/welcome/tab_sel_right1.png"); //NOI18N
private final Image imgSelRight2 = ImageUtilities.loadImage("org/netbeans/modules/welcome/tab_sel_right2.png"); //NOI18N
private final Image imgUnselTopLeft1 = ImageUtilities.loadImage("org/netbeans/modules/welcome/tab_unsel_topleft1.png"); //NOI18N
private final Image imgUnselLeft1 = ImageUtilities.loadImage("org/netbeans/modules/welcome/tab_unsel_left1.png"); //NOI18N
private final Image imgUnselLeftTop1 = ImageUtilities.loadImage("org/netbeans/modules/welcome/tab_unsel_lefttop1.png"); //NOI18N
private final Image imgUnselBottomLeft1 = ImageUtilities.loadImage("org/netbeans/modules/welcome/tab_unsel_bottomleft1.png"); //NOI18N
private final Image imgUnselTopRight1 = ImageUtilities.loadImage("org/netbeans/modules/welcome/tab_unsel_topright1.png"); //NOI18N
private final Image imgUnselRight1 = ImageUtilities.loadImage("org/netbeans/modules/welcome/tab_unsel_right1.png"); //NOI18N
private final Image imgUnselRightTop1 = ImageUtilities.loadImage("org/netbeans/modules/welcome/tab_unsel_righttop1.png"); //NOI18N
private final Image imgUnselBottomRight1 = ImageUtilities.loadImage("org/netbeans/modules/welcome/tab_unsel_bottomright1.png"); //NOI18N
private final Image imgUnselTopLeft2 = ImageUtilities.loadImage("org/netbeans/modules/welcome/tab_unsel_topleft2.png"); //NOI18N
private final Image imgUnselLeft2 = ImageUtilities.loadImage("org/netbeans/modules/welcome/tab_unsel_left2.png"); //NOI18N
private final Image imgUnselBottomLeft2 = ImageUtilities.loadImage("org/netbeans/modules/welcome/tab_unsel_bottomleft2.png"); //NOI18N
private final Image imgUnselTopRight2 = ImageUtilities.loadImage("org/netbeans/modules/welcome/tab_unsel_topright2.png"); //NOI18N
private final Image imgUnselRight2 = ImageUtilities.loadImage("org/netbeans/modules/welcome/tab_unsel_right2.png"); //NOI18N
private final Image imgUnselBottomRight2 = ImageUtilities.loadImage("org/netbeans/modules/welcome/tab_unsel_bottomright2.png"); //NOI18N
private final Image imgUnselTopRight3 = ImageUtilities.loadImage("org/netbeans/modules/welcome/tab_unsel_topright3.png"); //NOI18N
private final Image imgUnselRight3 = ImageUtilities.loadImage("org/netbeans/modules/welcome/tab_unsel_right3.png"); //NOI18N
private final Image imgUnselBottomRight3 = ImageUtilities.loadImage("org/netbeans/modules/welcome/tab_unsel_bottomright3.png"); //NOI18N
private final Image imgUnselTop = ImageUtilities.loadImage("org/netbeans/modules/welcome/tab_unsel_top.png"); //NOI18N
private final Image imgUnselBottom = ImageUtilities.loadImage("org/netbeans/modules/welcome/tab_unsel_bottom.png"); //NOI18N
private final Image imgUnselFiller = ImageUtilities.loadImage("org/netbeans/modules/welcome/tab_unsel_filler.png"); //NOI18N
public TabHeader( TabButton ... buttons ) {
super( new GridLayout(1,0) );
setOpaque(false);
this.buttons = buttons;
Border b = BorderFactory.createEmptyBorder( 12, 19, 2, 24 );
for( TabButton btn : buttons ) {
btn.setBorder(b);
add( btn );
}
sel = new Image[13];
unsel = new Image[13];
for( int i=0; i