Hello everybody,
I just discovered JXplorer and I like it. I was missing some features,
so i wrote them for myself and I hope they could be useful for others,
too. They are:
1) support for icons in PNG format
2) ability to copy children DNs in one level to clipboard
3) ability to save children DNs in one level to file
4) ability to paste links for DNs acquired with feature 2
I used sources that are available at sourceforge. I'm not sure how to
use diff properly, but I tried to make a patch (it's in attachment)
Have a nice day
Pavel Benak
diff -r jxplorer/src/com/ca/directory/jxplorer/MainMenu.java ag com/development/JXplorer/src/com/ca/directory/jxplorer/MainMenu.java
38c38
< JMenuItem cut, copy, paste, delete, rename, copyDN, newEntry, pasteAlias;
---
> JMenuItem cut, copy, paste, delete, rename, copyDN, copychildrenDNs, saveChildrenDNsToFile, newEntry, pasteAlias;
299a300,303
> else if (item == copychildrenDNs)
> tree.getPopupTool().copyChildDNs();
> else if (item == saveChildrenDNsToFile)
> tree.getPopupTool().saveChildDnsToFile();
313a318,325
>
> copychildrenDNs = setMenuItem(editMenu, editListener,
> new String[] {CBIntText.get("Copy Children DNs"), "Ctrl+C", CBIntText.get("Copy distinguished names of child entries to the clipboard."), "E", dirImages+"copy_dn.gif"} );
>
> setMenuItem(editMenu, editListener, new String[] {"-", "", "", ""} );
>
> saveChildrenDNsToFile = setMenuItem(editMenu, editListener,
> new String[] {CBIntText.get("Save Children DNs to File"), "", CBIntText.get("Save distinguished names of child entries to file."), "E", dirImages+"copy_dn.gif"} );
diff -r jxplorer/src/com/ca/directory/jxplorer/tree/SmartNode.java ag com/development/JXplorer/src/com/ca/directory/jxplorer/tree/SmartNode.java
108c108
< String[] extensions = {"jpg","gif","jpeg"};
---
> String[] extensions = {"jpg","gif","jpeg", "png"};
diff -r jxplorer/src/com/ca/directory/jxplorer/tree/SmartPopupTool.java ag com/development/JXplorer/src/com/ca/directory/jxplorer/tree/SmartPopupTool.java
16a17,29
> import java.io.BufferedOutputStream;
> import java.io.BufferedWriter;
> import java.io.File;
> import java.io.FileNotFoundException;
> import java.io.FileOutputStream;
> import java.io.IOException;
> import java.io.OutputStream;
> import java.io.OutputStreamWriter;
> import java.io.UnsupportedEncodingException;
> import java.util.Enumeration;
> import java.util.Iterator;
> import java.util.LinkedList;
> import java.util.Vector;
32a46
> LinkedList childrenDNs; // Enumeration storing children DN instances grabbed by 'copy children DNs'
35c49
< JMenuItem cut,copy,paste,pasteAlias,delete,rename,search,newEntry,refresh,copydn,bookmark;
---
> JMenuItem cut,copy,paste,pasteAlias,delete,rename,search,newEntry,refresh,copydn,copychildren,savechildrentofile, bookmark;
60a75,77
> add(copychildren = new JMenuItem(CBIntText.get("Copy Children DNs"), new ImageIcon(dirImage + "copy_dn.gif")));
> add(new JPopupMenu.Separator());
> add(savechildrentofile = new JMenuItem(CBIntText.get("Save Children DNs to file...")));
93a111,115
>
> copychildren.setAccelerator(KeyStroke.getKeyStroke("C".charAt(0), java.awt.Event.CTRL_MASK, false));
> copychildren.setToolTipText(CBIntText.get("Copy distinguished names of child entries to the clipboard"));
>
> savechildrentofile.setToolTipText(CBIntText.get("Save distinguished names of child entries to file"));
182a205,212
>
> /**
> * @return Enumeration of SmartNodes of active node children
> */
> public Enumeration getActiveNodeChildren() {
> SmartModel smartModel = tree.getTreeModel();
> return smartModel.getNodeForDN(smartModel.getDNForPath(getActivePath())).children();
> }
282a313,316
> else if (event == copychildren)
> copyChildDNs();
> else if (event == savechildrentofile)
> saveChildDnsToFile();
297c331,365
< /**
---
> public void saveChildDnsToFile() {
> JFileChooser fileChooser = new JFileChooser();
> //XXX how to get parent?
> if (fileChooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
> File outputFile = fileChooser.getSelectedFile();
> BufferedWriter bw = null;
> try {
> bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputFile), "utf-8"));
> Enumeration children = getActiveNodeChildren();
> while (children.hasMoreElements()) {
> bw.write(((SmartNode) children.nextElement()).getDN().toString());
> bw.newLine();
> }
> bw.close();
> } catch (UnsupportedEncodingException e) {
> // this should never happen
> //XXX how to get parent?
> JOptionPane.showMessageDialog(null, "UTF-8 Encoding is not supported", "Error", JOptionPane.ERROR_MESSAGE);
> } catch (FileNotFoundException e) {
> //XXX how to get parent?
> JOptionPane.showMessageDialog(null, "Unable to open " + outputFile.getName() + " for writing", "Error", JOptionPane.ERROR_MESSAGE);
> } catch (IOException e) {
> JOptionPane.showMessageDialog(null, e.getLocalizedMessage(), "I/O Error", JOptionPane.ERROR_MESSAGE);
> try {
> bw.close();
> } catch (IOException e1) {
> JOptionPane.showMessageDialog(null, e.getLocalizedMessage(), "I/O Error", JOptionPane.ERROR_MESSAGE);
> }
> }
> }
> }
>
>
>
> /**
302d369
<
570,580c637,656
< DN aliasedObject = selectDN;
< if (aliasedObject == null)
< aliasedObject = copyDN;
< if (aliasedObject == null)
< {
< log.warning("no DN selected for aliasing.");
< br.setItemEnabled(br.PASTE_ALIAS, false);
< return;
< }
<
< DN newAlias = new DN(getActiveDN());
---
> if (selectDN != null)
> addAlias(selectDN);
> else
> if (copyDN != null)
> addAlias(copyDN);
> else
> if (childrenDNs != null) {
> Iterator i = childrenDNs.iterator();
> while (i.hasNext())
> addAlias((DN) i.next());
> }
> else {
> log.warning("no DN selected for aliasing.");
> br.setItemEnabled(br.PASTE_ALIAS, false);
> return;
> }
> }
>
> protected void addAlias(DN aliasedObject) {
> DN newAlias = new DN(getActiveDN());
610a687,688
> // if there has been previously copied DN by "Copy Children DNs", null it to distinguish between "Copy Children DNs" and "Copy DN"
> childrenDNs = null;
620a699,721
>
> public void copyChildDNs()
> {
> // if there has been previously copied DN by "Copy DN", null it to distinguish between "Copy DN" and "Copy Children DNs"
> selectDN = null;
> String tempString = "";
> Enumeration children = getActiveNodeChildren();
> childrenDNs = new LinkedList();
> // create string for clipboard and create list of DNs for link pasting
> while (children.hasMoreElements()) {
> SmartNode node = (SmartNode) children.nextElement();
> childrenDNs.add(node.getDN());
> tempString += node.getDN() + "\n";
> }
>
> StringSelection ss = new StringSelection(tempString);
> Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();
> clip.setContents(ss, ss);
>
> if(!tree.getName().equalsIgnoreCase("Schema"))
> br.setItemEnabled(br.PASTE_ALIAS, true);
> br.setItemEnabled(br.PASTE, false);
> }
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Jxplorer-devel mailing list
Jxplorer-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jxplorer-devel