Permalink
Browse files

Merge pull request #33 from panossot/jmathPlotJAM

Changes needed in order not to get a null exception when trying to display the images within a jar file.
  • Loading branch information...
yannrichet committed Nov 12, 2017
2 parents b01c7bc + ef8c9da commit 8256c0602d1406c2ce9f004e2a304808a416be86
Showing with 126 additions and 121 deletions.
  1. +126 −121 src/main/java/org/math/plot/components/PlotToolBar.java
@@ -6,13 +6,14 @@
import javax.swing.*;
import javax.swing.filechooser.FileFilter;
import javax.imageio.ImageIO;
import org.math.plot.*;
import org.math.plot.canvas.*;
/**
* BSD License
*
*
* @author Yann RICHET
*/
public class PlotToolBar extends JToolBar {
@@ -32,7 +33,9 @@
protected JButton buttonAdjustBounds;
private boolean denySaveSecurity;
private JFileChooser pngFileChooser;
/** the currently selected PlotPanel */
/**
* the currently selected PlotPanel
*/
private PlotCanvas plotCanvas;
private PlotPanel plotPanel;
@@ -56,157 +59,155 @@ public String getDescription() {
denySaveSecurity = true;
}
buttonGroup = new ButtonGroup();
buttonCenter = new JToggleButton(new ImageIcon(PlotPanel.class.getResource("icons/center.png")));
buttonCenter.setToolTipText("Center axis");
buttonCenter.setSelected(plotCanvas.ActionMode == PlotCanvas.TRANSLATION);
buttonZoom = new JToggleButton(new ImageIcon(PlotPanel.class.getResource("icons/zoom.png")));
buttonZoom.setToolTipText("Zoom");
buttonZoom.setSelected(plotCanvas.ActionMode == PlotCanvas.ZOOM);
//buttonEdit = new JToggleButton(new ImageIcon(PlotPanel.class.getResource("icons/edit.png")));
//buttonEdit.setToolTipText("Edit mode");
//buttonViewCoords = new JToggleButton(new ImageIcon(PlotPanel.class.getResource("icons/position.png")));
//buttonViewCoords.setToolTipText("Highlight coordinates / Highlight plot");
buttonSetScales = new JButton(new ImageIcon(PlotPanel.class.getResource("icons/scale.png")));
buttonSetScales.setToolTipText("Edit axis scales");
buttonDatas = new JButton(new ImageIcon(PlotPanel.class.getResource("icons/data.png")));
buttonDatas.setToolTipText("Get data");
buttonSavePNGFile = new JButton(new ImageIcon(PlotPanel.class.getResource("icons/topngfile.png")));
buttonSavePNGFile.setToolTipText("Save graphics in a .PNG File");
buttonReset = new JButton(new ImageIcon(PlotPanel.class.getResource("icons/back.png")));
buttonReset.setToolTipText("Reset zoom & axis");
try {
buttonGroup = new ButtonGroup();
buttonAdjustBounds = new JButton(new ImageIcon(PlotPanel.class.getResource(plotCanvas.getAdjustBounds() ? "icons/adjustbounds.png" : "icons/noadjustbounds.png")));
buttonAdjustBounds.setToolTipText("Auto-update/fix bounds");
buttonCenter = new JToggleButton(new ImageIcon(ImageIO.read(PlotPanel.class.getResourceAsStream("icons/center.png"))));
buttonCenter.setToolTipText("Center axis");
buttonCenter.setSelected(plotCanvas.ActionMode == PlotCanvas.TRANSLATION);
/*buttonEdit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
plotCanvas.ActionMode = PlotCanvas.EDIT;
}
});*/
buttonZoom = new JToggleButton(new ImageIcon(ImageIO.read(PlotPanel.class.getResourceAsStream("icons/zoom.png"))));
buttonZoom.setToolTipText("Zoom");
buttonZoom.setSelected(plotCanvas.ActionMode == PlotCanvas.ZOOM);
buttonZoom.setSelected(true);
buttonZoom.addActionListener(new ActionListener() {
//buttonEdit = new JToggleButton(new ImageIcon(PlotPanel.class.getResource("icons/edit.png")));
//buttonEdit.setToolTipText("Edit mode");
//buttonViewCoords = new JToggleButton(new ImageIcon(PlotPanel.class.getResource("icons/position.png")));
//buttonViewCoords.setToolTipText("Highlight coordinates / Highlight plot");
buttonSetScales = new JButton(new ImageIcon(ImageIO.read(PlotPanel.class.getResourceAsStream("icons/scale.png"))));
buttonSetScales.setToolTipText("Edit axis scales");
public void actionPerformed(ActionEvent e) {
plotCanvas.ActionMode = PlotCanvas.ZOOM;
}
});
buttonDatas = new JButton(new ImageIcon(ImageIO.read(PlotPanel.class.getResourceAsStream("icons/data.png"))));
buttonDatas.setToolTipText("Get data");
buttonCenter.addActionListener(new ActionListener() {
buttonSavePNGFile = new JButton(new ImageIcon(ImageIO.read(PlotPanel.class.getResourceAsStream("icons/topngfile.png"))));
buttonSavePNGFile.setToolTipText("Save graphics in a .PNG File");
public void actionPerformed(ActionEvent e) {
plotCanvas.ActionMode = PlotCanvas.TRANSLATION;
}
});
buttonReset = new JButton(new ImageIcon(PlotPanel.class.getResource("icons/back.png")));
buttonReset.setToolTipText("Reset zoom & axis");
/*buttonViewCoords.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
plotCanvas.setNoteCoords(buttonViewCoords.isSelected());
}
});*/
buttonAdjustBounds = new JButton(new ImageIcon(ImageIO.read(PlotPanel.class.getResourceAsStream(plotCanvas.getAdjustBounds() ? "icons/adjustbounds.png" : "icons/noadjustbounds.png"))));
buttonAdjustBounds.setToolTipText("Auto-update/fix bounds");
buttonSetScales.addActionListener(new ActionListener() {
/*buttonEdit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
plotCanvas.ActionMode = PlotCanvas.EDIT;
}
});*/
buttonZoom.setSelected(true);
buttonZoom.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
plotCanvas.displayScalesFrame();
}
});
public void actionPerformed(ActionEvent e) {
plotCanvas.ActionMode = PlotCanvas.ZOOM;
}
});
buttonDatas.addActionListener(new ActionListener() {
buttonCenter.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
plotCanvas.displayDataFrame();
}
});
public void actionPerformed(ActionEvent e) {
plotCanvas.ActionMode = PlotCanvas.TRANSLATION;
}
});
buttonSavePNGFile.addActionListener(new ActionListener() {
/*buttonViewCoords.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
plotCanvas.setNoteCoords(buttonViewCoords.isSelected());
}
});*/
buttonSetScales.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
choosePNGFile();
}
});
public void actionPerformed(ActionEvent e) {
plotCanvas.displayScalesFrame();
}
});
buttonReset.addActionListener(new ActionListener() {
buttonDatas.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
plotCanvas.resetBase();
}
});
public void actionPerformed(ActionEvent e) {
plotCanvas.displayDataFrame();
}
});
buttonAdjustBounds.addActionListener(new ActionListener() {
buttonSavePNGFile.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
plotCanvas.setAdjustBounds(!plotCanvas.getAdjustBounds());
ajustBoundsChanged();
}
});
buttonGroup.add(buttonCenter);
buttonGroup.add(buttonZoom);
//buttonGroup.add(buttonEdit);
add(buttonCenter, null);
add(buttonZoom, null);
add(buttonReset, null);
//add(buttonViewCoords, null);
add(buttonSetScales, null);
if (adjustBoundsVisible) {
add(buttonAdjustBounds, null);
}
//add(buttonEdit, null);
add(buttonSavePNGFile, null);
add(buttonDatas, null);
public void actionPerformed(ActionEvent e) {
choosePNGFile();
}
});
if (!denySaveSecurity) {
pngFileChooser.addActionListener(new ActionListener() {
buttonReset.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
saveGraphicFile();
plotCanvas.resetBase();
}
});
} else {
buttonSavePNGFile.setEnabled(false);
}
//buttonEdit.setEnabled(plotCanvas.getEditable());
buttonAdjustBounds.addActionListener(new ActionListener() {
//buttonViewCoords.setEnabled(plotCanvas.getNotable());
public void actionPerformed(ActionEvent e) {
plotCanvas.setAdjustBounds(!plotCanvas.getAdjustBounds());
ajustBoundsChanged();
}
});
// allow mixed (2D/3D) plots managed by one toolbar
if (plotCanvas instanceof Plot3DCanvas) {
if (buttonRotate == null) {
buttonRotate = new JToggleButton(new ImageIcon(PlotPanel.class.getResource("icons/rotation.png")));
buttonRotate.setToolTipText("Rotate axes");
buttonGroup.add(buttonCenter);
buttonGroup.add(buttonZoom);
//buttonGroup.add(buttonEdit);
add(buttonCenter, null);
add(buttonZoom, null);
add(buttonReset, null);
//add(buttonViewCoords, null);
add(buttonSetScales, null);
if (adjustBoundsVisible) {
add(buttonAdjustBounds, null);
}
//add(buttonEdit, null);
add(buttonSavePNGFile, null);
add(buttonDatas, null);
buttonRotate.addActionListener(new ActionListener() {
if (!denySaveSecurity) {
pngFileChooser.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
plotCanvas.ActionMode = Plot3DCanvas.ROTATION;
saveGraphicFile();
}
});
buttonGroup.add(buttonRotate);
add(buttonRotate, null, 2);
buttonRotate.setSelected(plotCanvas.ActionMode == Plot3DCanvas.ROTATION);
} else {
buttonRotate.setEnabled(true);
buttonSavePNGFile.setEnabled(false);
}
} else {
if (buttonRotate != null) {
// no removal/disabling just disable
if (plotCanvas.ActionMode == Plot3DCanvas.ROTATION) {
plotCanvas.ActionMode = PlotCanvas.ZOOM;
//buttonEdit.setEnabled(plotCanvas.getEditable());
//buttonViewCoords.setEnabled(plotCanvas.getNotable());
// allow mixed (2D/3D) plots managed by one toolbar
if (plotCanvas instanceof Plot3DCanvas) {
if (buttonRotate == null) {
buttonRotate = new JToggleButton(new ImageIcon(ImageIO.read(PlotPanel.class.getResourceAsStream("icons/rotation.png"))));
buttonRotate.setToolTipText("Rotate axes");
buttonRotate.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
plotCanvas.ActionMode = Plot3DCanvas.ROTATION;
}
});
buttonGroup.add(buttonRotate);
add(buttonRotate, null, 2);
buttonRotate.setSelected(plotCanvas.ActionMode == Plot3DCanvas.ROTATION);
} else {
buttonRotate.setEnabled(true);
}
} else {
if (buttonRotate != null) {
// no removal/disabling just disable
if (plotCanvas.ActionMode == Plot3DCanvas.ROTATION) {
plotCanvas.ActionMode = PlotCanvas.ZOOM;
}
buttonRotate.setEnabled(false);
}
buttonRotate.setEnabled(false);
}
} catch (Exception e) {
e.printStackTrace();
}
}
@@ -237,6 +238,10 @@ public void viewAdjustBounds(boolean visible) {
}
public void ajustBoundsChanged() {
buttonAdjustBounds.setIcon(new ImageIcon(PlotPanel.class.getResource(plotCanvas.getAdjustBounds() ? "icons/adjustbounds.png" : "icons/noadjustbounds.png")));
try {
buttonAdjustBounds.setIcon(new ImageIcon(ImageIO.read(PlotPanel.class.getResourceAsStream(plotCanvas.getAdjustBounds() ? "icons/adjustbounds.png" : "icons/noadjustbounds.png"))));
} catch (Exception e) {
e.printStackTrace();
}
}
}
}

0 comments on commit 8256c06

Please sign in to comment.