Ejemplo n.º 1
2
  @Override
  protected Transferable createTransferable(JComponent c) {
    JTextPane aTextPane = (JTextPane) c;

    HTMLEditorKit kit = ((HTMLEditorKit) aTextPane.getEditorKit());
    StyledDocument sdoc = aTextPane.getStyledDocument();
    int sel_start = aTextPane.getSelectionStart();
    int sel_end = aTextPane.getSelectionEnd();

    int i = sel_start;
    StringBuilder output = new StringBuilder();
    while (i < sel_end) {
      Element e = sdoc.getCharacterElement(i);
      Object nameAttr = e.getAttributes().getAttribute(StyleConstants.NameAttribute);
      int start = e.getStartOffset(), end = e.getEndOffset();
      if (nameAttr == HTML.Tag.BR) {
        output.append("\n");
      } else if (nameAttr == HTML.Tag.CONTENT) {
        if (start < sel_start) {
          start = sel_start;
        }
        if (end > sel_end) {
          end = sel_end;
        }
        try {
          String str = sdoc.getText(start, end - start);
          output.append(str);
        } catch (BadLocationException ble) {
          Debug.error(me + "Copy-paste problem!\n%s", ble.getMessage());
        }
      }
      i = end;
    }
    return new StringSelection(output.toString());
  }
Ejemplo n.º 2
1
  private void updateTemplateFromEditor(PrintfTemplate template) {
    ArrayList params = new ArrayList();
    String format = null;
    int text_length = editorPane.getDocument().getLength();
    try {
      format = editorPane.getDocument().getText(0, text_length);
    } catch (BadLocationException ex1) {
    }
    Element section_el = editorPane.getDocument().getDefaultRootElement();
    // Get number of paragraphs.
    int num_para = section_el.getElementCount();
    for (int p_count = 0; p_count < num_para; p_count++) {
      Element para_el = section_el.getElement(p_count);
      // Enumerate the content elements
      int num_cont = para_el.getElementCount();
      for (int c_count = 0; c_count < num_cont; c_count++) {
        Element content_el = para_el.getElement(c_count);
        AttributeSet attr = content_el.getAttributes();
        // Get the name of the style applied to this content element; may be null
        String sn = (String) attr.getAttribute(StyleConstants.NameAttribute);
        // Check if style name match
        if (sn != null && sn.startsWith("Parameter")) {
          // we extract the label.
          JLabel l = (JLabel) StyleConstants.getComponent(attr);
          if (l != null) {
            params.add(l.getName());
          }
        }
      }
    }

    template.setFormat(format);
    template.setTokens(params);
  }
 /** 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 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");
  }
Ejemplo n.º 5
0
 /** Clear the log panel. */
 public void clearLogPanel() {
   try {
     logPane.getDocument().remove(1, logPane.getDocument().getLength() - 1);
   } catch (BadLocationException e) {
     LoggerFactory.getLogger(ProcessUIPanel.class).error(e.getMessage());
   }
 }
Ejemplo n.º 6
0
  private void updateEditorView() {
    editorPane.setText("");
    numParameters = 0;
    try {
      java.util.List elements = editableTemplate.getPrintfElements();
      for (Iterator it = elements.iterator(); it.hasNext(); ) {
        PrintfUtil.PrintfElement el = (PrintfUtil.PrintfElement) it.next();
        if (el.getFormat().equals(PrintfUtil.PrintfElement.FORMAT_NONE)) {
          appendText(el.getElement(), PLAIN_ATTR);
        } else {
          insertParameter(
              (ConfigParamDescr) paramKeys.get(el.getElement()),
              el.getFormat(),
              editorPane.getDocument().getLength());
        }
      }
    } catch (Exception ex) {
      JOptionPane.showMessageDialog(
          this,
          "Invalid Format: " + ex.getMessage(),
          "Invalid Printf Format",
          JOptionPane.ERROR_MESSAGE);

      selectedPane = 1;
      printfTabPane.setSelectedIndex(selectedPane);
      updatePane(selectedPane);
    }
  }
Ejemplo n.º 7
0
 private void jbInit() throws Exception {
   box1 = Box.createVerticalBox();
   this.getContentPane().setLayout(borderLayout1);
   close.setText("Close");
   close.addActionListener(new CellHelpWindow_close_actionAdapter(this));
   jLabel1.setText("Recommendation");
   jLabel2.setText("Description");
   jPanel1.setLayout(borderLayout2);
   jPanel2.setLayout(borderLayout3);
   description.setText("jTextPane1");
   description.setContentType("text/html");
   scp1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
   scp1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
   scp1.setToolTipText("");
   recom.setText("");
   recom.setContentType("text/html");
   this.getContentPane().add(box1, BorderLayout.CENTER);
   box1.add(jPanel1, null);
   box1.add(jPanel2, null);
   this.getContentPane().add(jPanel3, BorderLayout.SOUTH);
   jPanel3.add(close, null);
   jPanel2.add(jLabel1, BorderLayout.NORTH);
   jPanel2.add(scp2, BorderLayout.CENTER);
   scp2.getViewport().add(recom, null);
   jPanel2.add(scp2, BorderLayout.CENTER);
   jPanel1.add(jLabel2, BorderLayout.NORTH);
   jPanel1.add(scp1, BorderLayout.CENTER);
   scp1.getViewport().add(description, null);
 }
Ejemplo n.º 8
0
  public void toChatScreen(String toScreen, boolean selfSeen)
      throws IOException, BadLocationException {
    // Timestamp ts = new Timestamp();
    String toScreenFinal = "";
    Date now = Calendar.getInstance().getTime();
    SimpleDateFormat format = new SimpleDateFormat("hh:mm");
    String ts = format.format(now);

    // chatScreen.append(ts + " " + toScreen + "\n");
    toScreenFinal = "<font color=gray>" + ts + "</font> ";
    if (selfSeen) toScreenFinal = toScreenFinal + "<font color=red>" + toScreen + "</font>";
    else toScreenFinal = toScreenFinal + toScreen;

    // chatter.addTo(toScreen);

    // if(standardWindow) {
    //    chatScreen.setCaretPosition(chatScreen.getDocument().getLength());
    // }
    // else {
    JScrollBar vBar = scrollChat.getVerticalScrollBar();
    int vSize = vBar.getVisibleAmount();
    int maxVBar = vBar.getMaximum();
    int currVBar = vBar.getValue() + vSize;
    kit.insertHTML(doc, doc.getLength(), toScreenFinal, 0, 0, null);
    if (maxVBar == currVBar) {
      chatScreen.setCaretPosition(chatScreen.getDocument().getLength());
    }

    // }

    // kit.insertHTML(doc, doc.getLength(), toScreenFinal, 0, 0, null);

  }
Ejemplo n.º 9
0
  // Remove a test case from testBox and tests array.
  private void removeTest() {

    // Make sure they want to remove the checked tests.
    String message = "Are you sure you would like to remove the selected tests?";
    int decision =
        JOptionPane.showConfirmDialog(null, message, "Remove", JOptionPane.OK_CANCEL_OPTION);

    // If they definitely do want to remove.
    if (decision == JOptionPane.OK_OPTION) {

      // Make array list copy, so as to avoid index errors.
      ArrayList<JCheckBox> newTests = (ArrayList<JCheckBox>) tests.clone();
      int removed = 0;

      for (int i = 0; i < tests.size(); i++) {
        if (tests.get(i).isSelected()) {
          // Remove from the tests copy.
          newTests.remove(i - removed);
          // Remove from the GUI box.
          testBox.setEditable(true);
          testBox.remove(tests.get(i));
          testBox.repaint();
          testBox.setEditable(false);
        }
      }

      // Update the tests with the newly made list.
      tests = newTests;
    }
  }
Ejemplo n.º 10
0
 private void updateDisplay() {
   // first, set block colours
   textView.setBackground(getColour(backgroundColour("text-background-colour")));
   textView.setForeground(getColour(foregroundColour("text-foreground-colour")));
   textView.setCaretColor(getColour(foregroundColour("text-caret-colour")));
   problemsView.setBackground(getColour(backgroundColour("problems-background-colour")));
   problemsView.setForeground(getColour(foregroundColour("problems-foreground-colour")));
   consoleView.setBackground(getColour(backgroundColour("console-background-colour")));
   consoleView.setForeground(getColour(foregroundColour("console-foreground-colour")));
   // second, set colours on the code!
   java.util.List<Lexer.Token> tokens = Lexer.tokenise(textView.getText(), true);
   int pos = 0;
   for (Lexer.Token t : tokens) {
     int len = t.toString().length();
     if (t instanceof Lexer.RightBrace || t instanceof Lexer.LeftBrace) {
       highlightArea(pos, len, foregroundColour("text-brace-colour"));
     } else if (t instanceof Lexer.Strung) {
       highlightArea(pos, len, foregroundColour("text-string-colour"));
     } else if (t instanceof Lexer.Comment) {
       highlightArea(pos, len, foregroundColour("text-comment-colour"));
     } else if (t instanceof Lexer.Quote) {
       highlightArea(pos, len, foregroundColour("text-quote-colour"));
     } else if (t instanceof Lexer.Comma) {
       highlightArea(pos, len, foregroundColour("text-comma-colour"));
     } else if (t instanceof Lexer.Identifier) {
       highlightArea(pos, len, foregroundColour("text-identifier-colour"));
     } else if (t instanceof Lexer.Integer) {
       highlightArea(pos, len, foregroundColour("text-integer-colour"));
     }
     pos += len;
   }
 }
  public DisplayArea(final ClassySharkPanel tabPanel) {
    jTextPane = new JTextPane();
    jTextPane.setEditable(false);
    jTextPane.setBackground(ColorScheme.BACKGROUND);

    jTextPane.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent e) {
            if (displayDataState == DisplayDataState.SHARKEY
                || displayDataState == DisplayDataState.INFO) {
              return;
            }

            if (e.getButton() != MouseEvent.BUTTON1) {
              return;
            }

            if (e.getClickCount() != 2) {
              return;
            }

            int offset = jTextPane.viewToModel(e.getPoint());

            try {
              int rowStart = Utilities.getRowStart(jTextPane, offset);
              int rowEnd = Utilities.getRowEnd(jTextPane, offset);
              String selectedLine = jTextPane.getText().substring(rowStart, rowEnd);
              System.out.println(selectedLine);

              if (displayDataState == DisplayDataState.CLASSES_LIST) {
                tabPanel.onSelectedClassName(selectedLine);
              } else if (displayDataState == DisplayDataState.INSIDE_CLASS) {
                if (selectedLine.contains("import")) {
                  tabPanel.onSelectedImportFromMouseClick(
                      getClassNameFromImportStatement(selectedLine));
                } else {

                  rowStart = Utilities.getWordStart(jTextPane, offset);
                  rowEnd = Utilities.getWordEnd(jTextPane, offset);
                  String word = jTextPane.getText().substring(rowStart, rowEnd);

                  tabPanel.onSelectedTypeClassFromMouseClick(word);
                }
              }
            } catch (BadLocationException e1) {
              e1.printStackTrace();
            }
          }

          public String getClassNameFromImportStatement(String selectedLine) {
            final String IMPORT = "import ";
            int start = selectedLine.indexOf(IMPORT) + IMPORT.length();
            String result = selectedLine.trim().substring(start, selectedLine.indexOf(";"));
            return result;
          }
        });

    displaySharkey();
  }
Ejemplo n.º 12
0
  private void show(int _current) {
    OpenDefinitionsDocument doc = _docs.get(_current);

    String text = getTextFor(doc);

    _label.setText(_displayManager.getName(doc));
    _label.setIcon(_displayManager.getIcon(doc));

    if (text.length() > 0) {
      // as wide as the text area wants, but only 200px high
      _textpane.setText(text);
      _scroller.setPreferredSize(_textpane.getPreferredScrollableViewportSize());
      if (_scroller.getPreferredSize().getHeight() > 200)
        _scroller.setPreferredSize(
            new Dimension((int) _scroller.getPreferredSize().getWidth(), 200));

      _scroller.setVisible(_showSource);
    } else _scroller.setVisible(false);

    Dimension d = _label.getMinimumSize();
    d.setSize(d.getWidth() + _padding * 2, d.getHeight() + _padding * 2);
    _label.setPreferredSize(d);
    _label.setHorizontalAlignment(SwingConstants.CENTER);
    _label.setVerticalAlignment(SwingConstants.CENTER);
    pack();
    centerH();
  }
  public SurrenderUI() {
    setType(Type.UTILITY);

    ExitB = new JButton("Exit");
    ExitB.setFont(new Font("Tahoma", Font.BOLD, 12));
    ExitB.setBackground(new Color(255, 215, 0));
    ExitB.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            dispose();
            new HSmain();
          }
        });
    ExitB.setBounds(461, 427, 296, 60);

    setTitle("Surrendering a Pet");
    Container pane = getContentPane();
    getContentPane().setLayout(null);
    pane.add(ExitB);

    txtSurrender = new JTextField();
    txtSurrender.setEditable(false);
    txtSurrender.setForeground(new Color(0, 0, 0));
    txtSurrender.setBackground(new Color(255, 215, 0));
    txtSurrender.setBounds(10, 11, 764, 50);
    txtSurrender.setHorizontalAlignment(SwingConstants.CENTER);
    txtSurrender.setFont(new Font("Lucida Handwriting", Font.BOLD, 18));
    txtSurrender.setText("Surrendering a Pet");
    getContentPane().add(txtSurrender);
    txtSurrender.setColumns(10);

    BackB = new JButton("Back");
    BackB.setFont(new Font("Tahoma", Font.BOLD, 12));
    BackB.setBackground(new Color(255, 215, 0));
    BackB.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            new AnimalServiceUI();
            dispose();
          }
        });
    BackB.setBounds(26, 427, 320, 60);
    getContentPane().add(BackB);

    scrollPane = new JScrollPane();
    scrollPane.setBounds(0, 72, 764, 329);
    getContentPane().add(scrollPane);

    JTextPane txtSurrenderInfo = new JTextPane();
    scrollPane.setViewportView(txtSurrenderInfo);
    txtSurrenderInfo.setForeground(new Color(0, 0, 0));
    txtSurrenderInfo.setEditable(false);
    txtSurrenderInfo.setFont(new Font("Times New Roman", Font.BOLD, 15));
    txtSurrenderInfo.setText(
        "\tThe Humane Society of Lamar cannot accept every animal brought to our shelter immediately. \r\nWe respect the difficult decision of owners to relinquish their pets, and the hard choices of those \r\ngood citizens who are trying to help a stray. We accept the surrender of pets as space allows. \r\nWe maintain a waiting list for all animals needing to be admitted to the shelter.\r\nAnimals are surrendered to our facility by appointment.\r\nWe admit at least 12 animals per week. We accept more animals as adoptions and space allow.\r\nNote that we cannot accept aggressive, sick or pregnant animals.\r\nPlease call 409-225-7981, and one of our adoption specialists will speak to you.\r\nAt times our waiting list will have up to 100 animals waiting for admission and it can take several weeks \r\nbefore we can admit your pet.\r\nPlease understand that our primary goal is to place as many animals in forever homes as possible, \r\ntherefore we must give every pet admitted to the shelter enough time to find a loving home. \r\nWe cannot guarantee placement of every animal admitted to the shelter.\r\n\t\r\n\tAdmission of any animal into the Humane Society of Lamar  is based on the animal\u2019s health, \r\nbehavior, and adoptability. When you bring your pets, please have:\r\n\r\n    *Any veterinary records\r\n    *Your pet\u2019s medications\r\n    *Special food or treats that your pet needs\r\n    *Your pet\u2019s bed, toys, leash and other belongings from home\r\n\r\nA staff member will evaluate the temperament of your pet. Once your pet has been screened, \r\nand the Humane Society of Lamar decides to accept your pet, we ask a donation to our shelter to be made. \r\nThis is not required, but will greatly help us care for your pet.");

    setSize(800, 553);
    setVisible(true);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
  }
Ejemplo n.º 14
0
  @Override
  public synchronized void run() {
    try {
      for (int i = 0; i < NUM_PIPES; i++) {
        while (Thread.currentThread() == reader[i]) {
          try {
            this.wait(100);
          } catch (InterruptedException ie) {
          }
          if (pin[i].available() != 0) {
            String input = this.readLine(pin[i]);
            appendMsg(htmlize(input));
            if (textArea.getDocument().getLength() > 0) {
              textArea.setCaretPosition(textArea.getDocument().getLength() - 1);
            }
          }
          if (quit) {
            return;
          }
        }
      }

    } catch (Exception e) {
      Debug.error(me + "Console reports an internal error:\n%s", e.getMessage());
    }
  }
Ejemplo n.º 15
0
  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();
  }
Ejemplo n.º 16
0
  /**
   * 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();
  }
Ejemplo n.º 17
0
  public EditorConsolePane() {
    super();
    textArea = new JTextPane();
    textArea.setEditorKit(new HTMLEditorKit());
    textArea.setTransferHandler(new JTextPaneHTMLTransferHandler());
    String css = PreferencesUser.getInstance().getConsoleCSS();
    ((HTMLEditorKit) textArea.getEditorKit()).getStyleSheet().addRule(css);
    textArea.setEditable(false);

    setLayout(new BorderLayout());
    add(new JScrollPane(textArea), BorderLayout.CENTER);

    if (ENABLE_IO_REDIRECT) {
      Debug.log(3, "EditorConsolePane: starting redirection to message area");
      int npipes = 2;
      NUM_PIPES = npipes * ScriptRunner.scriptRunner.size();
      pin = new PipedInputStream[NUM_PIPES];
      reader = new Thread[NUM_PIPES];
      for (int i = 0; i < NUM_PIPES; i++) {
        pin[i] = new PipedInputStream();
      }

      int irunner = 0;
      for (IScriptRunner srunner : ScriptRunner.scriptRunner.values()) {
        Debug.log(3, "EditorConsolePane: redirection for %s", srunner.getName());
        if (srunner.doSomethingSpecial(
            "redirect", Arrays.copyOfRange(pin, irunner * npipes, irunner * npipes + 2))) {
          Debug.log(3, "EditorConsolePane: redirection success for %s", srunner.getName());
          quit = false; // signals the Threads that they should exit
          // TODO Hack to avoid repeated redirect of stdout/err
          ScriptRunner.systemRedirected = true;

          // Starting two seperate threads to read from the PipedInputStreams
          for (int i = irunner * npipes; i < irunner * npipes + npipes; i++) {
            reader[i] = new Thread(this);
            reader[i].setDaemon(true);
            reader[i].start();
          }
          irunner++;
        }
      }
    }

    // Create the popup menu.
    popup = new JPopupMenu();
    JMenuItem menuItem = new JMenuItem("Clear messages");
    // Add ActionListener that clears the textArea
    menuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            textArea.setText("");
          }
        });
    popup.add(menuItem);

    // Add listener to components that can bring up popup menus.
    MouseListener popupListener = new PopupListener(popup);
    textArea.addMouseListener(popupListener);
  }
Ejemplo n.º 18
0
 /**
  * Displays the string representation of the maze.
  *
  * @param mz String representing the maze.
  */
 public void displayMaze(String mz) {
   SimpleAttributeSet attr = new SimpleAttributeSet();
   StyleConstants.setLineSpacing(attr, -0.3f);
   mazeOutLabel.setParagraphAttributes(attr, false);
   mazeOutLabel.setText(mz);
   imagePanel.add(mazeOutLabel);
   pack();
 }
 private void addText(String str, String styleName, JTextPane pane) {
   Document doc = pane.getDocument();
   int len = doc.getLength();
   try {
     doc.insertString(len, str, pane.getStyle(styleName));
   } catch (javax.swing.text.BadLocationException e) {
   }
 }
Ejemplo n.º 20
0
 private void initFields(Student student) {
   if (student != null) {
     txtFaculty.setText(student.getGroup().getFaculty());
     txtNOG.setText(String.valueOf(student.getGroup().getNumberOfGroup()));
     txtName.setText(student.getNameOfStudent());
     txtDOE.setText(student.getDateOfEnrollment());
   }
 }
Ejemplo n.º 21
0
 private void appendMsg(String msg) {
   HTMLDocument doc = (HTMLDocument) textArea.getDocument();
   HTMLEditorKit kit = (HTMLEditorKit) textArea.getEditorKit();
   try {
     kit.insertHTML(doc, doc.getLength(), msg, 0, 0, null);
   } catch (Exception e) {
     Debug.error(me + "Problem appending text to message area!\n%s", e.getMessage());
   }
 }
Ejemplo n.º 22
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);
        }
      }
    }
  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);
  }
Ejemplo n.º 24
0
  public void appendToPane(String msg, Color c) {
    if (inputText.isEnabled()) {
      StyleContext sc = StyleContext.getDefaultStyleContext();
      AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c);

      textArea.setCharacterAttributes(aset, false);
      textArea.replaceSelection(msg);
      textArea.setCaretPosition(textArea.getDocument().getLength());
    }
  }
Ejemplo n.º 25
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) {
         }
       });
 }
Ejemplo n.º 26
0
  public LoginView() {

    // set head label Maybe it can be updated with a logo style image later.
    loginViewHeadLabel.setFont(new Font("arial", Font.BOLD, 18));
    loginViewHeadLabel.setForeground(new Color(143, 51, 32));
    loginViewHeadLabel.setText("E-COMMERCE for SME v0.01");
    // setting header jtextpane for information.
    loginViewTextPane.setFont(new Font("arial", Font.BOLD, 14));
    loginViewTextPane.setForeground(Color.RED);
    loginViewTextPane.setText("Kullanıcı adı ve parolanızı giriniz.");
  }
Ejemplo n.º 27
0
 public void createStudent(RemoteController control) {
   try {
     control.createStudent(
         txtName.getText(),
         Integer.parseInt(txtNOG.getText()),
         txtFaculty.getText(),
         txtDOE.getText());
   } catch (Exception iae) {
     JOptionPane.showMessageDialog(
         null, iae.getMessage(), "Inane error", JOptionPane.ERROR_MESSAGE);
   }
 }
Ejemplo n.º 28
0
  public static void appendToPane(JTextPane tp, String msg, Color c) {
    StyleContext sc = StyleContext.getDefaultStyleContext();
    AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c);

    aset = sc.addAttribute(aset, StyleConstants.FontFamily, "Lucida Console");
    aset = sc.addAttribute(aset, StyleConstants.Alignment, StyleConstants.ALIGN_JUSTIFIED);

    int len = tp.getDocument().getLength();
    tp.setCaretPosition(len);
    tp.setCharacterAttributes(aset, false);
    tp.replaceSelection(msg);
  }
Ejemplo n.º 29
0
 /**
  * Add the provided text with the provided color to the GUI document
  *
  * @param text The text that will be added
  * @param color The color used to show the text
  */
 public void print(String text, Color color) {
   StyleContext sc = StyleContext.getDefaultStyleContext();
   AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, color);
   int len = logPane.getDocument().getLength();
   try {
     logPane.setCaretPosition(len);
     logPane.getDocument().insertString(len, text + "\n", aset);
   } catch (BadLocationException e) {
     LoggerFactory.getLogger(ProcessUIPanel.class).error("Cannot show the log message", e);
   }
   logPane.setCaretPosition(logPane.getDocument().getLength());
 }
Ejemplo n.º 30
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;
  }