shorten absolute path

This commit is contained in:
Denis Molony 2023-02-24 12:33:21 +10:00
parent 64d5ce9ee2
commit f4a6465b04
3 changed files with 28 additions and 17 deletions

View File

@ -206,8 +206,7 @@ public abstract class AbstractFormattedDisk implements FormattedDisk
DefaultMutableTreeNode root = getCatalogTreeRoot (); DefaultMutableTreeNode root = getCatalogTreeRoot ();
if (root.getUserObject () == null) if (root.getUserObject () == null)
root.setUserObject ( root.setUserObject (new DefaultAppleFileSource (getName (), disk.toString (), this));
new DefaultAppleFileSource (getName (), disk.toString (), this));
} }
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
@ -234,15 +233,15 @@ public abstract class AbstractFormattedDisk implements FormattedDisk
public String getDisplayPath () public String getDisplayPath ()
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
{ {
// if (originalPath != null)
// return originalPath.toString ();
String home = System.getProperty ("user.home"); String home = System.getProperty ("user.home");
String path = originalPath != null ? originalPath.toString () String path =
: disk.getFile ().getAbsolutePath (); originalPath != null ? originalPath.toString () : disk.getFile ().getAbsolutePath ();
if (path.startsWith (home))
return "~" + path.substring (home.length ()); int pos = path.indexOf (home);
if (pos == 0 || (path.startsWith ("/Volumes/") && pos > 0))
return "~" + path.substring (home.length () + pos);
return disk.getFile ().getAbsolutePath (); return disk.getFile ().getAbsolutePath ();
} }
@ -327,8 +326,7 @@ public abstract class AbstractFormattedDisk implements FormattedDisk
if (children != null) if (children != null)
while (children.hasMoreElements ()) while (children.hasMoreElements ())
{ {
DefaultMutableTreeNode childNode = DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) children.nextElement ();
(DefaultMutableTreeNode) children.nextElement ();
if (childNode.getUserObject ().toString ().indexOf (name) > 0) if (childNode.getUserObject ().toString ().indexOf (name) > 0)
return childNode; return childNode;
} }

View File

@ -733,12 +733,8 @@ public class AppleDisk implements Disk
{ {
StringBuilder text = new StringBuilder (); StringBuilder text = new StringBuilder ();
String path = file.getAbsolutePath (); text.append (
String home = System.getProperty ("user.home"); String.format ("Path ......... %s%n", Utility.getShortPath (file.getAbsolutePath ())));
if (path.startsWith (home))
path = "~" + path.substring (home.length ());
text.append (String.format ("Path ......... %s%n", path));
text.append (String.format ("File name .... %s%n", file.getName ())); text.append (String.format ("File name .... %s%n", file.getName ()));
text.append (String.format ("File size .... %,d%n", file.length ())); text.append (String.format ("File size .... %,d%n", file.length ()));
text.append (String.format ("Tracks ....... %d%n", tracks)); text.append (String.format ("Tracks ....... %d%n", tracks));

View File

@ -565,6 +565,23 @@ public final class Utility
return suffixes.contains (getSuffix (filename)); return suffixes.contains (getSuffix (filename));
} }
// ---------------------------------------------------------------------------------//
public static String getShortPath (String path)
// ---------------------------------------------------------------------------------//
{
String home = System.getProperty ("user.home");
if (path.startsWith (home))
path = "~" + path.substring (home.length ());
else if (path.startsWith ("/Volumes/"))
{
int pos = path.indexOf (home);
if (pos > 0)
path = "~" + path.substring (home.length () + pos);
}
return path;
}
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//
public static void reverse (byte[] buffer) public static void reverse (byte[] buffer)
// ---------------------------------------------------------------------------------// // ---------------------------------------------------------------------------------//