_layerHandler = new LayerHandler(_layers);
_layerHandler.addLayerListener(_mapBean);
_layersMenu = new LayersMenu(_layerHandler);
_fileMenu = new JMenu("File");
_httpExample = new JMenuItem("HTTP Example");
_httpExample.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
String url = stripExtension(getRemoteFile(), "shp");
URL dbf = null, shp = null, shx = null;
dbf = new URL(url + ".dbf");
shp = new URL(url + ".shp");
shx = new URL(url + ".shx");
EsriLayer layer = new EsriLayer(url, dbf, shp, shx);
_layerHandler.addLayer(layer);
} catch (Exception exception) {
System.out.println(exception);
}
}
});
_showTable = new JMenuItem("Show Table");
_showTable.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
EsriLayer layer = pickEsriLayer();
showTable(layer);
}
});
_setModel = new JMenuItem("Set Model");
_setModel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
try {
_drawableLayer = new EsriLayer("Drawable Layer", 3, 1); //Create
// a
// polyline
// layer
_drawableLayer.setName("Drawable Layer");
_layerHandler.addLayer(_drawableLayer);
DbfTableModel model = new DbfTableModel(1);
model.setDecimalCount(0, (byte) 0);
model.setLength(0, (byte) 10);
model.setColumnName(0, "Column1");
model.setType(0, (byte) DbfTableModel.TYPE_CHARACTER);
_drawableLayer.setModel(model);
_addShape.setEnabled(true);
_setModel.setEnabled(false);
} catch (Exception exception) {
System.out.println(exception);
}
}
});
_addShape = new JMenuItem("Add Shape");
_addShape.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
EsriPolylineList shapeData = new EsriPolylineList();
ArrayList tabularData = new ArrayList();
float[] part0 = new float[] { 35.0f, -120.0f, -25.0f, -95.0f,
56.0f, -30.0f };
float[] part1 = new float[] { -15.0f, -110.0f, 13.0f, -80.0f,
-25.0f, 10.0f };
EsriPolyline poly0 = new EsriPolyline(part0, OMGraphic.DECIMAL_DEGREES, OMGraphic.LINETYPE_RHUMB);
EsriPolyline poly1 = new EsriPolyline(part1, OMGraphic.DECIMAL_DEGREES, OMGraphic.LINETYPE_RHUMB);
shapeData.add(poly0); //part 1
shapeData.add(poly1); //part 2
shapeData.generate(_mapBean.getProjection());
tabularData.add(0, "a value");
_drawableLayer.addRecord(shapeData, tabularData);
_drawableLayer.repaint();
}
});
_openFileChooser = new JMenuItem("Add Shape File");
_openFileChooser.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileFilter(new EsriFilter());
int returnVal = fileChooser.showOpenDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
try {
File shp = fileChooser.getSelectedFile();
String s = shp.getCanonicalPath();
int pos1 = s.lastIndexOf('.');
String name = s.substring(0, pos1);
File shx = new File(s.substring(0, pos1) + ".shx");
File dbf = new File(s.substring(0, pos1) + ".dbf");
EsriLayer layer = new EsriLayer(name, dbf.toURL(), shp.toURL(), shx.toURL());
_layerHandler.addLayer(layer);
} catch (Exception exception) {
System.out.println(exception);
}
}
}
});
_exit = new JMenuItem("Exit");
_exit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
_saveFileChooser = new JMenuItem("Save File");
_saveFileChooser.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
EsriLayer layer = pickEsriLayer();
if (layer != null) {
JFileChooser fileChooser = new JFileChooser();