KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > common > widgets > LineSeparatorInput


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
21 package org.apache.directory.ldapstudio.browser.common.widgets;
22
23
24 import java.util.Iterator JavaDoc;
25 import java.util.Map JavaDoc;
26
27 import org.apache.directory.ldapstudio.browser.core.BrowserCoreConstants;
28 import org.eclipse.core.runtime.Platform;
29
30
31 /**
32  * The LineSeparatorInput is an OptionInput with fixed options.
33  * It is used to select the line separator. The default
34  * value is always the platform's default line separator.
35  * The other options are the values return from
36  * {@link Platform#knownPlatformLineSeparators()}.
37  * No custom input is allowed.
38  *
39  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
40  * @version $Rev$, $Date$
41  */

42 public class LineSeparatorInput extends OptionsInput
43 {
44
45     /**
46      * Creates a new instance of LineSeparatorInput.
47      *
48      * @param initialRawValue the initial raw value
49      * @param asGroup the asGroup flag
50      */

51     public LineSeparatorInput( String JavaDoc initialRawValue, boolean asGroup )
52     {
53         super( "Line Separator", getDefaultDisplayValue(), getDefaultRawValue(), getOtherDisplayValues(),
54             getOtherRawValues(), initialRawValue, asGroup, false );
55
56     }
57
58
59     /**
60      * Gets the default display value.
61      *
62      * @return the default display value
63      */

64     private static String JavaDoc getDefaultDisplayValue()
65     {
66         Map JavaDoc lsMap = Platform.knownPlatformLineSeparators();
67         for ( Iterator JavaDoc iter = lsMap.keySet().iterator(); iter.hasNext(); )
68         {
69             String JavaDoc k = ( String JavaDoc ) iter.next();
70             String JavaDoc v = ( String JavaDoc ) lsMap.get( k );
71             if ( v.equals( getDefaultRawValue() ) )
72             {
73                 k = k + " (" + ( v.replaceAll( "\n", "\\\\n" ).replaceAll( "\r", "\\\\r" ) ) + ")";
74                 return k;
75             }
76         }
77         return getDefaultRawValue();
78     }
79
80
81     /**
82      * Gets the default raw value, always the platform's default
83      * line separator.
84      *
85      * @return the default raw value
86      */

87     private static String JavaDoc getDefaultRawValue()
88     {
89         return BrowserCoreConstants.LINE_SEPARATOR;
90     }
91
92
93     /**
94      * Gets the other display values That are all values
95      * returned from {@link Platform#knownPlatformLineSeparators()}.
96      *
97      * @return the other display values
98      */

99     @SuppressWarnings JavaDoc("unchecked")
100     private static String JavaDoc[] getOtherDisplayValues()
101     {
102         Map JavaDoc<String JavaDoc, String JavaDoc> lsMap = Platform.knownPlatformLineSeparators();
103         String JavaDoc[] displayValues = lsMap.keySet().toArray( new String JavaDoc[lsMap.size()] );
104         for ( int i = 0; i < displayValues.length; i++ )
105         {
106             displayValues[i] = displayValues[i]
107                 + " ("
108                 + ( ( ( String JavaDoc ) lsMap.get( displayValues[i] ) ).replaceAll( "\n", "\\\\n" ).replaceAll( "\r", "\\\\r" ) )
109                 + ")";
110         }
111         return displayValues;
112     }
113
114
115     /**
116      * Gets the other raw values.
117      *
118      * @return the other raw values
119      */

120     @SuppressWarnings JavaDoc("unchecked")
121     private static String JavaDoc[] getOtherRawValues()
122     {
123         Map JavaDoc<String JavaDoc, String JavaDoc> lsMap = Platform.knownPlatformLineSeparators();
124         String JavaDoc[] displayValues = lsMap.keySet().toArray( new String JavaDoc[lsMap.size()] );
125         String JavaDoc[] rawValues = new String JavaDoc[displayValues.length];
126         for ( int i = 0; i < rawValues.length; i++ )
127         {
128             rawValues[i] = ( String JavaDoc ) lsMap.get( displayValues[i] );
129         }
130         return rawValues;
131     }
132
133 }
134
Popular Tags