Hi,
The program below makes a SplitPane with
a map in it, but it shows some of the
toolbar icons more than once. How
can I fix this?
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Properties;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import com.bbn.openmap.LatLonPoint;
import com.bbn.openmap.LayerHandler;
import com.bbn.openmap.MapBean;
import com.bbn.openmap.MapHandler;
import com.bbn.openmap.MultipleSoloMapComponentException;
import com.bbn.openmap.examples.simple.RouteLayer;
import com.bbn.openmap.gui.DockMapPanel;
import com.bbn.openmap.gui.MapPanel;
import com.bbn.openmap.gui.OMToolSet;
import com.bbn.openmap.gui.OpenMapFrame;
import com.bbn.openmap.gui.ToolPanel;
import com.bbn.openmap.layer.GraticuleLayer;
import com.bbn.openmap.layer.shape.ShapeLayer;
class OpenMapSplitPane extends OpenMapFrame {
private JSplitPane splitPaneV;
private JSplitPane splitPaneH;
private JPanel panel1;
private JPanel panel2;
JPanel topPanel;
public OpenMapSplitPane() {
setTitle("Split Pane Application");
setBackground(Color.gray);
topPanel = new JPanel();
topPanel.setLayout(new BorderLayout());
// Create the panels
createPanel1();
createPanel2();
// Create a splitter pane
splitPaneV = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
topPanel.add(splitPaneV, BorderLayout.CENTER);
// Call quit when the window's close box is clicked.
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
quit();
}
});
}
public void createPanel1() {
panel1 = new JPanel();
panel1.setLayout(new BorderLayout());
panel1.setPreferredSize(new Dimension(100, 100));
panel1.setMinimumSize(new Dimension(50, 50));
// Add some buttons
panel1.add(new JButton("North"), BorderLayout.NORTH);
panel1.add(new JButton("South"), BorderLayout.SOUTH);
panel1.add(new JButton("East"), BorderLayout.EAST);
panel1.add(new JButton("West"), BorderLayout.WEST);
panel1.add(new JButton("Center"), BorderLayout.CENTER);
}
public void createPanel2() {
panel2 = new JPanel();
panel2.setLayout(new FlowLayout());
panel2.setPreferredSize(new Dimension(100, 100));
panel2.setMinimumSize(new Dimension(50, 50));
panel2.add(new JButton("Button 1"));
panel2.add(new JButton("Button 2"));
panel2.add(new JButton("Button 3"));
}
public static void main(String args[]) {
// Create an instance of the test application
OpenMapSplitPane mainFrame = new OpenMapSplitPane();
try {
MapPanel mapPanel = new DockMapPanel();
mainFrame.splitPaneV.setRightComponent((Component) mapPanel);
mainFrame.splitPaneH = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
mainFrame.splitPaneH.setLeftComponent(mainFrame.panel1);
mainFrame.splitPaneH.setRightComponent(mainFrame.panel2);
mainFrame.splitPaneV.setLeftComponent(mainFrame.splitPaneH);
// Get the default MapHandler the BasicMapPanel created.
MapHandler mapHandler = mapPanel.getMapHandler();
mainFrame.getContentPane().add(mainFrame.topPanel);
mapHandler.add(mainFrame.topPanel);
// Get the default MapBean that the BasicMapPanel created.
MapBean mapBean = mapPanel.getMapBean();
// Set the map's center
mapBean.setCenter(new LatLonPoint(43.0f, -95.0f));
// Set the map's scale 1:120 million
mapBean.setScale(120000000f);
// Add a route layer.
RouteLayer routeLayer = new RouteLayer();
routeLayer.setVisible(true);
ShapeLayer shapeLayer = new ShapeLayer();
Properties shapeLayerProps = new Properties();
shapeLayerProps.put("prettyName", "Political Solid");
shapeLayerProps.put("lineColor", "000000");
shapeLayerProps.put("fillColor", "BDDE83");
shapeLayerProps.put("shapeFile", "data/shape/dcwpo-browse.shp");
shapeLayerProps.put("spatialIndex", "data/shape/dcwpo-browse.ssx");
shapeLayer.setProperties(shapeLayerProps);
shapeLayer.setVisible(true);
// Last on top.
mapHandler.add(shapeLayer);
mapHandler.add(new GraticuleLayer());
mapHandler.add(routeLayer);
// Create the directional and zoom control tool
OMToolSet omts = new OMToolSet();
// Create an OpenMap toolbar
ToolPanel toolBar = new ToolPanel();
mapHandler.add(omts);
mapHandler.add(toolBar);
} catch (MultipleSoloMapComponentException msmce) {
msmce.printStackTrace();
}
mainFrame.setSize(640, 480);
mainFrame.pack();
mainFrame.setVisible(true);
}
/**
* Exits the application.
*/
protected void quit() {
System.exit(0);
}
}
--
[To unsubscribe to this list send an email to "majdart_at_bbn.com"
with the following text in the BODY of the message "unsubscribe openmap-users"]
Received on Sun Dec 12 2010 - 19:13:45 EST