1 23 24 package org.gjt.sp.jedit.options; 25 26 import java.awt.event.ActionEvent ; 27 import java.awt.event.ActionListener ; 28 import java.util.Arrays ; 29 30 import javax.swing.JCheckBox ; 31 import javax.swing.JComboBox ; 32 33 import org.gjt.sp.jedit.AbstractOptionPane; 34 import org.gjt.sp.jedit.Buffer; 35 import org.gjt.sp.jedit.GUIUtilities; 36 import org.gjt.sp.jedit.MiscUtilities; 37 import org.gjt.sp.jedit.Mode; 38 import org.gjt.sp.jedit.jEdit; 39 import org.gjt.sp.jedit.buffer.FoldHandler; 40 import org.gjt.sp.jedit.buffer.JEditBuffer; 41 42 45 public class BufferOptionPane extends AbstractOptionPane 46 { 47 JComboBox encoding; 48 JComboBox lineSeparator; 49 JCheckBox gzipped; 50 Mode[] modes; 51 JComboBox mode; 52 JComboBox folding; 53 JComboBox wrap; 54 JComboBox maxLineLen; 55 JComboBox tabSize; 56 JComboBox indentSize; 57 JComboBox checkModStatus; 58 JCheckBox noTabs; 59 Buffer buffer; 60 61 62 public BufferOptionPane() 63 { 64 super("Buffer Options"); 65 init(); 66 } 67 68 protected void _init() 69 { 70 71 72 buffer = jEdit.getActiveView().getBuffer(); 73 String filename = buffer.getName(); 74 setName("Buffer: " + filename); 75 addComponent(GUIUtilities.createMultilineLabel( 76 jEdit.getProperty("buffer-options.caption"))); 77 78 addSeparator("buffer-options.loading-saving"); 79 80 String [] lineSeps = { jEdit.getProperty("lineSep.unix"), 82 jEdit.getProperty("lineSep.windows"), 83 jEdit.getProperty("lineSep.mac") }; 84 lineSeparator = new JComboBox (lineSeps); 85 String lineSep = buffer.getStringProperty(JEditBuffer.LINESEP); 86 if(lineSep == null) 87 lineSep = System.getProperty("line.separator"); 88 if("\n".equals(lineSep)) 89 lineSeparator.setSelectedIndex(0); 90 else if("\r\n".equals(lineSep)) 91 lineSeparator.setSelectedIndex(1); 92 else if("\r".equals(lineSep)) 93 lineSeparator.setSelectedIndex(2); 94 addComponent(jEdit.getProperty("buffer-options.lineSeparator"), 95 lineSeparator); 96 98 String [] encodings = MiscUtilities.getEncodings(true); 100 Arrays.sort(encodings,new MiscUtilities.StringICaseCompare()); 101 encoding = new JComboBox (encodings); 102 encoding.setEditable(true); 103 encoding.setSelectedItem(buffer.getStringProperty(JEditBuffer.ENCODING)); 104 addComponent(jEdit.getProperty("buffer-options.encoding"), 105 encoding); 106 108 gzipped = new JCheckBox (jEdit.getProperty( 110 "buffer-options.gzipped")); 111 gzipped.setSelected(buffer.getBooleanProperty(Buffer.GZIPPED)); 112 addComponent(gzipped); 113 115 117 String [] modCheckOptions = { 118 jEdit.getProperty("options.general.checkModStatus.nothing"), 119 jEdit.getProperty("options.general.checkModStatus.prompt"), 120 jEdit.getProperty("options.general.checkModStatus.reload"), 121 jEdit.getProperty("options.general.checkModStatus.silentReload") 122 }; 123 checkModStatus = new JComboBox (modCheckOptions); 124 if(buffer.getAutoReload()) { 125 if(buffer.getAutoReloadDialog()) 126 checkModStatus.setSelectedIndex(2); 128 else checkModStatus.setSelectedIndex(3); 130 } 131 else { 132 if(buffer.getAutoReloadDialog()) 133 checkModStatus.setSelectedIndex(1); 135 else checkModStatus.setSelectedIndex(0); 137 } 138 addComponent(jEdit.getProperty("options.general.checkModStatus"), 139 checkModStatus); 140 141 143 addSeparator("buffer-options.editing"); 144 145 modes = jEdit.getModes(); 147 Arrays.sort(modes,new MiscUtilities.StringICaseCompare()); 148 mode = new JComboBox (modes); 149 mode.setSelectedItem(buffer.getMode()); 150 ActionHandler actionListener = new ActionHandler(); 151 mode.addActionListener(actionListener); 152 addComponent(jEdit.getProperty("buffer-options.mode"),mode); 153 155 String [] foldModes = FoldHandler.getFoldModes(); 157 158 folding = new JComboBox (foldModes); 159 folding.setSelectedItem(buffer.getStringProperty("folding")); 160 addComponent(jEdit.getProperty("options.editing.folding"), 161 folding); 162 164 String [] wrapModes = { 166 "none", 167 "soft", 168 "hard" 169 }; 170 171 wrap = new JComboBox (wrapModes); 172 wrap.setSelectedItem(buffer.getStringProperty("wrap")); 173 addComponent(jEdit.getProperty("options.editing.wrap"), 174 wrap); 175 177 String [] lineLengths = { "0", "72", "76", "80" }; 179 180 maxLineLen = new JComboBox (lineLengths); 181 maxLineLen.setEditable(true); 182 maxLineLen.setSelectedItem(buffer.getStringProperty("maxLineLen")); 183 addComponent(jEdit.getProperty("options.editing.maxLineLen"), 184 maxLineLen); 185 187 String [] tabSizes = { "2", "4", "8" }; 189 tabSize = new JComboBox (tabSizes); 190 tabSize.setEditable(true); 191 tabSize.setSelectedItem(buffer.getStringProperty("tabSize")); 192 addComponent(jEdit.getProperty("options.editing.tabSize"),tabSize); 193 195 indentSize = new JComboBox (tabSizes); 197 indentSize.setEditable(true); 198 indentSize.setSelectedItem(buffer.getStringProperty("indentSize")); 199 addComponent(jEdit.getProperty("options.editing.indentSize"), 200 indentSize); 201 203 noTabs = new JCheckBox (jEdit.getProperty( 205 "options.editing.noTabs")); 206 noTabs.setSelected(buffer.getBooleanProperty("noTabs")); 207 addComponent(noTabs); 208 209 } 210 211 212 protected void _save() 213 { 214 int index = lineSeparator.getSelectedIndex(); 215 String lineSep; 216 if(index == 0) 217 lineSep = "\n"; 218 else if(index == 1) 219 lineSep = "\r\n"; 220 else if(index == 2) 221 lineSep = "\r"; 222 else 223 throw new InternalError (); 224 225 String oldLineSep = buffer.getStringProperty(JEditBuffer.LINESEP); 226 if(oldLineSep == null) 227 oldLineSep = System.getProperty("line.separator"); 228 if(!oldLineSep.equals(lineSep)) 229 { 230 buffer.setStringProperty("lineSeparator",lineSep); 231 buffer.setDirty(true); 232 } 233 234 String encoding = (String )this.encoding.getSelectedItem(); 235 String oldEncoding = buffer.getStringProperty(JEditBuffer.ENCODING); 236 if(!oldEncoding.equals(encoding)) 237 { 238 buffer.setStringProperty(JEditBuffer.ENCODING,encoding); 239 buffer.setDirty(true); 240 } 241 242 boolean gzippedValue = gzipped.isSelected(); 243 boolean oldGzipped = buffer.getBooleanProperty( 244 Buffer.GZIPPED); 245 if(gzippedValue != oldGzipped) 246 { 247 buffer.setBooleanProperty(Buffer.GZIPPED,gzippedValue); 248 buffer.setDirty(true); 249 } 250 251 buffer.setStringProperty("folding",(String )folding.getSelectedItem()); 252 253 buffer.setStringProperty("wrap",(String )wrap.getSelectedItem()); 254 255 try 256 { 257 buffer.setProperty("maxLineLen",new Integer ( 258 maxLineLen.getSelectedItem().toString())); 259 } 260 catch(NumberFormatException nf) 261 { 262 } 263 264 try 265 { 266 buffer.setProperty("tabSize",new Integer ( 267 tabSize.getSelectedItem().toString())); 268 } 269 catch(NumberFormatException nf) 270 { 271 } 272 273 try 274 { 275 buffer.setProperty("indentSize",new Integer ( 276 indentSize.getSelectedItem().toString())); 277 } 278 catch(NumberFormatException nf) 279 { 280 } 281 282 buffer.setBooleanProperty("noTabs",noTabs.isSelected()); 283 284 index = mode.getSelectedIndex(); 285 buffer.setMode(modes[index]); 286 switch(checkModStatus.getSelectedIndex()) 287 { 288 case 0: 289 buffer.setAutoReloadDialog(false); 290 buffer.setAutoReload(false); 291 break; 292 case 1: 293 buffer.setAutoReloadDialog(true); 294 buffer.setAutoReload(false); 295 break; 296 case 2: 297 buffer.setAutoReloadDialog(true); 298 buffer.setAutoReload(true); 299 break; 300 case 3: 301 buffer.setAutoReloadDialog(false); 302 buffer.setAutoReload(true); 303 break; 304 } 305 } 306 307 308 class ActionHandler implements ActionListener 309 { 310 public void actionPerformed(ActionEvent evt) 312 { 313 Object source = evt.getSource(); 314 if(source == mode) 315 { 316 Mode _mode = (Mode)mode.getSelectedItem(); 317 folding.setSelectedItem(_mode.getProperty( 318 "folding")); 319 wrap.setSelectedItem(_mode.getProperty( 320 "wrap")); 321 maxLineLen.setSelectedItem(_mode.getProperty( 322 "maxLineLen")); 323 tabSize.setSelectedItem(_mode.getProperty( 324 "tabSize")); 325 indentSize.setSelectedItem(_mode.getProperty( 326 "indentSize")); 327 noTabs.setSelected(_mode.getBooleanProperty( 328 "noTabs")); 329 } 330 } } 333 } 334 | Popular Tags |