Exemplo n.º 1
0
 public MyRenderComponent(
     JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) {
   super();
   this.table = table;
   this.col = col;
   if (value != null) {
     setText(value.toString());
   } else {
     setText("");
   }
   setOpaque(false);
   setFont(UIManager.getFont("TableHeader.font"));
   setForeground(UIManager.getColor("TableHeader.foreground"));
   setHorizontalAlignment(JLabel.CENTER);
   setHorizontalTextPosition(SwingConstants.LEADING);
   setBorder(UIManager.getBorder("TableHeader.cellBorder"));
   if ((JTattooUtilities.getJavaVersion() >= 1.6)
       && (UIManager.getLookAndFeel() instanceof AbstractLookAndFeel)) {
     RowSorter rowSorter = table == null ? null : table.getRowSorter();
     List keyList = rowSorter == null ? null : rowSorter.getSortKeys();
     if ((keyList != null) && (keyList.size() > 0)) {
       RowSorter.SortKey sortKey = (RowSorter.SortKey) keyList.get(0);
       if (sortKey.getColumn() == table.convertColumnIndexToModel(col)) {
         AbstractIconFactory iconFactory =
             ((AbstractLookAndFeel) UIManager.getLookAndFeel()).getIconFactory();
         if (sortKey.getSortOrder().equals(SortOrder.ASCENDING)) {
           setIcon(iconFactory.getUpArrowIcon());
         } else if (sortKey.getSortOrder().equals(SortOrder.DESCENDING)) {
           setIcon(iconFactory.getDownArrowIcon());
         }
       }
     }
   }
   gv = ColorHelper.getGrayValue(AbstractLookAndFeel.getTheme().getRolloverColor());
 }
Exemplo n.º 2
0
 /** @inheritDoc */
 public Component getTableCellRendererComponent(
     JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
   Component c =
       candidate.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
   if (c instanceof JLabel && table != null) {
     ViperTableModel m = getCurrentModel();
     int modelIndex = table.convertColumnIndexToModel(column);
     AttrConfig ac = m.getAttributeForColumn(modelIndex);
     JLabel l = (JLabel) c;
     if (ac != null) {
       int visibility = mediator.getHiders().getAttrConfigVisibility(ac);
       l.setIcon(outerTablePanel.visibilityIcons[visibility]);
     } else if (m.getInternalColumn(modelIndex) == ViperTableModel.BY_VALID) {
       Config config = m.getConfig();
       int visibility = mediator.getHiders().getConfigVisibility(m.getConfig());
       if (visibility == NodeVisibilityManager.RANGE_LOCKED) {
         visibility = NodeVisibilityManager.LOCKED;
       }
       l.setIcon(outerTablePanel.visibilityIcons[visibility]);
     } else {
       l.setIcon(null);
     }
   }
   return c;
 }
Exemplo n.º 3
0
 public Component getTableCellRendererComponent(
     JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
   Component c =
       tableCellRenderer.getTableCellRendererComponent(
           table, value, isSelected, hasFocus, row, column);
   if (c instanceof JLabel) {
     JLabel l = (JLabel) c;
     l.setHorizontalTextPosition(JLabel.LEFT);
     int modelColumn = table.convertColumnIndexToModel(column);
     l.setIcon(getHeaderRendererIcon(modelColumn, l.getFont().getSize()));
   }
   return c;
 }
 @Override
 public void mouseClicked(MouseEvent e) {
   int col = table.columnAtPoint(new Point(e.getX(), e.getY()));
   String header = table.getColumnName(col);
   if (columnHeader.contains(header)) {
     int row = table.rowAtPoint(new Point(e.getX(), e.getY()));
     TableModel tableModel = table.getModel();
     Object val =
         tableModel.getValueAt(
             table.convertRowIndexToModel(row), table.convertColumnIndexToModel(col));
     if (val != null) {
       String text = val.toString();
       textDialog.setText(text);
       textDialog.setVisible(true);
     }
   }
 }
  public Component getTableCellRendererComponent(
      JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    // Whether we are printing the result or not
    boolean isPaintingForPrint = false;

    // Title icon
    Icon sortIcon = null;
    if (table != null) {
      JTableHeader header = table.getTableHeader();
      if (header != null) {
        Color fgColor = null;
        Color bgColor = null;
        if (hasFocus) {
          fgColor = UIManager.getColor("TableHeader.focusCellForeground");
          bgColor = UIManager.getColor("TableHeader.focusCellBackground");
        }
        if (fgColor == null) {
          fgColor = header.getForeground();
        }
        if (bgColor == null) {
          bgColor = header.getBackground();
        }
        setForeground(fgColor);
        setBackground(bgColor);

        setFont(header.getFont());

        isPaintingForPrint = header.isPaintingForPrint();
      }

      if (!isPaintingForPrint && table.getRowSorter() != null) {
        if (!horizontalTextPositionSet) {
          // There is a row sorter, and the developer hasn't
          // set a text position, change to leading.
          setHorizontalTextPosition(JLabel.LEADING);
        }
        List<? extends RowSorter.SortKey> sortKeys = table.getRowSorter().getSortKeys();
        if (sortKeys.size() > 0
            && sortKeys.get(0).getColumn() == table.convertColumnIndexToModel(column)) {
          switch (sortKeys.get(0).getSortOrder()) {
            case ASCENDING:
              sortIcon = UIManager.getIcon("Table.ascendingSortIcon");
              break;
            case DESCENDING:
              sortIcon = UIManager.getIcon("Table.descendingSortIcon");
              break;
            case UNSORTED:
              sortIcon = UIManager.getIcon("Table.naturalSortIcon");
              break;
          }
        }
      }
    }
    setIcon(sortIcon);

    // Title text
    setText(value == null ? "" : value.toString());

    // Title margin
    setMargin(WebTableStyle.headerMargin);

    return this;
  }