Skip to content

Commit

Permalink
Issue #65 - added the settings page with dot executable path.
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Gorbunov committed Sep 3, 2014
1 parent 23eb1d4 commit 9886a88
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 2 deletions.
4 changes: 3 additions & 1 deletion META-INF/plugin.xml
Expand Up @@ -56,5 +56,7 @@
<fileTypeFactory implementation="org.plantuml.idea.lang.PlantUmlTypeFactory"/>
<lang.parserDefinition language="PUML"
implementationClass="org.plantuml.idea.lang.PlantUmlParserDefinition"/>
<applicationConfigurable instance="org.plantuml.idea.lang.settings.PlantUmlSettingsPage"/>
<applicationService serviceImplementation="org.plantuml.idea.lang.settings.PlantUmlSettings"/>
</extensions>
</idea-plugin>
</idea-plugin>
4 changes: 3 additions & 1 deletion NOTICE.txt
Expand Up @@ -2,4 +2,6 @@ PlantUml4Idea
Copyright (c) 2012-2014 Eugene Steinberg

This product includes software developed at
PlantUml http://plantuml.sourceforge.net/
PlantUml http://plantuml.sourceforge.net/

Portions of this software were developed at Google.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -10,6 +10,7 @@ Author: [Eugene Steinberg](https://github.com/esteinberg)
Contributors:
* [Ivan Mamontov](https://github.com/IvanMamontov)
* [Henady Zakalusky](https://github.com/hza)
* [Max Gorbunov](https://github.com/6zow)

# Features

Expand Down
42 changes: 42 additions & 0 deletions src/org/plantuml/idea/lang/settings/PlantUmlSettings.java
@@ -0,0 +1,42 @@
package org.plantuml.idea.lang.settings;

import com.intellij.openapi.components.*;
import com.intellij.util.xmlb.XmlSerializerUtil;
import net.sourceforge.plantuml.OptionFlags;
import org.jetbrains.annotations.Nullable;

/**
* @author Max Gorbunov
*/
@State(name = "PlantUmlSettings", storages = {@Storage(file = StoragePathMacros.APP_CONFIG + "/plantuml.cfg")})
public class PlantUmlSettings implements PersistentStateComponent<PlantUmlSettings> {
private String dotExecutable = null;

public static PlantUmlSettings getInstance() {
return ServiceManager.getService(PlantUmlSettings.class);
}

public String getDotExecutable() {
return dotExecutable;
}

public void setDotExecutable(String dotExecutable) {
this.dotExecutable = dotExecutable;
if ("".equals(dotExecutable)) {
this.dotExecutable = null;
}
OptionFlags.getInstance().setDotExecutable(this.dotExecutable);
}

@Nullable
@Override
public PlantUmlSettings getState() {
return this;
}

@Override
public void loadState(PlantUmlSettings state) {
XmlSerializerUtil.copyBean(state, this);
OptionFlags.getInstance().setDotExecutable(dotExecutable);
}
}
34 changes: 34 additions & 0 deletions src/org/plantuml/idea/lang/settings/PlantUmlSettingsPage.form
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.plantuml.idea.lang.settings.PlantUmlSettingsPage">
<grid id="27dc6" binding="panel" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="36d0" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Graphviz dot executable:"/>
</properties>
</component>
<vspacer id="68158">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="c9516" class="javax.swing.JTextField" binding="textFieldDotExecutable">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
</children>
</grid>
</form>
53 changes: 53 additions & 0 deletions src/org/plantuml/idea/lang/settings/PlantUmlSettingsPage.java
@@ -0,0 +1,53 @@
package org.plantuml.idea.lang.settings;

import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.options.ConfigurationException;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;

/**
* @author Max Gorbunov
*/
public class PlantUmlSettingsPage implements Configurable {
private JPanel panel;
private JTextField textFieldDotExecutable;

@Nls
@Override
public String getDisplayName() {
return "PlantUML";
}

@Nullable
@Override
public String getHelpTopic() {
return null;
}

@Nullable
@Override
public JComponent createComponent() {
return panel;
}

@Override
public boolean isModified() {
return !textFieldDotExecutable.getText().equals(PlantUmlSettings.getInstance().getDotExecutable());
}

@Override
public void apply() throws ConfigurationException {
PlantUmlSettings.getInstance().setDotExecutable(textFieldDotExecutable.getText());
}

@Override
public void reset() {
textFieldDotExecutable.setText(PlantUmlSettings.getInstance().getDotExecutable());
}

@Override
public void disposeUIResources() {
}
}
6 changes: 6 additions & 0 deletions src/org/plantuml/idea/plantuml/PlantUml.java
Expand Up @@ -2,6 +2,7 @@

import net.sourceforge.plantuml.*;
import net.sourceforge.plantuml.core.Diagram;
import org.plantuml.idea.lang.settings.PlantUmlSettings;

import java.io.ByteArrayOutputStream;
import java.io.File;
Expand All @@ -18,6 +19,11 @@ public class PlantUml {
public static final String TESTDOT = "@startuml\ntestdot\n@enduml";
public static final String UMLSTART = "@start";

static {
// Make sure settings are loaded and applied before we start rendering.
PlantUmlSettings.getInstance();
}

public enum ImageFormat {
PNG {
@Override
Expand Down

0 comments on commit 9886a88

Please sign in to comment.