org.fife.rtext.plugins.langsupport.PhpOptionsPanel Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rtext Show documentation
Show all versions of rtext Show documentation
RText is a powerful, cross-platform programmer's text editor written in Java. It is designed
to be easy to use, highly customizable and flexible. Part of RText's design is for the source code
to be simple, easy to understand, and well documented, so that other programmers can look into its
inner-workings and figure out how RText ticks with ease. A good place to start (besides the source
code) is the Javadoc for all classes used in the project.
/*
* 05/27/2010
*
* PhpOptionsPanel.java - Options for PHP language support.
* Copyright (C) 2010 Robert Futrell
* robert_futrell at users.sourceforge.net
* http://rtext.fifesoft.com
*
* This file is a part of RText.
*
* RText 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.
*
* RText 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.fife.rtext.plugins.langsupport;
import java.awt.BorderLayout;
import java.awt.ComponentOrientation;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ResourceBundle;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.ImageIcon;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SpringLayout;
import javax.swing.border.Border;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.AbstractDocument;
import org.fife.rsta.ac.LanguageSupport;
import org.fife.rsta.ac.LanguageSupportFactory;
import org.fife.rtext.NumberDocumentFilter;
import org.fife.ui.OptionsDialogPanel;
import org.fife.ui.RButton;
import org.fife.ui.UIUtil;
import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
/**
* Options panel for PHP language support.
*
* @author Robert Futrell
* @version 1.0
*/
class PhpOptionsPanel extends OptionsDialogPanel {
private Listener listener;
private JCheckBox enabledCB;
private JCheckBox showDescWindowCB;
private JCheckBox autoActivateCB;
private JLabel aaDelayLabel;
private JTextField aaDelayField;
private JLabel aaHtmlKeysLabel;
private JTextField aaHtmlKeysField;
private RButton rdButton;
private static final String PROPERTY = "Property";
/**
* Constructor.
*/
public PhpOptionsPanel() {
ResourceBundle msg = Plugin.msg;
setName(msg.getString("Options.Php.Name"));
listener = new Listener();
setIcon(new ImageIcon(getClass().getResource("page_white_php.png")));
ComponentOrientation o = ComponentOrientation.
getOrientation(getLocale());
setLayout(new BorderLayout());
Border empty5Border = UIUtil.getEmpty5Border();
setBorder(empty5Border);
Box cp = Box.createVerticalBox();
cp.setBorder(null);
add(cp, BorderLayout.NORTH);
Box box = Box.createVerticalBox();
box.setBorder(new OptionPanelBorder(msg.
getString("Options.General.Section.General")));
cp.add(box);
cp.add(Box.createVerticalStrut(5));
enabledCB = createCB("Options.General.EnableCodeCompletion");
addLeftAligned(box, enabledCB, 5);
Box box2 = Box.createVerticalBox();
if (o.isLeftToRight()) {
box2.setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 0));
}
else {
box2.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 20));
}
box.add(box2);
showDescWindowCB = createCB("Options.General.ShowDescWindow");
addLeftAligned(box2, showDescWindowCB, 5);
box2.add(Box.createVerticalGlue());
box = Box.createVerticalBox();
box.setBorder(new OptionPanelBorder(
msg.getString("Options.General.AutoActivation")));
cp.add(box);
autoActivateCB = createCB("Options.General.EnableAutoActivation");
addLeftAligned(box, autoActivateCB, 5);
box2 = Box.createVerticalBox();
if (o.isLeftToRight()) {
box2.setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 0));
}
else {
box2.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 20));
}
box.add(box2);
SpringLayout sl = new SpringLayout();
JPanel temp = new JPanel(sl);
aaDelayLabel = new JLabel(msg.getString("Options.General.AutoActivationDelay"));
aaDelayField = new JTextField(10);
AbstractDocument doc = (AbstractDocument)aaDelayField.getDocument();
doc.setDocumentFilter(new NumberDocumentFilter());
doc.addDocumentListener(listener);
aaHtmlKeysLabel = new JLabel(msg.getString("Options.Php.AutoActivationHtmlKeys"));
aaHtmlKeysLabel.setEnabled(false);
aaHtmlKeysField = new JTextField("<", 10);
aaHtmlKeysField.setEnabled(false);
if (o.isLeftToRight()) {
temp.add(aaDelayLabel); temp.add(aaDelayField);
temp.add(aaHtmlKeysLabel); temp.add(aaHtmlKeysField);
}
else {
temp.add(aaDelayField); temp.add(aaDelayLabel);
temp.add(aaHtmlKeysField); temp.add(aaHtmlKeysLabel);
}
UIUtil.makeSpringCompactGrid(temp, 2,2, 0,0, 5,5);
JPanel temp2 = new JPanel(new BorderLayout());
temp2.add(temp, BorderLayout.LINE_START);
box2.add(temp2);
box2.add(Box.createVerticalGlue());
cp.add(Box.createVerticalStrut(5));
rdButton = new RButton(msg.getString("Options.General.RestoreDefaults"));
rdButton.addActionListener(listener);
addLeftAligned(cp, rdButton, 5);
cp.add(Box.createVerticalGlue());
applyComponentOrientation(o);
}
private JCheckBox createCB(String key) {
if (key.indexOf('.')==-1) {
key = "Options.Php." + key;
}
JCheckBox cb = new JCheckBox(Plugin.msg.getString(key));
cb.addActionListener(listener);
return cb;
}
/**
* {@inheritDoc}
*/
protected void doApplyImpl(Frame owner) {
LanguageSupportFactory lsf = LanguageSupportFactory.get();
LanguageSupport ls=lsf.getSupportFor(SyntaxConstants.SYNTAX_STYLE_PHP);
// Options dealing with code completion.
ls.setAutoCompleteEnabled(enabledCB.isSelected());
ls.setShowDescWindow(showDescWindowCB.isSelected());
// Options dealing with auto-activation.
ls.setAutoActivationEnabled(autoActivateCB.isSelected());
int delay = 300;
String temp = aaDelayField.getText();
if (temp.length()>0) {
try {
delay = Integer.parseInt(aaDelayField.getText());
} catch (NumberFormatException nfe) { // Never happens
nfe.printStackTrace();
}
}
ls.setAutoActivationDelay(delay);
}
/**
* {@inheritDoc}
*/
protected OptionsPanelCheckResult ensureValidInputsImpl() {
return null;
}
/**
* {@inheritDoc}
*/
public JComponent getTopJComponent() {
return enabledCB;
}
private void setAutoActivateCBSelected(boolean selected) {
autoActivateCB.setSelected(selected);
aaDelayLabel.setEnabled(selected);
aaDelayField.setEnabled(selected);
//aaHtmlKeysLabel.setEnabled(selected);
//aaHtmlKeysField.setEnabled(selected);
}
private void setEnabledCBSelected(boolean selected) {
enabledCB.setSelected(selected);
showDescWindowCB.setEnabled(selected);
}
/**
* {@inheritDoc}
*/
protected void setValuesImpl(Frame owner) {
LanguageSupportFactory lsf = LanguageSupportFactory.get();
LanguageSupport ls=lsf.getSupportFor(SyntaxConstants.SYNTAX_STYLE_PHP);
// Options dealing with code completion
setEnabledCBSelected(ls.isAutoCompleteEnabled());
showDescWindowCB.setSelected(ls.getShowDescWindow());
// Options dealing with auto-activation
setAutoActivateCBSelected(ls.isAutoActivationEnabled());
aaDelayField.setText(Integer.toString(ls.getAutoActivationDelay()));
}
/**
* Listens for events in this options panel.
*/
private class Listener implements ActionListener, DocumentListener {
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
if (enabledCB==source) {
// Trick related components to toggle enabled states
setEnabledCBSelected(enabledCB.isSelected());
hasUnsavedChanges = true;
firePropertyChange(PROPERTY, null, null);
}
else if (showDescWindowCB==source) {
hasUnsavedChanges = true;
firePropertyChange(PROPERTY, null, null);
}
else if (rdButton==source) {
if (!enabledCB.isSelected() ||
!showDescWindowCB.isSelected() ||
!autoActivateCB.isSelected() ||
!"300".equals(aaDelayField.getText())) {
setEnabledCBSelected(true);
showDescWindowCB.setSelected(true);
setAutoActivateCBSelected(true);
aaDelayField.setText("300");
hasUnsavedChanges = true;
firePropertyChange(PROPERTY, null, null);
}
}
}
public void changedUpdate(DocumentEvent e) {
handleDocumentEvent(e);
}
private void handleDocumentEvent(DocumentEvent e) {
hasUnsavedChanges = true;
firePropertyChange(PROPERTY, null, null);
}
public void insertUpdate(DocumentEvent e) {
handleDocumentEvent(e);
}
public void removeUpdate(DocumentEvent e) {
handleDocumentEvent(e);
}
}
}