/* Copyright (C) 2005 Board of Regents of the University of Wisconsin System (Univ. of Wisconsin-Madison, Trace R&D Center) This piece of the software package, developed by the Trace Center - University of Wisconsin is released to the public domain with only the following restrictions: 1) That the following acknowledgement be included in the source code and documentation for the program or package that use this code: Parts of this program were based on reference designs developed by the Trace Center, University of Wisconsin-Madison under funding from the National Institute on Disability and Rehabilitation Research US Dept of Education. 2) That this program not be modified unless it is plainly marked as modified from the original distributed by Trace. (NOTE: This release applies only to the files that contain this notice, not necessarily to any other code or libraries associated with this file. Please check individual files and libraries for the rights to use each) This reference design was developed under funding from the National Institute on Disability and Rehabilitation Research US Dept of Education. THIS PIECE OF THE SOFTWARE PACKAGE IS EXPERIMENTAL/DEMONSTRATION IN NATURE. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ package edu.wisc.trace.urcsamples.textclient; import java.util.logging.Logger; import edu.wisc.trace.urcsdk.base.UrcException; import edu.wisc.trace.urcsdk.client.ClientSession; import edu.wisc.trace.urcsdk.client.GenericClient; import edu.wisc.trace.urcsdk.client.IInteractor; import edu.wisc.trace.urcsdk.client.IUIBuilder; import edu.wisc.trace.urcsdk.client.Widget; import edu.wisc.trace.urcsdk.client.pret.BooleanInteractor; import edu.wisc.trace.urcsdk.client.pret.DateInteractor; import edu.wisc.trace.urcsdk.client.pret.DateTimeInteractor; import edu.wisc.trace.urcsdk.client.pret.DayInteractor; import edu.wisc.trace.urcsdk.client.pret.DecimalInteractor; import edu.wisc.trace.urcsdk.client.pret.DurationInteractor; import edu.wisc.trace.urcsdk.client.pret.Group; import edu.wisc.trace.urcsdk.client.pret.InputInteractor; import edu.wisc.trace.urcsdk.client.pret.ModalDialogInteractor; import edu.wisc.trace.urcsdk.client.pret.MonthDayInteractor; import edu.wisc.trace.urcsdk.client.pret.MonthInteractor; import edu.wisc.trace.urcsdk.client.pret.OutputInteractor; import edu.wisc.trace.urcsdk.client.pret.RangeInteractor; import edu.wisc.trace.urcsdk.client.pret.SecretInteractor; import edu.wisc.trace.urcsdk.client.pret.Select1Interactor; import edu.wisc.trace.urcsdk.client.pret.TimeInteractor; import edu.wisc.trace.urcsdk.client.pret.TimedTriggerInteractor; import edu.wisc.trace.urcsdk.client.pret.TriggerInteractor; import edu.wisc.trace.urcsdk.client.pret.YearInteractor; import edu.wisc.trace.urcsdk.client.pret.YearMonthInteractor; import edu.wisc.trace.urcsdk.client.uisocket.UISocketMirror; import edu.wisc.trace.urcsdk.support.LoggerUtil; /** *

* TextUIBuilder implements the IUIBuilder interface and provides * the methods needed to construct text-based UI Socket interactors. *

* *

* Created on: April 19, 2006
* Known bugs: None
* Thread safe: Yes
*

* * @author Hemanth Vijayan, Trace R&D Center * @version $Revision: 1.21 $ * */ public class TextUIBuilder implements IUIBuilder { private Logger logger = LoggerUtil.getSdkLogger(); private SessionPanel sessionPanel; UISocketMirror socket; private GenericClient urc; public TextUIBuilder(GenericClient urc) { this.urc = urc; } Widget createWidget(IInteractor i) { if (i instanceof Group) { return createGroupWidget((Group) i); } else if (i instanceof BooleanInteractor) { return createBooleanWidget((BooleanInteractor) i); } else if (i instanceof DateTimeInteractor) { return createDateTimeWidget((DateTimeInteractor) i); } else if (i instanceof TimeInteractor) { return createTimeWidget((TimeInteractor) i); } else if (i instanceof DateInteractor) { return createDateWidget((DateInteractor) i); } else if (i instanceof DecimalInteractor) { return createDecimalWidget((DecimalInteractor) i); } else if (i instanceof YearInteractor) { return createYearWidget((YearInteractor) i); } else if (i instanceof MonthInteractor) { return createMonthWidget((MonthInteractor) i); } else if (i instanceof DayInteractor) { return createDayWidget((DayInteractor) i); } else if (i instanceof MonthDayInteractor) { return createMonthDayWidget((MonthDayInteractor) i); } else if (i instanceof YearMonthInteractor) { return createYearMonthWidget((YearMonthInteractor) i); } else if (i instanceof InputInteractor) { return createInputStringWidget((InputInteractor) i); } else if (i instanceof ModalDialogInteractor) { return createModalDialogWidget((ModalDialogInteractor) i); } else if (i instanceof OutputInteractor) { return createOutputWidget((OutputInteractor) i); } else if (i instanceof RangeInteractor) { return createRangeNumberWidget((RangeInteractor) i); } else if (i instanceof SecretInteractor) { return createInputStringWidget((SecretInteractor) i); } else if (i instanceof Select1Interactor) { return createSelectOneWidget((Select1Interactor) i); } else if (i instanceof TriggerInteractor) { return createTriggerWidget((TriggerInteractor) i); } else if (i instanceof TimedTriggerInteractor) { return createTimedTriggerWidget((TimedTriggerInteractor) i); } else if (i == null) { // do nothing return null; } else { logger.warning("No Text Interface defined for interactor: " + i); return null; } } /** * Builds the UI.For a given session, the method gets all the interactors * and creates a widget and adds it to the session panel. * * @param session * @return returns the session panel object */ public Object buildUI(ClientSession session) { this.socket = session.getSocket(); this.sessionPanel = new SessionPanel(socket, session, this.urc); for (IInteractor i : session.getInteractors()) { Widget w = createWidget(i); if (w == null) continue; else ((TextWidget) w).setSessionPanel(sessionPanel); /* * if (w instanceof TextModalDialog) { ((TextModalDialog) * w).setSessionPanel(sessionPanel); } if (w instanceof TextBoolean) { * ((TextBoolean) w).setSessionPanel(sessionPanel); } */ sessionPanel.add(w); } return sessionPanel; } /* * (non-Javadoc) * * @see edu.wisc.trace.urcsdk.client.IUIBuilder#createGroupWidget(edu.wisc.trace.urcsdk.client.pret.Group) */ public Widget createGroupWidget(Group group) { try { TextGroup sg = new TextGroup(this, group, this.urc); return sg; } catch (UrcException e) { return null; } } /* * (non-Javadoc) * * @see edu.wisc.trace.urcsdk.client.IUIBuilder#createBooleanWidget(edu.wisc.trace.urcsdk.client.pret.BooleanInteractor) */ public Widget createBooleanWidget(BooleanInteractor Boolean) { TextBoolean widget = new TextBoolean(this, Boolean); return widget; } /* * (non-Javadoc) * * @see edu.wisc.trace.urcsdk.client.IUIBuilder#createDateTimeWidget(edu.wisc.trace.urcsdk.client.pret.DateTimeInteractor) */ public Widget createDateTimeWidget(DateTimeInteractor inputTime) { TextDateTime widget = new TextDateTime(this, inputTime, this.urc); return widget; } /* * (non-Javadoc) * * @see edu.wisc.trace.urcsdk.client.IUIBuilder#createTimeWidget(edu.wisc.trace.urcsdk.client.pret.TimeInteractor) */ public Widget createTimeWidget(TimeInteractor inputTime) { TextTime widget = new TextTime(this, inputTime, this.urc); return widget; } /* * (non-Javadoc) * * @see edu.wisc.trace.urcsdk.client.IUIBuilder#createDateWidget(edu.wisc.trace.urcsdk.client.pret.DateInteractor) */ public Widget createDateWidget(DateInteractor inputTime) { TextDate widget = new TextDate(this, inputTime, this.urc); return widget; } /* * (non-Javadoc) * * @see edu.wisc.trace.urcsdk.client.IUIBuilder#createYearWidget(edu.wisc.trace.urcsdk.client.pret.YearInteractor) */ public Widget createYearWidget(YearInteractor inputTime) { TextYear widget = new TextYear(this, inputTime); return widget; } /* * (non-Javadoc) * * @see edu.wisc.trace.urcsdk.client.IUIBuilder#createMonthWidget(edu.wisc.trace.urcsdk.client.pret.MonthInteractor) */ public Widget createMonthWidget(MonthInteractor inputTime) { TextMonth widget = new TextMonth(this, inputTime, this.urc); return widget; } /* * (non-Javadoc) * * @see edu.wisc.trace.urcsdk.client.IUIBuilder#createYearMonthWidget(edu.wisc.trace.urcsdk.client.pret.YearMonthInteractor) */ public Widget createYearMonthWidget(YearMonthInteractor inputTime) { TextYearMonth widget = new TextYearMonth(this, inputTime, this.urc); return widget; } /* * (non-Javadoc) * * @see edu.wisc.trace.urcsdk.client.IUIBuilder#createDecimalWidget(edu.wisc.trace.urcsdk.client.pret.DecimalInteractor) */ public Widget createDecimalWidget(DecimalInteractor decimal) { TextInputNumber widget = new TextInputNumber(this, decimal); return widget; } /* * (non-Javadoc) * * @see edu.wisc.trace.urcsdk.client.IUIBuilder#createDurationWidget(edu.wisc.trace.urcsdk.client.pret.DurationInteractor) */ public Widget createDurationWidget(DurationInteractor inputTime) { return null; // not implemented } /* * (non-Javadoc) * * @see edu.wisc.trace.urcsdk.client.IUIBuilder#createDayWidget(edu.wisc.trace.urcsdk.client.pret.DayInteractor) */ public Widget createDayWidget(DayInteractor inputTime) { TextDay widget = new TextDay(this, inputTime); return widget; } /* * (non-Javadoc) * * @see edu.wisc.trace.urcsdk.client.IUIBuilder#createMonthDayWidget(edu.wisc.trace.urcsdk.client.pret.MonthDayInteractor) */ public Widget createMonthDayWidget(MonthDayInteractor inputTime) { TextMonthDay widget = new TextMonthDay(this, inputTime, this.urc); return widget; } /* * (non-Javadoc) * * @see edu.wisc.trace.urcsdk.client.IUIBuilder#createInputNumberWidget(edu.wisc.trace.urcsdk.client.pret.InputInteractor) */ public Widget createInputNumberWidget(InputInteractor inputNumber) { TextInputNumber w = new TextInputNumber(this, inputNumber); return w; } /* * (non-Javadoc) * * @see edu.wisc.trace.urcsdk.client.IUIBuilder#createInputStringWidget(edu.wisc.trace.urcsdk.client.pret.InputInteractor) */ public Widget createInputStringWidget(InputInteractor inputString) { TextInputString w = new TextInputString(this, inputString, this.urc); return w; } /* * (non-Javadoc) * * @see edu.wisc.trace.urcsdk.client.IUIBuilder#createModalDialogWidget(edu.wisc.trace.urcsdk.client.pret.ModalDialogInteractor) */ public Widget createModalDialogWidget(ModalDialogInteractor modalDialog) { TextModalDialog w = new TextModalDialog(this, modalDialog); return w; } /* * (non-Javadoc) * * @see edu.wisc.trace.urcsdk.client.IUIBuilder#createOutputWidget(edu.wisc.trace.urcsdk.client.pret.OutputInteractor) */ public Widget createOutputWidget(OutputInteractor output) { TextOutput w = new TextOutput(this, output); return w; } /* * (non-Javadoc) * * @see edu.wisc.trace.urcsdk.client.IUIBuilder#createRangeNumberWidget(edu.wisc.trace.urcsdk.client.pret.RangeInteractor) */ public Widget createRangeNumberWidget(RangeInteractor rangeNumber) { TextRange widget = new TextRange(this, rangeNumber); return widget; } /* * (non-Javadoc) * * @see edu.wisc.trace.urcsdk.client.IUIBuilder#createSelectOneWidget(edu.wisc.trace.urcsdk.client.pret.Select1Interactor) */ public Widget createSelectOneWidget(Select1Interactor select1) { TextSelect1 w = new TextSelect1(this, select1); return w; } /* * (non-Javadoc) * * @see edu.wisc.trace.urcsdk.client.IUIBuilder#createTriggerWidget(edu.wisc.trace.urcsdk.client.pret.TriggerInteractor) */ public Widget createTriggerWidget(TriggerInteractor trigger) { TextTrigger w = new TextTrigger(this, trigger); return w; } /* * (non-Javadoc) * * @see edu.wisc.trace.urcsdk.client.IUIBuilder#createTimedTriggerWidget(edu.wisc.trace.urcsdk.client.pret.TimedTriggerInteractor) */ public Widget createTimedTriggerWidget(TimedTriggerInteractor trigger) { TextTimedTrigger w = new TextTimedTrigger(this, trigger); return w; } /** * Gets the client object. */ public GenericClient getUrc() { return urc; } }