Skip to content

Commit

Permalink
Merge pull request HanSolo#12 from gcauchis/master
Browse files Browse the repository at this point in the history
Add possibility to customize the gauge type
  • Loading branch information
Gerrit Grunwald committed Apr 20, 2015
2 parents 973d657 + 7eaf758 commit c2f7b45
Show file tree
Hide file tree
Showing 11 changed files with 417 additions and 204 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/target/
/.idea/
/SteelSeries.iml
/SteelSeries.iml
.classpath
.project
.settings/
55 changes: 40 additions & 15 deletions src/main/java/eu/hansolo/steelseries/gauges/AbstractRadial.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import eu.hansolo.steelseries.tools.ColorDef;
import eu.hansolo.steelseries.tools.ConicalGradientPaint;
import eu.hansolo.steelseries.tools.CustomColorDef;
import eu.hansolo.steelseries.tools.CustomGaugeType;
import eu.hansolo.steelseries.tools.Direction;
import eu.hansolo.steelseries.tools.ForegroundType;
import eu.hansolo.steelseries.tools.FrameType;
Expand All @@ -43,16 +44,7 @@
import eu.hansolo.steelseries.tools.PostPosition;
import eu.hansolo.steelseries.tools.TicklabelOrientation;
import eu.hansolo.steelseries.tools.Util;
import org.pushingpixels.trident.Timeline;
import org.pushingpixels.trident.TimelineScenario;
import org.pushingpixels.trident.callback.TimelineCallback;
import org.pushingpixels.trident.ease.Sine;
import org.pushingpixels.trident.ease.Spline;
import org.pushingpixels.trident.ease.TimelineEase;

import javax.swing.SwingConstants;
import javax.swing.Timer;
import javax.swing.border.Border;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Container;
Expand Down Expand Up @@ -81,6 +73,17 @@
import java.util.Arrays;
import java.util.List;

import javax.swing.SwingConstants;
import javax.swing.Timer;
import javax.swing.border.Border;

import org.pushingpixels.trident.Timeline;
import org.pushingpixels.trident.TimelineScenario;
import org.pushingpixels.trident.callback.TimelineCallback;
import org.pushingpixels.trident.ease.Sine;
import org.pushingpixels.trident.ease.Spline;
import org.pushingpixels.trident.ease.TimelineEase;


/**
*
Expand Down Expand Up @@ -152,22 +155,44 @@ public AbstractRadial() {
// <editor-fold defaultstate="collapsed" desc="Getters and Setters">
/**
* Returns the enum that defines the type of the gauge
* FG_TYPE1 a quarter gauge (90 deg)
* FG_TYPE2 a two quarter gauge (180 deg)
* FG_TYPE3 a three quarter gauge (270 deg)
* TYPE1 a quarter gauge (90 deg)
* TYPE2 a two quarter gauge (180 deg)
* TYPE3 a three quarter gauge (270 deg)
* TYPE4 a four quarter gauge (300 deg)
* CUSTOM see {@link #getCustomGaugeType() getCustomGaugeType}
* @return the type of the gauge (90, 180, 270 or 300 deg)
*/
public GaugeType getGaugeType() {
return getModel().getGaugeType();
}

/**
* Returns the custom type of the radial gauge.
* @return the custom type of the radial gauge.
*/
public CustomGaugeType getCustomGaugeType() {
return getModel().getCustomGaugeType();
}

/**
* Sets the custom radial type of the gauge.
* Set the gauge type to {@link GaugeType#CUSTOM CUSTOM}.
* @param CUSTOM_GAUGE_TYPE
*/
public void setCustomGaugeType(CustomGaugeType CUSTOM_GAUGE_TYPE)
{
getModel().setCustomGaugeType(CUSTOM_GAUGE_TYPE);
init(getInnerBounds().width, getInnerBounds().height);
repaint(getInnerBounds());
}

/**
* Sets the type of the gauge
* FG_TYPE1 a quarter gauge (90 deg)
* FG_TYPE2 a two quarter gauge (180 deg)
* FG_TYPE3 a three quarter gauge (270 deg)
* TYPE1 a quarter gauge (90 deg)
* TYPE2 a two quarter gauge (180 deg)
* TYPE3 a three quarter gauge (270 deg)
* TYPE4 a four quarter gauge (300 deg)
* CUSTOM set the {@link #setCustomGaugeType(CustomGaugeType) custom gauge type}.
* @param GAUGE_TYPE
*/
public void setGaugeType(final GaugeType GAUGE_TYPE) {
Expand Down
29 changes: 15 additions & 14 deletions src/main/java/eu/hansolo/steelseries/gauges/Radial.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public final AbstractGauge init(final int WIDTH, final int HEIGHT) {
}

if (getPostsVisible()) {
createPostsImage(GAUGE_WIDTH, fImage, getGaugeType().POST_POSITIONS);
createPostsImage(GAUGE_WIDTH, fImage, getModel().getPostPosition());
} else {
createPostsImage(GAUGE_WIDTH, fImage, new PostPosition[]{PostPosition.CENTER});
}
Expand Down Expand Up @@ -230,6 +230,7 @@ public final AbstractGauge init(final int WIDTH, final int HEIGHT) {
getModel().getMinorTickSpacing(),
getModel().getMajorTickSpacing(),
getGaugeType(),
getCustomGaugeType(),
getMinorTickmarkType(),
getMajorTickmarkType(),
isTickmarksVisible(),
Expand Down Expand Up @@ -258,15 +259,15 @@ public final AbstractGauge init(final int WIDTH, final int HEIGHT) {

if (isLcdVisible()) {
if (isLcdBackgroundVisible()) {
createLcdImage(new Rectangle2D.Double(((getGaugeBounds().width - GAUGE_WIDTH * getGaugeType().LCD_FACTORS.getX()) / 2.0),
(getGaugeBounds().height * getGaugeType().LCD_FACTORS.getY()),
(GAUGE_WIDTH * getGaugeType().LCD_FACTORS.getWidth()),
(GAUGE_WIDTH * getGaugeType().LCD_FACTORS.getHeight())),
createLcdImage(new Rectangle2D.Double(((getGaugeBounds().width - GAUGE_WIDTH * getModel().getLcdFactors().getX()) / 2.0),
(getGaugeBounds().height * getModel().getLcdFactors().getY()),
(GAUGE_WIDTH * getModel().getLcdFactors().getWidth()),
(GAUGE_WIDTH * getModel().getLcdFactors().getHeight())),
getLcdColor(),
getCustomLcdBackground(),
bImage);
}
LCD.setRect(((getGaugeBounds().width - GAUGE_WIDTH * getGaugeType().LCD_FACTORS.getX()) / 2.0), (getGaugeBounds().height * getGaugeType().LCD_FACTORS.getY()), GAUGE_WIDTH * getGaugeType().LCD_FACTORS.getWidth(), GAUGE_WIDTH * getGaugeType().LCD_FACTORS.getHeight());
LCD.setRect(((getGaugeBounds().width - GAUGE_WIDTH * getModel().getLcdFactors().getX()) / 2.0), (getGaugeBounds().height * getModel().getLcdFactors().getY()), GAUGE_WIDTH * getModel().getLcdFactors().getWidth(), GAUGE_WIDTH * getModel().getLcdFactors().getHeight());
lcdArea = new Area(LCD);

// Create the lcd threshold indicator image
Expand Down Expand Up @@ -629,9 +630,9 @@ private void createAreas(final BufferedImage IMAGE) {
if (bImage != null) {
final double ANGLE_STEP;
if (!isLogScale()) {
ANGLE_STEP = Math.toDegrees(getGaugeType().ANGLE_RANGE) / (getMaxValue() - getMinValue());
ANGLE_STEP = Math.toDegrees(getModel().getAngleRange()) / (getMaxValue() - getMinValue());
} else {
ANGLE_STEP = Math.toDegrees(getGaugeType().ANGLE_RANGE) / UTIL.logOfBase(BASE, (getMaxValue() - getMinValue()));
ANGLE_STEP = Math.toDegrees(getModel().getAngleRange()) / UTIL.logOfBase(BASE, (getMaxValue() - getMinValue()));
}

if (bImage != null && !getAreas().isEmpty()) {
Expand All @@ -646,9 +647,9 @@ private void createAreas(final BufferedImage IMAGE) {
final Rectangle2D AREA_FRAME = new Rectangle2D.Double(bImage.getMinX() + FREE_AREA, bImage.getMinY() + FREE_AREA, 2 * RADIUS, 2 * RADIUS);
for (Section area : getAreas()) {
if (!isLogScale()) {
area.setFilledArea(new Arc2D.Double(AREA_FRAME, getGaugeType().ORIGIN_CORRECTION - (area.getStart() * ANGLE_STEP) + (getMinValue() * ANGLE_STEP), -(area.getStop() - area.getStart()) * ANGLE_STEP, Arc2D.PIE));
area.setFilledArea(new Arc2D.Double(AREA_FRAME, getModel().getOriginCorrection() - (area.getStart() * ANGLE_STEP) + (getMinValue() * ANGLE_STEP), -(area.getStop() - area.getStart()) * ANGLE_STEP, Arc2D.PIE));
} else {
area.setFilledArea(new Arc2D.Double(AREA_FRAME, getGaugeType().ORIGIN_CORRECTION - (UTIL.logOfBase(BASE, area.getStart()) * ANGLE_STEP) + (UTIL.logOfBase(BASE, getMinValue()) * ANGLE_STEP), -UTIL.logOfBase(BASE, area.getStop() - area.getStart()) * ANGLE_STEP, Arc2D.PIE));
area.setFilledArea(new Arc2D.Double(AREA_FRAME, getModel().getOriginCorrection() - (UTIL.logOfBase(BASE, area.getStart()) * ANGLE_STEP) + (UTIL.logOfBase(BASE, getMinValue()) * ANGLE_STEP), -UTIL.logOfBase(BASE, area.getStop() - area.getStart()) * ANGLE_STEP, Arc2D.PIE));
}
}
}
Expand Down Expand Up @@ -676,9 +677,9 @@ private void createSections(final BufferedImage IMAGE) {
if (bImage != null) {
final double ANGLE_STEP;
if (!isLogScale()) {
ANGLE_STEP = getGaugeType().APEX_ANGLE / (getMaxValue() - getMinValue());
ANGLE_STEP = getModel().getApexAngle() / (getMaxValue() - getMinValue());
} else {
ANGLE_STEP = getGaugeType().APEX_ANGLE / UTIL.logOfBase(BASE, getMaxValue() - getMinValue());
ANGLE_STEP = getModel().getApexAngle() / UTIL.logOfBase(BASE, getMaxValue() - getMinValue());
}

final double OUTER_RADIUS = bImage.getWidth() * 0.38f;
Expand All @@ -692,10 +693,10 @@ private void createSections(final BufferedImage IMAGE) {
final double ANGLE_EXTEND;

if (!isLogScale()) {
ANGLE_START = getGaugeType().ORIGIN_CORRECTION - (section.getStart() * ANGLE_STEP) + (getMinValue() * ANGLE_STEP);
ANGLE_START = getModel().getOriginCorrection() - (section.getStart() * ANGLE_STEP) + (getMinValue() * ANGLE_STEP);
ANGLE_EXTEND = -(section.getStop() - section.getStart()) * ANGLE_STEP;
} else {
ANGLE_START = getGaugeType().ORIGIN_CORRECTION - (UTIL.logOfBase(BASE, section.getStart())) * ANGLE_STEP + (UTIL.logOfBase(BASE, getMinValue())) * ANGLE_STEP;
ANGLE_START = getModel().getOriginCorrection() - (UTIL.logOfBase(BASE, section.getStart())) * ANGLE_STEP + (UTIL.logOfBase(BASE, getMinValue())) * ANGLE_STEP;
ANGLE_EXTEND = -UTIL.logOfBase(BASE, section.getStop() - section.getStart()) * ANGLE_STEP;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ public final AbstractGauge init(final int WIDTH, final int HEIGHT) {
getModel().getMinorTickSpacing(),
getModel().getMajorTickSpacing(),
getGaugeType(),
getCustomGaugeType(),
getMinorTickmarkType(),
getMajorTickmarkType(),
isTickmarksVisible(),
Expand Down
25 changes: 13 additions & 12 deletions src/main/java/eu/hansolo/steelseries/gauges/Radial1Vertical.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ public final AbstractGauge init(final int WIDTH, final int HEIGHT) {
getModel().getMinorTickSpacing(),
getModel().getMajorTickSpacing(),
getGaugeType(),
getCustomGaugeType(),
getMinorTickmarkType(),
getMajorTickmarkType(),
isTickmarksVisible(),
Expand Down Expand Up @@ -412,9 +413,9 @@ protected void paintComponent(Graphics g) {
// Draw threshold indicator
if (isThresholdVisible()) {
if (!isLogScale()) {
G2.rotate(getGaugeType().ROTATION_OFFSET + (getThreshold() - getMinValue()) * getAngleStep(), CENTER.getX(), getGaugeBounds().width * 0.7336448598);
G2.rotate(getRotationOffset() + (getThreshold() - getMinValue()) * getAngleStep(), CENTER.getX(), getGaugeBounds().width * 0.7336448598);
} else {
G2.rotate(getGaugeType().ROTATION_OFFSET + UTIL.logOfBase(BASE, getThreshold() - getMinValue()) * getLogAngleStep(), CENTER.getX(), getGaugeBounds().width * 0.7336448598);
G2.rotate(getRotationOffset() + UTIL.logOfBase(BASE, getThreshold() - getMinValue()) * getLogAngleStep(), CENTER.getX(), getGaugeBounds().width * 0.7336448598);
}
G2.drawImage(thresholdImage, 0, 0, null);
G2.setTransform(FORMER_TRANSFORM);
Expand All @@ -423,9 +424,9 @@ protected void paintComponent(Graphics g) {
// Draw min measured value indicator
if (isMinMeasuredValueVisible()) {
if (!isLogScale()) {
G2.rotate(getGaugeType().ROTATION_OFFSET + (getMinMeasuredValue() - getMinValue()) * getAngleStep(), CENTER.getX(), getGaugeBounds().width * 0.7336448598);
G2.rotate(getRotationOffset() + (getMinMeasuredValue() - getMinValue()) * getAngleStep(), CENTER.getX(), getGaugeBounds().width * 0.7336448598);
} else {
G2.rotate(getGaugeType().ROTATION_OFFSET + UTIL.logOfBase(BASE, getMinMeasuredValue() - getMinValue()) * getLogAngleStep(), CENTER.getX(), getGaugeBounds().width * 0.7336448598);
G2.rotate(getRotationOffset() + UTIL.logOfBase(BASE, getMinMeasuredValue() - getMinValue()) * getLogAngleStep(), CENTER.getX(), getGaugeBounds().width * 0.7336448598);
}
G2.drawImage(minMeasuredImage, 0, 0, null);
G2.setTransform(FORMER_TRANSFORM);
Expand All @@ -434,9 +435,9 @@ protected void paintComponent(Graphics g) {
// Draw max measured value indicator
if (isMaxMeasuredValueVisible()) {
if (!isLogScale()) {
G2.rotate(getGaugeType().ROTATION_OFFSET + (getMaxMeasuredValue() - getMinValue()) * getAngleStep(), CENTER.getX(), getGaugeBounds().width * 0.7336448598);
G2.rotate(getRotationOffset() + (getMaxMeasuredValue() - getMinValue()) * getAngleStep(), CENTER.getX(), getGaugeBounds().width * 0.7336448598);
} else {
G2.rotate(getGaugeType().ROTATION_OFFSET + UTIL.logOfBase(BASE, getMaxMeasuredValue() - getMinValue()) * getLogAngleStep(), CENTER.getX(), getGaugeBounds().width * 0.7336448598);
G2.rotate(getRotationOffset() + UTIL.logOfBase(BASE, getMaxMeasuredValue() - getMinValue()) * getLogAngleStep(), CENTER.getX(), getGaugeBounds().width * 0.7336448598);
}
G2.drawImage(maxMeasuredImage, 0, 0, null);
G2.setTransform(FORMER_TRANSFORM);
Expand All @@ -458,9 +459,9 @@ protected void paintComponent(Graphics g) {

// Draw the pointer
if (!isLogScale()) {
angle = getGaugeType().ROTATION_OFFSET + (getValue() - getMinValue()) * getAngleStep();
angle = getRotationOffset() + (getValue() - getMinValue()) * getAngleStep();
} else {
angle = getGaugeType().ROTATION_OFFSET + UTIL.logOfBase(BASE, getValue() - getMinValue()) * getLogAngleStep();
angle = getRotationOffset() + UTIL.logOfBase(BASE, getValue() - getMinValue()) * getLogAngleStep();
}
//G2.rotate(ANGLE + (Math.cos(Math.toRadians(ANGLE - ROTATION_OFFSET - 91.5))), CENTER.getX(), backgroundImage.getHeight() * 0.7336448598);
G2.rotate(angle, CENTER.getX(), getGaugeBounds().height * 0.7336448598 + 2);
Expand Down Expand Up @@ -584,9 +585,9 @@ private void createAreas(final BufferedImage IMAGE) {

if (bImage != null) {
if (!isLogScale()) {
ANGLE_STEP = Math.toDegrees(getGaugeType().ANGLE_RANGE) / (getMaxValue() - getMinValue());
ANGLE_STEP = Math.toDegrees(getModel().getAngleRange()) / (getMaxValue() - getMinValue());
} else {
ANGLE_STEP = Math.toDegrees(getGaugeType().ANGLE_RANGE) / UTIL.logOfBase(BASE, getMaxValue() - getMinValue());
ANGLE_STEP = Math.toDegrees(getModel().getAngleRange()) / UTIL.logOfBase(BASE, getMaxValue() - getMinValue());
}

if (bImage != null && !getAreas().isEmpty()) {
Expand Down Expand Up @@ -662,9 +663,9 @@ private void createSections(final BufferedImage IMAGE) {

final double ANGLE_STEP;
if (!isLogScale()) {
ANGLE_STEP = getGaugeType().APEX_ANGLE / (getMaxValue() - getMinValue());
ANGLE_STEP = getModel().getApexAngle() / (getMaxValue() - getMinValue());
} else {
ANGLE_STEP = getGaugeType().APEX_ANGLE / UTIL.logOfBase(BASE, getMaxValue() - getMinValue());
ANGLE_STEP = getModel().getApexAngle() / UTIL.logOfBase(BASE, getMaxValue() - getMinValue());
}

final double OUTER_RADIUS = bImage.getWidth() * 0.44f;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/eu/hansolo/steelseries/gauges/Radial2Top.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import eu.hansolo.steelseries.tools.Section;
import eu.hansolo.steelseries.tools.Shadow;
import eu.hansolo.steelseries.tools.Util;

import java.awt.AlphaComposite;
import java.awt.BasicStroke;
import java.awt.Color;
Expand Down Expand Up @@ -207,6 +208,7 @@ public final AbstractGauge init(final int WIDTH, final int HEIGHT) {
getModel().getMinorTickSpacing(),
getModel().getMajorTickSpacing(),
getGaugeType(),
getCustomGaugeType(),
getMinorTickmarkType(),
getMajorTickmarkType(),
isTickmarksVisible(),
Expand Down
Loading

0 comments on commit c2f7b45

Please sign in to comment.