Skip to content

Commit

Permalink
encoding and move systray to controller
Browse files Browse the repository at this point in the history
  • Loading branch information
vistahr committed Mar 13, 2012
1 parent dbb9872 commit cb058a0
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 42 deletions.
6 changes: 3 additions & 3 deletions build.xml
@@ -1,4 +1,4 @@
<?xml version="1.0"?> <?xml version="1.0" encoding="UTF-8" ?>
<project name="LanChat" basedir="." default="build"> <project name="LanChat" basedir="." default="build">


<property name="src.dir" value="src"/> <property name="src.dir" value="src"/>
Expand Down Expand Up @@ -32,10 +32,10 @@


<target name="compile" depends="init-clean"> <target name="compile" depends="init-clean">
<mkdir dir="${build.dir}"/> <mkdir dir="${build.dir}"/>
<javac srcdir="${src.dir}" destdir="${build.dir}" debug="true" debuglevel="lines,source" includeantruntime="false"> <javac srcdir="${src.dir}" destdir="${build.dir}" debug="true" debuglevel="lines,source" includeantruntime="false" encoding="UTF-8">
<classpath refid="class.path" /> <classpath refid="class.path" />
</javac> </javac>
<javac srcdir="${test.dir}" destdir="${build.dir}" debug="true" debuglevel="lines,source" includeantruntime="false"> <javac srcdir="${test.dir}" destdir="${build.dir}" debug="true" debuglevel="lines,source" includeantruntime="false" encoding="UTF-8">
<classpath refid="class.path" /> <classpath refid="class.path" />
</javac> </javac>
</target> </target>
Expand Down
19 changes: 19 additions & 0 deletions src/de/vistahr/lanchat/controller/ChatController.java
Expand Up @@ -36,6 +36,8 @@
import java.awt.event.AdjustmentListener; import java.awt.event.AdjustmentListener;
import java.awt.event.FocusEvent; import java.awt.event.FocusEvent;
import java.awt.event.FocusListener; import java.awt.event.FocusListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowEvent; import java.awt.event.WindowEvent;
import java.awt.event.WindowListener; import java.awt.event.WindowListener;
import java.io.IOException; import java.io.IOException;
Expand Down Expand Up @@ -206,6 +208,23 @@ public void adjustmentValueChanged(AdjustmentEvent e) {
e.getAdjustable().setValue(e.getAdjustable().getMaximum()); e.getAdjustable().setValue(e.getAdjustable().getMaximum());
} }
}); });
// tray icon
view.getTrayIcon().addMouseListener(new MouseListener() {
public void mouseClicked(MouseEvent e) {
// Get back
view.getFrame().setVisible(true);
view.getFrame().setState(JFrame.NORMAL);
SystemTray.getSystemTray().remove(view.getTrayIcon());
}
@Override
public void mousePressed(MouseEvent e) {}
@Override
public void mouseReleased(MouseEvent e) {}
@Override
public void mouseEntered(MouseEvent e) {}
@Override
public void mouseExited(MouseEvent e) {}
});
} }


/** /**
Expand Down
49 changes: 12 additions & 37 deletions src/de/vistahr/lanchat/view/ChatView.java
Expand Up @@ -33,8 +33,6 @@
import java.awt.SystemTray; import java.awt.SystemTray;
import java.awt.Toolkit; import java.awt.Toolkit;
import java.awt.TrayIcon; import java.awt.TrayIcon;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.ConcurrentModificationException; import java.util.ConcurrentModificationException;
import java.util.Iterator; import java.util.Iterator;
Expand Down Expand Up @@ -141,6 +139,18 @@ public JButton getBtnMute() {
public JScrollPane getEditorScrollPane() { public JScrollPane getEditorScrollPane() {
return editorScrollPane; return editorScrollPane;
} }

public TrayIcon getTrayIcon() {
if (SystemTray.isSupported()) {
if(this.trayIcon == null) {
Image icon = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/res/chat.png"));
trayIcon = new TrayIcon(icon, APP_NAME);
trayIcon.setImageAutoSize(true);
return trayIcon;
}
}
return null;
}


private void setTxtChatname(String name) { private void setTxtChatname(String name) {
txtChatname.setText(name); txtChatname.setText(name);
Expand Down Expand Up @@ -236,41 +246,6 @@ public void update(Observable o, Object model) {
} }





/**
* Initialize and set up the trayicon
* @return TrayIcon object
*/
public TrayIcon getTrayIcon() {
// check if os supports tray
if (SystemTray.isSupported()) {
if(this.trayIcon == null) {
Image icon = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/res/chat.png"));
trayIcon = new TrayIcon(icon, APP_NAME);
trayIcon.setImageAutoSize(true);
trayIcon.addMouseListener(new MouseListener() {
public void mouseClicked(MouseEvent e) {
// Get back
getFrame().setVisible(true);
getFrame().setState(JFrame.NORMAL);
SystemTray.getSystemTray().remove(getTrayIcon());
}
@Override
public void mousePressed(MouseEvent e) {}
@Override
public void mouseReleased(MouseEvent e) {}
@Override
public void mouseEntered(MouseEvent e) {}
@Override
public void mouseExited(MouseEvent e) {}
});
}
return trayIcon;
}
return null;
}


/** /**
* Creates an warning dialog box * Creates an warning dialog box
* @param message * @param message
Expand Down
3 changes: 1 addition & 2 deletions src/de/vistahr/network/Multicast.java
Expand Up @@ -139,11 +139,10 @@ public void receive(Receivable r) throws IOException {
byte[] bytes = new byte[65536]; byte[] bytes = new byte[65536];
DatagramPacket packet = new DatagramPacket(bytes, bytes.length); DatagramPacket packet = new DatagramPacket(bytes, bytes.length);



while(true) { while(true) {
socket.receive(packet); socket.receive(packet);
if(packet.getLength() != 0) { if(packet.getLength() != 0) {
String message = new String(packet.getData(),0,packet.getLength(), CHARSET); String message = new String(packet.getData(),0,packet.getLength(),CHARSET);
byte[] byteMsg = new BASE64Decoder().decodeBuffer(message); byte[] byteMsg = new BASE64Decoder().decodeBuffer(message);
r.onReceive(new String(byteMsg)); r.onReceive(new String(byteMsg));
} }
Expand Down

0 comments on commit cb058a0

Please sign in to comment.