quaqua
  1. quaqua
  2. QUAQUA-160

JSheet doesn't work under JDK 7u4, Lion

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Blocker Blocker
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      I'm trying to upgrade my app to JDK 7u4 and I've found a blocker problem with Quaqua 8.0 code:

      [INFO] java.awt.IllegalComponentStateException: The dialog is decorated
      [INFO] at java.awt.Dialog.setOpacity(Dialog.java:1319)
      [INFO] at java.awt.Window$1.setOpacity(Window.java:4008)
      [INFO] at com.sun.awt.AWTUtilities.setWindowOpacity(AWTUtilities.java:174)
      [INFO] at sun.lwawt.macosx.CPlatformWindow$3.applyProperty(CPlatformWindow.java:159)
      [INFO] at sun.lwawt.macosx.CPlatformWindow$3.applyProperty(CPlatformWindow.java:158)
      [INFO] at com.apple.laf.ClientPropertyApplicator.applyProperty(ClientPropertyApplicator.java:45)
      [INFO] at com.apple.laf.ClientPropertyApplicator.propertyChange(ClientPropertyApplicator.java:75)
      [INFO] at java.beans.PropertyChangeSupport.fire(PropertyChangeSupport.java:335)
      [INFO] at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:327)
      [INFO] at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:263)
      [INFO] at java.awt.Component.firePropertyChange(Component.java:8382)
      [INFO] at javax.swing.JComponent.putClientProperty(JComponent.java:4093)
      [INFO] at ch.randelshofer.quaqua.QuaquaUtilities.setWindowAlpha(QuaquaUtilities.java:726)
      [INFO] at ch.randelshofer.quaqua.JSheet.addNotify(JSheet.java:306)
      [INFO] at java.awt.Window.pack(Window.java:807)
      [INFO] at ch.randelshofer.quaqua.JSheet.showSheet(JSheet.java:1190)
      [INFO] at ch.randelshofer.quaqua.JSheet.showSaveSheet(JSheet.java:1119)

      The relevant code is:

      707 /**
      708 * Uses some unsupported (dangerous) API calls on the native peers to make
      709 * a window translucent. If the API is not found, this method leaves the
      710 * window opaque.
      711 *
      712 * @param w The Window.
      713 * @param value The alpha channel for the window.
      714 */
      715 static void setWindowAlpha(Window w, int value) {
      716 if (w == null)

      { 717 return; 718 }

      719
      720
      721 if (w instanceof RootPaneContainer)

      { 722 JRootPane rp = ((RootPaneContainer) w).getRootPane(); 723 724 // Window alpha is for J2SE 5 on Mac OS X 10.5 725 // See: http://developer.apple.com/technotes/tn2007/tn2196.html#WINDOW_ALPHA 726 rp.putClientProperty("Window.alpha", new Float(value / 255f)); 727 728 }

      729 }

      302 @Override
      303 public void addNotify() {
      304 super.addNotify();
      305 if (UIManager.getBoolean("Sheet.showAsSheet") && !isExperimentalSheet())

      { 306 QuaquaUtilities.setWindowAlpha(this, 240); 307 }

      308 }

      I read also:

      • Caveats: We are using an unsupported API call to make the JSheet translucent.
      • This API may go away in future versions of the Macintosh Runtime for Java.
      • In such a case, we (hopefully) just end up with a non-opaque sheet.

      Unfortunately, the translucency API now just breaks. I'm asking to the Apple Java dev mailing list about more information, but I suppose that the best thing to do is to disable the call for JDK 7u4.

        Activity

        Hide
        fabriziogiudici added a comment -

        UIManager.put("Sheet.showAsSheet", false) can be used as a temporary workaround (but the sheet is not rendered as a native widget).

        Show
        fabriziogiudici added a comment - UIManager.put("Sheet.showAsSheet", false) can be used as a temporary workaround (but the sheet is not rendered as a native widget).
        Hide
        fabriziogiudici added a comment -

        The problem is still present with JDK 7u7.

        Show
        fabriziogiudici added a comment - The problem is still present with JDK 7u7.
        Hide
        trejkaz added a comment - - edited

        Still present with JDK 7u45. Additionally, the suggested workaround doesn't work either - the sheet never becomes visible and focus is taken away from my window, so I'm unable to use the application once an attempt has been made to show a sheet.

        Show
        trejkaz added a comment - - edited Still present with JDK 7u45. Additionally, the suggested workaround doesn't work either - the sheet never becomes visible and focus is taken away from my window, so I'm unable to use the application once an attempt has been made to show a sheet.
        Hide
        trejkaz added a comment -

        I see this is "fixed" in svn trunk. The sheet doesn't animate at all, but I'm not sure if it's supposed to.

        Show
        trejkaz added a comment - I see this is "fixed" in svn trunk. The sheet doesn't animate at all, but I'm not sure if it's supposed to.
        Hide
        trejkaz added a comment -

        Quaqua 9.1 displays the sheet but still doesn't animate it.

        Test program is a version of someone else's example which I modified to make it act on windowClosing because I wasn't sure if the problem was something to do with how JSheet was being used.

        import java.awt.Dimension;
        import java.awt.event.WindowAdapter;
        import java.awt.event.WindowEvent;
        
        import javax.swing.JFrame;
        import javax.swing.JOptionPane;
        import javax.swing.SwingUtilities;
        import javax.swing.UIManager;
        import javax.swing.WindowConstants;
        
        import ch.randelshofer.quaqua.JSheet;
        import ch.randelshofer.quaqua.SheetEvent;
        import ch.randelshofer.quaqua.SheetListener;
        
        public class QuaquaJSheetTest implements Runnable
        {
            public static void main(String[] args) throws Exception
            {
                System.setProperty("Quaqua.tabLayoutPolicy", "wrap");
                UIManager.setLookAndFeel("ch.randelshofer.quaqua.QuaquaLookAndFeel");
                SwingUtilities.invokeLater(new QuaquaJSheetTest());
            }
        
            @Override
            public void run()
            {
                JFrame editorFrame = new JFrame("Java Mac OS X Quaqua Test");
                constructAndDisplayJFrame(editorFrame);
            }
        
            private void constructAndDisplayJFrame(final JFrame editorFrame)
            {
                editorFrame.addWindowListener(new WindowAdapter()
                {
                    @Override
                    public void windowClosing(WindowEvent event)
                    {
                        displayJSheet(editorFrame);
                    }
                });
        
                editorFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
                editorFrame.setPreferredSize(new Dimension(300, 185));
                editorFrame.pack();
                editorFrame.setLocationRelativeTo(null);
                editorFrame.setVisible(true);
            }
        
            /**
             * Displays a JSheet using the Quaqua framework.
             * This code was just copied from the Quaqua help pages.
             */
            private void displayJSheet(final JFrame editorFrame)
            {
                JOptionPane pane = new JOptionPane(
                    "<html>"+UIManager.getString("OptionPane.css")+
                    "<b>Do you want to save changes to this document<br>"+
                    "before closing?</b><p>"+
                    "If you don't save, your changes will be lost.",
                    JOptionPane.WARNING_MESSAGE
                );
        
                Object[] options = { "Save", "Cancel", "Don't Save" };
                pane.setOptions(options);
                pane.setInitialValue(options[0]);
                pane.putClientProperty("Quaqua.OptionPane.destructiveOption", new Integer(2));
        
                JSheet.showSheet(pane, editorFrame, new SheetListener()
                {
                    @Override
                    public void optionSelected(SheetEvent event)
                    {
                        Object value = event.getValue();
                        if (value == null || value.equals("Cancel"))
                        {
                            editorFrame.setEnabled(true);
                        }
                        else if (value.equals("Don't Save"))
                        {
                            editorFrame.dispose();
                        }
                        else if (value.equals("Save"))
                        {
                            //saveChanges();
                        }
                    }
                });
            }
        }
        
        Show
        trejkaz added a comment - Quaqua 9.1 displays the sheet but still doesn't animate it. Test program is a version of someone else's example which I modified to make it act on windowClosing because I wasn't sure if the problem was something to do with how JSheet was being used. import java.awt.Dimension; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.SwingUtilities; import javax.swing.UIManager; import javax.swing.WindowConstants; import ch.randelshofer.quaqua.JSheet; import ch.randelshofer.quaqua.SheetEvent; import ch.randelshofer.quaqua.SheetListener; public class QuaquaJSheetTest implements Runnable { public static void main( String [] args) throws Exception { System .setProperty( "Quaqua.tabLayoutPolicy" , "wrap" ); UIManager.setLookAndFeel( "ch.randelshofer.quaqua.QuaquaLookAndFeel" ); SwingUtilities.invokeLater( new QuaquaJSheetTest()); } @Override public void run() { JFrame editorFrame = new JFrame( "Java Mac OS X Quaqua Test" ); constructAndDisplayJFrame(editorFrame); } private void constructAndDisplayJFrame( final JFrame editorFrame) { editorFrame.addWindowListener( new WindowAdapter() { @Override public void windowClosing(WindowEvent event) { displayJSheet(editorFrame); } }); editorFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); editorFrame.setPreferredSize( new Dimension(300, 185)); editorFrame.pack(); editorFrame.setLocationRelativeTo( null ); editorFrame.setVisible( true ); } /** * Displays a JSheet using the Quaqua framework. * This code was just copied from the Quaqua help pages. */ private void displayJSheet( final JFrame editorFrame) { JOptionPane pane = new JOptionPane( "<html>" +UIManager.getString( "OptionPane.css" )+ "<b>Do you want to save changes to this document<br>" + "before closing?</b><p>" + "If you don't save, your changes will be lost." , JOptionPane.WARNING_MESSAGE ); Object [] options = { "Save" , "Cancel" , "Don't Save" }; pane.setOptions(options); pane.setInitialValue(options[0]); pane.putClientProperty( "Quaqua.OptionPane.destructiveOption" , new Integer (2)); JSheet.showSheet(pane, editorFrame, new SheetListener() { @Override public void optionSelected(SheetEvent event) { Object value = event.getValue(); if (value == null || value.equals( "Cancel" )) { editorFrame.setEnabled( true ); } else if (value.equals( "Don't Save" )) { editorFrame.dispose(); } else if (value.equals( "Save" )) { //saveChanges(); } } }); } }

          People

          • Assignee:
            Unassigned
            Reporter:
            fabriziogiudici
          • Votes:
            2 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated: