01: /*
02: * CSSMode.java
03: *
04: * Copyright (C) 2002 Peter Graves
05: * $Id: CSSMode.java,v 1.1.1.1 2002/09/24 16:09:28 piso Exp $
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License
09: * as published by the Free Software Foundation; either version 2
10: * of the License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public License
18: * along with this program; if not, write to the Free Software
19: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20: */
21:
22: package org.armedbear.j;
23:
24: import java.awt.event.KeyEvent;
25:
26: public final class CSSMode extends AbstractMode implements Constants,
27: Mode {
28: private static final CSSMode mode = new CSSMode();
29:
30: private CSSMode() {
31: super (CSS_MODE, CSS_MODE_NAME);
32: }
33:
34: public static CSSMode getMode() {
35: return mode;
36: }
37:
38: public Formatter getFormatter(Buffer buffer) {
39: return new CSSFormatter(buffer);
40: }
41:
42: protected void setKeyMapDefaults(KeyMap km) {
43: km.mapKey(KeyEvent.VK_ENTER, 0, "newlineAndIndent");
44: }
45:
46: public boolean canIndent() {
47: return true;
48: }
49:
50: public boolean canIndentPaste() {
51: return false;
52: }
53:
54: public int getCorrectIndentation(Line line, Buffer buffer) {
55: final int indentSize = buffer.getIndentSize();
56: final Line model = findModel(line);
57: if (model == null)
58: return 0;
59: final int modelIndent = buffer.getIndentation(model);
60: if (model.getText().trim().endsWith("{"))
61: return modelIndent + indentSize;
62: return modelIndent;
63: }
64:
65: private Line findModel(Line line) {
66: Line model = line.previous();
67: while (model != null && model.isBlank())
68: model = model.previous();
69: return model;
70: }
71:
72: public boolean isIdentifierStart(char c) {
73: return startChars.indexOf(c) >= 0;
74: }
75:
76: public boolean isIdentifierPart(char c) {
77: return partChars.indexOf(c) >= 0;
78: }
79:
80: private static final String startChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
81:
82: private static final String partChars = "-ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
83: }
|