1 20 21 package org.apache.directory.ldapstudio.browser.common.widgets; 22 23 24 import java.util.Iterator ; 25 import java.util.Map ; 26 27 import org.apache.directory.ldapstudio.browser.core.BrowserCoreConstants; 28 import org.eclipse.core.runtime.Platform; 29 30 31 42 public class LineSeparatorInput extends OptionsInput 43 { 44 45 51 public LineSeparatorInput( String initialRawValue, boolean asGroup ) 52 { 53 super( "Line Separator", getDefaultDisplayValue(), getDefaultRawValue(), getOtherDisplayValues(), 54 getOtherRawValues(), initialRawValue, asGroup, false ); 55 56 } 57 58 59 64 private static String getDefaultDisplayValue() 65 { 66 Map lsMap = Platform.knownPlatformLineSeparators(); 67 for ( Iterator iter = lsMap.keySet().iterator(); iter.hasNext(); ) 68 { 69 String k = ( String ) iter.next(); 70 String v = ( String ) 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 87 private static String getDefaultRawValue() 88 { 89 return BrowserCoreConstants.LINE_SEPARATOR; 90 } 91 92 93 99 @SuppressWarnings ("unchecked") 100 private static String [] getOtherDisplayValues() 101 { 102 Map <String , String > lsMap = Platform.knownPlatformLineSeparators(); 103 String [] displayValues = lsMap.keySet().toArray( new String [lsMap.size()] ); 104 for ( int i = 0; i < displayValues.length; i++ ) 105 { 106 displayValues[i] = displayValues[i] 107 + " (" 108 + ( ( ( String ) lsMap.get( displayValues[i] ) ).replaceAll( "\n", "\\\\n" ).replaceAll( "\r", "\\\\r" ) ) 109 + ")"; 110 } 111 return displayValues; 112 } 113 114 115 120 @SuppressWarnings ("unchecked") 121 private static String [] getOtherRawValues() 122 { 123 Map <String , String > lsMap = Platform.knownPlatformLineSeparators(); 124 String [] displayValues = lsMap.keySet().toArray( new String [lsMap.size()] ); 125 String [] rawValues = new String [displayValues.length]; 126 for ( int i = 0; i < rawValues.length; i++ ) 127 { 128 rawValues[i] = ( String ) lsMap.get( displayValues[i] ); 129 } 130 return rawValues; 131 } 132 133 } 134 | Popular Tags |