Skip to content

Commit bb1e62c

Browse files
committed
Add Error Output TextArea to make it simpler extract error messages.
1 parent c8e9f8b commit bb1e62c

File tree

2 files changed

+71
-9
lines changed

2 files changed

+71
-9
lines changed

src/main/java/com/github/tgstation/fastdmm/FastDMM.java

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.awt.Canvas;
55
import java.awt.Color;
66
import java.awt.Component;
7+
import java.awt.Dimension;
78
import java.awt.Font;
89
import java.awt.Graphics2D;
910
import java.awt.KeyboardFocusManager;
@@ -82,9 +83,13 @@ public class FastDMM extends JFrame implements ActionListener, TreeSelectionList
8283
private JLabel coords;
8384
public JLabel selection;
8485
private JTabbedPane leftTabs;
85-
private JPanel editorPanel;
86+
87+
private JPanel rightPanel;
8688
private JTabbedPane editorTabs;
8789
private Canvas canvas;
90+
91+
private JTabbedPane rightBottomTabs;
92+
private JPanel rightBottomOutputpanel;
8893

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

103108
private JPopupMenu currPopup;
109+
110+
private PrintStream outputStream;
104111

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

152161
// FastDMM is now a singleton.
153162
private FastDMM() {
154-
}
163+
}
155164

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

216-
editorPanel = new JPanel();
217-
editorPanel.setLayout(new BorderLayout());
218-
editorPanel.add(canvas, BorderLayout.CENTER);
225+
rightPanel = new JPanel();
226+
rightPanel.setLayout(new BorderLayout());
227+
rightPanel.add(canvas, BorderLayout.CENTER);
219228

220229
editorTabs = new JTabbedPane();
221230
editorTabs.addChangeListener(new ChangeListener() {
@@ -241,10 +250,27 @@ public void stateChanged(ChangeEvent e) {
241250
+ dmm.file.getName().replaceFirst("[.][^.]+$", ""));
242251
}
243252
}
244-
});
245-
editorPanel.add(editorTabs, BorderLayout.NORTH);
253+
});
254+
rightPanel.add(editorTabs, BorderLayout.NORTH);
255+
256+
rightBottomTabs = new JTabbedPane();
257+
rightBottomTabs.setPreferredSize(new Dimension(800, 200));
258+
rightBottomTabs.addChangeListener(new ChangeListener() {
259+
public void stateChanged(ChangeEvent e) {
260+
}
261+
});
262+
263+
JTextArea outputTextArea = new JTextArea();
264+
265+
OutputStream outputStream = new TextAreaOutputStream(outputTextArea, "Debug", Color.RED);
266+
267+
System.setErr(new PrintStream(outputStream));
268+
269+
rightBottomTabs.addTab("Output", new JScrollPane(outputTextArea));
270+
271+
rightPanel.add(rightBottomTabs, BorderLayout.SOUTH);
246272

247-
getContentPane().add(editorPanel, BorderLayout.CENTER);
273+
getContentPane().add(rightPanel, BorderLayout.CENTER);
248274
getContentPane().add(leftPanel, BorderLayout.WEST);
249275

250276
setSize(1280, 720);
@@ -460,6 +486,7 @@ public void actionPerformed(ActionEvent e) {
460486
}
461487
dmm.save();
462488
} catch (Exception ex) {
489+
ex.printStackTrace();
463490
StringWriter sw = new StringWriter();
464491
PrintWriter pw = new PrintWriter(sw);
465492
ex.printStackTrace(pw);
@@ -608,6 +635,7 @@ public void run() {
608635
menuRecentMaps.setVisible(true);
609636
areMenusFrozen = false;
610637
} catch (Exception ex) {
638+
ex.printStackTrace();
611639
StringWriter sw = new StringWriter();
612640
PrintWriter pw = new PrintWriter(sw);
613641
ex.printStackTrace(pw);
@@ -667,7 +695,7 @@ private void openDMM(File filetoopen) {
667695
loadedMaps.add(dmm);
668696
int mapIndex = loadedMaps.indexOf(dmm);
669697
;
670-
editorTabs.insertTab(dmm.relPath, null, new EmptyTabPanel(editorPanel), dmm.relPath, mapIndex);
698+
editorTabs.insertTab(dmm.relPath, null, new EmptyTabPanel(rightPanel), dmm.relPath, mapIndex);
671699
editorTabs.setTabComponentAt(mapIndex, new EditorTabComponent(this, dmm));
672700
editorTabs.setSelectedIndex(mapIndex);
673701
viewportX = 0;
@@ -679,6 +707,7 @@ private void openDMM(File filetoopen) {
679707
StringWriter sw = new StringWriter();
680708
PrintWriter pw = new PrintWriter(sw);
681709
ex.printStackTrace(pw);
710+
ex.printStackTrace();
682711
JOptionPane.showMessageDialog(FastDMM.this, sw.getBuffer(), "Error", JOptionPane.ERROR_MESSAGE);
683712
dmm = null;
684713
menuItemExpand.setEnabled(false);
@@ -1141,6 +1170,7 @@ private void addToRecent(File dme, DMM dmm) {
11411170
try {
11421171
Files.write(Paths.get(path), main.toString().getBytes(), StandardOpenOption.CREATE);
11431172
} catch (IOException e) {
1173+
e.printStackTrace();
11441174
StringWriter sw = new StringWriter();
11451175
PrintWriter pw = new PrintWriter(sw);
11461176
e.printStackTrace(pw);
@@ -1156,6 +1186,7 @@ private void addToRecent(File dme, DMM dmm) {
11561186
PrintWriter pw = new PrintWriter(sw);
11571187
e.printStackTrace(pw);
11581188
JOptionPane.showMessageDialog(FastDMM.this, sw.getBuffer(), "Error", JOptionPane.ERROR_MESSAGE);
1189+
e.printStackTrace();
11591190
}
11601191
main = new JSONObject(new JSONTokener(Objects.requireNonNull(reader)));
11611192

@@ -1223,6 +1254,7 @@ private void addToRecent(File dme, DMM dmm) {
12231254
writer.flush();
12241255
writer.close();
12251256
} catch (IOException e) {
1257+
e.printStackTrace();
12261258
StringWriter sw = new StringWriter();
12271259
PrintWriter pw = new PrintWriter(sw);
12281260
e.printStackTrace(pw);
@@ -1244,6 +1276,7 @@ private void initRecent(String mode) {
12441276
try {
12451277
reader = new FileReader(recentPath);
12461278
} catch (FileNotFoundException e) {
1279+
e.printStackTrace();
12471280
StringWriter sw = new StringWriter();
12481281
PrintWriter pw = new PrintWriter(sw);
12491282
e.printStackTrace(pw);
@@ -1318,6 +1351,7 @@ private void convertintojson() {
13181351
}
13191352
}
13201353
} catch (IOException e) {
1354+
e.printStackTrace();
13211355
StringWriter sw = new StringWriter();
13221356
PrintWriter pw = new PrintWriter(sw);
13231357
e.printStackTrace(pw);
@@ -1328,6 +1362,7 @@ private void convertintojson() {
13281362
try {
13291363
Files.write(Paths.get(dummy), "".getBytes(), StandardOpenOption.CREATE);
13301364
} catch (IOException e) {
1365+
e.printStackTrace();
13311366
StringWriter sw = new StringWriter();
13321367
PrintWriter pw = new PrintWriter(sw);
13331368
e.printStackTrace(pw);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.github.tgstation.fastdmm;
2+
3+
import java.io.IOException;
4+
import java.io.OutputStream;
5+
6+
import javax.swing.JTextArea;
7+
8+
import java.awt.Color;
9+
10+
public class TextAreaOutputStream extends OutputStream {
11+
private JTextArea textArea;
12+
private Color color;
13+
private String prefix;
14+
15+
public TextAreaOutputStream(JTextArea textArea, String prefix, Color color) {
16+
this.textArea = textArea;
17+
}
18+
19+
@Override
20+
public void write(int b) throws IOException {
21+
// redirects data to the text area
22+
textArea.append(String.valueOf((char) b));
23+
// scrolls the text area to the end of data
24+
textArea.setCaretPosition(textArea.getDocument().getLength());
25+
}
26+
27+
}

0 commit comments

Comments
 (0)