/*
 * $Id$
 *
 * Copyright 2007 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.event.ActionEvent;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.logging.Logger;

import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.KeyStroke;

import org.jdesktop.swingx.action.AbstractActionExt;

/**
 * 
 * @author Jeanette Winzenburg
 */
public class JXTaskPaneIssues extends InteractiveTestCase {
    @SuppressWarnings("unused")
    private static final Logger LOG = Logger.getLogger(JXTaskPaneIssues.class
            .getName());
    
    public static void main(String[] args) {
        JXTaskPaneIssues test = new JXTaskPaneIssues();
        try {
            test.runInteractiveTests();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    /**
     * Trying to resize a top-level window on collapsed state changes of a taskpane.
     */
    public void interactiveDialogWithCollapsible() {
        JXTaskPane pane = new JXTaskPane();
        pane.setTitle("dummy ... with a looooooooooooong title");
        Action action = new AbstractActionExt("something to click") {

            public void actionPerformed(ActionEvent e) {
                LOG.info("got me");
            }
            
        };
        JComponent button = (JComponent) pane.add(action);
        Object actionKey = "dummy";
        button.getActionMap().put(actionKey, action);
        KeyStroke keyStroke = KeyStroke.getKeyStroke("F3");
        button.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(keyStroke, actionKey);
        final JXDialog dialog = new JXDialog(pane);
        PropertyChangeListener l = new PropertyChangeListener() {

            public void propertyChange(PropertyChangeEvent evt) {
                if ("collapsed".equals(evt.getPropertyName())) {
                    dialog.pack();
                }
            }
            
        };
        pane.addPropertyChangeListener(l);
        dialog.pack();
        dialog.setVisible(true);
    }
    

    /**
     * Quick check to see if hidden comps receive a keybinding (no).
     */
    public void interactiveDialogWithHidden() {
        JXPanel pane = new JXPanel(new BorderLayout());
        final JLabel label = new JLabel("dummy ... with a looooooooooooong title");
        Action action = new AbstractActionExt("something to click") {

            public void actionPerformed(ActionEvent e) {
                LOG.info("got me");
            }
            
        };
        pane.add(label);
        Object actionKey = "dummy";
        label.getActionMap().put(actionKey, action);
        KeyStroke keyStroke = KeyStroke.getKeyStroke("F3");
        label.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(keyStroke, actionKey);
        
        Action hide = new AbstractActionExt("toggle visible") {

            public void actionPerformed(ActionEvent e) {
                // OOPS ... visible is _not_ a bean property
                // so property change listener is useless if we want to pack
                label.setVisible(!label.isVisible());
            }
            
        };
        pane.add(new JButton(hide), BorderLayout.NORTH);
        final JXDialog dialog = new JXDialog(pane);
        dialog.pack();
        dialog.setVisible(true);
    }
    
    /**
     * Empty test method to keep the test runner happy if we have no 
     * open issues.
     */
    public void testDummy() {
        
    }
}

@@ -962,25 +962,18 @@
 awt.
-e
+E
 vent
-.ActionEvent
+Queue
 ;%0Aim
@@ -996,63 +996,19 @@
 ent.
-ComponentEvent;%0Aimport java.awt.event.ComponentListener
+ActionEvent
 ;%0Aim
@@ -1226,21 +1226,22 @@
 .swing.J
-Label
+Dialog
 ;%0Aimport
@@ -1263,16 +1263,51 @@
 yStroke;
+%0Aimport javax.swing.SwingUtilities;
 %0A%0Aimport
@@ -1931,16 +1931,101 @@
 skpane.%0A
+     * Need to listen to %22animationState%22 which is fired when animation is complete.%0A
      */%0A
@@ -2893,25 +2893,30 @@
    if (%22
-collapsed
+animationState
 %22.equals
@@ -3348,21 +3348,22 @@
  final J
-Label
+Button
  label =
@@ -3372,13 +3372,14 @@
 ew J
-Label
+Button
 (%22du
@@ -3941,22 +3941,33 @@
 xt(%22
-toggle visible
+hide other, then press F3
 %22) %7B
@@ -4356,32 +4356,86 @@
 JXDialog(pane);%0A
+        dialog.setTitle(%22hiding a component plain %22);%0A
         dialog.p
@@ -4476,28 +4476,25 @@
 rue);%0A    %7D%0A
-    
+%0A
 %0A    /**%0A   

update visual test in JXTaskPaneIssues (listen to animationState instead of collapse)