View Javadoc

1   /*
2   Copyright 2010 James Pether Sörling Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 
3   	$Id
4   */
5   
6   package com.hack23.cia.web.views.user;
7   
8   import thinwire.ui.Button;
9   import thinwire.ui.Component;
10  import thinwire.ui.Image;
11  import thinwire.ui.Label;
12  import thinwire.ui.Panel;
13  import thinwire.ui.layout.TableLayout;
14  
15  import com.hack23.cia.model.application.dto.common.UserSessionDTO;
16  import com.hack23.cia.model.application.impl.common.Agency;
17  import com.hack23.cia.model.application.impl.user.ExternalUrlActionEvent;
18  import com.hack23.cia.web.action.user.ExternalUrlAction;
19  import com.hack23.cia.web.common.BeanLocator;
20  import com.hack23.cia.web.common.ImageConstants;
21  
22  /***
23   * The Class PositionBarPanel.
24   */
25  public class PositionBarPanel extends Panel {
26  
27      /*** The current action. */
28      private final Label currentAction = new Label();
29  
30      /*** The current page title. */
31      private String currentPageTitle;
32  
33      /*** The current user object. */
34      private Object currentUserObject = null;
35  
36      /*** The last action button. */
37      private final Button lastActionButton = new Button();
38  
39      /***
40       * Instantiates a new position bar panel.
41       *
42       * @param userSessionDTO the user session dto
43       */
44      public PositionBarPanel(final UserSessionDTO userSessionDTO) {
45          super();
46          setLayout(new TableLayout(new double[][] { { 0, 0, 0, 0, 0, 0, 0, 0 }, // Column
47                  // Widths
48                  { 0 } }, // Row Heights
49                  2, // Margin around edge of container
50                  5)); // Spacing between cells
51  
52          final Image openSourceLogo = new Image(ImageConstants.OPEN_SOURCE_LOGO);
53          openSourceLogo.setLimit("0,0,0,0");
54          openSourceLogo.setSize(42, 36);
55  
56          final Label currentActionLabel = new Label(userSessionDTO
57                  .getLanguageResource(Agency.LanguageContentKey.CURRENT_ACTION));
58          currentActionLabel.setWrapText(true);
59          currentActionLabel.setLimit("1,0,1,1"); //$NON-NLS-1$
60  
61          currentAction.setWrapText(true);
62          currentAction.setLimit("2,0,2,1"); //$NON-NLS-1$
63  
64          final Button projectInformation = new Button(userSessionDTO
65                  .getLanguageResource(Agency.LanguageContentKey.PROJECT_INFORMATION));
66          projectInformation.addActionListener(Component.ACTION_CLICK,
67                  BeanLocator.getApplicationActionListener());
68          projectInformation.setUserObject(new ExternalUrlAction(
69                  ExternalUrlActionEvent.Operation.ShowProjectInformation));
70          projectInformation.setLimit("4,0,1,1"); //$NON-NLS-1$
71  
72          final Button projectDonate = new Button();        
73          projectDonate.setImage("http://images.sourceforge.net/images/project-support.jpg");
74          projectDonate.addActionListener(Component.ACTION_CLICK, BeanLocator
75                  .getApplicationActionListener());
76          projectDonate.setUserObject(new ExternalUrlAction(
77                  ExternalUrlActionEvent.Operation.ShowDonateToProject));
78          projectDonate.setLimit("5,0,1,1"); //$NON-NLS-1$
79  
80          final Button wikiLeaks = new Button(userSessionDTO
81                  .getLanguageResource(Agency.LanguageContentKey.WIKILEAKS));
82          wikiLeaks.addActionListener(Component.ACTION_CLICK, BeanLocator
83                  .getApplicationActionListener());
84          wikiLeaks.setUserObject(new ExternalUrlAction(
85                  ExternalUrlActionEvent.Operation.ShowWikiLeaks));
86          wikiLeaks.setLimit("6,0,1,1"); //$NON-NLS-1$
87  
88          lastActionButton.setLimit("7,0,1,1"); //$NON-NLS-1$       
89          lastActionButton.setImage(ImageConstants.GO_PREVIOUS_ICON);
90          lastActionButton.addActionListener(Component.ACTION_CLICK, BeanLocator
91                  .getApplicationActionListener());
92  
93          getChildren().add(openSourceLogo);
94          getChildren().add(currentActionLabel);
95          getChildren().add(currentAction);
96          getChildren().add(projectInformation);
97          getChildren().add(wikiLeaks);
98          getChildren().add(projectDonate);
99          getChildren().add(lastActionButton);
100 
101     }
102 
103     /***
104      * Gets the current action.
105      *
106      * @return the current action
107      */
108     public final Label getCurrentAction() {
109         return currentAction;
110     }
111 
112     /***
113      * Gets the current page title.
114      *
115      * @return the current page title
116      */
117     public final String getCurrentPageTitle() {
118         return currentPageTitle;
119     }
120 
121     /***
122      * Gets the current user object.
123      *
124      * @return the current user object
125      */
126     public final Object getCurrentUserObject() {
127         return currentUserObject;
128     }
129 
130     /***
131      * Gets the last action button.
132      *
133      * @return the last action button
134      */
135     public final Button getLastActionButton() {
136         return lastActionButton;
137     }
138 
139     /***
140      * Sets the current page title.
141      *
142      * @param pageTitle the new current page title
143      */
144     public final void setCurrentPageTitle(final String pageTitle) {
145         currentPageTitle = pageTitle;
146     }
147 
148     /***
149      * Sets the current user object.
150      *
151      * @param currentUserObject the new current user object
152      */
153     public final void setCurrentUserObject(final Object currentUserObject) {
154         this.currentUserObject = currentUserObject;
155     }
156 }