Captive Imagination
July 31, 2010, 11:50:19 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Check out the teaser site for the first official game by Captive Imagination: http://www.galaxiesbeyond.com
 
   Home   Help Search Calendar Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: How to bring a hidden Window to the front?  (Read 2800 times)
0 Members and 1 Guest are viewing this topic.
syam
Full Member
***
Offline Offline

Posts: 139


View Profile
« on: December 13, 2008, 03:01:15 AM »

In Java Swing, a JInternalFrame can be programmatically brought to the front by invoking JInternalFrame.toFront().

Is there such a feature in jSeamless Window object?

I came across this problem when I have a maximized Window that further invokes a child Window after disabling itself. Now the child Window is under the maximized Window and there is no way to reach the child Window.
Logged
darkfrog
Administrator
Inspired Imagination
*****
Offline Offline

Posts: 2650


View Profile
« Reply #1 on: December 13, 2008, 08:51:11 AM »

That's a good point. Windows are special in jSeamless 1.0 and don't have the extended functionality that all other components in jSeamless do to be able to say "toFront(component)" on the Container containing it.  Though I haven't really mentioned it, I've added functionality over the past few months to try to deprecate Window entirely. The idea has been to give much more flexibility in what can use the same functionality as a Window.  Take a look at this quick example:

Code:
    Box b = new Box(); {
    b.setSize(Dimension.fromString("600px", "600px"));
    b.getStyle().setBackgroundColor(ColorFactory.RED.toColor());
   
        Panel p = new Panel("Testing");
        p.setSize(Dimension.fromString("300px", "300px"));
        p.getHeader().setDragging(p);
        p.setDraggingBounds(new Bounds(0, 0, 600, 600));
        p.getBody().getStyle().setBackgroundColor(ColorFactory.WHITE.toColor());
        b.add(p);
       
        add(b);
    }

Let me know if that suffices as an alternative to Window.  If it does, you can simply call b.toFront(p); to bring the Panel to the front.  There are icons built-in for the maximize, minimize, close, etc. icons in the top-right as well if you wish to add them you can simply add them to p.getHeader().
Logged
syam
Full Member
***
Offline Offline

Posts: 139


View Profile
« Reply #2 on: December 13, 2008, 01:05:56 PM »

Yea, it looks OK. Thanks.
Other than programming the standard icons, we have to build other things like "selection (bring to the front) by clicking anywhere in the Panel Window" etc. when multiples of them floating around.
Isn't it  a good idea to have a component like this in the base package itself? Let us call it, say, "PanelWindow" or Window itself ?
« Last Edit: December 13, 2008, 08:59:05 PM by syam » Logged
darkfrog
Administrator
Inspired Imagination
*****
Offline Offline

Posts: 2650


View Profile
« Reply #3 on: December 14, 2008, 08:34:03 AM »

Yes, I agree, and that's why I haven't said anything really about it yet because my plan was to write a complete replacement for Window that extends Panel instead to provide all the functionality.

If you find yourself writing a replacement version of Window please feel free to post it and I'll get it added to jSeamless.
Logged
syam
Full Member
***
Offline Offline

Posts: 139


View Profile
« Reply #4 on: December 15, 2008, 12:34:55 AM »

I was trying to create a version of Window by extending Panel (based on the code example you posted) and stuck up with a problem.
The toFront() method does a layout and relocate all the Windows back to its original position. To eliminate this behavior, I did setIncludeInLayout(false), but it is now setting the location to (0,0) whenever toFront() is called.

I presume the location should not be touched if the component is not included in the layout process.
 
Logged
darkfrog
Administrator
Inspired Imagination
*****
Offline Offline

Posts: 2650


View Profile
« Reply #5 on: December 15, 2008, 08:31:08 AM »

Hmmm...I'm seeing the same thing...for some reason when the child order is re-arranged in Flex it resets their positions.  I'll look into this, can you file a bug at http://jseamless.googlecode.com?
Logged
syam
Full Member
***
Offline Offline

Posts: 139


View Profile
« Reply #6 on: December 17, 2008, 06:35:53 PM »

Logged Issue #6 for this.
Logged
syam
Full Member
***
Offline Offline

Posts: 139


View Profile
« Reply #7 on: December 18, 2008, 12:27:46 AM »

PanelWindow: Initial version of the code is posted here. Can you tell me the resource locations of the available icons?

Code:
/**
* Copyright (c) 2005-2008 jSeamless
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
*   notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
*   notice, this list of conditions and the following disclaimer in the
*   documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'jSeamless' nor the names of its contributors
*   may be used to endorse or promote products derived from this software
*   without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Created: Dec 18, 2008
*/

package com.jseamless.container;

import org.jseamless.*;
import org.jseamless.style.*;
import org.jseamless.event.Event;
import org.jseamless.event.EventType;
import org.jseamless.event.EventListener;
import org.jseamless.renderable.Resource;

/**
 *
 * @author Syam S. Pillai
 */
public class PanelWindow extends Panel {
   
private static final long serialVersionUID = -1L;
    private Component parent;
private Resource icon;
private float borderAlpha;
private boolean modal, maximum, minimum, showClose, showMaximize, showMinimize, showCollapse, showScaleUp, showScaleDown, showAlphaToggle;
    private Button closeButton, maximizeButton, minimizeButton, collapseButton, scaleUpButton, scaleDownButton, alphaToggleButton;
    private Box buttonBox;
    private Dimension normalSize;

public PanelWindow() {
this(null, null, false);
}
   
public PanelWindow(boolean modal) {
this(null, null, modal);
}
   
public PanelWindow(Container body) {
this(body, null, false);
}

public PanelWindow(Container body, boolean modal) {
this(body, null, modal);
}

public PanelWindow(String title) {
        this(null, title, false);
}

public PanelWindow(String title, boolean modal) {
        this(null, title, modal);
}

public PanelWindow(Container body, String title) {
        this(body, title, false);
}

public PanelWindow(Container body, String title, boolean modal) {
super(body == null ? new Box() : body, title == null ? "" : title);
        this.modal = modal;
        borderAlpha = 0.5f;
initUI();
}

private void initUI() {
        showClose = showMaximize = showMinimize = showCollapse = showScaleUp = showScaleDown = showAlphaToggle = true;
        setIncludeInLayout(false);
        getHeader().setDragging(this);
        getBody().getStyle().setBackgroundColor(ColorFactory.WHITE.toColor());
        final EventListener pel = new EventListener() {
            public void eventOccurred(Event e) {
                setDraggingBounds();
            }
        };
        EventListener el = new EventListener() {
            public void eventOccurred(Event e) {
                EventType type = e.getType();
                if(type == EventType.ADD) {
                    parent = getParent();
                    parent.addEventListener(pel, EventType.CHANGE_SIZE);
                    setDraggingBounds();
                } else if(type == EventType.REMOVE) {
                    parent.removeEventListener(pel);
                    parent = null;
                    removeEventListener(this);
                }
            }
        };
        addEventListener(el, EventType.ADD, EventType.REMOVE);
        EventListener hel = new EventListener() {
            public void eventOccurred(Event e) {
                toFront();
            }
        };
        org.jseamless.event.EventHandler eh = new org.jseamless.event.EventHandler(hel, EventType.CLICK);
        Component header = getHeader();
        header.addEventListener(eh);
        for(Component c: header.getDescendants()) {
            c.addEventListener(eh);
        }
        getHeader().add(buttonBox = new Box());
buttonBox.setLayout(Layout.HORIZONTAL);
        drawButtons();
}
   
    private void setDraggingBounds() {
        if(parent == null) {
            return;
        }
        Dimension d = parent.getActualSize();
        if(d != null) {
            setDraggingBounds(new Bounds(0, 0, d.getHeight(), d.getWidth()));
            Point point = new Point(0, 0);
            for(PanelWindow pw: parent.getChildrenByType(PanelWindow.class, false)) {
                if(pw.isMaximum()) {
                    pw.setLocation(point);
                    pw.setSize(d);
                }
            }
        }
    }
   
    /**
    * Programmatically bring this window to the front
    */
    public void toFront() {
        if(parent != null) {
            Container container = (Container)parent;
            Component front = container.peekLast();
            if(front != this) {
                if(!(front instanceof PanelWindow) || !((PanelWindow)front).isModal()) {
                    container.toFront(this);
                }
            }
        }
    }
   
/**
    * The visual icon to be displayed on this Component.
    *
    * @return
    * Resource
    */
public Resource getIcon() {
return icon;
}

/**
    * The visual icon to be displayed on this Component.
    *
    * @param icon
    */
public void setIcon(Resource icon) {
this.icon = icon;
        // To be coded
}

/**
    * The alpha translucency set on the border of this Window. This value
    * defaults to 0.5f.
    *
    * @return float
    */
public float getBorderAlpha() {
return borderAlpha;
}
   
/**
    * The alpha translucency set on the border of this Window. This value
    * defaults to 0.5f.
    *
    * @param borderAlpha
    */
public void setBorderAlpha(float borderAlpha) {
this.borderAlpha = borderAlpha;
}
   
/**
    * If true, a control is displayed to toggle the alpha transparency between
    * a translucent and opaque state. This can be useful to see through one
    * window to the contents under it.
    *
    * @return boolean
    */
public boolean isShowAlphaToggle() {
return showAlphaToggle;
}
   
/**
    * If true, a control is displayed to toggle the alpha transparency between
    * a translucent and opaque state. This can be useful to see through one
    * window to the contents under it.
    *
    * @param showAlphaToggle
    */
public void setShowAlphaToggle(boolean showAlphaToggle) {
this.showAlphaToggle = showAlphaToggle;
        // To be coded
}
   
/**
    * If true, a control is displayed that will throw a EventType.CLOSE when
    * it is pressed.
    *
    * @return boolean
    */
public boolean isShowClose() {
return showClose;
}
   
/**
    * If true, a control is displayed that will throw a EventType.CLOSE when
    * it is pressed.
    *
    * @param showClose
    */
public void setShowClose(boolean showClose) {
        if(this.showClose != showClose) {
            this.showClose = showClose;
            drawButtons();
        }
}
   
/**
    * If true, a control is displayed that will toggle to collapse the window
    * and only show the title bar.
    *
    * @return boolean
    */
public boolean isShowCollapse() {
return showCollapse;
}
   
/**
    * If true, a control is displayed that will toggle to collapse the window
    * and only show the title bar.
    *
    * @param showCollapse
    */
public void setShowCollapse(boolean showCollapse) {
        if(this.showCollapse != showCollapse) {
            this.showCollapse = showCollapse;
            drawButtons();
        }
}
   
/**
    * If true, a control is displayed that will toggle maximized and restored
    * states of the window.
    *
    * @return boolean
    */
public boolean isShowMaximize() {
return showMaximize;
}
   
/**
    * If true, a control is displayed that will toggle maximized and restored
    * states of the window.
    *
    * @param showMaximize
    */
public void setShowMaximize(boolean showMaximize) {
        if(this.showMaximize != showMaximize) {
            this.showMaximize = showMaximize;
            drawButtons();
        }
}
   
/**
    * If true, a control is displayed that will toggle minimized and restored
    * states of the window.
    *
    * @return boolean
    */
public boolean isShowMinimize() {
return showMinimize;
}
   
/**
    * If true, a control is displayed that will toggle minimized and restored
    * states of the window.
    *
    * @param showMinimize
    */
public void setShowMinimize(boolean showMinimize) {
        if(this.showMinimize != showMinimize) {
            this.showMinimize = showMinimize;
            drawButtons();
        }
}
   
/**
    * If true, a control is displayed that will scale the window contents down
    * by a degree every time the control is pressed.
    *
    * @return boolean
    */
public boolean isShowScaleDown() {
return showScaleDown;
}
   
/**
    * If true, a control is displayed that will scale the window contents down
    * by a degree every time the control is pressed.
    *
    * @param showScaleDown
    */
public void setShowScaleDown(boolean showScaleDown) {
        if(this.showScaleDown != showScaleDown) {
            this.showScaleDown = showScaleDown;
            drawButtons();
        }
}
   
/**
    * If true, a control is displayed that will scale the window contents up by
    * a degree every time the control is pressed.
    *
    * @return boolean
    */
public boolean isShowScaleUp() {
return showScaleUp;
}
   
/**
    * If true, a control is displayed that will scale the window contents up by
    * a degree every time the control is pressed.
    *
    * @param showScaleUp
    */
public void setShowScaleUp(boolean showScaleUp) {
        if(this.showScaleUp != showScaleUp) {
            this.showScaleUp = showScaleUp;
            drawButtons();
        }
}
   
    private void drawButtons() {
        buttonBox.clear();
        EventListener el;
        if(showAlphaToggle) {
            if(alphaToggleButton == null) {
                alphaToggleButton = new Button("a");
                el = new EventListener() {
                    public void eventOccurred(Event e) {
                        // To be coded
                    }
                };
                alphaToggleButton.addEventListener(el, EventType.CLICK);
            }
            buttonBox.add(alphaToggleButton);
        }
        if(showScaleDown) {
            if(scaleDownButton == null) {
                scaleDownButton = new Button("-");
                el = new EventListener() {
                    public void eventOccurred(Event e) {
                        // To be coded
                    }
                };
                scaleDownButton.addEventListener(el, EventType.CLICK);
            }
            buttonBox.add(scaleDownButton);
        }
        if(showScaleUp) {
            if(scaleUpButton == null) {
                scaleUpButton = new Button("+");
                el = new EventListener() {
                    public void eventOccurred(Event e) {
                        // To be coded
                    }
                };
                scaleUpButton.addEventListener(el, EventType.CLICK);
            }
            buttonBox.add(scaleUpButton);
        }
        if(showCollapse) {
            if(collapseButton == null) {
                collapseButton = new Button("^");
                el = new EventListener() {
                    public void eventOccurred(Event e) {
                        // To be coded
                    }
                };
                collapseButton.addEventListener(el, EventType.CLICK);
            }
            buttonBox.add(collapseButton);
        }
        if(showMinimize) {
            if(minimizeButton == null) {
                minimizeButton = new Button("_");
                el = new EventListener() {
                    public void eventOccurred(Event e) {
                        if(isMinimum()) {
                            restoreSize();
                        } else {
                            minimize();
                        }
                    }
                };
                minimizeButton.addEventListener(el, EventType.CLICK);
            }
            buttonBox.add(minimizeButton);
        }
        if(showMaximize) {
            if(maximizeButton == null) {
                maximizeButton = new Button("#");
                el = new EventListener() {
                    public void eventOccurred(Event e) {
                        if(isMaximum()) {
                            restoreSize();
                        } else {
                            maximize();
                        }
                    }
                };
                maximizeButton.addEventListener(el, EventType.CLICK);
            }
            buttonBox.add(maximizeButton);
        }
        if(showClose) {
            if(closeButton == null) {
                closeButton = new Button("x");
                el = new EventListener() {
                    public void eventOccurred(Event e) {
                        PanelWindow.this.close();
                    }
                };
                closeButton.addEventListener(el, EventType.CLICK);
            }
            buttonBox.add(closeButton);
        }
    }
   
/**
    * Returns the modal state of this Window. Modality can only be set on instantiation.
    *
    * @return
    * boolean
    */
public boolean isModal() {
return modal;
}

/**
    * Programmatically maximize this Window.
    */
public void maximize() {
        if(!minimum && !maximum) {
            computeSize();
        }
        if(parent != null) {
            setLocation(new Point(0, 0));
            setSize(parent.getActualSize());
        }
        maximum = true;
        minimum = false;
}
   
    /**
    * Returns true if the window is currently maximized.
    *
    * @return True or false
    */
    public boolean isMaximum() {
        return maximum;
    }

/**
    * Programmatically minimize this Window.
    */
public void minimize() {
        if(!minimum && !maximum) {
            computeSize();
        }
        if(parent != null) {
            // To be coded
        }
        minimum = true;
        maximum = false;
}
   
    /**
    * Returns true if the window is currently minimized.
    *
    * @return True or false
    */
    public boolean isMinimum() {
        return minimum;
    }
   
/**
    * Programmatically close this Window.
    */
    public void close() {
        removeFromParent();
    }

/**
    * Programmatically restores the size of this Window.
    */
    public void restoreSize() {
        if(normalSize == null) {
            computeSize();
        }
        setSize(normalSize);
    }
   
    private void computeSize() {
        Dimension d = getActualSize();
        if(d == null) {
            normalSize = new Dimension(100, 100);
        } else {
            normalSize = new Dimension(d);
        }
    }
}
Logged
darkfrog
Administrator
Inspired Imagination
*****
Offline Offline

Posts: 2650


View Profile
« Reply #8 on: December 18, 2008, 07:28:37 AM »

They can be found in src/resource in the jseamless-extensions project.

Just took a glance at your code, but why are you storing a reference to "parent" instead of just calling getParent() or getParentContainer() when you need it?
Logged
syam
Full Member
***
Offline Offline

Posts: 139


View Profile
« Reply #9 on: December 18, 2008, 10:28:53 AM »

In an EventHandler, do we get getParent() non-null when a REMOVE event happens?
I wanted to remove the listeners from the parent when the child gets removed.
Logged
darkfrog
Administrator
Inspired Imagination
*****
Offline Offline

Posts: 2650


View Profile
« Reply #10 on: December 18, 2008, 12:30:16 PM »

Ah, I see. Guess I shouldn't comment when I just glance. Wink
Logged
syam
Full Member
***
Offline Offline

Posts: 139


View Profile
« Reply #11 on: December 19, 2008, 08:54:59 PM »

Do we have to provide "scale up" and "scale down" features as in Window object?
Is that implementation dependent? Otherwise, how do we program that?
Also, I tried to implement the setBorderAlpha() as follows, but it didn't work.
Code:
        Border b = getStyle().getBorder();
        if(b != null) {
            Color c = Color.get(b.getColor());
            c.setAlpha(borderAlpha);
            b.setColor(c);
        }
Logged
darkfrog
Administrator
Inspired Imagination
*****
Offline Offline

Posts: 2650


View Profile
« Reply #12 on: December 20, 2008, 11:00:31 AM »

Don't worry about scale-up and scale-down unless you want them for your own applications.  Standard window controls are all that I think are really necessary.

jSeamless 2.0 is coming and with it will come many implementations.  I've resigned 1.0 to only have Flex as it's complete implementation.

This is one problem with Flex is that color alphas don't always carry across to certain aspects.
Logged
syam
Full Member
***
Offline Offline

Posts: 139


View Profile
« Reply #13 on: December 20, 2008, 08:51:08 PM »

Here is the final version of the code.
(1) I have put this component into org.jseamlessx package because I am using the resources from that package.
(2) The toFront() method resets the location of all windows to (0,0). I tried to provide workaround by saving the locations before the rearrangement of windows and restoring them afterwards. But, it didn't work! Somewhere, it is getting reset to (0,0). I put debug messages in the update() method and I can see that it is getting reset to (0,0).

Code:
/**
* Copyright (c) 2005-2008 jSeamless
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
*   notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
*   notice, this list of conditions and the following disclaimer in the
*   documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'jSeamless' nor the names of its contributors
*   may be used to endorse or promote products derived from this software
*   without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
    * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
    * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Created: Dec 18, 2008
*/

package org.jseamlessx;

import org.jseamless.*;
import org.jseamless.container.*;
import org.jseamless.style.*;
import org.jseamless.event.*;
import org.jseamless.renderable.Resource;
import org.jseamless.renderable.URLResource;

/**
*
* @author Syam S. Pillai
*/
public class PanelWindow extends Panel {
   
    private static final long serialVersionUID = -1L;
    private Component parent;
    private boolean modal, maximum, collapsed, showClose, showMaximize, showCollapse;
    private Link closeLink, maximizeLink, collapseLink;
    private Box linkBox;
    private Dimension normalSize;
    private Point normalLocation;
   
    public PanelWindow() {
        this(null, null, false);
    }
   
    public PanelWindow(boolean modal) {
        this(null, null, modal);
    }
   
    public PanelWindow(Container body) {
        this(body, null, false);
    }
   
    public PanelWindow(Container body, boolean modal) {
        this(body, null, modal);
    }
   
    public PanelWindow(String title) {
        this(null, title, false);
    }
   
    public PanelWindow(String title, boolean modal) {
        this(null, title, modal);
    }
   
    public PanelWindow(Container body, String title) {
        this(body, title, false);
    }
   
    public PanelWindow(Container body, String title, boolean modal) {
        super(body == null ? new Box() : body, title == null ? "" : title);
        this.modal = modal;
        initUI();
    }
   
    private void initUI() {
        setResizable(true);
        getStyle().setBorder(new Border(3, Color.get(0f, 0f, 0f, 0.5f)));
        showClose = showMaximize = showCollapse = true;
        setIncludeInLayout(false);
        getHeader().setDragging(this);
        getBody().getStyle().setBackgroundColor(ColorFactory.WHITE.toColor());
        final EventListener pel = new EventListener() {
            public void eventOccurred(Event e) {
                PanelWindow.this.setDraggingBounds();
            }
        };
        EventListener el = new EventListener() {
            public void eventOccurred(Event e) {
                EventType type = e.getType();
                if(type == EventType.ADD) {
                    parent = getParent();
                    parent.addEventListener(pel, EventType.CHANGE_SIZE);
                    PanelWindow.this.setDraggingBounds();
                } else if(type == EventType.REMOVE) {
                    parent.removeEventListener(pel);
                    parent = null;
                }
            }
        };
        addEventListener(el, EventType.ADD, EventType.REMOVE);
        el = new EventListener() {
            public void eventOccurred(Event e) {
                PanelWindow.this.toFront();
            }
        };
        EventHandler eh = new EventHandler(el, EventType.CLICK);
        eh.setAcceptRecursion(true);
        addEventListener(eh);
        getHeader().add(linkBox = new Box());
        linkBox.setLayout(Layout.HORIZONTAL);
        drawLinks();
    }
   
    private void setDraggingBounds() {
        if(parent == null) {
            return;
        }
        Dimension d = parent.getActualSize();
        if(d != null) {
            setDraggingBounds(new Bounds(0, 0, d.getHeight(), d.getWidth()));
            Point point = new Point(0, 0);
            for(PanelWindow pw: parent.getChildrenByType(PanelWindow.class, false)) {
                if(pw.isMaximum()) {
                    pw.setLocation(point);
                    pw.setSize(d);
                }
            }
        }
    }
   
    /**
    * Programmatically bring this window to the front
    */
    public void toFront() {
        if(parent != null) {
            Container container = (Container)parent;
            Component front = container.peekLast();
            if(front != this) {
                if(!(front instanceof PanelWindow) || !((PanelWindow)front).isModal()) {
                    container.toFront(this);
                }
            }
        }
    }
   
    /**
    * If true, a control is displayed that will throw a EventType.CLOSE when
    * it is pressed.
    *
    * @return boolean
    */
    public boolean isShowClose() {
        return showClose;
    }
   
    /**
    * If true, a control is displayed that will throw a EventType.CLOSE when
    * it is pressed.
    *
    * @param showClose
    */
    public void setShowClose(boolean showClose) {
        if(this.showClose != showClose) {
            this.showClose = showClose;
            drawLinks();
        }
    }
   
    /**
    * If true, a control is displayed that will toggle to collapse the window
    * and only show the title bar.
    *
    * @return boolean
    */
    public boolean isShowCollapse() {
        return showCollapse;
    }
   
    /**
    * If true, a control is displayed that will toggle to collapse the window
    * and only show the title bar.
    *
    * @param showCollapse
    */
    public void setShowCollapse(boolean showCollapse) {
        if(this.showCollapse != showCollapse) {
            this.showCollapse = showCollapse;
            drawLinks();
        }
    }
   
    /**
    * If true, a control is displayed that will toggle maximized and restored
    * states of the window.
    *
    * @return boolean
    */
    public boolean isShowMaximize() {
        return showMaximize;
    }
   
    /**
    * If true, a control is displayed that will toggle maximized and restored
    * states of the window.
    *
    * @param showMaximize
    */
    public void setShowMaximize(boolean showMaximize) {
        if(this.showMaximize != showMaximize) {
            this.showMaximize = showMaximize;
            drawLinks();
        }
    }
   
    private void drawLinks() {
        linkBox.clear();
        EventListener el;
        if(showCollapse) {
            if(collapseLink == null) {
                collapseLink = link("minimize", "Collapse");
                el = new EventListener() {
                    public void eventOccurred(Event e) {
                        if(PanelWindow.this.collapsed) {
                            PanelWindow.this.expand();
                        } else {
                            PanelWindow.this.collapse();
                        }
                    }
                };
                collapseLink.addEventListener(el, EventType.CLICK);
            }
            linkBox.add(collapseLink);
        }
        if(showMaximize) {
            if(maximizeLink == null) {
                maximizeLink = link("maximize", "Maximize");
                el = new EventListener() {
                    public void eventOccurred(Event e) {
                        if(PanelWindow.this.maximum) {
                            PanelWindow.this.restoreSize();
                        } else {
                            PanelWindow.this.maximize();
                        }
                    }
                };
                maximizeLink.addEventListener(el, EventType.CLICK);
            }
            linkBox.add(maximizeLink);
        }
        if(showClose) {
            if(closeLink == null) {
                closeLink = link("close", "Close");
                el = new EventListener() {
                    public void eventOccurred(Event e) {
                        PanelWindow.this.close();
                    }
                };
                closeLink.addEventListener(el, EventType.CLICK);
            }
            linkBox.add(closeLink);
        }
    }
   
    private Link link(String action, String tooltip) {
        Link b = new Link();
        b.setIcon(new URLResource(getClass().getClassLoader().getResource("resource/window_" + action + ".png"), Resource.Type.INTERNAL));
        b.setToolTip(tooltip);
        return b;
    }
   
    /**
    * Returns the modal state of this Window. Modality can only be set on instantiation.
    *
    * @return
    *   boolean
    */
    public boolean isModal() {
        return modal;
    }
   
    private void saveSize() {
        Dimension d = getActualSize();
        if(d == null) {
            normalSize = new Dimension(300, 200);
            normalLocation = new Point(0, 0);
        } else {
            normalSize = new Dimension(d);
            normalLocation = new Point(getLocation());
        }
    }
   
    /**
    * Programmatically maximize this Window. This is equivalent to setMaximum(true).
    */
    public void maximize() {
        expand();
        if(maximum) {
            return;
        }
        saveSize();
        maximizeInt();
        maximum = true;
    }
   
    private void maximizeInt() {
        if(parent != null) {
            setLocation(new Point(0, 0));
            setSize(parent.getActualSize());
        }
    }
   
    /**
    * Programmatically set the maximum property of the window.
    *
    * @param maximum True if it has to be maximized. False will restore the normal size.
    */
    public void setMaximum(boolean maximum) {
        if(maximum) {
            maximize();
        } else {
            restoreSize();
        }
    }
   
    /**
    * Returns true if the window is currently maximized.
    *
    * @return True or false
    */
    public boolean isMaximum() {
        return maximum;
    }
   
    /**
    * Programmatically close this Window.
    */
    public void close() {
        removeFromParent();
    }
   
    /**
    * Programmatically restores the normal size of this Window. This is equivalent to setMaximum(false).
    */
    public void restoreSize() {
        if(collapsed) {
            expand();
            if(!maximum) {
                return;
            }
        }
        maximum = false;
        restoreSizeInt();
    }
   
    private void restoreSizeInt() {
        if(normalSize != null) {
            setSize(normalSize);
            setLocation(normalLocation);
        }
    }
   
    /**
    * Programmatically collapse up this Window. No effect if it is already in the collapsed state.
    */
    public void collapse() {
        if(collapsed) {
            return;
        }
        if(!maximum) {
            saveSize();
        }
        collapsed = true;
        getBody().setSize(Dimension.zero());
        Dimension d = new Dimension(getHeader().getActualSize());
        Border b = getStyle().getBorder();
        if(b != null) {
            if(b.hasLeft()) {
                d.setWidth(d.getWidth() + b.getWidth());
            }
            if(b.hasRight()) {
                d.setWidth(d.getWidth() + b.getWidth());
            }
            if(b.hasTop()) {
                d.setHeight(d.getHeight() + b.getWidth());
            }
            if(b.hasBottom()) {
                d.setHeight(d.getHeight() + b.getWidth());
            }
        }
        setSize(d);
    }
   
    /**
    * Returns true if the window is currently collapsed.
    *
    * @return True or false
    */
    public boolean isCollapsed() {
        return collapsed;
    }
   
    /**
    * Programmatically expand this Window. No effect if it is already in the expanded state.
    */
    public void expand() {
        if(!collapsed) {
            return;
        }
        collapsed = false;
        getBody().setSize(Dimension.fill());
        if(maximum) {
            maximizeInt();
        } else {
            restoreSizeInt();
        }
    }
}
Logged
darkfrog
Administrator
Inspired Imagination
*****
Offline Offline

Posts: 2650


View Profile
« Reply #14 on: December 21, 2008, 11:37:36 AM »

Yes, it's a very strange issue.  If I even go so far as to copy the current x/y values before swapping them and try setting them back immediately afterwards it doesn't work either.  When I have some more time I'll dig a little deeper.
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.292 seconds with 20 queries.