115 lines
3.5 KiB
Java
115 lines
3.5 KiB
Java
package burp.ui;
|
|
|
|
import javax.swing.*;
|
|
import javax.swing.plaf.metal.MetalIconFactory;
|
|
import java.awt.*;
|
|
import java.awt.event.MouseEvent;
|
|
import java.awt.event.MouseListener;
|
|
|
|
/**
|
|
* @author 6dc
|
|
*
|
|
* A class which creates a JTabbedPane and auto sets a close button when you add a tab
|
|
*/
|
|
|
|
public class JTabbedPaneCloseButton extends JTabbedPane {
|
|
|
|
public JTabbedPaneCloseButton() {
|
|
super();
|
|
}
|
|
|
|
/** Override Addtab in order to add the close Button everytime */
|
|
@Override
|
|
public void addTab(String title, Icon icon, Component component, String tip) {
|
|
super.addTab(title, icon, component, tip);
|
|
int count = this.getTabCount() - 1;
|
|
setTabComponentAt(count, new CloseButtonTab(component, title, icon));
|
|
}
|
|
|
|
@Override
|
|
public void addTab(String title, Icon icon, Component component) {
|
|
addTab(title, icon, component, null);
|
|
}
|
|
|
|
@Override
|
|
public void addTab(String title, Component component) {
|
|
addTab(title, null, component);
|
|
}
|
|
|
|
|
|
public void addTab(String title,Component component,Boolean closewith){
|
|
if (closewith){
|
|
addTab(title,component);
|
|
}else{
|
|
super.addTab(title,null,component,null);
|
|
}
|
|
}
|
|
|
|
/** addTabNoExit */
|
|
public void addTabNoExit(String title, Icon icon, Component component, String tip) {
|
|
super.addTab(title, icon, component, tip);
|
|
}
|
|
|
|
public void addTabNoExit(String title, Icon icon, Component component) {
|
|
addTabNoExit(title, icon, component, null);
|
|
}
|
|
|
|
public void addTabNoExit(String title, Component component) {
|
|
addTabNoExit(title, null, component);
|
|
}
|
|
|
|
/** Button */
|
|
public class CloseButtonTab extends JPanel {
|
|
|
|
public CloseButtonTab(final Component tab, String title, Icon icon) {
|
|
setOpaque(false);
|
|
FlowLayout flowLayout = new FlowLayout(FlowLayout.CENTER, 3, 3);
|
|
setLayout(flowLayout);
|
|
JLabel jLabel = new JLabel(title);
|
|
jLabel.setIcon(icon);
|
|
add(jLabel);
|
|
JButton button = new JButton(MetalIconFactory.getInternalFrameCloseIcon(2));
|
|
button.setMargin(new Insets(0, 0, 0, 0));
|
|
button.addMouseListener(new CloseListener(tab));
|
|
add(button);
|
|
}
|
|
}
|
|
/** ClickListener */
|
|
public class CloseListener implements MouseListener
|
|
{
|
|
private final Component tab;
|
|
|
|
public CloseListener(Component tab){
|
|
this.tab=tab;
|
|
}
|
|
|
|
@Override
|
|
public void mouseClicked(MouseEvent e) {
|
|
if(e.getSource() instanceof JButton){
|
|
JButton clickedButton = (JButton) e.getSource();
|
|
JTabbedPane tabbedPane = (JTabbedPane) clickedButton.getParent().getParent().getParent();
|
|
tabbedPane.remove(tab);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void mousePressed(MouseEvent e) {}
|
|
|
|
@Override
|
|
public void mouseReleased(MouseEvent e) {}
|
|
|
|
@Override
|
|
public void mouseEntered(MouseEvent e) {
|
|
if(e.getSource() instanceof JButton){
|
|
JButton clickedButton = (JButton) e.getSource();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void mouseExited(MouseEvent e) {
|
|
if(e.getSource() instanceof JButton){
|
|
JButton clickedButton = (JButton) e.getSource();
|
|
}
|
|
}
|
|
}
|
|
} |