Permalink
Browse files

encoding and move systray to controller

  • Loading branch information...
1 parent dbb9872 commit cb058a08f3fef0fa77641bcf5f16fa20e56064fd @vistahr committed Mar 13, 2012
View
@@ -1,4 +1,4 @@
-<?xml version="1.0"?>
+<?xml version="1.0" encoding="UTF-8" ?>
<project name="LanChat" basedir="." default="build">
<property name="src.dir" value="src"/>
@@ -32,10 +32,10 @@
<target name="compile" depends="init-clean">
<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" />
</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" />
</javac>
</target>
@@ -36,6 +36,8 @@
import java.awt.event.AdjustmentListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.IOException;
@@ -206,6 +208,23 @@ public void adjustmentValueChanged(AdjustmentEvent e) {
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) {}
+ });
}
/**
@@ -33,8 +33,6 @@
import java.awt.SystemTray;
import java.awt.Toolkit;
import java.awt.TrayIcon;
-import java.awt.event.MouseEvent;
-import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.ConcurrentModificationException;
import java.util.Iterator;
@@ -141,6 +139,18 @@ public JButton getBtnMute() {
public JScrollPane getEditorScrollPane() {
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) {
txtChatname.setText(name);
@@ -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
* @param message
@@ -139,11 +139,10 @@ public void receive(Receivable r) throws IOException {
byte[] bytes = new byte[65536];
DatagramPacket packet = new DatagramPacket(bytes, bytes.length);
-
while(true) {
socket.receive(packet);
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);
r.onReceive(new String(byteMsg));
}

0 comments on commit cb058a0

Please sign in to comment.