Hi,
Here's a refactoring of SplitPaneSkin ..
one notable change would be the Shadow classes changed from terra::protected
to skin::public.
/john/
> Hi,
>
> Looks like much of the code in wtk/skin/terra isn't really L&F but more
> basic, and should probably be refactored back into wtk/skin. Comparing the
> state of TablePaneSkin / TerraTablePaneSkin with SplitPaneSkin /
> TerraSplitPaneSkin highlights the situation. (first, there is no
> SplitPaneSkin).
>
> I'll send some patches.
>
> And then I'm on to making Split Pane default to 50%. I have an eye out for
> a solution to relative layout for Split Pane.
>
> /john/
>
>
Index: wtk/src/pivot/wtk/skin/terra/TerraSplitPaneSkin.java
===================================================================
--- wtk/src/pivot/wtk/skin/terra/TerraSplitPaneSkin.java (revision
755824)
+++ wtk/src/pivot/wtk/skin/terra/TerraSplitPaneSkin.java (working copy)
@@ -33,166 +33,42 @@
import pivot.wtk.SplitPaneListener;
import pivot.wtk.Theme;
import pivot.wtk.skin.ComponentSkin;
-import pivot.wtk.skin.ContainerSkin;
+import pivot.wtk.skin.SplitPaneSkin;
/**
* Split pane skin.
*
* @author tvolkert
+ * @author jdp
*/
-public class TerraSplitPaneSkin extends ContainerSkin
+public class TerraSplitPaneSkin extends SplitPaneSkin
implements SplitPaneListener {
/**
* Split pane splitter component.
*
* @author tvolkert
+ * @author jdp
*/
- protected class Splitter extends Component {
+ protected class Splitter extends SplitPaneSkin.Splitter {
public Splitter() {
super();
- setSkin(new SplitterSkin());
+ setSkin(new TerraSplitPaneSkin.SplitterSkin());
}
-
- public void updateCursor() {
- Cursor cursor = Cursor.DEFAULT;
- SplitPane splitPane =
(SplitPane)TerraSplitPaneSkin.this.getComponent();
-
- if (!splitPane.isLocked()) {
- switch (splitPane.getOrientation()) {
- case HORIZONTAL:
- switch (splitPane.getPrimaryRegion()) {
- case TOP_LEFT:
- cursor = Cursor.RESIZE_EAST;
- break;
- case BOTTOM_RIGHT:
- cursor = Cursor.RESIZE_WEST;
- break;
- }
- break;
-
- case VERTICAL:
- switch (splitPane.getPrimaryRegion()) {
- case TOP_LEFT:
- cursor = Cursor.RESIZE_SOUTH;
- break;
- case BOTTOM_RIGHT:
- cursor = Cursor.RESIZE_NORTH;
- break;
- }
- break;
- }
- }
-
- setCursor(cursor);
- }
}
/**
* Split pane splitter component skin.
*
* @author tvolkert
+ * @author jdp
*/
- protected class SplitterSkin extends ComponentSkin {
- private class DragHandler
- implements ComponentMouseListener, ComponentMouseButtonListener {
- public boolean mouseMove(Component component, int x, int y) {
- SplitPane splitPane =
(SplitPane)TerraSplitPaneSkin.this.getComponent();
+ protected class SplitterSkin extends SplitPaneSkin.SplitterSkin {
- Orientation orientation = splitPane.getOrientation();
-
- // Calculate the would-be new split location
- int splitLocation;
- if (orientation == Orientation.HORIZONTAL) {
- splitLocation = x - dragOffset;
- } else {
- splitLocation = y - dragOffset;
- }
-
- splitLocation = boundSplitLocation(splitLocation);
-
- if (shadow == null) {
- // Update the split location immediately
- splitPane.setSplitLocation(splitLocation);
- } else {
- // Move the shadow
- if (orientation == Orientation.HORIZONTAL) {
- shadow.setLocation(splitLocation, 0);
- } else {
- shadow.setLocation(0, splitLocation);
- }
- }
-
- return false;
- }
-
- public void mouseOver(Component component) {
- }
-
- public void mouseOut(Component component) {
- }
-
- public boolean mouseDown(Component component, Mouse.Button button,
int x, int y) {
- return false;
- }
-
- public boolean mouseUp(Component component, Mouse.Button button,
int x, int y) {
- if (shadow != null) {
- SplitPane splitPane =
(SplitPane)TerraSplitPaneSkin.this.getComponent();
-
- // Update the split location and remove the shadow
- int splitLocation;
- if (splitPane.getOrientation() == Orientation.HORIZONTAL) {
- splitLocation = shadow.getX();
- } else {
- splitLocation = shadow.getY();
- }
-
- splitPane.setSplitLocation(splitLocation);
-
- splitPane.remove(shadow);
- shadow = null;
- }
-
- assert (component instanceof Display);
- component.getComponentMouseListeners().remove(this);
- component.getComponentMouseButtonListeners().remove(this);
-
- return false;
- }
-
- public boolean mouseClick(Component component, Mouse.Button
button, int x, int y, int count) {
- return false;
- }
+ public SplitterSkin(){
+ super();
}
- private int dragOffset;
- private SplitterShadow shadow = null;
- private DragHandler dragHandler = new DragHandler();
-
- @Override
- public boolean isFocusable() {
- return false;
- }
-
- public int getPreferredWidth(int height) {
- // This will never get called since the size of the splitter is set
- // automatically by SplitPaneSkin using the the size of the
- // SplitPane and the split thickness
- return 0;
- }
-
- public int getPreferredHeight(int width) {
- // This will never get called since the size of the splitter is set
- // automatically by SplitPaneSkin using the the size of the
- // SplitPane and the split thickness
- return 0;
- }
-
- public void layout() {
- // No-op
- }
-
public void paint(Graphics2D graphics) {
SplitPane splitPane =
(SplitPane)TerraSplitPaneSkin.this.getComponent();
@@ -245,130 +121,21 @@
}
}
}
-
- @Override
- public boolean mouseDown(Component component, Mouse.Button button, int
x, int y) {
- boolean consumed = super.mouseDown(component, button, x, y);
-
- Splitter splitter = (Splitter)getComponent();
- SplitPane splitPane =
(SplitPane)TerraSplitPaneSkin.this.getComponent();
-
- Orientation orientation = splitPane.getOrientation();
-
- if (!splitPane.isLocked()) {
- int splitLocation = splitPane.getSplitLocation();
-
- Display display = splitPane.getDisplay();
- Point displayCoordinates =
splitter.mapPointToAncestor(display, x, y);
-
- if (orientation == Orientation.HORIZONTAL) {
- dragOffset = displayCoordinates.x - splitLocation;
- } else {
- dragOffset = displayCoordinates.y - splitLocation;
- }
-
- if (useShadow) {
- shadow = new SplitterShadow();
- splitPane.add(shadow);
-
- if (orientation == Orientation.HORIZONTAL) {
- shadow.setLocation(splitter.getX(), 0);
- } else {
- shadow.setLocation(0, splitter.getY());
- }
- shadow.setSize(getWidth(), getHeight());
- }
-
- display.getComponentMouseListeners().add(dragHandler);
- display.getComponentMouseButtonListeners().add(dragHandler);
- }
-
- return consumed;
- }
-
- private int boundSplitLocation(int splitLocation) {
- SplitPane splitPane =
(SplitPane)TerraSplitPaneSkin.this.getComponent();
-
- int lower = 0;
- int upper;
- if (splitPane.getOrientation() == Orientation.HORIZONTAL) {
- upper = splitPane.getWidth() - splitterThickness;
- } else {
- upper = splitPane.getHeight() - splitterThickness;
- }
-
- Span bounds = splitPane.getSplitBounds();
- if (bounds != null) {
- lower = Math.max(lower, bounds.getStart());
- upper = Math.min(upper, bounds.getEnd());
- }
-
- if (splitLocation < lower) {
- splitLocation = lower;
- } else if (splitLocation > upper) {
- splitLocation = upper;
- }
-
- return splitLocation;
- }
}
- /**
- * Split pane splitter shadow component.
- *
- * @author tvolkert
- */
- protected class SplitterShadow extends Component {
- public SplitterShadow() {
- super();
- setSkin(new SplitterShadowSkin());
- }
- }
-
- /**
- * Split pane splitter shadow component skin.
- *
- * @author tvolkert
- */
- protected class SplitterShadowSkin extends ComponentSkin {
- public int getPreferredWidth(int height) {
- // This will never get called since the splitter will always just
- // set the size of its shadow to match its own size
- return 0;
- }
-
- public int getPreferredHeight(int width) {
- // This will never get called since the splitter will always just
- // set the size of its shadow to match its own size
- return 0;
- }
-
- public void layout() {
- // No-op
- }
-
- public void paint(Graphics2D graphics) {
- graphics.setStroke(new BasicStroke());
- graphics.setPaint(new Color(0, 0, 0, 64));
- graphics.fillRect(0, 0, getWidth(), getHeight());
- }
- }
-
private Splitter splitter = new Splitter();
private Color splitterHandlePrimaryColor;
private Color splitterHandleSecondaryColor;
- private int splitterThickness;
- private boolean useShadow;
public TerraSplitPaneSkin() {
+ super();
TerraTheme theme = (TerraTheme)Theme.getTheme();
splitterHandlePrimaryColor = theme.getColor(9);
splitterHandleSecondaryColor = theme.getColor(10);
- splitterThickness = 6;
- useShadow = false;
}
+
@Override
public void install(Component component) {
super.install(component);
@@ -390,61 +157,11 @@
super.uninstall();
}
- @Override
- public int getPreferredWidth(int height) {
- return 0;
+ protected void resizeSplitter(int x, int y, int w, int h){
+ this.splitter.setLocation(x, y);
+ this.splitter.setSize(w, h);
}
- @Override
- public int getPreferredHeight(int width) {
- return 0;
- }
-
- @Override
- public Dimensions getPreferredSize() {
- return new Dimensions(0, 0);
- }
-
- public void layout() {
- int width = getWidth();
- int height = getHeight();
-
- SplitPane splitPane = (SplitPane)getComponent();
- int splitLocation = splitPane.getSplitLocation();
- Component leftComponent = splitPane.getTopLeftComponent();
- Component rightComponent = splitPane.getBottomRightComponent();
-
- int rightStart = splitLocation + splitterThickness;
-
- if (splitPane.getOrientation() == Orientation.HORIZONTAL) {
- splitter.setLocation(splitLocation, 0);
- splitter.setSize(splitterThickness, height);
-
- if (leftComponent != null) {
- leftComponent.setLocation(0, 0);
- leftComponent.setSize(splitLocation, height);
- }
-
- if (rightComponent != null) {
- rightComponent.setLocation(rightStart, 0);
- rightComponent.setSize(Math.max(width - rightStart, 0),
height);
- }
- } else {
- splitter.setLocation(0, splitLocation);
- splitter.setSize(width, splitterThickness);
-
- if (leftComponent != null) {
- leftComponent.setLocation(0, 0);
- leftComponent.setSize(width, splitLocation);
- }
-
- if (rightComponent != null) {
- rightComponent.setLocation(0, rightStart);
- rightComponent.setSize(width, Math.max(height - rightStart,
0));
- }
- }
- }
-
public Color getSplitterHandlePrimaryColor() {
return splitterHandlePrimaryColor;
}
@@ -487,57 +204,18 @@
setSplitterHandleSecondaryColor(decodeColor(splitterHandleSecondaryColor));
}
- public int getSplitterThickness() {
- return splitterThickness;
- }
-
- public void setSplitterThickness(int splitterThickness) {
- this.splitterThickness = splitterThickness;
- invalidateComponent();
- }
-
- public final void setSplitterThickness(String splitterThickness) {
- if (splitterThickness == null) {
- throw new IllegalArgumentException("splitterThickness is null.");
- }
-
- setSplitterThickness(Integer.parseInt(splitterThickness));
- }
-
- public boolean getUseShadow() {
- return useShadow;
- }
-
- public void setUseShadow(boolean useShadow) {
- this.useShadow = useShadow;
- }
-
- public void topLeftComponentChanged(SplitPane splitPane, Component
previousTopLeftComponent) {
- // No-op
- }
-
- public void bottomRightComponentChanged(SplitPane splitPane, Component
previousBottomRightComponent) {
- // No-op
- }
-
public void orientationChanged(SplitPane splitPane) {
splitter.updateCursor();
- invalidateComponent();
+ super.orientationChanged(splitPane);
}
public void primaryRegionChanged(SplitPane splitPane) {
splitter.updateCursor();
+ super.primaryRegionChanged(splitPane);
}
- public void splitLocationChanged(SplitPane splitPane, int
previousSplitLocation) {
- invalidateComponent();
- }
-
- public void splitBoundsChanged(SplitPane splitPane, Span
previousSplitBounds) {
- invalidateComponent();
- }
-
public void lockedChanged(SplitPane splitPane) {
splitter.updateCursor();
+ super.lockedChanged(splitPane);
}
}