/* (swing1.1.1beta2) */
package jp.gr.java_conf.tame.swing.panel;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.plaf.basic.BasicTabbedPaneUI;
import javax.swing.plaf.metal.MetalTabbedPaneUI;
/**
* @version 1.0 07/09/99
*/
public class SingleRowTabbedPaneUI extends MetalTabbedPaneUI {
protected ActionListener[] buttonListeners;
public void installUI(JComponent c) {
this.tabPane = (JTabbedPane)c;
c.setLayout(createLayoutManager());
installDefaults();
installComponents();
installListeners();
installKeyboardActions();
runCount = 1;
selectedRun = 0;
}
public void uninstallUI(JComponent c) {
uninstallComponents();
super.uninstallUI(c);
}
protected LayoutManager createLayoutManager() {
return new SingleRowTabbedLayout(tabPane);
}
protected void installComponents() {
JButton[] buttons = ((SingleRowTabbedPane)tabPane).getButtons();
for (int i=0;i<buttons.length;i++) {
tabPane.add(buttons[i]);
}
}
protected void uninstallComponents() {
JButton[] buttons = ((SingleRowTabbedPane)tabPane).getButtons();
for (int i=0;i<buttons.length;i++) {
tabPane.remove(buttons[i]);
}
}
protected void installListeners() {
super.installListeners();
SingleRowTabbedPane stabPane = (SingleRowTabbedPane)tabPane;
JButton[] buttons = stabPane.getButtons();
int n = buttons.length;
buttonListeners = new ActionListener[n];
for (int i=0;i<n;i++) {
buttonListeners[i] = null;
String str = buttons[i].getActionCommand();
if (str.equals(SingleRowTabbedPane.ROTATE)) {
buttonListeners[i] = new ShiftTabs() {
protected int getStartIndex() {
int index = sPane.getVisibleStartIndex() + sPane.getVisibleCount();
return (index < sPane.getTabCount())? index: 0;
}
};
}
else if (str.equals(SingleRowTabbedPane.PREVIOUS)) {
buttonListeners[i] = new ShiftTabs() {
protected int getStartIndex() {
return getStartIndex(sPane.getVisibleStartIndex() - 1);
}
};
}
else if (str.equals(SingleRowTabbedPane.NEXT)) {
buttonListeners[i] = new ShiftTabs() {
protected int getStartIndex() {
return sPane.getVisibleStartIndex() + sPane.getVisibleCount();
}
};
}
else if (str.equals(SingleRowTabbedPane.FIRST)) {
buttonListeners[i] = new ShiftTabs();
}
else if (str.equals(SingleRowTabbedPane.LEFT_SHIFT)) {
buttonListeners[i] = new ShiftTabs() {
protected int getStartIndex() {
return sPane.getVisibleStartIndex() - 1;
}
};
}
else if (str.equals(SingleRowTabbedPane.RIGHT_SHIFT)) {
buttonListeners[i] = new ShiftTabs() {
protected int getStartIndex() {
return sPane.getVisibleStartIndex() + 1;
}
};
}
else if (str.equals(SingleRowTabbedPane.LAST)) {
buttonListeners[i] = new ShiftTabs() {
protected int getStartIndex() {
return getStartIndex(sPane.getTabCount() - 1);
}
};
}
buttons[i].addActionListener(buttonListeners[i]);
}
}
protected void uninstallListeners() {
super.uninstallListeners();
JButton[] buttons = ((SingleRowTabbedPane)tabPane).getButtons();
for (int i=0;i<buttons.length;i++) {
buttons[i].removeActionListener(buttonListeners[i]);
}
}
public int tabForCoordinate(JTabbedPane pane, int x, int y) {
int tabCount = tabPane.getTabCount();
SingleRowTabbedPane stabPane = (SingleRowTabbedPane)tabPane;
int visibleCount = stabPane.getVisibleCount();
int visibleStartIndex = stabPane.getVisibleStartIndex();
for (int i=0,index = visibleStartIndex; i < visibleCount; i++,index++) {
if (rects[index].contains(x, y)) {
return index;
}
}
return -1;
}
public void paint(Graphics g, JComponent c) {
int selectedIndex = tabPane.getSelectedIndex();
int tabPlacement = tabPane.getTabPlacement();
int tabCount = tabPane.getTabCount();
ensureCurrentLayout();
SingleRowTabbedPane stabPane = (SingleRowTabbedPane)tabPane;
int visibleCount = stabPane.getVisibleCount();
int visibleStartIndex = stabPane.getVisibleStartIndex();
Rectangle iconRect = new Rectangle(),
textRect = new Rectangle();
Rectangle clipRect = g.getClipBounds();
Insets insets = tabPane.getInsets();
tabRuns[0] = visibleStartIndex;
for (int i=0,index=visibleStartIndex; i<visibleCount; i++,index++) {
if (rects[index].intersects(clipRect)) {
paintTab(g, tabPlacement, rects, index, iconRect, textRect);
}
}
if (stabPane.isVisibleTab(selectedIndex)) {
if (rects[selectedIndex].intersects(clipRect)) {
paintTab(g, tabPlacement, rects, selectedIndex, iconRect, textRect);
}
}
paintContentBorder(g, tabPlacement, selectedIndex);
}
protected void paintContentBorderTopEdge( Graphics g,
int tabPlacement, int selectedIndex, int x, int y, int w, int h ) {
g.setColor(selectHighlight);
if (tabPlacement != TOP || selectedIndex < 0 ||
(rects[selectedIndex].y + rects[selectedIndex].height + 1 < y) ||
!((SingleRowTabbedPane)tabPane).isVisibleTab(selectedIndex) ) {
g.drawLine(x, y, x+w-2, y);
} else {
Rectangle selRect = rects[selectedIndex];
g.drawLine(x, y, selRect.x + 1, y);
if (selRect.x + selRect.width < x + w - 2) {
g.drawLine(selRect.x + selRect.width, y, x+w-2, y);
} else {
g.setColor(shadow);
g.drawLine(x+w-2, y, x+w-2, y);
}
}
}
protected void paintContentBorderBottomEdge(Graphics g,
int tabPlacement, int selectedIndex, int x, int y, int w, int h) {
g.setColor(darkShadow);
if (tabPlacement != BOTTOM || selectedIndex < 0 ||
(rects[selectedIndex].y - 1 > h) ||
!((SingleRowTabbedPane)tabPane).isVisibleTab(selectedIndex) ) {
g.drawLine(x, y+h-1, x+w-1, y+h-1);
} else {
Rectangle selRect = rects[selectedIndex];
g.drawLine(x, y+h-1, selRect.x, y+h-1);
if (selRect.x + selRect.width < x + w - 2) {
g.drawLine(selRect.x + selRect.width, y+h-1, x+w-1, y+h-1);
}
}
}
protected Insets getTabAreaInsets(int tabPlacement) {
SingleRowTabbedPane stabPane = (SingleRowTabbedPane)tabPane;
Dimension d = stabPane.getButtonPreferredSize();
int n = stabPane.getButtonCount();
int buttonPlacement = stabPane.getButtonPlacement();
Insets currentInsets = new Insets(0,0,0,0);
if (tabPlacement == TOP) {
currentInsets.top = tabAreaInsets.top;
currentInsets.bottom = tabAreaInsets.bottom;
} else {
currentInsets.top = tabAreaInsets.bottom;
currentInsets.bottom = tabAreaInsets.top;
}
if (buttonPlacement == RIGHT) {
currentInsets.left = tabAreaInsets.left;
currentInsets.right = tabAreaInsets.right + n * d.width;
} else {
currentInsets.left = tabAreaInsets.left + n * d.width;
currentInsets.right = tabAreaInsets.right;
}
return currentInsets;
}
protected int lastTabInRun(int tabCount, int run) {
SingleRowTabbedPane stabPane = (SingleRowTabbedPane)tabPane;
return stabPane.getVisibleStartIndex() + stabPane.getVisibleCount() -1;
}
protected void ensureCurrentLayout() {
SingleRowTabbedLayout layout = (SingleRowTabbedLayout)tabPane.getLayout();
layout.calculateLayoutInfo();
setButtonsEnabled();
}
protected void setButtonsEnabled() {
SingleRowTabbedPane stabPane = (SingleRowTabbedPane)tabPane;
int visibleCount = stabPane
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
JAVA_swing_example (234个子文件)
table13.gif 9KB
table10.gif 7KB
table11.gif 5KB
table28.gif 5KB
table12.gif 5KB
table8a.gif 5KB
table8b.gif 4KB
tree4.gif 4KB
table9.gif 4KB
menu1.gif 4KB
table31.gif 4KB
tree10.gif 4KB
tree5.gif 4KB
table19.gif 4KB
table24.gif 4KB
tree9.gif 3KB
border1.gif 3KB
tree8.gif 3KB
table26.gif 3KB
table32.gif 3KB
tabbedpane9.gif 3KB
table23.gif 3KB
list1.gif 3KB
border3.gif 3KB
tree6.gif 3KB
table1.gif 3KB
table25.gif 3KB
table16.gif 3KB
combobox1.gif 3KB
table7b.gif 3KB
tabbedpane8.gif 3KB
tabbedpane7.gif 3KB
table29.gif 3KB
table4.gif 3KB
list2.gif 3KB
tree1.gif 2KB
combobox2.gif 2KB
table27.gif 2KB
table14.gif 2KB
table22.gif 2KB
table17.gif 2KB
table15.gif 2KB
table30.gif 2KB
tabbedpane2.gif 2KB
table34.gif 2KB
table7a.gif 2KB
table3.gif 2KB
tree3.gif 2KB
table18.gif 2KB
slider4.gif 2KB
tooltip3.gif 2KB
tree2.gif 2KB
table6.gif 2KB
table2.gif 2KB
table5.gif 2KB
table33.gif 2KB
combobox3.gif 2KB
list3.gif 2KB
combobox4.gif 2KB
tabbedpane4.gif 2KB
tabbedpane6.gif 2KB
tabbedpane5.gif 2KB
tooltip1.gif 2KB
tree7.gif 2KB
border2.gif 2KB
tooltip2.gif 2KB
tabbedpane3.gif 2KB
slider3.gif 2KB
slider1.gif 1KB
slider2.gif 1KB
JTableExamples4.html 4KB
JTableExamples7.html 3KB
JTableExamples2.html 3KB
JTableExamples1.html 3KB
JSliderExamples1.html 2KB
JTabbedPaneExamples2.html 2KB
JTreeExamples2.html 2KB
SwingExamples.html 2KB
BorderExamples1.html 2KB
JTreeExamples3.html 2KB
JTableExamples8.html 2KB
JComboBoxExamples1.html 2KB
JTreeExamples1.html 2KB
JTableExamples9.html 1KB
JTableExamples6.html 1KB
JToolTipExamples1.html 1KB
JTableExamples5.html 1KB
notes.html 1KB
JTableExamples3.html 1KB
JTreeExamples4.html 1KB
JListExamples1.html 1KB
JTabbedPaneExamples3.html 1KB
JTabbedPaneExamples1.html 1KB
JMenuExamples1.html 995B
JComboBoxExamples2.html 833B
JSliderExamples2.html 823B
SingleRowTabbedPaneUI.java 17KB
MetalMThumbSliderUI.java 7KB
MThumbSliderAdditionalUI.java 7KB
MixedExample.java 7KB
共 234 条
- 1
- 2
- 3
资源评论
ycyhjj2865
- 粉丝: 10
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功