Browse Source

REPORT-20328 sonar

persist/11.0
jinbokai 5 years ago
parent
commit
2ebff9157d
  1. 8
      designer-base/src/main/java/com/fr/design/gui/syntax/ui/rsyntaxtextarea/RSyntaxTextArea.java
  2. 15
      designer-base/src/main/java/com/fr/design/gui/syntax/ui/rsyntaxtextarea/Style.java
  3. 21
      designer-base/src/main/java/com/fr/design/gui/syntax/ui/rsyntaxtextarea/SyntaxScheme.java
  4. 2
      designer-base/src/main/java/com/fr/design/gui/syntax/ui/rsyntaxtextarea/folding/HtmlFoldParser.java
  5. 36
      designer-base/src/main/java/com/fr/design/gui/syntax/ui/rtextarea/RTextAreaBase.java
  6. 3
      designer-base/src/main/java/com/fr/design/gui/syntax/ui/rtextarea/SearchEngine.java
  7. 5
      designer-base/src/main/java/com/fr/design/gui/syntax/ui/rtextarea/VolatileImageBackgroundPainterStrategy.java

8
designer-base/src/main/java/com/fr/design/gui/syntax/ui/rsyntaxtextarea/RSyntaxTextArea.java

@ -3016,11 +3016,6 @@ private boolean fractionalFontMetricsEnabled;
return he; return he;
} }
private final boolean equal(LinkGeneratorResult e1,
LinkGeneratorResult e2) {
return e1.getSourceOffset()==e2.getSourceOffset();
}
@Override @Override
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
if (getHyperlinksEnabled() && isScanningForLinks && if (getHyperlinksEnabled() && isScanningForLinks &&
@ -3080,8 +3075,7 @@ private boolean fractionalFontMetricsEnabled;
isLinkAtOffset(RSyntaxTextArea.this, offs); isLinkAtOffset(RSyntaxTextArea.this, offs);
if (newResult!=null) { if (newResult!=null) {
// Repaint if we're at a new link now. // Repaint if we're at a new link now.
if (linkGeneratorResult==null || if (linkGeneratorResult==null || newResult.getSourceOffset() != linkGeneratorResult.getSourceOffset()) {
!equal(newResult, linkGeneratorResult)) {
repaint(); repaint();
} }
linkGeneratorResult = newResult; linkGeneratorResult = newResult;

15
designer-base/src/main/java/com/fr/design/gui/syntax/ui/rsyntaxtextarea/Style.java

@ -9,6 +9,7 @@
*/ */
package com.fr.design.gui.syntax.ui.rsyntaxtextarea; package com.fr.design.gui.syntax.ui.rsyntaxtextarea;
import com.fr.log.FineLoggerFactory;
import java.awt.Color; import java.awt.Color;
import java.awt.Font; import java.awt.Font;
import java.awt.FontMetrics; import java.awt.FontMetrics;
@ -123,15 +124,15 @@ public class Style implements Cloneable {
Style clone = null; Style clone = null;
try { try {
clone = (Style)super.clone(); clone = (Style)super.clone();
clone.foreground = foreground;
clone.background = background;
clone.font = font;
clone.underline = underline;
clone.fontMetrics = fontMetrics;
} catch (CloneNotSupportedException cnse) { // Never happens } catch (CloneNotSupportedException cnse) { // Never happens
cnse.printStackTrace(); FineLoggerFactory.getLogger().error(cnse.getMessage(), cnse);
return null; clone = null;
} }
clone.foreground = foreground;
clone.background = background;
clone.font = font;
clone.underline = underline;
clone.fontMetrics = fontMetrics;
return clone; return clone;
} }

21
designer-base/src/main/java/com/fr/design/gui/syntax/ui/rsyntaxtextarea/SyntaxScheme.java

@ -9,6 +9,7 @@
*/ */
package com.fr.design.gui.syntax.ui.rsyntaxtextarea; package com.fr.design.gui.syntax.ui.rsyntaxtextarea;
import com.fr.log.FineLoggerFactory;
import java.awt.Color; import java.awt.Color;
import java.awt.Font; import java.awt.Font;
import java.awt.Graphics2D; import java.awt.Graphics2D;
@ -121,17 +122,17 @@ public class SyntaxScheme implements Cloneable, TokenTypes {
public Object clone() { public Object clone() {
SyntaxScheme shcs = null; SyntaxScheme shcs = null;
try { try {
shcs = (SyntaxScheme)super.clone(); shcs = (SyntaxScheme) super.clone();
} catch (CloneNotSupportedException cnse) { // Never happens shcs.styles = new Style[styles.length];
cnse.printStackTrace(); for (int i = 0; i < styles.length; i++) {
return null; Style s = styles[i];
} if (s != null) {
shcs.styles = new Style[styles.length]; shcs.styles[i] = (Style) s.clone();
for (int i=0; i<styles.length; i++) { }
Style s = styles[i];
if (s!=null) {
shcs.styles[i] = (Style)s.clone();
} }
} catch (CloneNotSupportedException cnse) { // Never happens
FineLoggerFactory.getLogger().error(cnse.getMessage(), cnse);
shcs = null;
} }
return shcs; return shcs;
} }

2
designer-base/src/main/java/com/fr/design/gui/syntax/ui/rsyntaxtextarea/folding/HtmlFoldParser.java

@ -149,7 +149,7 @@ public class HtmlFoldParser implements FoldParser {
} }
// ?> or %> // ?> or %>
else if (t.startsWith(LANG_END[language])) { else if (currentFold != null && t.startsWith(LANG_END[language])) {
int phpEnd = t.getEndOffset() - 1; int phpEnd = t.getEndOffset() - 1;
currentFold.setEndOffset(phpEnd); currentFold.setEndOffset(phpEnd);
Fold parentFold = currentFold.getParent(); Fold parentFold = currentFold.getParent();

36
designer-base/src/main/java/com/fr/design/gui/syntax/ui/rtextarea/RTextAreaBase.java

@ -723,37 +723,13 @@ int currentCaretY; // Used to know when to rehighlight current line.
// If we're wrapping lines we need to check the actual y-coordinate // If we're wrapping lines we need to check the actual y-coordinate
// of the caret, not just the line number, since a single logical // of the caret, not just the line number, since a single logical
// line can span multiple physical lines. // line can span multiple physical lines.
if (getLineWrap()) { try {
try { Rectangle temp = modelToView(dot);
Rectangle temp = modelToView(dot); if (temp != null) {
if (temp!=null) { currentCaretY = temp.y;
currentCaretY = temp.y;
}
} catch (BadLocationException ble) {
ble.printStackTrace(); // Should never happen.
} }
} } catch (BadLocationException ble) {
ble.printStackTrace(); // Should never happen.
// No line wrap - we can simply check the line number (quicker).
else {
// Document doc = getDocument();
// if (doc!=null) {
// Element map = doc.getDefaultRootElement();
// int caretLine = map.getElementIndex(dot);
// Rectangle alloc = ((RTextAreaUI)getUI()).
// getVisibleEditorRect();
// if (alloc!=null)
// currentCaretY = alloc.y + caretLine*lineHeight;
// }
// Modified for code folding requirements
try {
Rectangle temp = modelToView(dot);
if (temp!=null) {
currentCaretY = temp.y;
}
} catch (BadLocationException ble) {
ble.printStackTrace(); // Should never happen.
}
} }
// Repaint current line (to fill in entire highlight), and old line // Repaint current line (to fill in entire highlight), and old line

3
designer-base/src/main/java/com/fr/design/gui/syntax/ui/rtextarea/SearchEngine.java

@ -25,6 +25,7 @@ import javax.swing.text.Caret;
import com.fr.design.gui.syntax.ui.rsyntaxtextarea.DocumentRange; import com.fr.design.gui.syntax.ui.rsyntaxtextarea.DocumentRange;
import com.fr.design.gui.syntax.ui.rsyntaxtextarea.RSyntaxTextArea; import com.fr.design.gui.syntax.ui.rsyntaxtextarea.RSyntaxTextArea;
import com.fr.design.gui.syntax.ui.rsyntaxtextarea.folding.FoldManager; import com.fr.design.gui.syntax.ui.rsyntaxtextarea.folding.FoldManager;
import org.jetbrains.annotations.NotNull;
/** /**
@ -174,6 +175,7 @@ public class SearchEngine {
* @param forward Whether we're searching forward or backward. * @param forward Whether we're searching forward or backward.
* @return The character sequence. * @return The character sequence.
*/ */
@NotNull
private static CharSequence getFindInCharSequence(RTextArea textArea, private static CharSequence getFindInCharSequence(RTextArea textArea,
int start, boolean forward) { int start, boolean forward) {
RDocument doc = (RDocument)textArea.getDocument(); RDocument doc = (RDocument)textArea.getDocument();
@ -752,7 +754,6 @@ public class SearchEngine {
int start = makeMarkAndDotEqual(textArea, forward); int start = makeMarkAndDotEqual(textArea, forward);
CharSequence findIn = getFindInCharSequence(textArea, start, forward); CharSequence findIn = getFindInCharSequence(textArea, start, forward);
if (findIn==null) return new SearchResult();
int markAllCount = 0; int markAllCount = 0;
if (context.getMarkAll()) { if (context.getMarkAll()) {

5
designer-base/src/main/java/com/fr/design/gui/syntax/ui/rtextarea/VolatileImageBackgroundPainterStrategy.java

@ -103,6 +103,9 @@ public class VolatileImageBackgroundPainterStrategy
} finally { } finally {
tracker.removeImage(i, 1); tracker.removeImage(i, 1);
} }
if(bgImage == null) {
continue;
}
bgImage.getGraphics().drawImage(i, 0,0, null); bgImage.getGraphics().drawImage(i, 0,0, null);
tracker.addImage(bgImage, 0); tracker.addImage(bgImage, 0);
try { try {
@ -114,7 +117,7 @@ public class VolatileImageBackgroundPainterStrategy
} finally { } finally {
tracker.removeImage(bgImage, 0); tracker.removeImage(bgImage, 0);
} }
} while (bgImage.contentsLost()); } while (bgImage != null && bgImage.contentsLost());
} // End of if (master!=null). } // End of if (master!=null).
else { else {
bgImage = null; bgImage = null;

Loading…
Cancel
Save