KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > aciitemeditor > sourceeditor > ACITextAttributeProvider


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  *
19  */

20 package org.apache.directory.ldapstudio.aciitemeditor.sourceeditor;
21
22
23 import java.util.HashMap JavaDoc;
24 import java.util.Map JavaDoc;
25
26 import org.eclipse.jface.text.TextAttribute;
27 import org.eclipse.swt.SWT;
28 import org.eclipse.swt.graphics.Color;
29 import org.eclipse.swt.graphics.RGB;
30 import org.eclipse.swt.widgets.Display;
31
32
33 /**
34  * This class provides the TextAttributes elements for each kind of attribute
35  *
36  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
37  * @version $Rev$, $Date$
38  */

39 public class ACITextAttributeProvider
40 {
41     public static final String JavaDoc DEFAULT_ATTRIBUTE = "__pos_aci_default_attribute"; //$NON-NLS-1$
42
public static final String JavaDoc KEYWORD_ATTRIBUTE = "__pos_aci_keyword_attribute"; //$NON-NLS-1$
43
public static final String JavaDoc STRING_ATTRIBUTE = "__pos_aci_string_attribute"; //$NON-NLS-1$
44
public static final String JavaDoc GRANT_DENY_ATTRIBUTE = "__pos_aci_grant_deny_attribute"; //$NON-NLS-1$
45
public static final String JavaDoc IDENTIFICATION_ATTRIBUTE = "__pos_aci_identification_attribute"; //$NON-NLS-1$
46
public static final String JavaDoc PRECEDENCE_ATTRIBUTE = "__pos_aci_precedence_attribute"; //$NON-NLS-1$
47
public static final String JavaDoc AUTHENTICATIONLEVEL_ATTRIBUTE = "__pos_aci_authenticationlevel_attribute"; //$NON-NLS-1$
48
public static final String JavaDoc ITEMORUSERFIRST_ATTRIBUTE = "__pos_aci_itemoruserfirst_attribute"; //$NON-NLS-1$
49
public static final String JavaDoc USER_ATTRIBUTE = "__pos_aci_user_attribute"; //$NON-NLS-1$
50

51     public static final String JavaDoc GRANT_VALUE = "__pos_aci_grant_value"; //$NON-NLS-1$
52
public static final String JavaDoc DENY_VALUE = "__pos_aci_deny_value"; //$NON-NLS-1$
53

54     private Map JavaDoc<String JavaDoc, TextAttribute> attributes = new HashMap JavaDoc<String JavaDoc, TextAttribute>();
55
56
57     /**
58      * Creates a new instance of AciTextAttributeProvider.
59      */

60     public ACITextAttributeProvider()
61     {
62         attributes.put( DEFAULT_ATTRIBUTE, new TextAttribute( new Color( Display.getCurrent(), new RGB( 0, 0, 0 ) ) ) );
63
64         attributes.put( KEYWORD_ATTRIBUTE, new TextAttribute( new Color( Display.getCurrent(), new RGB( 127, 0, 85 ) ),
65             null, SWT.BOLD ) );
66
67         attributes.put( STRING_ATTRIBUTE, new TextAttribute( new Color( Display.getCurrent(), new RGB( 0, 0, 255 ) ) ) );
68
69         attributes.put( GRANT_DENY_ATTRIBUTE, new TextAttribute( new Color( Display.getCurrent(), new RGB( 125, 125,
70             125 ) ) ) );
71
72         attributes.put( GRANT_VALUE, new TextAttribute( new Color( Display.getCurrent(), new RGB( 0, 150, 0 ) ) ) );
73         attributes.put( DENY_VALUE, new TextAttribute( new Color( Display.getCurrent(), new RGB( 150, 0, 0 ) ) ) );
74
75         attributes.put( IDENTIFICATION_ATTRIBUTE, new TextAttribute( new Color( Display.getCurrent(), new RGB( 125, 0,
76             0 ) ), null, SWT.BOLD ) );
77
78         attributes.put( PRECEDENCE_ATTRIBUTE, new TextAttribute(
79             new Color( Display.getCurrent(), new RGB( 0, 0, 125 ) ), null, SWT.BOLD ) );
80
81         attributes.put( AUTHENTICATIONLEVEL_ATTRIBUTE, new TextAttribute( new Color( Display.getCurrent(), new RGB( 0,
82             125, 0 ) ), null, SWT.BOLD ) );
83
84         attributes.put( ITEMORUSERFIRST_ATTRIBUTE, new TextAttribute( new Color( Display.getCurrent(), new RGB( 125, 0,
85             125 ) ), null, SWT.BOLD ) );
86
87         attributes.put( USER_ATTRIBUTE, new TextAttribute( new Color( Display.getCurrent(), new RGB( 0, 122, 255 ) ),
88             null, SWT.BOLD ) );
89
90     }
91
92
93     /**
94      * Gets the correct TextAttribute for the given type
95      *
96      * @param type
97      * the type of element
98      * @return
99      * the correct TextAttribute for the given type
100      */

101     public TextAttribute getAttribute( String JavaDoc type )
102     {
103         TextAttribute attr = ( TextAttribute ) attributes.get( type );
104         if ( attr == null )
105         {
106             attr = ( TextAttribute ) attributes.get( DEFAULT_ATTRIBUTE );
107         }
108         return attr;
109     }
110 }
111
Popular Tags