Package edu.cmu.relativelayout.matrix

Examples of edu.cmu.relativelayout.matrix.RelativeMatrix


   * (non-Javadoc)
   *
   * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
   */
  public void layoutContainer(Container theParent) {
    RelativeMatrix myBackend = this.getBackend();

    initializeMatrixForContainer(theParent, myBackend);

    // Generate solutions:
    Map<Variable, Double> solutions = myBackend.solve();
    // System.out.println(solutions);

    setComponentBoundsFromVariables(theParent, solutions);
  }
View Full Code Here


   *
   * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
   */
  public Dimension preferredLayoutSize(Container theParent) {
    synchronized (theParent.getTreeLock()) {
      RelativeMatrix myBackend = this.getBackend();

      initializeMatrixForContainer(theParent, myBackend);

      // Check for dynamic sizes
      boolean hasDynamicWidth = false;
      boolean hasDynamicHeight = false;
      for (Component thisComponent : this.constraints.keySet()) {
        RelativeConstraints theseConstraints = this.constraints.get(thisComponent);
        for (Binding thisBinding : theseConstraints.bindings) {
          // If any of our bindings uses a dimensional variable, we have a dynamic size.
          if (thisBinding.usesDimensionalVariable()) {
            if (thisBinding.isHorizontal()) {
              hasDynamicWidth = true;
            } else {
              hasDynamicHeight = true;
            }
            break;
          }
        }
      }

      // Calculate the screen size if we're going to need it.
      int screenWidth = 0;
      int screenHeight = 0;
      if (hasDynamicWidth || hasDynamicHeight) {
        GraphicsConfiguration graphicsConfig = theParent.getGraphicsConfiguration();
        if (graphicsConfig == null) {
          screenWidth = 640;
          screenHeight = 480;
        } else {
          GraphicsDevice gs = graphicsConfig.getDevice();
          DisplayMode dm = gs.getDisplayMode();
          screenWidth = dm.getWidth();
          screenHeight = dm.getHeight();
        }

        // If we found dynamic sizes, return the maximum size possible, and we're done.
        if (hasDynamicWidth && hasDynamicHeight) {
          return new Dimension(screenWidth, screenHeight);
        }
      }

      // Otherwise, we have to generate solutions:
      Map<Variable, Double> solutions = myBackend.solve();

      // Now we find the max and min extents from all four corners:
      double maxLeftExtent = 0.0, maxTopExtent = 0.0;
      double minRightExtent = theParent.getSize().getWidth(), minBottomExtent = theParent.getSize().getHeight();

View Full Code Here

   * Gets an instance of the backend matrix, creating one if necessary. This method should be used rather than accessing
   * this.backend directly to avoid crashes or duplicated instances.
   */
  private RelativeMatrix getBackend() {
    if (this.backend == null) {
      this.backend = new RelativeMatrix();
    }
    return this.backend;
  }
View Full Code Here

TOP

Related Classes of edu.cmu.relativelayout.matrix.RelativeMatrix

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.