zerofile-svn Mailing List for ZeroFile (Page 2)
Status: Pre-Alpha
Brought to you by:
karl-bengtsson
You can subscribe to this list here.
| 2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(51) |
Dec
(26) |
|---|
|
From: <kar...@us...> - 2007-12-04 13:08:47
|
Revision: 61
http://zerofile.svn.sourceforge.net/zerofile/?rev=61&view=rev
Author: karl-bengtsson
Date: 2007-12-04 05:08:49 -0800 (Tue, 04 Dec 2007)
Log Message:
-----------
Added method to interpret URL message
Modified Paths:
--------------
trunk/src/XMPPDOMParser.java
trunk/src/XMPPLinkLocalChatSession.java
Modified: trunk/src/XMPPDOMParser.java
===================================================================
--- trunk/src/XMPPDOMParser.java 2007-11-29 23:20:21 UTC (rev 60)
+++ trunk/src/XMPPDOMParser.java 2007-12-04 13:08:49 UTC (rev 61)
@@ -61,4 +61,19 @@
return null;
}
}
+
+ public static String getUrlFromFileTransferStanza(String stanza)
+ {
+ try
+ {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ Document d = factory.newDocumentBuilder().parse(new InputSource(new StringReader(stanza)));
+ return d.getElementsByTagName("url").toString();
+ //return d.getAttributes().getNamedItem("from").toString();
+ }
+ catch (Exception e)
+ {
+ return null;
+ }
+ }
}
Modified: trunk/src/XMPPLinkLocalChatSession.java
===================================================================
--- trunk/src/XMPPLinkLocalChatSession.java 2007-11-29 23:20:21 UTC (rev 60)
+++ trunk/src/XMPPLinkLocalChatSession.java 2007-12-04 13:08:49 UTC (rev 61)
@@ -115,7 +115,19 @@
}
if (stanzaType.equals("message"))
{
- RecievedMessage(XMPPDOMParser.getMessageBodyFromMessageStanza(stanza));
+ if (XMPPDOMParser.getMessageBodyFromMessageStanza(stanza).equals(""))
+ {
+ if (stanza.contains("<x xmlns=\"jabber:x:oob\">"))
+ {
+ System.out.println(XMPPDOMParser.getUrlFromFileTransferStanza(stanza));
+ // This is a file
+
+ }
+ }
+ else
+ {
+ RecievedMessage(XMPPDOMParser.getMessageBodyFromMessageStanza(stanza));
+ }
}
else
System.out.println(stanza);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kar...@us...> - 2007-11-29 23:20:30
|
Revision: 60
http://zerofile.svn.sourceforge.net/zerofile/?rev=60&view=rev
Author: karl-bengtsson
Date: 2007-11-29 15:20:21 -0800 (Thu, 29 Nov 2007)
Log Message:
-----------
*) UpdateData() on XMPPLinkLocalHost is now blocking, meaning that most of the problems with the main contact list not being properly updated due to synchronization issues should now be resolved.
*) Code has been added to look through the contact list for possible hosts that we are communicating with when a session is opened on a socket. This implementation and the corresponding required changes in the registration code means that only one instance of the program will operate properly on a machine at any given time.
*) This also means that we now have a proper status bar title set on sessions originated by someone else as well.
*) The chat window messages have been improved, with indication of who sent what message, you or your chat partner.
Modified Paths:
--------------
trunk/src/XMPPDOMParser.java
trunk/src/XMPPLinkLocalChatSession.java
trunk/src/XMPPLinkLocalHost.java
trunk/src/ZeroFile.java
trunk/src/ZeroFileChatWindow.java
trunk/src/ZeroFileMainWindow.java
trunk/src/ZeroconfRegistration.java
Modified: trunk/src/XMPPDOMParser.java
===================================================================
--- trunk/src/XMPPDOMParser.java 2007-11-29 15:37:32 UTC (rev 59)
+++ trunk/src/XMPPDOMParser.java 2007-11-29 23:20:21 UTC (rev 60)
@@ -15,7 +15,6 @@
}
catch (Exception e)
{
- System.out.println(e);
return null;
}
}
@@ -31,7 +30,6 @@
}
catch (Exception e)
{
- System.out.println(e);
return null;
}
}
@@ -46,7 +44,6 @@
}
catch (Exception e)
{
- System.out.println(e);
return null;
}
}
@@ -61,7 +58,6 @@
}
catch (Exception e)
{
- System.out.println(e);
return null;
}
}
Modified: trunk/src/XMPPLinkLocalChatSession.java
===================================================================
--- trunk/src/XMPPLinkLocalChatSession.java 2007-11-29 15:37:32 UTC (rev 59)
+++ trunk/src/XMPPLinkLocalChatSession.java 2007-11-29 23:20:21 UTC (rev 60)
@@ -77,7 +77,6 @@
// Stanza is a handshake
{
_recievedHandshake = true;
- System.out.println(stanza);
if (!_sentHandshake)
sendHandshake();
}
@@ -93,7 +92,19 @@
{
if (_sentHandshake && _recievedHandshake)
{
- String stanzaType = null;
+ String stanzaType = null;
+ if (_chatPartner == null)
+ {
+ if (XMPPDOMParser.getFromAttributeFromMessageStanza(stanza) != null && !XMPPDOMParser.getFromAttributeFromMessageStanza(stanza).equals(""))
+ {
+ _chatPartner = new XMPPLinkLocalHost(XMPPDOMParser.getFromAttributeFromMessageStanza(stanza));
+ }
+ else
+ {
+ _chatPartner = ZeroFileMainWindow.getHostFromContactList(_s.getInetAddress());
+ }
+ _chatPartner.updateData();
+ }
try
{
stanzaType = XMPPDOMParser.getRootTagName(stanza);
@@ -104,36 +115,21 @@
}
if (stanzaType.equals("message"))
{
- String msg = XMPPDOMParser.getMessageBodyFromMessageStanza(stanza);
- String to = XMPPDOMParser.getToAttributeFromMessageStanza(stanza);
- String from = XMPPDOMParser.getFromAttributeFromMessageStanza(stanza);
- RecievedMessage(msg,to,from);
- System.out.println(stanza);
+ RecievedMessage(XMPPDOMParser.getMessageBodyFromMessageStanza(stanza));
}
else
System.out.println(stanza);
- //System.out.println(stanzaType + " - not yet handled stanza type.");
}
}
}
- private void RecievedMessage(String mess,String to,String from)
+ private void RecievedMessage(String mess)
{
- if (_chatPartner == null)
- {
- _chatPartner = new XMPPLinkLocalHost(from);
- _chatPartner.updateData();
- }
if (_chatWindow == null)
{
- /* TODO - set _chatPartner to a new host and update this hosts data
- * based on a browse of the network using the stanzas to-attribute
- * as search parameter - this also means that we need the entire stanza at this
- * point, not just the payload.
- */
- System.out.println("nu skapas f\x9Anstret");
_chatWindow = new ZeroFileChatWindow(this);
}
+ _chatWindow.printText(_chatPartner.toString()+":");
_chatWindow.printText(mess);
}
@@ -154,11 +150,9 @@
public void sendMessage(String m)
{
- String test = "<iq type='get' from='"+ZeroconfRegistration.getMyServiceName()+"' to='" + _chatPartner.getServiceName() + "' id='items1'> <query xmlns='http://jabber.org/protocol/disco#items'/></iq>";
- _toRemoteHost.print(test);
+ String messageStanza = "<message to=\""+_chatPartner.getServiceName()+"\" from=\""+ZeroconfRegistration.getMyServiceName()+"\"><body>"+m+"</body></message>";
+ _toRemoteHost.print(messageStanza);
_toRemoteHost.flush();
- _toRemoteHost.print("<message><body>"+m+"</body></message>");
- _toRemoteHost.flush();
}
public void disconnect()
Modified: trunk/src/XMPPLinkLocalHost.java
===================================================================
--- trunk/src/XMPPLinkLocalHost.java 2007-11-29 15:37:32 UTC (rev 59)
+++ trunk/src/XMPPLinkLocalHost.java 2007-11-29 23:20:21 UTC (rev 60)
@@ -10,6 +10,7 @@
private String _firstName;
private String _lastName;
private String _host;
+ private Boolean _hasBeenResolved;
private int _port;
private static DNSSDService _r;
@@ -45,22 +46,23 @@
public String toString()
{
- return _firstName;
- /*if (_nickName != null)
+ if (_nickName != null && !_nickName.equals(""))
return _nickName;
else
- if (_firstName != null && _lastName != null)
- return _firstName + " " + _lastName;
+ if (_firstName != null && !_firstName.equals(""))
+ if (_lastName != null && !_lastName.equals(""))
+ return _firstName + " " + _lastName;
+ else
+ return _firstName;
else
return _serviceName;
- */
}
- // TODO - Fungerar inte alltid
public void updateData()
{
try
{
+ _hasBeenResolved = false;
_r = DNSSD.resolve(0, DNSSD.ALL_INTERFACES, _serviceName, "_presence._tcp", "local", new ResolveListener()
{
public void operationFailed(DNSSDService service,int errorCode)
@@ -71,6 +73,7 @@
public void serviceResolved(DNSSDService resolver, int flags, int ifIndex,
String fullName, String hostName, int port, TXTRecord txtRecord)
{
+ _hasBeenResolved = true;
_host = hostName;
_port = port;
if (txtRecord != null)
@@ -82,18 +85,25 @@
if (txtRecord.contains("nick"))
_nickName = txtRecord.getValueAsString("nick").toString();
}
- System.out.println("nu har vi resolvat");
- System.out.println("1st - " + _firstName);
- System.out.println("2nd - " +_lastName);
- System.out.println("nick - "+ _nickName);
- System.out.println("vid: " + _host + ":" + _port);
_r.stop();
}
});
+ while (!_hasBeenResolved)
+ {
+ try
+ {
+ Thread.sleep(50);
+ }
+ catch (InterruptedException e)
+ {
+ e.printStackTrace();
+ }
+ }
}
catch (Exception e)
{
System.out.println("Error: " + e);
+ System.out.println(_serviceName);
}
}
Modified: trunk/src/ZeroFile.java
===================================================================
--- trunk/src/ZeroFile.java 2007-11-29 15:37:32 UTC (rev 59)
+++ trunk/src/ZeroFile.java 2007-11-29 23:20:21 UTC (rev 60)
@@ -7,6 +7,10 @@
* @throws IOException
*/
public static void main(String[] args) throws IOException {
+ System.out.println(
+ new java.io.OutputStreamWriter(
+ new java.io.ByteArrayOutputStream()).getEncoding()
+ );
ZeroFileMainWindow.startMainWindow();
ZeroFileSettings.loadSettings();
try
Modified: trunk/src/ZeroFileChatWindow.java
===================================================================
--- trunk/src/ZeroFileChatWindow.java 2007-11-29 15:37:32 UTC (rev 59)
+++ trunk/src/ZeroFileChatWindow.java 2007-11-29 23:20:21 UTC (rev 60)
@@ -29,12 +29,13 @@
public void printText(String s)
{
- _chatTextArea.append("\n"+s);
+ _chatTextArea.append(s+"\n");
}
public void sendMessage(String str)
{
- printText(str);
+ printText("You:");
+ printText(str+"\n");
_session.sendMessage(str);
_entryTextField.setText("");
}
Modified: trunk/src/ZeroFileMainWindow.java
===================================================================
--- trunk/src/ZeroFileMainWindow.java 2007-11-29 15:37:32 UTC (rev 59)
+++ trunk/src/ZeroFileMainWindow.java 2007-11-29 23:20:21 UTC (rev 60)
@@ -1,5 +1,6 @@
import java.awt.*;
import java.awt.event.*;
+import java.net.*;
import javax.swing.*;
public class ZeroFileMainWindow
@@ -22,14 +23,37 @@
static boolean containsHost(XMPPLinkLocalHost h)
{
for (int i = 0; i<_contactListModel.size(); i++)
+ {
if (((XMPPLinkLocalHost)_contactListModel.getElementAt(i)).getServiceName().equals(h.getServiceName()))
return true;
+ }
return false;
}
+ static XMPPLinkLocalHost getHostFromContactList(InetAddress searchedAddress)
+ {
+ for (int i = 0; i<_contactListModel.size(); i++)
+ {
+ InetAddress iteratedAddress = null;
+ XMPPLinkLocalHost iteratedHost = (XMPPLinkLocalHost)_contactListModel.getElementAt(i);
+ try
+ {
+ iteratedAddress = InetAddress.getByName(iteratedHost.getHost());
+ }
+ catch (Exception e)
+ {
+ System.out.println(e);
+ }
+ if (searchedAddress.equals(iteratedAddress))
+ {
+ return (XMPPLinkLocalHost)_contactListModel.getElementAt(i);
+ }
+ }
+ return new XMPPLinkLocalHost(null);
+ }
+
static void addHost(XMPPLinkLocalHost h)
{
- //h.updateData();
_contactListModel.addElement(h);
}
Modified: trunk/src/ZeroconfRegistration.java
===================================================================
--- trunk/src/ZeroconfRegistration.java 2007-11-29 15:37:32 UTC (rev 59)
+++ trunk/src/ZeroconfRegistration.java 2007-11-29 23:20:21 UTC (rev 60)
@@ -10,12 +10,14 @@
private static TXTRecord _txtRecord = new TXTRecord();
private static DNSSDRegistration _r;
private static String _myServiceName;
+ private static Boolean _registrationStarted = false;
static void registerService(String status,int port)
throws DNSSDException, InterruptedException
{
-
- _r = DNSSD.register(ZeroFile.getSuggestedServiceName(), "_presence._tcp", port, new RegisterListener()
+ _registrationStarted = true;
+ _r = DNSSD.register(0,0,ZeroFile.getSuggestedServiceName(), "_presence._tcp","local",null,port,_txtRecord, new RegisterListener()
+ //_r = DNSSD.register(ZeroFile.getSuggestedServiceName(), "_presence._tcp",port, new RegisterListener()
{
public void serviceRegistered(DNSSDRegistration registration, int flags,
String serviceName, String regType, String domain)
@@ -36,13 +38,25 @@
public static String getMyServiceName()
{
- while (_myServiceName == null)
- try {
- Thread.sleep(50);
- } catch (InterruptedException e) {
- e.printStackTrace();
+ if (!_registrationStarted)
+ {
+ return null;
+ }
+ else
+ {
+ while (_myServiceName == null)
+ {
+ try
+ {
+ Thread.sleep(50);
+ }
+ catch (InterruptedException e)
+ {
+ e.printStackTrace();
+ }
}
return _myServiceName;
+ }
}
static void registerService(int port)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kar...@us...> - 2007-11-29 15:53:41
|
Revision: 59
http://zerofile.svn.sourceforge.net/zerofile/?rev=59&view=rev
Author: karl-bengtsson
Date: 2007-11-29 07:37:32 -0800 (Thu, 29 Nov 2007)
Log Message:
-----------
Helt kukad release, som f?\195?\182rmodligen inte alls fungerar. Men det ?\195?\164r ny kod iaf.
Modified Paths:
--------------
trunk/src/XMPPDOMParser.java
trunk/src/XMPPLinkLocalChatSession.java
trunk/src/XMPPLinkLocalHost.java
trunk/src/XMPPSessionListener.java
trunk/src/ZeroFile.java
trunk/src/ZeroFileChatWindow.java
trunk/src/ZeroFileMainWindow.java
trunk/src/ZeroconfRegistration.java
Modified: trunk/src/XMPPDOMParser.java
===================================================================
--- trunk/src/XMPPDOMParser.java 2007-11-27 21:09:02 UTC (rev 58)
+++ trunk/src/XMPPDOMParser.java 2007-11-29 15:37:32 UTC (rev 59)
@@ -16,8 +16,8 @@
catch (Exception e)
{
System.out.println(e);
+ return null;
}
- return null;
}
public static String getMessageBodyFromMessageStanza(String stanza)
@@ -32,7 +32,37 @@
catch (Exception e)
{
System.out.println(e);
+ return null;
}
- return null;
}
+
+ public static String getToAttributeFromMessageStanza(String stanza)
+ {
+ try
+ {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ Document d = factory.newDocumentBuilder().parse(new InputSource(new StringReader(stanza)));
+ return d.getAttributes().getNamedItem("to").toString();
+ }
+ catch (Exception e)
+ {
+ System.out.println(e);
+ return null;
+ }
+ }
+
+ public static String getFromAttributeFromMessageStanza(String stanza)
+ {
+ try
+ {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ Document d = factory.newDocumentBuilder().parse(new InputSource(new StringReader(stanza)));
+ return d.getAttributes().getNamedItem("from").toString();
+ }
+ catch (Exception e)
+ {
+ System.out.println(e);
+ return null;
+ }
+ }
}
Modified: trunk/src/XMPPLinkLocalChatSession.java
===================================================================
--- trunk/src/XMPPLinkLocalChatSession.java 2007-11-27 21:09:02 UTC (rev 58)
+++ trunk/src/XMPPLinkLocalChatSession.java 2007-11-29 15:37:32 UTC (rev 59)
@@ -13,6 +13,7 @@
private Reader _fromRemoteHost;
private PrintWriter _toRemoteHost;
private ZeroFileChatWindow _chatWindow;
+ private XMPPLinkLocalHost _chatPartner;
private Thread _remoteHostReadingThread = new Thread() {
public void run() {
@@ -49,6 +50,7 @@
public XMPPLinkLocalChatSession(XMPPLinkLocalHost hostToChatWith)
{
+ _chatPartner = hostToChatWith;
_chatWindow = new ZeroFileChatWindow(this);
try
{
@@ -64,19 +66,26 @@
}
}
+ public XMPPLinkLocalHost getChatPartner()
+ {
+ return _chatPartner;
+ }
+
private void RecievedStanza(String stanza)
{
if (stanza.contains("<?xml"))
// Stanza is a handshake
{
_recievedHandshake = true;
+ System.out.println(stanza);
if (!_sentHandshake)
sendHandshake();
}
else if (stanza.contains("</stream:stream>"))
// Stanza is a hangup message
{
- _chatWindow.printText("Opposite party has left the chat");
+ if (_chatWindow != null)
+ _chatWindow.printText("Opposite party has left the chat");
disconnect();
}
else
@@ -95,18 +104,36 @@
}
if (stanzaType.equals("message"))
{
- RecievedMessage(XMPPDOMParser.getMessageBodyFromMessageStanza(stanza));
- }
+ String msg = XMPPDOMParser.getMessageBodyFromMessageStanza(stanza);
+ String to = XMPPDOMParser.getToAttributeFromMessageStanza(stanza);
+ String from = XMPPDOMParser.getFromAttributeFromMessageStanza(stanza);
+ RecievedMessage(msg,to,from);
+ System.out.println(stanza);
+ }
else
- System.out.println(stanzaType + " - not yet handled stanza type.");
+ System.out.println(stanza);
+ //System.out.println(stanzaType + " - not yet handled stanza type.");
}
}
}
- private void RecievedMessage(String mess)
+ private void RecievedMessage(String mess,String to,String from)
{
+ if (_chatPartner == null)
+ {
+ _chatPartner = new XMPPLinkLocalHost(from);
+ _chatPartner.updateData();
+ }
if (_chatWindow == null)
+ {
+ /* TODO - set _chatPartner to a new host and update this hosts data
+ * based on a browse of the network using the stanzas to-attribute
+ * as search parameter - this also means that we need the entire stanza at this
+ * point, not just the payload.
+ */
+ System.out.println("nu skapas f\x9Anstret");
_chatWindow = new ZeroFileChatWindow(this);
+ }
_chatWindow.printText(mess);
}
@@ -127,6 +154,9 @@
public void sendMessage(String m)
{
+ String test = "<iq type='get' from='"+ZeroconfRegistration.getMyServiceName()+"' to='" + _chatPartner.getServiceName() + "' id='items1'> <query xmlns='http://jabber.org/protocol/disco#items'/></iq>";
+ _toRemoteHost.print(test);
+ _toRemoteHost.flush();
_toRemoteHost.print("<message><body>"+m+"</body></message>");
_toRemoteHost.flush();
}
Modified: trunk/src/XMPPLinkLocalHost.java
===================================================================
--- trunk/src/XMPPLinkLocalHost.java 2007-11-27 21:09:02 UTC (rev 58)
+++ trunk/src/XMPPLinkLocalHost.java 2007-11-29 15:37:32 UTC (rev 59)
@@ -44,16 +44,19 @@
}
public String toString()
- {
- if (_nickName != null)
+ {
+ return _firstName;
+ /*if (_nickName != null)
return _nickName;
else
if (_firstName != null && _lastName != null)
return _firstName + " " + _lastName;
else
return _serviceName;
+ */
}
+ // TODO - Fungerar inte alltid
public void updateData()
{
try
@@ -79,13 +82,18 @@
if (txtRecord.contains("nick"))
_nickName = txtRecord.getValueAsString("nick").toString();
}
+ System.out.println("nu har vi resolvat");
+ System.out.println("1st - " + _firstName);
+ System.out.println("2nd - " +_lastName);
+ System.out.println("nick - "+ _nickName);
+ System.out.println("vid: " + _host + ":" + _port);
_r.stop();
}
});
}
catch (Exception e)
{
- System.out.println("Error: " + e.getStackTrace().toString());
+ System.out.println("Error: " + e);
}
}
Modified: trunk/src/XMPPSessionListener.java
===================================================================
--- trunk/src/XMPPSessionListener.java 2007-11-27 21:09:02 UTC (rev 58)
+++ trunk/src/XMPPSessionListener.java 2007-11-29 15:37:32 UTC (rev 59)
@@ -12,7 +12,6 @@
while(true)
{
Socket connection = _listeningSock.accept();
- //new ZeroFileChatWindow(connection);
new XMPPLinkLocalChatSession(connection);
}
}
Modified: trunk/src/ZeroFile.java
===================================================================
--- trunk/src/ZeroFile.java 2007-11-27 21:09:02 UTC (rev 58)
+++ trunk/src/ZeroFile.java 2007-11-29 15:37:32 UTC (rev 59)
@@ -25,18 +25,20 @@
}
}
- public static String getServiceName()
+ public static String getSuggestedServiceName()
{
- String serviceName = "serviceName";
+ String userName = System.getProperty("user.name");
+ String hostName;
try
{
InetAddress localMachine = InetAddress.getLocalHost();
- serviceName = localMachine.getHostName();
+ hostName = localMachine.getHostName().split("\\.")[0];
+ return userName + "@" + hostName;
}
catch (Exception e)
{
System.out.println(e);
+ return null;
}
- return serviceName;
}
}
Modified: trunk/src/ZeroFileChatWindow.java
===================================================================
--- trunk/src/ZeroFileChatWindow.java 2007-11-27 21:09:02 UTC (rev 58)
+++ trunk/src/ZeroFileChatWindow.java 2007-11-29 15:37:32 UTC (rev 59)
@@ -19,6 +19,7 @@
{
this.ZeroFileChatWindowInit();
_session = sess;
+ _chatWindowFrame.setTitle(_session.getChatPartner().toString());
}
public void setWindowTitle(String t)
Modified: trunk/src/ZeroFileMainWindow.java
===================================================================
--- trunk/src/ZeroFileMainWindow.java 2007-11-27 21:09:02 UTC (rev 58)
+++ trunk/src/ZeroFileMainWindow.java 2007-11-29 15:37:32 UTC (rev 59)
@@ -29,7 +29,7 @@
static void addHost(XMPPLinkLocalHost h)
{
- h.updateData();
+ //h.updateData();
_contactListModel.addElement(h);
}
Modified: trunk/src/ZeroconfRegistration.java
===================================================================
--- trunk/src/ZeroconfRegistration.java 2007-11-27 21:09:02 UTC (rev 58)
+++ trunk/src/ZeroconfRegistration.java 2007-11-29 15:37:32 UTC (rev 59)
@@ -14,7 +14,8 @@
static void registerService(String status,int port)
throws DNSSDException, InterruptedException
{
- _r = DNSSD.register(null, "_presence._tcp", port, new RegisterListener()
+
+ _r = DNSSD.register(ZeroFile.getSuggestedServiceName(), "_presence._tcp", port, new RegisterListener()
{
public void serviceRegistered(DNSSDRegistration registration, int flags,
String serviceName, String regType, String domain)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kar...@us...> - 2007-11-27 21:08:58
|
Revision: 58
http://zerofile.svn.sourceforge.net/zerofile/?rev=58&view=rev
Author: karl-bengtsson
Date: 2007-11-27 13:09:02 -0800 (Tue, 27 Nov 2007)
Log Message:
-----------
*) Added (more or less empty) About-window where we can brag about how great we are.
*) Modified the LayoutManager for the main window to use BorderLayout, and put the contact list inside a ScrollPane, providing scroll bars and a more balanced look.
*) Did likewise for the chat window.
So now our application looks a little bit more professional, at least on a Mac. Please try it out on other platforms.
Modified Paths:
--------------
trunk/src/ZeroFileChatWindow.java
trunk/src/ZeroFileMainWindow.java
trunk/src/ZeroFileSettingsWindow.java
Added Paths:
-----------
trunk/src/ZeroFileAboutWindow.java
Added: trunk/src/ZeroFileAboutWindow.java
===================================================================
--- trunk/src/ZeroFileAboutWindow.java (rev 0)
+++ trunk/src/ZeroFileAboutWindow.java 2007-11-27 21:09:02 UTC (rev 58)
@@ -0,0 +1,27 @@
+import java.awt.*;
+import javax.swing.*;
+
+/**
+ *
+ */
+
+/**
+ * @author Karl Bengtsson
+ *
+ */
+public class ZeroFileAboutWindow {
+ private static JFrame _aboutWindowFrame;
+ private static JLabel _aboutText;
+
+ public static void showAboutWindow()
+ {
+ _aboutWindowFrame = new JFrame();
+ _aboutWindowFrame.setTitle("About ZeroFile");
+ _aboutWindowFrame.setSize(new Dimension(300,200));
+ _aboutWindowFrame.setLayout(new BorderLayout(10,10));
+ _aboutText = new JLabel();
+ _aboutText.setText("Hell jeas!");
+ _aboutWindowFrame.add(_aboutText,BorderLayout.CENTER);
+ _aboutWindowFrame.setVisible(true);
+ }
+}
Modified: trunk/src/ZeroFileChatWindow.java
===================================================================
--- trunk/src/ZeroFileChatWindow.java 2007-11-27 15:38:23 UTC (rev 57)
+++ trunk/src/ZeroFileChatWindow.java 2007-11-27 21:09:02 UTC (rev 58)
@@ -8,23 +8,12 @@
*/
public class ZeroFileChatWindow {
private JFrame _chatWindowFrame;
- private JTextArea _chatTextArea;
+ private JTextArea _chatTextArea = new JTextArea();;
+ private JScrollPane _chatTextAreaPane = new JScrollPane(_chatTextArea);
private JPanel _bottomPanel;
private JTextField _entryTextField;
private JButton _sendButton;
private XMPPLinkLocalChatSession _session;
- /*public ZeroFileChatWindow(Socket sock)
- {
- this.ZeroFileChatWindowInit();
- _session = new XMPPLinkLocalChatSession(this,sock);
- }
- public ZeroFileChatWindow(XMPPLinkLocalHost hostToChatWith)
- {
- this.ZeroFileChatWindowInit();
- hostToChatWith.updateData();
- this.setWindowTitle(hostToChatWith.toString());
- _session = new XMPPLinkLocalChatSession(this,hostToChatWith);
- }*/
public ZeroFileChatWindow(XMPPLinkLocalChatSession sess)
{
@@ -42,29 +31,50 @@
_chatTextArea.append("\n"+s);
}
+ public void sendMessage(String str)
+ {
+ printText(str);
+ _session.sendMessage(str);
+ _entryTextField.setText("");
+ }
+
private void ZeroFileChatWindowInit()
{
_chatWindowFrame = new JFrame();
- _chatWindowFrame.setLayout(new GridLayout(0,1,1,1));
+ _chatWindowFrame.setLayout(new BorderLayout(1,1));
_chatWindowFrame.setLocation(0,400);
_chatWindowFrame.setSize(new Dimension(300,200));
- _chatTextArea = new JTextArea();
- _chatWindowFrame.add(_chatTextArea);
+ _chatTextAreaPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
+ _chatWindowFrame.add(_chatTextAreaPane,BorderLayout.CENTER);
_bottomPanel = new JPanel();
- _chatWindowFrame.add(_bottomPanel);
+ _chatWindowFrame.add(_bottomPanel,BorderLayout.SOUTH);
_bottomPanel.setLayout(new GridLayout(1,0,1,1));
_entryTextField = new JTextField();
_sendButton = new JButton("Send");
_bottomPanel.add(_entryTextField);
+ _entryTextField.addKeyListener(
+ new KeyListener()
+ {
+ public void keyPressed(KeyEvent e)
+ {
+ }
+ public void keyReleased(KeyEvent e)
+ {
+ }
+ public void keyTyped(KeyEvent e)
+ {
+ if (e.getKeyChar() == '\n')
+ {
+ sendMessage(_entryTextField.getText());
+ }
+ }
+ });
_bottomPanel.add(_sendButton);
_chatWindowFrame.setVisible(true);
_sendButton.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent sendButtonPress){
- String message = _entryTextField.getText();
- printText(message);
- _session.sendMessage(message);
- _entryTextField.setText("");
+ sendMessage(_entryTextField.getText());
}
}
);
Modified: trunk/src/ZeroFileMainWindow.java
===================================================================
--- trunk/src/ZeroFileMainWindow.java 2007-11-27 15:38:23 UTC (rev 57)
+++ trunk/src/ZeroFileMainWindow.java 2007-11-27 21:09:02 UTC (rev 58)
@@ -1,6 +1,5 @@
import java.awt.*;
import java.awt.event.*;
-
import javax.swing.*;
public class ZeroFileMainWindow
@@ -16,8 +15,9 @@
private static JMenu _helpMenu;
private static JMenuItem _aboutMenuItem;
private static JComboBox _statusLista;
- private static DefaultListModel _contactListModel = new DefaultListModel();;
- private static JList _contactList = new JList(_contactListModel);;
+ private static DefaultListModel _contactListModel = new DefaultListModel();
+ private static JList _contactList = new JList(_contactListModel);
+ private static JScrollPane _contactListPane = new JScrollPane(_contactList);
static boolean containsHost(XMPPLinkLocalHost h)
{
@@ -29,7 +29,6 @@
static void addHost(XMPPLinkLocalHost h)
{
- //System.out.println("forsoker adda: " + h.toString());
h.updateData();
_contactListModel.addElement(h);
}
@@ -71,10 +70,15 @@
_helpMenu = new JMenu("Help");
_mainMenuBar.add(_helpMenu);
_aboutMenuItem = new JMenuItem("About..");
+ _aboutMenuItem.addActionListener(new ActionListener(){
+ public void actionPerformed(ActionEvent e) {
+ ZeroFileAboutWindow.showAboutWindow();
+ }
+ });
_helpMenu.add(_aboutMenuItem);
// Layout, sizes, and the connection of the JMenuBar
- _mainWindowFrame.setLayout(new GridLayout(0,1,1,1));
+ _mainWindowFrame.setLayout(new BorderLayout(1,1));
_mainWindowFrame.setMinimumSize(new Dimension(120,300));
_mainWindowFrame.setSize(new Dimension(150,400));
_mainWindowFrame.setJMenuBar(_mainMenuBar);
@@ -83,7 +87,7 @@
String[] statusModes = {"Available","Away","Do not disturb"};
_statusLista = new JComboBox(statusModes);
_statusLista.setMaximumSize(new Dimension(20,100));
- _mainWindowFrame.add(_statusLista);
+ _mainWindowFrame.add(_statusLista,BorderLayout.NORTH);
_statusLista.addItemListener(new ItemListener(){
public void itemStateChanged(ItemEvent e)
{
@@ -97,8 +101,6 @@
});
// Contact list
- //_contactListModel = new DefaultListModel();
- //_contactList = new JList(_contactListModel);
_contactList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
_contactList.setLayoutOrientation(JList.VERTICAL);
_contactList.setSize(500,700);
@@ -122,11 +124,11 @@
public void mouseClicked(MouseEvent e)
{
if (e.getClickCount() == 2)
- //new ZeroFileChatWindow((XMPPLinkLocalHost)_contactList.getSelectedValue());
new XMPPLinkLocalChatSession((XMPPLinkLocalHost)_contactList.getSelectedValue());
}
});
- _mainWindowFrame.add(_contactList);
+ _contactListPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
+ _mainWindowFrame.add(_contactListPane,BorderLayout.CENTER);
// Show the window
_mainWindowFrame.setVisible(true);
Modified: trunk/src/ZeroFileSettingsWindow.java
===================================================================
--- trunk/src/ZeroFileSettingsWindow.java 2007-11-27 15:38:23 UTC (rev 57)
+++ trunk/src/ZeroFileSettingsWindow.java 2007-11-27 21:09:02 UTC (rev 58)
@@ -7,7 +7,7 @@
* @author Richard
*/
-public class ZeroFileSettingsWindow
+public class ZeroFileSettingsWindow
{
static void startSettingsWindow()
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kar...@us...> - 2007-11-27 15:38:31
|
Revision: 57
http://zerofile.svn.sourceforge.net/zerofile/?rev=57&view=rev
Author: karl-bengtsson
Date: 2007-11-27 07:38:23 -0800 (Tue, 27 Nov 2007)
Log Message:
-----------
Implemented DOM XMPP parsing and basic message handling thingys. And various improvements. Huzzah!
Modified Paths:
--------------
trunk/src/XMPPLinkLocalChatSession.java
trunk/src/ZeroFileChatWindow.java
trunk/src/ZeroconfBrowsing.java
Added Paths:
-----------
trunk/src/XMPPDOMParser.java
Added: trunk/src/XMPPDOMParser.java
===================================================================
--- trunk/src/XMPPDOMParser.java (rev 0)
+++ trunk/src/XMPPDOMParser.java 2007-11-27 15:38:23 UTC (rev 57)
@@ -0,0 +1,38 @@
+import java.io.*;
+import javax.xml.parsers.*;
+import org.w3c.dom.*;
+import org.xml.sax.*;
+
+public class XMPPDOMParser {
+ public static String getRootTagName(String XMLexcerpt)
+ {
+ try
+ {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ Document d = factory.newDocumentBuilder().parse(new InputSource(new StringReader(XMLexcerpt)));
+ Node n = d.getFirstChild();
+ return n.getNodeName();
+ }
+ catch (Exception e)
+ {
+ System.out.println(e);
+ }
+ return null;
+ }
+
+ public static String getMessageBodyFromMessageStanza(String stanza)
+ {
+ try
+ {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ Document d = factory.newDocumentBuilder().parse(new InputSource(new StringReader(stanza)));
+ Node n = d.getElementsByTagName("body").item(0);
+ return n.getTextContent();
+ }
+ catch (Exception e)
+ {
+ System.out.println(e);
+ }
+ return null;
+ }
+}
Modified: trunk/src/XMPPLinkLocalChatSession.java
===================================================================
--- trunk/src/XMPPLinkLocalChatSession.java 2007-11-27 13:04:34 UTC (rev 56)
+++ trunk/src/XMPPLinkLocalChatSession.java 2007-11-27 15:38:23 UTC (rev 57)
@@ -7,11 +7,11 @@
public class XMPPLinkLocalChatSession {
private boolean _sentHandshake = false;
- private boolean _recievedHandshake =false;
+ private boolean _recievedHandshake = false;
+ private boolean _sentHangup = false;
private Socket _s;
private Reader _fromRemoteHost;
private PrintWriter _toRemoteHost;
- //private PrintWriter _toUser = new PrintWriter(System.out,true);
private ZeroFileChatWindow _chatWindow;
private Thread _remoteHostReadingThread = new Thread() {
@@ -22,13 +22,13 @@
while ((chars_read = _fromRemoteHost.read(buffer)) != -1)
{
RecievedStanza(String.valueOf(buffer).substring(0,chars_read));
- //_toUser.write(buffer,0,chars_read);
- //_toUser.flush();
- //_chatWindow.printText(String.valueOf(buffer));
}
}
- catch (IOException e) {System.out.println(e);}
- System.out.println("Connection closed!");
+ catch (IOException e)
+ {
+ this.interrupt();
+ }
+
}
};
@@ -66,7 +66,41 @@
private void RecievedStanza(String stanza)
{
- RecievedMessage(stanza);
+ if (stanza.contains("<?xml"))
+ // Stanza is a handshake
+ {
+ _recievedHandshake = true;
+ if (!_sentHandshake)
+ sendHandshake();
+ }
+ else if (stanza.contains("</stream:stream>"))
+ // Stanza is a hangup message
+ {
+ _chatWindow.printText("Opposite party has left the chat");
+ disconnect();
+ }
+ else
+ // Stanza is neither handshake nor hangup, rather a message with a payload of some sort
+ {
+ if (_sentHandshake && _recievedHandshake)
+ {
+ String stanzaType = null;
+ try
+ {
+ stanzaType = XMPPDOMParser.getRootTagName(stanza);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ if (stanzaType.equals("message"))
+ {
+ RecievedMessage(XMPPDOMParser.getMessageBodyFromMessageStanza(stanza));
+ }
+ else
+ System.out.println(stanzaType + " - not yet handled stanza type.");
+ }
+ }
}
private void RecievedMessage(String mess)
@@ -84,7 +118,6 @@
_fromRemoteHost = new InputStreamReader(_s.getInputStream());
_remoteHostReadingThread.start();
_toRemoteHost = new PrintWriter(_s.getOutputStream());
- sendHandshake();
}
catch (Exception e)
{
@@ -102,9 +135,15 @@
{
try
{
- _toRemoteHost.print("</stream:stream>");
- _toRemoteHost.flush();
- _s.close();
+ if (!_sentHangup)
+ {
+ _toRemoteHost.print("</stream:stream>");
+ _toRemoteHost.flush();
+ _s.close();
+ _sentHandshake = false;
+ _recievedHandshake = false;
+ _sentHangup = true;
+ }
}
catch (Exception e)
{
Modified: trunk/src/ZeroFileChatWindow.java
===================================================================
--- trunk/src/ZeroFileChatWindow.java 2007-11-27 13:04:34 UTC (rev 56)
+++ trunk/src/ZeroFileChatWindow.java 2007-11-27 15:38:23 UTC (rev 57)
@@ -71,7 +71,7 @@
_chatWindowFrame.addWindowListener(new WindowListener(){
public void windowClosing(WindowEvent e)
{
-
+ _session.disconnect();
}
public void windowDeiconified(WindowEvent e)
{
@@ -87,7 +87,7 @@
}
public void windowClosed(WindowEvent e)
{
- _session.disconnect();
+
}
public void windowIconified(WindowEvent e)
{
Modified: trunk/src/ZeroconfBrowsing.java
===================================================================
--- trunk/src/ZeroconfBrowsing.java 2007-11-27 13:04:34 UTC (rev 56)
+++ trunk/src/ZeroconfBrowsing.java 2007-11-27 15:38:23 UTC (rev 57)
@@ -19,7 +19,6 @@
if (!ZeroFileMainWindow.containsHost(newHost) && !ZeroconfRegistration.getMyServiceName().equals(name))
{
ZeroFileMainWindow.addHost(newHost);
- System.out.println("hittat servicename: " + name);
}
}
public void serviceLost(DNSSDService browser, int flags, int ifIndex,
@@ -28,10 +27,8 @@
ZeroFileMainWindow.removeHost(new XMPPLinkLocalHost(name));
}
});
- System.out.println("Starting browsing...");
}
static void stopBrowsing(){
_s.stop();
- System.out.println("Stopped browsing");
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kar...@us...> - 2007-11-27 13:04:42
|
Revision: 56
http://zerofile.svn.sourceforge.net/zerofile/?rev=56&view=rev
Author: karl-bengtsson
Date: 2007-11-27 05:04:34 -0800 (Tue, 27 Nov 2007)
Log Message:
-----------
Changed back to the old inheritance structure for chats/chat windows and simplified the chat session class greatly.
Modified Paths:
--------------
trunk/src/XMPPLinkLocalChatSession.java
trunk/src/XMPPSessionListener.java
trunk/src/ZeroFileChatWindow.java
trunk/src/ZeroFileMainWindow.java
Modified: trunk/src/XMPPLinkLocalChatSession.java
===================================================================
--- trunk/src/XMPPLinkLocalChatSession.java 2007-11-21 16:39:56 UTC (rev 55)
+++ trunk/src/XMPPLinkLocalChatSession.java 2007-11-27 13:04:34 UTC (rev 56)
@@ -6,10 +6,12 @@
*/
public class XMPPLinkLocalChatSession {
+ private boolean _sentHandshake = false;
+ private boolean _recievedHandshake =false;
private Socket _s;
private Reader _fromRemoteHost;
private PrintWriter _toRemoteHost;
- private PrintWriter _toUser = new PrintWriter(System.out,true);
+ //private PrintWriter _toUser = new PrintWriter(System.out,true);
private ZeroFileChatWindow _chatWindow;
private Thread _remoteHostReadingThread = new Thread() {
@@ -19,9 +21,10 @@
try {
while ((chars_read = _fromRemoteHost.read(buffer)) != -1)
{
- _toUser.write(buffer,0,chars_read);
- _toUser.flush();
- _chatWindow.printText(String.valueOf(buffer));
+ RecievedStanza(String.valueOf(buffer).substring(0,chars_read));
+ //_toUser.write(buffer,0,chars_read);
+ //_toUser.flush();
+ //_chatWindow.printText(String.valueOf(buffer));
}
}
catch (IOException e) {System.out.println(e);}
@@ -29,24 +32,31 @@
}
};
- public XMPPLinkLocalChatSession(ZeroFileChatWindow cW,XMPPLinkLocalHost hostToChatWith)
+ public void sendHandshake()
{
- _chatWindow = cW;
- connect(hostToChatWith.getHost(),hostToChatWith.getPort());
+ try
+ {
+ _toRemoteHost.print("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
+ _toRemoteHost.print("<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0'>");
+ _toRemoteHost.flush();
+ _sentHandshake = true;
+ }
+ catch (Exception e)
+ {
+ System.out.println(e);
+ }
}
- public XMPPLinkLocalChatSession(ZeroFileChatWindow cW,Socket s)
+ public XMPPLinkLocalChatSession(XMPPLinkLocalHost hostToChatWith)
{
- _chatWindow = cW;
+ _chatWindow = new ZeroFileChatWindow(this);
try
{
- _s = s;
+ _s = new Socket(hostToChatWith.getHost(),hostToChatWith.getPort());
+ _toRemoteHost = new PrintWriter(_s.getOutputStream());
_fromRemoteHost = new InputStreamReader(_s.getInputStream());
- _toRemoteHost = new PrintWriter(_s.getOutputStream());
_remoteHostReadingThread.start();
- _toRemoteHost.print("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
- _toRemoteHost.print("<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0'>");
- _toRemoteHost.flush();
+ sendHandshake();
}
catch (Exception e)
{
@@ -54,29 +64,39 @@
}
}
- public void sendMessage(String m)
+ private void RecievedStanza(String stanza)
{
- _toRemoteHost.print("<message><body>"+m+"</body></message>");
- _toRemoteHost.flush();
+ RecievedMessage(stanza);
}
- public void connect(String host,int port)
+ private void RecievedMessage(String mess)
{
+ if (_chatWindow == null)
+ _chatWindow = new ZeroFileChatWindow(this);
+ _chatWindow.printText(mess);
+ }
+
+ public XMPPLinkLocalChatSession(Socket s)
+ {
+ _s = s;
try
{
- _s = new Socket(host,port);
_fromRemoteHost = new InputStreamReader(_s.getInputStream());
+ _remoteHostReadingThread.start();
_toRemoteHost = new PrintWriter(_s.getOutputStream());
- _remoteHostReadingThread.start();
- _toRemoteHost.print("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
- _toRemoteHost.print("<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0'>");
- _toRemoteHost.flush();
+ sendHandshake();
}
catch (Exception e)
{
System.out.println(e);
}
}
+
+ public void sendMessage(String m)
+ {
+ _toRemoteHost.print("<message><body>"+m+"</body></message>");
+ _toRemoteHost.flush();
+ }
public void disconnect()
{
Modified: trunk/src/XMPPSessionListener.java
===================================================================
--- trunk/src/XMPPSessionListener.java 2007-11-21 16:39:56 UTC (rev 55)
+++ trunk/src/XMPPSessionListener.java 2007-11-27 13:04:34 UTC (rev 56)
@@ -12,8 +12,8 @@
while(true)
{
Socket connection = _listeningSock.accept();
- new ZeroFileChatWindow(connection);
- //new XMPPLinkLocalChatSession(connection);
+ //new ZeroFileChatWindow(connection);
+ new XMPPLinkLocalChatSession(connection);
}
}
catch (Exception e)
Modified: trunk/src/ZeroFileChatWindow.java
===================================================================
--- trunk/src/ZeroFileChatWindow.java 2007-11-21 16:39:56 UTC (rev 55)
+++ trunk/src/ZeroFileChatWindow.java 2007-11-27 13:04:34 UTC (rev 56)
@@ -1,6 +1,5 @@
import java.awt.*;
import java.awt.event.*;
-import java.net.*;
import javax.swing.*;
@@ -14,7 +13,7 @@
private JTextField _entryTextField;
private JButton _sendButton;
private XMPPLinkLocalChatSession _session;
- public ZeroFileChatWindow(Socket sock)
+ /*public ZeroFileChatWindow(Socket sock)
{
this.ZeroFileChatWindowInit();
_session = new XMPPLinkLocalChatSession(this,sock);
@@ -25,6 +24,12 @@
hostToChatWith.updateData();
this.setWindowTitle(hostToChatWith.toString());
_session = new XMPPLinkLocalChatSession(this,hostToChatWith);
+ }*/
+
+ public ZeroFileChatWindow(XMPPLinkLocalChatSession sess)
+ {
+ this.ZeroFileChatWindowInit();
+ _session = sess;
}
public void setWindowTitle(String t)
Modified: trunk/src/ZeroFileMainWindow.java
===================================================================
--- trunk/src/ZeroFileMainWindow.java 2007-11-21 16:39:56 UTC (rev 55)
+++ trunk/src/ZeroFileMainWindow.java 2007-11-27 13:04:34 UTC (rev 56)
@@ -29,8 +29,8 @@
static void addHost(XMPPLinkLocalHost h)
{
- System.out.println("forsoker adda: " + h.toString());
- //h.updateData();
+ //System.out.println("forsoker adda: " + h.toString());
+ h.updateData();
_contactListModel.addElement(h);
}
@@ -122,8 +122,8 @@
public void mouseClicked(MouseEvent e)
{
if (e.getClickCount() == 2)
- new ZeroFileChatWindow((XMPPLinkLocalHost)_contactList.getSelectedValue());
- //new XMPPLinkLocalChatSession((XMPPLinkLocalHost)_contactList.getSelectedValue());
+ //new ZeroFileChatWindow((XMPPLinkLocalHost)_contactList.getSelectedValue());
+ new XMPPLinkLocalChatSession((XMPPLinkLocalHost)_contactList.getSelectedValue());
}
});
_mainWindowFrame.add(_contactList);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kar...@us...> - 2007-11-21 16:39:53
|
Revision: 55
http://zerofile.svn.sourceforge.net/zerofile/?rev=55&view=rev
Author: karl-bengtsson
Date: 2007-11-21 08:39:56 -0800 (Wed, 21 Nov 2007)
Log Message:
-----------
Bugfixes, simplifications, and refactoring of code (we're now back to the old model of the chat window owning the chat session, rather than the other way around).
Now recieved and sent messages are output to the chat window, rather than just the console. They are however still not parsed as proper XML, just dumped raw.
Needs to be done: XMPPLinkLocalChatSession class needs a thorough review and refactoring, our chat window needs to be prettified, and we need to start parsing xml.
Modified Paths:
--------------
trunk/src/XMPPLinkLocalChatSession.java
trunk/src/XMPPSessionListener.java
trunk/src/ZeroFile.java
trunk/src/ZeroFileChatWindow.java
trunk/src/ZeroFileMainWindow.java
trunk/src/ZeroconfBrowsing.java
Modified: trunk/src/XMPPLinkLocalChatSession.java
===================================================================
--- trunk/src/XMPPLinkLocalChatSession.java 2007-11-21 11:53:15 UTC (rev 54)
+++ trunk/src/XMPPLinkLocalChatSession.java 2007-11-21 16:39:56 UTC (rev 55)
@@ -6,12 +6,12 @@
*/
public class XMPPLinkLocalChatSession {
- //private XMPPLinkLocalHost _remoteHost;
private Socket _s;
private Reader _fromRemoteHost;
private PrintWriter _toRemoteHost;
private PrintWriter _toUser = new PrintWriter(System.out,true);
private ZeroFileChatWindow _chatWindow;
+
private Thread _remoteHostReadingThread = new Thread() {
public void run() {
char[] buffer = new char[1024];
@@ -21,23 +21,25 @@
{
_toUser.write(buffer,0,chars_read);
_toUser.flush();
+ _chatWindow.printText(String.valueOf(buffer));
}
}
catch (IOException e) {System.out.println(e);}
System.out.println("Connection closed!");
}
};
- public XMPPLinkLocalChatSession(XMPPLinkLocalHost hostToChatWith)
+
+ public XMPPLinkLocalChatSession(ZeroFileChatWindow cW,XMPPLinkLocalHost hostToChatWith)
{
- //_remoteHost = hostToChatWith;
+ _chatWindow = cW;
connect(hostToChatWith.getHost(),hostToChatWith.getPort());
- _chatWindow = new ZeroFileChatWindow(this);
}
- public XMPPLinkLocalChatSession(Socket s)
+
+ public XMPPLinkLocalChatSession(ZeroFileChatWindow cW,Socket s)
{
+ _chatWindow = cW;
try
{
- //_remoteHost = XMPPLinkLocalHost();
_s = s;
_fromRemoteHost = new InputStreamReader(_s.getInputStream());
_toRemoteHost = new PrintWriter(_s.getOutputStream());
@@ -45,28 +47,23 @@
_toRemoteHost.print("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
_toRemoteHost.print("<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0'>");
_toRemoteHost.flush();
- _chatWindow = new ZeroFileChatWindow(this);
}
catch (Exception e)
{
System.out.println(e);
}
}
+
public void sendMessage(String m)
{
_toRemoteHost.print("<message><body>"+m+"</body></message>");
_toRemoteHost.flush();
- //System.out.println(m);
- /*int port = _remoteHost.getPort();
- String hostName = _remoteHost.getHost();
- System.out.println("The text \"" + m + "\" should now be sent to:");
- System.out.println(hostName + ":" + port);*/
}
+
public void connect(String host,int port)
{
try
{
- //_s = new Socket(_remoteHost.getHost(),_remoteHost.getPort());
_s = new Socket(host,port);
_fromRemoteHost = new InputStreamReader(_s.getInputStream());
_toRemoteHost = new PrintWriter(_s.getOutputStream());
@@ -74,17 +71,13 @@
_toRemoteHost.print("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
_toRemoteHost.print("<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0'>");
_toRemoteHost.flush();
- //_toRemoteHost.print(s);
}
catch (Exception e)
{
System.out.println(e);
}
}
- /*public XMPPLinkLocalHost getRemoteHost()
- {
- return _remoteHost;
- }*/
+
public void disconnect()
{
try
Modified: trunk/src/XMPPSessionListener.java
===================================================================
--- trunk/src/XMPPSessionListener.java 2007-11-21 11:53:15 UTC (rev 54)
+++ trunk/src/XMPPSessionListener.java 2007-11-21 16:39:56 UTC (rev 55)
@@ -1,4 +1,3 @@
-import java.io.*;
import java.net.*;
public class XMPPSessionListener {
@@ -13,7 +12,8 @@
while(true)
{
Socket connection = _listeningSock.accept();
- new XMPPLinkLocalChatSession(connection);
+ new ZeroFileChatWindow(connection);
+ //new XMPPLinkLocalChatSession(connection);
}
}
catch (Exception e)
Modified: trunk/src/ZeroFile.java
===================================================================
--- trunk/src/ZeroFile.java 2007-11-21 11:53:15 UTC (rev 54)
+++ trunk/src/ZeroFile.java 2007-11-21 16:39:56 UTC (rev 55)
@@ -11,7 +11,6 @@
ZeroFileSettings.loadSettings();
try
{
- ZeroFileSettings.loadSettings();
ZeroconfRegistration.registerService();
XMPPSessionListener.startListening(ZeroFileSettings.getMainPort());
ZeroconfRegistration.set1st(ZeroFileSettings.getFirstName());
Modified: trunk/src/ZeroFileChatWindow.java
===================================================================
--- trunk/src/ZeroFileChatWindow.java 2007-11-21 11:53:15 UTC (rev 54)
+++ trunk/src/ZeroFileChatWindow.java 2007-11-21 16:39:56 UTC (rev 55)
@@ -1,5 +1,6 @@
import java.awt.*;
import java.awt.event.*;
+import java.net.*;
import javax.swing.*;
@@ -13,12 +14,32 @@
private JTextField _entryTextField;
private JButton _sendButton;
private XMPPLinkLocalChatSession _session;
- public ZeroFileChatWindow(XMPPLinkLocalChatSession chatSession)
+ public ZeroFileChatWindow(Socket sock)
{
- _session = chatSession;
- //_session.getRemoteHost().updateData();
+ this.ZeroFileChatWindowInit();
+ _session = new XMPPLinkLocalChatSession(this,sock);
+ }
+ public ZeroFileChatWindow(XMPPLinkLocalHost hostToChatWith)
+ {
+ this.ZeroFileChatWindowInit();
+ hostToChatWith.updateData();
+ this.setWindowTitle(hostToChatWith.toString());
+ _session = new XMPPLinkLocalChatSession(this,hostToChatWith);
+ }
+
+ public void setWindowTitle(String t)
+ {
+ _chatWindowFrame.setTitle(t);
+ }
+
+ public void printText(String s)
+ {
+ _chatTextArea.append("\n"+s);
+ }
+
+ private void ZeroFileChatWindowInit()
+ {
_chatWindowFrame = new JFrame();
- //_chatWindowFrame.setTitle(_session.getRemoteHost().toString());
_chatWindowFrame.setLayout(new GridLayout(0,1,1,1));
_chatWindowFrame.setLocation(0,400);
_chatWindowFrame.setSize(new Dimension(300,200));
@@ -35,7 +56,9 @@
_sendButton.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent sendButtonPress){
- _session.sendMessage(_entryTextField.getText());
+ String message = _entryTextField.getText();
+ printText(message);
+ _session.sendMessage(message);
_entryTextField.setText("");
}
}
Modified: trunk/src/ZeroFileMainWindow.java
===================================================================
--- trunk/src/ZeroFileMainWindow.java 2007-11-21 11:53:15 UTC (rev 54)
+++ trunk/src/ZeroFileMainWindow.java 2007-11-21 16:39:56 UTC (rev 55)
@@ -16,8 +16,8 @@
private static JMenu _helpMenu;
private static JMenuItem _aboutMenuItem;
private static JComboBox _statusLista;
- private static DefaultListModel _contactListModel;
- private static JList _contactList;
+ private static DefaultListModel _contactListModel = new DefaultListModel();;
+ private static JList _contactList = new JList(_contactListModel);;
static boolean containsHost(XMPPLinkLocalHost h)
{
@@ -29,6 +29,8 @@
static void addHost(XMPPLinkLocalHost h)
{
+ System.out.println("forsoker adda: " + h.toString());
+ //h.updateData();
_contactListModel.addElement(h);
}
@@ -95,8 +97,8 @@
});
// Contact list
- _contactListModel = new DefaultListModel();
- _contactList = new JList(_contactListModel);
+ //_contactListModel = new DefaultListModel();
+ //_contactList = new JList(_contactListModel);
_contactList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
_contactList.setLayoutOrientation(JList.VERTICAL);
_contactList.setSize(500,700);
@@ -120,7 +122,8 @@
public void mouseClicked(MouseEvent e)
{
if (e.getClickCount() == 2)
- new XMPPLinkLocalChatSession((XMPPLinkLocalHost)_contactList.getSelectedValue());
+ new ZeroFileChatWindow((XMPPLinkLocalHost)_contactList.getSelectedValue());
+ //new XMPPLinkLocalChatSession((XMPPLinkLocalHost)_contactList.getSelectedValue());
}
});
_mainWindowFrame.add(_contactList);
Modified: trunk/src/ZeroconfBrowsing.java
===================================================================
--- trunk/src/ZeroconfBrowsing.java 2007-11-21 11:53:15 UTC (rev 54)
+++ trunk/src/ZeroconfBrowsing.java 2007-11-21 16:39:56 UTC (rev 55)
@@ -15,10 +15,11 @@
String name, String regType, String domain)
{
XMPPLinkLocalHost newHost = new XMPPLinkLocalHost(name);
+ newHost.updateData();
if (!ZeroFileMainWindow.containsHost(newHost) && !ZeroconfRegistration.getMyServiceName().equals(name))
{
- newHost.updateData();
ZeroFileMainWindow.addHost(newHost);
+ System.out.println("hittat servicename: " + name);
}
}
public void serviceLost(DNSSDService browser, int flags, int ifIndex,
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kar...@us...> - 2007-11-21 11:53:10
|
Revision: 54
http://zerofile.svn.sourceforge.net/zerofile/?rev=54&view=rev
Author: karl-bengtsson
Date: 2007-11-21 03:53:15 -0800 (Wed, 21 Nov 2007)
Log Message:
-----------
Ugly as fuck patch to solve the problem of our registered service name not being set until after browsing begins - getMyServiceName now sleeps until service name is set. DO NOT CALL GETMYSERVICENAME() WITHOUT HAVING STARTED REGISTRATION OR YOU WILL DIE
Modified Paths:
--------------
trunk/src/ZeroconfBrowsing.java
trunk/src/ZeroconfRegistration.java
Modified: trunk/src/ZeroconfBrowsing.java
===================================================================
--- trunk/src/ZeroconfBrowsing.java 2007-11-21 11:01:21 UTC (rev 53)
+++ trunk/src/ZeroconfBrowsing.java 2007-11-21 11:53:15 UTC (rev 54)
@@ -15,7 +15,7 @@
String name, String regType, String domain)
{
XMPPLinkLocalHost newHost = new XMPPLinkLocalHost(name);
- if (!ZeroFileMainWindow.containsHost(newHost) && !ZeroFile.getServiceName().equals(name))
+ if (!ZeroFileMainWindow.containsHost(newHost) && !ZeroconfRegistration.getMyServiceName().equals(name))
{
newHost.updateData();
ZeroFileMainWindow.addHost(newHost);
Modified: trunk/src/ZeroconfRegistration.java
===================================================================
--- trunk/src/ZeroconfRegistration.java 2007-11-21 11:01:21 UTC (rev 53)
+++ trunk/src/ZeroconfRegistration.java 2007-11-21 11:53:15 UTC (rev 54)
@@ -9,23 +9,20 @@
{
private static TXTRecord _txtRecord = new TXTRecord();
private static DNSSDRegistration _r;
+ private static String _myServiceName;
static void registerService(String status,int port)
throws DNSSDException, InterruptedException
{
- _r = DNSSD.register(ZeroFile.getServiceName(), "_presence._tcp", port, new RegisterListener()
+ _r = DNSSD.register(null, "_presence._tcp", port, new RegisterListener()
{
public void serviceRegistered(DNSSDRegistration registration, int flags,
String serviceName, String regType, String domain)
{
- // TODO
- System.out.println("Registered Name : " + serviceName);
- System.out.println(" Type : " + regType);
- System.out.println(" Domain: " + domain);
+ _myServiceName = serviceName;
}
public void operationFailed(DNSSDService service, int errorCode)
{
- // TODO
System.out.println("Registration failed: " + errorCode);
}
});
@@ -36,6 +33,17 @@
_r.getTXTRecord().update(0, _txtRecord.getRawBytes(), 0);
}
+ public static String getMyServiceName()
+ {
+ while (_myServiceName == null)
+ try {
+ Thread.sleep(50);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ return _myServiceName;
+ }
+
static void registerService(int port)
throws DNSSDException, InterruptedException
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kar...@us...> - 2007-11-21 11:01:16
|
Revision: 53
http://zerofile.svn.sourceforge.net/zerofile/?rev=53&view=rev
Author: karl-bengtsson
Date: 2007-11-21 03:01:21 -0800 (Wed, 21 Nov 2007)
Log Message:
-----------
Missed committing this crusial file last time.
Added Paths:
-----------
trunk/src/XMPPSessionListener.java
Added: trunk/src/XMPPSessionListener.java
===================================================================
--- trunk/src/XMPPSessionListener.java (rev 0)
+++ trunk/src/XMPPSessionListener.java 2007-11-21 11:01:21 UTC (rev 53)
@@ -0,0 +1,38 @@
+import java.io.*;
+import java.net.*;
+
+public class XMPPSessionListener {
+ static private ServerSocket _listeningSock;
+
+ private static Thread _listenerThread = new Thread()
+ {
+ public void run()
+ {
+ try
+ {
+ while(true)
+ {
+ Socket connection = _listeningSock.accept();
+ new XMPPLinkLocalChatSession(connection);
+ }
+ }
+ catch (Exception e)
+ {
+ System.out.println(e);
+ }
+ }
+ };
+
+ public static void startListening(int portNr)
+ {
+ try
+ {
+ _listeningSock = new ServerSocket(portNr);
+ _listenerThread.start();
+ }
+ catch (Exception e)
+ {
+ System.out.println(e);
+ }
+ }
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kar...@us...> - 2007-11-21 11:00:01
|
Revision: 52
http://zerofile.svn.sourceforge.net/zerofile/?rev=52&view=rev
Author: karl-bengtsson
Date: 2007-11-21 03:00:01 -0800 (Wed, 21 Nov 2007)
Log Message:
-----------
We now listen for incoming connections, and when such connections are recieved, establish a socket and a chat window etc. All text is still output in raw format to the console.
Modified Paths:
--------------
trunk/src/XMPPLinkLocalChatSession.java
trunk/src/ZeroFile.java
trunk/src/ZeroFileChatWindow.java
trunk/src/ZeroFileSettings.java
trunk/src/ZeroFileSettingsWindow.java
trunk/src/ZeroconfRegistration.java
Modified: trunk/src/XMPPLinkLocalChatSession.java
===================================================================
--- trunk/src/XMPPLinkLocalChatSession.java 2007-11-13 14:49:17 UTC (rev 51)
+++ trunk/src/XMPPLinkLocalChatSession.java 2007-11-21 11:00:01 UTC (rev 52)
@@ -6,7 +6,7 @@
*/
public class XMPPLinkLocalChatSession {
- private XMPPLinkLocalHost _remoteHost;
+ //private XMPPLinkLocalHost _remoteHost;
private Socket _s;
private Reader _fromRemoteHost;
private PrintWriter _toRemoteHost;
@@ -29,10 +29,29 @@
};
public XMPPLinkLocalChatSession(XMPPLinkLocalHost hostToChatWith)
{
- _remoteHost = hostToChatWith;
- connect();
+ //_remoteHost = hostToChatWith;
+ connect(hostToChatWith.getHost(),hostToChatWith.getPort());
_chatWindow = new ZeroFileChatWindow(this);
}
+ public XMPPLinkLocalChatSession(Socket s)
+ {
+ try
+ {
+ //_remoteHost = XMPPLinkLocalHost();
+ _s = s;
+ _fromRemoteHost = new InputStreamReader(_s.getInputStream());
+ _toRemoteHost = new PrintWriter(_s.getOutputStream());
+ _remoteHostReadingThread.start();
+ _toRemoteHost.print("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
+ _toRemoteHost.print("<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0'>");
+ _toRemoteHost.flush();
+ _chatWindow = new ZeroFileChatWindow(this);
+ }
+ catch (Exception e)
+ {
+ System.out.println(e);
+ }
+ }
public void sendMessage(String m)
{
_toRemoteHost.print("<message><body>"+m+"</body></message>");
@@ -43,11 +62,12 @@
System.out.println("The text \"" + m + "\" should now be sent to:");
System.out.println(hostName + ":" + port);*/
}
- public void connect()
+ public void connect(String host,int port)
{
try
{
- _s = new Socket(_remoteHost.getHost(),_remoteHost.getPort());
+ //_s = new Socket(_remoteHost.getHost(),_remoteHost.getPort());
+ _s = new Socket(host,port);
_fromRemoteHost = new InputStreamReader(_s.getInputStream());
_toRemoteHost = new PrintWriter(_s.getOutputStream());
_remoteHostReadingThread.start();
@@ -61,10 +81,10 @@
System.out.println(e);
}
}
- public XMPPLinkLocalHost getRemoteHost()
+ /*public XMPPLinkLocalHost getRemoteHost()
{
return _remoteHost;
- }
+ }*/
public void disconnect()
{
try
Modified: trunk/src/ZeroFile.java
===================================================================
--- trunk/src/ZeroFile.java 2007-11-13 14:49:17 UTC (rev 51)
+++ trunk/src/ZeroFile.java 2007-11-21 11:00:01 UTC (rev 52)
@@ -11,8 +11,9 @@
ZeroFileSettings.loadSettings();
try
{
+ ZeroFileSettings.loadSettings();
ZeroconfRegistration.registerService();
- ZeroFileSettings.loadSettings();
+ XMPPSessionListener.startListening(ZeroFileSettings.getMainPort());
ZeroconfRegistration.set1st(ZeroFileSettings.getFirstName());
ZeroconfRegistration.setLast(ZeroFileSettings.getLastName());
ZeroconfRegistration.setEmail(ZeroFileSettings.getEmail());
Modified: trunk/src/ZeroFileChatWindow.java
===================================================================
--- trunk/src/ZeroFileChatWindow.java 2007-11-13 14:49:17 UTC (rev 51)
+++ trunk/src/ZeroFileChatWindow.java 2007-11-21 11:00:01 UTC (rev 52)
@@ -16,9 +16,9 @@
public ZeroFileChatWindow(XMPPLinkLocalChatSession chatSession)
{
_session = chatSession;
- _session.getRemoteHost().updateData();
+ //_session.getRemoteHost().updateData();
_chatWindowFrame = new JFrame();
- _chatWindowFrame.setTitle(_session.getRemoteHost().toString());
+ //_chatWindowFrame.setTitle(_session.getRemoteHost().toString());
_chatWindowFrame.setLayout(new GridLayout(0,1,1,1));
_chatWindowFrame.setLocation(0,400);
_chatWindowFrame.setSize(new Dimension(300,200));
Modified: trunk/src/ZeroFileSettings.java
===================================================================
--- trunk/src/ZeroFileSettings.java 2007-11-13 14:49:17 UTC (rev 51)
+++ trunk/src/ZeroFileSettings.java 2007-11-21 11:00:01 UTC (rev 52)
@@ -60,15 +60,15 @@
_zeroFileProperties.put("Email", e);
}
- public static String getMainPort() {
+ public static int getMainPort() {
if (_zeroFileProperties.containsKey("Port"))
- return _zeroFileProperties.getProperty("Port");
+ return Integer.valueOf(_zeroFileProperties.getProperty("Port"));
else
- return "1337";
+ return 5222;
}
- public static void setMainPort(String p)
+ public static void setMainPort(int p)
{
- _zeroFileProperties.put("Port", p);
+ _zeroFileProperties.put("Port", String.valueOf(p));
}
public static void setCheckBox(String p)
Modified: trunk/src/ZeroFileSettingsWindow.java
===================================================================
--- trunk/src/ZeroFileSettingsWindow.java 2007-11-13 14:49:17 UTC (rev 51)
+++ trunk/src/ZeroFileSettingsWindow.java 2007-11-21 11:00:01 UTC (rev 52)
@@ -49,7 +49,7 @@
//Label + field for port parameter
JLabel portLabel = new JLabel("Port", JLabel.CENTER);
final JTextField portField = new JTextField();
- portField.setText(ZeroFileSettings.getMainPort());
+ portField.setText(String.valueOf(ZeroFileSettings.getMainPort()));
settingsWindowFrame.add(portLabel);
settingsWindowFrame.add(portField);
@@ -104,7 +104,7 @@
if(!emailField.getText().equals(""))
ZeroFileSettings.setEmail(emailField.getText());
if(!portField.getText().equals(""))
- ZeroFileSettings.setMainPort(portField.getText());
+ ZeroFileSettings.setMainPort(Integer.valueOf(portField.getText()));
if(!pathNowLabel.getText().equals(""))
ZeroFileSettings.setDownloadFolder(pathNowLabel.getText());
ZeroFileSettings.setCheckBox(String.valueOf(checkBoxTransfer.isSelected()));
Modified: trunk/src/ZeroconfRegistration.java
===================================================================
--- trunk/src/ZeroconfRegistration.java 2007-11-13 14:49:17 UTC (rev 51)
+++ trunk/src/ZeroconfRegistration.java 2007-11-21 11:00:01 UTC (rev 52)
@@ -45,7 +45,7 @@
static void registerService()
throws DNSSDException, InterruptedException
{
- ZeroconfRegistration.registerService(5222);
+ ZeroconfRegistration.registerService(ZeroFileSettings.getMainPort());
}
static void unregisterService()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kar...@us...> - 2007-11-13 14:49:25
|
Revision: 51
http://zerofile.svn.sourceforge.net/zerofile/?rev=51&view=rev
Author: karl-bengtsson
Date: 2007-11-13 06:49:17 -0800 (Tue, 13 Nov 2007)
Log Message:
-----------
We now have a more descriptive service name, based on the host name of our system. This is gotten through a static method in the main ZeroFile class.
We also now don't list ourselves in the contact list.
Modified Paths:
--------------
trunk/src/ZeroFile.java
trunk/src/ZeroFileMainWindow.java
trunk/src/ZeroconfBrowsing.java
trunk/src/ZeroconfRegistration.java
Modified: trunk/src/ZeroFile.java
===================================================================
--- trunk/src/ZeroFile.java 2007-11-13 14:20:20 UTC (rev 50)
+++ trunk/src/ZeroFile.java 2007-11-13 14:49:17 UTC (rev 51)
@@ -1,4 +1,5 @@
import java.io.IOException;
+import java.net.InetAddress;
public class ZeroFile {
/**
@@ -23,4 +24,19 @@
System.exit(-1);
}
}
+
+ public static String getServiceName()
+ {
+ String serviceName = "serviceName";
+ try
+ {
+ InetAddress localMachine = InetAddress.getLocalHost();
+ serviceName = localMachine.getHostName();
+ }
+ catch (Exception e)
+ {
+ System.out.println(e);
+ }
+ return serviceName;
+ }
}
Modified: trunk/src/ZeroFileMainWindow.java
===================================================================
--- trunk/src/ZeroFileMainWindow.java 2007-11-13 14:20:20 UTC (rev 50)
+++ trunk/src/ZeroFileMainWindow.java 2007-11-13 14:49:17 UTC (rev 51)
@@ -82,6 +82,17 @@
_statusLista = new JComboBox(statusModes);
_statusLista.setMaximumSize(new Dimension(20,100));
_mainWindowFrame.add(_statusLista);
+ _statusLista.addItemListener(new ItemListener(){
+ public void itemStateChanged(ItemEvent e)
+ {
+ if (_statusLista.getSelectedItem().equals("Available"))
+ ZeroconfRegistration.setStatus("avail");
+ else if (_statusLista.getSelectedItem().equals("Away"))
+ ZeroconfRegistration.setStatus("away");
+ else
+ ZeroconfRegistration.setStatus("dnd");
+ }
+ });
// Contact list
_contactListModel = new DefaultListModel();
Modified: trunk/src/ZeroconfBrowsing.java
===================================================================
--- trunk/src/ZeroconfBrowsing.java 2007-11-13 14:20:20 UTC (rev 50)
+++ trunk/src/ZeroconfBrowsing.java 2007-11-13 14:49:17 UTC (rev 51)
@@ -15,7 +15,7 @@
String name, String regType, String domain)
{
XMPPLinkLocalHost newHost = new XMPPLinkLocalHost(name);
- if (!ZeroFileMainWindow.containsHost(newHost))
+ if (!ZeroFileMainWindow.containsHost(newHost) && !ZeroFile.getServiceName().equals(name))
{
newHost.updateData();
ZeroFileMainWindow.addHost(newHost);
Modified: trunk/src/ZeroconfRegistration.java
===================================================================
--- trunk/src/ZeroconfRegistration.java 2007-11-13 14:20:20 UTC (rev 50)
+++ trunk/src/ZeroconfRegistration.java 2007-11-13 14:49:17 UTC (rev 51)
@@ -13,7 +13,7 @@
static void registerService(String status,int port)
throws DNSSDException, InterruptedException
{
- _r = DNSSD.register("servicename", "_presence._tcp", port, new RegisterListener()
+ _r = DNSSD.register(ZeroFile.getServiceName(), "_presence._tcp", port, new RegisterListener()
{
public void serviceRegistered(DNSSDRegistration registration, int flags,
String serviceName, String regType, String domain)
@@ -60,13 +60,19 @@
}
static void setStatus(String s)
- throws DNSSDException, InterruptedException
{
- if (_r != null)
+ try
{
- _txtRecord.set("status", s);
- _r.getTXTRecord().update(0, _txtRecord.getRawBytes(), 0);
+ if (_r != null)
+ {
+ _txtRecord.set("status", s);
+ _r.getTXTRecord().update(0, _txtRecord.getRawBytes(), 0);
+ }
}
+ catch (Exception e)
+ {
+ System.out.println(e);
+ }
}
static String getEmail()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kar...@us...> - 2007-11-13 14:20:26
|
Revision: 50
http://zerofile.svn.sourceforge.net/zerofile/?rev=50&view=rev
Author: karl-bengtsson
Date: 2007-11-13 06:20:20 -0800 (Tue, 13 Nov 2007)
Log Message:
-----------
Closing the chat window now properly ends the chat session and closes the socket.
Modified Paths:
--------------
trunk/src/XMPPLinkLocalChatSession.java
trunk/src/ZeroFileChatWindow.java
Modified: trunk/src/XMPPLinkLocalChatSession.java
===================================================================
--- trunk/src/XMPPLinkLocalChatSession.java 2007-11-13 13:58:06 UTC (rev 49)
+++ trunk/src/XMPPLinkLocalChatSession.java 2007-11-13 14:20:20 UTC (rev 50)
@@ -67,6 +67,15 @@
}
public void disconnect()
{
- // TODO - disconnect from host
+ try
+ {
+ _toRemoteHost.print("</stream:stream>");
+ _toRemoteHost.flush();
+ _s.close();
+ }
+ catch (Exception e)
+ {
+ System.out.println(e);
+ }
}
}
Modified: trunk/src/ZeroFileChatWindow.java
===================================================================
--- trunk/src/ZeroFileChatWindow.java 2007-11-13 13:58:06 UTC (rev 49)
+++ trunk/src/ZeroFileChatWindow.java 2007-11-13 14:20:20 UTC (rev 50)
@@ -1,6 +1,5 @@
import java.awt.*;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
+import java.awt.event.*;
import javax.swing.*;
@@ -37,8 +36,40 @@
new ActionListener(){
public void actionPerformed(ActionEvent sendButtonPress){
_session.sendMessage(_entryTextField.getText());
+ _entryTextField.setText("");
}
}
);
+ _chatWindowFrame.addWindowListener(new WindowListener(){
+ public void windowClosing(WindowEvent e)
+ {
+
+ }
+ public void windowDeiconified(WindowEvent e)
+ {
+
+ }
+ public void windowActivated(WindowEvent e)
+ {
+
+ }
+ public void windowDeactivated(WindowEvent e)
+ {
+
+ }
+ public void windowClosed(WindowEvent e)
+ {
+ _session.disconnect();
+ }
+ public void windowIconified(WindowEvent e)
+ {
+
+ }
+ public void windowOpened(WindowEvent e)
+ {
+
+ }
+ });
+ _entryTextField.requestFocusInWindow();
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kar...@us...> - 2007-11-13 13:58:20
|
Revision: 49
http://zerofile.svn.sourceforge.net/zerofile/?rev=49&view=rev
Author: karl-bengtsson
Date: 2007-11-13 05:58:06 -0800 (Tue, 13 Nov 2007)
Log Message:
-----------
Stored settings are now registered with Bonjour
Modified Paths:
--------------
trunk/src/ZeroFile.java
Modified: trunk/src/ZeroFile.java
===================================================================
--- trunk/src/ZeroFile.java 2007-11-13 13:55:03 UTC (rev 48)
+++ trunk/src/ZeroFile.java 2007-11-13 13:58:06 UTC (rev 49)
@@ -11,8 +11,10 @@
try
{
ZeroconfRegistration.registerService();
- ZeroconfRegistration.set1st("Testar");
- ZeroconfRegistration.setLast("Nisse");
+ ZeroFileSettings.loadSettings();
+ ZeroconfRegistration.set1st(ZeroFileSettings.getFirstName());
+ ZeroconfRegistration.setLast(ZeroFileSettings.getLastName());
+ ZeroconfRegistration.setEmail(ZeroFileSettings.getEmail());
ZeroconfBrowsing.startBrowsing();
}
catch(Exception e)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kar...@us...> - 2007-11-13 13:55:21
|
Revision: 48
http://zerofile.svn.sourceforge.net/zerofile/?rev=48&view=rev
Author: karl-bengtsson
Date: 2007-11-13 05:55:03 -0800 (Tue, 13 Nov 2007)
Log Message:
-----------
We can now send messages, and read them out to the console. Parsing is required, as is fault tolerance, etc etc. Yay!
Modified Paths:
--------------
trunk/src/XMPPLinkLocalChatSession.java
trunk/src/ZeroFileChatWindow.java
trunk/src/ZeroFileMainWindow.java
Modified: trunk/src/XMPPLinkLocalChatSession.java
===================================================================
--- trunk/src/XMPPLinkLocalChatSession.java 2007-11-10 12:51:28 UTC (rev 47)
+++ trunk/src/XMPPLinkLocalChatSession.java 2007-11-13 13:55:03 UTC (rev 48)
@@ -1,3 +1,6 @@
+import java.io.*;
+import java.net.*;
+
/*
* Class for handling chat sessions.
*/
@@ -4,22 +7,64 @@
public class XMPPLinkLocalChatSession {
private XMPPLinkLocalHost _remoteHost;
+ private Socket _s;
+ private Reader _fromRemoteHost;
+ private PrintWriter _toRemoteHost;
+ private PrintWriter _toUser = new PrintWriter(System.out,true);
+ private ZeroFileChatWindow _chatWindow;
+ private Thread _remoteHostReadingThread = new Thread() {
+ public void run() {
+ char[] buffer = new char[1024];
+ int chars_read;
+ try {
+ while ((chars_read = _fromRemoteHost.read(buffer)) != -1)
+ {
+ _toUser.write(buffer,0,chars_read);
+ _toUser.flush();
+ }
+ }
+ catch (IOException e) {System.out.println(e);}
+ System.out.println("Connection closed!");
+ }
+ };
public XMPPLinkLocalChatSession(XMPPLinkLocalHost hostToChatWith)
{
_remoteHost = hostToChatWith;
connect();
+ _chatWindow = new ZeroFileChatWindow(this);
}
public void sendMessage(String m)
{
- int port = _remoteHost.getPort();
+ _toRemoteHost.print("<message><body>"+m+"</body></message>");
+ _toRemoteHost.flush();
+ //System.out.println(m);
+ /*int port = _remoteHost.getPort();
String hostName = _remoteHost.getHost();
System.out.println("The text \"" + m + "\" should now be sent to:");
- System.out.println(hostName + ":" + port);
+ System.out.println(hostName + ":" + port);*/
}
public void connect()
{
- // TODO - establish connection to host
+ try
+ {
+ _s = new Socket(_remoteHost.getHost(),_remoteHost.getPort());
+ _fromRemoteHost = new InputStreamReader(_s.getInputStream());
+ _toRemoteHost = new PrintWriter(_s.getOutputStream());
+ _remoteHostReadingThread.start();
+ _toRemoteHost.print("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
+ _toRemoteHost.print("<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0'>");
+ _toRemoteHost.flush();
+ //_toRemoteHost.print(s);
+ }
+ catch (Exception e)
+ {
+ System.out.println(e);
+ }
}
+ public XMPPLinkLocalHost getRemoteHost()
+ {
+ return _remoteHost;
+ }
public void disconnect()
{
// TODO - disconnect from host
Modified: trunk/src/ZeroFileChatWindow.java
===================================================================
--- trunk/src/ZeroFileChatWindow.java 2007-11-10 12:51:28 UTC (rev 47)
+++ trunk/src/ZeroFileChatWindow.java 2007-11-13 13:55:03 UTC (rev 48)
@@ -14,12 +14,12 @@
private JTextField _entryTextField;
private JButton _sendButton;
private XMPPLinkLocalChatSession _session;
- public ZeroFileChatWindow(XMPPLinkLocalHost chatPartner)
+ public ZeroFileChatWindow(XMPPLinkLocalChatSession chatSession)
{
- chatPartner.updateData();
- _session = new XMPPLinkLocalChatSession(chatPartner);
+ _session = chatSession;
+ _session.getRemoteHost().updateData();
_chatWindowFrame = new JFrame();
- _chatWindowFrame.setTitle(chatPartner.toString());
+ _chatWindowFrame.setTitle(_session.getRemoteHost().toString());
_chatWindowFrame.setLayout(new GridLayout(0,1,1,1));
_chatWindowFrame.setLocation(0,400);
_chatWindowFrame.setSize(new Dimension(300,200));
Modified: trunk/src/ZeroFileMainWindow.java
===================================================================
--- trunk/src/ZeroFileMainWindow.java 2007-11-10 12:51:28 UTC (rev 47)
+++ trunk/src/ZeroFileMainWindow.java 2007-11-13 13:55:03 UTC (rev 48)
@@ -109,7 +109,7 @@
public void mouseClicked(MouseEvent e)
{
if (e.getClickCount() == 2)
- new ZeroFileChatWindow((XMPPLinkLocalHost)_contactList.getSelectedValue());
+ new XMPPLinkLocalChatSession((XMPPLinkLocalHost)_contactList.getSelectedValue());
}
});
_mainWindowFrame.add(_contactList);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kar...@us...> - 2007-11-10 12:51:32
|
Revision: 47
http://zerofile.svn.sourceforge.net/zerofile/?rev=47&view=rev
Author: karl-bengtsson
Date: 2007-11-10 04:51:28 -0800 (Sat, 10 Nov 2007)
Log Message:
-----------
Removed deprecated class ZeroconfResolving
Removed Paths:
-------------
trunk/src/ZeroconfResolving.java
Deleted: trunk/src/ZeroconfResolving.java
===================================================================
--- trunk/src/ZeroconfResolving.java 2007-11-10 12:45:32 UTC (rev 46)
+++ trunk/src/ZeroconfResolving.java 2007-11-10 12:51:28 UTC (rev 47)
@@ -1,35 +0,0 @@
-import com.apple.dnssd.*;
-
-/*
- * A static class with methods for resolving hosts once we've found them
- */
-
-public class ZeroconfResolving {
- private static DNSSDService _r;
- static void getHost(String serviceName)
- throws DNSSDException, InterruptedException
- {
- _r = DNSSD.resolve(0, DNSSD.ALL_INTERFACES, serviceName, "_presence._tcp", "local", new ResolveListener()
- {
- public void operationFailed(DNSSDService service,int errorCode)
- {
- System.out.println("Resolved failed " + errorCode);
- System.exit(-1);
- }
- public void serviceResolved(DNSSDService resolver, int flags, int ifIndex,
- String fullName, String hostName, int port, TXTRecord txtRecord)
- {
- System.out.println("Host resolved: " + hostName + ":" + port);
- System.out.println("Flags: " + flags + ", ifIndex: " + ifIndex + ", FQDN: " + fullName);
- for (int i = 0; i < txtRecord.size(); i++)
- {
- String key = txtRecord.getKey(i);
- String value = txtRecord.getValueAsString(i);
- if (key.length() > 0)
- System.out.println("\t" + key + "=" + value);
- }
- _r.stop();
- }
- });
- }
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kar...@us...> - 2007-11-10 12:45:37
|
Revision: 46
http://zerofile.svn.sourceforge.net/zerofile/?rev=46&view=rev
Author: karl-bengtsson
Date: 2007-11-10 04:45:32 -0800 (Sat, 10 Nov 2007)
Log Message:
-----------
A lot of changes in this update. Essentially now we can launch a chat window by doubleclicking on a person, and text messages can be passed along to an empty stub method (which prints them to the console), paving the way for real network messaging with some more work.
*) removed appProperties from SVN synchronisation in eclipse project properties - this means that your testing settings won't be overwritten when doing an update from the SVN repo.
*) renamed the XMPPLinkLocalSession class to XMPPLinkLocalChatSession - it's a bit longer and a bit more unwieldy to type, but it clarifies what it is that this class represents.
*) Made some previously static classes (ZeroFileChatWindow, XMPPLinkLocalChatSession) into normal instantiable classes.
*) Added a few stub methods to XMPPLinkLocalChatSession, so that we have some sort of API for sending messages over the network. This will need to be expanded upon.
*) Made an instance of XMPPLinkLocalChatSession a private attribute of ZeroFileChatWindow - this means that each instantiated chat window will be tied to exactly one chat session. The constructor for the chat window now requires an XMPPLinkLocalHost type argument which gets passed along to this session in its constructor, so that the session in turn is tied to a particular host, just the way it should be. The name of this host also gets displayed in the chat window title bar.
*) Added mouse listeners for the contact list in the main window so that a new chat window is launched when a user doubleclicks a person in their contact list. I'm uncertain as to the stability of this piece of code, so it may need further review.
Modified Paths:
--------------
trunk/src/ZeroFile.java
trunk/src/ZeroFileChatWindow.java
trunk/src/ZeroFileMainWindow.java
Added Paths:
-----------
trunk/src/XMPPLinkLocalChatSession.java
Removed Paths:
-------------
trunk/src/XMPPLinkLocalSession.java
Property Changed:
----------------
trunk/
Property changes on: trunk
___________________________________________________________________
Name: svn:ignore
+ appProperties
Copied: trunk/src/XMPPLinkLocalChatSession.java (from rev 45, trunk/src/XMPPLinkLocalSession.java)
===================================================================
--- trunk/src/XMPPLinkLocalChatSession.java (rev 0)
+++ trunk/src/XMPPLinkLocalChatSession.java 2007-11-10 12:45:32 UTC (rev 46)
@@ -0,0 +1,27 @@
+/*
+ * Class for handling chat sessions.
+ */
+
+public class XMPPLinkLocalChatSession {
+ private XMPPLinkLocalHost _remoteHost;
+ public XMPPLinkLocalChatSession(XMPPLinkLocalHost hostToChatWith)
+ {
+ _remoteHost = hostToChatWith;
+ connect();
+ }
+ public void sendMessage(String m)
+ {
+ int port = _remoteHost.getPort();
+ String hostName = _remoteHost.getHost();
+ System.out.println("The text \"" + m + "\" should now be sent to:");
+ System.out.println(hostName + ":" + port);
+ }
+ public void connect()
+ {
+ // TODO - establish connection to host
+ }
+ public void disconnect()
+ {
+ // TODO - disconnect from host
+ }
+}
Deleted: trunk/src/XMPPLinkLocalSession.java
===================================================================
--- trunk/src/XMPPLinkLocalSession.java 2007-11-09 12:43:02 UTC (rev 45)
+++ trunk/src/XMPPLinkLocalSession.java 2007-11-10 12:45:32 UTC (rev 46)
@@ -1,8 +0,0 @@
-/* Stub class, to be the base for our actual chat sessions
-* Should perhaps be renamed to indicate that this is actually a
-* chat session?
-*/
-
-public class XMPPLinkLocalSession {
-
-}
Modified: trunk/src/ZeroFile.java
===================================================================
--- trunk/src/ZeroFile.java 2007-11-09 12:43:02 UTC (rev 45)
+++ trunk/src/ZeroFile.java 2007-11-10 12:45:32 UTC (rev 46)
@@ -7,7 +7,6 @@
*/
public static void main(String[] args) throws IOException {
ZeroFileMainWindow.startMainWindow();
- ZeroFileChatWindow.startChatWindow();
ZeroFileSettings.loadSettings();
try
{
Modified: trunk/src/ZeroFileChatWindow.java
===================================================================
--- trunk/src/ZeroFileChatWindow.java 2007-11-09 12:43:02 UTC (rev 45)
+++ trunk/src/ZeroFileChatWindow.java 2007-11-10 12:45:32 UTC (rev 46)
@@ -1,4 +1,6 @@
import java.awt.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
import javax.swing.*;
@@ -6,22 +8,37 @@
* @author Karl Bengtsson
*/
public class ZeroFileChatWindow {
- static void startChatWindow()
+ private JFrame _chatWindowFrame;
+ private JTextArea _chatTextArea;
+ private JPanel _bottomPanel;
+ private JTextField _entryTextField;
+ private JButton _sendButton;
+ private XMPPLinkLocalChatSession _session;
+ public ZeroFileChatWindow(XMPPLinkLocalHost chatPartner)
{
- JFrame chatWindowFrame = new JFrame();
- chatWindowFrame.setLayout(new GridLayout(0,1,1,1));
- chatWindowFrame.setLocation(0,400);
- chatWindowFrame.setSize(new Dimension(300,200));
- chatWindowFrame.setTitle("chatwindow");
- JTextArea chatTextArea = new JTextArea();
- chatWindowFrame.add(chatTextArea);
- JPanel bottomPanel = new JPanel();
- chatWindowFrame.add(bottomPanel);
- bottomPanel.setLayout(new GridLayout(1,0,1,1));
- JTextField entryTextField = new JTextField();
- JButton sendButton = new JButton("Send");
- bottomPanel.add(entryTextField);
- bottomPanel.add(sendButton);
- chatWindowFrame.setVisible(true);
+ chatPartner.updateData();
+ _session = new XMPPLinkLocalChatSession(chatPartner);
+ _chatWindowFrame = new JFrame();
+ _chatWindowFrame.setTitle(chatPartner.toString());
+ _chatWindowFrame.setLayout(new GridLayout(0,1,1,1));
+ _chatWindowFrame.setLocation(0,400);
+ _chatWindowFrame.setSize(new Dimension(300,200));
+ _chatTextArea = new JTextArea();
+ _chatWindowFrame.add(_chatTextArea);
+ _bottomPanel = new JPanel();
+ _chatWindowFrame.add(_bottomPanel);
+ _bottomPanel.setLayout(new GridLayout(1,0,1,1));
+ _entryTextField = new JTextField();
+ _sendButton = new JButton("Send");
+ _bottomPanel.add(_entryTextField);
+ _bottomPanel.add(_sendButton);
+ _chatWindowFrame.setVisible(true);
+ _sendButton.addActionListener(
+ new ActionListener(){
+ public void actionPerformed(ActionEvent sendButtonPress){
+ _session.sendMessage(_entryTextField.getText());
+ }
+ }
+ );
}
}
Modified: trunk/src/ZeroFileMainWindow.java
===================================================================
--- trunk/src/ZeroFileMainWindow.java 2007-11-09 12:43:02 UTC (rev 45)
+++ trunk/src/ZeroFileMainWindow.java 2007-11-10 12:45:32 UTC (rev 46)
@@ -89,6 +89,29 @@
_contactList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
_contactList.setLayoutOrientation(JList.VERTICAL);
_contactList.setSize(500,700);
+ _contactList.addMouseListener( new MouseListener(){
+ public void mouseEntered(MouseEvent e)
+ {
+
+ }
+ public void mouseExited(MouseEvent e)
+ {
+
+ }
+ public void mouseReleased(MouseEvent e)
+ {
+
+ }
+ public void mousePressed(MouseEvent e)
+ {
+
+ }
+ public void mouseClicked(MouseEvent e)
+ {
+ if (e.getClickCount() == 2)
+ new ZeroFileChatWindow((XMPPLinkLocalHost)_contactList.getSelectedValue());
+ }
+ });
_mainWindowFrame.add(_contactList);
// Show the window
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zo...@us...> - 2007-11-09 12:43:04
|
Revision: 45
http://zerofile.svn.sourceforge.net/zerofile/?rev=45&view=rev
Author: zondar
Date: 2007-11-09 04:43:02 -0800 (Fri, 09 Nov 2007)
Log Message:
-----------
added functionality to settings and settingswindow
Modified Paths:
--------------
trunk/src/ZeroFileSettings.java
trunk/src/ZeroFileSettingsWindow.java
Modified: trunk/src/ZeroFileSettings.java
===================================================================
--- trunk/src/ZeroFileSettings.java 2007-11-09 12:18:29 UTC (rev 44)
+++ trunk/src/ZeroFileSettings.java 2007-11-09 12:43:02 UTC (rev 45)
@@ -66,12 +66,39 @@
else
return "1337";
}
-
public static void setMainPort(String p)
{
_zeroFileProperties.put("Port", p);
}
+
+ public static void setCheckBox(String p)
+ {
+ _zeroFileProperties.put("CheckBox", p);
+ }
+
+ public static String getCheckBox() {
+ if (_zeroFileProperties.containsKey("CheckBox"))
+ return _zeroFileProperties.getProperty("CheckBox");
+ else
+ return "false";
+ }
+
+ public static void setDownloadFolder(String p)
+ {
+ _zeroFileProperties.put("DownloadFolder", p);
+ }
+
+ public static String getDownloadFolder() {
+ if (_zeroFileProperties.containsKey("DownloadFolder"))
+ return _zeroFileProperties.getProperty("DownloadFolder");
+ else
+ return "";
+ }
+
+
+
+
public static void saveSettings() throws IOException {
FileOutputStream appStream = new FileOutputStream("appProperties");
_zeroFileProperties.store(appStream, "settings");;
Modified: trunk/src/ZeroFileSettingsWindow.java
===================================================================
--- trunk/src/ZeroFileSettingsWindow.java 2007-11-09 12:18:29 UTC (rev 44)
+++ trunk/src/ZeroFileSettingsWindow.java 2007-11-09 12:43:02 UTC (rev 45)
@@ -56,6 +56,7 @@
//Label + browsing for chosing download folder
JLabel downloadLabel = new JLabel("Download Folder:", JLabel.CENTER);
final JLabel pathNowLabel = new JLabel("", JLabel.CENTER);
+ pathNowLabel.setText(ZeroFileSettings.getDownloadFolder());
JLabel pathLabel = new JLabel("Desired catalog:", JLabel.CENTER);
JButton browseButton = new JButton("Browse");
settingsWindowFrame.add(downloadLabel);
@@ -66,6 +67,7 @@
//Checkbox for auto accept file transfers
JLabel checkBoxLabel = new JLabel("Auto accept file transfers", JLabel.CENTER);
final JCheckBox checkBoxTransfer = new JCheckBox();
+ checkBoxTransfer.setSelected(Boolean.valueOf(ZeroFileSettings.getCheckBox()));
settingsWindowFrame.add(checkBoxLabel);
settingsWindowFrame.add(checkBoxTransfer);
@@ -93,7 +95,6 @@
okButton.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent okb){
- //checkBoxTransfer.isSelected();
if(!nickNameField.getText().equals(""))
ZeroFileSettings.setNickName(nickNameField.getText());
if(!firstNameField.getText().equals(""))
@@ -104,6 +105,9 @@
ZeroFileSettings.setEmail(emailField.getText());
if(!portField.getText().equals(""))
ZeroFileSettings.setMainPort(portField.getText());
+ if(!pathNowLabel.getText().equals(""))
+ ZeroFileSettings.setDownloadFolder(pathNowLabel.getText());
+ ZeroFileSettings.setCheckBox(String.valueOf(checkBoxTransfer.isSelected()));
try {
ZeroFileSettings.saveSettings();
} catch (IOException e) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <el...@us...> - 2007-11-09 12:18:32
|
Revision: 44
http://zerofile.svn.sourceforge.net/zerofile/?rev=44&view=rev
Author: elpedr0
Date: 2007-11-09 04:18:29 -0800 (Fri, 09 Nov 2007)
Log Message:
-----------
Working Save/load except for downloadpath and checkbox
Modified Paths:
--------------
trunk/src/ZeroFile.java
trunk/src/ZeroFileSettings.java
trunk/src/ZeroFileSettingsWindow.java
Modified: trunk/src/ZeroFile.java
===================================================================
--- trunk/src/ZeroFile.java 2007-11-09 10:30:52 UTC (rev 43)
+++ trunk/src/ZeroFile.java 2007-11-09 12:18:29 UTC (rev 44)
@@ -8,7 +8,6 @@
public static void main(String[] args) throws IOException {
ZeroFileMainWindow.startMainWindow();
ZeroFileChatWindow.startChatWindow();
- ZeroFileSettings.saveSettings();
ZeroFileSettings.loadSettings();
try
{
Modified: trunk/src/ZeroFileSettings.java
===================================================================
--- trunk/src/ZeroFileSettings.java 2007-11-09 10:30:52 UTC (rev 43)
+++ trunk/src/ZeroFileSettings.java 2007-11-09 12:18:29 UTC (rev 44)
@@ -5,33 +5,9 @@
import java.io.*;
public class ZeroFileSettings {
- //private static String _nickName;
- private static String _firstName;
- private static String _lastName;
- private static String _email;
- private static int _mainPort;
+
private static Properties _zeroFileProperties = new Properties();
- /*public static void saveSettings() throws IOException
- {
- // set up default properties
- Properties defaultProps = new Properties();
- FileInputStream defaultStream = new FileInputStream("defaultProperties");
- defaultProps.load(defaultStream);
- defaultStream.close();
-
- // set up real properties
- Properties applicationProps = new Properties(defaultProps);
- FileOutputStream appStream = new FileOutputStream("appProperties");
-
-
- applicationProps.put ( "HEIGHT","300" ) ;
- applicationProps.put ( "WIDTH","300" ) ;
-
-
- }*/
-
-
public static String getNickName()
{
if (_zeroFileProperties.containsKey("NickName"))
@@ -47,66 +23,66 @@
public static String getFirstName()
{
- return _firstName;
+ if (_zeroFileProperties.containsKey("FirstName"))
+ return _zeroFileProperties.getProperty("FirstName");
+ else
+ return "Anonymous";
}
public static void setFirstName(String f)
{
- _firstName = f;
+ _zeroFileProperties.put("FirstName", f);
}
public static String getLastName()
{
- return _lastName;
+ if (_zeroFileProperties.containsKey("LastName"))
+ return _zeroFileProperties.getProperty("LastName");
+ else
+ return "Anonymous";
}
public static void setLastName(String l)
{
- _lastName = l;
+ _zeroFileProperties.put("LastName", l);
}
public static String getEmail()
{
- return _email;
+ if (_zeroFileProperties.containsKey("Email"))
+ return _zeroFileProperties.getProperty("Email");
+ else
+ return "Ano...@an...";
}
public static void setEmail(String e)
{
- _email = e;
+ _zeroFileProperties.put("Email", e);
}
- public static int getMainPort()
- {
- return _mainPort;
+ public static String getMainPort() {
+ if (_zeroFileProperties.containsKey("Port"))
+ return _zeroFileProperties.getProperty("Port");
+ else
+ return "1337";
}
- public static void setMainPort(int p)
+ public static void setMainPort(String p)
{
- _mainPort = p;
+ _zeroFileProperties.put("Port", p);
}
public static void saveSettings() throws IOException {
-
- //Properties applicationProps = new Properties();
FileOutputStream appStream = new FileOutputStream("appProperties");
- _zeroFileProperties.put("first", "balle");
- //applicationProps.put("first", "balle");
- //applicationProps.put("last", "ballesson");
- _zeroFileProperties.store(appStream, "sttings");
- //applicationProps.store(appStream, "settings");
+ _zeroFileProperties.store(appStream, "settings");;
appStream.close();
}
public static void loadSettings() throws IOException {
- Properties applicationProps = new Properties();
FileInputStream appStream = new FileInputStream("appProperties");
- applicationProps.load(appStream);
- String key = "last";
- String val = applicationProps.getProperty ( key ) ;
- System.out.println ( val ) ;
- appStream.close();
+ _zeroFileProperties.load(appStream);
+ appStream.close();
}
-
}
Modified: trunk/src/ZeroFileSettingsWindow.java
===================================================================
--- trunk/src/ZeroFileSettingsWindow.java 2007-11-09 10:30:52 UTC (rev 43)
+++ trunk/src/ZeroFileSettingsWindow.java 2007-11-09 12:18:29 UTC (rev 44)
@@ -49,7 +49,7 @@
//Label + field for port parameter
JLabel portLabel = new JLabel("Port", JLabel.CENTER);
final JTextField portField = new JTextField();
- portField.setText(String.valueOf(ZeroFileSettings.getMainPort()));
+ portField.setText(ZeroFileSettings.getMainPort());
settingsWindowFrame.add(portLabel);
settingsWindowFrame.add(portField);
@@ -103,7 +103,7 @@
if(!emailField.getText().equals(""))
ZeroFileSettings.setEmail(emailField.getText());
if(!portField.getText().equals(""))
- ZeroFileSettings.setMainPort(Integer.valueOf(portField.getText()));
+ ZeroFileSettings.setMainPort(portField.getText());
try {
ZeroFileSettings.saveSettings();
} catch (IOException e) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zo...@us...> - 2007-11-09 10:30:47
|
Revision: 43
http://zerofile.svn.sourceforge.net/zerofile/?rev=43&view=rev
Author: zondar
Date: 2007-11-09 02:30:52 -0800 (Fri, 09 Nov 2007)
Log Message:
-----------
a little more complete
Modified Paths:
--------------
trunk/src/ZeroFileSettingsWindow.java
Modified: trunk/src/ZeroFileSettingsWindow.java
===================================================================
--- trunk/src/ZeroFileSettingsWindow.java 2007-11-09 10:20:03 UTC (rev 42)
+++ trunk/src/ZeroFileSettingsWindow.java 2007-11-09 10:30:52 UTC (rev 43)
@@ -55,7 +55,7 @@
//Label + browsing for chosing download folder
JLabel downloadLabel = new JLabel("Download Folder:", JLabel.CENTER);
- JLabel pathNowLabel = new JLabel("", JLabel.CENTER);
+ final JLabel pathNowLabel = new JLabel("", JLabel.CENTER);
JLabel pathLabel = new JLabel("Desired catalog:", JLabel.CENTER);
JButton browseButton = new JButton("Browse");
settingsWindowFrame.add(downloadLabel);
@@ -122,7 +122,7 @@
JFileChooser _directory = new JFileChooser();
_directory.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
_directory.showOpenDialog(null);
- //todo add method to handle the result
+ pathNowLabel.setText(String.valueOf(_directory.getSelectedFile()));
}
}
);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zo...@us...> - 2007-11-09 10:20:02
|
Revision: 42
http://zerofile.svn.sourceforge.net/zerofile/?rev=42&view=rev
Author: zondar
Date: 2007-11-09 02:20:03 -0800 (Fri, 09 Nov 2007)
Log Message:
-----------
added some functionality to the browse button.
TODO: add method to handle the result from the JFileChooser
(I will do this later)
Modified Paths:
--------------
trunk/src/ZeroFileSettingsWindow.java
Modified: trunk/src/ZeroFileSettingsWindow.java
===================================================================
--- trunk/src/ZeroFileSettingsWindow.java 2007-11-07 19:03:28 UTC (rev 41)
+++ trunk/src/ZeroFileSettingsWindow.java 2007-11-09 10:20:03 UTC (rev 42)
@@ -1,10 +1,12 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
+import java.io.IOException;
/**
* @author Richard
*/
+
public class ZeroFileSettingsWindow
{
static void startSettingsWindow()
@@ -44,6 +46,13 @@
settingsWindowFrame.add(emailLabel);
settingsWindowFrame.add(emailField);
+ //Label + field for port parameter
+ JLabel portLabel = new JLabel("Port", JLabel.CENTER);
+ final JTextField portField = new JTextField();
+ portField.setText(String.valueOf(ZeroFileSettings.getMainPort()));
+ settingsWindowFrame.add(portLabel);
+ settingsWindowFrame.add(portField);
+
//Label + browsing for chosing download folder
JLabel downloadLabel = new JLabel("Download Folder:", JLabel.CENTER);
JLabel pathNowLabel = new JLabel("", JLabel.CENTER);
@@ -93,9 +102,29 @@
ZeroFileSettings.setLastName(lastNameField.getText());
if(!emailField.getText().equals(""))
ZeroFileSettings.setEmail(emailField.getText());
+ if(!portField.getText().equals(""))
+ ZeroFileSettings.setMainPort(Integer.valueOf(portField.getText()));
+ try {
+ ZeroFileSettings.saveSettings();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
settingsWindowFrame.setVisible(false);
+
}
}
+ );
+
+ browseButton.addActionListener(
+ new ActionListener(){
+ public void actionPerformed(ActionEvent browseb){
+ JFileChooser _directory = new JFileChooser();
+ _directory.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
+ _directory.showOpenDialog(null);
+ //todo add method to handle the result
+ }
+ }
);
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zo...@us...> - 2007-11-07 19:03:29
|
Revision: 41
http://zerofile.svn.sourceforge.net/zerofile/?rev=41&view=rev
Author: zondar
Date: 2007-11-07 11:03:28 -0800 (Wed, 07 Nov 2007)
Log Message:
-----------
Updated SeroFileSettingsWindow
Modified Paths:
--------------
trunk/src/ZeroFileSettingsWindow.java
Modified: trunk/src/ZeroFileSettingsWindow.java
===================================================================
--- trunk/src/ZeroFileSettingsWindow.java 2007-11-07 16:31:40 UTC (rev 40)
+++ trunk/src/ZeroFileSettingsWindow.java 2007-11-07 19:03:28 UTC (rev 41)
@@ -3,43 +3,57 @@
import java.awt.event.*;
/**
- * @author Richard & Peter
+ * @author Richard
*/
public class ZeroFileSettingsWindow
{
static void startSettingsWindow()
{
final JFrame settingsWindowFrame = new JFrame();
- settingsWindowFrame.setSize(new Dimension(300,200));
+ settingsWindowFrame.setSize(new Dimension(350,200));
settingsWindowFrame.setResizable(false);
settingsWindowFrame.setLayout(new GridLayout(0,2,1,1));
settingsWindowFrame.setLocation(200, 200);
- settingsWindowFrame.setTitle("Settings");
+ settingsWindowFrame.setTitle("ZeroFile Settings");
// Label + field for Nickname parameter
JLabel nickNameLabel = new JLabel("Nickname:", JLabel.CENTER);
final JTextField nickNameField = new JTextField();
+ nickNameField.setText(ZeroFileSettings.getNickName());
settingsWindowFrame.add(nickNameLabel);
settingsWindowFrame.add(nickNameField);
// Label + field for First Name parameter
JLabel firstNameLabel = new JLabel("First name:", JLabel.CENTER);
final JTextField firstNameField = new JTextField();
+ firstNameField.setText(ZeroFileSettings.getFirstName());
settingsWindowFrame.add(firstNameLabel);
settingsWindowFrame.add(firstNameField);
// Label + field for Last Name parameter
JLabel lastNameLabel = new JLabel("Last name:", JLabel.CENTER);
final JTextField lastNameField = new JTextField();
+ lastNameField.setText(ZeroFileSettings.getLastName());
settingsWindowFrame.add(lastNameLabel);
settingsWindowFrame.add(lastNameField);
- // Label + field for Last Name parameter
+ // Label + field for email parameter
JLabel emailLabel = new JLabel("Email:", JLabel.CENTER);
final JTextField emailField = new JTextField();
+ emailField.setText(ZeroFileSettings.getEmail());
settingsWindowFrame.add(emailLabel);
settingsWindowFrame.add(emailField);
+ //Label + browsing for chosing download folder
+ JLabel downloadLabel = new JLabel("Download Folder:", JLabel.CENTER);
+ JLabel pathNowLabel = new JLabel("", JLabel.CENTER);
+ JLabel pathLabel = new JLabel("Desired catalog:", JLabel.CENTER);
+ JButton browseButton = new JButton("Browse");
+ settingsWindowFrame.add(downloadLabel);
+ settingsWindowFrame.add(browseButton);
+ settingsWindowFrame.add(pathLabel);
+ settingsWindowFrame.add(pathNowLabel);
+
//Checkbox for auto accept file transfers
JLabel checkBoxLabel = new JLabel("Auto accept file transfers", JLabel.CENTER);
final JCheckBox checkBoxTransfer = new JCheckBox();
@@ -61,45 +75,24 @@
//listener to Cancel button
cancelButton.addActionListener(
new ActionListener(){
- public void actionPerformed(ActionEvent e){
+ public void actionPerformed(ActionEvent cancelb){
settingsWindowFrame.setVisible(false);
- System.out.println("cancel");
}
}
);
- //listener to Ok button will change the local variables later when ZeroFileSettings is final
+ //listener to Ok, passes on the values to ZeroFileSettings methods
okButton.addActionListener(
new ActionListener(){
- public void actionPerformed(ActionEvent e){
- System.out.println("ok");
- String ni,na,la,em;
- Boolean check;
- check = checkBoxTransfer.isSelected();
- System.out.print(check);
+ public void actionPerformed(ActionEvent okb){
+ //checkBoxTransfer.isSelected();
if(!nickNameField.getText().equals(""))
- {
- ni = nickNameField.getText();
-
- System.out.print(ni);
-
- }
+ ZeroFileSettings.setNickName(nickNameField.getText());
if(!firstNameField.getText().equals(""))
- {
- na = firstNameField.getText();
-
- System.out.print(na);
-
- }
+ ZeroFileSettings.setFirstName(firstNameField.getText());
if(!lastNameField.getText().equals(""))
- {
- la = lastNameField.getText();
- System.out.print(la);
- }
+ ZeroFileSettings.setLastName(lastNameField.getText());
if(!emailField.getText().equals(""))
- {
- em = emailField.getText();
- System.out.print(em);
- }
+ ZeroFileSettings.setEmail(emailField.getText());
settingsWindowFrame.setVisible(false);
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zo...@us...> - 2007-11-07 16:31:40
|
Revision: 40
http://zerofile.svn.sourceforge.net/zerofile/?rev=40&view=rev
Author: zondar
Date: 2007-11-07 08:31:40 -0800 (Wed, 07 Nov 2007)
Log Message:
-----------
upgrade of listeners
Modified Paths:
--------------
trunk/src/ZeroFileSettingsWindow.java
Modified: trunk/src/ZeroFileSettingsWindow.java
===================================================================
--- trunk/src/ZeroFileSettingsWindow.java 2007-11-07 15:57:15 UTC (rev 39)
+++ trunk/src/ZeroFileSettingsWindow.java 2007-11-07 16:31:40 UTC (rev 40)
@@ -3,7 +3,7 @@
import java.awt.event.*;
/**
- * @author Peter
+ * @author Richard & Peter
*/
public class ZeroFileSettingsWindow
{
@@ -58,7 +58,7 @@
settingsWindowFrame.setVisible(true);
-
+ //listener to Cancel button
cancelButton.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
@@ -67,23 +67,14 @@
}
}
);
+ //listener to Ok button will change the local variables later when ZeroFileSettings is final
okButton.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
System.out.println("ok");
String ni,na,la,em;
Boolean check;
- na = firstNameField.getText();
- la = lastNameField.getText();
- em = emailField.getText();
check = checkBoxTransfer.isSelected();
- System.out.println("");
- System.out.print(na);
- System.out.println("");
- System.out.print(la);
- System.out.println("");
- System.out.print(em);
- System.out.println("");
System.out.print(check);
if(!nickNameField.getText().equals(""))
{
@@ -92,6 +83,24 @@
System.out.print(ni);
}
+ if(!firstNameField.getText().equals(""))
+ {
+ na = firstNameField.getText();
+
+ System.out.print(na);
+
+ }
+ if(!lastNameField.getText().equals(""))
+ {
+ la = lastNameField.getText();
+ System.out.print(la);
+ }
+ if(!emailField.getText().equals(""))
+ {
+ em = emailField.getText();
+ System.out.print(em);
+ }
+ settingsWindowFrame.setVisible(false);
}
}
);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kar...@us...> - 2007-11-07 15:57:11
|
Revision: 39
http://zerofile.svn.sourceforge.net/zerofile/?rev=39&view=rev
Author: karl-bengtsson
Date: 2007-11-07 07:57:15 -0800 (Wed, 07 Nov 2007)
Log Message:
-----------
Various changes in this commit. The contact list should now be almost fully operational. Yay!
*) In ZeroFileMainWindow: Completed the methods for adding and removing from the contact list, as well as checking if a certain host is already listed.
*) In ZeroconfBrowsing: Rewrote the browsing code to account for the above. Also added handling of unregistering of services.
*) In XMPPLinkLocalHost: Modified the class to include some more attributes.
*) In ZeroFile: removed the 20 second deregistration. Now the program stays registered until it exits.
Modified Paths:
--------------
trunk/src/XMPPLinkLocalHost.java
trunk/src/ZeroFile.java
trunk/src/ZeroFileMainWindow.java
trunk/src/ZeroconfBrowsing.java
Modified: trunk/src/XMPPLinkLocalHost.java
===================================================================
--- trunk/src/XMPPLinkLocalHost.java 2007-11-07 15:20:24 UTC (rev 38)
+++ trunk/src/XMPPLinkLocalHost.java 2007-11-07 15:57:15 UTC (rev 39)
@@ -1,5 +1,4 @@
import com.apple.dnssd.DNSSD;
-import com.apple.dnssd.DNSSDException;
import com.apple.dnssd.DNSSDService;
import com.apple.dnssd.ResolveListener;
import com.apple.dnssd.TXTRecord;
@@ -56,32 +55,38 @@
}
public void updateData()
- throws DNSSDException, InterruptedException
{
- _r = DNSSD.resolve(0, DNSSD.UNIQUE, _serviceName, "_presence._tcp", "local", new ResolveListener()
+ try
{
- public void operationFailed(DNSSDService service,int errorCode)
+ _r = DNSSD.resolve(0, DNSSD.ALL_INTERFACES, _serviceName, "_presence._tcp", "local", new ResolveListener()
{
- System.out.println("Resolved failed " + errorCode);
- System.exit(-1);
- }
- public void serviceResolved(DNSSDService resolver, int flags, int ifIndex,
- String fullName, String hostName, int port, TXTRecord txtRecord)
- {
- _host = hostName;
- _port = port;
- System.out.println("Host resolved: " + hostName + ":" + port);
- System.out.println("Flags: " + flags + ", ifIndex: " + ifIndex + ", FQDN: " + fullName);
- for (int i = 0; i < txtRecord.size(); i++)
+ public void operationFailed(DNSSDService service,int errorCode)
{
- String key = txtRecord.getKey(i);
- String value = txtRecord.getValueAsString(i);
- if (key.length() > 0)
- System.out.println("\t" + key + "=" + value);
+ System.out.println("Resolved failed " + errorCode);
+ System.exit(-1);
}
- _r.stop();
- }
- });
+ public void serviceResolved(DNSSDService resolver, int flags, int ifIndex,
+ String fullName, String hostName, int port, TXTRecord txtRecord)
+ {
+ _host = hostName;
+ _port = port;
+ if (txtRecord != null)
+ {
+ if (txtRecord.contains("1st"))
+ _firstName = txtRecord.getValueAsString("1st").toString();
+ if (txtRecord.contains("last"))
+ _lastName = txtRecord.getValueAsString("last").toString();
+ if (txtRecord.contains("nick"))
+ _nickName = txtRecord.getValueAsString("nick").toString();
+ }
+ _r.stop();
+ }
+ });
+ }
+ catch (Exception e)
+ {
+ System.out.println("Error: " + e.getStackTrace().toString());
+ }
}
}
Modified: trunk/src/ZeroFile.java
===================================================================
--- trunk/src/ZeroFile.java 2007-11-07 15:20:24 UTC (rev 38)
+++ trunk/src/ZeroFile.java 2007-11-07 15:57:15 UTC (rev 39)
@@ -1,10 +1,8 @@
import java.io.IOException;
-//import java.net.ServerSocket;
-
public class ZeroFile {
/**
- * @param name - The service name used by the registration class. Deprecated. Don't use.
+ * Main class of the program.
* @throws IOException
*/
public static void main(String[] args) throws IOException {
@@ -14,25 +12,10 @@
ZeroFileSettings.loadSettings();
try
{
- // Let system allocate us an available port to listen on
- //ServerSocket s = new ServerSocket(0);
- //ZeroconfRegistration.registerService(s.getLocalPort());
ZeroconfRegistration.registerService();
ZeroconfRegistration.set1st("Testar");
ZeroconfRegistration.setLast("Nisse");
ZeroconfBrowsing.startBrowsing();
- /*
- ZeroFileMainWindow.addContact("Test 1");
- ZeroFileMainWindow.addContact("Test 2");
- ZeroFileMainWindow.addContact("Test 3");
- ZeroFileMainWindow.addContact("Test 4");
- ZeroFileMainWindow.removeContact("Test 3");
- */
- Thread.sleep(5000);
- ZeroconfRegistration.setStatus("away");
- Thread.sleep(15000);
- ZeroconfBrowsing.stopBrowsing();
- ZeroconfRegistration.unregisterService();
}
catch(Exception e)
{
Modified: trunk/src/ZeroFileMainWindow.java
===================================================================
--- trunk/src/ZeroFileMainWindow.java 2007-11-07 15:20:24 UTC (rev 38)
+++ trunk/src/ZeroFileMainWindow.java 2007-11-07 15:57:15 UTC (rev 39)
@@ -1,5 +1,6 @@
import java.awt.*;
import java.awt.event.*;
+
import javax.swing.*;
public class ZeroFileMainWindow
@@ -17,17 +18,30 @@
private static JComboBox _statusLista;
private static DefaultListModel _contactListModel;
private static JList _contactList;
- static void addContact(Object c)
+
+ static boolean containsHost(XMPPLinkLocalHost h)
{
- _contactListModel.addElement(c);
+ for (int i = 0; i<_contactListModel.size(); i++)
+ if (((XMPPLinkLocalHost)_contactListModel.getElementAt(i)).getServiceName().equals(h.getServiceName()))
+ return true;
+ return false;
}
- static void removeContact(Object c)
+
+ static void addHost(XMPPLinkLocalHost h)
{
- _contactListModel.removeElement(c);
+ _contactListModel.addElement(h);
}
+
+ static void removeHost(XMPPLinkLocalHost h)
+ {
+ for (int i = 0; i<_contactListModel.size(); i++)
+ if (((XMPPLinkLocalHost)_contactListModel.getElementAt(i)).getServiceName().equals(h.getServiceName()))
+ _contactListModel.remove(i);
+ }
+
static void startMainWindow()
{
- // Grundkittet, JFrame + JMenuBar
+ // Basics, JFrame + JMenuBar
_mainWindowFrame = new JFrame();
_mainWindowFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
_mainMenuBar = new JMenuBar();
@@ -57,19 +71,19 @@
_aboutMenuItem = new JMenuItem("About..");
_helpMenu.add(_aboutMenuItem);
- // Layout, storlekar, samt koppling av JMenuBar
+ // Layout, sizes, and the connection of the JMenuBar
_mainWindowFrame.setLayout(new GridLayout(0,1,1,1));
_mainWindowFrame.setMinimumSize(new Dimension(120,300));
_mainWindowFrame.setSize(new Dimension(150,400));
_mainWindowFrame.setJMenuBar(_mainMenuBar);
- // Statuslista
+ // Status list
String[] statusModes = {"Available","Away","Do not disturb"};
_statusLista = new JComboBox(statusModes);
_statusLista.setMaximumSize(new Dimension(20,100));
_mainWindowFrame.add(_statusLista);
- // Kontaktlista
+ // Contact list
_contactListModel = new DefaultListModel();
_contactList = new JList(_contactListModel);
_contactList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
@@ -77,7 +91,7 @@
_contactList.setSize(500,700);
_mainWindowFrame.add(_contactList);
- // Sm\x8All upp f\x9Anstret
+ // Show the window
_mainWindowFrame.setVisible(true);
}
}
\ No newline at end of file
Modified: trunk/src/ZeroconfBrowsing.java
===================================================================
--- trunk/src/ZeroconfBrowsing.java 2007-11-07 15:20:24 UTC (rev 38)
+++ trunk/src/ZeroconfBrowsing.java 2007-11-07 15:57:15 UTC (rev 39)
@@ -15,22 +15,16 @@
String name, String regType, String domain)
{
XMPPLinkLocalHost newHost = new XMPPLinkLocalHost(name);
- ZeroFileMainWindow.addContact(newHost);
- /*System.out.println("Yay, found: " + name + " at interface: " + ifIndex);
- try
+ if (!ZeroFileMainWindow.containsHost(newHost))
{
- ZeroconfResolving.getHost(name);
+ newHost.updateData();
+ ZeroFileMainWindow.addHost(newHost);
}
- catch (Exception e)
- {
- System.out.println("Error: " + e.getStackTrace());
- }*/
}
public void serviceLost(DNSSDService browser, int flags, int ifIndex,
String name, String regType, String domain)
{
- ZeroFileMainWindow.removeContact("name");
- //System.out.println("Lost: " + name);
+ ZeroFileMainWindow.removeHost(new XMPPLinkLocalHost(name));
}
});
System.out.println("Starting browsing...");
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zo...@us...> - 2007-11-07 15:20:22
|
Revision: 38
http://zerofile.svn.sourceforge.net/zerofile/?rev=38&view=rev
Author: zondar
Date: 2007-11-07 07:20:24 -0800 (Wed, 07 Nov 2007)
Log Message:
-----------
added listeners to ZeroFileSettingsWindow
Modified Paths:
--------------
trunk/src/ZeroFileSettingsWindow.java
Modified: trunk/src/ZeroFileSettingsWindow.java
===================================================================
--- trunk/src/ZeroFileSettingsWindow.java 2007-11-07 14:32:01 UTC (rev 37)
+++ trunk/src/ZeroFileSettingsWindow.java 2007-11-07 15:20:24 UTC (rev 38)
@@ -1,5 +1,6 @@
import javax.swing.*;
import java.awt.*;
+import java.awt.event.*;
/**
* @author Peter
@@ -8,7 +9,7 @@
{
static void startSettingsWindow()
{
- JFrame settingsWindowFrame = new JFrame();
+ final JFrame settingsWindowFrame = new JFrame();
settingsWindowFrame.setSize(new Dimension(300,200));
settingsWindowFrame.setResizable(false);
settingsWindowFrame.setLayout(new GridLayout(0,2,1,1));
@@ -17,31 +18,31 @@
// Label + field for Nickname parameter
JLabel nickNameLabel = new JLabel("Nickname:", JLabel.CENTER);
- JTextField nickNameField = new JTextField();
+ final JTextField nickNameField = new JTextField();
settingsWindowFrame.add(nickNameLabel);
settingsWindowFrame.add(nickNameField);
// Label + field for First Name parameter
JLabel firstNameLabel = new JLabel("First name:", JLabel.CENTER);
- JTextField firstNameField = new JTextField();
+ final JTextField firstNameField = new JTextField();
settingsWindowFrame.add(firstNameLabel);
settingsWindowFrame.add(firstNameField);
// Label + field for Last Name parameter
JLabel lastNameLabel = new JLabel("Last name:", JLabel.CENTER);
- JTextField lastNameField = new JTextField();
+ final JTextField lastNameField = new JTextField();
settingsWindowFrame.add(lastNameLabel);
settingsWindowFrame.add(lastNameField);
// Label + field for Last Name parameter
JLabel emailLabel = new JLabel("Email:", JLabel.CENTER);
- JTextField emailField = new JTextField();
+ final JTextField emailField = new JTextField();
settingsWindowFrame.add(emailLabel);
settingsWindowFrame.add(emailField);
//Checkbox for auto accept file transfers
JLabel checkBoxLabel = new JLabel("Auto accept file transfers", JLabel.CENTER);
- JCheckBox checkBoxTransfer = new JCheckBox();
+ final JCheckBox checkBoxTransfer = new JCheckBox();
settingsWindowFrame.add(checkBoxLabel);
settingsWindowFrame.add(checkBoxTransfer);
@@ -52,7 +53,47 @@
settingsWindowFrame.add(okButton);
settingsWindowFrame.add(cancelButton);
+
// Show the window
- settingsWindowFrame.setVisible(true);
+ settingsWindowFrame.setVisible(true);
+
+
+
+ cancelButton.addActionListener(
+ new ActionListener(){
+ public void actionPerformed(ActionEvent e){
+ settingsWindowFrame.setVisible(false);
+ System.out.println("cancel");
+ }
+ }
+ );
+ okButton.addActionListener(
+ new ActionListener(){
+ public void actionPerformed(ActionEvent e){
+ System.out.println("ok");
+ String ni,na,la,em;
+ Boolean check;
+ na = firstNameField.getText();
+ la = lastNameField.getText();
+ em = emailField.getText();
+ check = checkBoxTransfer.isSelected();
+ System.out.println("");
+ System.out.print(na);
+ System.out.println("");
+ System.out.print(la);
+ System.out.println("");
+ System.out.print(em);
+ System.out.println("");
+ System.out.print(check);
+ if(!nickNameField.getText().equals(""))
+ {
+ ni = nickNameField.getText();
+
+ System.out.print(ni);
+
+ }
+ }
+ }
+ );
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <kar...@us...> - 2007-11-07 14:31:58
|
Revision: 37
http://zerofile.svn.sourceforge.net/zerofile/?rev=37&view=rev
Author: karl-bengtsson
Date: 2007-11-07 06:32:01 -0800 (Wed, 07 Nov 2007)
Log Message:
-----------
*) Moved the resolving code into the XMPPLinkLocalHost class - this makes sense if we consider that we will only resolve for one named instance of a presence service at a time, and that this service will be represented by an XMPPLinkLocalHost object.
*) Fixed a small null reference bug in ZeroFileSettings
*) Modified the ZeroconfBrowsing.startBrowse() method to actually post newly discovered hosts to the main contact list of the program.
Modified Paths:
--------------
trunk/src/XMPPLinkLocalHost.java
trunk/src/ZeroFileSettings.java
trunk/src/ZeroconfBrowsing.java
Modified: trunk/src/XMPPLinkLocalHost.java
===================================================================
--- trunk/src/XMPPLinkLocalHost.java 2007-11-07 14:04:37 UTC (rev 36)
+++ trunk/src/XMPPLinkLocalHost.java 2007-11-07 14:32:01 UTC (rev 37)
@@ -1,3 +1,9 @@
+import com.apple.dnssd.DNSSD;
+import com.apple.dnssd.DNSSDException;
+import com.apple.dnssd.DNSSDService;
+import com.apple.dnssd.ResolveListener;
+import com.apple.dnssd.TXTRecord;
+
// Stub class, to represent a compatible XMPP-capable host on the ZeroConf network
public class XMPPLinkLocalHost {
private String _serviceName;
@@ -4,17 +10,25 @@
private String _nickName;
private String _firstName;
private String _lastName;
+ private String _host;
+ private int _port;
+ private static DNSSDService _r;
public XMPPLinkLocalHost(String serviceName)
{
_serviceName = serviceName;
}
- /*public String getIPAddress()
+ public int getPort()
{
- return _ipAddress;
- }*/
+ return _port;
+ }
+ public String getHost()
+ {
+ return _host;
+ }
+
public String getServiceName()
{
return _serviceName;
@@ -40,4 +54,34 @@
else
return _serviceName;
}
+
+ public void updateData()
+ throws DNSSDException, InterruptedException
+ {
+ _r = DNSSD.resolve(0, DNSSD.UNIQUE, _serviceName, "_presence._tcp", "local", new ResolveListener()
+ {
+ public void operationFailed(DNSSDService service,int errorCode)
+ {
+ System.out.println("Resolved failed " + errorCode);
+ System.exit(-1);
+ }
+ public void serviceResolved(DNSSDService resolver, int flags, int ifIndex,
+ String fullName, String hostName, int port, TXTRecord txtRecord)
+ {
+ _host = hostName;
+ _port = port;
+ System.out.println("Host resolved: " + hostName + ":" + port);
+ System.out.println("Flags: " + flags + ", ifIndex: " + ifIndex + ", FQDN: " + fullName);
+ for (int i = 0; i < txtRecord.size(); i++)
+ {
+ String key = txtRecord.getKey(i);
+ String value = txtRecord.getValueAsString(i);
+ if (key.length() > 0)
+ System.out.println("\t" + key + "=" + value);
+ }
+ _r.stop();
+ }
+ });
+ }
+
}
Modified: trunk/src/ZeroFileSettings.java
===================================================================
--- trunk/src/ZeroFileSettings.java 2007-11-07 14:04:37 UTC (rev 36)
+++ trunk/src/ZeroFileSettings.java 2007-11-07 14:32:01 UTC (rev 37)
@@ -5,12 +5,12 @@
import java.io.*;
public class ZeroFileSettings {
- private static String _nickName;
+ //private static String _nickName;
private static String _firstName;
private static String _lastName;
private static String _email;
private static int _mainPort;
- private static Properties _zeroFileProperties;
+ private static Properties _zeroFileProperties = new Properties();
/*public static void saveSettings() throws IOException
{
@@ -62,7 +62,7 @@
public static void setLastName(String l)
{
- _nickName = l;
+ _lastName = l;
}
public static String getEmail()
Modified: trunk/src/ZeroconfBrowsing.java
===================================================================
--- trunk/src/ZeroconfBrowsing.java 2007-11-07 14:04:37 UTC (rev 36)
+++ trunk/src/ZeroconfBrowsing.java 2007-11-07 14:32:01 UTC (rev 37)
@@ -14,7 +14,9 @@
public void serviceFound(DNSSDService browser, int flags, int ifIndex,
String name, String regType, String domain)
{
- System.out.println("Yay, found: " + name + " at interface: " + ifIndex);
+ XMPPLinkLocalHost newHost = new XMPPLinkLocalHost(name);
+ ZeroFileMainWindow.addContact(newHost);
+ /*System.out.println("Yay, found: " + name + " at interface: " + ifIndex);
try
{
ZeroconfResolving.getHost(name);
@@ -22,12 +24,13 @@
catch (Exception e)
{
System.out.println("Error: " + e.getStackTrace());
- }
+ }*/
}
public void serviceLost(DNSSDService browser, int flags, int ifIndex,
String name, String regType, String domain)
{
- System.out.println("Lost: " + name);
+ ZeroFileMainWindow.removeContact("name");
+ //System.out.println("Lost: " + name);
}
});
System.out.println("Starting browsing...");
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|