View Javadoc

1   /*
2   $Id: BidimDisplayAllocator.java 706 2005-03-21 16:20:16Z guest $
3   */
4   
5   
6   /*
7   Copyright (C) 2001-2002 Mainline Project (I3S - ESSI - CNRS -UNSA)
8   
9   This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13  
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  Lesser General Public License for more details.
18  
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  
23  For further information on the GNU Lesser General Public License,
24  see: http://www.gnu.org/copyleft/lesser.html
25  For further information on this library, contact: mainline@essi.fr
26  */
27  
28  
29  package fr.ove.openmath.jome.ctrlview.bidim;
30  
31  import java.awt.*;
32  
33  import org.util.activemath.JomeConstants;
34  
35  import com.sun.naming.internal.ResourceManager;
36  
37  import fr.ove.openmath.jome.model.*;
38  
39  /***
40  * This class instanciates the right display according to the specified formula
41  * tree sturcture.
42  * This is an abstract class. It must be inherited to be specialized.
43  *
44  * @author © 1999 DIRAT Laurent
45  * @version 2.0  01/07/1999
46  */
47  
48  public class BidimDisplayAllocator extends DisplayAllocator {
49      /***
50      * The display layout allocator.
51      */
52      private static BidimLayoutAllocator layoutAllocator = new BidimLayoutAllocator();
53      
54      /***
55      * The resources manager for the displays
56      */
57      static BidimResourcesManager resourcesManager = new BidimResourcesManager("fr.ove.openmath.jome.ctrlview.bidim.resources");
58      
59      /***
60      * Instanciates and creates the right display according to the specified
61      * formula tree structure.
62      * @param fts the formula tree structure which need a display.
63      */
64      public Display allocateDisplay(GraphicContext graphicContext, FormulaTreeStructure fts) {
65          Display display = null;
66          
67          String ftsId = fts.getResourceIdentifier();
68          String idDisplay = resourcesManager.getIdDisplay(ftsId);
69          
70          // Si il y a un problËme de display, alors on met le display par dÈfaut
71          idDisplay = (idDisplay == null) ? "default" : idDisplay;
72          
73          //System.out.println("ftsId = " + ftsId + "\t\t idDisplay = " + idDisplay);
74          
75          if (idDisplay.equals("constant")) {
76              // Allocation d'un StringDisplay
77              String value = ((Constant) fts).getValue();
78              
79              Object value2 = JomeConstants.SYMBOLS.get(value);
80              if(value2 != null)
81              	value =  value2.toString();
82              
83              display = new StringDisplay(graphicContext, value, false);
84              
85              // Le display crÈÈ Ècoute la fts qui lui correspond
86              display.addControlListener(fts);
87              // Et vice et versa.
88              fts.addModelListener(display);
89          }
90          else if (idDisplay.equals("symbol")) {
91              // Allocation d'un SymbolDisplay
92              display = new SymbolDisplay(graphicContext);
93              // Allocation dudit symbole
94              ImageSymbol symbol = new ImageSymbol(/*fts.getSymbolName*/fts.getValue(), display);
95              // Affection du symbole
96              ((SymbolDisplay) display).setSymbol(symbol);
97              
98              // Le display crÈÈ Ècoute la fts qui lui correspond
99              display.addControlListener(fts);
100             // Et vice et versa.
101             fts.addModelListener(display);
102         }
103         else if (idDisplay.equals("icon")) {
104             if (((Icon) fts).isSubstitution()) {
105                 // Allocation d'un SubstitutionDisplay
106                 display = new SubstitutionDisplay(graphicContext, ((Icon) fts).getIconName());
107             }
108             else {
109                 // Allocation d'un SymbolDisplay
110                 display = new IconDisplay(graphicContext);
111                 // Allocation de l'icone
112                 ImageSymbol icon = new ImageSymbol(fts.getIconName(), display);
113                 // Affection du symbole (i.e. de l'icone)
114                 ((SymbolDisplay) display).setSymbol(icon);
115             }
116             
117             // Le display crÈÈ Ècoute la fts qui lui correspond
118             display.addControlListener(fts);
119             // Et vice et versa.
120             fts.addModelListener(display);
121         }
122         else {
123             // Dans tous les autres cas, allocation d'un BidimDisplay
124             display = new BidimDisplay(graphicContext);
125             
126             // Le display crÈÈ Ècoute la fts qui lui correspond
127             display.addControlListener(fts);
128             // Et vice et versa.
129             fts.addModelListener(display);
130             
131             // Allocation du layout manager qui va bien
132             String layoutName = resourcesManager.getLayoutManager(ftsId);
133             layoutName = (layoutName == null) ? resourcesManager.getLayoutManager("defaultLM") : layoutName;
134             
135             //System.out.println("layoutName = " + layoutName);
136             
137             DisplayLayout layout = layoutAllocator.allocateLayout(layoutName);
138             display.setLayout(layout);
139             layout.initDisplay(display);
140         }
141         
142         return display;
143     }
144 }