001: /*
002: * This file is part of the QuickServer library
003: * Copyright (C) 2003-2005 QuickServer.org
004: *
005: * Use, modification, copying and distribution of this software is subject to
006: * the terms and conditions of the GNU Lesser General Public License.
007: * You should have received a copy of the GNU LGP License along with this
008: * library; if not, you can download a copy from <http://www.quickserver.org/>.
009: *
010: * For questions, suggestions, bug-reports, enhancement-requests etc.
011: * visit http://www.quickserver.org
012: *
013: */
014:
015: package org.quickserver.net.qsadmin.gui;
016:
017: import java.awt.*;
018: import java.awt.event.*;
019: import javax.swing.*;
020: import javax.swing.event.*;
021: import javax.swing.border.*;
022: import java.io.IOException;
023:
024: import org.quickserver.util.TextFile;
025: import org.quickserver.swing.JFrameUtilities;
026: import java.util.logging.*;
027:
028: /**
029: * Control Panel - Header for
030: * QuickServer Admin GUI - QSAdminGUI
031: * @author Akshathkumar Shetty
032: */
033: public class HeaderPanel extends JPanel /*JFrame*/{
034: private static Logger logger = Logger.getLogger(HeaderPanel.class
035: .getName());
036: private ClassLoader classLoader = getClass().getClassLoader();
037: public ImageIcon logo = new ImageIcon(classLoader
038: .getResource("icons/logo.gif"));
039: public ImageIcon logoAbout = new ImageIcon(classLoader
040: .getResource("icons/logo.png"));
041:
042: private JLabel logoLabel;
043: private JPanel leftPanel;
044: private JPanel rightPanel;
045:
046: private JLabel productName;
047: private JLabel status;
048: private JButton login;
049:
050: private String statusTxt1 = "<html><font style=\"font-size:10pt;color:#535353\"><b> Status : ";
051: private String statusTxt2 = "</b></font>";
052: private String statusMsg = "Not Connected";
053: private GridBagConstraints gbc;
054:
055: //--
056: private LoginDialog loginDialog;
057: private final JFrame parentFrame;
058: private QSAdminMain qsadminMain;
059:
060: public HeaderPanel(QSAdminMain qsadminMain, JFrame parentFrame) {
061: this .parentFrame = parentFrame;
062: this .qsadminMain = qsadminMain;
063:
064: gbc = new GridBagConstraints();
065: logoLabel = new JLabel(logoAbout, JLabel.CENTER);
066: productName = new JLabel("<html><font "
067: + "style=\"font-size:20pt;color:#535353\">"
068: + " <b>QSAdmin GUI</b></font>", JLabel.LEFT);
069: status = new JLabel(statusTxt1 + statusMsg + statusTxt2);
070: login = new JButton(
071: "<html><font style=\"font-size:10pt;color:#535353\">"
072: + "<b>Login</b>" + "</font>");
073: login.setMnemonic('L');
074:
075: Container cp = this ;
076:
077: login.addActionListener(new ActionListener() {
078: public void actionPerformed(ActionEvent e) {
079: handleLoginLogout();
080: }
081: });
082:
083: //--- Left Panel
084: leftPanel = new JPanel();
085: leftPanel.setLayout(new GridBagLayout());
086: gbc.insets = new Insets(2, 2, 2, 2);
087: gbc.weighty = 0.0;
088: gbc.weightx = 0.0;
089: gbc.gridx = 0;
090: gbc.gridy = 0;
091: gbc.gridheight = 1;
092: gbc.gridwidth = 1;
093: gbc.anchor = GridBagConstraints.WEST;
094: gbc.fill = GridBagConstraints.NONE;
095: leftPanel.add(productName, gbc);
096:
097: gbc.gridx = 0;
098: gbc.gridy = 1;
099: gbc.weightx = 0.7;
100: gbc.weighty = 0.7;
101: gbc.gridheight = 1;
102: gbc.anchor = GridBagConstraints.EAST;
103: gbc.fill = GridBagConstraints.BOTH;
104: leftPanel.add(status, gbc);
105:
106: //--- Right Panel
107: rightPanel = new JPanel();
108: rightPanel.setLayout(new GridBagLayout());
109: gbc.insets = new Insets(0, 0, 0, 0);
110: gbc.weighty = 0.0;
111: gbc.weightx = 0.0;
112: gbc.gridx = 0;
113: gbc.gridy = 0;
114: gbc.gridheight = 1;
115: gbc.gridwidth = 1;
116: gbc.anchor = GridBagConstraints.CENTER;
117: gbc.fill = GridBagConstraints.NONE;
118: rightPanel.add(logoLabel, gbc);
119:
120: gbc.gridy = 1;
121: gbc.gridx = 0;
122: gbc.weightx = 0.8;
123: gbc.weighty = 0.8;
124: gbc.gridheight = 1;
125: gbc.gridwidth = 1;
126: gbc.insets = new Insets(1, 1, 1, 1);
127: gbc.anchor = GridBagConstraints.CENTER;
128: gbc.fill = GridBagConstraints.BOTH;
129: rightPanel.add(login, gbc);
130:
131: cp.setLayout(new BorderLayout(0, 10));
132: cp.add(rightPanel, BorderLayout.EAST);
133: cp.add(leftPanel, BorderLayout.CENTER);
134: }
135:
136: public void setStatus(String msg) {
137: statusMsg = msg;
138: status.setText(statusTxt1 + statusMsg + statusTxt2);
139: }
140:
141: public String getStatus() {
142: return statusMsg;
143: }
144:
145: public void setLoginText() {
146: login
147: .setText("<html><font style=\"font-size:10pt;color:#535353\">"
148: + "<b>Login</b>" + "</font>");
149: }
150:
151: public void setLogoutText() {
152: login
153: .setText("<html><font style=\"font-size:10pt;color:#535353\">"
154: + "<b>Logout</b>" + "</font>");
155: }
156:
157: public void handleLoginLogout() {
158: if (qsadminMain.isConnected() == false) {
159: if (loginDialog == null) {
160: loginDialog = new LoginDialog(parentFrame);
161: }
162: loginDialog.show();
163: if (loginDialog.isOk() == true) {
164: Thread performer = new Thread(new Runnable() {
165: public void run() {
166: String r[] = loginDialog.getValues();
167: try {
168: boolean flag = qsadminMain.doLogin(r[0],
169: Integer.parseInt(r[1]), r[2], r[3]);
170: if (flag == true) {
171: setLogoutText();
172: } else {
173: setLoginText();
174: //recall the login dialog
175: handleLoginLogout();
176: }
177: } catch (Exception ex) {
178: logger.warning("Error logging in : " + ex);
179: setLoginText();
180: }
181: }
182: }, "QsAdminGUI-LoginThread");
183: performer.start();
184: }
185: } else {
186: Thread performer = new Thread(new Runnable() {
187: public void run() {
188: try {
189: qsadminMain.doLogout();
190: setLoginText();
191: } catch (Exception ex) {
192: logger.warning("Error logging in : " + ex);
193: }
194: }
195: }, "QsAdminGUI-LogoutThread");
196: performer.start();
197: }
198: }
199: }
|