View Javadoc

1   // Copyright 2004, FreeHEP.
2   package hep.wired.plugin;
3   
4   import java.awt.*;
5   import java.util.*;
6   import java.util.logging.*;
7   import javax.swing.*;
8   import javax.swing.undo.*;
9   import javax.swing.event.*;
10  
11  import org.jdom.Element;
12  
13  import org.freehep.application.Application;
14  import org.freehep.application.studio.Studio;
15  import org.freehep.application.mdi.ManagedPage;
16  import org.freehep.application.mdi.PageContext;
17  import org.freehep.xml.io.XMLIO;
18  import org.freehep.xml.io.XMLIOManager;
19  import org.freehep.swing.popup.HasPopupItems;
20  import org.freehep.util.commanddispatcher.CommandProcessor;
21  
22  import hep.wired.services.RecordPlot;
23  
24  /***
25   * Defines a page with one plot for inclusion in JAS.
26   *
27   * @author Mark Donszelmann
28   * @version $Id: WiredPage.java 689 2005-03-16 09:06:57Z duns $
29   */
30  public class WiredPage extends JPanel
31                         implements ManagedPage, XMLIO {
32  
33      private static Logger logger = Logger.getLogger(WiredPage.class.getPackage().getName());
34      
35      private String name;
36      private RecordPlot plot;
37      private CommandProcessor processor;
38  
39      private WiredPage() {
40          this("NotInitialized", null, null);
41      }    
42  
43      public WiredPage(String name, RecordPlot plot, CommandProcessor processor) {
44          this.name = name;
45          this.plot = plot;
46          this.processor = processor;
47          setLayout(new BorderLayout());
48          if (plot != null) init(plot);
49      }
50      
51      private void init(RecordPlot plot) {
52          add((Component)plot, BorderLayout.CENTER);
53          
54          // undo support
55          if ((processor != null) && (processor instanceof UndoableEditListener)) {
56              UndoableEditSupport undoSupport = plot.getUndoableEditSupport();
57              if (undoSupport != null) undoSupport.addUndoableEditListener((UndoableEditListener)processor);
58          }
59      }        
60      
61      public String getName() {
62          return name;
63      }
64              
65      public RecordPlot getRecordPlot() {
66          return plot;
67      }
68      
69      public void setChanged() {
70          if (processor != null) processor.setChanged();
71      }
72              
73  //
74  // ManagedPage Interface
75  //
76      public boolean close() {
77          return true;
78      }
79  
80      public void pageClosed() {
81      }
82  
83      public void pageIconized() {
84      }
85  
86      public void pageDeiconized() {
87      }
88  
89      public void pageSelected() {
90          if (processor != null) ((Studio)Application.getApplication()).getCommandTargetManager().add(processor);
91          plot.setSelected(true);
92      }
93  
94      public void pageDeselected() {
95          if (processor != null) ((Studio)Application.getApplication()).getCommandTargetManager().remove(processor);
96          plot.setSelected(false);
97      }
98  
99      public void setPageContext(PageContext context) {
100     }
101 
102 //
103 // HasPopupItems interface
104 //
105     public JPopupMenu modifyPopupMenu(JPopupMenu menu, Component source, Point p) {
106         return (plot instanceof HasPopupItems) ? ((HasPopupItems)plot).modifyPopupMenu(menu, source, p) : menu;
107     }
108 
109 //
110 // XMLIO
111 //
112     public void save(XMLIOManager xmlioManager,
113                      org.jdom.Element nodeEl) {
114         nodeEl.setAttribute("name", name);
115         nodeEl.addContent(xmlioManager.save(plot));
116     }
117 
118     public void restore(XMLIOManager xmlioManager,
119                         org.jdom.Element nodeEl) {
120         name = nodeEl.getAttributeValue("name");
121         Iterator i = nodeEl.getChildren().iterator();
122         plot = (RecordPlot)xmlioManager.restore((Element)i.next());
123         init(plot);
124     }     
125 }