package ch.psi.plot.utils;

/*
 * Copyright (c) 2014 Paul Scherrer Institute. All rights reserved.
 */
import java.awt.event.HierarchyEvent;
import java.awt.event.HierarchyListener;
import javax.swing.JPanel;

/**
 *
 */
public class MonitoredPanel extends JPanel {

    public MonitoredPanel() {
        addHierarchyListener(new HierarchyListener() {
            @Override
            public void hierarchyChanged(HierarchyEvent e) {
                if ((HierarchyEvent.SHOWING_CHANGED & e.getChangeFlags()) != 0) {
                    if (isShowing()) {
                        try {
                            onShown();
                        } catch (Exception ex) {
                        }
                    } else {
                        try {
                            onHidden();
                        } catch (Exception ex) {
                        }
                    }
                }
            }
        });
    }

    protected void onShown() {
    }

    protected void onHidden() {
    }
}
