pvbemu/src/desktop/app/ChildWindow.java

67 lines
1.8 KiB
Java
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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);
}
}