/** Creates the error area component. */
 private void initErrorArea() {
   SimpleAttributeSet attribs = new SimpleAttributeSet();
   StyleConstants.setAlignment(attribs, StyleConstants.ALIGN_RIGHT);
   StyleConstants.setFontFamily(attribs, errorPane.getFont().getFamily());
   StyleConstants.setForeground(attribs, Color.RED);
   errorPane.setParagraphAttributes(attribs, true);
   errorPane.setPreferredSize(new Dimension(100, 50));
   errorPane.setMinimumSize(new Dimension(100, 50));
   errorPane.setOpaque(false);
 }
  public HelpUI(Frame parent, String title) {
    sidebar = new Sidebar();
    sidebar.setBorder(new EmptyBorder(10, 10, 10, 10));
    infoView = new JTextPane();
    Dimension d1 = sidebar.getPreferredSize();
    infoView.setPreferredSize(new Dimension(d1.width * 3, d1.height - 5));
    infoView.setEditable(false);

    MouseAdapter ma =
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent me) {
            SidebarOption sopt = (SidebarOption) me.getComponent();
            if (sel != null) {
              sel.setSelected(false);
              sel.repaint();
            }
            sel = sopt;
            sel.setSelected(true);
            sel.repaint();
            renderInfo();
          }
        };

    general = new SidebarOption("General Info", HELP_GENERAL_LOC);
    general.addMouseListener(ma);
    sidebar.add(general);

    sidebar.add(Box.createVerticalStrut(scy(10)));

    artifact = new SidebarOption("Artifacts", HELP_ARTIFACTS_LOC);
    artifact.addMouseListener(ma);
    sidebar.add(artifact);

    sidebar.add(Box.createVerticalStrut(scy(10)));

    net = new SidebarOption("Networking", HELP_NET_LOC);
    net.addMouseListener(ma);
    sidebar.add(net);

    sidebar.add(Box.createVerticalStrut(scy(10)));

    gpl = new SidebarOption("License", HELP_GPL_LOC);
    gpl.addMouseListener(ma);
    sidebar.add(gpl);

    general.setSelected(true);
    sel = general;

    sidebar.add(Box.createVerticalGlue());

    add(BorderLayout.WEST, sidebar);
    add(BorderLayout.CENTER, new JScrollPane(infoView));
    setResizable(false);
    pack();
    setLocationRelativeTo(parent);
    setTitle(title);

    renderInfo();
  }
  /**
   * Shows the given error message.
   *
   * @param text the text of the error
   */
  private void showErrorMessage(String text) {
    errorPane.setText(text);

    if (errorPane.getParent() == null) add(errorPane, BorderLayout.NORTH);

    SwingUtilities.getWindowAncestor(CreateSip2SipAccountForm.this).pack();
  }
예제 #4
0
    public void actionPerformed(ActionEvent a) {
      String command = a.getActionCommand();
      if (command.equals("e")) {
        // Log toggle.
        if (consoleDisplayed = !consoleDisplayed) {
          splitter.add(outputScroll);
          splitter.setDividerLocation(.8);
        } else {
          splitter.remove(outputScroll);
        }
      } else if (command.equals("k")) {
        if (text.getText().contains("class")) {
          // This means we should try to compile this as normal.

          // Pulls out class name
          String code = text.getText();
          int firstPos = code.indexOf("class");
          int secondPos = code.indexOf("{");
          String name = code.substring(firstPos + "class".length() + 1, secondPos).trim();

          compileAndRun(name, text.getText());
        } else {
          // This means we should compile this as a playground.
          String code = text.getText();

          // Common import statements built-in
          String importDump = new String();
          importDump +=
              ("import java.util.*;\n"
                  + "import javax.swing.*;\n"
                  + "import javax.swing.event.*;\n"
                  + "import java.awt.*;\n"
                  + "import java.awt.event.*;\n"
                  + "import java.io.*;\n");

          // Pulls out any "import" statements and appends them to the import dump.
          int i = code.indexOf("import");
          while (i >= 0) {
            String s = code.substring(i, code.indexOf(";", i) + 1);
            code = code.replaceFirst(s, "");
            importDump += s + "\n";
            i = code.indexOf("import", i + 1);
          }

          // Inject the class header and main method
          code =
              "//User and auto-imports pre-defined\n"
                  + importDump
                  + "//Autogenerated class\npublic class Main {\npublic static void main(String[] args) {\n"
                  + code
                  + "\n}\n}";

          compileAndRun("Main", code);
        }
      }
    }
예제 #5
0
 // For compatibility with writers when talking to the JVM.
 public void write(char[] buffer, int offset, int length) {
   String text = new String(buffer, offset, length);
   SwingUtilities.invokeLater(
       () -> {
         try {
           pane.getDocument().insertString(pane.getDocument().getLength(), text, properties);
         } catch (Exception e) {
         }
       });
 }
  private void renderInfo() {
    if (sel.rsc == null) {
      try {
        infoView.setPage(BLANK_PAGE);
      } catch (IOException e) {
        e.printStackTrace();
      }
      return;
    }

    try {
      infoView.setPage(sel.rsc);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
예제 #7
0
 // Appends text to the end of the log, using the provided settings. Doesn't add a new line.
 private static void print(String message, SimpleAttributeSet settings) {
   try {
     outputText
         .getDocument()
         .insertString(outputText.getDocument().getLength(), message, settings);
   } catch (BadLocationException e) {
     try {
       outputText
           .getDocument()
           .insertString(
               outputText.getDocument().getLength(),
               "Couldn't insert message \"" + message + "\".",
               progErr);
     } catch (BadLocationException b) {
       // If you ever reach this error, something is seriously wrong, so just please swallow it and
       // ignore it.
     }
   }
 }
  /** Clears all the data previously entered in the form. */
  public void clear() {
    usernameField.setText("");
    displayNameField.setText("");
    passField.setText("");
    retypePassField.setText("");
    emailField.setText("");
    errorPane.setText("");

    remove(errorPane);
  }
예제 #9
0
 // This is used for when the user's code has something wrong.
 // This has checks in place to make some more sense of the error messages.
 // Internal errors should be logged using println and the progErr font.
 private static void logError(String message) {
   if (message.contains("Playground$FrameAction")) {
     // This is a reflection error, so that means that we have a malformed class or method.
     String code = text.getText();
     if (!code.startsWith("public class")) {
       println(
           "Error: You defined a private class. Please use \"public class <classname>\".",
           progErr);
     } else {
       println(
           "Error: Malformed method. Make sure your main method is defined as \"public static void main(<any args>)\".",
           progErr);
     }
   } else {
     println(message, progErr);
   }
 }
예제 #10
0
  /**
   * Creates an instance of <tt>ShowPreviewDialog</tt>
   *
   * @param chatPanel The <tt>ChatConversationPanel</tt> that is associated with this dialog.
   */
  ShowPreviewDialog(final ChatConversationPanel chatPanel) {
    this.chatPanel = chatPanel;

    this.setTitle(
        GuiActivator.getResources().getI18NString("service.gui.SHOW_PREVIEW_DIALOG_TITLE"));
    okButton = new JButton(GuiActivator.getResources().getI18NString("service.gui.OK"));
    cancelButton = new JButton(GuiActivator.getResources().getI18NString("service.gui.CANCEL"));

    JPanel mainPanel = new TransparentPanel();
    mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
    mainPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    // mainPanel.setPreferredSize(new Dimension(200, 150));
    this.getContentPane().add(mainPanel);

    JTextPane descriptionMsg = new JTextPane();
    descriptionMsg.setEditable(false);
    descriptionMsg.setOpaque(false);
    descriptionMsg.setText(
        GuiActivator.getResources().getI18NString("service.gui.SHOW_PREVIEW_WARNING_DESCRIPTION"));

    Icon warningIcon = null;
    try {
      warningIcon =
          new ImageIcon(
              ImageIO.read(
                  GuiActivator.getResources().getImageURL("service.gui.icons.WARNING_ICON")));
    } catch (IOException e) {
      logger.debug("failed to load the warning icon");
    }
    JLabel warningSign = new JLabel(warningIcon);

    JPanel warningPanel = new TransparentPanel();
    warningPanel.setLayout(new BoxLayout(warningPanel, BoxLayout.X_AXIS));
    warningPanel.add(warningSign);
    warningPanel.add(Box.createHorizontalStrut(10));
    warningPanel.add(descriptionMsg);

    enableReplacement =
        new JCheckBox(
            GuiActivator.getResources()
                .getI18NString("plugin.chatconfig.replacement.ENABLE_REPLACEMENT_STATUS"));
    enableReplacement.setOpaque(false);
    enableReplacement.setSelected(cfg.getBoolean(ReplacementProperty.REPLACEMENT_ENABLE, true));
    enableReplacementProposal =
        new JCheckBox(
            GuiActivator.getResources()
                .getI18NString("plugin.chatconfig.replacement.ENABLE_REPLACEMENT_PROPOSAL"));
    enableReplacementProposal.setOpaque(false);

    JPanel checkBoxPanel = new TransparentPanel();
    checkBoxPanel.setLayout(new BoxLayout(checkBoxPanel, BoxLayout.Y_AXIS));
    checkBoxPanel.add(enableReplacement);
    checkBoxPanel.add(enableReplacementProposal);

    JPanel buttonsPanel = new TransparentPanel(new FlowLayout(FlowLayout.CENTER));
    buttonsPanel.add(okButton);
    buttonsPanel.add(cancelButton);

    mainPanel.add(warningPanel);
    mainPanel.add(Box.createVerticalStrut(10));
    mainPanel.add(checkBoxPanel);
    mainPanel.add(buttonsPanel);

    okButton.addActionListener(this);
    cancelButton.addActionListener(this);

    this.setPreferredSize(new Dimension(390, 230));
  }
예제 #11
0
  public static void main() {
    // Main
    frame = new JFrame("Java Playground");
    frame.setSize(640, 480);
    // Make sure the divider is properly resized
    frame.addComponentListener(
        new ComponentAdapter() {
          public void componentResized(ComponentEvent c) {
            splitter.setDividerLocation(.8);
          }
        });
    // Make sure the JVM is reset on close
    frame.addWindowListener(
        new WindowAdapter() {
          public void windowClosed(WindowEvent w) {
            new FrameAction().kill();
          }
        });

    // Setting up the keybinding
    // Ctrl+k or Cmd+k -> compile
    bind(KeyEvent.VK_K);

    // Ctrl+e or Cmd+e -> console
    bind(KeyEvent.VK_E);

    // Save, New file, Open file, Print.
    // Currently UNUSED until I figure out how normal java files and playground files will
    // interface.
    bind(KeyEvent.VK_S);
    bind(KeyEvent.VK_N);
    bind(KeyEvent.VK_O);
    bind(KeyEvent.VK_P);

    // Binds the keys to the action defined in the FrameAction class.
    frame.getRootPane().getActionMap().put("console", new FrameAction());

    // The main panel for typing code in.
    text = new JTextPane();
    textScroll = new JScrollPane(text);
    textScroll.setBorder(null);
    textScroll.setPreferredSize(new Dimension(640, 480));

    // Document with syntax highlighting. Currently unfinished.
    doc = text.getStyledDocument();
    doc.addDocumentListener(
        new DocumentListener() {
          public void changedUpdate(DocumentEvent d) {}

          public void insertUpdate(DocumentEvent d) {}

          public void removeUpdate(DocumentEvent d) {}
        });

    ((AbstractDocument) doc).setDocumentFilter(new NewLineFilter());

    // The output log; a combination compiler warning/error/runtime error/output log.
    outputText = new JTextPane();
    outputScroll = new JScrollPane(outputText);
    outputScroll.setBorder(null);

    // "Constant" for the error font
    error = new SimpleAttributeSet();
    error.addAttribute(StyleConstants.CharacterConstants.Italic, Boolean.TRUE);
    error.addAttribute(StyleConstants.Foreground, Color.RED);

    // "Constant" for the warning message font
    warning = new SimpleAttributeSet();
    warning.addAttribute(StyleConstants.CharacterConstants.Italic, Boolean.TRUE);
    warning.addAttribute(StyleConstants.Foreground, Color.PINK);

    // "Constant" for the debugger error font
    progErr = new SimpleAttributeSet();
    progErr.addAttribute(StyleConstants.Foreground, Color.BLUE);

    // Print streams to redirect System.out and System.err.
    out = new TextOutputStream(outputText, null);
    err = new TextOutputStream(outputText, error);
    System.setOut(new PrintStream(out));
    System.setErr(new PrintStream(err));

    // Sets up the output log
    outputText.setEditable(false);
    outputScroll.setVisible(true);

    // File input/output setup
    chooser = new JFileChooser();

    // Setting up miscellaneous stuff
    compiler = ToolProvider.getSystemJavaCompiler();
    JVMrunning = false;
    redirectErr = null;
    redirectOut = null;
    redirectIn = null;

    // Sets up the splitter pane and opens the program up
    splitter = new JSplitPane(JSplitPane.VERTICAL_SPLIT, textScroll, outputScroll);
    consoleDisplayed = false;
    splitter.remove(outputScroll); // Initially hides terminal until it is needed
    splitter.setOneTouchExpandable(true);
    frame.add(splitter);
    frame.setVisible(true);

    // Sets the divider to the proper one, for debugging
    // splitter.setDividerLocation(.8);
  }
예제 #12
0
    public void actionPerformed(ActionEvent a) {
      // Note that this only works on *nix OSes.
      // For windows, get the first character of the action command, cast it to int, and compare
      // that on a case-by-case basis.

      String command = a.getActionCommand();
      if (command.equals("e")) {
        // Log toggle.
        if (consoleDisplayed = !consoleDisplayed) {
          splitter.add(outputScroll);
          splitter.setDividerLocation(defaultSliderPosition);
        } else {
          splitter.remove(outputScroll);
        }
      } else if (command.equals("r")) {
        // Gets the code into a string.
        String code = text.getText();

        // Marks certain areas as "dirty".
        // Dirty areas are places that shouldn't be considered for any keywords,
        // including "import", "extend", and so on.
        ArrayList<Integer> dirtyBounds = getDirty(code);

        if (text.getText().contains("class")) {
          // This means we should try to compile this as normal.

          // Pulls out class name
          int firstPos = code.indexOf("public class");
          int secondPos = code.indexOf("{");
          String name = code.substring(firstPos + "public class".length() + 1, secondPos).trim();

          // Just a safety check to make sure you don't try to modify this program while it's
          // running.
          if (name.equals("Playground")) {
            System.out.println(
                "I know what you're doing and I don't approve. I won't even compile that.");
            return;
          }

          compileAndRun(name, code);
        } else {
          // This means we should compile this as a playground.

          // Common import statements built-in
          String importDump = new String();
          importDump +=
              ( // "import java.util.*;\n" +
              "import javax.swing.*;\n"
                  + "import javax.swing.event.*;\n"
                  + "import java.awt.*;\n"
                  + "import java.awt.event.*;\n"
                  + "import java.io.*;\n");

          // User-defined or auto-generated methods
          String methodDump = new String();

          // dirtyBounds.forEach(System.out::println);

          // Pulls out any "import" statements and appends them to the import dump.
          int i = code.indexOf("import");
          while (i >= 0) {
            // Ignores comments and string literals
            if (isDirty(dirtyBounds, i)) {
              i = code.indexOf("import", i + 1);
              continue;
            }

            String s = code.substring(i, code.indexOf(";", i) + 1);
            // System.out.println("Found import: " + s);
            code = code.replaceFirst(s, "");
            importDump += s + "\n";
            i = code.indexOf("import", i + 1);
          }

          // Pulls out methods- these are defined by the keyword "method" until a closing bracket.
          /*
          i = code.indexOf("method");
          while(i >= 0) {
          //Ignores comments and string literals
          if (isDirty(dirtyBounds, i)) {
          i = code.indexOf("method", i+1);
          continue;
          }

          //This scans from the first '{' until the last '}' to pull out the full method declaration.
          char temp = 0;
          int pos = code.indexOf("{", i+1), count = 1;
          if(pos != -1) {
          while(++pos < code.length()) {
          if (count == 0)
          break;

          temp = code.charAt(pos);
          if (temp == '{')
          count++;
          if (temp == '}')
          count--;
          }
          } else {
          //Missing an opening bracket, so just remove "method" and hope it compiles.
          code = code.replaceFirst("method", "");
          i = code.indexOf("method", i+1);
          continue;
          }
          String s = code.substring(i, pos);

          //System.out.println("Found method: " + s);
          code = code.replace(s, "");
          methodDump+=(s.replaceFirst("method ", "static ")) + "\n";

          i = code.indexOf("method", i+1);
          }*/

          // Pulls out all methods
          i = code.indexOf("(");
          while (i >= 0) {
            if (isDirty(dirtyBounds, i)) {
              i = code.indexOf("(", i + 1);
              continue;
            }

            // Move backwards first
            char temp = 0;
            int pos = i;
            boolean shouldSkip = false;
            while (--pos > 0) {
              temp = code.charAt(pos);
              if (temp == '.') {
                shouldSkip = true;
                break;
              } // This is a method call, ie String.charAt();
              if (temp == ';') {
                ++pos;
                break;
              } // This is most likely a method declaration, since we had no errors
              // If we hit the start of the file, that's probable a method dec. too!
            }
            if (shouldSkip || isDirty(dirtyBounds, pos)) {
              i = code.indexOf("(", i + 1);
              continue;
            } // If this def. isn't a method or it's in a comment

            int start = pos;
            temp = 0;
            pos = code.indexOf("{", i + 1);
            int count = 1;
            if (pos != -1) {
              while (++pos < code.length()) {
                if (count == 0) break;

                temp = code.charAt(pos);
                if (temp == '{') count++;
                if (temp == '}') count--;
              }
            } else {
              i = code.indexOf("(", i + 1);
              continue;
            }

            int end = pos;
            String s = code.substring(start, end);
            code = code.replace(s, "");

            // Just to make it look nicer
            s = s.trim();

            System.out.println("Found method: " + s);
            methodDump += (s + "\n");
            i = code.indexOf("(", i + 1);
          }

          // Inject the class header and main method, imports, and methods
          code =
              "//User and auto-imports pre-defined\n"
                  + importDump
                  + "//Autogenerated class\n"
                  + "public class Main {\n"
                  + "public static void main(String[] args) {\n"
                  + code
                  + "}\n"
                  + methodDump
                  + "}";

          // Run as normal
          compileAndRun("Main", code);
        }
      } else if (command.equals("k")) {
        kill();
      } else if (command.equals("o")) {
        new OptionFrame(frame);
      } else if (command.equals("/")) {
        new HelpFrame(frame);
      }
    }