[izpack-devel] yet another patch - user panel layout when switching packs

David.Guan soft.guan at yahoo.com.cn
Sat May 5 05:46:24 CEST 2007


Hello everyone.
This problem still exists in the IzPack3.10.1.
It has not been solved.


Joachim Hofer wrote:
> 
> Hi,
> 
> this has haunted IzPack for far too long now...
> 
> Scenario: When I select a pack and forward to some UserInputPanel (which
> has elements that depend on the pack), then go back and switch to
> another pack and forward again to the UserInputPanel, then I get ugly
> stuff (butchered layout, exceptions).
> 
> I noticed some beginnings of a workaround in the source, but disabling
> the back button isn't really a viable solution, imho.
> 
> The source of all evil really is the empty "removeLayoutComponent()" in
> the TwoColumnLayout. So I implemented it so that it allows a clean
> "removeAll()".
> 
> I adapted the UserInputPanel accordingly - buildUI() now does a
> "removeAll()" and adds all components back afterwards each time it's
> activated.
> 
> (Unfortunately, I didn't get the layout to work cleanly with individual
> "remove()"s. I'm no expert with custom LayoutManagers.)
> 
> I also removed a NullPointerException I happened upon (I think it was in
> the case of empty SearchField choices) - this is a small modification in
> the RuleInputField code.
> 
> These three changes are attached.
> 
> The patch is generated by subversion and based on rev 1493 (I did branch
> this time as I don't know yet if you're going to take over my previous
> patch(es)).
> 
> I hope you like it. :-)
> 
> Joachim Hofer
> imbus AG
> 
> Index: src/lib/com/izforge/izpack/gui/TwoColumnLayout.java
> ===================================================================
> --- src/lib/com/izforge/izpack/gui/TwoColumnLayout.java	(Revision 1493)
> +++ src/lib/com/izforge/izpack/gui/TwoColumnLayout.java	(Arbeitskopie)
> @@ -874,13 +874,34 @@
>      {
>      }
>  
> +    private void removeLayoutComponent(Component comp, int pos) {
> +        // look through all components
> +        int numComponents = components[pos].size();
> +        for (int i = numComponents - 1; i >= 0; i--)
> +        {
> +            TwoColumnConstraints existingComp = (TwoColumnConstraints)
> components[pos].get(i);
> +            if (null != existingComp && comp == existingComp.component)
> +            {
> +                components[pos].remove(i);
> +                break;
> +            }
> +        }
> +    }
> +
>      /**
> -     * This functionality is not supported
> +     * Removes the specified component from the layout.
>       * 
> +     * Unfortunately, this does not seem to work completely. This means
> that removing 
> +     * individual components from an existing layout will probably still
> kill that layout.
> +     * However, removeAll() and adding the components again afterwards
> should work now 
> +     * if you need a fresh start for the layout.
> +     *
>       * @param comp the component to be removed
>       */
>      public void removeLayoutComponent(Component comp)
>      {
> +        removeLayoutComponent(comp, LEFT);
> +        removeLayoutComponent(comp, RIGHT);
>      }
>  
>      /**
> Index: src/lib/com/izforge/izpack/panels/RuleInputField.java
> ===================================================================
> --- src/lib/com/izforge/izpack/panels/RuleInputField.java	(Revision 1493)
> +++ src/lib/com/izforge/izpack/panels/RuleInputField.java	(Arbeitskopie)
> @@ -748,17 +748,20 @@
>     
> /*--------------------------------------------------------------------------*/
>      public void caretUpdate(CaretEvent event)
>      {
> -        String text = activeField.getText();
> -        int fieldSize = activeField.getEditLength();
> -        int caretPosition = activeField.getCaretPosition();
> -        int selection = activeField.getSelectionEnd() -
> activeField.getSelectionStart();
> +        if (activeField != null)
> +        {
> +            String text = activeField.getText();
> +            int fieldSize = activeField.getEditLength();
> +            int caretPosition = activeField.getCaretPosition();
> +            int selection = activeField.getSelectionEnd() -
> activeField.getSelectionStart();
>  
> -        if ((!inputFields.lastElement().equals(activeField)) &&
> (!activeField.unlimitedEdit()))
> -        {
> -            if ((text.length() == fieldSize) && (selection == 0) &&
> (caretPosition == fieldSize)
> -                    && !backstep)
> +            if ((!inputFields.lastElement().equals(activeField)) &&
> (!activeField.unlimitedEdit()))
>              {
> -                activeField.transferFocus();
> +                if ((text.length() == fieldSize) && (selection == 0) &&
> (caretPosition == fieldSize)
> +                        && !backstep)
> +                {
> +                    activeField.transferFocus();
> +                }
>              }
>          }
>      }
> Index: src/lib/com/izforge/izpack/panels/UserInputPanel.java
> ===================================================================
> --- src/lib/com/izforge/izpack/panels/UserInputPanel.java	(Revision 1493)
> +++ src/lib/com/izforge/izpack/panels/UserInputPanel.java	(Arbeitskopie)
> @@ -308,14 +308,6 @@
>  
>      protected int instanceNumber = 0;
>  
> -    /**
> -     * If there is a possibility that some UI elements will not get added
> we can not allow to go
> -     * back to the PacksPanel, because the process of building the UI is
> not reversable. This
> -     * variable keeps track if any packs have been defined and will be
> used to make a decision for
> -     * locking the 'previous' button.
> -     */
> -    private boolean packsDefined = false;
> -
>      private InstallerFrame parentFrame;
>  
>      /** The parsed result from reading the XML specification from the
> file */
> @@ -519,16 +511,8 @@
>              parentFrame.skipPanel();
>              return;
>          }
> -        // if (uiBuilt)
> -        // {
> -        // return;
> -        // }
>  
>          buildUI();
> -        if (packsDefined)
> -        {
> -            parentFrame.lockPrevButton();
> -        }
>      }
>  
>     
> /*--------------------------------------------------------------------------*/
> @@ -561,6 +545,10 @@
>      {
>          Object[] uiElement;
>  
> +		// clean up before starting to build the UI; things may have changed
> +		// (ie if the user has selected a different panel in the meantime)
> +		removeAll();
> +
>          for (int i = 0; i < uiElements.size(); i++)
>          {
>              uiElement = (Object[]) uiElements.elementAt(i);
> @@ -570,11 +558,7 @@
>              {
>                  try
>                  {
> -                    if (uiElement[POS_DISPLAYED] == null
> -                            ||
> "false".equals(uiElement[POS_DISPLAYED].toString()))
> -                    {
> -                        add((JComponent) uiElement[POS_FIELD],
> uiElement[POS_CONSTRAINTS]);
> -                    }
> +					add((JComponent) uiElement[POS_FIELD], uiElement[POS_CONSTRAINTS]);
>  
>                      uiElement[POS_DISPLAYED] = Boolean.valueOf(true);
>                      uiElements.remove(i);
> @@ -588,19 +572,6 @@
>              }
>              else
>              {
> -                try
> -                {
> -                    if (uiElement[POS_DISPLAYED] != null
> -                            &&
> "true".equals(uiElement[POS_DISPLAYED].toString()))
> -                    {
> -                        remove((JComponent) uiElement[POS_FIELD]);
> -                    }
> -                }
> -                catch (Throwable exception)
> -                {
> -                    System.out.println("Internal format error in field: "
> -                            + uiElement[POS_TYPE].toString()); // !!!
> logging
> -                }
>                  uiElement[POS_DISPLAYED] = Boolean.valueOf(false);
>                  uiElements.remove(i);
>                  uiElements.add(i, uiElement);
> @@ -2318,16 +2289,6 @@
>          if (packs.size() == 0) { return (true); }
>  
>          // ----------------------------------------------------
> -        // We are getting to this point if any packs have been
> -        // specified. This means that there is a possibility
> -        // that some UI elements will not get added. This
> -        // means that we can not allow to go back to the
> -        // PacksPanel, because the process of building the
> -        // UI is not reversable.
> -        // ----------------------------------------------------
> -        // packsDefined = true;
> -
> -        // ----------------------------------------------------
>          // analyze if the any of the packs for which the item
>          // is required have been selected for installation.
>          // ----------------------------------------------------
> 
> _______________________________________________
> izpack-devel mailing list
> izpack-devel at lists.berlios.de
> http://bat.berlios.de/mailman/listinfo/izpack-devel
> 
> 

-- 
View this message in context: http://www.nabble.com/yet-another-patch---user-panel-layout-when-switching-packs-tf1980027.html#a10333386
Sent from the izpack devel mailing list archive at Nabble.com.




More information about the izpack-devel mailing list