/*
 * Created on 23.05.2005
 *
 */
package org.jdesktop.swingx;

import java.awt.Component;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.AbstractCellEditor;
import javax.swing.Action;
import javax.swing.JTable;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;

import org.jdesktop.swingx.action.LinkAction;
import org.jdesktop.swingx.util.Link;

/**
 * @author Jeanette Winzenburg
 */
public class LinkRenderer extends AbstractCellEditor implements
        TableCellRenderer, TableCellEditor {
    private JXHyperlinkButton linkButton;

    private LinkAction linkAction;

    public LinkRenderer() {
        this(null);
    }

    public LinkRenderer(ActionListener openAction) {
        linkAction = new LinkAction(null);
        linkButton = new JXHyperlinkButton(linkAction);
        linkButton.addActionListener(createEditorActionListener());
        setVisitingDelegate(openAction);
    }

    public void setVisitingDelegate(ActionListener openAction) {
        linkAction.setVisitingDelegate(openAction);
        
    }
    private ActionListener createEditorActionListener() {
        ActionListener l = new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                fireEditingStopped();

            }

        };
        return l;
    }

    public Component getTableCellRendererComponent(JTable table, Object value,
            boolean isSelected, boolean hasFocus, int row, int column) {
        linkAction.setLink(value instanceof Link ? (Link) value : null);
        Point p = (Point) table
                .getClientProperty(RolloverProducer.ROLLOVER_KEY);
        if (p != null && (p.x > 0) && (p.x == column) && (p.y == row)) {
            // JW: toggling model's rollover state is unreliable - hmmm...
             linkButton.getModel().setRollover(true);
           // linkButton.entered(true);
        } else {
             linkButton.getModel().setRollover(false);
          //  linkButton.exited(true);
        }
        return linkButton;
    }

    public Object getCellEditorValue() {
        return linkAction.getLink();
    }

    public Component getTableCellEditorComponent(JTable table, Object value,
            boolean isSelected, int row, int column) {
        linkAction.setLink(value instanceof Link ? (Link) value : null);
        linkButton.getModel().setRollover(true); //entered(true);
        return linkButton;
    }

}

@@ -1719,16 +1719,29 @@
       if
+ (hasFocus %7C%7C
  (p != n
@@ -1792,16 +1792,17 @@
 == row))
+)
  %7B%0A     

make LinkRenderer appear as rollover on hasFocus