[Nextobjects-devel] nextobjects/nextobjects/src/org/devaki/nextobjects/workspace/models BaseModel.ja
Status: Alpha
Brought to you by:
eflorent
From: <efl...@us...> - 2003-06-04 19:29:46
|
Update of /cvsroot/nextobjects/nextobjects/nextobjects/src/org/devaki/nextobjects/workspace/models In directory sc8-pr-cvs1:/tmp/cvs-serv8358/src/org/devaki/nextobjects/workspace/models Modified Files: BaseModel.java ConceptualModel.java PhysicalModel.java Log Message: Refactored graphics- Index: BaseModel.java =================================================================== RCS file: /cvsroot/nextobjects/nextobjects/nextobjects/src/org/devaki/nextobjects/workspace/models/BaseModel.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** BaseModel.java 2 Jun 2003 20:03:45 -0000 1.10 --- BaseModel.java 4 Jun 2003 19:29:41 -0000 1.11 *************** *** 21,25 **** import java.io.Serializable; - import java.awt.Rectangle; import javax.swing.JPanel; import java.util.Vector; --- 21,24 ---- *************** *** 29,34 **** import org.devaki.nextobjects.util.NORedoLog; import org.devaki.nextobjects.workspace.models.objects.InheritanceLink; ! import org.devaki.nextobjects.workspace.models.objects.BaseClass; ! import org.devaki.nextobjects.constants.CstGraphics; /** --- 28,32 ---- import org.devaki.nextobjects.util.NORedoLog; import org.devaki.nextobjects.workspace.models.objects.InheritanceLink; ! import org.devaki.nextobjects.workspace.models.objects.BaseObject; /** *************** *** 37,41 **** * @task check BaseModel.java against maven's project.xml DTD */ ! public class BaseModel implements Serializable { /** --- 35,39 ---- * @task check BaseModel.java against maven's project.xml DTD */ ! public abstract class BaseModel implements Serializable { /** *************** *** 196,204 **** /** - * the model bounds - */ - private Rectangle rectangle; - - /** * Construct a standard NOModel * @param pName the model name --- 194,197 ---- *************** *** 211,214 **** --- 204,214 ---- redoLog = new NORedoLog(); } + + /** + * return the objects of the model + * @return array of BaseObject + */ + public abstract BaseObject[] getModelObjects(); + /** *************** *** 232,238 **** /** * Set the panel associated ! * @param pFrame the panel */ ! public void setPanel(JPanel pPanel) { this.panel = pPanel; } /** --- 232,241 ---- /** * Set the panel associated ! * @param pPanel the panel */ ! public void setPanel(JPanel pPanel) ! { ! this.panel = pPanel; ! } /** *************** *** 493,497 **** * @return the panel */ ! public JPanel getPanel() { return this.panel; } /** --- 496,503 ---- * @return the panel */ ! public JPanel getPanel() ! { ! return this.panel; ! } /** *************** *** 764,832 **** } - /** - * Return a cached rectangle/bounds for the model - * @return the rectangle - */ - public Rectangle getRectangle() - { - if (rectangle == null) - { - rectangle = calculateRectangle(); - } - - if (rectangle.x == 999990) - { - rectangle = - new Rectangle( - CstGraphics.MODEL_INITIAL_POSITION.x, - CstGraphics.MODEL_INITIAL_POSITION.y, - 20, - 20); - } - return rectangle; - } - /** - * Calculate a cached model rectangle - * @return the rectangle - */ - public Rectangle calculateRectangle() - { - int xmin = 1000000; - int ymin = 1000000; - int xmax = 0; - int ymax = 0; - int xtmpmin = 0; - int ytmpmin = 0; - int xtmpmax = 0; - int ytmpmax = 0; - for (int i = 0; i < this.getClasses().size(); i++) - { - BaseClass baseObject = (BaseClass) this.getClasses().elementAt(i); - xtmpmin = (int) baseObject.getObjectView().getLocation().getX(); - ytmpmin = (int) baseObject.getObjectView().getLocation().getY(); - xtmpmax = - baseObject.getObjectView().getLocation().x - + baseObject.getObjectView().getSize().width; - ytmpmax = - baseObject.getObjectView().getLocation().y - + baseObject.getObjectView().getSize().height; - if (xtmpmin < xmin) - xmin = xtmpmin; - if (ytmpmin < ymin) - ymin = ytmpmin; - if (xtmpmax > xmax) - xmax = xtmpmax; - if (ytmpmax > ymax) - ymax = ytmpmax; - } - rectangle = - new Rectangle( - Math.abs(xmin - 10), - Math.abs(ymin - 10), - xmax - xmin + 20, - ymax - ymin + 20); - return rectangle; - } /** * The model is saved --- 770,774 ---- Index: ConceptualModel.java =================================================================== RCS file: /cvsroot/nextobjects/nextobjects/nextobjects/src/org/devaki/nextobjects/workspace/models/ConceptualModel.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ConceptualModel.java 31 May 2003 11:48:34 -0000 1.5 --- ConceptualModel.java 4 Jun 2003 19:29:41 -0000 1.6 *************** *** 32,36 **** /** * The Conceptual Data Model ! * @author efl...@de... */ public class ConceptualModel extends BaseModel implements Serializable --- 32,36 ---- /** * The Conceptual Data Model ! * @author efl...@de... */ public class ConceptualModel extends BaseModel implements Serializable *************** *** 132,136 **** * @return the base objects */ ! public BaseObject[] getModel0bjects() { --- 132,136 ---- * @return the base objects */ ! public BaseObject[] getModelObjects() { Index: PhysicalModel.java =================================================================== RCS file: /cvsroot/nextobjects/nextobjects/nextobjects/src/org/devaki/nextobjects/workspace/models/PhysicalModel.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** PhysicalModel.java 25 May 2003 08:02:36 -0000 1.5 --- PhysicalModel.java 4 Jun 2003 19:29:41 -0000 1.6 *************** *** 6,10 **** 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. This program is distributed in the hope that it will --- 6,10 ---- 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. This program is distributed in the hope that it will *************** *** 28,202 **** public class PhysicalModel extends BaseModel implements Serializable { ! /** Variables **/ ! // List of tables in the model ! private Vector tables = new Vector(); ! // List of constraints in the model ! private Vector constraints = new Vector(); ! // Graphical View ! private PhysicalView myPhysicalView; ! // If a SQL file has been generated for this model, this variable indicates ! // where to find it ! private String sqlFile; ! /** ! * Construct a new 'PhysicalModel' object ! * @param pName Nae of the model ! */ ! public PhysicalModel(String pName) ! { ! super(pName); ! } ! /** ! * Return the best possible filename for save ! * @return ! */ ! public String getBestFilename() ! { ! if (this.getFileForSave() == null) ! { ! return (new StringBuffer().append(this.getCode()) ! .append(".pdm")) ! .toString(); ! } ! else ! { ! return this.getFileForSave(); ! } ! } ! /** ! * Get the model view ! * @return ! */ ! public PhysicalView getPhysicalView() { return this.myPhysicalView; } ! /** ! * Get the list of tables in the model ! * @return ! */ ! public Vector getTables() { return this.tables; } ! /** ! * Get the list of constraints in the model ! * @return ! */ ! public Vector getConstraints() { return this.constraints; } ! /** ! * Get constraint(s) for the given table ! * @param t ! * @return ! */ ! public Vector getConstraints(Table t) ! { ! Vector cst = new Vector(); ! for (int i = 0; i < this.countConstraint(); i++) ! { ! if (this.getConstraintAt(i).getParentClass().equals(t)) ! { ! cst.addElement(this.getConstraintAt(i)); ! } ! } ! return cst; ! } ! /** ! * Get table for the given tableCode ! * @param pString ! * @return ! */ ! public Table getTableForId(String pString) ! { ! Table tmp=null; ! for (int i=0;i<getTables().size();i++) { ! if (this.getTableAt(i).getCode().equals(pString)) { ! tmp=(Table)this.tables.elementAt(i); ! } ! } ! return tmp; ! } ! /** ! * Return the table identified by the parameter in the list of tables. ! * @param at ! * @return ! */ ! public Table getTableAt(int at) ! { ! return (Table)this.tables.elementAt(at); ! } ! /** ! * Return the constraint identified by the parameter in the list ! * of constraints. ! * @param at ! * @return ! */ ! public Constraint getConstraintAt(int at) ! { ! return (Constraint)constraints.elementAt(at); ! } ! /** ! * Return the number of tables in the model ! * @return ! */ ! public int countTable() { return this.tables.size(); } ! /** ! * Return the number of constraint in the model ! * @return ! */ ! public int countConstraint () { return this.constraints.size(); } ! /** ! * Get the path for the SQL file generated from this model ! * @return ! */ ! public String getSqlFile() { return this.sqlFile; } ! /** ! * Set the path for the SQL file generated from this model ! * @param pSqlFile ! */ ! public void setSqlFile(String pSqlFile) { this.sqlFile = pSqlFile; } ! /** ! * Set the model view ! * @param pView ! */ ! public void setPhysicalView(PhysicalView pView) { this.myPhysicalView = pView; } ! /* ! * Conveniency method wich return all the objects in the models ! * in this models. -- OPTIMIZABLE, SUPPRESIBLE? ! */ ! public BaseObject[] getModel0bjects() { ! BaseObject[] baseObjects=new BaseObject[ tables.size() ! + getInheritanceLinks().size() ! + constraints.size() ! ]; ! int offset=0; ! for (int i = 0; i < tables.size(); i++) ! { ! baseObjects[offset]=getTableAt(i); ! offset++; ! } ! for (int i=0; i<getInheritanceLinks().size();i++) ! { ! baseObjects[offset]=getInheritanceLinkAt(i); ! offset++; ! } ! for (int i=0; i<constraints.size();i++) ! { ! baseObjects[offset]=getConstraintAt(i); ! offset++; ! } ! return baseObjects; ! } } --- 28,242 ---- + /** + * Physical model represent the database as it is. + * + *@see http://www.devaki.org/pdm.html + * @author efl...@de... + */ public class PhysicalModel extends BaseModel implements Serializable { ! /** ! * tables ! */ ! private Vector tables = new Vector(); + /** + * constraints + */ + private Vector constraints = new Vector(); ! /** ! * the model view ! */ ! private PhysicalView myPhysicalView; + /** + * If a SQL file has been generated for this model, this variable indicates + * where to find it + */ + private String sqlFile; ! /** ! * Construct a new 'PhysicalModel' object ! * @param pName Nae of the model ! */ ! public PhysicalModel(String pName) ! { ! super(pName); ! } ! /** ! * Return the best possible filename for save ! * @return filename ! */ ! public String getBestFilename() ! { ! if (this.getFileForSave() == null) ! { ! return (new StringBuffer().append(this.getCode()).append(".pdm")) ! .toString(); ! } else ! { ! return this.getFileForSave(); ! } ! } ! /** ! * Get the model view ! * @return model view ! */ ! public PhysicalView getPhysicalView() ! { ! return this.myPhysicalView; ! } ! /** ! * Get the list of tables in the model ! * @return tables ! */ ! public Vector getTables() ! { ! return this.tables; ! } ! /** ! * Get the list of constraints in the model ! * @return constraints ! */ ! public Vector getConstraints() ! { ! return this.constraints; ! } ! /** ! * Get constraint(s) for the given table ! * @param t the context table ! * @return vctConstraints ! */ ! public Vector getConstraints(Table t) ! { ! Vector cst = new Vector(); ! for (int i = 0; i < this.countConstraint(); i++) ! { ! if (this.getConstraintAt(i).getParentClass().equals(t)) ! { ! cst.addElement(this.getConstraintAt(i)); ! } ! } ! return cst; ! } ! /** ! * Get table for the given tableCode ! * @param pString the table code ! * @return table ! */ ! public Table getTableForId(String pString) ! { ! Table tmp = null; ! for (int i = 0; i < getTables().size(); i++) ! { ! if (this.getTableAt(i).getCode().equals(pString)) ! { ! tmp = (Table) this.tables.elementAt(i); ! } ! } ! return tmp; ! } ! /** ! * Return the table identified by the parameter in the list of tables. ! * @param at index ! * @return table ! */ ! public Table getTableAt(int at) ! { ! return (Table) this.tables.elementAt(at); ! } ! /** ! * Return the constraint identified by the parameter in the list ! * of constraints. ! * @param at index ! * @return constraint ! */ ! public Constraint getConstraintAt(int at) ! { ! return (Constraint) constraints.elementAt(at); ! } ! /** ! * Return the number of tables in the model ! * @return count ! */ ! public int countTable() ! { ! return this.tables.size(); ! } ! /** ! * Return the number of constraint in the model ! * @return count ! */ ! public int countConstraint() ! { ! return this.constraints.size(); ! } ! /** ! * Get the path for the SQL file generated from this model ! * @return filename ! */ ! public String getSqlFile() ! { ! return this.sqlFile; ! } ! /** ! * Set the path for the SQL file generated from this model ! * @param pSqlFile filename ! */ ! public void setSqlFile(String pSqlFile) ! { ! this.sqlFile = pSqlFile; ! } ! /** ! * Set the model view ! * @param pView the model view ! */ ! public void setPhysicalView(PhysicalView pView) ! { ! this.myPhysicalView = pView; ! } ! ! /** ! * Conveniency method wich return all the objects in the models ! * @return array of base objects ! */ ! public BaseObject[] getModelObjects() ! { ! ! BaseObject[] baseObjects = ! new BaseObject[tables.size() ! + getInheritanceLinks().size() ! + constraints.size()]; ! int offset = 0; ! for (int i = 0; i < tables.size(); i++) ! { ! baseObjects[offset] = getTableAt(i); ! offset++; ! } ! for (int i = 0; i < getInheritanceLinks().size(); i++) ! { ! baseObjects[offset] = getInheritanceLinkAt(i); ! offset++; ! } ! for (int i = 0; i < constraints.size(); i++) ! { ! baseObjects[offset] = getConstraintAt(i); ! offset++; ! } ! return baseObjects; ! } } |