Permalink
Browse files

Added support for tool window, removed alternative file editor as red…

…undand
  • Loading branch information...
1 parent 54ee8e2 commit bbe93a3d32a3a072009e71c59d836f053d50f52c @esteinberg committed May 20, 2012
View
@@ -17,7 +17,7 @@
</actions>
<extensions defaultExtensionNs="com.intellij">
- <toolWindow id="PlantUML" icon="/org/plantuml/idea/uml.gif" anchor="right" factoryClass="org.plantuml.idea.PlantUmlToolWindowFactory"/>
- <fileEditorProvider implementation="org.plantuml.idea.PlantUmlFileEditorProvider"/>
+ <toolWindow id="PlantUML" icon="/org/plantuml/idea/toolwindow/uml.gif" anchor="right" factoryClass="org.plantuml.idea.toolwindow.PlantUmlToolWindowFactory"/>
+ <fileEditorProvider implementation="org.plantuml.idea.editor.PlantUmlFileEditorProvider"/>
</extensions>
</idea-plugin>
@@ -1,192 +0,0 @@
-package org.plantuml.idea.editor;
-
-import com.intellij.codeHighlighting.BackgroundEditorHighlighter;
-import com.intellij.ide.structureView.StructureViewBuilder;
-import com.intellij.openapi.application.ApplicationManager;
-import com.intellij.openapi.editor.Document;
-import com.intellij.openapi.editor.event.DocumentEvent;
-import com.intellij.openapi.editor.event.DocumentListener;
-import com.intellij.openapi.fileEditor.*;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.util.UserDataHolderBase;
-import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.openapi.vfs.VirtualFileAdapter;
-import com.intellij.openapi.vfs.VirtualFileEvent;
-import com.intellij.openapi.vfs.VirtualFileManager;
-import com.intellij.util.messages.MessageBus;
-import org.intellij.images.ui.ImageComponent;
-import org.jetbrains.annotations.NotNull;
-import org.plantuml.idea.messaging.RenderingNotifier;
-import org.plantuml.idea.plantuml.PlantUml;
-import org.plantuml.idea.plantuml.PlantUmlResult;
-import org.plantuml.idea.util.LazyApplicationPoolExecutor;
-
-import javax.swing.*;
-import java.awt.*;
-import java.awt.image.BufferedImage;
-import java.beans.PropertyChangeListener;
-
-/**
- * User: eugene
- * Date: 5/7/12
- * Time: 12:54 AM
- */
-public class PlantUmlFileEditorImpl extends UserDataHolderBase implements FileEditor {
- private static final String NAME = "PlantUMLFileEditor";
- public static final int RENDERING_PERIOD = 2000;
-
- private ImageComponent imageComponent = new ImageComponent();
- private JLabel description = new JLabel("", null, SwingConstants.LEFT);
- JPanel mainPanel = new JPanel();
-
- private SourceDocumentListener sourceDocumentListener = new SourceDocumentListener();
- private SourceVirtualFileListener sourceVirtualFileListener = new SourceVirtualFileListener();
- Document sourceDocument;
-
- private LazyApplicationPoolExecutor lazyExecutor = new LazyApplicationPoolExecutor(RENDERING_PERIOD);
-
- public PlantUmlFileEditorImpl(Project project, VirtualFile file) {
-
- sourceDocument = FileDocumentManager.getInstance().getDocument(file);
-
- if (sourceDocument != null) {
- sourceDocument.addDocumentListener(sourceDocumentListener);
- }
-
- VirtualFileManager.getInstance().addVirtualFileListener(sourceVirtualFileListener);
- mainPanel.add(imageComponent);
- mainPanel.add(description);
-
- MessageBus messageBus = ApplicationManager.getApplication().getMessageBus();
-
- messageBus.connect().subscribe(RenderingNotifier.RENDERING_TOPIC, new RenderingNotifier() {
- public void afterRendering(PlantUmlResult result) {
- BufferedImage diagram = result.getDiagram();
- description.setText(result.getDescription());
- if (diagram != null) {
- imageComponent.getDocument().setValue(diagram);
- imageComponent.setPreferredSize(new Dimension(diagram.getWidth(), diagram.getHeight()));
- }
- }
- });
-
-
- lazyRender();
- }
-
- @NotNull
- public JComponent getComponent() {
- return mainPanel;
- }
-
- public JComponent getPreferredFocusedComponent() {
- return mainPanel;
- }
-
- @NotNull
- public String getName() {
- return NAME;
- }
-
- @NotNull
- public FileEditorState getState(@NotNull FileEditorStateLevel level) {
- return new FileEditorState() {
- public boolean canBeMergedWith(FileEditorState otherState, FileEditorStateLevel level) {
- return false;
- }
- };
- }
-
- public void setState(@NotNull FileEditorState state) {
- // do nothing;
- }
-
- public boolean isModified() {
- return false;
- }
-
- public boolean isValid() {
- return true;
- }
-
- public void selectNotify() {
- // do nothing
- }
-
- public void deselectNotify() {
- // do nothing
- }
-
- public void addPropertyChangeListener(@NotNull PropertyChangeListener listener) {
- // do nothing
- }
-
- public void removePropertyChangeListener(@NotNull PropertyChangeListener listener) {
- // do nothing
- }
-
- public BackgroundEditorHighlighter getBackgroundHighlighter() {
- return null;
- }
-
- public FileEditorLocation getCurrentLocation() {
- return null;
- }
-
- public StructureViewBuilder getStructureViewBuilder() {
- return null;
- }
-
- public void dispose() {
- if (sourceDocument != null) {
- sourceDocument.removeDocumentListener(sourceDocumentListener);
- }
- VirtualFileManager.getInstance().removeVirtualFileListener(sourceVirtualFileListener);
- }
-
- public ImageComponent getImageComponent() {
- return imageComponent;
- }
-
- private void lazyRender() {
- lazyExecutor.execute(new Runnable() {
- public void run() {
- render();
- }
- });
- }
-
-
- private void render() {
- if (sourceDocument != null) {
- final PlantUmlResult result = PlantUml.render(sourceDocument.getText());
- ApplicationManager.getApplication().invokeLater(new Runnable() {
- public void run() {
- MessageBus messageBus = ApplicationManager.getApplication().getMessageBus();
- RenderingNotifier renderingNotifier = messageBus.syncPublisher(RenderingNotifier.RENDERING_TOPIC);
- renderingNotifier.afterRendering(result);
-
- }
- });
- }
- }
-
- private class SourceDocumentListener implements DocumentListener {
- public void beforeDocumentChange(DocumentEvent event) {
- // nothing
- }
-
- public void documentChanged(DocumentEvent event) {
- lazyRender();
- }
- }
-
- private class SourceVirtualFileListener extends VirtualFileAdapter {
- public void contentsChanged(VirtualFileEvent event) {
- super.contentsChanged(event);
- lazyRender();
- }
-
- }
-
-}
@@ -1,59 +0,0 @@
-package org.plantuml.idea.editor;
-
-import com.intellij.openapi.editor.Document;
-import com.intellij.openapi.fileEditor.*;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.util.Disposer;
-import com.intellij.openapi.vfs.VirtualFile;
-import org.jdom.Element;
-import org.jetbrains.annotations.NonNls;
-import org.jetbrains.annotations.NotNull;
-import org.plantuml.idea.plantuml.PlantUml;
-
-/**
- * User: eugene
- * Date: 5/7/12
- * Time: 12:51 AM
- */
-public class PlantUmlFileEditorProvider implements FileEditorProvider {
- @NonNls
- private static final String EDITOR_TYPE_ID = "plantUML";
-
- public boolean accept(@NotNull Project project, @NotNull VirtualFile file) {
- Document document = FileDocumentManager.getInstance().getDocument(file);
- return document != null && PlantUml.containsPlantUmlSource(document.getText());
- }
-
- @NotNull
- public FileEditor createEditor(@NotNull Project project, @NotNull VirtualFile file) {
- return new PlantUmlFileEditorImpl(project, file);
- }
-
- public void disposeEditor(@NotNull FileEditor editor) {
- Disposer.dispose(editor);
- }
-
- @NotNull
- public FileEditorState readState(@NotNull Element sourceElement, @NotNull Project project, @NotNull VirtualFile file) {
- return new FileEditorState() {
- public boolean canBeMergedWith(FileEditorState otherState, FileEditorStateLevel level) {
- return false;
- }
- };
-
- }
-
- public void writeState(@NotNull FileEditorState state, @NotNull Project project, @NotNull Element targetElement) {
- // do nothing
- }
-
- @NotNull
- public String getEditorTypeId() {
- return EDITOR_TYPE_ID;
- }
-
- @NotNull
- public FileEditorPolicy getPolicy() {
- return FileEditorPolicy.PLACE_AFTER_DEFAULT_EDITOR;
- }
-}
@@ -1,15 +0,0 @@
-package org.plantuml.idea.messaging;
-
-import com.intellij.util.messages.Topic;
-
-/**
- * User: eugene
- * Date: 5/19/12
- * Time: 9:36 PM
- */
-public interface RenderingNotifier {
- Topic<RenderingNotifier> RENDERING_COMPLETED_TOPIC =
- Topic.create("org.plantuml.idea.renderingCompleted", RenderingNotifier.class);
- void afterRe
-
-}
@@ -10,10 +10,10 @@
import java.io.InputStream;
/**
- * User: eugene
- * Date: 5/13/12
- * Time: 9:19 PM
+ *
+ * @author Eugene Steinberg
*/
+
public class PlantUml {
public static final String STARTUML = "@startuml";
@@ -3,10 +3,10 @@
import java.awt.image.BufferedImage;
/**
- * User: eugene
- * Date: 5/13/12
- * Time: 9:22 PM
+ *
+ * @author Eugene Steinberg
*/
+
public class PlantUmlResult {
private BufferedImage diagram;
private String description;
@@ -15,10 +15,10 @@
import java.awt.image.BufferedImage;
/**
- * User: eugene
- * Date: 5/5/12
- * Time: 4:03 PM
+ *
+ * @author Eugene Steinberg
*/
+
public class PlantUmlToolWindowFactory implements ToolWindowFactory {
private ToolWindow toolWindow;
private JPanel mainPanel;
@@ -8,16 +8,13 @@
import java.util.concurrent.atomic.AtomicBoolean;
/**
- * User: eugene
- * Date: 5/15/12
- * Time: 10:01 PM
- */
-
-/**
* LazyApplicationPoolExecutor runs submitted Runnable asynchronously in separate thread if at least
- * <strong>period</strong> milliseconds passed since last submission
+ * <strong>period</strong> milliseconds passed since last submission
+ *
+ * @author Eugene Steinberg
*/
+
public class LazyApplicationPoolExecutor implements Executor {
Future<?> commandFuture;
AtomicBoolean isExecutionRequested = new AtomicBoolean(false);

0 comments on commit bbe93a3

Please sign in to comment.