本文整理汇总了Java中com.codename1.ui.Component.RIGHT属性的典型用法代码示例。如果您正苦于以下问题:Java Component.RIGHT属性的具体用法?Java Component.RIGHT怎么用?Java Component.RIGHT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.codename1.ui.Component
的用法示例。
在下文中一共展示了Component.RIGHT属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getOppositeInset
/**
* Gets the opposite inset of this inset within its parent constraint. E.g. if this is the
* left inset, it will get the associated right inset.
* @return The opposite inset.
*/
public Inset getOppositeInset() {
LayeredLayoutConstraint cnst = LayeredLayoutConstraint.this;
if (cnst != null) {
int oppSide = 0;
switch (side) {
case Component.TOP:
oppSide = Component.BOTTOM;
break;
case Component.BOTTOM:
oppSide = Component.TOP;
break;
case Component.LEFT:
oppSide = Component.RIGHT;
break;
default:
oppSide = Component.LEFT;
}
return cnst.insets[oppSide];
}
return null;
}
示例2: getHorizAlign
/**
* Converts a textual horizontal alignment description to a Codename One alignment constant
*
* @param alignment The string describing the alignment
* @param defaultAlign The default alignment if the string cannot be converted
* @param allowJustify true to allow justify alignment, false to return center if justify is mentioned
* @return Component.LEFT, RIGHT or CENTER or the defaultAlign in case no match was found.
*/
private int getHorizAlign(String alignment,int defaultAlign,boolean allowJustify) {
if (alignment!=null) {
if (alignment.equals("left")) {
return Component.LEFT;
} else if (alignment.equals("right")) {
return Component.RIGHT;
} else if ((alignment.equals("center")) || (alignment.equals("middle"))) {
return Component.CENTER;
} else if (alignment.equals("justify")) {
return ((allowJustify) && (FIXED_WIDTH))?JUSTIFY:Component.CENTER;
}
}
return defaultAlign; //unknown alignment
}
示例3: reverseAlignForBidi
/**
* Reverses alignment in the case of bidi
*/
protected final int reverseAlignForBidi(boolean rtl, int align) {
if (rtl) {
switch (align) {
case Component.RIGHT:
return Component.LEFT;
case Component.LEFT:
return Component.RIGHT;
}
}
return align;
}
示例4: drawText
public void drawText(String string, float x, float y, Paint paint) {
applyPaint(paint, true);
int offX = 0;
int offY = 0;
if ( paint.getTextAlign() == Component.CENTER){
offX = -g.getFont().stringWidth(string)/2;
} else if ( paint.getTextAlign() == Component.RIGHT ){
offX = -g.getFont().stringWidth(string);
}
int h = g.getFont().getAscent();
g.drawString(string, (int)x+offX, (int)y-h+offY);
}
示例5: createCompoundBorder
/**
* Creates a border that is comprised of multiple border types so one border type can be used on top
* while another one can be used at the bottom. Notice that this doesn't work well with all border types (e.g. image borders)
* @param top the top border
* @param bottom the bottom border
* @param left the left border
* @param right the right border
* @return a compound border
*/
public static Border createCompoundBorder(Border top, Border bottom, Border left, Border right) {
if ((top != null && !top.isRectangleType()) ||
(bottom != null && !bottom.isRectangleType()) ||
(left != null && !left.isRectangleType()) ||
(right != null && !right.isRectangleType())) {
throw new IllegalArgumentException("Compound Border can be created "
+ "only from Rectangle types Borders");
}
if ((isSame(top, bottom)) && (isSame(top, left)) && (isSame(top, right))) {
return top; // Borders are all the same, returning one of them instead of creating a compound border which is more resource consuming
}
Border b = new Border();
b.type = TYPE_COMPOUND;
b.compoundBorders = new Border[4];
b.compoundBorders[Component.TOP] = top;
b.compoundBorders[Component.BOTTOM] = bottom;
b.compoundBorders[Component.LEFT] = left;
b.compoundBorders[Component.RIGHT] = right;
// Calculates the thickness of the entire border as the maximum of all 4 sides
b.thickness=0;
for(int i=Component.TOP;i<=Component.RIGHT;i++) {
if (b.compoundBorders[i]!=null) {
int sideThickness = (int)b.compoundBorders[i].thickness;
if (sideThickness>b.thickness) {
b.thickness=sideThickness;
}
}
}
return b;
}
示例6: incPadding
private void incPadding(Style style,int location,int padding) {
if (location==-1) {
int pad[] = new int[4];
for(int i=Component.TOP;i<=Component.RIGHT;i++) {
pad[i]=style.getPadding(i)+padding;
}
style.setPadding(pad[Component.TOP], pad[Component.BOTTOM], pad[Component.LEFT], pad[Component.RIGHT]);
} else {
style.setPadding(location, style.getPadding(location)+padding);
}
}
示例7: equals
/**
* {{@inheritDoc}}
*/
public boolean equals(Object obj) {
if (obj != null && obj.getClass() == getClass()) {
Border b = (Border)obj;
if ((b.type==TYPE_COMPOUND) && (type==TYPE_COMPOUND)) {
for(int i=Component.TOP;i<=Component.RIGHT;i++) {
if (!isSame(compoundBorders[i], b.compoundBorders[i])) {
return false;
}
}
return true;
}
boolean v = ((themeColors==b.themeColors) &&
(type==b.type) &&
(thickness==b.thickness) &&
(colorA==b.colorA) &&
(colorB==b.colorB) &&
(colorC==b.colorC) &&
(colorD==b.colorD) &&
(arcWidth==b.arcWidth) &&
(arcHeight==b.arcHeight) &&
(outline==b.outline) &&
(isSame(borderTitle, b.borderTitle)) &&
(isSame(outerBorder, b.outerBorder))
);
if(v && (type == TYPE_IMAGE || type == TYPE_IMAGE_HORIZONTAL || type == TYPE_IMAGE_VERTICAL || type == TYPE_IMAGE_SCALED)) {
int ilen = images.length;
for(int iter = 0 ; iter < ilen ; iter++) {
if(images[iter] != b.images[iter]) {
return false;
}
}
}
return v;
}
return false;
}
示例8: getAlignmentString
private static String getAlignmentString(Integer alignment) {
if (alignment == null) {
return null;
}
switch (alignment) {
case Component.CENTER: return "center";
case Component.LEFT: return "left";
case Component.RIGHT: return "right";
}
return null;
}
示例9: getSpliceInsets
/**
* For a splicedImage border, this gets the spliced insets as a 4-element array of double values.
* @param out An out parameter. 4-element array of insets. Indices {@link Component#TOP}, {@link Component#BOTTOM}, {@link Component#LEFT}, and {@link Component#RIGHT}.
* @return 4-element array of insets. Indices {@link Component#TOP}, {@link Component#BOTTOM}, {@link Component#LEFT}, and {@link Component#RIGHT}.
*/
public double[] getSpliceInsets(double[] out) {
String[] parts = Util.split(BorderInfo.this.getSpliceInsets(), " ");
out[Component.TOP] = Double.parseDouble(parts[0]);
out[Component.RIGHT] = Double.parseDouble(parts[1]);
out[Component.BOTTOM] = Double.parseDouble(parts[2]);
out[Component.LEFT] = Double.parseDouble(parts[3]);
return out;
}
示例10: reverseAlignForBidi
/**
* Reverses alignment in the case of bidi
*/
private int reverseAlignForBidi(Component c, int align) {
if(c.isRTL()) {
switch(align) {
case Component.RIGHT:
return Component.LEFT;
case Component.LEFT:
return Component.RIGHT;
}
}
return align;
}
示例11: calcBaseValue
/**
* Calculates the "base" value off of which the inset's value should be calculated.
*
* @param top The top "y" coordinate within the parent container from which insets are measured.
* @param left The left "x" coordinate within the parent container from which insets are measured.
* @param bottom The bottom "y" coordinate within the parent container from which insets are measured.
* @param right The right "x" coordinate within the parent container from which insets are measured.
* @return
*/
private int calcBaseValue(int top, int left, int bottom, int right) {//, int paddingTop, int paddingLeft, int paddingBottom, int paddingRight) {
int h = bottom - top;
int w = right - left;
int baseValue = 0;
if (referenceComponent != null) {
switch (side) {
case Component.TOP:
baseValue = getOuterY(referenceComponent) + (int)(getOuterHeight(referenceComponent) * referencePosition) - top;
break;
case Component.BOTTOM:
baseValue = (bottom - getOuterHeight(referenceComponent) - getOuterY(referenceComponent)) + (int)(getOuterHeight(referenceComponent) * referencePosition);
break;
case Component.LEFT:
baseValue = getOuterX(referenceComponent) + (int)(getOuterWidth(referenceComponent) * referencePosition) - left;
break;
default:
baseValue = (right - getOuterWidth(referenceComponent) - getOuterX(referenceComponent)) + (int)(getOuterWidth(referenceComponent)* referencePosition);
break;
}
calculatedBaseValue = baseValue;
return baseValue;
}
if (referencePosition != 0) {
switch (side) {
case Component.TOP:
baseValue = (int) ((float) h * referencePosition);
break;
case Component.BOTTOM:
baseValue = (int) ((float) h * referencePosition);
break;
case Component.LEFT:
baseValue = (int) ((float) w * referencePosition);
break;
case Component.RIGHT:
baseValue = (int) ((float) w * referencePosition);
break;
default:
throw new RuntimeException("Illegal side for inset: " + side);
}
}
calculatedBaseValue = baseValue;
return baseValue;
}
示例12: moveComponents
private void moveComponents(Container target, int x, int y, int width, int height, int rowStart, int rowEnd, int baseline ) {
switch (orientation) {
case Component.CENTER:
// this will remove half of last gap
if (target.isRTL()) {
x -= (width) / 2;
} else {
x += (width) / 2;
}
break;
case Component.RIGHT:
x+=width; // this will remove the last gap
break;
}
Style parentStyle = target.getStyle();
int parentPadding = parentStyle.getHorizontalPadding();
for (int i = rowStart ; i < rowEnd ; i++) {
Component m = target.getComponentAt(i);
Style style = m.getStyle();
int marginX = style.getMarginLeftNoRTL() + style.getMarginRightNoRTL();
if(m.getWidth() + marginX < target.getWidth() - parentPadding){
m.setX(m.getX()+ x);
}
int marginTop = style.getMarginTop();
switch(valign) {
case Component.BOTTOM:
if (vAlignByRow) {
m.setY(y + Math.max(marginTop, height - m.getHeight()) - style.getMarginBottom());
} else {
m.setY(y + Math.max(marginTop, target.getHeight() - m.getHeight()) - style.getMarginBottom());
}
break;
case Component.CENTER:
if (vAlignByRow) {
m.setY(y + Math.max(marginTop, (height - m.getHeight()) / 2));
} else {
m.setY(y + Math.max(marginTop, (target.getHeight() - m.getHeight()) / 2));
}
break;
case Component.BASELINE:
m.setY(y + Math.max(marginTop, baseline - m.getBaseline(m.getWidth(), m.getHeight())));
break;
default:
m.setY(y + marginTop);
break;
}
}
}
示例13: addLayoutComponent
/**
* {@inheritDoc}
*/
public void addLayoutComponent(Object name, Component comp, Container c) {
// helper check for a common mistake...
if (name == null) {
throw new IllegalArgumentException("Cannot add component to BorderLayout Container without constraint parameter");
}
// allows us to work with Component constraints too which makes some code simpler
if(name instanceof Integer) {
switch(((Integer)name).intValue()) {
case Component.TOP:
name = NORTH;
break;
case Component.BOTTOM:
name = SOUTH;
break;
case Component.LEFT:
name = WEST;
break;
case Component.RIGHT:
name = EAST;
break;
case Component.CENTER:
name = CENTER;
break;
default:
throw new IllegalArgumentException("BorderLayout Container expects one of the constraints BorderLayout.NORTH/SOUTH/EAST/WEST/CENTER");
}
}
Component previous = null;
/* Assign the component to one of the known regions of the layout.
*/
if (CENTER.equals(name)) {
previous = portraitCenter;
portraitCenter = comp;
} else if (NORTH.equals(name)) {
previous = portraitNorth;
portraitNorth = comp;
} else if (SOUTH.equals(name)) {
previous = portraitSouth;
portraitSouth = comp;
} else if (EAST.equals(name)) {
previous = portraitEast;
portraitEast = comp;
} else if (WEST.equals(name)) {
previous = portraitWest;
portraitWest = comp;
} else if (OVERLAY.equals(name)) {
previous = overlay;
overlay = comp;
} else {
throw new IllegalArgumentException("cannot add to layout: unknown constraint: " + name);
}
if (previous != null && previous != comp) {
c.removeComponent(previous);
}
}
示例14: drawTextArea
/**
* {@inheritDoc}
*/
public void drawTextArea(Graphics g, TextArea ta) {
setFG(g, ta);
int line = ta.getLines();
int oX = g.getClipX();
int oY = g.getClipY();
int oWidth = g.getClipWidth();
int oHeight = g.getClipHeight();
Font f = ta.getStyle().getFont();
int fontHeight = f.getHeight();
int align = reverseAlignForBidi(ta);
int leftPadding = ta.getStyle().getPaddingLeft(ta.isRTL());
int rightPadding = ta.getStyle().getPaddingRight(ta.isRTL());
int topPadding = ta.getStyle().getPaddingTop();
boolean shouldBreak = false;
for (int i = 0; i < line; i++) {
int x = ta.getX() + leftPadding;
int y = ta.getY() + topPadding +
(ta.getRowsGap() + fontHeight) * i;
if(Rectangle.intersects(x, y, ta.getWidth(), fontHeight, oX, oY, oWidth, oHeight)) {
String rowText = (String) ta.getTextAt(i);
//display ******** if it is a password field
String displayText = "";
if ((ta.getConstraint() & TextArea.PASSWORD) != 0) {
int rlen = rowText.length();
for (int j = 0; j < rlen; j++) {
displayText += passwordChar;
}
} else {
displayText = rowText;
}
switch(align) {
case Component.RIGHT:
x = ta.getX() + ta.getWidth() - rightPadding - f.stringWidth(displayText);
break;
case Component.CENTER:
x+= (ta.getWidth()-leftPadding-rightPadding-f.stringWidth(displayText))/2;
break;
}
int nextY = ta.getY() + topPadding + (ta.getRowsGap() + fontHeight) * (i + 2);
//if this is the last line to display and there is more content and isEndsWith3Points() is true
//add "..." at the last row
if(ta.isEndsWith3Points() && ta.getGrowLimit() == (i + 1) && ta.getGrowLimit() != line){
if(displayText.length() > 3){
displayText = displayText.substring(0, displayText.length() - 3);
}
g.drawString(displayText + "...", x, y ,ta.getStyle().getTextDecoration());
return;
}else{
g.drawString(displayText, x, y ,ta.getStyle().getTextDecoration());
}
shouldBreak = true;
}else{
if(shouldBreak){
break;
}
}
}
}
示例15: getTextFieldCursorX
/**
* Calculates the position of the text field cursor within the string
*/
private int getTextFieldCursorX(TextArea ta) {
Style style = ta.getStyle();
Font f = style.getFont();
// display ******** if it is a password field
String displayText = getTextFieldString(ta);
String inputMode = ta.getInputMode();
int inputModeWidth = f.stringWidth(inputMode);
// QWERTY devices don't quite have an input mode hide it also when we have a VK
if(ta.isQwertyInput() || Display.getInstance().isVirtualKeyboardShowing()) {
inputMode = "";
inputModeWidth = 0;
}
int xPos = 0;
int cursorCharPosition = ta.getCursorX();
int cursorX=0;
int x = 0;
if (reverseAlignForBidi(ta) == Component.RIGHT) {
if (Display.getInstance().isBidiAlgorithm()) {
//char[] dest = displayText.toCharArray();
cursorCharPosition = Display.getInstance().getCharLocation(displayText, cursorCharPosition-1);
if (cursorCharPosition==-1) {
xPos = f.stringWidth(displayText);
} else {
displayText = Display.getInstance().convertBidiLogicalToVisual(displayText);
if (!isRTLOrWhitespace((displayText.charAt(cursorCharPosition)))) {
cursorCharPosition++;
}
xPos = f.stringWidth(displayText.substring(0, cursorCharPosition));
}
}
int displayX = ta.getX() + ta.getWidth() - style.getPaddingLeft(ta.isRTL()) - f.stringWidth(displayText);
cursorX = displayX + xPos;
x=0;
} else {
if (cursorCharPosition > 0) {
cursorCharPosition = Math.min(displayText.length(),
cursorCharPosition);
xPos = f.stringWidth(displayText.substring(0, cursorCharPosition));
}
cursorX = ta.getX() + style.getPaddingLeft(ta.isRTL()) + xPos;
if (ta.isSingleLineTextArea() && ta.getWidth() > (f.getHeight() * 2) && cursorX >= ta.getWidth() - inputModeWidth -style.getPaddingLeft(ta.isRTL())) {
if (x + xPos >= ta.getWidth() - inputModeWidth - style.getPaddingLeftNoRTL() - style.getPaddingRightNoRTL()) {
x = ta.getWidth() - inputModeWidth - style.getPaddingLeftNoRTL() - style.getPaddingRightNoRTL() - xPos -1;
}
}
}
return cursorX+x;
}