KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > quickserver > net > qsadmin > gui > HeaderPanel


1 /*
2  * This file is part of the QuickServer library
3  * Copyright (C) 2003-2005 QuickServer.org
4  *
5  * Use, modification, copying and distribution of this software is subject to
6  * the terms and conditions of the GNU Lesser General Public License.
7  * You should have received a copy of the GNU LGP License along with this
8  * library; if not, you can download a copy from <http://www.quickserver.org/>.
9  *
10  * For questions, suggestions, bug-reports, enhancement-requests etc.
11  * visit http://www.quickserver.org
12  *
13  */

14
15 package org.quickserver.net.qsadmin.gui;
16
17 import java.awt.*;
18 import java.awt.event.*;
19 import javax.swing.*;
20 import javax.swing.event.*;
21 import javax.swing.border.*;
22 import java.io.IOException JavaDoc;
23
24 import org.quickserver.util.TextFile;
25 import org.quickserver.swing.JFrameUtilities;
26 import java.util.logging.*;
27
28 /**
29  * Control Panel - Header for
30  * QuickServer Admin GUI - QSAdminGUI
31  * @author Akshathkumar Shetty
32  */

33 public class HeaderPanel extends JPanel /*JFrame*/{
34     private static Logger logger =
35             Logger.getLogger(HeaderPanel.class.getName());
36     private ClassLoader JavaDoc classLoader = getClass().getClassLoader();
37     public ImageIcon logo = new ImageIcon(
38         classLoader.getResource("icons/logo.gif"));
39     public ImageIcon logoAbout = new ImageIcon(
40         classLoader.getResource("icons/logo.png"));
41
42     private JLabel logoLabel;
43     private JPanel leftPanel;
44     private JPanel rightPanel;
45
46     private JLabel productName;
47     private JLabel status;
48     private JButton login;
49
50     private String JavaDoc statusTxt1 = "<html><font style=\"font-size:10pt;color:#535353\"><b> Status : ";
51     private String JavaDoc statusTxt2 = "</b></font>";
52     private String JavaDoc statusMsg = "Not Connected";
53     private GridBagConstraints gbc;
54
55     //--
56
private LoginDialog loginDialog;
57     private final JFrame parentFrame;
58     private QSAdminMain qsadminMain;
59
60     public HeaderPanel(QSAdminMain qsadminMain, JFrame parentFrame) {
61         this.parentFrame = parentFrame;
62         this.qsadminMain = qsadminMain;
63
64         gbc = new GridBagConstraints();
65         logoLabel = new JLabel(logoAbout, JLabel.CENTER);
66         productName = new JLabel("<html><font "+
67             "style=\"font-size:20pt;color:#535353\">"+
68             " <b>QSAdmin GUI</b></font>",JLabel.LEFT);
69         status = new JLabel(statusTxt1+statusMsg+statusTxt2);
70         login = new JButton("<html><font style=\"font-size:10pt;color:#535353\">"+
71             "<b>Login</b>"+"</font>");
72         login.setMnemonic('L');
73         
74         Container cp = this;
75
76         login.addActionListener( new ActionListener() {
77             public void actionPerformed(ActionEvent e) {
78                 handleLoginLogout();
79             }
80         });
81
82         //--- Left Panel
83
leftPanel = new JPanel();
84         leftPanel.setLayout(new GridBagLayout());
85         gbc.insets = new Insets( 2, 2, 2, 2 );
86         gbc.weighty = 0.0;
87         gbc.weightx = 0.0;
88         gbc.gridx = 0;
89         gbc.gridy = 0;
90         gbc.gridheight = 1;
91         gbc.gridwidth = 1;
92         gbc.anchor = GridBagConstraints.WEST;
93         gbc.fill = GridBagConstraints.NONE;
94         leftPanel.add(productName, gbc);
95
96         gbc.gridx = 0;
97         gbc.gridy = 1;
98         gbc.weightx = 0.7;
99         gbc.weighty = 0.7;
100         gbc.gridheight = 1;
101         gbc.anchor = GridBagConstraints.EAST;
102         gbc.fill = GridBagConstraints.BOTH;
103         leftPanel.add(status, gbc);
104
105
106     
107         
108         //--- Right Panel
109
rightPanel = new JPanel();
110         rightPanel.setLayout(new GridBagLayout());
111         gbc.insets = new Insets( 0, 0, 0, 0 );
112         gbc.weighty = 0.0;
113         gbc.weightx = 0.0;
114         gbc.gridx = 0;
115         gbc.gridy = 0;
116         gbc.gridheight = 1;
117         gbc.gridwidth = 1;
118         gbc.anchor = GridBagConstraints.CENTER;
119         gbc.fill = GridBagConstraints.NONE;
120         rightPanel.add(logoLabel, gbc);
121
122         gbc.gridy = 1;
123         gbc.gridx = 0;
124         gbc.weightx = 0.8;
125         gbc.weighty = 0.8;
126         gbc.gridheight = 1;
127         gbc.gridwidth = 1;
128         gbc.insets = new Insets( 1, 1, 1, 1 );
129         gbc.anchor = GridBagConstraints.CENTER;
130         gbc.fill = GridBagConstraints.BOTH;
131         rightPanel.add(login, gbc);
132
133         cp.setLayout(new BorderLayout(0,10));
134         cp.add(rightPanel,BorderLayout.EAST);
135         cp.add(leftPanel,BorderLayout.CENTER);
136     }
137
138     public void setStatus(String JavaDoc msg) {
139         statusMsg = msg;
140         status.setText(statusTxt1+statusMsg+statusTxt2);
141     }
142
143     public String JavaDoc getStatus() {
144         return statusMsg;
145     }
146
147     public void setLoginText() {
148         login.setText("<html><font style=\"font-size:10pt;color:#535353\">"+
149             "<b>Login</b>"+"</font>");
150     }
151     public void setLogoutText() {
152         login.setText("<html><font style=\"font-size:10pt;color:#535353\">"+
153             "<b>Logout</b>"+"</font>");
154     }
155
156     public void handleLoginLogout() {
157         if(qsadminMain.isConnected()==false) {
158             if(loginDialog==null) {
159                 loginDialog = new LoginDialog(parentFrame);
160             }
161             loginDialog.show();
162             if(loginDialog.isOk()==true) {
163                 Thread JavaDoc performer = new Thread JavaDoc(new Runnable JavaDoc() {
164                     public void run() {
165                         String JavaDoc r[] = loginDialog.getValues();
166                         try {
167                             boolean flag = qsadminMain.doLogin(r[0],
168                                 Integer.parseInt(r[1]), r[2], r[3]);
169                             if(flag==true) {
170                                 setLogoutText();
171                             } else {
172                                 setLoginText();
173                                 //recall the login dialog
174
handleLoginLogout();
175                             }
176                         } catch(Exception JavaDoc ex) {
177                             logger.warning("Error logging in : "+ex);
178                             setLoginText();
179                         }
180                     }
181                 }, "QsAdminGUI-LoginThread");
182                 performer.start();
183             }
184         } else {
185             Thread JavaDoc performer = new Thread JavaDoc(new Runnable JavaDoc() {
186                 public void run() {
187                     try {
188                         qsadminMain.doLogout();
189                         setLoginText();
190                     } catch(Exception JavaDoc ex) {
191                         logger.warning("Error logging in : "+ex);
192                     }
193                 }
194             }, "QsAdminGUI-LogoutThread");
195             performer.start();
196         }
197     }
198 }
199
200
Popular Tags