This question is answered. Helpful answers available: 1. Correct answers available: 1.


Permlink Replies: 17 - Pages: 2 [ 1 2 | Next ] - Last Post: 25 Jan 22, 12:38 Last Post By: davidekholm
RobM

Posts: 4,174
Registered: 4-Aug-2006
Create AlbumObject as a link
Posted: 22 Jan 22, 22:02
 
  Click to reply to this thread Reply
I have looked through the API for a method of adding/creating an AlbumObject as a linked file, rather than as a file, but can't find one. Obviously it is possible but is it a non-public method?

This is to avoid writing to album files.txt to 'create' the linked file reference. Not a problem if it is jAlbum proprietary code.
ctwist

Posts: 422
Registered: 27-Sep-2003
Re: Create AlbumObject as a link
Posted: 22 Jan 22, 22:48   in response to: RobM in response to: RobM
Helpful
  Click to reply to this thread Reply
You need to create an instance of LinkFile instead of File.

Since I am unsure exactly what you are trying to do, I won't try to provide additional details yet.
RobM

Posts: 4,174
Registered: 4-Aug-2006
Re: Create AlbumObject as a link
Posted: 22 Jan 22, 23:13   in response to: ctwist in response to: ctwist
 
  Click to reply to this thread Reply
ctwist wrote:
You need to create an instance of LinkFile instead of File.
Thanks, I will have a look.
Since I am unsure exactly what you are trying to do, I won't try to provide additional details yet.
I made a tool to convert a project (using folders and files) to a mirrored project linking to those files. The tool read the original project's albumfiles.txt file and wrote a modified one to the equivalent folder of the mirrored project structure (not yet a project). But David has said, in a recent bug post, to 'Never manually read or rely on the contents of albumfiles.txt. Use the AlbumObject abstraction at all times.'

So I'm looking to create a mirrored project from another project. So I thought loop through all of the original project folders and files and create a new project with link references to the old project's files.

If it is too complicated though I might just not recode the tool, just add a warning in the tools forum post.
ctwist

Posts: 422
Registered: 27-Sep-2003
Re: Create AlbumObject as a link
Posted: 22 Jan 22, 23:29   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
I have used LinkFile a few times. If you need guidance, maybe I can help.
RobM

Posts: 4,174
Registered: 4-Aug-2006
Re: Create AlbumObject as a link
Posted: 22 Jan 22, 23:31   in response to: ctwist in response to: ctwist
 
  Click to reply to this thread Reply
ctwist wrote:
I have used LinkFile a few times. If you need guidance, maybe I can help.
Thanks. I'll have a play over the next couple of days and if I get stuck I'll post back.
ctwist

Posts: 422
Registered: 27-Sep-2003
Re: Create AlbumObject as a link
Posted: 22 Jan 22, 23:38   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
You will probably need this:

Is this a linked file?
AlbumObject myAlbumObject;
......
if (myAlbumObject.getFile() instanceof LinkFile)
.........
RobM

Posts: 4,174
Registered: 4-Aug-2006
Re: Create AlbumObject as a link
Posted: 22 Jan 22, 23:45   in response to: ctwist in response to: ctwist
 
  Click to reply to this thread Reply
ctwist wrote:
You will probably need this:

Is this a linked file?

AlbumObject myAlbumObject;
......
if (myAlbumObject.getFile() instanceof LinkFile)
.........
I was thinking of testing via AlbumObject.isLink()
ctwist

Posts: 422
Registered: 27-Sep-2003
Re: Create AlbumObject as a link
Posted: 22 Jan 22, 23:53   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
isLink refers to folders. I haven't used it.

It doesn't seem to be applicable to linked images.
ctwist

Posts: 422
Registered: 27-Sep-2003
Re: Create AlbumObject as a link
Posted: 22 Jan 22, 23:56   in response to: ctwist in response to: ctwist
 
  Click to reply to this thread Reply
BTW
if (myAlbumObject.getFile() instanceof LinkFile)
is not hypothetical. I pulled this from working Mirage code.
RobM

Posts: 4,174
Registered: 4-Aug-2006
Re: Create AlbumObject as a link
Posted: 23 Jan 22, 00:09   in response to: ctwist in response to: ctwist
 
  Click to reply to this thread Reply
ctwist wrote:
isLink refers to folders. I haven't used it.

It doesn't seem to be applicable to linked images.

No it isn't. It does look like the full linking API has not been made available. I guess I'll have to play with the LinkFile Class.
davidekholm

Posts: 4,102
Registered: 18-Oct-2002
Re: Create AlbumObject as a link
Posted: 23 Jan 22, 10:46   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
The isLink() call simply checks whether the embedded File is an instaneof LinkFile. Here's code to add an AlbumObject linking to a file:
import se.datadosen.io.*;
f = new File("/Users/david/My Albums/Welcome to jAlbum/suganth.jpg")
ao = rootFolder.getFactory().createInstance(new LinkFile(rootFolder.getFile(), f.getName(), f), rootFolder);
rootFolder.add(ao);
window.albumExplorer.refreshAction.actionPerformed(null);
RobM

Posts: 4,174
Registered: 4-Aug-2006
Re: Create AlbumObject as a link
Posted: 23 Jan 22, 12:44   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
davidekholm wrote:
The isLink() call simply checks whether the embedded File is an instaneof LinkFile. Here's code to add an AlbumObject linking to a file:
import se.datadosen.io.*;
f = new File("/Users/david/My Albums/Welcome to jAlbum/suganth.jpg")
ao = rootFolder.getFactory().createInstance(new LinkFile(rootFolder.getFile(), f.getName(), f), rootFolder);
rootFolder.add(ao);
window.albumExplorer.refreshAction.actionPerformed(null);
Thank you, that has saved me a lot of head scratching.
davidekholm

Posts: 4,102
Registered: 18-Oct-2002
Re: Create AlbumObject as a link
Posted: 23 Jan 22, 19:53   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
You're welcome Rob
RobM

Posts: 4,174
Registered: 4-Aug-2006
Re: Create AlbumObject as a link
Posted: 24 Jan 22, 20:28   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
An observation for future reference (probably only me would run into this!)

I'm guessing that external tools access project variables at the time the tool is run. Example, load a project, print out rootFolder, run a tool that loads another project and print out rootFolder.
System.out.println("Current Project's root = " + rootFolder);
File anotherProject = new File(pathToAnotherProject, "jalbum-settings.jap");
window.loadProject(anotherProject);
window.albumExplorer.refreshAction.actionPerformed(null);
System.out.println("Another Project's root = " + rootFolder);
Results in, for example:
Sample Portfolio
Sample Portfolio

To get the correct rootFolder you need to use
window.albumExplorer.getRootFolder();
instead of just rootFolder. You then get:
Sample Portfolio
Sample Project
RobM

Posts: 4,174
Registered: 4-Aug-2006
Re: Create AlbumObject as a link
Posted: 25 Jan 22, 00:46   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
For anyone interested.
I have made the changes to the external tool this question was related to.

Not using albumfiles.txt to create the objects in the project, but using the code posted above, means the mirrored project does not reflect the ordering of objects in the original project.

Steps now used are:
Loop through the original project make a list of all of the objects files paths as strings.
Create the folder structure for the mirror project to use.
Copy any page template .info files to the mirror
Import (copy) the project settings file.
Load the mirror project (just empty folders for now)
Loop through the list of file paths and create album objects from each file path
Ask if the original project should have jAlbum specific files removed, and if so do it.

Thanks to everyone who has helped me learn a bit more Java.

Legend
Forum admins
Helpful Answer
Correct Answer

Point your RSS reader here for a feed of the latest messages in all forums