[Nextobjects-devel] nextobjects/nextobjects/src/org/devaki/nextobjects/workspace/models/graphics Bas
Status: Alpha
Brought to you by:
eflorent
|
From: <efl...@us...> - 2003-06-04 19:29:47
|
Update of /cvsroot/nextobjects/nextobjects/nextobjects/src/org/devaki/nextobjects/workspace/models/graphics
In directory sc8-pr-cvs1:/tmp/cvs-serv8358/src/org/devaki/nextobjects/workspace/models/graphics
Modified Files:
AssociationLinkView.java ConceptualView.java
ConstraintView.java InheritanceLinkView.java PhysicalView.java
Added Files:
BaseModelView.java
Log Message:
Refactored graphics-
--- NEW FILE: BaseModelView.java ---
/*
nextobjects Copyright (C) 2001-2005 Emmanuel Florent
This program 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.
This program 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 GeneralSys Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc., 59
Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.devaki.nextobjects.workspace.models.graphics;
import java.io.Serializable;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import javax.swing.event.ChangeListener;
import javax.swing.event.ChangeEvent;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import org.devaki.nextobjects.constants.CstGraphics;
import org.devaki.nextobjects.util.ModelMan;
import org.devaki.nextobjects.workspace.models.BaseModel;
import org.devaki.nextobjects.workspace.models.objects.BaseObject;
import org.devaki.nextobjects.workspace.models.objects.BaseClass;
import java.awt.Image;
public abstract class BaseModelView extends JPanel implements Serializable
{
/**
* X coordinates used when mouse clicking
*/
protected int x1;
/**
* Y coordinates used when mouse clicking
*/
protected int y1;
/**
* X coordinates used when mouse draging
*/
protected int x2;
/**
* Y coordinates used when mouse draging
*/
protected int y2;
/**
* X difference between x1 and object location
*/
protected int dx;
/**
* Y difference between x1 and object location
*/
protected int dy;
/**
* the model bounds
*/
protected Rectangle rectangle;
/**
* the context model
*/
protected BaseModel myModel;
/**
* the drawing area
*/
public JPanel drawingArea;
/**
* the scrollpane
*/
public JScrollPane jScrollPane;
/**
* full drawing refresh
*/
protected boolean fullRefresh = false;
/**
* The buffered image
*/
transient protected BufferedImage bi = null;
public BaseModelView(BaseModel pMerise)
{
/** Initialization **/
super(true); // is double buffered!
myModel = pMerise;
this.setVisible(true);
/** Components **/
// Main Panel
this.setLayout(new BorderLayout());
// Construct the drawing area
drawingArea = new JPanel()
{
/**
* Draw all components
* @param g the graphics
*/
public void paint(Graphics g)
{
update(g);
}
public Image makeImage(int x, int y)
{
Graphics2D big;
BufferedImage bi2;
Graphics2D bi2g;
BaseObject[] tmp = getMyModel().getModelObjects();
Rectangle rect;
calculateRectangle();
rect = getRectangle();
bi =
(BufferedImage) drawingArea.createImage(
rect.width,
rect.height);
big = bi.createGraphics();
big.setColor(CstGraphics.MODEL_BACKGROUND_COLOR);
big.fillRect(0, 0, rect.width, rect.height);
for (int k = 0; k < tmp.length; k++)
{
// Clears the rectangle that was previously drawn.
Dimension d = tmp[k].getObjectView().getSize();
Point l = tmp[k].getObjectView().getLocation();
if (tmp[k].getObjectView() instanceof LineView)
{
tmp[k].getObjectView().paint(big);
} else
{ // classview ?!
if (d.height > 0 && d.width > 0)
{
bi2 =
(BufferedImage) drawingArea.createImage(
d.width,
d.height);
bi2g = bi2.createGraphics();
tmp[k].getObjectView().paint(bi2g);
big.drawImage(
bi2,
l.x - getRectangle().x,
l.y - getRectangle().y,
this);
}
}
}
return bi;
}
public void update(Graphics g)
{
Graphics2D g2 = (Graphics2D) g;
// blank fill, clean ...
super.paintComponent(g2);
//Rectangle area;
BufferedImage bi2;
Graphics2D bi2g;
if (fullRefresh)
{
bi =
(BufferedImage) makeImage(getRectangle().height,
getRectangle().width);
fullRefresh = false;
}
g2.drawImage(bi, getRectangle().x, getRectangle().y, this);
// loop/paint selected objects objects toviewPort panel.
for (int j = 0; j < ModelMan.getCurrentObjects().size(); j++)
{
ObjectView tmpObjectView =
((BaseObject) ModelMan
.getCurrentObjects()
.elementAt(j))
.getObjectView();
Dimension d2 = tmpObjectView.getSize();
Point p2 = tmpObjectView.getLocation();
if (tmpObjectView instanceof ClassView)
{
g2.setColor(CstGraphics.MODEL_BACKGROUND_COLOR);
Rectangle r =
((ClassView) tmpObjectView).getOldrectangle();
g2.fillRect(r.x, r.y, r.width, r.height);
bi2 =
(BufferedImage) jScrollPane.createImage(
d2.width,
d2.height);
bi2g = bi2.createGraphics();
tmpObjectView.paint(bi2g);
((BaseObject) ModelMan
.getCurrentObjects()
.elementAt(j))
.getObjectView()
.paint(
bi2g);
g2.drawImage(bi2, p2.x, p2.y, this);
} else
{
Graphics tmpClip =
g2.create(
getRectangle().x,
getRectangle().y,
getViewSize().width,
getViewSize().height);
((BaseObject) ModelMan
.getCurrentObjects()
.elementAt(j))
.getObjectView()
.paint(
tmpClip);
}
((BaseObject) ModelMan.getCurrentObjects().elementAt(j))
.getObjectView()
.renderSelected(g);
}
}
};
// Define the color of the background
this.drawingArea.setBackground(CstGraphics.MODEL_BACKGROUND_COLOR);
this.drawingArea.setPreferredSize(CstGraphics.MODEL_DIMENSION);
/* Assembling components **/
this.jScrollPane = new JScrollPane(this.drawingArea);
jScrollPane.getViewport().setBackground(
CstGraphics.MODEL_BACKGROUND_COLOR);
this.add(jScrollPane, BorderLayout.CENTER);
//will update the buffered image in case viewport have changed.
// used at least at init
this.jScrollPane.getViewport().addChangeListener(new ChangeListener()
{
public void stateChanged(ChangeEvent e)
{
fullRefresh = true;
}
});
/** Extra **/
// Initialize scrolling position
jScrollPane.getViewport().setViewPosition(
CstGraphics.MODEL_INITIAL_POSITION);
}
/**
* 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 < myModel.getClasses().size(); i++)
{
BaseClass baseObject =
(BaseClass) myModel.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;
}
/**
* @return
*/
public BaseModel getMyModel()
{
return myModel;
}
/**
* @param model
*/
public void setMyModel(BaseModel model)
{
myModel = model;
}
/**
* set the dimension
* @param d the dimension
*/
public void setViewSize(Dimension d)
{
jScrollPane.getViewport().setViewSize(d);
}
/**
* return the view size
* @return the location
*/
public Dimension getViewSize()
{
return jScrollPane.getViewport().getViewSize();
}
/**
* Set if to refresh the drawing at next paint
* @param b full refresh
*/
public void setFullRefresh(boolean b)
{
fullRefresh = b;
}
/**
* Location of the view position
* @return the point
*/
public Point getViewPosition()
{
return jScrollPane.getViewport().getViewPosition();
}
}
Index: AssociationLinkView.java
===================================================================
RCS file: /cvsroot/nextobjects/nextobjects/nextobjects/src/org/devaki/nextobjects/workspace/models/graphics/AssociationLinkView.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** AssociationLinkView.java 2 Jun 2003 20:03:46 -0000 1.4
--- AssociationLinkView.java 4 Jun 2003 19:29:42 -0000 1.5
***************
*** 101,105 ****
public void paint(Graphics g)
{
! Point p0=myObject.getMyModel().getRectangle().getLocation();
Point p1=selectionPoints[0].getPoint();
--- 101,105 ----
public void paint(Graphics g)
{
! Point p0=((ConceptualView)myObject.getMyModel().getPanel()).getRectangle().getLocation();
Point p1=selectionPoints[0].getPoint();
Index: ConceptualView.java
===================================================================
RCS file: /cvsroot/nextobjects/nextobjects/nextobjects/src/org/devaki/nextobjects/workspace/models/graphics/ConceptualView.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -d -r1.21 -r1.22
*** ConceptualView.java 3 Jun 2003 18:00:55 -0000 1.21
--- ConceptualView.java 4 Jun 2003 19:29:42 -0000 1.22
***************
*** 19,40 ****
*/
package org.devaki.nextobjects.workspace.models.graphics;
import java.io.Serializable;
- import java.awt.BorderLayout;
import java.awt.Cursor;
import java.awt.Dimension;
-
- import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Color;
import java.awt.Point;
import java.awt.Polygon;
- import java.awt.Rectangle;
- import java.awt.image.BufferedImage;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
- import javax.swing.event.ChangeListener;
- import javax.swing.event.ChangeEvent;
- import javax.swing.JPanel;
- import javax.swing.JScrollPane;
import javax.swing.event.MouseInputAdapter;
import org.devaki.nextobjects.constants.CstGraphics;
--- 19,32 ----
*/
package org.devaki.nextobjects.workspace.models.graphics;
+
import java.io.Serializable;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Color;
import java.awt.Point;
import java.awt.Polygon;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import javax.swing.event.MouseInputAdapter;
import org.devaki.nextobjects.constants.CstGraphics;
***************
*** 53,57 ****
import org.devaki.nextobjects.workspace.models.objects.Entity;
import org.devaki.nextobjects.workspace.models.objects.InheritanceLink;
! import java.awt.Image;
/**
--- 45,49 ----
import org.devaki.nextobjects.workspace.models.objects.Entity;
import org.devaki.nextobjects.workspace.models.objects.InheritanceLink;
!
/**
***************
*** 59,119 ****
* @author efl...@de...
*/
! public class ConceptualView extends JPanel implements Serializable
{
! /**
! * X coordinates used when mouse clicking
! */
! private int x1;
!
! /**
! * Y coordinates used when mouse clicking
! */
! private int y1;
!
! /**
! * X coordinates used when mouse draging
! */
! private int x2;
!
! /**
! * Y coordinates used when mouse draging
! */
! private int y2;
!
! /**
! * X difference between x1 and object location
! */
! private int dx;
!
! /**
! * Y difference between x1 and object location
! */
! private int dy;
!
! /**
! * the context model
! */
! private ConceptualModel myModel;
!
! /**
! * the drawing area
! */
! public JPanel drawingArea;
!
! /**
! * the scrollpane
! */
! public JScrollPane jScrollPane;
!
! /**
! * full drawing refresh
! */
! private boolean fullRefresh = false;
!
! /**
! * The buffered image
! */
! transient private BufferedImage bi = null;
!
/**
* Construct a new <code>ConceptualView</code> object
--- 51,57 ----
* @author efl...@de...
*/
! public class ConceptualView extends BaseModelView implements Serializable
{
!
/**
* Construct a new <code>ConceptualView</code> object
***************
*** 122,275 ****
public ConceptualView(ConceptualModel pMerise)
{
! /** Initialization **/
! this.myModel = pMerise;
! this.setVisible(true);
!
! /** Components **/
! // Main Panel
! this.setLayout(new BorderLayout());
! // Construct the drawing area
! drawingArea = new JPanel()
! {
! /**
! * Draw all components
! * @param g the graphics
! */
! public void paint(Graphics g)
! {
! update(g);
! }
!
! public Image makeImage(int x,int y)
! {
! Graphics2D big;
! BufferedImage bi2;
! Graphics2D bi2g;
!
! BaseObject[] tmp = myModel.getModel0bjects();
!
! Rectangle rect;
! myModel.calculateRectangle();
! rect = myModel.getRectangle();
!
!
! bi=(BufferedImage) drawingArea.createImage(rect.width,rect.height);
!
! big = bi.createGraphics();
!
! big.setColor(CstGraphics.MODEL_BACKGROUND_COLOR);
! big.fillRect(0, 0, rect.width, rect.height);
!
! for (int k = 0; k < tmp.length; k++)
! {
! // Clears the rectangle that was previously drawn.
! Dimension d = tmp[k].getObjectView().getSize();
! Point l = tmp[k].getObjectView().getLocation();
!
! if (tmp[k].getObjectView() instanceof LineView)
! {
! tmp[k].getObjectView().paint(big);
! } else
! { // classview ?!
! if (d.height > 0 && d.width > 0)
! {
! bi2 =(BufferedImage)drawingArea.createImage(d.width,d.height);
! bi2g = bi2.createGraphics();
! tmp[k].getObjectView().paint(bi2g);
! big.drawImage(
! bi2,
! l.x - myModel.getRectangle().x,
! l.y - myModel.getRectangle().y,
! this);
! }
! }
! }
! return bi;
! }
!
! public void update(Graphics g)
! {
! Graphics2D g2 = (Graphics2D) g;
! // blank fill, clean ...
! super.paintComponent(g2);
! //Rectangle area;
! BufferedImage bi2;
! Graphics2D bi2g;
!
! if (fullRefresh)
! {
! bi = (BufferedImage) makeImage(myModel.getRectangle().height,myModel.getRectangle().width);
! fullRefresh = false;
! }
!
! g2.drawImage(bi,myModel.getRectangle().x, myModel.getRectangle().y,this);
!
! // loop/paint selected objects objects toviewPort panel.
! for (int j = 0; j < ModelMan.getCurrentObjects().size(); j++)
! {
! ObjectView tmpObjectView =
! ((BaseObject) ModelMan
! .getCurrentObjects()
! .elementAt(j))
! .getObjectView();
! Dimension d2 = tmpObjectView.getSize();
! Point p2 = tmpObjectView.getLocation();
!
! if (tmpObjectView instanceof ClassView)
! {
! g2.setColor(CstGraphics.MODEL_BACKGROUND_COLOR);
! Rectangle r =((ClassView) tmpObjectView).getOldrectangle();
! g2.fillRect(r.x, r.y, r.width, r.height);
! bi2 =(BufferedImage) jScrollPane.createImage( d2.width, d2.height);
! bi2g = bi2.createGraphics();
! tmpObjectView.paint(bi2g);
!
! ((BaseObject) ModelMan
! .getCurrentObjects()
! .elementAt(j))
! .getObjectView()
! .paint(
! bi2g);
! g2.drawImage(bi2, p2.x, p2.y, this);
! } else
! {
! Graphics tmpClip =g2.create(myModel.getRectangle().x,
! myModel.getRectangle().y,
! getViewSize().width,
! getViewSize().height);
! ((BaseObject) ModelMan.getCurrentObjects().elementAt(j)).getObjectView().paint(tmpClip);
! }
! ((BaseObject) ModelMan.getCurrentObjects().elementAt(j)).getObjectView().renderSelected(g);
! }
! }
! };
! // Define the color of the background
! this.drawingArea.setBackground(CstGraphics.MODEL_BACKGROUND_COLOR);
! this.drawingArea.setPreferredSize(CstGraphics.MODEL_DIMENSION);
!
/* Listeners **/
// Mouse Listeners
this.drawingArea.addMouseListener(new MyMouseListener());
this.drawingArea.addMouseMotionListener(new MyMouseMotionListener());
-
- /* Assembling components **/
- this.jScrollPane = new JScrollPane(this.drawingArea);
- jScrollPane.getViewport().setBackground(
- CstGraphics.MODEL_BACKGROUND_COLOR);
- this.add(jScrollPane, BorderLayout.CENTER);
-
- //will update the buffered image in case viewport have changed.
- // used at least at init
- this.jScrollPane.getViewport().addChangeListener(new ChangeListener()
- {
- public void stateChanged(ChangeEvent e)
- {
- fullRefresh = true;
- }
- });
- /** Extra **/
- // Initialize scrolling position
- jScrollPane.getViewport().setViewPosition(
- CstGraphics.MODEL_INITIAL_POSITION);
}
--- 60,68 ----
public ConceptualView(ConceptualModel pMerise)
{
! super(pMerise);
/* Listeners **/
// Mouse Listeners
this.drawingArea.addMouseListener(new MyMouseListener());
this.drawingArea.addMouseMotionListener(new MyMouseMotionListener());
}
***************
*** 307,311 ****
// Add the new association to the model
Association newAssociation =
! ModelMan.addAssociation(this.myModel, tmpPoint);
// Add links between the new association and the entities
--- 100,104 ----
// Add the new association to the model
Association newAssociation =
! ModelMan.addAssociation((ConceptualModel)this.myModel, tmpPoint);
// Add links between the new association and the entities
***************
*** 394,398 ****
&& (NOToolBar2.getCurrentTool() != NOToolBar2.TOOL_ASSOCIATION))
{
! BaseObject[] tmp = myModel.getModel0bjects();
// Loop for the association links and inheritance links.
for (int j = 0; j < tmp.length; j++)
--- 187,191 ----
&& (NOToolBar2.getCurrentTool() != NOToolBar2.TOOL_ASSOCIATION))
{
! BaseObject[] tmp = myModel.getModelObjects();
// Loop for the association links and inheritance links.
for (int j = 0; j < tmp.length; j++)
***************
*** 447,451 ****
case NOToolBar2.TOOL_TABLE :
{
! ModelMan.addEntity(myModel, e.getPoint());
//record old location
ModelMan.moveCurrentObject(0, 0);
--- 240,244 ----
case NOToolBar2.TOOL_TABLE :
{
! ModelMan.addEntity((ConceptualModel)myModel, e.getPoint());
//record old location
ModelMan.moveCurrentObject(0, 0);
***************
*** 455,459 ****
case NOToolBar2.TOOL_ASSOCIATION :
{
! ModelMan.addAssociation(myModel, e.getPoint());
break;
}
--- 248,252 ----
case NOToolBar2.TOOL_ASSOCIATION :
{
! ModelMan.addAssociation((ConceptualModel)myModel, e.getPoint());
break;
}
***************
*** 490,494 ****
{
fullRefresh = true;
! myModel.calculateRectangle();
x2 = e.getX();
y2 = e.getY();
--- 283,287 ----
{
fullRefresh = true;
! calculateRectangle();
x2 = e.getX();
y2 = e.getY();
***************
*** 796,802 ****
// Loop for the entities to find the targeted object
! for (int i = 0; i < myModel.countEntities(); i++)
{
! if (((Polygon) myModel
.getEntityAt(i)
.getObjectView()
--- 589,595 ----
// Loop for the entities to find the targeted object
! for (int i = 0; i < ((ConceptualModel)myModel).countEntities(); i++)
{
! if (((Polygon) ((ConceptualModel)myModel)
.getEntityAt(i)
.getObjectView()
***************
*** 815,822 ****
.getDraggedObject()
.equals(
! (BaseObject) myModel.getEntityAt(i)))
{
ModelMan.setDropTargetObject(
! (BaseObject) myModel.getEntityAt(i));
targetNotFound = false;
break;
--- 608,615 ----
.getDraggedObject()
.equals(
! (BaseObject)((ConceptualModel) myModel).getEntityAt(i)))
{
ModelMan.setDropTargetObject(
! (BaseObject) ((ConceptualModel)myModel).getEntityAt(i));
targetNotFound = false;
break;
***************
*** 829,836 ****
{
for (int i = 0;
! i < myModel.countAssociation();
i++)
{
! if (myModel
.getAssociationAt(i)
.getObjectView()
--- 622,629 ----
{
for (int i = 0;
! i < (((ConceptualModel))myModel).countAssociation();
i++)
{
! if (((ConceptualModel)myModel)
.getAssociationAt(i)
.getObjectView()
***************
*** 847,857 ****
.equals(
(
! BaseObject) myModel
.getAssociationAt(
i)))
{
ModelMan.setDropTargetObject(
! (
! BaseObject) myModel
.getAssociationAt(
i));
--- 640,649 ----
.equals(
(
! BaseObject) ((ConceptualModel) myModel)
.getAssociationAt(
i)))
{
ModelMan.setDropTargetObject(
! (BaseObject) ((ConceptualModel)myModel)
.getAssociationAt(
i));
***************
*** 922,979 ****
}
}
- }
-
-
-
- /**
- * Set if to refresh the drawing at next paint
- * @param b full refresh
- */
- public void setFullRefresh(boolean b)
- {
- fullRefresh = b;
- }
-
- /**
- * Location of the view position
- * @return the point
- */
- public Point getViewPosition()
- {
- return jScrollPane.getViewport().getViewPosition();
- }
-
- /**
- * return the view size
- * @return the location
- */
- public Dimension getViewSize()
- {
- return jScrollPane.getViewport().getViewSize();
- }
-
- /**
- * Set the view position
- * @param point the location
- */
- public void setViewPosition(Point point)
- {
- jScrollPane.getViewport().setViewPosition(point);
- }
- /**
- * Get the visible rectangle
- * @return the rectangle
- */
- public Rectangle getViewRect()
- {
- return jScrollPane.getViewport().getViewRect();
- }
- /**
- * set the dimension
- * @param d the dimension
- */
- public void setViewSize(Dimension d)
- {
- jScrollPane.getViewport().setViewSize(d);
}
--- 714,717 ----
Index: ConstraintView.java
===================================================================
RCS file: /cvsroot/nextobjects/nextobjects/nextobjects/src/org/devaki/nextobjects/workspace/models/graphics/ConstraintView.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** ConstraintView.java 2 Jun 2003 20:03:46 -0000 1.8
--- ConstraintView.java 4 Jun 2003 19:29:42 -0000 1.9
***************
*** 75,80 ****
public void paint(Graphics g)
{
!
! Point p0=this.myObject.getMyModel().getRectangle().getLocation();
Point p1=selectionPoints[0].getPoint();
--- 75,80 ----
public void paint(Graphics g)
{
! Point p0=((PhysicalView)myObject.getMyModel().getPanel()).getRectangle().getLocation();
!
Point p1=selectionPoints[0].getPoint();
Index: InheritanceLinkView.java
===================================================================
RCS file: /cvsroot/nextobjects/nextobjects/nextobjects/src/org/devaki/nextobjects/workspace/models/graphics/InheritanceLinkView.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** InheritanceLinkView.java 2 Jun 2003 20:03:46 -0000 1.7
--- InheritanceLinkView.java 4 Jun 2003 19:29:42 -0000 1.8
***************
*** 68,72 ****
{
! Point p0 =myObject.getMyModel().getRectangle().getLocation();
Point p1 = selectionPoints[0].getPoint();
--- 68,72 ----
{
! Point p0=((BaseModelView)myObject.getMyModel().getPanel()).getRectangle().getLocation();
Point p1 = selectionPoints[0].getPoint();
Index: PhysicalView.java
===================================================================
RCS file: /cvsroot/nextobjects/nextobjects/nextobjects/src/org/devaki/nextobjects/workspace/models/graphics/PhysicalView.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -d -r1.20 -r1.21
*** PhysicalView.java 3 Jun 2003 18:00:55 -0000 1.20
--- PhysicalView.java 4 Jun 2003 19:29:42 -0000 1.21
***************
*** 57,60 ****
--- 57,61 ----
/**
* Main class for drawing Physical Data Models
+ *
* @see http://www.devaki.org/pdm.html
* @author efl...@de...
***************
*** 62,124 ****
* @task set PhysicalView.jscrollbar to private
*/
! public class PhysicalView extends JPanel implements Serializable
{
- /**
- * X coordinates used when mouse clicking
- */
- private int x1;
-
- /**
- * Y coordinates used when mouse clicking
- */
- private int y1;
-
- /**
- * X coordinates used when mouse draging
- */
- private int x2;
-
- /**
- * Y coordinates used when mouse draging
- */
- private int y2;
-
- /**
- * X difference between x1 and object location
- */
- private int dx;
-
- /**
- * Y difference between x1 and object location
- */
- private int dy;
-
- /**
- * the context model
- */
- private PhysicalModel myModel;
-
- /**
- * the drawing area
- */
- public JPanel drawingArea;
-
- /**
- * the scrollpane
- */
- public JScrollPane jScrollPane;
-
- /**
- * full drawing refresh
- */
- private boolean fullRefresh = true;
-
- /**
- * the buffered image
- */
- transient private BufferedImage bi = null;
/**
! * Construct a new <code>PhysicalView</code> object
* @param theDatabase the context database
*/
--- 63,71 ----
* @task set PhysicalView.jscrollbar to private
*/
! public class PhysicalView extends BaseModelView implements Serializable
{
/**
! * Construct a new PhysicalView object
* @param theDatabase the context database
*/
***************
*** 126,130 ****
{
/** Initialization **/
! myModel = theDatabase;
this.setVisible(true);
--- 73,77 ----
{
/** Initialization **/
! super(theDatabase);
this.setVisible(true);
***************
*** 151,159 ****
Graphics2D bi2g;
! BaseObject[] tmp = myModel.getModel0bjects();
Rectangle rect;
! myModel.calculateRectangle();
! rect = myModel.getRectangle();
--- 98,106 ----
Graphics2D bi2g;
! BaseObject[] tmp = myModel.getModelObjects();
Rectangle rect;
! calculateRectangle();
! rect = getRectangle();
***************
*** 183,188 ****
big.drawImage(
bi2,
! l.x - myModel.getRectangle().x,
! l.y - myModel.getRectangle().y,
this);
}
--- 130,135 ----
big.drawImage(
bi2,
! l.x - getRectangle().x,
! l.y - getRectangle().y,
this);
}
***************
*** 203,211 ****
if (fullRefresh)
{
! bi = (BufferedImage) makeImage(myModel.getRectangle().height,myModel.getRectangle().width);
fullRefresh = false;
}
! System.out.println(myModel.getRectangle());
! g2.drawImage(bi,myModel.getRectangle().x, myModel.getRectangle().y,this);
// loop/paint selected objects objects toviewPort panel.
--- 150,158 ----
if (fullRefresh)
{
! bi = (BufferedImage) makeImage(getRectangle().height,getRectangle().width);
fullRefresh = false;
}
!
! g2.drawImage(bi,getRectangle().x, getRectangle().y,this);
// loop/paint selected objects objects toviewPort panel.
***************
*** 242,247 ****
} else
{
! Graphics tmpClip =g2.create(myModel.getRectangle().x,
! myModel.getRectangle().y,
getViewSize().width,
getViewSize().height);
--- 189,194 ----
} else
{
! Graphics tmpClip =g2.create(getRectangle().x,
! getRectangle().y,
getViewSize().width,
getViewSize().height);
***************
*** 294,298 ****
Constraint constraint =
ModelMan.addConstraint(
! this.myModel,
(Table) ModelMan.getDraggedObject(),
(Table) ModelMan.getDropTargetObject());
--- 241,245 ----
Constraint constraint =
ModelMan.addConstraint(
! (PhysicalModel)this.myModel,
(Table) ModelMan.getDraggedObject(),
(Table) ModelMan.getDropTargetObject());
***************
*** 432,436 ****
&& (NOToolBar2.getCurrentTool() != NOToolBar2.TOOL_ASSOCIATION))
{
! BaseObject[] tmp = myModel.getModel0bjects();
// Loop for the association links and inheritance links.
for (int j = 0; j < tmp.length; j++)
--- 379,383 ----
&& (NOToolBar2.getCurrentTool() != NOToolBar2.TOOL_ASSOCIATION))
{
! BaseObject[] tmp = myModel.getModelObjects();
// Loop for the association links and inheritance links.
for (int j = 0; j < tmp.length; j++)
***************
*** 491,495 ****
case NOToolBar2.TOOL_TABLE :
{
! ModelMan.addTable(myModel, e.getPoint());
break;
}
--- 438,442 ----
case NOToolBar2.TOOL_TABLE :
{
! ModelMan.addTable((PhysicalModel)myModel, e.getPoint());
break;
}
***************
*** 511,515 ****
{
fullRefresh = true;
! myModel.calculateRectangle();
x2 = e.getX();
y2 = e.getY();
--- 458,462 ----
{
fullRefresh = true;
! calculateRectangle();
x2 = e.getX();
y2 = e.getY();
***************
*** 824,830 ****
// Loop for the entities to find the targeted object
! for (int i = 0; i < myModel.countTable(); i++)
{
! if (((Polygon) myModel
.getTableAt(i)
.getObjectView()
--- 771,777 ----
// Loop for the entities to find the targeted object
! for (int i = 0; i < ((PhysicalModel) myModel).countTable(); i++)
{
! if (((Polygon) ((PhysicalModel)myModel)
.getTableAt(i)
.getObjectView()
***************
*** 836,843 ****
if (!ModelMan
.getDraggedObject()
! .equals((BaseObject) myModel.getTableAt(i)))
{
ModelMan.setDropTargetObject(
! (BaseObject) myModel.getTableAt(i));
break;
}
--- 783,790 ----
if (!ModelMan
.getDraggedObject()
! .equals((BaseObject) ((PhysicalModel)myModel).getTableAt(i)))
{
ModelMan.setDropTargetObject(
! (BaseObject) ((PhysicalModel) myModel).getTableAt(i));
break;
}
***************
*** 923,926 ****
--- 870,937 ----
return jScrollPane.getViewport().getViewSize();
}
+ /**
+ * 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 <myModel.getClasses().size(); i++)
+ {
+ BaseClass baseObject = (BaseClass) myModel.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;
+ }
}
|