Subversion Repository Public Repository

litesoft

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package com.temp.foundation.client.widget;

import com.google.gwt.dom.client.*;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.*;

/**
 * LeftRightSiblings is basically a Single Pixel Transparent Image that is used
 * to trigger behavior on attach to force it's Siblings to the Left and Right
 * respectively in a horizontal single row Panel.
 *
 * @author georgs
 */
public class LeftRightSiblings extends TransparentImage {

    private boolean shouldVerticallyCenter;

    public LeftRightSiblings( boolean shouldVerticallyCenter ) {
        this.shouldVerticallyCenter = shouldVerticallyCenter;
    }

    public LeftRightSiblings() {
        this( true );
    }

    @Override
    protected void onAttach() {
        super.onAttach();
        if ( !(getParent() instanceof HorizontalPanel) ) {
            throw new IllegalArgumentException( "LeftRightSiblings may only be used as a direct child of a HorizontalPanel!" );
        }
        HorizontalPanel parent = (HorizontalPanel) getParent();
        Widget left = null;
        Widget right = null;
        int ourIndex = parent.getWidgetIndex( this );
        switch ( parent.getWidgetCount() ) {
            case 1:
                throw new IllegalArgumentException( "LeftRightSiblings has NO Siblings!" );
            case 3:
                if ( ourIndex != 1 ) {
                    throw new IllegalArgumentException( "LeftRightSiblings is NOT the Center Widget!" );
                }
                left = parent.getWidget( 0 );
                right = parent.getWidget( 2 );
                break;
            case 2:
                if ( ourIndex == 1 ) {
                    left = parent.getWidget( 0 );
                } else {
                    right = parent.getWidget( 1 );
                }
                break;
            default:
                throw new IllegalArgumentException( "LeftRightSiblings has more than 2 Siblings!" );
        }
        TableElement element = getTableElement( parent.getElement() );
        setBorder( element, 0 );
        setCellPadding( element, 0 );
        setCellSpacing( element, 0 );
        setWidth( element, "100%" );
        setTD( left, "left" );
        setTD( right, "right" );

        // <table border=0 cellpadding=0 cellspacing=0 width='100%'><tr>
        // <td align='left' valign='middle'>widget</td>
        // <td align='right' valign='middle'>widget</td>
        // </tr></table>
    }

    private void setTD( Widget widget, String align ) {
        if ( widget != null ) {
            TableCellElement element = getTDElement( widget.getElement().getParentElement() );
            if ( shouldVerticallyCenter ) {
                setVAlign( element, "middle" );
            }
            element.setAlign( align );
        }
    }

    protected TableElement getTableElement( Element element ) {
        return element.cast();
    }

    protected TableCellElement getTDElement( com.google.gwt.dom.client.Element element ) {
        return element.cast();
    }

    protected void setBorder( TableElement tableElement, int width ) {
        tableElement.setBorder( width );
    }

    protected void setCellPadding( TableElement tableElement, int width ) {
        tableElement.setCellPadding( width );
    }

    protected void setCellSpacing( TableElement tableElement, int width ) {
        tableElement.setCellSpacing( width );
    }

    protected void setWidth( TableElement tableElement, String width ) {
        tableElement.setWidth( width );
    }

    protected void setVAlign( TableCellElement tableCellElement, String vAlign ) {
        tableCellElement.setVAlign( vAlign );
    }
}

Commits for litesoft/trunk/GWT_Sandbox/FormEngine/src/com/temp/foundation/client/widget/LeftRightSiblings.java

Diff revisions: vs.
Revision Author Commited Message
965 GeorgeS picture GeorgeS Fri 01 Aug, 2014 03:20:35 +0000

!