Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #17096 > unrolled thread

Light Box Effect (2 Windows, 1 Smaller And Active Above Inactive

Started by"clusardi2k" <clusardi2k@1:261/38.remove-yy0-this>
First post2012-08-03 18:54 +0000
Last post2012-08-17 18:56 +0000
Articles 10 — 7 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  Light Box Effect (2 Windows, 1 Smaller And Active Above Inactive "clusardi2k" <clusardi2k@1:261/38.remove-yy0-this> - 2012-08-03 18:54 +0000
    Re: Light Box Effect (2 Windows, 1 Smaller And Active Above Inactive "markspace" <markspace@1:261/38.remove-21x-this> - 2012-08-03 19:56 +0000
      Re: Light Box Effect (2 Windows, 1 Smaller And Active Above Inactive clusardi2k@aol.com - 2012-08-03 12:59 -0700
        Re: Light Box Effect (2 Windows, 1 Smaller And Active Above Inactive markspace <-@.> - 2012-08-03 13:31 -0700
          Re: Light Box Effect (2 Windows, 1 Smaller And Active Above Inactive clusardi2k@aol.com - 2012-08-04 01:16 -0700
            Re: Light Box Effect (2 Windows, 1 Smaller And Active Above Inactive markspace <-@.> - 2012-08-04 08:55 -0700
      Re: Light Box Effect (2 Windows, 1 Smaller And Active Above Inactive "clusardi2k" <clusardi2k@1:261/38.remove-sao-this> - 2012-08-06 18:08 +0000
        Re: Light Box Effect (2 Windows, 1 Smaller And Active Above Inactive "markspace" <markspace@1:261/38.remove-sao-this> - 2012-08-06 18:08 +0000
          Re: Light Box Effect (2 Windows, 1 Smaller And Active Above Inactive "clusardi2k" <clusardi2k@1:261/38.remove-4g4-this> - 2012-08-17 18:56 +0000
          Re: Light Box Effect (2 Windows, 1 Smaller And Active Above Inactive "clusardi2k" <clusardi2k@1:261/38.remove-4g4-this> - 2012-08-17 18:56 +0000

#17096 — Light Box Effect (2 Windows, 1 Smaller And Active Above Inactive

From"clusardi2k" <clusardi2k@1:261/38.remove-yy0-this>
Date2012-08-03 18:54 +0000
SubjectLight Box Effect (2 Windows, 1 Smaller And Active Above Inactive
Message-ID<501C156A.56055.calajapr@time.synchro.net>
From: clusardi2k@aol.com

Does anybody have a project that will give me a Light Box effect to a project.

A Light Box Effect produces two windows. One window will be active, but the one 
below it will be inactive and grayed out.

Here's an image of what I want to achieve.

http://stackoverflow.com/questions/6605964/lightbox-effect-in-swing

I'm not interested in licensed code.

Thank you,

--- BBBS/Li6 v4.10 Dada-1
 * Origin: Prism bbs (1:261/38)
--- Synchronet 3.16a-Win32 NewsLink 1.98
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [next] | [standalone]


#17097

From"markspace" <markspace@1:261/38.remove-21x-this>
Date2012-08-03 19:56 +0000
Message-ID<501C20B2.56058.calajapr@time.synchro.net>
In reply to#17096
  To: clusardi2k
From: markspace <-@.>

On 8/3/2012 10:37 AM, clusardi2k@aol.com wrote:
> Does anybody have a project that will give me a Light Box effect to a
> project.
>
> A Light Box Effect produces two windows. One window will be active,
> but the one below it will be inactive and grayed out.
>
> Here's an image of what I want to achieve.
>
> http://stackoverflow.com/questions/6605964/lightbox-effect-in-swing


There's a class JLayer which provides the basics.  You'll have to provide a 
fair amount of code though;  I'm not aware of any class that provides a 
lightbox feature.

There's also a book call Swing Hacks which has some interesting ideas, 
including an animated window similar to what you are asking for.  Still not 
exactly a lightbox however.

<http://docs.oracle.com/javase/tutorial/uiswing/misc/jlayer.html>

--- BBBS/Li6 v4.10 Dada-1
 * Origin: Prism bbs (1:261/38)
--- Synchronet 3.16a-Win32 NewsLink 1.98
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [next] | [standalone]


#17098

Fromclusardi2k@aol.com
Date2012-08-03 12:59 -0700
Message-ID<5b2fa969-49c8-4ddb-866d-d5088c19ec72@googlegroups.com>
In reply to#17097
On Friday, August 3, 2012 3:56:28 PM UTC-4, markspace wrote:
>>Wrote:There's also a book call Swing Hacks which has some interesting ideas, 
>>including an animated window similar to what you are asking for. Still not 
>> exactly a lightbox however. 

There are 2 books with that title from 2005.

I think Amazon says the book is old!

Thanks,

[toc] | [prev] | [next] | [standalone]


#17099

Frommarkspace <-@.>
Date2012-08-03 13:31 -0700
Message-ID<jvhcec$vha$1@dont-email.me>
In reply to#17098
On 8/3/2012 12:59 PM, clusardi2k@aol.com wrote:
> On Friday, August 3, 2012 3:56:28 PM UTC-4, markspace wrote:
>>> Wrote:There's also a book call Swing Hacks which has some interesting ideas,
>>> including an animated window similar to what you are asking for. Still not
>>> exactly a lightbox however.
>
> There are 2 books with that title from 2005.
>
> I think Amazon says the book is old!
>


It is old.  But the code still works, and shows some important things 
that are not available anywhere else.  Old is not always bad.


[toc] | [prev] | [next] | [standalone]


#17111

Fromclusardi2k@aol.com
Date2012-08-04 01:16 -0700
Message-ID<09d5e869-e586-4639-b71f-23410b2a24f0@googlegroups.com>
In reply to#17099
On Friday, August 3, 2012 4:31:06 PM UTC-4, markspace wrote: 
>>> Wrote:There's also a book call Swing Hacks which has 
>>> some interesting ideas, including an animated window 
>>> similar to what you are asking for. Still not exactly 
>>> a lightbox however. 

For a cost of $4.24, I'll definiately have the following book in about a week:

Swing Hacks: Tips and Tools for Killer GUIs(1st Edition)
by Joshua Marinacci, Chris Adamson
Paperback, 546 Pages, Published 2005 by O'reilly Media
ISBN-13: 978-0-596-00907-6, ISBN: 0-596-00907-0

Funny, how something so rich in ideas can be so inexpensive.

So thanks for another shelf book, but I won't keep my fingers crossed on me building the best of the best in this case. 

And, I don't think I'll ever be able to develop the animation totally on my own! My implementation would amount to being too slow, etc, etc, etc.

Anyway, what's wrong with just disabling a large window below a smaller enabled window?

(I'll probably try to just live with that.)

Does anyone have a project which hints of a light box effect. The code doesn't have to be a full blown light box effect.

Thanks,


  

[toc] | [prev] | [next] | [standalone]


#17116

Frommarkspace <-@.>
Date2012-08-04 08:55 -0700
Message-ID<jvjgm3$ikc$1@dont-email.me>
In reply to#17111
On 8/4/2012 1:16 AM, clusardi2k@aol.com wrote:

> Swing Hacks: Tips and Tools for Killer GUIs(1st Edition) by Joshua
> Marinacci, Chris Adamson

> So thanks for another shelf book, but I won't keep my fingers crossed
> on me building the best of the best in this case.


Yes, that's the book.  When you get it, Hack #45, Animating a Sheet 
Dialog, is the one I am thinking of.  It shows how to make an animation 
for a dialog as it appears and disappears.  Similar to the Mac interface 
at the time it was written.  I think you could use the same technique to 
grey the background and then display your dialog on top to make a lightbox.

[toc] | [prev] | [next] | [standalone]


#17255

From"clusardi2k" <clusardi2k@1:261/38.remove-sao-this>
Date2012-08-06 18:08 +0000
Message-ID<50200783.56213.calajapr@time.synchro.net>
In reply to#17097
  To: markspace
From: clusardi2k@aol.com

Is there another way besides using JLayer. Is JLayer the best way.

Thank you,

--- BBBS/Li6 v4.10 Dada-1
 * Origin: Prism bbs (1:261/38)
--- Synchronet 3.16a-Win32 NewsLink 1.98
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [next] | [standalone]


#17256

From"markspace" <markspace@1:261/38.remove-sao-this>
Date2012-08-06 18:08 +0000
Message-ID<50200784.56214.calajapr@time.synchro.net>
In reply to#17255
  To: clusardi2k
From: markspace <-@.>

On 8/6/2012 8:54 AM, clusardi2k@aol.com wrote:
> Is there another way besides using JLayer. Is JLayer the best way.


I think it might be the only way, short of doing it yourself like that Swing 
Hacks books shows you.  "Best" is a hard thing to determine without careful 
analysis.  But JLayer is certainly the way I would start, even if I decided 
later I had to change.  Can't go too badly wrong re-using code someone else 
already wrote.

--- BBBS/Li6 v4.10 Dada-1
 * Origin: Prism bbs (1:261/38)
--- Synchronet 3.16a-Win32 NewsLink 1.98
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [next] | [standalone]


#17970

From"clusardi2k" <clusardi2k@1:261/38.remove-4g4-this>
Date2012-08-17 18:56 +0000
Message-ID<502E8842.56918.calajapr@time.synchro.net>
In reply to#17256
  To: markspace
From: clusardi2k@aol.com

The book is here:

http://www.scribd.com/doc/15490884/Swing-Hacks-Tips-and-Tools-for-Killer-GUIs

--- BBBS/Li6 v4.10 Dada-1
 * Origin: Prism bbs (1:261/38)
--- Synchronet 3.16a-Win32 NewsLink 1.98
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [next] | [standalone]


#17971

From"clusardi2k" <clusardi2k@1:261/38.remove-4g4-this>
Date2012-08-17 18:56 +0000
Message-ID<502E8843.56919.calajapr@time.synchro.net>
In reply to#17256
  To: markspace
From: clusardi2k@aol.com

On Friday, August 17, 2012 8:30:58 AM UTC-4, (unknown) wrote:
> The book is here: http://www.scribd.com/doc/15490884/Swing-Hacks-Tips-and-Too
ls-for-Killer-GUIs

Here's the HACK #45 code from the book. It has two buttons. If you press one of 
th buttons everything on the screen will move away and the screen will become 
blank.

Question: How on Earth do I convert this into a light box effect.

Here is a link to other fun JLayer examples:

http://docs.oracle.com/javase/tutorial/uiswing/misc/jlayer.html

//File: SheetTest.java
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package anisheetablejframe;

        import javax.swing.*;
        import java.awt.*;
        import java.awt.event.*;
        import java.beans.*;

        public class SheetTest extends Object
                implements PropertyChangeListener {

                JOptionPane optionPane;
                AniSheetableJFrame frame;

                public static void main (String[] args) {
                        new SheetTest( );
                }

                public SheetTest ( ) {
                        frame = new AniSheetableJFrame ("Sheet test");
                        // put an image in the frame's content pane
                        ImageIcon icon = new ImageIcon ("keagy-lunch.png");
                        JLabel label = new JLabel (icon);
                        frame.getContentPane( ).add(label);
                        // build JOptionPane dialog and hold onto it
                        optionPane = new JOptionPane ("Do you want to save?",

JOptionPane.QUESTION_MESSAGE,

JOptionPane.YES_NO_OPTION);
                frame.pack( );
                        frame.setVisible(true);
                        optionPane.addPropertyChangeListener (this);
                        // pause for effect, then show the sheet
                        try {Thread.sleep(1000);}
                        catch (InterruptedException ie) {}
                        JDialog dialog =
                                optionPane.createDialog (frame, "irrelevant");
                        frame.showJDialogAsSheet (dialog);
                }

                public void propertyChange (PropertyChangeEvent pce) {
                   if (pce.getPropertyName( ).equals
(JOptionPane.VALUE_PROPERTY)) {
                                System.out.println ("Selected option " +
                                                pce.getNewValue( ));
                                frame.hideSheet( );
                   }
                }
        }

//---------------------------
//File AnimatingSheet.java
package anisheetablejframe;

import java.awt.*;
import java.awt.image.BufferedImage; import javax.swing.JComponent;
import javax.swing.JPanel;

class AnimatingSheet extends JPanel {
                Dimension animatingSize = new Dimension (0, 1);
                JComponent source;
                BufferedImage offscreenImage;
                public AnimatingSheet ( ) {
                        super( );
                        setOpaque(true);
                }
                public void setSource (JComponent source) {
                        this.source = source;
                        animatingSize.width = source.getWidth( );
                        makeOffscreenImage(source);
                }
                public void setAnimatingHeight (int height) {
                        animatingSize.height = height;
                        setSize (animatingSize);
                }
                private void makeOffscreenImage(JComponent source) {
                        GraphicsConfiguration gfxConfig =
                                GraphicsEnvironment.getLocalGraphicsEnvironment
( )
                                           .getDefaultScreenDevice( )
                                           .getDefaultConfiguration( );
                        offscreenImage =
                                gfxConfig.createCompatibleImage(source.getWidth
( ),

source.getHeight( ));
                        Graphics2D offscreenGraphics =
                                (Graphics2D) offscreenImage.getGraphics( );
                        source.paint (offscreenGraphics);
                }
                public Dimension getPreferredSize( ) {  return animatingSize; }
                public Dimension getMinimumSize( ) { return animatingSize; }
                public Dimension getMaximumSize( ) { return animatingSize; }
                public void paint (Graphics g) {
                        // get the bottom-most n pixels of source and
                        // paint them into g, where n is height

                    int x = 0;
                    int y = offscreenImage.getHeight() - animatingSize.height;
                    int w = source.getWidth();
                    int h = animatingSize.height;

                        BufferedImage fragment =
                                offscreenImage.getSubimage (x,y,w,h);
                        // g.drawImage (fragment, 0, 0, this);
                        g.drawImage (fragment, 0, 0, this);
                }
        }

//---------------------------
//File    AniSheettableJFrame.java
package anisheetablejframe;

import javax.swing.*;
        import javax.swing.border.*;
        import java.awt.*;
        import java.awt.event.*;
        import java.awt.image.*;

        public class AniSheetableJFrame extends JFrame
                implements ActionListener {

                public static final int INCOMING = 1;
                public static final int OUTGOING = -1;
                public static final float ANIMATION_DURATION = 1000f;
                public static final int ANIMATION_SLEEP = 50;

                JComponent sheet;
                JPanel glass;
                AnimatingSheet animatingSheet;
                boolean animating;
                int animationDirection;
                Timer animationTimer;
                long animationStart;
                BufferedImage offscreenImage;

                public AniSheetableJFrame (String name) {
                        super(name);
                        glass = (JPanel) getGlassPane( );
                        glass.setLayout (new GridBagLayout( ));
                        animatingSheet = new AnimatingSheet( );
                        animatingSheet.setBorder (new LineBorder(Color.black,
1));
                }
public JComponent showJDialogAsSheet (JDialog dialog) {
                        sheet = (JComponent) dialog.getContentPane( );
                        sheet.setBorder (new LineBorder(Color.black, 1));
                        glass.removeAll( );
                        animationDirection = INCOMING;
                        startAnimation( );
                        return sheet;
                }

                public void hideSheet( ) {
                        animationDirection = OUTGOING;
                        startAnimation( );
                }

                private void startAnimation( ) {
                        glass.repaint( );
                        // clear glasspane and set up animatingSheet
                        animatingSheet.setSource (sheet);
                        glass.removeAll( );
                        GridBagConstraints gbc = new GridBagConstraints( );
                        gbc.anchor = GridBagConstraints.NORTH;
                        glass.add (animatingSheet, gbc);
                        gbc.gridy=1;
                        gbc.weighty = Integer.MAX_VALUE;
                        glass.add (Box.createGlue( ), gbc);
                        glass.setVisible(true);

                        // start animation timer
                        animationStart = System.currentTimeMillis( );
                        if (animationTimer == null)
                                animationTimer = new Timer (ANIMATION_SLEEP,
this);
                        animating = true;
                        animationTimer.start( );
                }

                private void stopAnimation( ) {
                        animationTimer.stop( );
                        animating = false;
                }

                // used by the Timer
                public void actionPerformed (ActionEvent e) {
                        if (animating) {
                                // calculate height to show
                                float animationPercent =
                                (System.currentTimeMillis( ) - animationStart)
/
                                ANIMATION_DURATION;
                                animationPercent = Math.min (1.0f,
animationPercent);
                                int animatingHeight = 0;

                if (animationDirection == INCOMING) {
                                animatingHeight =
                                (int) (animationPercent * sheet.getHeight( ));
                        } else {
                                animatingHeight =
                    (int) ((1.0f - animationPercent) * sheet.getHeight( ));
                        }
                        // clip off that much from sheet and blit it
                        // into animatingSheet
                        animatingSheet.setAnimatingHeight (animatingHeight);
            animatingSheet.repaint( );

                        if (animationPercent >= 1.0f) {
                                stopAnimation( );
                                if (animationDirection == INCOMING) {
                                finishShowingSheet( );
                                } else {
                                glass.removeAll( );
                                glass.setVisible(false);
                                }
                        }
                }
        }
    private void finishShowingSheet( ) {
                glass.removeAll( );
                GridBagConstraints gbc = new GridBagConstraints( );
                gbc.anchor = GridBagConstraints.NORTH;
                glass.add (sheet, gbc);
                gbc.gridy=1;
                gbc.weighty = Integer.MAX_VALUE;
                glass.add (Box.createGlue( ), gbc);
                glass.revalidate( );
                glass.repaint( );
        }
        // inner class AnimatedSheet goes here
   }

--- BBBS/Li6 v4.10 Dada-1
 * Origin: Prism bbs (1:261/38)
--- Synchronet 3.16a-Win32 NewsLink 1.98
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web