    001    package escjava.gui;
    002
    003    import javax.swing.*;
    004
    005    public class WindowThread extends Thread {
    006
    007        static TaskQueue windowTasks = new TaskQueue();
    008
    009        public void run() {
    010            while (true) {
    011                Object o = windowTasks.getTask();
    012                String out = "";
    013                if (o instanceof GUI.EscTreeValue) {
    014                    ((GUI.EscTreeValue)o).showOutput(true);
    015                } else if (o instanceof HtmlTask) {
    016                    HtmlTask ht = (HtmlTask)o;
    017                    EscHtml jf = EscHtml.make(ht.title,ht.filename,
    018                        GUI.gui.escframe,500,0,600,400);
    019                    jf.showit();
    020                } else if (o instanceof String) {
    021                    // Pop up an editor window
    022                    try {
    023                        // Here we parse the various kinds of error messages
    024                        // that Esc/java2 produces to find a file name and
    025                        // line number
    026                        final String aheader =
    027                            "Associated declaration is \"";
    028                        final String linetext = "\", line ";
    029                        final String coltext = ", col ";
    030                        String s = (String)o;
    031                        String name;
    032                        int lin;
    033                        if (s.startsWith(aheader)) {
    034                            int i = s.indexOf('\"',aheader.length());
    035                            name = s.substring(aheader.length(),i);
    036                            i += linetext.length();
    037                            int j = s.indexOf(',',i);
    038                            try {
    039                                lin = Integer.parseInt(s.substring(i,j));
    040                            } catch (NumberFormatException e) {
    041                                lin = 0;
    042                            }
    043                        } else {
    044                            final String jarending = ".jar:";
    045                            int i = s.indexOf(jarending);
    046                            i = i == -1 ? 0 : i + jarending.length();
    047                            i = s.indexOf(':',i);
    048                            if (i == -1) continue;
    049                            name = s.substring(0,i);
    050                            i++;
    051                            int ii = s.indexOf(':',i);
    052                            if (ii == -1) continue;
    053                            try {
    054                                lin = Integer.parseInt(s.substring(i,ii));
    055                            } catch (NumberFormatException e) {
    056                                lin = 0;
    057                            }
    058                        }
    059                        if (name.endsWith(".class")) {
    060                            int result =
    061                            JOptionPane.showConfirmDialog(GUI.gui.escframe,
    062                                "The referenced location is in a class file, "
    063                              + " so there is probably no java or specification"
    064                              + Project.eol
    065                              + " file for this class.  Would you like to "
    066                              + " create a skeleton specification file and edit it?" + Project.eol + "[[[ Sorry - not yet implemented ]]]",
    067                                "Generate skeleton?",
    068                                JOptionPane.YES_NO_OPTION);
    069                            if (result == JOptionPane.NO_OPTION) continue;
    070                            continue;
    071
    072                        }
    073                        EscEditor.make(name,lin,null,null).showit();
    074                    } catch (Exception e) {
    075                        JOptionPane.showMessageDialog(GUI.gui.escframe,
    076                            "Failed to open editor window: " + Project.eol +
    077                            out +
    078                            o + Project.eol + e);
    079                    }
    080                }
    081            }
    082        }
    083
    084        static class HtmlTask {
    085            String filename;
    086            String title;
    087            public HtmlTask(String title, String filename) {
    088                this.title = title;
    089                this.filename = filename;
    090            }
    091        }
    092
    093    }
    094