Friday, October 29, 2010

Custom steel

This is a short post about how to customize a steelseries gauge.

Therefor i choosed a Radial2 component that has a standard look like this...





Step 1:
Disable the frame by setting the frameVisible property:


gauge.setFrameVisible(false);


Step 2:
Disable the foreground by setting the foregroundVisible property:


gauge.setForegroundVisible(false);

Step 3:
Set the backgroundColor to TRANSPARENT:


gauge.setBackgroundColor(TRANSPARENT);
Attention:
So you will also find a property backgroundVisible which will disable the painting of the backgroundImage. If you use this one you won't also see the custom layer and custom background because they will be painted in the backgroundImage.


Step 4:
Create a image in a drawing program of your choice. Use the same size that your gauge has (otherwise your image will be scaled to the size of the gauge which could lead to quality loss due to scaling).





Step 5: 
Apply your image to the gauge. I usually add the images to a package named resources and load them from there but you might want to load the image from another place. The following code is just a example:



// Add the following code to your initialization area
BufferedImage customLayer;
try
{
    customLayer = ImageIO.read(getClass().getResource("/resource/CustomLayer.png"));
}
catch (IOException exception)
{
    customLayer = null;
}

// Add the following code somewhere after the gauge was initialized
if (customLayer != null)
{
    gauge.setCustomLayer(customLayer);
}

// Add the following code e.g. to a ActionListener of a button
gauge.setCustomLayerVisible(true);
 


With the given code your result will look like this...




 Looks funny right...



2 comments:

  1. Was your MacBook in repair when you created this component? Nice JUG Razoblade gauge btw :-P

    ReplyDelete
  2. hello

    I'm newbie in java so I still don't understand how to use the library in my code. for example I want to make compass, I use netbean, I have wrote code but nothing view. here my code. can you give my some example code? thx

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    package javaapplication3;

    import eu.hansolo.steelseries.extras.Compass;
    import java.awt.image.BufferedImage;
    import java.io.IOException;
    import javax.imageio.ImageIO;


    /**
    *
    * @author aang
    */
    public class Main {

    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) {
    // TODO code application logic here

    Compass kompas = new Compass();

    BufferedImage gambar;

    try
    {
    gambar = ImageIO.read(new java.io.File("logo.png"));
    }
    catch (IOException exception)
    {
    gambar = null;
    }

    kompas.setValue(100);
    kompas.setTitle("Kompas");


    }

    }

    ReplyDelete