Skip to content

Commit 1518b78

Browse files
author
Open Lowcode SAS
committed
Close #227
1 parent 4e8293d commit 1518b78

File tree

3 files changed

+59
-14
lines changed

3 files changed

+59
-14
lines changed

src/org/openlowcode/tools/misc/SplitString.java

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,14 @@
2222
* SAS</a>
2323
*
2424
*/
25+
/**
26+
* @author demau
27+
*
28+
*/
2529
public class SplitString {
2630
private ArrayList<String> stringsplit;
2731
private ArrayList<Boolean> transitions;
32+
private ArrayList<Boolean> hasbullet;
2833

2934
/**
3035
* @return the number of sections of this string
@@ -53,19 +58,31 @@ public boolean getTransitionAt(int index) {
5358
return transitions.get(index).booleanValue();
5459
}
5560

61+
/**
62+
* provides information if the current section is a bullet
63+
*
64+
* @param index index of the section
65+
* @return true if the section is a bullet, false else
66+
* @since 1.12
67+
*/
68+
public boolean getBulletAt(int index) {
69+
return hasbullet.get(index).booleanValue();
70+
}
71+
5672
/**
5773
* create a Split chain, parsing the string for new lines only (\n or \r\n)
58-
* (carriage returns are kept in sections), or for all
74+
* (carriage returns are kept in sections), or for all. Also manages bullet
75+
* points in the text
5976
*
6077
* @param chaintosplit the string to split
6178
* @param onlymajor if true, only new lines are considered, if false, new
6279
* lines and carriage returns are considered
63-
* @since 1.5
80+
* @since 1.5
6481
*/
6582
public SplitString(String chaintosplit, boolean onlymajor) {
6683
stringsplit = new ArrayList<String>();
6784
transitions = new ArrayList<Boolean>();
68-
85+
hasbullet = new ArrayList<Boolean>();
6986
boolean lastsplitismajor = true;
7087
StringBuffer currentstring = new StringBuffer();
7188
int parseindex = 0;
@@ -78,18 +95,20 @@ public SplitString(String chaintosplit, boolean onlymajor) {
7895
}
7996
if (currentchar == 10) { // \n
8097
specialcharacter = true;
81-
98+
8299
if (lastisbackslashr) {
83100
// treats \r\n as a maj carriage return ()
84101
stringsplit.add(currentstring.toString());
102+
hasbullet.add(hasBullet(currentstring.toString()));
85103
transitions.add(new Boolean(lastsplitismajor));
86104
lastsplitismajor = true;
87105
currentstring = new StringBuffer();
88-
106+
89107
} else {
90108
// treats \n as minor carriage return (print as \n)
91109
if (!onlymajor) {
92110
stringsplit.add(currentstring.toString());
111+
hasbullet.add(hasBullet(currentstring.toString()));
93112
transitions.add(new Boolean(lastsplitismajor));
94113
lastsplitismajor = false;
95114
currentstring = new StringBuffer();
@@ -104,22 +123,38 @@ public SplitString(String chaintosplit, boolean onlymajor) {
104123
// treats \r\n as a maj carriage return ()
105124
specialcharacter = true;
106125
stringsplit.add(currentstring.toString());
126+
hasbullet.add(hasBullet(currentstring.toString()));
107127
transitions.add(new Boolean(lastsplitismajor));
108128
lastsplitismajor = true;
109129
lastisbackslashr = false;
110130
currentstring = new StringBuffer();
111-
112-
113-
}
131+
132+
}
114133
currentstring.append((char) currentchar);
115-
134+
116135
}
117136
if (currentchar == 13)
118137
lastisbackslashr = true;
119138
parseindex++;
120139
}
121140
stringsplit.add(currentstring.toString());
122141
transitions.add(new Boolean(lastsplitismajor));
142+
hasbullet.add(hasBullet(currentstring.toString()));
143+
}
144+
145+
/**
146+
*
147+
* @param string a String
148+
* @return true if a bullet is detected, false else
149+
* @since 1.12
150+
*/
151+
public static boolean hasBullet(String string) {
152+
153+
if (string.indexOf('\u25CF') >= 0)
154+
return true;
155+
if (string.indexOf('\u2022') >= 0)
156+
return true;
157+
return false;
123158
}
124159

125160
/**

src/org/openlowcode/tools/richtext/Paragraph.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,7 @@ public void handle(KeyEvent keyevent) {
12101210
+ splitstring.getNumberOfSections() + " --- ");
12111211
for (int i = 0; i < splitstring.getNumberOfSections(); i++)
12121212
logger.finest(" |" + splitstring.getTransitionAt(i) + "| "
1213+
+ splitstring.getBulletAt(i) + "| "
12131214
+ splitstring.getSplitStringAt(i));
12141215
logger.finest(" ---------------------------------------------------------------");
12151216
if (splitstring.getNumberOfSections() > 1) {

src/org/openlowcode/tools/richtext/RichTextArea.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ void mergeCurrentParagraphWithPrevious() {
335335
}
336336

337337
/**
338-
* insert a multi-line split string at the current carret. Only works with SplitString with several sections
338+
* insert a multi-line split string at the current carret. Only works with SplitString with several sections. Also manages the fact text may contain bullets.
339339
* @param templatetext a FormattedText that has the target format for the inserted text
340340
*
341341
* @param splistring a splitstring with
@@ -347,16 +347,25 @@ void insertSplitStringAtCarret(SplitString splitstring, FormattedText templatete
347347
// split section at current carret
348348
Paragraph newprevious = activeparagraph.generateParagraphBeforeCarret();
349349
Paragraph newnext = activeparagraph.generateParagraphAfterCarret();
350-
350+
boolean firsthasbullet = splitstring.getBulletAt(0);
351351
// add text before first carriage return to before section
352-
newprevious.addTextAtEnd(splitstring.getSplitStringAt(0));
352+
if (!firsthasbullet) newprevious.addTextAtEnd(splitstring.getSplitStringAt(0));
353353
logger.finest("added text in new previous "+splitstring.getSplitStringAt(0));
354354
// if intermediate,add each intermediate at standaalone with previous section formatting
355355
ArrayList<Paragraph> middleparagraphestoadd = new ArrayList<Paragraph>();
356-
for (int i=1;i<splitstring.getNumberOfSections()-1;i++) {
356+
int startindex = (firsthasbullet?0:1);
357+
for (int i=startindex;i<splitstring.getNumberOfSections()-1;i++) {
358+
357359
Paragraph paragraph = new Paragraph(this.richtext,this.editable, this);
360+
boolean bullet = splitstring.getBulletAt(i);
361+
String textstring = splitstring.getSplitStringAt(i);
362+
if (bullet) {
363+
paragraph.setBulletParagraph();
364+
textstring=textstring.replace('\u25CF',' ').replace('\u2022',' ').trim();
365+
}
358366
FormattedText formattedtext = new FormattedText(templatetext,paragraph);
359-
formattedtext.refreshText(splitstring.getSplitStringAt(i));
367+
368+
formattedtext.refreshText(textstring);
360369
paragraph.addText(formattedtext);
361370
middleparagraphestoadd.add(paragraph);
362371
}

0 commit comments

Comments
 (0)