Package jmri.util

Class PlaceWindow

  • All Implemented Interfaces:
    InstanceManagerAutoDefault

    public class PlaceWindow
    extends java.lang.Object
    implements InstanceManagerAutoDefault
    Position a Window relative to a component in another window so as to not obscure a component in that window. Typically, the Component is being edited by actions done in the target Window.\p Note the assumption in multiple screen environments is the screens are configured horizontally.
    Since:
    4.13.1
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) static java.awt.GraphicsEnvironment _environ  
      (package private) static java.awt.Dimension[] _screenSize  
      (package private) static java.awt.Dimension _totalScreenDim  
    • Constructor Summary

      Constructors 
      Constructor Description
      PlaceWindow()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static PlaceWindow getDefault()  
      int getScreenNum​(java.awt.Window window)
      In a possibly multi-monitor environment, find the screen displaying the window and return its dimensions.
      java.awt.Dimension getScreenSize​(int screenNum)  
      java.awt.Point nextTo​(java.awt.Window parent, java.awt.Component comp, java.awt.Window target)
      Find the best place to position the target window next to the component but not obscuring it.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getScreenNum

        public int getScreenNum​(java.awt.Window window)
        In a possibly multi-monitor environment, find the screen displaying the window and return its dimensions. \p getLocation() and getLocationOnScreen() return the same Point which has coordinates in the total display area, i.e. all screens combined. Note DefaultScreen is NOT this total combined display area. We assume monitors are aligned horizontally - at least this is the only configuration possible from Windows settings.
        Parameters:
        window - a window
        Returns:
        Screen number of window location
      • getScreenSize

        public java.awt.Dimension getScreenSize​(int screenNum)
      • nextTo

        public java.awt.Point nextTo​(java.awt.Window parent,
                                     java.awt.Component comp,
                                     java.awt.Window target)
        Find the best place to position the target window next to the component but not obscuring it. Positions target to the Left, Right, Below or Above. Tries in that order to keep target within the parent window. If not possible, tries to keep the target window within the parent's screen. Failing that, will minimize the amount the target window is off screen. The method guarantees a non-null component will not be obscured.\p If the component is null, the target window is placed beside the parent window, to the Left, Right, Below or Above it.\b Should be called after target is packed and before target is set visible.
        Parameters:
        parent - Window containing the Component
        comp - Component contained in the parent Window. May be null.
        target - a popup or some kind of window associated with the component
        Returns:
        the location Point to open the target window.