This question is answered.


Permlink Replies: 21 - Pages: 2 [ 1 2 | Next ] - Last Post: 18-Oct-2020 13:55 Last Post By: JeffTucker Threads: [ Previous | Next ]
AndreWolff

Posts: 1,883
Registered: 14-Dec-2007
Panoramic custom panel code gives errors in NetBeans
Posted: 15-Oct-2020 12:26
 
  Click to reply to this thread Reply
As a last step in the FancyBox GUI conversion process, I ported the Panoramic custom panel from the old onload.bsh code to a new file FancyBoxCustom.java file:
import java.awt.SystemColor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.JCheckBox;
import se.datadosen.jalbum.AlbumObject;
import se.datadosen.jalbum.AlbumObjectProperties;
import se.datadosen.jalbum.JAlbumContext;
import se.datadosen.jalbum.JCustomPanel;
 
/*
 * Begin custom Panoramic image panel, see http://jalbum.net/forum/message.jspa?messageID=315528#315528
 * Orignal code of Dschuwi adapted to add the pan360 checkbox
 */
class CustomUI extends JCustomPanel {
  AlbumObject cAO;
  AlbumObjectProperties cProps;
  JCheckBox panoramicSphericalImage = new JCheckBox("Spherical panoramic image",false);
  JCheckBox panoramicImage = new JCheckBox("Cylindrical panoramic image",false);
  JCheckBox pan360 = new JCheckBox("<html>360° panorama</html>",false);
    
  public void setAlbumObject(AlbumObject ao) {
    super.setAlbumObject(ao);
//    saveUI();
//   removeAll();
    if (ao != null) {
      cAO = ao;
      cProps = cAO.getProperties();
      File currentContextFile = ao.getFile();
      add(panoramicSphericalImage);
      add("br",panoramicImage);
      add("br", pan360);
      pan360.setEnabled(panoramicImage.isSelected());
      loadUI();
    }
  }
	
  public CustomUI(JAlbumContext context) {
    super(context);		
    // Set up the UI
    setBackground(SystemColor.text);
    setOpaque(true);
    panoramicSphericalImage.setBackground(SystemColor.text);
    panoramicImage.setBackground(SystemColor.text);
    pan360.setBackground(SystemColor.text);
 
    pan360.addActionListener(new ActionListener() {
       public void actionPerformed(ActionEvent e) {
          cProps.save();
        }
    }
  );
 
    panoramicSphericalImage.addActionListener(new ActionListener() {
       public void actionPerformed(ActionEvent e) {
          if (panoramicSphericalImage.isSelected()) {
	panoramicImage.setSelected(false);
	pan360.setEnabled(false);
	cProps.remove("maxImageWidth");
	cProps.remove("panoramicImage");
	cProps.remove("pan360");
          }
          cProps.save();
        }
    }
  );
    
    // Enable maxImageWidth field if panoramicImage is checked, otherwise remove userVariables
    panoramicImage.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        if (panoramicImage.isSelected()) {
        	panoramicSphericalImage.setSelected(false);
	cProps.put("maxImageWidth", "50000");
        }
        else {
          cProps.remove("maxImageWidth");
          cProps.remove("panoramicImage");
          cProps.remove("pan360");
        }
        cProps.save();
        pan360.setEnabled(panoramicImage.isSelected());
      }
    }
    );
  // 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 CustomUI = new CustomUI(context);
// Install custom panel in Jalbum's edit panel
editPanel.addCustomTab("Panoramic image", CustomUI);
/*
 * End custom edit view panel
 */
All last lines behind // Make some convenient references available show red lines.
The hint says: class, interface or enum expected

How can I solve this?

BTW Is it not allowed or recommended to add this code to the GUI file FancyBox.java?

Edited by: AndreWolff on 15-Oct-2020 12:26
davidekholm

Posts: 3,454
Registered: 18-Oct-2002
Re: Panoramic custom panel code gives errors in NetBeans
Posted: 15-Oct-2020 13:16   in response to: AndreWolff in response to: AndreWolff
 
  Click to reply to this thread Reply
In Java, as opposed to BeanShell, you're not allowed to put ordinary statements straight within a class definition, or outside a class definition. Ordinary statements (i.e. not declarative statements) need to be put within a method. The problematic line in your case is this:
editPanel.addCustomTab("Panoramic image", CustomUI);
That is not a declarative statement. You can solve it by putting that statement within a constructor method, or even within an "anonymous constructor method", i.e. within two curly braces:
{
  editPanel.addCustomTab("Panoramic image", CustomUI);
}
That code will then be executed when a class instance of that class is created.
AndreWolff

Posts: 1,883
Registered: 14-Dec-2007
Re: Panoramic custom panel code gives errors in NetBeans
Posted: 15-Oct-2020 13:45   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
Well I tried this:
JAlbumContext context = JAlbumContext.getInstance();
        
PluginContext pc = context.getPluginContext();
 
EditPanel editPanel = pc.getEditPanel();
 
CustomUI CustomUI = new CustomUI(context);
// Install custom panel in Jalbum's edit panel
{
  editPanel.addCustomTab("Panoramic image", CustomUI);
}
This removes indeed the red lines below the editPanel statement, but the other lines and the brackets have still red lines.

I have the java file enclosed.
davidekholm

Posts: 3,454
Registered: 18-Oct-2002
Re: Panoramic custom panel code gives errors in NetBeans
Posted: 15-Oct-2020 14:39   in response to: AndreWolff in response to: AndreWolff
 
  Click to reply to this thread Reply
Hover the mouse over the red icons to reveal the cause. Perhaps you just need to make an import.
AndreWolff

Posts: 1,883
Registered: 14-Dec-2007
Re: Panoramic custom panel code gives errors in NetBeans
Posted: 15-Oct-2020 14:43   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
davidekholm wrote:
Hover the mouse over the red icons to reveal the cause.
The yellow window says: class, interface or enum expected
Perhaps you just need to make an import.
Ctrl+Shift + I has no effect.
JeffTucker

Posts: 7,401
Registered: 31-Jan-2006
Re: Panoramic custom panel code gives errors in NetBeans
Posted: 15-Oct-2020 14:48   in response to: davidekholm in response to: davidekholm
Correct
  Click to reply to this thread Reply
I don't add the custom tab to the edit panel within the code for the custom edit panel - I do it in the main skin method. Take a look at any of my skins. For example, at the very end of Pluto.java:
// Install components into jAlbum
        window.setSkinUI(ui);
        window.pack();
// Add custom UI
        JAlbumContext custcontext = JAlbumContext.getInstance();
        PluginContext pc = custcontext.getPluginContext();
        EditPanel editPanel = pc.getEditPanel();
        PlutoCustom customUI = new PlutoCustom(custcontext);
        editPanel.addCustomTab("Pluto", customUI);
    }
}
davidekholm

Posts: 3,454
Registered: 18-Oct-2002
Re: Panoramic custom panel code gives errors in NetBeans
Posted: 15-Oct-2020 15:04   in response to: AndreWolff in response to: AndreWolff
 
  Click to reply to this thread Reply
AndreWolff wrote:
davidekholm wrote:
Hover the mouse over the red icons to reveal the cause.
The yellow window says: class, interface or enum expected
Perhaps you just need to make an import.
Ctrl+Shift + I has no effect.

I see, you're not even within the class scope. Just move the "}" ending the class definition down so it encloses those lines of code too. In the topmost scope of Java, only class, interface or enums are allowed.
davidekholm

Posts: 3,454
Registered: 18-Oct-2002
Re: Panoramic custom panel code gives errors in NetBeans
Posted: 15-Oct-2020 15:08   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
Think of Java code structured in a hierarchy like this:
A tree of file system folders for each package
   Folders containing .java files,
     each file containing either the keywords "class", "interface" or "enum", at most one of them public (dictating the file name too) 
        Each of these classes containing variable- and method declarations
           Each method containing either declarations or statements.

BeanShell, in contrast is a scripting language, allowing code statements in any scope.
AndreWolff

Posts: 1,883
Registered: 14-Dec-2007
Re: Panoramic custom panel code gives errors in NetBeans
Posted: 15-Oct-2020 16:25   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
jGromit wrote:
I don't add the custom tab to the edit panel within the code for the custom edit panel - I do it in the main skin method. Take a look at any of my skins.
Yes indeed that solves the problem!

Thanks you very much!

In contrast to the Pluto skin, I have all the code in one file FancyBox.java and that seems to work.
Not sure what the purpose of your file SlideModel.java is and whether I need it too.
AndreWolff

Posts: 1,883
Registered: 14-Dec-2007
Re: Panoramic custom panel code gives errors in NetBeans
Posted: 15-Oct-2020 16:26   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
davidekholm wrote:
Just move the "}" ending the class definition down so it encloses those lines of code too. In the topmost scope of Java, only class, interface or enums are allowed.
Yes, that works and thereafter I could fix the imports and compile it without errors.
However after I moved the result to the skin, the panoramic panel was still not visible.

But luckily jGromit's method worked
JeffTucker

Posts: 7,401
Registered: 31-Jan-2006
Re: Panoramic custom panel code gives errors in NetBeans
Posted: 15-Oct-2020 17:37   in response to: AndreWolff in response to: AndreWolff
 
  Click to reply to this thread Reply
AndreWolff wrote:
Not sure what the purpose of your file SlideModel.java is and whether I need it too.

SkinModel.java defines the variables that are on the main skin panels. SlideModel.java defines the variables that are on the custom edit panel. They apply only to individual objects, not to the entire project.
AndreWolff

Posts: 1,883
Registered: 14-Dec-2007
Re: Panoramic custom panel code gives errors in NetBeans
Posted: 15-Oct-2020 19:26   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
jGromit wrote:
SlideModel.java defines the variables that are on the custom edit panel. They apply only to individual objects, not to the entire project.
The default value of all variables in my custom panel for an image are false / 0, so I assume that I don't need that file.

Thanks for the information.
JeffTucker

Posts: 7,401
Registered: 31-Jan-2006
Re: Panoramic custom panel code gives errors in NetBeans
Posted: 15-Oct-2020 19:35   in response to: AndreWolff in response to: AndreWolff
Helpful
  Click to reply to this thread Reply
AndreWolff wrote:
The default value of all variables in my custom panel for an image are false / 0, so I assume that I don't need that file.

Well, if you don't mind having your album build fail because you're trying to check the value of a variable that hasn't been defined....
if(localSomething) do this;
If there's no default value declared for localSomething, the album build will blow up. If a variable hasn't been defined, it's not false - it's void.

We don't do things for no reason.
AndreWolff

Posts: 1,883
Registered: 14-Dec-2007
Re: Panoramic custom panel code gives errors in NetBeans
Posted: 15-Oct-2020 20:41   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
jGromit wrote:
Well, if you don't mind having your album build fail because you're trying to check the value of a variable that hasn't been defined....
if(localSomething) do this;
If there's no default value declared for localSomething, the album build will blow up. If a variable hasn't been defined, it's not false - it's void.

We don't do things for no reason.

Ok I will try it, but does a SlideModel.java file has an effect if the custom panel code is defined together with the other GUI code in my file FancyBox.java or is it a must that the custom panel code comes in a separate file?
JeffTucker

Posts: 7,401
Registered: 31-Jan-2006
Re: Panoramic custom panel code gives errors in NetBeans
Posted: 15-Oct-2020 21:41   in response to: AndreWolff in response to: AndreWolff
 
  Click to reply to this thread Reply
It doesn't matter where you define the variables - all in one file, or in two separate files.

SkinModel.java sets defaults for variables that apply to the entire project. SlideModel.java sets defaults for variables that apply only to individual objects (images, folders, whatever).
Legend
Forum admins
Helpful Answer
Correct Answer

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