parent
6c08d74fd6
commit
f08187d87f
@ -1027,10 +1027,10 @@ public class FunctionArea extends DArea implements Serializable {
|
|||||||
public void toggleLog() {
|
public void toggleLog() {
|
||||||
boolean setMinPos = false;
|
boolean setMinPos = false;
|
||||||
if (!log && !checkLoggable()) {
|
if (!log && !checkLoggable()) {
|
||||||
LOGGER.warning("Warning: toggling logarithmic scale with values <= 0! Some points will not be displayed.");
|
LOGGER.warning("Toggling logarithmic scale with values <= 0! Some points will not be displayed.");
|
||||||
setMinPos = true;
|
setMinPos = true;
|
||||||
}
|
}
|
||||||
if (log == false) {
|
if (!log) {
|
||||||
setMinRectangle(0.001, 0.001, 1, 1);
|
setMinRectangle(0.001, 0.001, 1, 1);
|
||||||
// setVisibleRectangle( 0.001, 0.001, 100000, 1000 );
|
// setVisibleRectangle( 0.001, 0.001, 100000, 1000 );
|
||||||
Exp exp = new Exp();
|
Exp exp = new Exp();
|
||||||
|
@ -11,6 +11,8 @@ import javax.imageio.ImageIO;
|
|||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import javax.swing.event.InternalFrameAdapter;
|
import javax.swing.event.InternalFrameAdapter;
|
||||||
import javax.swing.event.InternalFrameEvent;
|
import javax.swing.event.InternalFrameEvent;
|
||||||
|
import javax.swing.plaf.IconUIResource;
|
||||||
|
import javax.swing.plaf.metal.MetalIconFactory;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
@ -79,62 +81,62 @@ public class Plot implements PlotInterface, Serializable {
|
|||||||
|
|
||||||
protected void installButtons(JPanel buttonPan) {
|
protected void installButtons(JPanel buttonPan) {
|
||||||
JButton clearButton = new JButton("Clear");
|
JButton clearButton = new JButton("Clear");
|
||||||
clearButton.addActionListener(new ActionListener() {
|
clearButton.addActionListener(e -> clearAll());
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
clearAll();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
JButton loglinButton = new JButton("Log/Lin");
|
JButton loglinButton = new JButton("Log/Lin");
|
||||||
loglinButton.setToolTipText("Toggle between a linear and a log scale on the y-axis.");
|
loglinButton.setToolTipText("Toggle between a linear and a log scale on the y-axis.");
|
||||||
loglinButton.addActionListener(new ActionListener() {
|
loglinButton.addActionListener(e -> plotArea.toggleLog());
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
plotArea.toggleLog();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
JButton exportButton = new JButton("Export to TSV");
|
JButton exportButton = new JButton("Export to TSV");
|
||||||
exportButton.setToolTipText("Exports the graph data to a simple TSV file.");
|
exportButton.setToolTipText("Exports the graph data to a simple TSV file.");
|
||||||
exportButton.addActionListener(new ActionListener() {
|
exportButton.addActionListener(e -> exportPlot());
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
exportPlot();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
JButton dumpButton = new JButton("Dump");
|
JButton dumpButton = new JButton("Dump");
|
||||||
dumpButton.setToolTipText("Dump the graph data to standard output");
|
dumpButton.setToolTipText("Dump the graph data to standard output");
|
||||||
dumpButton.addActionListener(new ActionListener() {
|
dumpButton.addActionListener(e -> plotArea.exportToAscii());
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
plotArea.exportToAscii();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
JButton saveImageButton = new JButton("Save as PNG...");
|
JButton saveImageButton = new JButton("Save as PNG...");
|
||||||
saveImageButton.addActionListener(new ActionListener() {
|
saveImageButton.addActionListener(e -> {
|
||||||
|
FunctionArea fArea = getFunctionArea();
|
||||||
|
|
||||||
@Override
|
Object[] resolutions = {new Dimension(1920, 1080), new Dimension(1024, 768)};
|
||||||
public void actionPerformed(ActionEvent e) {
|
Dimension outputDimension = (Dimension)JOptionPane.showInputDialog(
|
||||||
FunctionArea fArea = getFunctionArea();
|
fArea,
|
||||||
BufferedImage bImg = new BufferedImage(fArea.getWidth(), fArea.getWidth(), BufferedImage.TYPE_INT_RGB);
|
"Select image resolution: ",
|
||||||
|
"Image Resolution",
|
||||||
|
JOptionPane.PLAIN_MESSAGE,
|
||||||
|
MetalIconFactory.getTreeComputerIcon(),
|
||||||
|
resolutions,
|
||||||
|
resolutions[0]
|
||||||
|
);
|
||||||
|
|
||||||
Graphics2D g = bImg.createGraphics();
|
// User pressed cancel
|
||||||
fArea.paintAll(g);
|
if (outputDimension == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
JFileChooser fc = new JFileChooser();
|
BufferedImage bImg = new BufferedImage((int)outputDimension.getWidth(), (int)outputDimension.getHeight(), BufferedImage.TYPE_INT_RGB);
|
||||||
if (fc.showSaveDialog(internalFrame) != JFileChooser.APPROVE_OPTION) {
|
|
||||||
return;
|
Graphics2D g = bImg.createGraphics();
|
||||||
}
|
// Store old dimensions
|
||||||
try {
|
Dimension d = fArea.getSize();
|
||||||
File file = new File(fc.getSelectedFile().getAbsolutePath() + ".png");
|
// Resize FunctionArea temporarily
|
||||||
ImageIO.write(bImg, "png", file);
|
fArea.setSize(outputDimension);
|
||||||
} catch (Exception eee) {
|
// Draw graph
|
||||||
System.err.println("Error on exporting PNG: " + eee.getMessage());
|
fArea.paintAll(g);
|
||||||
}
|
// Restore old size
|
||||||
|
fArea.setSize(d);
|
||||||
|
|
||||||
|
// Let user choose output path and filename
|
||||||
|
JFileChooser fc = new JFileChooser();
|
||||||
|
if (fc.showSaveDialog(internalFrame) != JFileChooser.APPROVE_OPTION) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
File file = new File(fc.getSelectedFile().getAbsolutePath() + ".png");
|
||||||
|
ImageIO.write(bImg, "png", file);
|
||||||
|
} catch (Exception eee) {
|
||||||
|
System.err.println("Error on exporting PNG: " + eee.getMessage());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -161,8 +163,7 @@ public class Plot implements PlotInterface, Serializable {
|
|||||||
installButtons(buttonPanel);
|
installButtons(buttonPanel);
|
||||||
|
|
||||||
internalFrame.add(buttonPanel, BorderLayout.PAGE_END);
|
internalFrame.add(buttonPanel, BorderLayout.PAGE_END);
|
||||||
internalFrame.add(plotArea, BorderLayout.CENTER); // north was not so
|
internalFrame.add(plotArea, BorderLayout.CENTER); // north was not so nice
|
||||||
// nice
|
|
||||||
internalFrame.addInternalFrameListener(new InternalFrameAdapter() {
|
internalFrame.addInternalFrameListener(new InternalFrameAdapter() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -299,16 +300,16 @@ public class Plot implements PlotInterface, Serializable {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void clearGraph(int GraphNumber) {
|
public void clearGraph(int graphNumber) {
|
||||||
plotArea.clearGraph(GraphNumber);
|
plotArea.clearGraph(graphNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setInfoString(int GraphLabel, String Info, float stroke) {
|
public void setInfoString(int graphLabel, String info, float stroke) {
|
||||||
plotArea.setInfoString(GraphLabel, Info, stroke);
|
plotArea.setInfoString(graphLabel, info, stroke);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user