Commit 2ad67daa authored by Matti Pulkkinen's avatar Matti Pulkkinen
Browse files

extracted layer list population into separate method

parent 5144609b
......@@ -5,6 +5,8 @@ import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.BorderFactory;
import javax.swing.Box;
......@@ -17,9 +19,11 @@ import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
// Kartankatseluohjelman graafinen käyttöliittymä
public class MapDialog extends JFrame {
......@@ -130,18 +134,7 @@ public class MapDialog extends JFrame {
this.leftPanel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
this.leftPanel.setMaximumSize(new Dimension(100, 600));
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder parser = factory.newDocumentBuilder();
Document document = parser.parse(new URL("http://demo.mapserver.org/cgi-bin/"
+ "wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetCapabilities").openStream());
Element mapservice = document.getDocumentElement();
NodeList capabilities = mapservice.getElementsByTagName("Layer");
for (int i = 0; i < capabilities.getLength(); i++) {
Element layer = (Element) capabilities.item(i);
String name = layer.getElementsByTagName("Name").item(0).getTextContent();
String title = layer.getElementsByTagName("Title").item(0).getTextContent();
this.leftPanel.add(new LayerCheckBox(name, title, (i == 0) ? true : false));
}
populateLayerList();
this.leftPanel.add(this.refreshB);
this.leftPanel.add(Box.createVerticalStrut(20));
......@@ -158,6 +151,22 @@ public class MapDialog extends JFrame {
this.setVisible(true);
} // MapDialog()
private void populateLayerList()
throws ParserConfigurationException, SAXException, IOException, MalformedURLException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder parser = factory.newDocumentBuilder();
Document document = parser.parse(new URL("http://demo.mapserver.org/cgi-bin/"
+ "wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetCapabilities").openStream());
Element mapservice = document.getDocumentElement();
NodeList capabilities = mapservice.getElementsByTagName("Layer");
for (int i = 0; i < capabilities.getLength(); i++) {
Element layer = (Element) capabilities.item(i);
String name = layer.getElementsByTagName("Name").item(0).getTextContent();
String title = layer.getElementsByTagName("Title").item(0).getTextContent();
this.leftPanel.add(new LayerCheckBox(name, title, (i == 0) ? true : false));
}
}
// Tarkastetaan mitkä karttakerrokset on valittu,
// tehdään uudesta karttakuvasta pyyntö palvelimelle ja päivitetään kuva
public void updateImage() throws Exception {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment