/**
   * Locate the visible view which has the earliest adapter position. Will skip headers unless they
   * are the only one visible.
   *
   * @param sectionFirstPosition Position of first position of section..
   * @param skipHeader Do not include the section header if it has one.
   * @return View.
   */
  public View getFirstVisibleView(int sectionFirstPosition, boolean skipHeader) {
    int lookAt = 0;
    int childCount = mLayoutManager.getChildCount();
    View candidate = null;
    while (true) {
      if (lookAt >= childCount) {
        return candidate;
      }

      final View view = mLayoutManager.getChildAt(lookAt);
      LayoutManager.LayoutParams lp = (LayoutManager.LayoutParams) view.getLayoutParams();
      if (sectionFirstPosition == lp.getTestedFirstPosition()) {
        if (!lp.isHeader || !skipHeader) {
          return view;
        } else {
          candidate = view;
        }
      } else {
        // Skipped past section.
        return candidate;
      }

      lookAt += 1;
    }
  }
Example #2
0
 /**
  * The method sets container's layout manager
  *
  * @param layoutManager new layout manager
  */
 public void setLayoutManager(LayoutManager layoutManager) {
   if (_layoutManager != null) {
     _layoutManager.unbindFromContainer();
   }
   _layoutManager = layoutManager;
   _layoutManager.bindToContainer(this);
 }
Example #3
0
  private void init(Context context, AttributeSet attrs, int defStyle) {
    PixelUtils.init(getContext());
    layoutManager = new LayoutManager();
    titleWidget =
        new TextLabelWidget(
            layoutManager,
            new Size(25, SizeLayoutType.ABSOLUTE, 100, SizeLayoutType.ABSOLUTE),
            TextOrientationType.HORIZONTAL);
    titleWidget.position(
        0,
        XLayoutStyle.RELATIVE_TO_CENTER,
        0,
        YLayoutStyle.ABSOLUTE_FROM_TOP,
        AnchorPosition.TOP_MIDDLE);

    // initialize attr defaults:
    titleWidget.getLabelPaint().setTextSize(PixelUtils.spToPix(DEFAULT_TITLE_WIDGET_TEXT_SIZE_SP));

    onPreInit();
    // make sure the title widget is always the topmost widget:
    layoutManager.moveToTop(titleWidget);
    if (context != null && attrs != null) {
      loadAttrs(attrs, defStyle);
    }

    layoutManager.onPostInit();
    if (renderMode == RenderMode.USE_BACKGROUND_THREAD) {
      renderThread =
          new Thread(
              new Runnable() {
                @Override
                public void run() {

                  keepRunning = true;
                  while (keepRunning) {
                    isIdle = false;
                    synchronized (pingPong) {
                      Canvas c = pingPong.getCanvas();
                      renderOnCanvas(c);
                      pingPong.swap();
                    }
                    synchronized (renderSynch) {
                      postInvalidate();
                      // prevent this thread from becoming an orphan
                      // after the view is destroyed
                      if (keepRunning) {
                        try {
                          renderSynch.wait();
                        } catch (InterruptedException e) {
                          keepRunning = false;
                        }
                      }
                    }
                  }
                }
              });
    }
  }
  protected int addView(
      LayoutState.View child, int position, LayoutManager.Direction direction, LayoutState state) {
    int addIndex;
    if (direction == LayoutManager.Direction.START) {
      addIndex = 0;
    } else {
      addIndex = mLayoutManager.getChildCount();
    }

    state.decacheView(position);
    mLayoutManager.addView(child.view, addIndex);

    return addIndex;
  }
  /**
   * Creation and initialization of a layout delegate for a new container.
   *
   * @param initialize
   * @return false if suitable layout delegate is not found
   * @throws java.lang.Exception
   * @throw IllegalArgumentException if the container instance is not empty
   */
  public boolean prepareLayoutDelegate(boolean initialize) throws Exception {
    LayoutSupportDelegate delegate = null;
    LayoutManager lmInstance = null;

    // first try to find a dedicated layout delegate (for the container)
    Class<?> layoutDelegateClass =
        LayoutSupportRegistry.getSupportClassForContainer(radContainer.getBeanClass());

    if (layoutDelegateClass != null) {
      delegate = (LayoutSupportDelegate) layoutDelegateClass.newInstance();
      /*
      if (!delegate.checkEmptyContainer(getPrimaryContainer())) {
          RuntimeException ex = new IllegalArgumentException();
          org.openide.ErrorManager.getDefault().annotate(
                  ex, AbstractLayoutSupport.getBundle().getString(
                          "MSG_ERR_NonEmptyContainer")); // NOI18N
          throw ex;
      }
      */
    } else {
      Container contDel = getPrimaryContainerDelegate();
      // if (contDel.getComponentCount() == 0) {
      // we can still handle only empty containers ...
      lmInstance = contDel.getLayout();
      delegate = LayoutSupportRegistry.createSupportForLayout(lmInstance.getClass());
      /*
      } else {
          RuntimeException ex = new IllegalArgumentException();
          org.openide.ErrorManager.getDefault().annotate(
                  ex, AbstractLayoutSupport.getBundle().getString(
                          "MSG_ERR_NonEmptyContainer")); // NOI18N
          throw ex;
      }
          */
    }

    if (delegate != null) {
      if (initialize) {
        setLayoutDelegate(delegate);
      } else {
        layoutDelegate = delegate;
        needInit = true;
        initializeFromInstance = lmInstance != null;
      }
      return true;
    } else {
      return false;
    }
  }
Example #6
0
 @Override
 protected void paint(PPaintContext paintContext) {
   layoutManager.updateZoomLayout(paintContext.getScale());
   if (layoutManager.isZUIVisibleChanged()) {
     if (getParent() instanceof ElementView) {
       ((ElementView) getParent()).getLayoutManager().updateLayout();
     }
     for (ConnectionView cv : getConnections()) {
       cv.updateLine();
     }
   }
   if (layoutManager.isZUIVisible()) {
     super.paint(paintContext);
   }
 }
 /**
  * Find the lowest displayed edge of the section. If there is no member found then return the
  * default edge instead.
  *
  * @param sectionFirstPosition Section id, position of first item in the section.
  * @param lastIndex Index to start looking from. Usually the index of the last attached view in
  *     this section.
  * @param defaultEdge Default value.
  * @return Lowest (attached) edge of the section.
  */
 public int getLowestEdge(int sectionFirstPosition, int lastIndex, int defaultEdge) {
   // Look from end to find children that are the lowest.
   for (int i = lastIndex; i >= 0; i--) {
     View child = mLayoutManager.getChildAt(i);
     LayoutManager.LayoutParams params = (LayoutManager.LayoutParams) child.getLayoutParams();
     if (params.getTestedFirstPosition() != sectionFirstPosition) {
       break;
     }
     if (params.isHeader) {
       continue;
     }
     // A more interesting layout would have to do something more here.
     return mLayoutManager.getDecoratedBottom(child);
   }
   return defaultEdge;
 }
 /**
  * Find the position of the first visible item of the section.
  *
  * @param sectionFirstPosition First position of section being queried.
  * @return Position of first visible item.
  */
 public int findLastVisibleItemPosition(int sectionFirstPosition) {
   View item = getLastVisibleView(sectionFirstPosition);
   if (item == null) {
     return LayoutManager.INVALID_POSITON;
   }
   return mLayoutManager.getPosition(item);
 }
 /** @deprecated, use getMinimumSize() */
 public Dimension minimumSize() {
   if (layoutm != null) {
     return layoutm.minimumLayoutSize(this);
   } else {
     return super.minimumSize();
   }
 }
Example #10
0
 private void initPrefs() {
   SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
   SharedPreferences.Editor edit = prefs.edit();
   boolean changes = false;
   if (!prefs.contains(PREFS_VIBRATE_KEY)) {
     changes = true;
     edit.putString(PREFS_VIBRATE_KEY, PREFS_VIBRATE_DEFAULT);
   }
   if (!prefs.contains(PREFS_SERVER_HOST_KEY)) {
     changes = true;
     edit.putString(PREFS_SERVER_HOST_KEY, PREFS_SERVER_HOST_DEFAULT);
   }
   if (!prefs.contains(PREFS_SERVER_PORT_KEY)) {
     changes = true;
     edit.putString(PREFS_SERVER_PORT_KEY, PREFS_SERVER_PORT_DEFAULT);
   }
   if (!prefs.contains(PREFS_LAYOUT_KEY)) {
     changes = true;
     edit.putString(PREFS_LAYOUT_KEY, PREFS_LAYOUT_DEFAULT);
   }
   try {
     layoutManager.getLayoutResource(prefs.getString(PREFS_LAYOUT_KEY, ""));
   } catch (NoSuchElementException e) {
     changes = true;
     edit.putString(PREFS_LAYOUT_KEY, PREFS_LAYOUT_DEFAULT);
   }
   if (changes) {
     edit.commit();
   }
 }
 /** @deprecated, use getPreferredSize(). */
 public Dimension preferredSize() {
   if (layoutm != null) {
     return (layoutm.preferredLayoutSize(this));
   } else {
     return (super.preferredSize());
   }
 }
 /**
  * Find the highest displayed edge of the section. If there is no member found then return the
  * default edge instead.
  *
  * @param sectionFirstPosition Section id, position of first item in the section.
  * @param firstIndex Child index to start looking from.
  * @param defaultEdge Default value.
  * @return Top (attached) edge of the section.
  */
 public int getHighestEdge(int sectionFirstPosition, int firstIndex, int defaultEdge) {
   // Look from start to find children that are the highest.
   for (int i = firstIndex; i < mLayoutManager.getChildCount(); i++) {
     View child = mLayoutManager.getChildAt(i);
     LayoutManager.LayoutParams params = (LayoutManager.LayoutParams) child.getLayoutParams();
     if (params.getTestedFirstPosition() != sectionFirstPosition) {
       break;
     }
     if (params.isHeader) {
       continue;
     }
     // A more interesting layout would have to do something more here.
     return mLayoutManager.getDecoratedTop(child);
   }
   return defaultEdge;
 }
Example #13
0
  /**
   * Rendering method.
   *
   * @param gl
   */
  public final void render(GL2 gl) {
    boolean displayListsAllowedByLayoutManager = false;
    if (layoutManager != null) {
      displayListsAllowedByLayoutManager = layoutManager.isUseDisplayLists();
    }

    if (displayListsAllowedByLayoutManager
        && !hasDisplayListIndex
        && permitsWrappingDisplayLists()) {
      displayListIndex = gl.glGenLists(1);
      hasDisplayListIndex = true;
    }

    prepare();

    if (isDisplayListDirty()
        && permitsWrappingDisplayLists()
        && displayListsAllowedByLayoutManager) {
      gl.glNewList(displayListIndex, GL2.GL_COMPILE);
      renderContent(gl);
      gl.glEndList();
      setDisplayListDirty(false);
    }

    if (permitsWrappingDisplayLists() && displayListsAllowedByLayoutManager) {
      gl.glCallList(displayListIndex);
    } else {
      renderContent(gl);
    }
  }
Example #14
0
  /** @see IFigure#setConstraint(IFigure, Object) */
  public void setConstraint(IFigure child, Object constraint) {
    if (child.getParent() != this)
      throw new IllegalArgumentException("Figure must be a child"); // $NON-NLS-1$

    if (layoutManager != null) layoutManager.setConstraint(child, constraint);
    revalidate();
  }
 /**
  * Find the position of the first completely visible item of this section.
  *
  * @param sectionFirstPosition First position of section being queried.
  * @return Position of first completely visible item.
  */
 public int findFirstCompletelyVisibleItemPosition(int sectionFirstPosition) {
   View item = getFirstCompletelyVisibleView(sectionFirstPosition, false);
   if (item == null) {
     return LayoutManager.INVALID_POSITON;
   }
   return mLayoutManager.getPosition(item);
 }
Example #16
0
  /**
   * Renders the plot onto a canvas. Used by both main thread to draw directly onto the View's
   * canvas as well as by background draw to render onto a Bitmap buffer. At the end of the day this
   * is the main entry for a plot's "heavy lifting".
   *
   * @param canvas
   */
  protected synchronized void renderOnCanvas(Canvas canvas) {
    try {
      // any series interested in synchronizing with plot should
      // implement PlotListener.onBeforeDraw(...) and do a read lock from within its
      // invocation.  This is the entry point into that call:
      notifyListenersBeforeDraw(canvas);
      try {
        // need to completely erase what was on the canvas before redrawing, otherwise
        // some odd aliasing artifacts begin to build up around the edges of aa'd entities
        // over time.
        canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
        if (backgroundPaint != null) {
          drawBackground(canvas, displayDims.marginatedRect);
        }

        layoutManager.draw(canvas);

        if (getBorderPaint() != null) {
          drawBorder(canvas, displayDims.marginatedRect);
        }
      } catch (PlotRenderException e) {
        Log.e(TAG, "Exception while rendering Plot.", e);
      } catch (Exception e) {
        Log.e(TAG, "Exception while rendering Plot.", e);
      }
    } finally {
      isIdle = true;
      // any series interested in synchronizing with plot should
      // implement PlotListener.onAfterDraw(...) and do a read unlock from within that
      // invocation. This is the entry point for that invocation.
      notifyListenersAfterDraw(canvas);
    }
  }
  /**
   * If <code>c</code> is the <code>JOptionPane</code> the receiver is contained in, the preferred
   * size that is returned is the maximum of the preferred size of the <code>LayoutManager</code>
   * for the <code>JOptionPane</code>, and <code>getMinimumOptionPaneSize</code>.
   */
  public Dimension getPreferredSize(JComponent c) {
    if (c == optionPane) {
      Dimension ourMin = getMinimumOptionPaneSize();
      LayoutManager lm = c.getLayout();

      if (lm != null) {
        Dimension lmSize = lm.preferredLayoutSize(c);

        if (ourMin != null)
          return new Dimension(
              Math.max(lmSize.width, ourMin.width), Math.max(lmSize.height, ourMin.height));
        return lmSize;
      }
      return ourMin;
    }
    return null;
  }
Example #18
0
 @Override
 public boolean fullPick(PPickPath pickPath) {
   if (layoutManager.isZUIVisible()) {
     return super.fullPick(pickPath);
   } else {
     return false;
   }
 }
Example #19
0
 @Override
 protected void finalize() throws Throwable {
   try {
     if (layoutManager != null && hasDisplayListIndex)
       layoutManager.addDisplayListToDelete(displayListIndex);
   } finally {
     super.finalize();
   }
 }
Example #20
0
    public void layout(IFigure container) {
      boolean consumed = false;
      for (int i = 0; i < listeners.size(); i++)
        consumed |= ((LayoutListener) listeners.get(i)).layout(container);

      if (realLayout != null && !consumed) realLayout.layout(container);
      for (int i = 0; i < listeners.size(); i++)
        ((LayoutListener) listeners.get(i)).postLayout(container);
    }
Example #21
0
 /**
  * @param x X-Coordinate of the top left corner of element. When using RELATIVE, must be a value
  *     between 0 and 1.
  * @param horizontalPositioning LayoutType to use when orienting this element's X-Coordinate.
  * @param y Y_VALS_ONLY-Coordinate of the top-left corner of element. When using RELATIVE, must be
  *     a value between 0 and 1.
  * @param verticalPositioning LayoutType to use when orienting this element's
  *     Y_VALS_ONLY-Coordinate.
  * @param anchor The point of reference used by this positioning call.
  */
 public void position(
     float x,
     HorizontalPositioning horizontalPositioning,
     float y,
     VerticalPositioning verticalPositioning,
     Anchor anchor) {
   setPositionMetrics(
       new PositionMetrics(x, horizontalPositioning, y, verticalPositioning, anchor));
   layoutManager.addToTop(this);
 }
Example #22
0
 /*
  * (non-Javadoc)
  *
  * @see javax.swing.JFrame#setLayout(java.awt.LayoutManager)
  */
 @Override
 public void setLayout(LayoutManager manager) {
   if (manager.getClass() != RibbonFrameLayout.class) {
     LayoutManager currManager = getLayout();
     if (currManager != null) {
       throw new IllegalArgumentException("Can't set a custom layout manager on JRibbonFrame");
     }
   }
   super.setLayout(manager);
 }
Example #23
0
 /**
  * Removes the given child Figure from this Figure's hierarchy and revalidates this Figure. The
  * child Figure's {@link #removeNotify()} method is also called.
  *
  * @param figure The Figure to remove
  */
 public void remove(IFigure figure) {
   if ((figure.getParent() != this))
     throw new IllegalArgumentException("Figure is not a child"); // $NON-NLS-1$
   if (getFlag(FLAG_REALIZED)) figure.removeNotify();
   if (layoutManager != null) layoutManager.remove(figure);
   // The updates in the UpdateManager *have* to be
   // done asynchronously, else will result in
   // incorrect dirty region corrections.
   figure.erase();
   figure.setParent(null);
   children.remove(figure);
   revalidate();
 }
Example #24
0
 public Test(LayoutManager layout, JComponent[] components) {
   super(layout.getClass().getName());
   JPanel panel = new JPanel(layout);
   // --- code needed to add the components
   // less than using a GridBagLayout
   for (JComponent component : components) {
     panel.add(component);
   }
   // ---
   panel.setBorder(new EtchedBorder());
   setContentPane(new JScrollPane(panel));
   pack();
   show();
 }
 public void windowClosing(WindowEvent event) {
   if (saveLayoutOnClose) {
     Perspective perspective =
         ((JideApplicationPage) window.getPage()).getPerspectiveManager().getCurrentPerspective();
     LayoutManager.savePageLayoutData(manager, window.getPage().getId(), perspective.getId());
     if (log.isDebugEnabled()) {
       log.debug(
           "Saving page layout for page "
               + window.getPage().getId()
               + " and perspective "
               + perspective.getId());
     }
   }
   window.close();
 }
  /**
   * Locate the visible view which has the latest adapter position.
   *
   * @param sectionFirstPosition Section id.
   * @return View.
   */
  public View getLastVisibleView(int sectionFirstPosition) {
    int lookAt = mLayoutManager.getChildCount() - 1;
    View candidate = null;
    while (true) {
      if (lookAt < 0) {
        return candidate;
      }

      View view = mLayoutManager.getChildAt(lookAt);
      LayoutManager.LayoutParams lp = (LayoutManager.LayoutParams) view.getLayoutParams();
      if (sectionFirstPosition == lp.getTestedFirstPosition()) {
        if (!lp.isHeader) {
          return view;
        } else {
          candidate = view;
        }
      } else {
        // Skipped past section.
        return candidate;
      }

      lookAt -= 1;
    }
  }
  public void layout() {
    // DEP - this should be in doLayout() (another nasty compat issue)
    // We keep the 'isLayouting' state regardless of the validation scheme, since
    // it is the way to prevent lots of redraws during recursive layout descents

    // another slow-downer: the async validation of swing forces us to sync on treeLock
    synchronized (treeLock) {

      // swing books need layout even without children
      if ((layoutm != null) && ((flags & IS_LAYOUTING) == 0)) {
        flags |= IS_LAYOUTING;
        layoutm.layoutContainer(this);
        flags &= ~IS_LAYOUTING;
      }
    }
  }
  /**
   * Locate the last view in this section that is completely visible. Will skip headers unless they
   * are the only one visible.
   *
   * @param sectionFirstPosition First position of section being queried.
   * @return Last completely visible item or null.
   */
  public View getLastCompletelyVisibleView(int sectionFirstPosition) {
    final int topEdge = mLayoutManager.getClipToPadding() ? mLayoutManager.getPaddingTop() : 0;
    final int bottomEdge =
        mLayoutManager.getClipToPadding()
            ? mLayoutManager.getHeight() - mLayoutManager.getPaddingBottom()
            : mLayoutManager.getHeight();

    int lookAt = mLayoutManager.getChildCount() - 1;
    View candidate = null;
    while (true) {
      if (lookAt < 0) {
        return candidate;
      }

      final View view = mLayoutManager.getChildAt(lookAt);

      final boolean topInside = mLayoutManager.getDecoratedTop(view) >= topEdge;
      final boolean bottomInside = mLayoutManager.getDecoratedBottom(view) <= bottomEdge;

      LayoutManager.LayoutParams lp = (LayoutManager.LayoutParams) view.getLayoutParams();
      if (sectionFirstPosition == lp.getTestedFirstPosition()) {
        if (topInside && bottomInside) {
          if (!lp.isHeader) {
            return view;
          } else {
            candidate = view;
          }
        }
      } else if (candidate == null) {
        sectionFirstPosition = lp.getTestedFirstPosition();
        continue;
      } else {
        return candidate;
      }

      lookAt -= 1;
    }
  }
  public void remove(int index) {
    synchronized (treeLock) {
      int n = nChildren - 1;

      if (index < 0 && index > n) {
        return;
      }

      Component c = children[index];

      if ((c.flags & IS_ADD_NOTIFIED) != 0) {
        c.removeNotify();
      }

      if (layoutm != null) {
        layoutm.removeLayoutComponent(c);
      }

      // Remove from container
      c.parent = null;
      if (index > -1 && index < n) {
        System.arraycopy(children, index + 1, children, index, n - index);
      }
      children[n] = null;
      nChildren--;

      if ((cntrListener != null) || (eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0) {
        AWTEvent.sendEvent(ContainerEvt.getEvent(this, ContainerEvent.COMPONENT_REMOVED, c), false);
      }

      if ((flags & IS_VALID) != 0) invalidate();

      c.flags &= ~IS_PARENT_SHOWING;
      c.propagateParentShowing(false);

      // Like in addImpl, this wouldn't be required in case we are subsequently
      // validated, again. However, native widgets cause a repaint regardless
      // of this validation
      if ((c.flags & IS_NATIVE_LIKE) != 0) repaint(c.x, c.y, c.width, c.height);
    }
  }
 public Map<JRElement, Rectangle> layout(JRElement[] elements, Dimension c) {
   Map<JRElement, Rectangle> map = new HashMap<JRElement, Rectangle>();
   int x = 0;
   int y = 0;
   int w = c.width;
   int h = (int) Math.floor((float) c.height / elements.length);
   int rest = c.height - h * elements.length;
   for (JRElement el : elements) {
     JRDesignElement del = (JRDesignElement) el;
     map.put(el, new Rectangle(el.getX(), el.getY(), el.getWidth(), el.getHeight()));
     del.setX(x);
     del.setY(y);
     del.setWidth(w);
     del.setHeight(h + rest);
     // if last grab free pixels
     y += h + rest;
     if (rest > 0) rest = 0;
     LayoutManager.layout(map, el);
   }
   return map;
 }