//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;i0){ Interval intV=null; for(int j=0;j0){ Vector intervalVector=new Vector(); for(int j=0;j0){ for(int j=0;j0){ for(int i=0;i0){ for(int i=0;i0){ for(int i=0;i0){ for(int i=0;i0){ for(int i=0;i0){ for(int j=0;j0){ for(int j=0;j0){ for(int j=0;j0){ // there are some graphical objects to display for(int j=0;j0){ for(int j=0;j0){ for(int j=0;j0){ for(int j=0;j0){ for(int j=0;j0){ for(int j=0;j0){ for(int j=0;j0){ for(int j=0;j0){ for(int j=0;j0){ for(int j=0;j0){ for(int j=0;j0){ for(int j=0;j0){ for(int j=0;j0){ for(int j=0;j0){ for(int j=0;j name(type):value */ private void initElements(){ ListExpr typeCopy = this.record.recTypes; ListExpr valCopy = this.record.recVal; ListExpr rest = null; ListExpr val = null; String typename = ""; try{ if(!typeCopy.isEmpty()){ rest = typeCopy.rest(); val = valCopy; // get first element if(rest.first().second().isAtom()){ // element is atom typename = rest.first().second().symbolValue(); Class t = Class.forName("viewer.hoese.algebras.Dspl" + typename); DsplGeneric elementClass = (DsplGeneric)t.newInstance(); // initialize element if(val.first()!=null){ elementClass.init(rest.first().first().toString() + " (" + typename.trim() + ")",0,0,rest.first().second(),val.first(),qrNEW); } else{ elementClass.init(rest.first().first().toString() + " (" + typename.trim() + ")",0,0,rest.first().second(),val,qrNEW); } } if(!rest.first().second().isAtom()){ // element is not atom typename = rest.first().second().first().symbolValue(); Class t = Class.forName("viewer.hoese.algebras.Dspl" + typename); DsplGeneric elementClass = (DsplGeneric)t.newInstance(); // initialize element elementClass.init(rest.first().first().toString() + " (" + rest.first().second().toString().trim() + ")",0,0,rest.first().second(),val.first(),qrNEW); } // iterate the rest of the record elements while(!rest.rest().isEmpty()){ // get next element rest = rest.rest(); if(val!=null){ val = val.rest(); } if(rest.first().second().isAtom()){ // element is atom typename = rest.first().second().symbolValue(); Class tN = Class.forName("viewer.hoese.algebras.Dspl" + typename); DsplGeneric elementClassN = (DsplGeneric)tN.newInstance(); // initialize element if(val!=null){ elementClassN.init(rest.first().first().toString() + " (" + typename.trim() + ")",0,0,rest.first().second(),val.first(),qrNEW); } else{ elementClassN.init(rest.first().first().toString() + " (" + typename.trim() + ")",0,0,rest.first().second(),new ListExpr(),qrNEW); } } if(!rest.first().second().isAtom()){ // element is not atom typename = rest.first().second().first().symbolValue(); Class tN = Class.forName("viewer.hoese.algebras.Dspl" + typename); DsplGeneric elementClassN = (DsplGeneric)tN.newInstance(); // initialize element elementClassN.init(rest.first().first().toString() + " (" + rest.first().second().toString().trim() + ")",0,0,rest.first().second(),val.first(),qrNEW); } } } } 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); } } /** * Returns the source of the set data. */ public Dsplrecord getSource(){ return record; } } /** Embedded class ShapeSet. * A class to handle the ShapeVector */ protected class ShapeSet{ private int[] set; private int lastSearch; private int lastPosition; /** Constructor. * @param position * @param count */ public ShapeSet(int position,int count){ set=new int[count]; for(int i=0;i