mirror of https://github.com/rusefi/RomRaider.git
fixed some swing threading issues
git-svn-id: http://svn.3splooges.com/romraider-arch/trunk@486 d2e2e1cd-ba16-0410-be16-b7c4453c7c2d
This commit is contained in:
parent
e9ade4bb84
commit
4991d77715
|
@ -35,7 +35,7 @@ public final class EcuLoggerExec {
|
|||
public static void main(String... args) {
|
||||
|
||||
// check for dodgy threading - dev only
|
||||
//RepaintManager.setCurrentManager(new ThreadCheckingRepaintManager());
|
||||
// RepaintManager.setCurrentManager(new ThreadCheckingRepaintManager(true));
|
||||
|
||||
// set look and feel
|
||||
LookAndFeelManager.initLookAndFeel();
|
||||
|
|
|
@ -1,22 +1,75 @@
|
|||
package enginuity.util;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class ThreadCheckingRepaintManager extends RepaintManager {
|
||||
public synchronized void addInvalidComponent(JComponent component) {
|
||||
checkThread();
|
||||
super.addInvalidComponent(component);
|
||||
private int tabCount = 0;
|
||||
private boolean checkIsShowing = false;
|
||||
|
||||
public ThreadCheckingRepaintManager() {
|
||||
}
|
||||
|
||||
private void checkThread() {
|
||||
if (!SwingUtilities.isEventDispatchThread()) {
|
||||
System.out.println("Wrong Thread");
|
||||
Thread.dumpStack();
|
||||
public ThreadCheckingRepaintManager(boolean checkIsShowing) {
|
||||
this.checkIsShowing = checkIsShowing;
|
||||
}
|
||||
|
||||
public synchronized void addInvalidComponent(JComponent jComponent) {
|
||||
checkThread(jComponent);
|
||||
super.addInvalidComponent(jComponent);
|
||||
}
|
||||
|
||||
private void checkThread(JComponent c) {
|
||||
if (!SwingUtilities.isEventDispatchThread() && checkIsShowing(c)) {
|
||||
System.out.println("----------Wrong Thread START");
|
||||
System.out.println(getStracktraceAsString(new Exception()));
|
||||
dumpComponentTree(c);
|
||||
System.out.println("----------Wrong Thread END");
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void addDirtyRegion(JComponent component, int i, int i1, int i2, int i3) {
|
||||
checkThread();
|
||||
super.addDirtyRegion(component, i, i1, i2, i3);
|
||||
private String getStracktraceAsString(Exception e) {
|
||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||
PrintStream printStream = new PrintStream(byteArrayOutputStream);
|
||||
e.printStackTrace(printStream);
|
||||
printStream.flush();
|
||||
return byteArrayOutputStream.toString();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkIsShowing(JComponent c) {
|
||||
return !this.checkIsShowing || c.isShowing();
|
||||
}
|
||||
|
||||
public synchronized void addDirtyRegion(JComponent jComponent, int i, int i1, int i2, int i3) {
|
||||
checkThread(jComponent);
|
||||
super.addDirtyRegion(jComponent, i, i1, i2, i3);
|
||||
}
|
||||
|
||||
private void dumpComponentTree(Component c) {
|
||||
System.out.println("----------Component Tree");
|
||||
resetTabCount();
|
||||
for (; c != null; c = c.getParent()) {
|
||||
printTabIndent();
|
||||
System.out.println(c);
|
||||
printTabIndent();
|
||||
System.out.println("Showing:" + c.isShowing() + " Visible: " + c.isVisible());
|
||||
incrementTabCount();
|
||||
}
|
||||
}
|
||||
|
||||
private void resetTabCount() {
|
||||
this.tabCount = 0;
|
||||
}
|
||||
|
||||
private void incrementTabCount() {
|
||||
this.tabCount++;
|
||||
}
|
||||
|
||||
private void printTabIndent() {
|
||||
for (int i = 0; i < this.tabCount; i++) {
|
||||
System.out.print("\t");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue