Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
EvA2
EvA2
Commits
d541e988
Commit
d541e988
authored
Dec 15, 2015
by
Fabian Becker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Subscript indices in PropertySheetPanel
- add subscriptIndices to StringTools - add tests
parent
ebe2e819
Pipeline
#50
passed with stage
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
6 deletions
+48
-6
src/main/java/eva2/gui/PropertySheetPanel.java
src/main/java/eva2/gui/PropertySheetPanel.java
+10
-6
src/main/java/eva2/tools/StringTools.java
src/main/java/eva2/tools/StringTools.java
+26
-0
src/test/java/eva2/tools/StringToolsTest.java
src/test/java/eva2/tools/StringToolsTest.java
+12
-0
No files found.
src/main/java/eva2/gui/PropertySheetPanel.java
View file @
d541e988
...
...
@@ -300,10 +300,7 @@ public final class PropertySheetPanel extends JPanel implements PropertyChangeLi
continue
;
}
// end try
// Add some specific display for some greeks here
name
=
StringTools
.
translateGreek
(
name
);
name
=
StringTools
.
humaniseCamelCase
(
name
);
propertyTableModel
.
addRow
(
new
Object
[]{
name
,
newView
});
propertyTableModel
.
addRow
(
new
Object
[]{
prepareLabel
(
name
),
newView
});
}
propertyTable
.
setToolTips
(
toolTips
);
...
...
@@ -327,6 +324,15 @@ public final class PropertySheetPanel extends JPanel implements PropertyChangeLi
setVisible
(
true
);
}
private
String
prepareLabel
(
String
label
)
{
// Add some specific display for some greeks here
label
=
StringTools
.
translateGreek
(
label
);
label
=
StringTools
.
humaniseCamelCase
(
label
);
label
=
StringTools
.
subscriptIndices
(
label
);
label
=
"<html>"
+
label
+
"</html>"
;
return
label
;
}
private
static
JPanel
buildTitledSeperator
(
String
title
)
{
JPanel
titledSeperator
=
new
JPanel
(
new
GridBagLayout
());
...
...
@@ -558,8 +564,6 @@ public final class PropertySheetPanel extends JPanel implements PropertyChangeLi
return
infoPanel
;
}
/**
* Get the html help file name.
*
...
...
src/main/java/eva2/tools/StringTools.java
View file @
d541e988
...
...
@@ -479,6 +479,9 @@ public final class StringTools {
}
/**
* Takes a full package name and returns the string
* after the last period (usually the class name).
*
* @param value The string to cut
* @return Returns the class Name without package.
*/
...
...
@@ -491,6 +494,13 @@ public final class StringTools {
return
className
;
// now is shortName
}
/**
* Takes a string and looks for greek letter names. If found,
* replaces them by their greek unicode counterparts.
*
* @param name A string
* @return String with greek letter names replaced
*/
public
static
String
translateGreek
(
String
name
)
{
// Add some specific display for some greeks here
final
String
[][]
mapping
=
{
...
...
@@ -549,5 +559,21 @@ public final class StringTools {
return
name
;
}
/**
* Takes a string and looks for trailing numbers. If present those numbers will
* be replaced by a HTML subscript. Make sure to wrap inside a html block when
* displaying as part of a JLabel.
*
* @param label
* @return
*/
public
static
String
subscriptIndices
(
String
label
)
{
// Trailing numbers
Pattern
p
=
Pattern
.
compile
(
"(\\d+)$"
);
Matcher
m
=
p
.
matcher
(
label
);
return
m
.
replaceFirst
(
"<sub>$1</sub>"
);
}
}
src/test/java/eva2/tools/StringToolsTest.java
View file @
d541e988
...
...
@@ -98,4 +98,16 @@ public class StringToolsTest {
assertEquals
(
"taur"
,
StringTools
.
translateGreek
(
"taur"
));
assertEquals
(
"taur12"
,
StringTools
.
translateGreek
(
"taur12"
));
}
@Test
public
void
testSubscriptIndices
()
throws
Exception
{
// Doesn't alter numbers at the start or mid string
assertEquals
(
"12derp"
,
StringTools
.
subscriptIndices
(
"12derp"
));
assertEquals
(
"der12p"
,
StringTools
.
subscriptIndices
(
"der12p"
));
// Replaces trailing numbers with a sub html tag
assertEquals
(
"derp<sub>12</sub>"
,
StringTools
.
subscriptIndices
(
"derp12"
));
assertEquals
(
"This is a string <sub>12</sub>"
,
StringTools
.
subscriptIndices
(
"This is a string 12"
));
assertEquals
(
"ϕ<sub>10</sub>"
,
StringTools
.
subscriptIndices
(
"ϕ10"
));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment