本文整理汇总了Java中com.codename1.ui.Component.setX方法的典型用法代码示例。如果您正苦于以下问题:Java Component.setX方法的具体用法?Java Component.setX怎么用?Java Component.setX使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.codename1.ui.Component
的用法示例。
在下文中一共展示了Component.setX方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: layoutContainer
import com.codename1.ui.Component; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
public void layoutContainer(Container parent) {
if(width < 0) {
return;
}
int numOfcomponents = parent.getComponentCount();
int parentW = parent.getWidth();
int parentH = parent.getHeight();
for(int i=0; i< numOfcomponents; i++){
Component cmp = parent.getComponentAt(i);
int x = cmp.getX() * parentW /width;
int y = cmp.getY() * parentH /height;
cmp.setX(x);
cmp.setY(y);
cmp.setWidth(cmp.getPreferredW());
cmp.setHeight(cmp.getPreferredH());
}
width = parentW;
height = parentH;
}
示例2: positionTopBottom
import com.codename1.ui.Component; //导入方法依赖的package包/类
private void positionTopBottom(Component target, Component c, int right, int left, int targetHeight) {
int w = right - left - c.getStyle().getMarginLeftNoRTL() - c.getStyle().getMarginRightNoRTL();
int x = left + c.getStyle().getMarginLeft(target.isRTL());
if(scaleEdges) {
c.setWidth(w);
c.setX(x);
} else {
int pw = c.getPreferredW();
if(pw < w) {
c.setWidth(pw);
c.setX(x + (w - pw) / 2);
} else {
c.setWidth(w);
c.setX(x);
}
}
c.setHeight(Math.min(targetHeight, c.getPreferredH())); //verify I want to use tge prefered size
}
示例3: animate
import com.codename1.ui.Component; //导入方法依赖的package包/类
public boolean animate() {
boolean result=super.animate();
if (marqueeMotion==null) {
return result;
}
for (Enumeration e=marqueeComponents.elements();e.hasMoreElements();) {
Component cmp=(Component)e.nextElement();
cmp.setX(marqueeMotion.getValue());
}
if (marqueeMotion.isFinished()) {
int dir=getUIManager().getLookAndFeel().isRTL()?1:-1;
marqueeMotion=Motion.createLinearMotion(dir*-HTMLComponent.this.getWidth(), dir*HTMLComponent.this.getWidth(), MARQUEE_DELAY);
marqueeMotion.start();
}
return true;
}
示例4: createMorphEffect
import com.codename1.ui.Component; //导入方法依赖的package包/类
private void createMorphEffect(Label titleLabel) {
// animate the components out of the previous form if we are coming in from the login form
Form parent = Display.getInstance().getCurrent();
if(parent.getUIID().equals("MainForm")) {
for(Component cmp : parent.getContentPane()) {
cmp.setX(parent.getWidth());
}
// moves all the components outside of the content pane to the right while fading them out over 400ms
parent.getContentPane().animateUnlayoutAndWait(400, 0);
parent.getContentPane().removeAll();
// we can't mutate a form into a component in another form so we need to convert the background to an image and then morph that
// this is especially easy since we already removed all the components
Label dummy = new Label();
dummy.setShowEvenIfBlank(true);
dummy.setUIID("Container");
dummy.setUnselectedStyle(new Style(parent.getUnselectedStyle()));
parent.setUIID("Form");
// special case to remove status bar on iOS 7
parent.getTitleArea().removeAll();
parent.setLayout(new BorderLayout());
parent.addComponent(BorderLayout.CENTER, dummy);
parent.revalidate();
// animate the main panel to the new location at the top title area of the screen
dummy.setName("fullScreen");
titleLabel.setName("titleImage");
parent.setTransitionOutAnimator(MorphTransition.create(1100).morph("fullScreen", "titleImage"));
}
}
示例5: respond
import com.codename1.ui.Component; //导入方法依赖的package包/类
private void respond(Container chatArea, String text, Image roundedHimOrHerImage) {
Component answer = respondNoLayout(chatArea, text, roundedHimOrHerImage);
answer.setX(chatArea.getWidth());
answer.setWidth(chatArea.getWidth());
answer.setHeight(40);
chatArea.animateLayoutAndWait(300);
chatArea.scrollComponentToVisible(answer);
}
示例6: arrangeForInterlace
import com.codename1.ui.Component; //导入方法依赖的package包/类
private void arrangeForInterlace(Container c) {
int w = Display.getInstance().getDisplayWidth();
for(int iter = 0 ; iter < c.getComponentCount() ; iter++) {
Component cmp = c.getComponentAt(iter);
if(iter % 2 == 0) {
cmp.setX(-w);
} else {
cmp.setX(w);
}
}
}
示例7: arrangeForConcentrate
import com.codename1.ui.Component; //导入方法依赖的package包/类
private void arrangeForConcentrate(Container c) {
int w = Display.getInstance().getDisplayWidth();
int h = Display.getInstance().getDisplayHeight();
int[] positionX = {-100, w / 2, w + 100, w + 100, w + 100, w / 2, -100, -100};
int[] positionY = {-100, -100, -100, h / 2, h + 100, h + 100, h + 100, h / 2};
for(int iter = 0 ; iter < c.getComponentCount() ; iter++) {
Component cmp = c.getComponentAt(iter);
cmp.setY(positionY[iter % positionY.length]);
cmp.setX(positionX[iter % positionX.length]);
}
}
示例8: paint
import com.codename1.ui.Component; //导入方法依赖的package包/类
public void paint(Graphics g) {
Component cmp = renderer.getCellRendererComponent(ContainerList.this, model, model.getItemAt(offset), offset, hasFocus());
cmp.setX(getX());
cmp.setY(getY());
cmp.setWidth(getWidth());
cmp.setHeight(getHeight());
if(cmp instanceof Container) {
((Container)cmp).revalidate();
}
cmp.setFocus(hasFocus());
cmp.paintComponent(g);
}
示例9: pointerReleasedImpl
import com.codename1.ui.Component; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
public void pointerReleasedImpl(int x, int y, boolean longPress) {
if (!isDragActivated()) {
// fire the action event into the selected component
Component cmp = renderer.getCellRendererComponent(ContainerList.this, model, model.getItemAt(offset), offset, hasFocus());
if(cmp instanceof Container) {
int absX = getAbsoluteX();
int absY = getAbsoluteY();
int newX = x - absX + cmp.getX();
int newY = y - absY + cmp.getY();
Component selectionCmp = ((Container) cmp).getComponentAt(newX, newY);
if(selectionCmp != null) {
selectionCmp.setX(0);
selectionCmp.setY(0);
if(longPress){
selectionCmp.longPointerPress(newX, newY);
fireActionEvent(new ActionEvent(ContainerList.this, x, y, true));
return;
}else{
selectionCmp.pointerPressed(newX, newY);
selectionCmp.pointerReleased(newX, newY);
}
}
}
fireActionEvent(new ActionEvent(ContainerList.this, x, y, longPress));
}
}
示例10: layoutContainer
import com.codename1.ui.Component; //导入方法依赖的package包/类
@Override
public void layoutContainer(Container parent) {
int componentCount = parent.getComponentCount();
if (componentCount < 1) {
return;
}
int tableaDepthIncrement = Display.getInstance().convertToPixels(2, false);
for (int iter = 0; iter < TABLEAU_DEPTH.length; iter++) {
TABLEAU_DEPTH[iter] = 0;
}
// we assume all components are exactly the same size (cards)
Component cmp = parent.getComponentAt(0);
Style stl = cmp.getStyle();
int cmpWidth = cmp.getPreferredW() + stl.getMargin(Component.LEFT) + stl.getMargin(Component.RIGHT);
int cmpHeight = cmp.getPreferredH() + stl.getMargin(Component.TOP) + stl.getMargin(Component.BOTTOM);
int width = parent.getLayoutWidth() - parent.getSideGap() - parent.getStyle().getPadding(false, Component.RIGHT) - parent.getStyle().getPadding(false, Component.LEFT);
int height = parent.getLayoutHeight() - parent.getBottomGap() - parent.getStyle().getPadding(false, Component.BOTTOM) - parent.getStyle().getPadding(false, Component.TOP);
int x = parent.getStyle().getPadding(parent.isRTL(), Component.LEFT);
int y = parent.getStyle().getPadding(false, Component.TOP);
int deck1X = x;
int tableauWidth = width / 7;
int deck2X = deck1X + tableauWidth;
boolean draw3 = Preferences.get("3cards", false);
FOUNDATION_POSITIONS_X[3] = x + width - tableauWidth;
FOUNDATION_POSITIONS_X[2] = FOUNDATION_POSITIONS_X[3] - tableauWidth;
FOUNDATION_POSITIONS_X[1] = FOUNDATION_POSITIONS_X[2] - tableauWidth;
FOUNDATION_POSITIONS_X[0] = FOUNDATION_POSITIONS_X[1] - tableauWidth;
// place the tableau a bit below the top cards but not at the complete bottom.
int tableauY = y + cmpHeight;
for (Component currentCmp : parent) {
Constraint cons = (Constraint) getComponentConstraint(currentCmp);
if (cons != null) {
currentCmp.setWidth(cmpWidth);
currentCmp.setHeight(cmpHeight);
switch (cons.pos) {
case DECK:
currentCmp.setY(y);
if (cons.offset == 0) {
currentCmp.setX(deck1X);
} else {
currentCmp.setX(deck2X);
}
break;
case FOUNDATION:
currentCmp.setY(y);
currentCmp.setX(FOUNDATION_POSITIONS_X[cons.offset]);
break;
case TABLEAU:
currentCmp.setY(tableauY + TABLEAU_DEPTH[cons.offset]);
TABLEAU_DEPTH[cons.offset] += tableaDepthIncrement;
currentCmp.setX(cons.offset * tableauWidth);
// special case for the drop targets for the foundation, we want them to stretch all the way down...
if(!(currentCmp instanceof CardComponent)) {
currentCmp.setHeight(height - currentCmp.getY());
}
break;
}
}
}
// shift right the top 2 deck card in draw 3 cards mode
if(draw3) {
int found = 0;
for(int iter = parent.getComponentCount() - 1 ; iter >= 0 ; iter--) {
Component c = parent.getComponentAt(iter);
Constraint con = (Constraint)getComponentConstraint(c);
if(con.pos == Position.DECK && con.offset == 1) {
c.setX(c.getX() + Display.getInstance().convertToPixels((2 - found) * 2, true));
found++;
if(found == 2) {
break;
}
}
}
}
}
示例11: layoutComponent
import com.codename1.ui.Component; //导入方法依赖的package包/类
/**
* Lays out the specific component within the container. This will first lay out any components that it depends on.
* @param parent The parent container being laid out.
* @param cmp The component being laid out.
* @param top
* @param left
* @param bottom
* @param right
*/
private void layoutComponent(Container parent, Component cmp, int top, int left, int bottom, int right) {
if (tmpLaidOut.contains(cmp)) {
return;
}
tmpLaidOut.add(cmp);
LayeredLayoutConstraint constraint = (LayeredLayoutConstraint) getComponentConstraint(cmp);
if (constraint != null) {
constraint.fixDependencies(parent);
for (LayeredLayoutConstraint.Inset inset : constraint.insets) {
if (inset.referenceComponent != null && inset.referenceComponent.getParent() == parent) {
layoutComponent(parent, inset.referenceComponent, top, left, bottom, right);
}
}
}
Style s = cmp.getStyle();
if (constraint != null) {
//int innerTop = top;
//int innerBottom = bottom;
//left = 0;
//right = parent.getLayoutWidth();
int leftInset = constraint.insets[Component.LEFT].calculate(cmp, top, left, bottom, right);
int rightInset = constraint.insets[Component.RIGHT].calculate(cmp, top, left, bottom, right);
int topInset = constraint.insets[Component.TOP].calculate(cmp, top, left, bottom, right);
int bottomInset = constraint.insets[Component.BOTTOM].calculate(cmp, top, left, bottom, right);
cmp.setX(left + leftInset + s.getMarginLeft(parent.isRTL()));
cmp.setY(top + topInset + s.getMarginTop());
cmp.setWidth(Math.max(0, right - cmp.getX() - s.getMarginRight(parent.isRTL()) - rightInset));
//cmp.setWidth(Math.max(0, right - left - s.getHorizontalMargins() - rightInset - leftInset));
//cmp.setHeight(Math.max(0, bottom - top - s.getVerticalMargins() - bottomInset - topInset));
cmp.setHeight(Math.max(0, bottom - cmp.getY() - s.getMarginBottom() - bottomInset));
} else {
int x = left + s.getMarginLeft(parent.isRTL());
int y = top + s.getMarginTop();
int w = right - left - s.getHorizontalMargins();
int h = bottom - top - s.getVerticalMargins();
cmp.setX(x);
cmp.setY(y);
cmp.setWidth(Math.max(0,w));
cmp.setHeight(Math.max(0,h));
//System.out.println("Component laid out "+cmp);
}
}
示例12: layoutContainer
import com.codename1.ui.Component; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
public void layoutContainer(Container parent) {
Style s = parent.getStyle();
int width = parent.getLayoutWidth() - parent.getSideGap() - s.getHorizontalPadding();
int height = parent.getLayoutHeight() - parent.getBottomGap() - s.getVerticalPadding();
int numOfcomponents = parent.getComponentCount();
autoSizeCols(parent, width);
int x = s.getPaddingLeft(parent.isRTL());
int y = s.getPaddingTop();
boolean rtl = parent.isRTL();
if (rtl) {
x += parent.getSideGap();
}
int localColumns = columns;
int cmpWidth = width / columns;
int cmpHeight;
if (numOfcomponents > rows * columns) {
// actual rows number
cmpHeight = height / (numOfcomponents / columns + (numOfcomponents % columns == 0 ? 0 : 1));
} else {
cmpHeight = height / rows;
}
int row = 0;
int offset = 0;
for(int iter = 0 ; iter < numOfcomponents ; iter++){
Component cmp = parent.getComponentAt(iter);
Style cmpStyle = cmp.getStyle();
int marginLeft = cmpStyle.getMarginLeft(parent.isRTL());
int marginTop = cmpStyle.getMarginTop();
if(hideZeroSized) {
if(cmp.isHidden()) {
continue;
}
}
cmp.setWidth(cmpWidth - marginLeft - cmpStyle.getMarginRight(parent.isRTL()));
cmp.setHeight(cmpHeight - marginTop - cmpStyle.getMarginBottom());
if (rtl) {
cmp.setX(x + (localColumns - 1 - (offset % localColumns)) * cmpWidth + marginLeft);
} else {
cmp.setX(x + (offset % localColumns) * cmpWidth + marginLeft);
}
cmp.setY(y + row * cmpHeight + marginTop);
if((offset + 1) % columns == 0){
row++;
// check if we need to recalculate component widths
if(fillLastRow && row == rows - 1) {
localColumns = numOfcomponents % columns;
if(localColumns == 0) {
localColumns = columns;
}
cmpWidth = width / localColumns;
}
}
offset++;
}
}
示例13: moveComponents
import com.codename1.ui.Component; //导入方法依赖的package包/类
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;
}
}
}
示例14: drawComboBox
import com.codename1.ui.Component; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
public void drawComboBox(Graphics g, List cb) {
int border = 2;
Style style = cb.getStyle();
int leftPadding = style.getPaddingLeft(cb.isRTL());
int rightPadding = style.getPaddingRight(cb.isRTL());
setFG(g, cb);
ListModel model = cb.getModel();
ListCellRenderer renderer = cb.getRenderer();
Object value = model.getItemAt(model.getSelectedIndex());
int comboImageWidth;
if (comboImage != null) {
comboImageWidth = comboImage.getWidth();
} else {
comboImageWidth = style.getFont().getHeight();
}
int cellX = cb.getX() + style.getPaddingTop();
if(cb.isRTL()){
cellX += comboImageWidth;
}
if (model.getSize() > 0) {
Component cmp = renderer.getListCellRendererComponent(cb, value, model.getSelectedIndex(), cb.hasFocus());
cmp.setX(cellX);
cmp.setY(cb.getY() + style.getPaddingTop());
cmp.setWidth(cb.getWidth() - comboImageWidth - rightPadding - leftPadding);
cmp.setHeight(cb.getHeight() - style.getPaddingTop() - style.getPaddingBottom());
cmp.paint(g);
}
g.setColor(style.getBgColor());
int y = cb.getY();
int height = cb.getHeight();
int width = comboImageWidth + border;
int x = cb.getX();
if (cb.isRTL()) {
x += leftPadding;
} else {
x += cb.getWidth() - comboImageWidth - rightPadding;
}
if (comboImage != null) {
g.drawImage(comboImage, x, y + height / 2 - comboImage.getHeight() / 2);
} else {
int color = g.getColor();
// brighten or darken the color slightly
int destColor = findDestColor(color);
g.fillLinearGradient(g.getColor(), destColor, x, y, width, height, false);
g.setColor(color);
g.drawRect(x, y, width, height - 1);
width--;
height--;
//g.drawRect(x, y, width, height);
g.translate(x + 1, y + 1);
g.setColor(0x111111);
int x1 = scaleCoordinate(2.5652081f, 16, width);
int y1 = scaleCoordinate(4.4753664f, 16, height);
int x2 = scaleCoordinate(8.2872691f, 16, width);
int y2 = scaleCoordinate(10f, 16, height);
int x3 = scaleCoordinate(13.516078f, 16, width);
int y3 = y1;
g.fillTriangle(x1, y1, x2, y2, x3, y3);
g.translate(-1, -1);
g.setColor(style.getFgColor());
g.fillTriangle(x1, y1, x2, y2, x3, y3);
//g.setColor(style.getFgColor());
//g.fillTriangle(x1 + 2, y1 + 2, x2, y2 - 2, x3 - 2, y3 + 2);
g.translate(-x, -y);
}
}