1 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 ; 23 24 import org.quickserver.util.TextFile; 25 import org.quickserver.swing.JFrameUtilities; 26 import java.util.logging.*; 27 28 33 public class HeaderPanel extends JPanel { 34 private static Logger logger = 35 Logger.getLogger(HeaderPanel.class.getName()); 36 private ClassLoader 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 statusTxt1 = "<html><font style=\"font-size:10pt;color:#535353\"><b> Status : "; 51 private String statusTxt2 = "</b></font>"; 52 private String statusMsg = "Not Connected"; 53 private GridBagConstraints gbc; 54 55 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 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 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 msg) { 139 statusMsg = msg; 140 status.setText(statusTxt1+statusMsg+statusTxt2); 141 } 142 143 public String 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 performer = new Thread (new Runnable () { 164 public void run() { 165 String 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 handleLoginLogout(); 175 } 176 } catch(Exception ex) { 177 logger.warning("Error logging in : "+ex); 178 setLoginText(); 179 } 180 } 181 }, "QsAdminGUI-LoginThread"); 182 performer.start(); 183 } 184 } else { 185 Thread performer = new Thread (new Runnable () { 186 public void run() { 187 try { 188 qsadminMain.doLogout(); 189 setLoginText(); 190 } catch(Exception ex) { 191 logger.warning("Error logging in : "+ex); 192 } 193 } 194 }, "QsAdminGUI-LogoutThread"); 195 performer.start(); 196 } 197 } 198 } 199 200 | Popular Tags |