2929import org .eclipse .swt .dnd .Transfer ;
3030import org .eclipse .swt .events .ControlAdapter ;
3131import org .eclipse .swt .events .ControlEvent ;
32- import org .eclipse .swt .events .DisposeEvent ;
33- import org .eclipse .swt .events .DisposeListener ;
3432import org .eclipse .swt .events .KeyAdapter ;
3533import org .eclipse .swt .events .KeyEvent ;
3634import org .eclipse .swt .events .MouseAdapter ;
6058import org .eclipse .swt .widgets .Combo ;
6159import org .eclipse .swt .widgets .Composite ;
6260import org .eclipse .swt .widgets .Display ;
63- import org .eclipse .swt .widgets .Event ;
6461import org .eclipse .swt .widgets .Label ;
65- import org .eclipse .swt .widgets .Listener ;
6662import org .eclipse .swt .widgets .ScrollBar ;
6763import org .eclipse .swt .widgets .Shell ;
6864
7773import com .maccasoft .propeller .internal .ColorRegistry ;
7874import com .maccasoft .propeller .internal .ImageRegistry ;
7975import com .maccasoft .propeller .internal .PngImageTransfer ;
80- import com .maccasoft .propeller .internal . Utils ;
76+ import com .maccasoft .propeller .preferences . Bounds ;
8177
8278import jssc .SerialPort ;
8379
@@ -326,12 +322,14 @@ public void propertyChange(PropertyChangeEvent evt) {
326322 gc .dispose ();
327323 }
328324
329- Rectangle rect = preferences .getTerminalWindow ();
330- GridData gridData = (GridData ) canvas .getLayoutData ();
331- gridData .widthHint = rect .width * characterWidth ;
332- gridData .heightHint = rect .height * characterHeight ;
325+ if (!shell .getMaximized ()) {
326+ Bounds bounds = preferences .getTerminalWindow ();
327+ GridData gridData = (GridData ) canvas .getLayoutData ();
328+ gridData .widthHint = bounds .width * characterWidth ;
329+ gridData .heightHint = bounds .height * characterHeight ;
330+ shell .pack ();
331+ }
333332
334- shell .pack ();
335333 redraw ();
336334 break ;
337335 }
@@ -394,9 +392,7 @@ public SerialTerminal(Display display, Preferences preferences) {
394392 public void open () {
395393 create ();
396394
397- shell .pack ();
398395 shell .open ();
399-
400396 shell .addShellListener (new ShellAdapter () {
401397
402398 @ Override
@@ -437,47 +433,71 @@ void create() {
437433 createContents (shell );
438434 applyTheme (preferences .getTheme ());
439435
440- Rectangle rect = preferences .getTerminalWindow ();
441- if (rect .x != -1 && rect .y != -1 ) {
442- rect .width *= characterWidth ;
443- rect .height *= characterHeight ;
444- if (!Utils .offscreen (rect , display .getBounds ())) {
445- shell .setLocation (rect .x , rect .y );
446- }
447- }
448-
449436 preferences .addPropertyChangeListener (preferencesChangeListener );
450437
451- shell .addListener ( SWT . Traverse , new Listener () {
438+ shell .pack ();
452439
453- @ Override
454- public void handleEvent (Event e ) {
455- if (e .detail == SWT .TRAVERSE_ESCAPE ) {
456- e .doit = false ;
457- }
458- }
459- });
440+ Bounds bounds = preferences .getTerminalWindow ();
441+ if (bounds .x != -1 && bounds .y != -1 ) {
442+ Rectangle windowBounds = shell .getBounds ();
443+ Rectangle clientArea = shell .getClientArea ();
444+ Rectangle displayBounds = display .getBounds ();
460445
461- shell .addDisposeListener (new DisposeListener () {
446+ boolean offscreen = false ;
447+ if (bounds .x >= displayBounds .x + displayBounds .width ) {
448+ offscreen = true ;
449+ }
450+ else if (bounds .x + windowBounds .width < displayBounds .x ) {
451+ offscreen = true ;
452+ }
453+ else if (bounds .y + (windowBounds .height - clientArea .height ) < displayBounds .y || bounds .y >= displayBounds .y + displayBounds .height ) {
454+ offscreen = true ;
455+ }
456+ if (!offscreen ) {
457+ shell .setLocation (bounds .x , bounds .y );
458+ }
462459
463- @ Override
464- public void widgetDisposed (DisposeEvent e ) {
465- preferences .removePropertyChangeListener (preferencesChangeListener );
466- try {
467- if (comPort .isOpened ()) {
468- comPort .closePort ();
460+ if (bounds .maximized ) {
461+ display .asyncExec (() -> {
462+ if (!shell .isDisposed ()) {
463+ shell .setMaximized (bounds .maximized );
469464 }
470- } catch (Exception ex ) {
465+ });
466+ }
467+ }
468+ else {
469+ Rectangle rect = shell .getBounds ();
470+ preferences .setTerminalWindow (new Bounds (rect .x , rect .y , screenWidth , screenHeight ));
471+ }
472+
473+ shell .addListener (SWT .Traverse , e -> {
474+ if (e .detail == SWT .TRAVERSE_ESCAPE ) {
475+ e .doit = false ;
476+ }
477+ });
471478
479+ shell .addDisposeListener (e -> {
480+ preferences .removePropertyChangeListener (preferencesChangeListener );
481+ try {
482+ if (comPort .isOpened ()) {
483+ comPort .closePort ();
472484 }
485+ } catch (Exception ex ) {
473486
474- Rectangle rect = shell .getBounds ();
475- rect .width = screenWidth ;
476- rect .height = screenHeight ;
477- preferences .setTerminalWindow (rect );
487+ }
478488
479- font .dispose ();
489+ if (shell .getMaximized ()) {
490+ Bounds currentBounds = preferences .getTerminalWindow ();
491+ Bounds bounds1 = new Bounds (currentBounds .x , currentBounds .y , currentBounds .width , currentBounds .height );
492+ bounds1 .maximized = shell .getMaximized ();
493+ preferences .setTerminalWindow (bounds1 );
480494 }
495+ else {
496+ Rectangle rect = shell .getBounds ();
497+ preferences .setTerminalWindow (new Bounds (rect .x , rect .y , screenWidth , screenHeight ));
498+ }
499+
500+ font .dispose ();
481501 });
482502 }
483503
@@ -494,12 +514,12 @@ protected void createContents(Composite parent) {
494514
495515 createLineInputGroup (container );
496516
497- Rectangle rect = preferences .getTerminalWindow ();
517+ Bounds bounds = preferences .getTerminalWindow ();
498518
499519 canvas = new Canvas (container , SWT .DOUBLE_BUFFERED | SWT .V_SCROLL );
500520 GridData gridData = new GridData (SWT .FILL , SWT .FILL , true , true );
501- gridData .widthHint = rect .width * characterWidth ;
502- gridData .heightHint = rect .height * characterHeight ;
521+ gridData .widthHint = bounds .width * characterWidth ;
522+ gridData .heightHint = bounds .height * characterHeight ;
503523 canvas .setLayoutData (gridData );
504524
505525 createBottomControls (container );
@@ -508,7 +528,7 @@ protected void createContents(Composite parent) {
508528 background = colors [0 ];
509529 canvas .setBackground (background );
510530
511- resizeScreen (rect .width , rect .height );
531+ resizeScreen (bounds .width , bounds .height );
512532
513533 canvas .addControlListener (new ControlAdapter () {
514534
@@ -536,11 +556,9 @@ public void controlResized(ControlEvent e) {
536556 int height = size .y / characterHeight ;
537557 if (width != screenWidth || height != screenHeight ) {
538558 resizeScreen (width , height );
539- preferences .removePropertyChangeListener (preferencesChangeListener );
540- try {
541- preferences .setTerminalSize (width , height );
542- } finally {
543- preferences .addPropertyChangeListener (preferencesChangeListener );
559+ if (!shell .getMaximized ()) {
560+ Bounds currentBounds = preferences .getTerminalWindow ();
561+ preferences .setTerminalWindow (new Bounds (currentBounds .x , currentBounds .y , width , height ));
544562 }
545563 sizeDisplayTimer = System .currentTimeMillis ();
546564 display .timerExec (500 , timerRunnable );
0 commit comments