コード例 #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());
  }
コード例 #2
2
ファイル: TextSnippet.java プロジェクト: kion/Bias
  /**
   * This method initializes jTextPane
   *
   * @return javax.swing.JTextPane
   */
  private JTextPane getJTextPane() {
    if (jTextPane == null) {
      jTextPane = new JTextPane();
      jTextPane.setEditorKit(new HTMLEditorKit());
      HTMLDocument doc =
          new HTMLDocument() {
            private static final long serialVersionUID = 1L;

            @Override
            public Font getFont(AttributeSet attr) {
              Object family = attr.getAttribute(StyleConstants.FontFamily);
              Object size = attr.getAttribute(StyleConstants.FontSize);
              if (family == null && size == null) {
                return new Font("SansSerif", Font.PLAIN, currentFontSize);
              }
              return super.getFont(attr);
            }
          };
      doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
      doc.setPreservesUnknownTags(false);
      jTextPane.setStyledDocument(doc);
      jTextPane.setEditable(false);
    }
    return jTextPane;
  }
コード例 #3
1
ファイル: RMSDFrame.java プロジェクト: joey0214/PhyStruComp
 protected void insertText(String textString, AttributeSet set) {
   try {
     content.getDocument().insertString(content.getDocument().getLength(), textString, set);
   } catch (BadLocationException e) {
     e.printStackTrace();
   }
 }
コード例 #4
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);
  }
コード例 #5
0
ファイル: History.java プロジェクト: subirsarkar/swdev-cdf
  /** Test the utility in a standalone mode */
  public static void main(String[] argv) {
    JTextPane textPane;
    JFrame f = new JFrame();
    Container content = f.getContentPane();
    content.add(new JScrollPane(textPane = new JTextPane()));

    History history = History.Instance();
    history.setEndSelection(textPane);
    history.addText(textPane, "Hello world");
    history.addText(textPane, "Hello world", true);
    history.addText(textPane, "Hello world\n", "Times", "Bold", 10, Color.red);
    history.addText(
        textPane, "Hello world\n", "Times", "Italic", 10, Color.green, Color.yellow, 0, true);
    history.addText(textPane, "Hello world\n", "Times", "Underline", 10, Color.blue);
    history.setEndSelection(textPane);
    history.addLabel(textPane, "Hello world\n", AppConstants.iconDir + "/file_open.gif");
    try {
      history.addIcon(textPane, AppConstants.iconDir + "/file_open.gif");
    } catch (Exception e) {
      System.out.println(e);
    }
    textPane.setEditable(false);
    f.setSize(600, 300);
    f.setVisible(true);
  }
コード例 #6
0
ファイル: InterpreterFrame.java プロジェクト: DavePearce/jkit
 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;
   }
 }
コード例 #7
0
ファイル: DecisionAnalyzer.java プロジェクト: CaoAo/BeehiveZ
  /**
   * Creates an evaluation overview of the built classifier.
   *
   * @return the panel to be displayed as result evaluation view for the current decision point
   */
  protected JPanel createEvaluationVisualization(Instances data) {
    // build text field to display evaluation statistics
    JTextPane statistic = new JTextPane();

    try {
      // build evaluation statistics
      Evaluation evaluation = new Evaluation(data);
      evaluation.evaluateModel(myClassifier, data);
      statistic.setText(
          evaluation.toSummaryString()
              + "\n\n"
              + evaluation.toClassDetailsString()
              + "\n\n"
              + evaluation.toMatrixString());

    } catch (Exception ex) {
      ex.printStackTrace();
      return createMessagePanel("Error while creating the decision tree evaluation view");
    }

    statistic.setFont(new Font("Courier", Font.PLAIN, 14));
    statistic.setEditable(false);
    statistic.setCaretPosition(0);

    JPanel resultViewPanel = new JPanel();
    resultViewPanel.setLayout(new BoxLayout(resultViewPanel, BoxLayout.PAGE_AXIS));
    resultViewPanel.add(new JScrollPane(statistic));

    return resultViewPanel;
  }
コード例 #8
0
ファイル: TerminalWindow.java プロジェクト: nvenky/f3270
 private JTextPane createTextPane(final Font font, final Color color) {
   final JTextPane textPane = new JTextPane();
   textPane.setFont(font);
   textPane.setBackground(color);
   textPane.setEditable(false);
   return textPane;
 }
コード例 #9
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();
  }
コード例 #10
0
  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();
  }
コード例 #11
0
  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");
  }
コード例 #12
0
  /**
   * @param logs
   * @param firstOrg
   * @param secondOrg
   * @return
   */
  private ProMSplitPane additionalDependencyPanelCreator(
      OrganizationalLogs logs, int firstOrg, int secondOrg) {
    ProMSplitPane splitPanelRefinedActivity = new ProMSplitPane();
    splitPanelRefinedActivity.setBackground(null);

    ProMTable comp = additionalDependencyTableCreator(logs, firstOrg, secondOrg);
    if (comp == null) return null;

    JTextPane textField = new JTextPane();
    textField.setContentType("text/html");
    textField.setText(
        fontBlack6
            + "Additional Dependencies ("
            + comp.getTable().getRowCount()
            + ")</font><hr>"
            + fontBlack4
            + " This pattern is a special case of different dependencies where one set of activities includes the other and results with additional dependencies. In the list you can see additional dependency sets in two organizations as "
            + logs.organizationNames.get(firstOrg)
            + "(Selected) and "
            + logs.organizationNames.get(secondOrg)
            + "(Other).");
    textField.setEditable(false);
    textField.setBackground(new Color(192, 192, 192));
    JScrollPane scrollPane = new JScrollPane(textField);
    scrollPane.setPreferredSize(new Dimension(500, 0));

    splitPanelRefinedActivity.setLeftComponent(comp);
    splitPanelRefinedActivity.setRightComponent(scrollPane);
    return splitPanelRefinedActivity;
  }
コード例 #13
0
  /**
   * @param logs
   * @param firstOrg
   * @param secondOrg
   * @return
   */
  private ProMSplitPane differentConditionsPanelCreator(
      OrganizationalLogs logs, int firstOrg, int secondOrg) {
    ProMSplitPane splitPanelRefinedActivity = new ProMSplitPane();
    splitPanelRefinedActivity.setBackground(null);

    ProMTable comp = differentConditionsTableCreator(logs, firstOrg, secondOrg);
    if (comp == null) return null;

    JTextPane textField = new JTextPane();
    textField.setContentType("text/html");
    textField.setText(
        fontBlack6
            + "Different Conditions for Occurrence ("
            + comp.getTable().getRowCount()
            + ")</font><hr>"
            + fontBlack4
            + "Set of dependencies are same for two processes; however, occurrence condition is different in organizations. In the list you can see different occurrence conditions in two organizations as "
            + logs.organizationNames.get(firstOrg)
            + "(Selected) and "
            + logs.organizationNames.get(secondOrg)
            + "(Other).");
    textField.setEditable(false);
    textField.setBackground(new Color(192, 192, 192));
    JScrollPane scrollPane = new JScrollPane(textField);
    scrollPane.setPreferredSize(new Dimension(500, 0));

    splitPanelRefinedActivity.setLeftComponent(comp);
    splitPanelRefinedActivity.setRightComponent(scrollPane);
    return splitPanelRefinedActivity;
  }
コード例 #14
0
  /**
   * @param logs
   * @param firstOrg
   * @param secondOrg
   * @return
   */
  private ProMSplitPane refinedActivityPanelCreator(
      OrganizationalLogs logs, int firstOrg, int secondOrg) {
    ProMSplitPane splitPanelRefinedActivity = new ProMSplitPane();
    splitPanelRefinedActivity.setBackground(null);

    ProMTable comp = refinedActivityTableCreator(logs, firstOrg, secondOrg);
    if (comp == null) return null;

    JTextPane textField = new JTextPane();
    textField.setContentType("text/html");
    textField.setText(
        fontBlack6
            + "Refined Activities ("
            + comp.getTable().getRowCount()
            + ")</font><hr>"
            + fontBlack4
            + "An activity exists in one process but, as an equivalent, a collection of activitiesare existing in the other process to achieve the same task. In the list you can see the refined activity in "
            + logs.organizationNames.get(firstOrg)
            + " and a potential list of activities in "
            + logs.organizationNames.get(secondOrg)
            + ".");
    textField.setEditable(false);
    textField.setBackground(new Color(192, 192, 192));
    JScrollPane scrollPane = new JScrollPane(textField);
    scrollPane.setPreferredSize(new Dimension(500, 0));

    splitPanelRefinedActivity.setLeftComponent(comp);
    splitPanelRefinedActivity.setRightComponent(scrollPane);
    return splitPanelRefinedActivity;
  }
コード例 #15
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);
    }
  }
コード例 #16
0
  public ChatPane createChatPane(String userName) {
    JTextPane chatPane = new JTextPane();
    chatPane.setEditable(false);
    Font font = chatPane.getFont();
    float size = Main.pref.getInteger("geochat.fontsize", -1);
    if (size < 6) size += font.getSize2D();
    chatPane.setFont(font.deriveFont(size));
    //        DefaultCaret caret = (DefaultCaret)chatPane.getCaret(); // does not work
    //        caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
    JScrollPane scrollPane =
        new JScrollPane(
            chatPane,
            JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    chatPane.addMouseListener(new GeoChatPopupAdapter(panel));

    ChatPane entry = new ChatPane();
    entry.pane = chatPane;
    entry.component = scrollPane;
    entry.notify = 0;
    entry.userName = userName;
    entry.isPublic = userName == null;
    chatPanes.put(userName == null ? PUBLIC_PANE : userName, entry);

    tabs.addTab(null, scrollPane);
    tabs.setTabComponentAt(tabs.getTabCount() - 1, new ChatTabTitleComponent(entry));
    tabs.setSelectedComponent(scrollPane);
    return entry;
  }
コード例 #17
0
  private void init() {
    setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
    setOpaque(false);

    JLabel label = new JLabel("Text");
    label.setAlignmentX(Component.CENTER_ALIGNMENT);
    label.setBorder(BorderFactory.createEmptyBorder(10, 0, 10, 0));
    add(label);

    final JTextPane textPane = new JTextPane();
    JScrollPane scrollPane = new JScrollPane(textPane);
    scrollPane.setMaximumSize(new Dimension(250, 100));
    scrollPane.setPreferredSize(new Dimension(250, 100));
    scrollPane.setAlignmentX(Component.CENTER_ALIGNMENT);
    add(scrollPane);

    textPane.setText(customGraphics.getText());

    textPane.addFocusListener(
        new FocusAdapter() {
          @Override
          public void focusLost(FocusEvent e) {
            customGraphics.setText(textPane.getText());
          }
        });
  }
コード例 #18
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();
  }
コード例 #19
0
  /** @param singleFormatter */
  protected void fillWithObjFormatter(final DataObjDataFieldFormatIFace singleFormatter) {
    ignoreFmtChange = true;
    try {
      formatEditor.setText("");

      if (singleFormatter == null) {
        return;
      }

      Document doc = formatEditor.getDocument();
      DataObjDataField[] fields = singleFormatter.getFields();
      if (fields == null) {
        return;
      }

      for (DataObjDataField field : fields) {
        try {
          doc.insertString(doc.getLength(), field.getSep(), null);

          // System.err.println("["+field.getName()+"]["+field.getSep()+"]["+field.getFormat()+"]["+field.toString()+"]");
          insertFieldIntoTextEditor(new DataObjDataFieldWrapper(field));
        } catch (BadLocationException ble) {
        }
      }
    } finally {
      ignoreFmtChange = false;
    }
  }
コード例 #20
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());
    }
  }
コード例 #21
0
ファイル: RecentDocFrame.java プロジェクト: jjsahalf/drjava
  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();
  }
コード例 #22
0
ファイル: MessageInputPanel.java プロジェクト: huxi/whistler
    public void actionPerformed(ActionEvent ae) {
      updatePanel();

      Message message = messagePanel.getMessage();
      if (message != null) {
        JTextPane textPane = messagePanel.getTextPane();
        int pos = textPane.getCaretPosition();
        Message.Element element = message.findElement(pos);
        if (logger.isInfoEnabled()) logger.info("Complete element {}.", element);

        boolean showPopup = false;
        if (element.getType() == Message.Element.Type.HashTag) {
          populateHashTags(element);
          showPopup = true;
        } else if (element.getType() == Message.Element.Type.Recipient) {
          populateRecipients(element);
          showPopup = true;
        }
        if (showPopup) {
          try {
            Rectangle viewPos = textPane.modelToView(pos);
            int x = viewPos.x;
            int y = viewPos.y + viewPos.height;

            popup.show(textPane, x, y);
          } catch (BadLocationException e) {
            e
                .printStackTrace(); // To change body of catch statement use File | Settings | File
                                    // Templates.
          }
        }
      }
    }
コード例 #23
0
 public ScrollableTextPane(String text) {
   super();
   _textPane = new JTextPane();
   _textPane.setText(text);
   _textPane.setEditable(false);
   this.setViewportView(_textPane);
 }
コード例 #24
0
ファイル: DiffView.java プロジェクト: LeeKamentsky/imagej
  /** Create a colorized diff view. */
  public DiffView() {
    super(VERTICAL_SCROLLBAR_AS_NEEDED, HORIZONTAL_SCROLLBAR_AS_NEEDED);
    setPreferredSize(new Dimension(800, 600));
    panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
    getViewport().setView(panel);

    normal = getStyle(Color.black, false, false, font, fontSize);
    bigBold = getStyle(Color.blue, false, true, font, bigFontSize);
    bold = getStyle(Color.black, false, true, font, fontSize);
    italic = getStyle(Color.black, true, false, font, fontSize);
    red = getStyle(Color.red, false, false, font, fontSize);
    green = getStyle(new Color(0, 128, 32), false, false, font, fontSize);

    textPane = new JTextPane();
    normalCursor = textPane.getCursor();
    handCursor = new Cursor(Cursor.HAND_CURSOR);
    textPane.setEditable(false);
    document = textPane.getStyledDocument();
    panel.add(textPane);

    getVerticalScrollBar().setUnitIncrement(10);

    textPane.addMouseListener(
        new MouseAdapter() {
          public void mouseClicked(MouseEvent event) {
            ActionListener action = getAction(event);
            if (action != null) action.actionPerformed(new ActionEvent(DiffView.this, 0, "action"));
          }
        });
  }
コード例 #25
0
  public void toScreen(String s, Class module, String TYPE) {
    Color c = Color.BLACK;
    if (TYPE != null) {
      if (TYPE.contains("ERROR")) c = Color.RED;
      if (TYPE.contains("WARNING")) c = new Color(255, 106, 0);
      if (TYPE.contains("DEBUG")) c = Color.BLUE;
      if (module.toString().equalsIgnoreCase("Exception")) c = Color.RED;
    }
    StyleContext sc = StyleContext.getDefaultStyleContext();
    javax.swing.text.AttributeSet aset =
        sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c);
    int len = SCREEN.getDocument().getLength(); // same value as
    SCREEN.setCaretPosition(len); // place caret at the end (with no selection)
    SCREEN.setCharacterAttributes(aset, false);
    SCREEN.replaceSelection(
        "["
            + getData()
            + " - "
            + module.getSimpleName()
            + " - "
            + TYPE
            + "] "
            + s
            + "\n"); // there is no selection, so inserts at caret
    SCREEN.setFont(new Font("Monospaced", Font.PLAIN, 14));

    aggiungiRiga(s, module, TYPE);
  }
コード例 #26
0
ファイル: HtmlPanel.java プロジェクト: marayl/doogal
  private final void find(Pattern pattern) {
    final WriteOnce<Integer> once = new WriteOnce<Integer>();
    final Highlighter highlighter = textPane.getHighlighter();
    highlighter.removeAllHighlights();

    int matches = 0;

    final HTMLDocument doc = (HTMLDocument) textPane.getDocument();
    for (final HTMLDocument.Iterator it = doc.getIterator(HTML.Tag.CONTENT);
        it.isValid();
        it.next())
      try {
        final String fragment =
            doc.getText(it.getStartOffset(), it.getEndOffset() - it.getStartOffset());
        final Matcher matcher = pattern.matcher(fragment);
        while (matcher.find()) {
          highlighter.addHighlight(
              it.getStartOffset() + matcher.start(),
              it.getStartOffset() + matcher.end(),
              HIGHLIGHTER);
          once.set(it.getStartOffset());
          ++matches;
        }
      } catch (final BadLocationException ex) {
      }
    if (!once.isEmpty()) textPane.setCaretPosition(once.get());
    this.matches.setText(String.format("%d matches", matches));
  }
コード例 #27
0
ファイル: MainWindow.java プロジェクト: dentalht/AppChat
  /** Displays the Spark error log. */
  private void showErrorLog() {
    final File logDir = new File(Spark.getLogDirectory(), "errors.log");

    // Read file and show
    final String errorLogs = URLFileSystem.getContents(logDir);

    final JFrame frame = new JFrame(Res.getString("title.client.logs"));
    frame.setLayout(new BorderLayout());
    frame.setIconImage(SparkManager.getApplicationImage().getImage());

    final JTextPane pane = new JTextPane();
    pane.setBackground(Color.white);
    pane.setFont(new Font("Dialog", Font.PLAIN, 12));
    pane.setEditable(false);
    pane.setText(errorLogs);

    frame.add(new JScrollPane(pane), BorderLayout.CENTER);

    final JButton copyButton = new JButton(Res.getString("button.copy.to.clipboard"));
    frame.add(copyButton, BorderLayout.SOUTH);

    copyButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            SparkManager.setClipboard(errorLogs);
            copyButton.setEnabled(false);
          }
        });

    frame.pack();
    frame.setSize(600, 400);

    GraphicUtils.centerWindowOnScreen(frame);
    frame.setVisible(true);
  }
コード例 #28
0
ファイル: ProcessUIPanel.java プロジェクト: glandais/orbisgis
 /** 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());
   }
 }
コード例 #29
0
  private void initComponents() {
    accountCombo = new AccountListComboBox();

    helpPane = new JTextPane();
    helpPane.setEditable(false);
    helpPane.setEditorKit(new StyledEditorKit());
    helpPane.setBackground(getBackground());
    helpPane.setText(TextResource.getString("QifOne.txt"));

    /* Create the combo for date format selection */
    String[] formats = {QifUtils.US_FORMAT, QifUtils.EU_FORMAT};
    dateFormatCombo = new JComboBox<>(formats);

    dateFormatCombo.addActionListener(this);
    dateFormatCombo.setSelectedIndex(pref.getInt(DATE_FORMAT, 0));

    accountCombo.addActionListener(this);

    /* Try a set the combobox to the last selected account */
    String lastAccount = pref.get(LAST_ACCOUNT, "");

    Account last = EngineFactory.getEngine(EngineFactory.DEFAULT).getAccountByUuid(lastAccount);

    if (last != null) {
      setAccount(last);
    }
  }
コード例 #30
0
  private void setDataView(List<BlackboardArtifact> artifacts, int offset) {
    // change the cursor to "waiting cursor" for this operation
    this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

    if (artifacts.isEmpty()) {
      setComponentsVisibility(false);
      this.setCursor(null);
      outputViewPane.setText("");
      return;
    }
    this.artifacts = artifacts;
    StringContent artifactString = new ArtifactStringContent(artifacts.get(offset - 1));
    String text = artifactString.getString();

    int pages = artifacts.size();

    nextPageButton.setEnabled(offset < pages);
    prevPageButton.setEnabled(offset > 1);

    currentPage = offset;

    totalPageLabel.setText(Integer.toString(pages));
    currentPageLabel.setText(Integer.toString(currentPage));
    outputViewPane.setText(text);
    setComponentsVisibility(true);
    outputViewPane.moveCaretPosition(0);
    this.setCursor(null);
  }