use of javax.swing.Icon in project Smack by igniterealtime.
the class EnhancedDebugger method addReadPacketToTable.
/**
* Adds the received stanza(/packet) detail to the messages table.
*
* @param dateFormatter the SimpleDateFormat to use to format Dates
* @param packet the read stanza(/packet) to add to the table
*/
private void addReadPacketToTable(final SimpleDateFormat dateFormatter, final Stanza packet) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
String messageType;
Jid 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++;
}
// Check if we need to remove old rows from the table to keep memory consumption low
if (EnhancedDebuggerWindow.MAX_TABLE_ROWS > 0 && messagesTable.getRowCount() >= EnhancedDebuggerWindow.MAX_TABLE_ROWS) {
messagesTable.removeRow(0);
}
messagesTable.addRow(new Object[] { formatXML(packet.toXML().toString()), dateFormatter.format(new Date()), packetReceivedIcon, packetTypeIcon, messageType, packet.getStanzaId(), type, "", from });
// Update the statistics table
updateStatistics();
}
});
}
use of javax.swing.Icon in project Smack by igniterealtime.
the class EnhancedDebugger method addSentPacketToTable.
/**
* Adds the sent stanza(/packet) detail to the messages table.
*
* @param dateFormatter the SimpleDateFormat to use to format Dates
* @param packet the sent stanza(/packet) to add to the table
*/
private void addSentPacketToTable(final SimpleDateFormat dateFormatter, final Stanza packet) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
String messageType;
Jid 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++;
}
// Check if we need to remove old rows from the table to keep memory consumption low
if (EnhancedDebuggerWindow.MAX_TABLE_ROWS > 0 && messagesTable.getRowCount() >= EnhancedDebuggerWindow.MAX_TABLE_ROWS) {
messagesTable.removeRow(0);
}
messagesTable.addRow(new Object[] { formatXML(packet.toXML().toString()), dateFormatter.format(new Date()), packetSentIcon, packetTypeIcon, messageType, packet.getStanzaId(), type, to, "" });
// Update the statistics table
updateStatistics();
}
});
}
use of javax.swing.Icon in project jna by java-native-access.
the class GhostedDragImageDemo method main.
public static void main(String[] args) {
try {
System.setProperty("sun.java2d.noddraw", "true");
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
JFrame f1 = new JFrame("Drag this");
JFrame f2 = new JFrame("Over here");
URL url = GhostedDragImageDemo.class.getResource("toucan.png");
if (url == null)
throw new RuntimeException("Icon not found");
Icon icon = new ImageIcon(url);
f1.getContentPane().add(new DragLabel(icon));
JLabel label2 = new DragLabel(icon);
f2.getContentPane().add(label2);
f1.setLocation(100, 100);
f1.pack();
f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f2.setLocation(300, 100);
f2.pack();
label2.setIcon(null);
f2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f2.setVisible(true);
f1.setVisible(true);
} catch (Throwable t) {
t.printStackTrace();
System.exit(1);
}
}
use of javax.swing.Icon in project jna by java-native-access.
the class DragHandler method dragGestureRecognized.
/** Called when a user drag gesture is recognized. This method is
* responsible for initiating the drag operation.
* @param e event
*/
public void dragGestureRecognized(DragGestureEvent e) {
if ((e.getDragAction() & supportedActions) != 0 && canDrag(e)) {
setModifiers(e.getTriggerEvent().getModifiersEx() & KEY_MASK);
Transferable transferable = getTransferable(e);
if (transferable == null)
return;
try {
Point srcOffset = new Point(0, 0);
Icon icon = getDragIcon(e, srcOffset);
Point origin = e.getDragOrigin();
// offset of the image origin from the cursor
imageOffset = new Point(srcOffset.x - origin.x, srcOffset.y - origin.y);
Icon dragIcon = scaleDragIcon(icon, imageOffset);
Cursor cursor = null;
if (dragIcon != null && DragSource.isDragImageSupported()) {
GraphicsConfiguration gc = e.getComponent().getGraphicsConfiguration();
e.startDrag(cursor, createDragImage(gc, dragIcon), imageOffset, transferable, this);
} else {
if (dragIcon != null) {
Point screen = dragSource.getLocationOnScreen();
screen.translate(origin.x, origin.y);
Point cursorOffset = new Point(-imageOffset.x, -imageOffset.y);
ghost = new GhostedDragImage(dragSource, dragIcon, getImageLocation(screen), cursorOffset);
ghost.setAlpha(ghostAlpha);
}
e.startDrag(cursor, transferable, this);
}
dragStarted(e);
moved = false;
e.getDragSource().addDragSourceMotionListener(this);
DragHandler.transferable = transferable;
} catch (InvalidDnDOperationException ex) {
if (ghost != null) {
ghost.dispose();
ghost = null;
}
}
}
}
use of javax.swing.Icon in project jadx by skylot.
the class OverlayIcon method paintIcon.
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
int w = getIconWidth();
int h = getIconHeight();
icon.paintIcon(c, g, x, y);
int k = 0;
for (Icon subIcon : icons) {
int dx = (int) (OVERLAY_POS[k++] * (w - subIcon.getIconWidth()));
int dy = (int) (OVERLAY_POS[k++] * (h - subIcon.getIconHeight()));
subIcon.paintIcon(c, g, x + dx, y + dy);
}
}
Aggregations