本文整理汇总了Java中com.codename1.ui.Component.CENTER属性的典型用法代码示例。如果您正苦于以下问题:Java Component.CENTER属性的具体用法?Java Component.CENTER怎么用?Java Component.CENTER使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.codename1.ui.Component
的用法示例。
在下文中一共展示了Component.CENTER属性的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: drawLabelStringValign
/**
* Implements the drawString for the text component and adjust the valign
* assuming the icon is in one of the sides
*/
private int drawLabelStringValign(AndroidGraphics underlying,
CodenameOneTextPaint nativeFont, String str, int x, int y, int textSpaceW,
boolean isTickerRunning, int tickerShiftText, int textDecoration, boolean rtl,
boolean endsWith3Points, int textWidth,
int iconStringHGap, int iconHeight, int fontHeight, int valign, Bitmap textCache) {
if(str.length() == 0) {
return 0;
}
switch (valign) {
case Component.TOP:
return drawLabelString(underlying, nativeFont, str, x, y, textSpaceW, isTickerRunning, tickerShiftText, textDecoration, rtl, endsWith3Points, textWidth, fontHeight, textCache);
case Component.CENTER:
return drawLabelString(underlying, nativeFont, str, x, y + iconHeight / 2 - fontHeight / 2, textSpaceW, isTickerRunning, tickerShiftText, textDecoration, rtl, endsWith3Points, textWidth, fontHeight, textCache);
default:
return drawLabelString(underlying, nativeFont, str, x, y + iconStringHGap, textSpaceW, isTickerRunning, tickerShiftText, textDecoration, rtl, endsWith3Points, textWidth, fontHeight, textCache);
}
}
示例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: drawLabelStringValign
/**
* Implements the drawString for the text component and adjust the valign
* assuming the icon is in one of the sides
*/
private int drawLabelStringValign(
Object nativeFont, String str, int x, int y, int textSpaceW,
boolean isTickerRunning, int tickerShiftText, int textDecoration, boolean rtl,
boolean endsWith3Points, int textWidth,
int iconStringHGap, int iconHeight, int fontHeight, int valign) {
switch (valign) {
case Component.TOP:
return drawLabelString(nativeFont, str, x, y, textSpaceW, isTickerRunning, tickerShiftText, textDecoration, rtl, endsWith3Points, textWidth, fontHeight);
case Component.CENTER:
return drawLabelString(nativeFont, str, x, y + iconHeight / 2 - fontHeight / 2, textSpaceW, isTickerRunning, tickerShiftText, textDecoration, rtl, endsWith3Points, textWidth, fontHeight);
default:
return drawLabelString(nativeFont, str, x, y + iconStringHGap, textSpaceW, isTickerRunning, tickerShiftText, textDecoration, rtl, endsWith3Points, textWidth, fontHeight);
}
}
示例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: initAxesRangeForScale
public void initAxesRangeForScale(int i) {
mMinX[i] = MathHelper.NULL_VALUE;
mMaxX[i] = MathHelper.NULL_VALUE;
mMinY[i] = MathHelper.NULL_VALUE;
mMaxY[i] = MathHelper.NULL_VALUE;
double[] range = new double[] { mMinX[i], mMaxX[i], mMinY[i], mMaxY[i] };
initialRange.put(i, range);
mYTitle[i] = "";
mYTextLabels.put(i, new HashMap<Double, String>());
yLabelsAlign[i] = Component.CENTER;
yAxisAlign[i] = Component.LEFT;
}
示例6: getVertAlign
/**
* Converts a textual vertical 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
* @return Component.TOP, BOTTOM or CENTER or the defaultAlign in case no match was found.
*/
private int getVertAlign(String alignment,int defaultAlign) {
if (alignment!=null) {
if (alignment.equals("top")) {
return Component.TOP;
} else if (alignment.equals("bottom")) {
return Component.BOTTOM;
} else if ((alignment.equals("center")) || (alignment.equals("middle"))) {
return Component.CENTER;
}
}
return defaultAlign;
}
示例7: parseAlignment
static Integer parseAlignment(String alignment) {
if (Character.isDigit(alignment.charAt(0))) {
return Integer.parseInt(alignment);
} else if ("center".equalsIgnoreCase(alignment)) {
return Component.CENTER;
} else if ("left".equalsIgnoreCase(alignment)) {
return Component.LEFT;
} else if ("right".equalsIgnoreCase(alignment)) {
return Component.RIGHT;
}
return null;
}
示例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: drawLabelStringValign
/**
* Implements the drawString for the text component and adjust the valign
* assuming the icon is in one of the sides
*/
private int drawLabelStringValign(Graphics g, Label l, String str, int x, int y,
int iconStringHGap, int iconHeight, int textSpaceW, int fontHeight) {
switch (l.getVerticalAlignment()) {
case Component.TOP:
return drawLabelString(g, l, str, x, y, textSpaceW);
case Component.CENTER:
return drawLabelString(g, l, str, x, y + iconHeight / 2 - fontHeight / 2, textSpaceW);
default:
return drawLabelString(g, l, str, x, y + iconStringHGap, textSpaceW);
}
}
示例10: 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;
}
}
}
示例11: 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);
}
}
示例12: 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;
}
}
}
}
示例13: drawTextFieldCursor
/**
* {@inheritDoc}
*/
public void drawTextFieldCursor(Graphics g, TextArea ta) {
Style style = ta.getStyle();
Font f = style.getFont();
int cursorY;
if(ta.isSingleLineTextArea()) {
switch(ta.getVerticalAlignment()) {
case Component.BOTTOM:
cursorY = ta.getY() + ta.getHeight() - f.getHeight();
break;
case Component.CENTER:
cursorY = ta.getY() + ta.getHeight() / 2 - f.getHeight() / 2;
break;
default:
cursorY = ta.getY() + style.getPaddingTop();
break;
}
} else {
cursorY = ta.getY() + style.getPaddingTop() + ta.getCursorY() * (ta.getRowsGap() + f.getHeight());
}
int cursorX = getTextFieldCursorX(ta);
int align = reverseAlignForBidi(ta);
int x=0;
if (align==Component.RIGHT) {
String inputMode = ta.getInputMode();
int inputModeWidth = f.stringWidth(inputMode);
int baseX=ta.getX()+style.getPaddingLeftNoRTL()+inputModeWidth;
if (cursorX<baseX) {
x=baseX-cursorX;
}
}
int oldColor = g.getColor();
if(getTextFieldCursorColor() == 0) {
g.setColor(style.getFgColor());
} else {
g.setColor(getTextFieldCursorColor());
}
g.drawLine(cursorX + x, cursorY, cursorX + x, cursorY + f.getHeight());
g.setColor(oldColor);
}
示例14: InfiniteScrollAdapter
private InfiniteScrollAdapter() {
progress = new InfiniteProgress();
Container p = new Container(new FlowLayout(Component.CENTER));
p.addComponent(progress);
ip = p;
}