|
From: <de...@us...> - 2014-03-04 11:11:48
|
Revision: 8647
http://sourceforge.net/p/fudaa/svn/8647
Author: deniger
Date: 2014-03-04 11:11:45 +0000 (Tue, 04 Mar 2014)
Log Message:
-----------
CRUE-543: deboguage
Modified Paths:
--------------
trunk/soft/fudaa-crue/ui-application/src/main/resources/etc/fudaacrueDev.conf
trunk/soft/fudaa-crue/ui-branding/src/main/java/org/fudaa/fudaa/crue/branding/InitGeneralUIInstaller.java
Added Paths:
-----------
trunk/soft/fudaa-crue/ui-branding/src/main/java/org/fudaa/fudaa/crue/branding/CheckThreadViolationRepaintManager.java
Modified: trunk/soft/fudaa-crue/ui-application/src/main/resources/etc/fudaacrueDev.conf
===================================================================
--- trunk/soft/fudaa-crue/ui-application/src/main/resources/etc/fudaacrueDev.conf 2014-03-04 09:33:20 UTC (rev 8646)
+++ trunk/soft/fudaa-crue/ui-application/src/main/resources/etc/fudaacrueDev.conf 2014-03-04 11:11:45 UTC (rev 8647)
@@ -3,7 +3,7 @@
# options used by the launcher by default, can be overridden by explicit
# command line switches
-default_options="-J-Ddev.etcDir="C:\data\Fudaa-Crue\etc" -J-Xmx512m --branding fudaacrue -J-Dsydoc-admin=true"
+default_options="-J-Ddev.etcDir="C:\data\Fudaa-Crue\etc" -J-Xmx512m --branding fudaacrue -J-Dsydoc-admin=true -J-Ddebug-swing=true"
# for development purposes you may wish to append: -J-Dnetbeans.logger.console=true -J-ea
# default location of JDK/JRE, can be overridden by using --jdkhome <dir> switch
Added: trunk/soft/fudaa-crue/ui-branding/src/main/java/org/fudaa/fudaa/crue/branding/CheckThreadViolationRepaintManager.java
===================================================================
--- trunk/soft/fudaa-crue/ui-branding/src/main/java/org/fudaa/fudaa/crue/branding/CheckThreadViolationRepaintManager.java (rev 0)
+++ trunk/soft/fudaa-crue/ui-branding/src/main/java/org/fudaa/fudaa/crue/branding/CheckThreadViolationRepaintManager.java 2014-03-04 11:11:45 UTC (rev 8647)
@@ -0,0 +1,155 @@
+/*
+ GPL 2
+ */
+
+package org.fudaa.fudaa.crue.branding;
+
+import java.lang.ref.WeakReference;
+import javax.swing.JButton;
+import javax.swing.JComponent;
+import javax.swing.JEditorPane;
+import javax.swing.JFrame;
+import javax.swing.RepaintManager;
+import javax.swing.SwingUtilities;
+
+/**
+ *
+ * @author Frederic Deniger
+ */
+public class CheckThreadViolationRepaintManager extends RepaintManager {
+
+ // it is recommended to pass the complete check
+ private boolean completeCheck = true;
+ private WeakReference<JComponent> lastComponent;
+
+ public CheckThreadViolationRepaintManager(boolean completeCheck) {
+ this.completeCheck = completeCheck;
+ }
+
+ public CheckThreadViolationRepaintManager() {
+ this(true);
+ }
+
+ public boolean isCompleteCheck() {
+ return completeCheck;
+ }
+
+ public void setCompleteCheck(boolean completeCheck) {
+ this.completeCheck = completeCheck;
+ }
+
+ public synchronized void addInvalidComponent(JComponent component) {
+ checkThreadViolations(component);
+ super.addInvalidComponent(component);
+ }
+
+ public void addDirtyRegion(JComponent component, int x, int y, int w, int h) {
+ checkThreadViolations(component);
+ super.addDirtyRegion(component, x, y, w, h);
+ }
+
+ private void checkThreadViolations(JComponent c) {
+ if (!SwingUtilities.isEventDispatchThread() && (completeCheck || c.isShowing())) {
+ boolean repaint = false;
+ boolean fromSwing = false;
+ boolean imageUpdate = false;
+ StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
+ for (StackTraceElement st : stackTrace) {
+ if (repaint && st.getClassName().startsWith("javax.swing.")
+ && // for details see
+ // https://swinghelper.dev.java.net/issues/show_bug.cgi?id=1
+ !st.getClassName().startsWith("javax.swing.SwingWorker")) {
+ fromSwing = true;
+ }
+ if (repaint && "imageUpdate".equals(st.getMethodName())) {
+ imageUpdate = true;
+ }
+ if ("repaint".equals(st.getMethodName())) {
+ repaint = true;
+ fromSwing = false;
+ }
+ }
+ if (imageUpdate) {
+ //assuming it is java.awt.image.ImageObserver.imageUpdate(...)
+ //image was asynchronously updated, that's ok
+ return;
+ }
+ if (repaint && !fromSwing) {
+ //no problems here, since repaint() is thread safe
+ return;
+ }
+ //ignore the last processed component
+ if (lastComponent != null && c == lastComponent.get()) {
+ return;
+ }
+ lastComponent = new WeakReference<JComponent>(c);
+ violationFound(c, stackTrace);
+ }
+ }
+
+ protected void violationFound(JComponent c, StackTraceElement[] stackTrace) {
+ System.out.println();
+ System.out.println("EDT violation detected");
+ System.out.println(c);
+ for (StackTraceElement st : stackTrace) {
+ System.out.println("\tat " + st);
+ }
+ }
+
+ public static void main(String[] args) throws Exception {
+ //set CheckThreadViolationRepaintManager
+ RepaintManager.setCurrentManager(new CheckThreadViolationRepaintManager());
+ //Valid code
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ test();
+ }
+ });
+ System.out.println("Valid code passed...");
+ repaintTest();
+ System.out.println("Repaint test - correct code");
+ //Invalide code (stack trace expected)
+ test();
+ }
+
+ static void test() {
+ JFrame frame = new JFrame("Am I on EDT?");
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ frame.add(new JButton("JButton"));
+ frame.pack();
+ frame.setVisible(true);
+ frame.dispose();
+ }
+
+ //this test must pass
+ static void imageUpdateTest() {
+ JFrame frame = new JFrame();
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ JEditorPane editor = new JEditorPane();
+ frame.setContentPane(editor);
+ editor.setContentType("text/html");
+ //it works with no valid image as well
+ editor.setText("<html><img src=\"file:\\lala.png\"></html>");
+ frame.setSize(300, 200);
+ frame.setVisible(true);
+ }
+
+ private static JButton test;
+
+ static void repaintTest() {
+ try {
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ test = new JButton();
+ test.setSize(100, 100);
+ }
+ });
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ // repaint(Rectangle) should be ok
+ test.repaint(test.getBounds());
+ test.repaint(0, 0, 100, 100);
+ test.repaint();
+ }
+}
Modified: trunk/soft/fudaa-crue/ui-branding/src/main/java/org/fudaa/fudaa/crue/branding/InitGeneralUIInstaller.java
===================================================================
--- trunk/soft/fudaa-crue/ui-branding/src/main/java/org/fudaa/fudaa/crue/branding/InitGeneralUIInstaller.java 2014-03-04 09:33:20 UTC (rev 8646)
+++ trunk/soft/fudaa-crue/ui-branding/src/main/java/org/fudaa/fudaa/crue/branding/InitGeneralUIInstaller.java 2014-03-04 11:11:45 UTC (rev 8647)
@@ -7,6 +7,7 @@
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JPanel;
+import javax.swing.RepaintManager;
import javax.swing.border.Border;
import org.openide.awt.Toolbar;
import org.openide.awt.ToolbarPool;
@@ -62,6 +63,9 @@
perspective.add(buttons, BorderLayout.SOUTH);
perspective.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));
}
+ if ("true".equals(System.getProperty("debug-swing"))) {
+ RepaintManager.setCurrentManager(new CheckThreadViolationRepaintManager());
+ }
}
public static Toolbar getPerspectiveToolbar(Toolbar[] in) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|