123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427 |
- /*
- @ITMillApache2LicenseForJavaFiles@
- */
-
- package com.vaadin.ui;
-
- import java.util.Hashtable;
- import java.util.Iterator;
-
- import com.vaadin.terminal.PaintException;
- import com.vaadin.terminal.PaintTarget;
- import com.vaadin.terminal.Resource;
- import com.vaadin.terminal.gwt.client.ui.VEmbedded;
-
- /**
- * Component for embedding external objects.
- *
- * @author IT Mill Ltd.
- * @version
- * @VERSION@
- * @since 3.0
- */
- @SuppressWarnings("serial")
- @ClientWidget(VEmbedded.class)
- public class Embedded extends AbstractComponent {
-
- /**
- * General object type.
- */
- public static final int TYPE_OBJECT = 0;
-
- /**
- * Image types.
- */
- public static final int TYPE_IMAGE = 1;
-
- /**
- * Browser ("iframe") type.
- */
- public static final int TYPE_BROWSER = 2;
-
- /**
- * Type of the object.
- */
- private int type = TYPE_OBJECT;
-
- /**
- * Source of the embedded object.
- */
- private Resource source = null;
-
- /**
- * Generic object attributes.
- */
- private String mimeType = null;
-
- private String standby = null;
-
- /**
- * Hash of object parameteres.
- */
- private final Hashtable parameters = new Hashtable();
-
- /**
- * Applet or other client side runnable properties.
- */
- private String codebase = null;
-
- private String codetype = null;
-
- private String classId = null;
-
- private String archive = null;
-
- /**
- * Creates a new empty Embedded object.
- */
- public Embedded() {
- }
-
- /**
- * Creates a new empty Embedded object with caption.
- *
- * @param caption
- */
- public Embedded(String caption) {
- setCaption(caption);
- }
-
- /**
- * Creates a new Embedded object whose contents is loaded from given
- * resource. The dimensions are assumed if possible. The type is guessed
- * from resource.
- *
- * @param caption
- * @param source
- * the Source of the embedded object.
- */
- public Embedded(String caption, Resource source) {
- setCaption(caption);
- setSource(source);
- }
-
- /**
- * Gets the component UIDL tag.
- *
- * @return the Component UIDL tag as string.
- */
- @Override
- public String getTag() {
- return "embedded";
- }
-
- /**
- * Invoked when the component state should be painted.
- */
- @Override
- public void paintContent(PaintTarget target) throws PaintException {
-
- switch (type) {
- case TYPE_IMAGE:
- target.addAttribute("type", "image");
- break;
- case TYPE_BROWSER:
- target.addAttribute("type", "browser");
- break;
- default:
- break;
- }
-
- if (getSource() != null) {
- target.addAttribute("src", getSource());
- }
-
- if (mimeType != null && !"".equals(mimeType)) {
- target.addAttribute("mimetype", mimeType);
- }
- if (classId != null && !"".equals(classId)) {
- target.addAttribute("classid", classId);
- }
- if (codebase != null && !"".equals(codebase)) {
- target.addAttribute("codebase", codebase);
- }
- if (codetype != null && !"".equals(codetype)) {
- target.addAttribute("codetype", codetype);
- }
- if (standby != null && !"".equals(standby)) {
- target.addAttribute("standby", standby);
- }
- if (archive != null && !"".equals(archive)) {
- target.addAttribute("archive", archive);
- }
-
- // Params
- for (final Iterator i = getParameterNames(); i.hasNext();) {
- target.startTag("embeddedparam");
- final String key = (String) i.next();
- target.addAttribute("name", key);
- target.addAttribute("value", getParameter(key));
- target.endTag("embeddedparam");
- }
- }
-
- /**
- * Sets an object parameter. Parameters are optional information, and they
- * are passed to the instantiated object. Parameters are are stored as name
- * value pairs. This overrides the previous value assigned to this
- * parameter.
- *
- * @param name
- * the name of the parameter.
- * @param value
- * the value of the parameter.
- */
- public void setParameter(String name, String value) {
- parameters.put(name, value);
- requestRepaint();
- }
-
- /**
- * Gets the value of an object parameter. Parameters are optional
- * information, and they are passed to the instantiated object. Parameters
- * are are stored as name value pairs.
- *
- * @return the Value of parameter or null if not found.
- */
- public String getParameter(String name) {
- return (String) parameters.get(name);
- }
-
- /**
- * Removes an object parameter from the list.
- *
- * @param name
- * the name of the parameter to remove.
- */
- public void removeParameter(String name) {
- parameters.remove(name);
- requestRepaint();
- }
-
- /**
- * Gets the embedded object parameter names.
- *
- * @return the Iterator of parameters names.
- */
- public Iterator getParameterNames() {
- return parameters.keySet().iterator();
- }
-
- /**
- * Gets the codebase, the root-path used to access resources with relative
- * paths.
- *
- * @return the code base.
- */
- public String getCodebase() {
- return codebase;
- }
-
- /**
- * Gets the MIME-Type of the code.
- *
- * @return the MIME-Type of the code.
- */
- public String getCodetype() {
- return codetype;
- }
-
- /**
- * Gets the MIME-Type of the object.
- *
- * @return the MIME-Type of the object.
- */
- public String getMimeType() {
- return mimeType;
- }
-
- /**
- * Gets the standby text displayed when the object is loading.
- *
- * @return the standby text.
- */
- public String getStandby() {
- return standby;
- }
-
- /**
- * Sets the codebase, the root-path used to access resources with relative
- * paths.
- *
- * @param codebase
- * the codebase to set.
- */
- public void setCodebase(String codebase) {
- if (codebase != this.codebase
- || (codebase != null && !codebase.equals(this.codebase))) {
- this.codebase = codebase;
- requestRepaint();
- }
- }
-
- /**
- * Sets the codetype, the MIME-Type of the code.
- *
- * @param codetype
- * the codetype to set.
- */
- public void setCodetype(String codetype) {
- if (codetype != this.codetype
- || (codetype != null && !codetype.equals(this.codetype))) {
- this.codetype = codetype;
- requestRepaint();
- }
- }
-
- /**
- * Sets the mimeType, the MIME-Type of the object.
- *
- * @param mimeType
- * the mimeType to set.
- */
- public void setMimeType(String mimeType) {
- if (mimeType != this.mimeType
- || (mimeType != null && !mimeType.equals(this.mimeType))) {
- this.mimeType = mimeType;
- requestRepaint();
- }
- }
-
- /**
- * Sets the standby, the text to display while loading the object.
- *
- * @param standby
- * the standby to set.
- */
- public void setStandby(String standby) {
- if (standby != this.standby
- || (standby != null && !standby.equals(this.standby))) {
- this.standby = standby;
- requestRepaint();
- }
- }
-
- /**
- * Gets the classId attribute.
- *
- * @return the class id.
- */
- public String getClassId() {
- return classId;
- }
-
- /**
- * Sets the classId attribute.
- *
- * @param classId
- * the classId to set.
- */
- public void setClassId(String classId) {
- if (classId != this.classId
- || (classId != null && !classId.equals(classId))) {
- this.classId = classId;
- requestRepaint();
- }
- }
-
- /**
- * Gets the resource contained in the embedded object.
- *
- * @return the Resource
- */
- public Resource getSource() {
- return source;
- }
-
- /**
- * Gets the type of the embedded object.
- * <p>
- * This can be one of the following:
- * <ul>
- * <li>TYPE_OBJECT <i>(This is the default)</i>
- * <li>TYPE_IMAGE
- * </ul>
- * </p>
- *
- * @return the type.
- */
- public int getType() {
- return type;
- }
-
- /**
- * Sets the object source resource. The dimensions are assumed if possible.
- * The type is guessed from resource.
- *
- * @param source
- * the source to set.
- */
- public void setSource(Resource source) {
- if (source != null && !source.equals(this.source)) {
- this.source = source;
- final String mt = source.getMIMEType();
-
- if (mimeType == null) {
- mimeType = mt;
- }
-
- if (mt.equals("image/svg+xml")) {
- type = TYPE_OBJECT;
- } else if ((mt.substring(0, mt.indexOf("/"))
- .equalsIgnoreCase("image"))) {
- type = TYPE_IMAGE;
- } else {
- // Keep previous type
- }
- requestRepaint();
- }
- }
-
- /**
- * Sets the object type.
- * <p>
- * This can be one of the following:
- * <ul>
- * <li>TYPE_OBJECT <i>(This is the default)</i>
- * <li>TYPE_IMAGE
- * </ul>
- * </p>
- *
- * @param type
- * the type to set.
- */
- public void setType(int type) {
- if (type != TYPE_OBJECT && type != TYPE_IMAGE && type != TYPE_BROWSER) {
- throw new IllegalArgumentException("Unsupported type");
- }
- if (type != this.type) {
- this.type = type;
- requestRepaint();
- }
- }
-
- /**
- * Gets the archive attribute.
- *
- * @return the archive attribute.
- */
- public String getArchive() {
- return archive;
- }
-
- /**
- * Sets the archive attribute.
- *
- * @param archive
- * the archive string to set.
- */
- public void setArchive(String archive) {
- if (archive != this.archive
- || (archive != null && !archive.equals(this.archive))) {
- this.archive = archive;
- requestRepaint();
- }
- }
-
- }
|