• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            逛奔的蝸牛

            我不聰明,但我會很努力

               ::  :: 新隨筆 ::  ::  :: 管理 ::

                /**

                 * Delete the line where the cursor is positioned.

                 */

                public void deleteCurrentLine() {

                    // ab^EndPos: so EndPos is 3, there are 2 characters a, b, ^ is the flag

                    // of end of the document.

                    int length = getDocument().getLength();

                    if (length <= 0) { return; }


                    Element root = getDocument().getDefaultRootElement();

                    int pos = getCaretPosition();

                    int lineNumber = root.getElementIndex(pos); // 取得光標所在行的行號

                    Element e = root.getElement(lineNumber);


                    int start = e.getStartOffset();

                    int end = e.getEndOffset(); // 取得所在行最后回車的下一個位置, 有可能是文檔結束位置


                    if (end == root.getEndOffset()) {

                        // 如果是文檔結束,則刪除前一行的回車,且跳到文檔結束的前一位置,其為行的有效位置

                        start = Math.max(0, start - 1); // 刪除前一行最后的回車

                        end--;

                    }

                    try {

                        getDocument().remove(start, end - start);


                        // 設置光標在所在行的首行

                        lineNumber = root.getElementIndex(start);

                        e = root.getElement(lineNumber);

                        start = e.getStartOffset();

                        setCaretPosition(start);

                    } catch (BadLocationException e2) {

                        e2.printStackTrace();

                    }


                    /*

                    start = Math.max(0, start - 1); // 刪除前一行最后的回車

                    end = Math.min(end, root.getEndOffset() - 1); //

                    // 最后一行的時候,要往前跳一個位置跳過文檔結束符

                    // System.out.println("Start:" + start + ", End: " + end);


                    if (start == 0) {

                        getDocument().remove(start, end - start); // 第一行的時候,要把第一行尾的回車刪除

                    } else if (end + 1 == root.getEndOffset()) {

                        getDocument().remove(start, end - start);


                        // 最后一行時,刪除后設置光標到行的最前面

                        pos = root.getElement(root.getElementIndex(start)).getStartOffset();

                        setCaretPosition(pos);

                    } else {

                        getDocument().remove(start, end - start - 1); // 刪除前一行的回車,留這一行的回車

                        setCaretPosition(start + 1); // 設置光標在下一行的首行

                    }*/

                }

            posted on 2010-05-22 01:12 逛奔的蝸牛 閱讀(371) 評論(0)  編輯 收藏 引用 所屬分類: Java
            久久天天躁狠狠躁夜夜网站| 伊人久久大香线蕉av不卡| 国产精品成人99久久久久| 久久久无码精品亚洲日韩蜜臀浪潮 | 97久久超碰国产精品旧版 | 国产精品激情综合久久| 久久精品国产久精国产果冻传媒| 97久久综合精品久久久综合| 怡红院日本一道日本久久 | 久久亚洲AV无码精品色午夜| 国产精品永久久久久久久久久| 久久久国产精华液| 一本一本久久aa综合精品| 久久久黄色大片| 亚洲国产精品无码久久一区二区 | 久久久久亚洲精品天堂| 99久久精品免费看国产一区二区三区 | 久久夜色精品国产噜噜麻豆 | 亚洲人成无码www久久久| 亚洲七七久久精品中文国产 | 青青青国产精品国产精品久久久久| 久久久久人妻一区精品色| 国产精品久久久久久吹潮| 欧美伊香蕉久久综合类网站| 久久综合欧美成人| 伊人久久大香线蕉综合网站 | 丰满少妇人妻久久久久久4| 久久久网中文字幕| 久久亚洲精品中文字幕| 久久一区二区三区99| 国产A三级久久精品| 欧美精品一区二区精品久久| 久久夜色精品国产www| 久久综合九色综合网站| 久久精品国产只有精品66| 国产婷婷成人久久Av免费高清| 欧美麻豆久久久久久中文| 91精品国产91久久久久福利| 久久无码专区国产精品发布| 久久亚洲精品视频| 久久久久久国产a免费观看不卡|