package com.vci.client.ui.swing.components;
|
|
import java.awt.BorderLayout;
|
import java.awt.Component;
|
import java.awt.Graphics;
|
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionListener;
|
|
import com.vci.client.ui.swing.VCISwingUtil;
|
|
|
public class TabTitleComponent extends VCIJPanel {
|
/**
|
*
|
*/
|
private static final long serialVersionUID = 4109281420551018722L;
|
private VCIJLabel lbl = new VCIJLabel();
|
private VCIJButton btnClose = VCISwingUtil.createVCIJButton("close", "", "关闭", "");
|
private JClosableTabbedPane tab = null;
|
private Component tabComponent = null;
|
public TabTitleComponent(JClosableTabbedPane tab, Component tabComponent){
|
this.tab = tab;
|
this.tabComponent = tabComponent;
|
setLayout(new BorderLayout(5, 0));
|
add(lbl, BorderLayout.CENTER);
|
this.setOpaque(false);
|
lbl.setOpaque(false);
|
setButtonProperty(btnClose);
|
btnClose.setIcon(new CloseTabIcon(null));
|
add(btnClose, BorderLayout.EAST);
|
btnClose.addActionListener(new ActionListener() {
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
closeTab();
|
}
|
});
|
}
|
|
private void closeTab(){
|
int index = this.tab.indexOfTabComponent(this);
|
if(index < 0) return;
|
this.tab.removeTabAt(index);
|
}
|
|
public void setTitle(String title){
|
lbl.setText(title);
|
}
|
|
@Override
|
public void paint(Graphics g) {
|
super.paint(g);
|
setButtonProperty(btnClose);
|
}
|
|
private void setButtonProperty(VCIJButton btn){
|
btn.setOpaque(false);
|
btn.setFocusable(false);
|
btn.setBorderPainted(false);
|
btn.setBorder(null);
|
}
|
|
public JClosableTabbedPane getTab() {
|
return tab;
|
}
|
|
public void setTab(JClosableTabbedPane tab) {
|
this.tab = tab;
|
}
|
|
public Component getTabComponent() {
|
return tabComponent;
|
}
|
|
public void setTabComponent(Component tabComponent) {
|
this.tabComponent = tabComponent;
|
}
|
}
|