001: /*
002: * GWT-Ext Widget Library
003: * Copyright(c) 2007-2008, GWT-Ext.
004: * licensing@gwt-ext.com
005: *
006: * http://www.gwt-ext.com/license
007: */
008: package com.gwtext.sample.showcase2.client.chooser;
009:
010: import com.google.gwt.user.client.Element;
011: import com.gwtext.client.core.DomHelper;
012: import com.gwtext.client.core.EventObject;
013: import com.gwtext.client.core.ExtElement;
014: import com.gwtext.client.data.*;
015: import com.gwtext.client.util.Format;
016: import com.gwtext.client.widgets.Button;
017: import com.gwtext.client.widgets.Panel;
018: import com.gwtext.client.widgets.event.ButtonListenerAdapter;
019: import com.gwtext.client.widgets.layout.VerticalLayout;
020: import com.gwtext.sample.showcase2.client.ShowcasePanel;
021:
022: /**
023: * Example that illustrates simple buttons.
024: */
025: public class ImageChooserSample extends ShowcasePanel {
026:
027: private ImageChooser ic;
028:
029: public Panel getViewPanel() {
030: if (panel == null) {
031: panel = new Panel();
032:
033: Panel verticalPanel = new Panel();
034: verticalPanel.setLayout(new VerticalLayout(20));
035: MemoryProxy dataProxy = new MemoryProxy(getData());
036: RecordDef recordDef = new RecordDef(new FieldDef[] {
037: new StringFieldDef("name"),
038: new IntegerFieldDef("size"),
039: new DateFieldDef("lastmod", "timestamp"),
040: new StringFieldDef("url") });
041: ArrayReader reader = new ArrayReader(recordDef);
042: final Store store = new Store(dataProxy, reader, true);
043: store.load();
044:
045: Button button = new Button("Add Image",
046: new ButtonListenerAdapter() {
047: public void onClick(final Button button,
048: EventObject e) {
049: if (ic == null) {
050: ic = new ImageChooser("Image Chooser",
051: 515, 400, store);
052: }
053:
054: ic.show(new ImageChooserCallback() {
055: public void onImageSelection(
056: ImageData data) {
057: Element el = DomHelper
058: .append(
059: "images",
060: Format
061: .format(
062: "<img src='{0}' style='margin:20px;visibility:hidden;'/>",
063: data
064: .getUrl()));
065: ExtElement extEl = new ExtElement(
066: el);
067: extEl.show(true).frame();
068: button.focus();
069: }
070: });
071: }
072: });
073: button.setIconCls("image-icon");
074:
075: Panel images = new Panel();
076: images.setId("images");
077: images.setBorder(false);
078: images.setMargins(20);
079: images.setWidth(450);
080:
081: verticalPanel.add(button);
082: verticalPanel.add(images);
083:
084: panel.add(verticalPanel);
085: }
086: return panel;
087: }
088:
089: public String getIntro() {
090: return "<p>This example shows loading a DataView in a Window. Each item has a linked details view, and the DataView "
091: + " supports custom sorting and filtering.</p>"
092: + "<p>This example was contributed by <b>Mario Lim</b>";
093: }
094:
095: private Object[][] getData() {
096: return new Object[][] {
097: new Object[] { "Pirates of the Caribbean",
098: new Integer(2120), new Long(1180231870000l),
099: "images/view/carribean.jpg" },
100: new Object[] { "Resident Evil", new Integer(2120),
101: new Long(1180231870000l),
102: "images/view/resident_evil.jpg" },
103: new Object[] { "Blood Diamond", new Integer(2120),
104: new Long(1180231870000l),
105: "images/view/blood_diamond.jpg" },
106: new Object[] { "No Reservations", new Integer(2120),
107: new Long(1180231870000l),
108: "images/view/no_reservations.jpg" },
109: new Object[] { "Casino Royale", new Integer(2120),
110: new Long(1180231870000l),
111: "images/view/casino_royale.jpg" },
112: new Object[] { "Good Shepherd", new Integer(2120),
113: new Long(1180231870000l),
114: "images/view/good_shepherd.jpg" },
115: new Object[] { "Ghost Rider", new Integer(2120),
116: new Long(1180231870000l),
117: "images/view/ghost_rider.jpg" },
118: new Object[] { "Batman Begins", new Integer(2120),
119: new Long(1180231870000l),
120: "images/view/batman_begins.jpg" },
121: new Object[] { "Last Samurai", new Integer(2120),
122: new Long(1180231870000l),
123: "images/view/last_samurai.jpg" },
124: new Object[] { "Italian Job", new Integer(2120),
125: new Long(1180231870000l),
126: "images/view/italian_job.jpg" },
127: new Object[] { "Mission Impossible III",
128: new Integer(2120), new Long(1180231870000l),
129: "images/view/mi3.jpg" },
130: new Object[] { "Mr & Mrs Smith", new Integer(2120),
131: new Long(1180231870000l),
132: "images/view/smith.jpg" },
133: new Object[] { "Inside Man", new Integer(2120),
134: new Long(1180231870000l),
135: "images/view/inside_man.jpg" },
136: new Object[] { "The Island", new Integer(2120),
137: new Long(1180231870000l),
138: "images/view/island.jpg" } };
139: }
140: }
|