📄 relationtype.java
字号:
package toocom.ocgl;
import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;
import java.awt.font.*;
/**
* This class represents the relation types in the ontology. A relation type has a signature
* and some properties.
*
* @author Fr閐閞ic F黵st
*/
public class RelationType extends ConceptualPrimitive{
private Signature signature;
/** Creates a generic relation type with the given arity of the signature and the given terms.
* This method can throws an IndexOutOfBoundsException if the arity is less than 2.
*/
public RelationType(int arity,Terms terms) throws IndexOutOfBoundsException{
super(terms);
this.signature = new Signature(arity);
}
/** Creates a generic relation type with the given arity of the signature and an undefined terms.
* This method can throws an IndexOutOfBoundsException if the arity is less than 2.
*/
public RelationType(int arity) throws IndexOutOfBoundsException{
super(Terms.getUndefinedTerms());
this.signature = new Signature(arity);
}
/** Returns a binary relation type with an undefined label. */
public static RelationType getUndefinedRelationType(){
return new RelationType(2);
}
public String toString(Language l){
return (this.getTerm(l).concat(this.getSignature().toString(l)));
}
public void setSignature(Signature signature){
this.signature = signature;
}
/** Returns the index of the given concept type in the signature of the relation or -1
* if the concept type does not appear in the signature. */
public int linkConceptType(ConceptType ct){
for(int i = 1;i < (this.getArity() + 1);i ++){
ConceptType contyp = this.getSignature().getConceptType(i);
if((contyp != null) && contyp.equals(ct)) return i;
}
return -1;
}
public LinkedList getLinkedConceptTypes(){
LinkedList result = new LinkedList();
for(int i = 1;i <= this.getArity();i ++){
result.add(this.signature.getConceptType(i));
}
return result;
}
public Signature getSignature(){
return this.signature;
}
public void setArity(int arity){
if(this.signature.getArity() != arity){
this.signature.setArity(arity);
}
}
public int getArity(){
return this.signature.getArity();
}
/** Returns the bounds of the image according to the font size of the given Graphics. */
public RectangularShape getBounds(Graphics g,Language l){
String s = this.toString(l);
return GraphicsToolkit.getEllipticalBounds(g,s,new Point(this.x,this.y));
}
/** Only draw the lines which represent the is-a link between the relation type and his children. */
public void paintChildrenLinks(Graphics g,Language l){
g.setColor(CGConstants.IS_A_LINK_COLOR);
for(Iterator i = this.getChildren().iterator();i.hasNext();){
RelationType rtTemp = (RelationType) i.next();
Point p1 = rtTemp.getCenter();
Point p2 = this.getCenter();
GraphicsToolkit.paintArrowLine(g,p1,p2);
}
}
/** Paint the relation type with its label in an elliptical shape. */
public void paintObject(Graphics g,Language l){
this.paintObject(g,CGConstants.RELATION_TYPE_COLOR,CGConstants.RELATION_TYPE_BORDER_COLOR,CGConstants.SELECTED_RELATION_TYPE_BORDER_COLOR,CGConstants.HIGHLIGHTED_RELATION_TYPE_COLOR,CGConstants.RELATION_TYPE_TEXT_COLOR,l);
}
/** Destroy the relation type and the link between it and others conceptual primitives. */
public void destroy(Ontology onto){
super.destroy(onto);
for(Iterator i = onto.getRelations().iterator();i.hasNext();){
Relation r = (Relation) i.next();
if((r.getType() != null) && r.getType().equals(this)) r.setType(RelationType.getUndefinedRelationType());
}
onto.removeRelationType(this);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -