📄 bookmarks.java
字号:
String editName = null;
/**
* A flag that represents the bookmark is being edited rather than
* added.
*/
boolean edit = false;
/**
* Makes a new dialog that allows the user to add or edit a bookmark.
* <b>NOTE:</b> see 'name' and 'edit'.
* @param name if the user wants to edit an existing bookmark,
* 'edit' should be true and 'name' should be the name of that existing
* bookmark. If the user just wants to add a new bookmark, then 'name'
* should be the DN of that bookmark and 'edit' should be false.
* @param edit true if the user wants to edit an existing
* bookmark, false if the user wants to add a new bookmark.
*/
public AddDialog(String name, boolean edit)
{
super(jxplorer, CBIntText.get("Add Bookmark"), null);
this.edit = edit;
if(edit)
{
// Should be the name of a previously saved bookmark...
displayBookmarkDetails(name);
editName = name;
setTitle(CBIntText.get("Edit Bookmark"));
}
else
{
// Should be the DN of the entry that the bookmark will represent...
displayNewBookmarkDetails(name);
}
CBPanel namePanel = new CBPanel();
namePanel.add(new JLabel(CBIntText.get("Bookmark Name: ")));
namePanel.makeWide();
namePanel.add(nameField);
namePanel.makeLight();
OK.setToolTipText(CBIntText.get("Click here to exit when finished."));
OK.setText(CBIntText.get("Save"));
Cancel.setToolTipText(CBIntText.get("Click here to exit."));
// NOTE: the Help button tooltip is set elsewhere (b/c it will be null here).
CBPanel detailsPanel = new CBPanel();
detailsPanel.add(new JLabel(CBIntText.get("DN: ")));
detailsPanel.makeWide();
detailsPanel.addln(dnField);
detailsPanel.makeLight();
detailsPanel.add(new JLabel(CBIntText.get("Description: " )));
detailsPanel.makeWide();
detailsPanel.addln(descField);
detailsPanel.setBorder(new TitledBorder(CBIntText.get(" Bookmark Properties ")));
display.makeWide();
display.addln(namePanel);
display.addln(detailsPanel);
setSize(480, 200);
CBUtility.center(this, jxplorer);
}
public JButton getHelpButton()
{
return Help;
}
/**
* Reads the details of the bookmark from the property file then
* displays the details such as it's DN and it's description
* in their appropriate text fields.
* @param name the name of the bookmark.
*/
protected void displayBookmarkDetails(String name)
{
try
{
nameField.setText(name);
dnField.setText(propertyList.getProperty("dn."+name));
descField.setText(propertyList.getProperty("desc."+name));
}
catch(Exception e)
{
CBUtility.error("Error loading '" + name + "' bookmark. The bookmark cannot be found.", e);
}
}
/**
* Set the text fields in this dialog.<br><br>
* The name text field is set with the RDN of the DN supplied.<br>
* The dn text field is set with the DN supplied.<br>
* The description text field is set to blank.<br>
* @param dn the dn of the bookmark.
*/
public void displayNewBookmarkDetails(String dn)
{
nameField.setText(getCurrentRDN(dn));
dnField.setText(dn);
descField.setText("");
}
/**
* Saves the bookmark to the property file after doing some
* basic checks.<br>
* The checks are if the name is valid, if the bookmark exists and
* if the dn is valid.<br>
* If the user is editing a bookmark and they change the name
* this method asks them if they want to delete the old bookmark.<br>
* The bookmark menu is updated also.
*/
public void doOK()
{
String name = nameField.getText();
String desc = descField.getText();
String dn = dnField.getText();
try
{
// Check if it only contains spaces...
if (!isValidName(name))
{
CBUtility.error(CBIntText.get("The bookmark you are trying to save " +
"contains an invalid Name. Please check the Name then try again."));
return;
}
if(checkIfBookmarkExists(name))
{
int response = JOptionPane.showConfirmDialog(this,
CBIntText.get("Do you want to replace it?"),
CBIntText.get("Bookmark Exists"), JOptionPane.OK_CANCEL_OPTION);
if (response != JOptionPane.OK_OPTION)
return;
}
// Check if the bookmark being added equals 'cn=no entries' or if it
// only contains spaces...
if (!isValidDN(dn))
{
CBUtility.error(CBIntText.get("The bookmark you are trying to save " +
"contains an invalid DN. Please check the DN then try again."));
return;
}
if(edit)
{
if(!name.equals(editName))
{
int response = JOptionPane.showConfirmDialog(this,
CBIntText.get("You have renamed ''{0}'' to ''{1}''. Do you want to delete ''{0}''?",
new String[] {editName,name}),
CBIntText.get("Delete Bookmark?"), JOptionPane.YES_NO_OPTION);
if (response == JOptionPane.YES_OPTION)
deleteBookmark(editName);
}
}
propertyList.setProperty("dn." +name, dn);
propertyList.setProperty("desc."+name, desc);
CBUtility.writePropertyFile(bookmarkPath, propertyList, null);
}
catch(Exception e)
{
CBUtility.error("Cannot add an empty bookmark.");
return;
}
// Updates the Bookmark menu items...
jxplorer.getMainMenu().updateBookmarkMenu();
JOptionPane.showMessageDialog(jxplorer,
CBIntText.get("The bookmark ''{0}'' was successfully saved.",
new String[] {name}), CBIntText.get("Save Succeeded"),
JOptionPane.INFORMATION_MESSAGE );
super.doOK();
}
/**
* When the user hits 'cancel', the window shuts and the bookmark menu is updated.
*/
public void doCancel()
{
super.doCancel();
// Updates the Bookmark menu items...
jxplorer.getMainMenu().updateBookmarkMenu();
}
}
/**
* Opens a dialog that allows a user to select a bookmark
* to edit. Once a bookmark is selected this dialog closes
* and the AddDialog dialog opens.
* @author Trudi.
*/
public class EditDialog
{
/**
* Opens a dialog that allows a user to select a bookmark
* to edit. Once a bookmark is selected this dialog closes
* and the AddDialog dialog opens.
*/
public EditDialog()
{
Object bookmarks[] = getSavedBookmarkNames();
CBJComboBox combo = makeComboBox(bookmarks);
combo.setToolTipText(CBIntText.get("Select the bookmark name that you want to edit."));
int response = JOptionPane.showConfirmDialog(jxplorer, combo,
CBIntText.get("Edit Bookmark"), JOptionPane.OK_CANCEL_OPTION);
if (response != JOptionPane.OK_OPTION)
return;
if (combo.getSelectedItem() != null)
{
String bookmark = combo.getSelectedItem().toString();
AddDialog ad = getAddDialog(bookmark, true);
ad.setVisible(true);
}
}
}
/**
* Opens a dialog that allows a user to select a bookmark
* to delete. Deletes that bookmark.
* @author Trudi.
*/
public class DeleteDialog
{
/**
* Opens a dialog that allows a user to select a bookmark
* to delete. Deletes that bookmark.
*/
public DeleteDialog()
{
Object bookmarks[] = getSavedBookmarkNames();
CBJComboBox combo = makeComboBox(bookmarks);
combo.setToolTipText(CBIntText.get("Select the bookmark name that you want to delete."));
int response = JOptionPane.showConfirmDialog(jxplorer, combo,
CBIntText.get("Delete Bookmark"), JOptionPane.OK_CANCEL_OPTION);
if (response != JOptionPane.OK_OPTION)
return;
if (combo.getSelectedItem()!=null)
{
String toDelete = combo.getSelectedItem().toString();
int res = JOptionPane.showConfirmDialog(jxplorer,
CBIntText.get("Are you sure you want to delete the bookmark called ''{0}''?", new String[] {toDelete}), CBIntText.get("Confirm Delete"), JOptionPane.OK_CANCEL_OPTION);
if (res != JOptionPane.OK_OPTION)
return;
deleteBookmark(toDelete);
JOptionPane.showMessageDialog(jxplorer,
CBIntText.get("The bookmark ''{0}'' was successfully deleted.",
new String[] {toDelete}), CBIntText.get("Delete Succeeded"),
JOptionPane.INFORMATION_MESSAGE );
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -