Is /pivot-trunk/tutorials the correct place for a small app demonstrating the functionality of a change, or is it supposed to be just for things that are included in the tutorial section of the website? http://pivot.apache.org/tutorials/
Perhaps /pivot-trunk/examples/ is better? Chris On 25 June 2011 02:41, <[email protected]> wrote: > Author: cbartlett > Date: Fri Jun 24 19:41:09 2011 > New Revision: 1139416 > > URL: http://svn.apache.org/viewvc?rev=1139416&view=rev > Log: > PIVOT-682 - Updated to include a new 'slideSource' style > Tutorial script application included > > Added: > pivot/trunk/tutorials/src/org/apache/pivot/tutorials/sheets/ > pivot/trunk/tutorials/src/org/apache/pivot/tutorials/sheets/Sheets.java > pivot/trunk/tutorials/src/org/apache/pivot/tutorials/sheets/sheets.bxml > Modified: > > pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraSheetSkin.java > > Added: > pivot/trunk/tutorials/src/org/apache/pivot/tutorials/sheets/Sheets.java > URL: > http://svn.apache.org/viewvc/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/sheets/Sheets.java?rev=1139416&view=auto > > ============================================================================== > --- pivot/trunk/tutorials/src/org/apache/pivot/tutorials/sheets/Sheets.java > (added) > +++ pivot/trunk/tutorials/src/org/apache/pivot/tutorials/sheets/Sheets.java > Fri Jun 24 19:41:09 2011 > @@ -0,0 +1,117 @@ > +/* > + * Licensed to the Apache Software Foundation (ASF) under one or more > + * contributor license agreements. See the NOTICE file distributed with > + * this work for additional information regarding copyright ownership. > + * The ASF licenses this file to you under the Apache License, > + * Version 2.0 (the "License"); you may not use this file except in > + * compliance with the License. You may obtain a copy of the License at > + * > + * http://www.apache.org/licenses/LICENSE-2.0 > + * > + * Unless required by applicable law or agreed to in writing, software > + * distributed under the License is distributed on an "AS IS" BASIS, > + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or > implied. > + * See the License for the specific language governing permissions and > + * limitations under the License. > + */ > +package org.apache.pivot.tutorials.sheets; > + > +import java.net.URL; > +import java.util.Iterator; > + > +import org.apache.pivot.beans.BXML; > +import org.apache.pivot.beans.Bindable; > +import org.apache.pivot.collections.ArrayList; > +import org.apache.pivot.collections.Map; > +import org.apache.pivot.util.Resources; > +import org.apache.pivot.wtk.Button; > +import org.apache.pivot.wtk.ButtonPressListener; > +import org.apache.pivot.wtk.Component; > +import org.apache.pivot.wtk.Container; > +import org.apache.pivot.wtk.ContainerMouseListener; > +import org.apache.pivot.wtk.Display; > +import org.apache.pivot.wtk.Form; > +import org.apache.pivot.wtk.ListButton; > +import org.apache.pivot.wtk.Mouse; > +import org.apache.pivot.wtk.PushButton; > +import org.apache.pivot.wtk.Sheet; > +import org.apache.pivot.wtk.TablePane; > +import org.apache.pivot.wtk.Window; > +import org.apache.pivot.wtk.WindowStateListener; > +import org.apache.pivot.wtk.skin.terra.TerraSheetSkin.SheetPlacement; > + > +public class Sheets extends Window implements Bindable { > + > + @BXML private Sheet sheet; > + @BXML private TablePane tablePane; > + @BXML private Form form; > + @BXML private ListButton listButton; > + > + @Override > + public void initialize(Map<String, Object> namespace, URL location, > Resources resources) { > + > + // Populate the ListButton with values from the enum > + listButton.setListData(new > ArrayList<SheetPlacement>(SheetPlacement.values())); > + listButton = null; > + > + // Populate the form with data from the Sheet's styles > + form.load(sheet.getStyles()); > + > + // Common ButtonPressListener to be applied to all four of > + // the PushButtons representing a slide direction > + ButtonPressListener openSheetButtonPressListener = new > ButtonPressListener() { > + @Override > + public void buttonPressed(Button button) { > + StyleDictionary sheetStyles = sheet.getStyles(); > + form.store(sheetStyles); > + button.store(sheetStyles); > + form.load(sheetStyles); > + sheet.load(sheetStyles); > + sheet.open(button.getWindow()); > + } > + }; > + > + // Apply the common ButtonPressListener to the PushButtons > + for (Iterator<Component> it = tablePane.iterator(); it.hasNext();) > { > + Component component = it.next(); > + if (component instanceof PushButton) { > + PushButton button = (PushButton) component; > + > button.getButtonPressListeners().add(openSheetButtonPressListener); > + button.setTooltipText("Press me!"); > + } > + } > + tablePane = null; > + > + // Mouse handler to enable users to quickly close the sheet > + final ContainerMouseListener displayMouseHandler = new > ContainerMouseListener.Adapter() { > + @Override > + public boolean mouseDown(Container container, Mouse.Button > button, int x, int y) { > + Display display = (Display) container; > + Component component = display.getComponentAt(x, y); > + > + // Close the sheet by clicking away from it. > + // This allows resizing etc to work without requiring > + // a close button or similar on the sheet. > + boolean consumed = (component != sheet); > + if (consumed) { > + sheet.close(); > + } > + return consumed; > + } > + }; > + > + // Add/remove the mouse handler based on the Sheet's state > + sheet.getWindowStateListeners().add(new > WindowStateListener.Adapter() { > + @Override > + public void windowOpened(Window window) { > + > window.getDisplay().getContainerMouseListeners().add(displayMouseHandler); > + } > + > + @Override > + public void windowClosed(Window window, Display display, > Window owner) { > + > display.getContainerMouseListeners().remove(displayMouseHandler); > + } > + }); > + } > + > +} > \ No newline at end of file > > Added: > pivot/trunk/tutorials/src/org/apache/pivot/tutorials/sheets/sheets.bxml > URL: > http://svn.apache.org/viewvc/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/sheets/sheets.bxml?rev=1139416&view=auto > > ============================================================================== > --- pivot/trunk/tutorials/src/org/apache/pivot/tutorials/sheets/sheets.bxml > (added) > +++ pivot/trunk/tutorials/src/org/apache/pivot/tutorials/sheets/sheets.bxml > Fri Jun 24 19:41:09 2011 > @@ -0,0 +1,121 @@ > +<?xml version="1.0" encoding="UTF-8"?> > +<!-- > +Licensed to the Apache Software Foundation (ASF) under one or more > +contributor license agreements. See the NOTICE file distributed with > +this work for additional information regarding copyright ownership. > +The ASF licenses this file to you under the Apache License, > +Version 2.0 (the "License"); you may not use this file except in > +compliance with the License. You may obtain a copy of the License at > + > + http://www.apache.org/licenses/LICENSE-2.0 > + > +Unless required by applicable law or agreed to in writing, software > +distributed under the License is distributed on an "AS IS" BASIS, > +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. > +See the License for the specific language governing permissions and > +limitations under the License. > +--> > + > +<sheets:Sheets > + xmlns:bxml="http://pivot.apache.org/bxml" > + xmlns="org.apache.pivot.wtk" > + xmlns:sheets="org.apache.pivot.tutorials.sheets" > + xmlns:content="org.apache.pivot.wtk.content" > + title="Sheets" maximized="true" > + width="600" height="600"> > + > + <bxml:define> > + <!-- Sheet that will be displayed when any of the 'open' buttons > are pressed --> > + <Sheet bxml:id="sheet" preferredWidth="300" preferredHeight="300" > + styles="{padding:8, slideSource:'north', > stateTransitionRate:30, stateTransitionDuration:300}"> > + <Border title="Sheet Styles"> > + <BoxPane orientation="vertical" > + styles="{fill:true, horizontalAlignment:'center', > verticalAlignment:'center'}" > > + <Form styles="{leftAlignLabels:false}"> > + <Form.Section> > + <Label Form.label="slideSource" > + textKey="slideSource" > styles="{font:{bold:true}}" /> > + <Label Form.label="stateTransitionDuration" > + textKey="stateTransitionDuration" > styles="{font:{bold:true}}" /> > + <Label Form.label="stateTransitionRate" > + textKey="stateTransitionRate" > styles="{font:{bold:true}}" /> > + <Label Form.label="resizable" > + textKey="resizable" > styles="{font:{bold:true}}" /> > + </Form.Section> > + </Form> > + </BoxPane> > + </Border> > + </Sheet> > + </bxml:define> > + > + > + <Border> > + > + <TablePane bxml:id="tablePane" > + styles="{padding:10, horizontalSpacing:20, > verticalSpacing:20}" > > + > + <columns> > + <TablePane.Column width="1*" /> > + <TablePane.Column width="1*" /> > + <TablePane.Column width="1*" /> > + </columns> > + > + <TablePane.Row height="1*"> > + <TablePane.Filler /> > + <PushButton buttonData="NORTH" buttonDataKey="slideSource" > /> > + <TablePane.Filler /> > + </TablePane.Row> > + > + <TablePane.Row height="1*"> > + <PushButton buttonData="WEST" buttonDataKey="slideSource" > /> > + > + <Border> > + <BoxPane orientation="vertical" > + styles="{horizontalAlignment:'center', > verticalAlignment:'center'}"> > + <!-- Central Form --> > + <Form bxml:id="form" > > + <Form.Section heading="Sheet Styles" > > + <ListButton Form.label="Slide Source" > selectedItemKey="slideSource" bxml:id="listButton" > + styles="{closeTransitionDuration:200, > closeTransitionRate:30}" /> > + <Spinner Form.label="Transition Duration" > selectedItemKey="stateTransitionDuration" > + selectedIndex="2" preferredWidth="50"> > + <spinnerData> > + <content:NumericSpinnerData > lowerBound="100" upperBound="2000" increment="100"/> > + </spinnerData> > + </Spinner> > + <Spinner Form.label="Transition Rate" > selectedItemKey="stateTransitionRate" > + selectedIndex="2" preferredWidth="50"> > + <spinnerData> > + <content:NumericSpinnerData > lowerBound="10" upperBound="100" increment="10"/> > + </spinnerData> > + </Spinner> > + <Checkbox Form.label="Resizable" > selectedKey="resizable" selected="true" /> > + </Form.Section> > + </Form> > + <PushButton buttonData="Open Sheet"> > + <buttonPressListeners> > + function buttonPressed(button) { > + var sheetStyles = sheet.getStyles(); > + form.store(sheetStyles); > + sheet.load(sheetStyles); > + sheet.open(button.getWindow()); > + } > + </buttonPressListeners> > + </PushButton> > + </BoxPane> > + </Border> > + > + <PushButton buttonData="EAST" buttonDataKey="slideSource" > /> > + </TablePane.Row> > + > + <TablePane.Row height="1*"> > + <TablePane.Filler /> > + <PushButton buttonData="SOUTH" buttonDataKey="slideSource" > /> > + <TablePane.Filler /> > + </TablePane.Row> > + > + </TablePane> > + > + </Border> > + > +</sheets:Sheets> > > Modified: > pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraSheetSkin.java > URL: > http://svn.apache.org/viewvc/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraSheetSkin.java?rev=1139416&r1=1139415&r2=1139416&view=diff > > ============================================================================== > --- > pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraSheetSkin.java > (original) > +++ > pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraSheetSkin.java > Fri Jun 24 19:41:09 2011 > @@ -55,7 +55,13 @@ import org.apache.pivot.wtk.skin.WindowS > * Sheet skin class. > */ > public class TerraSheetSkin extends WindowSkin implements > SheetStateListener { > + > + public enum SheetPlacement { > + NORTH, EAST, SOUTH, WEST > + } > + > public class OpenTransition extends Transition { > + private int dx = 0; > private int dy = 0; > > public OpenTransition(boolean reversed) { > @@ -67,6 +73,7 @@ public class TerraSheetSkin extends Wind > Sheet sheet = (Sheet)getComponent(); > sheet.getDecorators().add(translationDecorator); > > + dx = 0; > dy = 0; > > super.start(transitionListener); > @@ -95,14 +102,32 @@ public class TerraSheetSkin extends Wind > if (display != null) { > Bounds decoratedBounds = sheet.getDecoratedBounds(); > display.repaint(decoratedBounds.x, decoratedBounds.y, > - decoratedBounds.width, decoratedBounds.height + dy); > + decoratedBounds.width + dx, decoratedBounds.height + > dy); > > Dimensions size = sheet.getPreferredSize(); > - dy = -(int)(size.height * scale); > + switch (slideSource) { > + case NORTH: > + dy = -(int)(size.height * scale); > + break; > + case EAST: > + dx = (int)(size.width * scale); > + break; > + case SOUTH: > + dy = (int)(size.height * scale); > + break; > + case WEST: > + dx = -(int)(size.width * scale); > + break; > + default: > + throw new IllegalStateException( > + "slideSource is null or an unexpected value"); > + } > + > + translationDecorator.setX(dx); > translationDecorator.setY(dy); > > display.repaint(decoratedBounds.x, decoratedBounds.y, > - decoratedBounds.width, decoratedBounds.height + dy); > + decoratedBounds.width + dx, decoratedBounds.height + > dy); > } > } > } > @@ -145,6 +170,7 @@ public class TerraSheetSkin extends Wind > private Color borderColor; > private Insets padding; > private boolean resizable; > + private SheetPlacement slideSource = SheetPlacement.NORTH; > > private int stateTransitionDuration = > DEFAULT_STATE_TRANSITION_DURATION; > private int stateTransitionRate = DEFAULT_STATE_TRANSITION_RATE; > @@ -562,6 +588,17 @@ public class TerraSheetSkin extends Wind > invalidateComponent(); > } > > + public SheetPlacement getSlideSource() { > + return slideSource; > + } > + > + public void setSlideSource(SheetPlacement slideSource) { > + if (slideSource == null) { > + throw new IllegalArgumentException("slideSource is null."); > + } > + this.slideSource = slideSource; > + } > + > public int getStateTransitionDuration() { > return stateTransitionDuration; > } > @@ -668,9 +705,36 @@ public class TerraSheetSkin extends Wind > Sheet sheet = (Sheet)getComponent(); > > Window owner = sheet.getOwner(); > - Bounds clientArea = owner.getClientArea(); > + if (owner != null) { > + Bounds clientArea = owner.getClientArea(); > > - Point location = owner.mapPointToAncestor(owner.getDisplay(), > clientArea.x, clientArea.y); > - sheet.setLocation(location.x + (clientArea.width - getWidth()) / > 2, location.y); > + Point location = owner.mapPointToAncestor(owner.getDisplay(), > clientArea.x, > + clientArea.y); > + int x = location.x; > + int y = location.y; > + > + switch (slideSource) { > + case NORTH: > + x = location.x + (clientArea.width - getWidth()) / 2; > + y = location.y; > + break; > + case SOUTH: > + x = location.x + (clientArea.width - getWidth()) / 2; > + y = location.y + (clientArea.height - getHeight()); > + break; > + case WEST: > + x = location.x; > + y = location.y + (clientArea.height - getHeight()) / > 2; > + break; > + case EAST: > + x = location.x + (clientArea.width - getWidth()); > + y = location.y + (clientArea.height - getHeight()) / > 2; > + break; > + default: > + throw new IllegalStateException("slideSource is null > or an unexpected value"); > + } > + > + sheet.setLocation(x, y); > + } > } > } > > >
