use of net.sf.sdedit.util.Pair in project abstools by abstools.
the class DiagramLoader method load.
/**
* Loads a diagram from the text transmitted through the given
* <tt>stream</tt>. If the text contains a line that starts with
* <tt><?xml</tt>, it is interpreted as an XML file, containing the
* diagram source as a CDATA section along with a configuration. Otherwise
* the whole of the text is interpreted as a diagram source, and a default
* configuration is used.
*
* @param stream
* the stream from where the diagram specification is read
* @param encoding
* the encoding of the diagram specification
* @return a pair of the diagram source and the configuration to be used for
* generating the diagram
*
* @throws IOException
* @throws DocUtil.XMLException
*/
public static Pair<String, Bean<Configuration>> load(InputStream stream, String encoding) throws IOException, DocUtil.XMLException {
InputStreamReader reader = new InputStreamReader(stream, encoding);
BufferedReader buffered = new BufferedReader(reader);
StringWriter stringWriter = new StringWriter();
PrintWriter writer = new PrintWriter(stringWriter);
boolean xml = false;
String line = buffered.readLine();
while (line != null) {
xml |= line.trim().startsWith("<?xml");
writer.println(line);
line = buffered.readLine();
}
writer.close();
String source;
Bean<Configuration> configuration = ConfigurationManager.createNewDefaultConfiguration();
if (xml) {
InputStream inputStream = new ByteArrayInputStream(stringWriter.toString().getBytes(encoding));
try {
Document document = DocUtil.readDocument(inputStream, encoding);
source = DocUtil.evaluateCDATA(document, "/diagram/source");
Element confElement = (Element) DocUtil.evalXPathAsNode(document, "/diagram/configuration");
BeanConverter converter = new BeanConverter(configuration, document);
converter.setValues(confElement);
} finally {
inputStream.close();
}
} else {
source = stringWriter.toString();
}
return new Pair<String, Bean<Configuration>>(source, configuration);
}
use of net.sf.sdedit.util.Pair 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.util.Pair in project abstools by abstools.
the class TextHandler method getEventAssociation.
/**
* If the current line specifies an association of a note to the current
* vertical position of a lifeline, this method returns a pair consisting of
* the lifeline and the note number.
*
* @return a pair of a lifeline and a note number, if the current line
* specifies and association between the note and the lifeline,
* otherwise <tt>null</tt>
*/
public Pair<Lifeline, Integer> getEventAssociation() 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("\\((\\d+)\\)\\s*(\\w+)", currentLine);
if (parts == null) {
return null;
}
int number = Integer.parseInt(parts[0]);
String obj = parts[1];
Lifeline line = diagram.getLifeline(obj);
if (line == null) {
throw new SyntaxError(this, obj + " does not exist");
}
return new Pair<Lifeline, Integer>(line, number);
}
Aggregations