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

added automatic image resizing to fit the window

parent ebeca0cc
......@@ -5,6 +5,8 @@ import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
......@@ -17,6 +19,7 @@ import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.Timer;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
......@@ -96,7 +99,7 @@ public class MapDialog extends JFrame {
new MapDialog();
} // main(String[])
private JLabel imageLabel = new JLabel();
private final JLabel imageLabel = new JLabel();
private JPanel leftPanel = new JPanel();
private JButton refreshB = new JButton("Päivitä");
private JButton leftB = new JButton("<");
......@@ -109,6 +112,8 @@ public class MapDialog extends JFrame {
private JButton zoomOutB = new JButton("-");
private Timer resizeTimer;
public MapDialog() throws Exception {
// Valmistele ikkuna ja lisää siihen komponentit
......@@ -134,6 +139,25 @@ public class MapDialog extends JFrame {
this.zoomInB.addActionListener(bl);
this.zoomOutB.addActionListener(bl);
this.resizeTimer = new Timer(250, new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
try {
MapDialog.this.updateImage();
} catch (Exception e) {
e.printStackTrace();
}
}
});
this.resizeTimer.setRepeats(false);
this.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent evt) {
MapDialog.this.resizeTimer.restart();
}
});
this.leftPanel.setLayout(new BoxLayout(this.leftPanel, BoxLayout.Y_AXIS));
this.leftPanel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
this.leftPanel.setMaximumSize(new Dimension(100, 600));
......@@ -183,8 +207,9 @@ public class MapDialog extends JFrame {
try {
// TODO: coordinate updates
url = new URL("http://demo.mapserver.org/cgi-bin/wms?SERVICE="
+ "WMS&VERSION=1.1.1&REQUEST=GetMap&BBOX=-180,-90,180,90&SRS="
+ "EPSG:4326&WIDTH=1280&HEIGHT=720&LAYERS=" + ss + "&STYLES="
+ "WMS&VERSION=1.1.1&REQUEST=GetMap&BBOX=-180,-90,180,90&SRS=" + "EPSG:4326&WIDTH="
+ (MapDialog.this.getWidth() - MapDialog.this.leftPanel.getWidth()) + "&HEIGHT="
+ MapDialog.this.getHeight() + "&LAYERS=" + ss + "&STYLES="
+ "&FORMAT=image/png&TRANSPARENT=true");
} catch (MalformedURLException e) {
e.printStackTrace();
......
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