//This file is part of SECONDO. //Copyright (C) 2004, University in Hagen, Department of Computer Science, //Database Systems for New Applications. //SECONDO is free software; you can redistribute it and/or modify //it under the terms of the GNU General Public License as published by //the Free Software Foundation; either version 2 of the License, or //(at your option) any later version. //SECONDO is distributed in the hope that it will be useful, //but WITHOUT ANY WARRANTY; without even the implied warranty of //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //GNU General Public License for more details. //You should have received a copy of the GNU General Public License //along with SECONDO; if not, write to the Free Software //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA package viewer.hoese.algebras; import sj.lang.ListExpr; import viewer.*; import viewer.hoese.*; import java.util.*; import javax.swing.*; import java.awt.*; import java.awt.geom.*; import gui.SecondoObject; import tools.Reporter; /** * A displayclass for the record-type. * The displayclass for records creates one single query result. * The showing of the single record elements is delegated to the corresponding * display classes of the element types.
* *
Implements
* ExternDisplay: interface to enable displaying the record single elements
* in a separate frame
* Timed: interface for displaying temporal elements
* DsplGraph: interface for displaying graphical elements
* RenderAttribute: interface for setting the render attribute
* LabelAttribute: interface for setting the label attribute
* DisplayComplex: interface for displaying complex elements
*
* @author Sabrina Straub
* @version 1.0 for FaPra WS 2009/2010
*/
public class Dsplrecord extends DsplGeneric implements ExternDisplay, Timed,
DsplGraph, RenderAttribute, LabelAttribute,
DisplayComplex {
/** Frame to show record elements */
private RecordFrame display=null;
/** The Value ListExpr of the given secondo Object */
private ListExpr recVal;
/** The Types ListExpr of the given secondo Object */
private ListExpr recTypes;
/** A structur to store the instances of the record elements display classes */
private Vector graphVector = new Vector();
/** A structure to store the amount of shapes per object */
private Vector shapeVector = new Vector();
/** The category of this object.
* init with value defaultcategory */
private Category cat = Category.getDefaultCat();
/** The layer in which this object is drawn */
private Layer refLayer;
/** The subtype of the record */
private String subtype;
/** Dsplrecord Constructor.
* The constructor initializes a new frame for external display function
* when a new record object needs to be displayed.
*/
public Dsplrecord() {
if(this.display==null){
this.display = new RecordFrame();
}
}
/*
* Implemented methods to represent the query result
*/
/** Dsplrecord init.
* This method is used to analyse the types and values of this record type.
*
* @param type datatype record with its attribute-types
* @param value A listexpr of the attribute-values
* @param qr The queryresultlist to add alphanumeric representation
*/
public void init(String name, int nameWidth, int indent, ListExpr type,
ListExpr value, QueryResult qr) {
// create a new entry in query result
if(type.isAtom()){
this.subtype=getTypeName(type).symbolValue();
}
else{
this.subtype=getTypeName(type).toString();
}
// add entry
qr.addEntry(this);
this.recVal = value;
this.recTypes = type;
// initialize the record elements
initRecordElements(value, type);
}
/** Dsplrecord isGraph.
* A method to determine wether a record elements type is an instance of DsplGraph
* @param typename
* @return boolean result of the determination
* @throws ClassNotFoundException
* @throws InstantiationException
* @throws IllegalAccessException
*/
public boolean isGraph(String typename){
try{
Class c=Class.forName("viewer.hoese.algebras."+"Dspl" + typename);
Object o = c.newInstance();
if(o instanceof DsplGraph){
return true;
}
else{
return false;
}
}catch(ClassNotFoundException e){
Reporter.showError("No Displayclass found for record element type: " + typename);
}catch(InstantiationException e){
Reporter.showError("Displayclass for record element type " + typename + " could not be initialized!");
}catch(IllegalAccessException e){
Reporter.showError("Error while accessing DisplayClass for record element type :" + typename);
}
return false;
}
/** Dsplrecord toString.
* A method to return the textual represantation of a record
* as query result entry
* @return the textual Represantation as a string
*/
public String toString() {
return this.subtype;
}
/** Dsplrecord getAttrName.
* A method of the DsplBase-Interface.
* @return The name of the Attribute
*/
public String getAttrName() {
return this.subtype;
}
/** Dsplrecord getTypeName.
* A method to return the typename of the given type
* @param type
* @return the subtype as an ListExpr object
*/
public ListExpr getTypeName(ListExpr type){
ListExpr typename=null;
typename = type.first();
return typename;
}
/** Dsplrecord initRecordElements.
* A method that iterates over all record elements and initializes them.
* All graphical elements are stored in the graphVector, to ensure that all
* elements can be displayed.
* @param value
* @param type
* @throws ClassNotFoundException
* @throws InstantiationException
* @throws IllegalAccessException
*/
private void initRecordElements(ListExpr value, ListExpr type){
ListExpr val;
ListExpr rest;
String typename = "";
try{
if(!type.isEmpty()){
rest = type.rest();
val = value;
if(rest.first().second().isAtom() == true){
// the first element is atom
if(isGraph(rest.first().second().symbolValue())){
// element is graph
typename = rest.first().second().symbolValue();
Class to = Class.forName("viewer.hoese.algebras."+"Dspl" + typename);
DsplGraph elementClassO = (DsplGraph)to.newInstance();
// add element to graphVector
graphVector.addElement(elementClassO);
// initialize element
if(val.first() == null){
elementClassO.init(typename,0,0,rest.first().second(),val,new QueryResult(new SecondoObject("recordElem",val),true));
}
else{
elementClassO.init(typename,0,0,rest.first().second(),val.first(),new QueryResult(new SecondoObject("recordElem",val.first()),true));
}
}
}
if(rest.first().second().isAtom() == false){
// the first element is not atom
if(isGraph(rest.first().second().first().symbolValue())){
// element is graph
typename = rest.first().second().first().symbolValue();
Class to = Class.forName("viewer.hoese.algebras."+"Dspl" + typename);
DsplGraph elementClassO = (DsplGraph)to.newInstance();
// add element to graphVector
graphVector.addElement(elementClassO);
// initialize element - use complete type (including subelements)
elementClassO.init(rest.first().second().toString(),0,0,rest.first().second(),val.first(),new QueryResult(new SecondoObject("recordElem",val.first()),true));
}
}
while(!rest.rest().isEmpty()){
// iterate the other elements of the record
rest = rest.rest();
if(val!=null){
val = val.rest();
}
if(rest.first().second().isAtom() == true){
// element is atom
if(isGraph(rest.first().second().symbolValue())){
typename = rest.first().second().symbolValue();
// element is graph
Class to = Class.forName("viewer.hoese.algebras."+"Dspl" + typename);
DsplGraph elementClassO = (DsplGraph)to.newInstance();
// add element to graphVector
graphVector.addElement(elementClassO);
// initialize element
if(val == null){
elementClassO.init(typename,0,0,rest.first().second(), new ListExpr(),new QueryResult(new SecondoObject("recordElem",val),true));
}
else{
elementClassO.init(typename,0,0,rest.first().second(),val.first(),new QueryResult(new SecondoObject("recordElem",val.first()),true));
}
}
}
if(rest.first().second().isAtom() == false){
// element is not atom
if(isGraph(rest.first().second().first().symbolValue())){
// element is graph
typename = rest.first().second().first().symbolValue();
Class to = Class.forName("viewer.hoese.algebras."+"Dspl" + typename);
DsplGraph elementClassO = (DsplGraph)to.newInstance();
// add element to graphVector
graphVector.addElement(elementClassO);
// initialize element - use complete type (including subelements)
elementClassO.init(rest.first().second().toString(),0,0,rest.first().second(),val.first(),new QueryResult(new SecondoObject("recordElem",val.first()),true));
}
}
}
}
}
catch(ClassNotFoundException e){
Reporter.showError("No Displayclass found for record element type: " + typename);
}catch(InstantiationException e){
Reporter.showError("Displayclass for record element type " + typename + " could not be initialized!");
}catch(IllegalAccessException e){
Reporter.showError("Error while accessing DisplayClass for record element type: " + typename);
}
}
/** Dsplrecord findShape.
* A method to find a specific shape in the shapeVector
* @return the position in the shapeVector
* @param num
*/
public int findShape(int num){
for(int i=0;i