use of com.codename1.ui.Image in project CodenameOne by codenameone.
the class CodenameOneImageRenderer method mouseClicked.
public void mouseClicked(MouseEvent e) {
Timeline t = (Timeline) image;
AnimationObject selection = t.getAnimationAt(e.getX(), e.getY());
// editing
if (selection == null) {
animationObjectList.clearSelection();
} else {
if (e.getClickCount() == 2) {
selectValue(selection);
MouseListener[] ls = animationObjectList.getListeners(MouseListener.class);
for (MouseListener l : ls) {
l.mouseClicked(e);
}
} else {
// selection
selectValue(selection);
}
}
repaint();
}
use of com.codename1.ui.Image in project CodenameOne by codenameone.
the class CodenameOneImageRenderer method mouseReleased.
public void mouseReleased(MouseEvent e) {
Timeline t = (Timeline) image;
if (dragging != null && t.isPause()) {
// if this is a right mouse button update the source position
editor.updatePosition(e.getX(), e.getY(), dragging, BaseForm.isRightClick(e));
dragging = null;
}
repaint();
}
use of com.codename1.ui.Image in project CodenameOne by codenameone.
the class CodenameOneImageRenderer method mouseDragged.
public void mouseDragged(MouseEvent e) {
Timeline t = (Timeline) image;
if (t.isPause()) {
if (dragging == null) {
dragging = t.getAnimationAt(e.getX(), e.getY());
if (dragging == null) {
return;
}
}
dragX = e.getX();
dragY = e.getY();
repaint();
}
}
use of com.codename1.ui.Image 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.ui.Image 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()).bottomOnlyMode(rrMode.getSelectedIndex() == 1).topOnlyMode(rrMode.getSelectedIndex() == 2);
} 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.createUndelineBorder(((Number) thickness.getValue()).floatValue());
} else {
currentBorder = Border.createUnderlineBorder(((Number) thickness.getValue()).floatValue(), getColor(lineColor));
}
} else {
if (themeColors.isSelected()) {
currentBorder = Border.createUndelineBorder(((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();
}
});
}
});
}
Aggregations