package org.yamcs.ui.packetviewer;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.HashSet;
import java.util.Set;

import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.JLabel;
import javax.swing.border.Border;

/**
 * Image that looks and acts like a button, but only when mouse events are
 * performed.
 */
public class ImageIconButton extends JLabel implements MouseListener {

    private static final long serialVersionUID = 1L;
    private static final Border EMPTY_BORDER = BorderFactory.createEmptyBorder(3, 3, 3, 3);
    private static final Border HOVER_BORDER = BorderFactory.createRaisedSoftBevelBorder();
    private static final Border PRESSED_BORDER = BorderFactory.createLoweredSoftBevelBorder();
    private Set<ActionListener> actionListeners = new HashSet<ActionListener>();

    public ImageIconButton(Icon image) {
        super(image);
        setBorder(EMPTY_BORDER);
        addMouseListener(this);
    }

    @Override
    public void mouseEntered(MouseEvent e) {
        setBorder(HOVER_BORDER);
    }

    @Override
    public void mouseExited(MouseEvent e) {
        setBorder(EMPTY_BORDER);
    }

    @Override
    public void mouseReleased(MouseEvent e) {
        setBorder(EMPTY_BORDER);
        if (contains(e.getPoint())) {
            for (ActionListener al : actionListeners) {
                al.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, null));
            }
        }
    }

    @Override
    public void mousePressed(MouseEvent e) {
        setBorder(PRESSED_BORDER);
    }

    @Override
    public void mouseClicked(MouseEvent e) {
        // Ignore, because this does not register clicks when pressing and
        // releasing in the same component, but on a different location
    }

    public void addActionListener(ActionListener al) {
        actionListeners.add(al);
    }

    public void removeActionListener(ActionListener al) {
        actionListeners.remove(al);
    }
}

@@ -341,16 +341,56 @@
 .Border;
+%0Aimport javax.swing.border.EtchedBorder;
 %0A%0A/**%0A *
@@ -688,18 +688,18 @@
 der(
-3, 3, 3, 3
+2, 2, 2, 2
 );%0A 
@@ -768,30 +768,41 @@
 eate
-RaisedSoftBevelBorder(
+EtchedBorder(EtchedBorder.LOWERED
 );%0A 
@@ -873,31 +873,40 @@
 eate
-LoweredSoftBevelBorder(
+EtchedBorder(EtchedBorder.RAISED
 );%0A 

Make ImageIconButton borders compatible to Java 6