Example usage for java.awt Color getBlue

List of usage examples for java.awt Color getBlue

Introduction

In this page you can find the example usage for java.awt Color getBlue.

Prototype

public int getBlue() 

Source Link

Document

Returns the blue component in the range 0-255 in the default sRGB space.

Usage

From source file:org.nuclos.client.ui.collect.component.AbstractCollectableComponent.java

protected final static void setBackground(Component c, NuclosScript ns, final Collectable clct,
        EntityMetaDataVO meta, boolean isEnabled) {
    try {// w  ww  .j a v  a 2  s  .c o m
        String rgb = Integer.toHexString(c.getBackground().getRGB());
        rgb = rgb.substring(2, rgb.length());
        Object o = ScriptEvaluator.getInstance().eval(ns, new CollectableScriptContext(clct), "#" + rgb);

        if (o instanceof String) {
            Color color = Color.decode((String) o);
            if (isEnabled) {
                c.setBackground(color);
            } else {
                c.setBackground(new Color(Math.max(0, color.getRed() - (color.getRed() * 15 / 100)),
                        Math.max(0, color.getGreen() - (color.getGreen() * 15 / 100)),
                        Math.max(0, color.getBlue() - (color.getBlue() * 15 / 100))));
            }
        }
    } catch (Exception ex) {
        LOG.warn(ex);
    }
}

From source file:util.program.ProgramTextCreator.java

/**
 *
 * @param prog/*from   w  w w. j a va 2s  .  c  o  m*/
 *          The Program to show
 * @param doc
 *          The HTMLDocument.
 * @param fieldArr
 *          The object array with the field types.
 * @param tFont
 *          The title Font.
 * @param bFont
 *          The body Font.
 * @param settings
 *          Settings of the ProgramPanel
 * @param showHelpLinks
 *          Show the Help-Links (Quality of Data, ShowView)
 * @param zoom
 *          The zoom value for the picture.
 * @param showPluginIcons
 *          If the plugin icons should be shown.
 * @return The HTML String.
 * @since 3.0
 */
public static String createInfoText(Program prog, ExtendedHTMLDocument doc, Object[] fieldArr, Font tFont,
        Font bFont, ProgramPanelSettings settings, boolean showHelpLinks, int zoom, boolean showPluginIcons,
        boolean showPersonLinks) {
    String debugTables = "0"; //set to "1" for debugging, to "0" for no debugging
    try {
        // NOTE: All field types are included until type 25 (REPETITION_ON_TYPE)
        StringBuilder buffer = new StringBuilder(1024);

        String titleFont, titleSize, bodyFont;

        int bodyStyle;
        int titleStyle;
        if (tFont == null && bFont != null) {
            titleFont = bodyFont = bFont.getFamily();
            titleSize = mBodyFontSize = String.valueOf(bFont.getSize());
            titleStyle = bodyStyle = bFont.getStyle();
        } else if (tFont != null && bFont != null) {
            titleFont = tFont.getFamily();
            bodyFont = bFont.getFamily();
            titleSize = String.valueOf(tFont.getSize());
            mBodyFontSize = String.valueOf(bFont.getSize());
            titleStyle = tFont.getStyle();
            bodyStyle = bFont.getStyle();
        } else {
            return null;
        }

        if (fieldArr == null) {
            return null;
        }

        buffer.append("<html>");
        buffer.append("<table width=\"100%\" border=\"" + debugTables + "\" style=\"font-family:");

        buffer.append(bodyFont);

        buffer.append(";").append(getCssStyle(bodyStyle)).append("\"><tr>");
        buffer.append("<td width=\"60\">");
        buffer.append("<p \"align=center\">");

        JLabel channelLogo = new JLabel(prog.getChannel().getIcon());
        channelLogo.setToolTipText(prog.getChannel().getName());
        buffer.append(doc.createCompTag(channelLogo));

        buffer.append(
                "</p></td><td><table width=\"100%\" border=\"" + debugTables + "\" cellpadding=\"0\"><tr><td>");
        buffer.append("<div style=\"color:#ff0000; font-size:");

        buffer.append(mBodyFontSize);

        buffer.append(";\"><b>");

        Date currentDate = Date.getCurrentDate();
        Date programDate = prog.getDate();
        if (programDate.equals(currentDate.addDays(-1))) {
            buffer.append(Localizer.getLocalization(Localizer.I18N_YESTERDAY));
            buffer.append("  ");
        } else if (programDate.equals(currentDate)) {
            buffer.append(Localizer.getLocalization(Localizer.I18N_TODAY));
            buffer.append("  ");
        } else if (programDate.equals(currentDate.addDays(1))) {
            buffer.append(Localizer.getLocalization(Localizer.I18N_TOMORROW));
            buffer.append("  ");
        }
        buffer.append(prog.getDateString());

        buffer.append("  ");
        buffer.append(prog.getTimeString());
        if (prog.getLength() > 0) {
            buffer.append('-');
            buffer.append(prog.getEndTimeString());
        }
        buffer.append("  ");
        buffer.append(prog.getChannel());

        buffer.append("</b></div><div style=\"color:#003366; font-size:");

        buffer.append(titleSize);

        buffer.append("; line-height:2.5em; font-family:");
        buffer.append(titleFont).append(";").append(getCssStyle(titleStyle));
        buffer.append("\">");
        buffer.append(prog.getTitle());
        buffer.append("</div>");

        String episode = CompoundedProgramFieldType.EPISODE_COMPOSITION.getFormattedValueForProgram(prog);

        if (episode != null && episode.trim().length() > 0) {
            buffer.append("<div style=\"color:#808080; font-size:");

            buffer.append(mBodyFontSize);

            buffer.append("\">");
            buffer.append(episode);
            buffer.append("</div>");
        }

        buffer.append("</td><td align=\"right\" valign=\"top\"><table border=\"" + debugTables + "\"><tr><td>");
        JButton btn = new JButton(TVBrowserIcons.left(TVBrowserIcons.SIZE_SMALL));
        buffer.append(doc.createCompTag(btn));
        btn.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                ProgramInfo.getInstance().historyBack();
            }
        });
        btn.setEnabled(ProgramInfo.getInstance().canNavigateBack());
        btn.setToolTipText(ProgramInfo.getInstance().navigationBackwardText());

        buffer.append("</td><td>");
        btn = new JButton(TVBrowserIcons.right(TVBrowserIcons.SIZE_SMALL));
        buffer.append(doc.createCompTag(btn));
        btn.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                ProgramInfo.getInstance().historyForward();
            }
        });
        btn.setEnabled(ProgramInfo.getInstance().canNavigateForward());
        btn.setToolTipText(ProgramInfo.getInstance().navigationForwardText());

        buffer.append("</td></tr></table></td></tr></table></td></tr>");

        boolean show = false;

        if (settings.isShowingPictureForPlugins()) {
            String[] pluginIds = settings.getPluginIds();
            Marker[] markers = prog.getMarkerArr();

            if (markers != null && pluginIds != null) {
                for (Marker marker : markers) {
                    for (String pluginId : pluginIds) {
                        if (marker.getId().compareTo(pluginId) == 0) {
                            show = true;
                            break;
                        }
                    }
                }
            }
        }

        Color foreground = Color.black;//Settings.propProgramPanelForegroundColor.getColor();

        if (settings.isShowingPictureEver()
                || (settings.isShowingPictureInTimeRange()
                        && !ProgramUtilities.isNotInTimeRange(settings.getPictureTimeRangeStart(),
                                settings.getPictureTimeRangeEnd(), prog))
                || show
                || (settings.isShowingPictureForDuration() && settings.getDuration() <= prog.getLength())) {
            byte[] image = prog.getBinaryField(ProgramFieldType.PICTURE_TYPE);
            if (image != null) {
                String line = "<tr><td></td><td valign=\"top\" style=\"color:rgb(" + foreground.getRed() + ","
                        + foreground.getGreen() + "," + foreground.getBlue() + "); font-size:0\">";
                buffer.append(line);
                try {
                    ImageIcon imageIcon = new ImageIcon(image);

                    if (zoom != 100) {
                        imageIcon = (ImageIcon) UiUtilities.scaleIcon(imageIcon,
                                imageIcon.getIconWidth() * zoom / 100);
                    }

                    StringBuilder value = new StringBuilder();

                    String textField = prog.getTextField(ProgramFieldType.PICTURE_COPYRIGHT_TYPE);
                    if (textField != null) {
                        value.append(textField);
                    }

                    if (settings.isShowingPictureDescription()) {
                        textField = prog.getTextField(ProgramFieldType.PICTURE_DESCRIPTION_TYPE);
                        if (textField != null) {
                            value.append("<br>").append(textField);
                        }
                    }

                    buffer.append(doc.createCompTag(new JLabel(imageIcon)));
                    buffer.append("<div style=\"font-size:");

                    buffer.append(mBodyFontSize);

                    buffer.append("\">");
                    buffer.append(value);
                    buffer.append("</div>");
                    buffer.append("</td></tr>");
                } catch (Exception e) {
                    // Picture was wrong;
                    buffer.delete(buffer.length() - line.length(), buffer.length());
                }
            }
        }

        Marker[] pluginArr = prog.getMarkerArr();
        if (showPluginIcons && (pluginArr != null) && (pluginArr.length != 0)) {
            addSeparator(doc, buffer);

            buffer.append("<tr><td valign=\"top\" style=\"color:#808080; font-size:");

            buffer.append(mBodyFontSize);

            buffer.append("\"><b>");
            buffer.append(mLocalizer.msg("markedBy", "Marked by"));
            buffer.append("</b></td><td valign=\"middle\" style=\"font-size:4\">");
            openPara(buffer, "info");

            // Workaround: Without the &nbsp; the component are not put in one line.
            buffer.append("&nbsp;");
            for (int markerCount = pluginArr.length - 1; markerCount >= 0; markerCount--) {
                Icon[] icons = pluginArr[markerCount].getMarkIcons(prog);

                if (icons != null) {
                    for (int i = icons.length - 1; i >= 0; i--) {
                        JLabel iconLabel = new JLabel(icons[i]);
                        PluginAccess plugin = Plugin.getPluginManager()
                                .getActivatedPluginForId(pluginArr[markerCount].getId());
                        if (plugin != null) {
                            iconLabel.setToolTipText(plugin.getInfo().getName());
                        } else {
                            InternalPluginProxyIf internalPlugin = InternalPluginProxyList.getInstance()
                                    .getProxyForId(pluginArr[markerCount].getId());
                            if (internalPlugin != null) {
                                iconLabel.setToolTipText(internalPlugin.getName());
                                if (internalPlugin.equals(FavoritesPluginProxy.getInstance())) {
                                    // if this is a favorite, add the names of the favorite
                                    String favTitles = "";
                                    for (Favorite favorite : FavoriteTreeModel.getInstance()
                                            .getFavoritesContainingProgram(prog)) {
                                        if (favTitles.length() > 0) {
                                            favTitles = favTitles + ", ";
                                        }
                                        favTitles = favTitles + favorite.getName();
                                    }
                                    if (favTitles.length() > 0) {
                                        iconLabel.setToolTipText(
                                                iconLabel.getToolTipText() + " (" + favTitles + ")");
                                    }
                                }
                            } else {
                                iconLabel.setToolTipText(pluginArr[markerCount].toString());
                            }
                        }

                        buffer.append(doc.createCompTag(iconLabel));
                        buffer.append("&nbsp;&nbsp;");
                    }
                }
            }
            closePara(buffer);
            buffer.append("</td></tr>");
        }

        PluginAccess[] plugins = Plugin.getPluginManager().getActivatedPlugins();
        ArrayList<JLabel> iconLabels = new ArrayList<JLabel>();
        for (PluginAccess plugin : plugins) {
            Icon[] icons = plugin.getProgramTableIcons(prog);

            if (icons != null) {
                for (Icon icon : icons) {
                    JLabel iconLabel = new JLabel(icon);
                    iconLabel.setToolTipText(plugin.getInfo().getName());
                    iconLabels.add(iconLabel);
                }
            }
        }

        if (showPluginIcons && iconLabels.size() > 0) {
            addSeparator(doc, buffer);

            buffer.append("<tr><td valign=\"middle\" style=\"color:#808080; font-size:");

            buffer.append(mBodyFontSize);

            buffer.append("\"><b>");
            buffer.append("Plugin-Icons");
            buffer.append("</b></td><td valign=\"top\" style=\"font-size:4\">");

            openPara(buffer, "info");
            // Workaround: Without the &nbsp; the component are not put in one line.
            buffer.append("&nbsp;");

            for (JLabel iconLabel : iconLabels) {
                buffer.append(doc.createCompTag(iconLabel));
                buffer.append("&nbsp;&nbsp;");
            }

            closePara(buffer);
            buffer.append("</td></tr>");
        }

        addSeparator(doc, buffer);

        for (Object id : fieldArr) {
            ProgramFieldType type = null;

            if (id instanceof String) {
                if (((String) id).matches("\\d+")) {
                    try {
                        type = ProgramFieldType.getTypeForId(Integer.parseInt((String) id, 10));
                    } catch (Exception e) {
                        // Empty Catch
                    }
                }

                if (type == null) {
                    int length = prog.getLength();
                    if (length > 0 && ((String) id).trim().length() > 0) {

                        buffer.append("<tr><td valign=\"top\" style=\"color:gray; font-size:");

                        buffer.append(mBodyFontSize);

                        buffer.append("\"><b>");
                        buffer.append(mLocalizer.msg("duration", "Program duration/<br>-end"));
                        buffer.append("</b></td><td style=\"color:rgb(" + foreground.getRed() + ","
                                + foreground.getGreen() + "," + foreground.getBlue() + "); font-size:");

                        buffer.append(mBodyFontSize);

                        buffer.append("\">");

                        openPara(buffer, "time");

                        String msg = mLocalizer.msg("minutes", "{0} min", length);
                        buffer.append(msg).append(" (");
                        buffer.append(mLocalizer.msg("until", "until {0}", prog.getEndTimeString()));

                        int netLength = prog.getIntField(ProgramFieldType.NET_PLAYING_TIME_TYPE);
                        if (netLength != -1) {
                            msg = mLocalizer.msg("netMinuted", "{0} min net", netLength);
                            buffer.append(" - ").append(msg);
                        }
                        buffer.append(')');

                        closePara(buffer);

                        buffer.append("</td></tr>");
                        addSeparator(doc, buffer);
                    }
                }
            } else if (id instanceof CompoundedProgramFieldType) {
                CompoundedProgramFieldType value = (CompoundedProgramFieldType) id;
                String entry = value.getFormattedValueForProgram(prog);

                if (entry != null) {
                    startInfoSection(buffer, value.getName());
                    buffer.append(HTMLTextHelper.convertTextToHtml(entry, false));

                    addSeparator(doc, buffer);
                }
            } else {
                type = (ProgramFieldType) id;

                if (type == ProgramFieldType.DESCRIPTION_TYPE) {
                    String description = checkDescription(prog.getDescription());
                    if (description != null && description.length() > 0) {
                        addEntry(doc, buffer, prog, ProgramFieldType.DESCRIPTION_TYPE, true, showHelpLinks,
                                showPersonLinks);
                    } else {
                        addEntry(doc, buffer, prog, ProgramFieldType.SHORT_DESCRIPTION_TYPE, true,
                                showHelpLinks, showPersonLinks);
                    }
                } else if (type == ProgramFieldType.INFO_TYPE) {
                    int info = prog.getInfo();
                    if ((info != -1) && (info != 0)) {
                        buffer.append("<tr><td valign=\"top\" style=\"color:gray; font-size:");

                        buffer.append(mBodyFontSize);

                        buffer.append("\"><b>");
                        buffer.append(type.getLocalizedName());
                        buffer.append("</b></td><td valign=\"middle\" style=\"font-size:5\">");

                        openPara(buffer, "info");
                        // Workaround: Without the &nbsp; the component are not put in one
                        // line.
                        buffer.append("&nbsp;");

                        int[] infoBitArr = ProgramInfoHelper.getInfoBits();
                        Icon[] infoIconArr = ProgramInfoHelper.getInfoIcons();
                        String[] infoMsgArr = ProgramInfoHelper.getInfoIconMessages();

                        for (int i = 0; i < infoBitArr.length; i++) {
                            if (ProgramInfoHelper.bitSet(info, infoBitArr[i])) {
                                JLabel iconLabel;

                                if (infoIconArr[i] != null) {
                                    iconLabel = new JLabel(infoIconArr[i]);
                                } else {
                                    iconLabel = new JLabel(infoMsgArr[i]);
                                }

                                iconLabel.setToolTipText(infoMsgArr[i]);
                                buffer.append(doc.createCompTag(iconLabel));

                                buffer.append("&nbsp;&nbsp;");
                            }
                        }

                        closePara(buffer);

                        buffer.append("</td></tr>");
                        addSeparator(doc, buffer);
                    }
                } else if (type == ProgramFieldType.URL_TYPE) {
                    addEntry(doc, buffer, prog, ProgramFieldType.URL_TYPE, true, showHelpLinks,
                            showPersonLinks);
                } else if (type == ProgramFieldType.ACTOR_LIST_TYPE) {
                    ArrayList<String> knownNames = new ArrayList<String>();
                    String[] recognizedActors = ProgramUtilities.getActorNames(prog);
                    if (recognizedActors != null) {
                        knownNames.addAll(Arrays.asList(recognizedActors));
                    }
                    String actorField = prog.getTextField(type);
                    if (actorField != null) {
                        ArrayList<String>[] lists = ProgramUtilities.splitActors(prog);
                        if (lists == null) {
                            lists = splitActorsSimple(prog);
                        }
                        if (lists != null && lists[0].size() > 0) {
                            startInfoSection(buffer, type.getLocalizedName());
                            buffer.append("<table border=\"0\" cellpadding=\"0\" style=\"font-family:");
                            buffer.append(bodyFont);
                            buffer.append(";\">");
                            for (int i = 0; i < lists[0].size(); i++) {
                                String[] parts = new String[2];
                                parts[0] = lists[0].get(i);
                                parts[1] = "";
                                if (i < lists[1].size()) {
                                    parts[1] = lists[1].get(i);
                                }
                                int actorIndex = 0;
                                if (showPersonLinks) {
                                    if (knownNames.contains(parts[0])) {
                                        parts[0] = addPersonLink(parts[0]);
                                    } else if (knownNames.contains(parts[1])) {
                                        parts[1] = addPersonLink(parts[1]);
                                        actorIndex = 1;
                                    }
                                }
                                buffer.append("<tr><td valign=\"top\">&#8226;&nbsp;</td><td valign=\"top\">");
                                buffer.append(parts[actorIndex]);
                                buffer.append("</td><td width=\"10\">&nbsp;</td>");

                                if (parts[1 - actorIndex].length() > 0) {
                                    buffer.append("<td valign=\"top\">");
                                    buffer.append(parts[1 - actorIndex]);
                                    buffer.append("</td>");
                                } else {
                                    // if roles are missing add next actor in the same line
                                    if (i + 1 < lists[0].size() && lists[1].size() == 0) {
                                        i++;
                                        buffer.append(
                                                "<td valign=\"top\">&#8226;&nbsp;</td><td valign=\"top\">");
                                        if (showPersonLinks) {
                                            buffer.append(addSearchLink(lists[0].get(i)));
                                        } else {
                                            buffer.append(lists[0].get(i));
                                        }
                                        buffer.append("</td>");
                                    }
                                }
                                buffer.append("</td></tr>");
                            }
                            buffer.append("</table>");
                            buffer.append("</td></tr>");
                            addSeparator(doc, buffer);
                        } else {
                            addEntry(doc, buffer, prog, type, showHelpLinks, showPersonLinks);
                        }
                    }
                } else {
                    addEntry(doc, buffer, prog, type, showHelpLinks, showPersonLinks);
                }
            }
        }

        if (showHelpLinks) {
            buffer.append(
                    "<tr><td colspan=\"2\" valign=\"top\" align=\"center\" style=\"color:#808080; font-size:");
            buffer.append(mBodyFontSize).append("\">");
            buffer.append("<a href=\"");
            buffer.append(
                    mLocalizer.msg("dataInfo", "http://wiki.tvbrowser.org/index.php/Qualit%C3%A4t_der_Daten"))
                    .append("\">");
            buffer.append(mLocalizer.msg("dataQuality", "Details of the data quality"));
            buffer.append("</a>");
            buffer.append("</td></tr>");
        }
        buffer.append("</table></html>");

        return buffer.toString();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return "";
}

From source file:AnimatedGifEncoder.java

/**
 * Returns index of palette color closest to c
 * /*from   w  w w .j  a  v a 2s  .c  om*/
 */
protected int findClosest(Color c) {
    if (colorTab == null)
        return -1;
    int r = c.getRed();
    int g = c.getGreen();
    int b = c.getBlue();
    int minpos = 0;
    int dmin = 256 * 256 * 256;
    int len = colorTab.length;
    for (int i = 0; i < len;) {
        int dr = r - (colorTab[i++] & 0xff);
        int dg = g - (colorTab[i++] & 0xff);
        int db = b - (colorTab[i] & 0xff);
        int d = dr * dr + dg * dg + db * db;
        int index = i / 3;
        if (usedEntry[index] && (d < dmin)) {
            dmin = d;
            minpos = index;
        }
        i++;
    }
    return minpos;
}

From source file:org.apache.pdfbox.pdmodel.edit.PDPageContentStream.java

/**
 * Set the stroking color, specified as RGB.
 *
 * @param color The color to set./*from  ww  w  . j  a  va  2 s  .  co m*/
 * @throws IOException If an IO error occurs while writing to the stream.
 */
public void setStrokingColor(Color color) throws IOException {
    ColorSpace colorSpace = color.getColorSpace();
    if (colorSpace.getType() == ColorSpace.TYPE_RGB) {
        setStrokingColor(color.getRed(), color.getGreen(), color.getBlue());
    } else if (colorSpace.getType() == ColorSpace.TYPE_GRAY) {
        color.getColorComponents(colorComponents);
        setStrokingColor(colorComponents[0]);
    } else if (colorSpace.getType() == ColorSpace.TYPE_CMYK) {
        color.getColorComponents(colorComponents);
        setStrokingColor(colorComponents[0], colorComponents[2], colorComponents[2], colorComponents[3]);
    } else {
        throw new IOException("Error: unknown colorspace:" + colorSpace);
    }
}

From source file:org.apache.pdfbox.pdmodel.edit.PDPageContentStream.java

/**
 * Set the non stroking color, specified as RGB.
 *
 * @param color The color to set.//from w  w  w .j a  va2  s.c om
 * @throws IOException If an IO error occurs while writing to the stream.
 */
public void setNonStrokingColor(Color color) throws IOException {
    ColorSpace colorSpace = color.getColorSpace();
    if (colorSpace.getType() == ColorSpace.TYPE_RGB) {
        setNonStrokingColor(color.getRed(), color.getGreen(), color.getBlue());
    } else if (colorSpace.getType() == ColorSpace.TYPE_GRAY) {
        color.getColorComponents(colorComponents);
        setNonStrokingColor(colorComponents[0]);
    } else if (colorSpace.getType() == ColorSpace.TYPE_CMYK) {
        color.getColorComponents(colorComponents);
        setNonStrokingColor(colorComponents[0], colorComponents[2], colorComponents[2], colorComponents[3]);
    } else {
        throw new IOException("Error: unknown colorspace:" + colorSpace);
    }
}

From source file:net.sf.jabref.JabRefPreferences.java

/**
 * Stores a color in preferences.//w ww. ja  v  a  2  s  . c  o  m
 *
 * @param key The key for this setting.
 * @param color The Color to store.
 */
public void putColor(String key, Color color) {
    String rgb = String.valueOf(color.getRed()) + ':' + color.getGreen() + ':' + color.getBlue();
    put(key, rgb);
}

From source file:org.openmicroscopy.shoola.util.ui.UIUtilities.java

/**
 * Returns <code>true</code> if the passed color is a dark color,
 * <code>false</code> otherwise.
 * /* ww  w  .j  av  a2  s .c  o  m*/
 * @param c The color to handle. Mustn't be <code>null</code>.
 * @return See above.
 */
public static boolean isDarkColor(Color c) {
    if (c == null)
        return false;
    return (c.getRed() + c.getGreen() + c.getBlue()) / 3 < 128;
}

From source file:org.nuclos.client.ui.collect.component.AbstractCollectableComponent.java

public static void setBackgroundColor(Component cellRendererComponent, JTable tbl, Object oValue,
        boolean bSelected, boolean bHasFocus, int iRow, int iColumn) {
    cellRendererComponent.setBackground(bSelected ? tbl.getSelectionBackground()
            : iRow % 2 == 0 ? tbl.getBackground() : NuclosThemeSettings.BACKGROUND_PANEL);
    cellRendererComponent.setForeground(bSelected ? tbl.getSelectionForeground() : tbl.getForeground());

    final TableModel tm;
    final int adjustColIndex;
    if (tbl instanceof FixedColumnRowHeader.HeaderTable
            && ((FixedColumnRowHeader.HeaderTable) tbl).getExternalTable() != null) {
        tm = ((FixedColumnRowHeader.HeaderTable) tbl).getExternalTable().getModel();
        adjustColIndex = FixedRowIndicatorTableModel.ROWMARKERCOLUMN_COUNT;
    } else {/*from   w w w . j  av  a2s .  com*/
        tm = tbl.getModel();
        adjustColIndex = 0;
    }

    // check whether the data of the component is readable for current user, by asking the security agent of the actual field
    if (tm instanceof SortableCollectableTableModel<?>) {
        final SortableCollectableTableModel<Collectable> tblModel = (SortableCollectableTableModel<Collectable>) tm;
        if (tblModel.getRowCount() > iRow) {
            final Collectable clct = tblModel.getCollectable(iRow);
            final Integer iTColumn = tbl.getColumnModel().getColumn(iColumn).getModelIndex() - adjustColIndex;
            final CollectableEntityField clctef = tblModel.getCollectableEntityField(iTColumn);
            if (clctef == null) {
                throw new NullPointerException("getTableCellRendererComponent failed to find field: " + clct
                        + " tm index " + iTColumn);
            }

            boolean isEnabled = true;
            if (!clctef.isNullable() && isNull(oValue)) {
                cellRendererComponent.setBackground(getMandatoryColor());
                cellRendererComponent.setForeground(tbl.getForeground());
            } else {
                //               if (clct.getId() == null) {
                //                  cellRendererComponent.setBackground(tbl.getBackground());
                //                  cellRendererComponent.setForeground(tbl.getForeground());
                //               } else {
                if (tbl instanceof SubForm.SubFormTable) {
                    SubFormTable subformtable = (SubForm.SubFormTable) tbl;
                    Column subformcolumn = subformtable.getSubForm().getColumn(clctef.getName());
                    if (subformcolumn != null && !subformcolumn.isEnabled()) {
                        isEnabled = false;
                        if (bSelected) {
                            cellRendererComponent
                                    .setBackground(NuclosThemeSettings.BACKGROUND_INACTIVESELECTEDCOLUMN);
                        } else {
                            cellRendererComponent.setBackground(NuclosThemeSettings.BACKGROUND_INACTIVECOLUMN);
                        }
                    }
                }
                //               }

                try {
                    EntityMetaDataVO meta = MetaDataClientProvider.getInstance()
                            .getEntity(clctef.getEntityName());
                    if (meta.getRowColorScript() != null && !bSelected) {
                        AbstractCollectableComponent.setBackground(cellRendererComponent,
                                meta.getRowColorScript(), clct, meta, isEnabled);
                    }
                } catch (CommonFatalException ex) {
                    LOG.warn(ex);
                }
            }
        }
    }

    if (tbl instanceof TableRowMouseOverSupport) {
        TableRowMouseOverSupport trmos = (TableRowMouseOverSupport) tbl;
        if (trmos.isMouseOverRow(iRow)) {
            final Color bgColor = LangUtils.defaultIfNull(cellRendererComponent.getBackground(), Color.WHITE);
            cellRendererComponent
                    .setBackground(new Color(Math.max(0, bgColor.getRed() - (bgColor.getRed() * 8 / 100)),
                            Math.max(0, bgColor.getGreen() - (bgColor.getGreen() * 8 / 100)),
                            Math.max(0, bgColor.getBlue() - (bgColor.getBlue() * 8 / 100))));
            //            cellRendererComponent.setBackground(UIManager.getColor("Table.selectionBackground"));
        }
    }
}

From source file:ImageOpByRomain.java

/**
 * <p>/*  www .j  ava2  s .co  m*/
 * Creates a new color mixer filter. The specified color will be used to tint
 * the source image, with a mixing strength defined by <code>mixValue</code>.
 * </p>
 * 
 * @param mixColor
 *            the solid color to mix with the source image
 * @param mixValue
 *            the strength of the mix, between 0.0 and 1.0; if the specified
 *            value lies outside this range, it is clamped
 * @throws IllegalArgumentException
 *             if <code>mixColor</code> is null
 */
public ColorTintFilter(Color mixColor, float mixValue) {
    if (mixColor == null) {
        throw new IllegalArgumentException("mixColor cannot be null");
    }

    this.mixColor = mixColor;
    if (mixValue < 0.0f) {
        mixValue = 0.0f;
    } else if (mixValue > 1.0f) {
        mixValue = 1.0f;
    }
    this.mixValue = mixValue;

    int mix_r = (int) (mixColor.getRed() * mixValue);
    int mix_g = (int) (mixColor.getGreen() * mixValue);
    int mix_b = (int) (mixColor.getBlue() * mixValue);

    // Since we use only lookup tables to apply the filter, this filter
    // could be implemented as a LookupOp.
    float factor = 1.0f - mixValue;
    preMultipliedRed = new int[256];
    preMultipliedGreen = new int[256];
    preMultipliedBlue = new int[256];

    for (int i = 0; i < 256; i++) {
        int value = (int) (i * factor);
        preMultipliedRed[i] = value + mix_r;
        preMultipliedGreen[i] = value + mix_g;
        preMultipliedBlue[i] = value + mix_b;
    }
}

From source file:net.sf.jasperreports.engine.export.JRRtfExporter.java

/**
 *
 *///w  w  w  .  ja  v  a2s  .c o m
private int getColorRGB(Color color) {
    return color.getRed() + 256 * color.getGreen() + 65536 * color.getBlue();
}