2828import java .util .*;
2929
3030import javax .swing .*;
31+ import javax .swing .border .*;
32+ import javax .swing .event .*;
3133
3234import processing .core .*;
3335
@@ -107,6 +109,8 @@ public class Preferences {
107109 int wide , high ;
108110
109111 JTextField sketchbookLocationField ;
112+ JTextField presentColor ;
113+ JTextField presentColorHex ;
110114 JCheckBox editorAntialiasBox ;
111115 JCheckBox deletePreviousBox ;
112116 JCheckBox whinyBox ;
@@ -118,6 +122,8 @@ public class Preferences {
118122 JComboBox consoleSizeField ;
119123 JCheckBox inputMethodBox ;
120124 JCheckBox autoAssociateBox ;
125+
126+ ColorChooser selector ;
121127
122128 JCheckBox errorCheckerBox ;
123129 JCheckBox warningsCheckerBox ;
@@ -375,6 +381,131 @@ public void actionPerformed(ActionEvent e) {
375381 top += d .height + GUI_BETWEEN ;
376382
377383
384+ Container colorBox = Box .createHorizontalBox ();
385+
386+ label = new JLabel ("Background color when Presenting: " );
387+ colorBox .add (label );
388+
389+ final String colorTip = "<html>"
390+ + "Select the background color used when using Present.<br/>"
391+ + "Present is used to present a sketch in full-screen, <br/>"
392+ + "accessible from the Sketch menu." ;
393+ label .setToolTipText (colorTip );
394+
395+ presentColor = new JTextField (" " );
396+ presentColor .setOpaque (true );
397+ presentColor .setEnabled (false );
398+ presentColor .setBorder (new CompoundBorder (BorderFactory .createMatteBorder (
399+ 1 , 1 , 0 , 0 , new Color (195 , 195 , 195 )), BorderFactory .createMatteBorder (
400+ 0 , 0 , 1 , 1 , new Color (54 , 54 , 54 ))));
401+ presentColor .setBackground (Preferences .getColor ("run.present.bgcolor" ));
402+
403+ presentColorHex = new JTextField (6 );
404+ presentColorHex
405+ .setText (Preferences .get ("run.present.bgcolor" ).substring (1 ));
406+ presentColorHex .getDocument ().addDocumentListener (new DocumentListener () {
407+
408+ @ Override
409+ public void removeUpdate (DocumentEvent e ) {
410+ final String colorValue = presentColorHex .getText ().toUpperCase ();
411+ if (colorValue .length () == 7 && (colorValue .startsWith ("#" )))
412+ EventQueue .invokeLater (new Runnable () {
413+ public void run () {
414+ presentColorHex .setText (colorValue .substring (1 ));
415+ }
416+ });
417+ if (colorValue .length () == 6
418+ && colorValue .matches ("[0123456789ABCDEF]*" )) {
419+ presentColor .setBackground (new Color (Integer .parseInt (
420+ colorValue .substring (0 , 2 ), 16 ), Integer .parseInt (
421+ colorValue .substring (2 , 4 ), 16 ), Integer .parseInt (
422+ colorValue .substring (4 , 6 ), 16 )));
423+ if (!colorValue .equals (presentColorHex .getText ()))
424+ EventQueue .invokeLater (new Runnable () {
425+ public void run () {
426+ presentColorHex .setText (colorValue );
427+ }
428+ });
429+ }
430+ }
431+
432+ @ Override
433+ public void insertUpdate (DocumentEvent e ) {
434+ final String colorValue = presentColorHex .getText ().toUpperCase ();
435+ if (colorValue .length () == 7 && (colorValue .startsWith ("#" )))
436+ EventQueue .invokeLater (new Runnable () {
437+ public void run () {
438+ presentColorHex .setText (colorValue .substring (1 ));
439+ }
440+ });
441+ if (colorValue .length () == 6
442+ && colorValue .matches ("[0123456789ABCDEF]*" )) {
443+ presentColor .setBackground (new Color (Integer .parseInt (
444+ colorValue .substring (0 , 2 ), 16 ), Integer .parseInt (
445+ colorValue .substring (2 , 4 ), 16 ), Integer .parseInt (
446+ colorValue .substring (4 , 6 ), 16 )));
447+ if (!colorValue .equals (presentColorHex .getText ()))
448+ EventQueue .invokeLater (new Runnable () {
449+ public void run () {
450+ presentColorHex .setText (colorValue );
451+ }
452+ });
453+ }
454+ }
455+
456+ @ Override public void changedUpdate (DocumentEvent e ) {}
457+ });
458+
459+ selector = new ColorChooser (dialog , false ,
460+ Preferences .getColor ("run.present.bgcolor" ), "OK" ,
461+ new ActionListener () {
462+ @ Override
463+ public void actionPerformed (ActionEvent e ) {
464+ String colorValue = selector .getHexColor ();
465+ presentColorHex .setText (colorValue .substring (1 ));
466+ presentColor .setBackground (new Color (Integer .parseInt (
467+ colorValue .substring (1 , 3 ), 16 ), Integer .parseInt (
468+ colorValue .substring (3 , 5 ), 16 ), Integer .parseInt (
469+ colorValue .substring (5 , 7 ), 16 )));
470+ selector .hide ();
471+ }
472+ });
473+
474+ presentColor .addMouseListener (new MouseListener () {
475+ @ Override public void mouseReleased (MouseEvent e ) {}
476+ @ Override public void mousePressed (MouseEvent e ) {}
477+
478+ @ Override
479+ public void mouseExited (MouseEvent e ) {
480+ dialog .setCursor (Cursor .DEFAULT_CURSOR );
481+ }
482+
483+ @ Override
484+ public void mouseEntered (MouseEvent e ) {
485+ dialog .setCursor (Cursor .HAND_CURSOR );
486+ }
487+
488+ @ Override
489+ public void mouseClicked (MouseEvent e ) {
490+ selector .show ();
491+ }
492+ });
493+
494+ label = new JLabel ("#" );
495+ colorBox .add (label );
496+
497+ colorBox .add (presentColorHex );
498+
499+ colorBox .add (Box .createHorizontalStrut (GUI_SMALL + 2 / 3 * GUI_SMALL ));
500+
501+ colorBox .add (presentColor );
502+
503+ pain .add (colorBox );
504+ d = colorBox .getPreferredSize ();
505+ colorBox .setBounds (left , top , d .width , d .height );
506+
507+ top += d .height + GUI_BETWEEN ;
508+
378509 // [ ] Use smooth text in editor window
379510
380511 editorAntialiasBox = new JCheckBox ("Use smooth text in editor window" );
@@ -830,6 +961,8 @@ protected void applyFrame() {
830961 consoleSizeField .setSelectedItem (getInteger ("console.font.size" ));
831962 }
832963
964+ setColor ("run.present.bgcolor" , presentColor .getBackground ());
965+
833966 setBoolean ("editor.input_method_support" , inputMethodBox .isSelected ()); //$NON-NLS-1$
834967
835968 if (autoAssociateBox != null ) {
@@ -896,6 +1029,9 @@ public void run() {
8961029 fontSizeField .setSelectedItem (getInteger ("editor.font.size" ));
8971030 consoleSizeField .setSelectedItem (getInteger ("console.font.size" ));
8981031
1032+ presentColor .setBackground (Preferences .getColor ("run.present.bgcolor" ));
1033+ presentColorHex .setText (Preferences .get ("run.present.bgcolor" ).substring (1 ));
1034+
8991035 memoryOverrideBox .
9001036 setSelected (getBoolean ("run.options.memory" )); //$NON-NLS-1$
9011037 memoryField .
0 commit comments