001package jmri.jmrit.symbolicprog.tabbedframe;
002
003import javax.swing.*;
004
005/**
006 * JLabel that watches another component, setting itself invisible if when the
007 * other component is
008 *
009 * @author Bob Jacobsen Copyright (C) 2010, 2020
010 */
011public class WatchingLabel extends JLabel {
012
013    public WatchingLabel(String name, JComponent c) {
014        super(name);
015
016        comp = c;
017
018        comp.addComponentListener(new java.awt.event.ComponentListener() {
019            @Override
020            public void componentHidden(java.awt.event.ComponentEvent e) {
021                WatchingLabel.this.setVisible(false);
022            }
023
024            @Override
025            public void componentShown(java.awt.event.ComponentEvent e) {
026                WatchingLabel.this.setVisible(true);
027            }
028
029            @Override
030            public void componentMoved(java.awt.event.ComponentEvent e) {
031            }
032
033            @Override
034            public void componentResized(java.awt.event.ComponentEvent e) {
035            }
036
037        });
038
039        // set initial status
040        setVisible(c.isVisible());
041    }
042
043    public JComponent getWatcher() { return this; }
044    public JComponent getWatched() { return comp; }
045    
046    JComponent comp;
047}