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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
// 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.nonpublic.*;
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.*;

import java.util.*;

public class TaskbarHelper implements FloatableContainerListener {
    private NEWSposition mPosition;
    private List mFavorites = new ArrayList();
    private List mTasks = new ArrayList();
    private AbstractSizeableOneDimensionalPanel mItemsPanel;
    private PopupPanel mPopup;
    private PopupImage mPopupImage;
    private boolean mIsFavorite = false;
    private TaskbarItem mItem;
    private static final int POPUP_WIDTH = 24;
    private static final int POPUP_HEIGHT = 24;
    private FloaterFactoryFactory mFloaterFactoryFactory;
    protected boolean mContextMenuIsShown = false;
    private Image mSeparator;
    private TaskbarDockingPanel mTaskbarDockingPanel;
    private HashMap mFloaterToTaskbarItemMap = new HashMap();

    public TaskbarHelper( FloaterFactoryFactory pFloaterFactoryFactory ) {
        mFloaterFactoryFactory = pFloaterFactoryFactory;

        mPopup = new PopupPanel( true );
        mPopupImage = new PopupImage();

        mPopupImage.addClickListener( new ClickListener() {
            public void onClick( Widget sender ) {
                mPopupImage.click( sender );
            }
        } );

        mPopupImage.addMouseListener( new MouseListenerAdapter() {
            public void onMouseLeave( Widget sender ) {
                // Element toElement = DOM.eventGetToElement( DOM.eventGetCurrentEvent() );
                if ( !mContextMenuIsShown ) {
                    hidePopup();
                    showTaskbarImage( getLastItem() );
                }
            }
        } );
        mPopup.add( mPopupImage );
        mPopup.setPixelSize( POPUP_WIDTH, POPUP_HEIGHT );
    }

    public TaskbarHelper getTaskbarHelper() {
        return this;
    }

    public void setPosition( NEWSposition pPosition ) {
        mPosition = pPosition;
    }

    public void setTaskbarDockingPanel( TaskbarDockingPanel pTaskbarDockingPanel ) {
        mTaskbarDockingPanel = pTaskbarDockingPanel;
    }

    public TaskbarDockingPanel getTaskbarDockingPanel() {
        return mTaskbarDockingPanel;
    }

    public boolean isFirstFavoriteItem( TaskbarItem pTaskbarItem ) {
        return mFavorites.indexOf( pTaskbarItem ) == 0;
    }

    public boolean isLastFavoriteItem( TaskbarItem pTaskbarItem ) {
        return mFavorites.indexOf( pTaskbarItem ) == (mFavorites.size() - 1);
    }

    public void addToTasks( SizeableFloater pFloater, TaskbarEntry pTaskbarEntry ) {
        TaskbarItem taskbarItem = new TaskbarFloaterItem( this, (TaskbarFloaterEntry) pTaskbarEntry );

        mFloaterToTaskbarItemMap.put( pFloater, taskbarItem );
        mTasks.add( taskbarItem );
        Widget taskbarWidget = taskbarItem.getTaskbarWidget();
        mItemsPanel.add( taskbarWidget );
        mItemsPanel.relayout();
    }

    public void removeFromTasks( SizeableFloater pFloater ) {

        TaskbarItem taskbarItem = (TaskbarItem) mFloaterToTaskbarItemMap.get( pFloater );
        if ( taskbarItem != null ) {
            mTasks.remove( taskbarItem );
            mItemsPanel.remove( taskbarItem.getTaskbarWidget() );
            mItemsPanel.relayout();
        }
        mFloaterToTaskbarItemMap.remove( pFloater );
    }

    public TaskbarItem[] getFavorites() {
        return toArray( mFavorites );
    }

    public TaskbarItem[] getTasks() {
        return toArray( mTasks );
    }

    private TaskbarItem[] toArray( List pList ) {
        TaskbarItem[] rv = new TaskbarItem[pList.size()];
        for ( int i = 0; i < pList.size(); i++ ) {
            rv[i] = (TaskbarItem) pList.get( i );
        }
        return rv;
    }

    public void addTo( AbstractSizeableOneDimensionalPanel pPanel, String pSeparatorURL ) {
        mItemsPanel = pPanel;
        TaskbarItem[] items = getFavorites();
        for ( int i = 0; i < items.length; i++ ) {
            pPanel.add( items[i].getTaskbarWidget() );
        }

        mSeparator = new Image( pSeparatorURL );
        pPanel.add( mSeparator );

        items = getTasks();
        for ( int i = 0; i < items.length; i++ ) {
            pPanel.add( items[i].getTaskbarWidget() );
        }
    }

    public void bringToFront( TaskbarItem pItem ) {
        pItem.bringToFront();
    }

    public void manageFloater( TaskbarItem pItem ) {
        pItem.manageFloater();
    }

    public void updateFavoritesDisplay( List pFavorites ) {
        mFavorites.clear();

        for ( int j = 0; j < (pFavorites.size()); j++ ) {
            mFavorites.add( new TaskbarFavoriteItem( this, (TaskbarFavoriteEntry) pFavorites.get( j ) ) );
        }

        if ( mItemsPanel != null ) {
            int separatorIndex = mItemsPanel.getWidgetIndex( mSeparator );
            for ( int i = separatorIndex - 1; i >= 0; i-- ) {
                mItemsPanel.remove( i );
            }

            for ( int j = 0; j < (mFavorites.size()); j++ ) {
                TaskbarItem item = (TaskbarItem) mFavorites.get( j );
                mItemsPanel.insert( item.getTaskbarWidget(), mItemsPanel.getWidgetIndex( mSeparator ) );
            }
            mItemsPanel.relayout();
        }
    }

    public boolean isPositionHorizontal() {
        return mPosition.isNorthOrSouth();
    }

    private TaskbarItem mLastItem = null;

    public TaskbarItem getLastItem() {
        return mLastItem;
    }

    public void showPopup( TaskbarItem pItem ) {
        showTaskbarImage( getLastItem() );
        mLastItem = pItem;
        mPopup.hide();
        mPopupImage.setUrl( pItem.getLargeURL() );
        mPopupImage.setTitle( pItem.getTooltip() );

        int newLeft;
        int newTop;
        Widget widget = pItem.getTaskbarWidget();
        int zWidthDiff = POPUP_WIDTH - widget.getOffsetWidth();
        int zHeightDiff = POPUP_HEIGHT - widget.getOffsetHeight();

        if ( isPositionHorizontal() ) {
            newLeft = widget.getAbsoluteLeft() - (zWidthDiff / 2);

            if ( (widget.getAbsoluteTop() + POPUP_HEIGHT) > (Window.getClientHeight() - 9) ) {
                newTop = widget.getAbsoluteTop() - (POPUP_HEIGHT - widget.getOffsetHeight());
            } else {
                newTop = widget.getAbsoluteTop();
            }
        } else {
            newTop = widget.getAbsoluteTop() - (zHeightDiff / 2);

            if ( (widget.getAbsoluteLeft() + POPUP_WIDTH) > (Window.getClientWidth() - 9) ) {
                newLeft = widget.getAbsoluteLeft() - (POPUP_WIDTH - widget.getOffsetWidth());
            } else {
                newLeft = widget.getAbsoluteLeft();
            }
        }

        mPopup.setPopupPosition( newLeft, newTop );
        mPopup.show();
        hideTaskbarImage( pItem );
    }

    private void hideTaskbarImage( TaskbarItem pItem ) {
        DOM.setStyleAttribute( pItem.getTaskbarWidget().getElement(), "visibility", "hidden" );
    }

    private void showTaskbarImage() {
        if ( mItem != null ) {
            DOM.setStyleAttribute( mItem.getTaskbarWidget().getElement(), "visibility", "visible" );
        }
    }

    private void showTaskbarImage( TaskbarItem pItem ) {
        if ( pItem != null ) {
            DOM.setStyleAttribute( pItem.getTaskbarWidget().getElement(), "visibility", "visible" );
        }
    }

    public void hidePopup() {
        mPopup.hide();
        teardownForPopup();
    }

    public void setupForPopup( boolean pFavorite, TaskbarItem pTaskbarItem ) {
        mIsFavorite = pFavorite;
        mItem = pTaskbarItem;
    }

    private void teardownForPopup() {
        mIsFavorite = false;
        mItem = null;
        mPopupImage.setUrl( "common/images/misc/TransparentSpacer.gif" );
    }

    public void floaterAdded( SizeableFloater pFloater ) {
        if ( pFloater instanceof ITaskbarFloaterManageable ) {
            addToTasks( pFloater, new TaskbarFloaterEntry( (ITaskbarFloaterManageable) pFloater ) );
        }
    }

    public void floaterRemoved( SizeableFloater pFloater ) {
        removeFromTasks( pFloater );
    }

    public void setActive( SizeableFloater pFloater ) {
        BackgroundCellForTaskbarItem widgetForFloater =
                (BackgroundCellForTaskbarItem) getTaskbarWidgetForFloater( pFloater );
        if ( widgetForFloater != null ) {
            widgetForFloater.setActiveStyle();
        }
    }

    public void clearActive( SizeableFloater pFloater ) {
        BackgroundCellForTaskbarItem widgetForFloater =
                (BackgroundCellForTaskbarItem) getTaskbarWidgetForFloater( pFloater );
        if ( widgetForFloater != null ) {
            widgetForFloater.setRegularStyle();
        }
    }

    private Widget getTaskbarWidgetForFloater( SizeableFloater pFloater ) {
        TaskbarItem zTaskbarItem = (TaskbarItem) mFloaterToTaskbarItemMap.get( pFloater );
        if ( zTaskbarItem != null ) {
            return zTaskbarItem.getTaskbarWidget();
        } else {
            return null;
        }
    }

    public void click( Widget sender ) {
        mPopupImage.click( sender );
    }

    private class PopupImage extends OurImage {
        public void click( Widget sender ) {
            if ( mIsFavorite ) {
                clickFavorite( sender );
            } else {
                clickItem();
            }
        }

        private void clickItem() {
            IFloaterPanelMoveAndSize zFloaterPanel = mItem.getFloaterPanel();
            if ( UtilsGwt.wasAltKeyDownOnCurrentEvent() ) {
                mItem.bringToFront();
                mItem.manageFloater();
                showTaskbarImage();
                hidePopup();
            } else if ( zFloaterPanel.isChromed() ) {
                mItem.bringToFront();
            }
        }

        private void clickFavorite( Widget sender ) {
            if ( !UtilsGwt.wasAltKeyDownOnCurrentEvent() ) {
                mFloaterFactoryFactory.launchFloater( ((TaskbarFavoriteItem) mItem).getFloaterFactoryRef() );
                return;
            }
            FavoritesContextMenu zContextMenu = new FavoritesContextMenu( true, getTaskbarHelper(), mItem );
            zContextMenu.addStyleName( "FavoritesPopupMenu" );
            zContextMenu.showContextMenu( sender.getAbsoluteLeft(), sender.getAbsoluteTop() );
            mContextMenuIsShown = true;
            zContextMenu.addPopupListener( new PopupListener() {
                public void onPopupClosed( PopupPanel sender, boolean autoClosed ) {
                    mContextMenuIsShown = false;
                    showTaskbarImage();
                    hidePopup();
                }
            } );
        }
    }
}

Commits for litesoft/trunk/Java/GWT/OldClient/src/org/litesoft/GWT/client/taskbar/TaskbarHelper.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