• <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
            国产午夜精品久久久久免费视| 久久亚洲精品中文字幕三区| 久久久久久国产精品无码下载| 人妻无码久久精品| 亚洲国产美女精品久久久久∴| 国产精品久久午夜夜伦鲁鲁| 国产三级观看久久| 思思久久99热只有频精品66| 精品国产乱码久久久久久郑州公司| 91精品久久久久久无码| 国产香蕉久久精品综合网| 国产AⅤ精品一区二区三区久久 | 亚洲精品乱码久久久久久蜜桃图片| 狠狠色综合网站久久久久久久高清 | yy6080久久| 国产精品亚洲综合专区片高清久久久| 久久伊人色| 99热精品久久只有精品| 漂亮人妻被黑人久久精品| 久久伊人中文无码| 久久99国产精品99久久| 亚洲愉拍99热成人精品热久久| 99久久婷婷国产综合精品草原| 浪潮AV色综合久久天堂| 久久亚洲熟女cc98cm| 久久亚洲中文字幕精品一区四| 热99re久久国超精品首页| 久久婷婷五月综合97色| 热久久视久久精品18| 亚洲人成无码久久电影网站| 精品久久久久久国产免费了| 成人综合伊人五月婷久久| 久久婷婷五月综合色奶水99啪| 久久精品国产亚洲AV蜜臀色欲| 欧美日韩中文字幕久久久不卡| 久久久久国产日韩精品网站| 国产福利电影一区二区三区久久久久成人精品综合 | 国产精品美女久久福利网站| 欧美精品一区二区久久| 色综合久久中文字幕综合网| 久久久精品人妻无码专区不卡|