From: <fu...@us...> - 2009-07-31 18:53:45
|
Revision: 910 http://cishell.svn.sourceforge.net/cishell/?rev=910&view=rev Author: fugu13 Date: 2009-07-31 18:53:20 +0000 (Fri, 31 Jul 2009) Log Message: ----------- Add scrolling to parameter dialogue boxes. Reviewed by Micah. 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/SWTGuiComposite.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 2009-07-31 15:24:24 UTC (rev 909) +++ trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/SWTGui.java 2009-07-31 18:53:20 UTC (rev 910) @@ -25,6 +25,7 @@ import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.Point; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; @@ -41,6 +42,8 @@ * @author Bruce Herr (bh...@bh...) */ public class SWTGui implements GUI, UpdateListener { + private static final int MAXIMUM_INITIAL_DIALOGUE_HEIGHT = 400; + public static final int TEXT_WRAP_LENGTH = 350; private Shell shell; @@ -60,7 +63,9 @@ ObjectClassDefinition ocd = provider.getObjectClassDefinition(id, null); shell.setText(ocd.getName()); - + + + GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 1; shell.setLayout(gridLayout); @@ -76,9 +81,7 @@ GridData labelData = new GridData(); labelData.horizontalAlignment = GridData.CENTER; labelData.grabExcessHorizontalSpace = true; - System.out.println(msg.getSize().x); if (msg.getSize().x > TEXT_WRAP_LENGTH) { - System.out.println(msg.getSize().x); labelData.widthHint = TEXT_WRAP_LENGTH; } msg.setLayoutData(labelData); @@ -163,8 +166,18 @@ shell.getDisplay().syncExec(new Runnable() { public void run() { shell.pack(); + resizeShell(shell); shell.open(); - }}); + } + + private void resizeShell(Shell shell) { + Point shellSize = shell.getSize(); + shell.setSize(shellSize.x, calculateNewDialogHeight(shellSize.y)); + } + + private int calculateNewDialogHeight(int proposedHeight) { + return Math.min(MAXIMUM_INITIAL_DIALOGUE_HEIGHT, proposedHeight); + }}); } /** Modified: trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/SWTGuiComposite.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/SWTGuiComposite.java 2009-07-31 15:24:24 UTC (rev 909) +++ trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/SWTGuiComposite.java 2009-07-31 18:53:20 UTC (rev 910) @@ -26,6 +26,7 @@ import org.eclipse.swt.custom.ScrolledComposite; import org.eclipse.swt.events.DisposeEvent; import org.eclipse.swt.events.DisposeListener; +import org.eclipse.swt.graphics.Point; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; @@ -45,8 +46,8 @@ protected Set listeners; private Composite parent; - private Composite userArea; - private ScrolledComposite userScroll; + private Composite parameterArea; + private ScrolledComposite scroll; private int style; public SWTGuiComposite(Composite parent, int style, @@ -69,7 +70,7 @@ GUIComponent component = ComponentProvider.getInstance().createComponent(attrs[i]); component.setAttributeDefinition(attrs[i]); - component.createGUI(userArea, style); + component.createGUI(parameterArea, style); idToComponentMap.put(attrs[i].getID(), component); component.addUpdateListener(this); @@ -81,24 +82,32 @@ } } - userArea.addDisposeListener(new DisposeListener() { + setScrollDimensions(scroll, parameterArea); + + parameterArea.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { enteredResponses = getEnteredResponses(); }}); } + + private void setScrollDimensions(ScrolledComposite scroll, Composite innards) { + Point parameterAreaSize = innards.computeSize(SWT.DEFAULT, SWT.DEFAULT); + scroll.setMinWidth(parameterAreaSize.x); + scroll.setMinHeight(parameterAreaSize.y); + } private void setupGUI() { - userScroll = new ScrolledComposite(parent, style); - userScroll.setLayout(new GridLayout(1, true)); - userScroll.setExpandHorizontal(true); - userScroll.setExpandVertical(true); - userScroll.setAlwaysShowScrollBars(false); + scroll = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL); + scroll.setLayout(new GridLayout(1, true)); + scroll.setExpandHorizontal(true); + scroll.setExpandVertical(true); + scroll.setAlwaysShowScrollBars(false); - userArea = new Composite(userScroll, SWT.NONE); - userArea.setLayout(new GridLayout(GUIComponent.MAX_SPAN+1,false)); + parameterArea = new Composite(scroll, SWT.NONE); + parameterArea.setLayout(new GridLayout(GUIComponent.MAX_SPAN+1,false)); GridData gd = new GridData(SWT.FILL,SWT.FILL,true,true); - userArea.setLayoutData(gd); + parameterArea.setLayoutData(gd); GridData userData = new GridData(); userData.grabExcessVerticalSpace = true; @@ -106,8 +115,8 @@ userData.verticalAlignment = SWT.FILL; userData.horizontalAlignment = SWT.FILL; - userScroll.setLayoutData(userData); - userScroll.setContent(userArea); + scroll.setLayoutData(userData); + scroll.setContent(parameterArea); } @@ -138,11 +147,11 @@ * @return the composite */ public Composite getUserArea() { - return userArea; + return parameterArea; } public Composite getComposite() { - return userScroll; + return scroll; } public String validate() { 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 2009-07-31 15:24:24 UTC (rev 909) +++ trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/StringComponent.java 2009-07-31 18:53:20 UTC (rev 910) @@ -13,8 +13,6 @@ * ***************************************************************************/ package org.cishell.reference.gui.guibuilder.swt.builder.components; -import java.util.Arrays; - import org.cishell.reference.gui.guibuilder.swt.builder.AbstractComponent; import org.cishell.reference.gui.guibuilder.swt.builder.StringConverter; import org.eclipse.swt.SWT; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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. |
From: <pat...@us...> - 2010-11-12 16:51:06
|
Revision: 1152 http://cishell.svn.sourceforge.net/cishell/?rev=1152&view=rev Author: pataphil Date: 2010-11-12 16:50:55 +0000 (Fri, 12 Nov 2010) Log Message: ----------- * Made more Java 1.5 and cleaned up a bit. * Fixed bug in validation relating to multiple fields validating depending on each other. 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/SWTGuiComposite.java trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/AbstractComponent.java trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/BooleanComponent.java trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/LabelingComponent.java trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/MultiValuedComponent.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-11-12 16:47:14 UTC (rev 1151) +++ trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/SWTGui.java 2010-11-12 16:50:55 UTC (rev 1152) @@ -37,10 +37,6 @@ import org.osgi.service.metatype.MetaTypeProvider; import org.osgi.service.metatype.ObjectClassDefinition; -/** - * - * @author Bruce Herr (bh...@bh...) - */ public class SWTGui implements GUI, UpdateListener { private static final int MAXIMUM_INITIAL_DIALOGUE_HEIGHT = 500; @@ -53,8 +49,7 @@ private Button okButton; - public SWTGui(final Shell shell, int style, - String id, MetaTypeProvider provider) { + public SWTGui(final Shell shell, int style, String id, MetaTypeProvider provider) { this.shell = shell; if (provider == null) { @@ -62,20 +57,18 @@ } ObjectClassDefinition ocd = provider.getObjectClassDefinition(id, null); - shell.setText(ocd.getName()); - - - + this.shell.setText(ocd.getName()); + GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 1; - shell.setLayout(gridLayout); + this.shell.setLayout(gridLayout); - Font defaultFont = new Font(shell.getDisplay(), "SanSerif", 8, SWT.NONE); + Font defaultFont = new Font(this.shell.getDisplay(), "SanSerif", 8, SWT.NONE); //stuff to display a message String message = ocd.getDescription(); if(message != null && !message.equals("")){ - Label msg = new Label(shell, SWT.WRAP); + Label msg = new Label(this.shell, SWT.WRAP); msg.setText(message); msg.pack(true); GridData labelData = new GridData(); @@ -88,11 +81,11 @@ } //set up the user area where the main GUI will be set up using Parameters - composite = new SWTGuiComposite(shell, style, id, provider); + composite = new SWTGuiComposite(this.shell, style, id, provider); composite.addUpdateListener(this); //the group w/ ok and cancel - Composite buttonsGroup = new Composite(shell, SWT.NONE); + Composite buttonsGroup = new Composite(this.shell, SWT.NONE); FillLayout rowLayout = new FillLayout(); rowLayout.spacing = 5; buttonsGroup.setLayout(rowLayout); @@ -103,11 +96,11 @@ gridData.grabExcessHorizontalSpace = false; buttonsGroup.setLayoutData(gridData); - okButton = new Button(buttonsGroup, SWT.PUSH); - okButton.setText("OK"); - okButton.setSize(40, 20); - okButton.setFont(defaultFont); - okButton.addSelectionListener(new SelectionAdapter() { + this.okButton = new Button(buttonsGroup, SWT.PUSH); + this.okButton.setText("OK"); + this.okButton.setSize(40, 20); + this.okButton.setFont(defaultFont); + this.okButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { hitOk = true; close(); @@ -129,14 +122,14 @@ }); - shell.addDisposeListener(new DisposeListener() { + this.shell.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { if (!hitOk && listener != null) { listener.cancelled(); } }}); - shell.setDefaultButton(okButton); + this.shell.setDefaultButton(this.okButton); validate(); } @@ -145,10 +138,10 @@ * @see org.cishell.service.guibuilder.GUI#close() */ public void close() { - shell.getDisplay().syncExec(new Runnable() { + this.shell.getDisplay().syncExec(new Runnable() { public void run() { - shell.close(); - shell.dispose(); + SWTGui.this.shell.close(); + SWTGui.this.shell.dispose(); }}); } @@ -156,18 +149,18 @@ * @see org.cishell.service.guibuilder.GUI#isClosed() */ public boolean isClosed() { - return shell.isDisposed(); + return this.shell.isDisposed(); } /** * @see org.cishell.service.guibuilder.GUI#open() */ public void open() { - shell.getDisplay().syncExec(new Runnable() { + this.shell.getDisplay().syncExec(new Runnable() { public void run() { - shell.pack(); - resizeShell(shell); - shell.open(); + SWTGui.this.shell.pack(); + resizeShell(SWTGui.this.shell); + SWTGui.this.shell.open(); } private void resizeShell(Shell shell) { @@ -183,7 +176,7 @@ /** * @see org.cishell.service.guibuilder.GUI#openAndWait() */ - public Dictionary openAndWait() { + public Dictionary<String, Object> openAndWait() { open(); final Display display = shell.getDisplay(); @@ -201,11 +194,11 @@ } private static class OpenAndWaitListener implements SelectionListener { - Dictionary valuesEntered = null; + Dictionary<String, Object> valuesEntered = null; public void cancelled() {} - public void hitOk(Dictionary valuesEntered) { + public void hitOk(Dictionary<String, Object> valuesEntered) { this.valuesEntered = valuesEntered; } } @@ -220,11 +213,11 @@ public String validate() { String valid = composite.validate(); - //if valid is a string then the string is the error message - if (valid != null && valid.length() > 0) { - okButton.setEnabled(false); + // If valid is a string then the string is the error message. + if ((valid != null) && (valid.length() > 0)) { + this.okButton.setEnabled(false); } else { - okButton.setEnabled(true); + this.okButton.setEnabled(true); } return valid; Modified: trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/SWTGuiComposite.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/SWTGuiComposite.java 2010-11-12 16:47:14 UTC (rev 1151) +++ trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/SWTGuiComposite.java 2010-11-12 16:50:55 UTC (rev 1152) @@ -16,7 +16,6 @@ import java.util.Dictionary; import java.util.HashSet; import java.util.Hashtable; -import java.util.Iterator; import java.util.Set; import org.cishell.reference.gui.guibuilder.swt.builder.ComponentProvider; @@ -40,53 +39,50 @@ * @author Bruce Herr (bh...@bh...) */ public class SWTGuiComposite implements UpdateListener { - private ObjectClassDefinition ocd; - private Dictionary idToComponentMap; - private Dictionary enteredResponses; - protected Set listeners; + private ObjectClassDefinition objectClassDefinition; + private Dictionary<String, GUIComponent> idToComponentMap; + private Dictionary<String, Object> enteredResponses; + protected Set<UpdateListener> updateListeners; private Composite parent; private Composite parameterArea; - private ScrolledComposite scroll; - private int style; + private ScrolledComposite scrollingArea; - public SWTGuiComposite(Composite parent, int style, - String id, MetaTypeProvider provider) { + public SWTGuiComposite(Composite parent, int style, String id, MetaTypeProvider provider) { if (provider == null) { throw new IllegalArgumentException("Null MetaTypeProvider given"); } - this.idToComponentMap = new Hashtable(); - this.ocd = provider.getObjectClassDefinition(id, null); + this.idToComponentMap = new Hashtable<String, GUIComponent>(); + this.objectClassDefinition = provider.getObjectClassDefinition(id, null); this.parent = parent; - this.style = style; - this.listeners = new HashSet(); - this.enteredResponses = new Hashtable(); + this.updateListeners = new HashSet<UpdateListener>(); + this.enteredResponses = new Hashtable<String, Object>(); setupGUI(); - - AttributeDefinition[] attrs = ocd.getAttributeDefinitions(ObjectClassDefinition.ALL); - for (int i=0; i < attrs.length; i++) { - GUIComponent component = ComponentProvider.getInstance().createComponent(attrs[i]); - - component.setAttributeDefinition(attrs[i]); - component.createGUI(parameterArea, style); - idToComponentMap.put(attrs[i].getID(), component); + + for (AttributeDefinition attribute : + this.objectClassDefinition.getAttributeDefinitions(ObjectClassDefinition.ALL)) { + GUIComponent component = ComponentProvider.getInstance().createComponent(attribute); + + component.setAttributeDefinition(attribute); + component.createGUI(this.parameterArea, style); + this.idToComponentMap.put(attribute.getID(), component); component.addUpdateListener(this); Object value = component.getValue(); String valid = component.validate(); - if (value != null && (valid == null || valid.length() == 0)) { - enteredResponses.put(component.getAttributeDefinition().getID(), value); + if ((value != null) && ((valid == null) || (valid.length() == 0))) { + this.enteredResponses.put(component.getAttributeDefinition().getID(), value); } } - setScrollDimensions(scroll, parameterArea); + setScrollDimensions(this.scrollingArea, this.parameterArea); - parameterArea.addDisposeListener(new DisposeListener() { - public void widgetDisposed(DisposeEvent e) { - enteredResponses = getEnteredResponses(); + this.parameterArea.addDisposeListener(new DisposeListener() { + public void widgetDisposed(DisposeEvent event) { + SWTGuiComposite.this.enteredResponses = getEnteredResponses(); }}); } @@ -97,17 +93,17 @@ } private void setupGUI() { - scroll = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL); - scroll.setLayout(new GridLayout(1, true)); - scroll.setExpandHorizontal(true); - scroll.setExpandVertical(true); - scroll.setAlwaysShowScrollBars(false); + this.scrollingArea = new ScrolledComposite(this.parent, SWT.H_SCROLL | SWT.V_SCROLL); + this.scrollingArea.setLayout(new GridLayout(1, true)); + this.scrollingArea.setExpandHorizontal(true); + this.scrollingArea.setExpandVertical(true); + this.scrollingArea.setAlwaysShowScrollBars(false); - parameterArea = new Composite(scroll, SWT.NONE); - parameterArea.setLayout(new GridLayout(GUIComponent.MAX_SPAN+1,false)); + this.parameterArea = new Composite(scrollingArea, SWT.NONE); + this.parameterArea.setLayout(new GridLayout(GUIComponent.MAX_SPAN + 1, false)); - GridData gd = new GridData(SWT.FILL,SWT.FILL,true,true); - parameterArea.setLayoutData(gd); + GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true); + this.parameterArea.setLayoutData(gridData); GridData userData = new GridData(); userData.grabExcessVerticalSpace = true; @@ -115,23 +111,28 @@ userData.verticalAlignment = SWT.FILL; userData.horizontalAlignment = SWT.FILL; - scroll.setLayoutData(userData); - scroll.setContent(parameterArea); + this.scrollingArea.setLayoutData(userData); + this.scrollingArea.setContent(this.parameterArea); } public ObjectClassDefinition getObjectClassDefinition() { - return ocd; + return this.objectClassDefinition; } public Object getResponse(String id) { - GUIComponent component = (GUIComponent) idToComponentMap.get(id); - - return component == null ? null : component.getValue(); + GUIComponent component = this.idToComponentMap.get(id); + + if (component != null) { + return component.getValue(); + } else { + return null; + } +// return component == null ? null : component.getValue(); } - public Dictionary getEnteredResponses() { - return enteredResponses; + public Dictionary<String, Object> getEnteredResponses() { + return this.enteredResponses; } /** @@ -139,7 +140,7 @@ * @return the shell */ public Shell getShell() { - return parent.getShell(); + return this.parent.getShell(); } /** @@ -147,22 +148,22 @@ * @return the composite */ public Composite getUserArea() { - return parameterArea; + return this.parameterArea; } public Composite getComposite() { - return scroll; + return this.scrollingArea; } public String validate() { String totalValid = ""; - - AttributeDefinition[] attrs = ocd.getAttributeDefinitions(ObjectClassDefinition.REQUIRED); - - for (int i=0; i < attrs.length; i++) { - GUIComponent component = (GUIComponent) idToComponentMap.get(attrs[i].getID()); + + for (AttributeDefinition attribute : this.objectClassDefinition.getAttributeDefinitions( + ObjectClassDefinition.REQUIRED)) { + GUIComponent component = this.idToComponentMap.get(attribute.getID()); String valid = component.validate(); - if (valid != null && valid.length() > 0) { + + if ((valid != null) && (valid.length() > 0)) { totalValid += "\"" + valid + "\"; "; } } @@ -174,22 +175,22 @@ Object value = component.getValue(); String valid = component.validate(); - if (value != null && (valid == null || valid.length() == 0)) { - enteredResponses.put(component.getAttributeDefinition().getID(), value); + if ((value != null) && ((valid == null) || (valid.length() == 0))) { + this.enteredResponses.put(component.getAttributeDefinition().getID(), value); } else { - enteredResponses.remove(component.getAttributeDefinition().getID()); + this.enteredResponses.remove(component.getAttributeDefinition().getID()); } - - for (Iterator i=listeners.iterator(); i.hasNext(); ) { - ((UpdateListener) i.next()).componentUpdated(component); + + for (UpdateListener listener : this.updateListeners) { + listener.componentUpdated(component); } } public void addUpdateListener(UpdateListener listener) { - listeners.add(listener); + this.updateListeners.add(listener); } public void removeUpdateListener(UpdateListener listener) { - listeners.remove(listener); + this.updateListeners.remove(listener); } } Modified: trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/AbstractComponent.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/AbstractComponent.java 2010-11-12 16:47:14 UTC (rev 1151) +++ trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/AbstractComponent.java 2010-11-12 16:50:55 UTC (rev 1152) @@ -14,7 +14,6 @@ package org.cishell.reference.gui.guibuilder.swt.builder; import java.util.HashSet; -import java.util.Iterator; import java.util.Set; import org.eclipse.swt.widgets.Composite; @@ -26,51 +25,53 @@ * @author Bruce Herr (bh...@bh...) */ public abstract class AbstractComponent implements GUIComponent { - protected AttributeDefinition attr; + protected AttributeDefinition attribute; protected boolean drawsLabel; - protected int numColumns; - protected Set listeners; + protected int columnCount; + protected Set<UpdateListener> listeners; public abstract void setValue(Object value); public abstract Object getValue(); public abstract String validate(); public abstract Control createGUI(Composite parent, int style); - public AbstractComponent(boolean drawsLabel, int numColumns) { + public AbstractComponent(boolean drawsLabel, int columnCount) { this.drawsLabel = drawsLabel; - this.numColumns = numColumns; - this.listeners = new HashSet(); + this.columnCount = columnCount; + this.listeners = new HashSet<UpdateListener>(); } public AttributeDefinition getAttributeDefinition() { - if (attr == null) { + if (this.attribute == null) { throw new IllegalStateException("AttributeDefinition has not been set"); } - return attr; + return this.attribute; } - public void setAttributeDefinition(AttributeDefinition attr) { - this.attr = attr; + public void setAttributeDefinition(AttributeDefinition attribute) { + this.attribute = attribute; } + public boolean drawsLabel() { - return drawsLabel; + return this.drawsLabel; } + public int getColumns() { - return numColumns; + return this.columnCount; } protected void update() { - for (Iterator i=listeners.iterator(); i.hasNext(); ) { - ((UpdateListener) i.next()).componentUpdated(this); + for (UpdateListener listener : this.listeners) { + listener.componentUpdated(this); } } public void addUpdateListener(UpdateListener listener) { - listeners.add(listener); + this.listeners.add(listener); } public void removeUpdateListener(UpdateListener listener) { - listeners.remove(listener); + this.listeners.remove(listener); } } Modified: trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/BooleanComponent.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/BooleanComponent.java 2010-11-12 16:47:14 UTC (rev 1151) +++ trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/BooleanComponent.java 2010-11-12 16:50:55 UTC (rev 1152) @@ -32,18 +32,18 @@ public Control createGUI(Composite parent, int style) { checkbox = new Button(parent, SWT.CHECK); - GridData gridData = new GridData(SWT.LEFT,SWT.CENTER,false,false); + GridData gridData = new GridData(SWT.LEFT, SWT.CENTER, false, false); gridData.horizontalSpan = MAX_SPAN; checkbox.setLayoutData(gridData); - String label = attr.getName(); + String label = attribute.getName(); if(label != null) checkbox.setText(label); else checkbox.setText(""); checkbox.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { + public void widgetSelected(SelectionEvent event) { update(); }}); @@ -51,11 +51,11 @@ } public Object getValue() { - return checkbox.getSelection() ? Boolean.TRUE : Boolean.FALSE; + return Boolean.valueOf(this.checkbox.getSelection()); } public void setValue(Object value) { - if (value instanceof Boolean && value != null) { + if ((value instanceof Boolean) && (value != null)) { checkbox.setSelection(((Boolean) value).booleanValue()); } else { checkbox.setSelection(false); @@ -63,6 +63,6 @@ } public String validate() { - return attr.validate(""+checkbox.getSelection()); + return attribute.validate("" + checkbox.getSelection()); } } Modified: trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/LabelingComponent.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/LabelingComponent.java 2010-11-12 16:47:14 UTC (rev 1151) +++ trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/LabelingComponent.java 2010-11-12 16:50:55 UTC (rev 1152) @@ -50,20 +50,22 @@ setAttributeDefinition(childComponent.getAttributeDefinition()); if (!childComponent.drawsLabel()) { - numColumns++; + columnCount++; } - String description = attr.getDescription(); - if (description != null && description.length() > 0) { - numColumns++; + String description = attribute.getDescription(); + + if ((description != null) && (description.length() > 0)) { + columnCount++; } + childComponent.addUpdateListener(this); } public Control createGUI(Composite parent, int style) { if (drawsLabel && !childComponent.drawsLabel()) { - String labelText = attr.getName(); + String labelText = attribute.getName(); if (labelText == null) { labelText = ""; } @@ -81,7 +83,6 @@ } private void createAndAddDescriptionButton(Control control, Composite parent) { - /* * Create the description button, and add it to the parent. * */ @@ -116,13 +117,80 @@ descriptionButton.addSelectionListener(listener); } + + /** + * Sets the location for a hovering shell. + * + * @param descriptionShell + * the object that is to hover + * @param position + * the position of a widget to hover over + */ + private void setHoverLocation(Shell descriptionShell, Point position) { + Rectangle displayBounds = descriptionShell.getDisplay().getBounds(); + Rectangle shellBounds = descriptionShell.getBounds(); + shellBounds.x = Math.max(Math.min(position.x + + DESCRIPTION_SHELL_LEFT_MARGIN, displayBounds.width + - shellBounds.width), 0); + + shellBounds.y = Math.max(Math.min(position.y, displayBounds.height + - shellBounds.height), 0); + descriptionShell.setBounds(shellBounds); + } + + protected void setDefaultValue() { + String[] defaults = attribute.getDefaultValue(); + + if ((defaults != null) && (defaults.length > 0)) { + Object value = StringConverter.getInstance().stringToObject(attribute, defaults[0]); + setValue(value); + } + } + + public Object getValue() { + return childComponent.getValue(); + } + + public void setValue(Object value) { + childComponent.setValue(value); + } + + public String validate() { + String valid = childComponent.validate(); + + // If valid is a string then the string is the error message. + if ((valid != null) && (valid.length() > 0)) { + label.setForeground(ERROR_COLOR); + } else { + label.setForeground(null); + } + + return valid; + } + + public void componentUpdated(GUIComponent component) { + if (!childComponent.drawsLabel()) { + validate(); + } + + update(); + } + + private String getDescriptionText() { + String descriptionText = attribute.getDescription(); + if (descriptionText == null || descriptionText.length() == 0) { + descriptionText = DEFAULT_DESCRIPTION_TEXT; + } + + return descriptionText; + } + /* * Adds selection listener to the button. Whenever a button is pressed it triggers * the button selected event, which causes the creation of a new Description hover. * Once a button is unselected it deletes the Description hover. * */ class DescriptionButtonListener implements SelectionListener { - private Shell descriptionShell = null; private String descText; @@ -180,7 +248,6 @@ } } - private Shell createDescriptionShell(final String descText, Button descriptionButton) { Shell descriptionShell = new Shell(descriptionButton.getShell(), SWT.NONE); @@ -232,71 +299,4 @@ } } } - - /** - * Sets the location for a hovering shell. - * - * @param descriptionShell - * the object that is to hover - * @param position - * the position of a widget to hover over - */ - private void setHoverLocation(Shell descriptionShell, Point position) { - Rectangle displayBounds = descriptionShell.getDisplay().getBounds(); - Rectangle shellBounds = descriptionShell.getBounds(); - shellBounds.x = Math.max(Math.min(position.x - + DESCRIPTION_SHELL_LEFT_MARGIN, displayBounds.width - - shellBounds.width), 0); - - shellBounds.y = Math.max(Math.min(position.y, displayBounds.height - - shellBounds.height), 0); - descriptionShell.setBounds(shellBounds); - } - - protected void setDefaultValue() { - String[] defaults = attr.getDefaultValue(); - - if (defaults != null && defaults.length > 0) { - - Object value = StringConverter.getInstance().stringToObject(attr, - defaults[0]); - setValue(value); - } - } - - public Object getValue() { - return childComponent.getValue(); - } - - public void setValue(Object value) { - childComponent.setValue(value); - } - - public String validate() { - return childComponent.validate(); - } - - public void componentUpdated(GUIComponent component) { - if (!childComponent.drawsLabel()) { - String valid = validate(); - - // if valid is a string then the string is the error message - if (valid != null && valid.length() > 0) { - label.setForeground(ERROR_COLOR); - } else { - label.setForeground(null); - } - } - update(); - } - - private String getDescriptionText() { - String descriptionText = attr.getDescription(); - if (descriptionText == null || descriptionText.length() == 0) { - descriptionText = DEFAULT_DESCRIPTION_TEXT; - } - - return descriptionText; - } - } Modified: trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/MultiValuedComponent.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/MultiValuedComponent.java 2010-11-12 16:47:14 UTC (rev 1151) +++ trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/MultiValuedComponent.java 2010-11-12 16:50:55 UTC (rev 1152) @@ -54,7 +54,7 @@ } protected synchronized void addComponent(int position) { - GUIComponent component = ComponentProvider.getInstance().createBasicComponent(attr); + GUIComponent component = ComponentProvider.getInstance().createBasicComponent(attribute); Control control = component.createGUI(panel, style); 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-11-12 16:47:14 UTC (rev 1151) +++ trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/StringComponent.java 2010-11-12 16:50:55 UTC (rev 1152) @@ -50,15 +50,14 @@ } 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 = attribute.getOptionValues(); if(optionValues != null) { combo = new Combo(parent, style | SWT.DROP_DOWN | SWT.READ_ONLY); - String[] optionLabels = attr.getOptionLabels(); + String[] optionLabels = attribute.getOptionLabels(); if(optionLabels == null) { combo.setItems(optionValues); } else { @@ -78,18 +77,20 @@ return combo; } else { int flags; - if(multiline) { + + 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) { + public void modifyText(ModifyEvent event) { update(); } }); @@ -101,9 +102,9 @@ public Object getValue() { Object value; if(combo == null) { - value = StringConverter.getInstance().stringToObject(attr, textField.getText()); + value = StringConverter.getInstance().stringToObject(attribute, textField.getText()); } else { - value = StringConverter.getInstance().stringToObject(attr, getListValue()); + value = StringConverter.getInstance().stringToObject(attribute, getListValue()); } return value; @@ -122,9 +123,9 @@ return "Invalid basic value"; } if(combo == null) { - return attr.validate(textField.getText()); + return attribute.validate(textField.getText()); } else { - return attr.validate(getListValue()); + return attribute.validate(getListValue()); } } @@ -151,10 +152,10 @@ /* TODO: Log this (or do something with it besides printint it to a place most * users won't see it)? */ - String warningMessage = + /*String warningMessage = "Attempted to set combo box to a value that didn't exist inside the " + "combo box."; - System.err.println(warningMessage); + System.err.println(warningMessage);*/ } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2010-11-18 17:15:43
|
Revision: 1171 http://cishell.svn.sourceforge.net/cishell/?rev=1171&view=rev Author: pataphil Date: 2010-11-18 17:15:36 +0000 (Thu, 18 Nov 2010) Log Message: ----------- * Hack NPE fix. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/SWTGuiBuilderService.java trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/LabelingComponent.java Modified: trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/SWTGuiBuilderService.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/SWTGuiBuilderService.java 2010-11-17 23:23:34 UTC (rev 1170) +++ trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/SWTGuiBuilderService.java 2010-11-18 17:15:36 UTC (rev 1171) @@ -69,7 +69,7 @@ if (validParams) { GUICreator creator = new GUICreator(id, parameters); - display.syncExec(creator); + this.display.syncExec(creator); return creator.gui; } else { @@ -96,7 +96,7 @@ shell.setImage(activeShell.getImage()); } - gui = new SWTGui(shell,SWT.NONE,id,parameters); + gui = new SWTGui(shell, SWT.NONE, id, parameters); } catch (IllegalArgumentException e) {} } } Modified: trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/LabelingComponent.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/LabelingComponent.java 2010-11-17 23:23:34 UTC (rev 1170) +++ trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/LabelingComponent.java 2010-11-18 17:15:36 UTC (rev 1171) @@ -158,11 +158,14 @@ public String validate() { String valid = childComponent.validate(); - // If valid is a string then the string is the error message. - if ((valid != null) && (valid.length() > 0)) { - label.setForeground(ERROR_COLOR); - } else { - label.setForeground(null); + // TODO: HACK: label may not have been created yet. + if (this.label != null) { + // If valid is a string then the string is the error message. + if ((valid != null) && (valid.length() > 0)) { + label.setForeground(ERROR_COLOR); + } else { + label.setForeground(null); + } } return valid; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |