use of org.netbeans.swing.tabcontrol.event.TabActionEvent in project netbeans-rcp-lite by outersky.
the class DocumentSwitcherTable method onMouseEvent.
boolean onMouseEvent(MouseEvent e) {
Point p = e.getPoint();
p = SwingUtilities.convertPoint((Component) e.getSource(), p, this);
int selRow = getSelectedRow();
int selCol = getSelectedColumn();
if (selRow < 0 || selCol < 0)
return false;
Item item = (Item) getModel().getValueAt(selRow, selCol);
// #268040 - check whether the item is closable
if (null != item && isClosable(item)) {
Rectangle rect = getCellRect(selRow, selCol, false);
if (rect.contains(p)) {
Dimension size = btnClose.getPreferredSize();
int x = rect.x + rect.width - size.width;
int y = rect.y + (rect.height - size.height) / 2;
Rectangle btnRect = new Rectangle(x, y, size.width, size.height);
boolean inButton = btnRect.contains(p);
boolean mustRepaint = inCloseButtonRect != inButton;
inCloseButtonRect = inButton;
if (inButton) {
if (e.getID() == MouseEvent.MOUSE_PRESSED) {
TabData tab = item.getTabData();
int tabIndex = displayer.getModel().indexOf(tab);
if (tabIndex >= 0) {
TabActionEvent evt = new TabActionEvent(displayer, TabDisplayer.COMMAND_CLOSE, tabIndex);
displayer.postActionEvent(evt);
return true;
}
}
}
if (mustRepaint && lastRow == selRow && lastCol == selCol)
repaint(btnRect);
lastCol = selCol;
lastRow = selRow;
return inButton;
}
} else {
inCloseButtonRect = false;
}
return false;
}
use of org.netbeans.swing.tabcontrol.event.TabActionEvent in project netbeans-rcp-lite by outersky.
the class TabbedContainerUI method shouldPerformAction.
/**
* Allows ActionListeners attached to the container to determine if the
* event should be acted on. Delegates to <code>displayer.postActionEvent()</code>.
* This method will create a TabActionEvent with the passed string as an
* action command, and cause the displayer to fire this event. It will
* return true if no listener on the displayer consumed the TabActionEvent;
* consuming the event is the way a listener can veto a change, or provide
* special handling for it.
*
* @param command The action command - this should be TabDisplayer.COMMAND_SELECT
* or TabDisplayer.COMMAND_CLOSE, but private contracts
* between custom UIs and components are also an option.
* @param tab The index of the tab upon which the action should act, or
* -1 if non-applicable
* @param event A mouse event which initiated the action, or null
* @return true if the event posted was not consumed by any listener
*/
protected final boolean shouldPerformAction(String command, int tab, MouseEvent event) {
TabActionEvent evt = new TabActionEvent(container, command, tab, event);
container.postActionEvent(evt);
return !evt.isConsumed();
}
use of org.netbeans.swing.tabcontrol.event.TabActionEvent in project netbeans-rcp-lite by outersky.
the class SlideBar method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
if (e instanceof TabActionEvent) {
TabActionEvent tae = (TabActionEvent) e;
if (TabbedContainer.COMMAND_RESTORE_GROUP.equals(tae.getActionCommand())) {
String nameOfModeToRestore = tae.getGroupName();
WindowManagerImpl wm = WindowManagerImpl.getInstance();
ModeImpl modeToRestore = (ModeImpl) wm.findMode(nameOfModeToRestore);
if (null != modeToRestore) {
wm.userRestoredMode(tabbed.getSlidingMode(), modeToRestore);
}
}
}
}
use of org.netbeans.swing.tabcontrol.event.TabActionEvent in project netbeans-rcp-lite by outersky.
the class CommandManager method actionPerformed.
/**
******* implementation of ActionListener *************
*/
/**
* Reacts to actions from currently slided tabbed container, forwards
* received events to tabbed instance, which ensures that
* actions are handled in the same way as usual.
*/
@Override
public void actionPerformed(ActionEvent e) {
if (TabbedContainer.COMMAND_POPUP_REQUEST.equals(e.getActionCommand())) {
TabActionEvent tae = (TabActionEvent) e;
if (curSlidedComp != null && curSlidedComp instanceof TopComponent) {
TopComponent tc = (TopComponent) curSlidedComp;
Action[] actions = slideBar.getTabbed().getPopupActions(tc.getActions(), curSlidedIndex);
if (actions == null) {
actions = tc.getActions();
}
if (actions == null || actions.length == 0)
return;
showPopupMenu(Utilities.actionsToPopup(actions, tc.getLookup()), tae.getMouseEvent().getPoint(), tae.getMouseEvent().getComponent());
}
} else if (TabbedContainer.COMMAND_DISABLE_AUTO_HIDE.equals(e.getActionCommand())) {
if (curSlidedIndex >= 0)
slideIntoDesktop(curSlidedIndex, true);
} else if (TabbedContainer.COMMAND_ENABLE_AUTO_HIDE.equals(e.getActionCommand())) {
slideBar.getSelectionModel().setSelectedIndex(-1);
} else if (TabbedContainer.COMMAND_TOGGLE_TRANSPARENCY.equals(e.getActionCommand())) {
TabActionEvent tae = (TabActionEvent) e;
toggleTransparency(tae.getTabIndex());
} else if (TabbedContainer.COMMAND_MAXIMIZE.equals(e.getActionCommand())) {
// inform the window system that the slided window changes its maximized status
postEvent(new SlideBarActionEvent(slideBar, SlideBar.COMMAND_MAXIMIZE, null, null, curSlidedIndex));
} else {
// convert event - fix index, local tabbed container index isn't right in slide bar context
TabActionEvent tae = (TabActionEvent) e;
if (TabbedContainer.COMMAND_CLOSE.equals(tae.getActionCommand()) && curSlidedIndex < 0) {
// #242321
return;
}
TabActionEvent newEvt = new TabActionEvent(tae.getSource(), tae.getActionCommand(), curSlidedIndex, tae.getMouseEvent());
postEvent(newEvt);
}
}
use of org.netbeans.swing.tabcontrol.event.TabActionEvent in project netbeans-rcp-lite by outersky.
the class TabDisplayerUI method shouldPerformAction.
/**
* Allows ActionListeners attached to the container to determine if the
* event should be acted on. Delegates to <code>displayer.postActionEvent()</code>.
* This method will create a TabActionEvent with the passed string as an
* action command, and cause the displayer to fire this event. It will
* return true if no listener on the displayer consumed the TabActionEvent;
* consuming the event is the way a listener can veto a change, or provide
* special handling for it.
*
* @param command The action command - this should be TabDisplayer.COMMAND_SELECT
* or TabDisplayer.COMMAND_CLOSE, but private contracts
* between custom UIs and components are also an option.
* @param tab The index of the tab upon which the action should act, or
* -1 if non-applicable
* @param event A mouse event which initiated the action, or null
* @return true if the event posted was not consumed by any listener
*/
protected final boolean shouldPerformAction(String command, int tab, MouseEvent event) {
TabActionEvent evt = new TabActionEvent(displayer, command, tab, event);
displayer.postActionEvent(evt);
return !evt.isConsumed();
}
Aggregations