PageRenderTime 95ms CodeModel.GetById 30ms app.highlight 40ms RepoModel.GetById 20ms app.codeStats 0ms

/jEdit/tags/jedit-4-3-pre5/org/gjt/sp/jedit/gui/BufferOptions.java

#
Java | 639 lines | 223 code | 333 blank | 83 comment | 29 complexity | eedbc8158c9db8a5a1a6bb3715f70bd8 MD5 | raw file
  1/*
  2
  3 * BufferOptions.java - Buffer-specific options dialog
  4
  5 * :tabSize=8:indentSize=8:noTabs=false:
  6
  7 * :folding=explicit:collapseFolds=1:
  8
  9 *
 10
 11 * Copyright (C) 1999, 2004 Slava Pestov
 12
 13 *
 14
 15 * This program is free software; you can redistribute it and/or
 16
 17 * modify it under the terms of the GNU General Public License
 18
 19 * as published by the Free Software Foundation; either version 2
 20
 21 * of the License, or any later version.
 22
 23 *
 24
 25 * This program is distributed in the hope that it will be useful,
 26
 27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 28
 29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 30
 31 * GNU General Public License for more details.
 32
 33 *
 34
 35 * You should have received a copy of the GNU General Public License
 36
 37 * along with this program; if not, write to the Free Software
 38
 39 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 40
 41 */
 42
 43
 44
 45package org.gjt.sp.jedit.gui;
 46
 47
 48
 49//{{{ Imports
 50
 51import javax.swing.border.EmptyBorder;
 52
 53import javax.swing.*;
 54
 55import java.awt.*;
 56
 57import java.awt.event.*;
 58
 59import java.util.Arrays;
 60
 61import org.gjt.sp.jedit.buffer.FoldHandler;
 62import org.gjt.sp.jedit.buffer.JEditBuffer;
 63
 64import org.gjt.sp.jedit.*;
 65
 66//}}}
 67
 68
 69
 70/**
 71
 72 * Buffer-specific options dialog.
 73
 74 * @author Slava Pestov
 75
 76 * @version $Id: BufferOptions.java 5487 2006-06-23 22:58:12Z kpouer $
 77
 78 * 
 79
 80 */
 81
 82public class BufferOptions extends EnhancedDialog
 83
 84{
 85
 86	//{{{ BufferOptions constructor
 87
 88	public BufferOptions(View view, Buffer buffer)
 89
 90	{
 91
 92		super(view,jEdit.getProperty("buffer-options.title"),true);
 93
 94		this.view = view;
 95
 96		this.buffer = buffer;
 97
 98
 99
100		JPanel content = new JPanel(new BorderLayout());
101
102		content.setBorder(new EmptyBorder(12,12,12,12));
103
104		setContentPane(content);
105
106
107
108		ActionHandler actionListener = new ActionHandler();
109
110		AbstractOptionPane panel = new AbstractOptionPane(null);
111
112
113
114		panel.addComponent(GUIUtilities.createMultilineLabel(
115
116			jEdit.getProperty("buffer-options.caption")));
117
118
119
120		panel.addSeparator("buffer-options.loading-saving");
121
122
123
124		//{{{ Line separator
125
126		String[] lineSeps = { jEdit.getProperty("lineSep.unix"),
127
128			jEdit.getProperty("lineSep.windows"),
129
130			jEdit.getProperty("lineSep.mac") };
131
132		lineSeparator = new JComboBox(lineSeps);
133
134		String lineSep = buffer.getStringProperty(JEditBuffer.LINESEP);
135
136		if(lineSep == null)
137
138			lineSep = System.getProperty("line.separator");
139
140		if("\n".equals(lineSep))
141
142			lineSeparator.setSelectedIndex(0);
143
144		else if("\r\n".equals(lineSep))
145
146			lineSeparator.setSelectedIndex(1);
147
148		else if("\r".equals(lineSep))
149
150			lineSeparator.setSelectedIndex(2);
151
152		panel.addComponent(jEdit.getProperty("buffer-options.lineSeparator"),
153
154			lineSeparator);
155
156		//}}}
157
158
159
160		//{{{ Encoding
161
162		String[] encodings = MiscUtilities.getEncodings();
163
164		Arrays.sort(encodings,new MiscUtilities.StringICaseCompare());
165
166		encoding = new JComboBox(encodings);
167
168		encoding.setEditable(true);
169
170		encoding.setSelectedItem(buffer.getStringProperty(JEditBuffer.ENCODING));
171
172		panel.addComponent(jEdit.getProperty("buffer-options.encoding"),
173
174			encoding);
175
176		//}}}
177
178
179
180		//{{{ GZipped setting
181
182		gzipped = new JCheckBox(jEdit.getProperty(
183
184			"buffer-options.gzipped"));
185
186		gzipped.setSelected(buffer.getBooleanProperty(Buffer.GZIPPED));
187
188		panel.addComponent(gzipped);
189
190		//}}}
191
192
193
194		panel.addSeparator("buffer-options.editing");
195
196
197
198		//{{{ Edit mode
199
200		modes = jEdit.getModes();
201
202		Arrays.sort(modes,new MiscUtilities.StringICaseCompare());
203
204		mode = new JComboBox(modes);
205
206		mode.setSelectedItem(buffer.getMode());
207
208		mode.addActionListener(actionListener);
209
210		panel.addComponent(jEdit.getProperty("buffer-options.mode"),mode);
211
212		//}}}
213
214
215
216		//{{{ Fold mode
217
218		String[] foldModes = FoldHandler.getFoldModes();
219
220
221
222		folding = new JComboBox(foldModes);
223
224		folding.setSelectedItem(buffer.getStringProperty("folding"));
225
226		panel.addComponent(jEdit.getProperty("options.editing.folding"),
227
228			folding);
229
230		//}}}
231
232
233
234		//{{{ Wrap mode
235
236		String[] wrapModes = {
237
238			"none",
239
240			"soft",
241
242			"hard"
243
244		};
245
246
247
248		wrap = new JComboBox(wrapModes);
249
250		wrap.setSelectedItem(buffer.getStringProperty("wrap"));
251
252		panel.addComponent(jEdit.getProperty("options.editing.wrap"),
253
254			wrap);
255
256		//}}}
257
258
259
260		//{{{ Max line length
261
262		String[] lineLengths = { "0", "72", "76", "80" };
263
264
265
266		maxLineLen = new JComboBox(lineLengths);
267
268		maxLineLen.setEditable(true);
269
270		maxLineLen.setSelectedItem(buffer.getStringProperty("maxLineLen"));
271
272		panel.addComponent(jEdit.getProperty("options.editing.maxLineLen"),
273
274			maxLineLen);
275
276		//}}}
277
278
279
280		//{{{ Tab size
281
282		String[] tabSizes = { "2", "4", "8" };
283
284		tabSize = new JComboBox(tabSizes);
285
286		tabSize.setEditable(true);
287
288		tabSize.setSelectedItem(buffer.getStringProperty("tabSize"));
289
290		panel.addComponent(jEdit.getProperty("options.editing.tabSize"),tabSize);
291
292		//}}}
293
294
295
296		//{{{ Indent size
297
298		indentSize = new JComboBox(tabSizes);
299
300		indentSize.setEditable(true);
301
302		indentSize.setSelectedItem(buffer.getStringProperty("indentSize"));
303
304		panel.addComponent(jEdit.getProperty("options.editing.indentSize"),
305
306			indentSize);
307
308		//}}}
309
310
311
312		//{{{ Soft tabs
313
314		noTabs = new JCheckBox(jEdit.getProperty(
315
316			"options.editing.noTabs"));
317
318		noTabs.setSelected(buffer.getBooleanProperty("noTabs"));
319
320		panel.addComponent(noTabs);
321
322		//}}}
323
324
325
326		content.add(BorderLayout.NORTH,panel);
327
328
329
330		//{{{ Buttons
331
332		JPanel buttons = new JPanel();
333
334		buttons.setLayout(new BoxLayout(buttons,BoxLayout.X_AXIS));
335
336		buttons.setBorder(new EmptyBorder(12,0,0,0));
337
338		buttons.add(Box.createGlue());
339
340		ok = new JButton(jEdit.getProperty("common.ok"));
341
342		ok.addActionListener(actionListener);
343
344		getRootPane().setDefaultButton(ok);
345
346		buttons.add(ok);
347
348		buttons.add(Box.createHorizontalStrut(6));
349
350		cancel = new JButton(jEdit.getProperty("common.cancel"));
351
352		cancel.addActionListener(actionListener);
353
354		buttons.add(cancel);
355
356		buttons.add(Box.createGlue());
357
358		content.add(BorderLayout.SOUTH,buttons);
359
360		//}}}
361
362
363
364		pack();
365
366		setLocationRelativeTo(view);
367
368		setVisible(true);
369
370	} //}}}
371
372
373
374	//{{{ ok() method
375
376	public void ok()
377
378	{
379
380		int index = lineSeparator.getSelectedIndex();
381
382		String lineSep;
383
384		if(index == 0)
385
386			lineSep = "\n";
387
388		else if(index == 1)
389
390			lineSep = "\r\n";
391
392		else if(index == 2)
393
394			lineSep = "\r";
395
396		else
397
398			throw new InternalError();
399
400
401
402		String oldLineSep = buffer.getStringProperty(JEditBuffer.LINESEP);
403
404		if(oldLineSep == null)
405
406			oldLineSep = System.getProperty("line.separator");
407
408		if(!oldLineSep.equals(lineSep))
409
410		{
411
412			buffer.setStringProperty("lineSeparator",lineSep);
413
414			buffer.setDirty(true);
415
416		}
417
418
419
420		String encoding = (String)this.encoding.getSelectedItem();
421
422		String oldEncoding = buffer.getStringProperty(JEditBuffer.ENCODING);
423
424		if(!oldEncoding.equals(encoding))
425
426		{
427
428			buffer.setStringProperty(JEditBuffer.ENCODING,encoding);
429
430			buffer.setDirty(true);
431
432		}
433
434
435
436		boolean gzippedValue = gzipped.isSelected();
437
438		boolean oldGzipped = buffer.getBooleanProperty(
439
440			Buffer.GZIPPED);
441
442		if(gzippedValue != oldGzipped)
443
444		{
445
446			buffer.setBooleanProperty(Buffer.GZIPPED,gzippedValue);
447
448			buffer.setDirty(true);
449
450		}
451
452
453
454		buffer.setStringProperty("folding",(String)folding.getSelectedItem());
455
456
457
458		buffer.setStringProperty("wrap",(String)wrap.getSelectedItem());
459
460
461
462		try
463
464		{
465
466			buffer.setProperty("maxLineLen",new Integer(
467
468				maxLineLen.getSelectedItem().toString()));
469
470		}
471
472		catch(NumberFormatException nf)
473
474		{
475
476		}
477
478
479
480		try
481
482		{
483
484			buffer.setProperty("tabSize",new Integer(
485
486				tabSize.getSelectedItem().toString()));
487
488		}
489
490		catch(NumberFormatException nf)
491
492		{
493
494		}
495
496
497
498		try
499
500		{
501
502			buffer.setProperty("indentSize",new Integer(
503
504				indentSize.getSelectedItem().toString()));
505
506		}
507
508		catch(NumberFormatException nf)
509
510		{
511
512		}
513
514
515
516		buffer.setBooleanProperty("noTabs",noTabs.isSelected());
517
518
519
520		index = mode.getSelectedIndex();
521
522		buffer.setMode(modes[index]);
523
524
525
526		dispose();
527
528	} //}}}
529
530
531
532	//{{{ cancel() method
533
534	public void cancel()
535
536	{
537
538		dispose();
539
540	} //}}}
541
542
543
544        //{{{ Private members
545
546	private View view;
547
548	private Buffer buffer;
549
550	private Mode[] modes;
551
552	private JComboBox mode;
553
554	private JComboBox lineSeparator;
555
556	private JComboBox encoding;
557
558	private JCheckBox gzipped;
559
560	private JComboBox folding;
561
562	private JComboBox wrap;
563
564	private JComboBox maxLineLen;
565
566	private JComboBox tabSize;
567
568	private JComboBox indentSize;
569
570	private JCheckBox noTabs;
571
572	private JButton ok;
573
574	private JButton cancel;
575
576	//}}}
577
578
579
580	//{{{ ActionHandler class
581
582	class ActionHandler implements ActionListener
583
584	{
585
586		//{{{ actionPerformed() method
587
588		public void actionPerformed(ActionEvent evt)
589
590		{
591
592			Object source = evt.getSource();
593
594			if(source == ok)
595
596				ok();
597
598			else if(source == cancel)
599
600				cancel();
601
602			else if(source == mode)
603
604			{
605
606				Mode _mode = (Mode)mode.getSelectedItem();
607
608				folding.setSelectedItem(_mode.getProperty(
609
610					"folding"));
611
612				wrap.setSelectedItem(_mode.getProperty(
613
614					"wrap"));
615
616				maxLineLen.setSelectedItem(_mode.getProperty(
617
618					"maxLineLen"));
619
620				tabSize.setSelectedItem(_mode.getProperty(
621
622					"tabSize"));
623
624				indentSize.setSelectedItem(_mode.getProperty(
625
626					"indentSize"));
627
628				noTabs.setSelected(_mode.getBooleanProperty(
629
630					"noTabs"));
631
632			}
633
634		} //}}}
635
636	} //}}}
637
638}
639