3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
11 package eu
.etaxonomy
.taxeditor
.editor
.description
;
13 import java
.awt
.Color
;
16 import org
.eclipse
.swt
.SWT
;
17 import org
.eclipse
.swt
.browser
.Browser
;
18 import org
.eclipse
.swt
.browser
.ProgressEvent
;
19 import org
.eclipse
.swt
.browser
.ProgressListener
;
20 import org
.eclipse
.swt
.events
.ControlEvent
;
21 import org
.eclipse
.swt
.events
.ControlListener
;
22 import org
.eclipse
.swt
.layout
.GridData
;
23 import org
.eclipse
.swt
.layout
.GridLayout
;
24 import org
.eclipse
.swt
.widgets
.Dialog
;
25 import org
.eclipse
.swt
.widgets
.Display
;
26 import org
.eclipse
.swt
.widgets
.ProgressBar
;
27 import org
.eclipse
.swt
.widgets
.Shell
;
29 import eu
.etaxonomy
.cdm
.ext
.EditGeoService
;
30 import eu
.etaxonomy
.cdm
.ext
.IEditGeoService
;
31 import eu
.etaxonomy
.cdm
.model
.description
.PresenceAbsenceTermBase
;
32 import eu
.etaxonomy
.taxeditor
.editor
.AbstractTaxonEditor
;
39 public class DistributionMapDialog
extends Dialog
{
41 private IEditGeoService geoService
;
43 private AbstractTaxonEditor editor
;
45 private Browser browser
;
53 public DistributionMapDialog(Shell parent
, int style
) {
55 this.setText("Map Viewer");
56 geoService
= new EditGeoService();
62 public DistributionMapDialog(AbstractTaxonEditor editor
, Shell parent
) {
68 public Object
open () {
69 Shell parent
= getParent();
70 shell
= new Shell(parent
, SWT
.DIALOG_TRIM
| SWT
.MAX
| SWT
.RESIZE
| SWT
.APPLICATION_MODAL
);
71 shell
.setText(getText());
73 shell
.setSize(810, 450);
76 // Composite composite = new Composite(shell, SWT.NONE);
78 GridLayout gridLayout
= new GridLayout();
79 gridLayout
.numColumns
= 1;
80 shell
.setLayout(gridLayout
);
82 browser
= new Browser(shell
, SWT
.NONE
);
84 GridData data
= new GridData();
85 data
.horizontalAlignment
= GridData
.FILL
;
86 data
.verticalAlignment
= GridData
.FILL
;
87 data
.grabExcessHorizontalSpace
= true;
88 data
.grabExcessVerticalSpace
= true;
90 browser
.setLayoutData(data
);
93 final ProgressBar progressBar
= new ProgressBar(shell
, SWT
.NONE
);
94 data
= new GridData();
95 data
.horizontalAlignment
= GridData
.END
;
96 progressBar
.setLayoutData(data
);
99 browser
.addProgressListener(new ProgressListener() {
100 public void changed(ProgressEvent event
) {
101 if (event
.total
== 0) return;
102 int ratio
= event
.current
* 100 / event
.total
;
103 progressBar
.setSelection(ratio
);
105 public void completed(ProgressEvent event
) {
106 progressBar
.setSelection(0);
110 shell
.addControlListener(new ControlListener(){
112 public void controlMoved(ControlEvent e
) {
116 public void controlResized(ControlEvent e
) {
125 Display display
= parent
.getDisplay();
126 while (!shell
.isDisposed()) {
127 if (!display
.readAndDispatch()) display
.sleep();
132 private void loadMap(){
133 browser
.setUrl(getMapUrl());
136 private String
getMapUrl(){
137 // FIXME make these hardcoded parameters configurable via preferences
138 String url
= "http://edit.csic.es/v1/areas.php";
139 Map
<PresenceAbsenceTermBase
<?
>,Color
> presenceAbsenceTermColors
= null;
140 int width
= calculateWidth();
142 String bbox
= "-180,-90,180,90";
143 String backLayer
= null;
145 String parameter
= geoService
.getEditGeoServiceUrlParameterString(
147 presenceAbsenceTermColors
,
153 return url
+ "?" + parameter
;
159 private int calculateWidth(){
160 return shell
.getSize().x
- 10;
166 public AbstractTaxonEditor
getEditor() {