summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/NetrulesConfigurator.java
diff options
context:
space:
mode:
authorJonathan Bauer2016-11-02 15:58:03 +0100
committerJonathan Bauer2016-11-02 15:58:03 +0100
commitfcb581834613797635d2bb2afad215a66936ccb0 (patch)
tree4b4b4a28ff8fda90d0faa4fc73dd39a2d8b51a2b /dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/NetrulesConfigurator.java
parentMerge branch 'v1.1' of git.openslx.org:openslx-ng/tutor-module into v1.1 (diff)
downloadtutor-module-fcb581834613797635d2bb2afad215a66936ccb0.tar.gz
tutor-module-fcb581834613797635d2bb2afad215a66936ccb0.tar.xz
tutor-module-fcb581834613797635d2bb2afad215a66936ccb0.zip
[client] fix npe caused by bad if clause, minor color fix (now properly remembers the original color instead of assuming white, which would not be readable on white background :))
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/NetrulesConfigurator.java')
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/NetrulesConfigurator.java21
1 files changed, 15 insertions, 6 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/NetrulesConfigurator.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/NetrulesConfigurator.java
index d98c4cd6..67291c19 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/NetrulesConfigurator.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/NetrulesConfigurator.java
@@ -15,6 +15,7 @@ import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
+import javax.swing.UIManager;
import javax.swing.event.EventListenerList;
import javax.swing.text.BadLocationException;
import javax.swing.text.SimpleAttributeSet;
@@ -117,7 +118,7 @@ public class NetrulesConfigurator extends NetrulesConfiguratorLayout {
currentLine += currentRule.port + " \t ";
currentLine += currentRule.direction.name();
decodedRules += currentLine
- + (it.hasNext() ? System.lineSeparator() : "");
+ + (it.hasNext() ? "\n" : "");
}
return decodedRules;
}
@@ -142,11 +143,13 @@ public class NetrulesConfigurator extends NetrulesConfiguratorLayout {
prunedRawNetRules = prunedRawNetRules.replaceAll("(?m)\\s*$", "");
// split it line by line
- List<String> netRules = Arrays.asList(prunedRawNetRules.split("["
- + System.lineSeparator() + "]"));
+ List<String> netRules = Arrays.asList(prunedRawNetRules.split("\n"));
for (int i = 0; i < netRules.size(); i++) {
final String ruleLine = netRules.get(i);
- if (ruleLine == null || ruleLine.isEmpty()) {
+ if (ruleLine == null) {
+ continue;
+ }
+ if (ruleLine.isEmpty()) {
netRules.remove(i);
continue;
}
@@ -303,6 +306,12 @@ public class NetrulesConfigurator extends NetrulesConfiguratorLayout {
// TODO still buggy with text colors: the marking works fine
// but when trying to input new text, funny things happen
private void markText(final String txt, final Color color) {
+ // get original foreground color
+ Color fgOrigColor = UIManager.getDefaults().getColor("ColorChooser.foreground");
+ if (fgOrigColor == null) {
+ // use white as fallback
+ fgOrigColor = Color.WHITE;
+ }
SimpleAttributeSet set = new SimpleAttributeSet();
StyleConstants.setForeground(set, color);
StyleConstants.setBold(set, color == Color.red);
@@ -310,7 +319,7 @@ public class NetrulesConfigurator extends NetrulesConfiguratorLayout {
try {
for (int pos = 0; pos < doc.getLength() - txt.length() + 1; ++pos) {
String current = doc.getText(pos, txt.length());
- if (current.endsWith(System.lineSeparator())) {
+ if (current.endsWith("\n")) {
current = current.substring(0, current.length() - 1);
}
if (current.equals(txt)) {
@@ -326,7 +335,7 @@ public class NetrulesConfigurator extends NetrulesConfiguratorLayout {
// resetting the char attr to what they were before (buggy)
tpNetworkRules.setStyledDocument(doc);
- StyleConstants.setForeground(set, Color.WHITE);
+ StyleConstants.setForeground(set, fgOrigColor);
StyleConstants.setBold(set, false);
tpNetworkRules.setCharacterAttributes(set, true);
}