Difference between revisions of "Adding a Quick tour guide to your portlet"
(→Complete working example) |
|||
Line 114: | Line 114: | ||
== Complete working example == | == Complete working example == | ||
− | The following shows how to create a Quick Guided tour in Java | + | The following shows how to create a Quick Guided tour in Java. '''See it in [http://monitor.d4science.research-infrastructures.eu/guidedtour/ action]''' |
<pre> | <pre> |
Revision as of 20:18, 31 January 2012
Contents
gCube Quick tour guide
gCube Quick tour guide is a customizable dialogBox that can be loaded when your portlet starts up for new users. It is shipped with a built-in clickable option that allows a user to specify to not open it again.
gCube Quick tour guide comes with 12 different themes and is highly customizable. See some available themes in the picture below.
Adding a gCube Quick tour guide to your gCube Portlet Project
- Download the latest jar from here: gcube-quicktour.jar and add it to your build path.
- Add the following to your project .gwt.xml file
<!-- inherits GCUBE Quick tour --> <inherits name='org.gcube.portlets.user.guidedtour.GuidedTour' />
You are ready to use it.
Show Quick tour guide at your portlet startup
In order to load the quick tour at portlet startup create a private (void) method in your GWT EntryPoint class, say you name it showGuidedTour() then you would put showGuidedTour() and the end of your public void onModuleLoad() method.
Customize Quick tour guide for your portlet
Within the showGuidedTour() method you must instanciate the GCUBEGuidedTour class (org.gcube.portlets.user.guidedtour.client.GCUBEGuidedTour)
There are several constructors you can use, allowing you to set its size, its theme, whether you want animation transitions or not and much more. Please refer to documentation to find the one that fits your needs.
As an example, see the code below:
GCUBEGuidedTour gt = new GCUBEGuidedTour( "gCube Framework", /* caption */ MyClass.class.getName(), /* uniqueid (needed for implementing the don'tShowThisAgain feature) */ 700, /* width */ 350, /* height */ false, /* mask (When enabled, the background will be blocked with a semi-transparent panel) */ ThemeColor.MAGENTA /* themeColor */ );
will eventually create the following:
Adding steps to the tour
GCUBEGuidedTour supports templates(GCUBETemplate) for its steps. Although any Composite (com.google.gwt.user.client.ui.Composite) will do, we reccomend to use predefined Templates as shown in the following.
Creating Step from template
There are 3 Templates you can choose from, in each of these three the window is divided in two areas vertically.
- GCUBETemplate1Text1Image:
html | image
- GCUBETemplate1Text2Image:
image html | image
- GCUBETemplate2Text2Image:
html | image html | image
According to the GCUBETemplate you choose for your step you will have to implement some methods, the following example shows how to instanciate a step with a GCUBETemplate1Text1Image as template:
TourStep myFirstStep = new GCUBETemplate1Text1Image(true) { @Override public String setStepTitle() { return "What's gCube"; } @Override public String setStepImage() { //get the image from the web, use relative path to get it from your project return "//www.gcube-system.org/templates/gcube/images/logo-top.gif"; } @Override public String setStepBody() { return "gCube is a framework dedicated to scientists. It enables the declarative and interactive creation of transient Virtual Research Environments" } };
You then need to add the step to the GCUBEGuidedTour instance created previously:
gt.addStep(step1); //the following would set the text vertical alignment (default is TOP) myFirstStep.setTextVerticalAlignment(VerticalAlignment.ALIGN_MIDDLE);
and eventually show the tour on screen
gt.openTour();
Complete working example
The following shows how to create a Quick Guided tour in Java. See it in action
private void showGuidedTour() { TourStep step1 = new GCUBETemplate1Text1Image(true) { @Override public String setStepTitle() { return "From Wikipedia"; } @Override public String setStepImage() { return "//upload.wikimedia.org/wikipedia/commons/thumb/a/a2/Moai_Rano_raraku.jpg/200px-Moai_Rano_raraku.jpg"; } @Override public String setStepBody() { return "Easter Island (Rapa Nui: Rapa Nui, Spanish: Isla de Pascua) is a Polynesian island " + "in the southeastern Pacific Ocean, at the southeasternmost point of the Polynesian triangle. " + "<br /><br />A special territory of Chile that was annexed in 1888, Easter Island is famous for its 887 extant monumental statues, " + "called moai, created by the early Rapanui people. It is a World Heritage Site (as determined by UNESCO) with much " + "of the island protected within Rapa Nui National Park. <br /><br />In recent times the island has served as a warning of the cultural" + " and environmental dangers of overexploitation. Ethnographers and archaeologists also blame diseases carried by European " + "colonizers and slave raiding of the 1860s for devastating the local peoples"+ "<p><b>Easter Island is claimed to be the most remote inhabited island in the world</b></p>"; } }; TourStep step2 = new GCUBETemplate1Text2Image(true) { @Override public String setStepTitle() { return "Name"; } @Override public String setStepImage() { return "//upload.wikimedia.org/wikipedia/commons/thumb/5/50/AhuTongariki.JPG/220px-AhuTongariki.JPG"; } @Override public String setStepOtherImage() { return "//upload.wikimedia.org/wikipedia/commons/thumb/a/a8/Hodges_easter-island.jpg/220px-Hodges_easter-island.jpg"; } @Override public String setStepBody() { return "The name \"Easter Island\" was given by the island's first recorded European visitor, " + "the Dutch explorer Jacob Roggeveen, who encountered it on Easter Sunday 1722, while searching for Davis or David's island. " + "Roggeveen named it Paasch-Eyland (18th century Dutch for \"Easter Island\").[6] " + "The island's official Spanish name, Isla de Pascua, also means \"Easter Island\"." + "<p>The current Polynesian name of the island, <b>Rapa Nui, \"Big Rapa\"</b>, was coined after the slave raids of the early 1860s, " + "and refers to the island's topographic resemblance to the island of Rapa in the Bass Islands of the Austral Islands group." + " However Thor Heyerdahl argued that Rapa was the original name of Easter Island, and that Rapa Iti was named by refugees from there.</p>"; } }; TourStep step3 = new GCUBETemplate2Text2Image(false) { @Override public String setStepTitle() { return "History"; } @Override public String setStepOtherImage() { return "//imageseu.homeaway.com/vd2/files/HR/400x300/2/8495/7540_1321012895481.jpg"; } @Override public String setStepOtherBody() { return "Estimated dates of initial settlement of Easter Island have ranged from 300 to 1200 CE, approximately coinciding with the arrival of " + "the first settlers in Hawaii. Rectifications in radiocarbon dating have changed almost all of the previously-posited early settlement " + "dates in Polynesia. Rapa Nui has more recently been considered to have been settled in the narrower range of 700 to 1100 CE."; } @Override public String setStepImage() { return "//www.archidose.org/Blog/tikopia4.jpg"; } @Override public String setStepBody() { return "The history of Easter Island is rich and controversial. Its inhabitants have endured famines, epidemics, " + "civil war, slave raids, colonialism, and near deforestation; its population declined precipitously more than once." + "However, this hypothesis contradicts radiocarbon dating, according to which other sites preceded Anakena by many years, " + "especially the Tahai, whose radiocarbon dates precede Anakena's by several centuries."; } }; TourStep step4 = new GCUBETemplate1Text1Image(true) { @Override public String setStepTitle() { return "Merchandise"; } @Override public String setStepImage() { return "//rlv.zcache.com/easter_island_tshirt-p235231819274168933ohvp_400.jpg"; } @Override public String setStepBody() { return "<h3>Easter Island Pull Over Sweatshirt</h3><br /><h3>Only Euro 28.55 per shirt <input type=\"button\" value=\"Buy Now!\" onClick=\"Javascript:window.alert('Do you really wanna buy it? That was a joke man!')\"></h3>"; } }; step2.setTextVerticalAlignment(VerticalAlignment.ALIGN_MIDDLE); GCUBEGuidedTour gt = new GCUBEGuidedTour("Easter Island", GuidedTour.class.getName(), 750, 450, false, ThemeColor.AQUAMARINE); gt.addStep(step1); gt.addStep(step2); gt.addStep(step3); gt.addStep(step4); gt.openTour(); }