List of usage examples for javax.swing.text Highlighter addHighlight
public Object addHighlight(int p0, int p1, HighlightPainter p) throws BadLocationException;
From source file:org.zaproxy.zap.extension.ascan.CustomScanDialog.java
private JButton getAddCustomButton() { if (addCustomButton == null) { addCustomButton = new JButton(Constant.messages.getString("ascan.custom.button.pt.add")); addCustomButton.setEnabled(false); addCustomButton.addActionListener(new java.awt.event.ActionListener() { @Override//from w ww . j ava 2 s . com public void actionPerformed(java.awt.event.ActionEvent e) { // Add the selected injection point int userDefStart = getRequestField().getSelectionStart(); if (userDefStart >= 0) { int userDefEnd = getRequestField().getSelectionEnd(); Highlighter hl = getRequestField().getHighlighter(); HighlightPainter painter = new DefaultHighlighter.DefaultHighlightPainter(Color.RED); try { Highlight hlt = (Highlight) hl.addHighlight(userDefStart, userDefEnd, painter); injectionPointModel.addElement(hlt); // Unselect the text getRequestField().setSelectionStart(userDefEnd); getRequestField().setSelectionEnd(userDefEnd); getRequestField().getCaret().setVisible(true); } catch (BadLocationException e1) { logger.error(e1.getMessage(), e1); } } } }); } return addCustomButton; }
From source file:org.zaproxy.zap.extension.customFire.CustomFireDialog.java
/** * /*from w w w.j a v a2s .co m*/ * @param highlightList * @param httpReq * @return JList<Highlight> * Request field-HTTPMsg is highlighted based on saved list of injection points and add them to new JList<Highlight> */ private JList<Highlight> getSavedInjectionPointList(ArrayList highlightList, String httpReq) { getRequestField().setText(httpReq); //If list instance is null then add elements from highlightList to list or remove everything from list and add from saved highlightList list.clear(); //Highlight the coords Highlighter highLighter = getRequestField().getHighlighter(); highLighter.removeAllHighlights(); HighlightPainter painter = new DefaultHighlighter.DefaultHighlightPainter(Color.RED); for (int i = 0; i < highlightList.size(); i++) { String s = highlightList.get(i).toString(); try { //Find co ords from string String[] s1 = s.split(","); int start = Integer.parseInt(s1[0].replaceAll("[\\D]", "")); int end = ((Number) NumberFormat.getInstance().parse(s1[1])).intValue(); headerLength = httpReq.trim().length(); urlPathStart = httpReq.indexOf("/", httpReq.indexOf("://") + 2) + 1; if (!(start < urlPathStart || (start < headerLength && end > headerLength))) { highLighter.addHighlight(start, end, painter); list.add(s); } } catch (BadLocationException | ParseException e) { e.printStackTrace(); } } Highlight[] hls = highLighter.getHighlights(); if (hls != null && hls.length > 0) { for (Highlight hl : hls) { injectionPointModel.addElement(hl); } } injectionPointList = new JList<>(injectionPointModel); ListCellRendererEx listCellrender = new ListCellRendererEx(getRequestField()); injectionPointList.setCellRenderer(listCellrender); return injectionPointList; }
From source file:org.zaproxy.zap.extension.customFire.CustomFireDialog.java
private JButton getAddCustomButton() { if (addCustomButton == null) { addCustomButton = new JButton(Constant.messages.getString("customFire.custom.button.pt.add")); addCustomButton.setEnabled(false); addCustomButton.addActionListener(new java.awt.event.ActionListener() { @Override/*www . jav a 2s . c o m*/ public void actionPerformed(java.awt.event.ActionEvent e) { // Add the selected injection point int userDefStart = getRequestField().getSelectionStart(); if (userDefStart >= 0) { int userDefEnd = getRequestField().getSelectionEnd(); Highlighter hl = getRequestField().getHighlighter(); HighlightPainter painter = new DefaultHighlighter.DefaultHighlightPainter(Color.RED); try { Highlight hlt = (Highlight) hl.addHighlight(userDefStart, userDefEnd, painter); list.add("[" + userDefStart + "," + userDefEnd + "]:" + getRequestField().getText(userDefStart, userDefEnd - userDefStart)); injectionPointModel.addElement(hlt); // Unselect the text getRequestField().setSelectionStart(userDefEnd); getRequestField().setSelectionEnd(userDefEnd); getRequestField().getCaret().setVisible(true); } catch (BadLocationException e1) { logger.error(e1.getMessage(), e1); } } } }); } return addCustomButton; }
From source file:org.zaproxy.zap.extension.httppanel.view.syntaxhighlight.HttpPanelSyntaxHighlightTextArea.java
private void highlightEntryParser(HighlightSearchEntry entry) { String text;//from w ww . j a va2s . c o m int lastPos = 0; text = this.getText(); Highlighter hilite = this.getHighlighter(); HighlightPainter painter = new DefaultHighlighter.DefaultHighlightPainter(entry.getColor()); while ((lastPos = text.indexOf(entry.getToken(), lastPos)) > -1) { try { hilite.addHighlight(lastPos, lastPos + entry.getToken().length(), painter); lastPos += entry.getToken().length(); } catch (BadLocationException e) { log.warn("Could not highlight entry", e); } } }
From source file:org.zaproxy.zap.extension.httppanel.view.syntaxhighlight.HttpPanelSyntaxHighlightTextArea.java
protected void highlight(int start, int end) { Highlighter hilite = this.getHighlighter(); HighlightPainter painter = new DefaultHighlighter.DefaultHighlightPainter(Color.LIGHT_GRAY); try {/*from ww w . j a v a2 s. co m*/ // DOBIN removeAllHighlights(); hilite.addHighlight(start, end, painter); this.setCaretPosition(start); } catch (BadLocationException e) { log.error(e.getMessage(), e); } }