forked from jgraph/mxgraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmxImageCanvas.java
More file actions
executable file
·143 lines (121 loc) · 2.24 KB
/
Copy pathmxImageCanvas.java
File metadata and controls
executable file
·143 lines (121 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/**
* $Id: mxImageCanvas.java,v 1.14 2010/12/03 10:08:46 gaudenz Exp $
* Copyright (c) 2007-2010, Gaudenz Alder, David Benson
*/
package com.mxgraph.canvas;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.image.BufferedImage;
import com.mxgraph.util.mxUtils;
import com.mxgraph.view.mxCellState;
/**
* An implementation of a canvas that uses Graphics2D for painting. To use an
* image canvas for an existing graphics canvas and create an image the
* following code is used:
*
* <code>BufferedImage image = mxCellRenderer.createBufferedImage(graph, cells, 1, Color.white, true, null, canvas);</code>
*/
public class mxImageCanvas implements mxICanvas
{
/**
*
*/
protected mxGraphics2DCanvas canvas;
/**
*
*/
protected Graphics2D previousGraphics;
/**
*
*/
protected BufferedImage image;
/**
*
*/
public mxImageCanvas(mxGraphics2DCanvas canvas, int width, int height,
Color background, boolean antiAlias)
{
this.canvas = canvas;
previousGraphics = canvas.getGraphics();
image = mxUtils.createBufferedImage(width, height, background);
if (image != null)
{
Graphics2D g = image.createGraphics();
mxUtils.setAntiAlias(g, antiAlias, true);
canvas.setGraphics(g);
}
}
/**
*
*/
public mxGraphics2DCanvas getGraphicsCanvas()
{
return canvas;
}
/**
*
*/
public BufferedImage getImage()
{
return image;
}
/**
*
*/
public Object drawCell(mxCellState state)
{
return canvas.drawCell(state);
}
/**
*
*/
public Object drawLabel(String label, mxCellState state, boolean html)
{
return canvas.drawLabel(label, state, html);
}
/**
*
*/
public double getScale()
{
return canvas.getScale();
}
/**
*
*/
public Point getTranslate()
{
return canvas.getTranslate();
}
/**
*
*/
public void setScale(double scale)
{
canvas.setScale(scale);
}
/**
*
*/
public void setTranslate(int dx, int dy)
{
canvas.setTranslate(dx, dy);
}
/**
*
*/
public BufferedImage destroy()
{
BufferedImage tmp = image;
if (canvas.getGraphics() != null)
{
canvas.getGraphics().dispose();
}
canvas.setGraphics(previousGraphics);
previousGraphics = null;
canvas = null;
image = null;
return tmp;
}
}