You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by se...@apache.org on 2016/03/11 14:37:02 UTC
svn commit: r1734553 - in /jmeter/trunk/src/core/org/apache/jmeter/gui/util:
JSyntaxTextArea.java JTextScrollPane.java
Author: sebb
Date: Fri Mar 11 13:37:02 2016
New Revision: 1734553
URL: http://svn.apache.org/viewvc?rev=1734553&view=rev
Log:
RSyntaxtTextArea not compatible with headless testing
Add getInstance methods that handle headless mode
Bugzilla Id: 59165
Modified:
jmeter/trunk/src/core/org/apache/jmeter/gui/util/JSyntaxTextArea.java
jmeter/trunk/src/core/org/apache/jmeter/gui/util/JTextScrollPane.java
Modified: jmeter/trunk/src/core/org/apache/jmeter/gui/util/JSyntaxTextArea.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/gui/util/JSyntaxTextArea.java?rev=1734553&r1=1734552&r2=1734553&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/gui/util/JSyntaxTextArea.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/gui/util/JSyntaxTextArea.java Fri Mar 11 13:37:02 2016
@@ -19,6 +19,7 @@
package org.apache.jmeter.gui.util;
import java.awt.Font;
+import java.awt.HeadlessException;
import java.util.Properties;
import org.apache.jmeter.util.JMeterUtils;
@@ -28,6 +29,8 @@ import org.fife.ui.rtextarea.RUndoManage
/**
* Utility class to handle RSyntaxTextArea code
+ * It's not currently possible to instantiate the RSyntaxTextArea class when running headless.
+ * So we use getInstance methods to create the class and allow for headless testing.
*/
public class JSyntaxTextArea extends RSyntaxTextArea {
@@ -43,12 +46,87 @@ public class JSyntaxTextArea extends RSy
private static final String USER_FONT_FAMILY = JMeterUtils.getPropDefault("jsyntaxtextarea.font.family", RSyntaxTextArea.getDefaultFont().getName());
private static final int USER_FONT_SIZE = JMeterUtils.getPropDefault("jsyntaxtextarea.font.size", RSyntaxTextArea.getDefaultFont().getSize());
+ /**
+ * Creates the default syntax highlighting text area. The following are set:
+ * <ul>
+ * <li>setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA)</li>
+ * <li>setCodeFoldingEnabled(true)</li>
+ * <li>setAntiAliasingEnabled(true)</li>
+ * <li>setLineWrap(true)</li>
+ * <li>setWrapStyleWord(true)</li>
+ * </ul>
+ *
+ * @param rows
+ * The number of rows for the text area
+ * @param cols
+ * The number of columns for the text area
+ * @param disableUndo
+ * true to disable undo manager
+ */
+ public static JSyntaxTextArea getInstance(int rows, int cols, boolean disableUndo) {
+ try {
+ return new JSyntaxTextArea(rows, cols, disableUndo);
+ } catch (HeadlessException e) {
+ // Allow override for unit testing only
+ if ("true".equals(System.getProperty("java.awt.headless"))) { // $NON-NLS-1$ $NON-NLS-2$
+ return new JSyntaxTextArea(disableUndo) {
+ private static final long serialVersionUID = 1L;
+ @Override
+ protected void init() {
+ try {
+ super.init();
+ } catch (HeadlessException|NullPointerException e) {
+ // ignored
+ }
+ }
+ // Override methods that would fail
+ @Override
+ public void setCodeFoldingEnabled(boolean b) { }
+ @Override
+ public void setCaretPosition(int b) { }
+ @Override
+ public void discardAllEdits() { }
+ @Override
+ public void setText(String t) { }
+ @Override
+ public boolean isCodeFoldingEnabled(){ return true; }
+ };
+ } else {
+ throw e;
+ }
+ }
+ }
+
+ /**
+ * Creates the default syntax highlighting text area. The following are set:
+ * <ul>
+ * <li>setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA)</li>
+ * <li>setCodeFoldingEnabled(true)</li>
+ * <li>setAntiAliasingEnabled(true)</li>
+ * <li>setLineWrap(true)</li>
+ * <li>setWrapStyleWord(true)</li>
+ * </ul>
+ *
+ * @param rows
+ * The number of rows for the text area
+ * @param cols
+ * The number of columns for the text area
+ */
+ public static JSyntaxTextArea getInstance(int rows, int cols) {
+ return getInstance(rows, cols, false);
+ }
+
@Deprecated
public JSyntaxTextArea() {
// For use by test code only
this(30, 50, false);
}
+ // for use by headless tests only
+ private JSyntaxTextArea(boolean dummy) {
+ disableUndo = dummy;
+ }
+
/**
* Creates the default syntax highlighting text area. The following are set:
* <ul>
@@ -63,7 +141,9 @@ public class JSyntaxTextArea extends RSy
* The number of rows for the text area
* @param cols
* The number of columns for the text area
+ * @deprecated use {@link #getInstance(int, int)} instead
*/
+ @Deprecated
public JSyntaxTextArea(int rows, int cols) {
this(rows, cols, false);
}
@@ -84,7 +164,9 @@ public class JSyntaxTextArea extends RSy
* The number of columns for the text area
* @param disableUndo
* true to disable undo manager, defaults to false
+ * @deprecated use {@link #getInstance(int, int, boolean)} instead
*/
+ @Deprecated
public JSyntaxTextArea(int rows, int cols, boolean disableUndo) {
super(rows, cols);
super.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA);
Modified: jmeter/trunk/src/core/org/apache/jmeter/gui/util/JTextScrollPane.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/gui/util/JTextScrollPane.java?rev=1734553&r1=1734552&r2=1734553&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/gui/util/JTextScrollPane.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/gui/util/JTextScrollPane.java Fri Mar 11 13:37:02 2016
@@ -23,6 +23,8 @@ import org.fife.ui.rtextarea.RTextScroll
/**
* Utility class to handle RSyntaxTextArea code
+ * It's not currently possible to instantiate the RTextScrollPane class when running headless.
+ * So we use getInstance methods to create the class and allow for headless testing.
*/
public class JTextScrollPane extends RTextScrollPane {
@@ -33,10 +35,46 @@ public class JTextScrollPane extends RTe
// for use by test code only
}
+ public static JTextScrollPane getInstance(JSyntaxTextArea scriptField, boolean foldIndicatorEnabled) {
+ try {
+ return new JTextScrollPane(scriptField, foldIndicatorEnabled);
+ } catch (NullPointerException npe) { // for headless unit testing
+ if ("true".equals(System.getProperty("java.awt.headless"))) { // $NON-NLS-1$ $NON-NLS-2$
+ return new JTextScrollPane();
+ } else {
+ throw npe;
+ }
+ }
+ }
+
+ public static JTextScrollPane getInstance(JSyntaxTextArea scriptField) {
+ try {
+ return new JTextScrollPane(scriptField);
+ } catch (NullPointerException npe) { // for headless unit testing
+ if ("true".equals(System.getProperty("java.awt.headless"))) { // $NON-NLS-1$ $NON-NLS-2$
+ return new JTextScrollPane();
+ } else {
+ throw npe;
+ }
+ }
+ }
+
+ /**
+ *
+ * @param scriptField
+ * @deprecated use {@link #getInstance(JSyntaxTextArea)} instead
+ */
+ @Deprecated
public JTextScrollPane(JSyntaxTextArea scriptField) {
super(scriptField);
}
+ /**
+ *
+ * @param scriptField
+ * @deprecated use {@link #getInstance(JSyntaxTextArea, boolean)} instead
+ */
+ @Deprecated
public JTextScrollPane(JSyntaxTextArea scriptField, boolean foldIndicatorEnabled) {
super(scriptField);
super.setFoldIndicatorEnabled(foldIndicatorEnabled);