本文整理汇总了Java中com.codename1.ui.Component类的典型用法代码示例。如果您正苦于以下问题:Java Component类的具体用法?Java Component怎么用?Java Component使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Component类属于com.codename1.ui包,在下文中一共展示了Component类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: selectListOffset
import com.codename1.ui.Component; //导入依赖的package包/类
private static void selectListOffset(Component c, int offset) {
assertBool(c != null, "List not found");
if(c instanceof List) {
((List)c).setSelectedIndex(offset);
return;
}
if(c instanceof ContainerList) {
((ContainerList)c).setSelectedIndex(offset);
return;
}
if(c instanceof GenericSpinner) {
((GenericSpinner)c).getModel().setSelectedIndex(offset);
return;
}
assertBool(false, "Unsupported list type: " + c.getName());
}
示例2: calcPreferredValues
import com.codename1.ui.Component; //导入依赖的package包/类
private void calcPreferredValues(Component cmp) {
if (tmpLaidOut.contains(cmp)) {
return;
}
tmpLaidOut.add(cmp);
LayeredLayoutConstraint constraint = (LayeredLayoutConstraint) getComponentConstraint(cmp);
if (constraint != null) {
constraint.fixDependencies(cmp.getParent());
for (LayeredLayoutConstraint.Inset inset : constraint.insets) {
if (inset.referenceComponent != null && inset.referenceComponent.getParent() == cmp.getParent()) {
calcPreferredValues(inset.referenceComponent);
}
inset.calcPreferredValue(cmp.getParent(), cmp);
}
}
}
示例3: setState
import com.codename1.ui.Component; //导入依赖的package包/类
/**
* Called when the form is created to set the current state.
*/
public void setState(Form f, Map state) {
List list = getList(f);
f.putClientProperty(list.getName()+"ScrollY", state.get(list.getName()+"ScrollY"));
/**
* On loading the view for the list, it animates a scroll to the selected position.
* This position will overwrite the previous ScrollY position if the element is out-of-scope.
*
* @see UIBuilder.setContainerStateImpl(Container cnt, Hashtable state)
*/
String cmpName = (String)state.get(StateMachine.FORM_STATE_KEY_FOCUS);
if(cmpName != null) {
Component c = ui.findByName(cmpName, f);
if(c != null) {
c.requestFocus();
if(c instanceof List) {
Integer i = (Integer)state.get(StateMachine.FORM_STATE_KEY_SELECTION);
if(i != null) {
((List)c).setSelectedIndex(i.intValue());
}
}
}
}
}
示例4: replace
import com.codename1.ui.Component; //导入依赖的package包/类
/**
* Removes an existing component replacing it with the specified component.
*
* @param existingComponent the Component that should be removed and
* replaced with newComponent
* @param newComponent the Component to put in existingComponents place
* @throws IllegalArgumentException is either of the Components are null or
* if existingComponent is not being managed by this layout manager
*/
public void replace(Component existingComponent, Component newComponent) {
if (existingComponent == null || newComponent == null) {
throw new IllegalArgumentException("Components must be non-null");
}
// Make sure all the components have been registered, otherwise we may
// not update the correct Springs.
if (springsChanged) {
registerComponents(horizontalGroup, HORIZONTAL);
registerComponents(verticalGroup, VERTICAL);
}
ComponentInfo info = (ComponentInfo)componentInfos.
remove(existingComponent);
if (info == null) {
throw new IllegalArgumentException("Component must already exist");
}
host.removeComponent(existingComponent);
if (newComponent.getParent() != host) {
host.addComponent(newComponent);
}
info.setComponent(newComponent);
componentInfos.put(newComponent, info);
invalidateHost();
}
示例5: addLayoutComponent
import com.codename1.ui.Component; //导入依赖的package包/类
public void addLayoutComponent(Object constraints, Component comp, Container c) {
GridBagConstraints cons;
if (constraints != null) {
if (!(constraints instanceof GridBagConstraints)) {
throw new IllegalArgumentException("AddLayoutComponent: constraint object must be GridBagConstraints"); //$NON-NLS-1$
}
cons = (GridBagConstraints) constraints;
} else {
if (comptable.containsKey(comp)) {
// don't replace constraints with default ones
return;
}
cons = defaultConstraints;
}
/*try {
//cons.verify();
} catch (IllegalArgumentException e) {
// awt.81=AddLayoutComponent: {0}
throw new IllegalArgumentException("AddLayoutComponent: " + e.getMessage()); //$NON-NLS-1$
}*/
GridBagConstraints consClone = (GridBagConstraints) cons.clone();
comptable.put(comp, consClone);
Container parent = comp.getParent();
updateParentInfo(parent, consClone);
}
示例6: ComponentSpring
import com.codename1.ui.Component; //导入依赖的package包/类
private ComponentSpring(Component component, int min, int pref,
int max) {
this.component = component;
if (component == null) {
throw new IllegalArgumentException(
"Component must be non-null");
}
checkSize(min, pref, max, true);
this.min = min;
this.max = max;
this.pref = pref;
// getComponentInfo makes sure component is a child of the
// Container GroupLayout is the LayoutManager for.
getComponentInfo(component);
}
示例7: getApplicableStyles
import com.codename1.ui.Component; //导入依赖的package包/类
/**
* Returns a mask of the STYLE_* constants of which CodenameOne styles this selector should be applied to
*
* @param cmp The component in question
* @param selector The selector
* @return a mask of the STYLE_* constants of which CodenameOne styles this selector should be applied to
*/
private int getApplicableStyles(Component cmp,CSSElement selector) {
int result=0;
if (cmp instanceof HTMLLink) {
int pseudoClass=selector.getSelectorPseudoClass();
boolean done=false;
if ((pseudoClass & CSSElement.PC_FOCUS)!=0) { // Focused (i.e. CSS focus/hover)
result|=STYLE_SELECTED;
done=true;
}
if ((pseudoClass & CSSElement.PC_ACTIVE)!=0) { // active in CSS means pressed in CodenameOne
result|=STYLE_PRESSED;
done=true;
}
if (!done) {
result|=STYLE_SELECTED|STYLE_UNSELECTED;
}
} else {
result|=STYLE_SELECTED|STYLE_UNSELECTED;
}
return result;
}
示例8: findEmptyContainer
import com.codename1.ui.Component; //导入依赖的package包/类
private Container findEmptyContainer(Container c) {
int count = c.getComponentCount();
if(count == 0) {
return c;
}
for(int iter = 0 ; iter < count ; iter++) {
Component x = c.getComponentAt(iter);
if(x instanceof Container) {
Container current = findEmptyContainer((Container)x);
if(current != null) {
return current;
}
}
}
return null;
}
示例9: processAccessKey
import com.codename1.ui.Component; //导入依赖的package包/类
/**
* Tries to assign the given key string as an access key to the specified component
* The key string given here is a single key
*
* @param keyStr The string representing the key (either a character, a unicode escape sequence or a special key name
* @param htmlC The HTMLComponent
* @param ui The component to set the access key on
* @param override If true overrides other keys assigned previously for this component
* @return true if successful, false otherwise
*/
private boolean processAccessKey(String keyStr,HTMLComponent htmlC,Component ui,boolean override) {
if (keyStr.startsWith("\\")) { // Unicode escape sequence, may be used to denote * and # which technically are illegal as values
try {
int keyCode=Integer.parseInt(keyStr.substring(1), 16);
htmlC.addAccessKey((char)keyCode, ui, override);
return true;
} catch (NumberFormatException nfe) {
return false;
}
} else if (keyStr.length()==1) {
htmlC.addAccessKey(keyStr.charAt(0), ui, override);
return true;
} else { //special key shortcut
if (specialKeys!=null) {
Integer key=(Integer)specialKeys.get(keyStr);
if (key!=null) {
htmlC.addAccessKey(key.intValue(), ui, override);
return true;
}
}
return false;
}
}
示例10: launchAd
import com.codename1.ui.Component; //导入依赖的package包/类
private void launchAd() {
Component c = getComponentAt(0);
if (c instanceof HTMLComponent) {
HTMLComponent h = (HTMLComponent) c;
h.setSupressExceptions(true);
HTMLElement dom = h.getDOM();
Vector links = dom.getDescendantsByTagName("a");
if (links.size() > 0) {
HTMLElement e = (HTMLElement) links.elementAt(0);
String link = e.getAttribute("href");
if (link != null) {
Display.getInstance().execute(link);
}
}
}
}
示例11: wrap
import com.codename1.ui.Component; //导入依赖的package包/类
protected Form wrap(String title, Component c){
c.getStyle().setBgColor(0xff0000);
Form f = new Form(title);
f.setLayout(new BorderLayout());
if (isDrawOnMutableImage()) {
int dispW = Display.getInstance().getDisplayWidth();
int dispH = Display.getInstance().getDisplayHeight();
Image img = Image.createImage((int)(dispW * 0.8), (int)(dispH * 0.8), 0x0);
Graphics g = img.getGraphics();
c.setWidth((int)(dispW * 0.8));
c.setHeight((int)(dispH * 0.8));
c.paint(g);
f.addComponent(BorderLayout.CENTER, new Label(img));
} else {
f.addComponent(BorderLayout.CENTER, c);
}
return f;
}
示例12: refreshZoom
import com.codename1.ui.Component; //导入依赖的package包/类
void refreshZoom(Container solitairContainer) {
int dpi = DPIS[currentZoom / 5];
Preferences.set("dpi", dpi);
Preferences.set("zoom", currentZoom);
try {
cards = Resources.open("/gamedata.res",dpi);
cardImageCache.clear();
Image cardBack = getCardImage("card_back.png");
for(Component c : solitairContainer) {
CardComponent crd = (CardComponent)c;
crd.setImages(getCardImage(crd.getCard().getFileName()), cardBack);
}
solitairContainer.revalidate();
solitairContainer.getParent().replace(solitairContainer.getParent().getComponentAt(0), createPlacementContainer(solitairContainer), null);
} catch(IOException e) {
Log.e(e);
}
}
示例13: paintShiftFadeHierarchy
import com.codename1.ui.Component; //导入依赖的package包/类
private void paintShiftFadeHierarchy(Container c, int alpha, Graphics g, boolean incoming) {
int componentCount = c.getComponentCount();
for(int iter = 0 ; iter < componentCount ; iter++) {
Component current = c.getComponentAt(iter);
if(current instanceof Container) {
paintShiftFadeHierarchy((Container)current, alpha, g, incoming);
continue;
}
g.setAlpha(alpha);
Motion m = getComponentShiftMotion(current, incoming);
if(m != null) {
int tval = m.getValue();
g.translate(tval, 0);
current.paintComponent(g, false);
g.translate(-tval, 0);
}
g.setAlpha(255);
}
}
示例14: addPreferredGap
import com.codename1.ui.Component; //导入依赖的package包/类
/**
* Adds an element representing the preferred gap between the two
* components.
*
* @param comp1 the first component
* @param comp2 the second component
* @param type the type of gap; one of the constants defined by
* LayoutStyle
* @param canGrow true if the gap can grow if more
* space is available
* @return this <code>SequentialGroup</code>
* @throws IllegalArgumentException if <code>type</code> is not a
* valid LayoutStyle constant
* @see LayoutStyle
*/
public SequentialGroup addPreferredGap(Component comp1,
Component comp2,
int type, boolean canGrow) {
if (type != LayoutStyle.RELATED &&
type != LayoutStyle.UNRELATED &&
type != LayoutStyle.INDENT) {
throw new IllegalArgumentException("Invalid type argument");
}
if (comp1 == null || comp2 == null) {
throw new IllegalArgumentException(
"Components must be non-null");
}
return (SequentialGroup)addSpring(new PaddingSpring(
comp1, comp2, type, canGrow));
}
示例15: getComponentConstraint
import com.codename1.ui.Component; //导入依赖的package包/类
/**
* Returns the component constraint
*
* @param comp the component whose constraint is queried
* @return one of the constraints defined in this class
*/
public Object getComponentConstraint(Component comp) {
if (comp == portraitCenter) {
return CENTER;
} else if (comp == portraitNorth) {
return NORTH;
} else if (comp == portraitSouth) {
return SOUTH;
} else if (comp == portraitEast) {
return EAST;
} else if (comp == overlay) {
return OVERLAY;
} else {
if(comp == portraitWest) {
return WEST;
}
}
return null;
}