package app; // Java imports import java.awt.*; import javax.swing.*; // Project imports import util.*; // Child window class ChildWindow extends JInternalFrame { // Instance fields MainWindow parent; // Parent application window /////////////////////////////////////////////////////////////////////////// // Constructors // /////////////////////////////////////////////////////////////////////////// // Default constructor ChildWindow(MainWindow parent, String key) { super(); // Configure instanece fields this.parent = parent; // Configure component parent.app.getLocalizer().add(this, key); addInternalFrameListener(Util.onClose2(e->setVisible(false))); setClosable(true); setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); setResizable(true); } /////////////////////////////////////////////////////////////////////////// // Public Methods // /////////////////////////////////////////////////////////////////////////// // Show or hide the component public void setVisible​(boolean visible) { // Making visible if (visible) { // Not currently visible: center in parent if (!isVisible()) { var parent = getParent().getParent(); setLocation( Math.max(0, (parent.getWidth () - getWidth ()) / 2), Math.max(0, (parent.getHeight() - getHeight()) / 2) ); } // Already visible: bring to front else moveToFront(); } // Change visibility super.setVisible(visible); } }