use of net.sf.sdedit.drawable.Note in project abstools by abstools.
the class Editor method mouseClickedDrawable.
// TODO move this to the GUI side (use diagram reference of paint device)
/**
* Moves the cursor to the position in the text area where the object or
* message corresponding to the drawable instance is declared.
*
* @param drawable
* a drawable instance to show the corresponding declaration for
*/
public void mouseClickedDrawable(Drawable drawable) {
Diagram diag = ui.getDiagram();
if (diag != null) {
Integer pos = (Integer) diag.getStateForDrawable(drawable);
if (pos != null) {
ui.moveCursorToPosition(pos - 1);
}
}
if (drawable instanceof Note) {
Note note = (Note) drawable;
URI link = note.getLink();
if (link != null) {
File current = ui.getCurrentFile();
File linked;
if (current != null) {
linked = new File(current.toURI().resolve(link));
} else {
linked = new File(link);
}
if (!ui.selectTabWith(linked)) {
try {
loadCode(linked);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
ui.errorMessage(linked.getAbsolutePath() + "\n" + "could not be loaded due to an exception of\n" + "type " + e.getClass().getSimpleName() + " with the message\n" + e.getMessage());
}
}
}
}
}
use of net.sf.sdedit.drawable.Note in project abstools by abstools.
the class NoteManager method closeNote.
/**
* @param lifeline
* the name of a lifeline that may have a non-consuming note box
* associated to it
*/
void closeNote(String lifeline) {
Note note = pendingNotes.get(lifeline);
if (note != null) {
int diff = note.getTop() + note.getHeight() - diagram.getVerticalPosition();
if (diff > 0) {
diagram.extendLifelines(diff);
}
pendingNotes.remove(lifeline);
}
}
use of net.sf.sdedit.drawable.Note in project abstools by abstools.
the class NoteManager method computeArrowAssociations.
public void computeArrowAssociations() {
for (Note description : notes) {
List<Message> msgs = messageAssociation.get(description.getNumber());
if (msgs != null) {
for (Message msg : msgs) {
// note to this.
if (msg.getArrow() != null) {
description.addTarget(msg.getArrow().getAnchor());
}
}
}
List<Pair<Lifeline, Integer>> pairs = eventAssociation.get(description.getNumber());
if (pairs != null) {
for (Pair<Lifeline, Integer> pair : pairs) {
int x = pair.getFirst().getView().getLeft() + pair.getFirst().getView().getWidth() / 2;
Point p = new Point(x, pair.getSecond());
description.addTarget(p);
}
}
}
}
use of net.sf.sdedit.drawable.Note in project abstools by abstools.
the class NoteManager method step.
public boolean step() throws SyntaxError {
Note note = diagram.getDataProvider().getNote();
if (note != null) {
freeNoteNumber = Math.max(freeNoteNumber, note.getNumber() + 1);
diagram.getPaintDevice().addSequenceElement(note);
notes.add(note);
closeNote(note.getLocation().getName());
diagram.getFragmentManager().openFragments();
diagram.getPaintDevice().announce(note.getHeight());
note.setTop(diagram.getVerticalPosition());
if (note.isConsuming()) {
diagram.extendLifelines(note.getHeight());
} else {
pendingNotes.put(note.getLocation().getName(), note);
}
if (diagram.getDataProvider().getState() != null) {
diagram.addToStateMap(note, diagram.getDataProvider().getState());
}
diagram.getFragmentManager().clearLabels();
return true;
}
Pair<Lifeline, Integer> eventAssoc = diagram.getDataProvider().getEventAssociation();
if (eventAssoc != null) {
associateEvent(eventAssoc.getFirst(), eventAssoc.getSecond());
return true;
}
return false;
}
use of net.sf.sdedit.drawable.Note in project abstools by abstools.
the class TextHandler method getNote.
/**
* If there is a note specified at the current line and the subsequent
* lines, a {@linkplain Note} representation is returned, otherwise
* <tt>null</tt>
*
* @return a note, if one is specified at the current position in text,
* otherwise <tt>null</tt>
*/
public Note getNote() throws SyntaxError {
if (section == 0) {
throw new IllegalStateException("not all objects have been read");
}
if (currentLine == null) {
throw new IllegalStateException("nothing to read");
}
String[] parts = Grep.parse("\\s*(\\*|\\+)(\\d+)\\s*(.+)", currentLine);
if (parts == null) {
return null;
}
boolean consuming = parts[0].equals("+");
int number = -1;
try {
number = Integer.parseInt(parts[1]);
} catch (NumberFormatException nfe) {
/* empty */
}
if (number < 0) {
throw new SyntaxError(this, "bad note number: " + parts[1]);
}
String obj = parts[2];
Lifeline line = diagram.getLifeline(obj);
if (line == null) {
throw new SyntaxError(this, obj + " does not exist");
}
int oldBegin = lineBegin;
int oldEnd = lineEnd;
line = line.getRightmost();
List<String> desc = new LinkedList<String>();
boolean more;
do {
if (!advance(false)) {
lineBegin = oldBegin;
lineEnd = oldEnd;
throw new SyntaxError(this, "The note is not closed.");
}
more = !currentLine.trim().equals(parts[0] + parts[1]);
} while (more && desc.add(currentLine));
if (desc.size() == 0) {
lineBegin = oldBegin;
lineEnd = oldEnd;
throw new SyntaxError(this, "The note is empty.");
}
String[] noteText = desc.toArray(new String[0]);
URI link = null;
if (noteText.length == 1) {
String linkString = noteText[0].trim();
if (linkString.startsWith("link:")) {
try {
linkString = linkString.substring(5).trim();
link = new URI(linkString);
if (link.getPath() == null) {
throw new SyntaxError(this, "Empty path in URI: " + linkString);
}
noteText[0] = link.getPath();
} catch (URISyntaxException e) {
throw new SyntaxError(this, "Bad URI syntax: " + e.getMessage());
}
}
}
Note note = new Note(line, number, noteText, consuming);
note.setLink(link);
return note;
}
Aggregations