📄 rtextfilechooseroptionpanel.java
字号:
/*****************************************************************************/
/**
* Initializes the macro list.
*
* @param fileChooser The file chooser whose properties you want to use to
* initialize this options panel.
* @see #configureFileChooser
*/
public void initialize(RTextFileChooser fileChooser) {
boolean showHiddenFiles = fileChooser.getShowHiddenFiles();
hiddenFilesCheckBox.setSelected(showHiddenFiles);
hiddenColorButton.setColor(fileChooser.getHiddenFileColor());
hiddenColorButton.setEnabled(showHiddenFiles);
autoCompleteCheckBox.setSelected(fileChooser.getFileSystemAware());
colorTableModel.initCustomColorTable(fileChooser);
}
/*****************************************************************************/
/**
* Called whenever the extension/color mapping table is changed.
*
* @param e An event describing the change.
*/
public void modifiableTableChanged(ModifiableTableChangeEvent e) {
hasUnsavedChanges = true;
firePropertyChange(COLOR_CHANGED_PROPERTY, null,
new Integer(e.getRow()));
}
/*****************************************************************************/
/********************** PRIVATE INNER CLASSES ********************************/
/*****************************************************************************/
/**
* The dialog that allows the user to add or modify an extension/color
* mapping.
*/
static class ExtensionColorMappingDialog extends JDialog
implements ActionListener, ChangeListener, DocumentListener {
/**
*
*/
private static final long serialVersionUID = 4302662701802847367L;
static final int OK = 0;
static final int CANCEL = 1;
private JTextField extensionField;
private JColorChooser colorChooser;
private JButton okButton;
private JButton cancelButton;
private int rc;
public ExtensionColorMappingDialog(JDialog owner) {
super(owner);
ResourceBundle msg = ResourceBundle.
getBundle(MAPPING_DIALOG_BUNDLE);
JPanel contentPane = new JPanel(new BorderLayout());
contentPane.setBorder(UIUtilities.getEmpty5Border());
// Panel containing main stuff.
JPanel topPanel = new JPanel();
topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.Y_AXIS));
JPanel temp = new JPanel(new BorderLayout());
temp.setBorder(BorderFactory.createEmptyBorder(0,0,5,0));
JLabel label = RUtilities.createLabel(msg,
"Extension.Text", "Extension.Mnemonic");
JPanel temp2 = new JPanel(new BorderLayout());
temp2.setBorder(BorderFactory.createEmptyBorder(0,0,0,5));
temp2.add(label);
temp.add(temp2, BorderLayout.WEST);
extensionField = new JTextField();
extensionField.getDocument().addDocumentListener(this);
label.setLabelFor(extensionField);
temp.add(extensionField);
topPanel.add(temp);
colorChooser = new JColorChooser();
colorChooser.getSelectionModel().addChangeListener(this);
topPanel.add(colorChooser);
contentPane.add(topPanel, BorderLayout.NORTH);
// Panel containing buttons for the bottom.
JPanel buttonPanel = new JPanel();
buttonPanel.setBorder(BorderFactory.createEmptyBorder(5,5,0,5));
temp = new JPanel(new GridLayout(1,2, 5,5));
okButton = RUtilities.createRButton(msg,
"OK.Text", "OK.Mnemonic");
okButton.addActionListener(this);
temp.add(okButton);
cancelButton = RUtilities.createRButton(msg,
"Cancel.Text", "Cancel.Mnemonic");
cancelButton.addActionListener(this);
temp.add(cancelButton);
buttonPanel.add(temp);
contentPane.add(buttonPanel, BorderLayout.SOUTH);
// Get ready to go.
setTitle(msg.getString("Title"));
setContentPane(contentPane);
getRootPane().setDefaultButton(okButton);
setModal(true);
pack();
}
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
if (source==okButton)
rc = OK;
setVisible(false);
}
public void changedUpdate(DocumentEvent e) {
}
public Color getColor() {
return colorChooser.getColor();
}
public String getExtension() {
return extensionField.getText();
}
public void insertUpdate(DocumentEvent e) {
okButton.setEnabled(true);
}
public void removeUpdate(DocumentEvent e) {
okButton.setEnabled(extensionField.getDocument().getLength()>0);
}
public void setData(String extension, Color color) {
extensionField.setText(extension);
colorChooser.setColor(color);
}
public void setVisible(boolean visible) {
if (visible) {
String extension = extensionField.getText();
extensionField.setEnabled(
!extension.equals(defaultColorString));
}
super.setVisible(visible);
}
public int showMappingDialog() {
rc = CANCEL; // Set here in case they "X" the dialog out.
SwingUtilities.invokeLater(new Runnable() {
public void run() {
extensionField.requestFocusInWindow();
extensionField.selectAll();
}
});
setLocationRelativeTo(getOwner());
okButton.setEnabled(false);
setVisible(true);
return rc;
}
public void stateChanged(ChangeEvent e) {
// Ensure the document has text in it.
okButton.setEnabled(extensionField.getDocument().getLength()>0);
}
}
/*****************************************************************************/
/**
* The table model used by the custom colors table.
*/
private class ColorTableModel extends DefaultTableModel {
/**
*
*/
private static final long serialVersionUID = -2086537690424048621L;
private String[] columnNames;
public ColorTableModel(String extensionHeader, String colorHeader) {
super();
columnNames = new String[2];
columnNames[0] = extensionHeader;
columnNames[1] = colorHeader;
}
public int getColumnCount() {
return columnNames.length;
}
public String getColumnName(int column) {
return columnNames[column];
}
public void initCustomColorTable(RTextFileChooser chooser) {
setRowCount(0);
Vector v = new Vector(2);
v.add(defaultColorString);
v.add(chooser.getDefaultFileColor());
addRow(v);
HashMap map = chooser.getCustomColorsMap();
Set keySet = map.keySet();
if (keySet!=null) {
for (Iterator it=keySet.iterator(); it.hasNext(); ) {
// DefaultTableModel uses Vectors internally.
v = new Vector(2);
String extension = (String)it.next();
Color c = (Color)map.get(extension);
v.add(extension);
v.add(c);
addRow(v);
}
}
}
public boolean isCellEditable(int row, int column) {
return false;
}
}
/*****************************************************************************/
/**
* Handles the addition, removal, and modifying of rows in the color
* table.
*/
class FileChooserRowHandler implements RowHandler {
private ExtensionColorMappingDialog dialog;
public Object[] getNewRowInfo(Object[] oldData) {
if (dialog==null)
dialog = new ExtensionColorMappingDialog(getOptionsDialog());
if (oldData==null)
dialog.setData(null, null);
else
dialog.setData((String)oldData[0], (Color)oldData[1]);
int rc = dialog.showMappingDialog();
if (rc==ExtensionColorMappingDialog.OK) {
return new Object[] { dialog.getExtension(),
dialog.getColor() };
}
return null;
}
public boolean shouldRemoveRow(int row) {
// Row 0 is always "<Defualt>," which the user cannot remove.
return row>0;
}
}
/*****************************************************************************/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -