Examples of PositionBean


Examples of com.alkacon.geranium.client.util.PositionBean

     */
    public PositionBean getAreaPosition(boolean relative) {

        // returning the relative position
        if (relative) {
            return new PositionBean(m_currentSelection);
        }

        // returning the absolute position
        PositionBean abs = new PositionBean(m_currentSelection);
        abs.setTop(m_currentSelection.getTop() + getElement().getAbsoluteTop());
        abs.setLeft(m_currentSelection.getLeft() + getElement().getAbsoluteLeft());
        return abs;
    }
View Full Code Here

Examples of com.alkacon.geranium.client.util.PositionBean

        if (pos == null) {
            return;
        }
        m_state = State.SELECTED;
        showSelect(true);
        m_currentSelection = new PositionBean();
        m_firstX = pos.getLeft();
        m_firstY = pos.getTop();
        if (!relative) {
            m_firstX -= getElement().getAbsoluteLeft();
            m_firstY -= getElement().getAbsoluteTop();
View Full Code Here

Examples of com.alkacon.geranium.client.util.PositionBean

            case EMPTY:
                DOM.setCapture(getElement());
                m_state = State.SELECTING;
                m_firstX = event.getRelativeX(getElement());
                m_firstY = event.getRelativeY(getElement());
                m_currentSelection = new PositionBean();
                setSelectPosition(m_firstX, m_firstY, 0, 0);
                showSelect(true);

                break;
            case SELECTED:
View Full Code Here

Examples of com.alkacon.geranium.client.util.PositionBean

     * Positions the given pop-up relative to the reference element.<p>
     */
    void positionPopup() {

        if (m_referenceElement != null) {
            PositionBean referencePosition = PositionBean.getInnerDimensions(m_referenceElement);
            int currentTop = m_popup.getAbsoluteTop();
            int windowHeight = Window.getClientHeight();
            int scrollTop = Window.getScrollTop();
            int contentHeight = m_popup.getOffsetHeight();
            int top = referencePosition.getTop();
            if (((windowHeight + scrollTop) < (top + referencePosition.getHeight() + contentHeight + 20))
                && ((contentHeight + 40) < top)) {
                top = top - contentHeight - 5;
                if ((currentTop < top) && ((top - currentTop) < 200)) {
                    // keep the current position
                    top = currentTop;
                }
            } else {
                top = top + referencePosition.getHeight() + 5;
                if ((currentTop > top) && ((currentTop - top) < 200)) {
                    // keep the current position
                    top = currentTop;
                }
            }
View Full Code Here

Examples of com.alkacon.geranium.client.util.PositionBean

     * Resets the in line editing toolbar position.<p>
     */
    private void resetToolbarContainerPosition() {

        if (m_toolbarContainer != null) {
            PositionBean position = PositionBean.generatePositionInfo(m_contentElement);
            m_toolbarContainer.getStyle().setTop(position.getTop() - 5, Unit.PX);
            m_toolbarContainer.getStyle().setLeft(position.getLeft(), Unit.PX);
        }
    }
View Full Code Here

Examples of com.alkacon.geranium.client.util.PositionBean

     * Resets the in line editing toolbar position.<p>
     */
    private void resetToolbarContainerPosition() {

        if (m_toolbarContainer != null) {
            PositionBean position = PositionBean.generatePositionInfo(m_contentElement);
            m_toolbarContainer.getStyle().setTop(position.getTop() - 5, Unit.PX);
            m_toolbarContainer.getStyle().setLeft(position.getLeft(), Unit.PX);
        }
    }
View Full Code Here

Examples of com.alkacon.geranium.client.util.PositionBean

            minLeft = spaceAssurance;
        }
        // get the max right position
        int maxRight = minLeft + space;
        // get the middle button position
        PositionBean buttonPosition = PositionBean.generatePositionInfo(button.getElement());
        int buttonMiddle = (buttonPosition.getLeft() - Window.getScrollLeft()) + (buttonPosition.getWidth() / 2);
        // get the content width
        int contentWidth = popup.getOffsetWidth();

        // the optimum left position is in the middle of the button minus the half content width
        // assume that the optimum fits into the space
        int contentLeft = buttonMiddle - (contentWidth / 2);

        if (minLeft > contentLeft) {
            // if the optimum left position of the popup is outside the min left position:
            // move the popup to the right (take the min left position as left)
            contentLeft = minLeft;
        } else if ((contentLeft + contentWidth) > maxRight) {
            // if the left position plus the content width is outside the max right position:
            // move the popup to the left (take the max right position minus the content width)
            contentLeft = maxRight - contentWidth;
        }

        // limit the right position if the popup is right outside the window
        if ((contentLeft + contentWidth + spaceAssurance) > windowWidth) {
            contentLeft = windowWidth - contentWidth - spaceAssurance;
        }

        // limit the left position if the popup is left outside the window
        if (contentLeft < spaceAssurance) {
            contentLeft = spaceAssurance;
        }

        int arrowSpace = 10;
        int arrowWidth = I_LayoutBundle.INSTANCE.gwtImages().menuArrowTopImage().getWidth();
        int arrowHeight = I_LayoutBundle.INSTANCE.gwtImages().menuArrowTopImage().getHeight();

        // the optimum position for the arrow is in the middle of the button
        int arrowLeft = buttonMiddle - contentLeft - (arrowWidth / 2);
        if ((arrowLeft + arrowWidth + arrowSpace) > contentWidth) {
            // limit the arrow position if the maximum is reached (content width 'minus x')
            arrowLeft = contentWidth - arrowWidth - arrowSpace;
        } else if ((arrowLeft - arrowSpace) < 0) {
            // limit the arrow position if the minimum is reached ('plus x')
            arrowLeft = arrowWidth + arrowSpace;
        }

        int arrowTop = -(arrowHeight - 2);
        String arrowClass = I_LayoutBundle.INSTANCE.dialogCss().menuArrowTop();

        int contentTop = (((buttonPosition.getTop() + buttonPosition.getHeight()) - Window.getScrollTop()) + arrowHeight) - 2;
        if (!isToolbarMode) {
            contentTop = (buttonPosition.getTop() + buttonPosition.getHeight() + arrowHeight) - 2;
            int contentHeight = popup.getOffsetHeight();
            int windowHeight = Window.getClientHeight();

            if (((contentHeight + spaceAssurance) < windowHeight)
                && ((buttonPosition.getTop() - Window.getScrollTop()) > contentHeight)
                && (((contentHeight + spaceAssurance + contentTop) - Window.getScrollTop()) > windowHeight)) {
                // content fits into the window height,
                // there is enough space above the button
                // and there is to little space below the button
                // so show above
                contentTop = ((buttonPosition.getTop() - arrowHeight) + 2) - contentHeight;
                arrowTop = contentHeight - 1;
                arrowClass = I_LayoutBundle.INSTANCE.dialogCss().menuArrowBottom();
            }
        } else {
            contentLeft = contentLeft - Window.getScrollLeft();
View Full Code Here

Examples of com.quantcomponents.algo.PositionBean

 
  @Override
  public synchronized void onTrade(ITrade trade) {
    IContract contract = trade.getOrder().getContract();
    IContract currency = ContractBean.cash(contract.getCurrency());
    PositionBean contractPosition = positions.get(contract);
    if (contractPosition == null) {
      contractPosition = new PositionBean();
      positions.put(contract, contractPosition);
    }
    PositionBean cashPosition = positions.get(currency);
    if (cashPosition == null) {
      cashPosition = new PositionBean();
      cashPosition.setAveragePrice(1.0);
      cashPosition.setMarketPrice(1.0);
      positions.put(currency, cashPosition);
    }
    Integer contractMultiplier = contract.getMultiplier();
    if (contractMultiplier == null || contractMultiplier == 0) {
      contractMultiplier = 1;
    }
    contractPosition.setMarketPrice(trade.getExecutionPrice());
    contractPosition.setTimestamp(trade.getExecutionTime());
    cashPosition.setTimestamp(trade.getExecutionTime());
    double residueSignedPositionAmount = contractPosition.getSignedAmount();
    int residueTradeAmount = trade.getAmount();
    // reducing position
    if (residueSignedPositionAmount != 0) {
      if (residueSignedPositionAmount > 0 && trade.getOrder().getSide() == OrderSide.SELL) { // reducing long position
        double positionReduction = Math.min(residueSignedPositionAmount, residueTradeAmount);
        contractPosition.setRealizedPnl(contractPosition.getRealizedPnl() + (trade.getAveragePrice() - contractPosition.getAveragePrice()) * contractMultiplier * positionReduction);
        residueSignedPositionAmount -= positionReduction;
        residueTradeAmount -= positionReduction;
      } else if (residueSignedPositionAmount < 0 && trade.getOrder().getSide() == OrderSide.BUY) { // reducing short position
        double positionReduction = Math.min(-residueSignedPositionAmount, residueTradeAmount);
        contractPosition.setRealizedPnl(contractPosition.getRealizedPnl() + (contractPosition.getAveragePrice() - trade.getAveragePrice()) * contractMultiplier * positionReduction);
        residueSignedPositionAmount += positionReduction;
        residueTradeAmount -= positionReduction;
      }
    }
    double newSignedPositionAmount = residueSignedPositionAmount;
    if (newSignedPositionAmount == 0) {
      contractPosition.setAveragePrice(0.0);
    }
    // building position
    if (residueTradeAmount > 0) {
      if (trade.getOrder().getSide() == OrderSide.BUY) { // building long position from 0 or more
        newSignedPositionAmount = residueSignedPositionAmount + residueTradeAmount;
        contractPosition.setAveragePrice((contractPosition.getAveragePrice() * residueSignedPositionAmount + trade.getAveragePrice() * residueTradeAmount) / newSignedPositionAmount);
      } else { // building long position from 0 or less
        newSignedPositionAmount = residueSignedPositionAmount - residueTradeAmount;
        contractPosition.setAveragePrice((contractPosition.getAveragePrice() * residueSignedPositionAmount - trade.getAveragePrice() * residueTradeAmount) / newSignedPositionAmount);
      }
    }
    contractPosition.setSignedAmount(newSignedPositionAmount);
    double cashChange = trade.getAveragePrice() * trade.getAmount() * contractMultiplier * (trade.getOrder().getSide() == OrderSide.BUY ? -1 : 1);;
    cashPosition.setSignedAmount(cashPosition.getSignedAmount() + cashChange);
    recalculateMarketValueAndUPnl();
  }
View Full Code Here

Examples of com.quantcomponents.algo.PositionBean

  public void onPriceUpdate(IContract contract, ISeriesPoint<Date, Double> price) {
    updateMarketPrice(contract, price.getIndex(), price.getValue());
  }
 
  private void updateMarketPrice(IContract contract, Date timestamp, double price) {
    PositionBean position = positions.get(contract);
    if (position != null) {
      if (price != position.getMarketPrice()) {
        position.setMarketPrice(price);
        position.setTimestamp(timestamp);
        recalculateMarketValueAndUPnl();
      }
    }
  }
View Full Code Here

Examples of com.quantcomponents.algo.PositionBean

    for (Map.Entry<IContract, PositionBean> entry : positions.entrySet()) {
      Integer contractMultiplier = entry.getKey().getMultiplier();
      if (contractMultiplier == null || contractMultiplier == 0) {
        contractMultiplier = 1;
      }
      PositionBean position = entry.getValue();
      position.setMarketValue(position.getMarketPrice() * position.getSignedAmount() * contractMultiplier);
      position.setUnrealizedPnl(position.getMarketValue() - position.getAveragePrice() * position.getSignedAmount() * contractMultiplier);
    }
  }
 
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.