| UmlClassLabelPainter.java |
1 /****************************************************************************
2 * This demo file is part of yFiles for Java 2.14.
3 * Copyright (c) 2000-2017 by yWorks GmbH, Vor dem Kreuzberg 28,
4 * 72070 Tuebingen, Germany. All rights reserved.
5 *
6 * yFiles demo files exhibit yFiles for Java functionalities. Any redistribution
7 * of demo files in source code or binary form, with or without
8 * modification, is not permitted.
9 *
10 * Owners of a valid software license for a yFiles for Java version that this
11 * demo is shipped with are allowed to use the demo source code as basis
12 * for their own yFiles for Java powered applications. Use of such programs is
13 * governed by the rights and conditions as set out in the yFiles for Java
14 * license agreement.
15 *
16 * THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
19 * NO EVENT SHALL yWorks BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 *
27 ***************************************************************************/
28 package demo.view.uml;
29
30 import y.geom.OrientedRectangle;
31 import y.view.NodeLabel;
32 import y.view.YLabel;
33
34 import java.awt.Graphics2D;
35 import java.util.Map;
36
37 /**
38 * Decorates a label painter to prevent selection box painting.
39 */
40 class UmlClassLabelPainter implements YLabel.Painter {
41 private final YLabel.Painter painter;
42
43 public UmlClassLabelPainter() {
44 this(defaultPainter());
45 }
46
47 public UmlClassLabelPainter(final YLabel.Painter painter) {
48 this.painter = painter;
49 }
50
51 public void paint(final YLabel label, final Graphics2D gfx) {
52 if (painter != null) {
53 painter.paint(label, gfx);
54 }
55 }
56
57 public void paintContent(
58 final YLabel label,
59 final Graphics2D gfx,
60 final double x,
61 final double y,
62 final double width,
63 final double height
64 ) {
65 if (painter != null) {
66 painter.paintContent(label, gfx, x, y, width, height);
67 }
68 }
69
70 public void paintBox(
71 final YLabel label,
72 final Graphics2D gfx,
73 final double x,
74 final double y,
75 final double width,
76 final double height
77 ) {
78 // Do not draw the selection box.
79 }
80
81 public OrientedRectangle getTextBox(final YLabel label) {
82 if (painter != null) {
83 return painter.getTextBox(label);
84 } else {
85 return null;
86 }
87 }
88
89 public OrientedRectangle getIconBox(final YLabel label) {
90 if (painter != null) {
91 return painter.getIconBox(label);
92 } else {
93 return null;
94 }
95 }
96
97 static YLabel.Painter defaultPainter() {
98 final YLabel.Factory factory = NodeLabel.getFactory();
99 final Map configuration = factory.createDefaultConfigurationMap();
100 final Object painter = configuration.get(YLabel.Painter.class);
101 if (painter instanceof YLabel.Painter) {
102 return (YLabel.Painter) painter;
103 } else {
104 return null;
105 }
106 }
107 }
108