Node/GenericNode.pm

filter: Statementstmt 80.0% 48 / 60 Branchbran 21.4% 3 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.9% 10 / 11 Podpod 100% 4 / 4 totaltotal 73.0% 65 / 89 CC 11 SCAR 22.6
CC
11
Cov
69%
setJavaStyle
30.0
_addAdditionalNodes
6.5
getJavaStyle
2.1
CRAP 9.6
« Document.pm ↑ Summary PropertyBasedObject.pm »
1 package yEd::Node::GenericNode;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use yEd::PropertyBasedObject;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use base qw(yEd::Node);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 yEd::Node::GenericNode - Generic node type
11  
12 =head1 DESCRIPTION
13  
14 This is a very generic node type.
15 Its shape is defined by its C<configuration> property.
16 Special configurations are defined by using java style properties.
17 This indeed makes the Node type very generic and versatile but also cumbersome to configure as you don't have a GUI.
18  
19 For configuration of these java style properties use C<getJavaStyle()> and C<setJavaStyle()>.
20  
21 Make sure to have a look at L<yEd::Node>, the properties and functions described there will not be repeated here.
22  
23 =head1 SUPPORTED FEATURES
24  
25 The GenericNode type are the nodes defined in the following yEd groups:
26  
27 =over 4
28
29 =item *
30
31 Modern Nodes
32
33 =item *
34
35 Flowchart
36
37 =item *
38
39 BPMN
40
41 =item *
42
43 Entity Relationship
44
45 =back
46  
47 However the node types defined in BPMN are not supported, yet.
48  
49 The Entity Relationship Nodes are added with no Labels, you have to provide them yourself.
50  
51 For basic Node type feature support and which Node types are supported see L<yEd::Node>.
52  
53 =head1 PROPERTIES
54  
55 =head2 all properties from base class
56  
57 L<yEd::Node>
58  
59 =head2 configuration
60  
61 Type: descrete values ( see L</CONFIGURATIONS> section )
62  
63 Default: 'com.yworks.flowchart.cloud'
64  
65 The specialized type of GenericNode.
66  
67 The cloud has been choosen as default because I think people may need it as basic shape even if not working on a flowchart and on the other hand it is one of the types with a rather long identifier.
68  
69 =head1 SUBROUTINES/METHODS
70  
71 =head2 all functions from base class
72  
73 L<yEd::Node>
74  
75 =cut
76  
77 3 my %r = (
78 'bool' => '^(?:true|false)$',
79 'false' => '^false$',
80 );
81 # This one describes the known StyleProperties and how to handle them
82 my %styleProperty = (
83 'ModernNodeShadow' => {
84 'class' => 'java.lang.Boolean',
85 'match' => $r{'bool'},
86 'default' => 'false',
87 'hidevalues' => $r{'false'},
88 },
89 'ModernNodeRadius' => {
90 'class' => 'java.lang.Double',
91 'match' => $match{'ufloat'},
92 'default' => '10.0',
93 },
94 'y.view.ShadowNodePainter.SHADOW_PAINTING' => {
95 'class' => 'java.lang.Boolean',
96 'match' => $r{'bool'},
97 'default' => 'false',
98 },
99 'com.yworks.flowchart.style.orientation' => {
100 'class' => 'java.lang.Byte',
101 'match' => '^[01234]$',
102 'default' => '0',
103 },
104 'doubleBorder' => {
105 'class' => 'java.lang.Boolean',
106 'match' => $r{'bool'},
107 'default' => 'false',
108 3 'hidevalues' => $r{'false'},
109 },
110 );
111 # This one describes the known Configurations and which StyleProperties they support
112 3 my %Configuration = (
113 # Modern Nodes
114 'BevelNode' => {
115 'ModernNodeRadius' => 1,
116 'ModernNodeShadow' => 1,
117 },
118 'BevelNode2' => {
119 'ModernNodeRadius' => 1,
120 'ModernNodeShadow' => 1,
121 },
122 'BevelNode3' => {
123 'ModernNodeRadius' => 1,
124 'ModernNodeShadow' => 1,
125 },
126 'BevelNodeWithShadow' => {
127 'ModernNodeRadius' => 1,
128 'ModernNodeShadow' => 1,
129 },
130 'ShinyPlateNode' => {
131 'ModernNodeRadius' => 1,
132 'ModernNodeShadow' => 1,
133 },
134 'ShinyPlateNode2' => {
135 'ModernNodeRadius' => 1,
136 'ModernNodeShadow' => 1,
137 },
138 'ShinyPlateNode3' => {
139 'ModernNodeRadius' => 1,
140 'ModernNodeShadow' => 1,
141 },
142 'ShinyPlateNodeWithShadow' => {
143 'ModernNodeRadius' => 1,
144 'ModernNodeShadow' => 1,
145 },
146 # Flowchart
147 'com.yworks.flowchart.start1' => {
148 'y.view.ShadowNodePainter.SHADOW_PAINTING' => 1,
149 },
150 'com.yworks.flowchart.start2' => {
151 'y.view.ShadowNodePainter.SHADOW_PAINTING' => 1,
152 },
153 'com.yworks.flowchart.terminator' => {
154 'y.view.ShadowNodePainter.SHADOW_PAINTING' => 1,
155 },
156 'com.yworks.flowchart.process' => {
157 'y.view.ShadowNodePainter.SHADOW_PAINTING' => 1,
158 },
159 'com.yworks.flowchart.predefinedProcess' => {
160 'y.view.ShadowNodePainter.SHADOW_PAINTING' => 1,
161 },
162 'com.yworks.flowchart.decision' => {
163 'y.view.ShadowNodePainter.SHADOW_PAINTING' => 1,
164 },
165 'com.yworks.flowchart.loopLimit' => {
166 'y.view.ShadowNodePainter.SHADOW_PAINTING' => 1,
167 },
168 'com.yworks.flowchart.loopLimitEnd' => {
169 'y.view.ShadowNodePainter.SHADOW_PAINTING' => 1,
170 },
171 'com.yworks.flowchart.document' => {
172 'y.view.ShadowNodePainter.SHADOW_PAINTING' => 1,
173 },
174 'com.yworks.flowchart.data' => {
175 'y.view.ShadowNodePainter.SHADOW_PAINTING' => 1,
176 },
177 'com.yworks.flowchart.directData' => {
178 'y.view.ShadowNodePainter.SHADOW_PAINTING' => 1,
179 },
180 'com.yworks.flowchart.storedData' => {
181 'y.view.ShadowNodePainter.SHADOW_PAINTING' => 1,
182 },
183 'com.yworks.flowchart.sequentialData' => {
184 'y.view.ShadowNodePainter.SHADOW_PAINTING' => 1,
185 },
186 'com.yworks.flowchart.dataBase' => {
187 'y.view.ShadowNodePainter.SHADOW_PAINTING' => 1,
188 },
189 'com.yworks.flowchart.internalStorage' => {
190 'y.view.ShadowNodePainter.SHADOW_PAINTING' => 1,
191 },
192 'com.yworks.flowchart.manualInput' => {
193 'y.view.ShadowNodePainter.SHADOW_PAINTING' => 1,
194 },
195 'com.yworks.flowchart.card' => {
196 'y.view.ShadowNodePainter.SHADOW_PAINTING' => 1,
197 },
198 'com.yworks.flowchart.paperType' => {
199 'y.view.ShadowNodePainter.SHADOW_PAINTING' => 1,
200 },
201 'com.yworks.flowchart.cloud' => {
202 'y.view.ShadowNodePainter.SHADOW_PAINTING' => 1,
203 },
204 'com.yworks.flowchart.delay' => {
205 'y.view.ShadowNodePainter.SHADOW_PAINTING' => 1,
206 },
207 'com.yworks.flowchart.display' => {
208 'y.view.ShadowNodePainter.SHADOW_PAINTING' => 1,
209 },
210 'com.yworks.flowchart.manualOperation' => {
211 'y.view.ShadowNodePainter.SHADOW_PAINTING' => 1,
212 },
213 'com.yworks.flowchart.preparation' => {
214 'y.view.ShadowNodePainter.SHADOW_PAINTING' => 1,
215 },
216 'com.yworks.flowchart.onPageReference' => {
217 'y.view.ShadowNodePainter.SHADOW_PAINTING' => 1,
218 },
219 'com.yworks.flowchart.offPageReference' => {
220 'y.view.ShadowNodePainter.SHADOW_PAINTING' => 1,
221 },
222 'com.yworks.flowchart.userMessage' => {
223 'y.view.ShadowNodePainter.SHADOW_PAINTING' => 1,
224 },
225 'com.yworks.flowchart.networkMessage' => {
226 'y.view.ShadowNodePainter.SHADOW_PAINTING' => 1,
227 },
228 'com.yworks.flowchart.annotation' => {
229 'y.view.ShadowNodePainter.SHADOW_PAINTING' => 1,
230 'com.yworks.flowchart.style.orientation' => 1,
231 },
232 # Entity Relationship
233 'com.yworks.entityRelationship.big_entity' => {
234 'y.view.ShadowNodePainter.SHADOW_PAINTING' => 1,
235 },
236 'com.yworks.entityRelationship.small_entity' => {
237 'y.view.ShadowNodePainter.SHADOW_PAINTING' => 1,
238 'doubleBorder' => 1,
239 },
240 'com.yworks.entityRelationship.relationship' => {
241 'y.view.ShadowNodePainter.SHADOW_PAINTING' => 1,
242 'doubleBorder' => 1,
243 },
244 'com.yworks.entityRelationship.attribute' => {
245 'y.view.ShadowNodePainter.SHADOW_PAINTING' => 1,
246 'doubleBorder' => 1,
247 },
248 );
249  
250 3 my $confregex = '^(?:';
251 3 $confregex .= join '|', keys %Configuration;
252 3 $confregex .= ')$';
253  
254 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
255 1 my ($class, @args) = @_;
256 1 my $self = bless {}, $class;
257 1 return $self->_init(@args);
258 }
259  
260 1 ▶sub _init {
Subroutine _init: called CC=1 SCAR=0.0
261 1 my ($self, @args) = @_;
262 1 $self->configuration('com.yworks.flowchart.cloud');
263 1 $self->SUPER::_init(@args);
264 1 return $self;
265 }
266  
267 3 ▶sub configuration {
Subroutine configuration: called CC=1 SCAR=0.0
Pod documented
268 3 return _PROPERTY($confregex, @_);
269 }
270  
271 =head2 setJavaStyle
272  
273 Takes arguments of the form 'property1 => value, property2 => value2, ...' and sets the provided java style properties accordingly.
274  
275 =head3 EXAMPLE
276  
277 $node->setJavaStyle('y.view.ShadowNodePainter.SHADOW_PAINTING' => 'true');
278  
279 =cut
280  
281 0 ▶sub setJavaStyle {
Subroutine setJavaStyle: not called CC=5 SCAR=34.0
Pod documented
282 0 my $self = shift;
283 0 ▶ confess 'properties must be supplied as key => value pairs (odd number supplied)' if(@_ % 2);
Branch: 1 branch
BranchTrueFalseTotal
if @_ % 2 0 0 0
284 0 my %props = @_;
285 0 foreach my $key (keys %props) {
286 0 ▶ confess "no such property: $key" unless (exists $styleProperty{$key});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $styleProperty{$key} 0 0 0
287 0 my $r = $styleProperty{$key}{'match'};
288 0 my $v = $props{$key};
289 0 ▶ confess "value for property $key doesn't match $r (given value: $v)" unless ($v =~ m/$r/);
Branch: 1 branch
BranchTrueFalseTotal
unless $v =~ /$r/ 0 0 0
290 0 $self->{'java'}{$key} = $v;
291 }
292 0 return;
293 }
294  
295 =head2 getJavaStyle
296  
297 Takes a java style property name as parameter and returns its current value.
298  
299 =head3 EXAMPLE
300  
301 if ($node->getJavaStyle('y.view.ShadowNodePainter.SHADOW_PAINTING') eq 'true') { ...
302  
303 =cut
304  
305 1 ▶sub getJavaStyle {
Subroutine getJavaStyle: called CC=2 SCAR=7.6
Pod documented
306 1 my ($self, $sp) = @_;
307 1 ▶ if (exists $self->{'java'}{$sp}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"java"}{$sp}) 0 1 1
308 0 return $self->{'java'}{$sp};
309 }
310 1 return $styleProperty{$sp}{'default'};
311 }
312  
313 1 ▶sub _addTypeNode {
Subroutine _addTypeNode: called CC=1 SCAR=0.0
314 1 my ($self, $node) = @_;
315 1 my $gen = $node->addNewChild('', 'y:GenericNode');
316 1 $gen->setAttribute('configuration', $self->configuration());
317 1 return $gen;
318 }
319 1 ▶sub _addAdditionalNodes {
Subroutine _addAdditionalNodes: called CC=6 SCAR=18.7
320 1 my ($self, $node) = @_;
321 1 my $t = $self->configuration();
322 1 my @props;
323 1 foreach my $sp (keys %{$Configuration{$t}}) {
324 1 ▶ if (exists $styleProperty{$sp}{'hidevalues'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $styleProperty{$sp}{'hidevalues'}) { } 0 1 1
325 0 ▶ push @props, $sp unless ($self->getJavaStyle($sp) =~ m/$styleProperty{$sp}{'hidevalues'}/);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->getJavaStyle($sp) =~ /$styleProperty{$sp}{"hidevalues"}/ 0 0 0
326 } else {
327 1 push @props, $sp;
328 }
329 }
330 1 ▶ if (@props) {
Branch: 1 branch
BranchTrueFalseTotal
if (@props) 1 0 1
331 1 my $styles = $node->addNewChild('', 'y:StyleProperties');
332 1 foreach my $sp (@props) {
333 1 my $p = $styles->addNewChild('', 'y:Property');
334 1 $p->setAttribute('class', $styleProperty{$sp}{'class'});
335 1 $p->setAttribute('name', $sp);
336 1 $p->setAttribute('value', $self->getJavaStyle($sp));
337 }
338 }
339 }
340  
341 =head1 KNOWN JAVA STYLE PROPERTIES
342  
343 See L</CONFIGURATIONS> for which C<configuration> supports which style.
344  
345 =head2 ModernNodeShadow
346  
347 Type: java.lang.Boolean ('true'|'false')
348  
349 Default: 'false'
350  
351 use shadow
352  
353 =head2 ModernNodeRadius
354  
355 Type: java.lang.Double (ufloat, no negative values allowed here)
356  
357 Default: 10.0
358  
359 corner radius
360  
361 =head2 y.view.ShadowNodePainter.SHADOW_PAINTING
362  
363 Type: java.lang.Boolean ('true'|'false')
364  
365 Default: 'false'
366  
367 use shadow
368  
369 =head2 com.yworks.flowchart.style.orientation
370  
371 Type: java.lang.Byte (^[01234]$)
372  
373 Default: 0
374  
375 orientation of single side border (0 = auto, 1..4 = edges)
376  
377 =head2 doubleBorder
378  
379 Type: java.lang.Boolean ('true'|'false')
380  
381 Default 'false'
382  
383 draw a second border with a slight inset to the first
384  
385 =head1 CONFIGURATIONS
386  
387 =head2 yEd Group: Modern Nodes
388  
389 Styles all: ModernNodeRadius , ModernNodeShadow
390  
391 Configurations:
392  
393 =over 4
394  
395 =item *
396  
397 BevelNode
398  
399 =item *
400  
401 BevelNode2
402  
403 =item *
404  
405 BevelNode3
406  
407 =item *
408  
409 BevelNodeWithShadow
410  
411 =item *
412  
413 ShinyPlateNode
414  
415 =item *
416  
417 ShinyPlateNode2
418  
419 =item *
420  
421 ShinyPlateNode3
422  
423 =item *
424  
425 ShinyPlateNodeWithShadow
426  
427 =back
428  
429 =head2 yEd Group: Flowchart
430  
431 Styles all: y.view.ShadowNodePainter.SHADOW_PAINTING
432  
433 Configurations:
434  
435 =over 4
436  
437 =item *
438  
439 com.yworks.flowchart.start1
440  
441 =item *
442  
443 com.yworks.flowchart.start2
444  
445 =item *
446  
447 com.yworks.flowchart.terminator
448  
449 =item *
450
451 com.yworks.flowchart.process
452  
453 =item *
454
455 com.yworks.flowchart.predefinedProcess
456  
457 =item *
458
459 com.yworks.flowchart.decision
460  
461 =item *
462
463 com.yworks.flowchart.loopLimit
464  
465 =item *
466
467 com.yworks.flowchart.loopLimitEnd
468  
469 =item *
470
471 com.yworks.flowchart.document
472  
473 =item *
474
475 com.yworks.flowchart.data
476  
477 =item *
478
479 com.yworks.flowchart.directData
480  
481 =item *
482
483 com.yworks.flowchart.storedData
484  
485 =item *
486
487 com.yworks.flowchart.sequentialData
488  
489 =item *
490
491 com.yworks.flowchart.dataBase
492  
493 =item *
494
495 com.yworks.flowchart.internalStorage
496  
497 =item *
498
499 com.yworks.flowchart.manualInput
500  
501 =item *
502
503 com.yworks.flowchart.card
504  
505 =item *
506
507 com.yworks.flowchart.paperType
508  
509 =item *
510
511 com.yworks.flowchart.cloud
512  
513 =item *
514
515 com.yworks.flowchart.delay
516  
517 =item *
518
519 com.yworks.flowchart.display
520  
521 =item *
522
523 com.yworks.flowchart.manualOperation
524  
525 =item *
526
527 com.yworks.flowchart.preparation
528  
529 =item *
530
531 com.yworks.flowchart.onPageReference
532  
533 =item *
534
535 com.yworks.flowchart.offPageReference
536  
537 =item *
538
539 com.yworks.flowchart.userMessage
540  
541 =item *
542
543 com.yworks.flowchart.networkMessage
544  
545 =item *
546
547 com.yworks.flowchart.annotation
548  
549 Styles: y.view.ShadowNodePainter.SHADOW_PAINTING , com.yworks.flowchart.style.orientation
550
551 =back
552  
553 =head2 yEd Group: Entity Relationship
554  
555 Configurations:
556  
557 =over 4
558  
559 =item *
560  
561 com.yworks.entityRelationship.big_entity
562  
563 Styles: y.view.ShadowNodePainter.SHADOW_PAINTING
564  
565 =item *
566  
567 com.yworks.entityRelationship.small_entity
568  
569 Styles: y.view.ShadowNodePainter.SHADOW_PAINTING , doubleBorder
570  
571 =item *
572  
573 com.yworks.entityRelationship.relationship
574  
575 Styles: y.view.ShadowNodePainter.SHADOW_PAINTING , doubleBorder
576  
577 =item *
578  
579 com.yworks.entityRelationship.attribute
580  
581 Styles: y.view.ShadowNodePainter.SHADOW_PAINTING , doubleBorder
582  
583 =back
584  
585 =head1 SEE ALSO
586  
587 L<yEd::Document> for further informations about the whole package
588  
589 L<yEd::PropertyBasedObject> for further basic information about properties and their additional functions
590  
591 L<yEd::Node> for information about the Node base class and which other Node types are currently supported
592  
593 =cut
594  
595  
596 3 1;
« Document.pm ↑ Summary PropertyBasedObject.pm »