Project

General

Profile

vvt-refactorings.diff

proposed refactorings - Vladimir Tsichevski, 08/20/2025 02:47 PM

Download (8.16 KB)

View differences:

new/src/com/goldencode/p2j/ui/chui/ThinClient.java 2025-08-20 16:23:27 +0000
15980 15980

  
15981 15981
      if (widget instanceof FillIn)
15982 15982
      {
15983
         FillIn fillin = (FillIn) widget;
15984
         if (fillin.groupMode)
15985
         {
15986
            // Don't change the cursor offset.
15987
         }
15988 15983
         // fill-in's always reset the cursor on the first position, after the
15989 15984
         // widget is left
15990
         else if (!fillin.isPendingNoZap() && !((FillInConfig) fillin.config()).disableAutoZap)
15985
         FillIn fillin = (FillIn) widget;
15986
         if (!fillin.groupMode && 
15987
             !fillin.isPendingNoZap() && !((FillInConfig) fillin.config()).disableAutoZap)
15991 15988
         {
15992
            ((FillIn) widget).setCursorOffset(0);
15989
            fillin.setCursorOffset(0);
15993 15990
         }
15994 15991
      }
15995 15992

  
new/src/com/goldencode/p2j/ui/client/FillIn.java 2025-08-20 18:32:52 +0000
3921 3921
    *          was inserted.
3922 3922
    * @param   key
3923 3923
    *          The character which will be inserted.
3924
    * @param   isChui
3925
    *          client is executed in ChUI mode 
3924 3926
    * 
3925 3927
    * @return  <code>true</code> if after insertion operation cursor is
3926 3928
    *          allowed to go to the next widget.
3927 3929
    */
3928 3930
   private boolean refill(boolean insert, int key, boolean isChui)
3929 3931
   {
3930
      if (insert)
3931
      {
3932
         if(!isChui)
3933
         {
3934
            return handleGUIInsertMode(key);
3935
         }
3936
         else
3937
         {
3938
            return handleCHUIInsertMode(key);
3939
         }
3940
      }
3941
      // Character was removed
3942
      else
3943
      {
3944
         return handleRemoveMode();
3945
      }
3932
      return insert ? isChui ? handleCHUIInsertMode(key) : handleGUIInsertMode(key) : handleRemoveMode();
3946 3933
   }
3947 3934

  
3948 3935
   /**
3949 3936
    * Handle remove case when a character was deleted.
3950 3937
    *
3951
    * @return   {@code true} Returns "true" if we successfully handled the removal mode.
3952
    *           {@code false} otherwise.
3938
    * @return   always {@code true}
3953 3939
    */
3954 3940
   private boolean handleRemoveMode()
3955 3941
   {
3956
      // Current fill-in text is already updated after deletion.
3957
      String newTextAfterDeletion = getText();
3958
      int currentPosition = getCursorOffset();
3959

  
3960

  
3961 3942
      // Handle all fill-in cases. Fore the last Fill-In, we do nothing.
3962
      if (!isLastInGroup() &&
3963
          canAppendContentFromNextFillInToCurrentFillIn())
3943
      if (!isLastInGroup() && canAppendContentFromNextFillInToCurrentFillIn())
3964 3944
      {
3945
         // Current fill-in text is already updated after deletion.
3946
         String newTextAfterDeletion = getText();
3965 3947
         // Append content from the next fill-in to the current Fill-in.
3966
         String newTextAfterShifting = (StringHelper.safeTrimTrailing(newTextAfterDeletion).length() == 0) ?
3967
               newTextAfterDeletion + StringHelper.safeTrimTrailing(getNextInGroup().getText()) :
3968
               newTextAfterDeletion + " " + StringHelper.safeTrimTrailing(getNextInGroup().getText());
3969

  
3970
         updateCurrentContent(newTextAfterShifting, currentPosition);
3948
         StringBuilder newTextAfterShifting = new StringBuilder(newTextAfterDeletion);
3949
         if (StringHelper.safeTrimTrailing(newTextAfterDeletion).length() != 0)
3950
         {
3951
            newTextAfterShifting.append(' ');
3952
         }
3953
         newTextAfterShifting.append(StringHelper.safeTrimTrailing(getNextInGroup().getText()));
3954
         updateCurrentContent(newTextAfterShifting.toString(), getCursorOffset());
3971 3955

  
3972 3956
         // Shift from the right side to the left side.
3973 3957
         shiftToLeftAllFillInContents();
......
3992 3976
      // is NOT empty after trailing spaces are removed, a single space (+1) is
3993 3977
      // implicitly added after it before combining with the next FillIn's content.
3994 3978
      // If 'newTextAfterDeletion' IS empty, no space is added, so its effective length is 0.
3995
      int currentTextSize =  (StringHelper.safeTrimTrailing(newTextAfterDeletion).length() == 0)
3979
      final int length = StringHelper.safeTrimTrailing(newTextAfterDeletion).length();
3980
      int currentTextSize =  length == 0
3996 3981
            ? 0
3997 3982
            // If not empty, its effective size includes a trailing space.
3998
            : StringHelper.safeTrimTrailing(newTextAfterDeletion).length() + 1;
3983
            : length + 1;
3999 3984

  
4000 3985
      int maxFillInCapacity = config.appFormat.getScreenWidth();
4001 3986

  
4002
      return StringHelper.safeTrimTrailing(getNextInGroup().getText()).length() + currentTextSize <= maxFillInCapacity;
3987
      return StringHelper.safeTrimTrailing(getNextInGroup().getText()).length()
3988
               + currentTextSize <= maxFillInCapacity;
4003 3989
   }
4004 3990

  
4005 3991

  
......
4012 3998
      while (currentFillIn != null)
4013 3999
      {
4014 4000
         // If is the next fill in is not the last.
4015
         if (currentFillIn.getNextInGroup() != null)
4016
         {
4017
            String textFromLeftSide = currentFillIn.getNextInGroup().getText();
4018
            currentFillIn.updateCurrentContent(textFromLeftSide, textFromLeftSide.length());
4019
         }
4020
         // We are on the last fill-in.
4021
         else
4001
         final FillIn<O, C> nextInGroup = currentFillIn.getNextInGroup();
4002
         if (nextInGroup == null)
4022 4003
         {
4023 4004
            currentFillIn.updateCurrentContent("", 0);
4005
            
4006
            return;
4024 4007
         }
4025
         currentFillIn = currentFillIn.getNextInGroup();
4008
         
4009
         String textFromLeftSide = nextInGroup.getText();
4010
         currentFillIn.updateCurrentContent(textFromLeftSide, textFromLeftSide.length());
4011
         currentFillIn = nextInGroup;
4026 4012
      }
4027 4013
   }
4028 4014

  
......
4042 4028
   {
4043 4029
      // Character is about to be inserted
4044 4030
      String originalText = getText();
4045
      int currentPosition = getCursorOffset();
4046 4031
      int originalTextLengthTrimmed = StringHelper.safeTrimTrailing(originalText).length();
4047 4032
      int maxFillInCapacity = config.appFormat.getScreenWidth();
4048 4033

  
......
4052 4037
      {
4053 4038
         return handleGroupedFullFillInForSpaceKey();
4054 4039
      }
4040
      
4041
      int currentPosition = getCursorOffset();
4055 4042
      // Handle simple insert char.
4056
      else
4057
      {
4058
         if (isWhiteSpaceBeforeCurrentOffset(originalText, currentPosition, maxFillInCapacity))
4059
         {
4060
            updateCurrentContent(originalText, originalTextLengthTrimmed);
4061
            return true;
4062
         }
4063

  
4064
         if (shouldPropagateAfterInsertion(originalText, originalTextLengthTrimmed, maxFillInCapacity))
4065
         {
4066
            return handlePropagationAfterInsertion(originalText, currentPosition, key);
4067
         }
4068

  
4069
         if (canInsertWithoutPropagation(currentPosition, originalTextLengthTrimmed, maxFillInCapacity))
4070
         {
4071
            return handleSimpleInsert(originalText, currentPosition, key, maxFillInCapacity);
4072
         }
4043
      if (isWhiteSpaceBeforeCurrentOffset(originalText, currentPosition, maxFillInCapacity))
4044
      {
4045
         updateCurrentContent(originalText, originalTextLengthTrimmed);
4046
         return true;
4047
      }
4048

  
4049
      if (shouldPropagateAfterInsertion(originalText, originalTextLengthTrimmed, maxFillInCapacity))
4050
      {
4051
         return handlePropagationAfterInsertion(originalText, currentPosition, key);
4052
      }
4053

  
4054
      if (canInsertWithoutPropagation(currentPosition, originalTextLengthTrimmed, maxFillInCapacity))
4055
      {
4056
         return handleSimpleInsert(originalText, currentPosition, key, maxFillInCapacity);
4073 4057
      }
4074 4058

  
4075 4059
      return true;
......
4080 4064
      // Character is about to be inserted
4081 4065
      String originalText = getText();
4082 4066
      int currentPosition = getCursorOffset();
4083
      int originalTextLengthTrimmed = StringHelper.safeTrimTrailing(originalText).length();
4084 4067
      int maxFillInCapacity = config.appFormat.getScreenWidth();
4085 4068

  
4086 4069
      if (currentPosition < maxFillInCapacity)
4087 4070
      {
4088 4071
         return handleSimpleInsert(originalText, currentPosition, key, maxFillInCapacity);
4089 4072
      }
4090
      else if(String.valueOf((char) key).equals(" ") &&
4073
      
4074
      if(String.valueOf((char) key).equals(" ") &&
4091 4075
            !isLastInGroup())
4092 4076
      {
4093 4077
         // Move the focus to the next fill-in.