Flyweight Pattern use with multiple GUI components

Hi,
I am creating a simple application and I would like your advice on wether I should use the flyweight pattern or not.
My application is essentially a GUI front to a repository of small images. The GUI (in its simplest form) is a single window that will display all the images with their names in a clickable thumbnail format. The user will be able to select an thumbnail icon, drag it and move it around pretty much like the icons on your computer desktop.
The easiest way to do that is probably to load each image and its name into a JLabel, add it in a JFrame and write just few lines of code (say by extending the JLabel class) to handle mouse pressed/dragged events in order to move the label around. The rest will be taken care of by the swing functinality (e.g. painting etc).
However, I am considering using the flyweight pattern for efficiency but I am not sure if it is appropriate. So far I have seen simplistic examples of its use (apart from JTree) where the pattern is used to paint dozens of lines on the screen or the borders of components. But what happens if instead of lines or borders the objects in question are interactive GUI components such as my thumbnails? how does the flyweight pattern work in this case?
For example if I create just a single JLabel and use it to paint all my icons that's great! but what happens with mouse events? what happens when I want to drag a thumbnail over another one and how the partial repainting of the thumbnail below should be handled?
Am I missing something here, or in order to implement the flyiweight pattern in this case I will have to write endless lines of code to replicate the functionality that swing arleady provides in each JComponent? (e.g. targetting of mouse events, repainting etc)
Cheers,
Kyri

I don't think Flyweight applies, because you really don't want to share any UI component that generates events unless the response is the same for all of them.
If you read Flyweight, I think it was intended for things like caching the first 128 Integers, etc. - think finite, countable, immutable things. I don't think UI elements apply.
%

Similar Messages

  • "detected a page fragment with multiple root components" warning

    I am getting a warning on the standalone WLS when I run my page that contains a taskflow as region. I am using a page fragment in my taskflow.
    <Warning> <oracle.adfinternal.view.faces.renderkit.rich.RegionRenderer> <ADF_FACES-60099> <The region component with id: ptMain:r1 has detected a page fragment with multiple root components. Fragments with more than one root component may not display correctly in a region and may have a negative impact on performance. It is recommended that you restructure the page fragment to have a single root component.>
    The warning states the obvious, I have everything within a panelheader in my page fragment. Also, I do not get the warning on the integrated WLS. Any ideas as to why this warning is still popping up in the log? I am using JDev 11.1.1.3.
    Thanks,
    Jessica

    Thank you for responding. I do not have any popups. I do, however, have another region nested within this fragment ( have this warning on another fragment that doesn't have a nested region though). Here is the code for my fragment.
    <?xml version='1.0' encoding='UTF-8'?>
    <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
    xmlns:af="http://xmlns.oracle.com/adf/faces/rich"
    xmlns:f="http://java.sun.com/jsf/core">
    <af:panelHeader text="Pawn"
    binding="#{backingBeanScope.backing_Fragments_PawnSearch.ph1}"
    id="ph1" type="default">
    <af:panelFormLayout id="pfl2">
    <af:panelSplitter binding="#{backingBeanScope.backing_Fragments_PawnSearch.ps1}"
    id="ps1" orientation="vertical" splitterPosition="62"
    inlineStyle="width:775px; height:660px;">
    <f:facet name="first">
    <af:panelBox text="Search #{bindings.agency.inputValue} Data to Update"
    binding="#{backingBeanScope.backing_Fragments_PawnSearch.pb1}"
    id="pb1">
    <f:facet name="toolbar"/>
    <af:panelGroupLayout id="pgl3" layout="horizontal">
    <af:inputText value="#{bindings.control_number.inputValue}"
    label="Control Number" required="true"
    columns="#{bindings.control_number.hints.displayWidth}"
    maximumLength="#{bindings.control_number.hints.precision}"
    shortDesc="#{bindings.control_number.hints.tooltip}"
    id="it1">
    <f:validator binding="#{bindings.control_number.validator}"/>
    </af:inputText>
    <af:inputDate value="#{bindings.trans_date.inputValue}"
    label="Date" required="true"
    shortDesc="#{bindings.trans_date.hints.tooltip}"
    id="id1">
    <f:validator binding="#{bindings.trans_date.validator}"/>
    <af:convertDateTime pattern="#{bindings.trans_date.format}"/>
    </af:inputDate>
    <af:inputText value="#{bindings.agency.inputValue}" simple="true"
    required="#{bindings.agency.hints.mandatory}"
    columns="#{bindings.agency.hints.displayWidth}"
    maximumLength="#{bindings.agency.hints.precision}"
    shortDesc="#{bindings.agency.hints.tooltip}"
    binding="#{backingBeanScope.backing_Fragments_PawnSearch.it2}"
    id="it2" visible="false">
    <f:validator binding="#{bindings.agency.validator}"/>
    </af:inputText>
    <af:commandButton actionListener="#{bindings.ExecuteWithParams.execute}"
    text="Search"
    disabled="#{!bindings.ExecuteWithParams.enabled}"
    id="cb5"
    returnListener="#{backingBeanScope.backing_Fragments_PawnSearch.refreshPage}"
    action="#{backingBeanScope.backing_Fragments_PawnSearch.RenderMe}">
    <af:setActionListener from="#{bindings.PawnItemView1Iterator.currentRowKeyString}"
    to="#{requestScope.pawnkey}"/>
    </af:commandButton>
    <af:spacer width="10" height="10"
    binding="#{backingBeanScope.backing_Fragments_PawnSearch.s1}"
    id="s1"/>
    <af:goButton text="Clear Values and Create New" id="gb1"
    destination="index.jspx"
    rendered="#{backingBeanScope.backing_Fragments_PawnSearch.saveButtonRendered}"/>
    </af:panelGroupLayout>
    </af:panelBox>
    </f:facet>
    <f:facet name="second">
    <af:panelGroupLayout binding="#{backingBeanScope.backing_Fragments_PawnSearch.pgl4}"
    id="pgl4" layout="scroll" partialTriggers=""
    visible="true">
    <af:panelGroupLayout binding="#{backingBeanScope.backing_Fragments_PawnSearch.pgl6}"
    id="pgl6" inlineStyle="width:775px;"
    visible="#{backingBeanScope.backing_Fragments_PawnSearch.renderTF}">
    <af:region value="#{bindings.PawnEntryFormTF1.regionModel}"
    id="r1" inlineStyle="width:750px;"/>
    </af:panelGroupLayout>
    <af:panelGroupLayout binding="#{backingBeanScope.backing_Fragments_PawnSearch.pgl5}"
    id="pgl5" layout="horizontal"
    visible="#{backingBeanScope.backing_Fragments_PawnSearch.renderMessage}">
    <af:outputFormatted value="No #{bindings.agency.inputValue} Pawn data matching the Control Number and Transaction Date from above."
    binding="#{backingBeanScope.backing_Fragments_PawnSearch.of1}"
    id="of1"
    inlineStyle="font-weight:bolder; font-size:small;"/>
    <af:spacer width="10" height="10"
    binding="#{backingBeanScope.backing_Fragments_PawnSearch.s2}"
    id="s2"/>
    <af:goButton text="Clear Search and Start Again"
    binding="#{backingBeanScope.backing_Fragments_PawnSearch.gb2}"
    id="gb2" destination="index.jspx"/>
    </af:panelGroupLayout>
    </af:panelGroupLayout>
    </f:facet>
    </af:panelSplitter>
    </af:panelFormLayout>
    </af:panelHeader>
    <!--oracle-jdev-comment:auto-binding-backing-bean-name:backing_Fragments_PawnSearch-->
    </jsp:root>

  • RegionRenderer encodeAll The region component with id: pt1:r1 has detected a page fragment with multiple root components. Fragments with more than one root component may not display correctly in a region and may have a negative impact on performance.

    Hi,
    I am using JDEV 11.1.2.1.0
    I am getting the following error :-
    <RegionRenderer> <encodeAll> The region component with id: pt1:r1 has detected a page fragment with multiple root components. Fragments with more than one root component may not display correctly in a region and may have a negative impact on performance. It is recommended that you restructure the page fragment to have a single root component.
    Piece of code is for region is:-
       <f:facet name="second">
                                                <af:panelStretchLayout id="pa1"
                                                                       binding="#{backingBeanScope.Assign.pa1}">
                                                    <f:facet name="center">
                                                        <af:region value="#{bindings.tfdAssignGraph1.regionModel}" id="r1"
                                                                   binding="#{backingBeanScope.Assign.r1}"/>
                                                    </f:facet>
                                                </af:panelStretchLayout>
                                            </f:facet>
    How do I resolve it ?
    Thanks,

    Hi,
    I see at least 3 errors
    1. <RegionRenderer> <encodeAll> The region component with id: pt1:r1 has detected a page fragment with multiple root components.
    the page fragment should only have a single component under the jsp:root tag. If you see more than one, wrap them in e.g. an af:panelGroupLayout or af:group component
    2. SAPFunction.jspx/.xml" has an invalid character ".".
    check the document (you can open it in JDeveloper if the customization was a seeded one. Seems that editing this file smething has gone bad
    3. The expression "#{bindings..regionModel}" (that was specified for the RegionModel "value" attribute of the region component with id "pePanel") evaluated to null.
    "pageeditorpanel" does seem to be missing in the PageDef file of the page holding the region
    Frank

  • MDS Customization Problem with multiple root components

    Hello,
    Oracle JDeveloper 11.1.1.5.0 and WebLogic Server Version: 10.3.5.0
    I am using Oracle MDS Customization class with the following classes:
    oracle.adf.view.rich.change.MDSDocumentChangeManager
    org.apache.myfaces.trinidad.change.ChangeManager
    org.apache.myfaces.trinidad.change.MoveChildComponentChange
    Based on these classes I am moving UI components
    <af:panelStretchLayout>
    <f:facet name="center">
    <af:region />
    </f:facet>
    </af:panelStretchLayout>
    into another component thanks to the MDS.
    Once I do the movement and persist, I receive the following waning message:
    *<RegionRenderer> <encodeAll> The region component with id: pt1:r1:0:pt2:r1:0:r1 has detected a page fragment with multiple root components. Fragments with more than one root component may not display correctly in a region and may have a negative impact on performance. It is recommended that you restructure the page fragment to have a single root component.*
    When I run the application in Oracle JDeveloper 11.1.1.5.0, it work fine, but when I deploy it on WebLogic Server Version: 10.3.5.0 it is not working.
    I receive the same warning message on the server and in JDeveloper.
    I think that MDS makes a copy of the components that I move because of that it says me that "a page fragment with multiple root components"
    The problem is not because of duplication any of the tags <af:document> <f:view><f:form> <html> <head> <body>
    After the movement and persistence, I also call the FacesContext to reset its view root with the following code:
    FacesContext context =FacesContext.getCurrentInstance();
    String currentView = context.getViewRoot().getViewId();
    ViewHandler vh = context.getApplication().getViewHandler();
    UIViewRoot x = vh.createView(context, currentView);
    x.setViewId(currentView);
    context.setViewRoot(x);
    The idea is that the entire JSF tree to be rebuild on entering page with aim to clear previously drag and drop settings.
    Do you know how I can overcome the problem on the server WebLogic Server Version: 10.3.5.0?
    This worked on Oracle JDeveloper 11.1.1.3.0 and now the problem is with Oracle JDeveloper 11.1.1.5.0.
    Regards,
    Niki

    Hi,
    what the error means is that you have more than one node under the jsp:root node of the fragment. Say the content of your fragment is
    <af:panelGroupLayout id="pgl1">
    </af:PanelGrouPLayout>
    Then this is okay
    if you have
    <af:panelGroupLayout id="pgl1">
    </af:PanelGrouPLayout>
    <af:panelGroupLayout id="pgl2">
    </af:PanelGrouPLayout>
    or
    <af:panelGroupLayout id="pgl1">
    </af:PanelGrouPLayout>
    <af:commandButton id="cb1"/>
    Then these mean duplicated root components. The JDeveloper IDE flags this as Warnings (Structure Window) when selecting the page fragment
    Frank

  • Shuffle - can it be used with multiple winXP computers???

    Can my shuffle be used with multiple computers without losing songs that are on one library and not the other?
    I keep seeing references to "manage files manually" but I don't see that option for my shuffle settings. I just lost my songs when I plugged it in to my computer at work...
    Thanks for any help.

    Dave's already got you covered.
    just a thought, though. if you're also got a standard ipod (or some other way of keeping the two different libraries in alignment), you may be able to set up something along the lines that Arend describes in this thread:
    http://discussions.apple.com/thread.jspa?messageID=2161102#2161102
    love, b

  • Can I make a class holding multiple GUI components and make it visible?

    I am implementing an MDI where the different JInternalFrames are filled with a JPanel with components. Since the contents of my screen is dynamically generated, each screen can have multiple Jlabels, JTextFields, etc.
    So I thought, I make a class containing the representation of one row of GUI components on my screen, which is: one JLAbel and 4 JTextFields.
    Here is the code which adds the components to the panel:
    // create panel
    JPanel qpanel = new JPanel();
    qpanel.setLayout(new BoxLayout(qpanel, BoxLayout.Y_AXIS));
    qpanel.add(Box.createVerticalStrut(5));
    //add rows to panel
    for( int i = 0; i < nrRows; i++)
    // qpanel.add(new JLabel("Hello how are you"));
    qpanel.add(new ProcessRow("hello","how","are","you"));
    // add panel to scrollpanel
    this.getViewport().add(qpanel);
    Here is the ProcessRow class:
    public class ProcessRow extends JComponent
    public JLabel rowLabel = null;
    public JTextField myCost = null;
    public JTextField saratogaCost = null;
    public JTextField sapCost = null;
    public JTextField totalCost = null;
    public ProcessRow() {
    super();
    public ProcessRow(String LABEL,
    String DEFAULTCOST,
    String SARATOGACOST,
    String SAPCOST){
    super();
    JLabel rowLabel = new JLabel(LABEL);
    JTextField myCost = new JTextField(DEFAULTCOST, 6);
    JTextField saratogaCost = new JTextField(SARATOGACOST, 6);
    JTextField sapCost = new JTextField(SAPCOST, 6);
    JTextField totalCost = new JTextField(6);
    If I add the label "Hello how are you" directly to the panel, it shows fine but if I use my ProcessRow class, nothing shows.
    How can I make it visible and if not,
    how can I dynamically keep adding all these GUI components without loosing control over the components.
    Thanks,
    Johnny

    Modify your ProcessRow:
    (1) First extends JPanel ( Container, not Component)
    (2) Add Label and TextField to the container
    public class ProcessRow extends JPanel
    public JLabel rowLabel = null;
    public JTextField myCost = null;
    public JTextField saratogaCost = null;
    public JTextField sapCost = null;
    public JTextField totalCost = null;
    public ProcessRow() {
    super();
    public ProcessRow(String LABEL,
    String DEFAULTCOST,
    String SARATOGACOST,
    String SAPCOST){
    super();
    JLabel rowLabel = new JLabel(LABEL);
    JTextField myCost = new JTextField(DEFAULTCOST, 6);
    JTextField saratogaCost = new JTextField(SARATOGACOST, 6);
    JTextField sapCost = new JTextField(SAPCOST, 6);
    JTextField totalCost = new JTextField(6);
    // add everything to the container.
    add(rowLabel);
    add(myCost);
    add(sapCost);
    add(totalCost);
    }

  • Best wireless router (apple or non-apple)  for use with multiple Macs

    What is the best wireless router, from any manufacturer, for use with 3-5 Macs? (in a reasonable price range... sub $150)
    least problems
    most reliable
    strongest signal/best range
    fewest drops
    fewest reboots

    The Apple Routers "just work".
    I also have a linksys. It takes a good bit of knowledge and aggravation getting it set up, but once working it does fine.
    If you plan to use your router to share a printer, hook to your stereo, etc. definitely stick with Apple. It will save you much grief.

  • Can i use one pc with one installation of Itunes to use with multiple apple ID's?

    can i use a single pc with one edition of itunes to manage multiple apple id's (without everyone's mail and message popping up on eachothers ipads/iphones etc)?

    You would need the apps installed on both volumes. The versions installed on your 10.4 drive will most likely give you a "You cannot use this version, etc..." error if you try to launch them from a 10.5 volume. Some apps may run but you will end up "confusing" the system as to which instance of the app you want it to use.

  • How do I create multiple libraries & use with multiple ipods?

    Hi All,
    My wife and I have different tastes in music. Currently we use different user log ons to seperate our libraries. It's a complete pain because there's no other reason to use seperate log ons.
    We'll soon be upgrading to a new iMac and I'm wondering if it's possible to have two libraries operating in the one itunes sesssion?
    So here are my questions:
    1) Can I have two libraries sourcing the same music files?
    2) We each have an iPod, can it be set to only update one of those libraries, but still automatically update when connected?
    3) If we create playlists, will they be associated with only one library, or both (my preference is one, of course)?
    4) I'm pretty sure iPods can be set so my iPod only updates my playlists, and my wife's iPod only updates her playlists - is that correct?
    5) If we have seperate libraries, can we have seperate ratings? (Our opinion of what a five star song is is different)!
    Of course, for the above questions, if the answer is 'yes' please let me know how to do this. I've had a look through the itunes manuals online, but they don't seem to have any information.
    Cheers, Chris

    Chris,
    I have the exact same situation, and I have tried Doug's iTunes Library Manager, but it doesn't work for me. The first workaround I tried was to set up two smart playlists to group together any music that only one of us liked, which could then be checked or un-checked (control-click) depending on which iPod is being synced. This is clumsy, and if you aren't careful the Recently Added playlist will still "contaminate" your iPod.
    Last night I just made a new library for my wife (hold down Option when starting iTunes), copied everything over using the Add to Library command, exported all the playlists using the Export Library command, deleted all the music and playlists she doesn't want, and synced her iPod. It took a while to erase and re-sync, but it is now synced to HER library, and she doesn't see any music she doesn't like.
    Tonight I will do the same for myself. I will have, then, three libraries which can be selected by holding down the option key when starting iTunes: Mine, My wife's, and the main one with everything (called Library) All the music files stay on an external Firewire Drive. There is no way to toggle libraries from within iTunes, you have to quit and start it again holding down the option key.
    Podcasts are another story, and I haven't quite figured them out yet.
    Marty

  • HT204074 Can iTunes Match be used with multiple Apple IDs

    My wife and I have our own apple IDs for our iPhones.  I recently subscribed to iTunes Match on our MacBook under my Apple ID.  Can my wife's Apple ID be associated with the Match account so that she too can listen to music from our computer on her iPhone?

    Welcome to Apple Support Communities
    No. She must be using your Apple ID if she wants to use iTunes Match, or she has to subscribe to iTunes Match with her Apple ID.

  • What sequence settings should I use with multiple formats?

    I'm starting a new project in CS6 that's using multiple types of video.  I've got old camcorder video from 20 years ago...as well as digital video...and current HD video.  I want all the video in the sequence to output as full screen.  So do I need to use the 720 x 480 settings to accommodate the old camcorder video?  Or will that mess up my new HD stuff?  Thanks.

    First you need to force Premiere to interpret the camcorder files as widescreen. So highlight all the camcorder files from the project panel, right-click and select Modify -> Interpret Footage. Then change the pixel aspect ratio to "D1/DV NTSC Widescreen 16:9 (1.2121)".
    Next you need to upscale the camcorder files to the HD project window size. So after you drop them on to your timeline... highlight one or more of them, right-click and select "Scale to Frame Size".
    Finally you may want to fine tune it to remove edge artifacts or borders. There's a few ways to do this but the quickest would be to just slightly increase the Scale settings in the effects control panel. Once you have a good look, you can just copy and paste the scale settings to all the other clips on the timeline.
    Alternatively, you can use Red Giant Instant HD to do the up-scaling as I'm sure it do a much better job.
    -Pete

  • How to work with multiple catalyst components in Flash Builder?

    Hey There,
    Can I create multiple components and merge them together? For example, I want to create a list control state, and bring it into my existing Flash Builder project. Then down the road, do something similiar... How would I go about that, and what files are essential fromt he catalyst project.. (assets, components, main.css, privateData..
    Thanks in advance!

    Yes, you can :-)
    You can export the components from different Flash Catalyst projects as fxpl files and then import them into Flash Builder. In Flash Catalyst, right-click in the Library panel and you will see the export command to save the current project's components into an fxpl file.
    A great article on Flash Builder/Flash Catalyst workflows is here:
    http://www.adobe.com/devnet/flashcatalyst/articles/flashbuilder_flashcatalyst_workflows.ht ml
    Ty

  • Outgoing Email Account Used with Multiple SMTPs

    This seems to be a bug with the OS as I can replicate the issue on both my iPhone and iPad.
    iPhone 6 running: 8.1.3
    iPad Mini Retina running: 8.1.2
    I have 2 email accounts defined on my phone. 1 for work, and 1 for Gmail.  Gmail is currently selected as my default email account.
    If I am sending emails from the Mail app, everything works perfectly fine, I can select which email I want to send emails from and they work correctly.
    When sharing something in the Safari app, or other apps.. anything that uses the Share by Email feature, the email will be sent out by whatever the last account used to send an email in the the Mail app was, regardless of what is selected in the "From" field.
    So if I just sent an email from my work account in the Mail App, then I go and to share a page in safari by email, it will send it out via the work SMTP server even though it says my Gmail account would be used in the "From" field.
    Can anyone confirm this bug? Are there any solutions?
    I attempted deleting both my Gmail and Work accounts and readding them and I had the same issue.
    I was also able to replicate this issue when dealing with my Gmail and iCloud account.

    I was also able to replicate this issue when dealing with my Gmail, Yahoo, and iCloud accounts. I have restarted my phone and change the "Default Account" but it did not solve the problem.

  • Wireless printing HPCN245 useing with multiple PC

    Hi, i have bought a HP printer (CN245b) and currently setup with one laptop, if want to print from my other laptops do i have to install software in to all of them? need help. Thanks

    Yup.  Get the latest software for your printer from the "Support & Driver" link at the top of this page.
    Say thanks by clicking "Kudos" "thumbs up" in the post that helped you.
    I am employed by HP

  • Single VPP purchase with multiple configurators

    Can a single VPP purchase be used with multiple configurators(each with different apple ids).

    This works for me...
    Open first image in Preview View > Sidebar. Drag the other images into Sidebar, then select all.
    From File menu > print selected images. Choose PDF > Save as PDF
    -mj

Maybe you are looking for