/*
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 edu.wisc.trace.urcsdk.support.UserPreferences;
import edu.wisc.trace.urcsdk.base.Constants;
import edu.wisc.trace.urcsdk.client.IInteractor;
import edu.wisc.trace.urcsdk.client.TargetMirror;
import edu.wisc.trace.urcsdk.client.resources.EmptyResource;
import edu.wisc.trace.urcsdk.client.resources.IResource;
import edu.wisc.trace.urcsdk.client.resources.ResourceManager;
import edu.wisc.trace.urcsdk.client.uisocket.ElementRef;
import edu.wisc.trace.urcsdk.client.uisocket.UISocketMirror;
/**
*
* TextOutput is the text implementation of the Output
* interactor. For the sake of simplicity the variable and method regarding read
* are called write and getWriteable.
*
*
*
* Created on:April 19, 2006
* Known bugs: None
* Thread safe: Yes
*
*
* @author Hemanth Vijayan, Trace R&D Center
* @version $Revision: 1.20 $
*
*/
public class TextOutput extends TextWidget {
String label;
boolean write = false;
boolean read;
private SessionPanel sp;
/**
* Creates a textoutput object
*
* @param b
* @param i
*/
public TextOutput(TextUIBuilder b, IInteractor i) {
super(b, i);
this.label = getLabel();
updateResources();
}
/**
* Returns the label and the value in parenthesis.
*/
public String getUIComponent() {
if(this.label.equals("")) label = interactor.getSocketElement().getId();
return label + " (" + interactor.getSocketElement().getValue() + ")";
}
/*
* (non-Javadoc)
* @see edu.wisc.trace.urcsdk.client.Widget#updateResources()
*/
public void updateResources() {
}
/**
* This method adds the session panel to the textOutput object. The reason
* for this is so that it will be able to access whether or not a modal
* dialog has been displayed to the user.
*
* @param sp
* SessionPanel object
*/
public void setSessionPanel(SessionPanel sp) {
this.sp = sp;
}
/*
* (non-Javadoc)
* @see edu.wisc.trace.urcsdk.client.Widget#updateValue()
*/
public void updateValue() {
if (sp != null)
sp.paintSessionPanel();
}
/*
* (non-Javadoc)
* @see edu.wisc.trace.urcsdk.client.Widget#setReadable(boolean)
*/
public void setReadable(boolean read) {
this.read = read;
}
/*
* (non-Javadoc)
* @see edu.wisc.trace.urcsamples.textclient.TextWidget#getReadable()
*/
public boolean getReadable() {
return this.read;
}
/*
* (non-Javadoc)
* @see edu.wisc.trace.urcsdk.client.Widget#setWriteable(boolean)
*/
public void setWriteable(boolean write) {
this.write = write;
}
/*
* (non-Javadoc)
* @see edu.wisc.trace.urcsdk.client.Widget#setExecutable(boolean)
*/
public void setExecutable(boolean execute) {
}
/*
* (non-Javadoc)
* @see edu.wisc.trace.urcsamples.textclient.TextWidget#doChange()
*/
public void doChange() {
}
/**
* Returns the Output string for the interactor.
*
* @return String label.
*/
public String getLabel() {
return getText(Constants.ResourceRole.Label.toString());
}
/*
* (non-Javadoc)
* @see edu.wisc.trace.urcsamples.textclient.TextWidget#getWriteable()
*/
public boolean getWriteable() {
return write;
}
/**
* This method gets the HelpPurpose defined in a resource
* sheet for the output interactor and returns the text in the following
* format. Help-Purpose : (string text)
*
* @return help text.
*/
public String getHelpText() {
String tmp, text = "";
if (!(tmp = getText(Constants.ResourceRole.HelpPurpose.toString()))
.equals("")) {
text = "Help-Purpose: " + tmp;
}
return text;
}
/**
* This method is the base that the getHelpText() and getLabel() call. It
* has a role parameter which passes the desired role to the resource
* manager.
*
* @param role
* @return label/help
*/
private String getText(String role) {
UserPreferences uPrefs = builder.getUrc().getPreferences();
UISocketMirror uis = interactor.getSocketElement().getSocket();
TargetMirror t = uis.getTarget();
ResourceManager rm = t.getResourceManager();
ElementRef elementRef = interactor.getSocketElement().getRef();
String valueRef = interactor.getSocketElement().getValue().toString();
valueRef = (valueRef.equals("")) ? null : valueRef;
IResource label = rm.getResource(elementRef, valueRef, true, null,
role, uPrefs);
if (label == null)
return "";
else if (label instanceof EmptyResource)
return "";
else
return label.getValue().toString();
}
}