?? filerenamedialog.java
字號:
/** * File and FTP Explorer * Copyright 2002 * BOESCH Vincent * * 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 (at your option) 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 javaexplorer.gui.dialog;import java.awt.*;import java.awt.event.*;import java.util.*;import javaexplorer.Launcher;import javaexplorer.model.*;import javaexplorer.ressource.*;import javaexplorer.ressource.MagicNumber;import javaexplorer.util.comparator.*;import javax.swing.*;import javax.swing.border.*;import javax.swing.table.*;/** *@author BOESCH Vincent *@created 21 janvier 2002 *@version 3.3 * * 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 (at your option) 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. */public class FileRenameDialog extends JDialog implements ActionListener { private XFile[] _fileList = null; private Launcher _launcher = null; BorderLayout borderLayout1 = new BorderLayout(); BorderLayout borderLayout2 = new BorderLayout(); private BorderLayout borderLayout3 = new BorderLayout(); private GridLayout gridLayout1 = new GridLayout(); JPanel jPanel1 = new JPanel(); JPanel jPanel2 = new JPanel(); JPanel jPanel3 = new JPanel(); JPanel jPanel4 = new JPanel(); private JPanel jPanel5 = new JPanel(); JButton jbtCancel = new JButton(); JButton jbtGo = new JButton(); JButton jbtOk = new JButton(); private JButton jbtReset = new JButton(); JLabel jlblChangeExt = new JLabel(); JTable jtbRename = new JTable(); JScrollPane jspRename = new JScrollPane(jtbRename); JTextField jtfNewExt = new JTextField(); TitledBorder titledBorder1; /** * Constructeur objet FileRenameDialog * *@param frame Description of the * Parameter *@param launcher Description of the * Parameter */ public FileRenameDialog(JFrame frame, Launcher launcher) { super(frame, TextRessource.FILE_RENAME_DLG_RENAME + "...", true); _launcher = launcher; try { jbInit(); } catch (Exception e) { javaexplorer.util.Log.addError(e); } } /** * Description de la methode * *@param e Description of the Parameter */ public void actionPerformed(ActionEvent e) { Object obj = e.getSource(); if (obj == jbtOk) { // Valider inscription de donn閑s en cours jtbRename.dispatchEvent(new KeyEvent(this, KeyEvent.KEY_PRESSED, new Date().getTime(), 0, KeyEvent.VK_ENTER, KeyEvent.CHAR_UNDEFINED)); renameListFile(); closeWindow(); return; } if (obj == jbtCancel) { closeWindow(); return; } if (obj == jbtGo) { String newExt = cleanExtension(jtfNewExt.getText()); if (newExt.length() > 0) { changeAllExtension(newExt); } // Remplacer le texte original de jtfNewExt par le nouvel extension propre jtfNewExt.setText(newExt); } if (obj == jbtReset) { initData(); } } /** * Description de la methode * *@param newExt Description of the Parameter */ private void changeAllExtension(String newExt) { String oldExt; String ext; String fileName; //On ne prend dans l'extension que la derniere valeur sans point ext = MagicNumber.getExtension(newExt); for (int i = 0; i < _fileList.length; i++) { try { fileName = (String) jtbRename.getModel().getValueAt(i, 1); oldExt = MagicNumber.getExtension(fileName); if (oldExt != null) { fileName = fileName.substring(0, fileName.length() - oldExt.length() - 1); } fileName = fileName + '.' + ext; jtbRename.getModel().setValueAt(fileName, i, 1); } catch (Exception e) { javaexplorer.util.Log.addError(e); } } } /** * Description de la methode * *@param ext Description of the Parameter *@return Description of the Return * Value */ public String cleanExtension(String ext) { if (ext != null) { ext = ext.trim(); int fin = ext.length(); while ((fin > 0) && (ext.charAt(fin - 1) == '.')) { --fin; } int d閎ut = 0; while ((d閎ut < fin) && (ext.charAt(d閎ut) == '.')) { ++d閎ut; } if (d閎ut < fin) { return ext.substring(d閎ut, fin); } } return ""; } /** * Description de la methode */ public void closeWindow() { setVisible(false); dispose(); } /** * Description de la methode */ public void initData() { if (_fileList == null) { return; } DefaultTableModel dtm = new DefaultTableModel(new String[] { TextRessource.FILE_RENAME_DLG_RENAME, TextRessource.FILE_RENAME_DLG_TO }, _fileList.length); for (int i = 0; i < _fileList.length; i++) { dtm.setValueAt(_fileList[i].toString(), i, 0); dtm.setValueAt(_fileList[i].getName(), i, 1); } jtbRename.setModel(dtm); } /** * Description de la methode * *@throws Exception Description of the * Exception */ private void jbInit() throws Exception { titledBorder1 = new TitledBorder(""); jPanel1.setLayout(borderLayout1); jPanel1.setBorder(titledBorder1); jtbRename.setBorder(BorderFactory.createLineBorder(Color.black)); jPanel2.setLayout(borderLayout2); jbtCancel.setText(TextRessource.MAINFRAME_GLOBAL_CANCEL); jbtCancel.addActionListener(this); jbtOk.setText(TextRessource.MAINFRAME_GLOBAL_VALIDATE); jbtOk.addActionListener(this); jPanel4.setLayout(borderLayout3); jlblChangeExt.setText(TextRessource.FILE_RENAME_DLG_CHANGE_EXTENSIONS + "..."); jbtGo.setText(TextRessource.FILE_RENAME_DLG_GO); jbtGo.addActionListener(this); jPanel5.setLayout(gridLayout1); jbtReset.setText(TextRessource.FILE_RENAME_DLG_RESET); jbtReset.addActionListener(this); jPanel4.setBorder(BorderFactory.createEtchedBorder()); jtfNewExt.setMinimumSize(new Dimension(60, 21)); jtfNewExt.setPreferredSize(new Dimension(90, 21)); jPanel5.add(jtfNewExt, null); jPanel5.add(jbtGo, null); jPanel5.add(jbtReset, null); this.getContentPane().add(jPanel1, BorderLayout.CENTER); jPanel1.add(jspRename, BorderLayout.CENTER); jPanel1.add(jPanel2, BorderLayout.SOUTH); jPanel2.add(jPanel3, BorderLayout.SOUTH); jPanel3.add(jbtOk, null); jPanel3.add(jbtCancel, null); jPanel2.add(jPanel4, BorderLayout.NORTH); jPanel4.add(jlblChangeExt, BorderLayout.WEST); jPanel4.add(jPanel5, BorderLayout.SOUTH); jbtGo.addActionListener(this); } /** * Description de la methode */ private void renameListFile() { if (_fileList == null) { return; } String newName = null; for (int i = 0; i < _fileList.length; i++) { try { newName = (String) jtbRename.getModel().getValueAt(i, 1); if (!_fileList[i].getName().equals(newName)) { _fileList[i].renameTo(newName); _launcher.getMDIModel().refreshDisks(_fileList[i].getXParent()); } } catch (Exception e) { javaexplorer.util.Log.addError(e); } } } /** * Sets the fileList attribute of the * FileRenameDialog object * *@param tb_file The new fileList value */ public void setFileList(XFile[] tb_file) { _fileList = tb_file; Arrays.sort(_fileList, XFileComparator.getComparator()); initData(); } /** * Sets the launcher attribute of the * FileRenameDialog object * *@param launcher The new launcher value */ public void setLauncher(Launcher launcher) { _launcher = launcher; }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -