ColorPickerMethod use org.tizen.common.ui.dialog.ColorPickerDialog. And apply css live edit on ScaleMethod/TextStyleMethod.
Change-Id: Idda4490087079bfb21f7c5320b703fc38895a1d1
Signed-off-by: nakyoung2.choi <nakyoung2.choi@samsung.com>
org.eclipse.wst.jsdt.core.refactoring,
org.eclipse.wst.jsdt.core.refactoring.descriptors,
org.eclipse.wst.sse.ui,
+ org.tizen.common.ui.dialog,
org.w3c.css.sac;version="1.3.0",
org.w3c.css.sac.helpers;version="1.3.0"
Export-Package: org.tizen.webuibuilder.extintrf,
<property name="letter-spacing" type="text@letter-spacing" displayName="Space"></property>
<property name="line-height" type="text@line-height" displayName="Height"></property>
<property name="-webkit-text-stroke-color" type="color" displayName="Stroke" inline="true"></property>
- <property name="-webkit-text-stroke-width" type="size" displayName="Width" inline="true"></property>
+ <property name="-webkit-text-stroke-width" type="size" displayName="Width" inline="true" default="0px"></property>
<property name="text-shadow" type="group" displayName="Shadow">
- <property name="text-shadow.color" type="color" displayName=""></property>
+ <property name="text-shadow.color" type="color" displayName="" default="#000000"></property>
<property name="empty" type="empty" inline="true"></property>
- <property name="text-shadow.x" type="size" displayName="X" default="0"></property>
- <property name="text-shadow.y" type="size" displayName="Y" default="0"></property>
- <property name="text-shadow.blur" type="size" displayName="Blur" default="0"></property>
+ <property name="text-shadow.x" type="size" displayName="X" default="0px"></property>
+ <property name="text-shadow.y" type="size" displayName="Y" default="0px"></property>
+ <property name="text-shadow.blur" type="size" displayName="Blur" default="0px"></property>
</property>
</property>
</category>
</category>
<category name="border" displayName="Border" brief="%border%" folding="border-top, border-bottom, border-left, border-right">
<property name="border" type="group-border" displayName="All">
- <property name="border.color" type="color"></property>
- <property name="border.width" type="size"></property>
+ <property name="border.color" type="color" default="#000000"></property>
+ <property name="border.width" type="size" default="0px"></property>
<property name="border.style" type="border@style" default=""></property>
</property>
<property name="border-top" type="group-border" displayName="Top">
- <property name="border-top.color" type="color"></property>
- <property name="border-top.width" type="size"></property>
+ <property name="border-top.color" type="color" default="#000000"></property>
+ <property name="border-top.width" type="size" default="0px"></property>
<property name="border-top.style" type="border@style" default=""></property>
</property>
<property name="border-bottom" type="group-border" displayName="Bottom">
- <property name="border-bottom.color" type="color"></property>
- <property name="border-bottom.width" type="size"></property>
+ <property name="border-bottom.color" type="color" default="#000000"></property>
+ <property name="border-bottom.width" type="size" default="0px"></property>
<property name="border-bottom.style" type="border@style" default=""></property>
</property>
<property name="border-left" type="group-border" displayName="Left">
- <property name="border-left.color" type="color"></property>
- <property name="border-left.width" type="size"></property>
+ <property name="border-left.color" type="color" default="#000000"></property>
+ <property name="border-left.width" type="size" default="0px"></property>
<property name="border-left.style" type="border@style" default=""></property>
</property>
<property name="border-right" type="group-border" displayName="Right">
- <property name="border-right.color" type="color"></property>
- <property name="border-right.width" type="size"></property>
+ <property name="border-right.color" type="color" default="#000000"></property>
+ <property name="border-right.width" type="size" default="0px"></property>
<property name="border-right.style" type="border@style" default=""></property>
</property>
<category name="shadow" displayName="Shadow" brief="">
<property name="box-shadow" type="group" displayName="">
- <property name="box-shadow.color" type="color" displayName="Color"></property>
+ <property name="box-shadow.color" type="color" displayName="Color" default="#000000"></property>
<property name="empty" type="empty" inline="true"></property>
- <property name="box-shadow.horizontal" type="size" displayName="Horz" default="0"></property>
- <property name="box-shadow.vertical" type="size" displayName="Vert" default="0"></property>
- <property name="box-shadow.blur" type="size" displayName="Blur" default="0"></property>
- <property name="box-shadow.spread" type="size" displayName="Spread" default="0"></property>
+ <property name="box-shadow.horizontal" type="size" displayName="Horz" default="0px"></property>
+ <property name="box-shadow.vertical" type="size" displayName="Vert" default="0px"></property>
+ <property name="box-shadow.blur" type="size" displayName="Blur" default="0px"></property>
+ <property name="box-shadow.spread" type="size" displayName="Spread" default="0px"></property>
</property>
</category>
<category name="metrics" displayName="Metrics" brief="">
--- /dev/null
+/*
+ * UI Builder
+ *
+ * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+package org.tizen.webuibuilder.ui.views.properties.method;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.tizen.common.util.SWTUtil;
+import org.tizen.webuibuilder.BuilderConstants;
+
+public class ColorPickerFillMethod extends ColorPickerMethod {
+
+ private Button check;
+ private Label fillLabel;
+ private boolean defaultFlag = true;
+
+ private Listener selectionListener;
+
+ public ColorPickerFillMethod(Composite parent, int style, MethodType type, String name,
+ String value, String displayName, boolean hasFunc) {
+ super(parent, style, type, name, value, displayName, hasFunc);
+ }
+
+ @Override
+ protected Control createControl() {
+ Composite composite = (Composite) super.createControl();
+
+ check = new Button(composite, SWT.CHECK);
+ FormData data = new FormData();
+ data.left = new FormAttachment(getColorLabel(), 10);
+ data.top = new FormAttachment(getColorLabel(), 0 , SWT.CENTER);
+ check.setLayoutData(data);
+
+ selectionListener = createListener();
+ check.addListener(SWT.Selection, selectionListener);
+
+ fillLabel = new Label(composite, SWT.NONE);
+ FormData data2 = new FormData();
+ data2.left = new FormAttachment(check, 3);
+ data2.top = new FormAttachment(check, 0 , SWT.CENTER);
+ fillLabel.setLayoutData(data2);
+
+ fillLabel.setText("Fill");
+ fillLabel.addListener(SWT.MouseUp, selectionListener);
+
+ return composite;
+ }
+
+ private Listener createListener() {
+ return new Listener() {
+
+ @Override
+ public void handleEvent(Event event) {
+ if (check == null || check.isDisposed()) {
+ return;
+ }
+ switch (event.type) {
+ case SWT.Selection:
+ if (check.getSelection()) {
+ String color = BuilderConstants.EMPTY;
+ if (!defaultFlag) {
+ color = SWTUtil.convertRGBToHexadecimal(getCurrentRGB());
+ }
+
+ if (color != null && !color.isEmpty()
+ && !color.startsWith(BuilderConstants.SHARP)) {
+ color = BuilderConstants.SHARP + color;
+ }
+ setValue(color);
+ } else {
+ setValue(BuilderConstants.EMPTY);
+ }
+ break;
+ case SWT.MouseUp:
+ check.setSelection(!check.getSelection());
+ break;
+ default:
+ break;
+ }
+ }
+ };
+ }
+
+ @Override
+ public void setValue(String value) {
+ if (value == null) {
+ value = BuilderConstants.EMPTY;
+ }
+ if (value.isEmpty()) {
+ defaultFlag = true;
+ } else {
+ defaultFlag = false;
+ }
+ super.setValue(value);
+ }
+
+ @Override
+ public void refreshValue(String name, String value) {
+ if (value == null) {
+ value = BuilderConstants.EMPTY;
+ }
+
+ if (value.isEmpty()) {
+ defaultFlag = true;
+ } else {
+ defaultFlag = false;
+ }
+ super.refreshValue(name, value);
+ }
+
+}
--- /dev/null
+/*
+ * UI Builder
+ *
+ * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+package org.tizen.webuibuilder.ui.views.properties.method;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.browser.Browser;
+import org.eclipse.swt.browser.BrowserFunction;
+import org.eclipse.swt.events.FocusEvent;
+import org.eclipse.swt.events.FocusListener;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseListener;
+import org.eclipse.swt.events.PaintEvent;
+import org.eclipse.swt.events.PaintListener;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Shell;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.tizen.common.ui.dialog.ColorPickerDialog;
+import org.tizen.common.util.BrowserWrapper;
+import org.tizen.common.util.SWTUtil;
+import org.tizen.webuibuilder.BuilderConstants;
+import org.tizen.webuibuilder.ui.views.properties.method.Method.MethodType;
+
+public class ColorPickerMethod extends Method {
+
+ private Logger logger = LoggerFactory.getLogger(ColorPickerMethod.class);
+
+ // Control
+ private Label colorLabel;
+ private RGB currentRGB;
+
+ // ColorPickerDialog
+ private static int COLOR_DIALOG_WIDTH = 360;
+ private static int COLOR_DIALOG_HEIGHT = 180;
+ private static int COLOR_DIALOG_X_MARGIN = 30;
+ private Shell colorDialog;
+ private BrowserWrapper browserWrapper;
+
+ // Listeners
+ private Listener dialogListener = new Listener() {
+
+ @Override
+ public void handleEvent(Event event) {
+ if (colorDialog == null || colorDialog.isDisposed()) {
+ return;
+ }
+ switch (event.type) {
+ case SWT.Activate:
+ logger.debug("ColorPickerDialog activated");
+ break;
+ case SWT.Deactivate :
+ logger.debug("ColorPickerDialog deactivated");
+ String color = SWTUtil.convertRGBToHexadecimal(currentRGB);
+ setValue(color);
+
+ closeColorDialog();
+ break;
+
+ default:
+ break;
+ }
+
+ }
+ };
+ private PaintListener paintListener = new PaintListener() {
+
+ @Override
+ public void paintControl(PaintEvent e) {
+ if (currentRGB == null) {
+ resetCurrentRGB();
+ }
+ e.gc.setBackground(new Color(e.display, currentRGB.red, currentRGB.green,
+ currentRGB.blue));
+ // e.gc.setAlpha(userAlpha);
+ e.gc.fillRectangle(colorLabel.getLocation().x, colorLabel.getLocation().y - 2,
+ colorLabel.getSize().x, colorLabel.getSize().y);
+ e.gc.dispose();
+ }
+ };
+
+ private MouseListener mouseListener = new MouseListener() {
+
+ @Override
+ public void mouseUp(MouseEvent e) {
+ if (colorDialog != null && !colorDialog.isDisposed()) {
+ closeColorDialog();
+ }
+ createColorDialog();
+ openColorDialog();
+ }
+
+ @Override
+ public void mouseDown(MouseEvent e) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void mouseDoubleClick(MouseEvent e) {
+ // TODO Auto-generated method stub
+
+ }
+ };
+
+ private class ColorFunction extends BrowserFunction {
+ ColorFunction(Browser browser) {
+ super(browser, ColorPickerDialog.GET_COLOR_FUNCTION);
+ }
+
+ public Object function(Object[] arguments) {
+ if (arguments.length > 0 && (arguments[0] instanceof String)) {
+ String hex = (String) arguments[0];
+ StringBuilder builder = new StringBuilder(BuilderConstants.SHARP);
+ builder.append(hex);
+ modifyValue(builder.toString());
+ setCurrentRGB(hex);
+ colorLabel.redraw();
+ }
+ return null;
+ }
+
+ }
+
+ /**
+ * Construct
+ *
+ * @param parent
+ * a widget which will be the parent of the new instance (cannot be null)
+ * @param style
+ * the style of widget to construct
+ * @param type
+ * a {@link MethodType}
+ * @param name
+ * property name
+ * @param value
+ * property value
+ * @param displayName
+ * display name
+ * @param hasFunc
+ * <code>true</code> if the Method has function button, and <code>false</code>
+ * otherwise
+ */
+ public ColorPickerMethod(Composite parent, int style, MethodType type, String name,
+ String value, String displayName, boolean hasFunc) {
+ super(parent, style, type, name, value, displayName, hasFunc);
+
+ addListeners();
+ }
+
+ @Override
+ protected Control createControl() {
+ Composite composite = new Composite(this, SWT.NONE);
+ composite.setLayout(new FormLayout());
+ colorLabel = new Label(composite, SWT.BORDER);
+ FormData data = new FormData(16, 16);
+ data.left = new FormAttachment(0, 0);
+ data.top = new FormAttachment(0, 2);
+ colorLabel.setLayoutData(data);
+ resetCurrentRGB();
+
+
+ return composite;
+ }
+
+ @Override
+ public void refreshValue(String name, String value) {
+ super.refreshValue(name, value);
+ if (colorLabel != null) {
+ if (value == null || value.isEmpty()) {
+ resetCurrentRGB();
+ } else {
+ setCurrentRGB(value);
+ }
+
+ colorLabel.redraw();
+ }
+ }
+
+ @Override
+ public void setValue(String value) {
+ if (value == null || value.isEmpty()) {
+ resetCurrentRGB();
+ super.setValue(BuilderConstants.EMPTY);
+ } else {
+ setCurrentRGB(value);
+ super.setValue(value);
+ }
+ }
+
+ private void addListeners() {
+ if (colorLabel != null) {
+ colorLabel.addPaintListener(paintListener);
+ colorLabel.addMouseListener(mouseListener);
+ }
+
+ }
+
+ private void removesListeners() {
+ if (colorLabel != null && !colorLabel.isDisposed()) {
+ colorLabel.removePaintListener(paintListener);
+ colorLabel.removeMouseListener(mouseListener);
+ }
+
+ }
+
+ @Override
+ public void dispose() {
+ removesListeners();
+ super.dispose();
+ }
+
+ private void resetCurrentRGB() {
+ Color defaultColor = getDisplay().getSystemColor(SWT.COLOR_BLACK);
+ setCurrentRGB(defaultColor);
+ }
+
+ private void setCurrentRGB(String hex) {
+ if (!hex.startsWith(BuilderConstants.SHARP)) {
+ hex = BuilderConstants.SHARP + hex;
+ }
+ currentRGB = SWTUtil.convertHexadecimalToRGB(hex);
+ }
+
+ private void setCurrentRGB(Color color) {
+ currentRGB = new RGB(color.getRed(), color.getGreen(), color.getBlue());
+ }
+
+ protected Label getColorLabel() {
+ return colorLabel;
+ }
+
+ protected RGB getCurrentRGB() {
+ return currentRGB;
+ }
+
+ private void createColorDialog() {
+ colorDialog = new Shell(getShell(), SWT.NO_TRIM | SWT.ON_TOP);
+ colorDialog.setLayout(new FillLayout());
+ // shell.setLocation(100, 100);
+ Point ll = colorLabel.getLocation();
+ Point ls = colorLabel.getSize();
+ Rectangle sRect = getShell().getBounds();
+
+ Point location = colorLabel.toDisplay(ll.x, ll.y + ls.y);
+ if (sRect.x + sRect.width - location.x < COLOR_DIALOG_WIDTH) {
+ location.x = sRect.x + sRect.width - COLOR_DIALOG_WIDTH - COLOR_DIALOG_X_MARGIN;
+ }
+
+
+ colorDialog.setLocation(location);
+ colorDialog.setSize(COLOR_DIALOG_WIDTH, COLOR_DIALOG_HEIGHT);
+ browserWrapper = new BrowserWrapper(ColorPickerDialog.createBrowser(colorDialog));
+
+ StringBuilder urlBuilder = new StringBuilder();
+ urlBuilder.append(ColorPickerDialog.getColorPickerURL());
+ String color = getValue();
+
+ if (color == null || color.isEmpty()) {
+ if (currentRGB == null) {
+ resetCurrentRGB();
+ }
+ color = SWTUtil.convertRGBToHexadecimal(currentRGB);
+ }
+ urlBuilder.append("?color=" + color);
+ final String url = urlBuilder.toString();
+
+ // reset browser
+ browserWrapper.setText("");
+ browserWrapper.setUrl(url);
+
+ new ColorFunction(browserWrapper.getBrowser());
+
+ colorDialog.addListener(SWT.Activate, dialogListener);
+ colorDialog.addListener(SWT.Deactivate, dialogListener);
+ }
+
+ private void closeColorDialog() {
+ if (colorDialog == null || colorDialog.isDisposed()) {
+ return;
+ } else {
+ colorDialog.removeListener(SWT.Activate, dialogListener);
+ colorDialog.removeListener(SWT.Deactivate, dialogListener);
+
+ browserWrapper.dispose();
+ colorDialog.close();
+ }
+ }
+
+ private void openColorDialog() {
+ if (colorDialog == null || colorDialog.isDisposed()) {
+ return;
+ } else {
+ colorDialog.open();
+ }
+ }
+}
}
public void modifyValue(String value) {
+ modifyValue(getMethodName(), value);
+ }
+
+ public void modifyValue(String key, String value) {
IValueChangeListener listener = getValueChangedListener();
if (listener != null) {
- listener.valueModified(new MethodEvent(this, getMethodName(), value));
+ listener.valueModified(new MethodEvent(this, key, value));
}
-
}
/**
method =
// new ColorMethod(parent, SWT.NONE, methodType, name, value, displayName,
// hasFunc);
- new NewColorMethod(parent, SWT.NONE, methodType, name, value, displayName,
- hasFunc);
+// new NewColorMethod(parent, SWT.NONE, methodType, name, value, displayName,
+// hasFunc);
+ new ColorPickerMethod(parent, SWT.NONE, methodType, name, value, displayName, hasFunc);
break;
case COLOR2:
method =
break;
case COLOR_FILL:
method =
- new ColorFillMethod(parent, SWT.NONE, methodType, name, value, displayName,
- hasFunc);
+// new ColorFillMethod(parent, SWT.NONE, methodType, name, value, displayName,
+ // hasFunc);
+ new ColorPickerFillMethod(parent, SWT.NONE, methodType, name, value,
+ displayName, hasFunc);
break;
case GROUP:
method =
break;
case SWT.FocusIn:
// text.selectAll();
- combo.getDisplay().asyncExec(new Runnable() {
+ combo.getDisplay().syncExec(new Runnable() {
@Override
public void run() {
import java.util.List;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.browser.Browser;
+import org.eclipse.swt.browser.BrowserFunction;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
+import org.tizen.common.ui.dialog.ColorPickerDialog;
+import org.tizen.common.util.BrowserWrapper;
import org.tizen.webuibuilder.BuilderConstants;
import org.tizen.webuibuilder.ui.views.properties.PropertiesConstant;
private RGB currentRGB;
private RGB previousRGB;
private int prevUserAlpha;
+
+ // ColorPickerDialog
+ private static int COLOR_DIALOG_WIDTH = 360;
+ private static int COLOR_DIALOG_HEIGHT = 180;
+ private Shell colorDialog;
+ BrowserWrapper browserWrapper;
/**
* Construct
data.top = new FormAttachment(0, 2);
selectedColor.setLayoutData(data);
selectedColor.addPaintListener(createSelectedColorPaintListener());
+
+
+ selectedColor.addMouseListener(new MouseListener() {
+
+ @Override
+ public void mouseUp(MouseEvent e) {
+ if (colorDialog != null && !colorDialog.isDisposed()) {
+ colorDialog.close();
+ colorDialog = null;
+ }
+
+ colorDialog = new Shell(getShell(), SWT.NO_TRIM | SWT.ON_TOP);
+ colorDialog.setLayout(new FillLayout());
+ // shell.setLocation(100, 100);
+ Point ll = selectedColor.getLocation();
+ Point ls = selectedColor.getSize();
+ Point location = selectedColor.toDisplay(ll.x, ll.y + ls.y);
+
+ colorDialog.setLocation(location);
+ colorDialog.setSize(COLOR_DIALOG_WIDTH, COLOR_DIALOG_HEIGHT);
+ browserWrapper = new BrowserWrapper(ColorPickerDialog.createBrowser(colorDialog));
+
+ StringBuilder urlBuilder = new StringBuilder();
+ urlBuilder.append(ColorPickerDialog.getColorPickerURL());
+ String color = getValue();
+ urlBuilder.append("?color=" + color);
+ final String url = urlBuilder.toString();
+
+ // reset browser
+ browserWrapper.setText("");
+ browserWrapper.setUrl(url);
+
+ new ColorFunction(browserWrapper.getBrowser());
+ colorDialog.open();
+ }
+
+ @Override
+ public void mouseDown(MouseEvent e) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void mouseDoubleClick(MouseEvent e) {
+ // TODO Auto-generated method stub
+
+ }
+ });
/** color dialog */
Button dialogButton = new Button(composite, SWT.ARROW | SWT.DOWN);
return composite;
}
+
+ class ColorFunction extends BrowserFunction {
+ ColorFunction(Browser browser) {
+ super(browser, ColorPickerDialog.GET_COLOR_FUNCTION);
+ }
+
+ public Object function(Object[] arguments) {
+ if (arguments.length > 0 && (arguments[0] instanceof String)) {
+ String hex = (String) arguments[0];
+ modifyValue("#" + hex);
+ }
+ return null;
+ }
+
+ }
/**
* This method creates a {@link Listener} to represent the selected color.
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
+import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Scale;
import org.eclipse.swt.widgets.Text;
import org.tizen.webuibuilder.BuilderConstants;
+import org.tizen.webuibuilder.animator.utils.Constants;
import org.tizen.webuibuilder.model.descriptors.PropertyConditionDescriptor;
import org.tizen.webuibuilder.model.descriptors.PropertyDescriptor;
private Text scaleValue;
private Label unit;
private PropertyDescriptor parentDescriptor;
+ private Listener listener;
+ private Listener textListener;
/**
* Constructor.
this.parentDescriptor = parentDescriptor;
}
+ @Override
+ public void dispose() {
+ if (scale != null && !scale.isDisposed()) {
+ scale.removeListener(SWT.MouseUp, listener);
+ scale.removeListener(SWT.Selection, listener);
+ }
+
+ if (scaleValue != null && !scale.isDisposed()) {
+ scaleValue.removeListener(SWT.Traverse, textListener);
+ scaleValue.removeListener(SWT.FocusIn, textListener);
+ scaleValue.removeListener(SWT.FocusOut, textListener);
+ scaleValue.removeListener(SWT.MouseDown, textListener);
+ scaleValue.removeListener(SWT.MouseUp, textListener);
+ scaleValue.removeListener(SWT.MouseDoubleClick, textListener);
+ scaleValue.removeListener(SWT.MouseMove, textListener);
+ scaleValue.removeListener(SWT.Selection, textListener);
+ }
+
+ super.dispose();
+ }
/*
* (non-Javadoc)
*
data.bottom = new FormAttachment(100, 10);
scale.setLayoutData(data);
// scale.addListener(SWT.Selection, createScaleListener(this));
- scale.addListener(SWT.MouseUp, createScaleListener(this));
+ listener = createScaleListener();
+
+ scale.addListener(SWT.MouseUp, listener);
+ scale.addListener(SWT.Selection, listener);
/** scale value */
scaleValue = new Text(composite, SWT.LEFT | SWT.BORDER);
data.left = new FormAttachment(scale, -1);
data.top = new FormAttachment(0);
scaleValue.setLayoutData(data);
- scaleValue.addKeyListener(createTextListener(this));
+
+ textListener = createScaleTextListener();
+// scaleValue.addKeyListener(createTextListener(this));
+ scaleValue.addListener(SWT.Traverse, textListener);
+ scaleValue.addListener(SWT.FocusIn, textListener);
+ scaleValue.addListener(SWT.FocusOut, textListener);
+ scaleValue.addListener(SWT.MouseDown, textListener);
+ scaleValue.addListener(SWT.MouseUp, textListener);
+ scaleValue.addListener(SWT.MouseDoubleClick, textListener);
+ scaleValue.addListener(SWT.MouseMove, textListener);
+ scaleValue.addListener(SWT.Selection, textListener);
/** unit */
unit = new Label(composite, SWT.CENTER);
return composite;
}
+
+
+ private Listener createScaleTextListener() {
+ Listener textListener = new Listener() {
+
+ private boolean hasFocus = false;
+ private boolean hadFocusOnMousedown = false;
+ private Point mousePt = null;
+
+ @Override
+ public void handleEvent(Event event) {
+ Text text = (Text) event.widget;
+
+ switch (event.type) {
+ case SWT.Traverse:
+ if (event.detail == SWT.TRAVERSE_RETURN) {
+ setValue(convertFloatString(text.getText()));
+ } else if (event.detail == SWT.TRAVERSE_ESCAPE) {
+ refreshValue(getMethodName(), getValue());
+ }
+
+ break;
+ case SWT.FocusIn:
+ // text.selectAll();
+ text.getDisplay().syncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ hasFocus = true;
+ }
+ });
+ break;
+ case SWT.FocusOut:
+ setValue(convertFloatString(text.getText()));
+ hasFocus = false;
+ break;
+ case SWT.MouseDown:
+ mousePt = new Point(event.x, event.y);
+
+ hadFocusOnMousedown = hasFocus;
+ break;
+ case SWT.MouseUp:
+ if (mousePt != null) {
+ mousePt = null;
+ setValue(convertFloatString(text.getText()));
+ }
+ if (!hadFocusOnMousedown) {
+ text.setFocus();
+ // text.selectAll();
+ }
+ break;
+ case SWT.MouseDoubleClick:
+ setValue(convertFloatString(text.getText()));
+ break;
+ case SWT.MouseMove: {
+ if (hadFocusOnMousedown) {
+ // long startTime = System.nanoTime();
+ if (text != null && text.getText() != null && mousePt != null) {
+ int valueInt = 0;
+ if (!text.getText().equals(BuilderConstants.EMPTY)) {
+ try {
+ float valueFloat = Float.parseFloat(text.getText());
+ valueInt = Math.round(valueFloat);
+ // valueInt = Integer.parseInt(combo.getText());
+ } catch (Exception e) {
+ break;
+ }
+ }
+ if (mousePt.y - Constants.countPerPx > event.y) {
+ String value = String.valueOf(valueInt + 1);
+ int max = scale.getMaximum();
+ int intValue = Integer.parseInt(value);
+ if (intValue > max) {
+ value = String.valueOf(max);
+ intValue = max;
+ }
+
+ text.setText(value);
+ modifyValue(convertFloatString(value));
+ scale.setSelection(intValue);
+ mousePt.y = mousePt.y - 10;
+ } else if (mousePt.y + Constants.countPerPx < event.y) {
+ String value = String.valueOf(valueInt - 1);
+ int min = scale.getMinimum();
+ int intValue = Integer.parseInt(value);
+ if (intValue < min) {
+ value = String.valueOf(min);
+ intValue = min;
+ }
+
+ text.setText(value);
+ modifyValue(convertFloatString(value));
+ scale.setSelection(intValue);
+ mousePt.y = mousePt.y + 10;
+ }
+ }
+ }
+ }
+ break;
+
+ case SWT.Selection: {
+ setValue(convertFloatString(text.getText()), true);
+ // because not validate from combo box value
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ };
+
+ return textListener;
+ }
/*
* (non-Javadoc)
* own class ({@link Method})
* @return a {@link Listener}
*/
- private Listener createScaleListener(final Method target) {
+ private Listener createScaleListener() {
Listener listener = new Listener() {
@Override
public void handleEvent(Event event) {
String value = String.format("%d", scale.getSelection());
- scaleValue.setText(value);
- if (target.getMethodName().equals("opacity")) {
- float opacityValue = (float) (scale.getSelection()) / 100;
- target.setValue(String.format("%.2f", opacityValue));
- } else {
- target.setValue(value + unit.getText());
+
+ switch(event.type) {
+ case SWT.MouseUp :
+ scaleValue.setText(value);
+ if (getMethodName().equals("opacity")) {
+ String convertedValue = convertFloatString(value);
+ setValue(convertedValue);
+ } else {
+ setValue(value + unit.getText());
+ }
+ break;
+ case SWT.Selection :
+ scaleValue.setText(value);
+ if (getMethodName().equals("opacity")) {
+ String convertedValue = convertFloatString(value);
+ modifyValue(convertedValue);
+ } else {
+ modifyValue(value + unit.getText());
+ }
+ break;
+ default:
+ break;
}
+
+
}
};
data.right = new FormAttachment(80, 0);
return data;
}
+
+ private String convertFloatString(String value) {
+ int intValue = Integer.parseInt(value);
+ float opacityValue = (float) intValue / 100;
+ return String.format("%.2f", opacityValue);
+ }
+
+ @Override
+ public void setValue(String value) {
+ // FIXME 5.12000 compare 5.12
+ if (getValue().equals(value)) {
+ return;
+ }
+ super.setValue(value);
+ }
}
\ No newline at end of file
case 11:
/** text-shadow */
data.top = new FormAttachment(methods.get(9), heightMargin);
- data.left = new FormAttachment(0, 0);
+ data.left = new FormAttachment(0, 1);
data.right = new FormAttachment(100, 0);
labelPosition = 16;
break;
return;
}
- String resultValue = childKey + ":" + childValue;
- setValue(resultValue, true);
+ StringBuilder builder = new StringBuilder(childKey);
+ builder.append(BuilderConstants.COLON);
+ builder.append(childValue);
+
+ setValue(builder.toString(), true);
+ }
+
+ @Override
+ public void valueModified(MethodEvent event) {
+ String childKey = event.getKey();
+ String childValue = event.getValue();
+
+ if (childKey == null || childValue == null) {
+ return;
+ }
+
+ modifyValue(childKey, childValue);
}
/*
if (!defaultSelector.equals(selector.getSelectorName())
&& defaultSelector.equals(selector.getIdentity())) {
String selectorName = selector.getSelectorName();
- addListItem(selectorName);
+ addListItem(selectorName, false);
currentSelectors.add(selectorName);
}
}
} else {
currentSelectors = selectors;
for (int i = 1; i < currentSelectors.size(); i++) {
- addListItem(currentSelectors.get(i));
+ addListItem(currentSelectors.get(i), false);
}
}
}
- private void addListItem(String selectorName) {
+ private void addListItem(String selectorName, boolean selection) {
TableItem item = new TableItem(listBox, SWT.BORDER);
item.setText(selectorName);
- listBox.setSelection(item);
+ if (selection) {
+ listBox.setSelection(item);
+ }
+
}
@Override
String selectorName = event.getSelector().getSelectorName();
if (!currentSelectors.contains(selectorName)) {
currentSelectors.add(selectorName);
- addListItem(selectorName);
+ addListItem(selectorName, true);
} else {
setSelector(selectorName);
}
* clear
*/
private void clear() {
- for (CategoryComposite category : categories) {
- category.dispose();
- }
-
for (Method method : methods.values()) {
method.dispose();
}
+
+ for (CategoryComposite category : categories) {
+ category.dispose();
+ }
clearManagedMethods();