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


Permlink Replies: 124 - Pages: 9 [ 1 2 3 4 5 | Next ] - Last Post: 25-Jul-2015 21:51 Last Post By: ctwist
AndreWolff

Posts: 1,775
Registered: 14-Dec-2007
How to set maxImageWidth and maxImageHeight in a Custom panel?
Posted: 21-Apr-2015 20:03
 
  Click to reply to this thread Reply
Until now I enlarged the image dimensions of panorama pictures in Edit Image with variables

maxImageWidth=30000
maxImageHeight=1080

I tried this now to enter this in a more user friendly way via a custom panel, see enclosed screen-shot.
I use this code in onload.bsh:
class CustomUI extends JCustomPanel {
	
	JTextField picHeight = new JSmartTextField(5);
	JTextField picMaxWidth = new JSmartTextField(5);
 
  public void setAlbumObject(AlbumObject ao) {
    super.setAlbumObject(ao);
    saveUI();
    removeAll();
    if (ao != null) {
    	 File currentContextFile = ao.getFile();
    	 if (currentContextFile.isDirectory()) {
	   add("br", new JLabel(texts.getString("ui.noPanoramaPossible")));
      }
      else {
        picHeightLabel = new JLabel("Image height:");	  
        add(picHeightLabel);
  	   add("tab", picHeight);
  	   picMaxWidthLabel = new JLabel("Image max. width:");	  
        add("br",picMaxWidthLabel);
  	   add("tab", picMaxWidth);
      }
    }
    loadUI();
  }
	
	public CustomUI(JAlbumContext context) {
		super(context);		
		// Set up the UI
		setBackground(SystemColor.text);
		setOpaque(true);
		Dimension pSize = new Dimension(200,60);
    		setPreferredSize(pSize);
 
		// Make sure changes are saved even if one doesn't move between images
		FocusListener fl = new FocusAdapter() {
			public void focusLost(FocusEvent e) {
        			saveUI();
        			maxImageWidth = picMaxWidth;
				maxImageHeight = picHeight;
			}
		};
		picHeight.addFocusListener(fl);
		picMaxWidth.addFocusListener(fl);
 
		// Subclasses like us should call init after components are initiated
		init();
	}
}
 
// Make some convenient references available
JAlbumContext context = JAlbumContext.getInstance();
PluginContext pc = context.getPluginContext();
EditPanel editPanel = pc.getEditPanel();
 
CustomUI customUI2 = new CustomUI(context);
// Install custom panel in Jalbum's edit panel
editPanel.addCustomTab("Panorama", customUI2);
This does not give the same effect as I get when I enter maxImageWidth and maxImageHeight in the Variables panel.

What do I wrong?
ctwist

Posts: 546
Registered: 27-Sep-2003
Re: How to set maxImageWidth and maxImageHeight in a Custom panel?
Posted: 23-Apr-2015 03:04   in response to: AndreWolff in response to: AndreWolff
 
  Click to reply to this thread Reply
Coincidentally, I made a similar change last week. This is how I did it.
		new StateMonitor()
		{	public void onChange()
			{ if (vAO != null)
				{	AlbumObjectProperties vProps = vAO.getProperties();
					HashMap vUserVars = (HashMap)vProps.get("userVariables");
					if (SIVPanorama.isSelected())
					{	if (vUserVars == null)
						{	vUserVars = new HashMap();
						}
						vUserVars.put("maxImageWidth", new String("50000"));
					}
					else
					{	if (vUserVars != null)
						{	vUserVars.remove("maxImageWidth");
						}
					}
					if (vUserVars == null || vUserVars.isEmpty())
					{ vProps.remove("userVariables");
					}
					else
					{ vProps.put("userVariables", vUserVars);
					}
					vProps.save();
				}
			}
		}.add(SIVPanorama).done();


Edited by: ctwist on 23-Apr-2015 07:13

Something went wrong when I copied this. The correct version is attached

Edited by: ctwist on 23-Apr-2015 17:52
AndreWolff

Posts: 1,775
Registered: 14-Dec-2007
Re: How to set maxImageWidth and maxImageHeight in a Custom panel?
Posted: 23-Apr-2015 10:28   in response to: ctwist in response to: ctwist
 
  Click to reply to this thread Reply
ctwist wrote:
Coincidentally, I made a similar change last week. This is how I did it.
public void setAlbumObject(AlbumObject pAO)
{ AlbumObjectProperties vProps = pAO.getProperties();
  LinkedHashMap vUserVars = (LinkedHashMap)vProps.get("userVariables");
  if (vUserVars == null)
  { vUserVars = new LinkedHashMap();
  }
  vUserVars.put("maxImageWidth", new String("500"));
  vProps.put("userVariables", vUserVars);
  vProps.save();
}
Thanks for your help!

However, I am a stupid JAVA programmer, so even with your help I have no idea where to insert your code in my Custom panel code (which is not invented by me, but by Heinz-Peter Bader (Dschuwi))

There is already a function setAlbumObject used, for the setup of the UI and I think I have to save the new value of maxImageWidth and maxImageHeight at the end of the CustomUI function after saveUI(), but how do I get there your pAO AlbumObject?

So more help is appreciated!
Dschuwi

Posts: 390
Registered: 12-Nov-2003
Re: How to set maxImageWidth and maxImageHeight in a Custom panel?
Posted: 23-Apr-2015 11:52   in response to: AndreWolff in response to: AndreWolff
 
  Click to reply to this thread Reply
AndreWolff wrote:
However, I am a stupid JAVA programmer, so even with your help I have no idea where to insert your code in my Custom panel code (which is not invented by me, but by Heinz-Peter Bader (Dschuwi))

We have all been there ...
... and "my" code is not not invented by me either ;-)


There is already a function setAlbumObject used, for the setup of the UI and I think I have to save the new value of maxImageWidth and maxImageHeight at the end of the CustomUI function after saveUI(), but how do I get there your pAO AlbumObject?

As a starting point: Put Chris' code right before (or after - it seems to make no difference) the loadUI(); statement in your setAlbumObject method. The code within the the curly brackets only, and change his "pAO" to "ao", because Chris' albumObject is namend "pAO", your's is named "ao" already.

Then watch what happens when you navigate the thumbnails - a user variable "maxThumbWidth" will be created (if it does not exist already) with a value of "500".

To get your custom edit panel value in there, you need to change the line
vUserVars.put("maxImageWidth", new String("500"));
to be populated with your on picMaxWidth variable:
vUserVars.put("maxImageWidth", new String(pixMaxWidth.getText()));


And that's the point now where I am stuck. The user variable "maxImageWIdth" will be updated only if you navigate away from the thumbnail edit window ...
ctwist

Posts: 546
Registered: 27-Sep-2003
Re: How to set maxImageWidth and maxImageHeight in a Custom panel?
Posted: 23-Apr-2015 13:20   in response to: AndreWolff in response to: AndreWolff
 
  Click to reply to this thread Reply
I have re-posted the sample code. I was tired.

My example is slightly different from yours. I provide a checkbox. If the user checks it, I set maxImageWidth to 50000. I don't adjust the height.

vAO is the current AlbumObject. You probably name it differently.

Edited by: ctwist on 23-Apr-2015 07:22
davidekholm

Posts: 3,312
Registered: 18-Oct-2002
Re: How to set maxImageWidth and maxImageHeight in a Custom panel?
Posted: 23-Apr-2015 14:05   in response to: ctwist in response to: ctwist
 
  Click to reply to this thread Reply
I recommend you to change references to LinkedHashMap to HashMap, a LinkedHashMap is a HashMap (extends from HashMap), but clients using it generally has no need to know that it's indeed a LinkedHashMap. If I change the implementation to another kind of HashMap, your code will break if you assume LinkedHashMap.
AndreWolff

Posts: 1,775
Registered: 14-Dec-2007
Re: How to set maxImageWidth and maxImageHeight in a Custom panel?
Posted: 23-Apr-2015 17:32   in response to: ctwist in response to: ctwist
 
  Click to reply to this thread Reply
ctwist wrote:
My example is slightly different from yours. I provide a checkbox. If the user checks it, I set maxImageWidth to 50000. I don't adjust the height.
In which skin is this panel implemented?

I think we both have the same goal: expanding the width of panoramic pictures, so why should we not implement it in the same way?

I think your implementation is even more user friendly as the idea I had in mind, so if you don't mind I can copy it for my skin, in that case I don't have to invent the wheel again.

If you show your complete code here, David can give advise to make it even more reliable, or even better to decide that it will be included in the jAlbum program as I did ask earlier.
ctwist

Posts: 546
Registered: 27-Sep-2003
Re: How to set maxImageWidth and maxImageHeight in a Custom panel?
Posted: 23-Apr-2015 23:55   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
davidekholm wrote:
I recommend you to change references to LinkedHashMap to HashMap
This is fixed in the code sample in my earlier post.
ctwist

Posts: 546
Registered: 27-Sep-2003
Re: How to set maxImageWidth and maxImageHeight in a Custom panel?
Posted: 24-Apr-2015 00:11   in response to: AndreWolff in response to: AndreWolff
 
  Click to reply to this thread Reply
AndreWolff wrote:
In which skin is this panel implemented?
Mirage 7.8.
This is not published yet. I will probably publish it in about 1 week.
You can see an example at panorama sample. You can view the html file and slide.css to see how I display the scrollbar.
I think your implementation is even more user friendly as the idea I had in mind, so if you don't mind I can copy it for my skin, in that case I don't have to invent the wheel again.
Help yourself.
If you show your complete code here, David can give advise to make it even more reliable, or even better to decide that it will be included in the jAlbum program as I did ask earlier.
In customui, create a checkbox skin variable and add the StateMonitor. Nothing else is needed.
AndreWolff

Posts: 1,775
Registered: 14-Dec-2007
Re: How to set maxImageWidth and maxImageHeight in a Custom panel?
Posted: 24-Apr-2015 09:47   in response to: ctwist in response to: ctwist
 
  Click to reply to this thread Reply
ctwist wrote:
Mirage 7.8.
This is not published yet. I will probably publish it in about 1 week.
That will not help me because Mirage has a compiled onload.bsh, so I can't look at the code!

In customui, create a checkbox skin variable and add the StateMonitor. Nothing else is needed.
Well I tried this:
class PanCustomUI extends JCustomPanel {
  JCheckBox SIVPanorama = new JCheckBox("Enlarge the image of this panorama picture");
  public void setAlbumObject(AlbumObject ao) {
    super.setAlbumObject(ao);
    saveUI();
    removeAll();
	if (ao != null) {
		File currentContextFile = ao.getFile();
		if (currentContextFile.isDirectory()) {
			add("br", new JLabel(texts.getString("ui.noPanoramaPossible")));
		}
		else {
			add(SIVPanorama);
			new StateMonitor() {
				public void onChange() {
					AlbumObjectProperties vProps = ao.getProperties();
					HashMap vUserVars = (HashMap)vProps.get("userVariables");
					if (SIVPanorama.isSelected())	{
						if (vUserVars == null) {
							vUserVars = new HashMap();
						}
						vUserVars.put("maxImageWidth", new String("50000"));
					}
					else	{	
						if (vUserVars != null) {	
							vUserVars.remove("maxImageWidth");
						}
					}
					if (vUserVars == null || vUserVars.isEmpty()) { 
						vProps.remove("userVariables");
					}
					else	{
						vProps.put("userVariables", vUserVars);
					}
					vProps.save();
		  		}
			}.add(SIVPanorama).done();
		}
	}
	loadUI();
  }	
  public PanCustomUI(JAlbumContext context) {
	super(context);		
	// Set up the UI
	setBackground(SystemColor.text);
	setOpaque(true);
	Dimension pSize = new Dimension(200,60);
    	setPreferredSize(pSize);
	// Subclasses like us should call init after components are initiated
	init();
  }
}
 
// Make some convenient references available
JAlbumContext context = JAlbumContext.getInstance();
PluginContext pc = context.getPluginContext();
EditPanel editPanel = pc.getEditPanel();
 
PanCustomUI customUI2 = new PanCustomUI(context);
// Install custom panel in Jalbum's edit panel
editPanel.addCustomTab("Panorama", customUI2);
But if I edit a picture, I see only a black screen (with at the right panel the correct Panorama panel) and the System console shows a silent crash starting with:
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: IllegalName: setAlbumObject/BlockNameSpace/BlockNameSpace$9
	at java.lang.ClassLoader.preDefineClass(Unknown Source)
.
.
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)

I have no idea what this message means, for me it is not so simple!

Edited by: AndreWolff on 24-Apr-2015 12:21
ctwist

Posts: 546
Registered: 27-Sep-2003
Re: How to set maxImageWidth and maxImageHeight in a Custom panel?
Posted: 24-Apr-2015 15:49   in response to: AndreWolff in response to: AndreWolff
 
  Click to reply to this thread Reply
AndreWolff wrote:
That will not help me because Mirage has a compiled onload.bsh, so I can't look at the code!
If you looked at the code, I think it would just confuse you. customui.java is provided with Mirage 5.21.
StateMonitor should not be inside setAlbumObject.
AndreWolff

Posts: 1,775
Registered: 14-Dec-2007
Re: How to set maxImageWidth and maxImageHeight in a Custom panel?
Posted: 24-Apr-2015 16:53   in response to: ctwist in response to: ctwist
 
  Click to reply to this thread Reply
ctwist wrote:
StateMonitor should not be inside setAlbumObject.
?? How else does the StateMonitor get access to the used ao or vAO AlbumObject?
ctwist

Posts: 546
Registered: 27-Sep-2003
Re: How to set maxImageWidth and maxImageHeight in a Custom panel?
Posted: 24-Apr-2015 16:59   in response to: AndreWolff in response to: AndreWolff
 
  Click to reply to this thread Reply
vAO is a variable at the class level, i.e. it is also outside setAlbumObject.
AndreWolff

Posts: 1,775
Registered: 14-Dec-2007
Re: How to set maxImageWidth and maxImageHeight in a Custom panel?
Posted: 24-Apr-2015 17:43   in response to: ctwist in response to: ctwist
 
  Click to reply to this thread Reply
ctwist wrote:
vAO is a variable at the class level, i.e. it is also outside setAlbumObject.
After I inserted your StateMonitor after the declaration of the CheckBox:
class PanCustomUI extends JCustomPanel {
  JCheckBox SIVPanorama = new JCheckBox("Enlarge the image of this panorama picture");
  new StateMonitor()
		{	public void onChange()
			{ if (vAO != null)
				{	AlbumObjectProperties vProps = vAO.getProperties();
I get a crash with message
... Target exception: bsh.EvalError: Typed variable declaration : Attempt to resolve method: getProperties() on undefined variable or class name: vAO : at Line: 129 : ..
.which is the last showed line of code.

So I have my doubts whether vAO is known outside setAlbumObject. !!
ctwist

Posts: 546
Registered: 27-Sep-2003
Re: How to set maxImageWidth and maxImageHeight in a Custom panel?
Posted: 24-Apr-2015 18:22   in response to: AndreWolff in response to: AndreWolff
 
  Click to reply to this thread Reply
You need to declare vAO at the class level, and then populate it in setAlbumObject.
Legend
Forum admins
Helpful Answer
Correct Answer

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