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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
// This Source Code is in the Public Domain per: http://unlicense.org
package org.litesoft.GWT.client.taskbar;

import org.litesoft.GWT.client.*;
import org.litesoft.GWT.client.iconservice.*;
import org.litesoft.GWT.client.widgets.*;
import org.litesoft.GWT.client.widgets.nonpublic.*;

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

public class FavoritesContextMenu extends PopupPanel {
    private boolean isHorizontal;
    Grid mGrid;
    private static final int ADDITIONAL_OFFSET = 22; // 16
    private static final int PADDING = 5;

    public FavoritesContextMenu( boolean autoHide, final TaskbarHelper pHelper,
                                 final TaskbarItem pTaskbarItem ) {
        super( autoHide );

        final boolean isFirstItem = pHelper.isFirstFavoriteItem( pTaskbarItem );
        final boolean isLastItem = pHelper.isLastFavoriteItem( pTaskbarItem );

        isHorizontal = pHelper.isPositionHorizontal();

        if ( isHorizontal ) {
            mGrid = new Grid( 1, 3 );

            if ( isFirstItem ) {
                mGrid.setWidget( 0, 0, new OneCellTable( new Image( "common/images/windowbar/favcontext/arrow_left-Disabled.gif" ) ) );
            } else {
                mGrid.setWidget( 0, 0, new OneCellTable( new Image( "common/images/windowbar/favcontext/arrow_left.gif" ) ) );
            }

            if ( isLastItem ) {
                mGrid.setWidget( 0, 2, new OneCellTable( new Image( "common/images/windowbar/favcontext/arrow_right-Disabled.gif" ) ) );
            } else {
                mGrid.setWidget( 0, 2, new OneCellTable( new Image( "common/images/windowbar/favcontext/arrow_right.gif" ) ) );
            }

            mGrid.setWidget( 0, 1, new OneCellTable( new Image( "images/remove_red.gif" ) ) );

            mGrid.addTableListener( new TableListener() {
                public void onCellClicked( SourcesTableEvents sender, int row, int cell ) {
                    FavoritesManager favoritesManager = FavoritesManager.INSTANCE;
                    switch ( cell ) {
                        case 0:
                            if ( !isFirstItem ) {
                                favoritesManager.moveFavoriteUp( pTaskbarItem );
                            }
                            break;
                        case 1:
                            favoritesManager.removeFavorite( pTaskbarItem );
                            break;
                        case 2:
                            if ( !isLastItem ) {
                                favoritesManager.moveFavoriteDown( pTaskbarItem );
                            }
                            break;
                        default:
                            break;
                    }
                    hide();
                    pHelper.hidePopup();
                }
            } );
        } else {
            mGrid = new Grid( 3, 1 );

            if ( isFirstItem ) {
                mGrid.setWidget( 0, 0, new OneCellTable( new Image( "common/images/windowbar/favcontext/arrow_up-Disabled.gif" ) ) );
            } else {
                mGrid.setWidget( 0, 0, new OneCellTable( new Image( "common/images/windowbar/favcontext/arrow_up.gif" ) ) );
            }

            if ( isLastItem ) {
                mGrid.setWidget( 2, 0, new OneCellTable( new Image( "common/images/windowbar/favcontext/arrow_down-Disabled.gif" ) ) );
            } else {
                mGrid.setWidget( 2, 0, new OneCellTable( new Image( "common/images/windowbar/favcontext/arrow_down.gif" ) ) );
            }

            mGrid.setWidget( 1, 0, new OneCellTable( new Image( "images/remove_red.gif" ) ) );

            mGrid.addTableListener( new TableListener() {
                public void onCellClicked( SourcesTableEvents sender, int row, int cell ) {
                    FavoritesManager favoritesManager = FavoritesManager.INSTANCE;
                    switch ( row ) {
                        case 0:
                            if ( !isFirstItem ) {
                                favoritesManager.moveFavoriteUp( pTaskbarItem );
                            }
                            break;
                        case 1:
                            favoritesManager.removeFavorite( pTaskbarItem );
                            break;
                        case 2:
                            if ( !isLastItem ) {
                                favoritesManager.moveFavoriteDown( pTaskbarItem );
                            }
                            break;
                        default:
                            break;
                    }
                    hide();
                    pHelper.hidePopup();
                }
            } );
        }
        add( mGrid );
    }

    public void showContextMenu( final int pSenderAbsoluteLeft, final int pSenderAbsoluteTop ) {
        setPopupPositionAndShow( new PopupPanel.PositionCallback() {
            public void setPosition( int offsetWidth, int offsetHeight ) {
                int popupPositionX = 0;
                int popupPositionY = 0;

                int clientWidth = Window.getClientWidth();
                int clientHeight = Window.getClientHeight();

                if ( isHorizontal ) {
                    if ( (pSenderAbsoluteLeft + offsetWidth) > clientWidth ) {
                        popupPositionX = pSenderAbsoluteLeft - offsetWidth;
                    } else {
                        popupPositionX = pSenderAbsoluteLeft;
                    }

                    if ( (pSenderAbsoluteTop + offsetHeight + PADDING) > clientHeight ) {
                        popupPositionY = pSenderAbsoluteTop - offsetHeight;
                    } else {
                        popupPositionY = pSenderAbsoluteTop + ADDITIONAL_OFFSET;
                    }
                } else {
                    if ( (pSenderAbsoluteLeft + offsetWidth + PADDING) > clientWidth ) {
                        popupPositionX = pSenderAbsoluteLeft - offsetWidth;
                    } else {
                        popupPositionX = pSenderAbsoluteLeft + ADDITIONAL_OFFSET;
                    }

                    if ( (pSenderAbsoluteTop + offsetHeight) > clientHeight ) {
                        popupPositionY = pSenderAbsoluteTop - offsetHeight;
                    } else {
                        popupPositionY = pSenderAbsoluteTop;
                    }
                }

                setPopupPosition( popupPositionX, popupPositionY );
            }
        } );
    }

    private class OneCellTable extends TightGrid {
        public OneCellTable( Image pImage ) {
            super( 1, 1 );
            setWidget( 0, 0, pImage );
            DOM.setElementAttribute( getElement(), "width", "22" );
            DOM.setElementAttribute( getElement(), "height", "22" );
            addStyleName( "OneCellTable" );

            setOnBrowserEventListener( Event.MOUSEEVENTS, new OnBrowserEventListener() {
                public boolean onBrowserEvent( Event event ) {
                    switch ( DOM.eventGetType( event ) ) {
                        case Event.ONMOUSEUP:
                            UtilsGwt.eventPreventDefaultAndCancelBubble( event );

                            cleanStyles();
                            addStyleName( "OneCellTable-MouseUp" );
                            break;

                        case Event.ONMOUSEOVER:
                            UtilsGwt.eventPreventDefaultAndCancelBubble( event );

                            cleanStyles();
                            addStyleName( "OneCellTable-MouseOver" );
                            break;

                        case Event.ONMOUSEOUT:
                            UtilsGwt.eventPreventDefaultAndCancelBubble( event );

                            cleanStyles();
                            addStyleName( "OneCellTable-MouseOut" );
                            break;

                        case Event.ONMOUSEDOWN:
                            UtilsGwt.eventPreventDefaultAndCancelBubble( event );

                            cleanStyles();
                            addStyleName( "OneCellTable-MouseDown" );
                            break;

                        case Event.ONMOUSEMOVE:
                        default:
                            break;
                    }
                    return false;
                }
            } );
        }

        private void cleanStyles() {
            removeStyleName( "OneCellTable-MouseUp" );
            removeStyleName( "OneCellTable-MouseOver" );
            removeStyleName( "OneCellTable-MouseOut" );
            removeStyleName( "OneCellTable-MouseDown" );
        }
    }
}

Commits for litesoft/trunk/Java/GWT/OldClient/src/org/litesoft/GWT/client/taskbar/FavoritesContextMenu.java

Diff revisions: vs.
Revision Author Commited Message
950 Diff Diff GeorgeS picture GeorgeS Thu 19 Jun, 2014 17:57:04 +0000

New Lines

948 Diff Diff GeorgeS picture GeorgeS Sat 07 Jun, 2014 23:42:39 +0000

Jusefuls Formatter Updated to New Code Format

947 Diff Diff GeorgeS picture GeorgeS Fri 06 Jun, 2014 23:36:56 +0000

Correct Spelling of package!

447 Diff Diff GeorgeS picture GeorgeS Sat 20 Aug, 2011 21:48:35 +0000
60 Diff Diff GeorgeS picture GeorgeS Tue 24 Aug, 2010 00:37:36 +0000
49 Diff Diff GeorgeS picture GeorgeS Mon 12 Apr, 2010 02:59:10 +0000

License Text

2 GeorgeS picture GeorgeS Sun 07 Feb, 2010 12:50:58 +0000