From fcb581834613797635d2bb2afad215a66936ccb0 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Wed, 2 Nov 2016 15:58:03 +0100 Subject: [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 :)) --- .../dozmod/gui/control/NetrulesConfigurator.java | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'dozentenmodul/src/main/java') 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 netRules = Arrays.asList(prunedRawNetRules.split("[" - + System.lineSeparator() + "]")); + List 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); } -- cgit v1.2.3-55-g7522