<commit_before>/*
 * $Id$
 *
 * Copyright 2006 Sun Microsystems, Inc., 4150 Network Circle,
 * Santa Clara, California 95054, U.S.A. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */
package org.jdesktop.swingx;


import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Paint;
import java.awt.event.ActionEvent;

import javax.imageio.ImageIO;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

import org.jdesktop.swingx.action.AbstractActionExt;
import org.jdesktop.swingx.painter.ImagePainter;
import org.jdesktop.swingx.painter.MattePainter;
import org.jdesktop.swingx.util.PaintUtils;

/**
 * Contains methods to visually test JXPanel.
 * 
 * @author <NAME>
 */
public class JXPanelVisualCheck extends InteractiveTestCase {

    public static void main(String args[]) {
      final JXPanelVisualCheck test = new JXPanelVisualCheck();
      setLAF("Nimbus");
      SwingUtilities.invokeLater(new Runnable() {
          public void run() {
      try {
                
//         test.runInteractiveTests("interactive.*");
         test.runInteractive("BackgroundAlpha");
//         test.runInteractive("BackgroundAndAlphaCheck");
//         test.runInteractive("FrameArtefacts");
         
      } catch (Exception e) {
          System.err.println("exception when executing interactive tests:");
          e.printStackTrace();
      }
          }
      });
  }
    
    /**
     * Issue #1515-swingx: painting artefacts in a JXFrame (which uses JXPanel as rootPane)
     * 
     * If the upper frame contains a JXPanel with alpha, the lower background is painted
     * only below the area of the upper frame.
     * All fine without alpha on the upper.
     * The exact outcome is erractic (sometimes half or even fully painted). 
     * On/off EDT doesn't seem to make a difference.
     */
    public void interactiveXPanelInFrameArtefacts() {
        JPanel panel = new JPanel();
        Color red = Color.RED;
        panel.setBackground(red);
        JXFrame frame = wrapInFrame(panel, "plain panel added to contentPane of a xframe");
        show(frame, 400, 400);
        
        JXPanel other = new JXPanel();
        other.setAlpha(.5f);
        JXFrame otherFrame = wrapInFrame(other, "xpanel with alpha, showing on top of first");
        show(otherFrame, 100, 100);
    }
    
    /**
     * Issue #1516-swingx: need feature to _not_ paint the background if alpha and not-opaque
     * 
     * 
     */
    public void interactiveBackgroundAlphaToggleOpaque() {
        final JXPanel panel = new JXPanel();
        final boolean initialOpaque = false;
        panel.setOpaque(initialOpaque);
        Color red = Color.RED;
        Color alpha = PaintUtils.setAlpha(red, 100);
        panel.setBackground(alpha);
        JXFrame frame = wrapInFrame(panel, "changing opaque has no effect with alpha background");
        Action action = new AbstractAction("toggle opaque") {
            boolean realOpaque = initialOpaque;
            @Override
            public void actionPerformed(ActionEvent e) {
                realOpaque = !realOpaque;
                panel.setOpaque(realOpaque);
            }
        };
        addAction(frame, action);
        show(frame, 400, 400);
    }
    
    /**
     * Issue 1517-swingx: JXPanel - background color depends on opaqueness prior to setting   
     */
    public void interactiveBackgroundAlphaColorDependsOnOpaque() {
        JPanel container = new JPanel(new GridLayout(0, 2));
        Color alpha = PaintUtils.setAlpha(Color.RED, 100);
        
        JXPanel opaque = new JXPanel();
        opaque.setBackground(alpha);
        
        JXPanel nonOpaque = new JXPanel();
        nonOpaque.setOpaque(false);
        nonOpaque.setBackground(alpha);
        
        container.add(opaque);
        container.add(nonOpaque);<commit_msg>Update test to show core issues.  We need a possible workaround in JXPanel.<commit_after>/*
 * $Id$
 *
 * Copyright 2006 Sun Microsystems, Inc., 4150 Network Circle,
 * Santa Clara, California 95054, U.S.A. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */
package org.jdesktop.swingx;


import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Paint;
import java.awt.event.ActionEvent;

import javax.imageio.ImageIO;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

import org.jdesktop.swingx.action.AbstractActionExt;
import org.jdesktop.swingx.painter.ImagePainter;
import org.jdesktop.swingx.painter.MattePainter;
import org.jdesktop.swingx.util.PaintUtils;

/**
 * Contains methods to visually test JXPanel.
 * 
 * @author <NAME>
 */
public class JXPanelVisualCheck extends InteractiveTestCase {

    public static void main(String args[]) {
      final JXPanelVisualCheck test = new JXPanelVisualCheck();
//      setLAF("Nimbus");
      SwingUtilities.invokeLater(new Runnable() {
          @Override
        public void run() {
      try {
                
//         test.runInteractiveTests("interactive.*");
         test.runInteractiveTests("interactiveBackgroundAlphaToggleOpaque");
//         test.runInteractive("BackgroundAndAlphaCheck");
//         test.runInteractive("FrameArtefacts");
         
      } catch (Exception e) {
          System.err.println("exception when executing interactive tests:");
          e.printStackTrace();
      }
          }
      });
  }
    
    /**
     * Issue #1515-swingx: painting artefacts in a JXFrame (which uses JXPanel as rootPane)
     * 
     * If the upper frame contains a JXPanel with alpha, the lower background is painted
     * only below the area of the upper frame.
     * All fine without alpha on the upper.
     * The exact outcome is erractic (sometimes half or even fully painted). 
     * On/off EDT doesn't seem to make a difference.
     */
    public void interactiveXPanelInFrameArtefacts() {
        JPanel panel = new JPanel();
        Color red = Color.RED;
        panel.setBackground(red);
        JXFrame frame = wrapInFrame(panel, "plain panel added to contentPane of a xframe");
        show(frame, 400, 400);
        
        JXPanel other = new JXPanel();
        other.setAlpha(.5f);
        JXFrame otherFrame = wrapInFrame(other, "xpanel with alpha, showing on top of first");
        show(otherFrame, 100, 100);
    }
    
    /**
     * Issue #1516-swingx: need feature to _not_ paint the background if alpha and not-opaque
     * 
     * 
     */
    public void interactiveBackgroundAlphaToggleOpaque() {
        JPanel container = new JPanel(new GridLayout(0, 3));
        Color base = Color.RED;
        Color alpha = PaintUtils.setAlpha(base, 100);
        
        final JPanel p = new JPanel();
        p.setBackground(alpha);
        
        final JXPanel xp1 = new JXPanel();
        xp1.setBackground(alpha);
        
        final JXPanel xp2 = new JXPanel();
        xp2.setAlpha(100f/255f);
        xp2.setBackground(base);
        
        container.add(p);
        container.add(xp1);
        container.add(xp2);
        
        JXFrame frame = wrapInFrame(container, "changing opaque has no effect with alpha background");
        Action action = new AbstractAction("opaque on") {
            boolean realOpaque = true;
            @Override
            public void actionPerformed(ActionEvent e) {
                realOpaque = !realOpaque;
                
                putValue(Action.NAME, realOpaque ? "opaque on" : "opaque off");
                
                p.setOpaque(realOpaque);
                xp1.setOpaque(realOpaque);
                xp2.setOpaque(realOpaque);
                
                p.repaint();
                xp1.repaint();
                xp2.repaint();
            }
        };
        addAction(frame, action);
        show(frame, 400, 400);
    }
    
    /**
     * Issue 1517-swingx: JXPanel - background color depends on opaqueness prior to setting   
     */
    public void interactiveBackgroundAlphaColorDependsOnOpaque() {
        JPanel container = new JPanel(new GridLayout(0, 2));
        Color alpha = PaintUtils.setAlpha(Color.RED, 100);
        
        JXPanel opaque = new JXPanel();
        opaque.setBackground(alpha);
        
        JXPanel nonOpaque = new JXPanel();
        nonOpaque.setOpaque(false);
        nonOpaque.setBackground(alpha);
        
        container.add(opaque);
        container.add(nonOpaque);
{'fraction_non_alphanumeric': 0.08939423642423054, 'fraction_numerical': 0.014604979415800823, 'mean_word_length': 2.5637443241355222, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6542185', 'n_tokens_mistral': 3014, 'n_tokens_neox': 2821, 'n_words': 884}