001: // The UMLet source code is distributed under the terms of the GPL; see license.txt
002: package com.umlet.control;
003:
004: import com.umlet.element.base.*;
005:
006: /**
007: * <p>Title: </p>
008: * <p>Description: </p>
009: * <p>Copyright: Copyright (c) 2001</p>
010: * <p>Company: </p>
011: * @author unascribed
012: * @version 1.0
013: */
014:
015: public class Resize extends Command {
016: int _where, _diffx, _diffy;
017:
018: public int getX() {
019: return _diffx;
020: }
021:
022: public int getY() {
023: return _diffy;
024: }
025:
026: public int getWhere() {
027: return _where;
028: }
029:
030: Entity _entity;
031:
032: public Entity getEntity() {
033: return _entity;
034: }
035:
036: public Resize(Entity entity, int where, int diffx, int diffy) {
037: _entity = entity;
038: _where = where;
039: _diffx = diffx;
040: _diffy = diffy;
041: }
042:
043: public void execute() {
044: Entity e = _entity;
045: if (_where == 1) {
046: e.changeLocation(0, _diffy);
047: e.changeSize(0, -_diffy);
048: } else if (_where == 3) {
049: e.changeLocation(0, _diffy);
050: e.changeSize(_diffx, -_diffy);
051: } else if (_where == 9) {
052: e.changeLocation(_diffx, _diffy);
053: e.changeSize(-_diffx, -_diffy);
054: } else if (_where == 8) {
055: e.changeLocation(_diffx, 0);
056: e.changeSize(-_diffx, 0);
057: } else if (_where == 12) {
058: e.changeLocation(_diffx, 0);
059: e.changeSize(-_diffx, _diffy);
060: } else if (_where == 2) {
061: e.changeSize(_diffx, 0);
062: } else if (_where == 4) {
063: e.changeSize(0, _diffy);
064: } else if (_where == 6) {
065: e.changeSize(_diffx, _diffy);
066: }
067: }
068:
069: public void undo() {
070: super .undo();
071: Entity e = _entity;
072: if (_where == 1) {
073: e.changeLocation(0, -_diffy);
074: e.changeSize(0, _diffy);
075: } else if (_where == 3) {
076: e.changeLocation(0, -_diffy);
077: e.changeSize(-_diffx, _diffy);
078: } else if (_where == 9) {
079: e.changeLocation(-_diffx, -_diffy);
080: e.changeSize(_diffx, _diffy);
081: } else if (_where == 8) {
082: e.changeLocation(-_diffx, 0);
083: e.changeSize(_diffx, 0);
084: } else if (_where == 12) {
085: e.changeLocation(-_diffx, 0);
086: e.changeSize(_diffx, -_diffy);
087: } else if (_where == 2) {
088: e.changeSize(-_diffx, 0);
089: } else if (_where == 4) {
090: e.changeSize(0, -_diffy);
091: } else if (_where == 6) {
092: e.changeSize(-_diffx, -_diffy);
093: }
094: }
095:
096: public boolean isMergeableTo(Command c) {
097: if (!(c instanceof Resize))
098: return false;
099: Resize r = (Resize) c;
100: if (this .getEntity() != r.getEntity())
101: return false;
102: if (this .getWhere() != r.getWhere())
103: return false;
104: return true;
105: }
106:
107: public Command mergeTo(Command c) {
108: Resize tmp = (Resize) c;
109: Resize ret = new Resize(this.getEntity(), this.getWhere(), this
110: .getX()
111: + tmp.getX(), this.getY() + tmp.getY());
112: return ret;
113: }
114: }
|