use of org.apache.pivot.wtk.TabPane in project pivot by apache.
the class TerraTabPaneSkin method install.
@Override
public void install(Component component) {
super.install(component);
TabPane tabPane = (TabPane) component;
// Add this as a listener on the tab pane
tabPane.getTabPaneListeners().add(this);
tabPane.getTabPaneSelectionListeners().add(this);
tabPane.getTabPaneAttributeListeners().add(this);
// Add the tab button container
tabPane.add(tabButtonPanorama);
}
use of org.apache.pivot.wtk.TabPane in project pivot by apache.
the class TabPanes method initialize.
@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
confirmCloseTabPrompt = (Prompt) namespace.get("confirmCloseTabPrompt");
tabPane = (TabPane) namespace.get("tabPane");
closeableCheckbox = (Checkbox) namespace.get("closeableCheckbox");
collapsibleCheckbox = (Checkbox) namespace.get("collapsibleCheckbox");
horizontalRadioButton = (RadioButton) namespace.get("horizontalRadioButton");
verticalRadioButton = (RadioButton) namespace.get("verticalRadioButton");
cornerBoxPane = (BoxPane) namespace.get("cornerBoxPane");
tabPane.getTabPaneListeners().add(new TabPaneListener() {
@Override
public Vote previewRemoveTabs(final TabPane tabPaneArgument, final int index, final int count) {
Vote vote;
if (confirmCloseTab) {
confirmCloseTabPrompt.open(TabPanes.this, new SheetCloseListener() {
@Override
public void sheetClosed(Sheet sheet) {
if (confirmCloseTabPrompt.getResult() && confirmCloseTabPrompt.getSelectedOptionIndex() == 1) {
confirmCloseTab = false;
int n = tabPaneArgument.getTabs().getLength();
if (index < n - 1) {
tabPaneArgument.setSelectedIndex(index + 1);
} else {
tabPaneArgument.setSelectedIndex(index - 1);
}
tabPaneArgument.getTabs().remove(index, count);
confirmCloseTab = true;
}
}
});
vote = Vote.DENY;
} else {
vote = Vote.APPROVE;
}
return vote;
}
});
ButtonStateListener checkboxStateListener = new ButtonStateListener() {
@Override
public void stateChanged(Button button, Button.State previousState) {
updateTabPane();
}
};
closeableCheckbox.getButtonStateListeners().add(checkboxStateListener);
collapsibleCheckbox.getButtonStateListeners().add(checkboxStateListener);
ButtonStateListener radioButtonStateListener = new ButtonStateListener() {
@Override
public void stateChanged(Button button, Button.State previousState) {
if (button.isSelected()) {
updateTabPane();
}
}
};
horizontalRadioButton.getButtonStateListeners().add(radioButtonStateListener);
verticalRadioButton.getButtonStateListeners().add(radioButtonStateListener);
updateTabPane();
}
use of org.apache.pivot.wtk.TabPane in project pivot by apache.
the class Pivot751WithoutGUI method main.
public static void main(String[] args) {
final TabPane tabPane = new TabPane();
tabPane.getTabPaneSelectionListeners().add(new TabPaneSelectionListener() {
@Override
public void selectedIndexChanged(TabPane tabPaneArgument, int previousSelectedIndex) {
System.out.println(String.format("tabs : %-16d actual selectedIndex : %d", tabPaneArgument.getTabs().getLength(), tabPaneArgument.getSelectedIndex()));
System.out.println(String.format("indirect : %-16s 'previousSelectedIndex' : %d", (previousSelectedIndex == tabPaneArgument.getSelectedIndex()), previousSelectedIndex));
}
});
System.out.println("Empty TabPane sequence");
System.out.println(String.format("tabs : %-16d actual selectedIndex : %d", tabPane.getTabs().getLength(), tabPane.getSelectedIndex()));
System.out.println("\nAdding first Label to the sequence");
tabPane.getTabs().add(new Label("1"));
System.out.println("\nAdding second Label at the end of the sequence");
tabPane.getTabs().add(new Label("2"));
System.out.println("\nInserting third Label at the start of the sequence");
tabPane.getTabs().insert(new Label("3"), 0);
System.out.println("\nAdding a fourth Label at the end of the sequence");
tabPane.getTabs().add(new Label("4"));
System.out.println("\nExplicitly select the last tab");
tabPane.setSelectedIndex(3);
System.out.println("\nRemoving the first 2 Labels from the start of the sequence");
tabPane.getTabs().remove(0, 2);
System.out.println("\nRemoving the tab at the end of the sequence");
tabPane.getTabs().remove(1, 1);
}
use of org.apache.pivot.wtk.TabPane in project pivot by apache.
the class TerraTabPaneSkin method paint.
@Override
public void paint(Graphics2D graphics) {
TabPane tabPane = (TabPane) getComponent();
Bounds tabPaneBounds = tabPane.getBounds();
// Call the base class to paint the background
super.paint(graphics);
// Paint the content background and border
int x = 0;
int y = 0;
int width = 0;
int height = 0;
switch(tabOrientation) {
case HORIZONTAL:
{
x = 0;
y = Math.max(tabButtonPanorama.getY() + tabButtonPanorama.getHeight() - 1, 0);
width = tabPaneBounds.width;
height = Math.max(tabPaneBounds.height - y, 0);
break;
}
case VERTICAL:
{
x = Math.max(tabButtonPanorama.getX() + tabButtonPanorama.getWidth() - 1, 0);
y = 0;
width = Math.max(tabPaneBounds.width - x, 0);
height = tabPaneBounds.height;
break;
}
default:
{
break;
}
}
TabButton activeTabButton;
if (selectionChangeTransition == null) {
activeTabButton = (TabButton) tabButtonGroup.getSelection();
} else {
activeTabButton = (TabButton) tabButtonBoxPane.get(selectionChangeTransition.index);
}
if (activeTabButton != null) {
Bounds contentBounds = new Bounds(x, y, width, height);
GraphicsUtilities.setAntialiasingOn(graphics);
// Paint the background
graphics.setPaint(activeTabColor);
graphics.fillRect(contentBounds.x, contentBounds.y, contentBounds.width, contentBounds.height);
if (!themeIsFlat()) {
// Draw the border
double top = contentBounds.y + 0.5;
double left = contentBounds.x + 0.5;
double bottom = top + contentBounds.height - 1;
double right = left + contentBounds.width - 1;
graphics.setPaint(borderColor);
// Draw the right and bottom borders
graphics.draw(new Line2D.Double(right, top, right, bottom));
graphics.draw(new Line2D.Double(left, bottom, right, bottom));
// Draw the left and top borders
switch(tabOrientation) {
case HORIZONTAL:
{
graphics.draw(new Line2D.Double(left, top, left, bottom));
Point selectedTabButtonLocation = activeTabButton.mapPointToAncestor(tabPane, 0, 0);
graphics.draw(new Line2D.Double(left, top, selectedTabButtonLocation.x + 0.5, top));
graphics.draw(new Line2D.Double(selectedTabButtonLocation.x + activeTabButton.getWidth() - 0.5, top, right, top));
break;
}
case VERTICAL:
{
graphics.draw(new Line2D.Double(left, top, right, top));
Point selectedTabButtonLocation = activeTabButton.mapPointToAncestor(tabPane, 0, 0);
graphics.draw(new Line2D.Double(left, top, left, selectedTabButtonLocation.y + 0.5));
graphics.draw(new Line2D.Double(left, selectedTabButtonLocation.y + activeTabButton.getHeight() - 0.5, left, bottom));
break;
}
default:
{
break;
}
}
}
}
}
use of org.apache.pivot.wtk.TabPane in project pivot by apache.
the class TerraTabPaneSkin method getPreferredSize.
@Override
public Dimensions getPreferredSize() {
TabPane tabPane = (TabPane) getComponent();
int preferredWidth;
int preferredHeight;
Component selectedTab = tabPane.getSelectedTab();
Component corner = tabPane.getCorner();
switch(tabOrientation) {
case HORIZONTAL:
{
if (selectedTab == null && selectionChangeTransition == null) {
preferredWidth = getPreferredTabWidth(-1) + (padding.left + padding.right + 2);
preferredHeight = 1;
} else {
Dimensions preferredTabSize = getPreferredTabSize();
preferredWidth = preferredTabSize.width + (padding.left + padding.right + 2);
preferredHeight = preferredTabSize.height + (padding.top + padding.bottom);
if (selectionChangeTransition != null) {
float scale = selectionChangeTransition.getScale();
preferredHeight = (int) (preferredHeight * scale);
}
preferredHeight += 2;
}
int buttonAreaPreferredWidth = tabButtonPanorama.getPreferredWidth(-1);
if (corner != null) {
buttonAreaPreferredWidth += corner.getPreferredWidth(-1);
preferredHeight += Math.max(corner.getPreferredHeight(-1), Math.max(tabButtonPanorama.getPreferredHeight(-1) - 1, 0));
// space between corner and
buttonAreaPreferredWidth += 2;
// panorama
} else {
preferredHeight += Math.max(tabButtonPanorama.getPreferredHeight(-1) - 1, 0);
}
preferredWidth = Math.max(preferredWidth, buttonAreaPreferredWidth);
break;
}
case VERTICAL:
{
if (selectedTab == null && selectionChangeTransition == null) {
preferredWidth = 1;
preferredHeight = getPreferredTabHeight(-1) + (padding.top + padding.bottom + 2);
} else {
Dimensions preferredTabSize = getPreferredTabSize();
preferredWidth = preferredTabSize.width + (padding.left + padding.right);
preferredHeight = preferredTabSize.height + (padding.top + padding.bottom + 2);
if (selectionChangeTransition != null) {
float scale = selectionChangeTransition.getScale();
preferredWidth = (int) (preferredWidth * scale);
}
preferredWidth += 2;
}
int buttonAreaPreferredHeight = tabButtonPanorama.getPreferredHeight(-1);
if (corner != null) {
buttonAreaPreferredHeight += corner.getPreferredHeight(-1);
preferredWidth += Math.max(corner.getPreferredWidth(-1), Math.max(tabButtonPanorama.getPreferredWidth(-1) - 1, 0));
// space between corner and
buttonAreaPreferredHeight += 2;
// panorama
} else {
preferredWidth += Math.max(tabButtonPanorama.getPreferredWidth(-1) - 1, 0);
}
preferredHeight = Math.max(preferredHeight, buttonAreaPreferredHeight);
break;
}
default:
{
preferredWidth = 0;
preferredHeight = 0;
}
}
return new Dimensions(preferredWidth, preferredHeight);
}
Aggregations