-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from marcphilipp/highlight-strong-connections-…
…squashed Highlight strong connections (squashed)
- Loading branch information
Showing
20 changed files
with
689 additions
and
75 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
...ectusus.core/test/org/projectusus/core/filerelations/model/test/PackageRelationsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package org.projectusus.core.filerelations.model.test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.mockito.Mockito.mock; | ||
|
||
import org.eclipse.core.resources.IFile; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.projectusus.core.filerelations.model.ClassDescriptor; | ||
import org.projectusus.core.filerelations.model.Classname; | ||
import org.projectusus.core.filerelations.model.PackageRelations; | ||
import org.projectusus.core.filerelations.model.Packagename; | ||
import org.projectusus.core.statistics.UsusModelProvider; | ||
|
||
public class PackageRelationsTest { | ||
|
||
private static Packagename I = Packagename.of( "I", null ); //$NON-NLS-1$ | ||
private static Packagename II = Packagename.of( "II", null ); //$NON-NLS-1$ | ||
private static Packagename III = Packagename.of( "III", null ); //$NON-NLS-1$ | ||
|
||
private ClassDescriptor I_A; | ||
private ClassDescriptor I_B; | ||
private ClassDescriptor II_A; | ||
private ClassDescriptor II_B; | ||
private ClassDescriptor III_A; | ||
|
||
@Before | ||
public void setup() { | ||
UsusModelProvider.clear(); | ||
I_A = createDescriptor( I ); | ||
I_B = createDescriptor( I ); | ||
II_A = createDescriptor( II ); | ||
II_B = createDescriptor( II ); | ||
III_A = createDescriptor( III ); | ||
} | ||
|
||
@Test | ||
public void crossLinkCountIsDirected() { | ||
I_A.addChild( II_A ); | ||
I_A.addChild( I_B ); | ||
II_A.addChild( II_B ); | ||
|
||
assertEquals( 1, getCrossLinkCount( I, II ) ); | ||
assertEquals( 0, getCrossLinkCount( II, I ) ); | ||
} | ||
|
||
@Test | ||
public void noCrossLinksInsidePackages() { | ||
I_A.addChild( I_B ); | ||
|
||
assertEquals( 0, getCrossLinkCount( I, I ) ); | ||
} | ||
|
||
@Test | ||
public void crossLinkCountAddsUp() { | ||
I_A.addChild( II_A ); | ||
I_B.addChild( II_A ); | ||
I_A.addChild( II_B ); | ||
I_B.addChild( II_B ); | ||
|
||
assertEquals( 4, getCrossLinkCount( I, II ) ); | ||
} | ||
|
||
@Test | ||
public void referencesAmongTwoClassesCountOnce() { | ||
I_A.addChild( II_A ); | ||
I_A.addChild( II_A ); | ||
|
||
assertEquals( 1, getCrossLinkCount( I, II ) ); | ||
} | ||
|
||
@Test | ||
public void maxLinkCount() { | ||
I_A.addChild( II_A ); | ||
I_A.addChild( II_B ); | ||
I_A.addChild( III_A ); | ||
II_A.addChild( I_A ); | ||
II_A.addChild( I_B ); | ||
III_A.addChild( II_A ); | ||
|
||
assertEquals( 2, new PackageRelations().getMaxCrossLinkCount() ); | ||
} | ||
|
||
private int getCrossLinkCount( Packagename source, Packagename target ) { | ||
return new PackageRelations().getCrossLinkCount( source, target ); | ||
} | ||
|
||
private static ClassDescriptor createDescriptor( Packagename packagename ) { | ||
return ClassDescriptor.of( mock( IFile.class ), new Classname( "classname1" ), packagename ); //$NON-NLS-1$ | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
26 changes: 26 additions & 0 deletions
26
...ncygraph/src/org/projectusus/ui/dependencygraph/colorProvider/ClassEdgeColorProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.projectusus.ui.dependencygraph.colorProvider; | ||
|
||
import static org.projectusus.ui.colors.UsusColors.DARK_GREY; | ||
import static org.projectusus.ui.colors.UsusColors.DARK_RED; | ||
import static org.projectusus.ui.colors.UsusColors.getSharedColors; | ||
import static org.projectusus.ui.dependencygraph.nodes.NodeLabelProvider.isCrossPackageRelation; | ||
|
||
import java.util.Set; | ||
|
||
import org.eclipse.swt.graphics.Color; | ||
import org.projectusus.core.filerelations.model.Packagename; | ||
import org.projectusus.ui.dependencygraph.nodes.IEdgeColorProvider; | ||
|
||
public class ClassEdgeColorProvider implements IEdgeColorProvider { | ||
|
||
public Color getEdgeColor( Object src, Object dest, boolean highlightStrongConnections ) { | ||
if( isCrossPackageRelation( src, dest ) ) { | ||
return getSharedColors().getColor( DARK_RED ); | ||
} | ||
return getSharedColors().getColor( DARK_GREY ); | ||
} | ||
|
||
public void recalculateColors( Set<Packagename> visibleNodes ) { | ||
// nothing to refresh | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
...ygraph/src/org/projectusus/ui/dependencygraph/colorProvider/PackageEdgeColorProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package org.projectusus.ui.dependencygraph.colorProvider; | ||
|
||
import static org.projectusus.ui.colors.UsusColors.DARK_RED; | ||
import static org.projectusus.ui.colors.UsusColors.getSharedColors; | ||
|
||
import java.util.Set; | ||
|
||
import org.eclipse.swt.graphics.Color; | ||
import org.projectusus.core.filerelations.model.PackageRelations; | ||
import org.projectusus.core.filerelations.model.Packagename; | ||
import org.projectusus.ui.dependencygraph.nodes.IEdgeColorProvider; | ||
import org.projectusus.ui.dependencygraph.nodes.PackageRepresenter; | ||
|
||
import com.google.common.base.Predicate; | ||
import com.google.common.base.Predicates; | ||
import com.google.common.base.Supplier; | ||
import com.google.common.base.Suppliers; | ||
|
||
public class PackageEdgeColorProvider implements IEdgeColorProvider { | ||
|
||
private Supplier<PackageRelations> packageRelationsSupplier; | ||
private Predicate<Packagename> isVisible; | ||
|
||
public PackageEdgeColorProvider() { | ||
isVisible = Predicates.<Packagename> alwaysTrue(); | ||
calculatePackageRelations(); | ||
} | ||
|
||
public Color getEdgeColor( Object src, Object dest, boolean highlightStrongConnections ) { | ||
if( highlightStrongConnections ) { | ||
float saturation = computeSaturation( src, dest ); | ||
return getSharedColors().adjustSaturation( DARK_RED, saturation ); | ||
} | ||
return getSharedColors().getColor( DARK_RED ); | ||
} | ||
|
||
private float computeSaturation( Object src, Object dest ) { | ||
PackageRelations packageRelations = packageRelationsSupplier.get(); | ||
|
||
int crossLinkCount = getCrossLinkCount( (PackageRepresenter)src, (PackageRepresenter)dest, packageRelations ); | ||
float maxCrossLinkCount = packageRelations.getMaxCrossLinkCount(); | ||
float saturation = crossLinkCount / maxCrossLinkCount; | ||
return saturation; | ||
} | ||
|
||
private int getCrossLinkCount( PackageRepresenter src, PackageRepresenter target, PackageRelations packageRelations ) { | ||
return packageRelations.getCrossLinkCount( src.getPackagename(), target.getPackagename() ); | ||
} | ||
|
||
public void recalculateColors( final Set<Packagename> visiblePackages ) { | ||
isVisible = new Predicate<Packagename>() { | ||
public boolean apply( Packagename packagename ) { | ||
return visiblePackages.contains( packagename ); | ||
} | ||
}; | ||
calculatePackageRelations(); | ||
} | ||
|
||
public void calculatePackageRelations() { | ||
packageRelationsSupplier = Suppliers.memoize( new Supplier<PackageRelations>() { | ||
public PackageRelations get() { | ||
return new PackageRelations( isVisible ); | ||
} | ||
} ); | ||
} | ||
} |
Oops, something went wrong.