membrane
membrane copied to clipboard
set initial window location to arg or default to 0
Idk if initial windows have a non-zero default location. If so, then this overrides the default behavior which may be undesirable.
Since I'm also not sure what the default behavior is for all the operating systems Swing supports, then I think we should avoid setting the start location if no initial location is provided.
start-x window-start-x
start-y window-start-y]
(.setSize f start-width start-height)
(when (and start-x start-y) (.setLocation f start-x start-y))
This has the idiosyncrasy that setting window-start-x
won't have an effect unless you also set window-start-y
.
Is that good enough?
This has the idiosyncrasy that setting window-start-x won't have an effect unless you also set window-start-y.
Let's do something like the following:
(when (or window-start-x window-start-y)
(assert (and window-start-x window-start-y) "Specifying the window start position must provide both x and y coordinates")
(.setLocation f window-start-x window-start-y))
Yea, I didn't think of that as an option and I like it.
Alternatively, I just realized that the default initial location might be in scope...
start-x (or window-start-x (.getX f))
start-y (or window-start-y (.getX f))]
(.setSize f start-width start-height)
(.setLocation f start-x start-y)
where f
is a JFrame
Does this have any drawbacks?
I feel like I should offer why I'm even interested in supporting a default starting location. I'm recreating the window to load new code and this saves me from moving the window back to where I want it.
Alternatively, I just realized that the default initial location might be in scope...
I was also thinking similarly, but after doing a little more reading, https://docs.oracle.com/javase/7/docs/api/java/awt/Window.html#setLocationByPlatform(boolean), it doesn't seem like .getLocation
is likely to provide the default platform location. I think our best bet is requiring both the x and y coordinate if either is required. We can always loosen this restriction if we learn otherwise.
That sounds good!
Just tried this out. If you pass a window-start-x without a window-start-y, it still shows the window before asserting and throwing the error. The assertion should probably be checked before creating all the panels, listeners, windows, etc.
Ah, sorry, I never tested the failure scenario. Good catch!
https://github.com/phronmophobic/membrane/commit/3a706f154d049c214bb0d94ee239c499de91b2c4 Fixed!