Project

General

Profile

Download (4.06 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy 
5
* http://www.e-taxonomy.eu
6
* 
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.
9
*/
10

    
11
package eu.etaxonomy.taxeditor.editor.description;
12

    
13
import java.awt.Color;
14
import java.util.Map;
15
import java.util.Set;
16

    
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;
30

    
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;
35

    
36
/**
37
 * @author n.hoffmann
38
 * @created 26.05.2009
39
 * @version 1.0
40
 */
41
public class DistributionMapDialog extends Dialog {
42

    
43
	private Set<Distribution> distributions;
44

    
45
	private AbstractTaxonEditor editor;
46

    
47
	private Browser browser;
48

    
49
	private Shell shell;
50
	
51
	private static final Logger logger = Logger
52
	.getLogger(DistributionMapDialog.class);
53
	
54
	/**
55
	 * @param parent
56
	 * @param style
57
	 */
58
	public DistributionMapDialog(Shell parent, int style) {
59
		super(parent, style);
60
		this.setText("Map Viewer");
61
	}
62
	
63
	/**
64
	 * @param parent
65
	 */
66
	public DistributionMapDialog(AbstractTaxonEditor editor, Shell parent, Set<Distribution> distributions) {
67
		this(parent, 0);
68
		
69
		this.editor = editor;
70
		this.distributions = distributions;
71
	}
72

    
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());
77
		
78
		shell.setSize(810, 450);
79

    
80
		
81
//		Composite composite = new Composite(shell, SWT.NONE);
82
		
83
		GridLayout gridLayout = new GridLayout();
84
		gridLayout.numColumns = 1;
85
		shell.setLayout(gridLayout);
86
		
87
		browser = new Browser(shell, SWT.NONE);
88
		
89
		GridData data = new GridData();
90
		data.horizontalAlignment = GridData.FILL;
91
		data.verticalAlignment = GridData.FILL;
92
		data.grabExcessHorizontalSpace = true;
93
		data.grabExcessVerticalSpace = true;
94
		
95
		browser.setLayoutData(data);
96
		
97
		
98
		final ProgressBar progressBar = new ProgressBar(shell, SWT.NONE);
99
		data = new GridData();
100
		data.horizontalAlignment = GridData.END;
101
		progressBar.setLayoutData(data);
102
		
103

    
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);
109
			}
110
			public void completed(ProgressEvent event) {
111
				progressBar.setSelection(0);
112
			}
113
		});
114
		
115
		shell.addControlListener(new ControlListener(){
116

    
117
			public void controlMoved(ControlEvent e) {
118
				// do nothing
119
			}
120

    
121
			public void controlResized(ControlEvent e) {
122
				loadMap();
123
			}
124
			
125
		});
126
		
127
		shell.open();
128
		loadMap();
129
		
130
		Display display = parent.getDisplay();
131
		while (!shell.isDisposed()) {
132
			if (!display.readAndDispatch()) display.sleep();
133
		}
134
		return null;
135
	}
136
	
137
	private void loadMap(){
138
		browser.setUrl(getMapUrl());
139
	}
140
	
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();
146
		int height = 0; 
147
		String bbox = "-180,-90,180,90"; 
148
		String backLayer = null;
149
		
150
		String parameter = EditGeoService.getEditGeoServiceUrlParameterString(
151
				distributions, 
152
				presenceAbsenceTermColors, 
153
				width, 
154
				height, 
155
				bbox, 
156
				backLayer);
157
		
158
		return url + "?" + parameter;
159
	}
160

    
161
	/**
162
	 * @return
163
	 */
164
	private int calculateWidth(){
165
		return shell.getSize().x - 10;
166
	}
167
}
(9-9/13)