From: <fu...@us...> - 2010-02-04 22:49:58
|
Revision: 1032 http://cishell.svn.sourceforge.net/cishell/?rev=1032&view=rev Author: fugu13 Date: 2010-02-04 22:49:51 +0000 (Thu, 04 Feb 2010) Log Message: ----------- Add text area support. Increase maximum initial dialogue height somewhat, because the text areas were just large enough to push the "directed" checkbox on the graph extractor below the visible area (there was a scrollbar, but this is an easy tweak for a common algorithm, with no drawbacks, since the height is pretty arbitrary anyways, beyond being less than typical screen heights). Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/SWTGui.java trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/ComponentProvider.java trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/StringComponent.java Modified: trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/SWTGui.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/SWTGui.java 2010-01-28 20:18:19 UTC (rev 1031) +++ trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/SWTGui.java 2010-02-04 22:49:51 UTC (rev 1032) @@ -42,7 +42,7 @@ * @author Bruce Herr (bh...@bh...) */ public class SWTGui implements GUI, UpdateListener { - private static final int MAXIMUM_INITIAL_DIALOGUE_HEIGHT = 400; + private static final int MAXIMUM_INITIAL_DIALOGUE_HEIGHT = 500; public static final int TEXT_WRAP_LENGTH = 350; Modified: trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/ComponentProvider.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/ComponentProvider.java 2010-01-28 20:18:19 UTC (rev 1031) +++ trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/ComponentProvider.java 2010-02-04 22:49:51 UTC (rev 1032) @@ -56,6 +56,9 @@ } else if (defaultValue[0].startsWith("directory:")) { component = new DirectoryComponent(); break; + } else if(defaultValue[0].startsWith("textarea:")) { + component = new StringComponent(true); + break; } } case (AttributeDefinition.BYTE): Modified: trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/StringComponent.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/StringComponent.java 2010-01-28 20:18:19 UTC (rev 1031) +++ trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/StringComponent.java 2010-02-04 22:49:51 UTC (rev 1032) @@ -31,107 +31,124 @@ * @author Bruce Herr (bh...@bh...) */ public class StringComponent extends AbstractComponent { - protected Text textField; - protected Combo combo; - protected String[] optionValues; - - public StringComponent() { - this(false, 1); - } - - public StringComponent(boolean drawLabel, int numColumns) { - super(drawLabel, numColumns); - } - - public Control createGUI(Composite parent, int style) { - - GridData gd = new GridData(SWT.FILL,SWT.CENTER,true,false); + protected Text textField; + protected Combo combo; + protected String[] optionValues; + private boolean multiline; + + public StringComponent() { + this(false, 1); + } + + public StringComponent(boolean multiline) { + this(false, 1); + this.multiline = multiline; + } + + public StringComponent(boolean drawLabel, int numColumns) { + super(drawLabel, numColumns); + } + + public Control createGUI(Composite parent, int style) { + + GridData gd = new GridData(SWT.FILL,SWT.CENTER,true,true); gd.horizontalSpan = MAX_SPAN-1; gd.minimumWidth = 100; - optionValues = attr.getOptionValues(); + optionValues = attr.getOptionValues(); if(optionValues != null) { - combo = new Combo(parent, style | SWT.DROP_DOWN | SWT.READ_ONLY); - - String[] optionLabels = attr.getOptionLabels(); - if(optionLabels == null) { - combo.setItems(optionValues); - } else { - combo.setItems(optionLabels); - } - - combo.select(0); - - combo.setLayoutData(gd); - - combo.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent event) { - update(); - } - }); - - return combo; - } else { - textField = new Text(parent, style | SWT.BORDER); - textField.setLayoutData(gd); - - textField.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e) { - update(); - } - }); - - return textField; - } - } + combo = new Combo(parent, style | SWT.DROP_DOWN | SWT.READ_ONLY); - public Object getValue() { - Object value; - if(combo == null) { - value = StringConverter.getInstance().stringToObject(attr, textField.getText()); - } else { - value = StringConverter.getInstance().stringToObject(attr, getListValue()); - } - - return value; - } + String[] optionLabels = attr.getOptionLabels(); + if(optionLabels == null) { + combo.setItems(optionValues); + } else { + combo.setItems(optionLabels); + } - private String getListValue() { - if (optionValues != null) { - return optionValues[combo.getSelectionIndex()]; - } else { - return "You are not specifying option values, fool!"; - } + combo.select(0); + + combo.setLayoutData(gd); + + combo.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent event) { + update(); + } + }); + + return combo; + } else { + int flags; + if(multiline) { + flags = style | SWT.BORDER | SWT.MULTI | SWT.V_SCROLL; + gd.minimumHeight = 100; + gd.minimumWidth = 250; + } else { + flags = style | SWT.BORDER; + } + textField = new Text(parent, flags); + textField.setLayoutData(gd); + + textField.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + update(); + } + }); + + return textField; + } } + public Object getValue() { + Object value; + if(combo == null) { + value = StringConverter.getInstance().stringToObject(attr, textField.getText()); + } else { + value = StringConverter.getInstance().stringToObject(attr, getListValue()); + } + + return value; + } + + private String getListValue() { + if (optionValues != null) { + return optionValues[combo.getSelectionIndex()]; + } else { + return "You are not specifying option values, fool!"; + } + } + public String validate() { - if (getValue() == null) { - return "Invalid basic value"; - } - if(combo == null) { - return attr.validate(textField.getText()); - } else { - return attr.validate(getListValue()); - } - } + if (getValue() == null) { + return "Invalid basic value"; + } + if(combo == null) { + return attr.validate(textField.getText()); + } else { + return attr.validate(getListValue()); + } + } - public void setValue(Object value) { - if (textField != null) { - textField.setText(value == null ? "" : value.toString()); - } else if (combo != null) { - - int setComboToIndex = -1; - for (int i = 0; i < optionValues.length; i++) { - if (value.equals(optionValues[i])) { - setComboToIndex = i; - } - } - - if (setComboToIndex != -1) { - combo.select(setComboToIndex); - } else { - System.err.println("Attempted to set combo box to a value " + - "that didn't exist inside the combo box."); - } - } - } + public void setValue(Object value) { + if(value.toString().startsWith("textarea:")) { + value = value.toString().substring("textarea:".length()); + } + if (textField != null) { + textField.setText(value == null ? "" : value.toString()); + } else if (combo != null) { + + int setComboToIndex = -1; + for (int i = 0; i < optionValues.length; i++) { + if (value.equals(optionValues[i])) { + setComboToIndex = i; + } + } + + if (setComboToIndex != -1) { + combo.select(setComboToIndex); + } else { + System.err.println("Attempted to set combo box to a value " + + "that didn't exist inside the combo box."); + } + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |