Skip to content

Commit

Permalink
implement #18, using built-in color scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
oker1 committed Jun 19, 2016
1 parent 929a1fd commit 9d62bee
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 25 deletions.
36 changes: 22 additions & 14 deletions src/cc/takacs/php_codeverage_display/config/ConfigPanel.form
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@
</component>
</children>
</grid>
<grid id="5db59" layout-manager="GridLayoutManager" row-count="1" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="5db59" layout-manager="GridLayoutManager" row-count="1" column-count="6" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="93571" class="javax.swing.JLabel">
<component id="93571" class="javax.swing.JLabel" binding="coveredColorLabel">
<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"/>
<grid row="0" column="1" 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="Covered"/>
Expand All @@ -53,7 +53,7 @@
<grid id="838c" binding="coveredColor" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="20" height="20"/>
<preferred-size width="20" height="20"/>
<maximum-size width="20" height="20"/>
Expand All @@ -63,18 +63,10 @@
<border type="none"/>
<children/>
</grid>
<component id="ce562" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="2" 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="Uncovered"/>
</properties>
</component>
<grid id="95117" binding="uncoveredColor" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
<grid row="0" column="4" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="20" height="20"/>
<preferred-size width="20" height="20"/>
<maximum-size width="20" height="20"/>
Expand All @@ -86,9 +78,25 @@
</grid>
<hspacer id="2a1b2">
<constraints>
<grid row="0" column="4" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="0" column="5" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<component id="ce562" class="javax.swing.JLabel" binding="uncoveredColorLabel">
<constraints>
<grid row="0" column="3" 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="Uncovered"/>
</properties>
</component>
<component id="8810c" class="javax.swing.JCheckBox" binding="useColorScheme">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Use color scheme"/>
</properties>
</component>
</children>
</grid>
<grid id="fc678" layout-manager="GridLayoutManager" row-count="1" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
Expand Down
34 changes: 28 additions & 6 deletions src/cc/takacs/php_codeverage_display/config/ConfigPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
import com.intellij.openapi.vfs.VirtualFile;

import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.*;

/**
* @author Zsolt Takacs <[email protected]>
Expand All @@ -31,6 +30,11 @@ public class ConfigPanel {
// checkbox used to enable & disable error highlighting
// which usually looks like errors
public JCheckBox errorCheckBox;
public JCheckBox useColorScheme;
private JLabel coveredColorLabel;
private JLabel uncoveredColorLabel;
private PickerListener coveredColorListener = new PickerListener(panel, coveredColor);
private PickerListener uncoveredColorListener = new PickerListener(panel, uncoveredColor);

public ConfigPanel() {
browseCloverXmlButton.addActionListener(
Expand All @@ -40,15 +44,33 @@ public ConfigPanel() {
new BrowseListener(this.localDir, FileChooserDescriptorFactory.createSingleFolderDescriptor())
);

coveredColor.addMouseListener(new PickerListener(panel, coveredColor));
uncoveredColor.addMouseListener(new PickerListener(panel, uncoveredColor));
setColorListeners(true);
dirTranslation.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
localDir.setEnabled(dirTranslation.isSelected());
remoteDir.setEnabled(dirTranslation.isSelected());
browseLocalDir.setEnabled(dirTranslation.isSelected());
}
});
useColorScheme.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
boolean isNotSelected = e.getStateChange() != ItemEvent.SELECTED;
coveredColorLabel.setEnabled(isNotSelected);
uncoveredColorLabel.setEnabled(isNotSelected);
setColorListeners(isNotSelected);
}
});
}

private void setColorListeners(boolean enabled) {
if (enabled) {
coveredColor.addMouseListener(coveredColorListener);
uncoveredColor.addMouseListener(uncoveredColorListener);
} else {
coveredColor.removeMouseListener(coveredColorListener);
uncoveredColor.removeMouseListener(uncoveredColorListener);
}
}

private class PickerListener implements MouseListener {
Expand Down
31 changes: 31 additions & 0 deletions src/cc/takacs/php_codeverage_display/config/ConfigValues.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
package cc.takacs.php_codeverage_display.config;

import com.intellij.ide.util.PropertiesComponent;
import com.intellij.openapi.editor.colors.ColorKey;
import com.intellij.openapi.editor.colors.EditorColorsManager;
import com.intellij.openapi.editor.colors.EditorColorsScheme;
import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.editor.colors.ex.DefaultColorSchemesManager;
import com.intellij.openapi.editor.colors.impl.DefaultColorsScheme;
import com.intellij.rt.coverage.data.LineCoverage;
import com.intellij.util.xmlb.annotations.Transient;

import java.awt.*;
Expand All @@ -25,6 +32,7 @@ public class ConfigValues {
public boolean directoryMapping = false;
public String mapDirectoryFrom = "";
public String mapDirectoryTo = "";
public boolean useColorScheme = true;

//Should we use the php storm coverage suite?
public boolean useCoverageSuite = true;
Expand All @@ -47,6 +55,7 @@ public void loadFromInstance(ConfigValues values) {
mapDirectoryFrom = values.mapDirectoryFrom;
mapDirectoryTo = values.mapDirectoryTo;
useCoverageSuite = values.useCoverageSuite;
useColorScheme = values.useColorScheme;
}

public void setCloverXmlPath(String cloverXmlPath) {
Expand Down Expand Up @@ -82,6 +91,28 @@ public void setUncoveredColor(Color color) {
uncoveredA = color.getAlpha();
}

@Transient
public Color getCoveredColorToDraw() {
if (useColorScheme) {
EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
return scheme.getAttributes(TextAttributesKey.find("LINE_FULL_COVERAGE")).getForegroundColor();

} else {
return new Color(coveredR, coveredG, coveredB, coveredA);
}
}

@Transient
public Color getUncoveredColorToDraw() {
if (useColorScheme) {
EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
return scheme.getAttributes(TextAttributesKey.find("LINE_NONE_COVERAGE")).getForegroundColor();

} else {
return new Color(coveredR, coveredG, coveredB, coveredA);
}
}

/**
* If we should highlight lines
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public boolean isModified() {
configValues.useCoverageSuite != configPanel.useCoverageSuite.isSelected() ||
configValues.directoryMapping != configPanel.dirTranslation.isSelected() ||
!configValues.mapDirectoryFrom.equals(configPanel.localDir.getText()) ||
!configValues.mapDirectoryTo.equals(configPanel.remoteDir.getText());
!configValues.mapDirectoryTo.equals(configPanel.remoteDir.getText()) ||
configValues.useColorScheme != configPanel.useColorScheme.isSelected();
}

public void apply() throws ConfigurationException {
Expand All @@ -67,6 +68,7 @@ public void apply() throws ConfigurationException {
configValues.directoryMapping = configPanel.dirTranslation.isSelected();
configValues.mapDirectoryFrom = configPanel.localDir.getText();
configValues.mapDirectoryTo = configPanel.remoteDir.getText();
configValues.useColorScheme = configPanel.useColorScheme.isSelected();

displayHandler.initializeMap();
displayHandler.updateDisplays();
Expand All @@ -87,6 +89,7 @@ public void reset() {
configPanel.localDir.setEnabled(configPanel.dirTranslation.isSelected());
configPanel.remoteDir.setEnabled(configPanel.dirTranslation.isSelected());
configPanel.browseLocalDir.setEnabled(configPanel.dirTranslation.isSelected());
configPanel.useColorScheme.setSelected(configValues.useColorScheme);
}

public void disposeUIResources() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public synchronized void redraw() {

if (lineCoverage.isExecuted() != lastLineWasExecuted || lastLineNumber != lineNumber - 1) {
if (lastLineWasExecuted) {
this.coverageHighlighter.highlightLines(configValues.getCoveredColor(), lastDifferentLine, lastLineNumber, lastLineExecuted);
this.coverageHighlighter.highlightLines(configValues.getCoveredColorToDraw(), lastDifferentLine, lastLineNumber, lastLineExecuted);
} else {
this.coverageHighlighter.highlightLines(configValues.getUncoveredColor(), lastDifferentLine, lastLineNumber, lastLineExecuted);
this.coverageHighlighter.highlightLines(configValues.getUncoveredColorToDraw(), lastDifferentLine, lastLineNumber, lastLineExecuted);
}

lastLineExecuted = lineCoverage.getExecuted();
Expand All @@ -66,9 +66,9 @@ public synchronized void redraw() {

if (!iterator.hasNext()) {
if (lastLineWasExecuted) {
this.coverageHighlighter.highlightLines(configValues.getCoveredColor(), lastDifferentLine, lastLineNumber, lastLineExecuted);
this.coverageHighlighter.highlightLines(configValues.getCoveredColorToDraw(), lastDifferentLine, lastLineNumber, lastLineExecuted);
} else {
this.coverageHighlighter.highlightLines(configValues.getUncoveredColor(), lastDifferentLine, lastLineNumber, lastLineExecuted);
this.coverageHighlighter.highlightLines(configValues.getUncoveredColorToDraw(), lastDifferentLine, lastLineNumber, lastLineExecuted);
}
}
}
Expand Down

0 comments on commit 9d62bee

Please sign in to comment.