Re-add graph exporting, add graph label
This commit is contained in:
parent
6830fdd587
commit
25f601b278
@ -157,6 +157,7 @@ public class Functions {
|
|||||||
|
|
||||||
public void plotname(String t) {
|
public void plotname(String t) {
|
||||||
graphwin.setWindowTitle(t);
|
graphwin.setWindowTitle(t);
|
||||||
|
graphwin.setLabel(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String plotname() {
|
public String plotname() {
|
||||||
|
@ -139,6 +139,9 @@
|
|||||||
</Events>
|
</Events>
|
||||||
</Component>
|
</Component>
|
||||||
<Component class="org.math.plot.Plot2DPanel" name="plot">
|
<Component class="org.math.plot.Plot2DPanel" name="plot">
|
||||||
|
<Events>
|
||||||
|
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="plotMouseClicked"/>
|
||||||
|
</Events>
|
||||||
</Component>
|
</Component>
|
||||||
</SubComponents>
|
</SubComponents>
|
||||||
</Form>
|
</Form>
|
||||||
|
@ -29,11 +29,14 @@ package net.apocalypselabs.symat;
|
|||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
|
import java.awt.Font;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import static java.lang.Math.abs;
|
import static java.lang.Math.abs;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import javax.swing.ImageIcon;
|
import javax.swing.ImageIcon;
|
||||||
import javax.swing.JFileChooser;
|
import javax.swing.JFileChooser;
|
||||||
@ -41,6 +44,7 @@ import javax.swing.JOptionPane;
|
|||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
import javax.swing.filechooser.FileFilter;
|
import javax.swing.filechooser.FileFilter;
|
||||||
import javax.swing.filechooser.FileNameExtensionFilter;
|
import javax.swing.filechooser.FileNameExtensionFilter;
|
||||||
|
import org.math.plot.plotObjects.BaseLabel;
|
||||||
import org.matheclipse.core.eval.EvalUtilities;
|
import org.matheclipse.core.eval.EvalUtilities;
|
||||||
import org.matheclipse.parser.client.math.MathException;
|
import org.matheclipse.parser.client.math.MathException;
|
||||||
|
|
||||||
@ -55,6 +59,8 @@ public class Graph extends javax.swing.JInternalFrame {
|
|||||||
private boolean standalone = true;
|
private boolean standalone = true;
|
||||||
private boolean customName = false;
|
private boolean customName = false;
|
||||||
|
|
||||||
|
private BaseLabel lbl = new BaseLabel("", Color.black, 0.5, 1.1);
|
||||||
|
|
||||||
// History, used for redrawing when scale changed.
|
// History, used for redrawing when scale changed.
|
||||||
private String history = "";
|
private String history = "";
|
||||||
|
|
||||||
@ -87,6 +93,8 @@ public class Graph extends javax.swing.JInternalFrame {
|
|||||||
plot.plotToolBar.remove(5);
|
plot.plotToolBar.remove(5);
|
||||||
plot.plotToolBar.remove(4);
|
plot.plotToolBar.remove(4);
|
||||||
plot.plotToolBar.remove(3);
|
plot.plotToolBar.remove(3);
|
||||||
|
lbl.setFont(new Font("Courier", Font.BOLD, 18));
|
||||||
|
plot.addPlotable(lbl);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -153,6 +161,12 @@ public class Graph extends javax.swing.JInternalFrame {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
plot.addMouseListener(new java.awt.event.MouseAdapter() {
|
||||||
|
public void mouseClicked(java.awt.event.MouseEvent evt) {
|
||||||
|
plotMouseClicked(evt);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
jMenu1.setText("File");
|
jMenu1.setText("File");
|
||||||
|
|
||||||
exportBtn.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
|
exportBtn.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
|
||||||
@ -362,7 +376,18 @@ public class Graph extends javax.swing.JInternalFrame {
|
|||||||
}//GEN-LAST:event_clrGraphBtnActionPerformed
|
}//GEN-LAST:event_clrGraphBtnActionPerformed
|
||||||
|
|
||||||
private void exportBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportBtnActionPerformed
|
private void exportBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportBtnActionPerformed
|
||||||
|
int result = fc.showSaveDialog(MainGUI.mainPane);
|
||||||
|
if (result == JFileChooser.APPROVE_OPTION) {
|
||||||
|
File file = new File(addSaveExt(fc.getSelectedFile().toString()));
|
||||||
|
try {
|
||||||
|
plot.toGraphicFile(file);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
JOptionPane.showInternalMessageDialog(this,
|
||||||
|
"Image export failed!",
|
||||||
|
"Error",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
|
}
|
||||||
|
}
|
||||||
}//GEN-LAST:event_exportBtnActionPerformed
|
}//GEN-LAST:event_exportBtnActionPerformed
|
||||||
|
|
||||||
private void setTitleBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_setTitleBtnActionPerformed
|
private void setTitleBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_setTitleBtnActionPerformed
|
||||||
@ -372,9 +397,14 @@ public class Graph extends javax.swing.JInternalFrame {
|
|||||||
JOptionPane.QUESTION_MESSAGE);
|
JOptionPane.QUESTION_MESSAGE);
|
||||||
if (wintitle != null && !wintitle.equals("")) {
|
if (wintitle != null && !wintitle.equals("")) {
|
||||||
setWindowTitle(wintitle);
|
setWindowTitle(wintitle);
|
||||||
|
setLabel(wintitle);
|
||||||
}
|
}
|
||||||
}//GEN-LAST:event_setTitleBtnActionPerformed
|
}//GEN-LAST:event_setTitleBtnActionPerformed
|
||||||
|
|
||||||
|
private void plotMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_plotMouseClicked
|
||||||
|
|
||||||
|
}//GEN-LAST:event_plotMouseClicked
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the range of the graph.
|
* Get the range of the graph.
|
||||||
*
|
*
|
||||||
@ -390,6 +420,7 @@ public class Graph extends javax.swing.JInternalFrame {
|
|||||||
xmax = max;
|
xmax = max;
|
||||||
|
|
||||||
clearDraw(false);
|
clearDraw(false);
|
||||||
|
plot.setFixedBounds(0, min, max);
|
||||||
if (!history.trim().equals("")) {
|
if (!history.trim().equals("")) {
|
||||||
String temp = "";
|
String temp = "";
|
||||||
for (String cmd : history.trim().split("\n")) {
|
for (String cmd : history.trim().split("\n")) {
|
||||||
@ -415,6 +446,10 @@ public class Graph extends javax.swing.JInternalFrame {
|
|||||||
plotBtnActionPerformed(null);
|
plotBtnActionPerformed(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setLabel(String label) {
|
||||||
|
lbl.setText(label);
|
||||||
|
}
|
||||||
|
|
||||||
private String addSaveExt(String path) {
|
private String addSaveExt(String path) {
|
||||||
if (!path.matches(".*\\.(png)")) {
|
if (!path.matches(".*\\.(png)")) {
|
||||||
path += ".png";
|
path += ".png";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user