[Nextobjects-devel] nextobjects/nextobjects/src/org/devaki/nextobjects/util MeriseTransform.java,1.2
Status: Alpha
Brought to you by:
eflorent
|
From: <efl...@us...> - 2003-06-02 20:03:49
|
Update of /cvsroot/nextobjects/nextobjects/nextobjects/src/org/devaki/nextobjects/util
In directory sc8-pr-cvs1:/tmp/cvs-serv28736/src/org/devaki/nextobjects/util
Modified Files:
MeriseTransform.java ModelMan.java NOImageTransform.java
Log Message:
made model -> png about to work again + checkstyleS
Index: MeriseTransform.java
===================================================================
RCS file: /cvsroot/nextobjects/nextobjects/nextobjects/src/org/devaki/nextobjects/util/MeriseTransform.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -d -r1.20 -r1.21
*** MeriseTransform.java 31 May 2003 13:42:34 -0000 1.20
--- MeriseTransform.java 2 Jun 2003 20:03:45 -0000 1.21
***************
*** 48,569 ****
public class MeriseTransform
{
! /*
! * The logger from the log4j project
! */
! private static Category logger
! = Logger.getInstance(MeriseTransform.class.getName());
!
! /*
! * Dummy constructor
[...1100 lines suppressed...]
! newField = new Column(pAsso.getIdentifierAt(i));
! newField.setPrimaryKey(true);
! if (pAsso.getCardAt(i) == ConceptualModel._0N_)
! {
! newField.setRequired(false);
! }
! newField.setAutoIncrement(false); // always in that case!
! newTable.getData().addElement(newField);
! newCst =
! new Constraint(
! pDatabase,
! pAsso.getEntityAt(i).getSubsequentTable(),
! newTable);
! newCst.setAnyField(newField);
! newCst.setUniqueField(pAsso.getIdentifierAt(i));
! ModelMan.addConstraint(pDatabase, newCst);
! }
! ModelMan.addTable(pDatabase, newTable);
}
}
Index: ModelMan.java
===================================================================
RCS file: /cvsroot/nextobjects/nextobjects/nextobjects/src/org/devaki/nextobjects/util/ModelMan.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -C2 -d -r1.24 -r1.25
*** ModelMan.java 31 May 2003 13:42:34 -0000 1.24
--- ModelMan.java 2 Jun 2003 20:03:45 -0000 1.25
***************
*** 280,284 ****
pMerise.isVerified = false;
pMerise.isSaved = false;
-
((Association) pAssocLink.getParentClass()).addAssociationLink(
((Entity) pAssocLink.getChildClass()));
--- 280,283 ----
Index: NOImageTransform.java
===================================================================
RCS file: /cvsroot/nextobjects/nextobjects/nextobjects/src/org/devaki/nextobjects/util/NOImageTransform.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** NOImageTransform.java 24 May 2003 18:50:47 -0000 1.3
--- NOImageTransform.java 2 Jun 2003 20:03:45 -0000 1.4
***************
*** 22,29 ****
import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.ObjectInputStream;
- import java.io.ObjectOutputStream;
import java.awt.Point;
import java.awt.Rectangle;
--- 22,25 ----
***************
*** 36,218 ****
import org.devaki.nextobjects.workspace.models.ConceptualModel;
import org.devaki.nextobjects.workspace.models.objects.BaseObject;
public class NOImageTransform
{
! //private static BaseModel myModel
! static Category logger = Logger.getInstance(NOImageTransform.class.getName());
! public NOImageTransform()
! {
! }
! /*
! * Move the ConceptualModel to the upper left corner to get the samllest image.
! * param pPCM
! * @return
! */
! private static Rectangle resizeAndTranslate(ConceptualModel pCDM)
! {
! Rectangle rect=pCDM.getRectangle();
! BaseObject[] tmp = pCDM.getModel0bjects();
! // loop
! for (int j=0;j<tmp.length;j++)
! {
! tmp[j].getObjectView().setLocation(
! new Point(
! tmp[j].getObjectView().getLocation().x-rect.x,
! tmp[j].getObjectView().getLocation().y-rect.y
! )
! );
! }
! return rect;
! }
! /*
! * Move the PhysicalModel to the upper left corner to get the samllest image.
! * param pPDM
! * @return
! */
! private static Rectangle resizeAndTranslate(PhysicalModel pPDM)
! {
! Rectangle rect=pPDM.getRectangle();
! BaseObject[] tmp = pPDM.getModel0bjects();
! // loop
! for (int j=0;j<tmp.length;j++) {
! tmp[j].getObjectView().setLocation(
! new Point(
! tmp[j].getObjectView().getLocation().x-rect.x,
! tmp[j].getObjectView().getLocation().y-rect.y
! )
! );
! }
! return rect;
! }
! /*
! * Get a Buffered Image for the model
! * @param panel , width, height
! * @return
! */
! private static BufferedImage getImage(JPanel panel,int width,int height)
! {
! BufferedImage bi = new BufferedImage(width,height,
! BufferedImage.TYPE_4BYTE_ABGR_PRE);
! Graphics2D g2 = (Graphics2D)bi.createGraphics();
! // We do a null clip to avoid a null pointer when call
! // for getOldClip() later in XXXXView() paints.
! Rectangle rect= new Rectangle(0,0,width,height);
! g2.clip(rect);
! panel.paint(g2);
! //dispose of the graphics content
! g2.dispose();
! return bi;
! }
! /*
! * Write Conceptual Model the model to a PNG file
! * @param pPDM,file
! * @return
! */
! public static boolean writeImage(ConceptualModel pCDM,File file)
! {
! //pessimistic
! boolean success=false;
! //clone CDM
! // first I save the erd int temp.
! File tmp=new File (NOTools.TMP_DIR + File.separator + "temp.erd");
! try
! {
! ObjectOutputStream flux =
! new ObjectOutputStream(new FileOutputStream(tmp));
! flux.writeObject(pCDM);
! flux.flush();
! flux.close();
! }
! catch (Exception ioex)
! {
! logger.error("Unable to save temporary file " + tmp);
! }
! // then reload.
! ConceptualModel anotherMerise=null;
! try
! {
! ObjectInputStream flux=new ObjectInputStream(new FileInputStream(tmp));
! anotherMerise=(ConceptualModel)flux.readObject();
! flux.close();
! }
! catch (Exception ioex)
! {
! logger.error("I can't understand file : " + ioex );
! }
! Rectangle rect = resizeAndTranslate(anotherMerise);
! ModelMan.resizeModelObjects(anotherMerise);
! BufferedImage bi=getImage(anotherMerise.getConceptualView().drawingArea,
! rect.width,rect.height);
! try {
! success=javax.imageio.ImageIO.write(bi, "PNG",file);
! } catch (Exception e) {
! // most often lacks of jdk1.3
! e.printStackTrace();
! logger.error(e.getMessage());
! }
! System.gc();
! return success;
! }
! /*
! * Write Physical Model the model to a PNG file
! * @param pPDM,file
! * @return
! */
! public static boolean writeImage(PhysicalModel pPDM,File file)
! {
! //pessimistic
! boolean success=false;
! //clone PDM
! // first I save the erd int temp.
! File tmp=new File (NOTools.TMP_DIR + File.separator + "temp.pdm");
! try
! {
! ObjectOutputStream flux =
! new ObjectOutputStream(new FileOutputStream(tmp));
! flux.writeObject(pPDM);
! flux.flush();
! flux.close();
! }
! catch (Exception ioex)
! {
! logger.error("Unable to save temporary file " + tmp);
! }
! // then reload.
! PhysicalModel anotherPDM=null;
! try
! {
! ObjectInputStream flux=new ObjectInputStream(new FileInputStream(tmp));
! anotherPDM=(PhysicalModel)flux.readObject();
! flux.close();
! }
! catch (Exception ioex)
! {
! logger.error("I can't understand file : " + ioex );
! }
! // that's why we have cloned it.
! Rectangle rect = resizeAndTranslate(anotherPDM);
! ModelMan.resizeModelObjects(anotherPDM);
! // get the buffered image.
! BufferedImage bi=getImage(anotherPDM.getPhysicalView().drawingArea,
! rect.width,rect.height);
! try {
! success=javax.imageio.ImageIO.write(bi, "PNG",file);
! } catch (Exception e) {
! // most often lacks of jdk1.3
! e.printStackTrace();
! logger.error(e.getMessage());
! }
! System.gc();
! return success;
! }
}
--- 32,211 ----
import org.devaki.nextobjects.workspace.models.ConceptualModel;
import org.devaki.nextobjects.workspace.models.objects.BaseObject;
+ import org.devaki.nextobjects.workspace.models.graphics.ClassView;
+ /**
+ * This class is responsible for drawing models to files.
+ *
+ * @author efl...@de...
+ *
+ */
public class NOImageTransform
{
! /**
! * The Log4J logger
! */
! private static Category logger =
! Logger.getInstance(NOImageTransform.class.getName());
! /**
! * Dummy constructor
! */
! public NOImageTransform()
! {
! }
! /**
! * Move the ConceptualModel to the upper left corner to get the samllest image.
! * @param pCDM the context model
! * @param xOffset the X offset
! * @param yOffset the Y offset
! */
! private static void translateModel(
! ConceptualModel pCDM,
! int xOffset,
! int yOffset)
! {
! BaseObject[] tmp = pCDM.getModel0bjects();
! // loop
! for (int j = 0; j < tmp.length; j++)
! {
! if (tmp[j].getObjectView() instanceof ClassView)
! {
! ((ClassView) tmp[j].getObjectView()).setLocation(
! new Point(
! tmp[j].getObjectView().getLocation().x - xOffset,
! tmp[j].getObjectView().getLocation().y - yOffset));
! }
! }
! }
! /**
! * Move the PhysicalModel to the upper left corner to get the samllest image.
! * @param pPDM the context model
! * @param xOffset the X offset
! * @param yOffset the Y offset
! */
! private static void translateModel(
! PhysicalModel pPDM,
! int xOffset,
! int yOffset)
! {
! Rectangle rect = pPDM.getRectangle();
! BaseObject[] tmp = pPDM.getModel0bjects();
! // loop
! for (int j = 0; j < tmp.length; j++)
! {
! if (tmp[j].getObjectView() instanceof ClassView)
! {
! ((ClassView) tmp[j].getObjectView()).setLocation(
! new Point(
! tmp[j].getObjectView().getLocation().x - xOffset,
! tmp[j].getObjectView().getLocation().y - yOffset));
! }
! }
! System.out.println(xOffset + " -" + yOffset);
! }
! /**
! * Get a the drawed/sized image to print using the
! * model view drawing area
! *
! * @param panel the panel from the model to paint.
! * @param width the width of the image
! * @param height the height of the image
! * @return bufferedImage
! */
! private static BufferedImage getImage(JPanel panel, int width, int height)
! {
! ModelMan.resetCurrentObjects();
! BufferedImage bi =
! new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR_PRE);
! Graphics2D g2 = (Graphics2D) bi.createGraphics();
! Rectangle rect = new Rectangle(0, 0, width, height);
! panel.paint(g2);
! //dispose of the graphics content
! return bi;
! }
! /**
! * Write Conceptual Model the model to a PNG file
! * @param pCDM the context model
! * @param file the file to write
! * @return success
! */
! public static boolean writeImage(ConceptualModel pCDM, File file)
! {
! boolean success = false;
! Point oldP = pCDM.getRectangle().getLocation();
! // this is a hack, the model is moved to top left corner in
! // order to avoid drawing the whole 5000*5000 drawingArea.
! // then the model is returned to old position.
! // by that time it havn't been redrawed ...
! translateModel(pCDM, oldP.x, oldP.y);
! // the rectangle give the offfset.
! Rectangle rect = pCDM.getRectangle();
! pCDM.getConceptualView().setFullRefresh(true);
! BufferedImage bi =
! getImage(
! pCDM.getConceptualView().drawingArea,
! rect.width,
! rect.height);
! // return to the old offset.
! try
! {
! success = javax.imageio.ImageIO.write(bi, "PNG", file);
! } catch (Exception e)
! {
! logger.error(e.getMessage());
! // most often lacks of jdk1.4
! e.printStackTrace();
! }
! translateModel(pCDM, -oldP.x, -oldP.y);
! return success;
! }
!
! /**
! * Write Physical Model the model to a PNG file
! * @param pPDM the context model
! * @param file the file to write
! * @return success
! */
! public static boolean writeImage(PhysicalModel pPDM, File file)
! {
! boolean success = false;
!
! Point oldP = pPDM.getRectangle().getLocation();
! // this is a hack, the model is moved to top left corner in
! // order to avoid drawing the whole 5000*5000 drawingArea.
! // then the model is returned to old position.
! // by that time it havn't been redrawed ...
! translateModel(pPDM, oldP.x, oldP.y);
! // the rectangle give the offfset.
! Rectangle rect = pPDM.getRectangle();
!
! try
! {
! BufferedImage bi =
! getImage(
! pPDM.getPhysicalView().drawingArea,
! rect.width,
! rect.height);
! success = javax.imageio.ImageIO.write(bi, "PNG", file);
!
! } catch (Exception e)
! {
! logger.error(e.getMessage());
! // most often lacks of jdk1.4
! e.printStackTrace();
! }
! // return to the old offset.
! translateModel(pPDM, -oldP.x, -oldP.y);
!
! return success;
! }
}
|