-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathPanelImage.java
More file actions
93 lines (79 loc) · 2.24 KB
/
PanelImage.java
File metadata and controls
93 lines (79 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
/*
* bilib --- Java Bioimaging Library ---
*
* Author: Daniel Sage, Biomedical Imaging Group, EPFL, Lausanne, Switzerland
*
* Conditions of use: You are free to use this software for research or
* educational purposes. In addition, we expect you to include adequate
* citations and acknowledgments whenever you present or publish results that
* are based on it.
*/
/*
* Copyright 2010-2017 Biomedical Imaging Group at the EPFL.
*
* This file is part of DeconvolutionLab2 (DL2).
*
* DL2 is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* DL2 is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* DL2. If not, see <http://www.gnu.org/licenses/>.
*/
package bilib.component;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import javax.swing.JPanel;
import resources.ImageLoader;
public class PanelImage extends JPanel {
private Image image;
private int w = -1;
private int h = -1;
public PanelImage() {
super();
}
public PanelImage(String filename) {
super();
image = ImageLoader.get(filename);
}
public PanelImage(int w, int h) {
super();
image = null;
this.w = w;
this.h = h;
}
public PanelImage(String filename, int w, int h) {
super();
image = ImageLoader.get(filename);
this.w = w;
this.h = h;
}
public void setImage(BufferedImage image) {
this.image = image;
repaint();
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
if (image != null) {
if (w < 0)
g.drawImage(image, 0, 0, getWidth(), getHeight(), null);
else {
g.setColor(Color.WHITE);
g.fillRect(0, 0, getWidth(), getHeight());
g.drawImage(image, (getWidth()-w)/2, 0, w, h, null);
}
}
else {
g.setColor(Color.DARK_GRAY);
g.fillRect(0, 0, getWidth(), getHeight());
}
}
}