Saturday, October 2, 2010

Short note about custom backgrounds...

This post will be a short info about how to add a custom background paint to the gauges in the steelseries library.


We are talking about steel...right ? Because we have circular gauges in the library i had the idea to use the ConicalGradientPaint (that you could find in eu.hansolo.steelseries.tools) to create a round stainless steel background for a radial gauge.


The result will look like this...






That looks interesting and here is a really short description on how to achieve this...



// Create radial gauge
Radial4Lcd radialGauge = new Radial4Lcd();

// Set the black metal frame    radialGauge.setFrameDesign(eu.hansolo.steelseries.tools.FrameDesign.BLACK_METAL);
 

// Enable the usage of a custom background paint
radialGauge.setBackgroundColorFromTheme(false);       
         

// Set the title and unit string color to a custom color
radialGauge.setLabelColorFromTheme(false); 
radialGauge.setLabelColor(java.awt.Color.BLACK);       
         

// Set the tickmarks with their labels to a custom color 
radialGauge.setTickmarkColorFromTheme(false); 
radialGauge.setTickmarkColor(java.awt.Color.BLACK);
 

// Define the center of the gauge 
final java.awt.geom.Point2D CENTER = radialGauge.getCenter();       
 

// Define the fractions of the concial gradient paint 
final float[] STAINLESS_FRACTIONS =  
{
    0f,
    0.03f,
    0.10f,
    0.14f,
    0.24f,
    0.33f,
    0.38f,
    0.5f,
    0.62f,
    0.67f,
    0.76f,
    0.81f,
    0.85f,
    0.97f,
    1.0f 

};
 

// Define the colors of the conical gradient paint 
final java.awt.Color[] STAINLESS_COLORS = 
{ 
    new java.awt.Color(0xFDFDFD),
    new java.awt.Color(0xFDFDFD),
    new java.awt.Color(0xB2B2B4),
    new java.awt.Color(0xACACAE),
    new java.awt.Color(0xFDFDFD),
    new java.awt.Color(0x6E6E70),
    new java.awt.Color(0x6E6E70),
    new java.awt.Color(0xFDFDFD),
    new java.awt.Color(0x6E6E70),
    new java.awt.Color(0x6E6E70),
    new java.awt.Color(0xFDFDFD),
    new java.awt.Color(0xACACAE),
    new java.awt.Color(0xB2B2B4),
    new java.awt.Color(0xFDFDFD),
    new java.awt.Color(0xFDFDFD) 

};
 

// Define the conical gradient paint 
ConicalGradientPaint STAINLESS_GRADIENT = 
    new ConicalGradientPaint(false
                             CENTER, 
                             -0.45f
                             STAINLESS_FRACTIONS, 
                             STAINLESS_COLORS);
 

// Set the conical gradient paint on the radial gauge 
radialGauge.setCustomBackground(STAINLESS_GRADIENT);




If you use a gui builder like Mattisse in Netbeans you could set the attributes like tickmarkcolor, labelcolor and framedesign there and you only have to create and apply the ConicalGradientPaint in your code.


Would be interesting to see other custom backgrounds too, so if you have something to share...please let me know...


Enjoy coding Java Swing...




3 comments:

  1. Hi Gerrit Grunwald,

    can you post a whole source code of one example ?

    because i have problems to implement the project in my eclipse ... i have include the steelseries.jar and import the packages but i become every errors like ...

    radialGauge.setFrameDesign(eu.hansolo.steelseries.tools.FrameDesign.BLACK_METAL);

    the object radialGauge cant use the method setFrameDesign because the class Radial4Lcd
    dont have this method ...

    i hope this is not a stupid question but i am a beginner in java

    My Email: java_ado@hotmail.com

    Thank you

    ReplyDelete
  2. Hi there,

    I tried it directly in eclipse and it worked out fine, here's the code that i used:

    public class Main extends javax.swing.JFrame
    {
    public static void main(String[] args)
    {
    Main app = new Main();
    app.init();
    app.setSize(400, 400);
    app.setVisible(true);
    }

    private void init()
    {
    final eu.hansolo.steelseries.gauges.Radial4Lcd RADIAL = new eu.hansolo.steelseries.gauges.Radial4Lcd();

    RADIAL.setFrameDesign(eu.hansolo.steelseries.tools.FrameDesign.BLACK_METAL);
    add(RADIAL);
    }
    }


    Keep in mind that you not only have to add the SteelSeries.jar but also the Trident.jar to get it running...

    I hope that was of help for you...

    ReplyDelete
  3. Thx Han.Solo ... i have forget to include the
    " Trident.jar " now it works fine

    ReplyDelete