Пример #1
0
  public Component getTreeCellRendererComponent(
      JTree tree,
      Object value,
      boolean selected,
      boolean expanded,
      boolean leaf,
      int row,
      boolean hasFocus) {
    jl.setFont(tree.getFont());

    /*
     * Icons are *important*; this is (obviously) wholly inadequate ATM.
     * Individual programs should have their own icons, where possible
     * (ideally, favicons from main site pages). Seasons
     * could use Apple-alias-style derived icons, or something.
     */

    if (leaf) {
      jl.setIcon(UIManager.getIcon("Tree.leafIcon"));
    } else if (expanded) {
      jl.setIcon(UIManager.getIcon("Tree.openIcon"));
    } else {
      jl.setIcon(UIManager.getIcon("Tree.closedIcon"));
    }

    //        this.value = value.toString();
    jl.setText(value.toString());
    jl.setForeground(Color.BLACK);

    Checkable c = (Checkable) value;

    this.implicit = c.implicit;
    this.selected = c.isSelected();

    if (c instanceof EpisodeTreeNode) {
      EpisodeTreeNode n = (EpisodeTreeNode) c;
      if (n.icon != null) jl.setIcon(n.icon);
    }

    if (c.isLocal) {
      jl.setFont(jl.getFont().deriveFont(Font.BOLD));
    }

    if (c.isPartiallyLocal) {
      jl.setForeground(Color.BLUE);
    } else if (selected) {
      jl.setForeground(UIManager.getColor("Tree.selectionForeground"));
    }

    if (selected) {
      jl.setBackground(UIManager.getColor("Tree.selectionBackground"));
    } else {
      jl.setBackground(UIManager.getColor("Tree.textBackground"));
    }

    return this;
  }
Пример #2
0
 public static void checkObject(Object data, Class<?> outType, Checkable checkable)
     throws CheckableDataException {
   checkIsNull(data, checkable);
   if (outType.isArray()) {
     checkArray((Object[]) data, outType, checkable);
   } else if (outType == Date.class || StringUtils.isNotEmpty(checkable.dateFormat())) {
     checkDate(ConvertUtil.toString(data), checkable);
   } else if (outType == String.class) {
     checkString(ConvertUtil.toString(data), checkable);
   } else if (outType == Double.class || outType == double.class) {
     checkDouble(ConvertUtil.toString(data), checkable);
   } else if (outType == Float.class || outType == float.class) {
     checkFloat(ConvertUtil.toString(data), checkable);
   } else if (outType == Integer.class || outType == int.class) {
     checkInteger(ConvertUtil.toString(data), checkable);
   } else if (!ClassUtil.isJavaType(outType)) {
     Field[] fields = outType.getDeclaredFields();
     for (int i = 0; i < fields.length; i++) {
       if (fields[i].isAnnotationPresent(Checkable.class)) {
         Checkable tmpCheckable = fields[i].getAnnotation(Checkable.class);
         try {
           fields[i].setAccessible(true);
           Object fieldValue = fields[i].get(data);
           fields[i].setAccessible(false);
           checkObject(fieldValue, fields[i].getType(), tmpCheckable);
         } catch (Exception e) {
           throw new CheckableDataException(e.getMessage(), e);
         }
       }
     }
   }
 }
Пример #3
0
 public static void checkDate(String data, Checkable checkable) throws CheckableDataException {
   checkIsNull(data, checkable);
   try {
     DateFormat sf = new SimpleDateFormat(checkable.dateFormat());
     sf.parse(data);
   } catch (ParseException e) {
     String message =
         StringUtils.unite("[", data, "] claim date format does not pass. data check failed!");
     throw new CheckableDataException(message, e);
   }
 }
Пример #4
0
 public static void checkDouble(String data, Checkable checkable) throws CheckableDataException {
   checkString(data, checkable);
   try {
     Double.parseDouble(data);
     if (checkable.decimalLength() != -1) {
       Pattern pattern =
           Pattern.compile(StringUtils.unite("^\\d+\\.\\d{", checkable.decimalLength(), "}$"));
       Matcher matcher = pattern.matcher(data);
       if (!matcher.matches()) {
         String message =
             StringUtils.unite(
                 "[",
                 data,
                 "] decimal length is ",
                 checkable.decimalLength(),
                 " claim decimal length. data check failed!");
         throw new CheckableDataException(message);
       }
     }
   } catch (NumberFormatException e) {
     throw new CheckableDataException(e.getMessage(), e);
   }
 }
Пример #5
0
 public static void checkString(String data, Checkable checkable) throws CheckableDataException {
   checkIsNull(data, checkable);
   int length = data.length();
   if (checkable.maxLength() != -1 && length > checkable.maxLength()) {
     String message =
         StringUtils.unite(
             "[",
             data,
             "] length is ",
             length,
             " claim max length ",
             checkable.maxLength(),
             ". data check failed!");
     throw new CheckableDataException(message);
   }
   if (checkable.minLength() != -1 && length < checkable.minLength()) {
     String message =
         StringUtils.unite(
             "[",
             data,
             "] length is ",
             length,
             " claim min length ",
             checkable.minLength(),
             ". data check failed!");
     throw new CheckableDataException(message);
   }
   if (StringUtils.isNotEmpty(checkable.regex())) {
     Pattern pattern = Pattern.compile(checkable.regex());
     Matcher matcher = pattern.matcher(data);
     if (!matcher.matches()) {
       String message =
           StringUtils.unite("[", data, "] claim regex does not pass. data check failed!");
       throw new CheckableDataException(message);
     }
   }
 }
Пример #6
0
 public static void checkArray(Object[] data, Class<?> outType, Checkable checkable)
     throws CheckableDataException {
   checkIsNull(data, checkable);
   int length = data.length;
   if (checkable.maxLength() != -1 && length > checkable.maxLength()) {
     String message =
         StringUtils.unite(
             "[",
             data,
             "] length is ",
             length,
             " claim array max length ",
             checkable.maxLength(),
             ". data check failed!");
     throw new CheckableDataException(message);
   }
   if (checkable.minLength() != -1 && length < checkable.minLength()) {
     String message =
         StringUtils.unite(
             "[",
             data,
             "] length is ",
             length,
             " claim array min length ",
             checkable.minLength(),
             ". data check failed!");
     throw new CheckableDataException(message);
   }
   for (int i = 0; i < length; i++) {
     String tmp = ConvertUtil.toString(data[i]);
     if (outType == String[].class) {
       checkString(tmp, checkable);
     } else if (outType == Integer[].class || outType == int[].class) {
       checkInteger(tmp, checkable);
     } else if (outType == Double[].class || outType == double[].class) {
       checkDouble(tmp, checkable);
     } else if (outType == Float[].class || outType == float[].class) {
       checkFloat(tmp, checkable);
     } else if (outType == Date[].class) {
       checkDate(tmp, checkable);
     } else {
       checkObject(data[i], outType.getComponentType(), checkable);
     }
   }
 }
Пример #7
0
  // 学习学习再学习,学习定义自己的adapter,特定位置的特定视图,只能是图片或者文本
  // 为特定的view添加内容
  // 特定位置对view进行数据填充
  private void bindView(int position, View view) {
    final Map dataSet = mData.get(position);
    if (dataSet == null) {
      return;
    }

    final ViewBinder binder = mViewBinder;
    // 一个map中的数据,其key为string类型
    final String[] from = mFrom;
    // 对应的需要赋值的view
    final int[] to = mTo;
    // 需要进行填充的view的数量,to啊
    final int count = to.length;
    // 循环为每一个特定视图赋值
    for (int i = 0; i < count; i++) {
      final View v = view.findViewById(to[i]);
      if (v != null) {
        // 获取对应位置map对应的key的值
        final Object data = dataSet.get(from[i]);
        String text = data == null ? "" : data.toString();
        if (text == null) {
          // 防止错误
          text = "";
        }

        boolean bound = false;
        if (binder != null) {
          // bound是做什么用的呢
          bound = binder.setViewValue(v, data, text);
        }
        // 原来还可以有checkable
        if (!bound) {
          if (v instanceof Checkable) {
            if (data instanceof Boolean) {
              ((Checkable) v).setChecked((Boolean) data);
            } else if (v instanceof TextView) {
              // Note: keep the instanceof TextView check at the bottom of these
              // ifs since a lot of views are TextViews (e.g. CheckBoxes).
              setViewText((TextView) v, text);
            } else {
              throw new IllegalStateException(
                  v.getClass().getName()
                      + " should be bound to a Boolean, not a "
                      + (data == null ? "<unknown type>" : data.getClass()));
            }
          } else if (v instanceof TextView) {
            // Note: keep the instanceof TextView check at the bottom of these
            // ifs since a lot of views are TextViews (e.g. CheckBoxes).
            setViewText((TextView) v, text);
          } else if (v instanceof ImageView) {
            if (data instanceof Integer) {
              setViewImage((ImageView) v, (Integer) data);
            } else {
              setViewImage((ImageView) v, text);
            }
          } else {
            throw new IllegalStateException(
                v.getClass().getName()
                    + " is not a "
                    + " view that can be bounds by this SimpleAdapter");
          }
        }
      }
    }
  }
Пример #8
0
 public static void checkIsNull(Object data, Checkable checkable) throws CheckableDataException {
   if (data == null && !checkable.isNull()) {
     String message = StringUtils.unite("[", data, "] claim is not null. data check failed!");
     throw new CheckableDataException(message);
   }
 }
Пример #9
0
  @Override
  public void onBindViewHolder(RecycleViewHolder holder, int position) {

    if (mClientDataTable.isEmpty()) return;

    mClientDataTable.moveToPosition(position);

    if ((position >= getItemCount() - 1)) onLoadMore();

    int lListHolderSize = holder.mSparseArrayHolderViews.size();

    for (int i = 0; i < lListHolderSize; i++) {

      int lColumnIndex = holder.mSparseArrayHolderViews.keyAt(i);
      View lWidget = holder.mSparseArrayHolderViews.get(lColumnIndex);

      if (lWidget != null) {

        final TCell data = mClientDataTable.getCell(position, lColumnIndex);
        if (lWidget instanceof Checkable) {
          ((Checkable) lWidget).setChecked(data.asBoolean());
        } else if (lWidget instanceof TextView) {
          ((TextView) lWidget).setText(data.asString());
        } else if (lWidget instanceof UiPicassoImageView) {
          if (data.getValueType() == TCell.ValueType.BASE64) {
            try {
              throw new WrongTypeException(mContext, R.string.exception_canotUserBase64);
            } catch (WrongTypeException e) {
              e.printStackTrace();
            }
          } else {
            UiPicassoImageView picassoImageView = (UiPicassoImageView) lWidget;
            picassoImageView.setData(data.asString(), mIsNotUsePicassoCache);
          }
        } else if (lWidget instanceof ImageView) {
          ImageView im = (ImageView) lWidget;
          if (data.getValueType() == TCell.ValueType.INTEGER && !data.asString().isEmpty()) {
            im.setImageResource(data.asInteger());
          } else if (data.getValueType() == TCell.ValueType.BASE64) {
            byte[] decodedString = Base64.decode(data.asString(), Base64.NO_WRAP);
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inSampleSize = mBase64OptionSize;
            Bitmap decodedByte =
                BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length, options);
            im.setImageBitmap(decodedByte);
          } else {
            if (!data.asString().equals("")) setViewImage((ImageView) lWidget, data.asString());
            else im.setImageDrawable(null);
          }
        } else if (lWidget instanceof Spinner) {
          Spinner spinner = ((Spinner) lWidget);
          if (spinner.getAdapter() instanceof ArrayAdapter) {
            ArrayAdapter arrayAdapter = (ArrayAdapter) spinner.getAdapter();
            spinner.setSelection(arrayAdapter.getPosition(data.asString()));
          } else
            Log.e(
                this.getClass().getName(),
                "Cannot set Spinner default value, because Spinner Adapter is not ArrayAdapter Type, you need to customize it in onIterateWidget method");
        }

        onIteratedRow(holder.mRowView, lWidget, lWidget.getTag().toString());
      }
    }
    int lListHolderSizeNotInCDT = holder.mSparseArrayHolderViewsNotInCDT.size();

    for (int i = 0; i < lListHolderSizeNotInCDT; i++) {
      int lColumnIndex = holder.mSparseArrayHolderViewsNotInCDT.keyAt(i);
      View lWidget = holder.mSparseArrayHolderViewsNotInCDT.get(lColumnIndex);

      if (lWidget != null) {
        onIteratedRow(holder.mRowView, lWidget, lWidget.getTag().toString());
      }
    }

    // ClickListener
    holder.setClickListener(
        new OnRecycleClickListener() {
          @Override
          public void onClick(View v, int position) {
            onClickRow(v, position);
          }

          @Override
          public void onLongClick(View v, int position) {
            onLongClickRow(v, position);
          }
        });

    holder.setOnRecycleWidgetClickListener(
        new OnRecycleWidgetClickListener() {

          @Override
          public void onClick(View parentView, View clickedView, String tag, int position) {
            onClickWidget(parentView, clickedView, tag, position);
          }
        });

    holder.setOnRecycleCheckedRadioButtonGroupChangeListener(
        new OnRecycleCheckedRadioButtonGroupChangeListener() {
          @Override
          public void onCheckedChanged(
              View parentView,
              RadioGroup radioButtonGroup,
              String widgetTag,
              int radioButtonID,
              int position) {
            onCheckRadioButtonGroupWidget(
                parentView, radioButtonGroup, widgetTag, radioButtonID, position);
          }
        });

    holder.setOnRecycleCheckedChangeListener(
        new OnRecycleCheckedChangeListener() {
          @Override
          public void onCheckedChanged(
              boolean isWidgetInCDT, CompoundButton buttonView, boolean isChecked, int position) {

            if (!isWidgetInCDT || position >= mClientDataTable.getRowsCount()) return;

            String columnName = buttonView.getTag().toString();
            mClientDataTable.moveToPosition(position);
            mClientDataTable.cellByName(columnName).setValue(isChecked);
          }
        });

    holder.setOnRecycleTextWatcher(
        new OnRecycleTextWatcher() {
          @Override
          public void afterTextChanged(
              boolean isWidgetInCDT, EditText v, String newText, int position) {
            if (!isWidgetInCDT
                || position >= mClientDataTable.getRowsCount()
                || !(v.isFocusable() || v.isFocusableInTouchMode())) return;

            mClientDataTable.moveToPosition(position);
            String columnName = v.getTag().toString();
            mClientDataTable.cellByName(columnName).setValue(newText);
          }
        });
  }