Skip to content

Commit

Permalink
v14.4.0-SNAPSHOT_grouped_attributes_(20201125)_r0
Browse files Browse the repository at this point in the history
Majors:
• Support for grouped attribs
• Support for global attribs
  • Loading branch information
911992 committed Nov 26, 2020
1 parent b9ef995 commit 8f754d0
Show file tree
Hide file tree
Showing 7 changed files with 301 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.baselet.control.shared_attrib;

import java.util.ArrayList;
import java.util.List;

//a one-to-many relation between a attrib name and attribs(lines)
public class DiagramSharedAttributeEntity {

//when null, then it means the style should be applied globally
private String style_name;
private final ArrayList<String> attribs = new ArrayList<>(5);

//clears all associated key-p
public void invalide() {
attribs.clear();
}

public String getStyle_name() {
return style_name;
}

public void addAttrib(String arg_val) {
this.attribs.add(arg_val);
}

public void setStyle_name(String style_name) {
this.style_name = style_name;
}

public ArrayList<String> getAttribs() {
return attribs;
}

public int line_stream(List<String> arg_strb, int arg_idx) {
for (String _str : attribs) {
arg_strb.add(arg_idx, _str);
arg_idx++;
}
return attribs.size();
}

public int line_stream(List<String> arg_strb) {
return line_stream(arg_strb, arg_strb.size());
}

public boolean has_anything() {
return this.attribs.size() > 0;
}

public boolean name_equal(String arg_style_name) {
return this.style_name.equals(arg_style_name);
}

public boolean merge(DiagramSharedAttributeEntity arg_entry) {
if (arg_entry.getStyle_name().equals(this.getStyle_name()) /*&& arg_entry.has_anything()*/) {
this.attribs.addAll(arg_entry.getAttribs());
return true;
}
return false;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
package com.baselet.control.shared_attrib;

import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

/**
* This class handles diagram shared attributes are set in helptext.(when no element is selected, the welcome text).
* Could be related to #515
*/
public class DiagramSharedAttributesHandler {
private DiagramSharedAttributesHandler() {

}

//start of text for attrib definition
private static final String ATTRIB_DEF_SOT = "#";

//splittor for attrib names
private static final String ATTRIB_SPLITTERS_REGEX = "\\,";

private static final String ATTRIB_DEF_SOT_ESCAPE = "\\"+ATTRIB_DEF_SOT;

//triggers for attribute replace
public static final String ATTRIBUTE_MARKER = "#include=";

public static final String ATTRIBUTE_MARKER_ESCAPE = "\\"+ATTRIBUTE_MARKER;

//let say attrib0,attrib1,... that(,)
public static final String ATTRIBUTE_MARKER_SPLITER = ",";

private static final String ATTRIBUTE_MARKER_SPLITER_REGEX = "\\"+ATTRIBUTE_MARKER_SPLITER;

//delim as the first line
private static final String ATTRIBS_SOT_FL = "[includes]\n";

//start of styling (at the middle)
private static final String ATTRIBS_SOT = "\n"+ATTRIBS_SOT_FL;

//atrrib definition, could be started by something for compatibility sake
//for compatibility only, not essential
private static final String ATTRIB_ATTRIB_DEF_SOT = "-";

//escaping for ATTRIB_ATTRIB_DEF_SOT
private static final String ATTRIB_ATTRIB_DEF_SOT_ESCAPED = "\\"+ATTRIB_ATTRIB_DEF_SOT;

//contains only styling section as cached
private static volatile String last_attrib_plain_str;

//contains only styling section as cached
private static volatile String last_attrib_proceed_str="";

//contains non-styling section as cached
// private static volatile String last_non_attrib_plain_str;

//the last known (contains both attribs, and meta) original text were proceed
private static volatile String last_proceesed_str;

private static final DiagramSharedAttributeEntity public_attrib= new DiagramSharedAttributeEntity();

//contains only attribs with atleast one def
private static final ArrayList<DiagramSharedAttributeEntity> last_proceed_result=new ArrayList<>(5);

public static final boolean has_any_includes(){
return public_attrib.has_anything() || last_proceed_result.size()>0;
}

//returns numbers of lines has been added to the element property text
public static final int process_property_text(List<String> arg_src,List<String> arg_dest){
int _idx =0;
if(public_attrib.has_anything()){
_idx = public_attrib.line_stream(arg_dest);
}
String _markers[];
DiagramSharedAttributeEntity _att;
for(String _tok : arg_src){
if(_tok.startsWith(ATTRIBUTE_MARKER)){
_markers = _tok.substring(ATTRIBUTE_MARKER.length()).split(ATTRIBUTE_MARKER_SPLITER_REGEX);
for(String _m : _markers){
_att = find_attrib(_m, last_proceed_result);
if(_att == null){
continue;
}
_idx = _idx + _att.line_stream(arg_dest);
}
}
else {
if(_tok.startsWith(ATTRIBUTE_MARKER_ESCAPE)){
_tok = _tok.substring(1);
}
arg_dest.add(_tok);
}
};
return _idx;
}

//split the non--attrib and attrib sections
private static final void split_attrib(String arg_txt){
int _len = ATTRIBS_SOT.length();
int _idx = arg_txt.indexOf(ATTRIBS_SOT);
if(_idx==-1){
_len =ATTRIBS_SOT_FL.length();
_idx = arg_txt.startsWith(ATTRIBS_SOT_FL)?0:-1;
}
if(_idx==-1){//no stylying
// last_non_attrib_plain_str = arg_txt;
last_attrib_plain_str = "";
return;
}
// last_non_attrib_plain_str = arg_txt.substring(0,_idx);
last_attrib_plain_str = arg_txt.substring(_idx+_len);

}

//processes the given help text, and return the new string value where has non-styling data related
public static void process_text(String arg_data){
//using the cache, as happens most of the time
if(last_proceesed_str!=null && last_proceesed_str.equals(arg_data)){
return;
}
last_proceesed_str = arg_data;
split_attrib(arg_data);//will split the text and shared styling in two strings

process_attrib_text();
// return;
}

private static final DiagramSharedAttributeEntity find_attrib(String arg_name,ArrayList<DiagramSharedAttributeEntity> arg_ctx){
for(DiagramSharedAttributeEntity _ins : arg_ctx){
if(_ins.name_equal(arg_name)){
return _ins;
}
}
return null;
}

private static final DiagramSharedAttributeEntity find_or_create_attrib(String arg_name,ArrayList<DiagramSharedAttributeEntity> arg_ctx){
DiagramSharedAttributeEntity _res = find_attrib(arg_name, arg_ctx);
if(_res!=null){
return _res;
}
_res = new DiagramSharedAttributeEntity();
_res.setStyle_name(arg_name);
arg_ctx.add(_res);
return _res;
}

private static final void merge_or_add_attribs(ArrayList<DiagramSharedAttributeEntity> arg_dest,ArrayList<DiagramSharedAttributeEntity> arg_src){
if(arg_src.size() == 0){
return;
}
for(DiagramSharedAttributeEntity _dest:arg_dest){
DiagramSharedAttributeEntity _src;
for(int a=0;a<arg_src.size();a++){
_src = arg_src.get(a);
if(_dest.merge(_src)){
arg_src.remove(a);
a = arg_src.size();
}
}
}
arg_dest.addAll(arg_src);
arg_src.clear();
}

private static void process_attrib_text(){
//no any changes on stylying
if(last_attrib_proceed_str.equals(last_attrib_plain_str) ){
return;
}
public_attrib.invalide();
last_proceed_result.clear();
last_attrib_proceed_str = last_attrib_plain_str;
if(last_attrib_proceed_str.length() == 0){
return;
}
boolean public_processing=true;

StringTokenizer _str_reader=new StringTokenizer(last_attrib_plain_str, "\n");
String line;
String[] attrib_name=null;
while(_str_reader.hasMoreTokens()){
line=_str_reader.nextToken();
if(line.startsWith(ATTRIB_DEF_SOT)){
public_processing = false;
//splitting the attrib names
attrib_name = line.substring(1).split(ATTRIB_SPLITTERS_REGEX);
continue;
}
//escaped SOT for attribs, or an attrib
if(line.startsWith(ATTRIB_ATTRIB_DEF_SOT) || line.startsWith(ATTRIB_ATTRIB_DEF_SOT_ESCAPED) || line.startsWith(ATTRIB_DEF_SOT_ESCAPE)){
line = line.substring(1);
}
if(public_processing){
public_attrib.addAttrib(line);
}else{
for(String _st : attrib_name){
if(_st.trim().isEmpty()){
continue;
}
find_or_create_attrib(_st, last_proceed_result).addAttrib(line);
}
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import com.baselet.control.basics.geom.DimensionDouble;
import com.baselet.control.enums.ElementStyle;
import com.baselet.control.shared_attrib.DiagramSharedAttributesHandler;
import com.baselet.element.facet.Facet;
import com.baselet.element.facet.PropertiesParserState;

Expand All @@ -25,6 +26,12 @@ public class PropertiesParser {

public static void parsePropertiesAndHandleFacets(NewGridElement element, PropertiesParserState state) {
List<String> propertiesText = element.getPanelAttributesAsList();
if(DiagramSharedAttributesHandler.has_any_includes()){
//new requried, since propertiesText is immutable
ArrayList<String> _ls = new ArrayList<>(propertiesText.size());
DiagramSharedAttributesHandler.process_property_text(propertiesText,_ls);
propertiesText = _ls;
}
doPreparsing(element, state, propertiesText); // at first handle autoresize (which possibly changes elementsize) and calc the textblock size
parseFacets(element, state, propertiesText, true);
}
Expand Down
18 changes: 18 additions & 0 deletions umlet-standalone/nb-configuration.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-shared-configuration>
<!--
This file contains additional configuration written by modules in the NetBeans IDE.
The configuration is intended to be shared among all the users of project and
therefore it is assumed to be part of version control checkout.
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
-->
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
<!--
Properties that influence various parts of the IDE, especially code formatting and the like.
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
That way multiple projects can share the same settings (useful for formatting rules for example).
Any value defined here will override the pom.xml file value but is only applicable to the current project.
-->
<netbeans.hint.jdkPlatform>JDK_1.8_261</netbeans.hint.jdkPlatform>
</properties>
</project-shared-configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.baselet.control.basics.geom.Point;
import com.baselet.control.constants.Constants;
import com.baselet.control.enums.Program;
import com.baselet.control.shared_attrib.DiagramSharedAttributesHandler;
import com.baselet.diagram.io.DiagramFileHandler;
import com.baselet.element.ComponentSwing;
import com.baselet.element.NewGridElement;
Expand Down Expand Up @@ -291,6 +292,7 @@ else if (ch == JOptionPane.NO_OPTION) {

public void setHelpText(String helptext) {
this.helptext = helptext;
DiagramSharedAttributesHandler.process_text(helptext);
}

public String getHelpText() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.regex.Pattern;

import com.baselet.control.constants.Constants;
import com.baselet.control.shared_attrib.DiagramSharedAttributesHandler;
import com.baselet.control.util.Utils;
import com.baselet.diagram.DiagramHandler;

Expand All @@ -14,6 +15,8 @@ public class HelpPanelChanged extends Command {

public HelpPanelChanged(String text) {
changed_to = text;
//processing shared attribs if requried
DiagramSharedAttributesHandler.process_text(text);
}

private HelpPanelChanged(String changed_from, String changed_to) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.baselet.control.basics.Converter;
import com.baselet.control.basics.geom.Point;
import com.baselet.control.constants.SystemInfo;
import com.baselet.control.shared_attrib.DiagramSharedAttributesHandler;
import com.baselet.diagram.CurrentDiagram;
import com.baselet.diagram.DiagramHandler;
import com.baselet.diagram.SelectorFrame;
Expand Down Expand Up @@ -43,7 +44,7 @@ public void mousePressed(MouseEvent me) {
h.getDrawPanel().getSelector().deselectAllWithoutUpdatePropertyPanel();
}
selector.updateSelectorInformation(); // after everything is deselected updateSelectorInformation (to update property panel content)

DiagramSharedAttributesHandler.process_text(handler.getHelpText());
if ((me.getModifiers() & SystemInfo.META_KEY.getMask()) != 0) {
SelectorFrame selframe = selector.getSelectorFrame();
selframe.setLocation(getOffset(me).getX(), getOffset(me).getY());
Expand Down

0 comments on commit 8f754d0

Please sign in to comment.