@@ -489,32 +489,6 @@ private void installKeyboardInputMap() {
489
489
* @throws Exception
490
490
*/
491
491
protected boolean restoreSketches () throws Exception {
492
- // figure out window placement
493
-
494
- Dimension screen = Toolkit .getDefaultToolkit ().getScreenSize ();
495
- boolean windowPositionValid = true ;
496
-
497
- if (PreferencesData .get ("last.screen.height" ) != null ) {
498
- // if screen size has changed, the window coordinates no longer
499
- // make sense, so don't use them unless they're identical
500
- int screenW = PreferencesData .getInteger ("last.screen.width" );
501
- int screenH = PreferencesData .getInteger ("last.screen.height" );
502
-
503
- if ((screen .width != screenW ) || (screen .height != screenH )) {
504
- windowPositionValid = false ;
505
- }
506
- /*
507
- int windowX = Preferences.getInteger("last.window.x");
508
- int windowY = Preferences.getInteger("last.window.y");
509
- if ((windowX < 0) || (windowY < 0) ||
510
- (windowX > screenW) || (windowY > screenH)) {
511
- windowPositionValid = false;
512
- }
513
- */
514
- } else {
515
- windowPositionValid = false ;
516
- }
517
-
518
492
// Iterate through all sketches that were open last time p5 was running.
519
493
// If !windowPositionValid, then ignore the coordinates found for each.
520
494
@@ -534,13 +508,7 @@ protected boolean restoreSketches() throws Exception {
534
508
// path unchanged.
535
509
}
536
510
}
537
- int [] location ;
538
- if (windowPositionValid ) {
539
- String locationStr = PreferencesData .get ("last.sketch" + i + ".location" );
540
- location = PApplet .parseInt (PApplet .split (locationStr , ',' ));
541
- } else {
542
- location = nextEditorLocation ();
543
- }
511
+ int [] location = retrieveSketchLocation ("" + i );
544
512
// If file did not exist, null will be returned for the Editor
545
513
if (handleOpen (new File (path ), location , nextEditorLocation (), true , false , false ) != null ) {
546
514
opened ++;
@@ -587,6 +555,26 @@ private void storeSketchLocation(Editor editor, String index) {
587
555
PreferencesData .set ("last.sketch" + index + ".location" , loc );
588
556
}
589
557
558
+ private int [] retrieveSketchLocation (String index ) {
559
+ if (PreferencesData .get ("last.screen.height" ) == null )
560
+ return defaultEditorLocation ();
561
+
562
+ // if screen size has changed, the window coordinates no longer
563
+ // make sense, so don't use them unless they're identical
564
+ Dimension screen = Toolkit .getDefaultToolkit ().getScreenSize ();
565
+ int screenW = PreferencesData .getInteger ("last.screen.width" );
566
+ int screenH = PreferencesData .getInteger ("last.screen.height" );
567
+
568
+ if ((screen .width != screenW ) || (screen .height != screenH ))
569
+ return defaultEditorLocation ();
570
+
571
+ String locationStr = PreferencesData
572
+ .get ("last.sketch" + index + ".location" );
573
+ if (locationStr == null )
574
+ return defaultEditorLocation ();
575
+ return PApplet .parseInt (PApplet .split (locationStr , ',' ));
576
+ }
577
+
590
578
protected void storeRecentSketches (Sketch sketch ) {
591
579
if (sketch .isUntitled ()) {
592
580
return ;
@@ -628,49 +616,46 @@ protected void handleActivated(Editor whichEditor) {
628
616
EditorConsole .setCurrentEditorConsole (activeEditor .console );
629
617
}
630
618
631
-
632
- protected int [] nextEditorLocation () {
619
+ protected int [] defaultEditorLocation () {
633
620
int defaultWidth = PreferencesData .getInteger ("editor.window.width.default" );
634
621
int defaultHeight = PreferencesData .getInteger ("editor.window.height.default" );
622
+ Rectangle screen = GraphicsEnvironment .getLocalGraphicsEnvironment ().getDefaultScreenDevice ().getDefaultConfiguration ().getBounds ();
623
+ return new int []{
624
+ (screen .width - defaultWidth ) / 2 ,
625
+ (screen .height - defaultHeight ) / 2 ,
626
+ defaultWidth , defaultHeight , 0
627
+ };
628
+ }
635
629
630
+ protected int [] nextEditorLocation () {
636
631
if (activeEditor == null ) {
637
- Rectangle screen = GraphicsEnvironment .getLocalGraphicsEnvironment ().getDefaultScreenDevice ().getDefaultConfiguration ().getBounds ();
638
632
// If no current active editor, use default placement
639
- return new int []{
640
- (screen .width - defaultWidth ) / 2 ,
641
- (screen .height - defaultHeight ) / 2 ,
642
- defaultWidth , defaultHeight , 0
643
- };
633
+ return defaultEditorLocation ();
634
+ }
644
635
645
- } else {
646
- Dimension screen = Toolkit .getDefaultToolkit ().getScreenSize ();
647
-
648
- // With a currently active editor, open the new window
649
- // using the same dimensions, but offset slightly.
650
- synchronized (editors ) {
651
- final int OVER = 50 ;
652
- // In release 0160, don't
653
- //location = activeEditor.getPlacement();
654
- Editor lastOpened = activeEditor ;
655
- int [] location = lastOpened .getPlacement ();
656
- // Just in case the bounds for that window are bad
657
- location [0 ] += OVER ;
658
- location [1 ] += OVER ;
659
-
660
- if (location [0 ] == OVER ||
661
- location [2 ] == OVER ||
662
- location [0 ] + location [2 ] > screen .width ||
663
- location [1 ] + location [3 ] > screen .height ) {
664
- // Warp the next window to a randomish location on screen.
665
- return new int []{
666
- (int ) (Math .random () * (screen .width - defaultWidth )),
667
- (int ) (Math .random () * (screen .height - defaultHeight )),
668
- defaultWidth , defaultHeight , 0
669
- };
670
- }
636
+ Dimension screen = Toolkit .getDefaultToolkit ().getScreenSize ();
671
637
672
- return location ;
638
+ // With a currently active editor, open the new window
639
+ // using the same dimensions, but offset slightly.
640
+ synchronized (editors ) {
641
+ int [] location = activeEditor .getPlacement ();
642
+
643
+ // Just in case the bounds for that window are bad
644
+ final int OVER = 50 ;
645
+ location [0 ] += OVER ;
646
+ location [1 ] += OVER ;
647
+
648
+ if (location [0 ] == OVER || location [2 ] == OVER
649
+ || location [0 ] + location [2 ] > screen .width
650
+ || location [1 ] + location [3 ] > screen .height ) {
651
+ // Warp the next window to a randomish location on screen.
652
+ int [] l = defaultEditorLocation ();
653
+ l [0 ] *= Math .random () * 2 ;
654
+ l [1 ] *= Math .random () * 2 ;
655
+ return l ;
673
656
}
657
+
658
+ return location ;
674
659
}
675
660
}
676
661
0 commit comments