Fix formatting problems in pull request

This commit is contained in:
Sam Harwell 2013-03-06 15:15:32 -06:00
parent d4c8db4940
commit 82a00104f6
1 changed files with 40 additions and 31 deletions

View File

@ -44,7 +44,16 @@ import org.antlr.v4.runtime.tree.Trees;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import javax.print.PrintException; import javax.print.PrintException;
import javax.swing.*; import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSlider;
import javax.swing.SwingUtilities;
import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener; import javax.swing.event.ChangeListener;
import java.awt.BasicStroke; import java.awt.BasicStroke;
@ -288,43 +297,43 @@ public class TreeViewer extends JComponent {
// Make the scrollpane (containing the viewer) the center component // Make the scrollpane (containing the viewer) the center component
contentPane.add(scrollPane, BorderLayout.CENTER); contentPane.add(scrollPane, BorderLayout.CENTER);
JPanel wrapper = new JPanel(new FlowLayout()); JPanel wrapper = new JPanel(new FlowLayout());
// Add an export-to-png button left of the "OK" button // Add an export-to-png button left of the "OK" button
JButton png = new JButton("png"); JButton png = new JButton("png");
png.addActionListener( png.addActionListener(
new ActionListener() { new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
BufferedImage bi = new BufferedImage(viewer.getSize().width, BufferedImage bi = new BufferedImage(viewer.getSize().width,
viewer.getSize().height, BufferedImage.TYPE_INT_ARGB); viewer.getSize().height, BufferedImage.TYPE_INT_ARGB);
Graphics g = bi.createGraphics(); Graphics g = bi.createGraphics();
viewer.paint(g); viewer.paint(g);
g.dispose(); g.dispose();
try{ try{
File pngFile = new File("antlrv4_parse_tree_" + File pngFile = new File("antlrv4_parse_tree_" +
System.currentTimeMillis() + ".png"); System.currentTimeMillis() + ".png");
ImageIO.write(bi, "png", pngFile); ImageIO.write(bi, "png", pngFile);
JOptionPane.showMessageDialog(dialog, JOptionPane.showMessageDialog(dialog,
"Saved PNG to: " + pngFile.getAbsolutePath()); "Saved PNG to: " + pngFile.getAbsolutePath());
} catch (Exception ex) { } catch (Exception ex) {
JOptionPane.showMessageDialog(dialog, JOptionPane.showMessageDialog(dialog,
"Could not export to PNG: " + ex.getMessage(), "Could not export to PNG: " + ex.getMessage(),
"Error", "Error",
JOptionPane.ERROR_MESSAGE); JOptionPane.ERROR_MESSAGE);
ex.printStackTrace(); ex.printStackTrace();
} }
} }
} }
); );
wrapper.add(png); wrapper.add(png);
// Add button to bottom // Add button to bottom
JPanel bottomPanel = new JPanel(new BorderLayout(0,0)); JPanel bottomPanel = new JPanel(new BorderLayout(0,0));
contentPane.add(bottomPanel, BorderLayout.SOUTH); contentPane.add(bottomPanel, BorderLayout.SOUTH);
JButton ok = new JButton("OK"); JButton ok = new JButton("OK");
ok.addActionListener( ok.addActionListener(
new ActionListener() { new ActionListener() {
@Override @Override