Skip to content

Commit 8061edc

Browse files
committed
Add JFrame preview
1 parent b048b78 commit 8061edc

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,13 @@
33

44
A simple Java wraper for Python's matplotlib.
55

6-
See the examples [here](docs/examples.ipynb) or run the examples [online](https://mybinder.org/v2/gh/ruivieira/java-plotlib/master?filepath=docs%2Fexamples.ipynb).
6+
See the examples [here](docs/examples.ipynb) or run the examples [online](https://mybinder.org/v2/gh/ruivieira/java-plotlib/master?filepath=docs%2Fexamples.ipynb).
7+
8+
## features
9+
10+
* Line plots
11+
* Scatter plots
12+
* Histograms
13+
* Interpolation plots
14+
* Axis lines, domain limits
15+
* Export to PNG, Base64 and preview.

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>org.ruivieira</groupId>
88
<artifactId>java-plotlib</artifactId>
9-
<version>0.0.9</version>
9+
<version>0.0.10</version>
1010

1111
<build>
1212
<plugins>

src/main/java/org/ruivieira/plotlib/Figure.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import org.pmw.tinylog.Logger;
44

55
import javax.imageio.ImageIO;
6+
import javax.swing.*;
7+
import java.awt.*;
68
import java.awt.image.BufferedImage;
79
import java.io.*;
810
import java.nio.charset.Charset;
@@ -68,4 +70,31 @@ public String getPython() {
6870
public void setPython(String python) {
6971
this.python = python;
7072
}
73+
74+
public void show() {
75+
File tempFile = null;
76+
try {
77+
tempFile = File.createTempFile("tmp", ".png");
78+
} catch (IOException e) {
79+
e.printStackTrace();
80+
}
81+
save(tempFile.getAbsolutePath());
82+
ImageViewer frame = new ImageViewer(tempFile.getAbsolutePath());
83+
frame.setSize(640, 480);
84+
frame.setVisible(true);
85+
86+
}
87+
88+
private class ImageViewer extends JFrame
89+
{
90+
private ImageViewer(String arg){
91+
JPanel panel = new JPanel();
92+
panel.setSize(480,640);
93+
ImageIcon icon = new ImageIcon(arg);
94+
JLabel label = new JLabel();
95+
label.setIcon(icon);
96+
panel.add(label);
97+
this.getContentPane().add(panel);
98+
}
99+
}
71100
}

0 commit comments

Comments
 (0)