package org.tizen.webuibuilder.animator.ui.views.timeline.tree;
-import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.layout.FormAttachment;
-import org.eclipse.swt.layout.FormData;
-import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Label;
import org.tizen.webuibuilder.BuilderConstants;
import org.tizen.webuibuilder.animator.model.AnimatorKeyframe;
import org.tizen.webuibuilder.animator.model.AnimatorModel;
* This class is SWT Composite. This composite is be in TreeItem of fourth TreeColumn. This
* composite display all play time, start time and end time of current widget's animations.
*/
-public class TimelineWidgetElement extends Composite {
+public class TimelineWidgetElement extends Canvas {
- private final int IMAGE_BLANK = 3;
- private final int LABEL_BLANK = 15;
-
- private Label animationCountImage = null;
- private Label animationCountLabel = null;
- private Label playTimeImage = null;
- private Label playTimeLabel = null;
- private Label startTimeImage = null;
- private Label startTimeLabel = null;
- private Label endTimeImage = null;
- private Label endTimeLabel = null;
+ private Image animationsCountImage = null;
+ private String animationsCountText = null;
+ private Image playTimeImage = null;
+ private String playTimeText = null;
+ private Image startTimeImage = null;
+ private String startTimeText = null;
+ private Image endTimeImage = null;
+ private String endTimeText = null;
private TimelineEditPart editpart = null;
createControls();
- addPaintListener(new PaintListener() {
- @Override
- public void paintControl(PaintEvent e) {
- Rectangle clientArea = getClientArea();
-
- boolean isLock = TimelineWidgetElement.this.editpart.isLock();
- boolean isSelected = TimelineWidgetElement.this.editpart.isSelected();
-
- e.gc.setForeground(ColorResource.TREEITEM_BORDER);
-
- if (isLock) {
- setBackground(ColorResource.PARENT_TREEITEM_LOCKED);
-
- } else if (isSelected) {
- setBackground(ColorResource.PARENT_TREEITEM_SELECTED);
-
- } else {
- Color foreground = e.gc.getForeground();
-
- e.gc.setBackground(ColorResource.PARENT_TREEITEM_BACKGROUND);
- e.gc.setForeground(ColorResource.PARENT_TREEITEM_FOREGROUND);
- e.gc.fillGradientRectangle(clientArea.x, clientArea.y, clientArea.width,
- clientArea.height, true);
-
- e.gc.setForeground(foreground);
- }
-
- e.gc.drawRectangle(clientArea.x, clientArea.y, clientArea.width - 1,
- clientArea.height - 1);
- }
- });
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.swt.widgets.Control#redraw()
- */
- @Override
- public void redraw() {
- super.redraw();
- childredraw();
+ addPaintListener(widgetElementPaint);
}
/**
* Create Controls
*/
private void createControls() {
- this.setLayout(new FormLayout());
-
- // Animation Count ------------------------------------------------------------------------
- // Image
- animationCountImage = new Label(this, SWT.NONE);
- animationCountImage.setBackground(ColorResource.PARENT_TREEITEM);
- animationCountImage.setImage(ResourceManager
- .getImage(BuilderConstants.ICON_DIR, "animator_widget_animation_count.png"));
-
- FormData animationCountImageFormData = new FormData();
- animationCountImageFormData.top = new FormAttachment(0, 4);
- animationCountImageFormData.left = new FormAttachment(0, IMAGE_BLANK);
- animationCountImage.setLayoutData(animationCountImageFormData);
- animationCountImage.addPaintListener(timelineWidgetPaintListener);
-
- // Label
- animationCountLabel = new Label(this, SWT.NONE);
- animationCountLabel.setBackground(ColorResource.PARENT_TREEITEM);
-
- FormData animationCountLabelFormData = new FormData();
- animationCountLabelFormData.top = new FormAttachment(0, 4);
- animationCountLabelFormData.left = new FormAttachment(animationCountImage, IMAGE_BLANK);
- animationCountLabel.setLayoutData(animationCountLabelFormData);
-
- animationCountLabel.setText("Animations - 0EA");
- animationCountLabel.setForeground(ColorResource.KEYFRAMEWIDGET_TEXT);
- animationCountLabel.addPaintListener(timelineWidgetPaintListener);
-
- // Play Time ------------------------------------------------------------------------
- // Image
- playTimeImage = new Label(this, SWT.NONE);
- playTimeImage.setBackground(ColorResource.PARENT_TREEITEM);
- playTimeImage.setImage(ResourceManager.getImage(BuilderConstants.ICON_DIR,
- "animator_widget_playtime.png"));
-
- FormData playTimeImageFormData = new FormData();
- playTimeImageFormData.top = new FormAttachment(0, 4);
- playTimeImageFormData.left = new FormAttachment(animationCountLabel, LABEL_BLANK);
- playTimeImage.setLayoutData(playTimeImageFormData);
- playTimeImage.addPaintListener(timelineWidgetPaintListener);
-
- // Label
- playTimeLabel = new Label(this, SWT.NONE);
- playTimeLabel.setBackground(ColorResource.PARENT_TREEITEM);
-
- FormData playTimeLabelFormData = new FormData();
- playTimeLabelFormData.top = new FormAttachment(0, 4);
- playTimeLabelFormData.left = new FormAttachment(playTimeImage, IMAGE_BLANK);
- playTimeLabel.setLayoutData(playTimeLabelFormData);
-
- playTimeLabel.setText("Play Time - 0.0s");
- playTimeLabel.setForeground(ColorResource.KEYFRAMEWIDGET_TEXT);
- playTimeLabel.addPaintListener(timelineWidgetPaintListener);
-
- // Start Time ------------------------------------------------------------------------
- // Image
- startTimeImage = new Label(this, SWT.NONE);
- startTimeImage.setBackground(ColorResource.PARENT_TREEITEM);
- startTimeImage.setImage(ResourceManager.getImage(BuilderConstants.ICON_DIR,
- "animator_widget_starttime.png"));
-
- FormData startTimeImageFormData = new FormData();
- startTimeImageFormData.top = new FormAttachment(0, 4);
- startTimeImageFormData.left = new FormAttachment(playTimeLabel, LABEL_BLANK);
- startTimeImage.setLayoutData(startTimeImageFormData);
- startTimeImage.addPaintListener(timelineWidgetPaintListener);
-
- // Label
- startTimeLabel = new Label(this, SWT.NONE);
- startTimeLabel.setBackground(ColorResource.PARENT_TREEITEM);
-
- FormData startTimeLabelFormData = new FormData();
- startTimeLabelFormData.top = new FormAttachment(0, 4);
- startTimeLabelFormData.left = new FormAttachment(startTimeImage, IMAGE_BLANK);
- startTimeLabel.setLayoutData(startTimeLabelFormData);
-
- startTimeLabel.setText("Start Time - 0.0s");
- startTimeLabel.setForeground(ColorResource.KEYFRAMEWIDGET_TEXT);
- startTimeLabel.addPaintListener(timelineWidgetPaintListener);
-
- // End Time ------------------------------------------------------------------------
- // Image
- endTimeImage = new Label(this, SWT.NONE);
- endTimeImage.setBackground(ColorResource.PARENT_TREEITEM);
- endTimeImage.setImage(ResourceManager.getImage(BuilderConstants.ICON_DIR,
- "animator_widget_endtime.png"));
-
- FormData endTimeImageFormData = new FormData();
- endTimeImageFormData.top = new FormAttachment(0, 4);
- endTimeImageFormData.left = new FormAttachment(startTimeLabel, LABEL_BLANK);
- endTimeImage.setLayoutData(endTimeImageFormData);
- endTimeImage.addPaintListener(timelineWidgetPaintListener);
-
- // Label
- endTimeLabel = new Label(this, SWT.NONE);
- endTimeLabel.setBackground(ColorResource.PARENT_TREEITEM);
-
- FormData endTimeLabelFormData = new FormData();
- endTimeLabelFormData.top = new FormAttachment(0, 4);
- endTimeLabelFormData.left = new FormAttachment(endTimeImage, IMAGE_BLANK);
- endTimeLabel.setLayoutData(endTimeLabelFormData);
-
- endTimeLabel.setText("End Time - 0.0s");
- endTimeLabel.setForeground(ColorResource.KEYFRAMEWIDGET_TEXT);
- endTimeLabel.addPaintListener(timelineWidgetPaintListener);
+ animationsCountImage =
+ ResourceManager.getImage(BuilderConstants.ICON_DIR,
+ "animator_widget_animation_count.png");
+
+ playTimeImage =
+ ResourceManager.getImage(BuilderConstants.ICON_DIR, "animator_widget_playtime.png");
+
+ startTimeImage =
+ ResourceManager
+ .getImage(BuilderConstants.ICON_DIR, "animator_widget_starttime.png");
+
+ endTimeImage =
+ ResourceManager.getImage(BuilderConstants.ICON_DIR, "animator_widget_endtime.png");
+
+ animationsCountText = "Animations - 0EA";
+ playTimeText = "Play Time - 0.000s";
+ startTimeText = "Start Time - 0.000s";
+ endTimeText = "End Time - 0.000s";
}
/**
double totalPlayTime = currentEndTime - currentStartTime;
- StringBuffer stringBuffer = new StringBuffer();
- stringBuffer.append("Animations - ");
- stringBuffer.append(totalAnimationCount + "EA");
- animationCountLabel.setText(stringBuffer.toString());
- animationCountLabel.pack();
-
- stringBuffer = new StringBuffer();
- stringBuffer.append("Play Time - ");
- String resultTotalPlayTime = String.format("%.2f", totalPlayTime);
- stringBuffer.append(Double.parseDouble(resultTotalPlayTime) + "s");
- playTimeLabel.setText(stringBuffer.toString());
- playTimeLabel.pack();
-
- stringBuffer = new StringBuffer();
- stringBuffer.append("Start Time - ");
- String resultCurrentStartTime = String.format("%.2f", currentStartTime);
- stringBuffer.append(Double.parseDouble(resultCurrentStartTime) + "s");
- startTimeLabel.setText(stringBuffer.toString());
- startTimeLabel.pack();
-
- stringBuffer = new StringBuffer();
- stringBuffer.append("End Time - ");
- String resultCurrentEndTime = String.format("%.2f", currentEndTime);
- stringBuffer.append(Double.parseDouble(resultCurrentEndTime) + "s");
- endTimeLabel.setText(stringBuffer.toString());
- endTimeLabel.pack();
+ animationsCountText = "Animations - " + totalAnimationCount + "EA";
+ playTimeText = "Play Time - " + String.format("%.3f", totalPlayTime) + "s";
+ startTimeText = "Start Time - " + String.format("%.3f", currentStartTime) + "s";
+ endTimeText = "End Time - " + String.format("%.3f", currentEndTime) + "s";
redraw();
}
/**
- * Get animation count image
- *
- * @return {@link Label}
- */
- public Label getAnimationCountImage() {
- return animationCountImage;
- }
-
- /**
- * Get animation count label
- *
- * @return {@link Label}
- */
- public Label getAnimationCountLabel() {
- return animationCountLabel;
- }
-
- /**
- * Get play time image
- *
- * @return {@link Label}
- */
- public Label getPlayTimeImage() {
- return playTimeImage;
- }
-
- /**
- * Get play time label
- *
- * @return {@link Label}
- */
- public Label getPlayTimeLabel() {
- return playTimeLabel;
- }
-
- /**
- * Get start time image
- *
- * @return {@link Label}
- */
- public Label getStartTimeImage() {
- return startTimeImage;
- }
-
- /**
- * Get start time label
- *
- * @return {@link Label}
- */
- public Label getStartTimeLabel() {
- return startTimeLabel;
- }
-
- /**
- * Get end time image
- *
- * @return {@link Label}
- */
- public Label getEndTimeImage() {
- return endTimeImage;
- }
-
- /**
- * Get end time label
- *
- * @return {@link Label}
- */
- public Label getEndTimeLabel() {
- return endTimeLabel;
- }
-
- /**
* Apply lock
*/
public void applyLock() {
redraw();
}
- /**********************************************************************************************
- * PaintListener to Child Label
- **********************************************************************************************/
- PaintListener timelineWidgetPaintListener = new PaintListener() {
-
+ /******************************************************************************
+ * PaintListener
+ ******************************************************************************/
+ PaintListener widgetElementPaint = new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
-
- Label label = (Label) e.widget;
-
- Rectangle parentClientArea = label.getParent().getClientArea();
+ Rectangle clientArea = getClientArea();
boolean isLock = TimelineWidgetElement.this.editpart.isLock();
boolean isSelected = TimelineWidgetElement.this.editpart.isSelected();
+ e.gc.setForeground(ColorResource.TREEITEM_BORDER);
+
if (isLock) {
- label.setBackground(ColorResource.PARENT_TREEITEM_LOCKED);
+ setBackground(ColorResource.PARENT_TREEITEM_LOCKED);
} else if (isSelected) {
- label.setBackground(ColorResource.PARENT_TREEITEM_SELECTED);
+ setBackground(ColorResource.PARENT_TREEITEM_SELECTED);
} else {
+ Color foreground = e.gc.getForeground();
- drawGradiantWidget(label, e.gc, parentClientArea);
- }
+ e.gc.setBackground(ColorResource.PARENT_TREEITEM_BACKGROUND);
+ e.gc.setForeground(ColorResource.PARENT_TREEITEM_FOREGROUND);
+ e.gc.fillGradientRectangle(clientArea.x, clientArea.y, clientArea.width,
+ clientArea.height, true);
+ e.gc.setForeground(foreground);
+ }
+ drawImageAndText(e.gc);
+ e.gc.drawRectangle(clientArea.x, clientArea.y, clientArea.width - 1,
+ clientArea.height - 1);
}
- };
-
- /**
- * Draw gradiant Widget
- *
- * @param label
- * {@link Label} widget
- * @param gc
- * {@link GC}
- * @param parentClientArea
- * {@link Rectangle} parent widget size
- */
- public void drawGradiantWidget(Label label, GC gc, Rectangle parentClientArea) {
-
- Color foreground = gc.getForeground();
-
- Rectangle rt = label.getBounds();
-
- gc.setBackground(ColorResource.PARENT_TREEITEM_BACKGROUND);
- gc.setForeground(ColorResource.PARENT_TREEITEM_FOREGROUND);
- gc.fillGradientRectangle(0, -4, rt.width, parentClientArea.height, true);
-
- gc.setForeground(foreground);
-
- drawImgText(label, gc, rt);
- }
+ private void drawImageAndText(GC gc) {
+ gc.drawImage(animationsCountImage, 10, 4);
+ gc.drawImage(playTimeImage, 140, 4);
+ gc.drawImage(startTimeImage, 280, 4);
+ gc.drawImage(endTimeImage, 420, 4);
- /**
- * Draw Text and Image
- *
- * @param label
- * {@link Label} widget
- * @param gc
- * {@link GC}
- * @param rt
- * clientArea
- */
- private void drawImgText(Label label, GC gc, Rectangle rt) {
- if (label.equals(animationCountImage)) {
- gc.drawImage(ResourceManager.getImage(BuilderConstants.ICON_DIR,
- "animator_widget_animation_count.png"), 0, 0);
- } else if (label.equals(animationCountLabel)) {
- gc.setForeground(ColorResource.KEYFRAMEWIDGET_TEXT);
- gc.drawText(label.getText(), 0, 0, true);
- gc.setForeground(ColorResource.LATTICE);
- } else if (label.equals(playTimeImage)) {
- gc.drawImage(ResourceManager.getImage(BuilderConstants.ICON_DIR,
- "animator_widget_playtime.png"), 0, 0);
- } else if (label.equals(playTimeLabel)) {
gc.setForeground(ColorResource.KEYFRAMEWIDGET_TEXT);
- gc.drawText(label.getText(), 0, 0, true);
- gc.setForeground(ColorResource.LATTICE);
- } else if (label.equals(startTimeImage)) {
- gc.drawImage(ResourceManager.getImage(BuilderConstants.ICON_DIR,
- "animator_widget_starttime.png"), 0, 0);
- } else if (label.equals(startTimeLabel)) {
- gc.setForeground(ColorResource.KEYFRAMEWIDGET_TEXT);
- gc.drawText(label.getText(), 0, 0, true);
- gc.setForeground(ColorResource.LATTICE);
- } else if (label.equals(endTimeImage)) {
- gc.drawImage(ResourceManager.getImage(BuilderConstants.ICON_DIR,
- "animator_widget_endtime.png"), 0, 0);
- } else if (label.equals(endTimeLabel)) {
- gc.setForeground(ColorResource.KEYFRAMEWIDGET_TEXT);
- gc.drawText(label.getText(), 0, 0, true);
+ gc.drawText(animationsCountText, 30, 5, true);
+ gc.drawText(playTimeText, 160, 5, true);
+ gc.drawText(startTimeText, 300, 5, true);
+ gc.drawText(endTimeText, 440, 5, true);
gc.setForeground(ColorResource.LATTICE);
}
- }
-
- /**
- * Draw Children
- */
- private void childredraw() {
- animationCountImage.redraw();
- animationCountLabel.redraw();
- playTimeImage.redraw();
- playTimeLabel.redraw();
- startTimeImage.redraw();
- startTimeLabel.redraw();
- endTimeImage.redraw();
- endTimeLabel.redraw();
- }
-
+ };
}