Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » Customizable JDialog in Scout(Example on how to create customizable JDialog in Scout)
Customizable JDialog in Scout [message #827571] Fri, 23 March 2012 14:19 Go to next message
Ken Lee is currently offline Ken LeeFriend
Messages: 97
Registered: March 2012
Member
The default behavior of resizing of forms in Scout follows the rules:


  1. If a form is opened initially and exceeds the size of the screen, it will be scaled down to match the height of the screen.
  2. If a field gets visible during runtime, the form will always be resized, i.e. it gets expanded automatically.
  3. If a field gets invisible dynamically, the form will not be reduced.


This behavior is not always preferable. Consider a form that is too large to fit into the Y-dimension of the screen. It contains a large text field
configured with an extremely large grid height of 250 and two buttons A and B. Button B is initially invisible, but can be set visible by clicking on button A.

Code snippet of BigForm
public class BigForm extends AbstractForm {

  @Order(10.0)
  public class MainBox extends AbstractGroupBox {

    @Override
    protected int getConfiguredGridH() {
      return 250;
    }

    @Override
    protected boolean getConfiguredGridUseUiHeight() {
      return false;
    }

    @Order(10.0)
    public class AButton extends AbstractButton {
      @Override
      protected String getConfiguredLabel() {
        return getClass().getSimpleName();
      }

      @Override
      protected void execClickAction() throws ProcessingException {
        getBButton().setVisible(true);
      }
    }

    @Order(20.0)
    public class ATextField extends AbstractStringField {
      @Override
      protected String getConfiguredLabel() {
        return getClass().getSimpleName();
      }

      @Override
      protected boolean getConfiguredMultilineText() {
        return true;
      }

      @Override
      protected int getConfiguredGridH() {
        return 2;
      }

      @Override
      protected int getConfiguredGridW() {
        return 2;
      }
    }

    @Order(30.0)
    public class BButton extends AbstractButton {
      @Override
      protected String getConfiguredLabel() {
        return getClass().getSimpleName();
      }

      @Override
      protected boolean getConfiguredVisible() {
        return false;
      }
    }

    @Order(100.0)
    public class OkButton extends AbstractOkButton {
    }

    @Order(200.0)
    public class CancelButton extends AbstractCancelButton {
    }
  }

  public class DisplayHandler extends AbstractFormHandler {

    @Override
    protected void execLoad() throws ProcessingException {
      String string = "";
      string += "Click on the AButton to make BButton visible \n";
      string += "\n";
      string += "Press escape if you do not see the Cancel Button";
      getATextField().setValue(string);
    }
  }
}


According to rule 1, the form will fit into the screen initially (i.e. when the form is opened), although its height is larger than the Y-dimension of the screen. Button A is visible and if it gets clicked, the form will expand because of rule 2. This results in a form that does not fit into the screen anymore so that all buttons at the bottom (A, B, OK and Cancel) exceed the screen boundaries.

Scout provides the ability to override this default behavior by introducing new components implementing a different resizing logic. In the following example
we will ignore the second rule so that the form will not cross the screen boundaries.

First create a subtype of JDialogEx that overrides the createRootPane() method to return a subtype of JRootPaneEx. This subtype is called SampleJRootPaneEx and overrides the reflow() method.

Code snippet of SampleJDialogEx
public class SampleJDialogEx extends JDialogEx {

  public SampleJDialogEx() {
    super();
  }

  /* all other constructors are left out for the sake of simplicity */

  @Override
  protected JRootPane createRootPane() {
    SampleJRootPaneEx rp = new SampleJRootPaneEx() {
      private static final long serialVersionUID = 1L;

      @Override
      protected void reflow() {
        SampleJDialogEx.this.pack();
      }
    };
    rp.setName("Synth.Dialog");
    return rp;
  }
}


SampleJRootPaneEx additionally overrides the evaluateReflow() method that decides if the form should be resized.
The difference between the sample implementation of the method evaluateReflow() compared to the one in JRootPaneExis that reflow() will not be called even if the preferred height dimension is not matched. In the default implementation
the form gets resized if its current height does not match the actual (preferred) height.

Code snippet of SampleJRootPaneEx
public class SampleJRootPaneEx extends JRootPaneEx {

  @Override
  protected void evaluateReflow() {
    if (getParent() == null || !isVisible() || !isShowing()) {
      return;
    }
    // check minSize and maxSize requirements
    Dimension d = getSize();
    if (d.width > 0 && d.height > 0) {
      Dimension[] sizes = SwingLayoutUtility.getValidatedSizes(SampleJDialogEx.this);
      Dimension minMaxSize = new Dimension(
                        Math.min(Math.max(d.width, sizes[0].width), sizes[2].width),
                        Math.min(Math.max(d.height, sizes[0].height), sizes[2].height)
                        );
      int dw = minMaxSize.width - d.width;
      int dh = minMaxSize.height - d.height;
      if (dw != 0 || dh != 0) { // ignore preferred heights
        super.reflow();
      }
    }
  }
}


Finally the methods createJDialogEx() in SwingEnvironment are overridden to return the subtype SampleJDialogxEx.

Code snipped of SwingEnvironment
public class SwingEnvironment extends DefaultSwingEnvironment {

  @Override
  public JDialogEx createJDialogEx(Dialog swingParent) {
    return new SampleJDialogEx();
  }

  @Override
  public JDialogEx createJDialogEx(Frame swingParent) {
    return new SampleJDialogEx();
  }
}


With this implementation, the BigForm will not trigger resizing of the form anymore even if button A is clicked which makes button B visible.

All sources of this example can be found in the attached Zip file.

Re: Customizable JDialog in Scout [message #827596 is a reply to message #827571] Fri, 23 March 2012 14:47 Go to previous message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 1252
Registered: October 2011
Senior Member
This is related to bug Bugzilla 372222.

Thanks for these info.
Previous Topic:BeanArrayHolder and FormData
Next Topic:Eclipse Scout 3.8 M6
Goto Forum:
  


Current Time: Thu Apr 25 23:07:57 GMT 2024

Powered by FUDForum. Page generated in 0.03066 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top