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   package org.directdemocracyportal.democracy.web.views.header;
6   
7   import org.directdemocracyportal.democracy.model.application.User;
8   import org.directdemocracyportal.democracy.web.ApplicationMessageHolder;
9   import org.directdemocracyportal.democracy.web.BeanLocator;
10  import org.directdemocracyportal.democracy.web.ImageConstants;
11  import org.directdemocracyportal.democracy.web.ApplicationMessageHolder.MessageConstans;
12  import org.directdemocracyportal.democracy.web.action.LogoutAction;
13  import org.directdemocracyportal.democracy.web.action.ShowMyProfileAction;
14  
15  import thinwire.ui.Button;
16  import thinwire.ui.Label;
17  import thinwire.ui.Panel;
18  import thinwire.ui.layout.TableLayout;
19  import thinwire.ui.style.Color;
20  
21  /***
22   * The Class UserPanel.
23   */
24  public class UserPanel extends Panel
25  {
26  
27      /***
28       * Instantiates a new user panel.
29       *
30       * @param user the user
31       */
32      public UserPanel(User user) {
33          super();
34          getStyle().getBackground().setColor(Color.valueOf("rgb(0,51,153)"));
35          setLayout(new TableLayout(new double[][] { { 0, 0, 0 }, // Column Widths
36                  { 0 } }, // Row Heights
37                  1, // Margin around edge of container
38                  5)); // Spacing between cells
39  
40          Label label = new Label(ApplicationMessageHolder
41                  .getMessage(MessageConstans.WELCOME) + user.getUsername());
42          label.setLimit("0,0");
43          getChildren().add(label);
44  
45          Button profileButton = new Button();
46          profileButton.setImage(ImageConstants.USER_HOME_ICON);
47          profileButton.setText(ApplicationMessageHolder
48                  .getMessage(MessageConstans.BUTTON_MY_PROFILE));
49          profileButton.setSize(90, 30);
50          profileButton.setLimit("1,0,c,c");
51          profileButton.setUserObject(new ShowMyProfileAction());
52          profileButton.addActionListener(ACTION_CLICK, BeanLocator
53                  .getApplicationActionListener());
54          getChildren().add(profileButton);
55  
56          Button logoutButton = new Button();
57          logoutButton.setText(ApplicationMessageHolder
58                  .getMessage(MessageConstans.BUTTON_LOGOUT));
59          logoutButton.setUserObject(new LogoutAction());
60          logoutButton.addActionListener(ACTION_CLICK, BeanLocator
61                  .getApplicationActionListener());
62          logoutButton.setSize(90, 30);
63          logoutButton.setLimit("2,0,c,c");
64          getChildren().add(logoutButton);
65      }
66  }