📄 codecompletionconfigdialog.java
字号:
package org.jawin.browser.dialog;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import org.jawin.browser.codecompletion.*;
/**
* A dialog that caters for configuring the XSL code completion
* system
*
* <p>Title: Jawin Code Generation GUI</p>
* <p>Description: GUI for exploring type libraries and generating Java code</p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: Open Source Incentive</p>
*
* @author Josh Passenger
* @version 1.0
*/
public class CodeCompletionConfigDialog extends CenteredDialog
{
private JPanel basePanel = new JPanel();
private BorderLayout borderLayout = new BorderLayout();
private JPanel topPanel = new JPanel();
private JPanel buttonPanel = new JPanel();
private JButton okButton = new JButton();
private BorderLayout borderLayout1 = new BorderLayout();
private JButton deleteButton = new JButton();
private JButton newButton = new JButton();
private JSplitPane splitPane = new JSplitPane();
private JScrollPane listScrollPane = new JScrollPane();
private JScrollPane editScrollPane = new JScrollPane();
private CodeCompletionList list = new CodeCompletionList();
private JTextArea textArea = new JTextArea();
private JPanel rightPanel = new JPanel();
private BorderLayout borderLayout2 = new BorderLayout();
private JPanel leftPanel = new JPanel();
private FlowLayout flowLayout1 = new FlowLayout();
private CodeConfigDocumentListener docListener = new CodeConfigDocumentListener(list, textArea);
public CodeCompletionConfigDialog(Frame owner, String title, boolean modal)
{
super(owner, title, modal);
try
{
jbInit();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public CodeCompletionConfigDialog()
{
super();
try
{
jbInit();
}
catch(Exception e)
{
e.printStackTrace();
}
}
private void jbInit() throws Exception
{
this.setSize(new Dimension(400, 350));
basePanel.setLayout(borderLayout);
okButton.setText("OK");
okButton.setPreferredSize(BUTTON_DIMENSION);
buttonPanel.setLayout(borderLayout2);
topPanel.setLayout(borderLayout1);
deleteButton.setEnabled(false);
deleteButton.setText("Delete");
deleteButton.setPreferredSize(BUTTON_DIMENSION);
newButton.setText("New");
newButton.setPreferredSize(BUTTON_DIMENSION);
splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
textArea.setLineWrap(true);
textArea.setTabSize(4);
leftPanel.setLayout(flowLayout1);
flowLayout1.setAlignment(FlowLayout.LEFT);
this.getContentPane().add(basePanel, BorderLayout.CENTER);
basePanel.add(topPanel, BorderLayout.CENTER);
topPanel.add(splitPane, BorderLayout.CENTER);
splitPane.add(listScrollPane, JSplitPane.LEFT);
splitPane.add(editScrollPane, JSplitPane.RIGHT);
basePanel.add(buttonPanel, BorderLayout.SOUTH);
listScrollPane.getViewport().add(list, null);
editScrollPane.getViewport().add(textArea, null);
buttonPanel.add(rightPanel, BorderLayout.EAST);
rightPanel.add(okButton, null);
buttonPanel.add(leftPanel, BorderLayout.CENTER);
leftPanel.add(newButton, null);
leftPanel.add(deleteButton, null);
splitPane.setDividerLocation(150);
textArea.setEditable(false);
textArea.setEnabled(false);
textArea.setBackground(SystemColor.control);
registerListeners();
}
private void registerListeners()
{
newButton.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(ActionEvent e)
{
newConfig();
}
});
deleteButton.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(ActionEvent e)
{
deleteConfig();
}
});
okButton.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(ActionEvent e)
{
ok();
}
});
list.addListSelectionListener(new ListSelectionListener()
{
public void valueChanged(ListSelectionEvent e)
{
listSelectionChanged();
}
});
}
/**
* Create a new code completion entry
*/
private void newConfig()
{
String newName = JOptionPane.showInputDialog(this, "Please enter a name for this code completion entry",
"New code completion", JOptionPane.QUESTION_MESSAGE);
if (newName != null && !newName.trim().equals(""))
{
newName = newName.trim();
CodeCompletionConfig config = new CodeCompletionConfig(newName, "");
list.addConfig(config);
list.clearSelection();
}
}
/**
* Delete the selected config item
*/
private void deleteConfig()
{
CodeCompletionConfig config = (CodeCompletionConfig) list.getSelectedValue();
if (config != null)
{
list.removeConfig(config);
list.clearSelection();
}
}
/**
* OK this dialog, saving changes
*/
private void ok()
{
saveConfig();
dispose();
}
/**
* Save the configuration to disk and to the code completion manager
*/
private void saveConfig()
{
CodeCompletionManager.getInstance().persist();
}
/**
* Fired when the list selection changes
*/
private void listSelectionChanged()
{
CodeCompletionConfig config = (CodeCompletionConfig) list.getSelectedValue();
if (config == null)
{
textArea.setEditable(false);
textArea.setEnabled(false);
textArea.setBackground(SystemColor.control);
textArea.setText("");
deleteButton.setEnabled(false);
}
else
{
textArea.setEditable(true);
textArea.setEnabled(true);
textArea.setBackground(Color.white);
textArea.setText(config.getCode());
textArea.setCaretPosition(0);
deleteButton.setEnabled(true);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -