Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/gendiapo/editor/GenericGenDiapoEditor.java


1   package org.gendiapo.editor;
2   
3   import java.awt.*; 
4   import java.awt.event.*;
5   import java.awt.geom.*;
6   import java.util.*;
7   import java.beans.PropertyVetoException;
8   
9   import javax.swing.*;
10  import javax.swing.text.*;
11  import javax.swing.text.html.*;
12  
13  import org.merlotxml.merlot.*;
14  import org.merlotxml.merlot.plugin.dtd.*;
15  import org.merlotxml.util.xml.*; 
16  
17  import org.w3c.dom.*;
18  
19  import org.gendiapo.editor.*;
20  
21  public class GenericGenDiapoEditor extends GenericDOMEditor implements GenDiapoEditor
22  {
23      
24      final static ArrayList EMPTY = new ArrayList();
25  
26      /*
27       * Constructor
28       */    
29      public GenericGenDiapoEditor () 
30      {
31      }
32      
33      
34      /**
35       * Returns a set of menu items for any special actions for
36       * this particular editor
37       * that it wants in the popup menu. Standard stuff like cut, copy, paste
38       * is taken care of by other objects. If nothing needs added,
39       * can return null.
40       *
41       * @param node the node for which to get the menu items
42       */
43      public  JMenuItem[] getMenuItems(MerlotDOMNode node)
44      {
45      return null;
46      }    
47      
48          
49      /**
50       * returns a panel for editing this type of component.
51       */
52      public JPanel getEditPanel(MerlotDOMNode node)
53      {
54    JPanel editPanel = null;
55  
56    DTDPluginConfig dpc = node.getDTDPluginConfig();
57    if (dpc instanceof GD_DTDPluginConfig) {      
58         editPanel= ((GD_DTDPluginConfig) dpc).getEditPanel(node);
59    }
60  
61    if (editPanel == null) {
62        editPanel = new GenericGenDiapoEditPanel(node);
63    }
64  
65    if (editPanel != null) {
66        installListener(editPanel,node);
67    }
68      
69    return editPanel;  
70      }
71      
72      
73      
74      /**
75       * called by the editor when the user has chosen to save their
76       * changes in a panel.
77       * @param p the panel that was retreived with getEditPanel(node);
78       *
79       */
80      public void savePanel(JPanel p)
81      throws PropertyVetoException
82      {
83    if (p instanceof GenericDOMEditPanel) {
84        ((GenericDOMEditPanel)p).save();
85    }
86    else {
87        MerlotDebug.msg("Cannot save! Panel is not the right type.");
88    }
89    
90      }
91      
92      
93      /**
94       * Tells the edit panel it's gaining focus, so it can put the cursor in the first
95       * field. XXX this should probably be handled by event listening instead
96       */
97      public void grabFocus(JPanel p)
98      {
99    
100   if (p instanceof GenericGenDiapoEditPanel) {
101       ((GenericGenDiapoEditPanel)p).grabFocus();
102   }
103   
104     }
105 
106     public boolean suppressTag(String name) {
107   return false;
108     }   
109     
110     public boolean suppressTag(MerlotDOMNode node, String name) {
111         return suppressTag(name);
112     }
113    
114     /**
115      * Returns true if the component editor wants a particular node hidden
116      * from the user. If the editor wants to filter
117      * what the user sees in their display, it should look at the
118      * given node, otherwise it should return false. This is usefull
119      * particularly if the editor handles its children. It can hide
120      * the children nodes from the user's view.
121      */
122     // n'affiche pas le noeud dans l'arbre mais on peut l'ajouter
123     // si surcharge ne pas oublier de prendre en compte suppressTag
124     public boolean suppressNode(MerlotDOMNode node)
125     {        
126   if ( (node instanceof MerlotDOMText) || (super.suppressNode(node)) ) {
127       return true;
128   } else {
129             MerlotDOMNode parent = node.getParentNode();
130       return suppressTag(parent, node.getNodeName());
131   }
132     }
133 
134     /**
135      * allows the plugin to hide certain items on the add-> menu. For
136      * example, the plugin for the accessibility permissions might not
137      * want the user to be able to directly add an "access" element, so
138      * it can request that that be suppressed.
139      */
140     // enleve l'element des menus donc impossible d'ajouter l'element
141     // si surcharge ne pas oublier de prendre en compte suppressTag
142     public boolean suppressAddType(DTDElement el)
143     {  
144         return super.suppressAddType(el);        
145     }
146     
147     public boolean suppressAddType(MerlotDOMNode node, DTDElement el) {
148   if ( (suppressAddType(el)) ) {
149       return true;
150   } else {
151       String dtdName = el.getName();
152       return suppressTag(node, dtdName);
153   }        
154     }    
155     
156     
157     public void installListener(JPanel p, MerlotDOMNode node) 
158     {
159   if (p instanceof GenericGenDiapoEditPanel) {
160       // install us as a listener
161       MerlotDebug.msg("installing listener for "+p);
162       
163       ((GenericGenDiapoEditPanel)p).addVetoableChangeListener(new GenericSanityCheckListener());
164   }
165     }
166         
167     public int editionType(MerlotDOMNode node) {
168   int edition = GenDiapoEditor.EDITION_TREE;
169   DTDPluginConfig dpc = node.getDTDPluginConfig();
170   if (dpc instanceof GD_DTDPluginConfig) {
171       edition = ((GD_DTDPluginConfig) dpc).editionType(node.getNodeName());
172   }
173   return edition;
174     }
175 
176     public NodeControler getNodeControler(MerlotDOMNode node) {
177   NodeControler nc = null;
178   DTDPluginConfig dpc = node.getDTDPluginConfig();
179   if (dpc instanceof GD_DTDPluginConfig) {
180       nc = ((GD_DTDPluginConfig) dpc).getNodeControler(node.getNodeName());
181   }
182   return nc;
183     }
184     
185     public ViewFactory getViewFactory(MerlotDOMNode node) {
186   ViewFactory viewFactory = null;
187   DTDPluginConfig dpc = node.getDTDPluginConfig();
188   if (dpc instanceof GD_DTDPluginConfig) {
189       viewFactory = ((GD_DTDPluginConfig) dpc).getViewFactory();      
190   }
191   return viewFactory;
192     }
193         
194     public java.util.List attributesInStyledView(MerlotDOMNode node) {        
195   java.util.List order = EMPTY;
196   DTDPluginConfig dpc = node.getDTDPluginConfig();
197   if (dpc instanceof GD_DTDPluginConfig) {      
198       order = ((GD_DTDPluginConfig) dpc).inStyledView(node.getNodeName());
199   }
200   return order;  
201     }    
202     
203     public boolean addVoid(MerlotDOMNode node) {
204         boolean doit = true;        
205         DTDPluginConfig dpc = node.getDTDPluginConfig();
206   if (dpc instanceof GD_DTDPluginConfig) {      
207       doit = ((GD_DTDPluginConfig) dpc).addVoid(node.getNodeName());
208   }         
209         return doit;
210     }
211 
212     public StyleSheet getStyleSheet(MerlotDOMNode node) {
213   DTDPluginConfig dpc = node.getDTDPluginConfig();
214   if (dpc instanceof GD_DTDPluginConfig) {
215       StyleSheet style = ((GD_DTDPluginConfig) dpc).getStyleSheet(node.getNodeName());
216       return style;
217   }
218   return null;  
219     }
220 
221     public String getUserName(DTDElement element) {
222   return null;
223     }
224         
225     public String getUserName(MerlotDOMNode node, DTDElement element) {
226         String value = getUserName(element);
227         if (value == null) {           
228             DTDPluginConfig dpc = node.getDTDPluginConfig();
229             if (dpc instanceof GD_DTDPluginConfig) {
230                 value = ((GD_DTDPluginConfig) dpc).getNodeName(element.getName());
231             } else {
232                 value = element.getName();
233             }
234         }
235   return value;
236     }        
237 
238     public String getUserName(MerlotDOMNode node) {
239   String value = node.getNodeName();
240   if (node instanceof MerlotDOMElement) {      
241       value = ((MerlotDOMElement)node).getElementName();
242   }
243         DTDPluginConfig dpc = node.getDTDPluginConfig();
244   if (dpc instanceof GD_DTDPluginConfig) {
245             value = ((GD_DTDPluginConfig) dpc).getNodeName(node.getNodeName());
246         }        
247   return value;
248     }
249 
250     public String getUserName(MerlotDOMNode node, DTDAttribute attribute) {
251         String value = attribute.getName();
252         DTDPluginConfig dpc = node.getDTDPluginConfig();
253         if (dpc instanceof GD_DTDPluginConfig) {
254             value = ((GD_DTDPluginConfig) dpc).getAttributeName(node.getNodeName(), attribute.getName());
255         }
256   return value;
257     }        
258     
259     
260 }