-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.browsing.ui;\r
-\r
-\r
-/**\r
- * Immutable descriptor for an IGraphExplorer Column.\r
- * \r
- * Columns can be specified to be space-grabbing or non-space-grabbing. When a\r
- * column is marked as grabbing, it will receive/lose its own weight's worth of\r
- * screen space when the parenting control is resized in a way that allows\r
- * columns to shrink or grow.\r
- * \r
- * Each column is identified by a string that must be unique among the set of\r
- * columns used at a time. The key must be a valid string, <code>null</code> is\r
- * not allowed.\r
- * \r
- * See <code>@see org.simantics.browsing.ui.common.ColumnKeys</code> for some\r
- * commonly usable column keys.\r
- * \r
- * @see ColumnFactory\r
- * \r
- * @author Tuukka Lehtonen\r
- */\r
-public final class Column {\r
-\r
- public static enum Align {\r
- LEFT,\r
- CENTER,\r
- RIGHT\r
- }\r
-\r
- public static final int UNDEFINED_CONTROL_WIDTH = -1;\r
-\r
- public static final int DEFAULT_CONTROL_WIDTH = UNDEFINED_CONTROL_WIDTH;\r
-\r
- /**\r
- * Name of the column.\r
- * @see ColumnKeys\r
- */\r
- private final String key;\r
-\r
- /**\r
- * Text to be shown in the column.\r
- * @see ColumnKeys\r
- */\r
- private final String label;\r
-\r
- /**\r
- * Content alignment used by this column.\r
- */\r
- private final Align alignment;\r
-\r
- /**\r
- * -1 means not specified. If grab == false, this describes the default\r
- * width, if grab == true, this describes the minimum width of the column.\r
- */\r
- private final int width;\r
-\r
- /**\r
- * A string to show as tooltip or <code>null</code>.\r
- */\r
- private final String tooltip;\r
-\r
- /**\r
- * Indicates whether this column participates in grabbing extra widget space\r
- * that is freed when columns are resized.\r
- */\r
- private final boolean grab;\r
-\r
- /**\r
- * Weight describes how much a space-grabbing column will grab or release of\r
- * screen space that is gained or lost when controls are resized. The\r
- * percentage of space given to a column is defined by the formula:\r
- * <code>100*weight / sum(all column weights)</code>\r
- */\r
- private final int weight;\r
-\r
- public Column(String key) {\r
- this(key, key, Align.LEFT);\r
- }\r
-\r
- public Column(String key, String label, Align alignment) {\r
- this(key, label, alignment, DEFAULT_CONTROL_WIDTH);\r
- }\r
-\r
- public Column(String key, String label, Align alignment, int width) {\r
- this(key, label, alignment, width, null);\r
- }\r
-\r
- public Column(String key, Align alignment, int width) {\r
- this(key, key, alignment, width, null);\r
- }\r
-\r
- public Column(String key, Align alignment, int width, String tooltip) {\r
- this(key, key, alignment, width, tooltip);\r
- }\r
-\r
- public Column(String key, Align alignment, int width, String tooltip, boolean grab) {\r
- this(key, key, alignment, width, tooltip, grab);\r
- }\r
-\r
- public Column(String key, Align alignment, int width, String tooltip, boolean grab, int weight) {\r
- this(key, key, alignment, width, tooltip, grab, weight);\r
- }\r
-\r
- public Column(String key, String label, Align alignment, int width, String tooltip) {\r
- this(key, label, alignment, width, tooltip, false);\r
- }\r
-\r
- public Column(String key, String label, Align alignment, int width, String tooltip, boolean grab) {\r
- this(key, label, alignment, width, tooltip, grab, 1);\r
- }\r
-\r
- public Column(String key, String label, Align alignment, int width, String tooltip, boolean grab, int weight) {\r
- if (alignment == null)\r
- throw new IllegalArgumentException("null alignment");\r
- if (key == null)\r
- throw new IllegalArgumentException("null key");\r
-\r
- this.key = key;\r
- this.label = label;\r
- this.alignment = alignment;\r
- this.width = width;\r
- this.tooltip = tooltip;\r
- this.grab = grab;\r
- this.weight = weight;\r
- }\r
-\r
- public String getKey() {\r
- return key;\r
- }\r
-\r
- public String getLabel() {\r
- return label;\r
- }\r
-\r
- public Align getAlignment() {\r
- return alignment;\r
- }\r
-\r
- public int getWidth() {\r
- return width;\r
- }\r
-\r
- public String getTooltip() {\r
- return tooltip;\r
- }\r
-\r
- public boolean hasGrab() {\r
- return grab;\r
- }\r
-\r
- public int getWeight() {\r
- return weight;\r
- }\r
-\r
- public Column withKey(String key) {\r
- return new Column(key, this.label, this.alignment, this.width, this.tooltip, this.grab, this.weight);\r
- }\r
-\r
- public Column withLabel(String label) {\r
- return new Column(this.key, label, this.alignment, this.width, this.tooltip, this.grab, this.weight);\r
- }\r
-\r
- public Column withAlignment(Align alignment) {\r
- return new Column(this.key, this.label, alignment, this.width, this.tooltip, this.grab, this.weight);\r
- }\r
-\r
- public Column withWidth(int width) {\r
- return new Column(this.key, this.label, this.alignment, width, this.tooltip, this.grab, this.weight);\r
- }\r
-\r
- public Column withTooltip(String tooltip) {\r
- return new Column(this.key, this.label, this.alignment, this.width, tooltip, this.grab, this.weight);\r
- }\r
-\r
- public Column withGrab(boolean grab) {\r
- return new Column(this.key, this.label, this.alignment, this.width, this.tooltip, grab, this.weight);\r
- }\r
-\r
- public Column withWeight(int weight) {\r
- return new Column(this.key, this.label, this.alignment, this.width, this.tooltip, this.grab, weight);\r
- }\r
- \r
- @Override\r
- public int hashCode() {\r
- final int prime = 31;\r
- int result = 1;\r
- result = prime * result + alignment.hashCode();\r
- result = prime * result + (grab ? 1231 : 1237);\r
- result = prime * result + ((key == null) ? 0 : key.hashCode());\r
- result = prime * result + ((label == null) ? 0 : label.hashCode());\r
- result = prime * result + ((tooltip == null) ? 0 : tooltip.hashCode());\r
- result = prime * result + width;\r
- result = prime * result + weight;\r
- return result;\r
- }\r
-\r
- @Override\r
- public boolean equals(Object obj) {\r
- if (this == obj)\r
- return true;\r
- if (obj == null)\r
- return false;\r
- if (getClass() != obj.getClass())\r
- return false;\r
- Column other = (Column) obj;\r
- if (alignment != other.alignment)\r
- return false;\r
- if (grab != other.grab)\r
- return false;\r
- if (key == null) {\r
- if (other.key != null)\r
- return false;\r
- } else if (!key.equals(other.key))\r
- return false;\r
- if (label == null) {\r
- if (other.label != null)\r
- return false;\r
- } else if (!label.equals(other.label))\r
- return false;\r
- if (tooltip == null) {\r
- if (other.tooltip != null)\r
- return false;\r
- } else if (!tooltip.equals(other.tooltip))\r
- return false;\r
- if (width != other.width)\r
- return false;\r
- if (weight != other.weight)\r
- return false;\r
- return true;\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- StringBuilder sb = new StringBuilder();\r
- sb.append("Column[key=");\r
- sb.append(key);\r
- if (!key.equals(label))\r
- sb.append(", label=");\r
- sb.append(label);\r
- sb.append(", align=");\r
- sb.append(alignment);\r
- sb.append(", width=");\r
- sb.append(width);\r
- if (!label.equals(tooltip)) {\r
- sb.append(", tooltip=");\r
- sb.append(tooltip);\r
- }\r
- sb.append(", grab=");\r
- sb.append(grab);\r
- sb.append(", weight=");\r
- sb.append(weight);\r
- sb.append("]");\r
- return sb.toString();\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * 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:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.browsing.ui;
+
+
+/**
+ * Immutable descriptor for an IGraphExplorer Column.
+ *
+ * Columns can be specified to be space-grabbing or non-space-grabbing. When a
+ * column is marked as grabbing, it will receive/lose its own weight's worth of
+ * screen space when the parenting control is resized in a way that allows
+ * columns to shrink or grow.
+ *
+ * Each column is identified by a string that must be unique among the set of
+ * columns used at a time. The key must be a valid string, <code>null</code> is
+ * not allowed.
+ *
+ * See <code>@see org.simantics.browsing.ui.common.ColumnKeys</code> for some
+ * commonly usable column keys.
+ *
+ * @see ColumnFactory
+ *
+ * @author Tuukka Lehtonen
+ */
+public final class Column {
+
+ public static enum Align {
+ LEFT,
+ CENTER,
+ RIGHT
+ }
+
+ public static final int UNDEFINED_CONTROL_WIDTH = -1;
+
+ public static final int DEFAULT_CONTROL_WIDTH = UNDEFINED_CONTROL_WIDTH;
+
+ /**
+ * Name of the column.
+ * @see ColumnKeys
+ */
+ private final String key;
+
+ /**
+ * Text to be shown in the column.
+ * @see ColumnKeys
+ */
+ private final String label;
+
+ /**
+ * Content alignment used by this column.
+ */
+ private final Align alignment;
+
+ /**
+ * -1 means not specified. If grab == false, this describes the default
+ * width, if grab == true, this describes the minimum width of the column.
+ */
+ private final int width;
+
+ /**
+ * A string to show as tooltip or <code>null</code>.
+ */
+ private final String tooltip;
+
+ /**
+ * Indicates whether this column participates in grabbing extra widget space
+ * that is freed when columns are resized.
+ */
+ private final boolean grab;
+
+ /**
+ * Weight describes how much a space-grabbing column will grab or release of
+ * screen space that is gained or lost when controls are resized. The
+ * percentage of space given to a column is defined by the formula:
+ * <code>100*weight / sum(all column weights)</code>
+ */
+ private final int weight;
+
+ public Column(String key) {
+ this(key, key, Align.LEFT);
+ }
+
+ public Column(String key, String label, Align alignment) {
+ this(key, label, alignment, DEFAULT_CONTROL_WIDTH);
+ }
+
+ public Column(String key, String label, Align alignment, int width) {
+ this(key, label, alignment, width, null);
+ }
+
+ public Column(String key, Align alignment, int width) {
+ this(key, key, alignment, width, null);
+ }
+
+ public Column(String key, Align alignment, int width, String tooltip) {
+ this(key, key, alignment, width, tooltip);
+ }
+
+ public Column(String key, Align alignment, int width, String tooltip, boolean grab) {
+ this(key, key, alignment, width, tooltip, grab);
+ }
+
+ public Column(String key, Align alignment, int width, String tooltip, boolean grab, int weight) {
+ this(key, key, alignment, width, tooltip, grab, weight);
+ }
+
+ public Column(String key, String label, Align alignment, int width, String tooltip) {
+ this(key, label, alignment, width, tooltip, false);
+ }
+
+ public Column(String key, String label, Align alignment, int width, String tooltip, boolean grab) {
+ this(key, label, alignment, width, tooltip, grab, 1);
+ }
+
+ public Column(String key, String label, Align alignment, int width, String tooltip, boolean grab, int weight) {
+ if (alignment == null)
+ throw new IllegalArgumentException("null alignment");
+ if (key == null)
+ throw new IllegalArgumentException("null key");
+
+ this.key = key;
+ this.label = label;
+ this.alignment = alignment;
+ this.width = width;
+ this.tooltip = tooltip;
+ this.grab = grab;
+ this.weight = weight;
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public Align getAlignment() {
+ return alignment;
+ }
+
+ public int getWidth() {
+ return width;
+ }
+
+ public String getTooltip() {
+ return tooltip;
+ }
+
+ public boolean hasGrab() {
+ return grab;
+ }
+
+ public int getWeight() {
+ return weight;
+ }
+
+ public Column withKey(String key) {
+ return new Column(key, this.label, this.alignment, this.width, this.tooltip, this.grab, this.weight);
+ }
+
+ public Column withLabel(String label) {
+ return new Column(this.key, label, this.alignment, this.width, this.tooltip, this.grab, this.weight);
+ }
+
+ public Column withAlignment(Align alignment) {
+ return new Column(this.key, this.label, alignment, this.width, this.tooltip, this.grab, this.weight);
+ }
+
+ public Column withWidth(int width) {
+ return new Column(this.key, this.label, this.alignment, width, this.tooltip, this.grab, this.weight);
+ }
+
+ public Column withTooltip(String tooltip) {
+ return new Column(this.key, this.label, this.alignment, this.width, tooltip, this.grab, this.weight);
+ }
+
+ public Column withGrab(boolean grab) {
+ return new Column(this.key, this.label, this.alignment, this.width, this.tooltip, grab, this.weight);
+ }
+
+ public Column withWeight(int weight) {
+ return new Column(this.key, this.label, this.alignment, this.width, this.tooltip, this.grab, weight);
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + alignment.hashCode();
+ result = prime * result + (grab ? 1231 : 1237);
+ result = prime * result + ((key == null) ? 0 : key.hashCode());
+ result = prime * result + ((label == null) ? 0 : label.hashCode());
+ result = prime * result + ((tooltip == null) ? 0 : tooltip.hashCode());
+ result = prime * result + width;
+ result = prime * result + weight;
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ Column other = (Column) obj;
+ if (alignment != other.alignment)
+ return false;
+ if (grab != other.grab)
+ return false;
+ if (key == null) {
+ if (other.key != null)
+ return false;
+ } else if (!key.equals(other.key))
+ return false;
+ if (label == null) {
+ if (other.label != null)
+ return false;
+ } else if (!label.equals(other.label))
+ return false;
+ if (tooltip == null) {
+ if (other.tooltip != null)
+ return false;
+ } else if (!tooltip.equals(other.tooltip))
+ return false;
+ if (width != other.width)
+ return false;
+ if (weight != other.weight)
+ return false;
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("Column[key=");
+ sb.append(key);
+ if (!key.equals(label))
+ sb.append(", label=");
+ sb.append(label);
+ sb.append(", align=");
+ sb.append(alignment);
+ sb.append(", width=");
+ sb.append(width);
+ if (!label.equals(tooltip)) {
+ sb.append(", tooltip=");
+ sb.append(tooltip);
+ }
+ sb.append(", grab=");
+ sb.append(grab);
+ sb.append(", weight=");
+ sb.append(weight);
+ sb.append("]");
+ return sb.toString();
+ }
+
+}