use of com.codename1.rad.ui in project CodenameOne by codenameone.
the class ImageMultiEditor method pickFile.
private void pickFile(File selection) {
try {
byte[] data = new byte[(int) selection.length()];
DataInputStream di = new DataInputStream(new FileInputStream(selection));
di.readFully(data);
di.close();
com.codename1.ui.EncodedImage i = com.codename1.ui.EncodedImage.create(data);
int[] dpis = multi.getDpi();
int dpi = DPIS[this.dpi.getSelectedIndex()];
com.codename1.ui.EncodedImage[] imgs = multi.getInternalImages();
for (int iter = 0; iter < dpis.length; iter++) {
if (dpis[iter] == dpi) {
com.codename1.ui.EncodedImage[] newImages = new com.codename1.ui.EncodedImage[imgs.length];
System.arraycopy(imgs, 0, newImages, 0, imgs.length);
newImages[iter] = i;
multi = new EditableResources.MultiImage();
multi.setDpi(dpis);
multi.setInternalImages(newImages);
res.setMultiImage(name, multi);
setImage(multi);
return;
}
}
com.codename1.ui.EncodedImage[] newImages = new com.codename1.ui.EncodedImage[imgs.length + 1];
System.arraycopy(imgs, 0, newImages, 0, imgs.length);
newImages[imgs.length] = i;
int[] newDpis = new int[dpis.length + 1];
System.arraycopy(dpis, 0, newDpis, 0, dpis.length);
newDpis[dpis.length] = dpi;
multi = new EditableResources.MultiImage();
multi.setDpi(newDpis);
multi.setInternalImages(newImages);
res.setMultiImage(name, multi);
setImage(multi);
} catch (IOException ex) {
JOptionPane.showMessageDialog(this, "An error occured while trying to load the file:\n" + ex, "IO Error", JOptionPane.ERROR_MESSAGE);
}
}
use of com.codename1.rad.ui 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.rad.ui in project CodenameOne by codenameone.
the class FindMultiImages method updateLabelImages.
// GEN-LAST:event_select4kDensityActionPerformed
private void updateLabelImages(JLabel l, int dpi) {
File dir = new File(l.getText());
if (dir.exists() && dir.isDirectory()) {
File[] fileList = dir.listFiles();
for (File f : fileList) {
try {
if (ImageIO.read(f) != null) {
com.codename1.ui.Image img = res.getImage(f.getName());
if (img == null) {
// create new multi-image
EditableResources.MultiImage newImage = new EditableResources.MultiImage();
newImage.setDpi(new int[] { dpi });
newImage.setInternalImages(new com.codename1.ui.EncodedImage[] { com.codename1.ui.EncodedImage.create(new FileInputStream(f)) });
res.setMultiImage(f.getName(), newImage);
} else {
// verify this is a multi-image
Object o = res.getResourceObject(f.getName());
if (o instanceof EditableResources.MultiImage) {
EditableResources.MultiImage existing = (EditableResources.MultiImage) o;
EditableResources.MultiImage newImage = new EditableResources.MultiImage();
int[] dpis = new int[existing.getDpi().length + 1];
System.arraycopy(existing.getDpi(), 0, dpis, 0, existing.getDpi().length);
dpis[existing.getDpi().length] = dpi;
com.codename1.ui.EncodedImage[] images = new com.codename1.ui.EncodedImage[existing.getDpi().length + 1];
System.arraycopy(existing.getInternalImages(), 0, images, 0, existing.getDpi().length);
images[existing.getDpi().length] = com.codename1.ui.EncodedImage.create(new FileInputStream(f));
newImage.setDpi(dpis);
newImage.setInternalImages(images);
res.setMultiImage(f.getName(), newImage);
}
}
}
} catch (IOException ex) {
// not an image file proceed
}
}
}
}
use of com.codename1.rad.ui 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.rad.ui in project CodenameOne by codenameone.
the class RequestBuilder method createRequest.
private Connection createRequest(boolean parseJson) {
Connection req = new Connection(parseJson);
for (String key : pathParams.keySet()) {
url = com.codename1.util.StringUtil.replaceAll(url, "{" + key + "}", pathParams.get(key));
}
if (contentType != null) {
req.setContentType(contentType);
}
req.setFailSilently(false);
if (cache != null) {
req.setCacheMode(cache);
}
req.setReadResponseForErrors(true);
req.setDuplicateSupported(true);
req.setUrl(url);
req.setHttpMethod(method);
if (postParameters == null) {
req.setPost(method.equalsIgnoreCase("POST") || method.equalsIgnoreCase("PUT") || method.equalsIgnoreCase("PATCH"));
} else {
req.setPost(postParameters);
}
if (body != null) {
req.setRequestBody(body);
req.setWriteRequest(true);
}
if (timeout != null) {
req.setTimeout(timeout);
}
if (readTimeout != null) {
req.setReadTimeout(readTimeout);
}
for (String key : queryParams.keySet()) {
Object value = queryParams.get(key);
if (value instanceof String[]) {
req.addArgument(key, (String[]) value);
} else {
req.addArgument(key, (String) value);
}
}
for (String key : headers.keySet()) {
req.addRequestHeader(key, headers.get(key));
}
for (ActionListener<NetworkEvent> l : errorCallbacks) {
req.addExceptionListener(l);
}
req.setInsecure(insecure);
if (cookiesEnabled != null) {
req.setCookiesEnabled(cookiesEnabled);
}
if (priority != null) {
req.setPriority(priority);
}
return req;
}
Aggregations