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

View File

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

View File

@ -565,6 +565,23 @@ public final class Utility
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)
// ---------------------------------------------------------------------------------//