Bioinformants - Client.Gui Java - Io.Bufferedreader Java - Io.Inputstreamreader Java - Io.Outputstreamwriter Java - Io.Printwriter
Bioinformants - Client.Gui Java - Io.Bufferedreader Java - Io.Inputstreamreader Java - Io.Outputstreamwriter Java - Io.Printwriter
Bioinformants - Client.Gui Java - Io.Bufferedreader Java - Io.Inputstreamreader Java - Io.Outputstreamwriter Java - Io.Printwriter
* InterBio.java
* -- RELEASE: beta 1.00
* (C)2004 Davila, Jacinto - Vivas, Almathely.
*
* LICENSE
* =======
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
USA.
* More details at http://nux.ula.ve
*
* CHANGES
* =======
*
* Applet interface for Bioinformants. This applet creates the GUI to
* interact with the Bioinformant-server. It allows a user to prepare a
* text to be sent to an agent or an application running on the server
* on his/her behalf. It delivers this text, normally a command, but also
* input data to applications running on a pseudo-term on the side of
* the server. Finally, it catches any output from the applications and
* returns it to the user wrapped in html.
*
* As for version alfa 0.60, a new modality is introduced. The user in
front of
* the browser can send message to other users on other sessions. This
* program will deliver messages among users to the WebApp, where these
* messages will be distributed among their destinations. This will
* be the ChatRoom extension of Bioinformants. (Notice that these messages
* are delivered in full length to BioTerminal, which identifies their
* destination.
*
* We want to thank an anonymous programmer for the ideas applied to
* BioTalk and related classes.
*
* Created on October 13, 2002, 10:46 AM
* Modified on June 26, 2003. 10:00 PM
* Last modified on November 19, 2004. 10:00 AM
*
* @version bioinformantes beta 1.00
*/
package bioinformants.client.gui;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Vector;
import javax.swing.*;
ContextualHTML.setName("copyPaste");
ContextualHTML.setInvoker(FullOutput);
jMenuItem1.setText("Copiar");
jMenuItem1.setName("copy");
jMenuItem1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jMenuItem1MouseClicked(evt);
}
});
ContextualHTML.add(jMenuItem1);
jMenuItem2.setText("Pegar");
jMenuItem2.setName("paste");
jMenuItem2.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jMenuItem2MouseClicked(evt);
}
});
ContextualHTML.add(jMenuItem2);
jMenuItem3.setText("Cortar");
jMenuItem3.setName("cut");
jMenuItem3.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jMenuItem3MouseClicked(evt);
}
});
ContextualHTML.add(jMenuItem3);
ContextualInput.setName("copyPaste");
ContextualInput.setInvoker(Input);
jMenuItem4.setLabel("Copiar");
jMenuItem4.setName("copy");
jMenuItem4.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jMenuItem4MouseClicked(evt);
}
});
ContextualInput.add(jMenuItem4);
jMenuItem5.setLabel("Pegar");
jMenuItem5.setName("paste");
jMenuItem5.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jMenuItem5MouseClicked(evt);
}
});
ContextualInput.add(jMenuItem5);
jMenuItem6.setLabel("Cortar");
jMenuItem6.setName("cut");
jMenuItem6.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jMenuItem6MouseClicked(evt);
}
});
ContextualInput.add(jMenuItem6);
PanelBase.setLayout(new java.awt.BorderLayout());
PseudoOutputPane.setViewportView(PseudoOutput);
Tabs.addTab("Shell", PseudoOutputPane);
FullOutputPane.setViewportView(FullOutput);
Tabs.addTab("HTML", FullOutputPane);
InputScrollPane.setViewportView(Input);
PanelBase.add(Tabs, java.awt.BorderLayout.CENTER);
PanelSalida.setLayout(new java.awt.BorderLayout());
PanelSalida.add(ChatOutputPane, java.awt.BorderLayout.CENTER);
PanelBase.add(PanelSalida, java.awt.BorderLayout.NORTH);
PanelBotones.setLayout(new java.awt.BorderLayout());
Botones.setName("botones");
jPanel2.setPreferredSize(new java.awt.Dimension(100, 20));
jPanel2.setAutoscrolls(true);
jButton1.setText("Ver LogChat");
jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton1MouseClicked(evt);
}
public void mousePressed(java.awt.event.MouseEvent evt) {
jButton1MousePressed(evt);
}
});
jPanel2.add(jButton1);
jButton2.setText("BioTutor");
jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
jButton2MousePressed(evt);
}
});
jPanel2.add(jButton2);
Botones.setViewportView(jPanel2);
PanelBotones.add(Botones, java.awt.BorderLayout.CENTER);
PanelBotones.add(OverButton, java.awt.BorderLayout.NORTH);
PanelBotones.add(OverButton1, java.awt.BorderLayout.SOUTH);
PanelBase.add(PanelBotones, java.awt.BorderLayout.EAST);
PanelComandos.setLayout(new java.awt.BorderLayout());
PanelComandos.add(Comandos, java.awt.BorderLayout.SOUTH);
PanelBase.add(PanelComandos, java.awt.BorderLayout.SOUTH);
getContentPane().add(PanelBase, java.awt.BorderLayout.CENTER);
}//GEN-END:initComponents
PseudoOutput.setCaretPosition(PseudoOutput.getDocument().getLength());
//}
/*
* try { CommandParser parser = new CommandParser( new
* BufferedReader(new StringReader(command))); String[] args =
* parser.parse(); displayArea.setText(""); for (int i = 0; i <
* args.length; i++) { displayArea.append(args[i]); } } catch
* (Exception ioe) { displayArea.setText("ERROR:" +
* ioe.getMessage() + ":" + ioe.getCause() + "\n"); }
*/
}else{
if (evt.getKeyCode() == evt.VK_BACK_SPACE) {
String ultimo = texto.substring(texto.length()-
1,texto.length());
System.out.println("Texto..."+texto+" Ultimo.."+ultimo);
if(ultimo.compareTo(">")==0){
System.out.println("Entre...");
PseudoOutput.setText(texto);
String ultimo2 = texto.substring(texto.length()-
2,texto.length());
System.out.println(ultimo2);
if(ultimo2.compareTo(">>")!= 0){
PseudoOutput.append(">");
texto = PseudoOutput.getText();
}
//PseudoOutput.append(">");
}
//Para que no se pueda borrar lo anterior... pero no s�
como evitarlo...
evt.consume();
texto = PseudoOutput.getText();
System.out.println("Texto acutalizado... "+texto);
}
else{
texto = PseudoOutput.getText();
System.out.println("Texto acutalizado... "+texto);
}
}
}//GEN-LAST:event_PseudoOutputKeyPressed
if (f!=null) {
theConnection.setRequestProperty("bioinformants.datafilename", f );
};
or = new OutputStreamWriter(theConnection.getOutputStream());
or.write(text);
showStatus("Sending a message.. "); // To the Applet
or.flush();
or.close();
// Trace
//System.out.println("message: " + text + " sent");
// Open an input stream to receive the response.
//System.out.println("Aqui es el problema, al pedir el
getInputStream" + theConnection.toString());
try{
ir = new InputStreamReader(theConnection.getInputStream());
in = new BufferedReader(ir);
}
catch(Exception e){
System.out.println("InterBio: Error al leer el InputSream
"+e.getMessage()+ " "+in);
e.printStackTrace();
}
//System.out.println("Interbio: Capte el inputStream 1");
// Mark the current position in the input stream.
// in.mark(10);
// Receive the response...
//System.out.println("Interbio: Voy a leer...");
receiveAnswer(in);
//System.out.println("Interbio: Lei");
in.close();
} catch (Exception e){
System.out.println("Interbio: Coudn't connect -- "+
e.toString());
//e.printStackTrace();
};
}
PseudoOutput.setCaretPosition(PseudoOutput.getDocument().getLength());
texto = PseudoOutput.getText();
}
}
// s_=s_.toLowerCase()+" ";
s_ = s_ + " ";
if (_type!=BioTalk.UNKNOWN) {
break typed;
};
};
// it decides what to do
if(_type == BioTalk.COMMAND ) {
parseCommand(s_);
} else {
if(_type == BioTalk.QUERY) {
parseQuery(s_);
} else {
//
_resp=ChatLdr.cq[i].converse(s_.substring(idx,s_.length()));
//String mes = mantener(s_);
sendMessage(s_, resourceDir + servletTerminal, null);
}
};
_type=ChatLdr.cq[i].identify(s_.substring(idx,s_.length()));
System.out.println("The type of the sentence is " + _type);
// if the first token something..
if(_type == BioTalk.COMMAND ) {
parseCommand(s_.substring(idx,s_.length()));
} else {
if(_type == BioTalk.QUERY) {
parseQuery(s_.substring(idx,s_.length()));
} else {
//
_resp=ChatLdr.cq[i].converse(s_.substring(idx,s_.length()));
sendMessage(s_, resourceDir + servletTerminal,
null);
}
}
break bigloop;
}
// eat blanks
while(s_.length() > ++idxSpace &&
Character.isWhitespace(s_.charAt(idxSpace)));
idx=idxSpace;
s_=s_.toLowerCase()+" ";
while(s_.indexOf("'")>=0)
s_=s_.substring(0,s_.indexOf("'"))+s_.substring(s_.indexOf("'")
+1,
s_.length());
String _resp=null;
for(int i=0;i<BioTalk.num_chats && _resp == null;i++) {
_resp=ChatLdr.cq[i].converse(s_.substring(idx,s_.length()));
if(_resp != null) {
println("InterBio: "+_resp);
break bigloop;
}
}
// eat blanks
while(s_.length() > ++idxSpace &&
Character.isWhitespace(s_.charAt(idxSpace)));
idx=idxSpace;
/** parseAnswer retrieves the answer from the servlet and decides
* what to do with it. This can be either 1) to display the info on the
* output pane of the applet, 2) to show a html document with the
browser or
* 3) to play an audioClip. These actions are methods available to the
* applet.
*/
public void parseAnswer(String s_) {
int idx=0, idxSpace=0;
String action ;
try {
//** Check for actions
while(s_.indexOf("</ACTION>")>=0) {
action = s_.substring(s_.indexOf("<ACTION>")+8,
s_.indexOf("</ACTION>"));
s_=s_.substring(0,s_.indexOf("<ACTION>"))
+s_.substring(s_.indexOf("</ACTION>")+9,s_.length());
if ( action.indexOf("showDocument:") >= 0) {
getAppletContext().showDocument(new
URL(action.substring(action.indexOf("showDocument:")+13, action.length())),
"_blank");
};
if ( action.indexOf("play:") >= 0) {
// I may need to load the clip first
play(new URL(action.substring(action.indexOf("play:")
+1, action.length())));
};
if ( action.indexOf("showStatus:") >= 0) {
showStatus(action.substring(action.indexOf("showStatus:")+12,
action.length()));
};