Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > [SWING] Apply Decorator pattern to JProgressBar

Reply
Thread Tools

[SWING] Apply Decorator pattern to JProgressBar

 
 
Hole
Guest
Posts: n/a
 
      10-14-2009
Good Afternoon,

I have a nice JDialog window showing multiple progress bars.
Now, I would like to add decorated progress bars (it should be a panel
with a JLabel and a JProgressBar) to the JDialog's content pane so I
guessed I need to create a new component by Decorator pattern applied
to JProgressBar.


I read the decorator pattern documentation but I'm quite confused.
Does the decorator class extend the component that is being decorated
or the component that decorate?

Thanks!!!
 
Reply With Quote
 
 
 
 
Rzeźnik
Guest
Posts: n/a
 
      10-14-2009
On 14 Paź, 14:37, Hole <h0lefor...@gmail.com> wrote:
> Good Afternoon,
>
> I have a nice JDialog window showing multiple progress bars.
> Now, I would like to add decorated progress bars (it should be a panel
> with a JLabel and a JProgressBar) to the JDialog's content pane so I
> guessed I need to create a new component by Decorator pattern applied
> to JProgressBar.
>
> I read the decorator Â*pattern documentation but I'm quite confused.
> Does the decorator class extend the component that is being decorated
> or the component that decorate?


Hi
No, decorator typically does not extend decorated class (though it
usually extends some shared base class).
What you probably want to do is to make a composite component with
JLabel and a progress bar as its parts and delegate painting to them
(you might want LayoutManager instance as well). The other way is to
extend JProgressBar and redefine its painting method as needed (or UI
painting method). Nice example of composite controls is here:
https://flamingo.dev.java.net - browse CVS for JSlider, it is very
simple control so you should not have trouble in understanding what is
going on there.



 
Reply With Quote
 
 
 
 
John B. Matthews
Guest
Posts: n/a
 
      10-14-2009
In article
<600c2d3b-b519-4da5-a6cb->,
Hole <> wrote:

> I have a nice JDialog window showing multiple progress bars. Now, I
> would like to add decorated progress bars (it should be a panel with
> a JLabel and a JProgressBar) to the JDialog's content pane so I
> guessed I need to create a new component by Decorator pattern applied
> to JProgressBar.


The requirement that "it should be a panel with a JLabel and a
JProgressBar" suggests composition, as outlined here:

class LabelBar extends JPanel {
private JLabel label;
private JProgressBar bar;
public LabelBar(...) { ... }
...
}

Using suitable parameters, add LabelBar instances to a JPanel that
becomes your JDialog's contentPane.

> I read the decorator pattern documentation but I'm quite confused.
> Does the decorator class extend the component that is being decorated
> or the component that decorate?


Decoration seems more suited to altering the behavior of an existing
component:

<http://www.patterndepot.com/put/8/JavaPatterns.htm>

--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>
 
Reply With Quote
 
Hole
Guest
Posts: n/a
 
      10-15-2009
On Oct 14, 7:06*pm, "John B. Matthews" <nos...@nospam.invalid> wrote:
> In article
> <600c2d3b-b519-4da5-a6cb-a801a87b1...@l9g2000yqi.googlegroups.com>,
>
> *Hole <h0lefor...@gmail.com> wrote:
> > I have a nice JDialog window showing multiple progress bars. Now, I
> > would like to add decorated progress bars (it should be a panel with
> > a JLabel and a JProgressBar) to the JDialog's content pane so I
> > guessed I need to create a new component by Decorator pattern applied
> > to JProgressBar.

>
> The requirement that "it should be a panel with a JLabel and a
> JProgressBar" suggests composition, as outlined here:
>
> class LabelBar extends JPanel {
> * * private JLabel label;
> * * private JProgressBar bar;
> * * public LabelBar(...) { ... }
> * * ...
>
> }
>
> Using suitable parameters, add LabelBar instances to a JPanel that
> becomes your JDialog's contentPane.
>
> > I read the decorator *pattern documentation but I'm quite confused.
> > Does the decorator class extend the component that is being decorated
> > or the component that decorate?

>
> Decoration seems more suited to altering the behavior of an existing
> component:
>
> <http://www.patterndepot.com/put/8/JavaPatterns.htm>
>
> --
> John B. Matthews
> trashgod at gmail dot com
> <http://sites.google.com/site/drjohnbmatthews>


Thanks to all of you.
I wanted to extend JProgressBar to prevent too many modifies to code.
However, I simply extended JPanel (as John suggests) and did some
refactoring sessions.

Cheers!!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Using 'apply' as a decorator, to define constants alex23 Python 7 08-22-2009 08:11 PM
Why doesnt __getattr__ with decorator dont call __get_method in decorator glomde Python 5 03-29-2007 02:48 PM
Still slightly clueless about this GUI thing...(JProgressBar never draws on a JDialog) Inertia_sublimation Java 5 01-03-2004 12:05 AM
Update of JProgressBar Cengiz Java 2 08-07-2003 10:07 AM
[XSLT] could not apply "apply-templates" Stefan Siegl XML 1 07-18-2003 09:43 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57