KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > armedbear > j > MakefileMode


1 /*
2  * MakefileMode.java
3  *
4  * Copyright (C) 2000-2002 Peter Graves
5  * $Id: MakefileMode.java,v 1.1.1.1 2002/09/24 16:08:00 piso Exp $
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * 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.InputEvent JavaDoc;
25 import java.awt.event.KeyEvent JavaDoc;
26
27 public final class MakefileMode extends AbstractMode implements Constants, Mode
28 {
29     private static final MakefileMode mode = new MakefileMode();
30
31     private MakefileMode()
32     {
33         super(MAKEFILE_MODE, MAKEFILE_MODE_NAME);
34         keywords = new Keywords(this);
35         setProperty(Property.USE_TABS, true);
36     }
37
38     public static final MakefileMode getMode()
39     {
40         return mode;
41     }
42
43     public boolean canIndent()
44     {
45         return true;
46     }
47
48     public String JavaDoc getCommentStart()
49     {
50         return "# ";
51     }
52
53     public Formatter getFormatter(Buffer buffer)
54     {
55         return new MakefileFormatter(buffer);
56     }
57
58     protected void setKeyMapDefaults(KeyMap km)
59     {
60         km.mapKey(KeyEvent.VK_ENTER, 0, "newlineAndIndent");
61         km.mapKey(KeyEvent.VK_F9, 0, "compile");
62         km.mapKey(KeyEvent.VK_F9, InputEvent.CTRL_MASK, "recompile");
63     }
64
65     public int getCorrectIndentation(Line line, Buffer buffer)
66     {
67         Line model = getModel(line);
68         if (model == null)
69             return 0;
70         return buffer.getIndentation(model);
71     }
72
73     private static Line getModel(Line line)
74     {
75         Line model = line.previous();
76         while (model != null) {
77             if (model.isBlank() || model.charAt(0) == '#')
78                 model = model.previous();
79             else
80                 break;
81         }
82         return model;
83     }
84
85     private static final String JavaDoc validChars =
86         "-./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz";
87
88     public boolean isIdentifierStart(char c)
89     {
90         return validChars.indexOf(c) >= 0;
91     }
92
93     public boolean isIdentifierPart(char c)
94     {
95         return validChars.indexOf(c) >= 0;
96     }
97 }
98
Popular Tags