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


Permlink Replies: 6 - Pages: 1 - Last Post: 15-Mar-2016 13:54 Last Post By: JeffTucker
RobM

Posts: 3,247
Registered: 4-Aug-2006
Help, I don't understand what I'm doing!
Posted: 15-Mar-2016 02:07
 
  Click to reply to this thread Reply
I have compiled some Custom User Interface skin code (mostly lifted from others), without errors, but I can't get two aspects of it to work properly.

1: How do I disable the file chooser button, as I have for the style selector if the object is not a folder?

2: How do I get the file chooser to save the selected files as I do for the selected style?
(The style can be set per folder but the file chooser is being set for all items).

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
 
/**
 *
 * @author robert
 */
 
import java.awt.Component;
import java.awt.SystemColor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JTextField;
import se.datadosen.component.JLabelFor;
import se.datadosen.component.StateMonitor;
import se.datadosen.jalbum.AlbumBean;
import se.datadosen.jalbum.AlbumObject;
import se.datadosen.jalbum.Config;
import se.datadosen.jalbum.JAlbumContext;
import se.datadosen.jalbum.JAlbumUtilities;
import se.datadosen.jalbum.JCustomPanel;
import se.datadosen.jalbum.StyleFileFilter;
import se.datadosen.util.SmartResourceBundle;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;
import se.datadosen.jalbum.DeferredChooser;
import se.datadosen.util.IO;
import se.datadosen.util.Item;
 
import se.datadosen.component.JLabelFor;
 
 
 
class SprintCustomUI extends JCustomPanel {
    
// Fields
    JComboBox<String> showStyles = new JComboBox(new String[]{""});
    {
	   JAlbumUtilities.fillCombo(showStyles, new File(Config.getConfig().chainedSkinsDir.getFile(context.getEngine().getSkin()), "styles"), new StyleFileFilter());
    }
//Texts    
    SmartResourceBundle texts;
    AlbumBean engine;
 
// Set up custom UI panel
    public SprintCustomUI(JAlbumContext context) {
	   super(context);
            DeferredChooser ffc = new DeferredChooser(JFileChooser.class);
            FileFilter ffilter = new FileNameExtensionFilter("JPEG file", new String[] {"jpg", "jpeg"});
            ffc.setFileFilter(ffilter);
            
            JButton folderImgThemeSelector=new JButton("Select header image");
            JTextField folderImageTheme = new JTextField("");
            JTextField folderImageThemeFullPath = new JTextField("");
            
// Listeners
 
           folderImgThemeSelector.addActionListener(new ActionListener() {
               private Component window;
        	public void actionPerformed(ActionEvent e) {
                    int bgImageReturn = ffc.showOpenDialog(window);
                    if (bgImageReturn == JFileChooser.APPROVE_OPTION) {
			folderImageTheme.setText(ffc.getSelectedFile().getName());
			folderImageThemeFullPath.setText(ffc.getSelectedFile().getPath());
                    }
                }
           });
           
            new StateMonitor() {
		 public void onChange() {
                    saveUI();
		 }
	   }.add(showStyles).add(folderImageTheme).add(folderImageThemeFullPath);
   
//Texts
            engine = context.getEngine();
            Vars vars = new Vars(engine);
            texts = vars.getTexts();
// Layout
	   setBackground(SystemColor.text);
	   setOpaque(false);
	   add("br", new JLabelFor(texts.getString("ui.selectStyle"), showStyles));
	   add("br", showStyles);
           add("br", folderImgThemeSelector);
           add("br", folderImageTheme);
           add("br", folderImageThemeFullPath);
           putClientProperty("helpPage", "http://jalbum.net/help/en/Skin/Sprint/Settings/Style_Override");
 
// Init
	   init();
    }
    public void setAlbumObject(AlbumObject ao) {
	   if (ao != null) {
		  super.setAlbumObject(ao);
		  showStyles.setEnabled(currentAO.isFolder());
	   }
    }
}
Sorry for the amount of code, I'm not sure how much I could trim and still leave it meaningful.
JeffTucker

Posts: 6,958
Registered: 31-Jan-2006
Re: Help, I don't understand what I'm doing!
Posted: 15-Mar-2016 05:17   in response to: RobM in response to: RobM
Helpful
  Click to reply to this thread Reply
RobM wrote:
1: How do I disable the file chooser button, as I have for the style selector if the object is not a folder?

Isn't it just:
public void setAlbumObject(AlbumObject ao) {
 	   if (ao != null) {
 		  super.setAlbumObject(ao);
 		  showStyles.setEnabled(currentAO.isFolder());
 		  folderImgThemeSelector.setEnabled(currentAO.isFolder());
 	   }
     }
JeffTucker

Posts: 6,958
Registered: 31-Jan-2006
Re: Help, I don't understand what I'm doing!
Posted: 15-Mar-2016 05:32   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
RobM wrote:
2: How do I get the file chooser to save the selected files as I do for the selected style?
(The style can be set per folder but the file chooser is being set for all items).

I guess I don't understand the question. The code you've got should be saving folderImageTheme and folderImageThemeFullPath for whatever folder is the current album object (in the folder's .info file). That doesn't actually copy the chosen file into the project, of course - it's just saving the name of the file and the path to the file.

Somewhere in the skin's template files, it would need to copy that file into the project somewhere. Is that the part that has you stumped?
RobM

Posts: 3,247
Registered: 4-Aug-2006
Re: Help, I don't understand what I'm doing!
Posted: 15-Mar-2016 11:19   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
jGromit wrote:
RobM wrote:
1: How do I disable the file chooser button, as I have for the style selector if the object is not a folder?

Isn't it just:

public void setAlbumObject(AlbumObject ao) {
 	   if (ao != null) {
 		  super.setAlbumObject(ao);
 		  showStyles.setEnabled(currentAO.isFolder());
 		  folderImgThemeSelector.setEnabled(currentAO.isFolder());
 	   }
     }
I'm sure I tried that last night but as it was late I will try it again.
RobM

Posts: 3,247
Registered: 4-Aug-2006
Re: Help, I don't understand what I'm doing!
Posted: 15-Mar-2016 11:26   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
jGromit wrote:
RobM wrote:
2: How do I get the file chooser to save the selected files as I do for the selected style?
(The style can be set per folder but the file chooser is being set for all items).

I guess I don't understand the question.

I can move through the album objects and in th edit GUI set a style for each, if I then go back through the objects they each have their own style displayed in the selector. If I do the same for the file chooser every object shows the last selected image instead of their own. I haven't written the code to process the images yet,
RobM

Posts: 3,247
Registered: 4-Aug-2006
Re: Help, I don't understand what I'm doing!
Posted: 15-Mar-2016 12:34   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
Thanks for your help, something didn't seem right but I was flummoxed, now got it working properly :) I just had to move the image fields from the control panel section to the fields section above. All those items are now shown in green as variables, before they were just plain black text.
JeffTucker

Posts: 6,958
Registered: 31-Jan-2006
Re: Help, I don't understand what I'm doing!
Posted: 15-Mar-2016 13:54   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
Yeah, that's the way I normally set things up - define the fields, then wade into the control panel stuff.

Just make sure you also have a SlideModel.java file that sets default values for those variables, or you'll end up chasing your own tail in the skin templates later.
Legend
Forum admins
Helpful Answer
Correct Answer

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