3838
3939
4040/**
41- * Window for modifying preferences.
41+ * Creates the window for modifying preferences.
4242 */
4343public class PreferencesFrame {
44- JFrame dialog ;
44+ JFrame frame ;
4545 GroupLayout layout ;
4646
4747 static final Integer [] FONT_SIZES = { 10 , 12 , 14 , 18 , 24 , 36 , 48 };
@@ -83,18 +83,15 @@ public class PreferencesFrame {
8383
8484 public PreferencesFrame (Base base ) {
8585 this .base = base ;
86- //dialog = new JDialog(editor, "Preferences", true);
87- dialog = new JFrame (Language .text ("preferences" ));
88- Container pain = dialog .getContentPane ();
86+
87+ frame = new JFrame (Language .text ("preferences" ));
88+ Container pain = frame .getContentPane ();
8989 layout = new GroupLayout (pain );
9090 layout .setAutoCreateGaps (true );
9191 layout .setAutoCreateContainerGaps (true );
9292
9393 pain .setLayout (layout );
9494
95- // final int GUI_BETWEEN = Preferences.GUI_BETWEEN;
96- // final int GUI_BIG = Preferences.GUI_BIG;
97- // final int GUI_SMALL = Preferences.GUI_SMALL;
9895 final int BUTTON_WIDTH = Preferences .BUTTON_WIDTH ;
9996 final int BORDER = Base .isMacOS () ? 20 : 13 ;
10097
@@ -115,13 +112,12 @@ public void actionPerformed(ActionEvent e) {
115112 File dflt = new File (sketchbookLocationField .getText ());
116113 PApplet .selectFolder (Language .text ("preferences.sketchbook_location.popup" ),
117114 "sketchbookCallback" , dflt ,
118- PreferencesFrame .this , dialog );
115+ PreferencesFrame .this , frame );
119116 }
120117 });
121118
122- // Language: [ English ] (requires restart of Processing)
123-
124119
120+ // Language: [ English ] (requires restart of Processing)
125121
126122 JLabel languageLabel = new JLabel (Language .text ("preferences.language" )+": " );
127123 languageSelectionBox = new JComboBox <String >();
@@ -136,17 +132,10 @@ public void actionPerformed(ActionEvent e) {
136132 }
137133 }
138134 languageSelectionBox .setModel (new DefaultComboBoxModel <String >(languageSelection ));
139- restartProcessingLabel = new JLabel (" (" + Language .text ("preferences.requires_restart" )+ ")" );
135+ restartProcessingLabel = new JLabel (" (" + Language .text ("preferences.requires_restart" ) + ")" );
140136
141- // Editor and console font [ Source Code Pro ]
142137
143- // Nevermind on this for now.. Java doesn't seem to have a method for
144- // enumerating only the fixed-width (monospaced) fonts. To do this
145- // properly, we'd need to list the fonts, and compare the metrics of
146- // i and M for each. When they're identical (and not degenerate),
147- // we'd call that font fixed width. That's all a very expensive set of
148- // operations, so it should also probably be cached between runs and
149- // updated in the background.
138+ // Editor and console font [ Source Code Pro ]
150139
151140 JLabel fontLabel = new JLabel (Language .text ("preferences.editor_and_console_font" )+": " );
152141 final String fontTip = "<html>" + Language .text ("preferences.editor_and_console_font.tip" );
@@ -157,6 +146,7 @@ public void actionPerformed(ActionEvent e) {
157146 //updateDisplayList();
158147 fontSelectionBox .setEnabled (false ); // don't enable until fonts are loaded
159148
149+
160150 // Editor font size [ 12 ] Console font size [ 10 ]
161151
162152 JLabel fontSizelabel = new JLabel (Language .text ("preferences.editor_font_size" )+": " );
@@ -228,7 +218,7 @@ public void run() {
228218 @ Override public void changedUpdate (DocumentEvent e ) {}
229219 });
230220
231- selector = new ColorChooser (dialog , false ,
221+ selector = new ColorChooser (frame , false ,
232222 Preferences .getColor ("run.present.bgcolor" ), Language .text ("prompt.ok" ),
233223 new ActionListener () {
234224 @ Override
@@ -244,12 +234,12 @@ public void actionPerformed(ActionEvent e) {
244234
245235 @ Override
246236 public void mouseExited (MouseEvent e ) {
247- dialog .setCursor (Cursor .getPredefinedCursor (Cursor .DEFAULT_CURSOR ));
237+ frame .setCursor (Cursor .getPredefinedCursor (Cursor .DEFAULT_CURSOR ));
248238 }
249239
250240 @ Override
251241 public void mouseEntered (MouseEvent e ) {
252- dialog .setCursor (Cursor .getPredefinedCursor (Cursor .HAND_CURSOR ));
242+ frame .setCursor (Cursor .getPredefinedCursor (Cursor .HAND_CURSOR ));
253243 }
254244
255245 @ Override
@@ -260,57 +250,45 @@ public void mouseClicked(MouseEvent e) {
260250
261251 JLabel hashLabel = new JLabel ("#" );
262252
253+
263254 // [ ] Use smooth text in editor window
264255
265256 editorAntialiasBox = new JCheckBox (Language .text ("preferences.use_smooth_text" ));
266257
258+
267259 // [ ] Enable complex text input (for Japanese et al, requires restart)
268260
269261 inputMethodBox =
270262 new JCheckBox (Language .text ("preferences.enable_complex_text_input" )+
271263 " (" +Language .text ("preferences.enable_complex_text_input_example" )+
272264 ", " +Language .text ("preferences.requires_restart" )+")" );
273265
266+
274267 // [ ] Continuously check for errors - PDE X
275268
276269 errorCheckerBox =
277270 new JCheckBox (Language .text ("preferences.continuously_check" ));
278271
272+
279273 // [ ] Show Warnings - PDE X
280274
281275 warningsCheckerBox =
282276 new JCheckBox (Language .text ("preferences.show_warnings" ));
283277
278+
284279 // [ ] Enable Code Completion - PDE X
285280
286281 codeCompletionBox =
287282 new JCheckBox (Language .text ("preferences.code_completion" ) +
288283 " Ctrl-" + Language .text ("preferences.cmd_space" ));
289- //// codeCompletionBox.addActionListener(new ActionListener() {
290- ////
291- //// @Override
292- //// public void actionPerformed(ActionEvent e) {
293- //// // Disble code completion trigger option if completion is disabled
294- //// codeCompletionTriggerBox.setEnabled(codeCompletionBox.isSelected());
295- //// }
296- //// });
297-
298- //// int toggleLeft = left + d.width;
299-
300- //// [ ] Toggle Code Completion Trigger - PDE X. No longer needed (Manindra)
301-
302- //// codeCompletionTriggerBox =
303- //// new JCheckBox(Language.text("preferences.trigger_with")+" Ctrl-"+Language.text("preferences.cmd_space"));
304- //// pain.add(codeCompletionTriggerBox);
305- //// d = codeCompletionTriggerBox.getPreferredSize();
306- //// codeCompletionTriggerBox.setBounds(toggleLeft, top, d.width + 10, d.height);
307- //// right = Math.max(right, toggleLeft + d.width);
284+
308285
309286 // [ ] Show import suggestions - PDE X
310287
311288 importSuggestionsBox =
312289 new JCheckBox (Language .text ("preferences.suggest_imports" ));
313290
291+
314292 // [ ] Increase maximum available memory to [______] MB
315293
316294 memoryOverrideBox = new JCheckBox (Language .text ("preferences.increase_max_memory" )+": " );
@@ -323,16 +301,19 @@ public void stateChanged(ChangeEvent e) {
323301 });
324302 JLabel mbLabel = new JLabel ("MB" );
325303
304+
326305 // [ ] Delete previous application folder on export
327306
328307 deletePreviousBox =
329308 new JCheckBox (Language .text ("preferences.delete_previous_folder_on_export" ));
330309
310+
331311 // [ ] Check for updates on startup
332312
333313 checkUpdatesBox =
334314 new JCheckBox (Language .text ("preferences.check_for_updates_on_startup" ));
335315
316+
336317 // Run sketches on display [ 1 ]
337318
338319 JLabel displayLabel = new JLabel (Language .text ("preferences.run_sketches_on_display" )+": " );
@@ -347,6 +328,7 @@ public void stateChanged(ChangeEvent e) {
347328 new JCheckBox (Language .text ("preferences.automatically_associate_pde_files" ));
348329 autoAssociateBox .setVisible (false );
349330
331+
350332 // More preferences are in the ...
351333
352334 JLabel morePreferenceLabel = new JLabel (Language .text ("preferences.file" ) + ":" );
@@ -373,6 +355,7 @@ public void mouseExited(MouseEvent e) {
373355 JLabel preferenceHintLabel = new JLabel ("(" + Language .text ("preferences.file.hint" ) + ")" );
374356 preferenceHintLabel .setForeground (Color .gray );
375357
358+
376359 // [ OK ] [ Cancel ]
377360
378361 okButton = new JButton (Preferences .PROMPT_OK );
@@ -506,7 +489,7 @@ public void actionPerformed(ActionEvent e) {
506489 }
507490 // closing the window is same as hitting cancel button
508491
509- dialog .addWindowListener (new WindowAdapter () {
492+ frame .addWindowListener (new WindowAdapter () {
510493 public void windowClosing (WindowEvent e ) {
511494 disposeFrame ();
512495 }
@@ -519,11 +502,11 @@ public void actionPerformed(ActionEvent actionEvent) {
519502 };
520503 // finish up
521504
522- Toolkit .registerWindowCloseKeys (dialog .getRootPane (), disposer );
523- Toolkit .setIcon (dialog );
524- dialog .setResizable (false );
525- dialog .pack ();
526- dialog .setLocationRelativeTo (null );
505+ Toolkit .registerWindowCloseKeys (frame .getRootPane (), disposer );
506+ Toolkit .setIcon (frame );
507+ frame .setResizable (false );
508+ frame .pack ();
509+ frame .setLocationRelativeTo (null );
527510
528511 // Workaround for OS X, which breaks the layout when these are set earlier
529512 // https://github.com/processing/processing/issues/3212
@@ -545,26 +528,17 @@ public void keyPressed(KeyEvent e) {
545528 }
546529
547530
531+ /** Callback for the folder selector. */
548532 public void sketchbookCallback (File file ) {
549- if (file != null ) {
533+ if (file != null ) { // null if cancel or closed
550534 sketchbookLocationField .setText (file .getAbsolutePath ());
551535 }
552536 }
553537
554538
555- // public Dimension getPreferredSize() {
556- // return new Dimension(wide, high);
557- // }
558-
559-
560- // .................................................................
561-
562-
563- /**
564- * Close the window after an OK or Cancel.
565- */
539+ /** Close the window after an OK or Cancel. */
566540 protected void disposeFrame () {
567- dialog .dispose ();
541+ frame .dispose ();
568542 }
569543
570544
@@ -726,21 +700,21 @@ public void run() {
726700 }
727701 // The OK Button has to be set as the default button every time the
728702 // PrefWindow is to be displayed
729- dialog .getRootPane ().setDefaultButton (okButton );
703+ frame .getRootPane ().setDefaultButton (okButton );
730704
731705 // The pack is called again here second time to fix layout bugs
732706 // the bugs are not due to groupLayout but due to HTML rendering of components
733707 // more info can be found here -> https://netbeans.org/bugzilla/show_bug.cgi?id=79967
734- dialog .pack ();
708+ frame .pack ();
735709
736- dialog .setVisible (true );
710+ frame .setVisible (true );
737711 }
738712
739713
740714 /**
741715 * I have some ideas on how we could make Swing even more obtuse for the
742716 * most basic usage scenarios. Is there someone on the team I can contact?
743- * Oracle staffer, are you reading this? This could be your meal ticket.
717+ * Are you an Oracle staffer reading this? This could be your meal ticket.
744718 */
745719 static class FontNamer extends JLabel implements ListCellRenderer <Font > {
746720 public Component getListCellRendererComponent (JList <? extends Font > list ,
@@ -776,15 +750,25 @@ public void run() {
776750
777751 void updateDisplayList () {
778752 GraphicsEnvironment ge = GraphicsEnvironment .getLocalGraphicsEnvironment ();
779- displayCount = ge .getScreenDevices ().length ;
780- // displaySelectionBox.removeAll();
753+ GraphicsDevice defaultDevice = ge .getDefaultScreenDevice ();
754+ GraphicsDevice [] devices = ge .getScreenDevices ();
755+
756+ displayCount = devices .length ;
781757 String [] items = new String [displayCount ];
782758 for (int i = 0 ; i < displayCount ; i ++) {
783- items [i ] = String .valueOf (i + 1 );
784- // displaySelectionBox.add(String.valueOf(i + 1));
759+ DisplayMode mode = devices [i ].getDisplayMode ();
760+ String title = String .format ("%d (%d \u2715 %d)" , // or \u00d7?
761+ i + 1 , mode .getWidth (), mode .getHeight ());
762+ if (devices [i ] == defaultDevice ) {
763+ title += " default" ;
764+ }
765+ items [i ] = title ;
785766 }
786- // PApplet.println(items);
787767 displaySelectionBox .setModel (new DefaultComboBoxModel <String >(items ));
788- // displaySelectionBox = new JComboBox(items);
768+
769+ // Disable it if you can't actually change the default display
770+ if (displayCount == 1 ) {
771+ displaySelectionBox .setEnabled (false );
772+ }
789773 }
790774}
0 commit comments