Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/jext/textarea/NextLineIndent.java


1   /*
2    * 19:42:39 17/01/00
3    *
4    * NextLineIndent.java - Go to start of next line no indent
5    * Copyright (C) 1998-1999 Romain Guy
6    * romain.guy@jext.org
7    * www.jext.org
8    *
9    * This program is free software; you can redistribute it and/or
10   * modify it under the terms of the GNU General Public License
11   * as published by the Free Software Foundation; either version 2
12   * of the License, or any later version.
13   *
14   * This program is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17   * GNU General Public License for more details.
18   *
19   * You should have received a copy of the GNU General Public License
20   * along with this program; if not, write to the Free Software
21   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22   */
23  
24  package org.jext.textarea;
25  
26  import java.awt.event.ActionEvent;
27  import java.awt.event.ActionListener;
28  
29  import javax.swing.text.*;
30  import org.jext.*;
31  import org.gjt.sp.jedit.textarea.*;
32  
33  public final class NextLineIndent extends MenuAction
34  {
35    public NextLineIndent()
36    {
37      super("next_line_indent");
38    }
39  
40    public void actionPerformed(ActionEvent evt)
41    {
42      JEditTextArea textArea = getTextArea(evt);
43  
44      Document doc = textArea.getDocument();
45      Element map = doc.getDefaultRootElement();
46  
47      int caret = map.getElementIndex(textArea.getCaretPosition());
48      if (map.getElementCount() == caret + 1)
49      {
50        textArea.setCaretPosition(map.getElement(caret).getStartOffset());
51        return;
52      }
53  
54      Element lineElement = map.getElement(caret + 1);
55      int start = lineElement.getStartOffset();
56      int length = lineElement.getEndOffset() - 1 - start;
57  
58      char c;
59      int i = 0;
60      String _line = textArea.getText(start, length);
61  
62  out:  for ( ; i < length; i++)
63      {
64        c = _line.charAt(i);
65        switch(c)
66        {
67          case ' ': case '\t':
68            break;
69          default:
70            break out;
71        }
72      }
73  
74      textArea.setCaretPosition(start + i);
75    }
76  }
77  
78  // End of NextLineIndent.java