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
;
17 import org
.apache
.log4j
.Logger
;
18 import org
.eclipse
.swt
.SWT
;
19 import org
.eclipse
.swt
.browser
.Browser
;
20 import org
.eclipse
.swt
.browser
.ProgressEvent
;
21 import org
.eclipse
.swt
.browser
.ProgressListener
;
22 import org
.eclipse
.swt
.events
.ControlEvent
;
23 import org
.eclipse
.swt
.events
.ControlListener
;
24 import org
.eclipse
.swt
.layout
.GridData
;
25 import org
.eclipse
.swt
.layout
.GridLayout
;
26 import org
.eclipse
.swt
.widgets
.Dialog
;
27 import org
.eclipse
.swt
.widgets
.Display
;
28 import org
.eclipse
.swt
.widgets
.ProgressBar
;
29 import org
.eclipse
.swt
.widgets
.Shell
;
31 import eu
.etaxonomy
.cdm
.ext
.EditGeoService
;
32 import eu
.etaxonomy
.cdm
.model
.description
.Distribution
;
33 import eu
.etaxonomy
.cdm
.model
.description
.PresenceAbsenceTermBase
;
34 import eu
.etaxonomy
.taxeditor
.editor
.AbstractTaxonEditor
;
41 public class DistributionMapDialog
extends Dialog
{
43 private Set
<Distribution
> distributions
;
45 private AbstractTaxonEditor editor
;
47 private Browser browser
;
51 private static final Logger logger
= Logger
52 .getLogger(DistributionMapDialog
.class);
58 public DistributionMapDialog(Shell parent
, int style
) {
60 this.setText("Map Viewer");
66 public DistributionMapDialog(AbstractTaxonEditor editor
, Shell parent
, Set
<Distribution
> distributions
) {
70 this.distributions
= distributions
;
73 public Object
open () {
74 Shell parent
= getParent();
75 shell
= new Shell(parent
, SWT
.DIALOG_TRIM
| SWT
.MAX
| SWT
.RESIZE
| SWT
.APPLICATION_MODAL
);
76 shell
.setText(getText());
78 shell
.setSize(810, 450);
81 // Composite composite = new Composite(shell, SWT.NONE);
83 GridLayout gridLayout
= new GridLayout();
84 gridLayout
.numColumns
= 1;
85 shell
.setLayout(gridLayout
);
87 browser
= new Browser(shell
, SWT
.NONE
);
89 GridData data
= new GridData();
90 data
.horizontalAlignment
= GridData
.FILL
;
91 data
.verticalAlignment
= GridData
.FILL
;
92 data
.grabExcessHorizontalSpace
= true;
93 data
.grabExcessVerticalSpace
= true;
95 browser
.setLayoutData(data
);
98 final ProgressBar progressBar
= new ProgressBar(shell
, SWT
.NONE
);
99 data
= new GridData();
100 data
.horizontalAlignment
= GridData
.END
;
101 progressBar
.setLayoutData(data
);
104 browser
.addProgressListener(new ProgressListener() {
105 public void changed(ProgressEvent event
) {
106 if (event
.total
== 0) return;
107 int ratio
= event
.current
* 100 / event
.total
;
108 progressBar
.setSelection(ratio
);
110 public void completed(ProgressEvent event
) {
111 progressBar
.setSelection(0);
115 shell
.addControlListener(new ControlListener(){
117 public void controlMoved(ControlEvent e
) {
121 public void controlResized(ControlEvent e
) {
130 Display display
= parent
.getDisplay();
131 while (!shell
.isDisposed()) {
132 if (!display
.readAndDispatch()) display
.sleep();
137 private void loadMap(){
138 browser
.setUrl(getMapUrl());
141 private String
getMapUrl(){
142 // FIXME make these hardcoded parameters configurable via preferences
143 String url
= "http://edit.csic.es/v1/areas.php";
144 Map
<PresenceAbsenceTermBase
<?
>,Color
> presenceAbsenceTermColors
= null;
145 int width
= calculateWidth();
147 String bbox
= "-180,-90,180,90";
148 String backLayer
= null;
150 String parameter
= EditGeoService
.getEditGeoServiceUrlParameterString(
152 presenceAbsenceTermColors
,
158 return url
+ "?" + parameter
;
164 private int calculateWidth(){
165 return shell
.getSize().x
- 10;