KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > CVSDecoratorConfiguration


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.team.internal.ccvs.ui;
12
13
14 import java.util.Map JavaDoc;
15
16 import org.eclipse.osgi.util.TextProcessor;
17
18 public class CVSDecoratorConfiguration {
19
20     // bindings for
21
public static final String JavaDoc RESOURCE_NAME = "name"; //$NON-NLS-1$
22
public static final String JavaDoc RESOURCE_TAG = "tag"; //$NON-NLS-1$
23
public static final String JavaDoc FILE_REVISION = "revision"; //$NON-NLS-1$
24
public static final String JavaDoc FILE_KEYWORD = "keyword"; //$NON-NLS-1$
25

26     // bindings for repository location
27
public static final String JavaDoc REMOTELOCATION_METHOD = "method"; //$NON-NLS-1$
28
public static final String JavaDoc REMOTELOCATION_USER = "user"; //$NON-NLS-1$
29
public static final String JavaDoc REMOTELOCATION_HOST = "host"; //$NON-NLS-1$
30
public static final String JavaDoc REMOTELOCATION_ROOT = "root"; //$NON-NLS-1$
31
public static final String JavaDoc REMOTELOCATION_REPOSITORY = "repository"; //$NON-NLS-1$
32
public static final String JavaDoc REMOTELOCATION_LABEL = "label"; //$NON-NLS-1$
33

34     // bindings for resource states
35
// see bug 110022
36
public static final String JavaDoc NEW_DIRTY_FLAG = "outgoing_change_flag"; //$NON-NLS-1$
37
public static final String JavaDoc OLD_DIRTY_FLAG = "dirty_flag"; //$NON-NLS-1$
38
public static final String JavaDoc ADDED_FLAG = "added_flag"; //$NON-NLS-1$
39
public static final String JavaDoc DEFAULT_DIRTY_FLAG = CVSUIMessages.CVSDecoratorConfiguration_0;
40     public static final String JavaDoc DEFAULT_ADDED_FLAG = CVSUIMessages.CVSDecoratorConfiguration_1;
41     
42     // default text decoration formats
43
public static final String JavaDoc DEFAULT_FILETEXTFORMAT = CVSUIMessages.CVSDecoratorConfiguration_2;
44     public static final String JavaDoc DEFAULT_FOLDERTEXTFORMAT = CVSUIMessages.CVSDecoratorConfiguration_3;
45     public static final String JavaDoc DEFAULT_PROJECTTEXTFORMAT = CVSUIMessages.CVSDecoratorConfiguration_4;
46
47     // prefix characters that can be removed if the following binding is not found
48
private static final char KEYWORD_SEPCOLON = ':';
49     private static final char KEYWORD_SEPAT = '@';
50     
51     // font and color definition ids
52
public static final String JavaDoc OUTGOING_CHANGE_FOREGROUND_COLOR = "org.eclipse.team.cvs.ui.fontsandcolors.outgoing_change_foreground_color"; //$NON-NLS-1$
53
public static final String JavaDoc OUTGOING_CHANGE_BACKGROUND_COLOR = "org.eclipse.team.cvs.ui.fontsandcolors.outgoing_change_background_color"; //$NON-NLS-1$
54
public static final String JavaDoc OUTGOING_CHANGE_FONT = "org.eclipse.team.cvs.ui.fontsandcolors.outgoing_change_font"; //$NON-NLS-1$
55
public static final String JavaDoc IGNORED_FOREGROUND_COLOR = "org.eclipse.team.cvs.ui.fontsandcolors.ignored_resource_foreground_color"; //$NON-NLS-1$
56
public static final String JavaDoc IGNORED_BACKGROUND_COLOR = "org.eclipse.team.cvs.ui.fontsandcolors.ignored_resource_background_color"; //$NON-NLS-1$
57
public static final String JavaDoc IGNORED_FONT = "org.eclipse.team.cvs.ui.fontsandcolors.ignored_resource_font"; //$NON-NLS-1$
58

59     public static void decorate(CVSDecoration decoration, String JavaDoc format, Map JavaDoc bindings) {
60         StringBuffer JavaDoc prefix = new StringBuffer JavaDoc();
61         StringBuffer JavaDoc suffix = new StringBuffer JavaDoc();
62         StringBuffer JavaDoc output = prefix;
63         
64         int length = format.length();
65         int start = -1;
66         int end = length;
67         while (true) {
68             if ((end = format.indexOf('{', start)) > -1) {
69                 output.append(format.substring(start + 1, end));
70                 if ((start = format.indexOf('}', end)) > -1) {
71                     String JavaDoc key = format.substring(end + 1, start);
72                     String JavaDoc s;
73
74                     //We use the RESOURCE_NAME key to determine if we are doing the prefix or suffix. The name isn't actually part of either.
75
if(key.equals(RESOURCE_NAME)) {
76                         output = suffix;
77                         s = null;
78                     } else {
79                         s = (String JavaDoc) bindings.get(key);
80                     }
81
82                     if(s!=null) {
83                         output.append(s);
84                     } else {
85                         // support for removing prefix character if binding is null
86
int curLength = output.length();
87                         if(curLength>0) {
88                             char c = output.charAt(curLength - 1);
89                             if(c == KEYWORD_SEPCOLON || c == KEYWORD_SEPAT) {
90                                 output.deleteCharAt(curLength - 1);
91                             }
92                         }
93                     }
94                 } else {
95                     output.append(format.substring(end, length));
96                     break;
97                 }
98             } else {
99                 output.append(format.substring(start + 1, length));
100                 break;
101             }
102         }
103         
104         if (prefix.length() != 0) {
105             decoration.addPrefix(TextProcessor.process(prefix.toString(),"()[].")); //$NON-NLS-1$
106
}
107         if (suffix.length() != 0) {
108             decoration.addSuffix(TextProcessor.process(suffix.toString(),"()[].")); //$NON-NLS-1$
109
}
110     }
111 }
112
Popular Tags