[Nextobjects-devel] nextobjects/nextobjects/src/org/devaki/nextobjects/util ModelMan.java,1.26,1.27
Status: Alpha
Brought to you by:
eflorent
From: <efl...@us...> - 2003-06-09 19:06:14
|
Update of /cvsroot/nextobjects/nextobjects/nextobjects/src/org/devaki/nextobjects/util In directory sc8-pr-cvs1:/tmp/cvs-serv2512/src/org/devaki/nextobjects/util Modified Files: ModelMan.java NOClipboard.java NORedoLog.java Log Message: Added cut/paste labels. Index: ModelMan.java =================================================================== RCS file: /cvsroot/nextobjects/nextobjects/nextobjects/src/org/devaki/nextobjects/util/ModelMan.java,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** ModelMan.java 8 Jun 2003 09:28:26 -0000 1.26 --- ModelMan.java 9 Jun 2003 19:06:05 -0000 1.27 *************** *** 504,508 **** /** ! * Conveniency method for the ConceptualView.java to add an InheritanceLink. * @param pModel the model * @param p the point --- 504,508 ---- /** ! * method for the <code>ModelView</code> to add a label * @param pModel the model * @param p the point *************** *** 512,515 **** --- 512,525 ---- Label lbl = new Label(currentModel); lbl.getObjectView().setLocation(p); + addLabel(currentModel,lbl); + } + + /** + * Conveniency method for the <code>NOClipboard</code> to add a label + * @param pModel the model + * @param lbl the label + */ + public static void addLabel(BaseModel pModel, Label lbl) + { pModel.getLabels().addElement(lbl.getObjectView()); setCurrentObject(lbl); *************** *** 935,938 **** --- 945,949 ---- } resetCurrentObjects(); + currentModel.getModelView().setFullRefresh(true); currentModel.getModelView().repaint(); } Index: NOClipboard.java =================================================================== RCS file: /cvsroot/nextobjects/nextobjects/nextobjects/src/org/devaki/nextobjects/util/NOClipboard.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** NOClipboard.java 27 Apr 2003 17:05:27 -0000 1.5 --- NOClipboard.java 9 Jun 2003 19:06:06 -0000 1.6 *************** *** 47,50 **** --- 47,51 ---- import org.devaki.nextobjects.workspace.models.objects.InheritanceLink; import org.devaki.nextobjects.workspace.models.objects.Table; + import org.devaki.nextobjects.workspace.models.objects.Label; import org.devaki.nextobjects.workspace.models.styles.AssociationLinkStyle; import org.devaki.nextobjects.workspace.models.styles.AssociationStyle; *************** *** 55,511 **** /** [...963 lines suppressed...] ! public static void pasteConstraintStyle(ConstraintView pConstraintView) ! { ! Transferable clipboardContent = clipboard.getContents(myClipboard); ! try ! { ! ConstraintStyle clippedObject = ! (ConstraintStyle) clipboardContent.getTransferData( ! ConstraintStyle.fieldFlavor); ! pConstraintView.setStyle(clippedObject); ! } catch (IOException ioe) ! { ! logger.error("IOException : Cannot get transfer data"); ! } catch (UnsupportedFlavorException ufe) ! { ! logger.error( ! "UnsupportedFlavorException : Cannot get transfer data"); ! } ! } } Index: NORedoLog.java =================================================================== RCS file: /cvsroot/nextobjects/nextobjects/nextobjects/src/org/devaki/nextobjects/util/NORedoLog.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** NORedoLog.java 31 May 2003 11:48:34 -0000 1.3 --- NORedoLog.java 9 Jun 2003 19:06:07 -0000 1.4 *************** *** 32,36 **** import java.awt.Dimension; ! /* * This class is in charge of most of the Undo/Redo stuff. * The model was inspired from the gimp dual stack system. --- 32,36 ---- import java.awt.Dimension; ! /** * This class is in charge of most of the Undo/Redo stuff. * The model was inspired from the gimp dual stack system. *************** *** 40,320 **** */ ! public class NORedoLog { ! /* ! * Actions Delete ! */ ! public final static int ACTION_DELETE=0; ! /* ! * Actions Move ! */ ! public final static int ACTION_MOVE=1; ! /* ! * Actions Resize ! */ ! public final static int ACTION_RESIZE=2; ! /* ! * Actions Create ! */ ! public final static int ACTION_CREATE=3; ! /* ! * Log Type descriptorfor the undo stack ! */ ! public final static int LOG_UNDOLOG=0; ! /* ! * Log Type Descriptor for redo stack ! */ ! public final static int LOG_REDOLOG=1; ! /* ! * Log Size ! */ ! public final static int REDOLOG_SIZE=25; ! /* ! * The redo stack ! */ ! Stack redoLog=new Stack(); ! /* ! * The undo stack ! */ ! Stack undoLog=new Stack(); ! /* ! * A flag to know the current stack ! */ ! private static int currentStack=LOG_UNDOLOG; ! public NORedoLog() { ! } ! /* ! * Log all possible action coming from ModelMan.java ! */ ! public void log(int pAction,BaseObject pTarget, int pX, int pY) { ! NORedoItem redoItem=new NORedoItem(pAction,pTarget,pX,pY); ! switch (currentStack) { ! case LOG_REDOLOG: ! redoLog.push(redoItem); ! currentStack=LOG_UNDOLOG; ! if (redoLog.size()>REDOLOG_SIZE) ! { ! redoLog.removeElementAt(0); ! } ! break; ! default: ! undoLog.push(redoItem); ! if (undoLog.size()>REDOLOG_SIZE) ! { ! undoLog.removeElementAt(0); ! } ! break; ! } ! } ! /* ! * An <code>undo</code> call switch the current stack and call ! * each of the action executers for the last action ! * of the undo stack ! */ ! public void undo() { ! currentStack=LOG_REDOLOG; ! NORedoItem redoItem=null; ! if (undoLog.size()>0) { ! redoItem=(NORedoItem)undoLog.pop(); ! } else { ! NOMenuBar.jMenuItemUndo.setEnabled(false); ! } ! if (redoItem!=null ) { ! ModelMan.setCurrentObject(redoItem.target); ! switch (redoItem.action) { ! case ACTION_DELETE: ! redoDelete(redoItem); ! break; ! case ACTION_MOVE: ! redoMove(redoItem); ! break; ! case ACTION_RESIZE: ! redoResize(redoItem); ! break; ! case ACTION_CREATE: ! redoCreate(); ! break; ! default : ! //logger.debug("undoing unknow action!"); ! break; ! } ! } ! // else { ! // logger.warn("Nothing to undo!"); ! //} ! ModelMan.getCurrentModel().getPanel().repaint(); ! } ! /* ! * An <code>redo</code> call switch the current stack and call ! * each of the action executers for the last action ! * of the redo stack ! */ ! public void redo() { ! NORedoItem redoItem=null; ! if (redoLog.size()>0) ! { ! redoItem=(NORedoItem)redoLog.pop(); ! } else { ! NOMenuBar.jMenuItemRedo.setEnabled(false); ! } ! if (redoItem!=null ) ! { ! ModelMan.setCurrentObject(redoItem.target); ! switch (redoItem.action) { ! case ACTION_DELETE: ! redoDelete(redoItem); ! break; ! case ACTION_MOVE: ! redoMove(redoItem); ! break; ! case ACTION_RESIZE: ! redoResize(redoItem); ! break; ! case ACTION_CREATE: ! redoCreate(); ! break; ! default : ! //logger.debug("redoing unknow action!"); ! break; ! } ! } ! ModelMan.getCurrentModel().getPanel().repaint(); ! } ! /* ! * Redo Move action ! * @param redoItem the item to redo ! */ ! private void redoMove(NORedoItem redoItem) ! { ! ModelMan.moveCurrentObject(redoItem.x * (-1),redoItem.y * (-1)); ! } ! /* ! * Redo Resize action ! * @param redoItem the item to redo ! */ ! private static void redoResize(NORedoItem redoItem) ! { ! redoItem.target.getObjectView().setSize(new Dimension(redoItem.x,redoItem.y)); ! } ! /* ! * Redo Create action ! * @param redoItem the item to redo ! */ ! private static void redoCreate() ! { ! ModelMan.delete(); ! } ! /* ! * Redo Delete action ! * @param redoItem the item to redo ! */ ! private static void redoDelete(NORedoItem redoItem) ! { ! if (ModelMan.getCurrentModel() instanceof ConceptualModel) ! { ! if (redoItem.target instanceof Entity) ! { ! ModelMan.addEntity((ConceptualModel)ModelMan.getCurrentModel(), ! (Entity)redoItem.target); ! } ! if (redoItem.target instanceof Association) ! { ! ModelMan.addAssociation((ConceptualModel)ModelMan.getCurrentModel(), ! (Association)redoItem.target); ! } ! if (redoItem.target instanceof AssociationLink) ! { ! ModelMan.addAssociationLink((ConceptualModel)ModelMan.getCurrentModel(), ! (AssociationLink)redoItem.target); ! } ! } else if (ModelMan.getCurrentModel() instanceof PhysicalModel) ! { ! if (redoItem.target instanceof Table) ! { ! ModelMan.addTable((PhysicalModel)ModelMan.getCurrentModel(), ! (Table)redoItem.target); ! } ! if (redoItem.target instanceof Constraint) ! { ! ModelMan.addConstraint((PhysicalModel)ModelMan.getCurrentModel(), ! (Constraint)redoItem.target); ! } ! } ! } ! /* ! * This class represent a singe item to be redoed. ! * an action item which is made of : ! * @param pTarget flag describing the action ! * @param pTarget the object ! * @param pX optional X coordinate parameter ! * @para pY optional Y coordinate parameter ! * @author Emmanuel Florent ! */ ! class NORedoItem { ! /* a flag describing the action */ ! int action; ! /* the object */ ! BaseObject target; ! /* optional X coordinate */ ! int x; ! /* optional Y coordiante */ ! int y; ! /* ! * standard constructor ! */ ! public NORedoItem(int pAction, BaseObject pTarget, int pX, int pY) { ! action=pAction; ! target=pTarget; ! x=pX; ! y=pY; ! } ! /* ! * this function is used for debuging purpose. ! *@ return ! */ ! public String toString() ! { ! String actionName; ! switch (action) { ! case NORedoLog.ACTION_CREATE: ! actionName="ACTION_CREATE"; ! break; ! case NORedoLog.ACTION_DELETE: ! actionName="ACTION_DELETE"; ! break; ! case NORedoLog.ACTION_MOVE: ! actionName="ACTION_MOVE"; ! break; ! case NORedoLog.ACTION_RESIZE: ! actionName="ACTION_RESIZE"; ! break; ! default: ! actionName="unknow action"; ! break; ! } ! return new StringBuffer(actionName) ! .append(" ") ! .append(target) ! .append(" ") ! .append(x) ! .append("-") ! .append(y).toString(); ! } ! } // end of class RedoItem } // End of class NORedoLog --- 40,365 ---- */ ! public class NORedoLog ! { ! /** ! * Actions Delete ! */ ! public final static int ACTION_DELETE = 0; ! /** ! * Actions Move ! */ ! public final static int ACTION_MOVE = 1; ! /** ! * Actions Resize ! */ ! public final static int ACTION_RESIZE = 2; ! /** ! * Actions Create ! */ ! public final static int ACTION_CREATE = 3; ! /** ! * Log Type descriptorfor the undo stack ! */ ! public final static int LOG_UNDOLOG = 0; ! /** ! * Log Type Descriptor for redo stack ! */ ! public final static int LOG_REDOLOG = 1; ! /** ! * Log Size ! */ ! public final static int REDOLOG_SIZE = 25; ! /** ! * The redo stack ! */ ! private Stack redoLog = new Stack(); ! /** ! * The undo stack ! */ ! private Stack undoLog = new Stack(); ! /** ! * A flag to know the current stack ! */ ! private static int currentStack = LOG_UNDOLOG; ! /** ! * Dummy constructor. ! * Should never be used. ! * ! */ ! public NORedoLog() ! { ! } ! /** ! * Log all possible action coming from ModelMan.java ! * @param pAction flag describing the action ! * @param pTarget the object ! * @param pX optional X coordinate parameter ! * @param pY optional Y coordinate parameter ! */ ! public void log(int pAction, BaseObject pTarget, int pX, int pY) ! { ! NORedoItem redoItem = new NORedoItem(pAction, pTarget, pX, pY); ! switch (currentStack) ! { ! case LOG_REDOLOG : ! redoLog.push(redoItem); ! currentStack = LOG_UNDOLOG; ! if (redoLog.size() > REDOLOG_SIZE) ! { ! redoLog.removeElementAt(0); ! } ! break; ! default : ! undoLog.push(redoItem); ! if (undoLog.size() > REDOLOG_SIZE) ! { ! undoLog.removeElementAt(0); ! } ! break; ! } ! } ! /** ! * An <code>undo</code> call switch the current stack and call ! * each of the action executers for the last action ! * of the undo stack ! */ ! public void undo() ! { ! currentStack = LOG_REDOLOG; ! NORedoItem redoItem = null; ! if (undoLog.size() > 0) ! { ! redoItem = (NORedoItem) undoLog.pop(); ! } else ! { ! NOMenuBar.jMenuItemUndo.setEnabled(false); ! } ! if (redoItem != null) ! { ! ModelMan.setCurrentObject(redoItem.target); ! switch (redoItem.action) ! { ! case ACTION_DELETE : ! redoDelete(redoItem); ! break; ! case ACTION_MOVE : ! redoMove(redoItem); ! break; ! case ACTION_RESIZE : ! redoResize(redoItem); ! break; ! case ACTION_CREATE : ! redoCreate(); ! break; ! default : ! //logger.debug("undoing unknow action!"); ! break; ! } ! } ! // else { ! // logger.warn("Nothing to undo!"); ! //} ! ModelMan.getCurrentModel().getModelView().setFullRefresh(true); ! ModelMan.getCurrentModel().getModelView().repaint(); ! } ! /** ! * An <code>redo</code> call switch the current stack and call ! * each of the action executers for the last action ! * of the redo stack ! */ ! public void redo() ! { ! NORedoItem redoItem = null; ! if (redoLog.size() > 0) ! { ! redoItem = (NORedoItem) redoLog.pop(); ! } else ! { ! NOMenuBar.jMenuItemRedo.setEnabled(false); ! } ! if (redoItem != null) ! { ! ModelMan.setCurrentObject(redoItem.target); ! switch (redoItem.action) ! { ! case ACTION_DELETE : ! redoDelete(redoItem); ! break; ! case ACTION_MOVE : ! redoMove(redoItem); ! break; ! case ACTION_RESIZE : ! redoResize(redoItem); ! break; ! case ACTION_CREATE : ! redoCreate(); ! break; ! default : ! //logger.debug("redoing unknow action!"); ! break; ! } ! } ! ModelMan.getCurrentModel().getModelView().setFullRefresh(true); ! ModelMan.getCurrentModel().getModelView().repaint(); ! } + /** + * Redo Move action + * @param redoItem the item to redo + */ + private void redoMove(NORedoItem redoItem) + { + ModelMan.moveCurrentObject(redoItem.x * (-1), redoItem.y * (-1)); + } ! /** ! * Redo Resize action ! * @param redoItem the item to redo ! */ ! private static void redoResize(NORedoItem redoItem) ! { ! redoItem.target.getObjectView().setSize( ! new Dimension(redoItem.x, redoItem.y)); ! } ! /** ! * Redo Create action ! */ ! private static void redoCreate() ! { ! ModelMan.delete(); ! } ! /** ! * Redo Delete action ! * @param redoItem the item to redo ! */ ! private static void redoDelete(NORedoItem redoItem) ! { ! if (ModelMan.getCurrentModel() instanceof ConceptualModel) ! { ! if (redoItem.target instanceof Entity) ! { ! ModelMan.addEntity( ! (ConceptualModel) ModelMan.getCurrentModel(), ! (Entity) redoItem.target); ! } ! if (redoItem.target instanceof Association) ! { ! ModelMan.addAssociation( ! (ConceptualModel) ModelMan.getCurrentModel(), ! (Association) redoItem.target); ! } ! if (redoItem.target instanceof AssociationLink) ! { ! ModelMan.addAssociationLink( ! (ConceptualModel) ModelMan.getCurrentModel(), ! (AssociationLink) redoItem.target); ! } ! } else if (ModelMan.getCurrentModel() instanceof PhysicalModel) ! { ! if (redoItem.target instanceof Table) ! { ! ModelMan.addTable( ! (PhysicalModel) ModelMan.getCurrentModel(), ! (Table) redoItem.target); ! } ! if (redoItem.target instanceof Constraint) ! { ! ModelMan.addConstraint( ! (PhysicalModel) ModelMan.getCurrentModel(), ! (Constraint) redoItem.target); ! } ! } ! } ! /** ! * This class represent a singe item to be redoed. ! * an action item which is made of : ! * @param pTarget flag describing the action ! * @param pTarget the object ! * @param pX optional X coordinate parameter ! * @para pY optional Y coordinate parameter ! * @author Emmanuel Florent ! */ ! class NORedoItem ! { ! /** ! * a flag describing the action ! */ ! private int action; ! /** ! * the object ! */ ! private BaseObject target; ! /** ! * optional X coordinate ! * */ ! private int x; ! /** ! * optional Y coordiante ! */ ! private int y; ! /** ! * standard constructor ! * @param pAction the action kind flag ! * @param pTarget the changed object ! * @param pX optional x param ! * @param pY optional y param ! */ ! public NORedoItem(int pAction, BaseObject pTarget, int pX, int pY) ! { ! action = pAction; ! target = pTarget; ! x = pX; ! y = pY; ! } ! /* ! * this function is used for debuging purpose. ! *@ return debug string ! * ! public String toString() ! { ! String actionName; ! switch (action) ! { ! case NORedoLog.ACTION_CREATE : ! actionName = "ACTION_CREATE"; ! break; ! case NORedoLog.ACTION_DELETE : ! actionName = "ACTION_DELETE"; ! break; ! case NORedoLog.ACTION_MOVE : ! actionName = "ACTION_MOVE"; ! break; ! case NORedoLog.ACTION_RESIZE : ! actionName = "ACTION_RESIZE"; ! break; ! default : ! actionName = "unknow action"; ! break; ! } ! return new StringBuffer(actionName) ! .append(" ") ! .append(target) ! .append(" ") ! .append(x) ! .append("-") ! .append(y) ! .toString(); ! } ! */ ! } // end of class RedoItem } // End of class NORedoLog |