View Javadoc
1 package org.cyberiantiger.mudclient.config; 2 3 import java.util.*; 4 import java.io.*; 5 import javax.swing.InputMap; 6 import javax.swing.KeyStroke; 7 8 public class ClientConfiguration { 9 10 public static final String DEFAULT_VIEW = "DEFAULT"; 11 public static final String CURRENT_VIEW = "CURRENT"; 12 13 private String host; 14 private int port; 15 private String term; 16 private List outputs; 17 private String defaultOutput; 18 private Map redirects; 19 private Map outputConfigs; 20 private InputMap keyBindings; 21 22 23 public ClientConfiguration() { 24 } 25 26 public void load(InputStream in) throws IOException { 27 StringTokenizer tmp; 28 Iterator i; 29 Properties props = new Properties(); 30 props.load(in); 31 host=props.getProperty("net.host"); 32 port=Integer.parseInt(props.getProperty("net.port")); 33 term=props.getProperty("net.terminal"); 34 35 tmp = new StringTokenizer(props.getProperty("output"),","); 36 37 outputs = new ArrayList(); 38 while(tmp.hasMoreTokens()) { 39 outputs.add(tmp.nextToken()); 40 } 41 42 outputConfigs = new HashMap(); 43 44 i = outputs.iterator(); 45 while(i.hasNext()) { 46 String name = (String) i.next(); 47 OutputConfiguration outputConfig = new OutputConfiguration(); 48 outputConfig.load(props,name); 49 outputConfigs.put(name,outputConfig); 50 } 51 52 defaultOutput = props.getProperty("output.default"); 53 54 redirects = new HashMap(); 55 56 tmp = new StringTokenizer(props.getProperty("redirect"),","); 57 58 Set redirectTypes = new HashSet(); 59 while(tmp.hasMoreTokens()) { 60 redirectTypes.add(tmp.nextToken()); 61 } 62 63 i = redirectTypes.iterator(); 64 while(i.hasNext()) { 65 String type = (String) i.next(); 66 tmp = new StringTokenizer( 67 props.getProperty("redirect."+type),"," 68 ); 69 Set targets = new HashSet(); 70 while(tmp.hasMoreTokens()) { 71 targets.add(tmp.nextToken()); 72 } 73 redirects.put(type,targets); 74 } 75 76 tmp = new StringTokenizer(props.getProperty("action"),","); 77 78 Set actionKeys = new HashSet(); 79 while(tmp.hasMoreTokens()) { 80 actionKeys.add(tmp.nextToken()); 81 } 82 83 keyBindings = new InputMap(); 84 i = actionKeys.iterator(); 85 while(i.hasNext()) { 86 String actionKey = (String) i.next(); 87 88 tmp = new StringTokenizer( 89 props.getProperty("action."+actionKey),","); 90 while(tmp.hasMoreTokens()) { 91 String token = tmp.nextToken(); 92 KeyStroke ks = KeyStroke.getKeyStroke(token); 93 if(ks == null) { 94 System.out.println("Invalid KeyStroke: "+token+" for: "+actionKey); 95 } else { 96 keyBindings.put(ks,actionKey); 97 } 98 } 99 } 100 } 101 102 /*** 103 * Get the hostname to connect to 104 */ 105 public String getHost() { 106 return host; 107 } 108 109 /*** 110 * Get the port to connect to 111 */ 112 public int getPort() { 113 return port; 114 } 115 116 /*** 117 * Get the terminal type to send to the mud 118 */ 119 public String getTerminalType() { 120 return term; 121 } 122 123 /*** 124 * Get the name of the default output 125 */ 126 public String getDefaultOutputName() { 127 return defaultOutput; 128 } 129 130 /*** 131 * Get the list of output names. 132 */ 133 public List getOutputNames() { 134 return outputs; 135 } 136 137 /*** 138 * Get the OutputConfiguration for a specific Output 139 */ 140 public OutputConfiguration getOutputConfiguration(String name) { 141 return (OutputConfiguration) outputConfigs.get(name); 142 } 143 144 /*** 145 * Get the list of outputs which a message of type msgClass should be 146 * sent to. 147 */ 148 public Set getOutputFor(String msgClass) { 149 return (Set) redirects.get(msgClass); 150 } 151 152 /*** 153 * Get a map of key name to action name 154 */ 155 public InputMap getKeyBindings() { 156 return keyBindings; 157 } 158 }

This page was automatically generated by Maven