DetailsTableCellRenderer.java
001 /*
002  *  Copyright (c) 1995-2010, 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.*;
017 import gate.gui.MainFrame;
018 import java.awt.Component;
019 import javax.swing.*;
020 import javax.swing.table.DefaultTableCellRenderer;
021 
022 /**
023  * A Class that specifies how each node in the details panel should look
024  * like.
025  
026  @author niraj
027  
028  */
029 public class DetailsTableCellRenderer extends DefaultTableCellRenderer {
030   private static final long serialVersionUID = 3257572784619337525L;
031 
032   public Component getTableCellRendererComponent(JTable table, Object value,
033                     boolean isSelected, boolean hasFocus, int row, int column) {
034     super.getTableCellRendererComponent(
035       table, value, isSelected, hasFocus, row, column);
036     setText(null);
037     setToolTipText(null);
038     setIcon(null);
039     setEnabled(true);
040 
041     if(column == DetailsTableModel.EXPANDED_COLUMN) {
042       if (value == null) {
043         // render nothing
044       else if (value.equals("empty")) {
045         setEnabled(false);
046         setIcon(MainFrame.getIcon("closed"));
047       else {
048         setEnabled(true);
049         setIcon(MainFrame.getIcon((Stringvalue));
050       }
051     }
052     else if(column == DetailsTableModel.LABEL_COLUMN) {
053       if(value instanceof DetailsGroup) {
054         DetailsGroup detailsgroup = (DetailsGroupvalue;
055         setText(detailsgroup.getName());
056         setEnabled(detailsgroup.getSize() 0);
057       }
058       else if(value instanceof KeyValuePair) {
059         KeyValuePair kvp = (KeyValuePairvalue;
060         setIcon(MainFrame.getIcon("empty"));
061         setText(kvp.getKey());
062       }
063       else if(value instanceof Restriction) {
064         OClass tclass = (OClassvalue;
065         setIcon(MainFrame.getIcon("ontology-restriction"));
066         setText(tclass.getName());
067         setToolTipText(tclass.getURI().toString());
068       }
069       else if(value instanceof OClass) {
070         OClass tclass = (OClassvalue;
071         setIcon(MainFrame.getIcon("ontology-class"));
072         setText(tclass.getName());
073         setToolTipText(tclass.getURI().toString());
074       }
075       else if(value instanceof OInstance) {
076         OInstance oinstance = (OInstancevalue;
077         setIcon(MainFrame.getIcon("ontology-instance"));
078         setText(oinstance.getName());
079         setToolTipText(oinstance.getURI().toString());
080       }
081       else if(value instanceof RDFProperty) {
082         RDFProperty property = (RDFPropertyvalue;
083         String propertyType = "RDF";
084         if(property instanceof SymmetricProperty) {
085           setIcon(MainFrame.getIcon("ontology-symmetric-property"));
086           propertyType = "Symmetric";
087         }
088         else if(property instanceof AnnotationProperty) {
089           setIcon(MainFrame.getIcon("ontology-annotation-property"));
090           propertyType = "Annotation";
091         }
092         else if(property instanceof TransitiveProperty) {
093           setIcon(MainFrame.getIcon("ontology-transitive-property"));
094           propertyType = "Transitive";
095         }
096         else if(property instanceof ObjectProperty) {
097           setIcon(MainFrame.getIcon("ontology-object-property"));
098           propertyType = "Object";
099         }
100         else if(property instanceof DatatypeProperty) {
101           setIcon(MainFrame.getIcon("ontology-datatype-property"));
102           propertyType = "Datatype";
103         }
104         else setIcon(MainFrame.getIcon("ontology-rdf-property"));
105         String s = property.getName();
106         setText(s);
107         setToolTipText((new StringBuilder()).append(
108                 "<HTML><b>" + propertyType + " Property</b><br>").append(
109                 property.getURI()).append("</html>").toString());
110       }
111       else if(value instanceof PropertyValue) {
112 
113         PropertyValue property = (PropertyValuevalue;
114         String propertyType = "RDF";
115         if(property.getProperty() instanceof SymmetricProperty) {
116           setIcon(MainFrame.getIcon("ontology-symmetric-property"));
117           propertyType = "Symmetric";
118         }
119         else if(property.getProperty() instanceof AnnotationProperty) {
120           setIcon(MainFrame.getIcon("ontology-annotation-property"));
121           propertyType = "Annotation";
122         }
123         else if(property.getProperty() instanceof TransitiveProperty) {
124           setIcon(MainFrame.getIcon("ontology-transitive-property"));
125           propertyType = "Transitive";
126         }
127         else if(property.getProperty() instanceof ObjectProperty) {
128           setIcon(MainFrame.getIcon("ontology-object-property"));
129           propertyType = "Object";
130         }
131         else if(property.getProperty() instanceof DatatypeProperty) {
132           setIcon(MainFrame.getIcon("ontology-datatype-property"));
133           propertyType = "Datatype";
134         }
135         else {
136           setIcon(MainFrame.getIcon("ontology-rdf-property"));
137         }
138         String s = property.getProperty().getName();
139         setText(s);
140         setToolTipText((new StringBuilder()).append(
141                 "<HTML><b>" + propertyType + " Property Value</b><br>")
142                 .append(property.getProperty().getURI()).append("</html>")
143                 .toString());
144       }
145     }
146     else if(column == DetailsTableModel.VALUE_COLUMN) {
147       if(value == null || value.equals("")) { return this}
148       setText(value.toString());
149       Object property = table.getValueAt(row, DetailsTableModel.LABEL_COLUMN);
150        if(property instanceof PropertyValue) {
151         setToolTipText("Double-click to edit the value");
152       }
153       else if(property instanceof RDFProperty) {
154         setToolTipText("Double-click to add a property value");
155       }
156     }
157     else if(column == DetailsTableModel.DELETE_COLUMN) {
158       if(value instanceof PropertyValue) {
159         setIcon(MainFrame.getIcon("delete"));
160       }
161       else {
162         setEnabled(false);
163       }
164     }
165     else {
166       setEnabled(false);
167     }
168     return this;
169   }
170 }