use of com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLineContent in project binnavi by google.
the class CCharKeyBehavior method updateLabelContent.
@Override
protected void updateLabelContent() {
if (m_wasUneditableSelection) {
m_caretX = getCaretEndPosX();
return;
}
final int x = getCaretEndPosX();
final int y = getCaretMouseReleasedY();
m_caretX = x;
if (isComment(x, y)) {
// Cursor is within an existing comment
m_caretX += 1;
final ZyLineContent lineContent = getLineContent(y);
final IZyEditableObject editableObject = lineContent.getLineFragmentObjectAt(x);
if ((editableObject == null) || editableObject.isCommentDelimiter()) {
return;
}
final int textCursor = x - editableObject.getStart();
final String text = lineContent.getText().substring(editableObject.getStart(), editableObject.getEnd());
final String chr = String.valueOf(getEvent().getKeyChar());
String changedText = String.format("%s%s%s", text.substring(0, textCursor), chr, text.substring(textCursor));
if (isComment(x, y)) {
changedText = getMultilineComment(y, changedText);
}
editableObject.update(changedText);
getLabelContent().getLineEditor().recreateLabelLines(getLabelContent(), editableObject.getPersistentModel());
} else if (isEditable(x, y)) {
throw new RuntimeException("Not implemented yet.");
} else {
// Underlying object is NOT editable
final ZyLineContent lineContent = getLineContent(y);
if ((x == lineContent.getText().length()) && (lineContent.getLineObject() != null)) {
// Create new behind line comment
lineContent.getLineObject().updateComment(Character.toString(getEvent().getKeyChar()), ECommentPlacement.BEHIND_LINE);
getLabelContent().getLineEditor().recreateLabelLines(getLabelContent(), lineContent.getLineObject().getPersistentModel());
m_caretX = getLineContent(y).getText().length();
}
}
}
use of com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLineContent in project binnavi by google.
the class CCharKeyBehavior method updateUndoHistory.
@Override
protected void updateUndoHistory() {
if (m_editableObject != null) {
// There was an editable object that has been changed
final int x = getCaretEndPosX();
final int y = getCaretMouseReleasedY();
final ZyLineContent lineContent = getLineContent(y);
final IZyEditableObject editableObject = lineContent.getLineFragmentObjectAt(x);
if (editableObject != null) {
String text = lineContent.getText().substring(editableObject.getStart(), editableObject.getEnd());
if (isComment(x, y)) {
text = getMultiLineComment(y);
}
udpateUndolist(getLabelContent(), lineContent.getLineObject().getPersistentModel(), editableObject, text, m_isAboveComment, m_isBehindComment, m_isLabelComment, getCaretStartPosX(), getCaretMousePressedX(), getCaretMousePressedY(), getCaretEndPosX(), getCaretMouseReleasedX(), getCaretMouseReleasedY());
}
}
}
use of com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLineContent in project binnavi by google.
the class CCharKeyBehavior method initUndoHistory.
@Override
protected void initUndoHistory() {
final int x = getCaretEndPosX();
final int y = getCaretMouseReleasedY();
final ZyLineContent lineContent = getLineContent(y);
IZyEditableObject editableObject = lineContent.getLineFragmentObjectAt(x);
m_isAboveComment = isAboveLineComment(y);
m_isBehindComment = isBehindLineComment(x, y);
m_isLabelComment = isLabelComment(y);
boolean isNewBehindLineComment = false;
if ((x == lineContent.getText().length()) && !isComment(x, y)) {
// a new behind line comment will be created
m_isBehindComment = true;
isNewBehindLineComment = true;
editableObject = lineContent.getLineObject();
}
m_editableObject = editableObject;
String text = "";
if (editableObject != null) {
if (!isNewBehindLineComment) {
text = lineContent.getText().substring(editableObject.getStart(), editableObject.getEnd());
if (isComment(x, y)) {
text = getMultiLineComment(y);
}
}
udpateUndolist(getLabelContent(), lineContent.getLineObject().getPersistentModel(), editableObject, text, m_isAboveComment, m_isBehindComment, m_isLabelComment, getCaretStartPosX(), getCaretMousePressedX(), getCaretMousePressedY(), getCaretEndPosX(), getCaretMouseReleasedX(), getCaretMouseReleasedY());
}
}
use of com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLineContent in project binnavi by google.
the class CCursorKeyBehavior method handleNotShiftAndCtrl.
protected void handleNotShiftAndCtrl(final int xdelta, final int ydelta) {
final ZyLabelContent labelContent = getLabelContent();
int caretStartPos_X = getCaretStartPosX();
int mousePressed_X = getCaretMousePressedX();
final int mousePressed_Y = getCaretMousePressedY();
int caretEndPos_X = getCaretEndPosX();
int mouseReleased_X = getCaretMouseReleasedX();
final int mouseReleased_Y = getCaretMouseReleasedY();
if (xdelta != 0) {
final ZyLineContent lineContent = labelContent.getLineContent(mouseReleased_Y);
final String s = lineContent.getText() + " ";
if (xdelta > 0) {
final boolean firstIsSpace = s.charAt(caretEndPos_X) == ' ';
int endindex = 0;
for (int i = caretEndPos_X; i < s.length(); ++i) {
endindex = i;
if (firstIsSpace) {
if (s.charAt(i) != ' ') {
break;
}
} else {
if (s.charAt(i) == ' ') {
break;
}
}
}
if ((lineContent.getText().endsWith("\n") || lineContent.getText().endsWith("\r")) && (lineContent.getText().length() == endindex)) {
endindex -= 1;
}
caretStartPos_X = endindex;
mousePressed_X = endindex;
mouseReleased_X = endindex;
caretEndPos_X = endindex;
} else if (xdelta < 0) {
if (caretEndPos_X == 0) {
return;
}
final boolean firstIsSpace = s.charAt(caretEndPos_X - 1) == ' ';
int startindex = caretEndPos_X - 1;
for (int i = caretEndPos_X - 1; i >= 0; --i) {
if (firstIsSpace) {
if (s.charAt(i) != ' ') {
break;
}
} else {
if (s.charAt(i) == ' ') {
break;
}
}
startindex = i;
}
caretStartPos_X = startindex;
mousePressed_X = startindex;
mouseReleased_X = startindex;
caretEndPos_X = startindex;
}
mouseReleased_X = correctMouseReleasedX(mouseReleased_X, mouseReleased_Y, mousePressed_Y);
setCaret(caretStartPos_X, mousePressed_X, mousePressed_Y, caretEndPos_X, mouseReleased_X, mouseReleased_Y);
} else if (ydelta != 0) {
handleNotShiftAndNotCtrl(0, ydelta);
}
}
use of com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLineContent in project binnavi by google.
the class ClipboardCopier method copyToClipboard.
/**
* Copies the text content of a node to the clip board.
*
* @param node The node to copy to the clip board.
*/
public static void copyToClipboard(final ZyGraphNode<?> node) {
Preconditions.checkNotNull(node, "Error: Node argument can not be null");
final IZyNodeRealizer realizer = node.getRealizer();
final ZyLabelContent content = realizer.getNodeContent();
if (content.isSelectable()) {
final ZyLabelContent zyContent = content;
final StringBuilder textBuilder = new StringBuilder();
for (final ZyLineContent zyLineContent : zyContent) {
textBuilder.append(zyLineContent.getText());
//$NON-NLS-1$
textBuilder.append("\n");
}
ClipboardHelpers.copyToClipboard(textBuilder.toString());
}
}
Aggregations