- Timestamp:
- 2016-07-23T22:09:41+02:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/jdesktop/swinghelper/debug/CheckThreadViolationRepaintManager.java
r4728 r10617 19 19 import java.lang.ref.WeakReference; 20 20 21 import javax.swing.JButton;22 21 import javax.swing.JComponent; 23 import javax.swing.JEditorPane;24 import javax.swing.JFrame;25 22 import javax.swing.RepaintManager; 26 23 import javax.swing.SwingUtilities; … … 52 49 public CheckThreadViolationRepaintManager() { 53 50 this(true); 54 }55 56 public boolean isCompleteCheck() {57 return completeCheck;58 }59 60 public void setCompleteCheck(boolean completeCheck) {61 this.completeCheck = completeCheck;62 51 } 63 52 … … 105 94 if (lastComponent != null && c == lastComponent.get()) 106 95 return; 107 lastComponent = new WeakReference< JComponent>(c);96 lastComponent = new WeakReference<>(c); 108 97 violationFound(c, stackTrace); 109 98 } … … 118 107 } 119 108 } 120 121 public static void main(String[] args) throws Exception {122 //set CheckThreadViolationRepaintManager123 RepaintManager.setCurrentManager(new CheckThreadViolationRepaintManager());124 //Valid code125 SwingUtilities.invokeAndWait(new Runnable() {126 public void run() {127 test();128 }129 });130 System.out.println("Valid code passed...");131 repaintTest();132 System.out.println("Repaint test - correct code");133 //Invalide code (stack trace expected)134 test();135 }136 137 static void test() {138 JFrame frame = new JFrame("Am I on EDT?");139 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);140 frame.add(new JButton("JButton"));141 frame.pack();142 frame.setVisible(true);143 frame.dispose();144 }145 146 //this test must pass147 static void imageUpdateTest() {148 JFrame frame = new JFrame();149 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);150 JEditorPane editor = new JEditorPane();151 frame.setContentPane(editor);152 editor.setContentType("text/html");153 //it works with no valid image as well154 editor.setText("<html><img src=\"file:\\lala.png\"></html>");155 frame.setSize(300, 200);156 frame.setVisible(true);157 }158 159 private static JButton test;160 static void repaintTest() {161 try {162 SwingUtilities.invokeAndWait(new Runnable() {163 public void run() {164 test = new JButton();165 test.setSize(100, 100);166 }167 });168 } catch (Exception e) {169 e.printStackTrace();170 }171 // repaint(Rectangle) should be ok172 test.repaint(test.getBounds());173 test.repaint(0, 0, 100, 100);174 test.repaint();175 }176 109 }
Note:
See TracChangeset
for help on using the changeset viewer.