Example usage for java.awt Color getRed

List of usage examples for java.awt Color getRed

Introduction

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

Prototype

public int getRed() 

Source Link

Document

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

Usage

From source file:org.n52.server.sos.render.DiagramRenderer.java

/**
 * Builds up a DesignDescriptionList which stores the information
 * about the style of each timeseries./*from   ww  w.  j  a va  2  s.co  m*/
 * 
 * @param options
 *            the options
 * @return the design description list
 */
private DesignDescriptionList buildUpDesignDescriptionList(DesignOptions options) {

    String domainAxisLabel;
    if (options.getLanguage() != null && options.getLanguage().equals("de")) {
        domainAxisLabel = "Zeit";
    } else { // default => "en"
        domainAxisLabel = "Time";
    }
    if (this.isOverview) {
        domainAxisLabel = null;
    }

    DesignDescriptionList designDescriptions = new DesignDescriptionList(domainAxisLabel);
    String observedPropertyWithGrid = options.getProperties().get(0).getPhenomenon();

    for (TimeseriesProperties tsProperties : options.getProperties()) {
        Color c = JavaHelper.transformToColor(tsProperties.getHexColor());
        String phenomenonId = tsProperties.getPhenomenon();
        String procedureId = tsProperties.getProcedure();
        String featureId = tsProperties.getFeature();
        boolean drawGrid = observedPropertyWithGrid.equals(phenomenonId);

        TimeseriesParametersLookup lookup = getParameterLookup(tsProperties);
        Feature feature = lookup.getFeature(featureId);
        Procedure procedure = lookup.getProcedure(procedureId);
        Phenomenon phenomenon = lookup.getPhenomenon(phenomenonId);

        designDescriptions.add(phenomenon, procedure, feature, tsProperties,
                new Color(c.getRed(), c.getGreen(), c.getBlue(), (int) tsProperties.getOpacity() * 255 / 100),
                tsProperties.getLineStyle(), tsProperties.getLineWidth(), drawGrid);
    }
    return designDescriptions;
}

From source file:LightTest.java

protected void OnColor() {
    Color rgb = m_ColorChooser.showDialog(m_Panel, "Set Light Color", null);

    if (rgb != null) {
        m_Light.setColor(new Color3f((float) rgb.getRed() / 255f, (float) rgb.getGreen() / 255f,
                (float) rgb.getBlue() / 255f));
    }// w w  w.j  av a2 s .  c  o m
}

From source file:com.jcraft.weirdx.XColormap.java

static void reqAllocNamedColor(Client c) throws IOException {
    int foo;//  w w  w  .j a v a  2  s.c o  m
    int n;
    int len;
    InputOutput io = c.client;
    n = c.length;
    foo = io.readInt();
    XColormap cmap = (XColormap) XResource.lookupIDByType(foo, XResource.RT_COLORMAP);
    c.length -= 2;
    if (cmap == null) {
        c.errorValue = foo;
        c.errorReason = 12; // Colormap
        return;
    }
    len = io.readShort();
    io.readPad(2);
    n = n - 3;
    n *= 4;
    n -= len;
    io.readByte(c.bbuffer, 0, len);
    io.readPad(n);
    c.length = 0;
    len = chopspace(c.bbuffer, len);
    if (len == 0) {
        c.errorReason = 2; // BadValue
        return;
    }

    String s = new String(c.bbuffer, 0, len);
    Color color = (Color) rgbTable.get(s);
    if (color != null) {

        int red = color.getRed();
        int green = color.getGreen();
        int blue = color.getBlue();

        int i = cmap.allocColor(c, color.getRed(), color.getGreen(), color.getBlue());
        if (c.errorReason != 0) {
            return;
        }

        if (cmap.visual.depth.depth != 16) {
            LocalEntry ent = (LocalEntry) cmap.entries[i];
            red = ent.r;
            green = ent.g;
            blue = ent.b;
            if (ent.refcnt == 1) {
                cmap.mkIcm();
            }
        }

        synchronized (io) {
            io.writeByte(1);
            io.writePad(1);
            io.writeShort(c.seq);
            io.writeInt(0);
            io.writeInt(i);
            io.writeShort(red | (red << 8));
            io.writeShort(green | (green << 8));
            io.writeShort(blue | (blue << 8));
            io.writeShort(red | (red << 8));
            io.writeShort(green | (green << 8));
            io.writeShort(blue | (blue << 8));
            io.writePad(8);
            io.flush();
            return;
        }
    }

    synchronized (io) {
        io.writeByte((byte) 0);
        io.writeByte((byte) 15);
        io.writeShort(c.seq);
        io.writePad(4);
        io.writeShort(0);
        io.writeByte((byte) 85);
        io.writePad(21);
        io.flush();
    }
}

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 {/*  w w w .  jav a  2s .c o m*/
        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:mio_de_pso.MainForm.java

private LookupPaintScale createLookupPaintScale(double[] values) {
    double minVal = values[0];
    double maxVal = values[0];
    for (int i = 0; i < values.length; ++i) {
        if (values[i] < minVal)
            minVal = values[i];/*from   w  ww.  j ava  2  s  .  co m*/
        if (values[i] > maxVal)
            maxVal = values[i];
    }

    LookupPaintScale ps = new LookupPaintScale(minVal, maxVal + 0.0000001, Color.WHITE);

    Color startColor = Color.BLACK;
    Color secondColor = Color.BLUE;
    Color thirdColor = Color.GREEN;
    Color fourthColor = Color.YELLOW;
    Color endColor = Color.RED;

    int iterations = 80;
    int iterationPerColor = iterations / 4;
    double res = Math.round(((maxVal - minVal) / iterations) * 100.0) / 100.0;
    minVal -= res;

    for (int i = 0; i < iterationPerColor; ++i) {
        ps.add(minVal += res, new Color(
                startColor.getRed() + (((secondColor.getRed() - startColor.getRed()) * i) / iterationPerColor),
                startColor.getGreen()
                        + (((secondColor.getGreen()) - startColor.getGreen()) * i) / iterationPerColor,
                startColor.getBlue()
                        + (((secondColor.getBlue() - startColor.getBlue()) * i) / iterationPerColor)));
    }
    for (int i = 0; i < iterationPerColor; ++i) {
        ps.add(minVal += res, new Color(
                secondColor.getRed() + (((thirdColor.getRed() - secondColor.getRed()) * i) / iterationPerColor),
                secondColor.getGreen()
                        + (((thirdColor.getGreen()) - secondColor.getGreen()) * i) / iterationPerColor,
                secondColor.getBlue()
                        + (((thirdColor.getBlue() - secondColor.getBlue()) * i) / iterationPerColor)));
    }
    for (int i = 0; i < iterationPerColor; ++i) {
        ps.add(minVal += res, new Color(
                thirdColor.getRed() + (((fourthColor.getRed() - thirdColor.getRed()) * i) / iterationPerColor),
                thirdColor.getGreen()
                        + (((fourthColor.getGreen()) - thirdColor.getGreen()) * i) / iterationPerColor,
                thirdColor.getBlue()
                        + (((fourthColor.getBlue() - thirdColor.getBlue()) * i) / iterationPerColor)));
    }
    for (int i = 0; i < iterationPerColor; ++i) {
        ps.add(minVal += res, new Color(
                fourthColor.getRed() + (((endColor.getRed() - fourthColor.getRed()) * i) / iterationPerColor),
                fourthColor.getGreen()
                        + (((endColor.getGreen()) - fourthColor.getGreen()) * i) / iterationPerColor,
                fourthColor.getBlue()
                        + (((endColor.getBlue() - fourthColor.getBlue()) * i) / iterationPerColor)));
    }
    return ps;
}

From source file:edu.ku.brc.specify.plugins.latlon.LatLonUI.java

/**
 * Creates the UI./*from  w w  w . ja  v a  2  s . c  o m*/
 * @param localityCEP the locality object (can be null)
 */
protected void createEditUI() {
    loadAndPushResourceBundle("specify_plugins");

    PanelBuilder builder = new PanelBuilder(new FormLayout("p", "p, 2px, p"), this);

    Color bgColor = getBackground();
    bgColor = new Color(Math.min(bgColor.getRed() + 20, 255), Math.min(bgColor.getGreen() + 20, 255),
            Math.min(bgColor.getBlue() + 20, 255));
    //System.out.println(bgColor);
    setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(bgColor),
            BorderFactory.createEmptyBorder(4, 4, 4, 4)));

    for (int i = 0; i < types.length; i++) {
        typeMapper.put(types[i], typeStrs[i]);
    }

    currentType = LatLonUIIFace.LatLonType.LLPoint;

    pointImages = new ImageIcon[pointNames.length];
    for (int i = 0; i < pointNames.length; i++) {
        pointImages[i] = IconManager.getIcon(pointNames[i], IconManager.IconSize.Std16);
    }

    String[] formatLabels = new String[formats.length];
    for (int i = 0; i < formats.length; i++) {
        formatLabels[i] = getResourceString(formats[i]);
    }
    cardPanel = new JPanel(cardLayout);
    formatSelector = createComboBox(formatLabels);
    latLonPanes = new JComponent[formatLabels.length];

    formatSelector.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            swapForm(formatSelector.getSelectedIndex(), currentType);

            cardLayout.show(cardPanel, ((JComboBox) ae.getSource()).getSelectedItem().toString());

            //stateChanged(null);
        }
    });

    Dimension preferredSize = new Dimension(0, 0);
    cardSubPanes = new JPanel[formats.length * 2];
    panels = new DDDDPanel[formats.length * 2];
    int paneInx = 0;
    for (int i = 0; i < formats.length; i++) {
        cardSubPanes[i] = new JPanel(new BorderLayout());
        try {
            String packageName = "edu.ku.brc.specify.plugins.latlon.";
            DDDDPanel latLon1 = Class.forName(packageName + formatClass[i]).asSubclass(DDDDPanel.class)
                    .newInstance();
            latLon1.setIsRequired(isRequired);
            latLon1.setViewMode(isViewMode);
            latLon1.init();
            latLon1.setChangeListener(this);

            JPanel panel1 = latLon1;
            panel1.setBorder(panelBorder);
            panels[paneInx++] = latLon1;
            latLonPanes[i] = panel1;

            DDDDPanel latlon2 = Class.forName(packageName + formatClass[i]).asSubclass(DDDDPanel.class)
                    .newInstance();
            latlon2.setIsRequired(isRequired);
            latlon2.setViewMode(isViewMode);
            latlon2.init();
            latlon2.setChangeListener(this);

            panels[paneInx++] = latlon2;

            JTabbedPane tabbedPane = new JTabbedPane(
                    UIHelper.getOSType() == UIHelper.OSTYPE.MacOSX ? SwingConstants.BOTTOM
                            : SwingConstants.RIGHT);
            tabbedPane.addTab(null, pointImages[0], panels[paneInx - 2]);
            tabbedPane.addTab(null, pointImages[0], panels[paneInx - 1]);
            latLonPanes[i] = tabbedPane;

            Dimension size = tabbedPane.getPreferredSize();
            preferredSize.width = Math.max(preferredSize.width, size.width);
            preferredSize.height = Math.max(preferredSize.height, size.height);

            tabbedPane.removeAll();
            cardSubPanes[i].add(panel1, BorderLayout.CENTER);
            cardPanel.add(formatLabels[i], cardSubPanes[i]);

            /*if (locality != null)
            {
            latLon1.set(locality.getLatitude1(), locality.getLongitude1(), locality.getLat1text(), locality.getLong1text());
            latlon2.set(locality.getLatitude2(), locality.getLongitude2(), locality.getLat2text(), locality.getLong2text());
            }*/

        } catch (Exception e) {
            e.printStackTrace();
            edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
            edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(LatLonUI.class, e);
        }
    }

    // Makes they are all the same size
    for (int i = 0; i < formats.length; i++) {
        cardSubPanes[i].setPreferredSize(preferredSize);
    }

    //final LatLonPanel thisPanel = this;

    PanelBuilder botBtnBar = new PanelBuilder(new FormLayout("p:g,p,10px,p,10px,p,p:g", "p"));

    ButtonGroup btnGroup = new ButtonGroup();
    botBtns = new JToggleButton[typeNames.length];

    if (UIHelper.isMacOS()) {
        /*for (int i=0;i<botBtns.length;i++)
        {
        ImageIcon selIcon   = IconManager.getIcon(typeNames[i]+"Sel", IconManager.IconSize.Std16);
        ImageIcon unselIcon = IconManager.getIcon(typeNames[i], IconManager.IconSize.Std16);
                
        MacIconRadioButton rb = new MacIconRadioButton(selIcon, unselIcon);
        botBtns[i] = rb;
        rb.setBorder(new MacBtnBorder());
                
        Dimension size = rb.getPreferredSize();
        int max = Math.max(size.width, size.height);
        size.setSize(max, max);
        rb.setPreferredSize(size);
        }*/

        BorderedRadioButton.setSelectedBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
        BorderedRadioButton.setUnselectedBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
        for (int i = 0; i < botBtns.length; i++) {
            BorderedRadioButton rb = new BorderedRadioButton(
                    IconManager.getIcon(typeNames[i], IconManager.IconSize.Std16));
            botBtns[i] = rb;
            rb.makeSquare();
            rb.setBorder(new MacBtnBorder());
        }
    } else {
        BorderedRadioButton.setSelectedBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
        BorderedRadioButton.setUnselectedBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
        for (int i = 0; i < botBtns.length; i++) {
            BorderedRadioButton rb = new BorderedRadioButton(
                    IconManager.getIcon(typeNames[i], IconManager.IconSize.Std16));
            botBtns[i] = rb;
            rb.makeSquare();
        }
    }

    for (int i = 0; i < botBtns.length; i++) {
        botBtns[i].setToolTipText(typeToolTips[i]);
        botBtnBar.add(botBtns[i], cc.xy((i * 2) + 2, 1));
        btnGroup.add(botBtns[i]);
        selectedTypeHash.put(botBtns[i], types[i]);

        botBtns[i].addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ce) {
                stateChanged(null);
                currentType = selectedTypeHash.get(ce.getSource());
                swapForm(formatSelector.getSelectedIndex(), currentType);
            }
        });
    }
    botBtns[0].setSelected(true);

    if (isViewMode) {
        typeLabel = createLabel(" ");
    }

    ActionListener infoAL = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            doPrefs();
        }
    };

    JButton infoBtn = UIHelper.createIconBtn("Preferences", IconManager.IconSize.Std16,
            getResourceString("PREFERENCES"), true, infoAL);
    infoBtn.setEnabled(true);

    PanelBuilder topPane = new PanelBuilder(
            new FormLayout("l:p, c:p:g" + (isViewMode ? "" : ",4px,p,8px"), "p"));
    topPane.add(formatSelector, cc.xy(1, 1));
    topPane.add(isViewMode ? typeLabel : botBtnBar.getPanel(), cc.xy(2, 1));
    if (!isViewMode)
        topPane.add(infoBtn, cc.xy(4, 1));

    builder.add(topPane.getPanel(), cc.xy(1, 1));
    builder.add(cardPanel, cc.xy(1, 3));

    prefsPanel = new PrefsPanel(false);
    prefsPanel.add(getResourceString("LatLonUI.LL_SEP"));
    prefsPanel.add(CompType.eCheckbox, getResourceString("LatLonUI.LATDEF_DIR"), LAT_PREF, Boolean.class, true);
    prefsPanel.add(CompType.eCheckbox, getResourceString("LatLonUI.LONDEF_DIR"), LON_PREF, Boolean.class, true);
    prefsPanel.add(CompType.eComboBox, getResourceString("LatLonUI.DEF_TYP"), TYP_PREF, Integer.class,
            typeNamesLabels, 0);
    prefsPanel.add(CompType.eComboBox, getResourceString("LatLonUI.DEF_FMT"), FMT_PREF, Integer.class,
            formatLabels, 0);
    prefsPanel.createForm(null, null);

    popResourceBundle();
}

From source file:com.jcraft.weirdx.XColormap.java

static void reqStoreNamedColor(Client c) throws IOException {
    int foo, n, len, doc, pixel;
    InputOutput io = c.client;//www.ja v a  2 s  .com
    doc = c.data;
    n = c.length;
    foo = io.readInt();
    XColormap cmap = (XColormap) XResource.lookupIDByType(foo, XResource.RT_COLORMAP);
    c.length -= 2;
    if (cmap == null) {
        c.errorValue = foo;
        c.errorReason = 12; // Colormap
        return;
    }

    pixel = io.readInt();
    len = io.readShort();
    io.readPad(2);
    n = n - 4;
    n *= 4;
    n -= len;
    io.readByte(c.bbuffer, 0, len);
    io.readPad(n);
    c.length = 0;
    len = chopspace(c.bbuffer, len);
    if (len == 0) {
        c.errorReason = 2; // BadValue
        return;
    }

    String s = new String(c.bbuffer, 0, len);
    Color color = (Color) rgbTable.get(s);
    if (pixel == -1) {
        LOG.warn("?? pixel=" + pixel);
        pixel = 25;
    }

    int red = color.getRed(), green = color.getGreen(), blue = color.getBlue();
    Color cp = cmap.colors[pixel];
    if (cp != null) {
        if (doc != 0) {
            if ((doc & 1) == 0)
                red = cp.getRed();
            if ((doc & 2) == 0)
                green = cp.getGreen();
            if ((doc & 4) == 0)
                blue = cp.getBlue();
        }
    }
    c.errorReason = cmap.storeColor(c, pixel, red, green, blue, doc);
    if (c.errorReason == 0) {
        cmap.mkIcm();
    }
}

From source file:util.program.ProgramTextCreator.java

/**
 *
 * @param prog//from  www .j a  v  a2s  .  c  om
 *          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:net.sf.maltcms.chromaui.chromatogram1Dviewer.ui.panel.Chromatogram1DHeatmapViewerPanel.java

@Override
public void setPaintScale(PaintScale ps) {
    Logger.getLogger(getClass().getName()).info("Set paint scale called on HeatmapPanel");
    //        if (ps != null && ps instanceof GradientPaintScale) {
    Logger.getLogger(getClass().getName()).info("Paint scale using!");
    GradientPaintScale sps = (GradientPaintScale) ps;
    if (this.ps != null) {
        double lb = this.ps.getLowerBound();
        double ub = this.ps.getUpperBound();
        sps.setLowerBound(lb);/*w  w w .  ja  v a2 s. c o  m*/
        sps.setUpperBound(ub);
        //this.jSlider1.setValue(0);
    }
    this.alpha = (int) sps.getAlpha();
    this.beta = (int) sps.getBeta();
    this.ps = sps;
    Color c = (Color) sps.getPaint(this.ps.getUpperBound());
    if (chartPanel != null) {
        JFreeChart jfc = chartPanel.getChart();
        if (jfc != null) {
            XYPlot plot = jfc.getXYPlot();
            if (!jCheckBox2.isSelected()) {
                Color bg = (Color) this.ps.getPaint(this.ps.getLowerBound());
                Logger.getLogger(getClass().getName()).log(Level.INFO, "Background color: {0}", bg);
                setBackgroundColor(bg);
            }
        }
    }
    selectionFill = new Color(c.getRed(), c.getBlue(), c.getGreen(), 192);
    selectionOutline = new Color(c.getRed(), c.getBlue(), c.getGreen()).darker();
    this.jSlider1.setMaximum(100);
    this.jSlider1.setMinimum(0);
    handleSliderChange();
    //        }
}

From source file:AnimatedGifEncoder.java

/**
 * Returns index of palette color closest to c
 * /*w  ww.  ja  v  a2  s .  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;
}