01: /*
02: * <copyright>
03: *
04: * Copyright 1997-2004 BBNT Solutions, LLC
05: * under sponsorship of the Defense Advanced Research Projects
06: * Agency (DARPA).
07: *
08: * You can redistribute this software and/or modify it under the
09: * terms of the Cougaar Open Source License as published on the
10: * Cougaar Open Source Website (www.cougaar.org).
11: *
12: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
14: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
15: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
16: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
17: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
18: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23: *
24: * </copyright>
25: */
26:
27: package org.cougaar.planning.examples;
28:
29: import org.cougaar.planning.ldm.plan.*;
30: import org.cougaar.planning.ldm.asset.*;
31: import org.cougaar.planning.plugin.legacy.SimplePlugin;
32: import java.util.*;
33: import java.awt.event.*;
34: import java.awt.*;
35: import javax.swing.*;
36:
37: public class ReportCreatorPlugin extends SimplePlugin {
38:
39: // This plugin doesn't subscribe, but needs to set up a UI
40: // for the creation of Reports
41: public void setupSubscriptions() {
42: // System.out.println("ReportCreatorPlugin.setupSubscriptions...");
43:
44: ActionListener listener = new ActionListener() {
45: public void actionPerformed(ActionEvent e) {
46: generateReport();
47: }
48: };
49: createGUI("Create Report", "Report", listener);
50: }
51:
52: private static int counter = 1;
53:
54: private void generateReport() {
55: openTransaction();
56: NewReport Report = theLDMF.newReport();
57: Report.setText("ReportText-" + counter);
58: Report.setDate(new Date());
59:
60: System.out.println("Publishing new Report " + Report.getText());
61:
62: counter++;
63:
64: publishAdd(Report);
65: closeTransactionDontReset();
66: }
67:
68: public void execute() {
69: // System.out.println("ReportCreatorPlugin.execute...");
70: }
71:
72: /**
73: * Create a simple free-floating GUI button with a label
74: */
75: private static void createGUI(String button_label,
76: String frame_label, ActionListener listener) {
77: JFrame frame = new JFrame(frame_label);
78: frame.getContentPane().setLayout(new FlowLayout());
79: JPanel panel = new JPanel();
80: // Create the button
81: JButton button = new JButton(button_label);
82:
83: // Register a listener for the button
84: button.addActionListener(listener);
85: panel.add(button);
86: frame.getContentPane().add("Center", panel);
87: frame.pack();
88: frame.setVisible(true);
89: }
90:
91: }
|