Skip to content

Commit

Permalink
Synchronized add/rm from editor panel. Fixes #96.
Browse files Browse the repository at this point in the history
  • Loading branch information
parrt committed Apr 25, 2014
1 parent abbb1b7 commit 0e70fca
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 26 deletions.
16 changes: 3 additions & 13 deletions META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<idea-plugin version="2">
<id>org.antlr.intellij.plugin</id>
<name>ANTLR v4 grammar plugin</name>
<version>1.2</version>
<vendor email="[email protected]" url="http://www.antlr.org">ANTLR Project</vendor>
<version>1.2.1</version>
<vendor email="[email protected]" url="https://github.com/antlr/intellij-plugin-v4">ANTLR Project</vendor>

<description><![CDATA[
This plugin is for ANTLR v4 grammars. Features: syntax highlighting,
Expand Down Expand Up @@ -36,17 +36,7 @@
]]></description>

<change-notes><![CDATA[
You can use the meta-key while moving the mouse and it will show you
token information in the preview editor box via tooltips.
Errors within the preview editor are now highlighted with tooltips
and underlining just like a regular editor window. The difference
is that this window's grammar is specified in your grammar file.
Also note that the plug-in does not pay attention to any package statements
and actions now. You must use the configuration dialog.
More bug fixes. See github for complete list.
Hush annoying error.
]]>
</change-notes>

Expand Down
35 changes: 22 additions & 13 deletions src/java/org/antlr/intellij/plugin/preview/PreviewPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ public class PreviewPanel extends JPanel {
public static final int TOKEN_INFO_LAYER = HighlighterLayer.SELECTION; // Show token info over errors
public static final int ERROR_LAYER = HighlighterLayer.ERROR;

/** switchToGrammar() was seeing an empty slot instead of a previous
* editor or placeHolder. Figured it was an order of operations thing
* and synchronized add/remove ops. Works now w/o error.
*/
public final Object swapEditorComponentLock = new Object();

public static final JLabel placeHolder = new JLabel("");
public static final String missingStartRuleLabelText =
"Start rule: <select from navigator or grammar>";
Expand Down Expand Up @@ -96,10 +102,11 @@ public JPanel createEditorPanel() {
editorPanel = new JPanel(new BorderLayout(0,0));
startRuleLabel = new JLabel(missingStartRuleLabelText);
startRuleLabel.setForeground(JBColor.RED);
editorPanel.add(startRuleLabel, BorderLayout.NORTH);
editorPanel.add(placeHolder, BorderLayout.CENTER);
editorPanel.add(spane, BorderLayout.SOUTH);

synchronized ( swapEditorComponentLock ) {
editorPanel.add(startRuleLabel, BorderLayout.NORTH);
editorPanel.add(placeHolder, BorderLayout.CENTER);
editorPanel.add(spane, BorderLayout.SOUTH);
}
return editorPanel;
}

Expand Down Expand Up @@ -161,14 +168,14 @@ public void switchToGrammar(VirtualFile grammarFile) {
}

BorderLayout layout = (BorderLayout)editorPanel.getLayout();
Component editorSpotComp = layout.getLayoutComponent(BorderLayout.CENTER);
if ( editorSpotComp!=null ) {
editorPanel.remove(editorSpotComp); // remove old editor if it's there
}
else {
LOG.error("switchToGrammar no CENTER component in editorPanel"+" "+project.getName());
// atomically remove old
synchronized ( swapEditorComponentLock ) {
Component editorSpotComp = layout.getLayoutComponent(BorderLayout.CENTER);
if (editorSpotComp != null) {
editorPanel.remove(editorSpotComp); // remove old editor if it's there
}
editorPanel.add(previewState.editor.getComponent(), BorderLayout.CENTER);
}
editorPanel.add(previewState.editor.getComponent(), BorderLayout.CENTER);
clearParseErrors(grammarFile);

if ( previewState.startRuleName!=null ) {
Expand Down Expand Up @@ -205,8 +212,10 @@ public void closeGrammar(VirtualFile grammarFile) {
// restore the GUI
BorderLayout layout = (BorderLayout)editorPanel.getLayout();
Component editorSpotComp = layout.getLayoutComponent(BorderLayout.CENTER);
editorPanel.remove(editorSpotComp);
editorPanel.add(placeHolder, BorderLayout.CENTER); // put placeholder back after we remove the editor component.
synchronized ( swapEditorComponentLock ) {
editorPanel.remove(editorSpotComp);
editorPanel.add(placeHolder, BorderLayout.CENTER); // put placeholder back after we remove the editor component.
}
}

public void setParseTree(final List<String> ruleNames, final ParseTree tree) {
Expand Down

0 comments on commit 0e70fca

Please sign in to comment.