Search in sources :

Example 96 with Color

use of java.awt.Color in project adempiere by adempiere.

the class VCellRenderer method getTableCellRendererComponent.

/**
	 *	Get TableCell RendererComponent.
	 *  @param table table
	 *  @param value value
	 *  @param isSelected selected
	 *  @param hasFocus focus
	 *  @param row row
	 *  @param col col
	 *  @return component
	 */
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) {
    //	log.finest(m_columnName 
    //		+ ": Value=" + (value == null ? "null" : value.toString()) 
    //		+ ", Row=" + row + ", Col=" + col);
    Component c = null;
    if (m_displayType == DisplayType.YesNo)
        c = m_check;
    else {
        //	returns JLabel
        c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col);
        //c.setFont(AdempierePLAF.getFont_Field());
        c.setFont(table.getFont());
    }
    //  Background & Foreground
    Color bg = AdempierePLAF.getFieldBackground_Normal();
    Color fg = AdempierePLAF.getTextColor_Normal();
    //  Inactive Background
    boolean ro = !table.isCellEditable(row, col);
    if (ro) {
        bg = AdempierePLAF.getFieldBackground_Inactive();
        if (isSelected && !hasFocus)
            bg = bg.darker();
    }
    //  Foreground
    int cCode = 0;
    //  Grid
    if (table instanceof org.compiere.grid.VTable)
        cCode = ((org.compiere.grid.VTable) table).getColorCode(row);
    else //  MiniGrid
    if (table instanceof org.compiere.minigrid.MiniTable)
        cCode = ((org.compiere.minigrid.MiniTable) table).getColorCode(row);
    //
    if (cCode == 0)
        //	Black
        ;
    else if (cCode < 0)
        //	Red
        fg = AdempierePLAF.getTextColor_Issue();
    else
        //	Blue
        fg = AdempierePLAF.getTextColor_OK();
    //	Highlighted row
    if (isSelected) {
        //	Windows is white on blue
        bg = table.getSelectionBackground();
        fg = table.getSelectionForeground();
        if (hasFocus)
            bg = org.adempiere.apps.graph.GraphUtil.brighter(bg, .9);
    }
    //  Set Color
    c.setBackground(bg);
    c.setForeground(fg);
    //
    //	log.fine( "r=" + row + " c=" + col, // + " - " + c.getClass().getName(),
    //		"sel=" + isSelected + ", focus=" + hasFocus + ", edit=" + table.isCellEditable(row, col));
    //	Log.trace(7, "BG=" + (bg.equals(Color.white) ? "white" : bg.toString()), "FG=" + (fg.equals(Color.black) ? "black" : fg.toString()));
    //  Format it
    setValue(value);
    return c;
}
Also used : Color(java.awt.Color) Component(java.awt.Component)

Example 97 with Color

use of java.awt.Color in project adempiere by adempiere.

the class LayoutEngine method layoutTable.

//	getColor
/**************************************************************************
	 * 	Layout Table.
	 *	Convert PrintData into TableElement
	 *  @param format format to use
	 *  @param printData data to use
	 *  @param xOffset X Axis - offset (start of table) i.e. indentation
	 *  @return TableElement
	 */
private PrintElement layoutTable(MPrintFormat format, PrintData printData, int xOffset) {
    log.info(format.getName() + " - " + printData.getName());
    MPrintTableFormat tf = format.getTableFormat();
    //	Initial Values
    HashMap<Point, Font> rowColFont = new HashMap<Point, Font>();
    MPrintFont printFont = MPrintFont.get(format.getAD_PrintFont_ID());
    rowColFont.put(new Point(TableElement.ALL, TableElement.ALL), printFont.getFont());
    tf.setStandard_Font(printFont.getFont());
    rowColFont.put(new Point(TableElement.HEADER_ROW, TableElement.ALL), tf.getHeader_Font());
    //
    HashMap<Point, Color> rowColColor = new HashMap<Point, Color>();
    MPrintColor printColor = MPrintColor.get(getCtx(), format.getAD_PrintColor_ID());
    rowColColor.put(new Point(TableElement.ALL, TableElement.ALL), printColor.getColor());
    rowColColor.put(new Point(TableElement.HEADER_ROW, TableElement.ALL), tf.getHeaderFG_Color());
    //
    HashMap<Point, Color> rowColBackground = new HashMap<Point, Color>();
    rowColBackground.put(new Point(TableElement.HEADER_ROW, TableElement.ALL), tf.getHeaderBG_Color());
    //	Sizes
    boolean multiLineHeader = tf.isMultiLineHeader();
    int pageNoStart = m_pageNo;
    int repeatedColumns = 1;
    Rectangle firstPage = new Rectangle(m_content);
    firstPage.x += xOffset;
    firstPage.width -= xOffset;
    int yOffset = (int) m_position[AREA_CONTENT].y - m_content.y;
    firstPage.y += yOffset;
    firstPage.height -= yOffset;
    Rectangle nextPages = new Rectangle(m_content);
    nextPages.x += xOffset;
    nextPages.width -= xOffset;
    //	Column count
    int columnCount = 0;
    for (int c = 0; c < format.getItemCount(); c++) {
        if (format.getItem(c).isPrinted())
            columnCount++;
    }
    //	System.out.println("Cols=" + cols);
    //	Header & Column Setup
    ValueNamePair[] columnHeader = new ValueNamePair[columnCount];
    int[] columnMaxWidth = new int[columnCount];
    int[] columnMaxHeight = new int[columnCount];
    boolean[] fixedWidth = new boolean[columnCount];
    boolean[] colSuppressRepeats = new boolean[columnCount];
    String[] columnJustification = new String[columnCount];
    HashMap<Integer, Integer> additionalLines = new HashMap<Integer, Integer>();
    int col = 0;
    for (int c = 0; c < format.getItemCount(); c++) {
        MPrintFormatItem item = format.getItem(c);
        if (item.isPrinted()) {
            if (item.isNextLine() && item.getBelowColumn() != 0) {
                additionalLines.put(new Integer(col), new Integer(item.getBelowColumn() - 1));
                if (!item.isSuppressNull()) {
                    //	display size will be set to 0 in TableElement
                    item.setIsSuppressNull(true);
                    item.saveEx();
                }
            }
            columnHeader[col] = new ValueNamePair(item.getColumnName(), item.getPrintName(format.getLanguage()));
            columnMaxWidth[col] = item.getMaxWidth();
            fixedWidth[col] = (columnMaxWidth[col] != 0 && item.isFixedWidth());
            colSuppressRepeats[col] = item.isSuppressRepeats();
            if (item.isSuppressNull()) {
                if (columnMaxWidth[col] == 0)
                    //	indication suppress if Null
                    columnMaxWidth[col] = -1;
                else
                    columnMaxWidth[col] *= -1;
            }
            columnMaxHeight[col] = item.getMaxHeight();
            if (item.isHeightOneLine())
                columnMaxHeight[col] = -1;
            columnJustification[col] = item.getFieldAlignmentType();
            if (columnJustification[col] == null || columnJustification[col].equals(MPrintFormatItem.FIELDALIGNMENTTYPE_Default))
                //	when generated sets correct alignment
                columnJustification[col] = MPrintFormatItem.FIELDALIGNMENTTYPE_LeadingLeft;
            //	Column Fonts
            if (item.getAD_PrintFont_ID() != 0 && item.getAD_PrintFont_ID() != format.getAD_PrintFont_ID()) {
                MPrintFont font = MPrintFont.get(item.getAD_PrintFont_ID());
                rowColFont.put(new Point(TableElement.ALL, col), font.getFont());
            }
            if (item.getAD_PrintColor_ID() != 0 && item.getAD_PrintColor_ID() != format.getAD_PrintColor_ID()) {
                MPrintColor color = MPrintColor.get(getCtx(), item.getAD_PrintColor_ID());
                rowColColor.put(new Point(TableElement.ALL, col), color.getColor());
            }
            //
            col++;
        }
    }
    //	The Data
    int rows = printData.getRowCount();
    //	System.out.println("Rows=" + rows);
    Object[][] data = new Object[rows][columnCount];
    KeyNamePair[] pk = new KeyNamePair[rows];
    String pkColumnName = null;
    ArrayList<Integer> functionRows = new ArrayList<Integer>();
    ArrayList<Integer> pageBreak = new ArrayList<Integer>();
    //	for all rows
    for (int row = 0; row < rows; row++) {
        //	System.out.println("row=" + row);
        printData.setRowIndex(row);
        if (printData.isFunctionRow()) {
            functionRows.add(new Integer(row));
            rowColFont.put(new Point(row, TableElement.ALL), tf.getFunct_Font());
            rowColColor.put(new Point(row, TableElement.ALL), tf.getFunctFG_Color());
            rowColBackground.put(new Point(row, TableElement.ALL), tf.getFunctBG_Color());
            if (printData.isPageBreak()) {
                pageBreak.add(new Integer(row));
                log.finer("PageBreak row=" + row);
            }
        } else //	Summary/Line Levels for Finanial Reports
        {
            int levelNo = printData.getLineLevelNo();
            if (levelNo != 0) {
                if (levelNo < 0)
                    levelNo = -levelNo;
                Font base = printFont.getFont();
                if (levelNo == 1)
                    rowColFont.put(new Point(row, TableElement.ALL), new Font(base.getName(), Font.ITALIC, base.getSize() - levelNo));
                else if (levelNo == 2)
                    rowColFont.put(new Point(row, TableElement.ALL), new Font(base.getName(), Font.PLAIN, base.getSize() - levelNo));
            }
        }
        //	for all columns
        col = 0;
        for (int c = 0; c < format.getItemCount(); c++) {
            MPrintFormatItem item = format.getItem(c);
            Object dataElement = null;
            if (//	Text Columns
            item.isPrinted()) {
                if (item.isTypeImage()) {
                    if (item.isImageField())
                        data[row][col] = createImageElement(item);
                    else if (item.isImageIsAttached())
                        data[row][col] = ImageElement.get(item.get_ID());
                    else
                        data[row][col] = ImageElement.get(item.getImageURL());
                    // Image layout - teo_sarca, [ 1673548 ]
                    if (data[row][col] != null)
                        ((ImageElement) data[row][col]).layout(item.getMaxWidth(), item.getMaxHeight(), false, item.getFieldAlignmentType());
                } else if (item.isBarcode()) {
                    Object obj = null;
                    if (// teo_sarca, [ 1673542 ]
                    item.getAD_Column_ID() > 0)
                        obj = printData.getNode(new Integer(item.getAD_Column_ID()));
                    if (obj == null)
                        ;
                    else if (obj instanceof PrintDataElement) {
                        PrintDataElement pde = (PrintDataElement) obj;
                        // Get the PrintDataElement string value - teo_sarca [ 1673505 ]
                        String value = null;
                        Object o = pde.getValue();
                        if (o == null)
                            value = "";
                        if (o instanceof KeyNamePair)
                            value = ((KeyNamePair) o).getID();
                        else
                            value = o.toString();
                        BarcodeElement element = new BarcodeElement(value, item);
                        if (element.isValid())
                            data[row][col] = element;
                    }
                    if (data[row][col] != null)
                        ((BarcodeElement) data[row][col]).layout(item.getMaxWidth(), item.getMaxHeight(), false, item.getFieldAlignmentType());
                } else if (item.isTypeText()) {
                    data[row][col] = item.getPrintName(format.getLanguage());
                } else if (item.isTypeField()) {
                    Object obj = null;
                    if (// teo_sarca, [ 1673542 ]
                    item.getAD_Column_ID() > 0)
                        obj = printData.getNode(new Integer(item.getAD_Column_ID()));
                    if (obj == null)
                        ;
                    else if (obj instanceof PrintDataElement) {
                        PrintDataElement pde = (PrintDataElement) obj;
                        if (pde.isID() || pde.isYesNo())
                            dataElement = pde.getValue();
                        else
                            dataElement = pde.getValueDisplay(format.getLanguage());
                    } else
                        log.log(Level.SEVERE, "Element not PrintDataElement " + obj.getClass());
                    //	System.out.println("  row=" + row + ",col=" + col + " - " + item.getAD_Column_ID() + " => " + dataElement);
                    data[row][col] = dataElement;
                } else if (item.isTypePrintFormat()) {
                    m_currPage.addElement(includeFormat(item, printData));
                } else // item.isTypeBox() or isTypePrintFormat()
                {
                    log.warning("Unsupported: " + (item.isTypeBox() ? "Box" : "PrintFormat") + " in Table: " + item);
                }
                col++;
            }
        //	printed
        }
        //	for all columns
        PrintDataElement pde = printData.getPKey();
        if (//	for FunctionRows
        pde != null) {
            pk[row] = (KeyNamePair) pde.getValue();
            if (pkColumnName == null)
                pkColumnName = pde.getColumnName();
        }
    //	else
    //		System.out.println("No PK " + printData);
    }
    //	for all rows
    //
    TableElement table = new TableElement(columnHeader, columnMaxWidth, columnMaxHeight, columnJustification, fixedWidth, functionRows, multiLineHeader, data, pk, pkColumnName, pageNoStart, firstPage, nextPages, repeatedColumns, additionalLines, rowColFont, rowColColor, rowColBackground, tf, pageBreak, colSuppressRepeats);
    table.layout(0, 0, false, MPrintFormatItem.FIELDALIGNMENTTYPE_LeadingLeft);
    if (m_tableElement == null)
        m_tableElement = table;
    return table;
}
Also used : HashMap(java.util.HashMap) Rectangle(java.awt.Rectangle) ArrayList(java.util.ArrayList) MPrintFont(org.compiere.print.MPrintFont) Font(java.awt.Font) ValueNamePair(org.compiere.util.ValueNamePair) Color(java.awt.Color) MPrintColor(org.compiere.print.MPrintColor) MPrintFont(org.compiere.print.MPrintFont) MPrintFormatItem(org.compiere.print.MPrintFormatItem) Point(java.awt.Point) Point(java.awt.Point) PrintDataElement(org.compiere.print.PrintDataElement) MPrintTableFormat(org.compiere.print.MPrintTableFormat) MPrintColor(org.compiere.print.MPrintColor) KeyNamePair(org.compiere.util.KeyNamePair)

Example 98 with Color

use of java.awt.Color in project adempiere by adempiere.

the class LayoutEngine method createFieldElement.

//	createStringElement
/**
	 * 	Create Field Element
	 * 	@param item Format Item
	 * 	@param maxWidth max width
	 * 	@param FieldAlignmentType alignment type (MPrintFormatItem.FIELD_ALIGN_*)
	 * 	@param isForm true if document
	 * 	@return Print Element or null if nothing to print
	 */
private PrintElement createFieldElement(MPrintFormatItem item, int maxWidth, String FieldAlignmentType, boolean isForm) {
    //	Get Data
    Object obj = m_data.getNode(new Integer(item.getAD_Column_ID()));
    if (obj == null)
        return null;
    else if (obj instanceof PrintDataElement)
        ;
    else {
        log.log(Level.SEVERE, "Element not PrintDataElement " + obj.getClass());
        return null;
    }
    //	Convert DataElement to String
    PrintDataElement data = (PrintDataElement) obj;
    if (data.isNull() && item.isSuppressNull())
        return null;
    String stringContent = data.getValueDisplay(m_format.getLanguage());
    if ((stringContent == null || stringContent.length() == 0) && item.isSuppressNull())
        return null;
    //	non-string
    Object content = stringContent;
    if (data.getValue() instanceof Boolean)
        content = data.getValue();
    //	Convert AmtInWords Content to alpha
    if (item.getColumnName().equals("AmtInWords")) {
        log.fine("AmtInWords: " + stringContent);
        stringContent = Msg.getAmtInWords(m_format.getLanguage(), stringContent);
        content = stringContent;
    }
    //	Label
    String label = item.getPrintName(m_format.getLanguage());
    String labelSuffix = item.getPrintNameSuffix(m_format.getLanguage());
    //	ID Type
    NamePair ID = null;
    if (data.isID()) {
        //	Record_ID/ColumnName
        Object value = data.getValue();
        if (value instanceof KeyNamePair)
            ID = new KeyNamePair(((KeyNamePair) value).getKey(), item.getColumnName());
        else if (value instanceof ValueNamePair)
            ID = new ValueNamePair(((ValueNamePair) value).getValue(), item.getColumnName());
    } else if (MPrintFormatItem.FIELDALIGNMENTTYPE_Default.equals(FieldAlignmentType)) {
        if (data.isNumeric())
            FieldAlignmentType = MPrintFormatItem.FIELDALIGNMENTTYPE_TrailingRight;
        else
            FieldAlignmentType = MPrintFormatItem.FIELDALIGNMENTTYPE_LeadingLeft;
    }
    //	Get Color/ Font
    //	default
    Color color = getColor();
    if (ID != null && !isForm)
        //	link color/underline handeled in PrintElement classes
        ;
    else if (item.getAD_PrintColor_ID() != 0 && m_printColor.get_ID() != item.getAD_PrintColor_ID()) {
        MPrintColor c = MPrintColor.get(getCtx(), item.getAD_PrintColor_ID());
        if (c.getColor() != null)
            color = c.getColor();
    }
    //	default
    Font font = m_printFont.getFont();
    if (item.getAD_PrintFont_ID() != 0 && m_printFont.get_ID() != item.getAD_PrintFont_ID()) {
        MPrintFont f = MPrintFont.get(item.getAD_PrintFont_ID());
        if (f.getFont() != null)
            font = f.getFont();
    }
    //	Create String, HTML or Location
    PrintElement e = null;
    if (data.getDisplayType() == DisplayType.Location) {
        e = new LocationElement(m_printCtx, ((KeyNamePair) ID).getKey(), font, color, item.isHeightOneLine(), label, labelSuffix, m_format.getLanguage().getAD_Language());
        e.layout(maxWidth, item.getMaxHeight(), item.isHeightOneLine(), FieldAlignmentType);
    } else {
        if (HTMLElement.isHTML(stringContent))
            e = new HTMLElement(stringContent);
        else
            e = new StringElement(content, font, color, isForm ? null : ID, label, labelSuffix);
        e.layout(maxWidth, item.getMaxHeight(), item.isHeightOneLine(), FieldAlignmentType);
    }
    return e;
}
Also used : Color(java.awt.Color) MPrintColor(org.compiere.print.MPrintColor) NamePair(org.compiere.util.NamePair) ValueNamePair(org.compiere.util.ValueNamePair) KeyNamePair(org.compiere.util.KeyNamePair) MPrintFont(org.compiere.print.MPrintFont) MPrintFont(org.compiere.print.MPrintFont) Font(java.awt.Font) PrintDataElement(org.compiere.print.PrintDataElement) MPrintColor(org.compiere.print.MPrintColor) KeyNamePair(org.compiere.util.KeyNamePair) ValueNamePair(org.compiere.util.ValueNamePair)

Example 99 with Color

use of java.awt.Color in project adempiere by adempiere.

the class AcctViewer method jbInit.

/**
	 *  Static Init.
	 *  <pre>
	 *  - mainPanel
	 *      - tabbedPane
	 *          - query
	 *          - result
	 *          - graphPanel
	 *  </pre>
	 *  @throws Exception
	 */
private void jbInit() throws Exception {
    ImageIcon ii = new ImageIcon(org.compiere.Adempiere.class.getResource("images/InfoAccount16.gif"));
    setIconImage(ii.getImage());
    //
    mainLayout.setHgap(5);
    mainLayout.setVgap(5);
    mainPanel.setLayout(mainLayout);
    selectionPanel.setLayout(selectionLayout);
    this.getContentPane().add(mainPanel, BorderLayout.CENTER);
    mainPanel.add(tabbedPane, BorderLayout.CENTER);
    //  Selection
    selectionBorder = new TitledBorder(BorderFactory.createEtchedBorder(Color.white, new Color(148, 145, 140)), Msg.getMsg(Env.getCtx(), "Selection"));
    selectionPanel.setBorder(selectionBorder);
    lacctSchema.setLabelFor(selAcctSchema);
    lacctSchema.setText(Msg.translate(Env.getCtx(), "C_AcctSchema_ID"));
    lpostingType.setLabelFor(selPostingType);
    lpostingType.setText(Msg.translate(Env.getCtx(), "PostingType"));
    selDocument.setText(Msg.getMsg(Env.getCtx(), "SelectDocument"));
    selDocument.addActionListener(this);
    lOrg.setLabelFor(selOrg);
    lOrg.setText(Msg.translate(Env.getCtx(), "AD_Org_ID"));
    lAcct.setLabelFor(selAcct);
    lAcct.setText(Msg.translate(Env.getCtx(), "Account_ID"));
    lDate.setLabelFor(selDateFrom);
    lDate.setText(Msg.translate(Env.getCtx(), "DateAcct"));
    lsel1.setLabelFor(sel1);
    lsel2.setLabelFor(sel2);
    lsel3.setLabelFor(sel3);
    lsel4.setLabelFor(sel4);
    lsel5.setLabelFor(sel5);
    lsel6.setLabelFor(sel6);
    lsel7.setLabelFor(sel7);
    lsel8.setLabelFor(sel8);
    //  Display
    displayBorder = new TitledBorder(BorderFactory.createEtchedBorder(Color.white, new Color(148, 145, 140)), Msg.getMsg(Env.getCtx(), "Display"));
    displayPanel.setBorder(displayBorder);
    displayPanel.setLayout(displayLayout);
    displayQty.setText(Msg.getMsg(Env.getCtx(), "DisplayQty"));
    displaySourceAmt.setText(Msg.getMsg(Env.getCtx(), "DisplaySourceInfo"));
    displayDocumentInfo.setText(Msg.getMsg(Env.getCtx(), "DisplayDocumentInfo"));
    lSort.setText(Msg.getMsg(Env.getCtx(), "SortBy"));
    lGroup.setText(Msg.getMsg(Env.getCtx(), "GroupBy"));
    //
    displayPanel.add(displaySourceAmt, new GridBagConstraints(0, 1, 2, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0));
    displayPanel.add(displayDocumentInfo, new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0));
    displayPanel.add(lSort, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0));
    displayPanel.add(sortBy1, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 0, 5), 0, 0));
    displayPanel.add(sortBy2, new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 0, 5), 0, 0));
    displayPanel.add(group1, new GridBagConstraints(1, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0));
    displayPanel.add(group2, new GridBagConstraints(1, 6, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0));
    displayPanel.add(lGroup, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0));
    displayPanel.add(displayQty, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
    displayPanel.add(sortBy3, new GridBagConstraints(0, 7, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 0, 5), 0, 0));
    displayPanel.add(group3, new GridBagConstraints(1, 7, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0));
    displayPanel.add(sortBy4, new GridBagConstraints(0, 8, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0));
    displayPanel.add(group4, new GridBagConstraints(1, 8, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0));
    //
    selectionPanel.add(lacctSchema, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
    selectionPanel.add(selAcctSchema, new GridBagConstraints(1, 0, 2, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
    selectionPanel.add(selDocument, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(10, 5, 10, 5), 0, 0));
    selectionPanel.add(selTable, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 5, 10, 5), 0, 0));
    selectionPanel.add(selRecord, new GridBagConstraints(2, 1, 2, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(10, 5, 10, 5), 0, 0));
    selectionPanel.add(lpostingType, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0));
    selectionPanel.add(selPostingType, new GridBagConstraints(1, 2, 2, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0));
    selectionPanel.add(lDate, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0));
    selectionPanel.add(selDateFrom, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 0, 5), 0, 0));
    selectionPanel.add(selDateTo, new GridBagConstraints(2, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 0, 5), 0, 0));
    selectionPanel.add(lOrg, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 0, 0, 5), 0, 0));
    selectionPanel.add(selOrg, new GridBagConstraints(1, 4, 2, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0));
    selectionPanel.add(lAcct, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0));
    selectionPanel.add(selAcct, new GridBagConstraints(1, 5, 2, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0));
    selectionPanel.add(lsel1, new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0));
    selectionPanel.add(lsel2, new GridBagConstraints(0, 7, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0));
    selectionPanel.add(lsel3, new GridBagConstraints(0, 8, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0));
    selectionPanel.add(sel1, new GridBagConstraints(1, 6, 2, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0));
    selectionPanel.add(sel2, new GridBagConstraints(1, 7, 2, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0));
    selectionPanel.add(sel3, new GridBagConstraints(1, 8, 2, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0));
    selectionPanel.add(lsel4, new GridBagConstraints(0, 9, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0));
    selectionPanel.add(sel4, new GridBagConstraints(1, 9, 2, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0));
    selectionPanel.add(lsel5, new GridBagConstraints(0, 10, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0));
    selectionPanel.add(sel5, new GridBagConstraints(1, 10, 2, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0));
    selectionPanel.add(lsel6, new GridBagConstraints(0, 11, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0));
    selectionPanel.add(sel6, new GridBagConstraints(1, 11, 2, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0));
    selectionPanel.add(lsel7, new GridBagConstraints(0, 12, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0));
    selectionPanel.add(sel7, new GridBagConstraints(1, 12, 2, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0));
    selectionPanel.add(lsel8, new GridBagConstraints(0, 13, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0));
    selectionPanel.add(sel8, new GridBagConstraints(1, 13, 2, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0));
    //
    queryLayout.setHgap(5);
    queryLayout.setVgap(5);
    query.setLayout(queryLayout);
    query.add(selectionPanel, BorderLayout.CENTER);
    query.add(displayPanel, BorderLayout.EAST);
    //
    tabbedPane.add(query, Msg.getMsg(Env.getCtx(), "ViewerQuery"));
    tabbedPane.add(result, Msg.getMsg(Env.getCtx(), "ViewerResult"));
    //		tabbedPane.add(graphPanel,   Msg.getMsg(Env.getCtx(), "ViewerGraph"));
    tabbedPane.addChangeListener(this);
    result.getViewport().add(table, null);
    //  South
    southLayout.setHgap(5);
    southLayout.setVgap(5);
    southPanel.setLayout(southLayout);
    statusLine.setForeground(Color.blue);
    statusLine.setBorder(BorderFactory.createLoweredBevelBorder());
    southPanel.add(statusLine, BorderLayout.CENTER);
    bRePost.setText(Msg.getMsg(Env.getCtx(), "RePost"));
    bRePost.setToolTipText(Msg.getMsg(Env.getCtx(), "RePostInfo"));
    bRePost.addActionListener(this);
    bRePost.setVisible(false);
    forcePost.setText(Msg.getMsg(Env.getCtx(), "Force"));
    forcePost.setToolTipText(Msg.getMsg(Env.getCtx(), "ForceInfo"));
    forcePost.setVisible(false);
    CPanel leftSide = new CPanel(new FlowLayout(FlowLayout.LEADING, 0, 0));
    leftSide.add(bRePost);
    leftSide.add(forcePost);
    southPanel.add(leftSide, BorderLayout.WEST);
    //
    bQuery.setIcon(Env.getImageIcon("Refresh16.gif"));
    bQuery.setToolTipText(Msg.getMsg(Env.getCtx(), "Refresh"));
    bQuery.addActionListener(this);
    bPrint.setIcon(Env.getImageIcon("Print16.gif"));
    bPrint.setToolTipText(Msg.getMsg(Env.getCtx(), "Print"));
    bPrint.addActionListener(this);
    bExport.setIcon(Env.getImageIcon("Export16.gif"));
    bExport.setToolTipText(Msg.getMsg(Env.getCtx(), "Export"));
    bExport.setVisible(tabbedPane.getSelectedIndex() == 1);
    bExport.addActionListener(this);
    CPanel rightSide = new CPanel(new FlowLayout(FlowLayout.TRAILING, 0, 0));
    rightSide.add(bExport);
    rightSide.add(bPrint);
    rightSide.add(bQuery);
    southPanel.add(rightSide, BorderLayout.EAST);
    this.getContentPane().add(southPanel, BorderLayout.SOUTH);
//
}
Also used : ImageIcon(javax.swing.ImageIcon) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) FlowLayout(java.awt.FlowLayout) Color(java.awt.Color) CPanel(org.compiere.swing.CPanel) TitledBorder(javax.swing.border.TitledBorder)

Example 100 with Color

use of java.awt.Color in project adempiere by adempiere.

the class ColorBlind method getDichromatColor.

//  convertToDichromatColor
/**
	 *  Convert "normal" color to Dichromat Color
	 *  @param color Java Color object containing values for RGB
	 *  @param colorType  PROTANOPIA = 1, DEUTERANOPIA = 2 or TRITANOPIA = 3 as declared above
	 *  @return Dichromat Color
	 */
public static Color getDichromatColor(Color color, int colorType) {
    //  check type & return if not valid
    int type = 0;
    if (colorType > 0 && colorType < 4)
        type = colorType;
    //  No conversion or no color
    if (type == 0 || color == null)
        return color;
    //  correct to zero based
    type--;
    //  Return white & black - not converted
    if (color.equals(Color.black) || color.equals(Color.white))
        return color;
    double red = color.getRed();
    double green = color.getGreen();
    double blue = color.getBlue();
    //  System.out.println("Red: " + red + " Green: " + green + " Blue: " + blue);
    double X = RGBtoXYZMatrix[0][0] * Math.pow(red / 255.0, gamma) + RGBtoXYZMatrix[0][1] * Math.pow(green / 255.0, gamma) + RGBtoXYZMatrix[0][2] * Math.pow(blue / 255.0, gamma);
    double Y = RGBtoXYZMatrix[1][0] * Math.pow(red / 255.0, gamma) + RGBtoXYZMatrix[1][1] * Math.pow(green / 255.0, gamma) + RGBtoXYZMatrix[1][2] * Math.pow(blue / 255.0, gamma);
    double Z = RGBtoXYZMatrix[2][0] * Math.pow(red / 255.0, gamma) + RGBtoXYZMatrix[2][1] * Math.pow(green / 255.0, gamma) + RGBtoXYZMatrix[2][2] * Math.pow(blue / 255.0, gamma);
    //  System.out.println("X: " + X + " Y: " + Y + " Z: " + Z);
    double x = 0.0;
    double y = 0.0;
    if ((X + Y + Z) != 0.0) {
        x = X / (X + Y + Z);
        y = Y / (X + Y + Z);
    }
    //  System.out.println("x: " + x + " y: " + y + " Y: " + Y);
    double Yn = Y;
    double Xn = (whitePoint[0] * Yn) / whitePoint[1];
    double Zn = (whitePoint[2] * Yn) / whitePoint[1];
    double xc = confusionPoints[type][0];
    double yc = confusionPoints[type][1];
    double x1 = colorAxes[type][0][0];
    double y1 = colorAxes[type][0][1];
    double x2 = colorAxes[type][1][0];
    double y2 = colorAxes[type][1][1];
    double ap = (y2 - y1) / (x2 - x1);
    double bp = y1 - (x1 * ap);
    //  System.out.println("ap: " + ap + " bp: " + bp);
    double a;
    if (x < xc)
        a = (yc - y) / (xc - x);
    else
        a = (y - yc) / (x - xc);
    double b = y - (x * a);
    //  System.out.println("a: " + a + " b: " + b);
    x = (bp - b) / (a - ap);
    y = a * x + b;
    //  System.out.println("x: " + x + " y: " + y);
    X = 0.0;
    Z = 0.0;
    if (y != 0) {
        X = x * (Y / y);
        Z = (1 - x - y) * (Y / y);
    }
    //  System.out.println("X: " + X + " Y: " + Y + " Z: " + Z);
    red = XYZtoRGBMatrix[0][0] * X + XYZtoRGBMatrix[0][1] * Y + XYZtoRGBMatrix[0][2] * Z;
    green = XYZtoRGBMatrix[1][0] * X + XYZtoRGBMatrix[1][1] * Y + XYZtoRGBMatrix[1][2] * Z;
    blue = XYZtoRGBMatrix[2][0] * X + XYZtoRGBMatrix[2][1] * Y + XYZtoRGBMatrix[2][2] * Z;
    //  System.out.println("Red: " + red + " Green: " + green + " Blue: " + blue);
    double reddiff = XYZtoRGBMatrix[0][0] * (Xn - X) + XYZtoRGBMatrix[0][1] * (Yn - Y) + XYZtoRGBMatrix[0][2] * (Zn - Z);
    double greendiff = XYZtoRGBMatrix[1][0] * (Xn - X) + XYZtoRGBMatrix[1][1] * (Yn - Y) + XYZtoRGBMatrix[1][2] * (Zn - Z);
    double bluediff = XYZtoRGBMatrix[2][0] * (Xn - X) + XYZtoRGBMatrix[2][1] * (Yn - Y) + XYZtoRGBMatrix[2][2] * (Zn - Z);
    double cr = ((red < 0.0 ? 0.0 : 1.0) - red) / reddiff;
    double cg = ((green < 0.0 ? 0.0 : 1.0) - green) / greendiff;
    double cb = ((blue < 0.0 ? 0.0 : 1.0) - blue) / bluediff;
    //  System.out.println("cr: " + cr + " cg: " + cg + " cb: " + cb);
    double c1 = (cr < 0 || cr > 1) ? 0 : cr;
    double c2 = (cg < 0 || cg > 1) ? 0 : cg;
    double c3 = (cb < 0 || cb > 1) ? 0 : cb;
    double c = Math.max(c1, Math.max(c2, c3));
    //  System.out.println("c: " + c);
    red = red + c * reddiff;
    green = green + c * greendiff;
    blue = blue + c * bluediff;
    //  System.out.println("Red: " + red + " Green: " + green + " Blue: " + blue);
    red = Math.pow(red, 1.0 / gamma);
    green = Math.pow(green, 1.0 / gamma);
    blue = Math.pow(blue, 1.0 / gamma);
    //  System.out.println("Red: " + red + " Green: " + green + " Blue: " + blue);
    //  System.out.println("Red: " + red * 255.0 + " Green: " + green * 255.0 + " Blue: " + blue * 255.0);
    Color retValue = new Color((float) red, (float) green, (float) blue);
    log.fine("Color " + color.getRed() + "-" + color.getGreen() + "-" + color.getBlue() + " -> " + retValue.getRed() + "-" + retValue.getGreen() + "-" + retValue.getBlue() + " <- " + COLORBLIND_TYPE[colorType]);
    return retValue;
}
Also used : Color(java.awt.Color)

Aggregations

Color (java.awt.Color)2973 Graphics2D (java.awt.Graphics2D)396 Font (java.awt.Font)250 BufferedImage (java.awt.image.BufferedImage)236 Dimension (java.awt.Dimension)193 JPanel (javax.swing.JPanel)193 Point (java.awt.Point)188 BasicStroke (java.awt.BasicStroke)177 ArrayList (java.util.ArrayList)173 Test (org.junit.Test)156 JLabel (javax.swing.JLabel)148 Paint (java.awt.Paint)140 Rectangle (java.awt.Rectangle)109 GradientPaint (java.awt.GradientPaint)108 Insets (java.awt.Insets)103 GridBagConstraints (java.awt.GridBagConstraints)96 IOException (java.io.IOException)96 Stroke (java.awt.Stroke)94 JScrollPane (javax.swing.JScrollPane)93 File (java.io.File)89