01: /*
02: * Copyright (c) 2001, Jacob Smullyan.
03: *
04: * This is part of SkunkDAV, a WebDAV client. See http://skunkdav.sourceforge.net/
05: * for the latest version.
06: *
07: * SkunkDAV is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License as published
09: * by the Free Software Foundation; either version 2, or (at your option)
10: * any later version.
11: *
12: * SkunkDAV 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 GNU
15: * General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public License
18: * along with SkunkDAV; see the file COPYING. If not, write to the Free
19: * Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20: * 02111-1307, USA.
21: */
22:
23: package org.skunk.swing.text.syntax;
24:
25: import org.skunk.trace.Debug;
26: import org.skunk.util.GappedIntArray;
27:
28: public final class StyleBufferUtilities {
29: public static final int STYLE_BUFFER_STYLE_MASK = 31;
30: public static final int STYLE_BUFFER_STATE_MASK = 992;
31:
32: public static final int getState(int styleBufferEntry) {
33: return (styleBufferEntry & STYLE_BUFFER_STATE_MASK) >> 5;
34: }
35:
36: public static final int getStyle(int styleBufferEntry) {
37: return (styleBufferEntry & STYLE_BUFFER_STYLE_MASK);
38: }
39:
40: public static final int applyStyle(GappedIntArray styleBuffer,
41: int style, int state, int offset, int length) {
42: int type = style | (state << 5);
43: if (styleBuffer != null) {
44: int[] tmpBuff = new int[length];
45: for (int i = 0; i < length; i++) {
46: tmpBuff[i] = type;
47: }
48:
49: if (styleBuffer.length() > offset + length) {
50: styleBuffer.set(offset, tmpBuff);
51: } else {
52: Debug
53: .trace(StyleBufferUtilities.class, Debug.DP2,
54: "applyStyle tried to set style past end of style buffer");
55: }
56: }
57: return type;
58: }
59:
60: private StyleBufferUtilities() {
61: } //not meant to be instantiated
62: }
63:
64: /* $Log: StyleBufferUtilities.java,v $
65: /* Revision 1.1 2001/02/14 19:15:37 smulloni
66: /* modified usage of the style buffer to pack state information into its ints.
67: /* Previously, I had stipulated that a style could only be used in one state
68: /* per mode; that restriction may now be lifted.
69: /* */
|