1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-12-23 03:19:06 +00:00

Merge pull request #1587 from travkin79/patch/1580

#1580 Fix hiding stereotypes
This commit is contained in:
PlantUML 2023-10-30 13:33:40 +02:00 committed by GitHub
commit b8b98d0c18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 65 additions and 3 deletions

View File

@ -46,6 +46,7 @@ import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import net.sourceforge.plantuml.FileFormat; import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.FileFormatOption; import net.sourceforge.plantuml.FileFormatOption;
@ -84,10 +85,12 @@ import net.sourceforge.plantuml.security.SecurityUtils;
import net.sourceforge.plantuml.skin.UmlDiagramType; import net.sourceforge.plantuml.skin.UmlDiagramType;
import net.sourceforge.plantuml.skin.VisibilityModifier; import net.sourceforge.plantuml.skin.VisibilityModifier;
import net.sourceforge.plantuml.statediagram.StateDiagram; import net.sourceforge.plantuml.statediagram.StateDiagram;
import net.sourceforge.plantuml.stereo.Stereotype;
import net.sourceforge.plantuml.style.ClockwiseTopRightBottomLeft; import net.sourceforge.plantuml.style.ClockwiseTopRightBottomLeft;
import net.sourceforge.plantuml.svek.CucaDiagramFileMaker; import net.sourceforge.plantuml.svek.CucaDiagramFileMaker;
import net.sourceforge.plantuml.svek.CucaDiagramFileMakerSvek; import net.sourceforge.plantuml.svek.CucaDiagramFileMakerSvek;
import net.sourceforge.plantuml.text.BackSlash; import net.sourceforge.plantuml.text.BackSlash;
import net.sourceforge.plantuml.text.Guillemet;
import net.sourceforge.plantuml.xmi.CucaDiagramXmiMaker; import net.sourceforge.plantuml.xmi.CucaDiagramXmiMaker;
import net.sourceforge.plantuml.xmlsc.StateDiagramScxmlMaker; import net.sourceforge.plantuml.xmlsc.StateDiagramScxmlMaker;
@ -523,6 +526,41 @@ public abstract class CucaDiagram extends UmlDiagram implements GroupHierarchy,
return result; return result;
} }
@Override
public List<String> getVisibleStereotypeLabels(Entity entity) {
Stereotype stereotype = entity.getStereotype();
if (stereotype == null) {
return null;
}
List<EntityHideOrShow> commands = new ArrayList<>();
for (EntityHideOrShow hideOrShowEntry : hideOrShows) {
if (hideOrShowEntry.portion == EntityPortion.STEREOTYPE) {
commands.add(hideOrShowEntry);
}
}
List<String> visibleStereotypeLabels = new ArrayList<>();
for (String stereoTypeLabel: entity.getStereotype().getLabels(Guillemet.DOUBLE_COMPARATOR)) {
if (isHiddenStereotypeLabel(stereoTypeLabel, commands)) {
visibleStereotypeLabels.add(stereoTypeLabel);
}
}
return visibleStereotypeLabels;
}
private boolean isHiddenStereotypeLabel(String stereoTypeLabel, List<EntityHideOrShow> commands) {
for (EntityHideOrShow cmd : commands) {
String gender = cmd.gender.getGender();
if (gender != null && gender.equals(stereoTypeLabel)) {
return false;
}
}
return true;
}
public final void hideOrShow(EntityGender gender, EntityPortion portions, boolean show) { public final void hideOrShow(EntityGender gender, EntityPortion portions, boolean show) {
for (EntityPortion portion : portions.asSet()) for (EntityPortion portion : portions.asSet())
this.hideOrShows.add(new EntityHideOrShow(gender, portion, show)); this.hideOrShows.add(new EntityHideOrShow(gender, portion, show));

View File

@ -71,7 +71,14 @@ public class EntityGenderUtils {
if (test.getStereotype() == null) { if (test.getStereotype() == null) {
return false; return false;
} }
return stereotype.equals(test.getStereotype().getLabel(Guillemet.DOUBLE_COMPARATOR));
for (String label : test.getStereotype().getLabels(Guillemet.DOUBLE_COMPARATOR)) {
if (label.equals(stereotype)) {
return true;
}
}
return false;
} }
@Override @Override

View File

@ -38,7 +38,11 @@ package net.sourceforge.plantuml.cucadiagram;
import net.sourceforge.plantuml.abel.Entity; import net.sourceforge.plantuml.abel.Entity;
import net.sourceforge.plantuml.abel.EntityPortion; import net.sourceforge.plantuml.abel.EntityPortion;
import java.util.List;
public interface PortionShower { public interface PortionShower {
boolean showPortion(EntityPortion portion, Entity entity); boolean showPortion(EntityPortion portion, Entity entity);
List<String> getVisibleStereotypeLabels(Entity entity);
} }

View File

@ -37,6 +37,7 @@ package net.sourceforge.plantuml.dot;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
@ -101,6 +102,11 @@ final public class DotData implements PortionShower {
public boolean showPortion(EntityPortion portion, Entity entity) { public boolean showPortion(EntityPortion portion, Entity entity) {
return true; return true;
} }
public List<String> getVisibleStereotypeLabels(Entity entity) {
return Collections.emptyList();
}
}, entityFactory, isHideEmptyDescriptionForState, dotMode, namespaceSeparator, pragma); }, entityFactory, isHideEmptyDescriptionForState, dotMode, namespaceSeparator, pragma);
} }
@ -136,6 +142,10 @@ final public class DotData implements PortionShower {
return portionShower.showPortion(portion, entity); return portionShower.showPortion(portion, entity);
} }
public List<String> getVisibleStereotypeLabels(Entity entity) {
return portionShower.getVisibleStereotypeLabels(entity);
}
public Entity getRootGroup() { public Entity getRootGroup() {
return entityFactory.getRootGroup(); return entityFactory.getRootGroup();
} }

View File

@ -68,6 +68,8 @@ import net.sourceforge.plantuml.svek.HeaderLayout;
import net.sourceforge.plantuml.svek.ShapeType; import net.sourceforge.plantuml.svek.ShapeType;
import net.sourceforge.plantuml.text.Guillemet; import net.sourceforge.plantuml.text.Guillemet;
import java.util.List;
public class EntityImageClassHeader extends AbstractEntityImage { public class EntityImageClassHeader extends AbstractEntityImage {
final private HeaderLayout headerLayout; final private HeaderLayout headerLayout;
@ -112,11 +114,12 @@ public class EntityImageClassHeader extends AbstractEntityImage {
} }
final TextBlock stereo; final TextBlock stereo;
List<String> stereotypeLabels = portionShower.getVisibleStereotypeLabels(entity);
if (stereotype == null || stereotype.getLabel(Guillemet.DOUBLE_COMPARATOR) == null if (stereotype == null || stereotype.getLabel(Guillemet.DOUBLE_COMPARATOR) == null
|| portionShower.showPortion(EntityPortion.STEREOTYPE, entity) == false) || stereotypeLabels.isEmpty())
stereo = null; stereo = null;
else else
stereo = TextBlockUtils.withMargin(Display.create(stereotype.getLabels(skinParam.guillemet())).create( stereo = TextBlockUtils.withMargin(Display.create(stereotypeLabels).create(
FontConfiguration.create(getSkinParam(), FontParam.CLASS_STEREOTYPE, stereotype), FontConfiguration.create(getSkinParam(), FontParam.CLASS_STEREOTYPE, stereotype),
HorizontalAlignment.CENTER, skinParam), 1, 0); HorizontalAlignment.CENTER, skinParam), 1, 0);