arcgissamples\defensesolutions\MapTocToolbar.java
/* Copyright 2010 ESRI * * All rights reserved under the copyright laws of the United States * and applicable international laws, treaties, and conventions. * * You may freely redistribute and use this sample code, with or * without modification, provided you include the original copyright * notice and use restrictions. * * See the use restrictions. * */ package arcgissamples.defensesolutions; import com.esri.arcgis.beans.map.MapBean; import com.esri.arcgis.beans.toolbar.ToolbarBean; import com.esri.arcgis.beans.TOC.TOCBean; import com.esri.arcgis.system.AoInitialize; import java.awt.*; import java.io.*; import javax.swing.*; public class MapTocToolbar extends JFrame { private static final long serialVersionUID = 1; private JPanel jContentPane = null; private ToolbarBean toolbarBean = null; private JSplitPane jSplitPane = null; private TOCBean TOCBean = null; private JPanel toolPanel = null; private MapBean mapBean = null; private JToolBar toolBar = null; private JButton btnAdd200 = null; private JButton btnMoveUnits = null; private JTextField txtSIC = null; private JTextField txtSize = null; private JButton btnAddLine = null; private JButton btnAddArea = null; private JToggleButton btnAddMoleSymbol = null; private JToggleButton btnSelect = null; /** * This method initializes jSplitPane * * @return javax.swing.JSplitPane */ private JSplitPane getJSplitPane() { if ( jSplitPane == null ) { jSplitPane = new JSplitPane(); jSplitPane.setDividerLocation(150); jSplitPane.setDividerSize(2); jSplitPane.setRightComponent(getMapBean()); jSplitPane.setLeftComponent(getTOCBean()); } return jSplitPane; } /** * This method initializes TOCBean * * @return com.esri.arcgis.beans.TOC.TOCBean */ private TOCBean getTOCBean() { if ( TOCBean == null ) { TOCBean = new TOCBean(); try { TOCBean.setBuddyControl(getMapBean()); } catch (IOException e) { e.printStackTrace(); } } return TOCBean; } /** * This method initializes mapBean * * @return com.esri.arcgis.beans.map.MapBean */ MapBean getMapBean() { String arcgisHome = null; String dataPath = null; if (mapBean == null) { arcgisHome = System.getenv("AGSDEVKITJAVA"); if (arcgisHome == null) { JOptionPane.showInputDialog("AGSDEVKITJAVA environment variable is not set, exiting application"); System.exit(-1); } dataPath = arcgisHome + File.separator + "java" + File.separator + "samples" + File.separator + "data" + File.separator + "mole" + File.separator + "mole_base.mxd"; try { mapBean = new MapBean(); mapBean.loadMxFile( dataPath, null, null); } catch (Exception e) { e.printStackTrace(); } } return mapBean; } /** * This is the default constructor */ public MapTocToolbar() { super(); initializeArcGISLicenses(); initialize(); } /** * This method initializes this * * @return void */ private void initialize() { this.setSize(802, 572); this.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/arcgissamples/defensesolutions/Earth.png"))); this.setContentPane(getJContentPane()); this.setTitle("MOLE Basic Symbols"); this.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent e) { System.out.println("windowClosing()"); try { new AoInitialize().shutdown(); } catch (Exception ex) { ex.printStackTrace(); } } }); } /** * This method initializes jContentPane * * @return javax.swing.JPanel */ private JPanel getJContentPane() { if ( jContentPane == null ) { jContentPane = new JPanel(); jContentPane.setLayout(new BorderLayout()); jContentPane.add(getJSplitPane(), java.awt.BorderLayout.CENTER); jContentPane.add(getToolPanel(), BorderLayout.NORTH); } return jContentPane; } /** * This method initializes toolPanel * * @return javax.swing.JPanel */ private JPanel getToolPanel() { if ( toolPanel == null ) { GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); gridBagConstraints1.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints1.gridx = 0; gridBagConstraints1.gridy = 0; gridBagConstraints1.weightx = 0.0D; GridBagConstraints gridBagConstraints = new GridBagConstraints(); gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints.gridy = 0; gridBagConstraints.weightx = 1.0D; gridBagConstraints.gridx = 1; toolPanel = new JPanel(); toolPanel.setLayout(new GridBagLayout()); toolPanel.add(getToolBar(), gridBagConstraints1); toolPanel.add(getToolbarBean(), gridBagConstraints); } return toolPanel; } /** * This method initializes toolBar * * @return javax.swing.JToolBar */ private JToolBar getToolBar() { if ( toolBar == null ) { toolBar = new JToolBar(); toolBar.setFloatable(false); toolBar.add(getBtnAdd200()); toolBar.add(getBtnMoveUnits()); toolBar.add(getBtnSelect()); toolBar.add(getBtnAddMoleSymbol()); toolBar.add(getTxtSIC()); toolBar.add(getTxtSize()); toolBar.add(getBtnAddLine()); toolBar.add(getBtnAddArea()); } return toolBar; } /** * This method initializes toolbarBean * * @return com.esri.arcgis.beans.toolbar.ToolbarBean */ ToolbarBean getToolbarBean() { if ( toolbarBean == null ) { toolbarBean = new ToolbarBean(); toolbarBean.setItemsString(""); toolbarBean.setItemsString("5|controls/ControlsOpenDocCommand|0|-1|0|0|1;5|controls/ControlsAddDataCommand|0|-1|0|0|1;5|controls/ControlsSaveAsDocCommand|0|-1|0|0|1;11|controls/ControlsMapZoomPanTool|0|-1|0|0|1;11|controls/ControlsMapFullExtentCommand|0|-1|0|0|1;11|controls/ControlsMapZoomToLastExtentBackCommand|0|-1|0|0|1;11|controls/ControlsMapZoomToLastExtentForwardCommand|0|-1|0|0|1;10|controls/ControlsMapMeasureTool|0|-1|0|0|1;8|controls/ControlsSelectTool|0|-1|0|0|1"); try { toolbarBean.setBuddyControl(getMapBean()); } catch (IOException e) { e.printStackTrace(); } } return toolbarBean; } static void initializeArcGISLicenses() { try { com.esri.arcgis.system.AoInitialize ao = new com.esri.arcgis.system.AoInitialize(); if (ao.isProductCodeAvailable( com.esri.arcgis.system.esriLicenseProductCode.esriLicenseProductCodeEngine) == com.esri.arcgis.system.esriLicenseStatus.esriLicenseAvailable ) ao.initialize( com.esri.arcgis.system.esriLicenseProductCode.esriLicenseProductCodeEngine); else { System.err.println( "Could not initialize an ArcGIS Engine license. Exiting application."); System.exit(-1); } } catch (Exception e) { e.printStackTrace(); } } /** * This method initializes btnAdd200 * * @return javax.swing.JButton */ JButton getBtnAdd200() { if ( btnAdd200 == null ) { btnAdd200 = new JButton(); btnAdd200.setToolTipText("Create 200 graphics"); btnAdd200.setIcon(new ImageIcon(getClass().getResource("/arcgissamples/defensesolutions/Add.png"))); } return btnAdd200; } /** * This method initializes btnMoveUnits * * @return javax.swing.JButton */ JButton getBtnMoveUnits() { if ( btnMoveUnits == null ) { btnMoveUnits = new JButton(); btnMoveUnits.setToolTipText("Move units"); btnMoveUnits.setIcon(new ImageIcon(getClass().getResource("/arcgissamples/defensesolutions/Move.png"))); } return btnMoveUnits; } /** * This method initializes txtSIC * * @return javax.swing.JTextField */ JTextField getTxtSIC() { if ( txtSIC == null ) { txtSIC = new JTextField(); txtSIC.setText("SFGPUCAWW------"); txtSIC.setToolTipText("ID code of MOLE symbol to add"); txtSIC.setFont(new Font("Courier New", Font.PLAIN, 12)); } return txtSIC; } /** * This method initializes txtSize * * @return javax.swing.JTextField */ JTextField getTxtSize() { if ( txtSize == null ) { txtSize = new JTextField(); txtSize.setText("36"); txtSize.setToolTipText("Size of MOLE symbol to add"); } return txtSize; } /** * This method initializes btnAddLine * * @return javax.swing.JButton */ JButton getBtnAddLine() { if ( btnAddLine == null ) { btnAddLine = new JButton(); btnAddLine.setToolTipText("Add a sample line graphic"); btnAddLine.setIcon(new ImageIcon(getClass().getResource("/arcgissamples/defensesolutions/Line.png"))); } return btnAddLine; } /** * This method initializes btnAddArea * * @return javax.swing.JButton */ JButton getBtnAddArea() { if ( btnAddArea == null ) { btnAddArea = new JButton(); btnAddArea.setToolTipText("Add a sample area graphic"); btnAddArea.setIcon(new ImageIcon(getClass().getResource("/arcgissamples/defensesolutions/Area.png"))); } return btnAddArea; } /** * This method initializes btnAddMoleSymbol * * @return javax.swing.JToggleButton */ JToggleButton getBtnAddMoleSymbol() { if ( btnAddMoleSymbol == null ) { btnAddMoleSymbol = new JToggleButton(); btnAddMoleSymbol.setIcon(new ImageIcon(getClass().getResource("/arcgissamples/defensesolutions/Jazz.png"))); btnAddMoleSymbol.setToolTipText("Add MOLE symbol"); } return btnAddMoleSymbol; } /** * This method initializes btnSelect * * @return javax.swing.JToggleButton */ JToggleButton getBtnSelect() { if ( btnSelect == null ) { btnSelect = new JToggleButton(); btnSelect.setToolTipText("Select & drag graphics"); btnSelect.setIcon(new ImageIcon(getClass().getResource("/arcgissamples/defensesolutions/Select.png"))); } return btnSelect; } } // @jve:decl-index=0:visual-constraint="10,10"