Java Code Examples for javax.swing.JTable#getSelectionBackground()

The following examples show how to use javax.swing.JTable#getSelectionBackground() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JiveSortableTable.java    From Spark with Apache License 2.0 6 votes vote down vote up
@Override
public Component getTableCellRendererComponent(JTable table, Object value,
                                                     boolean isSelected, boolean hasFocus, int row, int column) {
          if (isSelected) {
              setForeground(table.getSelectionForeground());
              super.setBackground(table.getSelectionBackground());
          }
          else {
              setForeground(table.getForeground());
              setBackground(table.getBackground());
          }

          // Select the current value
          setSelectedItem(value);
          return this;
      }
 
Example 2
Source File: SectorRowsEditor.java    From ramus with GNU General Public License v3.0 5 votes vote down vote up
public Component getTableCellRendererComponent(final JTable table,
                                               final Object value, final boolean isSelected,
                                               final boolean hasFocus, final int row, final int column) {
    if (isSelected) {
        super.setForeground(table.getSelectionForeground());
        super.setBackground(table.getSelectionBackground());
    } else {
        super.setForeground(table.getForeground());
        super.setBackground(table.getBackground());
    }

    setFont(table.getFont());

    if (hasFocus) {
        Border border = null;
        if (isSelected) {
            border = UIManager
                    .getBorder("Table.focusSelectedCellHighlightBorder");
        }
        if (border == null) {
            border = UIManager
                    .getBorder("Table.focusCellHighlightBorder");
        }
        setBorder(border);
    } else {
        setBorder(noFocusBorder);
    }
    return this;
}
 
Example 3
Source File: MBooleanTableCellRenderer.java    From javamelody with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public Component getTableCellRendererComponent(final JTable table, final Object value,
		final boolean isSelected, final boolean hasFocus, final int row, final int column) {

	if (isSelected) {
		super.setForeground(table.getSelectionForeground());
		super.setBackground(table.getSelectionBackground());
	} else {
		super.setForeground(table.getForeground());
		if (MTable.BICOLOR_LINE != null && row % 2 == 0) {
			super.setBackground(MTable.BICOLOR_LINE);
		} else {
			super.setBackground(table.getBackground());
		}
	}

	if (hasFocus) {
		setBorder(BORDER);
	} else {
		setBorder(null);
	}

	setEnabled(table.isCellEditable(row, column));

	if (value instanceof Boolean) {
		final boolean selected = ((Boolean) value).booleanValue();
		this.setSelected(selected);
		// this.setToolTipText(selected ? "vrai" : "false");
		return this;
	}
	final JLabel label = (JLabel) table.getDefaultRenderer(String.class)
			.getTableCellRendererComponent(table, null, isSelected, hasFocus, row, column);
	if (value == null) {
		label.setText(null);
	} else {
		label.setText("??");
	}
	return label;
}
 
Example 4
Source File: TableCellRendererToLabel.java    From ET_Redux with Apache License 2.0 5 votes vote down vote up
/**
     * 
     * @param table
     * @param value
     * @param isSelected
     * @param hasFocus
     * @param rowIndex
     * @param vColIndex
     * @return
     */
    @Override
    public Component getTableCellRendererComponent ( JTable table, Object value,
            boolean isSelected, boolean hasFocus, int rowIndex, int vColIndex ) {
        // 'value' is value contained in the cell located at
        // (rowIndex, vColIndex)

////////        if (vColIndex > 2){
//            table.setRowSelectionAllowed(true);
////////        } else {
////////            table.setRowSelectionAllowed(false);
////////            isSelected = false;
////////        }


        selection = table.getSelectionBackground();

        if ( isSelected && vColIndex >= 2 ) {
            // cell (and perhaps other cells) are selected
            mePaint = false;
        } else {
            mePaint = true;
        }

        // Configure the component with the specified value
        setText( value.toString() );

        // Set tool tip if desired
        //setToolTipText(value.toString());

        // Since the renderer is a component, return itself
        return this;
    }
 
Example 5
Source File: YesNoRenderer.java    From RipplePower with Apache License 2.0 5 votes vote down vote up
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
		int row, int column) {
	if (isSelected) {
		super.setForeground(table.getSelectionForeground());
		super.setBackground(table.getSelectionBackground());
	} else {
		super.setForeground((unselectedForeground != null) ? unselectedForeground : table.getForeground());
		super.setBackground((unselectedBackground != null) ? unselectedBackground : table.getBackground());
	}

	setFont(table.getFont());

	if (hasFocus) {
		setBorder(UIManager.getBorder("Table.focusCellHighlightBorder"));

		if (table.isCellEditable(row, column)) {
			super.setForeground(UIManager.getColor("Table.focusCellForeground"));
			super.setBackground(UIManager.getColor("Table.focusCellBackground"));
		}
	} else {
		setBorder(noFocusBorder);
	}
	setValue(value);
	Color back = getBackground();
	boolean colorMatch = (back != null) && (back.equals(table.getBackground())) && table.isOpaque();
	setOpaque(!colorMatch);
	return this;
}
 
Example 6
Source File: BooleanPropertyCellRenderer.java    From openAGV with Apache License 2.0 5 votes vote down vote up
@Override
public Component getTableCellRendererComponent(
    JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {

  AttributesTable attributesTable = (AttributesTable) table;
  boolean editable = attributesTable.isEditable(row);

  if (isSelected) {
    setForeground(table.getSelectionForeground());
    super.setBackground(table.getSelectionBackground());
  }
  else {
    setForeground(table.getForeground());
    setBackground(editable ? table.getBackground() : StandardPropertyCellRenderer.BG_UNEDITABLE);
  }

  if (value instanceof BooleanProperty) {
    BooleanProperty property = (BooleanProperty) value;

    if (property.getValue() instanceof MultipleDifferentValues) {
      setBackground(AbstractPropertyCellEditor.DIFFERENT_VALUE_COLOR);
    }
    else if (property.getValue() instanceof Boolean) {
      setToolTipText(property.getHelptext());
      setSelected((boolean) property.getValue());
    }
    else {
      setEnabled(false);
    }
  }

  return this;
}
 
Example 7
Source File: MosaicExpressionsPanel.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
                                               int row, int column) {
    final boolean enabled = table.isEnabled();
    setText((String) value);

    if (isSelected) {
        super.setForeground(table.getSelectionForeground());
        super.setBackground(table.getSelectionBackground());
    } else if (!enabled) {
        super.setForeground(UIManager.getColor("TextField.inactiveForeground"));
        super.setBackground(table.getBackground());
    } else {
        super.setForeground(table.getForeground());
        super.setBackground(table.getBackground());
    }

    setFont(table.getFont());

    if (hasFocus) {
        setBorder(UIManager.getBorder("Table.focusCellHighlightBorder"));
        if (table.isCellEditable(row, column)) {
            super.setForeground(UIManager.getColor("Table.focusCellForeground"));
            super.setBackground(UIManager.getColor("Table.focusCellBackground"));
        }
    } else {
        setBorder(noFocusBorder);
    }

    setValue(value);

    return this;
}
 
Example 8
Source File: ObdItemTableRenderer.java    From AndrOBD with GNU General Public License v3.0 5 votes vote down vote up
/**
 * set visualisation parameters referring to given table
 *
 * @param table
 *          - the table object to refer to ...
 */
private void setParentTable(JTable table)
{
	parentTable = table;
	// set the font only once, and then just use it
	parentFont = table.getFont();
	setFont(parentFont);

	// get background color from Table
	bgColor = table.getBackground();
	// get selection color from Table
	selColor = table.getSelectionBackground();
}
 
Example 9
Source File: CoverageReportTopComponent.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public Component getTableCellRendererComponent(JTable table, Object value,
        boolean isSelected, boolean hasFocus, int row, int column) {
    if (value == null) {
        return new DefaultTableCellRenderer().getTableCellRendererComponent(table, value,
                isSelected, hasFocus, row, column);
    }

    if (isSelected) {
        super.setForeground(table.getSelectionForeground());
        super.setBackground(table.getSelectionBackground());
    } else {
        super.setForeground(table.getForeground());
        super.setBackground(table.getBackground());
    }

    setFont(table.getFont());

    if (hasFocus) {
        Border border = null;
        if (isSelected) {
            border = UIManager.getBorder("Table.focusSelectedCellHighlightBorder"); // NOI18N
        }
        if (border == null) {
            border = UIManager.getBorder("Table.focusCellHighlightBorder"); // NOI18N
        }
        setBorder(border);
    } else {
        setBorder(new EmptyBorder(1, 1, 1, 1));
    }


    FileCoverageSummary summary = (FileCoverageSummary) table.getValueAt(row, -1);
    FileObject file = summary.getFile();

    setText(summary.getDisplayName());
    if (file != null && file.isValid()) {
        try {
            DataObject dobj = DataObject.find(file);
            Node node = dobj.getNodeDelegate();
            Image icon = node.getIcon(BeanInfo.ICON_COLOR_32x32);
            setIcon(new ImageIcon(icon));
        } catch (DataObjectNotFoundException ex) {
            Exceptions.printStackTrace(ex);
        }
    } else {
        setIcon(null);
    }


    return this;
}
 
Example 10
Source File: TabDataRenderer.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column ) {
    renderer.clear();
    Rectangle rect = table.getCellRect( row, column, true );
    renderer.setSize( rect.width, rect.height );
    if( value instanceof TabData ) {
        TabData tab = ( TabData ) value;
        String text = tab.getText();
        Icon icon = tab.getIcon();
        Color colBackground = isSelected ? table.getSelectionBackground() : table.getBackground();
        Color colForeground = isSelected ? table.getSelectionForeground() : table.getForeground();

        boolean isActive = (activeBackground != null || underlineColor != null)
            ? TabbedImpl.isActive(table) : false;
        if (!isSelected && isActive && activeBackground != null) {
            colBackground = activeBackground;
        }

        for( TabDecorator td : decorators ) {
            Color c = td.getBackground( tab, isSelected );
            if( null != c )
                colBackground = c;
            c = td.getForeground( tab, isSelected );
            if( null != c )
                colForeground = c;

            String s = td.getText( tab );
            if( null != s )
                text = s;

            Icon i = td.getIcon( tab );
            if( null != i ) {
                icon = i;
            }
        }
        boolean isHover = (hoverBackground != null && TabTableUI.isHover(table, row, column));
        if (isHover) {
            colBackground = hoverBackground;
        }
        renderer.label.setText( text );
        renderer.label.setIcon( icon );
        renderer.label.setFont( table.getFont() );
        renderer.setBackground( colBackground );
        renderer.label.setForeground( colForeground );
        renderer.tabData = tab;
        renderer.isSelected = isSelected;
        renderer.isActive = isActive;
        renderer.tabsLocation = (table instanceof TabTable) ? ((TabTable)table).getTabsLocation() : JTabbedPane.TOP;

        if( table instanceof TabTable ) {
            TabTable tabTable = ( TabTable ) table;
            if( isClosable(tab) ) {
                boolean inCloseButton = tabTable.isCloseButtonHighlighted( row, column );
                renderer.closeButton.setVisible( true );
                renderer.closeButton.getModel().setRollover( inCloseButton );
                renderer.closeButton.getModel().setArmed( inCloseButton );
            } else {
                renderer.closeButton.setVisible( false );
            }
        }
    }
    return renderer;
}
 
Example 11
Source File: PeakStatusCellRenderer.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable,
 *      java.lang.Object, boolean, boolean, int, int)
 */
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
    boolean hasFocus, int row, int column) {

  JPanel newPanel = new JPanel();
  newPanel.setLayout(new OverlayLayout(newPanel));

  Color bgColor;

  if (isSelected)
    bgColor = table.getSelectionBackground();
  else
    bgColor = table.getBackground();

  newPanel.setBackground(bgColor);

  if (hasFocus) {
    Border border = null;
    if (isSelected)
      border = UIManager.getBorder("Table.focusSelectedCellHighlightBorder");
    if (border == null)
      border = UIManager.getBorder("Table.focusCellHighlightBorder");

    /*
     * The "border.getBorderInsets(newPanel) != null" is a workaround for OpenJDK 1.6.0 bug,
     * otherwise setBorder() may throw a NullPointerException
     */
    if ((border != null) && (border.getBorderInsets(newPanel) != null)) {
      newPanel.setBorder(border);
    }

  }

  if (value != null) {
    FeatureStatus status = (FeatureStatus) value;

    switch (status) {
      case DETECTED:
        newPanel.add(greenCircle);
        break;
      case ESTIMATED:
        newPanel.add(yellowCircle);
        break;
      case MANUAL:
        newPanel.add(orangeCircle);
        break;
      default:
        newPanel.add(redCircle);
        break;
    }

    newPanel.setToolTipText(status.toString());

  } else {
    newPanel.add(redCircle);
  }

  return newPanel;

}
 
Example 12
Source File: EncryptBackActionCellRenderer.java    From pgptool with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
		int row, int column) {

	if (table == null) {
		return this;
	}

	lbl.setFont(table.getFont().deriveFont(Font.BOLD));

	Color fg = null;
	Color bg = null;

	JTable.DropLocation dropLocation = table.getDropLocation();
	if (dropLocation != null && !dropLocation.isInsertRow() && !dropLocation.isInsertColumn()
			&& dropLocation.getRow() == row && dropLocation.getColumn() == column) {
		fg = UIManager.getColor("Table.dropCellForeground");
		bg = UIManager.getColor("Table.dropCellBackground");
		isSelected = true;
	}

	if (isSelected) {
		super.setForeground(fg == null ? table.getSelectionForeground() : fg);
		super.setBackground(bg == null ? table.getSelectionBackground() : bg);
	} else {
		Color background = unselectedBackground != null ? unselectedBackground : table.getBackground();
		if (background == null || background instanceof javax.swing.plaf.UIResource) {
			Color alternateColor = UIManager.getColor("Table.alternateRowColor");
			if (alternateColor != null && row % 2 != 0) {
				background = alternateColor;
			}
		}
		super.setForeground(unselectedForeground != null ? unselectedForeground : table.getForeground());
		super.setBackground(background);
	}

	setFont(table.getFont());

	if (hasFocus) {
		Border border = null;
		if (isSelected) {
			border = UIManager.getBorder("Table.focusSelectedCellHighlightBorder");
		}
		if (border == null) {
			border = UIManager.getBorder("Table.focusCellHighlightBorder");
		}
		setBorder(border);

		if (!isSelected && table.isCellEditable(row, column)) {
			Color col;
			col = UIManager.getColor("Table.focusCellForeground");
			if (col != null) {
				super.setForeground(col);
			}
			col = UIManager.getColor("Table.focusCellBackground");
			if (col != null) {
				super.setBackground(col);
			}
		}
	} else {
		setBorder(getNoFocusBorder());
	}

	return this;
}
 
Example 13
Source File: DateTimeTableEditor.java    From LGoodDatePicker with MIT License 4 votes vote down vote up
/**
 * getTableCellRendererComponent, Returns the renderer that is used for drawing the cell. This
 * is required by the TableCellRenderer interface.
 *
 * For additional details, see the Javadocs for the function:
 * TableCellRenderer.getTableCellRendererComponent().
 */
@Override
public Component getTableCellRendererComponent(JTable table, Object value,
        boolean isSelected, boolean hasFocus, int row, int column) {
    // Save the supplied value to the DateTimePicker.
    setCellEditorValue(value);
    // Draw the appropriate background colors to indicate a selected or unselected state.
    if (isSelected) {
        if (matchTableSelectionBackgroundColor) {
            Color selectionBackground = table.getSelectionBackground();
            dateTimePicker.setBackground(selectionBackground);
            dateTimePicker.datePicker.setBackground(selectionBackground);
            dateTimePicker.timePicker.setBackground(selectionBackground);
            dateTimePicker.datePicker.getComponentDateTextField().setBackground(selectionBackground);
            dateTimePicker.timePicker.getComponentTimeTextField().setBackground(selectionBackground);
        } else {
            dateTimePicker.datePicker.zDrawTextFieldIndicators();
            dateTimePicker.timePicker.zDrawTextFieldIndicators();
        }
    }
    if (!isSelected) {
        if (matchTableBackgroundColor) {
            Color tableBackground = table.getBackground();
            dateTimePicker.setBackground(tableBackground);
            dateTimePicker.datePicker.setBackground(tableBackground);
            dateTimePicker.timePicker.setBackground(tableBackground);
            dateTimePicker.datePicker.getComponentDateTextField().setBackground(tableBackground);
            dateTimePicker.timePicker.getComponentTimeTextField().setBackground(tableBackground);
        } else {
            dateTimePicker.datePicker.zDrawTextFieldIndicators();
            dateTimePicker.timePicker.zDrawTextFieldIndicators();
        }
    }
    // Draw the appropriate borders to indicate a focused or unfocused state.
    if (hasFocus) {
        dateTimePicker.setBorder(borderFocusedCell);
    } else {
        dateTimePicker.setBorder(borderUnfocusedCell);
    }
    // If needed, adjust the minimum row height for the table.
    zAdjustTableRowHeightIfNeeded(table);
    // This fixes a bug where the picker text could "move around" during a table resize event.
    dateTimePicker.datePicker.getComponentDateTextField().setScrollOffset(0);
    dateTimePicker.timePicker.getComponentTimeTextField().setScrollOffset(0);
    // Return the DateTimePicker component.
    return dateTimePicker;
}
 
Example 14
Source File: FormattedCellRenderer.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable,
 *      java.lang.Object, boolean, boolean, int, int)
 */
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
    boolean hasFocus, int row, int column) {

  JPanel newPanel = new JPanel();
  Color bgColor;

  if (isSelected)
    bgColor = table.getSelectionBackground();
  else
    bgColor = table.getBackground();

  newPanel.setBackground(bgColor);

  if (hasFocus) {
    Border border = null;
    if (isSelected)
      border = UIManager.getBorder("Table.focusSelectedCellHighlightBorder");
    if (border == null)
      border = UIManager.getBorder("Table.focusCellHighlightBorder");

    /*
     * The "border.getBorderInsets(newPanel) != null" is a workaround for OpenJDK 1.6.0 bug,
     * otherwise setBorder() may throw a NullPointerException
     */
    if ((border != null) && (border.getBorderInsets(newPanel) != null)) {
      newPanel.setBorder(border);
    }

  }

  if (value != null) {

    String text;

    if (value instanceof Number)
      text = format.format((Number) value);
    else
      text = value.toString();

    JLabel newLabel = new JLabel(text, JLabel.CENTER);

    if (font != null)
      newLabel.setFont(font);
    else if (table.getFont() != null)
      newLabel.setFont(table.getFont());

    newPanel.add(newLabel);

  }

  return newPanel;

}
 
Example 15
Source File: CompoundIdentityCellRenderer.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable,
 *      java.lang.Object, boolean, boolean, int, int)
 */
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
    boolean hasFocus, int row, int column) {

  JLabel newLabel = new JLabel();
  newLabel.setHorizontalAlignment(JLabel.LEFT);
  newLabel.setFont(defaultFont);
  newLabel.setOpaque(true);

  Color bgColor;

  if (isSelected)
    bgColor = table.getSelectionBackground();
  else
    bgColor = table.getBackground();

  newLabel.setBackground(bgColor);

  if (hasFocus) {
    Border border = null;
    if (isSelected)
      border = UIManager.getBorder("Table.focusSelectedCellHighlightBorder");
    if (border == null)
      border = UIManager.getBorder("Table.focusCellHighlightBorder");

    /*
     * The "border.getBorderInsets(newPanel) != null" is a workaround for OpenJDK 1.6.0 bug,
     * otherwise setBorder() may throw a NullPointerException
     */
    if ((border != null) && (border.getBorderInsets(newLabel) != null)) {
      newLabel.setBorder(border);
    }
  }

  if (value instanceof PeakIdentity) {

    PeakIdentity identity = (PeakIdentity) value;

    newLabel.setText(identity.getName());

    String toolTipText = identity.getDescription();

    newLabel.setToolTipText(toolTipText);

  }

  return newLabel;

}
 
Example 16
Source File: FormattedCellRenderer.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable,
 *      java.lang.Object, boolean, boolean, int, int)
 */
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
    boolean hasFocus, int row, int column) {

  JPanel newPanel = new JPanel();
  Color bgColor;

  if (isSelected)
    bgColor = table.getSelectionBackground();
  else
    bgColor = table.getBackground();

  newPanel.setBackground(bgColor);

  if (hasFocus) {
    Border border = null;
    if (isSelected)
      border = UIManager.getBorder("Table.focusSelectedCellHighlightBorder");
    if (border == null)
      border = UIManager.getBorder("Table.focusCellHighlightBorder");

    /*
     * The "border.getBorderInsets(newPanel) != null" is a workaround for OpenJDK 1.6.0 bug,
     * otherwise setBorder() may throw a NullPointerException
     */
    if ((border != null) && (border.getBorderInsets(newPanel) != null)) {
      newPanel.setBorder(border);
    }

  }

  if (value != null) {

    String text;

    if (value instanceof Number)
      text = format.format((Number) value);
    else
      text = value.toString();

    JLabel newLabel = new JLabel(text, JLabel.CENTER);

    if (font != null)
      newLabel.setFont(font);
    else if (table.getFont() != null)
      newLabel.setFont(table.getFont());

    newPanel.add(newLabel);

  }

  return newPanel;

}
 
Example 17
Source File: PeakStatusCellRenderer.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable,
 *      java.lang.Object, boolean, boolean, int, int)
 */
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
    boolean hasFocus, int row, int column) {

  JPanel newPanel = new JPanel();
  newPanel.setLayout(new OverlayLayout(newPanel));

  Color bgColor;

  if (isSelected)
    bgColor = table.getSelectionBackground();
  else
    bgColor = table.getBackground();

  newPanel.setBackground(bgColor);

  if (hasFocus) {
    Border border = null;
    if (isSelected)
      border = UIManager.getBorder("Table.focusSelectedCellHighlightBorder");
    if (border == null)
      border = UIManager.getBorder("Table.focusCellHighlightBorder");

    /*
     * The "border.getBorderInsets(newPanel) != null" is a workaround for OpenJDK 1.6.0 bug,
     * otherwise setBorder() may throw a NullPointerException
     */
    if ((border != null) && (border.getBorderInsets(newPanel) != null)) {
      newPanel.setBorder(border);
    }

  }

  if (value != null) {
    FeatureStatus status = (FeatureStatus) value;

    switch (status) {
      case DETECTED:
        newPanel.add(greenCircle);
        break;
      case ESTIMATED:
        newPanel.add(yellowCircle);
        break;
      case MANUAL:
        newPanel.add(orangeCircle);
        break;
      default:
        newPanel.add(redCircle);
        break;
    }

    newPanel.setToolTipText(status.toString());

  } else {
    newPanel.add(redCircle);
  }

  return newPanel;

}
 
Example 18
Source File: ComponentCellRenderer.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable,
 *      java.lang.Object, boolean, boolean, int, int)
 */
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
    boolean hasFocus, int row, int column) {

  JPanel newPanel = new JPanel();
  newPanel.setLayout(new OverlayLayout(newPanel));

  Color bgColor;

  if (isSelected)
    bgColor = table.getSelectionBackground();
  else
    bgColor = table.getBackground();

  newPanel.setBackground(bgColor);

  if (hasFocus) {
    Border border = null;
    if (isSelected)
      border = UIManager.getBorder("Table.focusSelectedCellHighlightBorder");
    if (border == null)
      border = UIManager.getBorder("Table.focusCellHighlightBorder");
    if (border != null)
      newPanel.setBorder(border);
  }

  if (value != null) {

    if (value instanceof JComponent) {

      newPanel.add((JComponent) value);

    } else {

      JLabel newLabel = new JLabel();
      if (value instanceof IIsotope) {
        IIsotope is = (IIsotope) value;
        newLabel.setText(is.getSymbol());
      } else {
        newLabel.setText(value.toString());
      }

      if (font != null)
        newLabel.setFont(font);
      else if (table.getFont() != null)
        newLabel.setFont(table.getFont());

      newPanel.add(newLabel);
    }

    if (createTooltips)
      newPanel.setToolTipText(value.toString());

  }

  return newPanel;

}
 
Example 19
Source File: CompoundIdentityCellRenderer.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable,
 *      java.lang.Object, boolean, boolean, int, int)
 */
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
    boolean hasFocus, int row, int column) {

  JLabel newLabel = new JLabel();
  newLabel.setHorizontalAlignment(JLabel.LEFT);
  newLabel.setFont(defaultFont);
  newLabel.setOpaque(true);

  Color bgColor;

  if (isSelected)
    bgColor = table.getSelectionBackground();
  else
    bgColor = table.getBackground();

  newLabel.setBackground(bgColor);

  if (hasFocus) {
    Border border = null;
    if (isSelected)
      border = UIManager.getBorder("Table.focusSelectedCellHighlightBorder");
    if (border == null)
      border = UIManager.getBorder("Table.focusCellHighlightBorder");

    /*
     * The "border.getBorderInsets(newPanel) != null" is a workaround for OpenJDK 1.6.0 bug,
     * otherwise setBorder() may throw a NullPointerException
     */
    if ((border != null) && (border.getBorderInsets(newLabel) != null)) {
      newLabel.setBorder(border);
    }
  }

  if (value instanceof PeakIdentity) {

    PeakIdentity identity = (PeakIdentity) value;

    newLabel.setText(identity.getName());

    String toolTipText = identity.getDescription();

    newLabel.setToolTipText(toolTipText);

  }

  return newLabel;

}
 
Example 20
Source File: PeakShapeCellRenderer.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable,
 *      java.lang.Object, boolean, boolean, int, int)
 */
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
    boolean hasFocus, int row, int column) {

  JPanel newPanel = new JPanel();
  newPanel.setLayout(new OverlayLayout(newPanel));

  Color bgColor;

  if (isSelected)
    bgColor = table.getSelectionBackground();
  else
    bgColor = table.getBackground();

  newPanel.setBackground(bgColor);

  if (value instanceof Feature) {

    Feature peak = (Feature) value;
    double maxHeight = 0;

    PeakShapeNormalization norm =
        parameters.getParameter(PeakListTableParameters.peakShapeNormalization).getValue();
    if (norm == null)
      norm = PeakShapeNormalization.ROWMAX;
    switch (norm) {
      case GLOBALMAX:
        maxHeight = peakList.getDataPointMaxIntensity();
        break;
      case ROWMAX:
        int rowNumber = peakList.getPeakRowNum(peak);
        maxHeight = peakList.getRow(rowNumber).getDataPointMaxIntensity();
        break;
      default:
        maxHeight = peak.getRawDataPointsIntensityRange().upperEndpoint();
        break;
    }
    PeakXICComponent xic = new PeakXICComponent(peak, maxHeight);

    // newPanel.add(xic);

    // newPanel.setToolTipText(xic.getToolTipText());

  }

  if (value instanceof PeakListRow) {

    PeakListRow plRow = (PeakListRow) value;

    RawDataFile[] dataFiles = peakList.getRawDataFiles().toArray(RawDataFile[]::new);
    Feature[] peaks = new Feature[dataFiles.length];
    for (int i = 0; i < dataFiles.length; i++) {
      peaks[i] = plRow.getPeak(dataFiles[i]);
    }

    // CombinedXICComponent xic = new CombinedXICComponent(peaks, plRow.getID());

    // newPanel.add(xic);

    // newPanel.setToolTipText(xic.getToolTipText());

  }

  return newPanel;

}