|
From: <pat...@us...> - 2010-07-12 21:24:20
|
Revision: 1084
http://cishell.svn.sourceforge.net/cishell/?rev=1084&view=rev
Author: pataphil
Date: 2010-07-12 21:24:14 +0000 (Mon, 12 Jul 2010)
Log Message:
-----------
* Continued developing on SWT Utilities.
Modified Paths:
--------------
trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModel.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModelField.java
Added Paths:
-----------
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/ExpandableComponentWidget.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/GUIBuilderUtilities.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/GridContainer.java
trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/ScrolledComponentFactory.java
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java 2010-07-09 20:55:18 UTC (rev 1083)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java 2010-07-12 21:24:14 UTC (rev 1084)
@@ -1,347 +1,352 @@
-package org.cishell.utilities;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.StringTokenizer;
-
-public class StringUtilities {
- // TODO: Make this wrap implodeItems.
- public static String implodeStringArray(String[] stringArray, String separator) {
- final int stringArrayLength = stringArray.length;
- StringBuffer workingResultString = new StringBuffer();
-
- for (int ii = 0; ii < stringArrayLength; ii++) {
- workingResultString.append(stringArray[ii]);
- if (ii != stringArrayLength - 1) {
- workingResultString.append(separator);
- }
- }
-
- return workingResultString.toString();
- }
-
- /* TODO: This is a wrapper for implodeItems. All new/updated code should refer to implodeItems
- * from now on.
- */
- @SuppressWarnings("unchecked") // Raw List.
- public static String implodeList(List list, String separator) {
- return implodeItems(list, separator);
- }
-
- public static<T> String implodeItems(Collection<T> items, String separator) {
- StringBuffer workingResultString = new StringBuffer();
-
- for (Iterator<T> it = items.iterator(); it.hasNext(); ) {
-// for (int ii = 0; ii < listLength; ii++) {
-// workingResultString.append(list.get(ii));
- workingResultString.append(it.next());
-
-// boolean isLastElement = (ii == listLength - 1);
- boolean isLastElement = !it.hasNext();
- if (!isLastElement) {
- workingResultString.append(separator);
- }
- }
-
- return workingResultString.toString();
- }
-
- public static String[] filterStringsByPattern(String[] stringsToFilter, String pattern) {
- ArrayList<String> filteredStrings = new ArrayList<String>();
-
- for (int ii = 0; ii < stringsToFilter.length; ii++) {
- if (!stringsToFilter[ii].matches(pattern)) {
- filteredStrings.add(stringsToFilter[ii]);
- }
- }
-
- return (String[])filteredStrings.toArray(new String[0]);
- }
-
- public static String[] filterEmptyStrings(String[] stringsToFilter) {
- // TODO: This maybe should use filterStringsByPattern?
- ArrayList<String> filteredStrings = new ArrayList<String>();
-
- for (int ii = 0; ii < stringsToFilter.length; ii++) {
- if (!"".equals(stringsToFilter[ii])) {
- filteredStrings.add(stringsToFilter[ii]);
- }
- }
-
- return (String[])filteredStrings.toArray(new String[0]);
- }
-
- /*
- * This method is really meant to simplify working with Prefuse tables.
- * Prefuse table columns are typed. If a column contains a null cell,
- * Prefuse types that column as an array type, and it then represents
- * null values with arrays of length 0.
- * To handle this, this method returns:
- * null if the object is actually null or array of length 0;
- * just the first element of the array; or
- * the result of the object's toString method.
- */
- // TODO: Rename to interpretAsString.
- // TODO: Move these things to TableUtilities.
- // TODO: Handle all cases, including all primitive array types and
- // perhaps primitive box types (i.e. Integer).
- public static String interpretObjectAsString(Object object) {
- if (object == null) {
- return null;
- } else if (object instanceof String[]) {
- String[] objectAsStringArray = (String[]) object;
-
- if (objectAsStringArray.length == 0) {
- return null;
- } else {
- return objectAsStringArray[0];
- }
- } else {
- return object.toString();
- }
- }
-
- // TODO Think about instead using a Pattern, "\s*". Don't have to though.
- public static boolean isEmptyOrWhitespace(String string) {
- String trimmed = string.trim();
-
- return (trimmed.length() == 0);
- }
-
- public static boolean allAreEmptyOrWhitespace(String... strings) {
- for (String string : strings) {
- if (!isEmptyOrWhitespace(string)) {
- return false;
- }
- }
-
- return true;
- }
-
- public static boolean allAreNeitherEmptyNorWhitespace(String... strings) {
- for (String string : strings) {
- if (isEmptyOrWhitespace(string)) {
- return false;
- }
- }
-
- return true;
- }
-
- public static boolean isNull_Empty_OrWhitespace(String string) {
- if (string == null) {
- return true;
- }
-
- return isEmptyOrWhitespace(string);
- }
-
- public static boolean allAreNull_Empty_OrWhitespace(String... strings) {
- for (String string : strings) {
- if (!isNull_Empty_OrWhitespace(string)) {
- return false;
- }
- }
-
- return true;
- }
-
- public static boolean allAreNeitherNullNorEmptyNorWhitespace(String... strings) {
- for (String string : strings) {
- if (isNull_Empty_OrWhitespace(string)) {
- return false;
- }
- }
-
- return true;
- }
-
- public static int countOccurrencesOfChar(CharSequence characters, char target) {
- int count = 0;
-
- for (int ii = 0; ii < characters.length(); ii++) {
- if (characters.charAt(ii) == target) {
- count++;
- }
- }
-
- return count;
- }
-
- public static String multiply(String target, int count) {
- if (count < 1) {
- return "";
- } else {
- StringBuffer stringInProgress = new StringBuffer();
-
- for (int ii = 0; ii < count; ii ++) {
- stringInProgress.append(target);
- }
-
- return stringInProgress.toString();
- }
- }
-
- public static String multiplyWithSeparator(String target, String separator, int count) {
- String multipliedWithExtraSeparator = multiply(target + separator, count);
-
- return multipliedWithExtraSeparator.substring(
- 0, multipliedWithExtraSeparator.length() - separator.length());
- }
-
- public static String emptyStringIfNull(Object object) {
- if (object == null) {
- return "";
- } else {
- return object.toString();
- }
- }
-
- public static String simpleClean(String string) {
- String guaranteedToNotBeNull = emptyStringIfNull(string);
-
- return guaranteedToNotBeNull.trim();
- }
-
- public static final String[] simpleCleanStrings(String[] strings) {
- List<String> cleanedStrings = new ArrayList<String>();
-
- for (int ii = 0; ii < strings.length; ii ++) {
- cleanedStrings.add(StringUtilities.simpleClean(strings[ii]));
- }
-
- return (String[])cleanedStrings.toArray(new String[0]);
- }
-
- public static String trimIfNotNull(String string) {
- if (string == null) {
- return null;
- }
-
- return string.trim();
- }
-
- public static String toSentenceCase(String word) {
- String cleanedWord = simpleClean(word);
-
- if (cleanedWord.length() == 0) {
- return "";
- } else {
- return
- Character.toUpperCase(cleanedWord.charAt(0)) +
- cleanedWord.substring(1).toLowerCase();
- }
- }
-
- public static int prefixIndex(String target, String[] prefixes) {
- /*
- * Look for the prefixes in reverse order (so a longer one will win out over a shorter one
- * if they both have a beginning in common).
- */
- for (int ii = (prefixes.length - 1); ii >= 0; ii--) {
- if (target.startsWith(prefixes[ii])) {
- return ii;
- }
- }
-
- return -1;
- }
-
- /* TODO Perhaps make a "hasContent" method in here and apply that terminology throughout. */
- public static boolean areValidAndEqual(String string1, String string2) {
- return (
- !isNull_Empty_OrWhitespace(string1) &&
- !isNull_Empty_OrWhitespace(string2) &&
- (string1.equals(string2)));
- }
-
- public static boolean bothAreEqualOrNull(String string1, String string2) {
- if (string1 != null) {
- return string1.equals(string2);
- } else {
- return (string2 == null);
- }
- }
-
- public static boolean areValidAndEqualIgnoreCase(String string1, String string2) {
- return (
- !isNull_Empty_OrWhitespace(string1) &&
- !isNull_Empty_OrWhitespace(string2) &&
- string1.equalsIgnoreCase(string2));
- }
-
- // TODO: New Name.
- public static String simpleMerge(String string1, String string2) {
- if (!isNull_Empty_OrWhitespace(string1)) {
- if (!isNull_Empty_OrWhitespace(string2)) {
- if (string1.length() >= string2.length()) {
- return string1;
- } else {
- return string2;
- }
- } else {
- return string1;
- }
- }
- else if (!isNull_Empty_OrWhitespace(string2)) {
- return string2;
- }
-
- return string1;
- }
-
- //TODO: Make this not exist (a check for 'Null Empty or Whitespace' can stay. Use ! for negated cases)
- public static Object alternativeIfNotNull_Empty_OrWhitespace(
- String string, Object alternative) {
- if (!isNull_Empty_OrWhitespace(string)) {
- return string;
- } else {
- return alternative;
- }
- }
-
- public static Object alternativeIfNotNull_Empty_OrWhitespace_IgnoreCase(
- String string, Object alternative) {
- if (!isNull_Empty_OrWhitespace(string)) {
- return string.toLowerCase();
- } else {
- return alternative;
- }
- }
-
- public static String getNthToken(
- String originalString, String separator, int index, boolean trim) {
- return getAllTokens(originalString, separator, trim)[index];
- }
-
- public static String[] getAllTokens(
- String originalString, String separator, boolean trim) {
- String[] tokens = originalString.split(separator);
-
- if (trim) {
- String[] trimmedTokens = new String[tokens.length];
-
- for (int ii = 0; ii < tokens.length; ii++) {
- trimmedTokens[ii] = tokens[ii].trim();
- }
-
- return trimmedTokens;
- } else {
- return tokens;
- }
- }
-
- public static String[] tokenizeByWhitespace(String originalString) {
- StringTokenizer tokenizer = new StringTokenizer(originalString);
- int tokenCount = tokenizer.countTokens();
- String[] tokens = new String[tokenCount];
-
- for (int ii = 0; ii < tokenCount; ii++) {
- tokens[ii] = tokenizer.nextToken();
- }
-
- return tokens;
- }
-}
+package org.cishell.utilities;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.StringTokenizer;
+
+public class StringUtilities {
+ // TODO: Make this wrap implodeItems.
+ public static String implodeStringArray(String[] stringArray, String separator) {
+ final int stringArrayLength = stringArray.length;
+ StringBuffer workingResultString = new StringBuffer();
+
+ for (int ii = 0; ii < stringArrayLength; ii++) {
+ workingResultString.append(stringArray[ii]);
+ if (ii != stringArrayLength - 1) {
+ workingResultString.append(separator);
+ }
+ }
+
+ return workingResultString.toString();
+ }
+
+ /* TODO: This is a wrapper for implodeItems. All new/updated code should refer to implodeItems
+ * from now on.
+ */
+ @SuppressWarnings("unchecked") // Raw List.
+ public static String implodeList(List list, String separator) {
+ return implodeItems(list, separator);
+ }
+
+ public static<T> String implodeItems(Collection<T> items, String separator) {
+ StringBuffer workingResultString = new StringBuffer();
+
+ for (Iterator<T> it = items.iterator(); it.hasNext(); ) {
+// for (int ii = 0; ii < listLength; ii++) {
+// workingResultString.append(list.get(ii));
+ workingResultString.append(it.next());
+
+// boolean isLastElement = (ii == listLength - 1);
+ boolean isLastElement = !it.hasNext();
+ if (!isLastElement) {
+ workingResultString.append(separator);
+ }
+ }
+
+ return workingResultString.toString();
+ }
+
+ public static String[] filterStringsByPattern(String[] stringsToFilter, String pattern) {
+ ArrayList<String> filteredStrings = new ArrayList<String>();
+
+ for (int ii = 0; ii < stringsToFilter.length; ii++) {
+ if (!stringsToFilter[ii].matches(pattern)) {
+ filteredStrings.add(stringsToFilter[ii]);
+ }
+ }
+
+ return (String[])filteredStrings.toArray(new String[0]);
+ }
+
+ public static String[] filterEmptyStrings(String[] stringsToFilter) {
+ // TODO: This maybe should use filterStringsByPattern?
+ ArrayList<String> filteredStrings = new ArrayList<String>();
+
+ for (int ii = 0; ii < stringsToFilter.length; ii++) {
+ if (!"".equals(stringsToFilter[ii])) {
+ filteredStrings.add(stringsToFilter[ii]);
+ }
+ }
+
+ return (String[])filteredStrings.toArray(new String[0]);
+ }
+
+ /*
+ * This method is really meant to simplify working with Prefuse tables.
+ * Prefuse table columns are typed. If a column contains a null cell,
+ * Prefuse types that column as an array type, and it then represents
+ * null values with arrays of length 0.
+ * To handle this, this method returns:
+ * null if the object is actually null or array of length 0;
+ * just the first element of the array; or
+ * the result of the object's toString method.
+ */
+ // TODO: Rename to interpretAsString.
+ // TODO: Move these things to TableUtilities.
+ // TODO: Handle all cases, including all primitive array types and
+ // perhaps primitive box types (i.e. Integer).
+ public static String interpretObjectAsString(Object object) {
+ if (object == null) {
+ return null;
+ } else if (object instanceof String[]) {
+ String[] objectAsStringArray = (String[]) object;
+
+ if (objectAsStringArray.length == 0) {
+ return null;
+ } else {
+ return objectAsStringArray[0];
+ }
+ } else {
+ return object.toString();
+ }
+ }
+
+ // TODO Think about instead using a Pattern, "\s*". Don't have to though.
+ public static boolean isEmptyOrWhitespace(String string) {
+ String trimmed = string.trim();
+
+ return (trimmed.length() == 0);
+ }
+
+ public static boolean allAreEmptyOrWhitespace(String... strings) {
+ for (String string : strings) {
+ if (!isEmptyOrWhitespace(string)) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ public static boolean allAreNeitherEmptyNorWhitespace(String... strings) {
+ for (String string : strings) {
+ if (isEmptyOrWhitespace(string)) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ public static boolean isNull_Empty_OrWhitespace(String string) {
+ if (string == null) {
+ return true;
+ }
+
+ return isEmptyOrWhitespace(string);
+ }
+
+ public static boolean allAreNull_Empty_OrWhitespace(String... strings) {
+ for (String string : strings) {
+ if (!isNull_Empty_OrWhitespace(string)) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ public static boolean allAreNeitherNullNorEmptyNorWhitespace(String... strings) {
+ for (String string : strings) {
+ if (isNull_Empty_OrWhitespace(string)) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ public static int countOccurrencesOfChar(CharSequence characters, char target) {
+ int count = 0;
+
+ for (int ii = 0; ii < characters.length(); ii++) {
+ if (characters.charAt(ii) == target) {
+ count++;
+ }
+ }
+
+ return count;
+ }
+
+ public static String multiply(String target, int count) {
+ if (count < 1) {
+ return "";
+ } else {
+ StringBuffer stringInProgress = new StringBuffer();
+
+ for (int ii = 0; ii < count; ii ++) {
+ stringInProgress.append(target);
+ }
+
+ return stringInProgress.toString();
+ }
+ }
+
+ public static String multiplyWithSeparator(String target, String separator, int count) {
+ String multipliedWithExtraSeparator = multiply(target + separator, count);
+
+ return multipliedWithExtraSeparator.substring(
+ 0, multipliedWithExtraSeparator.length() - separator.length());
+ }
+
+ public static String emptyStringIfNull(Object object) {
+ if (object == null) {
+ return "";
+ } else {
+ return object.toString();
+ }
+ }
+
+ public static String simpleClean(String string) {
+ String guaranteedToNotBeNull = emptyStringIfNull(string);
+
+ return guaranteedToNotBeNull.trim();
+ }
+
+ public static final String[] simpleCleanStrings(String[] strings) {
+ List<String> cleanedStrings = new ArrayList<String>();
+
+ for (int ii = 0; ii < strings.length; ii ++) {
+ cleanedStrings.add(StringUtilities.simpleClean(strings[ii]));
+ }
+
+ return (String[])cleanedStrings.toArray(new String[0]);
+ }
+
+ public static String trimIfNotNull(String string) {
+ if (string == null) {
+ return null;
+ }
+
+ return string.trim();
+ }
+
+ public static String toSentenceCase(String word) {
+ String cleanedWord = simpleClean(word);
+
+ if (cleanedWord.length() == 0) {
+ return "";
+ } else {
+ return
+ Character.toUpperCase(cleanedWord.charAt(0)) +
+ cleanedWord.substring(1).toLowerCase();
+ }
+ }
+
+ public static int prefixIndex(String target, String[] prefixes) {
+ /*
+ * Look for the prefixes in reverse order (so a longer one will win out over a shorter one
+ * if they both have a beginning in common).
+ */
+ for (int ii = (prefixes.length - 1); ii >= 0; ii--) {
+ if (target.startsWith(prefixes[ii])) {
+ return ii;
+ }
+ }
+
+ return -1;
+ }
+
+ /* TODO Perhaps make a "hasContent" method in here and apply that terminology throughout. */
+ public static boolean areValidAndEqual(String string1, String string2) {
+ return (
+ !isNull_Empty_OrWhitespace(string1) &&
+ !isNull_Empty_OrWhitespace(string2) &&
+ (string1.equals(string2)));
+ }
+
+ public static boolean bothAreEqualOrNull(String string1, String string2) {
+ if (string1 != null) {
+ return string1.equals(string2);
+ } else {
+ return (string2 == null);
+ }
+ }
+
+ public static boolean areValidAndEqualIgnoreCase(String string1, String string2) {
+ return (
+ !isNull_Empty_OrWhitespace(string1) &&
+ !isNull_Empty_OrWhitespace(string2) &&
+ string1.equalsIgnoreCase(string2));
+ }
+
+ // TODO: New Name.
+ public static String simpleMerge(String string1, String string2) {
+ if (!isNull_Empty_OrWhitespace(string1)) {
+ if (!isNull_Empty_OrWhitespace(string2)) {
+ if (string1.length() >= string2.length()) {
+ return string1;
+ } else {
+ return string2;
+ }
+ } else {
+ return string1;
+ }
+ }
+ else if (!isNull_Empty_OrWhitespace(string2)) {
+ return string2;
+ }
+
+ return string1;
+ }
+
+ //TODO: Make this not exist (a check for 'Null Empty or Whitespace' can stay. Use ! for negated cases)
+ public static Object alternativeIfNotNull_Empty_OrWhitespace(
+ String string, Object alternative) {
+ if (!isNull_Empty_OrWhitespace(string)) {
+ return string;
+ } else {
+ return alternative;
+ }
+ }
+
+ public static Object alternativeIfNotNull_Empty_OrWhitespace_IgnoreCase(
+ String string, Object alternative) {
+ if (!isNull_Empty_OrWhitespace(string)) {
+ return string.toLowerCase();
+ } else {
+ return alternative;
+ }
+ }
+
+ public static String getNthToken(
+ String originalString, String separator, int index, boolean trim) {
+ return getAllTokens(originalString, separator, trim)[index];
+ }
+
+ public static String[] getAllTokens(
+ String originalString, String separator, boolean trim) {
+ String[] tokens = originalString.split(separator);
+
+ if (trim) {
+ String[] trimmedTokens = new String[tokens.length];
+
+ for (int ii = 0; ii < tokens.length; ii++) {
+ trimmedTokens[ii] = tokens[ii].trim();
+ }
+
+ return trimmedTokens;
+ } else {
+ return tokens;
+ }
+ }
+
+ public static String[] tokenizeByWhitespace(String originalString) {
+ StringTokenizer tokenizer = new StringTokenizer(originalString);
+ int tokenCount = tokenizer.countTokens();
+ String[] tokens = new String[tokenCount];
+
+ for (int ii = 0; ii < tokenCount; ii++) {
+ tokens[ii] = tokenizer.nextToken();
+ }
+
+ return tokens;
+ }
+
+ // TODO
+// public static String escape(String unescaped) {
+// return unescaped.replaceAll("\"", "\\\""
+// }
+}
Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/ExpandableComponentWidget.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/ExpandableComponentWidget.java (rev 0)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/ExpandableComponentWidget.java 2010-07-12 21:24:14 UTC (rev 1084)
@@ -0,0 +1,246 @@
+package org.cishell.utilities.swt;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.ScrolledComposite;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+
+/**
+ * This is meant to be subclassed.
+ */
+public class ExpandableComponentWidget<T> extends Composite {
+ public static final int COLUMN_AREA_LAYOUT_VERTICAL_SPACING = 1;
+ public static final int VERTICAL_SCROLL_INCREMENT = 50;
+
+ private ScrolledComponentFactory<T> componentFactory;
+ private Composite headerArea;
+ private ScrolledComposite scrollingArea;
+ private GridContainer scrolledAreaGrid;
+ private Composite footerArea;
+ private List<T> components = new ArrayList<T>();
+ private int uniqueComponentCount = 0;
+ private Collection<Label> columnLabels;
+
+ public ExpandableComponentWidget(
+ Composite parent, ScrolledComponentFactory<T> componentFactory) {
+ super(parent, SWT.NONE);
+ this.componentFactory = componentFactory;
+
+ setLayout(createLayout());
+ this.headerArea = createHeaderArea();
+ this.scrollingArea = createScrollingArea();
+ this.footerArea = createFooterArea();
+ this.scrolledAreaGrid = createScrolledAreaGrid(this.scrollingArea);
+
+ this.scrollingArea.setExpandHorizontal(true);
+ this.scrollingArea.setExpandVertical(true);
+ this.scrollingArea.setAlwaysShowScrollBars(true);
+ fixSize();
+ this.scrollingArea.setContent(this.scrolledAreaGrid.getActualParent());
+ this.scrollingArea.getVerticalBar().setPageIncrement(VERTICAL_SCROLL_INCREMENT);
+ this.columnLabels = createColumnLabels(this.scrolledAreaGrid.getActualParent(), SWT.NONE);
+ }
+
+ public Composite getHeaderArea() {
+ return this.headerArea;
+ }
+
+ public Composite getFooterArea() {
+ return this.footerArea;
+ }
+
+ public List<T> getComponents() {
+ return Collections.unmodifiableList(this.components);
+ }
+
+ public int getColumnCount() {
+ return 1;
+ }
+
+ public T addComponent(int style, Map<String, Object> arguments) {
+ // TODO: Fix this terrible hack?
+ if (this.components.size() == 0) {
+ for (Label columnLabel : this.columnLabels) {
+ columnLabel.setVisible(true);
+ }
+ }
+
+ final int componentCount = this.components.size();
+ T component = this.componentFactory.constructWidget(
+ this, this.scrolledAreaGrid, style, arguments, componentCount, this.uniqueComponentCount);
+ this.uniqueComponentCount++;
+
+// Control componentControlHack = (Control) component;
+// componentControlHack.setLayoutData(createComponentLayoutData());
+ fixSize();
+
+ this.components.add(component);
+
+ return component;
+ }
+
+ public void removeComponent(int index) {
+// this.components.get(index).dispose();
+ this.scrolledAreaGrid.removeRow(index);
+ this.components.remove(index);
+ fixSize();
+
+ for (int ii = 0; ii < this.components.size(); ii++) {
+ this.componentFactory.reindexComponent(this.components.get(ii), ii);
+ }
+
+ // TODO: Fix this terrible hack?
+ if (this.components.size() == 0) {
+ for (Label columnLabel : this.columnLabels) {
+ columnLabel.setVisible(false);
+ }
+ }
+ }
+
+ public Collection<Label> createColumnLabels(Composite parent, int style) {
+ List<Label> columnLabels = new ArrayList<Label>();
+
+ for (String columnLabelText : createColumnLabelTexts()) {
+ Label columnLabel = new Label(parent, style);
+ columnLabel.setLayoutData(createColumnLabelLayoutData());
+ columnLabel.setText(columnLabelText);
+ columnLabels.add(columnLabel);
+ }
+
+ return columnLabels;
+ }
+
+ public Collection<String> createColumnLabelTexts() {
+ List<String> columnLabelTexts = new ArrayList<String>();
+
+ for (int ii = 0; ii < getColumnCount(); ii++) {
+ columnLabelTexts.add("Column " + ii);
+ }
+
+ return columnLabelTexts;
+ }
+
+ private void fixSize() {
+ Composite scrolledArea = this.scrolledAreaGrid.getActualParent();
+ this.scrollingArea.setMinSize(scrolledArea.computeSize(SWT.DEFAULT, SWT.DEFAULT));
+ scrolledArea.pack();
+ }
+
+ protected Composite createHeaderArea() {
+ Composite headerArea = new Composite(this, SWT.NONE);
+ headerArea.setLayoutData(createHeaderAreaLayoutData());
+ headerArea.setLayout(createHeaderLayout());
+
+ return headerArea;
+ }
+
+ protected GridData createHeaderAreaLayoutData() {
+ GridData layoutData = new GridData(SWT.FILL, SWT.TOP, true, false);
+
+ return layoutData;
+ }
+
+ protected GridLayout createHeaderLayout() {
+ GridLayout layout = new GridLayout(1, false);
+ GUIBuilderUtilities.clearMargins(layout);
+ GUIBuilderUtilities.clearSpacing(layout);
+
+ return layout;
+ }
+
+ protected ScrolledComposite createScrollingArea() {
+ ScrolledComposite scrollingArea =
+ new ScrolledComposite(this, SWT.BORDER | SWT.V_SCROLL);
+ scrollingArea.setLayoutData(createScrollingAreaLayoutData());
+ scrollingArea.setLayout(createScrollingLayout());
+
+ return scrollingArea;
+ }
+
+ protected GridData createScrollingAreaLayoutData() {
+ GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
+
+ return layoutData;
+ }
+
+ private GridLayout createScrollingLayout() {
+ GridLayout layout = new GridLayout(1, true);
+ GUIBuilderUtilities.clearMargins(layout);
+ GUIBuilderUtilities.clearSpacing(layout);
+
+ return layout;
+ }
+
+ protected Composite createFooterArea() {
+ Composite footerArea = new Composite(this, SWT.BORDER);
+ footerArea.setLayoutData(createFooterAreaLayoutData());
+ footerArea.setLayout(createFooterLayout());
+
+ return footerArea;
+ }
+
+ protected GridData createFooterAreaLayoutData() {
+ GridData layoutData = new GridData(SWT.FILL, SWT.TOP, true, false);
+
+ return layoutData;
+ }
+
+ protected GridLayout createFooterLayout() {
+ GridLayout layout = new GridLayout(1, false);
+ GUIBuilderUtilities.clearMargins(layout);
+ GUIBuilderUtilities.clearSpacing(layout);
+
+ return layout;
+ }
+
+ private GridContainer createScrolledAreaGrid(Composite parent) {
+ Composite columnArea = new Composite(parent, SWT.NONE);
+ columnArea.setLayoutData(createScrolledAreaLayoutData());
+ final int columnCount = getColumnCount();
+ columnArea.setLayout(createScrolledAreaLayout(columnCount));
+
+ return new GridContainer(columnArea, columnCount);
+ }
+
+ protected GridData createScrolledAreaLayoutData() {
+ GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
+
+ return layoutData;
+ }
+
+ protected GridLayout createScrolledAreaLayout(int columnCount) {
+ GridLayout layout = new GridLayout(columnCount, false);
+// GUIBuilderUtilities.clearMargins(layout);
+// GUIBuilderUtilities.clearSpacing(layout);
+
+ return layout;
+ }
+
+ protected GridData createColumnLabelLayoutData() {
+ GridData layoutData = new GridData(SWT.CENTER, SWT.CENTER, false, false);
+
+ return layoutData;
+ }
+
+ protected GridData createComponentLayoutData() {
+ GridData layoutData = new GridData(SWT.FILL, SWT.TOP, true, false);
+
+ return layoutData;
+ }
+
+ private static GridLayout createLayout() {
+ GridLayout layout = new GridLayout(1, true);
+ GUIBuilderUtilities.clearMargins(layout);
+ GUIBuilderUtilities.clearSpacing(layout);
+
+ return layout;
+ }
+}
\ No newline at end of file
Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/GUIBuilderUtilities.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/GUIBuilderUtilities.java (rev 0)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/GUIBuilderUtilities.java 2010-07-12 21:24:14 UTC (rev 1084)
@@ -0,0 +1,78 @@
+package org.cishell.utilities.swt;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+
+public class GUIBuilderUtilities {
+ public static Display createDisplay() {
+ return new Display();
+ }
+
+ public static Shell createShell(
+ Display display,
+ String windowTitle,
+ int windowWidth,
+ int windowHeight,
+ int columnCount,
+ boolean clearSpacing) {
+ Shell shell = new Shell(display, SWT.CLOSE | SWT.MIN | SWT.TITLE);
+ shell.setText(windowTitle);
+ shell.setSize(windowWidth, windowHeight);
+ shell.setLayout(createShellLayout(columnCount, clearSpacing));
+
+ return shell;
+ }
+
+ public static GridLayout createShellLayout(int columnCount, boolean clearSpacing) {
+ GridLayout layout = new GridLayout(columnCount, true);
+
+ if (clearSpacing) {
+ clearSpacing(layout);
+ }
+
+ return layout;
+ }
+
+ public static void openShell(
+ Shell shell, int windowHeight, boolean useWindowHeightToSizeShell) {
+// if (useWindowHeightToSizeShell) {
+// /* (So far, we've created the shell at the maximum possible size we'll allow
+// * (according to windowHeight). This line shrinks the shell to be a more fitting size
+// * if the actual contents (i.e. our (number of) columns) are smaller than the maximum
+// * size we set.)
+// */
+// Point shellSize = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT);
+// shell.setMinimumSize(shellSize.x, Math.min(windowHeight, shellSize.y));
+// }
+
+ shell.pack();
+ shell.open();
+
+ if (useWindowHeightToSizeShell) {
+ Point shellSize = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT);
+ shell.setSize(shell.getSize().x, Math.min(windowHeight, shellSize.y));
+ }
+ }
+
+ public static void swtLoop(Display display, Shell shell) {
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch()) {
+ display.sleep();
+ }
+ }
+
+ display.dispose();
+ }
+
+ public static void clearMargins(GridLayout layout) {
+ layout.marginTop = layout.marginBottom = layout.marginHeight = 0;
+ layout.marginLeft = layout.marginRight = layout.marginWidth = 0;
+ }
+
+ public static void clearSpacing(GridLayout layout) {
+ layout.horizontalSpacing = layout.verticalSpacing = 0;
+ }
+}
\ No newline at end of file
Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/GridContainer.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/GridContainer.java (rev 0)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/GridContainer.java 2010-07-12 21:24:14 UTC (rev 1084)
@@ -0,0 +1,92 @@
+package org.cishell.utilities.swt;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Widget;
+
+public class GridContainer {
+ private Composite actualParent;
+ private int columnCount;
+ private List<GridRow> rows = new ArrayList<GridRow>();
+
+ public GridContainer(Composite actualParent, int columnCount) {
+ this.actualParent = actualParent;
+ this.columnCount = columnCount;
+ }
+
+ public Composite getActualParent() {
+ return this.actualParent;
+ }
+
+ public int getColumnCount() {
+ return this.columnCount;
+ }
+
+ public int getRowCount() {
+ return this.rows.size();
+ }
+
+ public GridRow addComponent(Widget component) {
+ GridRow lastRow = getOrCreateLastUsableRow();
+ lastRow.addComponent(component);
+
+ return lastRow;
+ }
+
+ public void removeRow(int rowIndex) {
+ this.rows.get(rowIndex).dispose();
+ this.rows.remove(rowIndex);
+ }
+
+ private GridRow getOrCreateLastUsableRow() {
+ final int rowCount = getRowCount();
+
+ if (rowCount == 0) {
+ return addNewRow();
+ } else {
+ GridRow lastRow = this.rows.get(rowCount - 1);
+
+ if (lastRow.componentCount < getColumnCount()) {
+ return lastRow;
+ } else {
+ return addNewRow();
+ }
+ }
+ }
+
+ private GridRow addNewRow() {
+ GridRow row = new GridRow(getRowCount());
+ this.rows.add(row);
+
+ return row;
+ }
+
+ public class GridRow {
+ private int rowIndex;
+ private int componentCount = 0;
+ private Collection<Widget> components =
+ new ArrayList<Widget>(GridContainer.this.columnCount);
+
+ private GridRow(int rowIndex) {
+ this.rowIndex = rowIndex;
+ }
+
+ public int getRowIndex() {
+ return this.rowIndex;
+ }
+
+ private void addComponent(Widget component) {
+ this.components.add(component);
+ this.componentCount++;
+ }
+
+ private void dispose() {
+ for (Widget component : this.components) {
+ component.dispose();
+ }
+ }
+ }
+}
Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/ScrolledComponentFactory.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/ScrolledComponentFactory.java (rev 0)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/ScrolledComponentFactory.java 2010-07-12 21:24:14 UTC (rev 1084)
@@ -0,0 +1,15 @@
+package org.cishell.utilities.swt;
+
+import java.util.Map;
+
+public interface ScrolledComponentFactory<T> {
+ public T constructWidget(
+ ExpandableComponentWidget<T> componentWidget,
+ GridContainer scrolledAreaGrid,
+ int style,
+ Map<String, Object> arguments,
+ int index,
+ int uniqueIndex);
+
+ public void reindexComponent(T component, int newIndex);
+}
\ No newline at end of file
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModel.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModel.java 2010-07-09 20:55:18 UTC (rev 1083)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModel.java 2010-07-12 21:24:14 UTC (rev 1084)
@@ -2,6 +2,7 @@
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -63,6 +64,7 @@
Composite parent,
int style) {
java.util.List<String> orderedOptionLabels = new ArrayList<String>(unorderedOptionLabels);
+ Collections.sort(orderedOptionLabels);
Combo dropDown = new Combo(parent, style | SWT.DROP_DOWN);
DropDownDataSynchronizer dataSynchronizer = new DropDownDataSynchronizer(
dropDown, selectedIndex, orderedOptionLabels, optionValuesByLabels);
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModelField.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModelField.java 2010-07-09 20:55:18 UTC (rev 1083)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModelField.java 2010-07-12 21:24:14 UTC (rev 1084)
@@ -28,6 +28,7 @@
if (event.type == GUIModelField.this.dataSynchronizer.swtUpdateListenerCode()) {
GUIModelField.this.value =
GUIModelField.this.dataSynchronizer.synchronizeFromGUI();
+ System.err.println(GUIModelField.this.value);
}
}
});
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|