From: nakyoung2.choi Date: Tue, 29 Apr 2014 01:04:36 +0000 (+0900) Subject: PROP : Add ColorPikcerMethod. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e05524546c5af6e6a24d9503b7c5d77bc5401c1a;p=sdk%2Fide%2Fweb-ui-builder-eplugin.git PROP : Add ColorPikcerMethod. ColorPickerMethod use org.tizen.common.ui.dialog.ColorPickerDialog. And apply css live edit on ScaleMethod/TextStyleMethod. Change-Id: Idda4490087079bfb21f7c5320b703fc38895a1d1 Signed-off-by: nakyoung2.choi --- diff --git a/org.tizen.webuibuilder/META-INF/MANIFEST.MF b/org.tizen.webuibuilder/META-INF/MANIFEST.MF index bdf2752..e3811b4 100644 --- a/org.tizen.webuibuilder/META-INF/MANIFEST.MF +++ b/org.tizen.webuibuilder/META-INF/MANIFEST.MF @@ -39,6 +39,7 @@ Import-Package: org.eclipse.core.filesystem, 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, diff --git a/org.tizen.webuibuilder/res/descriptors/Tizen-web-ui-fw/CSSProperties.xml b/org.tizen.webuibuilder/res/descriptors/Tizen-web-ui-fw/CSSProperties.xml index 81b27aa..98a5a34 100644 --- a/org.tizen.webuibuilder/res/descriptors/Tizen-web-ui-fw/CSSProperties.xml +++ b/org.tizen.webuibuilder/res/descriptors/Tizen-web-ui-fw/CSSProperties.xml @@ -32,13 +32,13 @@ - + - + - - - + + + @@ -89,28 +89,28 @@ - - + + - - + + - - + + - - + + - - + + @@ -146,12 +146,12 @@ - + - - - - + + + + diff --git a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/properties/method/ColorPickerFillMethod.java b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/properties/method/ColorPickerFillMethod.java new file mode 100644 index 0000000..e6be6d6 --- /dev/null +++ b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/properties/method/ColorPickerFillMethod.java @@ -0,0 +1,137 @@ +/* + * 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); + } + +} diff --git a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/properties/method/ColorPickerMethod.java b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/properties/method/ColorPickerMethod.java new file mode 100644 index 0000000..b62cf5f --- /dev/null +++ b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/properties/method/ColorPickerMethod.java @@ -0,0 +1,328 @@ +/* + * 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 + * true if the Method has function button, and false + * 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(); + } + } +} diff --git a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/properties/method/Method.java b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/properties/method/Method.java index bf917c6..6f24f54 100644 --- a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/properties/method/Method.java +++ b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/properties/method/Method.java @@ -655,12 +655,15 @@ public abstract class Method extends Composite { } 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)); } - } /** diff --git a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/properties/method/MethodCreationFactory.java b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/properties/method/MethodCreationFactory.java index b86c858..45f3b0d 100644 --- a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/properties/method/MethodCreationFactory.java +++ b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/properties/method/MethodCreationFactory.java @@ -154,8 +154,9 @@ public class MethodCreationFactory { 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 = @@ -206,8 +207,10 @@ public class MethodCreationFactory { 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 = diff --git a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/properties/method/MethodUtil.java b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/properties/method/MethodUtil.java index 1267eaf..83b6f6c 100644 --- a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/properties/method/MethodUtil.java +++ b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/properties/method/MethodUtil.java @@ -405,7 +405,7 @@ public class MethodUtil { break; case SWT.FocusIn: // text.selectAll(); - combo.getDisplay().asyncExec(new Runnable() { + combo.getDisplay().syncExec(new Runnable() { @Override public void run() { diff --git a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/properties/method/NewColorMethod.java b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/properties/method/NewColorMethod.java index c6358c8..d272363 100644 --- a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/properties/method/NewColorMethod.java +++ b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/properties/method/NewColorMethod.java @@ -27,8 +27,12 @@ import java.util.ArrayList; 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; @@ -54,6 +58,8 @@ import org.eclipse.swt.widgets.Listener; 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; @@ -97,6 +103,12 @@ public class NewColorMethod extends Method { 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 @@ -183,6 +195,54 @@ public class NewColorMethod extends Method { 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); @@ -197,6 +257,21 @@ public class NewColorMethod extends Method { 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. diff --git a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/properties/method/ScaleMethod.java b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/properties/method/ScaleMethod.java index 63b68f6..1af6fb0 100644 --- a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/properties/method/ScaleMethod.java +++ b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/properties/method/ScaleMethod.java @@ -28,6 +28,7 @@ import java.util.List; 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; @@ -40,6 +41,7 @@ import org.eclipse.swt.widgets.MessageBox; 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; @@ -53,6 +55,8 @@ public class ScaleMethod extends Method { private Text scaleValue; private Label unit; private PropertyDescriptor parentDescriptor; + private Listener listener; + private Listener textListener; /** * Constructor. @@ -81,6 +85,26 @@ public class ScaleMethod extends Method { 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) * @@ -155,7 +179,10 @@ public class ScaleMethod extends Method { 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); @@ -164,7 +191,17 @@ public class ScaleMethod extends Method { 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); @@ -175,6 +212,119 @@ public class ScaleMethod extends Method { 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) @@ -228,19 +378,37 @@ public class ScaleMethod extends Method { * 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; } + + } }; @@ -330,4 +498,19 @@ public class ScaleMethod extends Method { 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 diff --git a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/properties/method/TextStyleMethod.java b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/properties/method/TextStyleMethod.java index 71e2352..5dc2540 100644 --- a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/properties/method/TextStyleMethod.java +++ b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/properties/method/TextStyleMethod.java @@ -166,7 +166,7 @@ public class TextStyleMethod extends GroupMethod { 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; @@ -199,8 +199,23 @@ public class TextStyleMethod extends GroupMethod { 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); } /* diff --git a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/properties/style/CssSelectorCategoryComposite.java b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/properties/style/CssSelectorCategoryComposite.java index bf569e0..6635332 100644 --- a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/properties/style/CssSelectorCategoryComposite.java +++ b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/properties/style/CssSelectorCategoryComposite.java @@ -312,7 +312,7 @@ public class CssSelectorCategoryComposite extends CategoryComposite implements I if (!defaultSelector.equals(selector.getSelectorName()) && defaultSelector.equals(selector.getIdentity())) { String selectorName = selector.getSelectorName(); - addListItem(selectorName); + addListItem(selectorName, false); currentSelectors.add(selectorName); } } @@ -321,16 +321,19 @@ public class CssSelectorCategoryComposite extends CategoryComposite implements I } 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 @@ -356,7 +359,7 @@ public class CssSelectorCategoryComposite extends CategoryComposite implements I String selectorName = event.getSelector().getSelectorName(); if (!currentSelectors.contains(selectorName)) { currentSelectors.add(selectorName); - addListItem(selectorName); + addListItem(selectorName, true); } else { setSelector(selectorName); } diff --git a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/properties/style/CssStyleTab.java b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/properties/style/CssStyleTab.java index 89056ac..781c946 100644 --- a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/properties/style/CssStyleTab.java +++ b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/properties/style/CssStyleTab.java @@ -1044,13 +1044,13 @@ public class CssStyleTab extends PropertiesTabItem implements IPageDataListener * clear */ private void clear() { - for (CategoryComposite category : categories) { - category.dispose(); - } - for (Method method : methods.values()) { method.dispose(); } + + for (CategoryComposite category : categories) { + category.dispose(); + } clearManagedMethods();