Example #1
0
 public void actionPerformed(ActionEvent e) {
   Object value = getValue(NAME);
   if (value == MNEMONIC) {
     JComponent c = (JComponent) e.getSource();
     c.requestFocusInWindow();
     value = getValue(MNEMONIC);
     if (value != null) {
       JComboBox combo = (JComboBox) c;
       combo.setSelectedItem(value);
     }
   } else if (value == EDIT) {
     JTable table = (JTable) e.getSource();
     int row = table.getSelectionModel().getLeadSelectionIndex();
     if (row < 0 || row >= table.getRowCount()) return;
     int col = UITableModel.VALUE_COLUMN_INDEX;
     table.editCellAt(row, table.convertColumnIndexToView(col));
   } else if (value == SORT) {
     value = getValue(SORT);
     JTable table = (JTable) e.getSource();
     for (int col = table.getColumnCount(); --col >= 0; ) {
       if (value.equals(table.getColumnName(col))) {
         table.getRowSorter().toggleSortOrder(table.convertColumnIndexToModel(col));
         break;
       }
     }
   } else if (value == CLOSE) {
     SwingUtilities.getWindowAncestor((Component) e.getSource()).dispose();
   }
 }
  /** TableCellRenderer implementation */
  public Component getTableCellRendererComponent(
      JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    // Try to set default fore- and background colors
    if (table != null) {
      JTableHeader header = table.getTableHeader();
      if (header != null) {
        setForeground(header.getForeground());
        setBackground(header.getBackground());
        setFont(header.getFont());
        AbstractTableModel model = (AbstractTableModel) table.getModel();

        column = table.convertColumnIndexToModel(column);
        setText(model.getColumnName(column));
        // set normal border
        setBorder(javax.swing.UIManager.getBorder("TableHeader.cellBorder"));

        if (m_sortmode == SortMode.ASCENDING) setIcon(m_upimage);
        else if (m_sortmode == SortMode.DESCENDING) setIcon(m_downimage);
        else
          // if NONE
          setIcon(m_emptyheaderimage);
      }
    }
    return this;
  }
 /** @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;
 }
 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());
 }
Example #5
0
    public Component getTableCellRendererComponent(
        final JTable table,
        final Object value,
        final boolean isSelected,
        final boolean hasFocus,
        final int row,
        final int column) {

      final int modelColumn = table.convertColumnIndexToModel(column);
      if (modelColumn == 0) {
        final Object pairValue = table.getValueAt(row, column == 0 ? 1 : 0);
        LOGGER.debug(
            "KeyCellValueTypeRenderer. pairValue: "
                + pairValue
                + ", pairValueClass: "
                + (pairValue != null ? pairValue.getClass() : pairValue));
        if (pairValue != null) {
          Class<?> valueClass = pairValue.getClass();
          while (valueClass != Object.class && classIconMap.get(valueClass) == null) {
            valueClass = valueClass.getSuperclass();
          }
          this.setIcon(classIconMap.get(valueClass));
        }
      }
      return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    }
Example #6
0
 private JLabel renderHeaderCell(int rowIndex, int columnIndex) {
   TableCellRenderer renderer = table.getTableHeader().getDefaultRenderer();
   int modelIndex = table.convertColumnIndexToModel(columnIndex);
   TableColumn tableColumn = table.getColumnModel().getColumn(modelIndex);
   Object cellValue = tableColumn.getHeaderValue();
   return (JLabel)
       renderer.getTableCellRendererComponent(
           table, cellValue, false, false, rowIndex, columnIndex);
 }
 /**
  * Save table column positions and sizes. Note, the table must have its auto resize mode set to
  * off, i.e.
  *
  * @param table
  * @param registry prefix
  * @param table name
  */
 private void saveTableMetrics(JTable table, String propertyName) {
   for (int i = 0; i < table.getColumnModel().getColumnCount(); i++) {
     int w = table.getColumnModel().getColumn(i).getWidth();
     context.putPreference(propertyName + ".column." + i + ".width", String.valueOf(w));
     context.putPreference(
         propertyName + ".column." + i + ".position",
         String.valueOf(table.convertColumnIndexToModel(i)));
   }
 }
Example #8
0
      public Component getTableCellRendererComponent(
          JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
        setOpaque(true);
        int actualCol = table.convertColumnIndexToModel(column);
        int actualRow = table.convertRowIndexToModel(row);
        setHorizontalAlignment(getAlignment(actualCol));
        setToolTipText(getTooltip(actualRow, actualCol));

        return this;
      }
Example #9
0
 public java.awt.Component getTableCellRendererComponent(
     JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
   java.awt.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;
 }
    // note that column and rows received by this method are view-related, so we'll use the
    // convertColumnIndexToModel
    // to convert them when wee nedd'em to be model-related
    @Override
    public synchronized Component getTableCellRendererComponent(
        JTable table, Object value, boolean selected, boolean focused, int row, int column) {
      // all the columns but the stock_name one have to be aligned on the right
      if (table.convertColumnIndexToModel(column) != 0) {
        this.setHorizontalAlignment(RIGHT);
      } else {
        this.setHorizontalAlignment(LEFT);
      }

      UpdateString valueUS;
      // we check on the UpdateString if the value is hot or cold and we set the background color
      // accordingly; in case the field is null or is not an UpdatString we use the cold colors
      if (value != null
          && value instanceof UpdateString
          && (valueUS = (UpdateString) value).isHot()) {
        if ((row % 2) == 0) {
          this.setBackground(evenHot);
        } else {
          this.setBackground(oddHot);
        }
        // in case the update is hot we schedule a task to make it cold after 300ms
        shutDown.add(
            new ShutDownTask(
                new Date().getTime() + 300,
                valueUS.getUpdateCount(),
                table.convertRowIndexToModel(row),
                table.convertColumnIndexToModel(column)));

      } else {
        if ((row % 2) == 0) {
          this.setBackground(evenRow);
        } else {
          this.setBackground(oddRow);
        }
      }

      return super.getTableCellRendererComponent(table, value, selected, focused, row, column);
    }
Example #11
0
  protected void handleClickEvent(MouseEvent e) {
    if (mousePressed) {
      mousePressed = false;
      JTableHeader header = (JTableHeader) (e.getSource());
      JTable tableView = header.getTable();
      TableColumnModel columnModel = tableView.getColumnModel();
      int viewColumn = columnModel.getColumnIndexAtX(e.getX());
      int _column = tableView.convertColumnIndexToModel(viewColumn);

      if (viewColumn == this.column && e.getClickCount() == 1 && _column != -1) {
        doClick();
      }
    }
  }
 @Override
 public void mouseMoved(MouseEvent evt) {
   JTableHeader header = (JTableHeader) evt.getSource();
   JTable table = header.getTable();
   TableColumnModel colModel = table.getColumnModel();
   int vColIndex = colModel.getColumnIndexAtX(evt.getX());
   TableColumn col = null;
   if (vColIndex >= 0) {
     col = colModel.getColumn(table.convertColumnIndexToModel(vColIndex));
   }
   if (table.convertColumnIndexToModel(vColIndex) != curCol) {
     if (col != null) {
       MageFrame.getInstance().getBalloonTip().setAttachedComponent(header);
       JLabel content = new JLabel(tips.get(table.convertColumnIndexToModel(vColIndex)));
       content.setFont(GUISizeHelper.tooltipFont);
       MageFrame.getInstance().getBalloonTip().setContents(content);
       ToolTipUtils.balloonToToolTip(MageFrame.getInstance().getBalloonTip(), 600, 10000);
     } else {
       MageFrame.getInstance().getBalloonTip().setTextContents("");
     }
     curCol = table.convertColumnIndexToModel(vColIndex);
   }
 }
 @Override
 public Component getTableCellRendererComponent(
     JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
   setText(value.toString());
   int convertColumn = table.convertColumnIndexToModel(column);
   if (m_sorter != null && m_sorter.isSortColumn(convertColumn)) {
     if (m_sorter.isAsscending(convertColumn)) {
       setIcon(UPARROW);
     } else {
       setIcon(DOWNARROW);
     }
   } else {
     setIcon(null);
   }
   return this;
 }
 @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);
     }
   }
 }
Example #15
0
  /** Render table header */
  public Component getTableCellRendererComponent(
      JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {

    Component result =
        superRenderer.getTableCellRendererComponent(
            table, value, isSelected, hasFocus, row, column);

    if (result instanceof JLabel) {
      final JLabel label = (JLabel) result;
      label.setHorizontalTextPosition(javax.swing.SwingConstants.LEADING);

      final int columnModel = table.convertColumnIndexToModel(column);
      final Key colProperty = ((UjoTable) table).getModel().getColumn(columnModel);
      label.setIcon(colProperty == sortedColumn ? sortIcon : null);
    }

    return result;
  }
Example #16
0
 /**
  * returns a JLabel that is highlighted if the row is selected.
  *
  * @param table
  * @param value
  * @param isSelected
  * @param hasFocus
  * @param row
  * @param column
  * @return
  */
 public Component getTableCellRendererComponent(
     JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
   if (table.isRowSelected(row)) {
     int[] i = table.getSelectedColumns();
     if ((i.length == 1) && (table.convertColumnIndexToModel(i[0]) == 0)) {
       setBackground(PANEL_BACKGROUND);
     } else {
       setBackground(Color.gray);
     }
   } else {
     setBackground(PANEL_BACKGROUND);
   }
   if (value == null) { // added by W. Christian
     setText("???"); // $NON-NLS-1$
   } else {
     setText(value.toString());
   }
   return this;
 }
 @Override
 public Component getTableCellRendererComponent(
     JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
   setIcon(null);
   super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
   try {
     int c = table.convertColumnIndexToModel(column);
     if (c == DatenProg.PROGRAMM_RESTART || c == DatenProg.PROGRAMM_DOWNLOADMANAGER) {
       setHorizontalAlignment(CENTER);
       if (getText().equals(Boolean.TRUE.toString())) {
         setIcon(ja_16);
       } else {
         setIcon(nein_12);
       }
       setText("");
     }
   } catch (Exception ex) {
     Log.errorLog(338740095, ex);
   }
   return this;
 }
  public Component getTableCellRendererComponent(
      final JTable table,
      final Object value,
      final boolean isSelected,
      final boolean hasFocus,
      final int row,
      final int column) {

    setOpaque(true);

    if (isSelected) {
      setBackground(ViewColors.TABLE_SELECTION_COLOR);
      setForeground(ViewColors.TABLE_FOREGROUND_COLOR);
    } else {
      setBackground(ViewColors.TABLE_UNSELECTION_COLOR);
      setForeground(ViewColors.TABLE_FOREGROUND_COLOR);
    }

    final int modelColumn = table.convertColumnIndexToModel(column);

    switch (modelColumn) {
      case CloneSetListViewModel.COL_ID:
        {
          this.setHorizontalAlignment(JLabel.CENTER);
          this.setText(value.toString());
          break;
        }
      case CloneSetListViewModel.COL_RAD:
        {
          this.setHorizontalAlignment(JLabel.RIGHT);
          this.setText(value.toString());
          break;
        }
      case CloneSetListViewModel.COL_LEN:
        {
          this.setHorizontalAlignment(JLabel.RIGHT);
          this.setText(value.toString());
          break;
        }
      case CloneSetListViewModel.COL_RNR:
        {
          this.setHorizontalAlignment(JLabel.RIGHT);
          this.setText(value.toString());
          break;
        }
      case CloneSetListViewModel.COL_NIF:
        {
          this.setHorizontalAlignment(JLabel.RIGHT);
          this.setText(value.toString());
          break;
        }
      case CloneSetListViewModel.COL_POP:
        {
          this.setHorizontalAlignment(JLabel.RIGHT);
          this.setText(value.toString());
          break;
        }
      case CloneSetListViewModel.COL_DFL:
        {
          this.setHorizontalAlignment(JLabel.RIGHT);
          this.setText(value.toString());
          break;
        }
    }

    return this;
  }
  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;
  }