<commit_before>/*
 * Created on 08.12.2010
 *
 */
package org.jdesktop.swingx.rollover;

import java.awt.Color;
import java.awt.event.MouseEvent;
import java.util.logging.Logger;

import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.TransferHandler;

import org.jdesktop.swingx.InteractiveTestCase;
import org.jdesktop.swingx.JXFrame;
import org.jdesktop.swingx.JXList;
import org.jdesktop.swingx.JXTable;
import org.jdesktop.swingx.JXTree;
import org.jdesktop.swingx.decorator.ColorHighlighter;
import org.jdesktop.swingx.decorator.HighlightPredicate;
import org.jdesktop.swingx.renderer.DefaultListRenderer;
import org.jdesktop.swingx.renderer.DefaultTableRenderer;
import org.jdesktop.swingx.renderer.DefaultTreeRenderer;
import org.jdesktop.test.AncientSwingTeam;

public class RolloverVisualCheck extends InteractiveTestCase {
    
    @SuppressWarnings("unused")
    private static final Logger LOG = Logger
            .getLogger(RolloverVisualCheck.class.getName());

    public static void main(String[] args) {
        RolloverVisualCheck test = new RolloverVisualCheck();
        try {
            test.runInteractive("Drag");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    /**
     * Issue #456-swingx: Rollover highlighter not showing while dragging.
     * 
     * Example how to force rollover while dragging (NOT dnd - in that case the visuals
     * are controlled by the dnd mechanism): subclass JXList to install a custom 
     * RolloverProducer
     */
    public void interactiveEnforceRolloverWhileDragging() {
        final JXList list = new JXList(AncientSwingTeam.createNamedColorListModel()) {

            /** 
             * @inherited <p>
             */
            @Override
            protected RolloverProducer createRolloverProducer() {
                ListRolloverProducer producer = new ListRolloverProducer() {

                    /** 
                     * @inherited <p>
                     */
                    @Override
                    public void mouseDragged(MouseEvent e) {
                        super.mouseDragged(e);
                        updateRollover(e, ROLLOVER_KEY, false);
                    }
                    
                };
                return producer;
            }
            
        };
        list.setVisibleRowCount(list.getElementCount());
        list.setRolloverEnabled(true);
        list.addHighlighter(new ColorHighlighter(
                HighlightPredicate.ROLLOVER_ROW, 
                Color.MAGENTA, null, Color.MAGENTA, null));
        
        TransferHandler handler = new TransferHandler() {
            
            /** 
             * @inherited <p>
             */
            @Override
            public boolean canImport(TransferSupport support) {
                return true;
            }
            
        };
        list.setTransferHandler(handler);
        JXFrame frame = wrapWithScrollingInFrame(list, "force Rollover while dragging");
        JTextField textField = new JTextField("just something to drag ...", 40);
        textField.setDragEnabled(true);
        addStatusComponent(frame, textField);
        show(frame);
    }
    
    /**
     * Issue #456-swingx: Rollover highlighter not showing while dragging.
     */
    public void interactiveRolloverWhileDragging() {
        final JXList list = new JXList(AncientSwingTeam.createNamedColorListModel());
        list.setVisibleRowCount(list.getElementCount());
        list.setRolloverEnabled(true);
        list.addHighlighter(new ColorHighlighter(
                HighlightPredicate.ROLLOVER_ROW, 
                Color.MAGENTA, null, Color.MAGENTA, null));

        TransferHandler handler = new TransferHandler() {

            /** 
             * @inherited <p>
             */
            @Override
            public boolean canImport(TransferSupport support) {
                return true;
            }
            
        };
        list.setTransferHandler(handler);
        JXFrame frame = wrapWithScrollingInFrame(list, "rollover and drag-enabled (fake drop)");
        JTextField textField = new JTextField("just something to drag ...", 40);
        textField.setDragEnabled(true);
        addStatusComponent(frame, textField);
        show(frame);
    }
    
    /**
     * Issue #456-swingx: Rollover highlighter not showing while dragging.
     */
    public void interactiveRolloverClickAfterDrag() {
        JXList list = new JXList(AncientSwingTeam.createNamedColorListModel());
        list.setVisibleRowCount(list.getElementCount());
        list.setRolloverEnabled(true);
        final JXFrame frame = showWithScrollingInFrame(list, "disable table must not trigger rollover renderer");
        // rollover-enabled default renderer
        DefaultListRenderer renderer = new DefaultListRenderer() {
            @Override
            public void doClick() {
                JOptionPane.showMessageDialog(frame, "Click");
            }
            
            @Override
            public boolean isEnabled() {
                return true;
            }
        };
        list.setCellRenderer(renderer);
    }
    
    /**
     * Issue #1374-swingx: Rollover click must be disabled if target disabled
     * 
     * Visual test for JXTable, adapted from reporter's test case
     */
    public void interactiveRolloverDisabledClickList() {
        JXList table = new JXList(AncientSwingTeam.createNamedColorListModel());
        table.setEnabled(false);
        table.setRolloverEnabled(true);
        final JXFrame frame = showWithScrollingInFrame(table, "disable table must not trigger rollover renderer");
        // rollover-enabled default renderer
        DefaultListRenderer renderer = new DefaultListRenderer() {
            @Override
            public void doClick() {
                JOptionPane.showMessageDialog(frame, "Click");
            }
            
            @Override
            public boolean isEnabled() {
                return true;
            }
        };
        table.setCellRenderer(renderer);
        addEnabledToggle(frame, table);
    }
    <commit_msg>Issue #1387-swingx: RolloverProducer behaviour on release-after-drag - visual test update<commit_after>/*
 * Created on 08.12.2010
 *
 */
package org.jdesktop.swingx.rollover;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
import java.util.logging.Logger;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.TransferHandler;

import org.jdesktop.swingx.InteractiveTestCase;
import org.jdesktop.swingx.JXFrame;
import org.jdesktop.swingx.JXList;
import org.jdesktop.swingx.JXTable;
import org.jdesktop.swingx.JXTree;
import org.jdesktop.swingx.decorator.ColorHighlighter;
import org.jdesktop.swingx.decorator.HighlightPredicate;
import org.jdesktop.swingx.renderer.DefaultListRenderer;
import org.jdesktop.swingx.renderer.DefaultTableRenderer;
import org.jdesktop.swingx.renderer.DefaultTreeRenderer;
import org.jdesktop.test.AncientSwingTeam;

public class RolloverVisualCheck extends InteractiveTestCase {
    
    @SuppressWarnings("unused")
    private static final Logger LOG = Logger
            .getLogger(RolloverVisualCheck.class.getName());

    public static void main(String[] args) {
        RolloverVisualCheck test = new RolloverVisualCheck();
        try {
            test.runInteractive("Drag");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    /**
     * Issue #456-swingx: Rollover highlighter not showing while dragging.
     * 
     * Example how to force rollover while dragging (NOT dnd - in that case the visuals
     * are controlled by the dnd mechanism): subclass JXList to install a custom 
     * RolloverProducer
     */
    public void interactiveEnforceRolloverWhileDragging() {
        final JXList list = new JXList(AncientSwingTeam.createNamedColorListModel()) {

            /** 
             * @inherited <p>
             */
            @Override
            protected RolloverProducer createRolloverProducer() {
                ListRolloverProducer producer = new ListRolloverProducer() {

                    /** 
                     * @inherited <p>
                     */
                    @Override
                    public void mouseDragged(MouseEvent e) {
                        super.mouseDragged(e);
                        updateRollover(e, ROLLOVER_KEY, false);
                    }
                    
                };
                return producer;
            }
            
        };
        list.setVisibleRowCount(list.getElementCount());
        list.setRolloverEnabled(true);
        list.addHighlighter(new ColorHighlighter(
                HighlightPredicate.ROLLOVER_ROW, 
                Color.MAGENTA, null, Color.MAGENTA, null));
        
        TransferHandler handler = new TransferHandler() {
            
            /** 
             * @inherited <p>
             */
            @Override
            public boolean canImport(TransferSupport support) {
                return true;
            }
            
        };
        list.setTransferHandler(handler);
        JXFrame frame = wrapWithScrollingInFrame(list, "force Rollover while dragging");
        JTextField textField = new JTextField("just something to drag ...", 40);
        textField.setDragEnabled(true);
        addStatusComponent(frame, textField);
        show(frame);
    }
    
    /**
     * Issue #456-swingx: Rollover highlighter not showing while dragging.
     */
    public void interactiveRolloverWhileDragging() {
        final JXList list = new JXList(AncientSwingTeam.createNamedColorListModel());
        list.setVisibleRowCount(list.getElementCount());
        list.setRolloverEnabled(true);
        list.addHighlighter(new ColorHighlighter(
                HighlightPredicate.ROLLOVER_ROW, 
                Color.MAGENTA, null, Color.MAGENTA, null));

        TransferHandler handler = new TransferHandler() {

            /** 
             * @inherited <p>
             */
            @Override
            public boolean canImport(TransferSupport support) {
                return true;
            }
            
        };
        list.setTransferHandler(handler);
        JXFrame frame = wrapWithScrollingInFrame(list, "rollover and drag-enabled (fake drop)");
        JTextField textField = new JTextField("just something to drag ...", 40);
        textField.setDragEnabled(true);
        addStatusComponent(frame, textField);
        show(frame);
    }
    
    /**
     * Issue #1387-swingx: Rollover click-on-release-after drag.
     * 
     * PENDING JW: what's the expected behaviour?
     */
    public void interactiveRolloverClickAfterDrag() {
        JXList list = new JXList(AncientSwingTeam.createNamedColorListModel());
        list.setVisibleRowCount(list.getElementCount());
        list.setRolloverEnabled(true);

        TransferHandler handler = new TransferHandler() {

            /** 
             * @inherited <p>
             */
            @Override
            public boolean canImport(TransferSupport support) {
                return true;
            }
            
        };
        list.setTransferHandler(handler);
        final JXFrame frame = wrapWithScrollingInFrame(list, "release-after-drag must not trigger clicked");
        // rollover-enabled default renderer
        DefaultListRenderer renderer = new DefaultListRenderer() {
            @Override
            public void doClick() {
                JOptionPane.showMessageDialog(frame, "Click");
            }
            
            @Override
            public boolean isEnabled() {
                return true;
            }
        };
        list.setCellRenderer(renderer);
        JTextField textField = new JTextField("just something to drag ...", 40);
        textField.setDragEnabled(true);
        addStatusComponent(frame, textField);
        Action action = new AbstractAction("drag into me - am I called on release?") {
            
            @Override
            public void actionPerformed(ActionEvent e) {
                LOG.info("triggered...");
            }
        };
        JButton button = new JButton(action);
        addStatusComponent(frame, button);
        show(frame);
    }
    
    /**
     * Issue #1374-swingx: Rollover click must be disabled if target disabled
     * 
     * Visual test for JXTable, adapted from reporter's test case
     */
    public void interactiveRolloverDisabledClickList() {
        JXList table = new JXList(AncientSwingTeam.createNamedColorListModel());
        table.setEnabled(false);
        table.setRolloverEnabled(true);
        final JXFrame frame = showWithScrollingInFrame(table, "disable table must not trigger rollover renderer");
        // rollover-enabled default renderer
        DefaultListRenderer renderer = new DefaultListRenderer() {
            @Override
            public void doClick() {
                JOptionPane.showMessageDialog(frame, "Click");
            }
            
            @Override
            public boolean isEnabled() {
                return true;
            }
        };
        table.setCellRenderer(renderer);
        addEnabledToggle(frame, table);
    }
    
{'fraction_non_alphanumeric': 0.08581227167673153, 'fraction_numerical': 0.004249608588682621, 'mean_word_length': 2.0369028752546976, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4743644', 'n_tokens_mistral': 3622, 'n_tokens_neox': 3389, 'n_words': 754}