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
The newest version!
/**
* Copyright (C) 2008-2013 LimeTri. All rights reserved.
*
* AgroSense is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* There are special exceptions to the terms and conditions of the GPLv3 as it is applied to
* this software, see the FLOSS License Exception
* .
*
* AgroSense is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AgroSense. If not, see .
*/
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