• <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>

            逛奔的蝸牛

            我不聰明,但我會(huì)很努力

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

                /**

                 * 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); // 取得光標(biāo)所在行的行號(hào)

                    Element e = root.getElement(lineNumber);


                    int start = e.getStartOffset();

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


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

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

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

                        end--;

                    }

                    try {

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


                        // 設(shè)置光標(biāo)在所在行的首行

                        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); //

                    // 最后一行的時(shí)候,要往前跳一個(gè)位置跳過文檔結(jié)束符

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


                    if (start == 0) {

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

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

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


                        // 最后一行時(shí),刪除后設(shè)置光標(biāo)到行的最前面

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

                        setCaretPosition(pos);

                    } else {

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

                        setCaretPosition(start + 1); // 設(shè)置光標(biāo)在下一行的首行

                    }*/

                }

            posted on 2010-05-22 01:12 逛奔的蝸牛 閱讀(372) 評(píng)論(0)  編輯 收藏 引用 所屬分類: Java
            婷婷久久综合九色综合九七| 理论片午午伦夜理片久久| 久久夜色精品国产噜噜亚洲AV| 国产综合久久久久| 久久一区二区三区免费| 亚洲级αV无码毛片久久精品| 久久国产乱子精品免费女| 亚洲欧美久久久久9999| 久久精品无码一区二区三区| 久久亚洲精品无码VA大香大香| 精品国产VA久久久久久久冰| 久久精品综合一区二区三区| 久久久久久亚洲AV无码专区| 久久青青色综合| 精品久久久久久国产牛牛app| 国产精品9999久久久久| 思思久久99热只有频精品66| 久久精品国产亚洲5555| 99久久精品日本一区二区免费| 思思久久精品在热线热| 色偷偷88欧美精品久久久| 国产精品一久久香蕉国产线看| 中文字幕日本人妻久久久免费| 老司机午夜网站国内精品久久久久久久久| 国产成人久久精品区一区二区| 中文精品久久久久人妻不卡| 热久久视久久精品18| 久久青青国产| 精品久久久久久无码不卡| 久久综合久久鬼色| 亚洲国产日韩欧美久久| 久久受www免费人成_看片中文| 久久人人爽人人爽人人片AV东京热| 91精品国产91久久久久久青草 | 久久96国产精品久久久| 国产精品久久99| 国产精品免费久久久久电影网| 青青青青久久精品国产| 久久国产精品免费一区| 香蕉久久永久视频| 国产精品亚洲综合久久|