DefaultTableCellRender

this render overload my cpu (%65)
 
class Form08_014_labelRenderer222 extends DefaultTableCellRenderer {
  Form08_014 adaptee;
  public Form08_014_labelRenderer222(Form08_014 adaptee) {
    super();
    this.adaptee = adaptee;
  }

  public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    DateFormat formatter;
    switch (column) {
      case 0:
        setHorizontalAlignment(SwingConstants.RIGHT);
        break;
      case 2:
        setHorizontalAlignment(SwingConstants.LEFT);
        break;
      case 1:
      case 4:
/*
        formatter = DateFormat.getDateInstance(DateFormat.SHORT);
        value = (value == null) ? "" : formatter.format(value);
*/
        if (value != null)
          value = DateUtil.tarihIslem((Date) value, 0, this.getLocale());
        setHorizontalAlignment(SwingConstants.CENTER);
        break;
      case 9:
        if ((value != null) && (value != Dil.deger(adaptee.mpGlobal, "REJECTED"))) {
          formatter = DateFormat.getDateInstance(DateFormat.SHORT);
          value = formatter.format(value);
        }
      default:
        setHorizontalAlignment(SwingConstants.CENTER);
    }

    switch (column) {
      case 8:
        if ((value == null) || (value.toString().equals("")) || (value.toString().equals(Dil.deger(adaptee.mpModul, "ACCEPTED")))) {
          if (isSelected) {
            adaptee.sorguTablosu.setSelectionBackground(EROUtil.getThemeColor(ETable.COLOR_SELBACK));
            adaptee.sorguTablosu.setSelectionForeground(EROUtil.getThemeColor(ETable.COLOR_SELFORE));
            setForeground(table.getSelectionForeground());
            setBackground(table.getSelectionBackground());
          } else {
            setForeground(table.getForeground());
            setBackground(table.getBackground());
          }
        } else if (value.toString().equals(Dil.deger(adaptee.mpModul, "RISKLI"))) {
          if (isSelected) {
            adaptee.sorguTablosu.setSelectionBackground(new Color(192, 192, 0));
            adaptee.sorguTablosu.setSelectionForeground(new Color(0, 0, 0));
          } else {
            adaptee.sorguTablosu.setSelectionBackground(EROUtil.getThemeColor(ETable.COLOR_SELBACK));
            adaptee.sorguTablosu.setSelectionForeground(EROUtil.getThemeColor(ETable.COLOR_SELFORE));
            setBackground(new Color(255, 255, 63));
            setForeground(new Color(63, 63, 63));
          }
        } else if (value.toString().equals(Dil.deger(adaptee.mpModul, "ree"))) {
          if (isSelected) {
            adaptee.sorguTablosu.setSelectionBackground(new Color(192, 0, 0));
            adaptee.sorguTablosu.setSelectionForeground(new Color(192, 192, 192));
          } else {
            adaptee.sorguTablosu.setSelectionBackground(EROUtil.getThemeColor(ETable.COLOR_SELBACK));
            adaptee.sorguTablosu.setSelectionForeground(EROUtil.getThemeColor(ETable.COLOR_SELFORE));
            setBackground(new Color(255, 63, 63));
            setForeground(new Color(255, 255, 255));
          }
        }
        break;
      case 9:
        if ((value == null) || (value.toString().equals(""))) {
          if (isSelected) {
            adaptee.sorguTablosu.setSelectionBackground(EROUtil.getThemeColor(ETable.COLOR_SELBACK));
            adaptee.sorguTablosu.setSelectionForeground(EROUtil.getThemeColor(ETable.COLOR_SELFORE));
            setForeground(table.getSelectionForeground());
            setBackground(table.getSelectionBackground());
          } else {
            setForeground(table.getForeground());
            setBackground(table.getBackground());
          }
        } else if (value.toString().equals(Dil.deger(adaptee.mpModul, "UYGUNSUZ"))) {
          if (isSelected) {
            adaptee.sorguTablosu.setSelectionBackground(new Color(192, 0, 0));
            adaptee.sorguTablosu.setSelectionForeground(new Color(192, 192, 192));
          } else {
            adaptee.sorguTablosu.setSelectionBackground(EROUtil.getThemeColor(ETable.COLOR_SELBACK));
            adaptee.sorguTablosu.setSelectionForeground(EROUtil.getThemeColor(ETable.COLOR_SELFORE));
            setBackground(new Color(255, 63, 63));
            setForeground(new Color(255, 255, 255));
          }
        } else {
          if (isSelected) {
            adaptee.sorguTablosu.setSelectionBackground(new Color(192, 192, 0));
            adaptee.sorguTablosu.setSelectionForeground(new Color(0, 0, 0));
          } else {
            adaptee.sorguTablosu.setSelectionBackground(EROUtil.getThemeColor(ETable.COLOR_SELBACK));
            adaptee.sorguTablosu.setSelectionForeground(EROUtil.getThemeColor(ETable.COLOR_SELFORE));
            setBackground(new Color(255, 255, 63));
            setForeground(new Color(63, 63, 63));
          }
        }
        break;
      case 14:
      case 15:
        if ((value == null) || (value.toString().equals("")) || (value.toString().equals(Dil.deger(adaptee.mpModul, "NORMAL")))) {
          if (isSelected) {
            adaptee.sorguTablosu.setSelectionBackground(EROUtil.getThemeColor(ETable.COLOR_SELBACK));
            adaptee.sorguTablosu.setSelectionForeground(EROUtil.getThemeColor(ETable.COLOR_SELFORE));
            setForeground(table.getSelectionForeground());
            setBackground(table.getSelectionBackground());
          } else {
            setForeground(table.getForeground());
            setBackground(table.getBackground());
          }
        } else {
          if (isSelected) {
            adaptee.sorguTablosu.setSelectionBackground(new Color(192, 192, 0));
            adaptee.sorguTablosu.setSelectionForeground(new Color(0, 0, 0));
          } else {
            adaptee.sorguTablosu.setSelectionBackground(EROUtil.getThemeColor(ETable.COLOR_SELBACK));
            adaptee.sorguTablosu.setSelectionForeground(EROUtil.getThemeColor(ETable.COLOR_SELFORE));
            setBackground(new Color(255, 255, 63));
            setForeground(new Color(63, 63, 63));
          }
        }
        break;
      default:
        if (column > 15) {
          if ((value == null) || (value.toString().equals("")) || (value.toString().equals("-"))) {
            if (isSelected) {
              adaptee.sorguTablosu.setSelectionBackground(EROUtil.getThemeColor(ETable.COLOR_SELBACK));
              adaptee.sorguTablosu.setSelectionForeground(EROUtil.getThemeColor(ETable.COLOR_SELFORE));
              setForeground(table.getSelectionForeground());
              setBackground(table.getSelectionBackground());
            } else {
              setForeground(table.getForeground());
              setBackground(table.getBackground());
            }
          } else {
            if (isSelected) {
              adaptee.sorguTablosu.setSelectionBackground(new Color(192, 0, 0));
              adaptee.sorguTablosu.setSelectionForeground(new Color(192, 192, 192));
            } else {
              adaptee.sorguTablosu.setSelectionBackground(EROUtil.getThemeColor(ETable.COLOR_SELBACK));
              adaptee.sorguTablosu.setSelectionForeground(EROUtil.getThemeColor(ETable.COLOR_SELFORE));
              setBackground(new Color(255, 63, 63));
              setForeground(new Color(255, 255, 255));
            }
          }
        }
    }
    return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
  }
}
emrecaniazAsked:
Who is Participating?
 
ksivananthConnect With a Mentor Commented:
one classic improvement I can suggest that split this class into multiple renderer class for each columns and so avoid the switch case!

second, you can initialize the formatter once in the constructors and use them in the get... method!

third, value.toString() can be done at once and store in a string var and re-use the string var!

4th, you may want to look at the other your classes used here!
0
All Courses

From novice to tech pro — start learning today.