📄 syntaxschemecelleditor.java
字号:
/*
* 07/30/2004
*
* SyntaxSchemeCellEditor.java - Editor for a JTable allowing you to select a
* syntax scheme for a cell.
* 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.Color;
import java.awt.Component;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ResourceBundle;
import javax.swing.AbstractCellEditor;
import javax.swing.JButton;
import javax.swing.JTable;
import javax.swing.table.TableCellEditor;
/**
* An editor for a <code>JTable</code> allowing you to select a syntax scheme
* for a cell.
*
* @author Robert Futrell
* @version 1.0
*/
public class SyntaxSchemeCellEditor extends AbstractCellEditor implements
TableCellEditor, ActionListener {
/**
*
*/
private static final long serialVersionUID = 7174958280264656223L;
/**
* The syntax scheme the user chooses.
*/
private SyntaxScheme scheme;
/**
* The component used to know when to edit.
*/
private JButton button;
/**
* The dialog we display.
*/
private SyntaxSchemeDialog dialog;
/*****************************************************************************/
/**
* Constructor.
*
* @param owner The frame that owns this cell editor.
* @param resources The resource bundle with which to label everything
* (an instance of org.fife.ui.rsyntaxtextarea.ResourceBundle).
*/
public SyntaxSchemeCellEditor(Frame owner, ResourceBundle resources) {
button = new JButton("Example text");
button.setActionCommand("edit");
button.addActionListener(this);
button.setBorderPainted(false);
//Set up the dialog that the button brings up.
dialog = new SyntaxSchemeDialog(owner, this, resources);
}
/*****************************************************************************/
/**
* Listens for actions in this class.
*/
public void actionPerformed(ActionEvent e) {
String actionCommand = e.getActionCommand();
// If the user has clicked on a cell...
if (actionCommand.equals("edit")) {
button.setBackground(scheme.background==null ? Color.WHITE : scheme.background);
button.setForeground(scheme.foreground==null ? Color.BLACK : scheme.foreground);
dialog.setSyntaxScheme(scheme);
dialog.setVisible(true);
fireEditingStopped();
}
//User pressed the dialog's "OK" button.
else if (actionCommand.equals(SyntaxSchemeDialog.OK_PRESSED)) {
scheme = dialog.getSelectedScheme();
}
else if (actionCommand.equals(SyntaxSchemeDialog.CANCEL_PRESSED)) {
scheme = null;
}
}
/*****************************************************************************/
/**
* Returns the value contained in the editor.
*
* @return The value; in this case, the syntax scheme.
*/
public Object getCellEditorValue() {
return scheme;
}
/*****************************************************************************/
/**
* Sets the initial value for the editor.
*
* @return The component for editing.
*/
public Component getTableCellEditorComponent(JTable table, Object value,
boolean isSelected,
int row, int column) {
scheme = (SyntaxScheme)value;
return button;
}
/*****************************************************************************/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -