Skip to content

Commit

Permalink
update: modify paragraph space
Browse files Browse the repository at this point in the history
  • Loading branch information
muedsa committed Jun 3, 2021
1 parent bd1f687 commit 08e9cd7
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 12 deletions.
5 changes: 5 additions & 0 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
<li>format chapter</li>
<li>content before first chapter</li>
</ul>
<h3>2021.06.03<h3>
<ul>
<li>Setting: modify paragraph space</li>
</ul>
<hr/>
]]>
</change-notes>
Expand Down
40 changes: 32 additions & 8 deletions src/com/muedsa/intellij/textReader/composes/ReaderWindow.form
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
<properties/>
<border type="none"/>
<children>
<grid id="311f4" layout-manager="GridLayoutManager" row-count="11" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="311f4" layout-manager="GridLayoutManager" row-count="12" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="2" bottom="0" right="0"/>
<constraints/>
<properties/>
Expand Down Expand Up @@ -170,7 +170,7 @@
<grid id="c0b1c" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="1" fill="1" indent="0" use-parent-layout="false">
<grid row="7" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="1" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="212" height="35"/>
</grid>
</constraints>
Expand Down Expand Up @@ -200,7 +200,7 @@
<grid id="1c385" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="7" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
<grid row="8" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
Expand Down Expand Up @@ -228,7 +228,7 @@
<grid id="5cfd6" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="8" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<grid row="9" column="0" 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"/>
Expand Down Expand Up @@ -256,7 +256,7 @@
<grid id="f3f32" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<grid row="6" column="0" 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"/>
Expand All @@ -280,7 +280,7 @@
<grid id="7db19" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="10" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<grid row="11" column="0" 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"/>
Expand Down Expand Up @@ -331,12 +331,12 @@
</grid>
<vspacer id="b79a">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<vspacer id="21a47">
<constraints>
<grid row="9" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<grid row="10" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<grid id="ba1c0" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
Expand Down Expand Up @@ -387,6 +387,30 @@
</component>
</children>
</grid>
<grid id="78234" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="a3df6" class="javax.swing.JLabel">
<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"/>
</constraints>
<properties>
<text value="段落间隔"/>
</properties>
</component>
<component id="ccf2c" class="javax.swing.JSpinner" binding="paragraphSpaceSpinner">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="7" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
</children>
</grid>
</children>
</grid>
</children>
Expand Down
11 changes: 11 additions & 0 deletions src/com/muedsa/intellij/textReader/composes/ReaderWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class ReaderWindow {
private JSpinner firstLineIndentSpinner;
private JComboBox<String> fontFamilyEl;
private JButton clearButton;
private JSpinner paragraphSpaceSpinner;

private Project project;
private ToolWindow toolWindow;
Expand Down Expand Up @@ -91,6 +92,11 @@ private void createUIComponents(){
firstLineIndentSpinner.setModel(firstLineIndentSpinnerModel);
firstLineIndentSpinner.addChangeListener(e -> updateFirstLineIndent());

//段落间隔
SpinnerModel paragraphSpaceSpinnerModel = new SpinnerNumberModel(1, 0, 4, 1);
paragraphSpaceSpinner.setModel(paragraphSpaceSpinnerModel);
paragraphSpaceSpinner.addChangeListener(e -> updateParagraphSpace());

//标题解析最大字数限制设置
SpinnerModel maxLineSizeSpinnerModel = new SpinnerNumberModel(20, 1, 200, 1);
maxLineSizeSpinner.setModel(maxLineSizeSpinnerModel);
Expand Down Expand Up @@ -246,6 +252,11 @@ private void updateFirstLineIndent(){
styledDocument.setParagraphAttributes(0, styledDocument.getLength(), attributes, false);
}

private void updateParagraphSpace(){
ChapterUtil.CONFIG_PARAGRAPH_SPACE = (int) paragraphSpaceSpinner.getValue();
setTextContent();
}

public JPanel getContent(){
return readerPanel;
}
Expand Down
18 changes: 14 additions & 4 deletions src/com/muedsa/intellij/textReader/util/ChapterUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
public class ChapterUtil {

public static final String LF_CR = "\n\r";
public static final String LF = "\n";
public static final char HALF_WIDTH_SPACE = ' ';
public static final char FULL_WIDTH_SPACE = ' ';

public static int CONFIG_PARAGRAPH_SPACE = 1;

public static Vector<Chapter> getChapters(TextFile textFile, int maxLineSize, Pattern pattern) {
Vector<Chapter> list = new Vector<>();
Expand Down Expand Up @@ -93,13 +98,18 @@ public static String formatChapterContent(TextFile textFile, Chapter chapter){
}

public static String formatChapterContent(String chapterContent){
String[] paragraphs = StringUtils.split(chapterContent, LF_CR);
chapterContent = StringUtils.replace(chapterContent, LF_CR, LF);
String[] paragraphs = StringUtils.split(chapterContent, LF);
StringBuilder formatContentBuilder = new StringBuilder(chapterContent.length());
for(String paragraph : paragraphs){
if(StringUtils.isNotBlank(paragraph)){
String newParagraph = trim(paragraph);
formatContentBuilder.append(newParagraph);
formatContentBuilder.append(LF_CR);
int i = 0;
while(CONFIG_PARAGRAPH_SPACE + 1 > 0 && i < CONFIG_PARAGRAPH_SPACE + 1){
formatContentBuilder.append(LF);
i++;
}
}
}
return formatContentBuilder.toString();
Expand All @@ -110,10 +120,10 @@ public static String trim(String text) {
int st = 0;
int len = val.length;

while ((st < len) && (val[st] <= ' ' || val[st] == ' ')) {
while ((st < len) && (val[st] <= HALF_WIDTH_SPACE || val[st] == FULL_WIDTH_SPACE)) {
st++;
}
while ((st < len) && (val[len - 1] <= ' ' || val[st] == ' ')) {
while ((st < len) && (val[len - 1] <= HALF_WIDTH_SPACE || val[st] == FULL_WIDTH_SPACE)) {
len--;
}
return ((st > 0) || (len < val.length)) ? text.substring(st, len) : text;
Expand Down

0 comments on commit 08e9cd7

Please sign in to comment.