Example usage for java.awt Component getFont

List of usage examples for java.awt Component getFont

Introduction

In this page you can find the example usage for java.awt Component getFont.

Prototype

@Transient
public Font getFont() 

Source Link

Document

Gets the font of this component.

Usage

From source file:com.raddle.tools.MergeMain.java

private void setCellRenderer(JList list) {
    list.setCellRenderer(new DefaultListCellRenderer() {

        private static final long serialVersionUID = 1L;

        @Override//  w w w. j  a  va2  s. com
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                boolean cellHasFocus) {
            Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            if (value != null) {
                PropertyLine line = (PropertyLine) value;
                boolean isInSelected = false;
                for (int selectedIndex : list.getSelectedIndices()) {
                    if (index == selectedIndex) {
                        isInSelected = true;
                    }
                }
                if (!isInSelected) {
                    if (CompareResult.extra == line.getCompareResult()) {
                        c.setBackground(new Color(0xFFC48E));
                    } else if (CompareResult.different == line.getCompareResult()) {
                        c.setBackground(new Color(0xBBBBFF));
                    }
                }
                if (line.getState() != null) {
                    if (LineState.added == line.getState()) {
                        c.setForeground(new Color(0xCC0033));
                    } else if (LineState.updated == line.getState()) {
                        c.setForeground(new Color(0x0066CC));
                    } else if (LineState.deleted == line.getState()) {
                        if (line.getOriginalValue() == null) {
                            c.setForeground(new Color(0xAAAAAA));
                        } else {
                            c.setForeground(new Color(0x666666));
                        }
                        Map<Attribute, Object> map = new HashMap<Attribute, Object>();
                        map.put(TextAttribute.FONT, c.getFont());
                        map.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON);
                        c.setFont(Font.getFont(map));
                    }
                }
            }
            return c;
        }

    });
}

From source file:edu.ku.brc.specify.tasks.subpane.wb.WorkbenchPaneSS.java

/**
 * Adjust all the column width for the data in the column, this may be handles with JDK 1.6 (6.)
 * @param tableArg the table that should have it's columns adjusted
 *///from  w  ww. j a  v a  2s .  c o m
private void initColumnSizes(final JTable tableArg, final JButton theSaveBtn) throws Exception {
    TableModel tblModel = tableArg.getModel();
    TableColumn column = null;
    Component comp = null;
    int headerWidth = 0;
    int cellWidth = 0;

    Element uploadDefs = null;
    if (WorkbenchTask.isCustomizedSchema()) {
        uploadDefs = XMLHelper.readFileToDOM4J(
                new File(UIRegistry.getAppDataDir() + File.separator + "specify_workbench_upload_def.xml"));
    } else {
        uploadDefs = XMLHelper.readDOMFromConfigDir("specify_workbench_upload_def.xml");
    }

    //UIRegistry.getInstance().hookUpUndoableEditListener(cellEditor);

    Vector<WorkbenchTemplateMappingItem> wbtmis = new Vector<WorkbenchTemplateMappingItem>();
    wbtmis.addAll(workbench.getWorkbenchTemplate().getWorkbenchTemplateMappingItems());
    Collections.sort(wbtmis);

    DBTableIdMgr databaseSchema = WorkbenchTask.getDatabaseSchema();

    columnMaxWidths = new Integer[tableArg.getColumnCount()];
    for (int i = 0; i < wbtmis.size() /*tableArg.getColumnCount()*/; i++) {
        TableCellRenderer headerRenderer = tableArg.getColumnModel().getColumn(i).getHeaderRenderer();
        WorkbenchTemplateMappingItem wbtmi = wbtmis.elementAt(i);

        // Now go retrieve the data length
        int fieldWidth = WorkbenchDataItem.getMaxWBCellLength();
        DBTableInfo ti = databaseSchema.getInfoById(wbtmi.getSrcTableId());
        if (ti != null) {
            DBFieldInfo fi = ti.getFieldByName(wbtmi.getFieldName());
            if (fi != null) {
                wbtmi.setFieldInfo(fi);
                //System.out.println(fi.getName()+"  "+fi.getLength()+"  "+fi.getType());
                if (RecordTypeCodeBuilder.getTypeCode(fi) == null && fi.getLength() > 0) {
                    fieldWidth = Math.min(fi.getLength(), WorkbenchDataItem.getMaxWBCellLength());
                }
            } else {
                log.error("Can't find field with name [" + wbtmi.getFieldName() + "]");
            }
        } else {
            log.error("Can't find table [" + wbtmi.getSrcTableId() + "]");
        }
        columnMaxWidths[i] = new Integer(fieldWidth);
        GridCellEditor cellEditor = getCellEditor(wbtmi, fieldWidth, theSaveBtn, uploadDefs);
        column = tableArg.getColumnModel().getColumn(i);

        comp = headerRenderer.getTableCellRendererComponent(null, column.getHeaderValue(), false, false, 0, 0);
        headerWidth = comp.getPreferredSize().width;

        comp = tableArg.getDefaultRenderer(tblModel.getColumnClass(i)).getTableCellRendererComponent(tableArg,
                tblModel.getValueAt(0, i), false, false, 0, i);

        cellWidth = comp.getPreferredSize().width;

        //comp.setBackground(Color.WHITE);

        int maxWidth = headerWidth + 10;
        TableModel m = tableArg.getModel();
        FontMetrics fm = comp.getFontMetrics(comp.getFont());
        for (int row = 0; row < tableArg.getModel().getRowCount(); row++) {
            String text = m.getValueAt(row, i).toString();
            maxWidth = Math.max(maxWidth, fm.stringWidth(text) + 10);
            //log.debug(i+" "+maxWidth);
        }

        //XXX: Before Swing 1.1 Beta 2, use setMinWidth instead.
        //log.debug(Math.max(maxWidth, cellWidth));
        //log.debug(Math.min(Math.max(maxWidth, cellWidth), 400));
        column.setPreferredWidth(Math.min(Math.max(maxWidth, cellWidth), 400));

        column.setCellEditor(cellEditor);
    }
    //tableArg.setCellEditor(cellEditor);
}

From source file:org.drugis.addis.gui.renderer.CategoryComboboxRenderer.java

public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
        boolean cellHasFocus) {

    // Pre-processing 
    boolean postprocess = false;
    if (value instanceof ChoiceNode) {
        postprocess = true;/*from  w ww  . j  a v  a 2s.co m*/
        String property = StringUtils.lowerCase(value.toString());
        if (d_alternate) {
            value = "Consider " + property;
        } else {
            value = "Consider " + property + " first";
        }
    }

    Component c = d_defaultRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
    //Post-processing 
    if (postprocess || value instanceof CategorySpecifiers
            || (value instanceof LeafNode && value.toString().equals(LeafNode.NAME_EXCLUDE))) {
        c.setFont(c.getFont().deriveFont(Font.BOLD));
    }
    return c;
}

From source file:org.ut.biolab.medsavant.client.view.component.ListViewTablePanel.java

public ListViewTablePanel(Object[][] data, String[] columnNames, Class[] columnClasses, int[] hiddenColumns,
        boolean allowSearch, boolean allowSort, boolean allowPages, boolean allowSelection) {

    this.hiddenColumns = hiddenColumns;
    table = new SortableTable() {
        @Override//from   w  w w . j a v  a2 s.com
        public Component prepareRenderer(TableCellRenderer renderer, int Index_row, int Index_col) {
            Component comp = super.prepareRenderer(renderer, Index_row, Index_col);
            //even index, selected or not selected

            if (isRowSelected(Index_row)) {
                comp.setBackground(ViewUtil.detailSelectedBackground);
            } else {
                if (Index_row % 2 == 0) {
                    comp.setBackground(evenRowColor);
                } else {
                    comp.setBackground(oddRowColor);
                }
            }
            comp.setForeground(ViewUtil.detailForeground);

            comp.setFont(comp.getFont().deriveFont(fontSize));

            return comp;
        }
    };

    table.setBorder(null);
    table.setSelectionForeground(Color.darkGray);
    table.setRowHeight(30);
    table.setClearSelectionOnTableDataChanges(true);
    table.setOptimized(true);
    table.setColumnAutoResizable(true);
    table.setAutoResort(false);
    //table.setDragEnabled(false);
    //table.setRowHeight(20);
    table.setSortable(allowSort);
    table.setSortingEnabled(allowSort);
    table.setFocusable(allowSelection);
    table.setCellSelectionEnabled(allowSelection);
    table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

    table.setAutoResizeMode(SortableTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);

    //table.setMinimumSize(new Dimension(500,999));
    //table.setPreferredSize(new Dimension(500,999));

    //column chooser
    TableHeaderPopupMenuInstaller installer = new TableHeaderPopupMenuInstaller(table);
    installer.addTableHeaderPopupMenuCustomizer(new AutoResizePopupMenuCustomizer());
    columnChooser = new ColumnChooser(table);
    installer.addTableHeaderPopupMenuCustomizer(columnChooser);

    AutoFilterTableHeader header = new AutoFilterTableHeader(table);
    header.setAutoFilterEnabled(true);
    header.setShowFilterIcon(true);
    header.setShowFilterName(true);
    table.setTableHeader(header);

    filterField = new QuickTableFilterField(model);
    filterField.setHintText("Type to search");

    setLayout(new BorderLayout(3, 3));
    fieldPanel = ViewUtil.getClearPanel();
    fieldPanel.setLayout(new GridBagLayout());
    setOpaque(false);

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.weightx = 1.0;
    //gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.fill = GridBagConstraints.BOTH;
    if (allowSearch) {
        fieldPanel.add(filterField, gbc);
    }
    if (columnNames.length > 1) {
        JButton chooseColumnButton = new JButton("Fields");
        chooseColumnButton.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseReleased(MouseEvent e) {
                columnChooser.showDialog();
            }
        });
        gbc.weightx = 0.0;
        gbc.fill = GridBagConstraints.NONE;
        fieldPanel.add(chooseColumnButton, gbc);
    }

    setTableModel(data, columnNames, columnClasses);

    if (allowSort) {
        add(fieldPanel, BorderLayout.NORTH);
    }

    JScrollPane jsp = new JScrollPane(table);
    jsp.setBorder(null);
    add(jsp, BorderLayout.CENTER);

    updateData(data);
    updateView();
}

From source file:org.yccheok.jstock.gui.IndicatorPanel.java

private ListCellRenderer getListCellRenderer(final IndicatorProjectManager projectManager) {
    return new DefaultListCellRenderer() {
        @Override// w  w w .  jav a2  s  .  c o  m
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                boolean cellHasFocus) {
            Component component = super.getListCellRendererComponent(list, value, index, isSelected,
                    cellHasFocus);
            if (component != null && value != null) {
                final OperatorIndicator operatorIndicator = projectManager
                        .getOperatorIndicator(value.toString());
                if (operatorIndicator != null
                        && operatorIndicator.getType() != projectManager.getPreferredOperatorIndicatorType()) {
                    final Font oldFont = component.getFont();
                    component.setFont(oldFont.deriveFont(oldFont.getStyle() | Font.ITALIC));
                }
            }
            return component;
        }
    };
}