diff options
Diffstat (limited to 'org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow')
33 files changed, 3341 insertions, 0 deletions
diff --git a/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/PWContainer.java b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/PWContainer.java new file mode 100644 index 000000000..17784f6ff --- /dev/null +++ b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/PWContainer.java @@ -0,0 +1,45 @@ +/*******************************************************************************
+ * Copyright (c) 2011 Laurent CARON
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Laurent CARON (laurent.caron at gmail dot com) - Initial implementation and API
+ *******************************************************************************/
+package org.mihalis.opal.preferenceWindow;
+
+import org.eclipse.swt.widgets.Composite;
+import org.mihalis.opal.preferenceWindow.widgets.PWWidget;
+
+/**
+ * Abstract class for "Containers" (row, group and tab)
+ *
+ */
+public abstract class PWContainer {
+
+ /**
+ * Add a container to the current element
+ *
+ * @param element element to add
+ * @return the container
+ */
+ public abstract PWContainer add(final PWContainer element);
+
+ /**
+ * Add a widget to the current element
+ *
+ * @param widget widget to add
+ * @return the container
+ */
+ public abstract PWContainer add(final PWWidget widget);
+
+ /**
+ * Build the content of the container
+ *
+ * @param parent parent composite
+ */
+ public abstract void build(final Composite parent);
+
+}
diff --git a/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/PWGroup.java b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/PWGroup.java new file mode 100644 index 000000000..ac0efb4aa --- /dev/null +++ b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/PWGroup.java @@ -0,0 +1,169 @@ +/*******************************************************************************
+ * Copyright (c) 2011 Laurent CARON
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Laurent CARON (laurent.caron at gmail dot com) - Initial implementation and API
+ *******************************************************************************/
+package org.mihalis.opal.preferenceWindow;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Group;
+import org.mihalis.opal.preferenceWindow.widgets.PWWidget;
+
+/**
+ * Instances of this class are groups
+ */
+public class PWGroup extends PWRowGroup {
+
+ private final String label;
+ private final boolean hasBorder;
+ private final List<PWRow> children;
+
+ /**
+ * Constructor
+ *
+ * @param hasBorder if <code>true</code>, the group has a border
+ */
+ public PWGroup(final boolean hasBorder) {
+ this(null, hasBorder);
+ }
+
+ /**
+ * Constructor
+ *
+ * @param label label associated to the group
+ */
+ public PWGroup(final String label) {
+ this(label, true);
+ }
+
+ /**
+ * Constructor
+ *
+ * @param label label associated to the group
+ * @param hasBorder if <code>true</code>, the group has a border
+ */
+ public PWGroup(final String label, final boolean hasBorder) {
+ this.label = label;
+ this.hasBorder = hasBorder;
+ this.children = new ArrayList<PWRow>();
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.PWContainer#add(org.mihalis.opal.preferenceWindow.PWContainer)
+ */
+ @Override
+ public PWContainer add(final PWContainer element) {
+ if (!(element instanceof PWRow)) {
+ throw new UnsupportedOperationException("Can only add a PWRow.");
+ }
+ this.children.add((PWRow) element);
+ return this;
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.PWContainer#add(org.mihalis.opal.preferenceWindow.widgets.PWWidget)
+ */
+ @Override
+ public PWContainer add(final PWWidget widget) {
+ final PWRow row = new PWRow();
+ row.add(widget);
+ this.children.add(row);
+ return this;
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.PWContainer#build(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ public void build(final Composite parent) {
+ final Composite composite;
+ if (this.hasBorder) {
+ composite = new Group(parent, SWT.NONE);
+ if (this.label != null && !this.label.trim().equals("")) {
+ ((Group) composite).setText(this.label);
+ }
+ } else {
+ composite = new Composite(parent, SWT.BORDER);
+ }
+
+ final int numCol = computeNumberOfColumns();
+
+ composite.setLayout(new GridLayout(numCol, false));
+ composite.setLayoutData(new GridData(GridData.BEGINNING, GridData.FILL, false, false, this.parentNumberOfColums, 1));
+
+ for (final PWRow row : this.children) {
+ row.setParentNumberOfColumns(numCol);
+ row.build(composite);
+ }
+
+ }
+
+ /**
+ * @return
+ */
+ private int computeNumberOfColumns() {
+ int numberOfColumns = 1;
+ for (final PWRow row : this.children) {
+ numberOfColumns = Math.max(numberOfColumns, row.getNumberOfColums());
+ }
+ return numberOfColumns;
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.PWRowGroup#checkParent(org.mihalis.opal.preferenceWindow.PWContainer)
+ */
+ @Override
+ protected void checkParent(final PWContainer parent) {
+ if (parent instanceof PWTab) {
+ return;
+ }
+ throw new UnsupportedOperationException("Bad parent, should be only PWTab ");
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.PWRowGroup#enableOrDisable()
+ */
+ @Override
+ public void enableOrDisable() {
+ if (this.enabler == null) {
+ return;
+ }
+
+ final boolean enabled = this.enabler.isEnabled();
+ for (final PWRow row : this.children) {
+ enableOrDisable(row, enabled);
+ }
+ }
+
+ /**
+ * Enable or disable a row
+ *
+ * @param row row to enable or disable
+ * @param enabled enable flag
+ */
+ private void enableOrDisable(final PWRow row, final boolean enabled) {
+ for (final PWWidget widget : row.widgets) {
+ final boolean widgetEnable = widget.enableOrDisable();
+
+ for (final Control c : widget.getControls()) {
+ if (!c.isDisposed()) {
+ c.setEnabled(enabled && widgetEnable);
+ }
+ }
+ }
+
+ }
+
+}
diff --git a/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/PWRow.java b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/PWRow.java new file mode 100644 index 000000000..e38abdc0e --- /dev/null +++ b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/PWRow.java @@ -0,0 +1,142 @@ +/*******************************************************************************
+ * Copyright (c) 2011 Laurent CARON
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Laurent CARON (laurent.caron at gmail dot com) - Initial implementation and API
+ *******************************************************************************/
+package org.mihalis.opal.preferenceWindow;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.mihalis.opal.preferenceWindow.widgets.PWButton;
+import org.mihalis.opal.preferenceWindow.widgets.PWLabel;
+import org.mihalis.opal.preferenceWindow.widgets.PWWidget;
+
+/**
+ * Instances of this class are rows
+ */
+public class PWRow extends PWRowGroup {
+ protected final List<PWWidget> widgets;
+
+ /**
+ * Constructor
+ */
+ public PWRow() {
+ this.widgets = new ArrayList<PWWidget>();
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.PWContainer#add(org.mihalis.opal.preferenceWindow.widgets.PWWidget)
+ */
+ @Override
+ public PWContainer add(final PWWidget widget) {
+ this.widgets.add(widget);
+ addColumn(widget.getNumberOfColumns());
+ return this;
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.PWContainer#add(org.mihalis.opal.preferenceWindow.PWContainer)
+ */
+ @Override
+ public PWContainer add(final PWContainer element) {
+ if (element instanceof PWRow || element instanceof PWGroup) {
+ return this.parent.add(element);
+ } else {
+ throw new UnsupportedOperationException("Can only add a PWGroup or a PWRow.");
+ }
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.PWContainer#build(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ public void build(final Composite parent) {
+ final int size = this.widgets.size();
+ int columIndex = 0;
+ for (int i = 0; i < size; i++) {
+ final PWWidget widget = this.widgets.get(i);
+ final Control control = widget.checkAndBuild(parent);
+ if (control != null && control.getLayoutData() == null) {
+ final int colSpan;
+ final boolean grabExcessSpace;
+ final int alignment;
+ if (size == 1) {
+ if (widget.isSingleWidget()) {
+ colSpan = this.parentNumberOfColums;
+ } else {
+ colSpan = this.parentNumberOfColums - widget.getNumberOfColumns() + 1;
+ }
+ grabExcessSpace = true;
+ } else {
+ if (i == size - 1) {
+ colSpan = this.parentNumberOfColums - columIndex;
+ grabExcessSpace = widget.isGrabExcessSpace();
+ } else {
+ colSpan = 1;
+ grabExcessSpace = widget instanceof PWButton && i == 0 ? true : widget.isGrabExcessSpace();
+ }
+ }
+ columIndex += widget.getNumberOfColumns();
+
+ if (i == 0 && grabExcessSpace && size > 1) {
+ if (widget instanceof PWLabel || widget instanceof PWButton) {
+ alignment = GridData.END;
+ } else {
+ alignment = GridData.BEGINNING;
+ }
+ } else {
+ alignment = widget.getAlignment();
+ }
+
+ final GridData gd = new GridData(alignment, GridData.BEGINNING, grabExcessSpace, false, colSpan, 1);
+ gd.horizontalIndent = widget.getIndent();
+ gd.widthHint = widget.getWidth();
+ if (widget.getHeight() != -1) {
+ gd.heightHint = widget.getHeight();
+ }
+ control.setLayoutData(gd);
+ }
+ }
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.PWRowGroup#checkParent(org.mihalis.opal.preferenceWindow.PWContainer)
+ */
+ @Override
+ protected void checkParent(final PWContainer parent) {
+ if (parent instanceof PWTab || parent instanceof PWGroup) {
+ return;
+ }
+ throw new UnsupportedOperationException("Bad parent, should be only PWTab or PWGroup");
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.PWRowGroup#enableOrDisable()
+ */
+ @Override
+ public void enableOrDisable() {
+ if (this.enabler == null) {
+ return;
+ }
+
+ final boolean enabled = this.enabler.isEnabled();
+ for (final PWWidget widget : this.widgets) {
+ final boolean widgetEnable = widget.enableOrDisable();
+ for (final Control c : widget.getControls()) {
+ if (!c.isDisposed()) {
+ c.setEnabled(enabled && widgetEnable);
+ }
+ }
+ }
+ }
+
+}
diff --git a/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/PWRowGroup.java b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/PWRowGroup.java new file mode 100644 index 000000000..63674bc29 --- /dev/null +++ b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/PWRowGroup.java @@ -0,0 +1,79 @@ +/*******************************************************************************
+ * Copyright (c) 2011 Laurent CARON
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Laurent CARON (laurent.caron at gmail dot com) - Initial implementation and API
+ *******************************************************************************/
+package org.mihalis.opal.preferenceWindow;
+
+import org.mihalis.opal.preferenceWindow.enabler.Enabler;
+
+/**
+ * Abstract class for both row and groups
+ */
+public abstract class PWRowGroup extends PWContainer {
+
+ protected int numberOfColumns;
+ protected int parentNumberOfColums;
+ protected PWContainer parent;
+ protected Enabler enabler;
+
+ /**
+ * Check if the parent is compatible with the object
+ *
+ * @param parent parent to check
+ * @throws UnsupportedOperationException if the parent is not compatible
+ * with the object
+ */
+ protected abstract void checkParent(PWContainer parent);
+
+ /**
+ * Enables or disables all elements stored in this group or row
+ */
+ public abstract void enableOrDisable();
+
+ /**
+ * Add a column to the current element
+ *
+ * @param number number of column to add
+ */
+ public void addColumn(final int number) {
+ this.numberOfColumns += number;
+ }
+
+ /**
+ * @return the number of columns of this group or row
+ */
+ public int getNumberOfColums() {
+ return this.numberOfColumns;
+ }
+
+ /**
+ * @param enabler the enabler to set
+ */
+ public PWRowGroup setEnabler(final Enabler enabler) {
+ this.enabler = enabler;
+ this.enabler.injectRowGroup(this);
+ return this;
+ }
+
+ /**
+ * @param parent the parent to set
+ */
+ public void setParent(final PWContainer parent) {
+ checkParent(parent);
+ this.parent = parent;
+ }
+
+ /**
+ * @param numberOfColumns the number of columns of the parent
+ */
+ public void setParentNumberOfColumns(final int numberOfColumns) {
+ this.parentNumberOfColums = numberOfColumns;
+ }
+
+}
diff --git a/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/PWTab.java b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/PWTab.java new file mode 100644 index 000000000..03fc554be --- /dev/null +++ b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/PWTab.java @@ -0,0 +1,111 @@ +/*******************************************************************************
+ * Copyright (c) 2011 Laurent CARON
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Laurent CARON (laurent.caron at gmail dot com) - Initial implementation and API
+ *******************************************************************************/
+package org.mihalis.opal.preferenceWindow;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.mihalis.opal.preferenceWindow.widgets.PWWidget;
+
+/**
+ * Instance of this class are tabs
+ *
+ */
+public class PWTab extends PWContainer {
+ private final Image image;
+ private final String text;
+ private final List<PWRowGroup> children;
+
+ /**
+ * Constructor
+ *
+ * @param image image associated to the tab
+ * @param text text associated to the tab
+ */
+ PWTab(final Image image, final String text) {
+ this.image = image;
+ this.text = text;
+ this.children = new ArrayList<PWRowGroup>();
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.PWContainer#add(org.mihalis.opal.preferenceWindow.PWContainer)
+ */
+ @Override
+ public PWContainer add(final PWContainer element) {
+ if (!(element instanceof PWGroup) && !(element instanceof PWRow)) {
+ throw new UnsupportedOperationException("Can only add a PWGroup or a PWRow.");
+ }
+ ((PWRowGroup) element).setParent(this);
+ this.children.add((PWRowGroup) element);
+ return this;
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.PWContainer#add(org.mihalis.opal.preferenceWindow.widgets.PWWidget)
+ */
+ @Override
+ public PWContainer add(final PWWidget widget) {
+ final PWRow row = new PWRow();
+ row.setParent(this);
+ row.add(widget);
+ this.children.add(row);
+ return this;
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.PWContainer#build(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ public void build(final Composite parent) {
+ final int numberOfColumns = computeNumberOfColums();
+ parent.setLayout(new GridLayout(numberOfColumns, false));
+
+ for (final PWRowGroup rowGroup : this.children) {
+ rowGroup.setParentNumberOfColumns(numberOfColumns);
+ rowGroup.build(parent);
+ }
+
+ PreferenceWindow.getInstance().fireEnablers();
+
+ }
+
+ /**
+ * @return the total number of columns in this tab
+ */
+ private int computeNumberOfColums() {
+ int numberOfColumns = 1;
+ for (final PWRowGroup rowGroup : this.children) {
+ if (rowGroup instanceof PWRow) {
+ numberOfColumns = Math.max(numberOfColumns, rowGroup.getNumberOfColums());
+ }
+ }
+ return numberOfColumns;
+ }
+
+ /**
+ * @return the image associate to this tab
+ */
+ public Image getImage() {
+ return this.image;
+ }
+
+ /**
+ * @return the text associated to this tab
+ */
+ public String getText() {
+ return this.text;
+ }
+
+}
diff --git a/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/PWTabContainer.java b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/PWTabContainer.java new file mode 100644 index 000000000..8bfe14c5f --- /dev/null +++ b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/PWTabContainer.java @@ -0,0 +1,228 @@ +/*******************************************************************************
+ * Copyright (c) 2011 Laurent CARON
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Laurent CARON (laurent.caron at gmail dot com) - Initial implementation and API
+ *******************************************************************************/
+package org.mihalis.opal.preferenceWindow;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+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.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.mihalis.opal.flatButton.FlatButton;
+import org.mihalis.opal.utils.SWTGraphicUtil;
+
+/**
+ * Instances of this class are a container that allows the user to select a tab
+ */
+class PWTabContainer extends Composite {
+
+ private final List<PWTab> tabs;
+ private Composite container;
+ private Image oldButtonContainerImage;
+ private final List<FlatButton> buttons;
+ private Composite buttonContainer;
+
+ /**
+ * Constructor
+ *
+ * @param parent parent composite
+ * @param style style (not used)
+ * @param tabs list of tabs
+ */
+ PWTabContainer(final Composite parent, final int style, final List<PWTab> tabs) {
+ super(parent, style);
+ this.tabs = new ArrayList<PWTab>();
+ this.tabs.addAll(tabs);
+
+ this.buttons = new ArrayList<FlatButton>();
+
+ final GridLayout gridLayout = new GridLayout(2, false);
+ gridLayout.marginWidth = gridLayout.marginHeight = 0;
+ gridLayout.horizontalSpacing = gridLayout.verticalSpacing = 0;
+ setLayout(gridLayout);
+
+ }
+
+ /**
+ * Build the container
+ */
+ void build() {
+ build(null);
+ }
+
+ void build(Color selectedTabColor) {
+
+ createButtonsContainer();
+ createButtons(selectedTabColor);
+ createContentContainer();
+
+ select(0);
+ }
+
+ /**
+ * Create the buttons container
+ */
+ private void createButtonsContainer() {
+ createContainer();
+ createButtonsContainerBackground();
+
+ }
+
+ /**
+ * Create the container
+ */
+ private void createContainer() {
+ this.buttonContainer = new Composite(this, SWT.NONE);
+ final GridData buttonContainerGridData = new GridData(GridData.FILL, GridData.FILL, true, false, 2, 1);
+ //buttonContainerGridData.heightHint = 63; // Original size (32x32)
+ //buttonContainerGridData.heightHint = 79; // Tizen fit size (48x48)
+ this.buttonContainer.setLayoutData(buttonContainerGridData);
+
+ this.buttonContainer.setBackground(getDisplay().getSystemColor(SWT.COLOR_WHITE));
+
+ final GridLayout gridLayout = new GridLayout(this.tabs.size(), false);
+ gridLayout.marginWidth = gridLayout.marginHeight = 0;
+ gridLayout.horizontalSpacing = gridLayout.verticalSpacing = 0;
+ gridLayout.marginBottom = 2;
+ this.buttonContainer.setLayout(gridLayout);
+ }
+
+ /**
+ * Create the background of the container
+ */
+ private void createButtonsContainerBackground() {
+ this.buttonContainer.addListener(SWT.Resize, new Listener() {
+
+ @Override
+ public void handleEvent(final Event event) {
+ final Rectangle rect = PWTabContainer.this.buttonContainer.getClientArea();
+ final Image image = new Image(getDisplay(), Math.max(1, rect.width), Math.max(1, rect.height));
+ final GC gc = new GC(image);
+ final Color grey = new Color(getDisplay(), 204, 204, 204);
+ gc.setForeground(grey);
+ gc.drawLine(0, rect.height - 1, rect.width, rect.height - 1);
+ grey.dispose();
+ gc.dispose();
+ PWTabContainer.this.buttonContainer.setBackgroundImage(image);
+ if (PWTabContainer.this.oldButtonContainerImage != null) {
+ PWTabContainer.this.oldButtonContainerImage.dispose();
+ }
+ PWTabContainer.this.oldButtonContainerImage = image;
+
+ }
+ });
+ SWTGraphicUtil.dispose(this.buttonContainer, this.oldButtonContainerImage);
+ }
+
+// /**
+// * Create the buttons
+// */
+// private void createButtons() {
+// createButtons(null);
+// }
+
+ private void createButtons(Color selectedTabColor) {
+ for (int i = 0; i < this.tabs.size(); i++) {
+ final PWTab tab = this.tabs.get(i);
+ final FlatButton button = new FlatButton(this.buttonContainer, SWT.NONE);
+ button.setText(tab.getText());
+ button.setImage(tab.getImage());
+
+ if(selectedTabColor != null) {
+ button.setSelectedColor(selectedTabColor);
+ }
+ SWTGraphicUtil.dispose(button, tab.getImage());
+
+ final GridData gd;
+ if (i == this.tabs.size() - 1) {
+ gd = new GridData(GridData.BEGINNING, GridData.BEGINNING, true, false);
+ } else {
+ gd = new GridData(GridData.BEGINNING, GridData.BEGINNING, false, false);
+ }
+ if (i == 0) {
+ gd.horizontalIndent = 5;
+ }
+ gd.widthHint = 75;
+ button.setLayoutData(gd);
+
+ final int index = i;
+ button.addSelectionListener(new SelectionAdapter() {
+
+ /**
+ * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
+ */
+ @Override
+ public void widgetSelected(final SelectionEvent e) {
+ select(index);
+ }
+
+ });
+
+ this.buttons.add(button);
+
+ }
+ }
+
+ /**
+ * Select a given button
+ *
+ * @param index index of the selected button
+ */
+ private void select(final int index) {
+ for (final Control c : this.container.getChildren()) {
+ c.dispose();
+ }
+
+ this.tabs.get(index).build(this.container);
+ this.container.layout();
+
+ for (int i = 0; i < this.buttons.size(); i++) {
+ this.buttons.get(i).setSelection(i == index);
+ }
+ }
+
+ /**
+ * Create the content container, ie the composite that will contain all
+ * widgets
+ */
+ private void createContentContainer() {
+ this.container = new Composite(this, SWT.NONE);
+ final GridData tempContainer = new GridData(GridData.FILL, GridData.FILL, true, true, 2, 1);
+
+ int defaultSize = 350;
+ int notebookSize = 280;
+
+ //tempContainer.widthHint = 700;
+ tempContainer.heightHint = defaultSize;
+
+ Rectangle bounds = Display.getCurrent().getBounds();
+ if (bounds.height <= (768 + defaultSize - notebookSize)) {
+ tempContainer.heightHint = notebookSize; // 280px is fitted on 768px display
+ }
+
+ this.container.setLayoutData(tempContainer);
+ }
+
+ public Composite getContainer() {
+ return this.container;
+ }
+}
diff --git a/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/PreferenceWindow.java b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/PreferenceWindow.java new file mode 100644 index 000000000..01de51e67 --- /dev/null +++ b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/PreferenceWindow.java @@ -0,0 +1,306 @@ +/*******************************************************************************
+ * Copyright (c) 2011 Laurent CARON
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Laurent CARON (laurent.caron at gmail dot com) - Initial implementation and API
+ *******************************************************************************/
+package org.mihalis.opal.preferenceWindow;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+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.mihalis.opal.preferenceWindow.widgets.PWWidget;
+import org.mihalis.opal.utils.ResourceManager;
+import org.mihalis.opal.utils.SWTGraphicUtil;
+
+/**
+ * This class is a preference window
+ *
+ */
+public class PreferenceWindow {
+ private final Map<String, ValueAndAssociatedWidgets> values;
+ private final List<PWTab> tabs;
+ private final Shell parentShell;
+ private boolean returnedValue;
+ private Shell shell;
+ private static PreferenceWindow instance;
+
+
+ /**
+ * Constructor
+ *
+ * @param parent parent shell (may be null)
+ * @param values a map that contains all values that will be displayed in
+ * widgets
+ */
+ private PreferenceWindow(final Shell parent, final Map<String, Object> values) {
+ this.parentShell = parent;
+ this.values = new HashMap<String, ValueAndAssociatedWidgets>(values.size());
+
+ for (final String key : values.keySet()) {
+ this.values.put(key, new ValueAndAssociatedWidgets(values.get(key)));
+ }
+
+ this.tabs = new ArrayList<PWTab>();
+ }
+
+ /**
+ * Create a preference window (a singleton)
+ *
+ * @param parent parent shell (may be null)
+ * @param values a map that contains all values that will be displayed in
+ * widgets
+ * @return
+ */
+ public static PreferenceWindow create(final Shell parent, final Map<String, Object> values) {
+ instance = new PreferenceWindow(parent, values);
+ return instance;
+ }
+
+ /**
+ * Create a preference window (a singleton)
+ *
+ * @param values a map that contains all values that will be displayed in
+ * widgets
+ * @return
+ */
+ public static PreferenceWindow create(final Map<String, Object> values) {
+ instance = new PreferenceWindow(null, values);
+ return instance;
+ }
+
+ /**
+ * @return an instance of the preference window
+ */
+ public static PreferenceWindow getInstance() {
+ if (instance == null) {
+ throw new NullPointerException("The instance of PreferenceWindow has not yet been created or has been destroyed.");
+ }
+ return instance;
+ }
+
+ /**
+ * Add a tab to the preference window
+ *
+ * @param image image associated to the tab
+ * @param text text associated to the image
+ * @return the
+ */
+ public PWTab addTab(final Image image, final String text) {
+ final PWTab tab = new PWTab(image, text);
+ this.tabs.add(tab);
+ return tab;
+ }
+
+ /**
+ * Add a widget that is linked to a given property
+ *
+ * @param propertyKey the property
+ * @param widget the widget
+ */
+ public void addWidgetLinkedTo(final String propertyKey, final PWWidget widget) {
+ if (!this.values.containsKey(propertyKey)) {
+ this.values.put(propertyKey, new ValueAndAssociatedWidgets(null));
+ }
+ this.values.get(propertyKey).addWidget(widget);
+ }
+
+ /**
+ * Add a row group that is linked to a given property
+ *
+ * @param propertyKey the property
+ * @param rowGroup the widget
+ */
+ public void addRowGroupLinkedTo(final String propertyKey, final PWRowGroup rowGroup) {
+ if (!this.values.containsKey(propertyKey)) {
+ this.values.put(propertyKey, new ValueAndAssociatedWidgets(null));
+ }
+ this.values.get(propertyKey).addRowGroup(rowGroup);
+ }
+
+ /**
+ * Open the preference window
+ *
+ * @return <code>true</code> if the user pressed on the Ok button,
+ * <code>false</code> if the user pressed on the Cancel button
+ */
+ public boolean open() {
+ if (this.parentShell == null) {
+ this.shell = new Shell(SWT.SHELL_TRIM);
+ } else {
+ this.shell = new Shell(instance.parentShell, SWT.SHELL_TRIM);
+ }
+
+ this.shell.addListener(SWT.Dispose, new Listener() {
+
+ @Override
+ public void handleEvent(final Event event) {
+ instance = null;
+ }
+ });
+
+ buildShell();
+ openShell();
+
+ return this.returnedValue;
+ }
+
+ /**
+ * Builds the shell
+ */
+ private void buildShell() {
+ this.shell.setText(ResourceManager.getLabel(ResourceManager.PREFERENCES));
+ final GridLayout gridLayout = new GridLayout(2, false);
+ gridLayout.marginWidth = gridLayout.marginHeight = 0;
+ gridLayout.horizontalSpacing = gridLayout.verticalSpacing = 0;
+ this.shell.setLayout(gridLayout);
+ final PWTabContainer container = new PWTabContainer(this.shell, SWT.NONE, this.tabs);
+ container.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true, 2, 1));
+ container.build();
+
+ final Label sep = new Label(this.shell, SWT.SEPARATOR | SWT.HORIZONTAL);
+ sep.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true, 2, 1));
+
+ buildButtons();
+
+ }
+
+ /**
+ * Builds the Tabs for inner composite
+ *
+ * @author Jihoon Song {@literal <jihoon80.song@samsung.com>} (S-Core)
+ */
+ public void buildTabs(Composite parent) {
+ buildTabs(parent, null);
+ }
+
+ public void buildTabs(Composite parent, Color selectedTabColor) {
+ final PWTabContainer container = new PWTabContainer(parent, SWT.BORDER, this.tabs);
+ container.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true, 2, 1));
+ container.build(selectedTabColor);
+ }
+
+ /**
+ * Builds the buttons
+ */
+ private void buildButtons() {
+ final Button buttonOK = new Button(this.shell, SWT.PUSH);
+ buttonOK.setText(ResourceManager.getLabel(ResourceManager.OK));
+ final GridData gridDataOk = new GridData(GridData.END, GridData.END, true, false);
+ gridDataOk.widthHint = 100;
+ buttonOK.setLayoutData(gridDataOk);
+ buttonOK.addSelectionListener(new SelectionAdapter() {
+
+ /**
+ * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
+ */
+ @Override
+ public void widgetSelected(final SelectionEvent e) {
+ PreferenceWindow.this.returnedValue = true;
+ PreferenceWindow.this.shell.dispose();
+ }
+
+ });
+ this.shell.setDefaultButton(buttonOK);
+
+ final Button buttonCancel = new Button(this.shell, SWT.PUSH);
+ buttonCancel.setText(ResourceManager.getLabel(ResourceManager.CANCEL));
+ final GridData gridDataCancel = new GridData(GridData.BEGINNING, GridData.END, false, false);
+ gridDataCancel.widthHint = 100;
+ buttonCancel.setLayoutData(gridDataCancel);
+ buttonCancel.addSelectionListener(new SelectionAdapter() {
+
+ /**
+ * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
+ */
+ @Override
+ public void widgetSelected(final SelectionEvent e) {
+ PreferenceWindow.this.returnedValue = false;
+ PreferenceWindow.this.shell.dispose();
+ }
+
+ });
+ }
+
+ /**
+ * Open the shell
+ */
+ private void openShell() {
+ this.shell.pack();
+ this.shell.open();
+ SWTGraphicUtil.centerShell(this.shell);
+
+ while (!this.shell.isDisposed()) {
+ if (!this.shell.getDisplay().readAndDispatch()) {
+ this.shell.getDisplay().sleep();
+ }
+ }
+
+ }
+
+ /**
+ * Fire all enablers
+ */
+ public void fireEnablers() {
+ for (final String key : this.values.keySet()) {
+ this.values.get(key).fireValueChanged();
+ }
+ }
+
+ /**
+ * @param key
+ * @return the value associated to the <i>key</i>
+ */
+ public Object getValueFor(final String key) {
+ if (this.values.containsKey(key)) {
+ return this.values.get(key).getValue();
+ }
+ return null;
+ }
+
+ /**
+ * @return the list of all values
+ */
+ public Map<String, Object> getValues() {
+ final Map<String, Object> returnedValues = new HashMap<String, Object>();
+ for (final String key : this.values.keySet()) {
+ returnedValues.put(key, this.values.get(key).getValue());
+ }
+ return returnedValues;
+ }
+
+ /**
+ * Store a value associated to the key
+ *
+ * @param key
+ * @param value
+ */
+ public void setValue(final String key, final Object value) {
+ if (this.values.containsKey(key)) {
+ this.values.get(key).setValue(value);
+ } else {
+ this.values.put(key, new ValueAndAssociatedWidgets(value));
+ }
+
+ }
+
+}
diff --git a/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/ValueAndAssociatedWidgets.java b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/ValueAndAssociatedWidgets.java new file mode 100644 index 000000000..5d13736fd --- /dev/null +++ b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/ValueAndAssociatedWidgets.java @@ -0,0 +1,79 @@ +/*******************************************************************************
+ * Copyright (c) 2011 Laurent CARON
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Laurent CARON (laurent.caron at gmail dot com) - Initial implementation and API
+ *******************************************************************************/
+package org.mihalis.opal.preferenceWindow;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.mihalis.opal.preferenceWindow.widgets.PWWidget;
+
+/**
+ * This POJO contains a value a list of widgets that depends on a given property
+ *
+ */
+class ValueAndAssociatedWidgets {
+ private Object value;
+ private final List<PWWidget> widgets;
+ private final List<PWRowGroup> rowGroups;
+
+ /**
+ * Constructor
+ *
+ * @param value associated value
+ */
+ ValueAndAssociatedWidgets(final Object value) {
+ this.value = value;
+ this.widgets = new ArrayList<PWWidget>();
+ this.rowGroups = new ArrayList<PWRowGroup>();
+ }
+
+ /**
+ * @param widget dependant widget
+ */
+ void addWidget(final PWWidget widget) {
+ this.widgets.add(widget);
+ }
+
+ /**
+ * @param rowGroup dependant row or group
+ */
+ void addRowGroup(final PWRowGroup rowGroup) {
+ this.rowGroups.add(rowGroup);
+ }
+
+ /**
+ * @return the value stored in the instance
+ */
+ Object getValue() {
+ return this.value;
+ }
+
+ /**
+ * @param value new value stored in this instance
+ */
+ void setValue(final Object value) {
+ this.value = value;
+ fireValueChanged();
+ }
+
+ /**
+ * Fire events when the value has changed
+ */
+ void fireValueChanged() {
+ for (final PWRowGroup rowGroup : this.rowGroups) {
+ rowGroup.enableOrDisable();
+ }
+
+ for (final PWWidget widget : this.widgets) {
+ widget.enableOrDisable();
+ }
+ }
+}
diff --git a/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/enabler/EnabledIfEquals.java b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/enabler/EnabledIfEquals.java new file mode 100644 index 000000000..b29db9dce --- /dev/null +++ b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/enabler/EnabledIfEquals.java @@ -0,0 +1,44 @@ +/*******************************************************************************
+ * Copyright (c) 2011 Laurent CARON
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Laurent CARON (laurent.caron at gmail dot com) - Initial implementation and API
+ *******************************************************************************/
+package org.mihalis.opal.preferenceWindow.enabler;
+
+import org.mihalis.opal.preferenceWindow.PreferenceWindow;
+
+/**
+ * This enabler is used to enable a widget if a property is equal to a given
+ * value
+ */
+public class EnabledIfEquals extends Enabler {
+ private final Object value;
+
+ /**
+ * Constructor
+ *
+ * @param prop property to evaluate
+ * @param value condition value
+ */
+ public EnabledIfEquals(final String prop, final Object value) {
+ super(prop);
+ this.value = value;
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.enabler.Enabler#isEnabled()
+ */
+ @Override
+ public boolean isEnabled() {
+ final Object propValue = PreferenceWindow.getInstance().getValueFor(this.prop);
+ if (this.value == null) {
+ return propValue == null;
+ }
+ return this.value.equals(propValue);
+ }
+}
diff --git a/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/enabler/EnabledIfNotEquals.java b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/enabler/EnabledIfNotEquals.java new file mode 100644 index 000000000..7f4e9c130 --- /dev/null +++ b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/enabler/EnabledIfNotEquals.java @@ -0,0 +1,44 @@ +/*******************************************************************************
+ * Copyright (c) 2011 Laurent CARON
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Laurent CARON (laurent.caron at gmail dot com) - Initial implementation and API
+ *******************************************************************************/
+package org.mihalis.opal.preferenceWindow.enabler;
+
+import org.mihalis.opal.preferenceWindow.PreferenceWindow;
+
+/**
+ * This enabler is used to enable a widget if a property is not equal to a given
+ * value
+ */
+public class EnabledIfNotEquals extends Enabler {
+ private final Object value;
+
+ /**
+ * Constructor
+ *
+ * @param prop property to evaluate
+ * @param value condition value
+ */
+ public EnabledIfNotEquals(final String prop, final Object value) {
+ super(prop);
+ this.value = value;
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.enabler.Enabler#isEnabled()
+ */
+ @Override
+ public boolean isEnabled() {
+ final Object propValue = PreferenceWindow.getInstance().getValueFor(this.prop);
+ if (this.value == null) {
+ return propValue == null;
+ }
+ return !this.value.equals(propValue);
+ }
+}
diff --git a/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/enabler/EnabledIfTrue.java b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/enabler/EnabledIfTrue.java new file mode 100644 index 000000000..969e2c58a --- /dev/null +++ b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/enabler/EnabledIfTrue.java @@ -0,0 +1,46 @@ +/*******************************************************************************
+ * Copyright (c) 2011 Laurent CARON
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Laurent CARON (laurent.caron at gmail dot com) - Initial implementation and API
+ *******************************************************************************/
+package org.mihalis.opal.preferenceWindow.enabler;
+
+import org.mihalis.opal.preferenceWindow.PreferenceWindow;
+
+/**
+ * This enabler is used to enable a widget if a boolean property is true
+ */
+public class EnabledIfTrue extends Enabler {
+
+ /**
+ * Constructor
+ *
+ * @param prop boolean property
+ */
+ public EnabledIfTrue(final String prop) {
+ super(prop);
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.enabler.Enabler#isEnabled()
+ */
+ @Override
+ public boolean isEnabled() {
+ final Object value = PreferenceWindow.getInstance().getValueFor(this.prop);
+
+ if (value != null && !(value instanceof Boolean)) {
+ throw new UnsupportedOperationException("Impossible to evaluate [" + this.prop + "] because it is not a Boolean !");
+ }
+
+ if (value == null) {
+ return true;
+ }
+
+ return ((Boolean) value).booleanValue();
+ }
+}
diff --git a/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/enabler/Enabler.java b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/enabler/Enabler.java new file mode 100644 index 000000000..3b0e04afd --- /dev/null +++ b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/enabler/Enabler.java @@ -0,0 +1,57 @@ +/*******************************************************************************
+ * Copyright (c) 2011 Laurent CARON
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Laurent CARON (laurent.caron at gmail dot com) - Initial implementation and API
+ *******************************************************************************/
+package org.mihalis.opal.preferenceWindow.enabler;
+
+import org.mihalis.opal.preferenceWindow.PWRowGroup;
+import org.mihalis.opal.preferenceWindow.PreferenceWindow;
+import org.mihalis.opal.preferenceWindow.widgets.PWWidget;
+
+/**
+ * This is the abstract class of all Enablers. An enabler is an object used to
+ * enable or disable a widget depending on a value of a stored property.
+ */
+public abstract class Enabler {
+
+ protected String prop;
+
+ /**
+ * Constructor
+ *
+ * @param prop property linked to the enabler.
+ */
+ public Enabler(final String prop) {
+ this.prop = prop;
+ }
+
+ /**
+ * @return the evaluation condition
+ */
+ public abstract boolean isEnabled();
+
+ /**
+ * Link a widget to the enabler
+ *
+ * @param widget widget to link
+ */
+ public void injectWidget(final PWWidget widget) {
+ PreferenceWindow.getInstance().addWidgetLinkedTo(this.prop, widget);
+ }
+
+ /**
+ * Link a row or a group to the enabler
+ *
+ * @param rowGroup RowGroup to link
+ */
+ public void injectRowGroup(final PWRowGroup rowGroup) {
+ PreferenceWindow.getInstance().addRowGroupLinkedTo(this.prop, rowGroup);
+ }
+
+}
diff --git a/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWButton.java b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWButton.java new file mode 100644 index 000000000..4762b8050 --- /dev/null +++ b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWButton.java @@ -0,0 +1,63 @@ +/*******************************************************************************
+ * Copyright (c) 2011 Laurent CARON
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Laurent CARON (laurent.caron at gmail dot com) - Initial implementation and API
+ *******************************************************************************/
+package org.mihalis.opal.preferenceWindow.widgets;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+
+/**
+ * Instances of this class are buttons
+ *
+ */
+public class PWButton extends PWWidget {
+ private final SelectionListener listener;
+
+ /**
+ * Constructor
+ *
+ * @param label associated label
+ * @param listener selection listener
+ */
+ public PWButton(final String label, final SelectionListener listener) {
+ super(label, null, 1, true);
+ this.listener = listener;
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWWidget#build(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ public Control build(final Composite parent) {
+ final Button button = new Button(parent, SWT.PUSH);
+ addControl(button);
+ if (getLabel() == null) {
+ throw new UnsupportedOperationException("You need to set a label for a button");
+ } else {
+ button.setText(getLabel());
+ }
+ if (this.listener != null) {
+ button.addSelectionListener(this.listener);
+ }
+
+ return button;
+
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWWidget#check()
+ */
+ @Override
+ public void check() {
+ }
+}
diff --git a/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWCheckbox.java b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWCheckbox.java new file mode 100644 index 000000000..8dc7f367e --- /dev/null +++ b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWCheckbox.java @@ -0,0 +1,76 @@ +/*******************************************************************************
+ * Copyright (c) 2011 Laurent CARON
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Laurent CARON (laurent.caron at gmail dot com) - Initial implementation and API
+ *******************************************************************************/
+package org.mihalis.opal.preferenceWindow.widgets;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.mihalis.opal.preferenceWindow.PreferenceWindow;
+
+/**
+ * Instances of this class are checkboxes
+ */
+public class PWCheckbox extends PWWidget {
+
+ /**
+ * Constructor
+ *
+ * @param label associated label
+ * @param propertyKey associated key
+ */
+ public PWCheckbox(final String label, final String propertyKey) {
+ super(label, propertyKey, 1, true);
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWWidget#build(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ public Control build(final Composite parent) {
+ if (getLabel() == null) {
+ throw new UnsupportedOperationException("Please specify a label for a checkbox");
+ }
+ final Button button = new Button(parent, SWT.CHECK);
+ addControl(button);
+ button.setText(getLabel());
+ final boolean originalSelection = (Boolean) PreferenceWindow.getInstance().getValueFor(getPropertyKey());
+ button.setSelection(originalSelection);
+
+ button.addSelectionListener(new SelectionAdapter() {
+ /**
+ * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
+ */
+ @Override
+ public void widgetSelected(final SelectionEvent e) {
+ PreferenceWindow.getInstance().setValue(getPropertyKey(), button.getSelection());
+ }
+ });
+ return button;
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWWidget#check()
+ */
+ @Override
+ public void check() {
+ final Object value = PreferenceWindow.getInstance().getValueFor(getPropertyKey());
+ if (value == null) {
+ PreferenceWindow.getInstance().setValue(getPropertyKey(), new Boolean(false));
+ } else {
+ if (!(value instanceof Boolean)) {
+ throw new UnsupportedOperationException("The property '" + getPropertyKey() + "' has to be a Boolean because it is associated to a checkbox");
+ }
+ }
+ }
+}
diff --git a/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWChooser.java b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWChooser.java new file mode 100644 index 000000000..318215a50 --- /dev/null +++ b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWChooser.java @@ -0,0 +1,82 @@ +/*******************************************************************************
+ * Copyright (c) 2011 Laurent CARON
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Laurent CARON (laurent.caron at gmail dot com) - Initial implementation and API
+ *******************************************************************************/
+package org.mihalis.opal.preferenceWindow.widgets;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+import org.mihalis.opal.utils.ResourceManager;
+
+/**
+ * Abstract class for chooser widgets
+ *
+ */
+public abstract class PWChooser extends PWWidget {
+
+ /**
+ * Constructor
+ *
+ * @param label associated label
+ * @param propertyKey associated key
+ */
+ public PWChooser(final String label, final String propertyKey) {
+ super(label, propertyKey, 3, false);
+ setGrabExcessSpace(false);
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWWidget#build(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ public Control build(final Composite parent) {
+ final Label label = new Label(parent, SWT.NONE);
+
+ if (getLabel() == null) {
+ throw new UnsupportedOperationException("You need to set a label for a directory or a dialog chooser");
+ } else {
+ label.setText(getLabel());
+ }
+ addControl(label);
+ final GridData labelGridData = new GridData(GridData.END, GridData.BEGINNING, false, false);
+ labelGridData.horizontalIndent = getIndent();
+ label.setLayoutData(labelGridData);
+
+ final Text text = new Text(parent, SWT.BORDER | SWT.READ_ONLY);
+ addControl(text);
+ final GridData textGridData = new GridData(GridData.FILL, GridData.BEGINNING, true, false);
+ text.setLayoutData(textGridData);
+
+ final Button button = new Button(parent, SWT.PUSH);
+ addControl(button);
+ final GridData buttonGridData = new GridData(GridData.FILL, GridData.BEGINNING, false, false);
+ buttonGridData.widthHint = 150;
+ button.setText(ResourceManager.getLabel(ResourceManager.CHOOSE) + "...");
+ button.setLayoutData(buttonGridData);
+
+ setButtonAction(text, button);
+
+ return button;
+
+ }
+
+ /**
+ * Code executed when the user presses the button
+ *
+ * @param text text box
+ * @param button associated button
+ */
+ protected abstract void setButtonAction(Text text, Button button);
+
+}
diff --git a/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWColorChooser.java b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWColorChooser.java new file mode 100644 index 000000000..0d3b1b327 --- /dev/null +++ b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWColorChooser.java @@ -0,0 +1,133 @@ +/*******************************************************************************
+ * Copyright (c) 2011 Laurent CARON
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Laurent CARON (laurent.caron at gmail dot com) - Initial implementation and API
+ *******************************************************************************/
+package org.mihalis.opal.preferenceWindow.widgets;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.ColorDialog;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.mihalis.opal.preferenceWindow.PreferenceWindow;
+import org.mihalis.opal.utils.SWTGraphicUtil;
+
+/**
+ * Instances of this class are used to select a color
+ *
+ */
+public class PWColorChooser extends PWWidget {
+
+ private Color color;
+
+ /**
+ * Constructor
+ *
+ * @param label associated label
+ * @param propertyKey associated key
+ */
+ public PWColorChooser(final String label, final String propertyKey) {
+ super(label, propertyKey, label == null ? 1 : 2, false);
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWWidget#build(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ public Control build(final Composite parent) {
+ final RGB rgb = (RGB) PreferenceWindow.getInstance().getValueFor(getPropertyKey());
+
+ if (rgb == null) {
+ this.color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
+ } else {
+ this.color = new Color(Display.getDefault(), rgb);
+ }
+
+ buildLabel(parent, GridData.CENTER);
+ final Button button = new Button(parent, SWT.PUSH);
+ addControl(button);
+
+ button.addListener(SWT.Resize, new Listener() {
+ @Override
+ public void handleEvent(final Event event) {
+ drawButton(button);
+ }
+ });
+
+ button.addListener(SWT.Selection, new Listener() {
+
+ @Override
+ public void handleEvent(final Event event) {
+ final ColorDialog dialog = new ColorDialog(button.getShell());
+ final RGB result = dialog.open();
+ if (result != null) {
+ SWTGraphicUtil.dispose(PWColorChooser.this.color);
+ PWColorChooser.this.color = new Color(button.getDisplay(), result);
+ drawButton(button);
+ PreferenceWindow.getInstance().setValue(getPropertyKey(), result);
+ }
+ }
+ });
+
+ button.addListener(SWT.Dispose, new Listener() {
+
+ @Override
+ public void handleEvent(final Event event) {
+ SWTGraphicUtil.dispose(PWColorChooser.this.color);
+ }
+ });
+
+ return button;
+ }
+
+ /**
+ * @param button button on which we draw the rectangle
+ */
+ protected void drawButton(final Button button) {
+ final int height = (int) button.getFont().getFontData()[0].height;
+ final int width = button.getBounds().width - 16;
+
+ final Image newImage = new Image(button.getDisplay(), Math.max(1, width), Math.max(1, height));
+
+ final GC gc = new GC(newImage);
+ gc.setBackground(PWColorChooser.this.color);
+ gc.fillRectangle(0, 0, width, height);
+
+ gc.setForeground(button.getDisplay().getSystemColor(SWT.COLOR_BLACK));
+ gc.drawRectangle(0, 0, width - 1, height - 1);
+
+ gc.dispose();
+
+ button.setImage(newImage);
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWWidget#check()
+ */
+ @Override
+ public void check() {
+ final Object value = PreferenceWindow.getInstance().getValueFor(getPropertyKey());
+ if (value == null) {
+ PreferenceWindow.getInstance().setValue(getPropertyKey(), null);
+ } else {
+ if (!(value instanceof RGB)) {
+ throw new UnsupportedOperationException("The property '" + getPropertyKey() + "' has to be a RGB because it is associated to a color chooser");
+ }
+ }
+ }
+
+}
diff --git a/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWCombo.java b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWCombo.java new file mode 100644 index 000000000..1960011bc --- /dev/null +++ b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWCombo.java @@ -0,0 +1,107 @@ +/*******************************************************************************
+ * Copyright (c) 2011 Laurent CARON
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Laurent CARON (laurent.caron at gmail dot com) - Initial implementation and API
+ *******************************************************************************/
+package org.mihalis.opal.preferenceWindow.widgets;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.mihalis.opal.preferenceWindow.PreferenceWindow;
+
+/**
+ * Instances of this class are Combo
+ *
+ */
+public class PWCombo extends PWWidget {
+
+ private final List<Object> data;
+ private final boolean editable;
+
+ /**
+ * Constructor
+ *
+ * @param label associated label
+ * @param propertyKey associated key
+ */
+ public PWCombo(final String label, final String propertyKey, final Object... values) {
+ this(label, propertyKey, false, values);
+ }
+
+ /**
+ * Constructor
+ *
+ * @param label associated label
+ * @param propertyKey associated key
+ */
+ public PWCombo(final String label, final String propertyKey, final boolean editable, final Object... values) {
+ super(label, propertyKey, label == null ? 1 : 2, false);
+ this.data = new ArrayList<Object>(Arrays.asList(values));
+ this.editable = editable;
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWWidget#build(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ public Control build(final Composite parent) {
+ buildLabel(parent, GridData.CENTER);
+
+ final Combo combo = new Combo(parent, SWT.BORDER | (this.editable ? SWT.NONE : SWT.READ_ONLY));
+ addControl(combo);
+
+ for (int i = 0; i < this.data.size(); i++) {
+ final Object datum = this.data.get(i);
+ combo.add(datum.toString());
+ if (datum.equals(PreferenceWindow.getInstance().getValueFor(getPropertyKey()))) {
+ combo.select(i);
+ }
+ }
+
+ combo.addListener(SWT.Modify, new Listener() {
+
+ @Override
+ public void handleEvent(final Event event) {
+ PreferenceWindow.getInstance().setValue(getPropertyKey(), PWCombo.this.data.get(combo.getSelectionIndex()));
+ }
+ });
+
+ return combo;
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWWidget#check()
+ */
+ @Override
+ public void check() {
+ final Object value = PreferenceWindow.getInstance().getValueFor(getPropertyKey());
+ if (value == null) {
+ PreferenceWindow.getInstance().setValue(getPropertyKey(), null);
+ } else {
+ if (this.editable && !(value instanceof String)) {
+ throw new UnsupportedOperationException("The property '" + getPropertyKey() + "' has to be a String because it is associated to an editable combo");
+ }
+
+ if (!this.data.isEmpty()) {
+ if (!value.getClass().equals(this.data.get(0).getClass())) {
+ throw new UnsupportedOperationException("The property '" + getPropertyKey() + "' has to be a " + this.data.get(0).getClass() + " because it is associated to a combo");
+ }
+ }
+
+ }
+ }
+}
diff --git a/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWDirectoryChooser.java b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWDirectoryChooser.java new file mode 100644 index 000000000..db0cd9b13 --- /dev/null +++ b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWDirectoryChooser.java @@ -0,0 +1,78 @@ +/*******************************************************************************
+ * Copyright (c) 2011 Laurent CARON
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Laurent CARON (laurent.caron at gmail dot com) - Initial implementation and API
+ *******************************************************************************/
+package org.mihalis.opal.preferenceWindow.widgets;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.DirectoryDialog;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Text;
+import org.mihalis.opal.preferenceWindow.PreferenceWindow;
+import org.mihalis.opal.utils.ResourceManager;
+
+/**
+ * Instances of this class are used to select a directory
+ */
+public class PWDirectoryChooser extends PWChooser {
+
+ /**
+ * Constructor
+ *
+ * @param label associated label
+ * @param propertyKey associated key
+ */
+ public PWDirectoryChooser(final String label, final String propertyKey) {
+ super(label, propertyKey);
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWChooser#setButtonAction(org.eclipse.swt.widgets.Text,
+ * org.eclipse.swt.widgets.Button)
+ */
+ @Override
+ protected void setButtonAction(final Text text, final Button button) {
+
+ final String originalDirectory = (String) PreferenceWindow.getInstance().getValueFor(getPropertyKey());
+ text.setText(originalDirectory);
+
+ button.addListener(SWT.Selection, new Listener() {
+
+ @Override
+ public void handleEvent(final Event event) {
+ final DirectoryDialog dialog = new DirectoryDialog(text.getShell());
+ dialog.setMessage(ResourceManager.getLabel(ResourceManager.CHOOSE_DIRECTORY));
+ final String result = dialog.open();
+ if (result != null) {
+ text.setText(result);
+ PreferenceWindow.getInstance().setValue(getPropertyKey(), result);
+ }
+
+ }
+ });
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWWidget#check()
+ */
+ @Override
+ public void check() {
+ final Object value = PreferenceWindow.getInstance().getValueFor(getPropertyKey());
+ if (value == null) {
+ PreferenceWindow.getInstance().setValue(getPropertyKey(), "");
+ } else {
+ if (!(value instanceof String)) {
+ throw new UnsupportedOperationException("The property '" + getPropertyKey() + "' has to be a String because it is associated to a directory chooser");
+ }
+ }
+ }
+
+}
diff --git a/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWFileChooser.java b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWFileChooser.java new file mode 100644 index 000000000..421aa0e76 --- /dev/null +++ b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWFileChooser.java @@ -0,0 +1,75 @@ +/*******************************************************************************
+ * Copyright (c) 2011 Laurent CARON
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Laurent CARON (laurent.caron at gmail dot com) - Initial implementation and API
+ *******************************************************************************/
+package org.mihalis.opal.preferenceWindow.widgets;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Text;
+import org.mihalis.opal.preferenceWindow.PreferenceWindow;
+
+/**
+ * Instances of this class are used to select a file
+ */
+public class PWFileChooser extends PWChooser {
+
+ /**
+ * Constructor
+ *
+ * @param label associated label
+ * @param propertyKey associated key
+ */
+ public PWFileChooser(final String label, final String propertyKey) {
+ super(label, propertyKey);
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWChooser#setButtonAction(org.eclipse.swt.widgets.Text,
+ * org.eclipse.swt.widgets.Button)
+ */
+ @Override
+ protected void setButtonAction(final Text text, final Button button) {
+ final String originalFile = (String) PreferenceWindow.getInstance().getValueFor(getPropertyKey());
+ text.setText(originalFile);
+
+ button.addListener(SWT.Selection, new Listener() {
+ @Override
+ public void handleEvent(final Event event) {
+ final FileDialog dialog = new FileDialog(text.getShell(), SWT.OPEN);
+ final String result = dialog.open();
+ if (result != null) {
+ text.setText(result);
+ PreferenceWindow.getInstance().setValue(getPropertyKey(), result);
+ }
+
+ }
+ });
+
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWWidget#check()
+ */
+ @Override
+ public void check() {
+ final Object value = PreferenceWindow.getInstance().getValueFor(getPropertyKey());
+ if (value == null) {
+ PreferenceWindow.getInstance().setValue(getPropertyKey(), "");
+ } else {
+ if (!(value instanceof String)) {
+ throw new UnsupportedOperationException("The property '" + getPropertyKey() + "' has to be a String because it is associated to a file chooser");
+ }
+ }
+ }
+
+}
diff --git a/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWFloatText.java b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWFloatText.java new file mode 100644 index 000000000..db6446816 --- /dev/null +++ b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWFloatText.java @@ -0,0 +1,114 @@ +/*******************************************************************************
+ * Copyright (c) 2011 Laurent CARON
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Laurent CARON (laurent.caron at gmail dot com) - Initial implementation and API
+ *******************************************************************************/
+package org.mihalis.opal.preferenceWindow.widgets;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.VerifyEvent;
+import org.eclipse.swt.events.VerifyListener;
+import org.mihalis.opal.preferenceWindow.PreferenceWindow;
+import org.mihalis.opal.utils.StringUtil;
+
+/**
+ * Instances of this class are text box to type floats
+ */
+public class PWFloatText extends PWText {
+
+ /**
+ * Constructor
+ *
+ * @param label associated label
+ * @param propertyKey associated key
+ */
+ public PWFloatText(final String label, final String propertyKey) {
+ super(label, propertyKey);
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWText#addVerifyListeners()
+ */
+ @Override
+ public void addVerifyListeners() {
+ this.text.addVerifyListener(new VerifyListener() {
+
+ @Override
+ public void verifyText(final VerifyEvent e) {
+ if (e.character != 0 && !Character.isDigit(e.character) && e.keyCode != SWT.BS && e.keyCode != SWT.DEL && e.character != '.' && e.character != ',') {
+ e.doit = false;
+ return;
+ }
+
+ e.doit = verifyEntry(e.text, e.keyCode);
+
+ }
+ });
+
+ }
+
+ /**
+ * Check if an entry is a float
+ *
+ * @param entry text typed by the user
+ * @param keyCode key code
+ * @return true if the user typed a float value, false otherwise
+ */
+ private boolean verifyEntry(final String entry, final int keyCode) {
+ final String work;
+ if (keyCode == SWT.DEL) {
+ work = StringUtil.removeCharAt(this.text.getText(), this.text.getCaretPosition());
+ } else if (keyCode == SWT.BS && this.text.getCaretPosition() == 0) {
+ work = StringUtil.removeCharAt(this.text.getText(), this.text.getCaretPosition() - 1);
+ } else if (keyCode == 0) {
+ work = entry;
+ } else {
+ work = StringUtil.insertString(this.text.getText(), entry, this.text.getCaretPosition());
+ }
+
+ try {
+ Double.parseDouble(work.replace(',', '.'));
+ } catch (final NumberFormatException nfe) {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWWidget#check()
+ */
+ @Override
+ public void check() {
+ final Object value = PreferenceWindow.getInstance().getValueFor(getPropertyKey());
+ if (value == null) {
+ PreferenceWindow.getInstance().setValue(getPropertyKey(), new Float(0));
+ } else {
+ if (!(value instanceof Float)) {
+ throw new UnsupportedOperationException("The property '" + getPropertyKey() + "' has to be a Float because it is associated to a float text widget");
+ }
+ }
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWText#convertValue()
+ */
+ @Override
+ public Object convertValue() {
+ return Float.parseFloat(this.text.getText());
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWText#getStyle()
+ */
+ @Override
+ public int getStyle() {
+ return SWT.NONE;
+ }
+
+}
diff --git a/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWFontChooser.java b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWFontChooser.java new file mode 100644 index 000000000..5637fe2ea --- /dev/null +++ b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWFontChooser.java @@ -0,0 +1,95 @@ +/*******************************************************************************
+ * Copyright (c) 2011 Laurent CARON
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Laurent CARON (laurent.caron at gmail dot com) - Initial implementation and API
+ *******************************************************************************/
+package org.mihalis.opal.preferenceWindow.widgets;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.FontData;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.FontDialog;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Text;
+import org.mihalis.opal.preferenceWindow.PreferenceWindow;
+import org.mihalis.opal.utils.ResourceManager;
+
+/**
+ * Instances of this class are used to select a font
+ */
+public class PWFontChooser extends PWChooser {
+ private FontData fontData;
+
+ /**
+ * Constructor
+ *
+ * @param label associated label
+ * @param propertyKey associated key
+ */
+ public PWFontChooser(final String label, final String propertyKey) {
+ super(label, propertyKey);
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWWidget#check()
+ */
+ @Override
+ public void check() {
+ final Object value = PreferenceWindow.getInstance().getValueFor(getPropertyKey());
+ if (value == null) {
+ PreferenceWindow.getInstance().setValue(getPropertyKey(), null);
+ } else {
+ if (!(value instanceof FontData)) {
+ throw new UnsupportedOperationException("The property '" + getPropertyKey() + "' has to be a FontData because it is associated to a font chooser");
+ }
+ }
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWChooser#setButtonAction(org.eclipse.swt.widgets.Text,
+ * org.eclipse.swt.widgets.Button)
+ */
+ @Override
+ protected void setButtonAction(final Text text, final Button button) {
+ this.fontData = (FontData) PreferenceWindow.getInstance().getValueFor(getPropertyKey());
+
+ button.addListener(SWT.Selection, new Listener() {
+
+ @Override
+ public void handleEvent(final Event event) {
+ final FontDialog dialog = new FontDialog(text.getShell());
+ final FontData result = dialog.open();
+ if (result != null && result.getName() != null && !"".equals(result.getName().trim())) {
+ PWFontChooser.this.fontData = result;
+ PreferenceWindow.getInstance().setValue(getPropertyKey(), result);
+ text.setText(buildFontInformation());
+ }
+
+ }
+ });
+
+ }
+
+ /**
+ * @return a string that contains data about the choosen font
+ */
+ protected String buildFontInformation() {
+ final StringBuilder sb = new StringBuilder();
+ if (this.fontData != null) {
+ sb.append(this.fontData.getName()).append(",").append(this.fontData.getHeight()).append(" pt");
+ if ((this.fontData.getStyle() & SWT.BOLD) == SWT.BOLD) {
+ sb.append(", ").append(ResourceManager.getLabel(ResourceManager.BOLD));
+ }
+ if ((this.fontData.getStyle() & SWT.ITALIC) == SWT.ITALIC) {
+ sb.append(", ").append(ResourceManager.getLabel(ResourceManager.ITALIC));
+ }
+ }
+ return sb.toString();
+ }
+}
diff --git a/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWIntegerText.java b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWIntegerText.java new file mode 100644 index 000000000..8e681df17 --- /dev/null +++ b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWIntegerText.java @@ -0,0 +1,84 @@ +/*******************************************************************************
+ * Copyright (c) 2011 Laurent CARON
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Laurent CARON (laurent.caron at gmail dot com) - Initial implementation and API
+ *******************************************************************************/
+package org.mihalis.opal.preferenceWindow.widgets;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.mihalis.opal.preferenceWindow.PreferenceWindow;
+
+/**
+ * Instances of this class are text box to type Integers
+ */
+public class PWIntegerText extends PWText {
+
+ /**
+ * Constructor
+ *
+ * @param label associated label
+ * @param propertyKey associated key
+ */
+ public PWIntegerText(final String label, final String propertyKey) {
+ super(label, propertyKey);
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWText#addVerifyListeners()
+ */
+ @Override
+ public void addVerifyListeners() {
+ this.text.addListener(SWT.Verify, new Listener() {
+ @Override
+ public void handleEvent(final Event e) {
+ final String string = e.text;
+ final char[] chars = new char[string.length()];
+ string.getChars(0, chars.length, chars, 0);
+ for (int i = 0; i < chars.length; i++) {
+ if (!('0' <= chars[i] && chars[i] <= '9') && e.keyCode != SWT.BS && e.keyCode != SWT.DEL) {
+ e.doit = false;
+ return;
+ }
+ }
+ }
+ });
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWWidget#check()
+ */
+ @Override
+ public void check() {
+ final Object value = PreferenceWindow.getInstance().getValueFor(getPropertyKey());
+ if (value == null) {
+ PreferenceWindow.getInstance().setValue(getPropertyKey(), new Integer(0));
+ } else {
+ if (!(value instanceof Integer)) {
+ throw new UnsupportedOperationException("The property '" + getPropertyKey() + "' has to be an Integer because it is associated to a integer text widget");
+ }
+ }
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWText#convertValue()
+ */
+ @Override
+ public Object convertValue() {
+ return Integer.parseInt(this.text.getText());
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWText#getStyle()
+ */
+ @Override
+ public int getStyle() {
+ return SWT.NONE;
+ }
+}
diff --git a/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWLabel.java b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWLabel.java new file mode 100644 index 000000000..bcffef7b8 --- /dev/null +++ b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWLabel.java @@ -0,0 +1,81 @@ +/*******************************************************************************
+ * Copyright (c) 2011 Laurent CARON
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Laurent CARON (laurent.caron at gmail dot com) - Initial implementation and API
+ *******************************************************************************/
+package org.mihalis.opal.preferenceWindow.widgets;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.mihalis.opal.utils.SWTGraphicUtil;
+
+/**
+ * Instances of this class are labels, that could contain some HTML tags (B,I,U)
+ */
+public class PWLabel extends PWWidget {
+
+ private StyledText labelWidget;
+
+ /**
+ * Constructor
+ *
+ * @param label associated label
+ */
+ public PWLabel(final String label) {
+ super(label, null, 1, true);
+ setAlignment(GridData.FILL);
+ setGrabExcessSpace(true);
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWWidget#build(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ public Control build(final Composite parent) {
+ if (getLabel() == null) {
+ throw new UnsupportedOperationException("You need to set a description for a PWLabel object");
+ }
+ this.labelWidget = new StyledText(parent, SWT.WRAP | SWT.READ_ONLY);
+ this.labelWidget.setEnabled(false);
+ this.labelWidget.setBackground(parent.getBackground());
+ this.labelWidget.setText("<html><body>" + getLabel() + "</body></html>");
+ SWTGraphicUtil.applyHTMLFormating(this.labelWidget);
+ return this.labelWidget;
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWWidget#check()
+ */
+ @Override
+ public void check() {
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWWidget#enableOrDisable()
+ */
+ @Override
+ public boolean enableOrDisable() {
+ if (this.enabler == null) {
+ return true;
+ }
+
+ final boolean enabled = this.enabler.isEnabled();
+ if (!this.labelWidget.isDisposed()) {
+ if (enabled) {
+ this.labelWidget.setForeground(this.labelWidget.getDisplay().getSystemColor(SWT.COLOR_BLACK));
+ } else {
+ this.labelWidget.setForeground(this.labelWidget.getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY));
+ }
+ }
+ return enabled;
+ }
+
+}
diff --git a/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWPasswordText.java b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWPasswordText.java new file mode 100644 index 000000000..843b2882b --- /dev/null +++ b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWPasswordText.java @@ -0,0 +1,69 @@ +/*******************************************************************************
+ * Copyright (c) 2011 Laurent CARON
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Laurent CARON (laurent.caron at gmail dot com) - Initial implementation and API
+ *******************************************************************************/
+package org.mihalis.opal.preferenceWindow.widgets;
+
+import org.eclipse.swt.SWT;
+import org.mihalis.opal.preferenceWindow.PreferenceWindow;
+
+/**
+ * Instances of this class are text box to type password
+ */
+public class PWPasswordText extends PWText {
+
+ /**
+ * Constructor
+ *
+ * @param label associated label
+ * @param propertyKey associated key
+ */
+ public PWPasswordText(final String label, final String propertyKey) {
+ super(label, propertyKey);
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWText#addVerifyListeners()
+ */
+ @Override
+ public void addVerifyListeners() {
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWWidget#check()
+ */
+ @Override
+ public void check() {
+ final Object value = PreferenceWindow.getInstance().getValueFor(getPropertyKey());
+ if (value == null) {
+ PreferenceWindow.getInstance().setValue(getPropertyKey(), "");
+ } else {
+ if (!(value instanceof String)) {
+ throw new UnsupportedOperationException("The property '" + getPropertyKey() + "' has to be a String because it is associated to a password text box");
+ }
+ }
+
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWText#convertValue()
+ */
+ @Override
+ public Object convertValue() {
+ return this.text.getText();
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWText#getStyle()
+ */
+ @Override
+ public int getStyle() {
+ return SWT.PASSWORD;
+ }
+}
diff --git a/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWRadio.java b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWRadio.java new file mode 100644 index 000000000..3dfee00df --- /dev/null +++ b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWRadio.java @@ -0,0 +1,98 @@ +/*******************************************************************************
+ * Copyright (c) 2011 Laurent CARON
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Laurent CARON (laurent.caron at gmail dot com) - Initial implementation and API
+ *******************************************************************************/
+package org.mihalis.opal.preferenceWindow.widgets;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+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.Listener;
+import org.mihalis.opal.preferenceWindow.PreferenceWindow;
+
+/**
+ * Instances of this class are a group of radio buttons
+ *
+ */
+public class PWRadio extends PWWidget {
+
+ private final List<Object> data;
+ private final List<Button> buttons;
+
+ /**
+ * Constructor
+ *
+ * @param label associated label
+ * @param propertyKey associated key
+ */
+ public PWRadio(final String label, final String prop, final Object... values) {
+ super(null, prop, label == null ? 1 : 2, false);
+ this.data = new ArrayList<Object>(Arrays.asList(values));
+ this.buttons = new ArrayList<Button>();
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWWidget#build(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ public Control build(final Composite parent) {
+ buildLabel(parent, GridData.BEGINNING);
+
+ final Composite composite = new Composite(parent, SWT.NONE);
+ final GridLayout gridLayout = new GridLayout();
+ gridLayout.marginHeight = gridLayout.marginWidth = 0;
+ composite.setLayout(gridLayout);
+
+ for (final Object datum : this.data) {
+ final Button button = new Button(composite, SWT.RADIO);
+ addControl(button);
+ button.setText(datum.toString());
+ button.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, false));
+ button.setSelection(datum.equals(PreferenceWindow.getInstance().getValueFor(getPropertyKey())));
+ button.setData(datum);
+ button.addListener(SWT.Selection, new Listener() {
+ @Override
+ public void handleEvent(final Event event) {
+ if (button.getSelection()) {
+ PreferenceWindow.getInstance().setValue(getPropertyKey(), button.getData());
+ }
+ }
+ });
+
+ this.buttons.add(button);
+ }
+ return composite;
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWWidget#check()
+ */
+ @Override
+ public void check() {
+ final Object value = PreferenceWindow.getInstance().getValueFor(getPropertyKey());
+ if (value == null) {
+ PreferenceWindow.getInstance().setValue(getPropertyKey(), null);
+ } else {
+ if (!this.data.isEmpty()) {
+ if (!value.getClass().equals(this.data.get(0).getClass())) {
+ throw new UnsupportedOperationException("The property '" + getPropertyKey() + "' has to be a " + this.data.get(0).getClass() + " because it is associated to a combo");
+ }
+ }
+ }
+ }
+
+}
diff --git a/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWScale.java b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWScale.java new file mode 100644 index 000000000..a6bb64837 --- /dev/null +++ b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWScale.java @@ -0,0 +1,91 @@ +/*******************************************************************************
+ * Copyright (c) 2011 Laurent CARON
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Laurent CARON (laurent.caron at gmail dot com) - Initial implementation and API
+ *******************************************************************************/
+package org.mihalis.opal.preferenceWindow.widgets;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Scale;
+import org.mihalis.opal.preferenceWindow.PreferenceWindow;
+
+/**
+ * Instances of this class are scales
+ */
+public class PWScale extends PWWidget {
+
+ private final int max;
+ private final int min;
+ private final int increment;
+
+ /**
+ * Constructor
+ *
+ * @param label associated label
+ * @param propertyKey associated key
+ * @param min minimum value
+ * @param max maximum value
+ * @param increment increment value
+ */
+ public PWScale(final String label, final String propertyKey, final int min, final int max, final int increment) {
+ super(label, propertyKey, label == null ? 1 : 2, false);
+ this.min = min;
+ this.max = max;
+ this.increment = increment;
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWWidget#build(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ public Control build(final Composite parent) {
+ buildLabel(parent, GridData.CENTER);
+ final Scale scale = new Scale(parent, SWT.HORIZONTAL);
+ addControl(scale);
+ scale.setIncrement(this.increment);
+ scale.setMinimum(this.min);
+ scale.setMaximum(this.max);
+ final Integer originalValue = (Integer) PreferenceWindow.getInstance().getValueFor(getPropertyKey());
+ scale.setSelection(originalValue.intValue());
+
+ scale.addListener(SWT.Modify, new Listener() {
+ @Override
+ public void handleEvent(final Event event) {
+ PreferenceWindow.getInstance().setValue(getPropertyKey(), new Integer(scale.getSelection()));
+ }
+ });
+
+ return scale;
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWWidget#check()
+ */
+ @Override
+ public void check() {
+ final Object value = PreferenceWindow.getInstance().getValueFor(getPropertyKey());
+ if (value == null) {
+ PreferenceWindow.getInstance().setValue(getPropertyKey(), new Integer(this.min));
+ } else {
+ if (!(value instanceof Integer)) {
+ throw new UnsupportedOperationException("The property '" + getPropertyKey() + "' has to be an Integer because it is associated to a iscale");
+ }
+
+ final int valueAsInt = ((Integer) value).intValue();
+ if (valueAsInt < this.min || valueAsInt > this.max) {
+ throw new UnsupportedOperationException("The property '" + getPropertyKey() + "' is out of range (value is " + valueAsInt + ", range is " + this.min + "-" + this.max + ")");
+ }
+ }
+ }
+
+}
diff --git a/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWSeparator.java b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWSeparator.java new file mode 100644 index 000000000..b24032ae4 --- /dev/null +++ b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWSeparator.java @@ -0,0 +1,78 @@ +/*******************************************************************************
+ * Copyright (c) 2011 Laurent CARON
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Laurent CARON (laurent.caron at gmail dot com) - Initial implementation and API
+ *******************************************************************************/
+package org.mihalis.opal.preferenceWindow.widgets;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.mihalis.opal.titledSeparator.TitledSeparator;
+
+/**
+ * Instances of this class are separators
+ *
+ */
+public class PWSeparator extends PWWidget {
+
+ private final Image image;
+
+ /**
+ * Constructor
+ *
+ */
+ public PWSeparator() {
+ this(null, null);
+ }
+
+ /**
+ * Constructor
+ *
+ * @param label associated label
+ */
+ public PWSeparator(final String label) {
+ this(label, null);
+ }
+
+ /**
+ * Constructor
+ *
+ * @param label associated label
+ * @param image associated image
+ */
+ public PWSeparator(final String label, final Image image) {
+ super(label, null, 1, true);
+ this.image = image;
+ setAlignment(GridData.FILL);
+ setGrabExcessSpace(true);
+ setHeight(20);
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWWidget#build(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ public Control build(final Composite parent) {
+ final TitledSeparator sep = new TitledSeparator(parent, SWT.NONE);
+ addControl(sep);
+ sep.setText(getLabel());
+ sep.setImage(this.image);
+ return sep;
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWWidget#check()
+ */
+ @Override
+ public void check() {
+ }
+
+}
diff --git a/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWSpinner.java b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWSpinner.java new file mode 100644 index 000000000..9fe4875d3 --- /dev/null +++ b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWSpinner.java @@ -0,0 +1,86 @@ +/*******************************************************************************
+ * Copyright (c) 2011 Laurent CARON
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Laurent CARON (laurent.caron at gmail dot com) - Initial implementation and API
+ *******************************************************************************/
+package org.mihalis.opal.preferenceWindow.widgets;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Spinner;
+import org.mihalis.opal.preferenceWindow.PreferenceWindow;
+
+/**
+ * Instances of this class are spinners
+ */
+public class PWSpinner extends PWWidget {
+ private final int max;
+ private final int min;
+
+ /**
+ * Constructor
+ *
+ * @param label associated label
+ * @param propertyKey associated key
+ * @param min minimum value
+ * @param max maximum value
+ */
+ public PWSpinner(final String label, final String propertyKey, final int min, final int max) {
+ super(label, propertyKey, label == null ? 1 : 2, false);
+ this.min = min;
+ this.max = max;
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWWidget#build(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ public Control build(final Composite parent) {
+ buildLabel(parent, GridData.CENTER);
+ final Spinner spinner = new Spinner(parent, SWT.HORIZONTAL | SWT.BORDER);
+ addControl(spinner);
+ spinner.setMinimum(this.min);
+ spinner.setMaximum(this.max);
+ final Integer originalValue = (Integer) PreferenceWindow.getInstance().getValueFor(getPropertyKey());
+ spinner.setSelection(originalValue.intValue());
+
+ spinner.addListener(SWT.Modify, new Listener() {
+ @Override
+ public void handleEvent(final Event event) {
+ PreferenceWindow.getInstance().setValue(getPropertyKey(), new Integer(spinner.getSelection()));
+ }
+ });
+
+ return spinner;
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWWidget#check()
+ */
+ @Override
+ public void check() {
+ final Object value = PreferenceWindow.getInstance().getValueFor(getPropertyKey());
+ if (value == null) {
+ PreferenceWindow.getInstance().setValue(getPropertyKey(), new Integer(this.min));
+ } else {
+ if (!(value instanceof Integer)) {
+ throw new UnsupportedOperationException("The property '" + getPropertyKey() + "' has to be an Integer because it is associated to a spinner");
+ }
+
+ final int valueAsInt = ((Integer) value).intValue();
+ if (valueAsInt < this.min || valueAsInt > this.max) {
+ throw new UnsupportedOperationException("The property '" + getPropertyKey() + "' is out of range (value is " + valueAsInt + ", range is " + this.min + "-" + this.max + ")");
+ }
+ }
+ }
+
+}
diff --git a/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWStringText.java b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWStringText.java new file mode 100644 index 000000000..bc2301aa2 --- /dev/null +++ b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWStringText.java @@ -0,0 +1,68 @@ +/*******************************************************************************
+ * Copyright (c) 2011 Laurent CARON
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Laurent CARON (laurent.caron at gmail dot com) - Initial implementation and API
+ *******************************************************************************/
+package org.mihalis.opal.preferenceWindow.widgets;
+
+import org.eclipse.swt.SWT;
+import org.mihalis.opal.preferenceWindow.PreferenceWindow;
+
+/**
+ * Instances of this class are text box to type Strings
+ */
+public class PWStringText extends PWText {
+
+ /**
+ * Constructor
+ *
+ * @param label associated label
+ * @param propertyKey associated key
+ */
+ public PWStringText(final String label, final String propertyKey) {
+ super(label, propertyKey);
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWText#addVerifyListeners()
+ */
+ @Override
+ public void addVerifyListeners() {
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWWidget#check()
+ */
+ @Override
+ public void check() {
+ final Object value = PreferenceWindow.getInstance().getValueFor(getPropertyKey());
+ if (value == null) {
+ PreferenceWindow.getInstance().setValue(getPropertyKey(), "");
+ } else {
+ if (!(value instanceof String)) {
+ throw new UnsupportedOperationException("The property '" + getPropertyKey() + "' has to be a String because it is associated to a stringtext");
+ }
+ }
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWText#convertValue()
+ */
+ @Override
+ public Object convertValue() {
+ return this.text.getText();
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWText#getStyle()
+ */
+ @Override
+ public int getStyle() {
+ return SWT.NONE;
+ }
+}
diff --git a/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWText.java b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWText.java new file mode 100644 index 000000000..3d37a8606 --- /dev/null +++ b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWText.java @@ -0,0 +1,74 @@ +/*******************************************************************************
+ * Copyright (c) 2011 Laurent CARON
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Laurent CARON (laurent.caron at gmail dot com) - Initial implementation and API
+ *******************************************************************************/
+package org.mihalis.opal.preferenceWindow.widgets;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Text;
+import org.mihalis.opal.preferenceWindow.PreferenceWindow;
+
+/**
+ * This is the abstract class for all text widgets (except textarea)
+ */
+public abstract class PWText extends PWWidget {
+
+ protected Text text;
+
+ /**
+ * Constructor
+ *
+ * @param label associated label
+ * @param propertyKey associated property key
+ */
+ public PWText(final String label, final String propertyKey) {
+ super(label, propertyKey, label == null ? 1 : 2, false);
+ setGrabExcessSpace(true);
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWWidget#build(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ public Control build(final Composite parent) {
+ buildLabel(parent, GridData.CENTER);
+ this.text = new Text(parent, SWT.BORDER | getStyle());
+ addControl(this.text);
+ addVerifyListeners();
+ this.text.setText(PreferenceWindow.getInstance().getValueFor(getPropertyKey()).toString());
+ this.text.addListener(SWT.Modify, new Listener() {
+ @Override
+ public void handleEvent(final Event event) {
+ PreferenceWindow.getInstance().setValue(getPropertyKey(), convertValue());
+ }
+ });
+ return this.text;
+ }
+
+ /**
+ * Add the verify listeners
+ */
+ public abstract void addVerifyListeners();
+
+ /**
+ * @return the value of the data typed by the user in the correct format
+ */
+ public abstract Object convertValue();
+
+ /**
+ * @return the style (SWT.NONE or SWT.PASSWORD)
+ */
+ public abstract int getStyle();
+
+}
diff --git a/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWTextarea.java b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWTextarea.java new file mode 100644 index 000000000..0521707b7 --- /dev/null +++ b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWTextarea.java @@ -0,0 +1,77 @@ +/*******************************************************************************
+ * Copyright (c) 2011 Laurent CARON
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Laurent CARON (laurent.caron at gmail dot com) - Initial implementation and API
+ *******************************************************************************/
+package org.mihalis.opal.preferenceWindow.widgets;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Text;
+import org.mihalis.opal.preferenceWindow.PreferenceWindow;
+
+/**
+ * Instances of this class are text areas
+ *
+ */
+public class PWTextarea extends PWWidget {
+
+ /**
+ * Constructor
+ *
+ * @param label associated label
+ * @param propertyKey associated key
+ */
+ public PWTextarea(final String label, final String propertyKey) {
+ super(label, propertyKey, label == null ? 1 : 2, false);
+ setGrabExcessSpace(true);
+ setHeight(50);
+ setWidth(350);
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWWidget#build(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ public Control build(final Composite parent) {
+ buildLabel(parent, GridData.BEGINNING);
+
+ final Text text = new Text(parent, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
+ addControl(text);
+ text.setText(PreferenceWindow.getInstance().getValueFor(getPropertyKey()).toString());
+ text.addListener(SWT.FocusOut, new Listener() {
+
+ @Override
+ public void handleEvent(final Event event) {
+ PreferenceWindow.getInstance().setValue(getPropertyKey(), text.getText());
+ }
+ });
+
+ return text;
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWWidget#check()
+ */
+ @Override
+ public void check() {
+ final Object value = PreferenceWindow.getInstance().getValueFor(getPropertyKey());
+ if (value == null) {
+ PreferenceWindow.getInstance().setValue(getPropertyKey(), "");
+ } else {
+ if (!(value instanceof String)) {
+ throw new UnsupportedOperationException("The property '" + getPropertyKey() + "' has to be a String because it is associated to a textarea");
+ }
+ }
+ }
+
+}
diff --git a/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWURLText.java b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWURLText.java new file mode 100644 index 000000000..ebb145afe --- /dev/null +++ b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWURLText.java @@ -0,0 +1,98 @@ +/*******************************************************************************
+ * Copyright (c) 2011 Laurent CARON
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Laurent CARON (laurent.caron at gmail dot com) - Initial implementation and API
+ *******************************************************************************/
+package org.mihalis.opal.preferenceWindow.widgets;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.mihalis.opal.opalDialog.Dialog;
+import org.mihalis.opal.preferenceWindow.PreferenceWindow;
+import org.mihalis.opal.utils.ResourceManager;
+
+/**
+ * Instances of this class are text box used to type URL
+ */
+public class PWURLText extends PWText {
+
+ /**
+ * Constructor
+ *
+ * @param label associated label
+ * @param propertyKey associated key
+ */
+ public PWURLText(final String label, final String propertyKey) {
+ super(label, propertyKey);
+ setWidth(200);
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWText#addVerifyListeners()
+ */
+ @Override
+ public void addVerifyListeners() {
+ this.text.addListener(SWT.FocusOut, new Listener() {
+
+ @Override
+ public void handleEvent(final Event event) {
+ try {
+ new URL(PWURLText.this.text.getText());
+ } catch (final MalformedURLException e) {
+ Dialog.error(ResourceManager.getLabel(ResourceManager.APPLICATION_ERROR), ResourceManager.getLabel(ResourceManager.VALID_URL));
+ event.doit = false;
+ PWURLText.this.text.forceFocus();
+ }
+
+ }
+ });
+
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWWidget#check()
+ */
+ @Override
+ public void check() {
+ final Object value = PreferenceWindow.getInstance().getValueFor(getPropertyKey());
+ if (value == null) {
+ PreferenceWindow.getInstance().setValue(getPropertyKey(), "");
+ } else {
+ if (!(value instanceof String)) {
+ throw new UnsupportedOperationException("The property '" + getPropertyKey() + "' has to be a String because it is associated to a URL text box");
+ }
+
+ try {
+ new URL((String) value);
+ } catch (final MalformedURLException e) {
+ throw new UnsupportedOperationException("The property '" + getPropertyKey() + "' has a value (" + value + ") that is not an URL");
+ }
+ }
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWText#convertValue()
+ */
+ @Override
+ public Object convertValue() {
+ return this.text.getText();
+ }
+
+ /**
+ * @see org.mihalis.opal.preferenceWindow.widgets.PWText#getStyle()
+ */
+ @Override
+ public int getStyle() {
+ return SWT.NONE;
+ }
+
+}
diff --git a/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWWidget.java b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWWidget.java new file mode 100644 index 000000000..424cf0223 --- /dev/null +++ b/org.tizen.common.externals/src/org/mihalis/opal/preferenceWindow/widgets/PWWidget.java @@ -0,0 +1,264 @@ +/*******************************************************************************
+ * Copyright (c) 2011 Laurent CARON
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Laurent CARON (laurent.caron at gmail dot com) - Initial implementation and API
+ *******************************************************************************/
+package org.mihalis.opal.preferenceWindow.widgets;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.mihalis.opal.preferenceWindow.enabler.Enabler;
+
+/**
+ * This class is the root class for all widgets that take part of a preference
+ * window
+ *
+ */
+public abstract class PWWidget {
+ private final String propertyKey;
+ private final String label;
+ protected Enabler enabler;
+ private final List<Control> controls;
+
+ private int alignment = GridData.BEGINNING;
+ private int indent = 0;
+ private int width = 100;
+ private int height = -1;
+ protected int numberOfColumns = 1;
+ private boolean grabExcessSpace = false;
+
+ private boolean singleWidget = false;
+
+ /**
+ * Constructor
+ *
+ * @param label label associated to the widget
+ * @param propertyKey property key binded to the widget
+ * @param numberOfColumns number of columns taken by the widget
+ * @param singleWidget if true, the widget is supposed to be "alone" (used
+ * for placement)
+ */
+ protected PWWidget(final String label, final String propertyKey, final int numberOfColumns, final boolean singleWidget) {
+ this.label = label;
+ this.propertyKey = propertyKey;
+ this.numberOfColumns = numberOfColumns;
+ this.singleWidget = singleWidget;
+ this.controls = new ArrayList<Control>();
+ }
+
+ /**
+ * Build the widget
+ *
+ * @param parent parent composite
+ * @return the created control
+ */
+ protected abstract Control build(Composite parent);
+
+ /**
+ * Build the label associated to the widget
+ *
+ * @param parent parent composite
+ * @param verticalAlignment vertical alignment
+ */
+ protected void buildLabel(final Composite parent, final int verticalAlignment) {
+ if (getLabel() != null) {
+ final Label label = new Label(parent, SWT.NONE);
+ label.setText(getLabel());
+ final GridData labelGridData = new GridData(GridData.END, verticalAlignment, false, false);
+ labelGridData.horizontalIndent = getIndent();
+ label.setLayoutData(labelGridData);
+ addControl(label);
+ }
+ }
+
+ /**
+ * Check if the property can be binded to the widget
+ *
+ * @throws UnsupportedOperationException if the property could not be binded
+ * to the widget
+ */
+ protected abstract void check();
+
+ /**
+ * Check if the property can be binded to the widget, then build the widget
+ *
+ * @param parent parent composite
+ * @return the created control
+ */
+ public Control checkAndBuild(final Composite parent) {
+ check();
+ return build(parent);
+ }
+
+ /**
+ * Enable or disable the widget, depending on the associated enabler
+ */
+ public boolean enableOrDisable() {
+ if (this.enabler == null) {
+ return true;
+ }
+
+ final boolean enabled = this.enabler.isEnabled();
+ for (final Control c : this.controls) {
+ if (!c.isDisposed()) {
+ c.setEnabled(enabled);
+ }
+ }
+ return enabled;
+ }
+
+ // ------------------------------- getters & setters
+
+ /**
+ * @return the alignment (GridData.BEGINNING, GridData.CENTER, GridData.END,
+ * GridData.FILL)
+ */
+ public int getAlignment() {
+ return this.alignment;
+ }
+
+ /**
+ * @return the list of controls contained in the widget
+ */
+ public List<Control> getControls() {
+ return this.controls;
+ }
+
+ /**
+ * @return <code>true</code> if the widget should grab the excess space
+ */
+ public boolean isGrabExcessSpace() {
+ return this.grabExcessSpace;
+ }
+
+ /**
+ * @return the height of the widget
+ */
+ public int getHeight() {
+ return this.height;
+ }
+
+ /**
+ * @return the indentation space of the widget
+ */
+ public int getIndent() {
+ return this.indent;
+ }
+
+ /**
+ * @return the label associated to the widget (may be <code>null</code>)
+ */
+ public String getLabel() {
+ return this.label;
+ }
+
+ /**
+ * @return the number of columns associated to the widget
+ */
+ public int getNumberOfColumns() {
+ return this.numberOfColumns;
+ }
+
+ /**
+ * @return the propertyKey associated to the widget
+ */
+ String getPropertyKey() {
+ return this.propertyKey;
+ }
+
+ /**
+ * @return the width of the widget
+ */
+ public int getWidth() {
+ return this.width;
+ }
+
+ /**
+ * @return <code>true</code> if the widget is "alone"
+ */
+ public boolean isSingleWidget() {
+ return this.singleWidget;
+ }
+
+ /**
+ * Adds a control to the list of control contained in the widget
+ *
+ * @param control control to add
+ */
+ protected void addControl(final Control control) {
+ this.controls.add(control);
+ }
+
+ /**
+ * @param alignment the alignment to set (GridData.BEGINNING,
+ * GridData.CENTER, GridData.END, GridData.FILL)
+ * @return the widget
+ */
+ public PWWidget setAlignment(final int alignment) {
+ if (alignment != GridData.BEGINNING && alignment != GridData.CENTER && alignment != GridData.END && alignment != GridData.FILL) {
+ throw new UnsupportedOperationException("Value should be one of the following :GridData.BEGINNING, GridData.CENTER, GridData.END, GridData.FILL");
+ }
+ this.alignment = alignment;
+ return this;
+ }
+
+ /**
+ * @param enabler the enabler to set
+ * @return the widget
+ */
+ public PWWidget setEnabler(final Enabler enabler) {
+ this.enabler = enabler;
+ this.enabler.injectWidget(this);
+ return this;
+ }
+
+ /**
+ * @param grabExcessSpace true if you want the widget to grab the excess
+ * space
+ * @return the widget
+ */
+ public PWWidget setGrabExcessSpace(final boolean grabExcessSpace) {
+ this.grabExcessSpace = grabExcessSpace;
+ return this;
+ }
+
+ /**
+ * @param height the height to set
+ * @return the widget
+ */
+ public PWWidget setHeight(final int height) {
+ this.height = height;
+ return this;
+
+ }
+
+ /**
+ * @param indent the indentation space to set
+ * @return the widget
+ */
+ public PWWidget setIndent(final int indent) {
+ this.indent = indent;
+ return this;
+ }
+
+ /**
+ * @param width the width to set
+ * @return the widget
+ */
+ public PWWidget setWidth(final int width) {
+ this.width = width;
+ return this;
+ }
+
+}
|