/******************************************************************* Copyright (c) 2001-2010 Apprisant Technologies Inc. All rights reserved. Apprisant Technologies permits non-exclusive royalty free use, copying and modification of this demo program source code for the purposes of evaluating the Apprisant Toolkit or building applications that use it. This software and documentation is provided "AS IS". APPRISANT TECHNOLOGIES DISCLAIMS ANY REPRESENTATIONS AND WARRANTIES, INCLUDING BUT NOT LIMITED TO ANY IMPLIED WARRANTY OF MERCHANTABILITY AND FITNESS OF THIS PRODUCT FOR ANY PARTICULAR PURPOSE. APPRISANT TECHNOLOGIES SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY ANY PARTY, INCLUDING LOST PROFITS, ARISING FROM THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ITS DERIVATIONS. ********************************************************************/ package oilfield; import java.awt.*; import java.awt.geom.*; import java.awt.event.*; import javax.swing.*; import java.util.*; import apprisant.diagram.*; import apprisant.diagram.event.*; import apprisant.diagram.env.*; import apprisant.diagram.awtext.AGGradientPaint; /* The main class for the Oilfield demo. This class assembles the user interface. Display elements are created from the data objects by the KeyModel. The renderers are configured to use the position property of the data objects. */ public class Oilfield extends JApplet { Diagram diagram; OilfieldData dataModel; DiagramSelectionModel selectionModel; public void init() { setLayout(new BorderLayout()); try { // Properties file sets rendering hints AGEnvironment.loadProperties("oilfield/oilfield.properties"); // Create the diagram diagram = new Diagram("Oilfield"); diagram.setRaiseSelected(true); diagram.setScrollSelected(true); ViewManager viewMgr = diagram.getViewManager(); viewMgr.setViewBounds(new Rectangle2D.Float(0, 0, 600, 400)); viewMgr.setMargin(new Dimension(10, 10)); // Renderers diagram.readRenderers("oilfield/oilfield.rdr"); // Background color from the renderer file RenderManager renMgr = diagram.getRenderManager(); Color bg = (Color) renMgr.getDefinitions().get("bg"); diagram.setBackground(bg); } catch (AGException ae) { AGLog.log("Oilfield", "initializing", AGLog.ERROR, ae); return; } // Selection model selectionModel = diagram.getSelectionModel(); selectionModel.setSelectionMode(SelectionParams.SINGLE); // Data model dataModel = new OilfieldData(); dataModel.initWells(); diagram.setDataModel(dataModel); // Add the diagram to the applet add(new JScrollPane(diagram), BorderLayout.CENTER); // Button panel add(buildButtonPanel(), BorderLayout.SOUTH); } Box buildButtonPanel() { Box buttonPanel; buttonPanel = new Box(BoxLayout.X_AXIS); JButton addButton = new JButton("Add"); buttonPanel.add(Box.createGlue()); buttonPanel.add(addButton); buttonPanel.add(Box.createHorizontalStrut(5)); addButton.addActionListener(new ActionListener() { public void actionPerformed (ActionEvent ev) { dataModel.addWell(); } }); JButton removeButton = new JButton("Remove"); buttonPanel.add(removeButton); buttonPanel.add(Box.createGlue()); removeButton.addActionListener(new ActionListener() { public void actionPerformed (ActionEvent ev) { Object key = selectionModel.getSingleSelection(); dataModel.removeWell(key); } }); return buttonPanel; } public static void main (String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { JApplet applet = new Oilfield(); applet.init(); JFrame frame = new JFrame("Oilfield Demo"); frame.setLocation(100, 100); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(applet, BorderLayout.CENTER); frame.pack(); frame.setVisible (true); } }); } }