1 |
|
/******************************************************************************* |
2 |
|
* Copyright (c) 2009 Martin O. J. Schmitz. |
3 |
|
* |
4 |
|
* This file is part of the SCHMITZM library - a collection of utility |
5 |
|
* classes based on Java 1.6, focusing (not only) on Java Swing |
6 |
|
* and the Geotools library. |
7 |
|
* |
8 |
|
* The SCHMITZM project is hosted at: |
9 |
|
* http://wald.intevation.org/projects/schmitzm/ |
10 |
|
* |
11 |
|
* This program is free software; you can redistribute it and/or |
12 |
|
* modify it under the terms of the GNU Lesser General Public License |
13 |
|
* as published by the Free Software Foundation; either version 3 |
14 |
|
* of the License, or (at your option) any later version. |
15 |
|
* |
16 |
|
* This program is distributed in the hope that it will be useful, |
17 |
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 |
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19 |
|
* GNU General Public License for more details. |
20 |
|
* |
21 |
|
* You should have received a copy of the GNU Lesser General Public License (license.txt) |
22 |
|
* along with this program; if not, write to the Free Software |
23 |
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
24 |
|
* or try this link: http://www.gnu.org/licenses/lgpl.html |
25 |
|
* |
26 |
|
* Contributors: |
27 |
|
* Martin O. J. Schmitz - initial API and implementation |
28 |
|
* Stefan A. Tzeggai - additional utility classes |
29 |
|
******************************************************************************/ |
30 |
/* |
/* |
31 |
* SearchMapDialog.java |
* SearchMapDialog.java |
32 |
* |
* |
37 |
|
|
38 |
import java.awt.BorderLayout; |
import java.awt.BorderLayout; |
39 |
import java.awt.Cursor; |
import java.awt.Cursor; |
|
import java.awt.FlowLayout; |
|
40 |
import java.awt.Point; |
import java.awt.Point; |
41 |
import java.awt.Window; |
import java.awt.Window; |
42 |
import java.awt.event.KeyAdapter; |
import java.awt.event.KeyAdapter; |
54 |
import javax.swing.ListSelectionModel; |
import javax.swing.ListSelectionModel; |
55 |
import javax.swing.SwingWorker; |
import javax.swing.SwingWorker; |
56 |
|
|
57 |
|
import net.miginfocom.swing.MigLayout; |
58 |
|
|
59 |
import org.apache.log4j.Logger; |
import org.apache.log4j.Logger; |
|
import org.geotools.gui.swing.ExceptionMonitor; |
|
|
import org.geotools.gui.swing.JMapPane; |
|
60 |
|
|
61 |
|
import schmitzm.geotools.gui.SelectableXMapPane; |
62 |
|
import schmitzm.swing.ExceptionDialog; |
63 |
import schmitzm.swing.SortableJTable; |
import schmitzm.swing.SortableJTable; |
64 |
import schmitzm.swing.SwingUtil; |
import schmitzm.swing.SwingUtil; |
|
import skrueger.geotools.labelsearch.LabelSearch; |
|
|
import skrueger.geotools.labelsearch.SearchResult; |
|
65 |
|
|
66 |
/** |
/** |
67 |
* @author Stefan A. Krueger |
* @author Stefan A. Krueger |
83 |
searchTextField.setText(text); |
searchTextField.setText(text); |
84 |
} |
} |
85 |
|
|
86 |
private final JMapPane mapPane; |
private final SelectableXMapPane mapPane; |
87 |
|
|
88 |
/** |
/** |
89 |
* The dialog will be relative to the {@link JMapPane}s parent |
* The dialog will be relative to the {@link SelectableXMapPane}s parent |
90 |
* {@link Window}. |
* {@link Window}. |
91 |
* |
* |
92 |
* @param parent |
* @param parent |
95 |
* @param windowTitle |
* @param windowTitle |
96 |
* A title to be used for the dialog. |
* A title to be used for the dialog. |
97 |
*/ |
*/ |
98 |
public SearchMapDialog(LabelSearch labelSearch, JMapPane mapPane, |
public SearchMapDialog(LabelSearch labelSearch, SelectableXMapPane mapPane, |
99 |
final String windowTitle) { |
final String windowTitle) { |
100 |
super(SwingUtil.getParentWindow(mapPane), windowTitle); |
super(SwingUtil.getParentWindow(mapPane), windowTitle); |
101 |
this.labelSearch = labelSearch; |
this.labelSearch = labelSearch; |
126 |
|
|
127 |
private void initialize() { |
private void initialize() { |
128 |
|
|
129 |
JPanel cp = new JPanel(new BorderLayout()); |
JPanel cp = new JPanel(new MigLayout("wrap 1","[grow]","[][][grow]")); |
130 |
|
|
131 |
JLabel label = new JLabel(LabelSearch.R("SearchMapDialog.searchString.Label")); |
JLabel label = new JLabel(LabelSearch.R("SearchMapDialog.searchString.Label")); |
132 |
label.setLabelFor(searchTextField); |
label.setLabelFor(searchTextField); |
133 |
searchTextField.setToolTipText(LabelSearch.R("SearchMapDialog.searchString.tt")); |
searchTextField.setToolTipText(LabelSearch.R("SearchMapDialog.searchString.tt")); |
|
|
|
134 |
searchTextField.addKeyListener(keyListenerStartSearch); |
searchTextField.addKeyListener(keyListenerStartSearch); |
|
|
|
135 |
// Pressing ESC disposes the Dialog |
// Pressing ESC disposes the Dialog |
136 |
searchTextField.addKeyListener(keyEscDispose); |
searchTextField.addKeyListener(keyEscDispose); |
137 |
|
cp.add(label, "split 2"); |
138 |
|
cp.add(searchTextField); |
139 |
|
|
140 |
|
cp.add(new JLabel(LabelSearch.R("SearchMapDialog.Explanation"))); |
141 |
|
|
142 |
|
cp.add(scrollPane); |
143 |
|
|
|
JPanel upper = new JPanel(new FlowLayout(FlowLayout.LEFT)); |
|
|
upper.add(label); |
|
|
upper.add(searchTextField); |
|
|
|
|
|
cp.add(upper, BorderLayout.NORTH); |
|
|
|
|
|
SwingUtil.setPreferredHeight(scrollPane, 0); |
|
|
SwingUtil.setMaximumHeight(scrollPane, 0); |
|
144 |
cp.add(scrollPane, BorderLayout.SOUTH); |
cp.add(scrollPane, BorderLayout.SOUTH); |
145 |
|
|
146 |
cp.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); |
cp.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); |
157 |
} |
} |
158 |
|
|
159 |
/** |
/** |
160 |
* Performes a search on the {@link JMapPane}'s labels and outputs the |
* Performes a search on the {@link SelectableXMapPane}'s labels and outputs the |
161 |
* possible numerouse results. |
* possible numerouse results. |
162 |
* |
* |
163 |
* @param text |
* @param text |
185 |
showMultipleResults(get()); |
showMultipleResults(get()); |
186 |
} catch (InterruptedException e) { |
} catch (InterruptedException e) { |
187 |
LOGGER.error(e); |
LOGGER.error(e); |
188 |
ExceptionMonitor.show(SearchMapDialog.this, e); |
ExceptionDialog.show(SearchMapDialog.this, e); |
189 |
} catch (ExecutionException e) { |
} catch (ExecutionException e) { |
190 |
LOGGER.error(e); |
LOGGER.error(e); |
191 |
ExceptionMonitor.show(SearchMapDialog.this, e); |
ExceptionDialog.show(SearchMapDialog.this, e); |
192 |
} |
} |
193 |
} |
} |
194 |
}; |
}; |
235 |
pack(); |
pack(); |
236 |
} |
} |
237 |
|
|
|
} |
|
238 |
|
} |