/* A basic extension of the java.awt.Frame class */ import java.awt.*; import java.io.*; import java.util.*; import java.net.*; import twinfeats.io.*; import twinfeats.conf.core.*; import twinfeats.util.*; import java.awt.event.*; import twinfeats.jar.*; public class LogonWin extends Frame { Profile profile; Comm comm; boolean loggedOn; ClientWin cwin; class HandleConnect implements twinfeats.io.GenericMessageListener { HandleConnect() { } /** * CommMessageListener: A message has been received */ public void message(CommMessageEvent cme) { Status.setText("Logon in progress..."); MsgLogon logon = new MsgLogon(Name.getText(),Password.getText()); logon.setNewUser(New.getState()); logon.setVersion(ClientWin.VERSION); CommMessage msg = new CommMessage(Name.getText(),ConfBean.CONFERENCESERVER,ConfBean.LOGON, logon); comm.send(msg); } } class HandleLogon implements twinfeats.io.GenericMessageListener { HandleLogon() { } /** * CommMessageListener: A message has been received */ public void message(CommMessageEvent cme) { CommMessage cm = cme.getCommMessage(); MsgLogon body = (MsgLogon)cm.getBody(); if (body.isSuccess()) { if (body.isNewUser()) { Status.setText("Password sent to E-Mail!"); Send.setLabel("Close"); cwin.dispose(); cwin = null; comm.stop(); } else { loggedOn = true; hide(); dispose(); MsgConfInProgress[] list = body.getMsgConfInProgress(); if (list != null) cwin.setConfList(list); cwin.show(); } } else { String r = body.getResult(); if (r == null) Status.setText("Error, no explanation given"); else Status.setText(r); cwin.dispose(); cwin = null; comm.stop(); } Name.enable(); Password.enable(); Send.enable(); } } public LogonWin() { // This code is automatically generated by Visual Cafe when you add // components to the visual environment. It instantiates and initializes // the components. To modify the code, only use code syntax that matches // what Visual Cafe can generate, or Visual Cafe may be unable to back // parse your Java file into its visual environment. //{{INIT_CONTROLS setLayout(null); setVisible(false); setSize(insets().left + insets().right + 364,insets().top + insets().bottom + 208); setFont(new Font("SansSerif", Font.PLAIN, 12)); Name = new java.awt.TextField(); Name.setBounds(insets().left + 70,insets().top + 38,209,31); add(Name); Password = new java.awt.TextField(); Password.setBounds(insets().left + 69,insets().top + 75,209,31); add(Password); PasswordLabel = new java.awt.Label("Password"); PasswordLabel.setBounds(insets().left + 5,insets().top + 74,61,31); add(PasswordLabel); Send = new java.awt.Button(); Send.setLabel("Send"); Send.setBounds(insets().left + 132,insets().top + 121,60,40); Send.setBackground(java.awt.Color.lightGray); add(Send); label2 = new java.awt.Label("Name"); label2.setBounds(insets().left + 5,insets().top + 36,61,31); add(label2); label3 = new java.awt.Label("Server"); label3.setBounds(insets().left + 5,insets().top + 1,61,31); add(label3); Server = new java.awt.Choice(); add(Server); Server.setBounds(insets().left + 72,insets().top + 8,206,24); Servers = new java.awt.Button(); Servers.setLabel("Servers..."); Servers.setBounds(insets().left + 289,insets().top + 9,70,25); Servers.setBackground(java.awt.Color.lightGray); add(Servers); Servers.setEnabled(false); New = new java.awt.Checkbox("New User"); New.setBounds(insets().left + 7,insets().top + 113,117,27); add(New); Status = new java.awt.TextField(); Status.setEditable(false); Status.setBounds(insets().left + 13,insets().top + 169,340,32); add(Status); setTitle("TwinFeats Conference Logon"); //}} //{{INIT_MENUS //}} //{{REGISTER_LISTENERS SymWindow aSymWindow = new SymWindow(); this.addWindowListener(aSymWindow); SymAction lSymAction = new SymAction(); Password.addActionListener(lSymAction); Send.addActionListener(lSymAction); SymItem lSymItem = new SymItem(); New.addItemListener(lSymItem); //}} try { profile = new Profile("client.ini",true); profile.parse(); ProfileSection ps = profile.getSection("Servers"); if (ps == null) { ps = new ProfileSection("Servers"); ps.setValue("TwinFeats Conference Center","204.26.80.70:1972"); profile.addSection(ps); profile.write(); } Enumeration e = ps.elements(); ProfileVariable pv; while (e.hasMoreElements()) { pv = (ProfileVariable)e.nextElement(); Server.addItem(pv.getName()); } Server.select(0); } catch (IOException ioe) { ioe.printStackTrace(); System.exit(0); } } public LogonWin(String title) { this(); setTitle(title); } public synchronized void show() { move(50, 50); super.show(); } public void addNotify() { // Record the size of the window prior to calling parents addNotify. Dimension d = getSize(); super.addNotify(); if (fComponentsAdjusted) return; // Adjust components according to the insets setSize(insets().left + insets().right + d.width, insets().top + insets().bottom + d.height); Component components[] = getComponents(); for (int i = 0; i < components.length; i++) { Point p = components[i].getLocation(); p.translate(insets().left, insets().top); components[i].setLocation(p); } fComponentsAdjusted = true; } // Used for addNotify check. boolean fComponentsAdjusted = false; //{{DECLARE_CONTROLS java.awt.TextField Name; java.awt.TextField Password; java.awt.Label PasswordLabel; java.awt.Button Send; java.awt.Label label2; java.awt.Label label3; java.awt.Choice Server; java.awt.Button Servers; java.awt.Checkbox New; java.awt.TextField Status; //}} //{{DECLARE_MENUS //}} class SymWindow extends java.awt.event.WindowAdapter { public void windowClosing(java.awt.event.WindowEvent event) { Object object = event.getSource(); if (object == LogonWin.this) Frame1_WindowClosing(event); } } void Frame1_WindowClosing(java.awt.event.WindowEvent event) { hide(); dispose(); // dispose of the Frame. if (!loggedOn) System.exit(0); } class SymAction implements java.awt.event.ActionListener { public void actionPerformed(java.awt.event.ActionEvent event) { Object object = event.getSource(); if (object == Password) Password_EnterHit(event); else if (object == Send) Send_Action(event); } } void Password_EnterHit(java.awt.event.ActionEvent event) { // to do: code goes here. Send_Action(null); } void Send_Action(java.awt.event.ActionEvent event) { // to do: code goes here. if (Send.getLabel().equals("Close")) { hide(); dispose(); System.exit(0); } String v = profile.getValue("Servers",Server.getSelectedItem()); if (v == null) { Status.setText("Bad client.ini, no servers"); return; } StringTokenizer st = new StringTokenizer(v,":"); if (st.countTokens() != 2) return; String host = st.nextToken(); int port; try { port = Integer.parseInt(st.nextToken()); } catch (NumberFormatException nfe) { Status.setText("Bad client.ini, invalid port"); return; } Name.disable(); Password.disable(); Send.disable(); Status.setText("Connecting to "+host); /* try { ZipLoader zl = new ZipLoader("tfcio.jar"); // zl.loadAll(null); Class c = zl.loadClass("twinfeats.io.Comm",true); comm = (twinfeats.io.Comm)(c.newInstance()); comm.setServerInfo(host,port,Name.getText()); } catch (Exception e) { e.printStackTrace(); } */ comm = new Comm(host,port,Name.getText()); new ReadListener(comm,Name.getText(),Comm.CONNECT,new HandleConnect()); new ReadListener(comm,Name.getText(),ConfBean.LOGON,new HandleLogon()); cwin = new ClientWin(comm); } class SymItem implements java.awt.event.ItemListener { public void itemStateChanged(java.awt.event.ItemEvent event) { Object object = event.getSource(); if (object == New) New_ItemStateChanged(event); } } void New_ItemStateChanged(java.awt.event.ItemEvent event) { // to do: code goes here. if (event.getStateChange() == ItemEvent.SELECTED) { PasswordLabel.setText("E-Mail"); } else PasswordLabel.setText("Password"); } }