Mercurial > hg > STI-GWT
comparison src/econnect/wp3_3/client/core/ApplicationGrid.java @ 3:cf06b77a8bbd
Committed branch of the e4D repos sti-gwt branch 16384.
git-svn-id: http://dev.dariah.eu/svn/repos/eu.dariah.de/ap1/sti-gwt-dariah-geobrowser@36 f2b5be40-def6-11e0-8a09-b3c1cc336c6b
| author | StefanFunk <StefanFunk@f2b5be40-def6-11e0-8a09-b3c1cc336c6b> |
|---|---|
| date | Tue, 17 Jul 2012 13:34:40 +0000 |
| parents | |
| children | 517a6422d1bd |
comparison
equal
deleted
inserted
replaced
| 2:2897af43ccc6 | 3:cf06b77a8bbd |
|---|---|
| 1 package econnect.wp3_3.client.core; | |
| 2 | |
| 3 import java.util.ArrayList; | |
| 4 import java.util.Date; | |
| 5 import java.util.List; | |
| 6 | |
| 7 import com.google.gwt.user.client.rpc.AsyncCallback; | |
| 8 import com.google.gwt.user.client.rpc.ServiceDefTarget; | |
| 9 import com.google.gwt.user.client.ui.Button; | |
| 10 import com.google.gwt.user.client.ui.FileUpload; | |
| 11 import com.google.gwt.user.client.ui.Grid; | |
| 12 import com.google.gwt.user.client.ui.HTML; | |
| 13 import com.google.gwt.user.client.ui.HasHorizontalAlignment; | |
| 14 import com.google.gwt.user.client.ui.HasVerticalAlignment; | |
| 15 import com.google.gwt.user.client.ui.HorizontalPanel; | |
| 16 import com.google.gwt.user.client.ui.Image; | |
| 17 import com.google.gwt.user.client.ui.Label; | |
| 18 import com.google.gwt.user.client.ui.ListBox; | |
| 19 import com.google.gwt.user.client.ui.MenuItem; | |
| 20 import com.google.gwt.user.client.ui.TextBox; | |
| 21 import com.google.gwt.event.dom.client.ChangeEvent; | |
| 22 import com.google.gwt.event.dom.client.ChangeHandler; | |
| 23 import com.google.gwt.event.dom.client.ClickHandler; | |
| 24 import com.google.gwt.event.dom.client.ClickEvent; | |
| 25 import com.google.gwt.event.dom.client.KeyCodes; | |
| 26 import com.google.gwt.event.dom.client.KeyUpEvent; | |
| 27 import com.google.gwt.event.dom.client.KeyUpHandler; | |
| 28 import com.google.gwt.event.logical.shared.ResizeEvent; | |
| 29 import com.google.gwt.event.logical.shared.ResizeHandler; | |
| 30 import com.google.gwt.user.client.Command; | |
| 31 import com.google.gwt.user.client.Window; | |
| 32 import com.google.gwt.core.client.GWT; | |
| 33 import com.google.gwt.core.client.JsArray; | |
| 34 import com.google.gwt.dom.client.DivElement; | |
| 35 import com.google.gwt.dom.client.Document; | |
| 36 import com.google.gwt.dom.client.Element; | |
| 37 import com.google.gwt.dom.client.OptGroupElement; | |
| 38 import com.google.gwt.dom.client.OptionElement; | |
| 39 import com.google.gwt.dom.client.SelectElement; | |
| 40 import com.google.gwt.dom.client.Style.Position; | |
| 41 import com.google.gwt.dom.client.Style.Unit; | |
| 42 import com.google.gwt.dom.client.Style.VerticalAlign; | |
| 43 import com.google.gwt.user.client.ui.MenuBar; | |
| 44 import com.google.gwt.user.client.ui.RootPanel; | |
| 45 | |
| 46 import econnect.wp3_3.client.services.FlickrService; | |
| 47 import econnect.wp3_3.client.services.FlickrServiceAsync; | |
| 48 import econnect.wp3_3.client.widgets.map.Map; | |
| 49 import econnect.wp3_3.client.widgets.table.StiTable; | |
| 50 import econnect.wp3_3.client.widgets.timeplot.Timeplot; | |
| 51 import econnect.wp3_3.shared.DataElement; | |
| 52 | |
| 53 /** | |
| 54 * Implementation of the Main Grid of the application where all widgets except tables will be embedded | |
| 55 */ | |
| 56 public class ApplicationGrid extends Grid { | |
| 57 | |
| 58 /** | |
| 59 * The Java map object | |
| 60 */ | |
| 61 private Map map; | |
| 62 | |
| 63 /** | |
| 64 * The Java timeplot object | |
| 65 */ | |
| 66 private Timeplot plot; | |
| 67 | |
| 68 /** | |
| 69 * The Javascript core object | |
| 70 */ | |
| 71 private StiCore core; | |
| 72 | |
| 73 /** | |
| 74 * The Object that holds the history bar | |
| 75 */ | |
| 76 private MenuBar history; | |
| 77 | |
| 78 /** | |
| 79 * The actual history index | |
| 80 */ | |
| 81 private int historyIndex; | |
| 82 | |
| 83 /** | |
| 84 * The list of history items | |
| 85 */ | |
| 86 private ArrayList<MenuItem> historyItems; | |
| 87 | |
| 88 /** | |
| 89 * The image representing the back button | |
| 90 */ | |
| 91 private Image back; | |
| 92 | |
| 93 /** | |
| 94 * The image representing the forward button | |
| 95 */ | |
| 96 private Image forward; | |
| 97 | |
| 98 /** | |
| 99 * The logo image | |
| 100 */ | |
| 101 private Image logo; | |
| 102 | |
| 103 /** | |
| 104 * The label image for the history | |
| 105 */ | |
| 106 private Image historyLabel; | |
| 107 | |
| 108 private int width; | |
| 109 private Grid links; | |
| 110 | |
| 111 /** | |
| 112 * Constructor for the main grid of the application | |
| 113 * | |
| 114 * @param core object to allow interaction with all javascript components | |
| 115 */ | |
| 116 public ApplicationGrid( StiCore stiCore, StiTable table ){ | |
| 117 | |
| 118 int minWidth = 800; | |
| 119 int minHeight = 600; | |
| 120 int ph = 112; | |
| 121 | |
| 122 int docWidth = Document.get().getClientWidth(); | |
| 123 | |
| 124 int height = (new Double(Document.get().getClientHeight()*0.5+ph)).intValue(); | |
| 125 int width = (new Double(height*4/3)).intValue(); | |
| 126 | |
| 127 if( height < minHeight ){ | |
| 128 height = minHeight; | |
| 129 width = minWidth; | |
| 130 } | |
| 131 | |
| 132 this.width = width; | |
| 133 | |
| 134 this.core = stiCore; | |
| 135 this.historyItems = new ArrayList<MenuItem>(); | |
| 136 this.resize(2,2); | |
| 137 this.setCellSpacing(0); | |
| 138 this.setCellPadding(0); | |
| 139 this.getElement().getStyle().setPosition(Position.ABSOLUTE); | |
| 140 this.getElement().getStyle().setPropertyPx("left", (docWidth-width)/2); | |
| 141 this.getElement().getStyle().setPropertyPx("top", 120-39); | |
| 142 this.getElement().getStyle().setZIndex(1); | |
| 143 this.getCellFormatter().getElement(0,1).setClassName("cellStyleTop"); | |
| 144 this.getCellFormatter().getElement(1,0).setClassName("cellStyleLeft"); | |
| 145 RootPanel.get("mainContainer").add(this); | |
| 146 | |
| 147 final ApplicationConstants constants = (ApplicationConstants) GWT.create(ApplicationConstants.class); | |
| 148 final StiConstants textConstants = (StiConstants) GWT.create(StiConstants.class); | |
| 149 | |
| 150 final Grid headerGrid = new Grid(1,2); | |
| 151 headerGrid.setWidth("100%"); | |
| 152 | |
| 153 ArrayList<String> kmlLabels = new ArrayList<String>(); | |
| 154 ArrayList<Integer> kmlSources = new ArrayList<Integer>(); | |
| 155 ArrayList<Integer> kmlCategories = new ArrayList<Integer>(); | |
| 156 ArrayList<Integer> kmlLocations = new ArrayList<Integer>(); | |
| 157 if( !Window.Location.getParameter("kml1").equals("undefined") ){ | |
| 158 kmlLabels.add(core.hexToAscii(Window.Location.getParameter("kml1"))); | |
| 159 kmlSources.add(new Integer(Window.Location.getParameter("source1"))); | |
| 160 kmlCategories.add(new Integer(-1)); | |
| 161 kmlLocations.add(new Integer(-1)); | |
| 162 } | |
| 163 if( !Window.Location.getParameter("kml2").equals("undefined") ){ | |
| 164 kmlLabels.add(core.hexToAscii(Window.Location.getParameter("kml2"))); | |
| 165 kmlSources.add(new Integer(Window.Location.getParameter("source2"))); | |
| 166 kmlCategories.add(new Integer(-1)); | |
| 167 kmlLocations.add(new Integer(-1)); | |
| 168 } | |
| 169 if( !Window.Location.getParameter("kml3").equals("undefined") ){ | |
| 170 kmlLabels.add(core.hexToAscii(Window.Location.getParameter("kml3"))); | |
| 171 kmlSources.add(new Integer(Window.Location.getParameter("source3"))); | |
| 172 kmlCategories.add(new Integer(-1)); | |
| 173 kmlLocations.add(new Integer(-1)); | |
| 174 } | |
| 175 if( !Window.Location.getParameter("kml4").equals("undefined") ){ | |
| 176 kmlLabels.add(core.hexToAscii(Window.Location.getParameter("kml4"))); | |
| 177 kmlSources.add(new Integer(Window.Location.getParameter("source4"))); | |
| 178 kmlCategories.add(new Integer(-1)); | |
| 179 kmlLocations.add(new Integer(-1)); | |
| 180 } | |
| 181 int sources = core.getDatasources(); | |
| 182 if( sources > 0 ){ | |
| 183 final TextBox searchField = new TextBox(); | |
| 184 final Image searchButton = new Image(constants.openImage()); | |
| 185 searchButton.getElement().addClassName("vCenter"); | |
| 186 final ListBox datasource = new ListBox(false); | |
| 187 final List<ListBox> staticListBoxes = new ArrayList<ListBox>(); | |
| 188 final ArrayList<ArrayList<int[]>> entries = new ArrayList<ArrayList<int[]>>(); | |
| 189 for( int i=0; i<sources; i++ ){ | |
| 190 try { | |
| 191 if( core.hasItems(i) ){ | |
| 192 try { | |
| 193 ListBox staticData = new ListBox(); | |
| 194 SelectElement select = staticData.getElement().cast(); | |
| 195 OptionElement blank = Document.get().createOptionElement(); | |
| 196 blank.setInnerText("select set ..."); | |
| 197 select.appendChild(blank); | |
| 198 int categories = core.getCategories(i); | |
| 199 ArrayList<int[]> values = new ArrayList<int[]>(); | |
| 200 for( int j=0; j<categories; j++ ){ | |
| 201 try { | |
| 202 OptGroupElement group = Document.get().createOptGroupElement(); | |
| 203 group.setLabel(core.getCategory(i,j)); | |
| 204 for (int k=0; k<core.getItemCount(i,j); k++) { | |
| 205 OptionElement optElement = Document.get().createOptionElement(); | |
| 206 optElement.setInnerText(core.getLabel(i,j,k)); | |
| 207 for( int l=0; l<kmlLabels.size(); l++ ){ | |
| 208 if( kmlLabels.get(l).equals(core.getLabel(i,j,k)) ){ | |
| 209 kmlCategories.set(l,new Integer(j)); | |
| 210 kmlLocations.set(l,new Integer(k)); | |
| 211 } | |
| 212 } | |
| 213 group.appendChild(optElement); | |
| 214 int[] pair = {j,k}; | |
| 215 values.add(pair); | |
| 216 } | |
| 217 select.appendChild(group); | |
| 218 } | |
| 219 catch( Exception e ){ | |
| 220 continue; | |
| 221 } | |
| 222 } | |
| 223 entries.add(values); | |
| 224 staticListBoxes.add(staticData); | |
| 225 } | |
| 226 catch( Exception e ){ | |
| 227 continue; | |
| 228 } | |
| 229 } | |
| 230 else { | |
| 231 entries.add(null); | |
| 232 staticListBoxes.add(null); | |
| 233 } | |
| 234 datasource.addItem(core.getDatasourceLabel(i)); | |
| 235 } | |
| 236 catch( Exception e ){ | |
| 237 continue; | |
| 238 } | |
| 239 } | |
| 240 | |
| 241 if( datasource.getItemCount() > 0 ){ | |
| 242 final Grid searchPanel = new Grid(1,3); | |
| 243 searchPanel.setWidget(0, 0, datasource); | |
| 244 if( staticListBoxes.get(0) == null ){ | |
| 245 searchPanel.setWidget(0, 1, searchField); | |
| 246 } | |
| 247 else { | |
| 248 searchPanel.setWidget(0, 1, staticListBoxes.get(0)); | |
| 249 } | |
| 250 searchPanel.setWidget(0, 2, searchButton); | |
| 251 searchPanel.addStyleName("center"); | |
| 252 headerGrid.setWidget(0, 0, searchPanel); | |
| 253 | |
| 254 datasource.addChangeHandler(new ChangeHandler() { | |
| 255 public void onChange(ChangeEvent event) { | |
| 256 int ds = datasource.getSelectedIndex(); | |
| 257 if( ds == -1 ){ | |
| 258 return; | |
| 259 } | |
| 260 if( staticListBoxes.get(ds) == null ){ | |
| 261 searchPanel.setWidget(0, 1, searchField); | |
| 262 } | |
| 263 else { | |
| 264 searchPanel.setWidget(0, 1, staticListBoxes.get(ds)); | |
| 265 } | |
| 266 } | |
| 267 }); | |
| 268 | |
| 269 class LoadDataHandler implements ClickHandler, KeyUpHandler { | |
| 270 public void onClick(ClickEvent event) { | |
| 271 searchButton.setUrl(constants.openDisabledImage()); | |
| 272 loadData(); | |
| 273 } | |
| 274 public void onKeyUp(KeyUpEvent event) { | |
| 275 if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) { | |
| 276 searchButton.setUrl(constants.openDisabledImage()); | |
| 277 loadData(); | |
| 278 } | |
| 279 } | |
| 280 private void loadData() { | |
| 281 int ds = datasource.getSelectedIndex(); | |
| 282 if( core.isMaximumReached() ){ | |
| 283 core.alert(textConstants.maxDatasources()); | |
| 284 } | |
| 285 else if( staticListBoxes.get(ds) != null ){ | |
| 286 if( staticListBoxes.get(ds).getSelectedIndex() > 0 ){ | |
| 287 int[] pair = entries.get(ds).get(staticListBoxes.get(ds).getSelectedIndex() - 1); | |
| 288 core.openStaticKml(ds,pair[0],pair[1]); | |
| 289 } | |
| 290 } | |
| 291 else if( !searchField.getText().equals("") ){ | |
| 292 core.openDynamicKml( ds, searchField.getText() ); | |
| 293 } | |
| 294 searchButton.setUrl(constants.openImage()); | |
| 295 } | |
| 296 } | |
| 297 | |
| 298 LoadDataHandler handler = new LoadDataHandler(); | |
| 299 searchButton.addClickHandler(handler); | |
| 300 searchField.addKeyUpHandler(handler); | |
| 301 } | |
| 302 | |
| 303 } | |
| 304 | |
| 305 Grid historyGrid = new Grid(1,3); | |
| 306 historyLabel = new Image(constants.historyImage()); | |
| 307 | |
| 308 history = new MenuBar(true); | |
| 309 history.setAnimationEnabled(true); | |
| 310 history.addStyleName("zHigh"); | |
| 311 addHistoryItem(0); | |
| 312 historyGrid.setWidget(0, 1, historyLabel); | |
| 313 headerGrid.setWidget(0, 1, historyGrid); | |
| 314 | |
| 315 historyLabel.setTitle(textConstants.history()); | |
| 316 historyLabel.addClickHandler(new ClickHandler() { | |
| 317 public void onClick(ClickEvent event) { | |
| 318 if( !RootPanel.get().remove(history) ){ | |
| 319 RootPanel.get().add(history,0,0); | |
| 320 historyLabel.setUrl(constants.historyOverImage()); | |
| 321 int left = historyLabel.getAbsoluteLeft() + historyLabel.getOffsetWidth()/2 - history.getOffsetWidth()/2; | |
| 322 int top = historyLabel.getAbsoluteTop() + historyLabel.getOffsetHeight(); | |
| 323 RootPanel.get().setWidgetPosition(history,left,top); | |
| 324 } | |
| 325 else { | |
| 326 historyLabel.setUrl(constants.historyImage()); | |
| 327 } | |
| 328 } | |
| 329 }); | |
| 330 historyLabel.getElement().addClassName("vCenter"); | |
| 331 | |
| 332 headerGrid.getCellFormatter().setHorizontalAlignment(0,0,HasHorizontalAlignment.ALIGN_LEFT); | |
| 333 headerGrid.getCellFormatter().setHorizontalAlignment(0,1,HasHorizontalAlignment.ALIGN_RIGHT); | |
| 334 | |
| 335 back = new Image(constants.backwardDisabledImage()); | |
| 336 back.getElement().addClassName("vCenter"); | |
| 337 back.setTitle(textConstants.back()); | |
| 338 forward = new Image(constants.forwardDisabledImage()); | |
| 339 forward.getElement().addClassName("vCenter"); | |
| 340 forward.setTitle(textConstants.forward()); | |
| 341 historyGrid.setWidget(0, 0, back); | |
| 342 historyGrid.setWidget(0, 2, forward); | |
| 343 | |
| 344 back.addClickHandler(new ClickHandler() { | |
| 345 public void onClick(ClickEvent event) { | |
| 346 if( historyIndex > 0 ){ | |
| 347 core.switchThroughHistory(historyIndex-1); | |
| 348 historyIndex--; | |
| 349 setHistoryStyle(historyIndex+1,historyIndex); | |
| 350 } | |
| 351 } | |
| 352 }); | |
| 353 | |
| 354 forward.addClickHandler(new ClickHandler() { | |
| 355 public void onClick(ClickEvent event) { | |
| 356 if( historyIndex < core.getHistoryLength()-1 ){ | |
| 357 core.switchThroughHistory(historyIndex+1); | |
| 358 historyIndex++; | |
| 359 setHistoryStyle(historyIndex-1,historyIndex); | |
| 360 } | |
| 361 } | |
| 362 }); | |
| 363 | |
| 364 this.setWidget(0, 1, headerGrid); | |
| 365 | |
| 366 Grid widgets = new Grid(2,1); | |
| 367 this.setWidget(1, 1, widgets); | |
| 368 widgets.setCellPadding(0); | |
| 369 widgets.setCellSpacing(0); | |
| 370 | |
| 371 DivElement mapWindow = Document.get().createDivElement(); | |
| 372 mapWindow.setId("mapWindow"); | |
| 373 mapWindow.setClassName("mapWindow"); | |
| 374 mapWindow.getStyle().setPropertyPx("height", height-ph); | |
| 375 mapWindow.getStyle().setPropertyPx("width", width); | |
| 376 mapWindow.getStyle().setProperty("position", "relative"); | |
| 377 DivElement mapDiv = Document.get().createDivElement(); | |
| 378 mapDiv.setId("map"); | |
| 379 mapDiv.getStyle().setPropertyPx("height", height-ph); | |
| 380 mapDiv.getStyle().setPropertyPx("width", width); | |
| 381 mapDiv.getStyle().setProperty("position", "absolute"); | |
| 382 mapWindow.appendChild(mapDiv); | |
| 383 widgets.getCellFormatter().getElement(0,0).setInnerHTML(mapWindow.getString()); | |
| 384 this.map = new Map(core,"mapWindow","map"); | |
| 385 | |
| 386 DivElement plotWindow = Document.get().createDivElement(); | |
| 387 plotWindow.setId("plotWindow"); | |
| 388 plotWindow.getStyle().setPropertyPx("width", width); | |
| 389 plotWindow.getStyle().setPropertyPx("height", ph); | |
| 390 DivElement plotDiv = Document.get().createDivElement(); | |
| 391 plotDiv.setId("plot"); | |
| 392 plotDiv.getStyle().setPropertyPx("width", width); | |
| 393 plotWindow.appendChild(plotDiv); | |
| 394 widgets.getCellFormatter().getElement(1,0).setInnerHTML(plotWindow.getString()); | |
| 395 this.plot = new Timeplot(core,"plotWindow","plot"); | |
| 396 | |
| 397 final Grid controls = new Grid(4,1); | |
| 398 controls.setCellSpacing(0); | |
| 399 controls.setCellPadding(0); | |
| 400 controls.addStyleName("center"); | |
| 401 controls.setWidth("100%"); | |
| 402 | |
| 403 final Image mapControl = new Image(constants.globeImage()); | |
| 404 mapControl.setTitle(textConstants.mapControls()); | |
| 405 controls.setWidget(0, 0, mapControl); | |
| 406 | |
| 407 final Image plotControl = new Image(constants.timeImage()); | |
| 408 plotControl.setTitle(textConstants.plotControls()); | |
| 409 controls.setWidget(3, 0, plotControl); | |
| 410 | |
| 411 final Grid plotControls = this.plot.initPlotControls(); | |
| 412 final Grid mapControls = this.map.initMapControls(); | |
| 413 | |
| 414 controls.setWidget(1, 0, mapControls); | |
| 415 controls.setWidget(2, 0, plotControls); | |
| 416 | |
| 417 controls.getCellFormatter().getElement(0,0).getStyle().setHeight(25,Unit.PX); | |
| 418 controls.getCellFormatter().getElement(1,0).getStyle().setVerticalAlign(VerticalAlign.TOP); | |
| 419 controls.getCellFormatter().getElement(2,0).getStyle().setVerticalAlign(VerticalAlign.BOTTOM); | |
| 420 controls.getCellFormatter().getElement(3,0).getStyle().setHeight(25,Unit.PX); | |
| 421 | |
| 422 this.setWidget(1,0,controls); | |
| 423 controls.setSize("100%",height+"px"); | |
| 424 | |
| 425 this.logo = new Image(constants.logoImage()); | |
| 426 this.logo.addStyleName("logo"); | |
| 427 RootPanel.get().add(this.logo); | |
| 428 RootPanel.get().setWidgetPosition(this.logo,(docWidth-width)/2-40,8); | |
| 429 | |
| 430 Grid linkList = new Grid(1,7); | |
| 431 HTML informationLink = new HTML(" Information"); | |
| 432 informationLink.setTitle("Information"); | |
| 433 informationLink.addClickHandler(new ClickHandler(){ | |
| 434 public void onClick(ClickEvent event) { | |
| 435 Window.open("http://wp1187670.wp212.webpack.hosteurope.de/e4d/?page_id=2", "_blank", ""); | |
| 436 } | |
| 437 }); | |
| 438 informationLink.setStyleName("headerLink"); | |
| 439 linkList.setWidget(0, 0, informationLink); | |
| 440 HTML helpLink = new HTML(" Help"); | |
| 441 helpLink.setTitle("Help"); | |
| 442 helpLink.addClickHandler(new ClickHandler(){ | |
| 443 public void onClick(ClickEvent event) { | |
| 444 Window.open("http://wp1187670.wp212.webpack.hosteurope.de/e4d/?page_id=23", "_blank", ""); | |
| 445 } | |
| 446 }); | |
| 447 helpLink.setStyleName("headerLink"); | |
| 448 linkList.setWidget(0, 1, helpLink); | |
| 449 HTML contactLink = new HTML(" Contact"); | |
| 450 contactLink.setTitle("Contact"); | |
| 451 contactLink.addClickHandler(new ClickHandler(){ | |
| 452 public void onClick(ClickEvent event) { | |
| 453 Window.open("http://wp1187670.wp212.webpack.hosteurope.de/e4d/?page_id=4", "_blank", ""); | |
| 454 } | |
| 455 }); | |
| 456 contactLink.setStyleName("headerLink"); | |
| 457 linkList.setWidget(0, 2, contactLink); | |
| 458 HTML clearLink = new HTML(" Clear Data"); | |
| 459 clearLink.setTitle("Clear Data"); | |
| 460 clearLink.addClickHandler(new ClickHandler(){ | |
| 461 public void onClick(ClickEvent event) { | |
| 462 Window.Location.assign(Window.Location.getHref()); | |
| 463 } | |
| 464 }); | |
| 465 clearLink.setStyleName("headerLink"); | |
| 466 linkList.setWidget(0, 3, clearLink); | |
| 467 HTML uploadLink = new HTML(" Upload Data"); | |
| 468 uploadLink.setTitle("Upload Data"); | |
| 469 uploadLink.setStyleName("headerLink"); | |
| 470 uploadLink.addClickHandler(new ClickHandler(){ | |
| 471 public void onClick(ClickEvent event) { | |
| 472 Window.open("http://wp1187670.wp212.webpack.hosteurope.de/e4d/?page_id=11", "_blank", ""); | |
| 473 } | |
| 474 }); | |
| 475 linkList.setWidget(0, 4, uploadLink); | |
| 476 ClickHandler magneticClick = new ClickHandler(){ | |
| 477 public void onClick(ClickEvent event) { | |
| 478 if( core.getDataSets().length() > 0 ){ | |
| 479 String link = Window.Location.getHref() + "?"; | |
| 480 for( int i=0; i<core.getDataSets().length(); i++ ){ | |
| 481 if( i>0 ){ | |
| 482 link += "\n&"; | |
| 483 } | |
| 484 String name = core.getDataSets().get(i).getTermIdentifier(); | |
| 485 link += "kml"+(i+1)+"="+core.asciiToHex(name); | |
| 486 link += "&source"+(i+1)+"="+core.getDataSets().get(i).getSource(); | |
| 487 } | |
| 488 link += "\n&minTime=" + plot.getJsTimeplot().minTime(); | |
| 489 link += "&maxTime=" + plot.getJsTimeplot().maxTime(); | |
| 490 if( plot.getJsTimeplot().minSelTime() != null ){ | |
| 491 link += "\n&minSelTime=" + plot.getJsTimeplot().minSelTime(); | |
| 492 link += "&maxSelTime=" + plot.getJsTimeplot().maxSelTime(); | |
| 493 } | |
| 494 link += "\n&mapId=" + map.getJsMap().baseLayerIndex(); | |
| 495 link += "&zoom=" + map.getJsMap().getZoom(); | |
| 496 link += "¢erLon=" + map.getJsMap().centerLon(); | |
| 497 link += "¢erLat=" + map.getJsMap().centerLat(); | |
| 498 link += "&connections=" + map.getJsMap().getConnections(); | |
| 499 Window.open(link,"_blank",""); | |
| 500 core.alert("e4D Magnetic Link opened in new tab!\n(Currently considered are: loaded datasets, map settings, temporal range, temporal selection)\n\n"+link); | |
| 501 } | |
| 502 else { | |
| 503 core.alert("Link could not be created; no datasets available."); | |
| 504 } | |
| 505 } | |
| 506 }; | |
| 507 | |
| 508 HTML magneticLink = new HTML(" Magnetic Link"); | |
| 509 magneticLink.setStyleName("headerLink"); | |
| 510 magneticLink.addClickHandler(magneticClick); | |
| 511 linkList.setWidget(0, 5, magneticLink); | |
| 512 | |
| 513 Image link = new Image(constants.linkImage()); | |
| 514 link.addStyleName("link"); | |
| 515 link.setTitle("Create Magnetic Link"); | |
| 516 linkList.setWidget(0, 6, link); | |
| 517 | |
| 518 linkList.getElement().getStyle().setPosition(Position.ABSOLUTE); | |
| 519 linkList.getElement().getStyle().setPropertyPx("left", 0); | |
| 520 linkList.getElement().getStyle().setPropertyPx("top", 0); | |
| 521 RootPanel.get().add(linkList); | |
| 522 int left = this.getElement().getOffsetLeft() + this.getElement().getOffsetWidth() - linkList.getElement().getOffsetWidth(); | |
| 523 RootPanel.get().setWidgetPosition(linkList,left,0); | |
| 524 this.links = linkList; | |
| 525 | |
| 526 link.addClickHandler(magneticClick); | |
| 527 | |
| 528 core.setElements( this.getMap().getJsMap(), this.getPlot().getJsTimeplot() ); | |
| 529 StiCore.exportStaticMethods(table,this,this.getPlot(),this.getMap()); | |
| 530 | |
| 531 table.setTop( this.getElement().getOffsetTop() + this.getElement().getOffsetHeight() + 40 ); | |
| 532 | |
| 533 for( int i=0; i<kmlLabels.size(); i++ ){ | |
| 534 if( kmlSources.get(i).intValue() == 0 && kmlCategories.get(i) > -1 ){ | |
| 535 core.openStaticKml(kmlSources.get(i), kmlCategories.get(i), kmlLocations.get(i)); | |
| 536 } | |
| 537 else if( kmlSources.get(i).intValue() < 4 ){ | |
| 538 core.openDynamicKml(kmlSources.get(i),kmlLabels.get(i)); | |
| 539 } | |
| 540 else { | |
| 541 core.alert("Unable to load \""+kmlLabels.get(i)+"\"!"); | |
| 542 } | |
| 543 } | |
| 544 | |
| 545 } | |
| 546 | |
| 547 public void setDefinedBounds(){ | |
| 548 int zoom = 0; | |
| 549 float cLon = 0, cLat = 0; | |
| 550 int mapId = 0; | |
| 551 if( !Window.Location.getParameter("zoom").equals("undefined") ){ | |
| 552 zoom = new Integer(Window.Location.getParameter("zoom")).intValue(); | |
| 553 } | |
| 554 if( !Window.Location.getParameter("centerLon").equals("undefined") ){ | |
| 555 cLon = new Float(Window.Location.getParameter("centerLon")).floatValue(); | |
| 556 } | |
| 557 if( !Window.Location.getParameter("centerLat").equals("undefined") ){ | |
| 558 cLat = new Float(Window.Location.getParameter("centerLat")).floatValue(); | |
| 559 } | |
| 560 if( !Window.Location.getParameter("mapId").equals("undefined") ){ | |
| 561 mapId = new Integer(Window.Location.getParameter("mapId")).intValue(); | |
| 562 } | |
| 563 if( zoom != 0 || cLon != 0 || cLat != 0 || mapId != 0 ){ | |
| 564 this.getMap().getJsMap().configure(zoom, cLon, cLat, mapId); | |
| 565 } | |
| 566 String minSelTime = null, maxSelTime = null; | |
| 567 if( !Window.Location.getParameter("minSelTime").equals("undefined") ){ | |
| 568 minSelTime = Window.Location.getParameter("minSelTime"); | |
| 569 } | |
| 570 if( !Window.Location.getParameter("maxSelTime").equals("undefined") ){ | |
| 571 maxSelTime = Window.Location.getParameter("maxSelTime"); | |
| 572 } | |
| 573 if( minSelTime != null && maxSelTime != null ){ | |
| 574 this.getPlot().getJsTimeplot().selectTimerange(minSelTime,maxSelTime); | |
| 575 } | |
| 576 if( !Window.Location.getParameter("connections").equals("undefined") ){ | |
| 577 int connections = new Integer(Window.Location.getParameter("connections")).intValue(); | |
| 578 if( connections == 1 ){ | |
| 579 this.getMap().getJsMap().setConnections(connections); | |
| 580 this.getMap().setConImage(true); | |
| 581 } | |
| 582 } | |
| 583 String minTime = null, maxTime = null; | |
| 584 if( !Window.Location.getParameter("minTime").equals("undefined") ){ | |
| 585 minTime = Window.Location.getParameter("minTime"); | |
| 586 } | |
| 587 if( !Window.Location.getParameter("maxTime").equals("undefined") ){ | |
| 588 maxTime = Window.Location.getParameter("maxTime"); | |
| 589 } | |
| 590 if( minTime != null && maxTime != null ){ | |
| 591 this.core.refineByTime(minTime,maxTime); | |
| 592 } | |
| 593 } | |
| 594 /* | |
| 595 public String asciiToHex(String text){ | |
| 596 String[] ascii = { "!","#","$","%","&","'","(",")","*","+",",","/",":",";","=","?","@","[","]", " " }; | |
| 597 String[] hex = { "%21","%23","%24","$","%26","%27","%28","%29","%2a","%2b","%2c","%2f","%3a","%3b","%3d","%3f","%40","%5b","%5d","%20"}; | |
| 598 for( int i=0; i<ascii.length; i++ ){ | |
| 599 text = text.replaceAll(ascii[i],hex[i]); | |
| 600 } | |
| 601 text = text.replaceAll("$","%25"); | |
| 602 return text; | |
| 603 } | |
| 604 | |
| 605 public String hexToAscii(String text){ | |
| 606 String[] ascii = { "!","#","$","%","&","'","(",")","*","+",",","/",":",";","=","?","@","[","]", " " }; | |
| 607 String[] hex = { "%21","%23","%24","%25","%26","%27","%28","%29","%2a","%2b","%2c","%2f","%3a","%3b","%3d","%3f","%40","%5b","%5d","%20"}; | |
| 608 for( int i=0; i<ascii.length; i++ ){ | |
| 609 text = text.replaceAll(hex[i],ascii[i]); | |
| 610 } | |
| 611 return text; | |
| 612 } | |
| 613 */ | |
| 614 public void resize(){ | |
| 615 int w = Document.get().getClientWidth(); | |
| 616 RootPanel.get().setWidgetPosition(this.logo,(w-width)/2-40,8); | |
| 617 RootPanel.get("mainContainer").setWidgetPosition(this,(w-width)/2,120-39); | |
| 618 int left = this.getElement().getOffsetLeft() + this.getElement().getOffsetWidth() - this.links.getElement().getOffsetWidth(); | |
| 619 RootPanel.get().setWidgetPosition(this.links,left,0); | |
| 620 } | |
| 621 | |
| 622 /** | |
| 623 * Sets the style of the history panel | |
| 624 * | |
| 625 * @param oldIndex last active history entry | |
| 626 * @param newIndex actual active history entry | |
| 627 */ | |
| 628 public void setHistoryStyle( int oldIndex, int newIndex ){ | |
| 629 final ApplicationConstants constants = (ApplicationConstants) GWT.create(ApplicationConstants.class); | |
| 630 if( oldIndex == -1 ){ | |
| 631 oldIndex = historyIndex; | |
| 632 } | |
| 633 if( newIndex == core.getHistoryLength()-1 ){ | |
| 634 forward.setUrl(constants.forwardDisabledImage()); | |
| 635 } | |
| 636 else { | |
| 637 forward.setUrl(constants.forwardImage()); | |
| 638 } | |
| 639 if( newIndex == 0 ){ | |
| 640 back.setUrl(constants.backwardDisabledImage()); | |
| 641 } | |
| 642 else { | |
| 643 back.setUrl(constants.backwardImage()); | |
| 644 } | |
| 645 MenuItem oldItem = (MenuItem) historyItems.get(oldIndex); | |
| 646 oldItem.setHTML( oldItem.getHTML().replaceFirst("bold","normal") ); | |
| 647 MenuItem newItem = (MenuItem) historyItems.get(newIndex); | |
| 648 newItem.setHTML( newItem.getHTML().replaceFirst("normal","bold") ); | |
| 649 } | |
| 650 | |
| 651 /** | |
| 652 * Adds an item to the history panel | |
| 653 * | |
| 654 * @param index index in the corresponding javascript array source | |
| 655 */ | |
| 656 public void addHistoryItem( final int index ){ | |
| 657 final ApplicationConstants constants = (ApplicationConstants) GWT.create(ApplicationConstants.class); | |
| 658 for( int i=historyItems.size(); i>index; i-- ){ | |
| 659 this.history.removeItem( (MenuItem) historyItems.get(i-1) ); | |
| 660 this.historyItems.remove(i-1); | |
| 661 } | |
| 662 String text = "<span style='font-weight:bold;'>"; | |
| 663 JsArray<DataSet> sets = core.getHistoryDataSets(index); | |
| 664 for( int j=0; j<sets.length(); j++ ){ | |
| 665 DataSet set = sets.get(j); | |
| 666 text += set.getTermIdentifier(); | |
| 667 if( j+1 < sets.length() ){ | |
| 668 text += ", "; | |
| 669 } | |
| 670 } | |
| 671 if( text.equals("<span style='font-weight:bold;'>") ){ | |
| 672 text += "empty"; | |
| 673 } | |
| 674 else { | |
| 675 text += " ("+(new Date()).toString()+")"; | |
| 676 } | |
| 677 text += "</span>"; | |
| 678 MenuItem item = new MenuItem(text,true,new Command() { | |
| 679 public void execute() { | |
| 680 core.switchThroughHistory(index); | |
| 681 setHistoryStyle(-1,index); | |
| 682 historyIndex = index; | |
| 683 RootPanel.get().remove(history); | |
| 684 historyLabel.setUrl(constants.historyImage()); | |
| 685 } | |
| 686 }); | |
| 687 historyItems.add(item); | |
| 688 this.history.addItem(item); | |
| 689 historyIndex = index; | |
| 690 if( index > 0 ){ | |
| 691 setHistoryStyle(index-1,index); | |
| 692 } | |
| 693 } | |
| 694 | |
| 695 /** | |
| 696 * Getter for the Java timeplot element | |
| 697 * | |
| 698 * @return the Java timeplot element | |
| 699 */ | |
| 700 public Timeplot getPlot(){ | |
| 701 return this.plot; | |
| 702 } | |
| 703 | |
| 704 /** | |
| 705 * Getter for the Java map element | |
| 706 * | |
| 707 * @return the Java map element | |
| 708 */ | |
| 709 public Map getMap(){ | |
| 710 return this.map; | |
| 711 } | |
| 712 | |
| 713 } |
