Package org.qdl_lang.gui
Class LineUtil
- java.lang.Object
-
- org.qdl_lang.gui.LineUtil
-
public class LineUtil extends Object
Do line operations on a text area. This allows you to insert a line, cut, copy or paste a line and move lines. This is generally intended to be used as a utility for theSwingTerminal
.Created by Jeff Gaynor
on 3/17/23 at 7:39 AM
-
-
Constructor Summary
Constructors Constructor Description LineUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description protected static boolean
checkPosition(List<String> lines, int position)
Checks that the position of the caret is in the list of lines.protected static boolean
checkString(String out)
protected static ArrayList<String>
doClipboardCopyorCut(ArrayList<String> lines, int position, boolean isCut)
static String
doOperation(String text, int lineNumber, String operation)
protected static ArrayList<String>
duplicateLine(ArrayList<String> lines, int position)
static Clipboard
getClipboard()
static int
getFirstNonwhitespaceIndex(String string)
protected static boolean
hasClipboard()
static void
main(String[] args)
protected static ArrayList<String>
pasteLines(ArrayList<String> lines, int position)
protected static void
testInputForm()
protected static void
testLineModes()
protected static ArrayList<String>
toggleComment(ArrayList<String> lines, int lineNumber)
static String
toInputForm(String in, boolean isLongForm)
Converts a string (from the clipboard) to input form.static ArrayList<String>
toLines(String text)
Has to be an array list to get remove() and other methods.
-
-
-
Field Detail
-
COPY_LINE
public static final String COPY_LINE
- See Also:
- Constant Field Values
-
DUPLICATE_LINE
public static final String DUPLICATE_LINE
- See Also:
- Constant Field Values
-
PASTE_LINES
public static final String PASTE_LINES
- See Also:
- Constant Field Values
-
CUT_LINE
public static final String CUT_LINE
- See Also:
- Constant Field Values
-
UP_LINE
public static final String UP_LINE
- See Also:
- Constant Field Values
-
DOWN_LINE
public static final String DOWN_LINE
- See Also:
- Constant Field Values
-
TOGGLE_COMMENT_LINE
public static final String TOGGLE_COMMENT_LINE
- See Also:
- Constant Field Values
-
JOIN_LINE
public static final String JOIN_LINE
- See Also:
- Constant Field Values
-
-
Method Detail
-
doOperation
public static String doOperation(String text, int lineNumber, String operation) throws IOException, UnsupportedFlavorException
-
toLines
public static ArrayList<String> toLines(String text)
Has to be an array list to get remove() and other methods.- Parameters:
text
-- Returns:
-
checkPosition
protected static boolean checkPosition(List<String> lines, int position)
Checks that the position of the caret is in the list of lines. True if ok, false otherwise.- Parameters:
lines
-position
-- Returns:
-
getClipboard
public static Clipboard getClipboard()
-
hasClipboard
protected static boolean hasClipboard()
-
doClipboardCopyorCut
protected static ArrayList<String> doClipboardCopyorCut(ArrayList<String> lines, int position, boolean isCut) throws IOException, UnsupportedFlavorException
-
duplicateLine
protected static ArrayList<String> duplicateLine(ArrayList<String> lines, int position)
-
pasteLines
protected static ArrayList<String> pasteLines(ArrayList<String> lines, int position) throws IOException, UnsupportedFlavorException
-
toggleComment
protected static ArrayList<String> toggleComment(ArrayList<String> lines, int lineNumber)
-
getFirstNonwhitespaceIndex
public static int getFirstNonwhitespaceIndex(String string)
-
toInputForm
public static String toInputForm(String in, boolean isLongForm)
Converts a string (from the clipboard) to input form. This checks if it is a string and if not just returns it. If it is, then shoirt form is a single line of input form, long form break it up into lines and formats each one as a concatenation. The latter is really useful when pasting things like long formatted JSON blobs.- Parameters:
in
-isLongForm
-- Returns:
-
checkString
protected static boolean checkString(String out)
-
-