javax.swing.table.JTableHeader#isPaintingForPrint ( )源码实例Demo

下面列出了javax.swing.table.JTableHeader#isPaintingForPrint ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: dsworkbench   文件: DefaultTableHeaderRenderer.java
@Override
public Component getTableCellRendererComponent(JTable table,
        Object value, boolean isSelected, boolean hasFocus,
        int row, int column) {
    Icon sortIcon = null;
   // setBackground(Constants.DS_BACK);
    boolean isPaintingForPrint = false;

    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();
            }

            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);
            }
            java.util.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;
                }
            }
        }
    }

    setText(value == null ? "" : value.toString());
    setIcon(sortIcon);

    Border border = null;
    if (hasFocus) {
        border = UIManager.getBorder("TableHeader.focusCellBorder");
    }
    if (border == null) {
        border = UIManager.getBorder("TableHeader.cellBorder");
    }
    setBorder(border);

    return this;
}
 
源代码2 项目: dsworkbench   文件: SupportTableHeaderRenderer.java
@Override
public Component getTableCellRendererComponent(JTable table,
        Object value, boolean isSelected, boolean hasFocus,
        int row, int column) {
    Icon sortIcon = null;
    boolean isPaintingForPrint = false;

    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);
            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);
            }
            java.util.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;
                }
            }
        }
    }

    SupportTableModel model = (SupportTableModel) table.getModel();

    ImageIcon icon = model.getColumnIcon((String) value);
    BufferedImage i = ImageUtils.createCompatibleBufferedImage(18, 18, BufferedImage.BITMASK);
    Graphics2D g2d = i.createGraphics();
    // setIcon(sortIcon);
    if (icon != null) {
        icon.paintIcon(this, g2d, 0, 0);
        setText("");
        if (sortIcon != null) {
            g2d.setColor(getBackground());
            g2d.fillRect(18 - sortIcon.getIconWidth() - 2, 18 - sortIcon.getIconHeight() - 2, sortIcon.getIconWidth() + 2, sortIcon.getIconHeight() + 2);
            sortIcon.paintIcon(this, g2d, 18 - sortIcon.getIconWidth() - 1, 18 - sortIcon.getIconHeight() - 1);
        }
        setIcon(new ImageIcon(i));
    } else {
        setIcon(sortIcon);
        setText(value == null ? "" : value.toString());
    }


    Border border = null;
    if (hasFocus) {
        border = UIManager.getBorder("TableHeader.focusCellBorder");
    }
    if (border == null) {
        border = UIManager.getBorder("TableHeader.cellBorder");
    }
    setBorder(border);

    return this;
}
 
源代码3 项目: dsworkbench   文件: TroopTableHeaderRenderer.java
@Override
public Component getTableCellRendererComponent(JTable table,
        Object value, boolean isSelected, boolean hasFocus,
        int row, int column) {
    Icon sortIcon = null;
    boolean isPaintingForPrint = false;

    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);
            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);
            }
            java.util.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;
                }
            }
        }
    }

    TroopsTableModel model = (TroopsTableModel) table.getModel();

    ImageIcon icon = model.getColumnIcon((String) value);
    BufferedImage i = ImageUtils.createCompatibleBufferedImage(18, 18, BufferedImage.BITMASK);
    Graphics2D g2d = i.createGraphics();
    // setIcon(sortIcon);
    if (icon != null) {
        icon.paintIcon(this, g2d, 0, 0);
        setText("");
        if (sortIcon != null) {
            g2d.setColor(getBackground());
            g2d.fillRect(18 - sortIcon.getIconWidth() - 2, 18 - sortIcon.getIconHeight() - 2, sortIcon.getIconWidth() + 2, sortIcon.getIconHeight() + 2);
            sortIcon.paintIcon(this, g2d, 18 - sortIcon.getIconWidth() - 1, 18 - sortIcon.getIconHeight() - 1);
        }
        setIcon(new ImageIcon(i));
    } else {
        setIcon(sortIcon);
        setText(value == null ? "" : value.toString());
    }


    Border border = null;
    if (hasFocus) {
        border = UIManager.getBorder("TableHeader.focusCellBorder");
    }
    if (border == null) {
        border = UIManager.getBorder("TableHeader.cellBorder");
    }
    setBorder(border);

    return this;
}
 
源代码4 项目: seaglass   文件: SeaGlassTableHeaderUI.java
/**
 * @see javax.swing.table.DefaultTableCellRenderer#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) {
    Icon sortIcon = null;

    boolean isPaintingForPrint = false;

    if (table != null) {
        JTableHeader header = table.getTableHeader();

        if (header != null) {
            Color fgColor = null;
            Color bgColor = null;

            if (hasFocus) {
                fgColor = DefaultLookup.getColor(this, ui, "TableHeader.focusCellForeground");
                bgColor = DefaultLookup.getColor(this, ui, "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) {
            SortOrder sortOrder = getColumnSortOrder(table, column);

            if (sortOrder != null) {
                switch (sortOrder) {

                case ASCENDING:
                    sortIcon = DefaultLookup.getIcon(this, ui, "Table.ascendingSortIcon");
                    break;

                case DESCENDING:
                    sortIcon = DefaultLookup.getIcon(this, ui, "Table.descendingSortIcon");
                    break;

                case UNSORTED:
                    sortIcon = DefaultLookup.getIcon(this, ui, "Table.naturalSortIcon");
                    break;
                }
            }
        }
    }

    if (value instanceof Icon) {
        setText("");
        setIcon((Icon) value);
    } else if (value instanceof JLabel) {
        JLabel label = (JLabel) value;

        setText(label.getText());
        setIcon(label.getIcon());
        setHorizontalAlignment(label.getHorizontalAlignment());
        setHorizontalTextPosition(label.getHorizontalTextPosition());
        setVerticalAlignment(label.getVerticalAlignment());
        setVerticalTextPosition(label.getVerticalTextPosition());
        setToolTipText(label.getToolTipText());
        
    } else {
        setText(value == null ? "" : value.toString());
        setIcon(null);
    }

    sortArrow = sortIcon;

    Border border = null;

    if (hasFocus) {
        border = DefaultLookup.getBorder(this, ui, "TableHeader.focusCellBorder");
    }

    if (border == null) {
        border = DefaultLookup.getBorder(this, ui, "TableHeader.cellBorder");
    }

    setBorder(border);

    return this;
}
 
源代码5 项目: weblaf   文件: WebTableHeaderCellRenderer.java
@Override
public Component getTableCellRendererComponent ( final JTable table, final Object value, final boolean isSelected,
                                                 final boolean hasFocus, final int row, final int column )
{
    // Whether we are printing the result or not
    boolean isPaintingForPrint = false;

    // Updating custom style identifier
    if ( table != null )
    {
        setStyleId ( StyleId.tableHeaderCellRenderer.at ( table.getTableHeader () ) );
    }

    // Title icon
    Icon sortIcon = null;
    if ( table != null )
    {
        final 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 );
            }
            final 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 () );

    return this;
}