~ubuntu-branches/ubuntu/lucid/groovy/lucid

« back to all changes in this revision

Viewing changes to src/main/groovy/ui/text/AutoIndentAction.groovy

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath, Torsten Werner, Varun Hiremath
  • Date: 2009-04-01 19:24:19 UTC
  • mfrom: (3.2.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090401192419-c5mpylqhcdkv3zuv
Tags: 1.6.0-1
[ Torsten Werner ]
* New upstream release (Closes: #521648)
* Remove Build-Depends: libclassworlds-java.
* Switch to source and target version 1.5.

[ Varun Hiremath ]
* Fix build.xml file
* Add ivy to Build-Depends
* Remove unnecessary Depends -- collections3, mx4j and xpp3 
* Add build.diff patch to fix a build error
* Use quilt to manage patches
* Update manpage (Closes: #507862)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2008 the original author or authors.
 
3
 *
 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
 
5
 * you may not use this file except in compliance with the License.
 
6
 * You may obtain a copy of the License at
 
7
 *
 
8
 *     http://www.apache.org/licenses/LICENSE-2.0
 
9
 *
 
10
 * Unless required by applicable law or agreed to in writing, software
 
11
 * distributed under the License is distributed on an "AS IS" BASIS,
 
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
13
 * See the License for the specific language governing permissions and
 
14
 * limitations under the License.
 
15
 */
 
16
 
 
17
package groovy.ui.text
 
18
 
 
19
import java.awt.event.ActionEvent
 
20
import javax.swing.AbstractAction
 
21
import javax.swing.text.AttributeSet
 
22
import javax.swing.text.SimpleAttributeSet
 
23
 
 
24
class AutoIndentAction extends AbstractAction {
 
25
    AttributeSet simpleAttributeSet = new SimpleAttributeSet()
 
26
 
 
27
    public void actionPerformed(ActionEvent evt) {
 
28
        def inputArea = evt.source
 
29
        def rootElement = inputArea.document.defaultRootElement
 
30
        def cursorPos = inputArea.getCaretPosition()
 
31
        int rowNum = rootElement.getElementIndex(cursorPos)
 
32
        def rowElement = rootElement.getElement(rowNum)
 
33
        int startOffset = rowElement.getStartOffset()
 
34
        int endOffset = rowElement.getEndOffset()
 
35
        String rowContent = inputArea.document.getText(startOffset, endOffset - startOffset);
 
36
        String contentBeforeCursor = inputArea.document.getText(startOffset, cursorPos - startOffset);
 
37
        String whitespaceStr = ''
 
38
        def matcher = (rowContent =~ /(?m)^(\s*).*\n$/)
 
39
        matcher.each { all, ws ->
 
40
            whitespaceStr = ws
 
41
        }
 
42
 
 
43
        if (contentBeforeCursor ==~ /(\s)*/) {
 
44
            whitespaceStr = contentBeforeCursor
 
45
        }
 
46
 
 
47
        inputArea.document.insertString(cursorPos, '\n' + whitespaceStr, simpleAttributeSet)
 
48
    }
 
49
}
 
 
b'\\ No newline at end of file'