@@ -1678,18 +1678,29 @@ public void run() {
16781678
16791679class UpdateFileText implements Runnable {
16801680
1681- private FileWindow w ;
1681+ private Main main ;
1682+ private SourceInfo sourceInfo ;
16821683
16831684 private UpdateFileText () {}
16841685
1685- static Runnable action (FileWindow w ) {
1686+ static Runnable action (Main main , SourceInfo sourceInfo )
1687+ {
16861688 UpdateFileText obj = new UpdateFileText ();
1687- obj .w = w ;
1689+ obj .main = main ;
1690+ obj .sourceInfo = sourceInfo ;
16881691 return obj ;
16891692 }
16901693
1691- public void run () {
1692- w .updateText ();
1694+ public void run ()
1695+ {
1696+ String fileName = sourceInfo .getUrl ();
1697+ FileWindow w = main .getFileWindow (fileName );
1698+ if (w != null ) {
1699+ w .updateText ();
1700+ w .show ();
1701+ } else if (!fileName .equals ("<stdin>" )) {
1702+ CreateFileWindow .action (main , sourceInfo , -1 ).run ();
1703+ }
16931704 }
16941705}
16951706
@@ -2407,8 +2418,11 @@ ScriptItem getScriptItem(DebuggableScript fnOrScript) {
24072418 String source = null ;
24082419 try {
24092420 InputStream is = openSource (url );
2410- try { source = readSource (is ); }
2411- finally { is .close (); }
2421+ try {
2422+ source = Kit .readReader (new InputStreamReader (is ));
2423+ } finally {
2424+ is .close ();
2425+ }
24122426 } catch (IOException ex ) {
24132427 System .err .println
24142428 ("Failed to load source from " +url +": " + ex );
@@ -2525,22 +2539,6 @@ private static InputStream openSource(String sourceUrl)
25252539 return (new java .net .URL (sourceUrl )).openStream ();
25262540 }
25272541
2528- private static String readSource (InputStream is ) throws IOException {
2529- byte [] buffer = new byte [4096 ];
2530- int offset = 0 ;
2531- for (;;) {
2532- int n = is .read (buffer , 0 , buffer .length - offset );
2533- if (n < 0 ) { break ; }
2534- offset += n ;
2535- if (offset == buffer .length ) {
2536- byte [] tmp = new byte [buffer .length * 2 ];
2537- System .arraycopy (buffer , 0 , tmp , 0 , offset );
2538- buffer = tmp ;
2539- }
2540- }
2541- return new String (buffer , 0 , offset );
2542- }
2543-
25442542 private SourceInfo registerSource (String sourceUrl , String source ) {
25452543 SourceInfo si ;
25462544 synchronized (sourceNames ) {
@@ -2567,7 +2565,8 @@ private ScriptItem registerScript(SourceInfo si,
25672565 functionNames .put (name , item );
25682566 }
25692567
2570- loadedFile (si );
2568+ swingInvokeLater (UpdateFileText .action (this , si ));
2569+
25712570 return item ;
25722571 }
25732572
@@ -2766,35 +2765,9 @@ FileWindow getFileWindow(String url) {
27662765 return (FileWindow )fileWindows .get (url );
27672766 }
27682767
2769- void loadedFile (SourceInfo si ) {
2770- String fileName = si .getUrl ();
2771- FileWindow w = getFileWindow (fileName );
2772- if (w != null ) {
2773- swingInvoke (UpdateFileText .action (w ));
2774- w .show ();
2775- } else if (!fileName .equals ("<stdin>" )) {
2776- swingInvoke (CreateFileWindow .action (this , si , -1 ));
2777- }
2778- }
2779-
2780- static void swingInvoke (Runnable f ) {
2781- if (SwingUtilities .isEventDispatchThread ()) {
2782- f .run ();
2783- return ;
2784- }
2785- try {
2786- SwingUtilities .invokeAndWait (f );
2787- } catch (Exception exc ) {
2788- exc .printStackTrace ();
2789- }
2790- }
2791-
2792- static void swingInvokeLater (Runnable f ) {
2793- try {
2794- SwingUtilities .invokeLater (f );
2795- } catch (RuntimeException exc ) {
2796- exc .printStackTrace ();
2797- }
2768+ static void swingInvokeLater (Runnable f )
2769+ {
2770+ SwingUtilities .invokeLater (f );
27982771 }
27992772
28002773 int frameIndex = -1 ;
@@ -3352,22 +3325,6 @@ static void setResizeWeight(JSplitPane pane, double weight) {
33523325
33533326 java .util .Hashtable toplevels = new java .util .Hashtable ();
33543327
3355- boolean shouldDispatchTo (Component source ) {
3356- Component root = SwingUtilities .getRoot (source );
3357- if (root == this ) {
3358- return true ;
3359- }
3360- Enumeration e = toplevels .keys ();
3361- while (e .hasMoreElements ()) {
3362- Object key = e .nextElement ();
3363- JFrame frame = (JFrame )toplevels .get (key );
3364- if (root == frame ) {
3365- return true ;
3366- }
3367- }
3368- return false ;
3369- }
3370-
33713328 void addTopLevel (String key , JFrame frame ) {
33723329 if (frame != this ) {
33733330 toplevels .put (key , frame );
@@ -3391,13 +3348,6 @@ private static void dispatchNextAwtEvent()
33913348 Object source = event .getSource ();
33923349 if (source instanceof Component ) {
33933350 Component comp = (Component )source ;
3394- // Suppress Window/InputEvent's that aren't
3395- // directed to the Debugger
3396- // if (!(event instanceof InputEvent ||
3397- //event instanceof WindowEvent)||
3398- // shouldDispatchTo(comp)) {
3399- //comp.dispatchEvent(event);
3400- //}
34013351 comp .dispatchEvent (event );
34023352 } else if (source instanceof MenuComponent ) {
34033353 ((MenuComponent )source ).dispatchEvent (event );
0 commit comments