Skip to content

Commit

Permalink
Add Error Output TextArea to make it simpler extract error messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rockdtben committed Aug 11, 2018
1 parent c8e9f8b commit bb1e62c
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 9 deletions.
53 changes: 44 additions & 9 deletions src/main/java/com/github/tgstation/fastdmm/FastDMM.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.KeyboardFocusManager;
Expand Down Expand Up @@ -82,9 +83,13 @@ public class FastDMM extends JFrame implements ActionListener, TreeSelectionList
private JLabel coords;
public JLabel selection;
private JTabbedPane leftTabs;
private JPanel editorPanel;

private JPanel rightPanel;
private JTabbedPane editorTabs;
private Canvas canvas;

private JTabbedPane rightBottomTabs;
private JPanel rightBottomOutputpanel;

private JMenuBar menuBar;
private JMenu menuRecent;
Expand All @@ -101,6 +106,8 @@ public class FastDMM extends JFrame implements ActionListener, TreeSelectionList
private JCheckBoxMenuItem menuItemAutoSave;

private JPopupMenu currPopup;

private PrintStream outputStream;

public JTree objTreeVis;
public JList<ObjInstance> instancesVis;
Expand Down Expand Up @@ -139,9 +146,11 @@ public static final void main(String[] args) throws IOException, LWJGLException
fastdmm.init();
fastdmm.loop();
} catch (Exception ex) {
// If an error gets this high you should throw an exception popup and kill the app.
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
ex.printStackTrace(pw);
ex.printStackTrace();
JOptionPane.showMessageDialog(fastdmm, sw.getBuffer(), "Error", JOptionPane.ERROR_MESSAGE);
System.exit(1);
} finally {
Expand All @@ -151,7 +160,7 @@ public static final void main(String[] args) throws IOException, LWJGLException

// FastDMM is now a singleton.
private FastDMM() {
}
}

// FastDMM is now a singleton.
private static FastDMM fastDMM;
Expand Down Expand Up @@ -213,9 +222,9 @@ public void initSwing() {
leftTabs.addTab("Instances", instancesPanel);
leftPanel.add(leftTabs, BorderLayout.CENTER);

editorPanel = new JPanel();
editorPanel.setLayout(new BorderLayout());
editorPanel.add(canvas, BorderLayout.CENTER);
rightPanel = new JPanel();
rightPanel.setLayout(new BorderLayout());
rightPanel.add(canvas, BorderLayout.CENTER);

editorTabs = new JTabbedPane();
editorTabs.addChangeListener(new ChangeListener() {
Expand All @@ -241,10 +250,27 @@ public void stateChanged(ChangeEvent e) {
+ dmm.file.getName().replaceFirst("[.][^.]+$", ""));
}
}
});
editorPanel.add(editorTabs, BorderLayout.NORTH);
});
rightPanel.add(editorTabs, BorderLayout.NORTH);

rightBottomTabs = new JTabbedPane();
rightBottomTabs.setPreferredSize(new Dimension(800, 200));
rightBottomTabs.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
}
});

JTextArea outputTextArea = new JTextArea();

OutputStream outputStream = new TextAreaOutputStream(outputTextArea, "Debug", Color.RED);

System.setErr(new PrintStream(outputStream));

rightBottomTabs.addTab("Output", new JScrollPane(outputTextArea));

rightPanel.add(rightBottomTabs, BorderLayout.SOUTH);

getContentPane().add(editorPanel, BorderLayout.CENTER);
getContentPane().add(rightPanel, BorderLayout.CENTER);
getContentPane().add(leftPanel, BorderLayout.WEST);

setSize(1280, 720);
Expand Down Expand Up @@ -460,6 +486,7 @@ public void actionPerformed(ActionEvent e) {
}
dmm.save();
} catch (Exception ex) {
ex.printStackTrace();
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
ex.printStackTrace(pw);
Expand Down Expand Up @@ -608,6 +635,7 @@ public void run() {
menuRecentMaps.setVisible(true);
areMenusFrozen = false;
} catch (Exception ex) {
ex.printStackTrace();
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
ex.printStackTrace(pw);
Expand Down Expand Up @@ -667,7 +695,7 @@ private void openDMM(File filetoopen) {
loadedMaps.add(dmm);
int mapIndex = loadedMaps.indexOf(dmm);
;
editorTabs.insertTab(dmm.relPath, null, new EmptyTabPanel(editorPanel), dmm.relPath, mapIndex);
editorTabs.insertTab(dmm.relPath, null, new EmptyTabPanel(rightPanel), dmm.relPath, mapIndex);
editorTabs.setTabComponentAt(mapIndex, new EditorTabComponent(this, dmm));
editorTabs.setSelectedIndex(mapIndex);
viewportX = 0;
Expand All @@ -679,6 +707,7 @@ private void openDMM(File filetoopen) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
ex.printStackTrace(pw);
ex.printStackTrace();
JOptionPane.showMessageDialog(FastDMM.this, sw.getBuffer(), "Error", JOptionPane.ERROR_MESSAGE);
dmm = null;
menuItemExpand.setEnabled(false);
Expand Down Expand Up @@ -1141,6 +1170,7 @@ private void addToRecent(File dme, DMM dmm) {
try {
Files.write(Paths.get(path), main.toString().getBytes(), StandardOpenOption.CREATE);
} catch (IOException e) {
e.printStackTrace();
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
Expand All @@ -1156,6 +1186,7 @@ private void addToRecent(File dme, DMM dmm) {
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
JOptionPane.showMessageDialog(FastDMM.this, sw.getBuffer(), "Error", JOptionPane.ERROR_MESSAGE);
e.printStackTrace();
}
main = new JSONObject(new JSONTokener(Objects.requireNonNull(reader)));

Expand Down Expand Up @@ -1223,6 +1254,7 @@ private void addToRecent(File dme, DMM dmm) {
writer.flush();
writer.close();
} catch (IOException e) {
e.printStackTrace();
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
Expand All @@ -1244,6 +1276,7 @@ private void initRecent(String mode) {
try {
reader = new FileReader(recentPath);
} catch (FileNotFoundException e) {
e.printStackTrace();
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
Expand Down Expand Up @@ -1318,6 +1351,7 @@ private void convertintojson() {
}
}
} catch (IOException e) {
e.printStackTrace();
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
Expand All @@ -1328,6 +1362,7 @@ private void convertintojson() {
try {
Files.write(Paths.get(dummy), "".getBytes(), StandardOpenOption.CREATE);
} catch (IOException e) {
e.printStackTrace();
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.github.tgstation.fastdmm;

import java.io.IOException;
import java.io.OutputStream;

import javax.swing.JTextArea;

import java.awt.Color;

public class TextAreaOutputStream extends OutputStream {
private JTextArea textArea;
private Color color;
private String prefix;

public TextAreaOutputStream(JTextArea textArea, String prefix, Color color) {
this.textArea = textArea;
}

@Override
public void write(int b) throws IOException {
// redirects data to the text area
textArea.append(String.valueOf((char) b));
// scrolls the text area to the end of data
textArea.setCaretPosition(textArea.getDocument().getLength());
}

}

0 comments on commit bb1e62c

Please sign in to comment.