use of com.codename1.ui.animations.Timeline in project CodenameOne by codenameone.
the class EditableResources method writeTimeline.
private void writeTimeline(DataOutputStream output, Timeline t) throws IOException {
output.writeInt(t.getDuration());
output.writeInt(t.getSize().getWidth());
output.writeInt(t.getSize().getHeight());
AnimationObject[] animations = new AnimationObject[t.getAnimationCount()];
output.writeShort(animations.length);
for (int iter = 0; iter < animations.length; iter++) {
animations[iter] = t.getAnimation(iter);
String name = AnimationAccessor.getImageName(animations[iter]);
if (name == null) {
name = findId(AnimationAccessor.getImage(animations[iter]));
}
output.writeUTF(name);
int startTime = animations[iter].getStartTime();
int animDuration = animations[iter].getEndTime() - startTime;
output.writeInt(startTime);
output.writeInt(animDuration);
Motion motionX = AnimationAccessor.getMotionX(animations[iter]);
Motion motionY = AnimationAccessor.getMotionY(animations[iter]);
output.writeInt(motionX.getSourceValue());
output.writeInt(motionY.getSourceValue());
int frameDelay = AnimationAccessor.getFrameDelay(animations[iter]);
output.writeInt(frameDelay);
if (frameDelay > -1) {
output.writeInt(AnimationAccessor.getFrameWidth(animations[iter]));
output.writeInt(AnimationAccessor.getFrameHeight(animations[iter]));
}
if (motionX.getSourceValue() != motionX.getDestinationValue()) {
output.writeBoolean(true);
output.writeInt(AnimationAccessor.getMotionType(motionX));
output.writeInt(motionX.getDestinationValue());
} else {
output.writeBoolean(false);
}
if (motionY.getSourceValue() != motionY.getDestinationValue()) {
output.writeBoolean(true);
output.writeInt(AnimationAccessor.getMotionType(motionY));
output.writeInt(motionY.getDestinationValue());
} else {
output.writeBoolean(false);
}
writeMotion(AnimationAccessor.getWidth(animations[iter]), output);
writeMotion(AnimationAccessor.getHeight(animations[iter]), output);
writeMotion(AnimationAccessor.getOpacity(animations[iter]), output);
writeMotion(AnimationAccessor.getOrientation(animations[iter]), output);
}
}
use of com.codename1.ui.animations.Timeline in project CodenameOne by codenameone.
the class ImageRGBEditor method findImageUseImpl.
private static void findImageUseImpl(com.codename1.ui.Image resourceValue, Vector users, EditableResources res, JLabel borderPreview) {
for (String themeName : res.getThemeResourceNames()) {
Hashtable theme = res.getTheme(themeName);
for (Object key : theme.keySet()) {
Object value = theme.get(key);
if (value instanceof com.codename1.ui.Image) {
if (value.equals(resourceValue)) {
addToUsers((String) key, users);
}
}
if (value instanceof Border) {
Border b = (Border) value;
// BORDER_TYPE_IMAGE
if (Accessor.getType(b) == Accessor.TYPE_IMAGE || Accessor.getType(b) == Accessor.TYPE_IMAGE_HORIZONTAL || Accessor.getType(b) == Accessor.TYPE_IMAGE_VERTICAL) {
com.codename1.ui.Image[] images = Accessor.getImages(b);
for (int i = 0; i < images.length; i++) {
if (images[i] == resourceValue) {
addToUsers((String) key, users);
if (borderPreview != null && borderPreview.getIcon() == null) {
int borderWidth = Math.max(100, b.getMinimumWidth());
int borderHeight = Math.max(100, b.getMinimumHeight());
com.codename1.ui.Image img = com.codename1.ui.Image.createImage(borderWidth, borderHeight);
com.codename1.ui.Label l = new com.codename1.ui.Label("Preview");
l.getStyle().setBorder(b);
l.setSize(new com.codename1.ui.geom.Dimension(borderWidth, borderHeight));
l.paintComponent(img.getGraphics());
CodenameOneImageIcon icon = new CodenameOneImageIcon(img, borderWidth, borderHeight);
borderPreview.setIcon(icon);
}
}
}
}
}
}
}
// check if a timeline is making use of said image and replace it
for (String image : res.getImageResourceNames()) {
com.codename1.ui.Image current = res.getImage(image);
if (current instanceof com.codename1.ui.animations.Timeline) {
com.codename1.ui.animations.Timeline time = (com.codename1.ui.animations.Timeline) current;
for (int iter = 0; iter < time.getAnimationCount(); iter++) {
com.codename1.ui.animations.AnimationObject o = time.getAnimation(iter);
if (AnimationAccessor.getImage(o) == resourceValue) {
addToUsers(image, users);
}
}
}
}
// check if a UI resource is making use of the image
UIBuilderOverride builder = new UIBuilderOverride();
for (String uiResource : res.getUIResourceNames()) {
com.codename1.ui.Container c = builder.createContainer(res, uiResource);
if (ResourceEditorView.findImageInContainer(c, resourceValue)) {
addToUsers(uiResource, users);
}
}
}
use of com.codename1.ui.animations.Timeline in project CodenameOne by codenameone.
the class ResourceEditorView method removeImageOrAnimation.
private void removeImageOrAnimation(String resourceToRemove) {
Object resourceValue = loadedResources.getImage(resourceToRemove);
if (!loadedResources.isOverrideMode()) {
for (String themeName : loadedResources.getThemeResourceNames()) {
Hashtable theme = loadedResources.getTheme(themeName);
if (theme.values().contains(resourceValue)) {
JOptionPane.showMessageDialog(mainPanel, "Image is in use by the theme" + "\nYou must remove it from the theme first", "Image In Use", JOptionPane.ERROR_MESSAGE);
return;
}
// we need to check the existance of image borders to replace images there...
for (Object v : theme.values()) {
if (v instanceof Border) {
Border b = (Border) v;
// BORDER_TYPE_IMAGE
if (Accessor.getType(b) == 8) {
com.codename1.ui.Image[] images = Accessor.getImages(b);
for (int i = 0; i < images.length; i++) {
if (images[i] == resourceValue) {
JOptionPane.showMessageDialog(mainPanel, "Image is in use by the theme in a border" + "\nYou must remove it from the theme first", "Image In Use", JOptionPane.ERROR_MESSAGE);
return;
}
}
}
}
}
}
// check if a timeline is making use of said image and replace it
for (String image : loadedResources.getImageResourceNames()) {
com.codename1.ui.Image current = loadedResources.getImage(image);
if (current instanceof com.codename1.ui.animations.Timeline) {
com.codename1.ui.animations.Timeline time = (com.codename1.ui.animations.Timeline) current;
for (int iter = 0; iter < time.getAnimationCount(); iter++) {
com.codename1.ui.animations.AnimationObject o = time.getAnimation(iter);
if (AnimationAccessor.getImage(o) == resourceValue) {
JOptionPane.showMessageDialog(mainPanel, "Image is in use by a timeline: " + image, "Image In Use", JOptionPane.ERROR_MESSAGE);
return;
}
}
}
}
if (isInUse(loadedResources.getImage(resourceToRemove))) {
JOptionPane.showMessageDialog(mainPanel, "Image is in use in the resource file", "Image In Use", JOptionPane.ERROR_MESSAGE);
return;
}
}
removeSelection(resourceToRemove);
imageList.refresh();
imageListMain.refresh();
imageListSVG.refresh();
imageListMulti.refresh();
imageListTimeline.refresh();
}
use of com.codename1.ui.animations.Timeline in project CodenameOne by codenameone.
the class TimelineEditor method removeAnimationObjectActionPerformed.
// GEN-LAST:event_addAnimationObjectActionPerformed
private void removeAnimationObjectActionPerformed(java.awt.event.ActionEvent evt) {
// GEN-FIRST:event_removeAnimationObjectActionPerformed
Timeline t = (Timeline) res.getImage(name);
AnimationObject[] animations = new AnimationObject[t.getAnimationCount() - 1];
int offset = 0;
for (int iter = 0; iter < t.getAnimationCount(); iter++) {
if (iter != animationObjectList.getSelectedRow()) {
animations[offset] = t.getAnimation(iter);
offset++;
}
}
((AnimationObjectTableModel) animationObjectList.getModel()).remove(animationObjectList.getSelectedRow());
Timeline nt = Timeline.createTimeline(getValue(duration), animations, new com.codename1.ui.geom.Dimension(getValue(width), getValue(height)));
nt.setPause(t.isPause());
setImage(nt);
animationObjectList.clearSelection();
duplicateObject.setEnabled(false);
moveDown.setEnabled(false);
moveUp.setEnabled(false);
removeAnimationObject.setEnabled(false);
}
use of com.codename1.ui.animations.Timeline in project CodenameOne by codenameone.
the class TimelineEditor method timelineStateChanged.
// GEN-LAST:event_heightStateChanged
private void timelineStateChanged(javax.swing.event.ChangeEvent evt) {
// GEN-FIRST:event_timelineStateChanged
currentTime.setText("" + timeline.getValue());
if (!refreshingTimelineLock) {
Timeline t = (Timeline) renderer.getImage();
t.setPause(false);
t.setTime(timeline.getValue());
renderer.updateAnimation();
t.setPause(true);
}
}
Aggregations