public void displayAllClassesNames(List<String> classNames) {
    long start = System.currentTimeMillis();

    displayDataState = DisplayDataState.CLASSES_LIST;
    StyleConstants.setFontSize(style, 18);
    StyleConstants.setForeground(style, ColorScheme.FOREGROUND_CYAN);

    clearText();

    BatchDocument blank = new BatchDocument();
    jTextPane.setDocument(blank);

    for (String className : classNames) {
      blank.appendBatchStringNoLineFeed(className, style);
      blank.appendBatchLineFeed(style);
    }

    try {
      blank.processBatchUpdates(0);
    } catch (BadLocationException e) {
      e.printStackTrace();
    }

    jTextPane.setDocument(blank);

    System.out.println("UI update " + (System.currentTimeMillis() - start) + " ms");
  }
Пример #2
0
  /**
   * Creates a new JTextPane for the code.
   *
   * @return the text pane
   */
  protected JTextPane newCodePane() {
    JTextPane result;
    SyntaxDocument doc;
    Properties props;

    try {
      props = Utils.readProperties(PROPERTIES_FILE);
    } catch (Exception e) {
      e.printStackTrace();
      props = new Properties();
    }

    result = new JTextPane();
    if (props.getProperty("Syntax", "false").equals("true")) {
      doc = new SyntaxDocument(props);
      result.setDocument(doc);
      result.setBackground(doc.getBackgroundColor());
    } else {
      result.setForeground(
          VisualizeUtils.processColour(props.getProperty("ForegroundColor", "black"), Color.BLACK));
      result.setBackground(
          VisualizeUtils.processColour(props.getProperty("BackgroundColor", "white"), Color.WHITE));
      result.setFont(
          new Font(
              props.getProperty("FontName", "monospaced"),
              Font.PLAIN,
              Integer.parseInt(props.getProperty("FontSize", "12"))));
    }

    return result;
  }
  private void initDebugTextPane() {
    HTMLEditorKit htmlEditorKit = new HTMLEditorKit();
    HTMLDocument htmlDocument = new HTMLDocument();

    debugTextPane.setEditable(false);
    debugTextPane.setBackground(Color.WHITE);
    debugTextPane.setEditorKit(htmlEditorKit);
    htmlEditorKit.install(debugTextPane);
    debugTextPane.setDocument(htmlDocument);
  }
Пример #4
0
  private void setupTab() {

    // The chat area
    BorderLayout chatLayout = new BorderLayout();
    JPanel chatWrapper = new JPanel(chatLayout);

    chatLog = new JTextPane();
    chatLog.setEditable(false);
    chatLog.setDocument(new ChatDocument());
    chatLogScrollPane = new JScrollPane(chatLog);
    chatLogScrollPane.addMouseListener(this);

    chatWrapper.add(chatLogScrollPane, BorderLayout.CENTER);

    // The send message panel
    message = new JTextArea();
    message.addMouseListener(this);
    message.addKeyListener(this);
    messageScrollPane = new JScrollPane(message);
    message.setLineWrap(true);
    message.setWrapStyleWord(true);
    message.requestFocus();
    message.setDocument(new JTextFieldLimit(512));

    sendMessage = new JButton("Send", frame.getGui().getUtil().getImage("sendmessage"));
    sendMessage.addMouseListener(this);
    sendMessage.addActionListener(this);

    chatMessagePanel = new JPanel();
    chatMessagePanel.setLayout(new BoxLayout(chatMessagePanel, BoxLayout.X_AXIS));
    chatMessagePanel.add(messageScrollPane);
    chatMessagePanel.add(sendMessage);

    chatWrapper.add(chatMessagePanel, BorderLayout.PAGE_END);

    // Setup the avatars
    avatarTable = new JTable(new AvatarTableModel(indexNode));
    avatarTable.addMouseListener(this);
    avatarTable.setTableHeader(null);
    avatarTable.setDefaultRenderer(Object.class, new AvatarRenderer(frame));
    avatarTable.setRowHeight(70);
    avatarScrollPane = new JScrollPane(avatarTable);
    avatarScrollPane.setMaximumSize(new Dimension(200, -1));
    avatarScrollPane.setPreferredSize(new Dimension(200, -1));

    // Add all to parent
    BorderLayout pageLayout = new BorderLayout();

    this.setLayout(pageLayout);
    this.add(avatarScrollPane, BorderLayout.LINE_END);
    this.add(chatWrapper, BorderLayout.CENTER);

    // Set the status
    active = true;
  }
Пример #5
0
  public Container CreateContentPane() {
    // Create the content-pane-to-be.
    JPanel contentPane = new JPanel(new BorderLayout());
    contentPane.setOpaque(true);

    // the log panel
    log = new JTextPane();
    log.setEditable(false);
    log.setBackground(Color.BLACK);
    logPane = new JScrollPane(log);
    kit = new HTMLEditorKit();
    doc = new HTMLDocument();
    log.setEditorKit(kit);
    log.setDocument(doc);
    DefaultCaret c = (DefaultCaret) log.getCaret();
    c.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
    ClearLog();

    // the preview panel
    previewPane = new DrawPanel();
    previewPane.setPaperSize(paper_top, paper_bottom, paper_left, paper_right);

    // status bar
    statusBar = new StatusBar();
    Font f = statusBar.getFont();
    statusBar.setFont(f.deriveFont(Font.BOLD, 15));
    Dimension d = statusBar.getMinimumSize();
    d.setSize(d.getWidth(), d.getHeight() + 30);
    statusBar.setMinimumSize(d);

    // layout
    Splitter split = new Splitter(JSplitPane.VERTICAL_SPLIT);
    split.add(previewPane);
    split.add(logPane);
    split.setDividerSize(8);

    contentPane.add(statusBar, BorderLayout.SOUTH);
    contentPane.add(split, BorderLayout.CENTER);

    // open the file
    if (recentFiles[0].length() > 0) {
      OpenFileOnDemand(recentFiles[0]);
    }

    // connect to the last port
    ListSerialPorts();
    if (Arrays.asList(portsDetected).contains(recentPort)) {
      OpenPort(recentPort);
    }

    return contentPane;
  }
Пример #6
0
  private JPanel buildDebugPanel(final Font monospacedFont, final Font sansFont) {
    final JScrollPane textPaneDebugScroller = buildTextPaneDebug();

    documentDebug = new DefaultStyledDocument();
    textPaneDebug.setDocument(documentDebug);

    final JPanel debugPanel = new JPanel();
    final BoxLayout boxLayout = new BoxLayout(debugPanel, BoxLayout.PAGE_AXIS);
    debugPanel.setLayout(boxLayout);
    debugPanel.setBackground(new Color(224, 224, 224));
    debugPanel.setBorder(new EmptyBorder(3, 0, 0, 0));
    debugPanel.add(textPaneDebugScroller);
    return debugPanel;
  }
  public void displaySharkey() {
    displayDataState = DisplayDataState.SHARKEY;
    clearText();
    style = jTextPane.addStyle("STYLE", null);
    Document doc = jTextPane.getStyledDocument();

    try {
      StyleConstants.setForeground(style, ColorScheme.FOREGROUND_YELLOW);
      StyleConstants.setFontSize(style, 13);
      StyleConstants.setFontFamily(style, "Menlo");

      doc.insertString(doc.getLength(), SharkBG.SHARKEY, style);
    } catch (BadLocationException e) {
      e.printStackTrace();
    }

    jTextPane.setDocument(doc);
  }
  public void displayClass(List<Translator.ELEMENT> elements) {
    displayDataState = DisplayDataState.INSIDE_CLASS;
    clearText();
    StyleConstants.setFontSize(style, 18);

    Document doc = new DefaultStyledDocument();

    try {
      for (Translator.ELEMENT e : elements) {
        switch (e.tag) {
          case MODIFIER:
            StyleConstants.setForeground(style, ColorScheme.FOREGROUND_ORANGE);
            break;
          case DOCUMENT:
            StyleConstants.setForeground(style, ColorScheme.FOREGROUND_YELLOW);
            break;
          case IDENTIFIER:
            StyleConstants.setForeground(style, ColorScheme.FOREGROUND_CYAN);
            break;
          case ANNOTATION:
            StyleConstants.setForeground(style, ColorScheme.FOREGROUND_YELLOW_ANNOTATIONS);
            break;
          case XML_TAG:
            StyleConstants.setForeground(style, ColorScheme.FOREGROUND_YELLOW);
            break;
          case XML_ATTR_NAME:
            StyleConstants.setForeground(style, ColorScheme.FOREGROUND_CYAN);
            break;
          case XML_ATTR_VALUE:
            StyleConstants.setForeground(style, ColorScheme.FOREGROUND_YELLOW_ANNOTATIONS);
            break;
          default:
            StyleConstants.setForeground(style, Color.LIGHT_GRAY);
        }
        doc.insertString(doc.getLength(), e.text, style);
      }
    } catch (BadLocationException e) {
      e.printStackTrace();
    }

    StyleConstants.setForeground(style, ColorScheme.FOREGROUND_CYAN);

    jTextPane.setDocument(doc);
  }
  public void displayReducedClassesNames(List<String> classNamesToShow, String inputText) {
    displayDataState = DisplayDataState.CLASSES_LIST;

    clearText();

    int matchIndex;

    String beforeMatch = "";
    String match;
    String afterMatch = "";

    StyleConstants.setFontSize(style, 18);
    StyleConstants.setForeground(style, ColorScheme.FOREGROUND_CYAN);

    Document doc = jTextPane.getDocument();

    for (String className : classNamesToShow) {
      matchIndex = className.indexOf(inputText);

      if (matchIndex > -1) {
        beforeMatch = className.substring(0, matchIndex);
        match = className.substring(matchIndex, matchIndex + inputText.length());
        afterMatch = className.substring(matchIndex + inputText.length(), className.length());
      } else {
        // we are here by camel match
        // i.e. 2-3 letters that fits
        // to class name
        match = className;
      }

      try {
        doc.insertString(doc.getLength(), beforeMatch, style);
        StyleConstants.setBackground(style, ColorScheme.SELECTION_BG);
        doc.insertString(doc.getLength(), match, style);
        StyleConstants.setBackground(style, ColorScheme.BACKGROUND);
        doc.insertString(doc.getLength(), afterMatch + "\n", style);
      } catch (BadLocationException e) {
        e.printStackTrace();
      }
    }

    jTextPane.setDocument(doc);
  }
Пример #10
0
    @Subscribe
    public void displayChatMessage(ChatEvent ev) {
        ReceivedChatMessage fm = createReceivedMessage(ev);
        formattedMessages.addLast(fm);

        if (client.getState() == JFrame.ICONIFIED) {
            messageReceivedWhileIconified = true;
        } else {
            setForceFocus();
        }

        DefaultStyledDocument doc = new DefaultStyledDocument();
        int offset = 0;
        try {
            for (ReceivedChatMessage msg : formattedMessages) {
                SimpleAttributeSet attrs = new SimpleAttributeSet();
                ColorConstants.setForeground(attrs, msg.color);
                String nick = msg.nickname;
                String text = msg.ev.getText();
                doc.insertString(offset, nick + ": ", attrs);
                offset += nick.length() + 2;

                Color textColor = client.getTheme().getTextColor();
                if (textColor == null) {
                    attrs = null;
                } else {
                    attrs = new SimpleAttributeSet();
                    ColorConstants.setForeground(attrs, client.getTheme().getTextColor());
                }
                doc.insertString(offset, text + "\n", attrs);
                offset += text.length() + 1;
            }
        } catch (BadLocationException e) {
            logger.error(e.getMessage(), e); //should never happen
        }
        messagesPane.setDocument(doc);
        repaint();
    }
  public void displayClass(String classString) {
    displayDataState = DisplayDataState.INSIDE_CLASS;
    try {
      String currentText = jTextPane.getDocument().getText(0, jTextPane.getDocument().getLength());
      if (currentText.equals(getOneColorFormattedOutput(classString))) {
        return;
      }
    } catch (BadLocationException e) {
      e.printStackTrace();
    }

    clearText();
    StyleConstants.setFontSize(style, 18);

    Document doc = new DefaultStyledDocument();

    try {
      doc.insertString(doc.getLength(), getOneColorFormattedOutput(classString), style);
    } catch (BadLocationException e) {
      e.printStackTrace();
    }

    jTextPane.setDocument(doc);
  }
Пример #12
0
  HtmlPanel(final Map<String, Action> actions, HtmlPage page) throws IOException {
    super(new BorderLayout());

    this.actions = actions;
    textPane = new JTextPane();
    find = new JTextField();
    matches = new JLabel();
    this.page = null;

    final Dimension d = matches.getPreferredSize();
    matches.setPreferredSize(new Dimension(100, d.height));

    textPane.setEditable(false);
    textPane.setFocusable(false);
    textPane.addHyperlinkListener(
        new HyperlinkListener() {

          public final void hyperlinkUpdate(HyperlinkEvent ev) {
            if (ev.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
              final JEditorPane pane = (JEditorPane) ev.getSource();
              if (ev instanceof HTMLFrameHyperlinkEvent) {
                final HTMLFrameHyperlinkEvent evt = (HTMLFrameHyperlinkEvent) ev;
                final HTMLDocument doc = (HTMLDocument) pane.getDocument();
                doc.processHTMLFrameHyperlinkEvent(evt);
              } else if (Desktop.isDesktopSupported())
                try {
                  Desktop.getDesktop().browse(ev.getURL().toURI());
                } catch (final Exception e) {
                  e.printStackTrace();
                }
            }
          }
        });

    final HTMLEditorKit kit =
        new HTMLEditorKit() {
          private static final long serialVersionUID = 1L;

          @Override
          public final Document createDefaultDocument() {
            final HTMLDocument doc = (HTMLDocument) super.createDefaultDocument();
            // Load synchronously.
            doc.setAsynchronousLoadPriority(-1);
            return doc;
          }
        };

    final StyleSheet styleSheet = kit.getStyleSheet();
    final InputStream is = getClass().getResourceAsStream("/doogal.css");
    try {
      styleSheet.loadRules(newBufferedReader(is), null);
    } finally {
      is.close();
    }

    textPane.setEditorKit(kit);

    final Document doc = kit.createDefaultDocument();
    textPane.setDocument(doc);
    textPane.addMouseListener(
        new MouseAdapter() {

          private final void showPopup(MouseEvent e) {
            if (e.isPopupTrigger()) {
              final JPopupMenu menu = newPopupMenu(TableType.DOCUMENT, actions);
              if (null != menu) menu.show(e.getComponent(), e.getX(), e.getY());
            }
          }

          @Override
          public final void mousePressed(MouseEvent e) {
            showPopup(e);
          }

          @Override
          public final void mouseReleased(MouseEvent e) {
            showPopup(e);
          }
        });
    find.setColumns(16);
    find.setFont(new Font("Dialog", Font.PLAIN, TINY_FONT));
    find.setMargin(new Insets(2, 2, 2, 2));
    find.addActionListener(
        new ActionListener() {
          public final void actionPerformed(ActionEvent ev) {
            find(find.getText());
          }
        });

    final JLabel label = new JLabel("Quick Find: ");
    label.setLabelFor(find);

    final JButton clear = new JButton("Clear");
    clear.setMargin(new Insets(1, 5, 0, 5));
    clear.setFont(new Font("Dialog", Font.PLAIN, TINY_FONT));
    clear.addActionListener(
        new ActionListener() {
          public final void actionPerformed(ActionEvent e) {
            find.setText("");
            find("");
          }
        });

    final JPanel findPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    findPanel.add(label);
    findPanel.add(find);
    findPanel.add(clear);
    findPanel.add(matches);

    scrollPane =
        new JScrollPane(
            textPane,
            ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    scrollPane.setFocusable(false);
    final JScrollBar scrollBar = scrollPane.getVerticalScrollBar();
    scrollBar.setBlockIncrement(scrollBar.getBlockIncrement() * 20);
    scrollBar.setUnitIncrement(scrollBar.getUnitIncrement() * 20);

    add(scrollPane, BorderLayout.CENTER);
    add(findPanel, BorderLayout.SOUTH);

    setPage(page);
  }
  About() {
    window = new JWindow();
    this.setPreferredSize(new Dimension(650, 550));
    this.setVisible(true);
    this.setLayout(null);

    JTextPane text = new JTextPane();
    text.setBounds(5, 150, 625, 525);
    text.setVisible(true);
    text.setEditable(false);
    text.setOpaque(false);
    HTMLEditorKit htmlKit =
        new HTMLEditorKit() {
          public Parser getParser() {
            return super.getParser();
          }
        };
    HTMLDocument htmlDoc = new HTMLDocument();
    text.addHyperlinkListener(
        new HyperlinkListener() {
          public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
              if (Desktop.isDesktopSupported()) {
                try {
                  Desktop.getDesktop().browse(e.getURL().toURI());
                  return;
                } catch (IOException e1) {
                } catch (URISyntaxException e1) {
                }
              }
              try {
                Runtime.getRuntime().exec("xdg-open ".concat(e.getURL().toString()));
              } catch (IOException ioex) {
                ControlRoom.log(
                    Level.WARNING,
                    "Failed to show file: '"
                        + e.getURL().toString()
                        + "'. Possible unsupported File Manager...",
                    null);
              }
            }
          }
        });
    text.setEditorKit(htmlKit);
    text.setDocument(htmlDoc);
    try {
      BufferedReader reader =
          new BufferedReader(
              new InputStreamReader(
                  this.getClass().getResourceAsStream("/resources/about.html"), "UTF-8"));
      htmlKit.read(reader, htmlDoc, htmlDoc.getLength());
    } catch (IOException ioex) {
      ControlRoom.log(Level.SEVERE, "Failed to read about.html", ioex);
    } catch (BadLocationException e) {
      e
          .printStackTrace(); // To change body of catch statement use File | Settings | File
                              // Templates.
    }

    text.addMouseListener(this);
    window.getContentPane().add(text);
    window.getContentPane().add(this);
    window.addMouseListener(this);
    window.pack();
    ControlRoom.setWindowRelativeToCentral(window);
    window.setVisible(true);
    window.setAlwaysOnTop(true);
  }
Пример #14
0
  public IRCBOT(boolean uList, String channel, int chatNum) {

    // chatter = new ChatDisplay("<html><body bgcolor='black'><table border=0pt width=100%>");
    winNum = chatNum;
    URL iconURL = getClass().getResource("P_300x300.png");
    ImageIcon icon = new ImageIcon(iconURL);
    setIconImage(icon.getImage());

    Action doNothing =
        new AbstractAction() {

          @Override
          public void actionPerformed(ActionEvent e) {}
        };

    channelName = channel;
    standardWindow = uList;

    chatInput = new JTextArea(4, 55);
    chatInput.setWrapStyleWord(true);
    chatInput.setLineWrap(true);
    chatInput.getInputMap().put(KeyStroke.getKeyStroke("ENTER"), "doNothing");
    chatScreen = new JTextPane();
    chatScreen.setContentType("text/html");
    chatScreen.setEditorKit(kit);
    chatScreen.setDocument(doc);
    userList = new JTextPane();
    registeredUserList = new JTextPane();
    sendButton = new JButton("SEND");
    g_start = new JButton("START");
    g_end = new JButton("END");
    g_reroll = new JButton("secret");

    JLabel l_giveaway = new JLabel("Giveaway", JLabel.CENTER);
    JLabel l_chat = new JLabel("Chat", JLabel.CENTER);
    JLabel l_uList = new JLabel("User List", JLabel.CENTER);

    sendButton.addActionListener(this);
    g_start.addActionListener(this);
    g_end.addActionListener(this);
    g_reroll.addActionListener(this);

    g_start.setEnabled(false); // disabled for basic irc client
    g_end.setEnabled(false);
    g_reroll.setEnabled(false);

    // String start = "<html><body>";

    Dimension min = new Dimension(100, 1);
    Dimension pref = new Dimension(150, 1);
    Dimension max = new Dimension(600, 600);
    // chatScreen.setMinimumSize(min);
    // userList.setMinimumSize(min);
    // chatInput.addKeyListener(KeyBoardListener);

    JPanel mainPanel = new JPanel(new BorderLayout(5, 5));
    JPanel left = new JPanel(new BorderLayout(5, 5));
    JPanel mid = new JPanel(new BorderLayout(5, 5));
    JPanel right = new JPanel(new BorderLayout(5, 5));
    JPanel giveaway_buttons = new JPanel(new BorderLayout(5, 5));

    JPanel sendBar = new JPanel();
    scrollChat = new JScrollPane(chatScreen);
    JScrollPane scrollChatInput = new JScrollPane(chatInput);
    userListScroll = new JScrollPane(userList);
    JScrollPane regUserListScroll = new JScrollPane(registeredUserList);

    userListScroll.setMinimumSize(min);
    // userListScroll.setPreferredSize(pref);
    // userListScroll.setMaximumSize(new Dimension(800,600));
    // userListScroll.setPreferredSize(new Dimension(100,100));
    // scrollChat.setPreferredSize(pref);
    scrollChat.setMinimumSize(min);
    // scrollChat.setMaximumSize(new Dimension(500,500));
    regUserListScroll.setPreferredSize(pref);

    mid.add(l_chat, BorderLayout.NORTH);
    mid.add(scrollChat, BorderLayout.CENTER);

    right.add(l_uList, BorderLayout.NORTH);
    right.add(userListScroll, BorderLayout.CENTER);

    giveaway_buttons.add(g_start, BorderLayout.WEST);
    giveaway_buttons.add(g_end, BorderLayout.CENTER);
    giveaway_buttons.add(g_reroll, BorderLayout.PAGE_END);

    left.add(giveaway_buttons, BorderLayout.PAGE_END);

    JSplitPane chat_userList = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, mid, right);
    chat_userList.setOneTouchExpandable(true);
    chat_userList.setDividerLocation(500);
    chat_userList.setResizeWeight(0.5);
    chat_userList.setContinuousLayout(true);
    // chat_userList.setPreferredSize(new Dimension(100,100));
    chat_userList.setMinimumSize(min);
    // chat_userList.setMaximumSize(max);

    userListScroll.setHorizontalScrollBarPolicy(HORIZONTAL_SCROLLBAR_NEVER);
    // scroll.add(chatScreen);

    sendBar.add(scrollChatInput);
    sendBar.add(sendButton);

    if (standardWindow) {

      mainPanel.add(chat_userList, BorderLayout.CENTER);
      mainPanel.add(sendBar, BorderLayout.PAGE_END);

      JMenuBar menuBar = new JMenuBar();
      JMenu fileMenu = new JMenu("File");
      settings = new JMenuItem("Settings");

      settings.addActionListener(this);

      fileMenu.add(settings);
      menuBar.add(fileMenu);

      left.add(l_giveaway, BorderLayout.NORTH);
      left.add(regUserListScroll, BorderLayout.CENTER);
      // left.setBorder(new EmptyBorder(0,5,0,0));
      // chat_userList.setBorder(new EtchedBorder(0,0,0,5));
      mainPanel.add(left, BorderLayout.WEST);
      mainPanel.add(menuBar, BorderLayout.PAGE_START);
      // mainPanel.setBorder(new EmptyBorder(0,10,10,10));
    } else {
      mainPanel.add(scrollChat, BorderLayout.CENTER);
    }
    registeredUserList.setEditable(false);
    userList.setEditable(false);
    chatScreen.setEditable(false);

    registeredUserList.setFont(new Font("Courier New", Font.PLAIN, 12));
    chatScreen.setFont(new Font("Courier New", Font.PLAIN, 12));
    chatInput.setFont(new Font("Courier New", Font.PLAIN, 12));

    getContentPane().add(mainPanel);
    setSize(800, 500);
    setVisible(true);
    setResizable(true);
    setLocationRelativeTo(null);
    setTitle("IRC Chatter");
    setMinimumSize(new Dimension(500, 200));

    addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowClosing(WindowEvent e) {
            // System.out.println("\n\n\n\n\n\\n\nCLOSEDWINDOW\n\n\n\n\n\n\n\n");
            if (sock.isSafe() == true) sock.outputText("PART " + channelName + "\r\n");
            // System.out.println("\n\n\n\n\n\\n\nCLOSEDWINDOW\n\n\n\n\n\n\n\n");
          }
        });
    chatInput.addKeyListener(this);
    chatInput.requestFocus();
  }
Пример #15
0
  private static void createEnvironment(String aFilename, JFrame jframe) {
    JTextPane textPane =
        new JTextPane() {
          public boolean getScrollableTracksViewportWidth() {
            return getUI().getPreferredSize(this).width <= getParent().getSize().width;
          }
        };

    JTextField filenameTextField = new JTextField(aFilename);
    JSpinner skipSizeSpinner = new JSpinner(new SpinnerNumberModel(50, 0, 100000, 1000));
    JCheckBox skipSmall = new JCheckBox("skip productions smaller than:");
    JCheckBox skipAll = new JCheckBox("skip all  ");

    DebuggerParserListener debugListener =
        new DebuggerParserListener(
            skipSmall.getModel(), skipSizeSpinner.getModel(), skipAll.getModel());
    CallStackParserListener callStackParserListener = new CallStackParserListener(debugListener);
    HighlighterParserListener highlighterParserListener =
        new HighlighterParserListener(textPane, debugListener);
    ProductionsParserListener productionsParserListener =
        new ProductionsParserListener(debugListener);
    ExecutionParserListener treeParserListener = new ExecutionParserListener(debugListener);
    ParserListenerMultiplexer parserListenerMultiplexer =
        new ParserListenerMultiplexer(
            productionsParserListener,
            treeParserListener,
            highlighterParserListener,
            callStackParserListener,
            debugListener);
    debugListener.setProductionFrames(parserListenerMultiplexer.getProductionFrames());
    ListenedParser parser = new ListenedParser(parserListenerMultiplexer);
    debugListener.stepInto();

    parser.getLoggingMap().log("begin parsing");
    boolean initialized = false;

    while (true) {
      try {
        parser.setDisabled(false);

        String file = filenameTextField.getText();
        StringBuilder sourcecode =
            new StringBuilder(
                new Scanner(HumoTester.class.getResourceAsStream("/" + file))
                    .useDelimiter("\\Z")
                    .next());

        parserListenerMultiplexer.init(file, sourcecode, !initialized);
        treeParserListener.init(file, !initialized, sourcecode);
        productionsParserListener.init(file, !initialized);
        callStackParserListener.init(file, sourcecode, !initialized);
        textPane.setDocument(parserListenerMultiplexer.getCurrentFrame().getDocument());
        debugListener.stepInto();

        ((DefaultTreeModel) treeParserListener.getExecutionTree().getModel()).reload();
        ((DefaultTreeModel) callStackParserListener.getUsedProductionsTree().getModel()).reload();
        ((DefaultTreeModel) productionsParserListener.getProductionsTree().getModel()).reload();

        if (!initialized) {
          showTree(
              highlighterParserListener,
              debugListener,
              parser,
              sourcecode,
              textPane,
              callStackParserListener.getUsedProductionsTree(),
              treeParserListener.getExecutionTree(),
              productionsParserListener.getProductionsTree(),
              jframe,
              filenameTextField,
              skipSmall,
              skipSizeSpinner,
              parserListenerMultiplexer,
              skipAll);
          initialized = true;
        }
        parser.init();
        parser.parse(sourcecode, 0);
        parser.getLoggingMap().log("end parsing");
        debugListener.getStepper().pause();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
Пример #16
0
 public void setDocument(Document doc) {
   super.setDocument(new OverwritableDocument(this, doc));
 }