Example usage for java.awt Color getRGB

List of usage examples for java.awt Color getRGB

Introduction

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

Prototype

public int getRGB() 

Source Link

Document

Returns the RGB value representing the color in the default sRGB ColorModel .

Usage

From source file:ca.sqlpower.matchmaker.MatchMakerTestCase.java

/**
 * Returns a new value that is not equal to oldVal. If oldVal is immutable, the
 * returned object will be a new instance compatible with oldVal.  If oldVal is 
 * mutable, it will be modified in some way so it is no longer equal to its original
 * value. {@link #getNewDifferentValue(MatchMakerObject, PropertyDescriptor, Object)}
 * is a similar method that does not take mutability into account and always returns 
 * a new value./*from   w w w .  j a v a 2s . com*/
 * 
 * @param mmo The object to which the property belongs.  You might need this
 *  if you have a special case for certain types of objects.
 * @param property The property that should be modified.  It belongs to mmo.
 * @param oldVal The existing value of the property to modify.  The returned value
 * will not equal this one at the time this method was first called, although it may
 * be the same instance as this one, but modified in some way.
 */
private Object modifyObject(MatchMakerObject mmo, PropertyDescriptor property, Object oldVal)
        throws IOException {
    if (property.getPropertyType() == Integer.TYPE || property.getPropertyType() == Integer.class) {
        return ((Integer) oldVal) + 1;
    } else if (property.getPropertyType() == Short.TYPE || property.getPropertyType() == Short.class) {
        return ((Short) oldVal) + 1;
    } else if (property.getPropertyType() == String.class) {
        if (oldVal == null) {
            return "new";
        } else {
            return "new " + oldVal;
        }
    } else if (property.getPropertyType() == Boolean.class || property.getPropertyType() == Boolean.TYPE) {
        return new Boolean(!((Boolean) oldVal).booleanValue());
    } else if (property.getPropertyType() == Long.class) {
        return new Long(((Long) oldVal).longValue() + 1L);
    } else if (property.getPropertyType() == BigDecimal.class) {
        return new BigDecimal(((BigDecimal) oldVal).longValue() + 1L);
    } else if (property.getPropertyType() == MungeSettings.class) {
        Integer processCount = ((MatchMakerSettings) oldVal).getProcessCount();
        processCount = new Integer((processCount == null) ? new Integer(0) : processCount + 1);
        ((MatchMakerSettings) oldVal).setProcessCount(processCount);
        return oldVal;
    } else if (property.getPropertyType() == MergeSettings.class) {
        Integer processCount = ((MatchMakerSettings) oldVal).getProcessCount();
        processCount = new Integer((processCount == null) ? new Integer(0) : processCount + 1);
        ((MatchMakerSettings) oldVal).setProcessCount(processCount);
        return oldVal;
    } else if (property.getPropertyType() == SQLTable.class) {
        ((SQLTable) oldVal).setRemarks("Testing Remarks");
        return oldVal;
    } else if (property.getPropertyType() == ViewSpec.class) {
        ((ViewSpec) oldVal).setName("Testing New Name");
        return oldVal;
    } else if (property.getPropertyType() == File.class) {
        oldVal = File.createTempFile("mmTest2", ".tmp");
        ((File) oldVal).deleteOnExit();
        return oldVal;
    } else if (property.getPropertyType() == ProjectMode.class) {
        if (oldVal == ProjectMode.BUILD_XREF) {
            return ProjectMode.FIND_DUPES;
        } else {
            return ProjectMode.BUILD_XREF;
        }
    } else if (property.getPropertyType() == MergeActionType.class) {
        if (oldVal == MergeActionType.AUGMENT) {
            return MergeActionType.SUM;
        } else {
            return MergeActionType.AUGMENT;
        }
    } else if (property.getPropertyType() == MatchMakerObject.class) {
        ((MatchMakerObject) oldVal).setName("Testing New Name");
        return oldVal;
    } else if (property.getPropertyType() == MatchMakerTranslateGroup.class) {
        ((MatchMakerObject) oldVal).setName("Testing New Name2");
        return oldVal;
    } else if (property.getPropertyType() == SQLColumn.class) {
        ((SQLColumn) oldVal).setRemarks("Testing Remarks");
        return oldVal;
    } else if (property.getPropertyType() == Date.class) {
        ((Date) oldVal).setTime(((Date) oldVal).getTime() + 10000);
        return oldVal;
    } else if (property.getPropertyType() == List.class) {
        if (property.getName().equals("children")) {
            if (mmo instanceof TableMergeRules) {
                ((List) oldVal).add(new ColumnMergeRules());
            } else {
                ((List) oldVal).add(new StubMatchMakerObject());
            }
        } else {
            ((List) oldVal).add("Test");
        }
        return oldVal;
    } else if (property.getPropertyType() == SQLIndex.class) {
        ((SQLIndex) oldVal).setName("modified index");
        return oldVal;
    } else if (property.getPropertyType() == Color.class) {
        if (oldVal == null) {
            return new Color(0xFAC157);
        } else {
            Color oldColor = (Color) oldVal;
            return new Color((oldColor.getRGB() + 0xF00) % 0x1000000);
        }
    } else if (property.getPropertyType() == ChildMergeActionType.class) {
        if (oldVal != null && oldVal.equals(ChildMergeActionType.DELETE_ALL_DUP_CHILD)) {
            return ChildMergeActionType.UPDATE_DELETE_ON_CONFLICT;
        } else {
            return ChildMergeActionType.DELETE_ALL_DUP_CHILD;
        }
    } else if (property.getPropertyType() == TableMergeRules.class) {
        if (oldVal == null) {
            return mmo;
        } else {
            return null;
        }
    } else if (property.getPropertyType() == PoolFilterSetting.class) {
        if (oldVal != PoolFilterSetting.EVERYTHING) {
            return PoolFilterSetting.EVERYTHING;
        } else {
            return PoolFilterSetting.INVALID_ONLY;
        }
    } else if (property.getPropertyType() == AutoValidateSetting.class) {
        if (oldVal != AutoValidateSetting.NOTHING) {
            return AutoValidateSetting.NOTHING;
        } else {
            return AutoValidateSetting.SERP_CORRECTABLE;
        }
    } else if (property.getPropertyType() == TableIndex.class) {
        CachableTable cachableTable = new CachableTable("newValue");
        TableIndex tableIndex = new TableIndex(cachableTable, "newValueIndex");
        if (tableIndex.getTableIndex() == null) {
            tableIndex.setTableIndex(new SQLIndex());
        } else {
            tableIndex.setTableIndex(null);
        }
        return tableIndex;
    } else if (property.getPropertyType() == CachableTable.class) {
        CachableTable cachableTable = new CachableTable("newValue");
        return cachableTable;
    } else {
        throw new RuntimeException("This test case lacks the ability to modify values for " + property.getName()
                + " (type " + property.getPropertyType().getName() + ")");
    }
}

From source file:ca.sqlpower.matchmaker.MatchMakerTestCase.java

/**
 * Returns a new value that is not equal to oldVal. The returned object
 * will always be a NEW instance compatible with oldVal. This differs from
 * {@link #modifyObject(MatchMakerObject, PropertyDescriptor, Object)} in that
 * this does not take mutability into account.
 * /*from  w w w  .ja  v a2s.c o  m*/
 * @param mmo The object to which the property belongs.  You might need this
 *  if you have a special case for certain types of objects.
 * @param property The property that should be modified.  It belongs to mmo.
 * @param oldVal The existing value of the property.
 */
private Object getNewDifferentValue(MatchMakerObject mmo, PropertyDescriptor property, Object oldVal)
        throws IOException {
    Object newVal; // don't init here so compiler can warn if the
    // following code doesn't always give it a value
    if (property.getPropertyType() == Integer.TYPE || property.getPropertyType() == Integer.class) {
        if (oldVal == null)
            newVal = new Integer(0);
        else {
            newVal = ((Integer) oldVal) + 1;
        }
    } else if (property.getPropertyType() == Short.TYPE || property.getPropertyType() == Short.class) {
        if (oldVal == null)
            newVal = new Short("0");
        else {
            Integer temp = (Short) oldVal + 1;
            newVal = Short.valueOf(temp.toString());
        }
    } else if (property.getPropertyType() == String.class) {
        // make sure it's unique
        newVal = "new " + oldVal;

    } else if (property.getPropertyType() == Boolean.class || property.getPropertyType() == Boolean.TYPE) {
        if (oldVal == null) {
            newVal = new Boolean(false);
        } else {
            newVal = new Boolean(!((Boolean) oldVal).booleanValue());
        }
    } else if (property.getPropertyType() == Long.class) {
        if (oldVal == null) {
            newVal = new Long(0L);
        } else {
            newVal = new Long(((Long) oldVal).longValue() + 1L);
        }
    } else if (property.getPropertyType() == BigDecimal.class) {
        if (oldVal == null) {
            newVal = new BigDecimal(0);
        } else {
            newVal = new BigDecimal(((BigDecimal) oldVal).longValue() + 1L);
        }
    } else if (property.getPropertyType() == MungeSettings.class) {
        newVal = new MungeSettings();
        Integer processCount = ((MatchMakerSettings) newVal).getProcessCount();
        if (processCount == null) {
            processCount = new Integer(0);
        } else {
            processCount = new Integer(processCount + 1);
        }
        ((MatchMakerSettings) newVal).setProcessCount(processCount);
    } else if (property.getPropertyType() == MergeSettings.class) {
        newVal = new MergeSettings();
        Integer processCount = ((MatchMakerSettings) newVal).getProcessCount();
        if (processCount == null) {
            processCount = new Integer(0);
        } else {
            processCount = new Integer(processCount + 1);
        }
        ((MatchMakerSettings) newVal).setProcessCount(processCount);
    } else if (property.getPropertyType() == SQLTable.class) {
        newVal = new SQLTable();
    } else if (property.getPropertyType() == ViewSpec.class) {
        newVal = new ViewSpec("*", "test_table", "true");
    } else if (property.getPropertyType() == File.class) {
        newVal = File.createTempFile("mmTest", ".tmp");
        ((File) newVal).deleteOnExit();
    } else if (property.getPropertyType() == PlFolder.class) {
        newVal = new PlFolder();
    } else if (property.getPropertyType() == ProjectMode.class) {
        if (oldVal == ProjectMode.BUILD_XREF) {
            newVal = ProjectMode.FIND_DUPES;
        } else {
            newVal = ProjectMode.BUILD_XREF;
        }
    } else if (property.getPropertyType() == MergeActionType.class) {
        if (oldVal == MergeActionType.AUGMENT) {
            newVal = MergeActionType.SUM;
        } else {
            newVal = MergeActionType.AUGMENT;
        }
    } else if (property.getPropertyType() == MatchMakerTranslateGroup.class) {
        newVal = new MatchMakerTranslateGroup();
    } else if (property.getPropertyType() == MatchMakerObject.class) {
        newVal = new TestingAbstractMatchMakerObject();
    } else if (property.getPropertyType() == SQLColumn.class) {
        newVal = new SQLColumn();
    } else if (property.getPropertyType() == Date.class) {
        newVal = new Date();
    } else if (property.getPropertyType() == List.class) {
        newVal = new ArrayList();
    } else if (property.getPropertyType() == Project.class) {
        newVal = new Project();
        ((Project) newVal).setName("Fake_Project_" + System.currentTimeMillis());
    } else if (property.getPropertyType() == SQLIndex.class) {
        return new SQLIndex("new index", false, "", "HASHED", "");
    } else if (property.getPropertyType() == Color.class) {
        if (oldVal == null) {
            newVal = new Color(0xFAC157);
        } else {
            Color oldColor = (Color) oldVal;
            newVal = new Color((oldColor.getRGB() + 0xF00) % 0x1000000);
        }
    } else if (property.getPropertyType() == ChildMergeActionType.class) {
        if (oldVal != null && oldVal.equals(ChildMergeActionType.DELETE_ALL_DUP_CHILD)) {
            newVal = ChildMergeActionType.UPDATE_DELETE_ON_CONFLICT;
        } else {
            newVal = ChildMergeActionType.DELETE_ALL_DUP_CHILD;
        }
    } else if (property.getPropertyType() == MungeResultStep.class
            || property.getPropertyType() == DeDupeResultStep.class) {
        newVal = new DeDupeResultStep();
    } else if (property.getPropertyType() == TableMergeRules.class) {
        if (oldVal == null) {
            newVal = mmo;
        } else {
            newVal = null;
        }
    } else if (property.getPropertyType() == PoolFilterSetting.class) {
        if (oldVal != PoolFilterSetting.EVERYTHING) {
            newVal = PoolFilterSetting.EVERYTHING;
        } else {
            newVal = PoolFilterSetting.INVALID_ONLY;
        }
    } else if (property.getPropertyType() == AutoValidateSetting.class) {
        if (oldVal != AutoValidateSetting.NOTHING) {
            newVal = AutoValidateSetting.NOTHING;
        } else {
            newVal = AutoValidateSetting.SERP_CORRECTABLE;
        }
    } else if (property.getPropertyType() == Point.class) {
        if (oldVal == null) {
            newVal = new Point(0, 0);
        } else {
            newVal = new Point(((Point) oldVal).x + 1, ((Point) oldVal).y + 1);
        }
    } else {
        throw new RuntimeException("This test case lacks a value for " + property.getName() + " (type "
                + property.getPropertyType().getName() + ") from " + mmo.getClass());
    }

    if (newVal instanceof MatchMakerObject) {
        ((MatchMakerObject) newVal).setSession(session);
    }
    return newVal;
}

From source file:de.btobastian.javacord.entities.permissions.impl.ImplRole.java

@Override
public Future<Void> update(String name, Color color, boolean hoist, Permissions permissions) {
    if (name == null) {
        name = getName();//  w  w w. j a  va2s.  co  m
    }
    if (color == null) {
        color = getColor();
    }
    if (permissions == null) {
        permissions = getPermissions();
    }
    return update(name, color.getRGB(), hoist, ((ImplPermissions) permissions).getAllowed());
}

From source file:org.wings.plaf.css.Utils.java

/**
 * writes the given java.awt.Color to the device. Speed optimized;
 * character conversion avoided.//from ww  w.jav a  2s .c o m
 */
public static void write(final Device d, final Color c) throws IOException {
    d.print('#');
    int rgb = (c == null) ? 0 : c.getRGB();
    int mask = 0xf00000;
    for (int bitPos = 20; bitPos >= 0; bitPos -= 4) {
        d.print(hexDigits[(rgb & mask) >>> bitPos]);
        mask >>>= 4;
    }
}

From source file:net.rptools.lib.image.ImageUtil.java

public static BufferedImage createOutline(BufferedImage sourceImage, Color color) {
    if (sourceImage == null) {
        return null;
    }/* www.  j  a va2 s.co  m*/
    BufferedImage image = new BufferedImage(sourceImage.getWidth() + 2, sourceImage.getHeight() + 2,
            Transparency.BITMASK);

    for (int row = 0; row < image.getHeight(); row++) {
        for (int col = 0; col < image.getWidth(); col++) {
            int sourceX = col - 1;
            int sourceY = row - 1;

            // Pixel under current location
            if (sourceX >= 0 && sourceY >= 0 && sourceX <= sourceImage.getWidth() - 1
                    && sourceY <= sourceImage.getHeight() - 1) {
                int sourcePixel = sourceImage.getRGB(sourceX, sourceY);
                if (sourcePixel >> 24 != 0) {
                    // Not an empty pixel, don't overwrite it
                    continue;
                }
            }
            for (int i = 0; i < outlineNeighborMap.length; i++) {
                int[] neighbor = outlineNeighborMap[i];
                int x = sourceX + neighbor[0];
                int y = sourceY + neighbor[1];

                if (x >= 0 && y >= 0 && x <= sourceImage.getWidth() - 1 && y <= sourceImage.getHeight() - 1) {
                    if ((sourceImage.getRGB(x, y) >> 24) != 0) {
                        image.setRGB(col, row, color.getRGB());
                        break;
                    }
                }
            }
        }
    }
    return image;
}

From source file:com.t3.image.ImageUtil.java

public static BufferedImage createOutline(BufferedImage sourceImage, Color color) {
    if (sourceImage == null) {
        return null;
    }/*from  ww w . j  av a 2 s  .c om*/

    BufferedImage image = new BufferedImage(sourceImage.getWidth() + 2, sourceImage.getHeight() + 2,
            Transparency.BITMASK);

    for (int row = 0; row < image.getHeight(); row++) {
        for (int col = 0; col < image.getWidth(); col++) {

            int sourceX = col - 1;
            int sourceY = row - 1;

            // Pixel under current location
            if (sourceX >= 0 && sourceY >= 0 && sourceX <= sourceImage.getWidth() - 1
                    && sourceY <= sourceImage.getHeight() - 1) {
                int sourcePixel = sourceImage.getRGB(sourceX, sourceY);
                if (sourcePixel >> 24 != 0) {
                    // Not an empty pixel, don't overwrite it
                    continue;
                }
            }

            for (int i = 0; i < outlineNeighborMap.length; i++) {
                int[] neighbor = outlineNeighborMap[i];
                int x = sourceX + neighbor[0];
                int y = sourceY + neighbor[1];

                if (x >= 0 && y >= 0 && x <= sourceImage.getWidth() - 1 && y <= sourceImage.getHeight() - 1) {
                    if ((sourceImage.getRGB(x, y) >> 24) != 0) {
                        image.setRGB(col, row, color.getRGB());
                        break;
                    }

                }
            }
        }
    }

    return image;
}

From source file:org.apache.myfaces.custom.roundeddiv.HtmlRoundedDivRenderer.java

/**
 * Convert a color to an HTML style color (i.e. FFFFFF)
 * /*from   w w  w . jav a2s .  co  m*/
 * @param c The color
 * @return Color as hexidemal representation
 */
protected String colorToHtml(Color c) {
    int rbg = c.getRGB();
    String[] strs = { Integer.toHexString((rbg >> 16) & 0xFF), Integer.toHexString((rbg >> 8) & 0xFF),
            Integer.toHexString(rbg & 0xFF) };

    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < strs.length; i++) {
        if (strs[i].length() == 1) {
            sb.append('0');
        }
        sb.append(strs[i]);
    }
    return sb.toString();
}

From source file:FormularioGuardarEstudio.java

private void ejecutarInsertQuery(Estudio estudio, String base64, int[][] histogramaArray, Color colorPromedio,
        Connection connection) throws SQLException {

    Statement statement = connection.createStatement();
    String histograma = Histograma.parsearHistograma(histogramaArray);

    Integer idPaciente = ((Paciente) pacientesCombo.getSelectedItem()).getId();

    String sql = "INSERT INTO imagenes_filtradas (Nombre,Imagen,Histograma,Descripcion,Notas,Id_Paciente) "
            + "VALUES ('" + estudio.getNombre() + "','" + base64 + "',('" + estudio.getNombre() + "_histograma"
            + "','" + histograma + "', " + colorPromedio.getRGB() + "), '" + estudio.getDescripcion() + "','"
            + estudio.getNotas() + "'," + idPaciente + ");";
    statement.executeUpdate(sql);//from   w  w  w .j  a v  a2 s  .  co  m

    mostrarMensaje("Se guardo el estudio", Color.BLUE);

    statement.close();
    connection.close();
}

From source file:org.openstreetmap.josm.tools.Utils.java

/**
 * convert Color to String/*w  w  w.  j a  v a 2  s  .  co m*/
 * (Color.toString() omits alpha value)
 * @param c the color
 * @return the String representation, including alpha
 */
public static String toString(Color c) {
    if (c == null)
        return "null";
    if (c.getAlpha() == 255)
        return String.format("#%06x", c.getRGB() & 0x00ffffff);
    else
        return String.format("#%06x(alpha=%d)", c.getRGB() & 0x00ffffff, c.getAlpha());
}

From source file:openlr.mapviewer.properties.MapViewerProperties.java

/**
 * Convenience method that sets a color property value from the given
 * {@link Color} object./*ww  w  .ja va  2 s .com*/
 * 
 * @param key
 *            The property key.
 * @param value
 *            The color value for this property.
 */
public final void setColorProperty(final String key, final Color value) {
    String rgb = Integer.toHexString(value.getRGB());
    rgb = rgb.substring(2, rgb.length());
    setProperty(key, "#" + rgb);
}