Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access to ContenPane #7

Open
CyclingJack opened this issue Sep 19, 2022 · 3 comments
Open

Access to ContenPane #7

CyclingJack opened this issue Sep 19, 2022 · 3 comments

Comments

@CyclingJack
Copy link

Hello,
I am programming a billing programme for my IT project and I am using jGAF.
I have developed an application interface that loads the appropriate JPanel via the respective menu selection.
This is done in a menu manager class in a switch case loop, in which I assign the component as a frame to a variable via EZEnvironment.getEZUIListener.getApplicationComponent().
But I can't get to the ContentPane of the frame via this. I have to convert this to a JFrame via a cast, from which I can add the panel to the interface via .getContentPane().add(new WorkPanel, BorderLayout.CENTER).
Of course, I would like to do this without a cast, because that can always lead to errors.
Is there another possibility, or can this functionality of accessing the ContentPane directly be included in the framework?

@pgdurand
Copy link
Owner

Hi,

with the current jGAF API (EZEnvironment et al. classes were written before Java introduces Generics), there is no other way than using cast... I understand this is quite "old school" ;-), but I never updated the API to use Generics, enabling a more generic use of various types of Component as the ContentPane...

Patrick

@CyclingJack
Copy link
Author

Hello Patrick,
that's understandable.

In the EZUIStarterImplem class, the EZFrame of JFrame is extended.
There, a reference to this object is written into the class EZEnvironment with the method setParentFrame(this).
However, the method setParentFrame() only has the frame as a transfer parameter. What would be wrong with passing the JFrame here and making it available again via the getApplicationComponent() method? Then you could access the JFrame without a cast and without having to resort to generics.
I'm older and could never really get used to generics, although they make a lot of sense in some places.

Many greetings
Andreas

@pgdurand
Copy link
Owner

Hi Andreas,

first of all: very sorry for the delay of my answer, but unfortunatelly I don't have much time to spend on this project as I would have (because of my current job position).

However, I take the time ;-) to dig into the code. The way the API works is, for short: the framework handles the entire startup of the application and its main Frame, the one that is shown on screen. During that startup procedure, the developper (you, me, etc.) is supposed to populate the Frame with a content (a Component class) through the use of the getApplicationComponent() method (see for instance example: https://github.com/pgdurand/jGAF-Tutorial/blob/master/src/com/plealog/gaf4j/tutorial/part2/TutorialTwoUIStarter.java#L49). That method is not intended to be reused elsewhere, but only during startup. On the other hand, you can get the master application Frame using EZEnvironment.getParentFrame().

When I designed the API, I was a little confused: did I use Frame (AWT) or JFrame (Swing), did I use Component (AWT) or JComponent (Swing). I chose to rely the API on AWT components. But having in mind that getApplicationComponent() should returns a Swing component. This is my mistake in the design of jGAF.

In your original post, maybe I misunderstood this : "This is done in a menu manager class in a switch case loop, in which I assign the component as a frame to a variable via EZEnvironment.getEZUIListener.getApplicationComponent()." As stated above, that method call is intended to be done by the framework, not by "you". For instance, in other softwares where I use jGAF API, if I need to access the content (usually a JPanel) of my master JFrame, I keep a reference to that object somehow.

cheers,
Patrick

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants