You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by no...@apache.org on 2009/11/11 14:04:35 UTC
svn commit: r834865 - in /incubator/pivot/trunk/wtk:
src/org/apache/pivot/wtk/ src/org/apache/pivot/wtk/skin/terra/
test/org/apache/pivot/wtk/test/
Author: noelgrandin
Date: Wed Nov 11 13:04:35 2009
New Revision: 834865
URL: http://svn.apache.org/viewvc?rev=834865&view=rev
Log:
PIVOT-236 SplitPane's resize weight should be configurable
Added:
incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/SplitPaneTest.java
incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/splitpane_test.wtkx
Modified:
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/SplitPane.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/SplitPaneListener.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraSplitPaneSkin.java
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/SplitPane.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/SplitPane.java?rev=834865&r1=834864&r2=834865&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/SplitPane.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/SplitPane.java Wed Nov 11 13:04:35 2009
@@ -42,6 +42,16 @@
BOTTOM_RIGHT
}
+ /**
+ * Enumeration defining split pane resizing modes.
+ */
+ public enum ResizeMode {
+ /** when resizing, maintain the ratio between the regions */
+ SPLIT_RATIO,
+ /** when resizing, preserve the size of the primary region */
+ PRIMARY_REGION
+ }
+
private static class SplitPaneListenerList extends ListenerList<SplitPaneListener>
implements SplitPaneListener {
@Override
@@ -85,12 +95,20 @@
listener.lockedChanged(splitPane);
}
}
+
+ @Override
+ public void resizeModeChanged(SplitPane splitPane, ResizeMode previousResizeMode) {
+ for (SplitPaneListener listener : this) {
+ listener.resizeModeChanged(splitPane, previousResizeMode);
+ }
+ }
}
private Component topLeft = null;
private Component bottomRight = null;
private Orientation orientation = null;
private Region primaryRegion = Region.TOP_LEFT;
+ private ResizeMode resizeMode = ResizeMode.SPLIT_RATIO;
private float splitRatio = 0.5f;
private boolean locked = false;
@@ -278,6 +296,31 @@
}
}
+ public ResizeMode getResizeMode() {
+ return resizeMode;
+ }
+
+ public void setResizeMode(ResizeMode resizeMode) {
+ if (resizeMode == null) {
+ throw new IllegalArgumentException("resizeMode is null.");
+ }
+
+ ResizeMode previousResizeMode = this.resizeMode;
+
+ if (this.resizeMode != resizeMode) {
+ this.resizeMode = resizeMode;
+ splitPaneListeners.resizeModeChanged(this, previousResizeMode);
+ }
+ }
+
+ public void setResizeMode(String resizeMode) {
+ if (resizeMode == null) {
+ throw new IllegalArgumentException("resizeMode is null.");
+ }
+
+ setResizeMode(ResizeMode.valueOf(resizeMode.toUpperCase()));
+ }
+
@Override
public Sequence<Component> remove(int index, int count) {
for (int i = index, n = index + count; i < n; i++) {
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/SplitPaneListener.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/SplitPaneListener.java?rev=834865&r1=834864&r2=834865&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/SplitPaneListener.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/SplitPaneListener.java Wed Nov 11 13:04:35 2009
@@ -76,4 +76,16 @@
* The source of the event.
*/
public void lockedChanged(SplitPane splitPane);
+
+ /**
+ * Called when a split pane's split location has changed.
+ *
+ * @param splitPane
+ * The source of the event.
+ *
+ * @param previousResizeMode
+ * The previous setting of the resizeMode.
+ */
+ public void resizeModeChanged(SplitPane splitPane, SplitPane.ResizeMode previousResizeMode);
+
}
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraSplitPaneSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraSplitPaneSkin.java?rev=834865&r1=834864&r2=834865&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraSplitPaneSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/terra/TerraSplitPaneSkin.java Wed Nov 11 13:04:35 2009
@@ -29,6 +29,7 @@
import org.apache.pivot.wtk.SplitPane;
import org.apache.pivot.wtk.SplitPaneListener;
import org.apache.pivot.wtk.Theme;
+import org.apache.pivot.wtk.SplitPane.ResizeMode;
import org.apache.pivot.wtk.skin.ComponentSkin;
import org.apache.pivot.wtk.skin.ContainerSkin;
@@ -156,6 +157,11 @@
if (shadow == null) {
// Update the split location immediately
splitPane.setSplitRatio(splitRatio);
+ if (orientation == Orientation.HORIZONTAL) {
+ splitter.setLocation(splitLocation, 0);
+ } else {
+ splitter.setLocation(0, splitLocation);
+ }
} else {
// Move the shadow to the split location
if (orientation == Orientation.HORIZONTAL) {
@@ -209,6 +215,7 @@
&& Mouse.getCapturer() == component) {
if (shadow != null) {
SplitPane splitPane = (SplitPane)TerraSplitPaneSkin.this.getComponent();
+ Orientation orientation = splitPane.getOrientation();
// Update the split location and remove the shadow
int splitLocation;
@@ -222,7 +229,11 @@
}
splitPane.setSplitRatio(splitRatio);
-
+ if (orientation == Orientation.HORIZONTAL) {
+ splitter.setLocation(splitLocation, 0);
+ } else {
+ splitter.setLocation(0, splitLocation);
+ }
splitPane.remove(shadow);
shadow = null;
}
@@ -295,6 +306,7 @@
SplitPane splitPane = (SplitPane)component;
splitPane.getSplitPaneListeners().add(this);
+ splitter.setLocation(-1, -1);
splitPane.add(splitter);
updateSplitterCursor();
}
@@ -322,11 +334,17 @@
SplitPane splitPane = (SplitPane)getComponent();
float splitRatio = splitPane.getSplitRatio();
+ SplitPane.ResizeMode resizeMode = splitPane.getResizeMode();
Component topLeft = splitPane.getTopLeft();
Component bottomRight = splitPane.getBottomRight();
if (splitPane.getOrientation() == Orientation.HORIZONTAL) {
- int splitLocation = limitSplitLocation((int)(splitRatio * width));
+ int splitLocation;
+ if (resizeMode == SplitPane.ResizeMode.SPLIT_RATIO || splitter.getX()==-1) {
+ splitLocation = limitSplitLocation((int)(splitRatio * width));
+ } else {
+ splitLocation = limitSplitLocation(splitter.getX());
+ }
int rightStart = splitLocation + splitterThickness;
splitter.setLocation(splitLocation, 0);
splitter.setSize(splitterThickness, height);
@@ -341,7 +359,12 @@
bottomRight.setSize(Math.max(width - rightStart, 0), height);
}
} else {
- int splitLocation = limitSplitLocation((int)(splitRatio * height));
+ int splitLocation;
+ if (resizeMode == SplitPane.ResizeMode.SPLIT_RATIO || splitter.getY()==-1) {
+ splitLocation = limitSplitLocation((int)(splitRatio * height));
+ } else {
+ splitLocation = limitSplitLocation(splitter.getY());
+ }
int bottomStart = splitLocation + splitterThickness;
splitter.setLocation(0, splitLocation);
splitter.setSize(width, splitterThickness);
@@ -464,6 +487,10 @@
public void lockedChanged(SplitPane splitPane) {
updateSplitterCursor();
}
+
+ @Override
+ public void resizeModeChanged(SplitPane splitPane, ResizeMode previousResizeMode) {
+ }
private void updateSplitterCursor() {
Cursor cursor = Cursor.DEFAULT;
Added: incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/SplitPaneTest.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/SplitPaneTest.java?rev=834865&view=auto
==============================================================================
--- incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/SplitPaneTest.java (added)
+++ incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/SplitPaneTest.java Wed Nov 11 13:04:35 2009
@@ -0,0 +1,60 @@
+/*
+ * 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.wtk.test;
+
+import org.apache.pivot.collections.Map;
+import org.apache.pivot.wtk.Application;
+import org.apache.pivot.wtk.Component;
+import org.apache.pivot.wtk.DesktopApplicationContext;
+import org.apache.pivot.wtk.Display;
+import org.apache.pivot.wtk.Window;
+import org.apache.pivot.wtkx.WTKXSerializer;
+
+public class SplitPaneTest implements Application {
+ private Window window = null;
+
+ @Override
+ public void startup(Display display, Map<String, String> properties) throws Exception {
+ WTKXSerializer wtkxSerializer = new WTKXSerializer();
+ window = new Window((Component)wtkxSerializer.readObject(getClass().getResource("splitpane_test.wtkx")));
+
+ window.setTitle("SplitPane Test");
+ window.setMaximized(true);
+ window.open(display);
+ }
+
+ @Override
+ public boolean shutdown(boolean optional) {
+ if (window != null) {
+ window.close();
+ }
+
+ return false;
+ }
+
+ @Override
+ public void suspend() {
+ }
+
+ @Override
+ public void resume() {
+ }
+
+ public static void main(String[] args) {
+ DesktopApplicationContext.main(SplitPaneTest.class, args);
+ }
+}
Added: incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/splitpane_test.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/splitpane_test.wtkx?rev=834865&view=auto
==============================================================================
--- incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/splitpane_test.wtkx (added)
+++ incubator/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/splitpane_test.wtkx Wed Nov 11 13:04:35 2009
@@ -0,0 +1,66 @@
+<?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.
+-->
+
+<BoxPane xmlns:wtkx="http://pivot.apache.org/wtkx"
+ xmlns="org.apache.pivot.wtk" orientation="vertical" styles="{fill:true}">
+ <Label text="Test 1"/>
+ <SplitPane orientation="vertical" splitRatio="0.5" preferredWidth="480" preferredHeight="360">
+ <top>
+ <SplitPane orientation="horizontal" splitRatio="0.5" resizeMode="primary_region">
+ <left>
+ <ImageView asynchronous="true"
+ image="@IMG_0735_2.jpg"
+ styles="{backgroundColor:'#404040'}"/>
+ </left>
+ <right>
+ <ImageView asynchronous="true"
+ image="@IMG_0735_2.jpg"
+ styles="{backgroundColor:'#404040'}"/>
+ </right>
+ </SplitPane>
+ </top>
+ <bottom>
+ <ImageView asynchronous="true"
+ image="@IMG_0735_2.jpg"
+ styles="{backgroundColor:'#404040'}"/>
+ </bottom>
+ </SplitPane>
+ <Label text="Test 2"/>
+ <SplitPane orientation="horizontal" splitRatio="0.5" preferredWidth="480" preferredHeight="360">
+ <top>
+ <SplitPane orientation="vertical" splitRatio="0.5" resizeMode="primary_region">
+ <left>
+ <ImageView asynchronous="true"
+ image="@IMG_0735_2.jpg"
+ styles="{backgroundColor:'#404040'}"/>
+ </left>
+ <right>
+ <ImageView asynchronous="true"
+ image="@IMG_0735_2.jpg"
+ styles="{backgroundColor:'#404040'}"/>
+ </right>
+ </SplitPane>
+ </top>
+ <bottom>
+ <ImageView asynchronous="true"
+ image="@IMG_0735_2.jpg"
+ styles="{backgroundColor:'#404040'}"/>
+ </bottom>
+ </SplitPane>
+</BoxPane>
+
\ No newline at end of file
Re: svn commit: r834865
Posted by Greg Brown <gk...@mac.com>.
Yeah, yeah - I know you think my methods are too long. ;-) But in
this context, "long" means "anything more than 3 or 4 lines".
You may disagree, but I find that a single return value does improve
readability.
On Nov 11, 2009, at 9:12 AM, Christopher Brind wrote:
> You could argue that if your methods are that long, they are doing
> too much.
> :)
>
>
> 2009/11/11 Greg Brown <gk...@mac.com>
>
>> I thought Todd had checked in an eclipse-formatter file? I can't
>> seem to
>>> find it in SVN right now.
>>>
>>
>> It was moved to the new /project branch Todd created (it used to be
>> in a
>> /project sub-directory of /trunk):
>>
>> http://svn.apache.org/repos/asf/incubator/pivot/project/pivot_style.xml
>>
>> It is also in the Wiki:
>>
>> http://cwiki.apache.org/confluence/display/PIVOT/Platform+Developer+Info
>>
>>
>> Cool, I'm happy to follow the pivot-style, although I disagree with
>> the
>>> Pascal-style single-return-from-routine theory.
>>> I'm in the linux-kernel-style multiple-return early-exit camp :-)
>>>
>>
>> Though I generally don't use the style myself, I do think multiple
>> returns
>> are OK for trivial methods. However, I think it has a negative
>> effect on
>> readability for longer methods.
>>
>>
Re: svn commit: r834865
Posted by Christopher Brind <ch...@googlemail.com>.
You could argue that if your methods are that long, they are doing too much.
:)
2009/11/11 Greg Brown <gk...@mac.com>
> I thought Todd had checked in an eclipse-formatter file? I can't seem to
>> find it in SVN right now.
>>
>
> It was moved to the new /project branch Todd created (it used to be in a
> /project sub-directory of /trunk):
>
> http://svn.apache.org/repos/asf/incubator/pivot/project/pivot_style.xml
>
> It is also in the Wiki:
>
> http://cwiki.apache.org/confluence/display/PIVOT/Platform+Developer+Info
>
>
> Cool, I'm happy to follow the pivot-style, although I disagree with the
>> Pascal-style single-return-from-routine theory.
>> I'm in the linux-kernel-style multiple-return early-exit camp :-)
>>
>
> Though I generally don't use the style myself, I do think multiple returns
> are OK for trivial methods. However, I think it has a negative effect on
> readability for longer methods.
>
>
Re: svn commit: r834865
Posted by Greg Brown <gk...@mac.com>.
> I thought Todd had checked in an eclipse-formatter file? I can't
> seem to
> find it in SVN right now.
It was moved to the new /project branch Todd created (it used to be in
a /project sub-directory of /trunk):
http://svn.apache.org/repos/asf/incubator/pivot/project/pivot_style.xml
It is also in the Wiki:
http://cwiki.apache.org/confluence/display/PIVOT/Platform+Developer+Info
> Cool, I'm happy to follow the pivot-style, although I disagree with
> the
> Pascal-style single-return-from-routine theory.
> I'm in the linux-kernel-style multiple-return early-exit camp :-)
Though I generally don't use the style myself, I do think multiple
returns are OK for trivial methods. However, I think it has a negative
effect on readability for longer methods.
Re: svn commit: r834865
Posted by Noel Grandin <no...@gmail.com>.
Thanks. I have some free time right now (at least until the next crisis
at work erupts), so I'm picking off the simpler issues from the JIRA.
I thought Todd had checked in an eclipse-formatter file? I can't seem to
find it in SVN right now.
Cool, I'm happy to follow the pivot-style, although I disagree with the
Pascal-style single-return-from-routine theory.
I'm in the linux-kernel-style multiple-return early-exit camp :-)
-- Noel.
Greg Brown wrote:
> Noel,
>
> Great work on your recent checkins - thanks! I just have a couple
> minor coding style comments:
>
> - Don't include a space after a cast operator.
>
> - Do include spaces around mathematical operators (e.g. 1 + 2 vs. 1+2).
>
> - Try to structure your methods to use a single return statement,
> rather than returning from arbitrary points in the method. It makes it
> easier to follow the logic.
>
> Thanks!
> Greg
>
Re: svn commit: r834865
Posted by Greg Brown <gk...@mac.com>.
Noel,
Great work on your recent checkins - thanks! I just have a couple
minor coding style comments:
- Don't include a space after a cast operator.
- Do include spaces around mathematical operators (e.g. 1 + 2 vs. 1+2).
- Try to structure your methods to use a single return statement,
rather than returning from arbitrary points in the method. It makes it
easier to follow the logic.
Thanks!
Greg