Sash becomes lost after resize

81 views Asked by At

I have an application that I have created a sash for, so that users can resize the Styled Text objects as they choose.Original

I have a bug though that if the application is maximized, the sash is moved very low on the application, and then the user un-maximizes the application, the sash is then still beyond the bounds of the screen. after maximize then back to original How can I make it so that when the user changes the application from maximized, to a smaller size, the sash automatically moves within the bounds of the application size; as in the first picture?

Also, is there a better (more dynamic) way to control the position limits for the sash?

separator.addSelectionListener(new SelectionAdapter() {
          public void widgetSelected(SelectionEvent event) {
              double height = shlPstmKnowledgeCatalogue.getBounds().height;
              double qpBtnHeight = btnQuickParts.getBounds().height;
              double workLblHeight = lblWorkInstructions.getBounds().height;

              if (!shlPstmKnowledgeCatalogue.getMaximized()) {
                  if (event.y < workLblHeight + 30) {
                      event.y = (int) workLblHeight + 30;
                  }
                  else if (event.y > height - qpBtnHeight - 90) {
                      event.y = (int) (height - qpBtnHeight - 90);
                  }
              }
              else {
                  if (event.y < workLblHeight + 30) {
                      event.y = (int) (workLblHeight + 30);
                  }
                  else if (event.y > height - qpBtnHeight - 90) {
                      event.y = (int) (height - qpBtnHeight - 90);
                  }
              }
              separator.setBounds(event.x, event.y, event.width, event.height);
            FormData formData = new FormData();
            formData.top = new FormAttachment(0, event.y);
            formData.left = new FormAttachment(lblScript, 6);
            formData.right = new FormAttachment(script, 0, SWT.RIGHT);
            formData.height = 5;
            separator.setLayoutData(formData);

            /*
             * Used to move the script label with the movement of the script
             * text box. Otherwise, the label gets lost behind the text boxes.
             */
            FormData lblScriptData = new FormData();
            lblScriptData.top = new FormAttachment(0, event.y - 5);
            lblScriptData.bottom = new FormAttachment(0, event.y + 12);
            lblScriptData.left = new FormAttachment (workInstructions,2, SWT.LEFT);
            lblScript.setLayoutData(lblScriptData);
            shlPstmKnowledgeCatalogue.layout(true);
          }
        });
    /*
     * Attaches the Work Instuction text box to the sash for dynamic resizing
     * The resizing is done in relation to the Script text box
     */
    FormData workInstForm = new FormData();
    workInstForm.left = new FormAttachment(0, 194);
    workInstForm.right = new FormAttachment(100, -6);
    workInstForm.bottom = new FormAttachment(separator, -15);
    workInstForm.top = new FormAttachment(lblWorkInstructions, 7);
    workInstructions.setLayoutData(workInstForm);
    formToolkit.adapt(workInstructions, true, true);

    /*
     * Attaches the Script text box to the sash for dynamic resizing
     * The resizing is done in relation to the work instruction text box
     */
    FormData scriptForm = new FormData();
    scriptForm.top = new FormAttachment(separator, 15);
    scriptForm.right = new FormAttachment(workInstructions, 0, SWT.RIGHT);
    scriptForm.left = new FormAttachment(workInstructions, 0, SWT.LEFT);
    scriptForm.bottom = new FormAttachment(btnQuickParts, -6);
    script.setLayoutData(scriptForm);
    formToolkit.adapt(script, true, true);
1

There are 1 answers

0
Evan Bechtol On

I ended up writing a separate method to constantly check the position of the sash. Maybe it is not the most efficient way of doing it, but it does work!

/**
 * Check the sash position to verify that it is within the bounds of the shell.
 * This is primarily used when the user maxmimizes the application, moves the
 * sash, then minimizes the application.
 */
private void checkSashPosition() {
    if (!shlPstmKnowledgeCatalogue.isDisposed() && separator.getBounds().y > shlPstmKnowledgeCatalogue.getBounds().height) {
        separator.setLocation(235, shlPstmKnowledgeCatalogue.getBounds().height - 248);
        workInstructions.setSize(455, 100);
        script.setSize(455, 130);
        script.setLocation(194, 167);
        lblScript.setLocation(194, 143);
    }
}

The method is called inside of a while-loop, and the objects that are relative to the sash are also adjusted.