use of com.codename1.ui in project CodenameOne by codenameone.
the class AddUIResource method addResource.
// GEN-LAST:event_templateActionPerformed
public String addResource(EditableResources res, ResourceEditorView view) {
String newName = name.getText();
for (String r : res.getResourceNames()) {
if (r.equalsIgnoreCase(newName)) {
JOptionPane.showMessageDialog(this, "A resource called: " + newName + " already exists\nYou must delete the resource first.", "Add Resource", JOptionPane.ERROR_MESSAGE);
return null;
}
}
Object ui = null;
InputStream is = getClass().getResourceAsStream("/templates/" + template.getSelectedItem().toString() + ".res");
if (is != null) {
try {
EditableResources r = new EditableResources();
r.openFile(is);
is.close();
ui = r.getResourceObject("Main");
r.remove("Main");
view.checkDuplicateResourcesLoop(r, res.getImageResourceNames(), r.getImageResourceNames(), "Rename Image", "Image ", true);
view.checkDuplicateResourcesLoop(r, res.getL10NResourceNames(), r.getL10NResourceNames(), "Rename Localization", "Localization ", true);
view.checkDuplicateResourcesLoop(r, res.getDataResourceNames(), r.getDataResourceNames(), "Rename Data", "Data ", true);
view.checkDuplicateResourcesLoop(r, res.getUIResourceNames(), r.getUIResourceNames(), "Rename GUI", "GUI ", true);
view.checkDuplicateResourcesLoop(r, res.getFontResourceNames(), r.getFontResourceNames(), "Rename Font", "Font ", true);
for (String s : r.getImageResourceNames()) {
res.setImage(s, r.getImage(s));
}
for (String s : r.getL10NResourceNames()) {
res.setL10N(s, (Hashtable) r.getResourceObject(s));
}
for (String s : r.getDataResourceNames()) {
res.setData(s, (byte[]) r.getResourceObject(s));
}
for (String s : r.getUIResourceNames()) {
res.setUi(s, (byte[]) r.getResourceObject(s));
}
for (String s : r.getFontResourceNames()) {
res.setFont(s, r.getFont(s));
}
} catch (IOException err) {
err.printStackTrace();
}
}
res.setUi(name.getText(), (byte[]) ui);
view.setSelectedResource(name.getText());
return name.getText();
}
use of com.codename1.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.ui in project CodenameOne by codenameone.
the class ImageBorderCuttingWizard method generate.
// GEN-LAST:event_multiImageComboActionPerformed
public void generate() {
if (applies.getAppliesTo().getModel().getSize() == 0) {
JOptionPane.showMessageDialog(this, "You haven't selected components to apply this border to!\nPlease go to the apply tab and ADD component types/styles", "No Components Selected", JOptionPane.ERROR_MESSAGE);
return;
}
BufferedImage img = wiz.getImage();
BufferedImage buff = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D bg2d = buff.createGraphics();
bg2d.drawImage(img.getSubimage(get(cropLeft), get(cropTop), img.getWidth() - get(cropLeft) - get(cropRight), img.getHeight() - get(cropTop) - get(cropBottom)), get(cropLeft), get(cropTop), null);
bg2d.dispose();
img = buff;
BufferedImage topLeft = img.getSubimage(0, 0, get(left), get(top));
BufferedImage topRight = img.getSubimage(img.getWidth() - get(right), 0, get(right), get(top));
BufferedImage bottomLeft = img.getSubimage(0, img.getHeight() - get(bottom), get(left), get(bottom));
BufferedImage bottomRight = img.getSubimage(img.getWidth() - get(right), img.getHeight() - get(bottom), get(right), get(bottom));
BufferedImage center = img.getSubimage(get(left), get(top), img.getWidth() - get(right) - get(left), img.getHeight() - get(bottom) - get(top));
BufferedImage topImage = img.getSubimage(get(left), 0, img.getWidth() - get(left) - get(right), get(top));
BufferedImage bottomImage = img.getSubimage(get(left), img.getHeight() - get(bottom), img.getWidth() - get(left) - get(right), get(bottom));
BufferedImage leftImage = img.getSubimage(0, get(top), get(left), img.getHeight() - get(top) - get(bottom));
BufferedImage rightImage = img.getSubimage(img.getWidth() - get(right), get(top), get(right), img.getHeight() - get(top) - get(bottom));
// optimize the size of the center/top/left/bottom/right images which is a HUGE performance deterant
if (center.getWidth() < 10 || center.getHeight() < 10) {
center = ImageTools.getScaledInstance(center, Math.max(20, center.getWidth()), Math.max(20, center.getHeight()));
topImage = ImageTools.getScaledInstance(topImage, Math.max(20, topImage.getWidth()), topImage.getHeight());
leftImage = ImageTools.getScaledInstance(leftImage, leftImage.getWidth(), Math.max(20, leftImage.getHeight()));
rightImage = ImageTools.getScaledInstance(rightImage, rightImage.getWidth(), Math.max(20, rightImage.getHeight()));
bottomImage = ImageTools.getScaledInstance(bottomImage, Math.max(20, bottomImage.getWidth()), bottomImage.getHeight());
}
com.codename1.ui.EncodedImage topLeftCodenameOne = com.codename1.ui.EncodedImage.create(toPng(topLeft));
com.codename1.ui.EncodedImage topRightCodenameOne = com.codename1.ui.EncodedImage.create(toPng(topRight));
com.codename1.ui.EncodedImage bottomLeftCodenameOne = com.codename1.ui.EncodedImage.create(toPng(bottomLeft));
com.codename1.ui.EncodedImage bottomRightCodenameOne = com.codename1.ui.EncodedImage.create(toPng(bottomRight));
com.codename1.ui.EncodedImage centerCodenameOne = com.codename1.ui.EncodedImage.create(toPng(center));
com.codename1.ui.EncodedImage topImageCodenameOne = com.codename1.ui.EncodedImage.create(toPng(topImage));
com.codename1.ui.EncodedImage bottomImageCodenameOne = com.codename1.ui.EncodedImage.create(toPng(bottomImage));
com.codename1.ui.EncodedImage leftImageCodenameOne = com.codename1.ui.EncodedImage.create(toPng(leftImage));
com.codename1.ui.EncodedImage rightImageCodenameOne = com.codename1.ui.EncodedImage.create(toPng(rightImage));
String prefix = (String) applies.getAppliesTo().getModel().getElementAt(0);
topLeftCodenameOne = storeImage(topLeftCodenameOne, prefix + "TopL");
topRightCodenameOne = storeImage(topRightCodenameOne, prefix + "TopR");
bottomLeftCodenameOne = storeImage(bottomLeftCodenameOne, prefix + "BottomL");
bottomRightCodenameOne = storeImage(bottomRightCodenameOne, prefix + "BottomR");
centerCodenameOne = storeImage(centerCodenameOne, prefix + "Center");
topImageCodenameOne = storeImage(topImageCodenameOne, prefix + "Top");
bottomImageCodenameOne = storeImage(bottomImageCodenameOne, prefix + "Bottom");
leftImageCodenameOne = storeImage(leftImageCodenameOne, prefix + "Left");
rightImageCodenameOne = storeImage(rightImageCodenameOne, prefix + "Right");
com.codename1.ui.plaf.Border b = com.codename1.ui.plaf.Border.createImageBorder(topImageCodenameOne, bottomImageCodenameOne, leftImageCodenameOne, rightImageCodenameOne, topLeftCodenameOne, topRightCodenameOne, bottomLeftCodenameOne, bottomRightCodenameOne, centerCodenameOne);
Hashtable newTheme = new Hashtable(res.getTheme(theme));
for (int i = 0; i < applies.getAppliesTo().getModel().getSize(); i++) {
newTheme.put(applies.getAppliesTo().getModel().getElementAt(i), b);
}
((DefaultListModel) applies.getAppliesTo().getModel()).removeAllElements();
res.setTheme(theme, newTheme);
}
use of com.codename1.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.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
}
}
}
}
Aggregations