use of com.codename1.components.Switch in project CodenameOne by codenameone.
the class AddThemeEntry method updateThemeHashtable.
/**
* Updates the theme hash with the values from this editor
*/
public void updateThemeHashtable(Hashtable themeRes) {
if (disableRefresh) {
return;
}
String uiid = prefix;
String item = (String) componentName.getSelectedItem();
if (item != null && item.length() > 0) {
uiid = item + "." + prefix;
}
removeKeys(themeRes, uiid);
if (!defineAttribute.isSelected()) {
String val = (String) baseStyle.getSelectedItem();
if (val != null && val.length() > 0) {
switch(baseStyleType.getSelectedIndex()) {
case 0:
themeRes.put(uiid + "derive", val);
break;
case 1:
themeRes.put(uiid + "derive", val + ".sel");
break;
case 2:
themeRes.put(uiid + "derive", val + ".press");
break;
case 3:
themeRes.put(uiid + "derive", val + ".dis");
break;
}
}
}
if (!deriveAlignment.isSelected()) {
switch(alignmentCombo.getSelectedIndex()) {
case 0:
themeRes.put(uiid + "align", new Integer(com.codename1.ui.Component.LEFT));
break;
case 1:
themeRes.put(uiid + "align", new Integer(com.codename1.ui.Component.RIGHT));
break;
default:
themeRes.put(uiid + "align", new Integer(com.codename1.ui.Component.CENTER));
break;
}
}
if (!deriveBackground.isSelected()) {
int index = backgroundType.getSelectedIndex();
themeRes.put(uiid + "bgType", new Byte(BACKGROUND_VALUES[index]));
if (backgroundType.getSelectedIndex() >= BACKGROUND_VALUES_GRADIENT_ARRAY_OFFSET) {
// this is a gradient related type
themeRes.put(uiid + "bgGradient", new Object[] { Integer.valueOf(gradientStartColor.getText(), 16), Integer.valueOf(gradientEndColor.getText(), 16), new Float(((Number) gradientX.getValue()).floatValue()), new Float(((Number) gradientY.getValue()).floatValue()), new Float(((Number) gradientSize.getValue()).floatValue()) });
} else {
// this is an image related type
if (imagesCombo.getSelectedItem() != null && imagesCombo.getSelectedItem().toString().length() > 0) {
themeRes.put(uiid + "bgImage", resources.getImage((String) imagesCombo.getSelectedItem()));
} else {
brokenImage = true;
themeRes.put(uiid + "bgImage", com.codename1.ui.Image.createImage(5, 5));
}
}
}
if (!deriveBackgroundColor.isSelected()) {
themeRes.put(uiid + "bgColor", colorValueBG.getText());
}
if (!deriveBorder.isSelected()) {
if (currentBorder == null) {
themeRes.remove(uiid + "border");
} else {
themeRes.put(uiid + "border", currentBorder);
}
}
if (!deriveFont.isSelected()) {
Object v;
if (bitmapFont.isSelected()) {
String val = (String) bitmapFontValue.getSelectedItem();
if (val != null) {
v = resources.getFont(val);
} else {
v = Font.getDefaultFont();
}
} else {
if (trueTypeFont.getSelectedIndex() > 0) {
Font sys = Font.createSystemFont(FONT_FACE_VALUES[fontFace.getSelectedIndex()], FONT_STYLE_VALUES[fontStyle.getSelectedIndex()], FONT_SIZE_VALUES[fontSize.getSelectedIndex()]);
String selectedItem = (String) trueTypeFont.getSelectedItem();
if (selectedItem.startsWith("native:")) {
v = new EditorTTFFont(selectedItem, trueTypeFontSizeOption.getSelectedIndex(), ((Number) trueTypeFontSizeValue.getValue()).floatValue(), sys);
} else {
v = new EditorTTFFont(new File(ResourceEditorView.getLoadedFile().getParentFile(), selectedItem), trueTypeFontSizeOption.getSelectedIndex(), ((Number) trueTypeFontSizeValue.getValue()).floatValue(), sys);
}
} else {
v = Font.createSystemFont(FONT_FACE_VALUES[fontFace.getSelectedIndex()], FONT_STYLE_VALUES[fontStyle.getSelectedIndex()], FONT_SIZE_VALUES[fontSize.getSelectedIndex()]);
}
}
themeRes.put(uiid + "font", v);
}
if (!deriveForegroundColor.isSelected()) {
themeRes.put(uiid + "fgColor", colorValueFG.getText());
}
if (!deriveMargin.isSelected()) {
themeRes.put(uiid + "margin", marginTop.getValue() + "," + marginBottom.getValue() + "," + marginLeft.getValue() + "," + marginRight.getValue());
byte[] padUnit = new byte[4];
padUnit[com.codename1.ui.Component.BOTTOM] = (byte) marginBottomUnit.getSelectedIndex();
padUnit[com.codename1.ui.Component.TOP] = (byte) marginTopUnit.getSelectedIndex();
padUnit[com.codename1.ui.Component.LEFT] = (byte) marginLeftUnit.getSelectedIndex();
padUnit[com.codename1.ui.Component.RIGHT] = (byte) marginRightUnit.getSelectedIndex();
updateThemeRes(padUnit, themeRes, uiid + "marUnit");
}
if (!derivePadding.isSelected()) {
themeRes.put(uiid + "padding", paddingTop.getValue() + "," + paddingBottom.getValue() + "," + paddingLeft.getValue() + "," + paddingRight.getValue());
byte[] padUnit = new byte[4];
padUnit[com.codename1.ui.Component.BOTTOM] = (byte) paddingBottomUnit.getSelectedIndex();
padUnit[com.codename1.ui.Component.TOP] = (byte) paddingTopUnit.getSelectedIndex();
padUnit[com.codename1.ui.Component.LEFT] = (byte) paddingLeftUnit.getSelectedIndex();
padUnit[com.codename1.ui.Component.RIGHT] = (byte) paddingRightUnit.getSelectedIndex();
updateThemeRes(padUnit, themeRes, uiid + "padUnit");
}
if (!deriveTextDecoration.isSelected()) {
Object v;
switch(textDecorationCombo.getSelectedIndex()) {
case 1:
v = new Integer(com.codename1.ui.plaf.Style.TEXT_DECORATION_UNDERLINE);
break;
case 2:
v = new Integer(com.codename1.ui.plaf.Style.TEXT_DECORATION_STRIKETHRU);
break;
case 3:
v = new Integer(com.codename1.ui.plaf.Style.TEXT_DECORATION_3D);
break;
case 4:
v = new Integer(com.codename1.ui.plaf.Style.TEXT_DECORATION_3D_LOWERED);
break;
case 5:
v = new Integer(com.codename1.ui.plaf.Style.TEXT_DECORATION_3D_SHADOW_NORTH);
break;
default:
v = new Integer(0);
break;
}
themeRes.put(uiid + "textDecoration", v);
}
if (!deriveTransparency.isSelected()) {
themeRes.put(uiid + "transparency", "" + transparencyValue.getValue());
}
}
use of com.codename1.components.Switch in project CodenameOne by codenameone.
the class Import9Patch method create9Patch.
// GEN-LAST:event_okButtonActionPerformed
private void create9Patch(List<BufferedImage> biList, List<Integer> densities) {
List<com.codename1.ui.EncodedImage> topLeftCodenameOne = new ArrayList<EncodedImage>();
List<com.codename1.ui.EncodedImage> topRightCodenameOne = new ArrayList<EncodedImage>();
List<com.codename1.ui.EncodedImage> bottomLeftCodenameOne = new ArrayList<EncodedImage>();
List<com.codename1.ui.EncodedImage> bottomRightCodenameOne = new ArrayList<EncodedImage>();
List<com.codename1.ui.EncodedImage> centerCodenameOne = new ArrayList<EncodedImage>();
List<com.codename1.ui.EncodedImage> topImageCodenameOne = new ArrayList<EncodedImage>();
List<com.codename1.ui.EncodedImage> bottomImageCodenameOne = new ArrayList<EncodedImage>();
List<com.codename1.ui.EncodedImage> leftImageCodenameOne = new ArrayList<EncodedImage>();
List<com.codename1.ui.EncodedImage> rightImageCodenameOne = new ArrayList<EncodedImage>();
for (BufferedImage bi : biList) {
int left = 0;
for (int x = 0; x < bi.getWidth(); x++) {
int pixel = bi.getRGB(x, 0);
if ((pixel & 0xff000000) == 0xff000000) {
break;
}
left++;
}
int right = 0;
for (int x = bi.getWidth() - 1; x > 0; x--) {
int pixel = bi.getRGB(x, 0);
if ((pixel & 0xff000000) == 0xff000000) {
break;
}
right++;
}
int top = 0;
for (int y = 0; y < bi.getHeight(); y++) {
int pixel = bi.getRGB(0, y);
if ((pixel & 0xff000000) == 0xff000000) {
break;
}
top++;
}
int bottom = 0;
for (int y = bi.getHeight() - 1; y > 0; y--) {
int pixel = bi.getRGB(0, y);
if ((pixel & 0xff000000) == 0xff000000) {
break;
}
bottom++;
}
bi = bi.getSubimage(1, 1, bi.getWidth() - 2, bi.getHeight() - 2);
top--;
bottom--;
left--;
right--;
BufferedImage topLeft = bi.getSubimage(0, 0, left, top);
BufferedImage topRight = bi.getSubimage(bi.getWidth() - right, 0, right, top);
BufferedImage bottomLeft = bi.getSubimage(0, bi.getHeight() - bottom, left, bottom);
BufferedImage bottomRight = bi.getSubimage(bi.getWidth() - right, bi.getHeight() - bottom, right, bottom);
BufferedImage center = bi.getSubimage(left, top, bi.getWidth() - right - left, bi.getHeight() - bottom - top);
BufferedImage topImage = bi.getSubimage(left, 0, bi.getWidth() - left - right, top);
BufferedImage bottomImage = bi.getSubimage(left, bi.getHeight() - bottom, bi.getWidth() - left - right, bottom);
BufferedImage leftImage = bi.getSubimage(0, top, left, bi.getHeight() - top - bottom);
BufferedImage rightImage = bi.getSubimage(bi.getWidth() - right, top, right, bi.getHeight() - top - bottom);
topLeftCodenameOne.add(com.codename1.ui.EncodedImage.create(ImageBorderCuttingWizard.toPng(topLeft)));
topRightCodenameOne.add(com.codename1.ui.EncodedImage.create(ImageBorderCuttingWizard.toPng(topRight)));
bottomLeftCodenameOne.add(com.codename1.ui.EncodedImage.create(ImageBorderCuttingWizard.toPng(bottomLeft)));
bottomRightCodenameOne.add(com.codename1.ui.EncodedImage.create(ImageBorderCuttingWizard.toPng(bottomRight)));
centerCodenameOne.add(com.codename1.ui.EncodedImage.create(ImageBorderCuttingWizard.toPng(center)));
topImageCodenameOne.add(com.codename1.ui.EncodedImage.create(ImageBorderCuttingWizard.toPng(topImage)));
bottomImageCodenameOne.add(com.codename1.ui.EncodedImage.create(ImageBorderCuttingWizard.toPng(bottomImage)));
leftImageCodenameOne.add(com.codename1.ui.EncodedImage.create(ImageBorderCuttingWizard.toPng(leftImage)));
rightImageCodenameOne.add(com.codename1.ui.EncodedImage.create(ImageBorderCuttingWizard.toPng(rightImage)));
}
String prefix = (String) uiidCombo.getSelectedItem() + ".";
switch(styleState.getSelectedIndex()) {
case 1:
prefix += "sel#";
break;
case 2:
prefix += "press#";
break;
case 3:
prefix += "dis#";
break;
}
com.codename1.ui.EncodedImage topLeftCodenameOneE = storeImage(topLeftCodenameOne, densities, prefix + " ");
com.codename1.ui.EncodedImage topRightCodenameOneE = storeImage(topRightCodenameOne, densities, prefix + " ");
com.codename1.ui.EncodedImage bottomLeftCodenameOneE = storeImage(bottomLeftCodenameOne, densities, prefix + " ");
com.codename1.ui.EncodedImage bottomRightCodenameOneE = storeImage(bottomRightCodenameOne, densities, prefix + " ");
com.codename1.ui.EncodedImage centerCodenameOneE = storeImage(centerCodenameOne, densities, prefix + " ");
com.codename1.ui.EncodedImage topImageCodenameOneE = storeImage(topImageCodenameOne, densities, prefix + " ");
com.codename1.ui.EncodedImage bottomImageCodenameOneE = storeImage(bottomImageCodenameOne, densities, prefix + " ");
com.codename1.ui.EncodedImage leftImageCodenameOneE = storeImage(leftImageCodenameOne, densities, prefix + " ");
com.codename1.ui.EncodedImage rightImageCodenameOneE = storeImage(rightImageCodenameOne, densities, prefix + " ");
com.codename1.ui.plaf.Border b = com.codename1.ui.plaf.Border.createImageScaledBorder(topImageCodenameOneE, bottomImageCodenameOneE, leftImageCodenameOneE, rightImageCodenameOneE, topLeftCodenameOneE, topRightCodenameOneE, bottomLeftCodenameOneE, bottomRightCodenameOneE, centerCodenameOneE);
Hashtable newTheme = new Hashtable(res.getTheme(theme));
newTheme.put(prefix + "border", b);
res.setTheme(theme, newTheme);
}
use of com.codename1.components.Switch in project CodenameOne by codenameone.
the class BorderEditor method updateBorder.
private void updateBorder(boolean updateEnabled) {
if (updateEnabled) {
okButton.setEnabled(true);
for (JComponent c : comboSelectionEnabled[0]) {
c.setEnabled(false);
}
if (borderType.getSelectedIndex() > 1) {
List<JComponent> colorElements = colorComponents;
if (borderType.getSelectedIndex() == 6 && !imageMode.isSelected()) {
colorElements = new ArrayList<JComponent>();
} else {
if (borderType.getSelectedIndex() < 6 && !themeColors.isSelected()) {
colorElements = new ArrayList<JComponent>();
} else {
if (borderType.getSelectedIndex() > 6) {
colorElements = new ArrayList<JComponent>();
}
}
}
for (JComponent c : comboSelectionEnabled[borderType.getSelectedIndex()]) {
// if colors arrive from the theme then don't enable any color related element
c.setEnabled(!colorElements.contains(c));
}
}
}
if (borderType.getSelectedIndex() == borderType.getItemCount() - 2) {
// we need to use a special case because a theme with no images will have a different offset for the border
currentBorder = RoundBorder.create().color(getColor(backgroundColor)).opacity(((Number) opacity.getValue()).intValue()).rectangle(isRectangle.isSelected()).shadowBlur(((Number) shadowBlur.getValue()).floatValue()).shadowOpacity(((Number) shadowOpacity.getValue()).intValue()).shadowSpread(((Number) shadowSpread.getValue()).intValue()).shadowX(((Number) shadowX.getValue()).floatValue()).shadowY(((Number) shadowY.getValue()).floatValue()).stroke(((Number) strokeThickness.getValue()).floatValue(), strokeMillimeter.isSelected()).strokeColor(getColor(strokeColor)).strokeOpacity(((Number) strokeOpacity.getValue()).intValue());
} else {
if (borderType.getSelectedIndex() == borderType.getItemCount() - 1) {
// we need to use a special case because a theme with no images will have a different offset for the border
currentBorder = RoundRectBorder.create().shadowBlur(((Number) rrShadowBlur.getValue()).floatValue()).shadowOpacity(((Number) rrShadowOpacity.getValue()).intValue()).shadowSpread(((Number) rrShadowSpread.getValue()).floatValue()).shadowX(((Number) rrShadowX.getValue()).floatValue()).shadowY(((Number) rrShadowY.getValue()).floatValue()).stroke(((Number) rrStrokeThickness.getValue()).floatValue(), rrStrokeMillimeter.isSelected()).strokeColor(getColor(rrStrokeColor)).strokeOpacity(((Number) rrStrokeOpacity.getValue()).intValue()).bezierCorners(rrBezier.isSelected()).cornerRadius(((Number) rrRadius.getValue()).floatValue());
switch(rrMode.getSelectedIndex()) {
case 1:
((RoundRectBorder) currentBorder).topOnlyMode(true);
break;
case 2:
((RoundRectBorder) currentBorder).bottomOnlyMode(true);
break;
}
} else {
switch(borderType.getSelectedIndex()) {
case 0:
// null border
currentBorder = null;
break;
case 1:
// empty border
currentBorder = Border.getEmpty();
break;
case 2:
// bevel border
if (themeColors.isSelected()) {
if (raisedBorder.isSelected()) {
currentBorder = Border.createBevelRaised();
} else {
currentBorder = Border.createBevelLowered();
}
} else {
if (raisedBorder.isSelected()) {
currentBorder = Border.createBevelRaised(getColor(highlightColor), getColor(secondaryHighlightColor), getColor(shadowColor), getColor(secondaryShadowColor));
} else {
currentBorder = Border.createBevelLowered(getColor(highlightColor), getColor(secondaryHighlightColor), getColor(shadowColor), getColor(secondaryShadowColor));
}
}
break;
case 3:
// etched border
if (themeColors.isSelected()) {
if (raisedBorder.isSelected()) {
currentBorder = Border.createEtchedRaised();
} else {
currentBorder = Border.createEtchedLowered();
}
} else {
if (raisedBorder.isSelected()) {
currentBorder = Border.createEtchedRaised(getColor(highlightColor), getColor(shadowColor));
} else {
currentBorder = Border.createEtchedLowered(getColor(highlightColor), getColor(shadowColor));
}
}
break;
case 7:
{
// this is a theme with no images
if (borderType.getItemCount() < 8) {
break;
}
// image border
Image c = getButtonImageBorderIcon(this.center);
if (imageMode.isSelected()) {
currentBorder = Border.createImageBorder(getButtonImageBorderIconNotNull(top), getButtonImageBorderIconNotNull(topLeft), c);
} else {
currentBorder = Border.createImageBorder(getButtonImageBorderIconNotNull(top), getButtonImageBorderIconNotNull(bottom), getButtonImageBorderIconNotNull(left), getButtonImageBorderIconNotNull(right), getButtonImageBorderIconNotNull(topLeft), getButtonImageBorderIconNotNull(topRight), getButtonImageBorderIconNotNull(bottomLeft), getButtonImageBorderIconNotNull(bottomRight), c);
}
break;
}
case 8:
{
Image c = getButtonImageBorderIcon(this.center);
currentBorder = Border.createHorizonalImageBorder(getButtonImageBorderIconNotNull(left), getButtonImageBorderIconNotNull(right), c);
break;
}
case 9:
{
Image c = getButtonImageBorderIcon(this.center);
currentBorder = Border.createVerticalImageBorder(getButtonImageBorderIconNotNull(top), getButtonImageBorderIconNotNull(bottom), c);
break;
}
case 4:
// line border
if (thicknessMillimeters.isSelected()) {
if (themeColors.isSelected()) {
currentBorder = Border.createLineBorder(((Number) thickness.getValue()).floatValue());
} else {
currentBorder = Border.createLineBorder(((Number) thickness.getValue()).floatValue(), getColor(lineColor));
}
} else {
if (themeColors.isSelected()) {
currentBorder = Border.createLineBorder(((Number) thickness.getValue()).intValue());
} else {
currentBorder = Border.createLineBorder(((Number) thickness.getValue()).intValue(), getColor(lineColor));
}
}
break;
case 5:
// underline border
if (thicknessMillimeters.isSelected()) {
if (themeColors.isSelected()) {
currentBorder = Border.createUnderlineBorder(((Number) thickness.getValue()).floatValue());
} else {
currentBorder = Border.createUnderlineBorder(((Number) thickness.getValue()).floatValue(), getColor(lineColor));
}
} else {
if (themeColors.isSelected()) {
currentBorder = Border.createUnderlineBorder(((Number) thickness.getValue()).intValue());
} else {
currentBorder = Border.createUnderlineBorder(((Number) thickness.getValue()).intValue(), getColor(lineColor));
}
}
break;
case 6:
// rounded border
if (themeColors.isSelected()) {
currentBorder = Border.createRoundBorder(((Number) arcWidth.getValue()).intValue(), ((Number) arcHeight.getValue()).intValue());
} else {
currentBorder = Border.createRoundBorder(((Number) arcWidth.getValue()).intValue(), ((Number) arcHeight.getValue()).intValue(), getColor(lineColor));
}
break;
}
}
}
final CodenameOneComponentWrapper w = (CodenameOneComponentWrapper) imageBorderPreview;
final Border finalBorder = currentBorder;
final Button b = (Button) w.getCodenameOneComponent();
Display.getInstance().callSerially(new Runnable() {
@Override
public void run() {
b.clearClientProperties();
b.setPreferredSize(new com.codename1.ui.geom.Dimension(200, 100));
b.getAllStyles().setPadding(20, 20, 20, 20);
b.getAllStyles().setBorder(finalBorder);
b.getParent().revalidate();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
w.revalidate();
}
});
}
});
}
use of com.codename1.components.Switch in project CodenameOne by codenameone.
the class SimpleDateFormat method format.
@Override
String format(Date source, StringBuilder toAppendTo) {
if (pattern == null) {
return super.format(source, toAppendTo);
}
// format based on local timezone
Calendar calendar = Calendar.getInstance(TimeZone.getDefault());
calendar.setTime(source);
List<String> pattern = getPatternTokens();
for (int i = 0; i < pattern.size(); i++) {
String token = (String) pattern.get(i);
char patternChar = token.charAt(0);
token = token.substring(1);
int len = token.length();
int v = -1;
switch(patternChar) {
case LITERAL_LETTER:
toAppendTo.append(token);
break;
case AMPM_LETTER:
boolean am = calendar.get(Calendar.AM_PM) == Calendar.AM;
String[] ampm = getDateFormatSymbols().getAmPmStrings();
toAppendTo.append(am ? ampm[0] : ampm[1]);
break;
case ERA_LETTER:
toAppendTo.append(getDateFormatSymbols().getEras()[calendar.get(ERA)]);
break;
case DAY_OF_WEEK_LETTER:
v = calendar.get(Calendar.DAY_OF_WEEK) - 1;
if (len > 3) {
toAppendTo.append(getDateFormatSymbols().getWeekdays()[v]);
} else {
toAppendTo.append(getDateFormatSymbols().getShortWeekdays()[v]);
}
break;
case TIMEZONE_LETTER:
String[] names = getTimeZoneDisplayNames(calendar.getTimeZone().getID());
if (names == null) {
toAppendTo.append(calendar.getTimeZone().getID());
} else {
DateUtil du = new DateUtil(TimeZone.getTimeZone(names[DateFormatSymbols.ZONE_ID]));
toAppendTo.append(names[du.inDaylightTime(source) ? DateFormatSymbols.ZONE_SHORTNAME_DST : DateFormatSymbols.ZONE_SHORTNAME]);
}
break;
case TIMEZONE822_LETTER:
v = getOffsetInMinutes(calendar, calendar.getTimeZone());
if (v < 0) {
toAppendTo.append(SIGN_NEGATIVE);
v = -v;
} else {
toAppendTo.append(SIGN_POSITIVE);
}
toAppendTo.append(leftPad(v / 60, 2));
toAppendTo.append(leftPad(v % 60, 2));
break;
case YEAR_LETTER:
v = calendar.get(Calendar.YEAR);
if (len == 2) {
v %= 100;
}
toAppendTo.append(leftPad(v, len));
break;
case MONTH_LETTER:
v = calendar.get(Calendar.MONTH) - Calendar.JANUARY;
if (len > 3) {
toAppendTo.append(L10NManager.getInstance().getLongMonthName(source));
} else if (len == 3) {
toAppendTo.append(L10NManager.getInstance().getShortMonthName(source));
} else {
toAppendTo.append(leftPad(v + 1, len));
}
break;
case DAY_LETTER:
v = calendar.get(Calendar.DAY_OF_MONTH);
toAppendTo.append(leftPad(v, len));
break;
case HOUR_LETTER:
case HOUR_1_LETTER:
case HOUR12_LETTER:
case HOUR12_1_LETTER:
v = calendar.get(Calendar.HOUR_OF_DAY);
if (patternChar == HOUR_1_LETTER && v == 0) {
v = 24;
}
if (patternChar == HOUR12_1_LETTER) {
v %= 12;
if (v == 0) {
v = 12;
}
} else {
if (patternChar == HOUR12_LETTER) {
v %= 12;
}
}
toAppendTo.append(leftPad(v, len));
break;
case MINUTE_LETTER:
v = calendar.get(Calendar.MINUTE);
toAppendTo.append(leftPad(v, len));
break;
case SECOND_LETTER:
v = calendar.get(Calendar.SECOND);
toAppendTo.append(leftPad(v, len));
break;
case MILLISECOND_LETTER:
v = calendar.get(Calendar.MILLISECOND);
toAppendTo.append(leftPad(v, len));
break;
case WEEK_IN_YEAR_LETTER:
v = calendar.get(WEEK_OF_YEAR);
toAppendTo.append(leftPad(v, len));
break;
case WEEK_IN_MONTH_LETTER:
v = calendar.get(WEEK_OF_MONTH);
toAppendTo.append(leftPad(v, len));
break;
case DAY_IN_YEAR_LETTER:
v = calendar.get(DAY_OF_YEAR);
toAppendTo.append(leftPad(v, len));
break;
case DOW_IN_MONTH_LETTER:
v = calendar.get(DAY_OF_WEEK_IN_MONTH);
toAppendTo.append(leftPad(v, len));
break;
}
}
return toAppendTo.toString();
}
use of com.codename1.components.Switch in project CodenameOne by codenameone.
the class CSSBgPainter method paint.
/**
* {@inheritDoc}
*/
public void paint(Graphics g, Rectangle rect) {
Style s = parent.getStyle();
int x = rect.getX();
int y = rect.getY();
int width = rect.getSize().getWidth();
int height = rect.getSize().getHeight();
if (width <= 0 || height <= 0) {
return;
}
g.setColor(s.getBgColor());
g.fillRect(x, y, width, height, s.getBgTransparency());
Image bgImage = s.getBgImage();
if (bgImage == null) {
return;
}
if (fixedX) {
if (scrollableParent == null) {
scrollableParent = getScrollableParent(parent);
}
if (scrollableParent != null) {
x += scrollableParent.getScrollX();
y += scrollableParent.getScrollY();
width = scrollableParent.getWidth();
height = scrollableParent.getHeight();
}
}
int iW = bgImage.getWidth();
int iH = bgImage.getHeight();
int offsetX = horizPos;
int offsetY = vertPos;
if (horizIsPercentage) {
offsetX = (width - iW) * offsetX / 100;
}
if (vertIsPercentage) {
offsetY = (height - iH) * offsetY / 100;
}
switch(s.getBackgroundType()) {
case 0:
g.drawImage(s.getBgImage(), x + offsetX, y + offsetY);
return;
case Style.BACKGROUND_IMAGE_TILE_BOTH:
for (int xPos = getTiledPosition(offsetX, iW); xPos <= width; xPos += iW) {
for (int yPos = getTiledPosition(offsetY, iH); yPos <= height; yPos += iH) {
g.drawImage(s.getBgImage(), x + xPos, y + yPos);
}
}
return;
case Style.BACKGROUND_IMAGE_TILE_HORIZONTAL:
for (int xPos = getTiledPosition(offsetX, iW); xPos <= width; xPos += iW) {
g.drawImage(s.getBgImage(), x + xPos, y + offsetY);
}
return;
case Style.BACKGROUND_IMAGE_TILE_VERTICAL:
for (int yPos = getTiledPosition(offsetY, iH); yPos <= height; yPos += iH) {
g.drawImage(s.getBgImage(), x + offsetX, y + yPos);
}
return;
}
}
Aggregations