Wykład 1 - WikiDyd

Transkrypt

Wykład 1 - WikiDyd
Modelowanie oprogramowania w języku
UML
Wykład 1
Modelowanie oprogramowania w
języku UML
Regulamin przedmiotu
Literatura
Wprowadzenie
Treść przedmiotu
Modelowanie oprogramowania w języku UML, Michał Śmiałek
Informacje o przedmiocie
Strona wykładowcy: http://www.iem.pw.edu.pl/~smialek/
Zawiera:
Aktualne ogłoszenia dla studentów (w zakładce „Dydaktyka”)
Przykłady do książki „Zrozumieć UML 2.0” (w pliku .EAP)
Strona przedmiotu: http://wikidyd.iem.pw.edu.pl/index.cgi/UML1
Zawiera:
Dokładny regulamin zaliczania
Literaturę
Konspekty kolejnych wykładów.
Konspekty kolejnych ćwiczeń laboratoryjnych
Modelowanie oprogramowania w języku UML
Michał Śmiałek
1
Modelowanie oprogramowania w języku
UML
Wykład 1
Zasady zaliczenia wykładu
Wykład
Ocena za egzamin: max. 55 pkt.
Punkty dodatkowe za ćwiczenia na wykładzie.
Konkurs na najlepsze notatki.
Możliwość zwolnienia z egzaminu lub podwyższenia oceny dla osób,
które wygrają konkurs!
Ćwiczenia na wykładzie
5 ćwiczeń wykonywanych na zakończenie wybranych wykładów (na
razie nie wiadomo których9 ☺ )
Notatki
Notatki wykonane na wykładzie, zeskanowane do formatu PDF.
Podpis wykładowcy.
Terminy oddania: co ok. 4 wykłady (będą podane tydzień wcześniej).
Od kiedy? Od wykładu 3.
Modelowanie oprogramowania w języku UML
Michał Śmiałek
Zasady zaliczenia laboratorium
Laboratorium
Ocena za laboratorium: max. 45 pkt.
Ściśle powiązane z wykładem
4 małe ćwiczenia wprowadzające za 2 pkt
3 duże ćwiczenia (po 3 zajęcia) za 12-13 pkt.
Obecność obowiązkowa – ocena wystawiana bezpośrednio na
zajęciach
Więcej informacji na zajęciach laboratoryjnych.
Modelowanie oprogramowania w języku UML
Michał Śmiałek
2
Modelowanie oprogramowania w języku
UML
Wykład 1
Zasady wyliczania oceny końcowej
if (w>= 28 and l >= 23 and w+l>=51) {
suma = w+l+c+n;
case suma:
suma < 61
ocena = 3
break;
suma < 71
ocena = 3,5
break;
suma < 81
ocena = 4
break;
suma <91
ocena = 4,5
break;
suma <= 100
ocena = 5
break;
}
w
l
c
n
–
–
–
–
punkty
punkty
punkty
punkty
za
za
za
za
wykład
laboratorium
ćwiczenia (ekstra)
notatki (ekstra)
Modelowanie oprogramowania w języku UML
Michał Śmiałek
Literatura
Podstawowy podręcznik:
Michał Śmiałek, „Zrozumieć UML 2.0”, Helion, 2005
Książki dodatkowe:
R. S. Pressman, „Praktyczne podejście do inżynierii
oprogramowania”, Wydawnictwa Naukowo-Techniczne, 2004
I. Sommerville, „Inżynieria oprogramowania”, Wydawnictwa
Naukowo-Techniczne, 2003
M. Fowler, „UML 2.0 w kropelce”, LTP, 2005
T. Pender, „UML Bible”, Wiley, 2003
Inne książki na temat języka UML9
Modelowanie oprogramowania w języku UML
Michał Śmiałek
3
Modelowanie oprogramowania w języku
UML
Wykład 1
Modelowanie – co to jest?
Modelowanie oprogramowania w języku UML
Michał Śmiałek
Dlaczego modelowanie oprogramowania?
Gerald M. Weinberg, w swojej książce zatytułowanej Zrozumieć
Profesjonalnego Programistę napisał tak:
„(...) programowanie komputerów jest zdecydowanie
najtrudniejszym zadaniem intelektualnym, jakie ludzie próbowali
kiedykolwiek wykonywać. Kiedykolwiek.”
Zatem:
• Potrzebujemy metod na pokonanie tej złożoności!
• Modelowanie pokonuje złożoność poprzez dodanie opisu
umożliwiającego zastosowanie zasady abstrakcji.
Modelowanie oprogramowania w języku UML
Michał Śmiałek
4
Modelowanie oprogramowania w języku
UML
Wykład 1
Abstrakcja pomaga zrozumieć problem
Miasto
Budynek
Użyteczności
Publicznej
Dom
Szkoła
Urząd
Sąd
Okno
Modelowanie oprogramowania w języku UML
Michał Śmiałek
Model jako „mapa” dla kodu
p ackage pwu ml.e lem ents. nod es.classes;
im por t ja va.a wt .*;
im por t ja va.a wt .geo m .*;
im por t ja va.u til. *;
voi d pa intI ns ide (Grap hic s g) {
re set Fie ldAdd it ion ();
ad dFi eld (g, c la ssD ata.n am e, Sett ings .t itle Font , FIEL D_AL IGN _C ENTER );
im por t pw uml. *;
im por t pw uml. err or. *;
im por t pw uml. dat a.b ase.* ;
ad dFi eld Separ at or( g);
if (s how Attri bu tes )
im por t pw uml. dat a.d ata st or age. *;
im por t pw uml. dat a.d iagra m .Diagr amI D;
im por t pw uml. gra phicba se .* ;
fo r ( int i =0 ;i< class Da ta. attr ibut es .siz e(); i+ +) {
At tribu te Dat a att = (At trib uteD at a) c lass Da ta.a ttri but es .get( i);
St ring at tri buteN ame = att. toSt ri ng() ;
im por t pw uml. diagr am ma na gem ent .*;
im por t pw uml. diagr am ma na gem ent .gr aph ic edition .* ;
package pwuml.diagrammanagement;
import java.awt.*;
import java.awt.event .*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
packa ge p wum l.ele me nts. nodes .classes;
package pwuml.diagrammanagement;
ad dFiel d( g, attri but eN ame, Set ti ngs. data Fon t, FIEL D_A LI GN_LE FT) ;
/ **
*
*
* @au th or da vid
*/
p ubliccla ssCla ssA pp eran ce ext end sG r aphicNode {
}
ad dFi eld Separ at or( g);
if (s how Metho ds )
fo r ( int i =0 ;i< class Da ta. meth ods. si ze() ;i++ ) {
St ring me tho dName = m et hodR ende re r.re nder Met hod (met );
* ID o f Class ob je ct which cont ains class da ta.
*/
ClassData ID
ad dFiel d( g, metho dNa me , Se ttin gs .dat aFon t, FIE LD_A LIG N_ LEFT) ;
classID;
}
}
pro tect ed int posX;
pro tect ed int posY;
void pai ntIn sid e(G rap hics g) {
import pwuml.data.datastorage.*;
import pwuml.data.diagram.*;
import pwuml.data.base.*;
import pwuml.error.*;
import pwuml.*;
cl assD ata. at tri butes .g et( i);
rese tFie ld Add ition () ;
addF ield (g , c lass Dat a.n ame, Se tti ngs. titl eF ont, FIE LD _AL IGN_C EN TER );
addF ield Se par ator( g) ;
imp ort p wum l.* ;
imp ort p wum l.e rro r. *;
imp ort p wum l.d ata. ba se .* ;
imp ort p wum l.d ata. da tast orag e. *;
imp ort p wum l.d ata. diag ra m. Dia gram ID;
if ( sho wAt tri bute s)
f or ( in t i =0;i <cl ass Data. at tri bute s.s ize ();i ++) {
imp ort p wum l.g raph icbase .*;
imp ort p wum l.d iagra mm a nage me nt. *;
A ttr ibu teDa ta att = (At tr ibu teDa ta)
S tri ng attri bu teN ame= at t.t oStr ing ();
imp ort p wum l.d iagra mm a nage me nt. gr aphiced ition .*;
pu blic v oid setS af eCl ip(Gr ap hic s g, int x , in t y, in t w idth , i nt heig ht) {
ol dCl ipB ounds = g.g etCli pB oun ds() ;
g. cli pRe ct(x, y , w idth, he ig ht);
tra nsient
ClassDa ta classData ;
Meth od Ren der er met ho dRe nd erer ;
}
pro tect ed bo olean
pro tect ed bo olean
fullNam e= f alse;
sh owA ttr ib ut es= tr ue;
pro tect ed bo olean
sh owMe th ods= t rue;
static int
static int
MINIMAL_ W IDT H;
MINIMAL_ HEIG HT ;
pu blic v oid rest or eSa feCli p( Gra phic s g) {
// we will ev aluate it af te r "em pty " class is creat ed
final st atic int FIE LD_A LIGN_L EFT = 0 ;
final st atic int FIE LD_A LIGN_C ENTER = 1 ;
/**
final st atic int LE FT_ MAR G IN =
10 ;
final st atic inttoolbar.
VE R TICA L_SPA CE = 4 ;
* Implements diagram window, creat es diagram's
int
yP ointe r;
*
boole an
sizeF ound = fals e;
* @aut hor david
public C la ssA pper an ce (C lassAp peran ceIDn ewOb jectID, Diag ram ID diagr am ID, ClassDataI DclassID) {
*/
su per ( (G ra phicNode ID )n ewObje ct ID, dia gram ID);
public
DiagramWindow extends JInternalFrame
Set ting s.d ata Font , FI EL
D_A LIGN_ LEclass
FT) ;
this.classID= cla ssID;
addM aster ( cla ssID) ;
implements InternalFrameListener
{
a ddF iel d(g, at tri buteN am e, Sett ings .d ataF ont, F IEL D_ALI GN _LE FT);
/**
*
*
* @aut hor da vid
*/
pub lic class Cla ssApp er ance e xte nds Gr ap hicNode {
}
addF ield Se par ator( g) ;
if ( sho wMe tho ds)
f or ( in t i =0;i <cl ass Data. me tho ds.s ize (); i++) {
M eth odD ata m et = ( Metho dD ata ) cl ass Dat a.me thod s. get (i);
S tri ng metho dN ame = met ho dRe nder er.r en derM etho d( met );
/ **
* ID of Class obje ct which co nt ainscl assd ata .
*/
C la ssDa taID clas sID;
a ddF iel d(g, me tho dName ,
}
}
p rote cted in t po sX ;
p rote cted in t po sY ;
met ho dRe nde rer = new Meth odR en der er () ;
lo ad Dat a( ) ;
Rec tang le old Cli pBou nds = n ull;
p rote cted in t widt h;
p rote cted in t he ig ht ;
oldC lipB ou nds = g. get Cli pBoun ds ();
g.cl ipRe ct (x, y, w id th, heig ht );
}
p rote cted boo le an f ullName = fa ls e;
pub lic voi d r est oreS afe Cli p(Gra ph ics g) {
p rote cted boo le an sho wAtt rib utes= true ;
p rote cted boo le an sho wMet hod s= t ru e;
//if (o ldC lip Boun ds= =nu ll) r et urn ;
sta tic int
sta tic int
MINIM AL_ WIDTH;
MINIM AL_ HEIG HT;
supe r( ( G rap hicNodeID) newOb jectI D, d ia gr amI D) ;
th is. classID= classID;
ad dMa st er( classID);
m eth odR e nder er = new Me th odR en derer ( ) ;
load Data () ;
setS ize( ) ;
MINIMAL_ W IDT H= wi dth;
MINIMAL_ HEIGHT = heig ht;
}
v oid loa dDa ta () {
tr y {
D ataT ran sf er dt= R eg ist ry .get Data Tra nsfer ( ) ;
cl assDat a= ( Cla ssDat a) dt .get (cl assID) ;
} cat ch ( DataObj ectNo tExist Except ion ex ) {
E L. repo rt (E L.INTER NAL _E RR OR , this, "C la ss doesn t' exist wit h ID " + classID.to St ring( ) , e x) ;
}
}
p ublic DataOb jectID get Data Instanc eID( ) {
re tur n classID;
}
p rote cted void r eloa dAd ditiona lData( ) {
load Data( ) ;
}
v oid r esetFi eldAdd ition( ) {
yP oint er= posY;
}
v oid ad dField (G ra phics g, Str in g te xt , Font fo nt, i nt alig n) {
g. se tF ont( font );
Fo ntM etric sm etr ics= g.ge tF ontMe tr ics( ) ;
int t ex tWid th=
m etr ics.stri ngW id th (t ex t) ;
int t ex tHeight = me trics.g et Heigh t( ) ;
int t ex tX;
int t ex tY= yPoint er + V ER TIC AL_S PACE + me tri cs.g et Asce nt () ;
if ( alig n==F IE LD_ALI GN_LE FT) te xt X= po sX + LEF T_M AR GIN;
else t ext X= ( int) ( po sX + ( widt h- tex tWidt h) /2 );
g. dr awStr ing (t ext , te xtX , tex tY );
yP oint er+ = text Height + VE RT IC AL_ SPA CE;
}
v oid ad dField Sepa rat or( Gr aphics g) {
yP oint er+ = VER TICA L_S PAC E;
g. dr awLin e( p osX, yPoin ter , po sX +widt h, y Poin ter );
}
/ **
* E valu ates wid th a nd h eight so allf ields a re visib le .
*/
v oid set Size ( ) {
he ig ht = 0;
widt h= 0;
Fo ntM etric sda ta Metr ic s= R e gist ry .get Data Fon tMet rics( );
Fo ntM etric stit leMe trics = R egistr y. getT itleF ont Metr ics() ;
int t ex tWid th;
int t ex tHeight ;
// t itle
te xt Widt h = tit le Met rics.str ingW idt h( cla ss Dat a. nam e) ;
te xt Heig ht = t itleM etrics. get He ig ht () ;
he ig ht += VER TIC AL_ SPAC E + te xt Heigh t;
if ( wid th<t ext Wi dth) w id th= text W id th;
// t itle- a ttr ib utes sep arat or
he ig ht += VER TI CAL_S PAC E;
te xt Heig ht = d at aMetr ics.get Heigh t( ) ;
// a tt ribut es
if ( sho wAtt ribu te s)
for ( int i=0 ;i<classDa ta .att r ib utes .size ( ); i++) {
A tt ribut eData at t= ( At trib uteDat a) classDa ta .att rib utes. get (i) ;
S tr ing at trib ut eNa m e= att .t oStr ing () ;
t ex tWid th= d at aMe trics.st ringW idt h( at tribut eNam e) + L EFT_ MAR G IN;
if ( widt h<tex tW idth ) widt h= te xtW idt h;
h eigh t+= V ER TICA L_SP ACE + t ex tHeigh t;
}
// a tt ribut es- m etho dssep ar ator
he ig ht += VER TI CAL_S PAC E;
// m e thod s
/*
g. se tF ont( Sett in gs.d at aFont ) ;
m etr ics= g.ge tF ontMe tr ics( ) ;
te xt Heig ht = m e trics.g etHeigh t( ) ;
*/
pro tect ed Dia gra mID
pro tect ed Dia gra mCan vas
di ag ram ID;
di ag ram Canv as;
pro tect ed JSc rol lPan e
di ag ram Scro llP ane ;
if ( sho wMet hods )
fo r ( int i=0 ;i<cla ssDat a.m et hods.si ze () ;i ++) {
Met hodD ata m et = ( Meth od Dat a) classData. m etho ds.ge t( i) ;
Str ing m et hodNa me = me tho dR end erer .r end erMe th od( m et) ;
tex tW idt h= dat aMet rics.str ingW id th( m eth odNam e) + LE FT_ MAR G IN;
if ( widt h<t ext Widt h) widt h= te xt Widt h;
pub lic Dia gra mWi ndow (Di agr amID di agr amID ) {
supe r() ;
this .di agr amI D= d iag ram ID;
init ();
}
pro tect ed voi d i nit( ) {
Diag ram Dat a d iagr amD ata = lo adD iag ramD ata ();
setT itl e( dia gram Dat a.g etDi agr amN ame( ) ) ;
heig ht+ = VER TICA L_S PAC E + te xtHeig ht;
show ();
addI nte rna lFr ameL ist ene r(th is) ;
pro tect ed voi d c reat eTo olB ar() {
Tool Bar to olB ar= Reg ist ry.g etT ool Bar( );
tool Bar .cl ear Tool Bar ();
tool Bar .se tDi agra mCa nva s(di agr amC anva s);
load Dia gra mDa ta() .se tup Tool Bar ();
}
}
pub lic voi d p ain t(Gr aph ics g) {
setS afeC li p(g , po sX, po sY, w id th+ 1, h eigh t+ 1);
}
g.dr awRe ct ( p osX, po sY, widt h, he ight );
import pwuml.*; pain
tIns id e(g );
import pwuml.error.*;
rest oreS af eCl ip(g) ;
}
import pwuml.data.diagram.*;
pub lic voi d p ain tSel ect ed( Graph ic s g ) {
import pwuml.diagrammanagement.*;
g.se tCol or (Se tting s. SEL ECTED _C OLO R);
import pwuml.data.base.*;
// d raw ju st in bo un ds
import pwuml.data.datastorage.*;
setS afeC li p(g , po sX, po sY, w id th+ 1, h eigh t+ 1);
import pwuml.element s.nodes.classes.*;
g.dr awRe ct ( p osX, po sY, widt h, he ight );
import pwuml.element
pain tInss.nodes.interfaces.*;
id e(g );
}
public DiagramWindow(DiagramID diagramID)
{
public Dat aObje ct IDg et Dat aInsta nceID()
super();
retu rn classID;
}
this.diagramID= diagramID;
pro tect ed vo id relo adAd dit io nalDat a( ) {
init();
lo adDat a( ) ;
}
{
}
protected void init() {
void r eset FieldA ddit ion( ) {
DiagramData diagramData= loadDiagramData();
yPoin ter = posY;
}
setTitle( diagram Data.getDiagramName() );
void a ddF ie ld( G ra phicsg , St rin g text , F ont font , int align) {
setClosable(t rue);
g.set Font ( fo nt) ;
setMaximizable(t rue);
Font Met rics met rics = g. getF on tMe trics() ;
in t te xtW idt h=
in t te xtHeig ht=
rest oreS af eCl ip(g) ;
} Metr ics.get Height ( ) ;
text Height = title
} V ERT ICAL _SP ACE +t ext Heigh t;
heigh t +=
if (wi dth <te xtW idth ) w idth = te xtW idth ;
}
public DiagramID getDiagramID() {
Re cta ng le o ldCl ip Boun ds= nu ll;
prot ecte d int wid th ;
// tit le- att ribut es se par ator
pub lic voi d g rap hicE dit ion End() {
{
return diagramID;
pu V
bli
void_SP
set
Sa feCl ip(G rap hic s g, in t x, in t y , int w idt h,
throws ImproperLinkException
heigh t+=
ERcTICAL
ACE;
prot ecte d int h eigh t;
}
}
text Height ol
= dat
dC lipB
aMet ound
rics.gs=
etHeigh
g.g etCl
t( ) ; ipB oun ds() ;
tran si ent
Cla ssDat a classDa ta;
g. cl ipRe ct(x , y, w idth , h eig ht);
Metho dR en der er m eth od Ren der er;
// checking pub
nodes
lic Col lec tio n ge ner ate GEPs( ) {
} te s
// at tribu
prot ecte d bo olean f ullNam e= fa lse ;
tr ibute s)
public void setZoom(double newZoomRatio)if fo(sh{r (owAt
Arra yLis t res ult= ne w A rrayL is t() ;
c void
feCl ip(
Gra phic
prot ecte d bo olean sho wAt trib ute s= tru e;
intpu
i=bli
0;i<cla
ssDatres
a.ato
ttr reSa
ibut es.size(
) ;i++
){ s g ) {
resu lt.a dd (ne w Cl ass GEP (this , new Poi nt( pos X+wi dth, p osY +heig ht ) ) );
prot ecte d bo olean sho wMet ho ds= tr ue;
// self referencing
not
diagram Canvas.setZoom(newZoomRatio); At tribu te//Daifta a(ol
retu rn res
ult ; allowed
ull
) r etur
tt= dCli
( A ttr pB
ibutound
eDats==n
a) cla
ssData
.a ttr n;
ib ut es.g et( i) ;
}
se tCli
dCt lipB
st atic int
MINI MAL_ WIDTH;
// we will eva lu ate it aft er "e m pty" class is cr eate d
St ring a ttg.
ribut
eNamp(ol
e= at
.toS triound
ng( )s);
;
if (sourceID.equals(destinationID))
throw new }
ol dC lipB ound s= nul l;
st atic int
MINI MAL_ HE IG HT;
pub lic voi d f orm Edit ion () {
te xtW
} idt h= d ataMe tr ics.st ring W id th( a ttr ib ut eNam e) + LEF T_M ARG IN;
ImproperLinkException("Selfreferencing
not allowed.");
final st atic i nt FIE LD_AL IG N_L EFT = 0;
if ( widt h<t ext Widt h) widt h= t ext Widt h;
// t his wi ll chang e cla ss da ta & appe ranc e (OK) or no t ( Cance l)
he ight+
pu bli
= VE
c RT
void
ICA L_
pai
SPA
ntCE
(Gra
+ tphic
extHei
s g
ght;
) {
final st atic i nt FIE LD_AL IG N_C ENT ER = 1;
public double getZoom() {
Clas sEdi ti on ce= n ew Cl assEd it ion (thi s, cla ssDa ta);
}
final st atic i nt LE FT_ MAR G IN =
10;
g. se tCol or(S et ting s.NO RM AL_C OLOR );
DataTransfer ifdt( ce.
=datfinal
Registry.getDataTransfer();
st atic i nt VE R TICAL _SPA CE = 4;
return diagramCanvas.getZoom();
aCh ange d() ) s etSiz e( );
// at tribu te s- m et hods separ ato r
in t
y Po in te r;
d raw _SP
just
}
heigh t+= V//
ER TICAL
ACE;in bo unds
// u pdat e dat a
se tS afeC lip( g, pos X, p osY , w idth +1, h eight +1) ;
boole an
sizeFo und = false;
try {
DataObject sourceNode
= null;
// m etho ds
Re gis try .getD at aTr ansfe r( ).u pdat e(th is );
g. dr awRe ct( po sX, posY , w idt h, h eig ht );
/*
public ClassA pper ance( Cl assA ppe ran ceIDn ewObj ectID, Diagr am IDdia gr amID, C la ss Da taID cla ssID) {
Re gis try .getD at aTr ansfe
).u pdat e(cl as sDat a);
DataObject destinationNode
=r(null;
pa in
protected DiagramData loadDiagramData() g.set
{ Font ( Set
tin tIns
gs.datide(
aFo g);
nt );
} ca tch (D
ata
Obje
ctN
otE
xistE
xc
ept
ion
ex)
{
sup er (( G ra phicNode ID) ne wObject ID, diag ram ID);
met rics = g. getF ont Met rics() ;
EL .re por t(EL. IN TER NAL_E RR OR, thi s, "Cl ass does n' t e xisttry
wi th{ID " + c la ssID .toS tr ing( ), e x) ;
st oreS
li p(g)
t his.classID= clas sID;
text Height re
= me
tr ic s.gafeC
et Heig
ht( ) ; ;
}
*/
}
a ddM aster( classID) ;
return (DiagramData)
Diag ramC an vas .upda te Dep enden tL ink s(th is.g et ID() );
if (sh owMe
pu bli
thocds)void pai nt Sele cted (Gr aph ics g) {
m eth od Re nder er = new Meth odR en dere r( ) ;
Registry.getDataTransfer().get(diagramID);
Regi stry .g etD iagra mA cti vatio n( ).r efre shAl lD iagr amWi nd
ows ();
for ( in t i=0; i<cla ssDat a. met ho ds.size( ) ;i++) {
loa dDat a() ;
}
g. se
et ting
LE CTED
OR)
Me tho dData
m tCol
et= ( or(S
Me thod
Data)s.SE
classData
.m_COL
et hod
( i);
set Size( ) ;
try {
} catch (Dat aObjectNotExistException e) {St rin g me tho dNam e= m eth odR e nder er .ren de rMeth ods. ;get
(m et ) ;
pub lic boo lea n h asFo rmE dit ion() {
//dadta
raw
in gWid
bo unds
Widt h=
Metrjust
ics. strin
th (m et hod Name) + LEF T_MA RG IN;
MINIMAL _W IDT H=w idth ;
sourceNode = dt.get(sourceID);
EL.report(EL.INTERNA L_ERROR, this, "Cifte(xtan't
f ind
Diagram
se tSWafeC
p osY , w idth +1, h eight +1) ;
MINIMAL _HEIG HT= he ight;
w id th <text
idth)lip(
w id g,
th =pos
textX,
W idth;
retu rn tru e;
he ight += VE RT ICAL_ SPA CE + t ext He ight ;
}
destinationNode
= dt.get(destinationID); data @ " + diagramID.toString(), e);
}
g. dr awRe ct( po sX, posY , w idt h, h eig ht );
}
}
pa in tIns ide( g);
void lo adDat a( ) {
}
heigh t+= V ER TICAL _SP ACE;
width += 10re
; st oreS afeC li p(g) ;
t ry {
return null;
} catch (DataObjectNotExistException
ex) {
class Cl assG EP ext end s St and art GEP {
}
DataT ra nsfer dt= R e gistry .ge tDat aTra nsfer ( ) ;
sizeF ound = tr ue;
}
EL.report(EL.INTERNA
cl assDat a=
L_ERROR,
( Cl assDa ta) dt .ge t( clthis,
assID) ; "Node can't
be found
pub lic Cla ssG EP( Grap hic Obj ect c li ent Obje ct, Po int posi ti on) {
}
pu bli c void pai nt Outl ine( Gra phi cs g ) {
} cat ch ( Data Obj ectNo tEx is t Excep tion ex) {
with ID " +
EL .rep or t( EL.I NTE R NA L_E RR OR , th is , "Class does n't exi st with ID " + cla ss ID.t oS tring ( ) , ex) ;
supe r(cl ie ntO bject , pos ition );
g. se tCol or(S et ting s.SE LE CTED _COL OR) ;
}
}
sourceID.toString()
+ " or " + destinationID.toSt
ring()void
); createToolBar() {
g. dr awRe ct( po sX, posY , w idt h, h eig ht );
protected
}
}
pub lic voi d m ove (Poi nt new Posit io n) {
ToolBar toolBar= Registry.getToolB ar();
return null;
public DataO bjectI Dge tDat aInstan ceID() {
pu bli c void pai nt Edit ed(G rap hic s g) {
toolBar.clearToolBar();
}
Clas sApp err etur
anc n
e classID;
no de= (C lassA pp era nce) clie nt Obje ct;
g. se tCol or(S et ting s.SE LE CTED _COL OR) ;
}
toolBar.setDiagramCanvas(diagramCanvas);
Poin t o ldP osi tion= g etP ositi on ();
int new Gep
X ecte
= (in
t)o
ldP adAd
ositidition
on .ge
tX()(;) {
// d raw just in bo unds
prot
d vo
id relo
alData
// classes or interfaces
be
selected
loadDiagramData().setupToolB ar();
int new Gep Y = (inmust
t)o ldP ositi
on .ge
tY() ;
se tS afeC lip( g, pos X, p osY , w idth +1, h eight +1) ;
loa dData () ;
boolean testOk=
false;
}
int cur ren tX = (in t) new Posit io n.g etX( );
g. dr awRe ct( po sX, posY , w idt h, h eig ht );
}
int cur ren tY = (in t) new Posit io n.g etY( );
int hei ght ) {
pa in tIns ide( g);
node .wid th = c urre ntX node. posX;
void r esetF ieldAdClassApperance
ditio n() {
if ( sourceNode
instanceof
&& public DiagramCanvas get DiagramCanvas() {
if ( nod e.w idt h<no de. MIN IMAL_ WI DTH ) no de. wid th= node .M INI MAL_W ID TH;
newG epX = n ode .pos X + no de.wi dt h;
yPinstanceof
oint er= posY;
destinationNode
ClassApperance ) return diagramCanvas;
}
node .hei gh t= curre nt Ynode .posY ;
}
if ( nod e.h eig ht<n ode .MI NIMAL _H EIG HT) nod e.h eigh t= n od e.M INIMA L_ HEI GHT;
testOk= true;
void a ddFiel d( Gr ap hics g , Str ing t ext , Fo nt f ont, int a lig n) {
newG epY = n ode .pos Y + no de.he ig ht;
re st oreS afeC li p(g) ;
}
pu bli c bool ean co ntai ns(P oin t p oint ) {
re tu rn g etBo un ds() .con tai ns( poin t);
}
g. set Font ( font ) ;
upda teOw nP osi tion( ne w P oint( ne wGe pX, new Gep Y));
public void internalFrameClosing(InternalFrameEvent
e)e{getB ound s() {
pu bli c Rect angl
Fo nt Metr icsm etr ics= g.g etF ont Met rics( ) ;
}
int te xtW idth =
met rics.str ingW idt h( tex t) ;
}
if ( sourceNode
instanceof
erfaceApperance
&&// calls deactivation too
re tu rn n ew R ec tang le(p os X, p osY,
int te xtHeigh t=Int
m etri
cs. get He ig ht () ;
}
} )
destinationNodeintinstanceof
InterfaceApperance
te xtX;
he ig ht += VER TI CAL_S PAC E;
widt h+= 1 0;
sizeFo und = true ;
wi dt h, he igh t);
pu bli c void mov e( int vect orX , i nt v ect or Y) {
int te xtY= yPoint er + VER TIC AL_S PAC E + m etr ics. get Ascen t( );
testOk= true;
po sX += v ecto rX ;
public void internalFrameClosed(InternalFrameEvent
e) {
po sY += v ecto rY ;
}
Registry.getDiagramActivation().markDiagramAsClosed(this);
pu bli c void gra ph icEd itio nEn d() {
}
if (!testOk) throw new ImproperLinkException("Improper
}
inheritance.");
void a ddFiel dSep ar ator ( Gr aphi csg) {
pu bli c Coll ecti
public void internalFrameOpened(InternalFrameEvent
e)on{gen erat eGE Ps( ) {
yP oint er+ = VER T ICA L_ SPAC E;
Ar ra yLis t re sul t= new Ar rayL ist( );
Inheritance newLink=
new
g. dr awLin
e( posXInheritance(
, yPoi nter , p osX+wid th, yPoin ter );
}
re su lt.a dd(n ew Cla ssGE P(t his , ne w P oi nt(po sX+ wi dth,
}
Regist ry.getDataTransfer().getNewID(), diagramID,
re tu rn r esul t;
}
/**
sourceID,
public void internalFrameIconified(Int ernalFrameEvent e) {
* Eval uates
width and h eight so all fie ld sa re v is i ble.
pu bli c void for mE diti on() {
*/
}
destinationID
);
void set Size(
){
if ( ali gn== FIELD_A LIG N_L EF T) t ex tX= p osX + LE FT_ MAR G IN;
else text X= ( int ) ( p osX + ( widt h- te xtW id th) /2 );
g. dr awSt ring (t ex t, te xt X, te xt Y) ;
yP oint er+ = tex tHeight + VE R TICAL _SPA CE;
}
Fo nt Metr icsd ata Metr ics= R e gistry .ge tDat aFon tMet rics( ) ;
Fo nt Metr icst itleM etrics = R eg is t ry. get Title Font Met rics( );
int te xtW idth ;
int te xtHeigh t;
pos Y+h eig ht) ) ) ;
// t his will ch ang e cl ass da ta & ap pe rance (O K) or n ot (Ca nce l)
Cl as sEdi tion ce = n ew C las sEd itio n(t hi s, cl ass Da ta);
he ight = 0;
widt h= 0 ;
return (GraphicLink)newLink;
}
}
}
pu blic v oid move (i nt vecto rX, i nt v ecto rY ) {
po sX+ = v ector X;
po sY+ = v ector Y;
}
pu blic v oid grap hi cEd ition En d() {
}
pu blic C oll ectio n gen erate GE Ps( ) {
Ar ray Lis t res ul t= new A rra yL ist( );
re sul t.a dd(ne w Cla ssGEP (t his , ne w Po in t(po sX+w id th, posY +he ig ht) ) );
re tur n r esult ;
}
pu blic v oid form Ed iti on() {
public void internalFrameDeiconified(InternalFrameEvent
e) {
if ( ce.d ataC ha nged ()) se tSiz e();
}
// u pdat e da ta
public void internalFrameClosed(InternalFrameEvent
public void internalFrameActivated(Int
e) {
ernalFrameEvent e) {
Registry.getDiagramActivation().markDiagramAsClosed(t
Registry.getDiagramAct his);
ivation().openDiagram(diagramID);
}
}
tr y {
Reg istr y. getD ataT ra nsfe r(). upd at e(thi s);
Reg istr y. getD ataT ra nsfe r(). upd at e(cla ssD at a);
publicPoint
void internalFrameActivated(InternalFrameEvent
e) {
public GraphicNode createNode(DiagramID
diagramID,
p) {
} ca tch (Dat aO bjec tNot Exi stE xcep tio n ex) {
// tit le
EL. repo rt (EL. INTE RN AL_E RROR , t hi s, "C las s doesn 't exi st
t ext Widt h = t it leMe trics.st ring Widt h( classDa ta. nam e );
Registry.getDiagramActivation().openDiagram (diagram
ID);
}
t ext He ight = title Metr ic s. get Height ( );
he ight += VE RTI CAL_ SPA CE + t ext He ight ;
}
return null;
Di ag ramC anva s. upda teDe pe nden tLin ks( th is.ge tID () );
if ( wi dth<t ex tWi dth) w idth= text W idth;
Re gi stry .get Di agra mAct iv atio n(). ref re shAll Dia gr amWin dow s() ;
}
}
// tit le - attr ibute ssep ara tor
public void internalFrameDeact ivated(InternalFrameEvent e) {
he ight += VE RT ICAL_ SPA CE;
pu bli c bool ean ha sFor mEdi tio n() {
public boolean isNode()
t ext He{
ight = dat aMet rics.ge tHeigh t( ) ;
re tu rn t rue;
Registry.getDiagramA ct ivation().deactivateDiagramWindow(this);
}
// at tribu tes
}
if ( sh owAtt r ib ute s)
}
for ( int i= 0;i<classDat a.at tr ibute s.size ( ) ;i++ ) {
return false;
At tribu teDat a at t= ( At trib ute Da ta ) classData .at trib ute s. ge t( i);
cl ass C las sG EP e xten ds Sta ndar tGE P {
St ring a ttr ibut eNam e= at t. toSt rin g() ;
}
}
pu bli c Clas sGEP (G raph icOb jec t c lien tOb je ct, P oin t posit ion ) {
}
public DiagramWindow(DiagramID setIconifiable(true);
diagramID) {
super();
setResizable(true);
this.diagramID= diagramID;
diagramCanvas= new DiagramCanvas(diagramID);
init();
diagramScrollPane= new JScrollPane(diagramCanvas);
}
setContentPane(diagramScrollPane);
setLocation(210,10);
protected void init() {
setSize(Settings.APPLICATION_WINDOW_X_SIZE /2,
PPLICA TION_WINDOW_Y_SIZE /2);
DiagramDat a diagramData= Settings.A
loadDiagramData();
setTitle( diagram Data.getDiagramName()
JDesktopPane
);
workingSpace= Registry.getWorkingSpace();
setClosable(true);
if (workingSpace==null) EL.report(EL.INTERNAL_ERROR, this,
setMaximizable(true);
"Working space not set.");
workingSpace.add(this, Settings.DIA GRAM_WINDOW_LA YER);
// th is will ch ang e cla ss da ta & app er ance (OK ) or n ot ( Can ce l)
setVisible(true);
Cl ass Edi tion ce = n ew Cl ass Ed itio n(th is , cl assD at a);
setIconif iable(true);
show();
if (c e.d ataCh an ged ()) s etS iz e();
i
setResizable(true);
addInternalFrameListener(this);
// up dat e dat a
tr y { diagramCanvas= new DiagramCanvas(diagramID);
}
Reg istry .g etD ataTr ans fe r(). upda te (thi s);
diagramScrollPane=
new
Reg istry .g etD ataTr ans fe r(). upda te (cla
ssDa taJScrollPane(diagramCanvas);
);
} c at ch (Data Ob jec tNotE xi stE xcep tion e x) {
setContentPane(diagramScrollPane);
public
getDiagramID()
{
EL. repor t( EL. INTER NAL _E RROR , th is , "C lass do esn 't e xis
t with IDDiagramID
" + cla ssI D.t oSt ring
(), ex );
}
setLocation(210,10);
ret urn diagramID;
Di agr amC anvas .u pda teDep en den tLin ks(t hi s.ge tID( )) ;
}
/2,
Re gis setSize(Settings.APPLICATION_WINDOW_X_SIZE
try .getD ia gra mActi va tio n(). refr es hAll Diag ra mWin dows ();
}
Settings.APPLICA TION_WINDOW_Y_SIZE /2);
pu blic b ool ean h as For mEdit io n() {
JDesktopPane workingSpace= Registry.get
public void setZoom(double
WorkingSpace();newZoomRatio) {
re tur n t rue;
if (workingSpace==null) EL.report(E
diagramCanvas.setZoom(newZoomRatio);
L.INTERNA L_ERROR, this,
}
}
"Working space not set.");
}
workingSpace.add(this, Sett ings.DIAGRAM_WINDOW_LA YER);
cla ss C lass GE P e xtend s Sta ndart GE P {
setVisible(true);
public double getZoom() {
pu blic C las sGEP( Gr aph icObj ect c lien tObj ec t, P oint po sit ion) {
show();
ret urn diagramCanvas.getZoom();
su per (cl ientO bj ect , pos it ion );
addInternalFrameListener(this);}
}
} v oid move (P oin t new Po sit ion) {
pu blic
protected DiagramData loadDiagramData() {
Cl ass App eranc e nod e= (C las sA pper ance )c lien tObj ect ;
public DiagramID getDiagramID() {t ry {
Po int ol dPosi ti on= getP osi ti on() ;
in t n ewG epX = ( int )oldP os iti on.g etX( );
ret urn diagram ID;
return (DiagramDat a)
in t n ewG epY = ( int )oldP os iti on.g etY( );
}
Registry.getDat aTransfer().get(diagramID);
in t c urr entX = (in t)new Pos it ion. getX () ;
in t c urr entY = (in t)new Pos it ion. getY () ;
} catch (DataObject NotExistException e) {
no de. wid th= c ur ren tXnod e.pos X;
public void setZoom(double
newZoomRatio)
EL.report(EL.INTERNAL_ERROR,
{
this, "C an't find Diagram
if (n ode .widt h< nod e.MIN IMA L_ WIDT H) n od e.wi dth= no de. MINI MAL _W IDTH;
ne wGe diagramCanvas.setZoom(newZoomRatio);
pX= node .p osX + no de. wi dth;
data @ " + diagramID.toString(), e);
no de. hei ght= cu rre ntYnode.po sY;
}
}
if (n ode .heig ht <no de.MI NIM AL _HEI GHT) n ode. heig ht = no de.M INI MA L_HEI GHT ;
ne wGe pY= node .p osY + no de. he ight ;
ret urn null;
uppublic
dat eOw nPosi double
ti on( new P oin
getZoom()
t( newG epX, n ewGe pY))
{;
}
}
}
ret urn diagram Canvas.getZoom();
}
protected void createToolBar() {
ToolBar toolBar= Registry.getToolB ar();
protected DiagramData loadDiagramData()
t oolB ar.clearToolBar();
{
try {
t oolB ar.setDiagramCanvas(diagramCanvas);
return (DiagramData)
loadDiagramData().setupToolB ar();
Registry.getDataTransfer().get(diagramID);
}
} catch (DataObjectNotExistException e) {
EL.report(EL.INTERNA L_ERROR,
public
this,
DiagramCanvas
"C an't f ind Diagram
getDiagramCanvas() {
data @ " + diagramID.toString(), e); ret urn diagramCanvas;
}
}
ret urn null;
}
public void internalFrameClosing(InternalFrameEvent e) {
// calls deactivation too
protected void createToolBar() { }
ToolBar toolBar= Registry.getToolB ar();
toolBar.clearToolBar();
public void internalFrameClosed(InternalFrameEvent e) {
toolBar.setDiagramCanvas(diagramCanvas);
Registry.getDiagramAct ivation().m arkDiagramAsClosed(this);
loadDiagramData().setupToolB ar();
}
}
public void internalFrameOpened(Int ernalFram eEvent e) {
public DiagramCanvas get DiagramCanvas()
}
{
ret urn diagram Canvas;
}
public void internalFrameIconified(InternalFrameEvent e) {
}
public void internalFrameClosing(InternalFrameEvent e) {
// calls deactivation too
public void internalFrameDeiconified(InternalFrameEvent e) {
}
}
re tur n n ew Re cta ng le(po sX, p osY, wid th , he ight );
public class InheritanceSelection extends ToolSelection {
in t te xtX ;
pub lic voi d p ain tOut lin e(G raphi cs g) {
in t te xtY = yPo in te r + VE RT IC AL_ SPA CE + m etr ics.get Ascen t( ) ;
setIconifiable(true);
g.se tCol or (Se tting s. SEL ECTED _C OLO R);
if (a li gn== FIEL D_A LIG N_ LEF T) te xtX= posX + L EFT _MAR G IN;
public Inherit anceSelection(ToolBar
toolBar)
{
setResizable(true);
g.dr awRe ct ( p osX, po sY, widt h, he ight
);
else tex tX = (int ) ( posX + ( wi dth- t extW idth) /2 ) ;
}
pa ck age pwum l.ele m ents. node s.classes;
diagram Canvas= new DiagramCanvas(diagramID);
g.dr awS tri ng( tex t, t ext X, t ex tY) ;
pub lic voi d p ain tEdi ted (Gr aphic s g) {
yPoin ter += te xt Heigh t + V ER TICA L_SPA CE ;
super(toolBar);
im port ja va.a wt. *;
diagram ScrollPane= new JScrollPane(diagramCanvas);
im port ja va.a wt. geo m. *;
} vo id pa int In side (Gra ph ics g) {
g.se tCol
(Se
s. SEL
ECTED _C OLO R);
imor
port
jatting
va.u til.*
;
}
setContentPane(diagramScrollPane);
re se
diicsg
tion) ();
void a ddF ie ldSe
partFie
ato r(ldAd
G raph
{
// d raw ju st in bo un ds
setLocation(210,10);
ad dF ield (g, cl assD ata. nam e, Sett ing s. title Fon t, FIEL D_A LIG N_C ENTE R);
im port pwu ml. *;
setS afeC li p(g , po sX, po sY, w id th+ 1, h eigh t+ 1);
dF ield
raE;
tor( g);
yPoin ter +=ad
VER
TICALSepa
_SPAC
im port pwu ml. err or. *;
public String getIconFileName()
setSize(Sett
}
ings.A PPLICATION_WINDOW_X_SIZE
g.dr awL in e( pos X,/2,
yPo inte r, posX+ width, yPo in te r) ;
im port pwu ml. data .b ase.* ;{ return "inheritance.gif";
g.dr awRe ct ( p osX, po sY, widt h, he ight );
if ( show Attr ib utes )
im port pwu ml. data .d atast ora ge. *;
}
pain tIns id e(g );
Settings.APPLICA TION_WINDOW_Y_SIZE /2);
f or ( int i= 0;i< clas sDa ta. attr ibu te s.siz e() ;i+ +) {
im port pwu ml. data .d iagra m. Dia gr amID;
im port pwu ml. grap hicbase .*;
/**
rest oreS af eCl ip(g){
;
JDesktopPane workingSpace= Regist ry.getWorkingSpace();
public String getToolTip()
Athtrib
eDat
at t=
im port pwu ml. diagr am ma nag em ent. *;
* Eval uat es width and
eighut
t so
all fiaelds
ar e(At
visi trib
ble. ute Da ta) c las sDa ta.a ttr ibu tes .get (i) ;
}
im port pwu ml. diagr am ma nag em ent. gr aphic edition .*;
*/
St ring at tri bute Nam e= att. toS tr ing() ;
if (workingSpace==null) EL.report(EL.INTERNA
L_ERROR,
this,
void se tSize () {
pub lic boo lea n c onta ins (Po int p oi nt) {
ad dFie ld (g, attr ibu teN ame, Se tt ings. dat aF ont, FIE LD _ALI GN_L EFT );
/* *
"Working space not set.");
*
}
heigh t= 0;
retu rn *get Bou nds( ).c ont ains( po int );
width = 0;
return "Inheritance";
workingSpace.add(this, Set tings.DIAGRAM_WINDOW_LAYER);
}
ad dF ield Sepa ra tor( g);
* @aut ho r da vid
( show
Meth
Font Met ricsif
data
Met rics
= od
Re s)
gistry .g etDat aFon tM etri cs( ) ;
*/
setVisible(true);
}
pub lic Rec tan gle getB ou nds () {
or (ic int
0;i< clas
sDa
ta. meth
ods).s
Font Met rics titlefMetr
s = Ri=
e gistry.
ge tTitl
eFont
Me trics(
; ize() ;i+ +) {
pu bliccla ss Cla ssAp pe rance exte nds G ra phicNode {
in t te xtW idt h;
show();
retu rn new Re ctang le (po sX, p os Y, widt h, hei ght) ;
Me thod Da ta m et= (Me tho dDat a) cl assDa ta. met hods .ge t(i );
/**
in t te xtHeig ht;
}
St ring me tho dNam e= met hodR end er er.re nde rM ethod (me t);
* ID o f Class obj ect wh ic h cont ains cl assd at a.
addInternalFrameListener(this);
public GraphicLink
createLink(DiagramID
diagramID,
*/
// tit le
pub lic voi d m ove (int ve cto rX, i nt ve ctor Y) {
ad dFie
ldgWidt
(g, meth
odN ame ,
ClassDGraphicNodeID
ataID cla ssID;
}
text W id th =t itle Metric
s. st rin
h( classData.
naSe
metti
) ; ng s.dat aFo nt , FIE LD_ AL IGN_ LEFT );
GraphicNodeID sourceID,
destinationID)
posX += vec
tor
X;d int p osX;
prot
ecte
posY += vec tor Y;
prot ecte d int p osY;
import
java.awt.*;
}
import
pu blic v oid pain
java.awt.event.*;
t( Gra phics g) {
import
java.util.*;
g. set Col or(Se
tt ing s.NOR MA L_C OLOR );
import
javax.swing.*;
// dr aw just
in bo unds
se tSa feC lip(g , pos X, po sY, w idth +1, he ight +1);
import
javax.swing.event.*;
pu blic R ect angle g etB ounds () {
me trics.str ing Wid th( tex t) ;
m etr ics. get Heigh t( );
}
}
setC los abl e(t rue) ;
setM axi miz abl e(tr ue) ;
setI con ifi abl e(tr ue) ;
setR esi zab le( true );
diag ram Can vas = ne w D iag ramC anv as( diag ram ID) ;
diag ram Scr oll Pane = n ew JScro ll Pan e(di agr amC anva s);
setC ont ent Pan e(di agr amS crol lPa ne) ;
setL oca tio n(2 10,1 0);
setS ize (Se tti ngs. APP LIC ATIO N_W IND OW_X _SI ZE /2, Set tin gs. APPL ICA TIO N_WIN DO W_Y _SIZ E /2 );
JDes kto pPa ne work ing Spa ce= Reg ist ry.g etW ork ingS pac e() ;
if ( wor kin gSp ace= =nu ll) EL. rep ort (EL. INT ERN AL_E RRO R, thi s, "W or kin g spa ce no t se t.") ;
work ing Spa ce. add( thi s, Setti ng s.D IAGR AM_ WIN DOW_ LAY ER) ;
setV isi ble (tr ue);
}
}
package pwuml.elements.links.inheritance;
import javax.swing.*;
g.se tCol or (Se tting s. NOR MAL_C OL OR) ;
import java.awt.*; // d raw ju st in bo un ds
size Fou nd= f alse;
p ublic ClassAp pera nce( Cla ssAp per an ce ID n ewObj ectID, Dia gr amI Ddiag ra mID, Cla ssDat aID clas sID) {
packa ge pwum l.d iag ram mana gem ent ;
publi c c lass Di agr amW indo w
e xten ds JIn tern alF ram e
im pl eme nts Int ern alFr ame Lis ten er {
g.se tCli p( old ClipB ou nds );
oldC lipB ou nds = nu ll;
// we wille valu ate it aft er "em p ty" cl assis cre ate d
f inal sta tic in t FIEL D_A LIG N_ LEF T = 0;
f inal sta tic in t FIEL D_A LIG N_ CENT ER =1 ;
f inal sta tic in t LE FT_MA R GIN =
10;
f inal sta tic in t VE RTICA L_ SPA CE = 4;
int
y Point er ;
b oole an
se tSize( ) ;
/**
MINIMA L_W IDT H= widt h;
* ID of the diagram which is supposed to be
displayed in this
MINIMA L_HEIG HT= he ight ;
window.
}
*/
void lo adDat a( ) {
protected DiagramID
diagramID;
try {
Dat aTra nsfer dt = Re gistry .g etDat aTra nsfe r( ) ;
protected DiagramCanvas diagramCanvas; classDa ta = (C lassDa ta) dt .g et( classID);
} ca tch ( Dat aOb je ct No tE xist Ex ce pt io n ex ) {
protected JScrollPane diagramScrollPane; EL .re por t( EL. INTER NAL_E R ROR , t his, "Class doe sn't ex ist with ID " + classID. to Strin g( ) , ex) ;
pub lic voi d s etS afeC lip (Gr aphic s g, int x, int y, int wi dth , int he ig ht) {
t ransi ent
ClassData cl assDat a;
Me tho dR en dere r m etho dR end er er;
import pwuml.data.datast orage.*;
import pwuml.data.diagram.*;
import pwuml.data.base.*;
import pwuml.error.*;
import pwuml.*;
package pwuml.diagrammanagement;
//i f (ol dClip Bo und s==nu ll) r etur n;
g. set Cli p(old Cl ipB ounds );
/**
ol dCl ipB ounds = nul l;
* Implement s diagram window, creates diagram's toolbar.
*
* @author david
*/
public class DiagramWindow extends JInternalFrame
g. dra wRe ct( p os X, posY, wi dt h, h eigh t) ;
implements InternalFrameListener {
pa int Ins ide(g );
import
pwuml.data.datastorage.*;
re sto reS afeCl ip (g) ;
}
import
pwuml.data.diagram.*;
/**
pu blic v oid pain tS ele cted( Gr aph ics g) {
import
pwuml.data.base.*;
* ID of the diagram which is supposed to be displayed in this
g. set Col or(Se
tt ing s.SEL EC TED _COL OR);
import
pwuml.error.*;
window.
// dr aw just
in bo unds
*/
import
pwuml.*;
se tSa feC lip(g , pos X, po sY, w idth +1, he ight +1);
protected DiagramID diagramID;
g. dra wRe ct( p os X, posY, wi dt h, h eigh t) ;
/**
protected DiagramCanvas diagramCanvas;
pa int Ins ide(g );
*re sto
Implements
diagram window, creat
protected
es diagram's
JScrollPane
toolbar.diagramScrollPane;
reS afeCl ip (g) ;
}
*
pu blic v oid pain tO utl ine(G ra phi cs g ) {
* @aut hor david
public DiagramWindow(DiagramID diagramID) {
g. set Col or(Se tt ing s.SEL EC TED _COL OR);
*/
super();
g. dra wRe ct( p os X, posY, wi dt h, h eigh t) ;
}
public
class DiagramWindow extendst his.diagramID=
JInternalFrame diagramID;
pu blic v oid pain tE dit ed(Gr ap hic
s g) {
init();
implements
InternalFrameListener
{
g. set Col or(Se tt ing s.SEL EC TED _COL OR);
}
///**
dr aw just in bo unds
se tSa feC lip(g , pos X, po sY, w idth +1, he ight +1);
* ID of the diagram which is supposed
protected
to bevoid
displayed
init() {in this
g. dra wRe ct( p os X, posY, wi dt h, h eigh t) ;
window.
DiagramDat a diagram Data= loadDiagramData();
pa int Ins ide(g );
setTitle( diagramData.getDiagramName() );
*/
re sto
reS afeCl ip (g) ;
}
protected DiagramID diagramID;setClosable(true);
pu blic b ool ean c on tai ns(Po in t p oint ) {
protected DiagramCanvas diagramCanvas;
setMaximizable(true);
re tur n g etBou nd s() .cont ain s( poin t);
protected JScrollPane diagramScrollPane;
}
Re ctan gl e o ldCli pB oun ds= n ull ;
pro tect ed int widt h;
pro tect ed int heig ht;
imp ort j av a.a wt.* ;
imp ort j av a.a wt.g eo m.* ;
imp ort j av a.ut il.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
Me thodD at a m et= ( Me tho dDat a) c la ssDa ta.m et hods .get (i) ;
/**
te xtW idth = da taMe trics.st ringW idt h( at tribu te Nam e ) + L EFT _MA RG IN;
if ( widt h<te xt Widt h) widt h= te xt Widt h;
heig ht+ = VER TICA L_S PAC E + te xtHeig ht;
with ID " + cl ass ID .toSt rin g() , ex );
public void internalFrameOpened(InternalFrameEvent
public void internalFrameDeactivat
e) {
ed(InternalFrameEvent e) {
}
Registry.getDiagramActivation().deactivateDiagramWindow(this);
public void internalFrameIconified(Int
}
ernalFrameEvent e) {
}
}
public void internalFrameDeiconified(InternalFrameEvent e) {
}
su pe r(cl ient Ob ject , po sit ion );
public void internalFrameActivated(InternalFrameEvent e) {
Registry.getDiagramActivation().openDiagram(diagramID);
}
}
pu bli c void mov e( Poin t ne wPo sit ion) {
// at tribu tes- m etho ds se par ator
he ight += VE RT ICAL_ SPA CE;
}
Cl as sApp eran ce nod e= ( Cl assA pper anc e) clien tOb je ct;
Po in t ol dPos it ion= get Po siti on() ;
in t newG epX = (int )old Pos iti on.g etX () ;
// m etho ds
/*
g. set Font ( Sett ing s. dat aFon t) ;
m etr ics= g.g etF ont Met rics( ) ;
public void internalFrameDeact ivated(InternalFrameEvent e) {
in t newG epY = (int )old Pos iti on.g etY () ;
in t curr entX = (in t)ne wPo sit ion. get X( );
in t curr entY = (in t)ne wPo sit ion. get Y( );
t ext He ight = me trics.g etHeig ht( ) ;
*/
no de .wid th= cu rren tXno de.po sX;
if ( node .wid th <nod e.MI NIM AL_ WIDT H) no de.wi dth = node. MIN IM AL_W IDTH ;
ne wG epX= nod e. posX + n ode .wi dth;
if ( sh owMe thod s)
f or ( int i= 0;i<cla ssDat a.m et hod s. si ze( ); i++) {
Me thod Data m e t= ( Met hod Da ta) classData. m etho ds.g et (i) ;
Str ing m e thod Name = m eth odR en dere r. rend er Meth od( m et );
tex tW idt h= dat aM etri cs. st rin gWid th( m et hod Na me) + LE FT _MA RG IN;
if ( widt h<t ext W id th) widt h= t ext Widt h;
hei ght+ = VER T IC AL_ SPAC E + te xt Heig ht;
}
no de .hei ght= cu rre ntYnode.p osY;
if ( node .hei gh t<no de.M INI MAL _HEI GHT ) node. hei gh t= no de. MI NIMA L_HE IGH T;
ne wG epY= nod e. posY + n ode .he ight ;
Registry.getDiagramA ct ivation().deactivateDiagramWindow(this);
}
}
up da teOw nPos it ion( new Po int( newG epX , newGe pY) );
he ight += VE RT ICAL_ SPA CE;
widt h+= 1 0;
}
}
sizeF ound = tru e;
}
Modelowanie oprogramowania w języku UML
Michał Śmiałek
5
Modelowanie oprogramowania w języku
UML
Wykład 1
Po co to wszystko?
Aby
wytarzać systemy:
Na czas
W budżecie
Spełniające rzeczywiste potrzeby klienta
Oto moje
potrzeby
To nie takie
proste!
Oto system
spełniający
Twoje potrzeby
Projekt konstrukcji
oprogramowania
Modelowanie oprogramowania w języku UML
Michał Śmiałek
Problemy, problemy@
Niezadowoleni zamawiający: „nie o taki system nam chodziło”, „żaden z naszych
urzędników nie będzie w stanie zrozumieć jak to działa”.
Niezadowoleni wykonawcy: „to właściwie, jaki system oni od nas chcą?”, „przecież
tak ciężko się napracowaliśmy”.
Kłótnie o zakres systemu: „żądacie od nas systemu dwa razy większego niż było
zapisane w umowie!”, „przecież te funkcje miały być uwzględnione dopiero w
następnej wersji”.
Chaotyczna obsługa zmian wymagań: „koledzy, dodajcie nam tu jeszcze taką małą
tabelkę na środku, to was prawie nic nie będzie kosztowało”, „myśleliśmy, że ta
zmiana nie będzie miała dla was istotnego znaczenia”.
Niewyspani programiści: „poprosimy pizzę pod drzwi o północy i dużo Jolt Coli”,
„dajcie nam dziesięciu nowych programistów”.
Stres pod koniec projektu: „ten system działa jak żółw!”, „przecież tu brakuje połowy
funkcjonalności, która jest zapisana w par. 7 pkt. 223 umowy!”.
Brak powtarzalności procesu – wyniki zawsze są trudne do przewidzenia: „to o ile
tym razem przekroczymy budżet?”, „właściwie to jak będziemy tym razem pisać
te wymagania?”.
Godzenie się na „marsz ku klęsce”: „musicie ten system zrobić dwa razy szybciej niż
konkurencja; O.K., nie ma sprawy”.
Modelowanie oprogramowania w języku UML
Michał Śmiałek
6
Modelowanie oprogramowania w języku
UML
Wykład 1
Lekarstwo? Metodyka!
Patrz: wykład z Podstaw inżynierii oprogramowania (2 semestr)
Metodyka to:
Notacja - język modelowania, przy pomocy którego zapisuje się
produkty procesu tworzenia oprogramowania (modele) – UML!
Techniki - zbiór sposobów postępowania w celu stworzenia
konkretnych elementów modeli (zapisanych przy pomocy notacji).
Proces techniczny - uporządkowanie wytwarzania oprogramowania
poprzez wyodrębnienie atomowych zadań do wykonania (przy
użyciu technik) i określenie kolejności i zależności między
zadaniami.
Co więcej:
Narzędzia CASE (będziemy je używać na laboratorium)
Integracja modelowania i programowania (generowanie kodu –
będzie na laboratorium)
Modelowanie oprogramowania w języku UML
Michał Śmiałek
Co dalej? (1)
Podstawy modelowania obiektowego
Obiekty, klasy, interakcje między obiektami, przegląd rodzajów
diagramów
Model przypadków użycia
Notowanie wymagań dla systemu oprogramowania
Model czynności – scenariusze
Notowanie szczegółów dla przypadków użycia
Scenariusze tekstowe (rozszerzenie UML)
Scenariusze w formie diagramów
Model klas
Obiekty – UML jest obiektowy!
Klasy na poziomie wymagań (model dziedziny problemu)
Klasy na poziomie projektu (mapa kodu)
Modelowanie oprogramowania w języku UML
Michał Śmiałek
7
Modelowanie oprogramowania w języku
UML
Wykład 1
Co dalej? (2)
Model interakcji
Model działania systemu jako współdziałania (interakcji) między
obiektami
Diagramy sekwencji – komunikaty, warunki, pętle (kod w formie
diagramu!)
Model komponentów i model montażu
Znacznie ułatwiają pokazanie struktury bardziej złożonych
systemów (kilkadziesiąt klas i więcej)
Na przykład: jak pokazać system składający się z tysiąca klas w
Javie??!!
Modelowanie w procesie wytwarzania oprogramowani
Umiejscowienie języka UML w procesie technicznym
Nawiązanie do przedmiotu „Podstawy inżynierii oprogramowania” z
2 semestru
Modelowanie oprogramowania w języku UML
Michał Śmiałek
Schemat wykładu
Krótkie wprowadzenie do notacji
Przedstawienie głównych elementów języka UML i ich semantyki
(znaczenia)
Aktywna demonstracja
Ćwiczenie wykonywane wspólnie ze studentami
Symulacje działania systemu „na żywo”
Projektowanie systemu „na żywo”
Generacja kodu „na żywo”
itp9
Ćwiczenie
Po niektórych wykładach
Krótkie zadanie do wykonania na podstawie bieżącego wykładu
(max. 15 min)
Modelowanie oprogramowania w języku UML
Michał Śmiałek
8
Modelowanie oprogramowania w języku
UML
Wykład 1
Ćwiczenie (1)
Proszę przeanalizować kod i spróbować narysować wyjaśnienie, jak
ten kod działa.
class wnd : event {
cntrl c;
wnd(cntrl cn) {
c = cn;
}
void on_click(){
c.run();
}
void show(int n){
printf(n);
}
} UWAGA: kod ten nie
jest pisany w jakimś
konkretnym języku,
ale przypomna Javę
lub C#!
class cntrl {
wnd w; dom d;
cntrl(dom dm) {
d = dm;
d.init();
}
void set_wnd(wnd wn){
w = wn;
}
void run(){
num = d.get_next();
w.show(num);
}
void show(int n){
printf(n);
}
}
Modelowanie oprogramowania w języku UML
class dom {
int number;
voin init() {
number = 0;
}
int get_next(){
number = number +1;
return number;
}
main() {
dom d = new dom();
cntrl c = new cntrl(d);
wnd w = new wnd(c);
UI.set_event(wnd);
}
Michał Śmiałek
Ćwiczenie (2)
Wskazówki:
Proszę w jakiś sposób oznaczyć klasy i ich składniki (atrybuty i
operacje)
Proszę w jakiś sposób oznaczyć kolejność (sekwencję) wywołań dla
trzech obiektów (w, c, d) podczas realizacji funkcji „main” oraz
podczas i po wywołaniu funkcji „on_click”.
Najważniejsze:
Rysunki powinny być „mapą” dla kodu, tak, aby łatwiej go można
było zrozumieć i się po nim poruszać.
Rozwiązanie w języku UML? Za tydzień! Na razie proszę wymyślić
dowolny sposób rysowania „obrazków”.
Modelowanie oprogramowania w języku UML
Michał Śmiałek
9

Podobne dokumenty