|
What this is
Other links
The source code/* * BufferOptions.java - Buffer-specific options dialog * :tabSize=8:indentSize=8:noTabs=false: * :folding=explicit:collapseFolds=1: * * Copyright (C) 1999, 2004 Slava Pestov * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package org.gjt.sp.jedit.gui; //{{{ Imports import javax.swing.border.EmptyBorder; import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.Arrays; import org.gjt.sp.jedit.buffer.FoldHandler; import org.gjt.sp.jedit.*; //}}} /** * Buffer-specific options dialog. * @author Slava Pestov * @version $Id: BufferOptions.java,v 1.31 2004/06/28 06:45:26 spestov Exp $ */ public class BufferOptions extends EnhancedDialog { //{{{ BufferOptions constructor public BufferOptions(View view, Buffer buffer) { super(view,jEdit.getProperty("buffer-options.title"),true); this.view = view; this.buffer = buffer; JPanel content = new JPanel(new BorderLayout()); content.setBorder(new EmptyBorder(12,12,12,12)); setContentPane(content); ActionHandler actionListener = new ActionHandler(); AbstractOptionPane panel = new AbstractOptionPane(null); panel.addComponent(GUIUtilities.createMultilineLabel( jEdit.getProperty("buffer-options.caption"))); panel.addSeparator("buffer-options.loading-saving"); //{{{ Line separator String[] lineSeps = { jEdit.getProperty("lineSep.unix"), jEdit.getProperty("lineSep.windows"), jEdit.getProperty("lineSep.mac") }; lineSeparator = new JComboBox(lineSeps); String lineSep = buffer.getStringProperty(Buffer.LINESEP); if(lineSep == null) lineSep = System.getProperty("line.separator"); if("\n".equals(lineSep)) lineSeparator.setSelectedIndex(0); else if("\r\n".equals(lineSep)) lineSeparator.setSelectedIndex(1); else if("\r".equals(lineSep)) lineSeparator.setSelectedIndex(2); panel.addComponent(jEdit.getProperty("buffer-options.lineSeparator"), lineSeparator); //}}} //{{{ Encoding String[] encodings = MiscUtilities.getEncodings(); Arrays.sort(encodings,new MiscUtilities.StringICaseCompare()); encoding = new JComboBox(encodings); encoding.setEditable(true); encoding.setSelectedItem(buffer.getStringProperty(Buffer.ENCODING)); panel.addComponent(jEdit.getProperty("buffer-options.encoding"), encoding); //}}} //{{{ GZipped setting gzipped = new JCheckBox(jEdit.getProperty( "buffer-options.gzipped")); gzipped.setSelected(buffer.getBooleanProperty(Buffer.GZIPPED)); panel.addComponent(gzipped); //}}} panel.addSeparator("buffer-options.editing"); //{{{ Edit mode modes = jEdit.getModes(); MiscUtilities.quicksort(modes,new MiscUtilities.StringICaseCompare()); mode = new JComboBox(modes); mode.setSelectedItem(buffer.getMode()); mode.addActionListener(actionListener); panel.addComponent(jEdit.getProperty("buffer-options.mode"),mode); //}}} //{{{ Fold mode String[] foldModes = FoldHandler.getFoldModes(); folding = new JComboBox(foldModes); folding.setSelectedItem(buffer.getStringProperty("folding")); panel.addComponent(jEdit.getProperty("options.editing.folding"), folding); //}}} //{{{ Wrap mode String[] wrapModes = { "none", "soft", "hard" }; wrap = new JComboBox(wrapModes); wrap.setSelectedItem(buffer.getStringProperty("wrap")); panel.addComponent(jEdit.getProperty("options.editing.wrap"), wrap); wrap.addActionListener(new ActionHandler()); //}}} //{{{ Max line length String[] lineLengths = { "0", "72", "76", "80" }; maxLineLen = new JComboBox(lineLengths); maxLineLen.setEditable(true); maxLineLen.setSelectedItem(buffer.getStringProperty("maxLineLen")); maxLineLen.addActionListener(new ActionHandler()); panel.addComponent(jEdit.getProperty("options.editing.maxLineLen"), maxLineLen); //}}} //{{{ Tab size String[] tabSizes = { "2", "4", "8" }; tabSize = new JComboBox(tabSizes); tabSize.setEditable(true); tabSize.setSelectedItem(buffer.getStringProperty("tabSize")); panel.addComponent(jEdit.getProperty("options.editing.tabSize"),tabSize); //}}} //{{{ Indent size indentSize = new JComboBox(tabSizes); indentSize.setEditable(true); indentSize.setSelectedItem(buffer.getStringProperty("indentSize")); panel.addComponent(jEdit.getProperty("options.editing.indentSize"), indentSize); //}}} //{{{ Soft tabs noTabs = new JCheckBox(jEdit.getProperty( "options.editing.noTabs")); noTabs.setSelected(buffer.getBooleanProperty("noTabs")); panel.addComponent(noTabs); //}}} content.add(BorderLayout.NORTH,panel); //{{{ Buttons JPanel buttons = new JPanel(); buttons.setLayout(new BoxLayout(buttons,BoxLayout.X_AXIS)); buttons.setBorder(new EmptyBorder(12,0,0,0)); buttons.add(Box.createGlue()); ok = new JButton(jEdit.getProperty("common.ok")); ok.addActionListener(actionListener); getRootPane().setDefaultButton(ok); buttons.add(ok); buttons.add(Box.createHorizontalStrut(6)); cancel = new JButton(jEdit.getProperty("common.cancel")); cancel.addActionListener(actionListener); buttons.add(cancel); buttons.add(Box.createGlue()); content.add(BorderLayout.SOUTH,buttons); //}}} pack(); setLocationRelativeTo(view); setVisible(true); } //}}} //{{{ ok() method public void ok() { int index = lineSeparator.getSelectedIndex(); String lineSep; if(index == 0) lineSep = "\n"; else if(index == 1) lineSep = "\r\n"; else if(index == 2) lineSep = "\r"; else throw new InternalError(); String oldLineSep = buffer.getStringProperty(Buffer.LINESEP); if(oldLineSep == null) oldLineSep = System.getProperty("line.separator"); if(!oldLineSep.equals(lineSep)) { buffer.setStringProperty("lineSeparator",lineSep); buffer.setDirty(true); } String encoding = (String)this.encoding.getSelectedItem(); String oldEncoding = buffer.getStringProperty(Buffer.ENCODING); if(!oldEncoding.equals(encoding)) { buffer.setStringProperty(Buffer.ENCODING,encoding); buffer.setDirty(true); } boolean gzippedValue = gzipped.isSelected(); boolean oldGzipped = buffer.getBooleanProperty( Buffer.GZIPPED); if(gzippedValue != oldGzipped) { buffer.setBooleanProperty(Buffer.GZIPPED,gzippedValue); buffer.setDirty(true); } buffer.setStringProperty("folding",(String)folding.getSelectedItem()); buffer.setStringProperty("wrap",(String)wrap.getSelectedItem()); try { buffer.setProperty("maxLineLen",new Integer( maxLineLen.getSelectedItem().toString())); } catch(NumberFormatException nf) { } try { buffer.setProperty("tabSize",new Integer( tabSize.getSelectedItem().toString())); } catch(NumberFormatException nf) { } try { buffer.setProperty("indentSize",new Integer( indentSize.getSelectedItem().toString())); } catch(NumberFormatException nf) { } buffer.setBooleanProperty("noTabs",noTabs.isSelected()); index = mode.getSelectedIndex(); buffer.setMode(modes[index]); dispose(); } //}}} //{{{ cancel() method public void cancel() { dispose(); } //}}} //{{{ Private members //{{{ Instance variables private View view; private Buffer buffer; private Mode[] modes; private JComboBox mode; private JComboBox lineSeparator; private JComboBox encoding; private JCheckBox gzipped; private JComboBox folding; private JComboBox wrap; private JComboBox maxLineLen; private JComboBox tabSize; private JComboBox indentSize; private JCheckBox noTabs; private JButton ok; private JButton cancel; //}}} //{{{ ActionHandler class class ActionHandler implements ActionListener { //{{{ actionPerformed() method public void actionPerformed(ActionEvent evt) { Object source = evt.getSource(); if(source == ok) ok(); else if(source == cancel) cancel(); else if(source == mode) { Mode _mode = (Mode)mode.getSelectedItem(); folding.setSelectedItem(_mode.getProperty( "folding")); wrap.setSelectedItem(_mode.getProperty( "wrap")); maxLineLen.setSelectedItem(_mode.getProperty( "maxLineLen")); tabSize.setSelectedItem(_mode.getProperty( "tabSize")); indentSize.setSelectedItem(_mode.getProperty( "indentSize")); noTabs.setSelected(_mode.getBooleanProperty( "noTabs")); } else if(source == wrap) { if(!wrap.getSelectedItem().equals("none")) { if(maxLineLen.getSelectedItem() .equals("0")) { maxLineLen.setSelectedItem("80"); } } } else if(source == maxLineLen) { if(!wrap.getSelectedItem().equals("none")) { if(maxLineLen.getSelectedItem() .equals("0")) { wrap.setSelectedItem("none"); } } } } //}}} } //}}} //}}} } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.