super();
putValue(Action.SHORT_DESCRIPTION, Resource.getResourceBundle(Locale.getDefault()).getString(BUTTON_NAME_CLOSE));
}
public void actionPerformed(ActionEvent e) {
JideTabbedPane pane;
Object src = e.getSource();
int index;
boolean closeSelected = false;
if (src instanceof JideTabbedPane) {
pane = (JideTabbedPane) src;
}
else if (src instanceof JideTabbedPane.NoFocusButton && ((JideTabbedPane.NoFocusButton) src).getParent() instanceof JideTabbedPane) {
pane = (JideTabbedPane) ((JideTabbedPane.NoFocusButton) src).getParent();
closeSelected = true;
}
else if (src instanceof JideTabbedPane.NoFocusButton && ((JideTabbedPane.NoFocusButton) src).getParent() instanceof ScrollableTabPanel) {
pane = (JideTabbedPane) SwingUtilities.getAncestorOfClass(JideTabbedPane.class, (JideTabbedPane.NoFocusButton) src);
closeSelected = false;
}
else {
return; // shouldn't happen
}
if (pane.isTabEditing()) {
((BasicJideTabbedPaneUI) pane.getUI()).stopOrCancelEditing();//pane.stopTabEditing();
}
ActionEvent e2 = e;
if (src instanceof JideTabbedPane.NoFocusButton) {
index = ((JideTabbedPane.NoFocusButton) src).getIndex();
Component compSrc = index != -1 ? pane.getComponentAt(index) : pane.getSelectedComponent();
// note - We create a new action because we could be in the middle of a chain and
// if we just use setSource we could cause problems.
// also the AWT documentation pooh-pooh this. (for good reason)
if (compSrc != null)
e2 = new ActionEvent(compSrc, e.getID(), e.getActionCommand(), e.getWhen(), e.getModifiers());
}
else if ("middleMouseButtonClicked".equals(e.getActionCommand())) {
index = e.getID();
Component compSrc = index != -1 ? pane.getComponentAt(index) : pane.getSelectedComponent();
// note - We create a new action because we could be in the middle of a chain and
// if we just use setSource we could cause problems.
// also the AWT documentation pooh-pooh this. (for good reason)
if (compSrc != null)
e2 = new ActionEvent(compSrc, e.getID(), e.getActionCommand(), e.getWhen(), e.getModifiers());
}
if (pane.getCloseAction() != null) {
e2 = new ActionEvent(e2.getSource(), e2.getID(), (String) pane.getCloseAction().getValue(Action.ACTION_COMMAND_KEY), e2.getWhen(), e2.getModifiers());
pane.getCloseAction().actionPerformed(e2);
}
else {
if ("middleMouseButtonClicked".equals(e.getActionCommand())) {
index = e.getID();
if (index >= 0)
pane.removeTabAt(index);
if (pane.getTabCount() == 0) {
pane.updateUI();
}
pane.doLayout();
if (pane.getSelectedIndex() >= 0) {
((BasicJideTabbedPaneUI) pane.getUI())._tabScroller.tabPanel.scrollIndexToVisible(pane.getSelectedIndex());
}
}
else if (closeSelected) {
if (pane.getSelectedIndex() >= 0)
pane.removeTabAt(pane.getSelectedIndex());
if (pane.getTabCount() == 0) {
pane.updateUI();
}
pane.doLayout();
if (pane.getSelectedIndex() >= 0) {
((BasicJideTabbedPaneUI) pane.getUI())._tabScroller.tabPanel.scrollIndexToVisible(pane.getSelectedIndex());
}
}
else if (src instanceof JideTabbedPane.NoFocusButton) {
int i = ((JideTabbedPane.NoFocusButton) src).getIndex();
if (i != -1) {
int tabIndex = pane.getSelectedIndex();
pane.removeTabAt(i);
if (i < tabIndex) {
pane.setSelectedIndex(tabIndex - 1);
}
if (pane.getTabCount() == 0) {
pane.updateUI();
}
pane.doLayout();
if (pane.getSelectedIndex() >= 0) {
((BasicJideTabbedPaneUI) pane.getUI())._tabScroller.tabPanel.scrollIndexToVisible(pane.getSelectedIndex());
}
}
}
}
}