PropertyDetailsTableCellRenderer.java
001 /*
002  *  PropertyDetailsTableCellRenderer.java
003  *
004  *  Niraj Aswani, 09/March/07
005  *
006  *  $Id: PropertyDetailsTableCellRenderer.html,v 1.0 2007/03/09 16:13:01 niraj Exp $
007  */
008 package gate.gui.ontology;
009 
010 import gate.creole.ontology.*;
011 import gate.gui.MainFrame;
012 import java.awt.Component;
013 import java.util.Set;
014 
015 import javax.swing.JTable;
016 import javax.swing.table.DefaultTableCellRenderer;
017 
018 /**
019  * A Class that specifies how each node in the details panel should look
020  * like.
021  
022  @author niraj
023  
024  */
025 public class PropertyDetailsTableCellRenderer extends DefaultTableCellRenderer {
026   private static final long serialVersionUID = 3257572784619337525L;
027 
028   public PropertyDetailsTableCellRenderer(
029           PropertyDetailsTableModel detailstablemodel) {
030     propertyDetailsTableModel = detailstablemodel;
031   }
032 
033   @Override
034   public Component getTableCellRendererComponent(JTable table, Object obj,
035           boolean flag, boolean flag1, int i, int j) {
036     Component component = super.getTableCellRendererComponent(table, "", flag,
037             flag1, i, j);
038     try {
039       if(j == 0) {
040         setText(null);
041         if(obj == null) {
042           setIcon(null);
043         }
044         else {
045           Object obj1 = propertyDetailsTableModel.getValueAt(i, 1);
046           setIcon(MainFrame.getIcon(((Boolean)obj).booleanValue()
047                   "expanded"
048                   "closed"));
049           setEnabled(((DetailsGroup)obj1).getSize() 0);
050         }
051       }
052       else if(j == 1) {
053         if(obj instanceof DetailsGroup) {
054           DetailsGroup detailsgroup = (DetailsGroup)obj;
055           setIcon(null);
056           setFont(getFont().deriveFont(1));
057           setText(detailsgroup.getName());
058           setEnabled(detailsgroup.getSize() 0);
059         }
060         else if(obj instanceof KeyValuePair) {
061           KeyValuePair kvp = (KeyValuePair)obj;
062           setIcon(MainFrame.getIcon("empty"));
063           setFont(getFont().deriveFont(0));
064           setText(kvp.getKey());
065           setEnabled(true);
066         }
067         else if(obj instanceof Restriction) {
068           OClass tclass = (OClass)obj;
069           setIcon(MainFrame.getIcon("ontology-restriction"));
070           setFont(getFont().deriveFont(0));
071           setText(tclass.getName());
072           setToolTipText(tclass.getONodeID().toString());
073           setEnabled(true);
074         }
075         else if(obj instanceof OClass) {
076           OClass tclass = (OClass)obj;
077           setIcon(MainFrame.getIcon("ontology-class"));
078           setFont(getFont().deriveFont(0));
079           setText(tclass.getName());
080           setToolTipText(tclass.getONodeID().toString());
081           setEnabled(true);
082         }
083         else if(obj instanceof OInstance) {
084           OInstance oinstance = (OInstance)obj;
085           setIcon(MainFrame.getIcon("ontology-instance"));
086           setFont(getFont().deriveFont(0));
087           setText(oinstance.getName());
088           setToolTipText(oinstance.getONodeID().toString());
089           setEnabled(true);
090         }
091         else if(obj instanceof RDFProperty) {
092           RDFProperty property = (RDFProperty)obj;
093           String propertyType = "RDF";
094           if(property instanceof SymmetricProperty) {
095             setIcon(MainFrame.getIcon("ontology-symmetric-property"));
096             propertyType = "Symmetric";
097           }
098           else if(property instanceof AnnotationProperty) {
099             setIcon(MainFrame.getIcon("ontology-annotation-property"));
100             propertyType = "Annotation";
101           }
102           else if(property instanceof TransitiveProperty) {
103             setIcon(MainFrame.getIcon("ontology-transitive-property"));
104             propertyType = "Transitive";
105           }
106           else if(property instanceof ObjectProperty) {
107             setIcon(MainFrame.getIcon("ontology-object-property"));
108             propertyType = "Object";
109           }
110           else if(property instanceof DatatypeProperty) {
111             setIcon(MainFrame.getIcon("ontology-datatype-property"));
112             propertyType = "Datatype";
113           }
114           else {
115             setIcon(MainFrame.getIcon("ontology-rdf-property"));
116           }
117           setFont(getFont().deriveFont(0));
118           String s = property.getName();
119           setText(s);
120           setToolTipText((new StringBuilder()).append(
121                   "<HTML><b>" + propertyType + " Property</b><br>").append(
122                   property.getONodeID()).append("</html>").toString());
123           setEnabled(true);
124         }
125         else if(obj instanceof PropertyValue) {
126 
127           PropertyValue property = (PropertyValue)obj;
128           String propertyType = "RDF";
129           if(property.getProperty() instanceof SymmetricProperty) {
130             setIcon(MainFrame.getIcon("ontology-symmetric-property"));
131             propertyType = "Symmetric";
132           }
133           else if(property.getProperty() instanceof AnnotationProperty) {
134             setIcon(MainFrame.getIcon("ontology-annotation-property"));
135             propertyType = "Annotation";
136           }
137           else if(property.getProperty() instanceof TransitiveProperty) {
138             setIcon(MainFrame.getIcon("ontology-transitive-property"));
139             propertyType = "Transitive";
140           }
141           else if(property.getProperty() instanceof ObjectProperty) {
142             setIcon(MainFrame.getIcon("ontology-object-property"));
143             propertyType = "Object";
144           }
145           else if(property.getProperty() instanceof DatatypeProperty) {
146             setIcon(MainFrame.getIcon("ontology-datatype-property"));
147             propertyType = "Datatype";
148           }
149           else {
150             setIcon(MainFrame.getIcon("ontology-rdf-property"));
151           }
152 
153           setFont(getFont().deriveFont(0));
154           String s = property.getProperty().getName();
155           setText(s);
156           setToolTipText((new StringBuilder()).append(
157                   "<HTML><b>" + propertyType + " Property Value</b><br>")
158                   .append(property.getProperty().getONodeID()).append("</html>")
159                   .toString());
160           setEnabled(true);
161         }
162       }
163       else if(j == 2) {
164         setIcon(null);
165         if(obj instanceof PropertyValue) {
166           PropertyValue property = (PropertyValue)obj;
167           setFont(getFont().deriveFont(0));
168           String s = "";
169           if(property.getValue() instanceof Literal) {
170             s = ((Literal)property.getValue()).getValue();
171           }
172           else {
173             s = property.getValue().toString();
174           }
175           setText(s);
176           setEnabled(true);
177         }
178         else if(obj instanceof KeyValuePair) {
179           KeyValuePair kvp = (KeyValuePair)obj;
180           setIcon(null);
181           setFont(getFont().deriveFont(0));
182           setText(kvp.getValue().toString());
183           setEnabled(true);
184         }
185         else if(obj instanceof RDFProperty) {
186           RDFProperty prop = (RDFProperty)obj;
187           String s = "";
188           if(prop instanceof DatatypeProperty) {
189             s = ((DatatypeProperty)prop).getDataType().getXmlSchemaURIString();
190           }
191           else if(prop instanceof ObjectProperty) {
192             @SuppressWarnings("deprecation")
193             Set<OResource> set = prop.getRange();
194             if(set == null || set.isEmpty()) {
195               s = "[ALL CLASSES]";
196             }
197             else {
198               s = "[";
199               boolean firstTime = true;
200               for(OResource res : set) {
201                 if(!firstTime) {
202                   s += ",";
203                 }
204                 else {
205                   firstTime = false;
206                 }
207                 s += res.getName();
208               }
209               s += "]";
210             }
211           }
212           else {
213             s = "[ALL RESOURCES]";
214           }
215           setIcon(null);
216           setFont(getFont().deriveFont(0));
217           setText(s);
218           setEnabled(true);
219         }
220         else {
221           setIcon(null);
222           setFont(getFont().deriveFont(0));
223           setText("");
224           setEnabled(false);
225         }
226       else if(j==3) {
227         if(obj instanceof PropertyValue) {
228           setIcon(MainFrame.getIcon("delete"));
229           setText("");
230           setEnabled(true);
231           setFont(getFont().deriveFont(0));
232         else {
233           setIcon(null);
234           setText("");
235           setEnabled(false);
236           setFont(getFont().deriveFont(0));
237         }
238       }
239       else {
240         setIcon(null);
241         setFont(getFont().deriveFont(0));
242         setText("");
243         setEnabled(false);
244       }
245     }
246     catch(Exception e) {
247       // refreshing errors hiding them
248     }
249     return component;
250   }
251 
252   protected PropertyDetailsTableModel propertyDetailsTableModel;
253 }