Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Small improvements in SmartPresentation.

  • Loading branch information...
commit cbb33a2f791c013fadb7d5bcc985bedf7ae8707b 1 parent 50c3436
@marlonrichert authored
Showing with 33 additions and 8 deletions.
  1. +33 −8 src/org/vaadin/jefferson/presentation/SmartPresentation.java
View
41 src/org/vaadin/jefferson/presentation/SmartPresentation.java
@@ -22,6 +22,8 @@
import com.vaadin.ui.VerticalSplitPanel;
public class SmartPresentation extends Presentation {
+ private static final double GOLDEN_RATIO = 1.61803399;
+
public enum Orientation {
HORIZONTAL, VERTICAL,
}
@@ -39,16 +41,40 @@ protected void render(Composite<ComponentContainer> view) {
protected void style(Composite<?> view) {
ComponentContainer rendition = getRendition(view);
+ View<?>[] children = view.getChildren();
if (rendition instanceof AbstractSplitPanel) {
- ((AbstractSplitPanel) rendition).setSplitPosition(50);
+ double weightA = 1;
+ double weightB = 1;
+ if (rendition instanceof HorizontalSplitPanel) {
+ if (containsTable(children[0])) {
+ weightA = GOLDEN_RATIO;
+ }
+ if (containsTable(children[1])) {
+ weightB = GOLDEN_RATIO;
+ }
+ }
+ ((AbstractSplitPanel) rendition).setSplitPosition(
+ (int) (100 * weightA / (weightA + weightB)));
}
if (!stretches(view)) {
- View<?>[] children = view.getChildren();
expand(getRendition(children[children.length - 1]));
}
style((View<?>) view);
}
+ private boolean containsTable(View<?> view) {
+ if (!(view instanceof Composite<?>)) {
+ return getRendition(view) instanceof Table;
+ }
+ Composite<?> composite = (Composite<?>) view;
+ for (View<?> child : composite.getChildren()) {
+ if (containsTable(child)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
@Override
protected void style(View<?> view) {
Component rendition = getRendition(view);
@@ -123,12 +149,11 @@ private boolean stretches(View<?> view) {
call(MethodName.RENDER, view);
rendition = getRendition(view);
}
- Class<? extends Component> cls = rendition.getClass();
- return Form.class.isAssignableFrom(cls)
- || ListSelect.class.isAssignableFrom(cls)
- || TwinColSelect.class.isAssignableFrom(cls)
- || Table.class.isAssignableFrom(cls)
- || Tree.class.isAssignableFrom(cls);
+ return rendition instanceof Form
+ || rendition instanceof ListSelect
+ || rendition instanceof TwinColSelect
+ || rendition instanceof Table
+ || rendition instanceof Tree;
}
private Orientation getOrientation(View<?> view) {
Please sign in to comment.
Something went wrong with that request. Please try again.