@@ -143,7 +143,6 @@ public void actionPerformed(ActionEvent e) {
143143 // get a wide name in there before getPreferredSize() is called
144144 fontSelectionBox = new JComboBox <String >(new String [] { Toolkit .getMonoFontName () });
145145 fontSelectionBox .setToolTipText (fontTip );
146- //updateDisplayList();
147146 fontSelectionBox .setEnabled (false ); // don't enable until fonts are loaded
148147
149148
@@ -317,17 +316,18 @@ public void stateChanged(ChangeEvent e) {
317316
318317 // Run sketches on display [ 1 ]
319318
320- JLabel displayLabel = new JLabel (Language .text ("preferences.run_sketches_on_display" )+ ": " );
319+ JLabel displayLabel = new JLabel (Language .text ("preferences.run_sketches_on_display" ) + ": " );
321320 final String tip = "<html>" + Language .text ("preferences.run_sketches_on_display.tip" );
322321 displayLabel .setToolTipText (tip );
323322 displaySelectionBox = new JComboBox <String >();
324323 updateDisplayList (); // needs to happen here for getPreferredSize()
325324
325+
326326 // [ ] Automatically associate .pde files with Processing
327327
328- autoAssociateBox =
329- new JCheckBox (Language .text ("preferences.automatically_associate_pde_files" ));
330- autoAssociateBox .setVisible (false );
328+ autoAssociateBox =
329+ new JCheckBox (Language .text ("preferences.automatically_associate_pde_files" ));
330+ autoAssociateBox .setVisible (false );
331331
332332
333333 // More preferences are in the ...
@@ -577,17 +577,21 @@ protected void applyFrame() {
577577 Language .saveLanguage (language );
578578 }
579579
580- int oldDisplayIndex = Preferences .getInteger ("run.display" ); //$NON-NLS-1$
581- int displayIndex = 0 ;
582- for (int d = 0 ; d < displaySelectionBox .getItemCount (); d ++) {
583- if (displaySelectionBox .getSelectedIndex () == d ) {
584- displayIndex = d ;
580+ // The preference will have already been reset when the window was created
581+ if (displaySelectionBox .isEnabled ()) {
582+ int oldDisplayNum = Preferences .getInteger ("run.display" );
583+ int displayNum = -1 ;
584+ for (int d = 0 ; d < displaySelectionBox .getItemCount (); d ++) {
585+ if (displaySelectionBox .getSelectedIndex () == d ) {
586+ displayNum = d + 1 ;
587+ }
585588 }
586- }
587- if (oldDisplayIndex != displayIndex ) {
588- Preferences .setInteger ("run.display" , displayIndex ); //$NON-NLS-1$
589- for (Editor editor : base .getEditors ()) {
590- editor .setSketchLocation (null );
589+ if ((displayNum != -1 ) && (displayNum != oldDisplayNum )) {
590+ Preferences .setInteger ("run.display" , displayNum ); //$NON-NLS-1$
591+ // Reset the location of the sketch, the window has changed
592+ for (Editor editor : base .getEditors ()) {
593+ editor .setSketchLocation (null );
594+ }
591595 }
592596 }
593597
@@ -670,11 +674,14 @@ protected void showFrame() {
670674 sketchbookLocationField .setText (Preferences .getSketchbookPath ());
671675 checkUpdatesBox .setSelected (Preferences .getBoolean ("update.check" )); //$NON-NLS-1$
672676
673- updateDisplayList ();
677+ int defaultDisplayNum = updateDisplayList ();
674678 int displayNum = Preferences .getInteger ("run.display" ); //$NON-NLS-1$
675- if (displayNum >= 0 && displayNum < displayCount ) {
676- displaySelectionBox .setSelectedIndex (displayNum );
679+ //if (displayNum > 0 && displayNum <= displayCount) {
680+ if (displayNum < 1 || displayNum > displayCount ) {
681+ displayNum = defaultDisplayNum ;
682+ Preferences .setInteger ("run.display" , displayNum );
677683 }
684+ displaySelectionBox .setSelectedIndex (displayNum -1 );
678685
679686 // This takes a while to load, so run it from a separate thread
680687 //EventQueue.invokeLater(new Runnable() {
@@ -749,11 +756,15 @@ public void run() {
749756 }
750757
751758
752- void updateDisplayList () {
759+ /**
760+ * @return the number (1..whatever, not 0-indexed) of the default display
761+ */
762+ int updateDisplayList () {
753763 GraphicsEnvironment ge = GraphicsEnvironment .getLocalGraphicsEnvironment ();
754764 GraphicsDevice defaultDevice = ge .getDefaultScreenDevice ();
755765 GraphicsDevice [] devices = ge .getScreenDevices ();
756766
767+ int defaultNum = -1 ;
757768 displayCount = devices .length ;
758769 String [] items = new String [displayCount ];
759770 for (int i = 0 ; i < displayCount ; i ++) {
@@ -762,6 +773,7 @@ void updateDisplayList() {
762773 i + 1 , mode .getWidth (), mode .getHeight ());
763774 if (devices [i ] == defaultDevice ) {
764775 title += " default" ;
776+ defaultNum = i + 1 ;
765777 }
766778 items [i ] = title ;
767779 }
@@ -771,5 +783,6 @@ void updateDisplayList() {
771783 if (displayCount == 1 ) {
772784 displaySelectionBox .setEnabled (false );
773785 }
786+ return defaultNum ;
774787 }
775788}
0 commit comments