DetailsTableCellRenderer.java
001 /*
002  *  Copyright (c) 1995-2012, The University of Sheffield. See the file
003  *  COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt
004  *
005  *  This file is part of GATE (see http://gate.ac.uk/), and is free
006  *  software, licenced under the GNU Library General Public License,
007  *  Version 2, June 1991 (in the distribution as file licence.html,
008  *  and also available at http://gate.ac.uk/gate/licence.html).
009  *
010  *  Niraj Aswani, 09/March/07
011  *
012  *  $Id: DetailsTableCellRenderer.html,v 1.0 2007/03/09 16:13:01 niraj Exp $
013  */
014 package gate.gui.ontology;
015 
016 import gate.creole.ontology.AnnotationProperty;
017 import gate.creole.ontology.DatatypeProperty;
018 import gate.creole.ontology.OClass;
019 import gate.creole.ontology.OInstance;
020 import gate.creole.ontology.ObjectProperty;
021 import gate.creole.ontology.RDFProperty;
022 import gate.creole.ontology.Restriction;
023 import gate.creole.ontology.SymmetricProperty;
024 import gate.creole.ontology.TransitiveProperty;
025 import gate.gui.MainFrame;
026 
027 import java.awt.Component;
028 
029 import javax.swing.JTable;
030 import javax.swing.table.DefaultTableCellRenderer;
031 
032 /**
033  * A Class that specifies how each node in the details panel should look
034  * like.
035  
036  @author niraj
037  
038  */
039 public class DetailsTableCellRenderer extends DefaultTableCellRenderer {
040   private static final long serialVersionUID = 3257572784619337525L;
041 
042   @Override
043   public Component getTableCellRendererComponent(JTable table, Object value,
044                     boolean isSelected, boolean hasFocus, int row, int column) {
045     super.getTableCellRendererComponent(
046       table, value, isSelected, hasFocus, row, column);
047     setText(null);
048     setToolTipText(null);
049     setIcon(null);
050     setEnabled(true);
051 
052     if(column == DetailsTableModel.EXPANDED_COLUMN) {
053       if (value == null) {
054         // render nothing
055       else if (value.equals("empty")) {
056         setEnabled(false);
057         setIcon(MainFrame.getIcon("closed"));
058       else {
059         setEnabled(true);
060         setIcon(MainFrame.getIcon((Stringvalue));
061       }
062     }
063     else if(column == DetailsTableModel.LABEL_COLUMN) {
064       if(value instanceof DetailsGroup) {
065         DetailsGroup detailsgroup = (DetailsGroupvalue;
066         setText(detailsgroup.getName());
067         setEnabled(detailsgroup.getSize() 0);
068       }
069       else if(value instanceof KeyValuePair) {
070         KeyValuePair kvp = (KeyValuePairvalue;
071         setIcon(MainFrame.getIcon("empty"));
072         setText(kvp.getKey());
073       }
074       else if(value instanceof Restriction) {
075         OClass tclass = (OClassvalue;
076         setIcon(MainFrame.getIcon("ontology-restriction"));
077         setText(tclass.getName());
078         setToolTipText(tclass.getONodeID().toString());
079       }
080       else if(value instanceof OClass) {
081         OClass tclass = (OClassvalue;
082         setIcon(MainFrame.getIcon("ontology-class"));
083         setText(tclass.getName());
084         setToolTipText(tclass.getONodeID().toString());
085       }
086       else if(value instanceof OInstance) {
087         OInstance oinstance = (OInstancevalue;
088         setIcon(MainFrame.getIcon("ontology-instance"));
089         setText(oinstance.getName());
090         setToolTipText(oinstance.getONodeID().toString());
091       }
092       else if(value instanceof RDFProperty) {
093         RDFProperty property = (RDFPropertyvalue;
094         String propertyType = "RDF";
095         if(property instanceof SymmetricProperty) {
096           setIcon(MainFrame.getIcon("ontology-symmetric-property"));
097           propertyType = "Symmetric";
098         }
099         else if(property instanceof AnnotationProperty) {
100           setIcon(MainFrame.getIcon("ontology-annotation-property"));
101           propertyType = "Annotation";
102         }
103         else if(property instanceof TransitiveProperty) {
104           setIcon(MainFrame.getIcon("ontology-transitive-property"));
105           propertyType = "Transitive";
106         }
107         else if(property instanceof ObjectProperty) {
108           setIcon(MainFrame.getIcon("ontology-object-property"));
109           propertyType = "Object";
110         }
111         else if(property instanceof DatatypeProperty) {
112           setIcon(MainFrame.getIcon("ontology-datatype-property"));
113           propertyType = "Datatype";
114         }
115         else setIcon(MainFrame.getIcon("ontology-rdf-property"));
116         String s = property.getName();
117         setText(s);
118         setToolTipText((new StringBuilder()).append(
119                 "<HTML><b>" + propertyType + " Property</b><br>").append(
120                 property.getONodeID()).append("</html>").toString());
121       }
122       else if(value instanceof PropertyValue) {
123 
124         PropertyValue property = (PropertyValuevalue;
125         String propertyType = "RDF";
126         if(property.getProperty() instanceof SymmetricProperty) {
127           setIcon(MainFrame.getIcon("ontology-symmetric-property"));
128           propertyType = "Symmetric";
129         }
130         else if(property.getProperty() instanceof AnnotationProperty) {
131           setIcon(MainFrame.getIcon("ontology-annotation-property"));
132           propertyType = "Annotation";
133         }
134         else if(property.getProperty() instanceof TransitiveProperty) {
135           setIcon(MainFrame.getIcon("ontology-transitive-property"));
136           propertyType = "Transitive";
137         }
138         else if(property.getProperty() instanceof ObjectProperty) {
139           setIcon(MainFrame.getIcon("ontology-object-property"));
140           propertyType = "Object";
141         }
142         else if(property.getProperty() instanceof DatatypeProperty) {
143           setIcon(MainFrame.getIcon("ontology-datatype-property"));
144           propertyType = "Datatype";
145         }
146         else {
147           setIcon(MainFrame.getIcon("ontology-rdf-property"));
148         }
149         String s = property.getProperty().getName();
150         setText(s);
151         setToolTipText((new StringBuilder()).append(
152                 "<HTML><b>" + propertyType + " Property Value</b><br>")
153                 .append(property.getProperty().getONodeID()).append("</html>")
154                 .toString());
155       }
156     }
157     else if(column == DetailsTableModel.VALUE_COLUMN) {
158       if(value == null || value.equals("")) { return this}
159       setText(value.toString());
160       Object property = table.getValueAt(row, DetailsTableModel.LABEL_COLUMN);
161        if(property instanceof PropertyValue) {
162         setToolTipText("Double-click to edit the value");
163       }
164       else if(property instanceof RDFProperty) {
165         setToolTipText("Double-click to add a property value");
166       }
167     }
168     else if(column == DetailsTableModel.DELETE_COLUMN) {
169       if(value instanceof PropertyValue) {
170         setIcon(MainFrame.getIcon("delete"));
171       }
172       else {
173         setEnabled(false);
174       }
175     }
176     else {
177       setEnabled(false);
178     }
179     return this;
180   }
181 }