Search in sources :

Example 1 with Configuration

use of net.sf.sdedit.config.Configuration in project abstools by abstools.

the class Editor method addActions.

private void addActions() {
    actions = new Actions(this);
    ui.addAction("&File", actions.newDiagramAction, null);
    ui.addAction("&File", actions.loadCodeAction, null);
    ui.addCategory("&File.Open &recent file", "open");
    ui.addAction("&File", actions.saveCodeAction, actions.regularTabActivator);
    ui.addAction("&File", actions.saveCodeAsAction, actions.regularTabActivator);
    Action exportAction = actions.getExportAction();
    if (exportAction != null) {
        ui.addAction("&File", exportAction, actions.nonEmptyDiagramActivator);
    } else {
        ui.addAction("&File", actions.saveImageAction, actions.nonEmptyDiagramActivator);
    }
    ui.addAction("&File", actions.closeDiagramAction, null);
    ui.addAction("&File", actions.closeAllAction, null);
    Action printPDFAction = actions.getPrintAction("pdf");
    if (printPDFAction != null) {
        ui.addAction("&File", printPDFAction, actions.noDiagramErrorActivator);
    }
    ui.addAction("&File", actions.quitAction, null);
    ConfigurationAction<Configuration> wrapAction = new ConfigurationAction<Configuration>("lineWrap", "[control shift W]&Wrap lines", "Wrap lines whose length exceed the width of the text area", "wrap") {

        @Override
        public Bean<Configuration> getBean() {
            return ui.getConfiguration();
        }
    };
    ConfigurationAction<Configuration> threadedAction = new ConfigurationAction<Configuration>("threaded", Shortcuts.getShortcut(Shortcuts.ENABLE_THREADS) + "Enable &multithreading", "Create diagrams with arbitrarily many sequences running concurrently", "threads") {

        @Override
        public Bean<Configuration> getBean() {
            return ui.getConfiguration();
        }
    };
    ConfigurationAction<GlobalConfiguration> autoUpdateAction = new ConfigurationAction<GlobalConfiguration>("autoUpdate", "Auto-redraw", "Update diagram as you type", "reload") {

        @Override
        public Bean<GlobalConfiguration> getBean() {
            return ConfigurationManager.getGlobalConfigurationBean();
        }
    };
    ConfigurationAction<GlobalConfiguration> autoScrollAction = new ConfigurationAction<GlobalConfiguration>("autoScroll", "Auto-scrolling", "Scroll automatically to where the message currently being specified is visible", "autoscroll") {

        @Override
        public Bean<GlobalConfiguration> getBean() {
            return ConfigurationManager.getGlobalConfigurationBean();
        }
    };
    ui.addAction("&Edit", actions.undoAction, actions.regularTabActivator);
    ui.addAction("&Edit", actions.redoAction, actions.regularTabActivator);
    ui.addAction("&Edit", actions.clearAction, actions.regularTabActivator);
    ui.addConfigurationAction("&Edit", threadedAction, actions.regularTabActivator);
    ui.addAction("&Edit", actions.configureGloballyAction, null);
    ui.addAction("&Edit", actions.configureDiagramAction, actions.regularTabActivator);
    ui.addCategory("&View", null);
    ui.addConfigurationAction("&View", autoUpdateAction, null);
    ui.addConfigurationAction("&View", autoScrollAction, null);
    ui.addAction("&View", actions.redrawAction, actions.regularTabActivator);
    ui.addAction("&View", actions.widenAction, actions.canConfigureActivator);
    ui.addAction("&View", actions.narrowAction, actions.canNarrowActivator);
    ui.addConfigurationAction("&View", wrapAction, actions.regularTabActivator);
    ui.addAction("&View", actions.fullScreenAction, actions.nonEmptyDiagramActivator);
    ui.addAction("&View", actions.splitLeftRightAction, actions.horizontalSplitPossibleActivator);
    ui.addAction("&View", actions.splitTopBottomAction, actions.verticalSplitPossibleActivator);
    if (OS.TYPE != OS.Type.MAC) {
        ui.setQuitAction(actions.quitAction);
    }
    ui.addToToolbar(actions.newDiagramAction, null);
    ui.addToToolbar(actions.loadCodeAction, null);
    ui.addToToolbar(actions.saveCodeAction, actions.regularTabActivator);
    ui.addToToolbar(actions.saveCodeAsAction, actions.regularTabActivator);
    if (exportAction != null) {
        ui.addToToolbar(exportAction, actions.nonEmptyDiagramActivator);
    } else {
        ui.addToToolbar(actions.saveImageAction, actions.nonEmptyDiagramActivator);
    }
    if (printPDFAction != null) {
        ui.addToToolbar(printPDFAction, actions.noDiagramErrorActivator);
    }
    ui.addToolbarSeparator();
    ui.addToToolbar(actions.configureGloballyAction, null);
    ui.addToToolbar(actions.configureDiagramAction, actions.regularTabActivator);
    ui.addToToolbar(actions.redrawAction, actions.regularTabActivator);
    ui.addToolbarSeparator();
    ui.addToToolbar(actions.fullScreenAction, actions.nonEmptyDiagramActivator);
    ui.addToToolbar(actions.splitLeftRightAction, actions.horizontalSplitPossibleActivator);
    ui.addToToolbar(actions.splitTopBottomAction, actions.verticalSplitPossibleActivator);
    ui.addAction("E&xtras", actions.serverAction, null);
    ui.addAction("E&xtras", actions.filterAction, actions.regularTabActivator);
    ui.addAction("E&xtras", new ExportMapAction(this), actions.nonEmptyDiagramActivator);
    ui.addAction("&Help", actions.helpAction, null);
    ui.addAction("&Help", actions.helpOnMultithreadingAction, null);
    ui.addAction("&Help", actions.asyncNotesAction, null);
    if (OS.TYPE != OS.Type.MAC) {
        ui.addAction("&Help", actions.showAboutDialogAction, null);
    }
    ui.addAction("&Help.&Examples", actions.getExampleAction("Ticket order", "order.sdx"), null);
    ui.addAction("&Help.&Examples", actions.getExampleAction("Breadth first search", "bfs.sdx"), null);
    ui.addAction("&Help.&Examples", actions.getExampleAction("Levels and mnemonics", "levels.sdx"), null);
    ui.addAction("&Help.&Examples", actions.getExampleAction("SSH 2 (by courtesy of Carlos Duarte)", "ssh.sdx"), null);
    ui.addAction("&Help.&Examples", actions.getExampleAction("Webserver", "webserver.sdx"), null);
}
Also used : Action(javax.swing.Action) ConfigurationAction(net.sf.sdedit.ui.components.configuration.ConfigurationAction) GlobalConfiguration(net.sf.sdedit.config.GlobalConfiguration) GlobalConfiguration(net.sf.sdedit.config.GlobalConfiguration) Configuration(net.sf.sdedit.config.Configuration) ConfigurationAction(net.sf.sdedit.ui.components.configuration.ConfigurationAction)

Example 2 with Configuration

use of net.sf.sdedit.config.Configuration in project abstools by abstools.

the class Editor method saveCode.

/**
 * Saves the code from the text area to the current file or to a file whose
 * name is given by the user. If the file has been successfully written, the
 * current file is set to that file.
 *
 * @param as
 *            flag denoting whether the user should give the file, if not,
 *            the current file (if present) is used
 * @throws IOException
 *             if the file cannot be written
 * @return flag denoting if the code has actually been saved
 */
public boolean saveCode(boolean as) throws IOException, XMLException {
    String code = ui.getCode().trim();
    Bean<Configuration> configuration = ui.getConfiguration();
    boolean createNew = as || ui.getCurrentFile() == null;
    File file = null;
    if (createNew) {
        String currentFile;
        File current = ui.getCurrentFile();
        if (current != null) {
            currentFile = current.getName();
            current = current.getParentFile();
        } else {
            currentFile = "untitled.sdx";
        }
        File[] files = ui.getFiles(false, false, "Save diagram file", currentFile, current, "Plain diagram source (.sd)", "sd", "Diagram source with preferences (.sdx)", "sdx");
        if (files != null) {
            file = files[0];
        }
    } else {
        file = ui.getCurrentFile();
    }
    if (file == null) {
        return false;
    }
    if (file.exists()) {
        if (createNew) {
            String option = ui.getOption("Overwrite existing file?", "Cancel", "No", "Yes#");
            if (!option.equals("Yes")) {
                return false;
            }
        }
        if (globalConfiguration.isBackupFiles()) {
            File backup = new File(file.getParent(), file.getName() + ".bak");
            if (backup.exists()) {
                backup.delete();
            }
            file.renameTo(backup);
        }
    }
    // set configuration to null if the diagram is to be saved as
    // plain text
    configuration = file.getName().toLowerCase().endsWith("sdx") ? configuration : null;
    OutputStream stream = new FileOutputStream(file);
    String encoding = globalConfiguration.getFileEncoding();
    try {
        DiagramLoader.saveDiagram(code, configuration, stream, encoding);
        addToRecentFiles(file.getAbsolutePath());
        ui.setCurrentFile(file);
        ui.setClean();
        if (createNew) {
            ui.setTabTitle(file.getName());
        }
    } finally {
        stream.close();
    }
    return true;
}
Also used : GlobalConfiguration(net.sf.sdedit.config.GlobalConfiguration) Configuration(net.sf.sdedit.config.Configuration) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 3 with Configuration

use of net.sf.sdedit.config.Configuration in project abstools by abstools.

the class Main method createImage.

private static void createImage(CommandLine cmd) throws IOException, XMLException, SyntaxError, SemanticError {
    File inFile = new File(getInputFiles(cmd)[0]);
    File outFile = new File(cmd.getOptionValue('o'));
    String type = "png";
    if (cmd.getOptionValue('t') != null) {
        type = cmd.getOptionValue('t').toLowerCase();
    }
    String format = "A4";
    if (cmd.getOptionValue('f') != null) {
        format = cmd.getOptionValue('f').toUpperCase();
    }
    String orientation = "Portrait";
    if (cmd.getOptionValue('r') != null) {
        orientation = cmd.getOptionValue('r').toLowerCase();
        if (orientation.length() > 0) {
            orientation = orientation.substring(0, 1).toUpperCase() + orientation.substring(1);
        }
    }
    InputStream in = null;
    OutputStream out = null;
    in = new FileInputStream(inFile);
    try {
        out = new FileOutputStream(outFile);
        try {
            Pair<String, Bean<Configuration>> pair = DiagramLoader.load(in, ConfigurationManager.getGlobalConfiguration().getFileEncoding());
            TextHandler th = new TextHandler(pair.getFirst());
            Bean<Configuration> conf = pair.getSecond();
            configure(conf, cmd);
            if (type.equals("png")) {
                ImagePaintDevice paintDevice = new ImagePaintDevice();
                new Diagram(conf.getDataObject(), th, paintDevice).generate();
                paintDevice.writeToStream(out);
            } else {
                Exporter paintDevice = Exporter.getExporter(type, orientation, format, out);
                new Diagram(conf.getDataObject(), th, paintDevice).generate();
                paintDevice.export();
            }
            out.flush();
        } finally {
            out.close();
        }
    } finally {
        in.close();
    }
}
Also used : Configuration(net.sf.sdedit.config.Configuration) ImagePaintDevice(net.sf.sdedit.ui.ImagePaintDevice) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) Exporter(net.sf.sdedit.server.Exporter) FileInputStream(java.io.FileInputStream) Bean(net.sf.sdedit.ui.components.configuration.Bean) Diagram(net.sf.sdedit.diagram.Diagram) FileOutputStream(java.io.FileOutputStream) TextHandler(net.sf.sdedit.text.TextHandler) File(java.io.File)

Example 4 with Configuration

use of net.sf.sdedit.config.Configuration in project abstools by abstools.

the class LoopArrow method init.

private void init() {
    Message message = getMessage();
    Configuration conf = message.getConfiguration();
    xExtent = conf.getSelfMessageHorizontalSpace();
    setWidth(diagram.messagePadding + xExtent + diagram.subLifelineWidth + textWidth());
    isAnswer = message instanceof AnswerToSelf;
    from = message.getCaller().getView();
    to = message.getCallee().getView();
    if (getAlign() == Direction.LEFT) {
        // loop arrows on the left must have a left neighbour
        setLeftEndpoint(message.getCallee().getLeftNeighbour().getView());
        if (message.getCaller().getSideLevel() < message.getCallee().getSideLevel()) {
            setRightEndpoint(message.getCaller().getView());
        } else {
            setRightEndpoint(message.getCallee().getView());
        }
    } else {
        int p = message.getCallee().getPosition();
        if (p < message.getDiagram().getNumberOfLifelines() - 1 && message.getDiagram().getLifelineAt(p + 1).isAlive()) {
            setRightEndpoint(message.getCallee().getRightNeighbour().getView());
        } else {
            setRightEndpoint(message.getDiagram().getPaintDevice().getRightBound());
        }
        if (message.getCaller().getSideLevel() < message.getCallee().getSideLevel()) {
            setLeftEndpoint(message.getCaller().getView());
        } else {
            setLeftEndpoint(message.getCallee().getView());
        }
    }
}
Also used : AnswerToSelf(net.sf.sdedit.message.AnswerToSelf) Message(net.sf.sdedit.message.Message) Configuration(net.sf.sdedit.config.Configuration) Point(java.awt.Point)

Example 5 with Configuration

use of net.sf.sdedit.config.Configuration 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>&lt;?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);
}
Also used : InputStreamReader(java.io.InputStreamReader) Configuration(net.sf.sdedit.config.Configuration) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) StringWriter(java.io.StringWriter) ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedReader(java.io.BufferedReader) BeanConverter(net.sf.sdedit.ui.components.configuration.BeanConverter) PrintWriter(java.io.PrintWriter) Pair(net.sf.sdedit.util.Pair)

Aggregations

Configuration (net.sf.sdedit.config.Configuration)8 File (java.io.File)4 GlobalConfiguration (net.sf.sdedit.config.GlobalConfiguration)3 Diagram (net.sf.sdedit.diagram.Diagram)3 TextHandler (net.sf.sdedit.text.TextHandler)3 ImagePaintDevice (net.sf.sdedit.ui.ImagePaintDevice)3 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 Image (java.awt.Image)1 Point (java.awt.Point)1 BufferedReader (java.io.BufferedReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 InputStreamReader (java.io.InputStreamReader)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 Action (javax.swing.Action)1 PrintConfiguration (net.sf.sdedit.config.PrintConfiguration)1