use of javax.swing.text.Highlighter.Highlight in project CoreNLP by stanfordnlp.
the class HighlightUtils method isInHighlight.
/**
* Returns true if the given mouse event occurred within a highlight h on label.
*/
public static boolean isInHighlight(MouseEvent e, JTextField label, Highlighter h) {
Highlight[] hls = h.getHighlights();
if (hls == null || hls.length == 0)
return false;
Highlight hl = hls[0];
FontMetrics fm = label.getFontMetrics(label.getFont());
int offset = getCharOffset(fm, label.getText(), e.getX());
return hl.getStartOffset() <= offset && offset < hl.getEndOffset();
}
use of javax.swing.text.Highlighter.Highlight in project zaproxy by zaproxy.
the class CustomScanDialog method getAddCustomButton.
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
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;
}
use of javax.swing.text.Highlighter.Highlight in project zaproxy by zaproxy.
the class CustomScanDialog method getInjectionPointList.
private JList<Highlight> getInjectionPointList() {
if (injectionPointList == null) {
injectionPointList = new JList<>(injectionPointModel);
injectionPointList.setCellRenderer(new ListCellRenderer<Highlight>() {
@Override
public Component getListCellRendererComponent(JList<? extends Highlight> list, Highlight hlt, int index, boolean isSelected, boolean cellHasFocus) {
String str = "";
try {
str = getRequestField().getText(hlt.getStartOffset(), hlt.getEndOffset() - hlt.getStartOffset());
if (str.length() > 8) {
// just show first 8 chrs (arbitrary limit;)
str = str.substring(0, 8) + "..";
}
} catch (BadLocationException e) {
// Ignore
}
return new JLabel("[" + hlt.getStartOffset() + "," + hlt.getEndOffset() + "]: " + str);
}
});
}
return injectionPointList;
}
use of javax.swing.text.Highlighter.Highlight in project zaproxy by zaproxy.
the class CustomScanDialog method save.
/**
* Use the save method to launch a scan
*/
@Override
public void save() {
List<Object> contextSpecificObjects = new ArrayList<Object>();
if (!this.getBoolValue(FIELD_ADVANCED)) {
contextSpecificObjects.add(scanPolicy);
} else {
contextSpecificObjects.add(policyPanel.getScanPolicy());
if (target == null && this.customPanels != null) {
// One of the custom scan panels must have specified a target
for (CustomScanPanel customPanel : this.customPanels) {
target = customPanel.getTarget();
if (target != null) {
break;
}
}
}
// Save all Variant configurations
getVariantPanel().saveParam(scannerParam);
// force all injectable params and rpc model to NULL
if (getDisableNonCustomVectors().isSelected()) {
scannerParam.setTargetParamsInjectable(0);
scannerParam.setTargetParamsEnabledRPC(0);
}
if (!getBoolValue(FIELD_RECURSE) && injectionPointModel.getSize() > 0) {
int[][] injPoints = new int[injectionPointModel.getSize()][];
for (int i = 0; i < injectionPointModel.getSize(); i++) {
Highlight hl = injectionPointModel.elementAt(i);
injPoints[i] = new int[2];
injPoints[i][0] = hl.getStartOffset();
injPoints[i][1] = hl.getEndOffset();
}
try {
if (target != null && target.getStartNode() != null) {
VariantUserDefined.setInjectionPoints(this.target.getStartNode().getHistoryReference().getURI().toString(), injPoints);
enableUserDefinedRPC();
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
scannerParam.setHostPerScan(extension.getScannerParam().getHostPerScan());
scannerParam.setThreadPerHost(extension.getScannerParam().getThreadPerHost());
scannerParam.setHandleAntiCSRFTokens(extension.getScannerParam().getHandleAntiCSRFTokens());
scannerParam.setMaxResultsToList(extension.getScannerParam().getMaxResultsToList());
contextSpecificObjects.add(scannerParam);
contextSpecificObjects.add(getTechTree().getTechSet());
if (this.customPanels != null) {
for (CustomScanPanel customPanel : this.customPanels) {
Object[] objs = customPanel.getContextSpecificObjects();
if (objs != null) {
for (Object obj : objs) {
contextSpecificObjects.add(obj);
}
}
}
}
}
target.setRecurse(this.getBoolValue(FIELD_RECURSE));
if (target.getContext() == null && getSelectedContext() != null) {
target.setContext(getSelectedContext());
}
this.extension.startScan(target, getSelectedUser(), contextSpecificObjects.toArray());
}
use of javax.swing.text.Highlighter.Highlight in project zaproxy by zaproxy.
the class CustomScanDialog method getRemoveCustomButton.
private JButton getRemoveCustomButton() {
if (removeCustomButton == null) {
removeCustomButton = new JButton(Constant.messages.getString("ascan.custom.button.pt.rem"));
removeCustomButton.setEnabled(false);
removeCustomButton.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
// Remove any selected injection points
int userDefStart = getRequestField().getSelectionStart();
if (userDefStart >= 0) {
int userDefEnd = getRequestField().getSelectionEnd();
Highlighter hltr = getRequestField().getHighlighter();
Highlight[] hls = hltr.getHighlights();
if (hls != null && hls.length > 0) {
for (Highlight hl : hls) {
if (selectionIncludesHighlight(userDefStart, userDefEnd, hl)) {
hltr.removeHighlight(hl);
injectionPointModel.removeElement(hl);
}
}
}
// Unselect the text
getRequestField().setSelectionStart(userDefEnd);
getRequestField().setSelectionEnd(userDefEnd);
getRequestField().getCaret().setVisible(true);
}
}
});
}
return removeCustomButton;
}
Aggregations