001package jmri.util.swing.multipane;
002
003import java.awt.Frame;
004import java.util.HashSet;
005import javax.swing.JComponent;
006import jmri.util.swing.JmriAbstractAction;
007
008/**
009 * Display a JComponent in a specific paned window.
010 *
011 * @author Bob Jacobsen Copyright 2010
012 * @since 2.9.4
013 */
014public class PanedInterface implements jmri.util.swing.WindowInterface {
015
016    public PanedInterface(MultiPaneWindow frame) {
017        this.frame = frame;
018    }
019
020    MultiPaneWindow frame;
021
022    @Override
023    public void show(jmri.util.swing.JmriPanel child,
024            JmriAbstractAction act,
025            Hint hint) {
026
027        JComponent destination;
028        if (hint == Hint.EXTEND) {
029            destination = frame.getLowerRight();
030        } else {
031            destination = frame.getUpperRight();
032        }
033
034        destination.removeAll();
035        destination.add(child);
036        destination.revalidate();
037        frame.resetRightToPreferredSizes();
038
039        if (act != null) {
040            actions.add(act);
041        }
042    }
043
044    @Override
045    public void show(final jmri.util.swing.JmriPanel child,
046            jmri.util.swing.JmriAbstractAction act) {
047
048        show(child, act, Hint.DEFAULT);
049    }
050
051    HashSet<JmriAbstractAction> actions = new HashSet<JmriAbstractAction>();
052
053    /**
054     * Return the same instance for multiple requests
055     */
056    @Override
057    public boolean multipleInstances() {
058        return false;
059    }
060
061    /**
062     * Dispose when associated window is complete
063     */
064    @Override
065    public void dispose() {
066        for (JmriAbstractAction a : actions) {
067            a.dispose();
068        }
069    }
070
071    @Override
072    public Frame getFrame() {
073        return (this.frame != null) ? this.frame : null;
074    }
075}