mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-26 22:12:05 +01:00
Adds icon representations
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2199 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
0d0340a0b7
commit
29903213a3
2 changed files with 121 additions and 10 deletions
|
@ -56,6 +56,7 @@ import java.awt.*;
|
|||
import java.awt.datatransfer.*;
|
||||
import java.awt.event.*;
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.text.*;
|
||||
import java.util.Date;
|
||||
|
||||
|
@ -81,6 +82,42 @@ public class EnhancedDebugger implements SmackDebugger {
|
|||
|
||||
private static final String NEWLINE = "\n";
|
||||
|
||||
private static ImageIcon packetReceivedIcon;
|
||||
private static ImageIcon packetSentIcon;
|
||||
private static ImageIcon presencePacketIcon;
|
||||
private static ImageIcon iqPacketIcon;
|
||||
private static ImageIcon messagePacketIcon;
|
||||
private static ImageIcon unknownPacketTypeIcon;
|
||||
|
||||
{
|
||||
URL url;
|
||||
// Load the image icons
|
||||
url = ClassLoader.getSystemClassLoader().getResource("images/nav_left_blue.png");
|
||||
if (url != null) {
|
||||
packetReceivedIcon = new ImageIcon(url);
|
||||
}
|
||||
url = ClassLoader.getSystemClassLoader().getResource("images/nav_right_red.png");
|
||||
if (url != null) {
|
||||
packetSentIcon = new ImageIcon(url);
|
||||
}
|
||||
url = ClassLoader.getSystemClassLoader().getResource("images/photo_portrait.png");
|
||||
if (url != null) {
|
||||
presencePacketIcon = new ImageIcon(url);
|
||||
}
|
||||
url = ClassLoader.getSystemClassLoader().getResource("images/question_and_answer.png");
|
||||
if (url != null) {
|
||||
iqPacketIcon = new ImageIcon(url);
|
||||
}
|
||||
url = ClassLoader.getSystemClassLoader().getResource("images/message.png");
|
||||
if (url != null) {
|
||||
messagePacketIcon = new ImageIcon(url);
|
||||
}
|
||||
url = ClassLoader.getSystemClassLoader().getResource("images/unknown.png");
|
||||
if (url != null) {
|
||||
unknownPacketTypeIcon = new ImageIcon(url);
|
||||
}
|
||||
}
|
||||
|
||||
private JFrame frame = null;
|
||||
private DefaultTableModel messagesTable = null;
|
||||
private JTextArea messageTextArea = null;
|
||||
|
@ -170,6 +207,7 @@ public class EnhancedDebugger implements SmackDebugger {
|
|||
connListener = new ConnectionListener() {
|
||||
public void connectionClosed() {
|
||||
statusField.setValue("Closed");
|
||||
EnhancedDebuggerWindow.connectionClosed(EnhancedDebugger.this);
|
||||
}
|
||||
|
||||
public void connectionClosedOnError(Exception e) {
|
||||
|
@ -185,10 +223,17 @@ public class EnhancedDebugger implements SmackDebugger {
|
|||
tabbedPane.add("All Packets", allPane);
|
||||
tabbedPane.setToolTipTextAt(0, "Sent and received packets processed by Smack");
|
||||
|
||||
messagesTable = new DefaultTableModel(new Object[] { "Hide", "Timestamp", "Message", "Type", "To", "From" }, 0) {
|
||||
messagesTable = new DefaultTableModel(new Object[] { "Hide", "Timestamp", "", "", "Message", "Type", "To", "From" }, 0) {
|
||||
public boolean isCellEditable(int rowIndex, int mColIndex) {
|
||||
return false;
|
||||
}
|
||||
public Class getColumnClass(int columnIndex) {
|
||||
if (columnIndex == 2 || columnIndex == 3) {
|
||||
return Icon.class;
|
||||
}
|
||||
return super.getColumnClass(columnIndex);
|
||||
}
|
||||
|
||||
};
|
||||
JTable table = new JTable(messagesTable);
|
||||
// Allow only single a selection
|
||||
|
@ -201,15 +246,21 @@ public class EnhancedDebugger implements SmackDebugger {
|
|||
// Set the column "timestamp" size
|
||||
table.getColumnModel().getColumn(1).setMaxWidth(300);
|
||||
table.getColumnModel().getColumn(1).setPreferredWidth(70);
|
||||
// Set the column "direction" icon size
|
||||
table.getColumnModel().getColumn(2).setMaxWidth(50);
|
||||
table.getColumnModel().getColumn(2).setPreferredWidth(30);
|
||||
// Set the column "packet type" icon size
|
||||
table.getColumnModel().getColumn(3).setMaxWidth(50);
|
||||
table.getColumnModel().getColumn(3).setPreferredWidth(30);
|
||||
// Set the column "type" size
|
||||
table.getColumnModel().getColumn(3).setMaxWidth(200);
|
||||
table.getColumnModel().getColumn(3).setPreferredWidth(50);
|
||||
table.getColumnModel().getColumn(5).setMaxWidth(200);
|
||||
table.getColumnModel().getColumn(5).setPreferredWidth(50);
|
||||
// Set the column "to" size
|
||||
table.getColumnModel().getColumn(4).setMaxWidth(300);
|
||||
table.getColumnModel().getColumn(4).setPreferredWidth(90);
|
||||
table.getColumnModel().getColumn(6).setMaxWidth(300);
|
||||
table.getColumnModel().getColumn(6).setPreferredWidth(90);
|
||||
// Set the column "from" size
|
||||
table.getColumnModel().getColumn(5).setMaxWidth(300);
|
||||
table.getColumnModel().getColumn(5).setPreferredWidth(90);
|
||||
table.getColumnModel().getColumn(7).setMaxWidth(300);
|
||||
table.getColumnModel().getColumn(7).setPreferredWidth(90);
|
||||
// Create a table listener that listen for row selection events
|
||||
SelectionListener selectionListener = new SelectionListener(table);
|
||||
table.getSelectionModel().addListSelectionListener(selectionListener);
|
||||
|
@ -662,23 +713,28 @@ public class EnhancedDebugger implements SmackDebugger {
|
|||
String messageType = null;
|
||||
String from = packet.getFrom();
|
||||
String type = "";
|
||||
Icon packetTypeIcon;
|
||||
receivedPackets++;
|
||||
if (packet instanceof IQ) {
|
||||
packetTypeIcon = iqPacketIcon;
|
||||
messageType = "IQ Received (class=" + packet.getClass().getName() + ")";
|
||||
type = ((IQ) packet).getType().toString();
|
||||
receivedIQPackets++;
|
||||
}
|
||||
else if (packet instanceof Message) {
|
||||
packetTypeIcon = messagePacketIcon;
|
||||
messageType = "Message Received";
|
||||
type = ((Message) packet).getType().toString();
|
||||
receivedMessagePackets++;
|
||||
}
|
||||
else if (packet instanceof Presence) {
|
||||
packetTypeIcon = presencePacketIcon;
|
||||
messageType = "Presence Received";
|
||||
type = ((Presence) packet).getType().toString();
|
||||
receivedPresencePackets++;
|
||||
}
|
||||
else {
|
||||
packetTypeIcon = unknownPacketTypeIcon;
|
||||
messageType = packet.getClass().getName()+ " Received";
|
||||
receivedOtherPackets++;
|
||||
}
|
||||
|
@ -687,6 +743,8 @@ public class EnhancedDebugger implements SmackDebugger {
|
|||
new Object[] {
|
||||
packet.toXML(),
|
||||
dateFormatter.format(new Date()),
|
||||
packetReceivedIcon,
|
||||
packetTypeIcon,
|
||||
messageType,
|
||||
type,
|
||||
"",
|
||||
|
@ -705,23 +763,28 @@ public class EnhancedDebugger implements SmackDebugger {
|
|||
String messageType = null;
|
||||
String to = packet.getTo();
|
||||
String type = "";
|
||||
Icon packetTypeIcon;
|
||||
sentPackets++;
|
||||
if (packet instanceof IQ) {
|
||||
packetTypeIcon = iqPacketIcon;
|
||||
messageType = "IQ Sent (class=" + packet.getClass().getName() + ")";
|
||||
type = ((IQ) packet).getType().toString();
|
||||
sentIQPackets++;
|
||||
}
|
||||
else if (packet instanceof Message) {
|
||||
packetTypeIcon = messagePacketIcon;
|
||||
messageType = "Message Sent";
|
||||
type = ((Message) packet).getType().toString();
|
||||
sentMessagePackets++;
|
||||
}
|
||||
else if (packet instanceof Presence) {
|
||||
packetTypeIcon = presencePacketIcon;
|
||||
messageType = "Presence Sent";
|
||||
type = ((Presence) packet).getType().toString();
|
||||
sentPresencePackets++;
|
||||
}
|
||||
else {
|
||||
packetTypeIcon = unknownPacketTypeIcon;
|
||||
messageType = packet.getClass().getName()+ " Sent";
|
||||
sentOtherPackets++;
|
||||
}
|
||||
|
@ -730,10 +793,13 @@ public class EnhancedDebugger implements SmackDebugger {
|
|||
new Object[] {
|
||||
packet.toXML(),
|
||||
dateFormatter.format(new Date()),
|
||||
packetSentIcon,
|
||||
packetTypeIcon,
|
||||
messageType,
|
||||
type,
|
||||
to,
|
||||
""});
|
||||
|
||||
// Update the statistics table
|
||||
updateStatistics();
|
||||
}
|
||||
|
|
|
@ -54,6 +54,7 @@ package org.jivesoftware.smackx.debugger;
|
|||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.net.*;
|
||||
import java.util.*;
|
||||
|
||||
import javax.swing.*;
|
||||
|
@ -75,6 +76,33 @@ class EnhancedDebuggerWindow {
|
|||
|
||||
private static EnhancedDebuggerWindow instance;
|
||||
|
||||
private static ImageIcon connectionCreatedIcon;
|
||||
private static ImageIcon connectionActiveIcon;
|
||||
private static ImageIcon connectionClosedIcon;
|
||||
private static ImageIcon connectionClosedOnErrorIcon;
|
||||
|
||||
{
|
||||
URL url;
|
||||
|
||||
url = ClassLoader.getSystemClassLoader().getResource("images/trafficlight_off.png");
|
||||
if (url != null) {
|
||||
connectionCreatedIcon = new ImageIcon(url);
|
||||
}
|
||||
url = ClassLoader.getSystemClassLoader().getResource("images/trafficlight_green.png");
|
||||
if (url != null) {
|
||||
connectionActiveIcon = new ImageIcon(url);
|
||||
}
|
||||
url = ClassLoader.getSystemClassLoader().getResource("images/trafficlight_red.png");
|
||||
if (url != null) {
|
||||
connectionClosedIcon = new ImageIcon(url);
|
||||
}
|
||||
url = ClassLoader.getSystemClassLoader().getResource("images/warning.png");
|
||||
if (url != null) {
|
||||
connectionClosedOnErrorIcon = new ImageIcon(url);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private JFrame frame = null;
|
||||
private JTabbedPane tabbedPane = null;
|
||||
|
||||
|
@ -113,6 +141,7 @@ class EnhancedDebuggerWindow {
|
|||
}
|
||||
debugger.tabbedPane.setName("Connection_" + tabbedPane.getComponentCount());
|
||||
tabbedPane.add(debugger.tabbedPane, tabbedPane.getComponentCount() - 1);
|
||||
tabbedPane.setIconAt(tabbedPane.indexOfComponent(debugger.tabbedPane), connectionCreatedIcon);
|
||||
frame.setTitle(
|
||||
"Smack Debug Window -- Total connections: " + (tabbedPane.getComponentCount() - 1));
|
||||
}
|
||||
|
@ -125,9 +154,24 @@ class EnhancedDebuggerWindow {
|
|||
* @param user the user@host/resource that has just logged in
|
||||
*/
|
||||
synchronized static void userHasLogged(EnhancedDebugger debugger, String user) {
|
||||
int index = getInstance().tabbedPane.indexOfComponent(debugger.tabbedPane);
|
||||
getInstance().tabbedPane.setTitleAt(
|
||||
getInstance().tabbedPane.indexOfComponent(debugger.tabbedPane),
|
||||
index,
|
||||
user);
|
||||
getInstance().tabbedPane.setIconAt(
|
||||
index,
|
||||
connectionActiveIcon);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notification that the connection was properly closed.
|
||||
*
|
||||
* @param debugger the debugger whose connection was properly closed.
|
||||
*/
|
||||
synchronized static void connectionClosed(EnhancedDebugger debugger) {
|
||||
getInstance().tabbedPane.setIconAt(
|
||||
getInstance().tabbedPane.indexOfComponent(debugger.tabbedPane),
|
||||
connectionClosedIcon);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -138,11 +182,12 @@ class EnhancedDebuggerWindow {
|
|||
*/
|
||||
synchronized static void connectionClosedOnError(EnhancedDebugger debugger, Exception e) {
|
||||
int index = getInstance().tabbedPane.indexOfComponent(debugger.tabbedPane);
|
||||
String label = getInstance().tabbedPane.getTitleAt(index);
|
||||
getInstance().tabbedPane.setTitleAt(index, "(!)" + label);
|
||||
getInstance().tabbedPane.setToolTipTextAt(
|
||||
index,
|
||||
"Connection closed due to the exception: " + e.getMessage());
|
||||
getInstance().tabbedPane.setIconAt(
|
||||
index,
|
||||
connectionClosedOnErrorIcon);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue