Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.mihalis.opal/src/main/java/org/mihalis/opal/propertyTable/editor/PTInsetsEditor.java')
-rw-r--r--org.mihalis.opal/src/main/java/org/mihalis/opal/propertyTable/editor/PTInsetsEditor.java138
1 files changed, 138 insertions, 0 deletions
diff --git a/org.mihalis.opal/src/main/java/org/mihalis/opal/propertyTable/editor/PTInsetsEditor.java b/org.mihalis.opal/src/main/java/org/mihalis/opal/propertyTable/editor/PTInsetsEditor.java
new file mode 100644
index 0000000..8556a0c
--- /dev/null
+++ b/org.mihalis.opal/src/main/java/org/mihalis/opal/propertyTable/editor/PTInsetsEditor.java
@@ -0,0 +1,138 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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 API and implementation
+ *******************************************************************************/
+package org.mihalis.opal.propertyTable.editor;
+
+import java.awt.Insets;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Item;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.swt.widgets.TreeItem;
+import org.mihalis.opal.propertyTable.PTProperty;
+import org.mihalis.opal.utils.ResourceManager;
+
+/**
+ * Editor for {@link Insets} values.
+ */
+public class PTInsetsEditor extends PTWindowEditor {
+
+ /** The top. */
+ private Text top;
+
+ /** The left. */
+ private Text left;
+
+ /** The right. */
+ private Text right;
+
+ /** The bottom. */
+ private Text bottom;
+
+ /**
+ * Creates the content.
+ *
+ * @param shell the shell
+ * @param property the property
+ * @see org.mihalis.opal.propertyTable.editor.PTWindowEditor#createContent(org.eclipse.swt.widgets.Shell,
+ * org.mihalis.opal.propertyTable.PTProperty)
+ */
+ @Override
+ protected void createContent(final Shell shell, final PTProperty property) {
+ final Label topLabel = new Label(shell, SWT.NONE);
+ topLabel.setLayoutData(new GridData(GridData.END, GridData.BEGINNING, false, false));
+ topLabel.setText(ResourceManager.getLabel(ResourceManager.TOP));
+
+ this.top = new Text(shell, SWT.BORDER);
+ this.top.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, false));
+ if (property.getValue() != null) {
+ final Insets insets = (Insets) property.getValue();
+ this.top.setText(String.valueOf(insets.top));
+ }
+ addVerifyListeners(this.top);
+
+ final Label heightLabel = new Label(shell, SWT.NONE);
+ heightLabel.setLayoutData(new GridData(GridData.END, GridData.BEGINNING, false, false));
+ heightLabel.setText(ResourceManager.getLabel(ResourceManager.LEFT));
+
+ this.left = new Text(shell, SWT.BORDER);
+ this.left.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, false));
+ if (property.getValue() != null) {
+ final Insets insets = (Insets) property.getValue();
+ this.left.setText(String.valueOf(insets.left));
+ }
+ addVerifyListeners(this.left);
+
+ final Label bottomLabel = new Label(shell, SWT.NONE);
+ bottomLabel.setLayoutData(new GridData(GridData.END, GridData.BEGINNING, false, false));
+ bottomLabel.setText(ResourceManager.getLabel(ResourceManager.BOTTOM));
+
+ this.bottom = new Text(shell, SWT.BORDER);
+ this.bottom.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, false));
+ if (property.getValue() != null) {
+ final Insets insets = (Insets) property.getValue();
+ this.bottom.setText(String.valueOf(insets.bottom));
+ }
+ addVerifyListeners(this.bottom);
+
+ final Label rightLabel = new Label(shell, SWT.NONE);
+ rightLabel.setLayoutData(new GridData(GridData.END, GridData.BEGINNING, false, false));
+ rightLabel.setText(ResourceManager.getLabel(ResourceManager.RIGHT));
+
+ this.right = new Text(shell, SWT.BORDER);
+ this.right.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, false));
+ if (property.getValue() != null) {
+ final Insets insets = (Insets) property.getValue();
+ this.right.setText(String.valueOf(insets.bottom));
+ }
+ addVerifyListeners(this.right);
+
+ }
+
+ /**
+ * Fill property.
+ *
+ * @param item the item
+ * @param property the property
+ * @see org.mihalis.opal.propertyTable.editor.PTWindowEditor#fillProperty(org.eclipse.swt.widgets.Item,
+ * org.mihalis.opal.propertyTable.PTProperty)
+ */
+ @Override
+ protected void fillProperty(final Item item, final PTProperty property) {
+ final Insets i = new Insets(getIntValue(this.top), getIntValue(this.left), getIntValue(this.bottom), getIntValue(this.right));
+ property.setValue(i);
+ if (item instanceof TableItem) {
+ ((TableItem) item).setText(1, getTextFor(property));
+ } else {
+ ((TreeItem) item).setText(1, getTextFor(property));
+ }
+ }
+
+ /**
+ * Gets the text for.
+ *
+ * @param property the property
+ * @return the text for
+ * @see org.mihalis.opal.propertyTable.editor.PTChooserEditor#getTextFor(org.mihalis.opal.propertyTable.PTProperty)
+ */
+ @Override
+ protected String getTextFor(final PTProperty property) {
+ if (property.getValue() == null) {
+ return "(null)";
+ }
+ final Insets insets = (Insets) property.getValue();
+ return "[" + insets.top + "," + insets.left + "," + insets.bottom + "," + insets.right + "]";
+ }
+
+}

Back to the top