?? basetabbedpanel.java
字號(hào):
/*
$Author:丂$
$Date: $
$Revision: $
$NoKeywords: $
*/
package jp.co.ntl.awt;
import java.awt.*;
import java.util.Vector;
import java.awt.event.*;
import java.beans.*;
import java.io.*;
public class BaseTabbedPanel extends Panel {
/**
*
*/
private static final long serialVersionUID = 1L;
public static final int TOP = 0;
public static final int BOTTOM = 1;
public static final int ROUNDED = 0;
public static final int SQUARE = 1;
/** 昞帵偝傟偰偄傞僞僽偺斣崋 */
protected int curIndex = -1;
private VetoableChangeSupport vetos = new VetoableChangeSupport(this);
private PropertyChangeSupport changes = new PropertyChangeSupport(this);
/** 嵞昤夋梷惂僼儔僌 */
transient protected boolean suppressRepaints = false;
protected Vector vPolys;
protected int firstVisibleTab = 0;
protected ArrowButton arbLeft;
protected ArrowButton arbRight;
protected Polygon nullPoly;
protected Vector vLabels;
protected Color borderDarkerColor = null;
protected Color borderLightColor = null;
protected Color borderDarkColor = null;
protected Color disabledTextColor = null;
protected Color cachedForeground = null;
protected Color cachedBackground = null;
protected static int TF_LEFT = 9;
protected static int TF_RIGHT = -9;
protected static int TF_TOP = 30;
protected static int TF_BOTTOM = -9;
protected static int TF_BTN_HEIGHT = 20;
/*
private Vector vEnabled;
private Font fReg;
private Font fSel;
private Component userPanel = null;
//** 僞僽偺埵抲 /
private int iTabsPosition = TOP;
//** 僞僽偺僗僞僀儖 /
private int iTabsStyle = ROUNDED;
private int lastWidth = -1;
private Insets btpInsets;
private MyMouseAdapter mouseAdapter = null;
private MyActionAdapter actionAdapter = null;
*/
protected Vector vEnabled;
protected Font fReg;
protected Font fSel;
protected Component userPanel = null;
//** 僞僽偺埵抲 /
protected int iTabsPosition = TOP;
//** 僞僽偺僗僞僀儖 /
protected int iTabsStyle = ROUNDED;
protected int lastWidth = -1;
protected Insets btpInsets;
protected MyMouseAdapter mouseAdapter = null;
protected MyActionAdapter actionAdapter = null;
Image imageBuffer = null;
Graphics graphicsImage;
public BaseTabbedPanel() {
this(TOP, ROUNDED);
}
public BaseTabbedPanel(boolean bTabsOnTop) {
this(bTabsOnTop ? TOP : BOTTOM, bTabsOnTop ? ROUNDED : SQUARE);
}
public BaseTabbedPanel(int tabsPostion, int tabsStyle) {
vLabels = new Vector();
vEnabled = new Vector();
vPolys = new Vector();
btpInsets = new Insets(0,0,0,0);
setTabsInfo(tabsPostion, tabsStyle);
fReg = new Font("SansSerif", Font.PLAIN, 12);
fSel = new Font("SansSerif", Font.BOLD, 12);
super.setLayout(null);
// prepare left/right arrows
arbLeft = new ArrowButton(ArrowButton.LEFT);
arbRight = new ArrowButton(ArrowButton.RIGHT);
super.add(arbLeft, -1);
super.add(arbRight, -1);
nullPoly = new Polygon();
nullPoly.addPoint(0, 0);
nullPoly.addPoint(1, 1);
nullPoly.addPoint(0, 0);
//Initilize the cached colors.
cachedForeground = getForeground();
cachedBackground = getBackground();
}
/**
* 僞僽偺埵抲傪愝掕偡傞
* @param tabsPosition 僞僽偺埵抲
*/
public void setTabsPosition(int tabsPosition) throws PropertyVetoException {
if (iTabsPosition != tabsPosition) {
Integer oldValue = new Integer(iTabsPosition);
Integer newValue = new Integer(tabsPosition);
vetos.fireVetoableChange("TabsPosition", oldValue, newValue);
setTabsInfo(tabsPosition, iTabsStyle);
changes.firePropertyChange("TabsPosition", oldValue, newValue);
}
}
/**
* 僞僽偺埵抲傪庢摼偡傞
*/
public int getTabsPosition() {
return iTabsPosition;
}
/**
* 僞僽偺僗僞僀儖傪愝掕偡傞
* @param tabsStyle 僞僽偺僗僞僀儖
*/
public void setTabsStyle(int tabsStyle) throws PropertyVetoException {
if (iTabsStyle != tabsStyle) {
Integer oldValue = new Integer(iTabsStyle);
Integer newValue = new Integer(tabsStyle);
vetos.fireVetoableChange("TabsStyle", oldValue, newValue);
setTabsInfo(iTabsPosition, tabsStyle);
changes.firePropertyChange("TabsStyle", oldValue, newValue);
}
}
/**
* 僞僽偺僗僞僀儖傪庢摼偡傞丅
*/
public int getTabsStyle() {
return iTabsStyle;
}
/**
* 僞僽偺昞帵埵抲偲僗僞僀儖傪愝掕偡傞丅
* @param tabsPosition 僞僽偺埵抲
* @param tabsStyle 僞僽偺僗僞僀儖
*/
public void setTabsInfo(int tabsPosition, int tabsStyle) {
iTabsPosition = tabsPosition;
if (iTabsPosition == TOP) {
iTabsStyle = ROUNDED;
} else {
iTabsStyle = tabsStyle;
}
if (iTabsStyle == ROUNDED) {
TF_BTN_HEIGHT = 20;
} else {
TF_BTN_HEIGHT = 17;
}
triggerRepaint();
}
/**
* @param b 嵞昤夋?zhèn)饤}惂偡傞偐偳偆偐
* @return 捈慜偺嵞昤夋梷惂忬嫷
*/
public boolean setSuppressRepaints(boolean b) {
boolean wasSuppressingRepaints = suppressRepaints;
suppressRepaints = b;
return wasSuppressingRepaints;
}
/**
* suppressRepaints偑false偺偲偒嵞昤夋?zhèn)穫? * @see #setSuppressRepaints
*/
protected void triggerRepaint() {
if (!suppressRepaints) {
repaint();
}
}
/**
* 昞帵偝傟傞僐儞億乕僱儞僩傪愝掕偡傞丅
* @param p 昞帵偝傟傞僐儞億乕僱儞僩
*/
public void setPanel(Component p) throws PropertyVetoException {
Component oldValue = userPanel;
vetos.fireVetoableChange("Panel", oldValue, p);
removeAll();
userPanel = p;
if (userPanel != null) {
super.add(userPanel, -1);
userPanel.requestFocus();
}
changes.firePropertyChange("Panel", oldValue, p);
}
/**
* 僞僽柤偲巊梡壜擻偐偳偆偐傪愝掕偡傞
* @param label 僞僽柤
* @param enables 巊梡壜擻偐偳偆偐
* @param index 僞僽偺埵抲
*/
public synchronized void setTab(String label, boolean enabled, int index) throws PropertyVetoException {
boolean wasSuppressingRepaints = setSuppressRepaints(true);
try {
setLabel(label, index);
setEnabled(enabled, index);
} finally {
setSuppressRepaints(wasSuppressingRepaints);
}
triggerRepaint();
}
/**
* 僞僽柤傪愝掕偡傞
* @param label 僞僽柤傪愝掕偡傞
*/
public synchronized void setLabel(String label, int index) throws PropertyVetoException {
if ((index < 0) || (index >= vLabels.size())) {
return;
}
try {
String oldValue = (String) vLabels.elementAt(index);
vetos.fireVetoableChange("Label", oldValue, label);
vLabels.setElementAt(label, index);
triggerRepaint();
changes.firePropertyChange("Label", oldValue, label);
} catch (ArrayIndexOutOfBoundsException e) {
}
}
/**
* 僞僽柤傪庢摼偡傞丅
* @param index 僞僽偺埵抲
*/
public synchronized String getLabel(int index) {
if ((index < 0) || (index >= vLabels.size())) {
return "";
}
try {
return (String)vLabels.elementAt(index);
} catch (ArrayIndexOutOfBoundsException e) {
}
return "";
}
/**
* @param enabled 巊梡壜擻偐偳偆偐
* @param index 僞僽偺斣崋
*/
public synchronized void setEnabled(boolean enabled, int index) throws PropertyVetoException {
if ((index < 0) || (index >= vLabels.size())) {
return;
}
if (index == curIndex && !enabled) {
return;
}
try {
Boolean oldValue = (Boolean) vEnabled.elementAt(index);
Boolean newValue = new Boolean(enabled);
vetos.fireVetoableChange("Enabled", oldValue, newValue);
vEnabled.setElementAt(newValue, index);
triggerRepaint();
changes.firePropertyChange("Enabled", oldValue, newValue);
} catch (ArrayIndexOutOfBoundsException e) {
}
}
/**
* @param index 僞僽偺斣崋
*/
public boolean isEnabled(int index) {
if ((index < 0) || (index >= vLabels.size())) {
return false;
}
try {
Boolean bool = (Boolean) vEnabled.elementAt(index);
if (bool.booleanValue()) {
return true;
}
} catch (ArrayIndexOutOfBoundsException e) {
}
return false;
}
/**
* 昞帵偝傟傞僞僽偺愝掕丅巜掕偝傟偨僞僽偑巊梡晄壜偺応崌偼柍帇偡傞丅
* @param index 僞僽偺斣崋
*/
public void setCurrentTab(int index) throws PropertyVetoException {
if ((index < 0) || (index >= vLabels.size()) || index == curIndex) {
return;
}
if ( isEnabled(index) ) {
boolean wasSuppressingRepaints = setSuppressRepaints(true);
try {
Integer oldValue = new Integer(curIndex);
Integer newValue = new Integer(index);
vetos.fireVetoableChange("CurrentTab", oldValue, newValue);
curIndex = index;
invalidate();
validate();
changes.firePropertyChange("CurrentTab", oldValue, newValue);
} finally {
setSuppressRepaints(wasSuppressingRepaints);
}
triggerRepaint();
}
}
/**
* 尰嵼昞帵偝傟偰偄傞僞僽偺斣崋傪庢摼偡傞
*/
public int getCurrentTab() {
return curIndex;
}
/*
public void enableTab(boolean enabled, int index) {
try {
setEnabled(enabled, index);
} catch (PropertyVetoException e) {
}
}
*/
/*
public boolean tabIsEnabled(int index) {
return(isEnabled(index));
}
*/
/**
* 僐儞億乕僱儞僩偑婛偵嵹偭偰偄傞偐偳偆偐傪挷傋丄
* 嵹偭偰偄傞偲偒偼偦偺傑傑昞帵偟丄
* 嵹偭偰偄側(cè)偄偲偒偼捛壛偟偰偐傜昞帵偡傞丅
*/
public void showPanel(Component p) {
if (userPanel != null) {
userPanel.setVisible(false);
}
userPanel = p;
if (userPanel != null) {
Component[] comps = getComponents();
int l = comps.length;
int x;
for (x = 0; x < l; x++) {
if (comps[x] == userPanel) {
break;
}
}
if (x == l) {
super.add(userPanel, -1);
}
userPanel.setVisible(true);
userPanel.requestFocus();
validate();
triggerRepaint();
}
}
/**
* 嵟屻偵僞僽傪捛壛偡傞
* @param label 僞僽柤
* @param enabled 巊梡壜擻偐偳偆偐
* @return 捛壛偟偨埵抲
*/
public int addTab(String sLabel, boolean bEnabled) {
return addTab(sLabel, bEnabled, -1);
}
/**
* 僞僽傪捛壛偡傞
* @param label 僞僽柤
* @param enabled 巊梡壜擻偐偳偆偐
* @param pos 捛壛偡傞埵抲乮-1偺偲偒偼嵟屻偵捛壛乯
* @return 捛壛偟偨埵抲
*/
public int addTab(String label, boolean enabled, int pos) {
int index;
if (pos == -1) {
vLabels.addElement(label);
vEnabled.addElement(new Boolean(enabled));
index = vLabels.size() - 1;
} else {
vLabels.insertElementAt(label, pos);
vEnabled.insertElementAt(new Boolean(enabled), pos);
index = pos;
}
if (curIndex == -1 && enabled) {
try {
setCurrentTab(index);
} catch (PropertyVetoException e) {
//Return an error state
index = -1;
}
}
return (index);
}
/*
public void showTab(int index) throws PropertyVetoException {
setCurrentTab(index);
}
*/
/*
public int currentTabIndex() {
return getCurrentTab();
}
*/
/**
* 僞僽傪憓擖偡傞
* @param label 僞僽柤
* @param enabled 巊梡壜擻偐偳偆偐
* @param index 憓擖偡傞埵抲
*/
public synchronized void insertTab(String label, boolean enabled, int index) {
if ((index < 0) || (index >= vLabels.size())) {
return;
}
if (index == curIndex && !enabled) {
return;
}
try {
vLabels.insertElementAt(label, index);
vEnabled.insertElementAt(new Boolean(enabled), index);
triggerRepaint();
} catch (ArrayIndexOutOfBoundsException e) {
}
}
/**
* 僞僽傪嶍彍偡傞丅偨偩偟丄尰嵼昞帵偟偰偄傞僞僽偼嶍彍偟側(cè)偄丅
* @param index 僞僽斣崋
*/
public void removeTab(int index) {
if ((index < 0) || (index >= vEnabled.size()) || index == curIndex) {
return;
}
try {
vLabels.removeElementAt(index);
vEnabled.removeElementAt(index);
triggerRepaint();
} catch (ArrayIndexOutOfBoundsException e) {
}
}
/**
* 偡傋偰偺僞僽傪嶍彍偡傞
*/
public void removeAllTabs() {
vLabels = new Vector();
vEnabled = new Vector();
vPolys = new Vector();
curIndex = -1;
firstVisibleTab = 0;
lastWidth = -1;
removeAll();
triggerRepaint();
}
/**
* userPanel偺埵抲傪愝掕偡傞丅
*/
public void setLayout() {
Rectangle r = getBounds();
int width = r.width - TF_LEFT + TF_RIGHT;
if (width < 0) {
return;
}
int height = r.height - TF_TOP + TF_BOTTOM;
if (height < 0) {
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -