⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 syntaxschemedialog.java

📁 具有不同语法高亮的编辑器实例
💻 JAVA
字号:
/*
 * 08/06/2004
 *
 * SyntaxSchemeDialog.java - A subdialog used by the RSyntaxTextAreaOptionPanel
 *                           allowing the user to modify a syntax scheme for a
 *                           particular token type.
 * Copyright (C) 2004 Robert Futrell
 * email@address.com
 * www.website.com
 *
 * 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.fife.ui.rsyntaxtextarea;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ResourceBundle;
import javax.swing.*;

import org.fife.ui.RButton;
import org.fife.ui.RColorSwatchesButton;


/**
 * A subdialog used by <code>RSyntaxTextAreaOptionPanel</code> allowing the user
 * to modify a syntax scheme for a particular token type.
 *
 * @author Robert Futrell
 * @version 0.2
 */
class SyntaxSchemeDialog extends JDialog implements ActionListener {

	/**
	 * 
	 */
	private static final long serialVersionUID = -2720407649345760828L;

	public static final String OK_PRESSED		= "SyntaxSchemeDialog.OKPressed";
	public static final String CANCEL_PRESSED	= "SyntaxSchemeDialog.CancelPressed";

	private SyntaxScheme currentScheme;	// The scheme currently selected.
	private ActionListener doneListener;

	private JLabel fontLabel;
	private RColorSwatchesButton fontColorButton;

	private JCheckBox backgroundCheckBox;
	private RColorSwatchesButton backgroundColorButton;

	private JCheckBox boldCheckBox;
	private JCheckBox italicCheckBox;
	private JCheckBox underlineCheckBox;

	private RButton okButton;
	private RButton cancelButton;


/*****************************************************************************/


	/**
	 * Constructor.
	 *
	 * @param owner The parent frame.
	 * @param scheme The syntax scheme to start off showing.
	 * @param doneListener Someone listening for this dialog to disappear
	 *                     (i.e., the cell editor).  When this dialog is
	 *                     hidden, the listener will receive one of
	 *                     <code>OK_PRESSED</code> or
	 *                     <code>CANCEL_PRESSED</code>.
	 * @param resources The resource bundle with which to label everything
	 *        (an instance of org.fife.ui.rsyntaxtextarea.ResourceBundle).
	 */
	public SyntaxSchemeDialog(Frame owner, ActionListener doneListener,
							ResourceBundle resources) {

		super(owner);
		setTitle(resources.getString("SyntaxDialogTitle"));

		Dimension spacer = new Dimension(5,5);

		JPanel contentPane = new JPanel();
		contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
		contentPane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));

		JPanel temp = new JPanel();
		temp.setLayout(new BoxLayout(temp, BoxLayout.X_AXIS));
		temp.setAlignmentX(JComponent.LEFT_ALIGNMENT);
		fontLabel = new JLabel(resources.getString("FontColor"));
		temp.add(fontLabel);
		fontColorButton = new RColorSwatchesButton(Color.BLACK);
		fontLabel.setLabelFor(fontColorButton);
		temp.add(fontColorButton);
		temp.add(Box.createHorizontalGlue());
		contentPane.add(temp);

		// Must go through all this trouble for a little space, as the rigid
		// area is a Component and thus we cannot set its alignment.
		temp = new JPanel();
		temp.setAlignmentX(JComponent.LEFT_ALIGNMENT);
		temp.add(Box.createRigidArea(spacer));
		contentPane.add(temp);

		temp = new JPanel();
		temp.setLayout(new BoxLayout(temp, BoxLayout.X_AXIS));
		temp.setAlignmentX(JComponent.LEFT_ALIGNMENT);
		backgroundCheckBox = new JCheckBox(resources.getString("Background"));
		backgroundCheckBox.setActionCommand("BackgroundCheckBox");
		backgroundCheckBox.addActionListener(this);
		temp.add(backgroundCheckBox);
		backgroundColorButton = new RColorSwatchesButton(Color.WHITE);
		temp.add(backgroundColorButton);
		temp.add(Box.createHorizontalGlue());
		contentPane.add(temp);

		temp = new JPanel();
		temp.setAlignmentX(JComponent.LEFT_ALIGNMENT);
		temp.add(Box.createRigidArea(spacer));
		contentPane.add(temp);

		temp = new JPanel();
		temp.setLayout(new BoxLayout(temp, BoxLayout.X_AXIS));
		temp.setAlignmentX(JComponent.LEFT_ALIGNMENT);
		boldCheckBox = new JCheckBox(resources.getString("Bold"));
		boldCheckBox.setActionCommand("Bold");
		boldCheckBox.addActionListener(this);
		temp.add(boldCheckBox);
		italicCheckBox = new JCheckBox(resources.getString("Italic"));
		italicCheckBox.setActionCommand("Italic");
		italicCheckBox.addActionListener(this);
		temp.add(italicCheckBox);
		underlineCheckBox = new JCheckBox(resources.getString("Underline"));
		underlineCheckBox.setActionCommand("Underline");
		underlineCheckBox.addActionListener(this);
underlineCheckBox.setEnabled(false);
		temp.add(underlineCheckBox);
		temp.add(Box.createHorizontalGlue());
		contentPane.add(temp);

		temp = new JPanel();
		temp.setAlignmentX(JComponent.LEFT_ALIGNMENT);
		temp.add(Box.createRigidArea(spacer));
		contentPane.add(temp);

		temp = new JPanel();
		temp.setAlignmentX(JComponent.LEFT_ALIGNMENT);
		okButton = new RButton(resources.getString("OK"));
		okButton.setActionCommand("OK");
		okButton.addActionListener(this);
		temp.add(okButton);
		cancelButton = new RButton(resources.getString("Cancel"));
		cancelButton.setActionCommand("Cancel");
		cancelButton.addActionListener(this);
		temp.add(cancelButton);
		contentPane.add(temp);

		// Get everything ready to go!
		setContentPane(contentPane);
		setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
		setModal(true);
		setResizable(false);
		setLocationRelativeTo(null);
		pack();

	}


/*****************************************************************************/


	/**
	 * Listens for actions performed in this dialog.
	 */
	public void actionPerformed(ActionEvent e) {

		String actionCommand = e.getActionCommand();

		if (actionCommand.equals("OK")) {
			currentScheme.foreground = fontColorButton.getColor();
			if (backgroundCheckBox.isSelected())
				currentScheme.background = backgroundColorButton.getColor();
			else
				currentScheme.background = null;
			setVisible(false);
			if (doneListener!=null)
				doneListener.actionPerformed(new ActionEvent(
						this, ActionEvent.ACTION_PERFORMED, OK_PRESSED));
		}

		else if (actionCommand.equals("Cancel")) {
			currentScheme = null;	// Signifies the cancel.
			setVisible(false);
			if (doneListener!=null)
				doneListener.actionPerformed(new ActionEvent(
						this, ActionEvent.ACTION_PERFORMED, CANCEL_PRESSED));
		}

		else if (actionCommand.equals("BackgroundCheckBox")) {
			backgroundColorButton.setEnabled(backgroundCheckBox.isSelected());
		}

		else if (actionCommand.equals("Bold")) {
			currentScheme.font = currentScheme.font.deriveFont(
							currentScheme.font.getStyle()|Font.BOLD);
		}

		else if (actionCommand.equals("Italic")) {
			currentScheme.font = currentScheme.font.deriveFont(
							currentScheme.font.getStyle()|Font.ITALIC);
		}

		else if (actionCommand.equals("Underline")) {
		}

	}


/*****************************************************************************/


	/**
	 * Returns the selected syntax scheme.
	 *
	 * @return The selected syntax scheme, or <code>null</code> if the dialog
	 *         was cancelled.
	 */
	public SyntaxScheme getSelectedScheme() {
		return currentScheme;
	}


/*****************************************************************************/


	/**
	 * Sets the currently displayed syntax scheme.
	 *
	 * @param scheme The syntax scheme to display.
	 */
	public void setSyntaxScheme(SyntaxScheme scheme) {

		currentScheme = scheme;

		fontColorButton.setColor(currentScheme.foreground==null ? Color.BLACK : currentScheme.foreground);
		backgroundColorButton.setColor(currentScheme.background==null ? Color.WHITE : currentScheme.background);
		backgroundCheckBox.setSelected(currentScheme.background!=null);
		backgroundColorButton.setEnabled(currentScheme.background!=null);

		boldCheckBox.setSelected((scheme.font.getStyle()&Font.BOLD)==Font.BOLD);
		italicCheckBox.setSelected((scheme.font.getStyle()&Font.ITALIC)==Font.ITALIC);

	}


/*****************************************************************************/

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -