Search in sources :

Example 31 with Location

use of com.codename1.location.Location in project CodenameOne by codenameone.

the class CSSEngine method createBorder.

/**
 *  Returns a border for a specific side of the component
 *
 * @param styleAttributes The style attributes element containing the border directives
 * @param ui The component we want to set the border on
 * @param location One of Component.TOP/BOTTOM/LEFT/RIGHT
 * @return
 */
Border createBorder(CSSElement styleAttributes, Component ui, int location, int styles, int type) {
    int borderStyle = styleAttributes.getAttrVal(BORDER_OUTLINE_PROPERTIES[type][STYLE] + location);
    if ((borderStyle == -1) || (borderStyle == BORDER_STYLE_NONE)) {
        return null;
    }
    int borderColor = styleAttributes.getAttrVal(BORDER_OUTLINE_PROPERTIES[type][COLOR] + location);
    int borderWidth = styleAttributes.getAttrLengthVal(BORDER_OUTLINE_PROPERTIES[type][WIDTH] + location, ui, 0);
    if (borderWidth == -1) {
        // Default value
        borderWidth = CSSElement.BORDER_DEFAULT_WIDTH;
    }
    if (type == OUTLINE) {
        // all
        location = -1;
    }
    if ((styles & STYLE_SELECTED) != 0) {
        incPadding(ui.getSelectedStyle(), location, borderWidth);
    }
    if ((styles & STYLE_UNSELECTED) != 0) {
        incPadding(ui.getUnselectedStyle(), location, borderWidth);
    }
    if ((styles & STYLE_PRESSED) != 0) {
        incPadding(((HTMLLink) ui).getPressedStyle(), location, borderWidth);
    }
    Border border = null;
    if ((borderColor == -1) && (borderStyle >= BORDER_STYLE_GROOVE)) {
        borderColor = DEFAULT_3D_BORDER_COLOR;
    }
    switch(borderStyle) {
        case BORDER_STYLE_SOLID:
            if (borderColor == -1) {
                border = Border.createLineBorder(borderWidth);
            } else {
                border = Border.createLineBorder(borderWidth, borderColor);
            }
            break;
        case BORDER_STYLE_DOUBLE:
            if (borderColor == -1) {
                border = Border.createDoubleBorder(borderWidth);
            } else {
                border = Border.createDoubleBorder(borderWidth, borderColor);
            }
            break;
        case BORDER_STYLE_GROOVE:
            border = Border.createGrooveBorder(borderWidth, borderColor);
            break;
        case BORDER_STYLE_RIDGE:
            border = Border.createRidgeBorder(borderWidth, borderColor);
            break;
        case BORDER_STYLE_INSET:
            border = Border.createInsetBorder(borderWidth, borderColor);
            break;
        case BORDER_STYLE_OUTSET:
            border = Border.createOutsetBorder(borderWidth, borderColor);
            break;
        case BORDER_STYLE_DOTTED:
            if (borderColor == -1) {
                border = Border.createDottedBorder(borderWidth);
            } else {
                border = Border.createDottedBorder(borderWidth, borderColor);
            }
            break;
        case BORDER_STYLE_DASHED:
            if (borderColor == -1) {
                border = Border.createDashedBorder(borderWidth);
            } else {
                border = Border.createDashedBorder(borderWidth, borderColor);
            }
            break;
    }
    return border;
}
Also used : Border(com.codename1.ui.plaf.Border)

Example 32 with Location

use of com.codename1.location.Location in project CodenameOne by codenameone.

the class ResetableTextWatcher method reLayoutEdit.

public static void reLayoutEdit(boolean force) {
    if (mIsEditing && !isActiveTextEditorHidden() && sInstance != null && sInstance.mEditText != null) {
        final TextArea txt = sInstance.mEditText.mTextArea;
        if (!force && lastTextAreaX == txt.getAbsoluteX() + txt.getScrollX() && lastTextAreaY == txt.getAbsoluteY() + txt.getScrollY() && lastTextAreaWidth == txt.getWidth() && lastTextAreaHeight == txt.getHeight()) {
            return;
        }
        Display.getInstance().callSerially(new Runnable() {

            public void run() {
                if (mIsEditing && !isActiveTextEditorHidden() && sInstance != null && sInstance.mEditText != null) {
                    if (txt != null) {
                        if (sInstance.mEditText.mTextArea != txt) {
                            // has changed in between, skip or would change location back to old field
                            return;
                        }
                        final int txty = lastTextAreaY = txt.getAbsoluteY() + txt.getScrollY();
                        final int txtx = lastTextAreaX = txt.getAbsoluteX() + txt.getScrollX();
                        final int w = lastTextAreaWidth = txt.getWidth();
                        final int h = lastTextAreaHeight = txt.getHeight();
                        sInstance.impl.getActivity().runOnUiThread(new Runnable() {

                            public void run() {
                                if (mIsEditing && !isActiveTextEditorHidden() && sInstance != null && sInstance.mEditText != null) {
                                    if (sInstance.mEditText.mTextArea != txt) {
                                        // has changed in between, skip or would change location back to old field
                                        return;
                                    }
                                    sInstance.mEditLayoutParams.setMargins(txtx, txty, 0, 0);
                                    sInstance.mEditLayoutParams.width = w;
                                    sInstance.mEditLayoutParams.height = h;
                                    sInstance.mEditText.requestLayout();
                                    sInstance.invalidate();
                                    if (sInstance.getVisibility() != VISIBLE) {
                                        sInstance.setVisibility(VISIBLE);
                                    }
                                    sInstance.bringToFront();
                                }
                            }
                        });
                    }
                }
            }
        });
    }
}
Also used : TextArea(com.codename1.ui.TextArea)

Example 33 with Location

use of com.codename1.location.Location in project CodenameOne by codenameone.

the class Component method getAbsoluteX.

/**
 * Returns the absolute X location based on the component hierarchy, this method
 * calculates a location on the screen for the component rather than a relative
 * location as returned by getX()
 *
 * @return the absolute x location of the component
 * @see #getX
 */
public int getAbsoluteX() {
    int x = getX() - getScrollX();
    Container parent = getParent();
    if (parent != null) {
        x += parent.getAbsoluteX();
    }
    return x;
}
Also used : Point(com.codename1.ui.geom.Point)

Example 34 with Location

use of com.codename1.location.Location in project CodenameOne by codenameone.

the class Component method getAbsoluteY.

/**
 * Returns the absolute Y location based on the component hierarchy, this method
 * calculates a location on the screen for the component rather than a relative
 * location as returned by getX()
 *
 * @return the absolute y location of the component
 * @see #getY
 */
public int getAbsoluteY() {
    int y = getY() - getScrollY();
    Container parent = getParent();
    if (parent != null) {
        y += parent.getAbsoluteY();
    }
    return y;
}
Also used : Point(com.codename1.ui.geom.Point)

Example 35 with Location

use of com.codename1.location.Location in project CodenameOne by codenameone.

the class Table method paintGlass.

/**
 * {@inheritDoc}
 */
protected void paintGlass(Graphics g) {
    if ((drawBorder) && (innerBorder != INNER_BORDERS_NONE)) {
        int xPos = getAbsoluteX();
        int yPos = getAbsoluteY();
        g.translate(xPos, yPos);
        int rows = model.getRowCount();
        int cols = model.getColumnCount();
        if (includeHeader) {
            rows++;
        }
        g.setColor(getStyle().getFgColor());
        TableLayout t = (TableLayout) getLayout();
        int actualWidth = Math.max(getWidth(), getScrollDimension().getWidth());
        int actualHeight = Math.max(getHeight(), getScrollDimension().getHeight());
        if (// inner borders cols/rows are supported only in collapsed mode
        (collapseBorder) || (innerBorder != INNER_BORDERS_ALL) || (t.hasHorizontalSpanning()) || (t.hasVerticalSpanning())) {
            // TODO - We currently don't support separate borders for tables with spanned cells
            if ((innerBorder == INNER_BORDERS_ALL) || (innerBorder == INNER_BORDERS_ROWS)) {
                if (t.hasVerticalSpanning()) {
                    // the components other than the ones that are at the last column.
                    for (int cellRow = 0; cellRow < rows - 1; cellRow++) {
                        for (int cellColumn = 0; cellColumn < cols; cellColumn++) {
                            // if this isn't the last row
                            if (cellRow + t.getCellVerticalSpan(cellRow, cellColumn) - 1 != rows - 1) {
                                // if this is a spanned through cell we don't want to draw a line here
                                if (t.isCellSpannedThroughHorizontally(cellRow, cellColumn)) {
                                    continue;
                                }
                                int x = t.getColumnPosition(cellColumn);
                                int y = t.getRowPosition(cellRow);
                                int rowHeight = t.getRowPosition(cellRow + t.getCellVerticalSpan(cellRow, cellColumn)) - y;
                                int columnWidth;
                                if (cellColumn < getModel().getColumnCount() - 1) {
                                    columnWidth = t.getColumnPosition(cellColumn + 1) - x;
                                } else {
                                    columnWidth = getWidth() - y;
                                }
                                if ((innerBorder != INNER_BORDERS_ROWS) || (shouldDrawInnerBorderAfterRow(cellRow))) {
                                    g.drawLine(x, y + rowHeight, x + columnWidth, y + rowHeight);
                                }
                            }
                        }
                    }
                } else {
                    // this is much faster since we don't need to check spanning
                    for (int row = 1; row < rows; row++) {
                        int y = t.getRowPosition(row);
                        if ((innerBorder != INNER_BORDERS_ROWS) || (shouldDrawInnerBorderAfterRow(row - 1))) {
                            g.drawLine(0, y, actualWidth, y);
                        }
                    // g.drawLine(0+2, y+2, actualWidth-2, y+2);
                    }
                }
            }
            if ((innerBorder == INNER_BORDERS_ALL) || (innerBorder == INNER_BORDERS_COLS)) {
                if (t.hasHorizontalSpanning()) {
                    // the components other than the ones that are at the last column.
                    for (int cellRow = 0; cellRow < rows; cellRow++) {
                        for (int cellColumn = 0; cellColumn < cols - 1; cellColumn++) {
                            // if this isn't the last column
                            if (cellColumn + t.getCellHorizontalSpan(cellRow, cellColumn) - 1 != cols - 1) {
                                // if this is a spanned through cell we don't want to draw a line here
                                if (t.isCellSpannedThroughVertically(cellRow, cellColumn)) {
                                    continue;
                                }
                                int x = t.getColumnPosition(cellColumn);
                                int y = t.getRowPosition(cellRow);
                                int rowHeight;
                                int columnWidth = t.getColumnPosition(cellColumn + t.getCellHorizontalSpan(cellRow, cellColumn)) - x;
                                if (cellRow < getModel().getRowCount() - 1) {
                                    rowHeight = t.getRowPosition(cellRow + 1) - y;
                                } else {
                                    rowHeight = getHeight() - y;
                                }
                                g.drawLine(x + columnWidth, y, x + columnWidth, y + rowHeight);
                            }
                            if (t.getCellHorizontalSpan(cellRow, cellColumn) > 1) {
                                cellColumn += t.getCellHorizontalSpan(cellRow, cellColumn) - 1;
                            }
                        }
                    }
                } else {
                    for (int col = 1; col < cols; col++) {
                        int x = t.getColumnPosition(col);
                        g.drawLine(x, 0, x, actualHeight);
                    // g.drawLine(x+2, 0+2, x+2, actualHeight-2);
                    }
                }
            }
        } else {
            // if ((!t.hasHorizontalSpanning()) && (!t.hasVerticalSpanning())) {
            for (int row = 0; row < rows; row++) {
                int y = t.getRowPosition(row);
                int h;
                if (row + 1 < rows) {
                    h = t.getRowPosition(row + 1) - y;
                } else {
                    h = getY() + actualHeight - y - 2;
                }
                for (int col = 0; col < cols; col++) {
                    int x = t.getColumnPosition(col);
                    int w;
                    if (col + 1 < cols) {
                        w = t.getColumnPosition(col + 1) - x;
                    } else {
                        w = getX() + actualWidth - x - 2;
                    }
                    Component comp = t.getComponentAt(row, col);
                    if ((comp.isVisible()) && ((drawEmptyCellsBorder) || ((comp.getWidth() - comp.getStyle().getPaddingRightNoRTL() - comp.getStyle().getPaddingLeftNoRTL() > 0) && (comp.getHeight() - comp.getStyle().getPaddingTop() - comp.getStyle().getPaddingBottom() > 0)))) {
                        int rightMargin = comp.getStyle().getMarginRightNoRTL();
                        int bottomMargin = comp.getStyle().getMarginBottom();
                        if (col == 0) {
                            // Since the first cell includes margins from both sides (left/right) so the next cell location is farther away - but we don't want to paint the border up to it
                            rightMargin *= 2;
                        }
                        if (row == 0) {
                            bottomMargin *= 2;
                        }
                        g.drawRect(x + comp.getStyle().getMarginLeftNoRTL(), y + comp.getStyle().getMarginTop(), w - 2 - rightMargin, h - 2 - bottomMargin);
                    }
                }
            }
        }
        g.translate(-xPos, -yPos);
    }
}
Also used : Component(com.codename1.ui.Component)

Aggregations

ArrayList (java.util.ArrayList)18 Location (location.Location)17 Location (com.codename1.location.Location)5 IOException (java.io.IOException)5 Point (com.codename1.ui.geom.Point)4 Component (com.codename1.ui.Component)3 ActionEvent (com.codename1.ui.events.ActionEvent)3 ConnectionRequest (com.codename1.io.ConnectionRequest)2 BrowserComponent (com.codename1.ui.BrowserComponent)2 ActionListener (com.codename1.ui.events.ActionListener)2 QualifiedCoordinates (javax.microedition.location.QualifiedCoordinates)2 Paint (com.codename1.charts.compat.Paint)1 Point (com.codename1.charts.models.Point)1 XYSeries (com.codename1.charts.models.XYSeries)1 Orientation (com.codename1.charts.renderers.XYMultipleSeriesRenderer.Orientation)1 XYSeriesRenderer (com.codename1.charts.renderers.XYSeriesRenderer)1 BindTarget (com.codename1.cloud.BindTarget)1 CodenameOneImplementation (com.codename1.impl.CodenameOneImplementation)1 BufferedOutputStream (com.codename1.io.BufferedOutputStream)1 FileSystemStorage (com.codename1.io.FileSystemStorage)1