Search in sources :

Example 1 with Icon

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();
        }
    });
}
Also used : Jid(org.jxmpp.jid.Jid) EntityFullJid(org.jxmpp.jid.EntityFullJid) Message(org.jivesoftware.smack.packet.Message) IQ(org.jivesoftware.smack.packet.IQ) Presence(org.jivesoftware.smack.packet.Presence) Icon(javax.swing.Icon) ImageIcon(javax.swing.ImageIcon) Date(java.util.Date)

Example 2 with Icon

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();
        }
    });
}
Also used : Jid(org.jxmpp.jid.Jid) EntityFullJid(org.jxmpp.jid.EntityFullJid) Message(org.jivesoftware.smack.packet.Message) IQ(org.jivesoftware.smack.packet.IQ) Presence(org.jivesoftware.smack.packet.Presence) Icon(javax.swing.Icon) ImageIcon(javax.swing.ImageIcon) Date(java.util.Date)

Example 3 with Icon

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);
    }
}
Also used : ImageIcon(javax.swing.ImageIcon) JFrame(javax.swing.JFrame) JLabel(javax.swing.JLabel) Icon(javax.swing.Icon) ImageIcon(javax.swing.ImageIcon) URL(java.net.URL)

Example 4 with Icon

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;
            }
        }
    }
}
Also used : InvalidDnDOperationException(java.awt.dnd.InvalidDnDOperationException) Transferable(java.awt.datatransfer.Transferable) Point(java.awt.Point) Icon(javax.swing.Icon) Cursor(java.awt.Cursor) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 5 with Icon

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);
    }
}
Also used : Icon(javax.swing.Icon)

Aggregations

Icon (javax.swing.Icon)77 ImageIcon (javax.swing.ImageIcon)40 JLabel (javax.swing.JLabel)15 Component (java.awt.Component)7 Color (java.awt.Color)6 Graphics2D (java.awt.Graphics2D)4 Point (java.awt.Point)4 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 Dimension (java.awt.Dimension)3 FontMetrics (java.awt.FontMetrics)3 Insets (java.awt.Insets)3 MouseEvent (java.awt.event.MouseEvent)3 Map (java.util.Map)3 JComponent (javax.swing.JComponent)3 FlowLayout (java.awt.FlowLayout)2 Font (java.awt.Font)2 GradientPaint (java.awt.GradientPaint)2 KeyEvent (java.awt.event.KeyEvent)2 MouseAdapter (java.awt.event.MouseAdapter)2