Java源码示例:eu.hansolo.medusa.Gauge

示例1
@Override public void start(Stage stage) {
    StackPane pane = new StackPane(gauge);
    pane.setPadding(new Insets(20));
    pane.setBackground(new Background(new BackgroundFill(Gauge.DARK_COLOR, CornerRadii.EMPTY, Insets.EMPTY)));

    Scene scene = new Scene(pane);

    stage.setTitle("Medusa MultiGauge");
    stage.setScene(scene);
    stage.show();

    timer.start();

    // Calculate number of nodes
    calcNoOfNodes(pane);
    System.out.println(noOfNodes + " Nodes in SceneGraph");
}
 
示例2
public Slim1Skin(Gauge gauge) {
    super(gauge);
    if (gauge.isAutoScale()) gauge.calcAutoScale();
    minValue             = gauge.getMinValue();
    range                = gauge.getRange();
    angleStep            = ANGLE_RANGE / range;
    colorGradientEnabled = gauge.isGradientBarEnabled();
    noOfGradientStops    = gauge.getGradientBarStops().size();
    sectionsVisible      = gauge.getSectionsVisible();
    sections             = gauge.getSections();
    currentValueListener = o -> setBar(gauge.getCurrentValue());

    initGraphics();
    registerListeners();

    setBar(gauge.getCurrentValue());
}
 
示例3
public InteractiveGaugeSkin(Gauge gauge) {
    super(gauge);
    if (gauge.isAutoScale()) gauge.calcAutoScale();
    startAngle        = gauge.getStartAngle();
    angleRange        = gauge.getAngleRange();
    angleStep         = gauge.getAngleStep();
    oldValue          = gauge.getValue();
    minValue          = gauge.getMinValue();
    maxValue          = gauge.getMaxValue();
    formatString      = new StringBuilder("%.").append(Integer.toString(gauge.getDecimals())).append("f").toString();
    locale            = gauge.getLocale();
    sections          = gauge.getSections();
    highlightSections = gauge.isHighlightSections();
    sectionsVisible   = gauge.getSectionsVisible();
    areas             = gauge.getAreas();
    highlightAreas    = gauge.isHighlightAreas();
    areasVisible      = gauge.getAreasVisible();
    tickLabelLocation = gauge.getTickLabelLocation();
    scaleDirection    = gauge.getScaleDirection();
    needleBehavior    = gauge.getNeedleBehavior();
    mouseHandler      = event -> handleMouseEvent(event);
    updateMarkers();

    initGraphics();
    registerListeners();
}
 
示例4
private VBox getVBox(final String TEXT, final Color COLOR, final Gauge GAUGE) {
    Rectangle bar = new Rectangle(200, 3);
    bar.setArcWidth(6);
    bar.setArcHeight(6);
    bar.setFill(COLOR);

    Label label = new Label(TEXT);
    label.setTextFill(COLOR);
    label.setAlignment(Pos.CENTER);
    label.setPadding(new Insets(0, 0, 10, 0));

    GAUGE.setBarColor(COLOR);

    VBox vBox = new VBox(bar, label, GAUGE);
    vBox.setSpacing(3);
    vBox.setAlignment(Pos.CENTER);
    return vBox;
}
 
示例5
public CustomGaugeSkin(Gauge gauge) {
    super(gauge);
    if (gauge.isAutoScale()) gauge.calcAutoScale();
    range              = gauge.getRange();
    stepSize           = NO_OF_LEDS / range;
    barBackgroundColor = gauge.getBarBackgroundColor();
    barColor           = gauge.getBarColor();
    sectionsVisible    = gauge.getSectionsVisible();
    sections           = gauge.getSections();
    ledSize            = PREFERRED_WIDTH * 0.5;
    ledSpacer          = PREFERRED_WIDTH * 0.05;
    ledBorder          = PREFERRED_WIDTH * 0.25;

    init();
    initGraphics();
    registerListeners();
}
 
示例6
public void calcAutoScale(final Gauge gauge) {
    double maxNoOfMajorTicks = 10;
    double maxNoOfMinorTicks = 10;
    double niceRange         = Helper.calcNiceNumber(gauge.getRange(), false);
    double majorTickSpace    = Helper.calcNiceNumber(niceRange / (maxNoOfMajorTicks - 1), true);
    double niceMinValue      = (Math.floor(gauge.getMinValue() / gauge.getMajorTickSpace()) * gauge.getMajorTickSpace());
    double niceMaxValue      = (Math.ceil(gauge.getMaxValue() / gauge.getMajorTickSpace()) * gauge.getMajorTickSpace());
    double minorTickSpace    = Helper.calcNiceNumber(majorTickSpace / (maxNoOfMinorTicks - 1), true);

    System.out.println("minorTickSpace: " + minorTickSpace);
    System.out.println("majorTickSpace: " + majorTickSpace);

    System.out.println("min           : " + gauge.getMinValue());
    System.out.println("max           : " + gauge.getMaxValue());

    System.out.println("nice min value: " + niceMinValue);
    System.out.println("nice max value: " + niceMaxValue);
    System.out.println("niceRange     : " + niceRange);
}
 
示例7
private HBox getHBox(final String TEXT, final Gauge GAUGE) {
    Label label = new Label(TEXT);
    label.setPrefWidth(150);
    label.setFont(Font.font(26));
    label.setTextFill(MaterialDesign.GREY_800.get());
    label.setAlignment(Pos.CENTER_LEFT);
    label.setPadding(new Insets(0, 10, 0, 0));

    GAUGE.setBarBackgroundColor(Color.rgb(232, 231, 223));
    GAUGE.setAnimated(true);
    GAUGE.setAnimationDuration(1000);

    HBox hBox = new HBox(label, GAUGE);
    hBox.setSpacing(20);
    hBox.setAlignment(Pos.CENTER_LEFT);
    return hBox;
}
 
示例8
@Override public void start(Stage stage) {
    Pane pane = new Pane(bigGauge, smallGauge);
    pane.setBackground(new Background(new BackgroundFill(Gauge.DARK_COLOR, CornerRadii.EMPTY, Insets.EMPTY)));
    bigGauge.relocate(0, 0);
    smallGauge.relocate(0, 230);

    Scene scene = new Scene(pane);

    stage.setScene(scene);
    stage.show();

    timer.start();

    // Calculate number of nodes
    calcNoOfNodes(pane);
    System.out.println(noOfNodes + " Nodes in SceneGraph");
}
 
示例9
@Override public void start(Stage stage) {
    HBox pane = new HBox(gauge0, gauge1, gauge2, gauge3, gauge4, gauge5, gauge6, gauge7, gauge8, gauge9);
    pane.setBackground(new Background(new BackgroundFill(Gauge.DARK_COLOR, CornerRadii.EMPTY, Insets.EMPTY)));
    pane.setPadding(new Insets(10));
    pane.setPrefWidth(400);

    Scene scene = new Scene(pane);

    stage.setTitle("Medusa Custom Gauge Skin");
    stage.setScene(scene);
    stage.show();

    timer.start();

    // Calculate number of nodes
    calcNoOfNodes(pane);
    System.out.println(noOfNodes + " Nodes in SceneGraph");
}
 
示例10
private Gauge createBar() {
    Gauge gauge = GaugeBuilder.create()
                              .backgroundPaint(Gauge.DARK_COLOR)
                              .barBackgroundColor(Color.DARKRED)
                              .barColor(Color.RED)
                              .minValue(0)
                              .maxValue(100)
                              .sectionsVisible(true)
                              .sections(new Section(0, 70, Color.LIME),
                                        new Section(70,85, Color.YELLOW),
                                        new Section(85, 100, Color.RED))
                              .build();

    gauge.setSkin(new CustomGaugeSkin(gauge));
    return gauge;
}
 
示例11
public BulletChartSkin(Gauge gauge) {
    super(gauge);
    if (gauge.isAutoScale()) gauge.calcAutoScale();
    orientation              = gauge.getOrientation();
    barTooltip               = new Tooltip();
    thresholdTooltip         = new Tooltip();
    sectionListener          = c -> redraw();
    markerListener           = c -> redraw();
    currentValueListener     = o -> updateBar();
    paneSizeListener         = o -> handleEvents("RESIZE");

    if (Orientation.VERTICAL == orientation) {
        preferredWidth  = 64;
        preferredHeight = 400;
    } else {
        preferredWidth  = 400;
        preferredHeight = 64;
    }
    gauge.setPrefSize(preferredWidth, preferredHeight);

    initGraphics();
    registerListeners();
}
 
示例12
public PlainAmpSkin(Gauge gauge) {
    super(gauge);
    if (gauge.isAutoScale()) gauge.calcAutoScale();
    angleStep            = gauge.getAngleRange() / gauge.getRange();
    oldValue             = gauge.getValue();
    formatString         = new StringBuilder("%.").append(Integer.toString(gauge.getDecimals())).append("f").toString();
    locale               = gauge.getLocale();
    sectionListener      = c -> redraw();
    currentValueListener = o -> rotateNeedle();
    needleRotateListener = o -> handleEvents("ANGLE");
    markerListener       = c -> {
        updateMarkers();
        redraw();
    };

    updateMarkers();

    initGraphics();
    registerListeners();
}
 
示例13
public SimpleDigitalSkin(Gauge gauge) {
    super(gauge);
    if (gauge.isAutoScale()) gauge.calcAutoScale();
    minValue             = gauge.getMinValue();
    maxValue             = gauge.getMaxValue();
    range                = gauge.getRange();
    angleStep            = ANGLE_RANGE / range;
    barBackgroundColor   = gauge.getBarBackgroundColor();
    barColor             = gauge.getBarColor();
    valueColor           = gauge.getValueColor();
    unitColor            = gauge.getUnitColor();
    isStartFromZero      = gauge.isStartFromZero();
    sectionsVisible      = gauge.getSectionsVisible();
    sections             = gauge.getSections();
    thresholdVisible     = gauge.isThresholdVisible();
    thresholdColor       = gauge.getThresholdColor();
    decimalListener      = o -> handleEvents("DECIMALS");
    currentValueListener = o -> setBar(gauge.getCurrentValue());
    gradientNeedsRefresh = true;

    initGraphics();
    registerListeners();

    setBar(gauge.getCurrentValue());
}
 
示例14
public TileSparklineSkin(Gauge gauge) {
    super(gauge);
    if (gauge.isAutoScale()) gauge.calcAutoScale();
    low                  = gauge.getMaxValue();
    high                 = gauge.getMinValue();
    minValue             = gauge.getMinValue();
    maxValue             = gauge.getMaxValue();
    range                = gauge.getRange();
    stdDeviation         = 0;
    formatString         = new StringBuilder("%.").append(Integer.toString(gauge.getDecimals())).append("f").toString();
    locale               = gauge.getLocale();
    noOfDatapoints       = gauge.getAveragingPeriod();
    dataList             = new LinkedList<>();
    currentValueListener = o -> handleEvents("CURRENT_VALUE");
    averagingListener    = o -> handleEvents("AVERAGING_PERIOD");
    for (int i = 0; i < noOfDatapoints; i++) { dataList.add(minValue); }

    // To get smooth lines in the chart we need at least 4 values
    if (noOfDatapoints < 4) throw new IllegalArgumentException("Please increase the averaging period to a value larger than 3.");

    initGraphics();
    registerListeners();
}
 
示例15
public AmpSkin(Gauge gauge) {
    super(gauge);
    if (gauge.isAutoScale()) gauge.calcAutoScale();
    angleStep            = gauge.getAngleRange() / gauge.getRange();
    oldValue             = gauge.getValue();
    formatString         = new StringBuilder("%.").append(Integer.toString(gauge.getDecimals())).append("f").toString();
    locale               = gauge.getLocale();
    sectionListener      = c -> redraw();
    currentValueListener = o -> rotateNeedle();
    needleRotateListener = o -> handleEvents("ANGLE");
    markerListener       = c -> {
        updateMarkers();
        redraw();
    };

    updateMarkers();

    initGraphics();
    registerListeners();
}
 
示例16
public DashboardSkin(Gauge gauge) {
    super(gauge);
    if (gauge.isAutoScale()) gauge.calcAutoScale();
    range                = gauge.getRange();
    angleStep            = ANGLE_RANGE / range;
    colorGradientEnabled = gauge.isGradientBarEnabled();
    noOfGradientStops    = gauge.getGradientBarStops().size();
    sectionsVisible      = gauge.getSectionsVisible();
    sections             = gauge.getSections();
    currentValueAngle    = 0;
    formatString         = new StringBuilder("%.").append(Integer.toString(gauge.getDecimals())).append("f").toString();
    otherFormatString    = new StringBuilder("%.").append(Integer.toString(gauge.getTickLabelDecimals())).append("f").toString();
    locale               = gauge.getLocale();
    currentValueListener = o -> setBar(gauge.getCurrentValue());

    initGraphics();
    registerListeners();

    setBar(gauge.getValue());
}
 
示例17
public ModernSkin(Gauge gauge) {
    super(gauge);
    if (gauge.isAutoScale()) gauge.calcAutoScale();
    angleStep            = ANGLE_RANGE / (gauge.getRange());
    mouseHandler         = event -> handleMouseEvent(event);
    buttonTooltip        = new Tooltip();
    locale               = gauge.getLocale();
    sectionsVisible      = gauge.getSectionsVisible();
    sections             = gauge.getSections();
    barColor             = gauge.getBarColor();
    thresholdColor       = gauge.getThresholdColor();
    animatedListener     = o -> handleEvents("ANIMATED");
    sectionListener      = c -> handleEvents("RESIZE");
    currentValueListener = o -> rotateNeedle(gauge.getCurrentValue());
    titleLength          = 0;
    subTitleLength       = 0;
    unitLength           = 0;

    initGraphics();
    registerListeners();
}
 
示例18
public TileKpiSkin(Gauge gauge) {
    super(gauge);
    if (gauge.isAutoScale()) gauge.calcAutoScale();
    angleRange           = Helper.clamp(90.0, 180.0, gauge.getAngleRange());
    oldValue             = gauge.getValue();
    minValue             = gauge.getMinValue();
    threshold            = gauge.getThreshold();
    thresholdColor       = gauge.getThresholdColor();
    range                = gauge.getRange();
    angleStep            = angleRange / range;
    formatString         = new StringBuilder("%.").append(Integer.toString(gauge.getDecimals())).append("f").toString();
    locale               = gauge.getLocale();
    sectionsVisible      = gauge.getSectionsVisible();
    highlightSections    = gauge.isHighlightSections();
    sections             = gauge.getSections();
    sectionMap           = new HashMap<>(sections.size());
    currentValueListener = o -> rotateNeedle(gauge.getCurrentValue());
    for(Section section : sections) { sectionMap.put(section, new Arc()); }

    initGraphics();
    registerListeners();

    rotateNeedle(gauge.getCurrentValue());
}
 
示例19
public LcdSkin(Gauge gauge) {
    super(gauge);
    width                 = PREFERRED_WIDTH;
    height                = PREFERRED_HEIGHT;
    valueOffsetLeft       = 0.0;
    valueOffsetRight      = 0.0;
    digitalFontSizeFactor = 1.0;
    backgroundTextBuilder = new StringBuilder();
    valueFormatString     = new StringBuilder("%.").append(gauge.getDecimals()).append("f").toString();
    otherFormatString     = new StringBuilder("%.").append(gauge.getTickLabelDecimals()).append("f").toString();
    locale                = gauge.getLocale();
    sections              = gauge.getSections();
    sectionColorMap       = new HashMap<>(sections.size());
    currentValueListener  = o -> handleEvents("REDRAW");
    updateSectionColors();
    FOREGROUND_SHADOW.setOffsetX(0);
    FOREGROUND_SHADOW.setOffsetY(1);
    FOREGROUND_SHADOW.setColor(Color.rgb(0, 0, 0, 0.5));
    FOREGROUND_SHADOW.setBlurType(BlurType.TWO_PASS_BOX);
    FOREGROUND_SHADOW.setRadius(2);

    initGraphics();
    registerListeners();
}
 
示例20
public DigitalSkin(Gauge gauge) {
    super(gauge);
    if (gauge.isAutoScale()) gauge.calcAutoScale();
    minValue             = gauge.getMinValue();
    maxValue             = gauge.getMaxValue();
    range                = gauge.getRange();
    angleStep            = ANGLE_RANGE / range;
    locale               = gauge.getLocale();
    barColor             = gauge.getBarColor();
    valueColor           = gauge.getValueColor();
    titleColor           = gauge.getTitleColor();
    subTitleColor        = gauge.getSubTitleColor();
    unitColor            = gauge.getUnitColor();
    isStartFromZero      = gauge.isStartFromZero();
    sectionsVisible      = gauge.getSectionsVisible();
    sections             = gauge.getSections();
    thresholdVisible     = gauge.isThresholdVisible();
    thresholdColor       = gauge.getThresholdColor();
    currentValueListener = o -> setBar(gauge.getCurrentValue());

    initGraphics();
    registerListeners();

    setBar(gauge.getCurrentValue());
}
 
示例21
public KpiSkin(Gauge gauge) {
    super(gauge);
    if (gauge.isAutoScale()) gauge.calcAutoScale();
    angleRange           = Helper.clamp(90.0, 180.0, gauge.getAngleRange());
    oldValue             = gauge.getValue();
    minValue             = gauge.getMinValue();
    range                = gauge.getRange();
    angleStep            = angleRange / range;
    locale               = gauge.getLocale();
    currentValueListener = o -> rotateNeedle(gauge.getCurrentValue());

    initGraphics();
    registerListeners();

    rotateNeedle(gauge.getCurrentValue());
}
 
示例22
public LinearSkin(Gauge gauge) {
    super(gauge);
    if (gauge.isAutoScale()) gauge.calcAutoScale();
    orientation           = gauge.getOrientation();
    tickLabelFormatString = new StringBuilder("%.").append(Integer.toString(gauge.getTickLabelDecimals())).append("f").toString();
    locale                = gauge.getLocale();
    sections              = gauge.getSections();
    areas                 = gauge.getAreas();
    currentValueListener  = o -> setBar(gauge.getCurrentValue());
    paneSizeListener      = o -> handleEvents("RESIZE");

    if (Orientation.VERTICAL == orientation) {
        preferredWidth  = 140;
        preferredHeight = 350;
    } else {
        preferredWidth  = 350;
        preferredHeight = 140;
    }

    initGraphics();
    registerListeners();
}
 
示例23
public TinySkin(Gauge gauge) {
    super(gauge);
    if (gauge.isAutoScale()) gauge.calcAutoScale();
    oldValue             = gauge.getValue();
    minValue             = gauge.getMinValue();
    maxValue             = gauge.getMaxValue();
    range                = gauge.getRange();
    angleStep            = ANGLE_RANGE / range;
    colorGradientEnabled = gauge.isGradientBarEnabled();
    noOfGradientStops    = gauge.getGradientBarStops().size();
    sections             = gauge.getSections();
    formatString         = new StringBuilder("%.").append(Integer.toString(gauge.getDecimals())).append("f").toString();
    locale               = gauge.getLocale();
    currentValueListener = o -> rotateNeedle(gauge.getCurrentValue());

    initGraphics();
    registerListeners();

    rotateNeedle(gauge.getCurrentValue());

    redraw();
}
 
示例24
public IndicatorSkin(Gauge gauge) {
    super(gauge);
    if (gauge.isAutoScale()) gauge.calcAutoScale();
    angleRange                   = Helper.clamp(90.0, 180.0, gauge.getAngleRange());
    startAngle                   = getStartAngle();
    oldValue                     = gauge.getValue();
    minValue                     = gauge.getMinValue();
    range                        = gauge.getRange();
    angleStep                    = angleRange / range;
    colorGradientEnabled         = gauge.isGradientBarEnabled();
    noOfGradientStops            = gauge.getGradientBarStops().size();
    sectionsAlwaysVisible        = gauge.getSectionsAlwaysVisible();
    sectionsVisible              = gauge.getSectionsVisible();
    sections                     = gauge.getSections();
    formatString                 = new StringBuilder("%.").append(Integer.toString(gauge.getDecimals())).append("f").toString();
    locale                       = gauge.getLocale();
    barColor                     = gauge.getBarColor();
    currentValueListener         = o -> rotateNeedle(gauge.getCurrentValue());
    sectionAlwaysVisibleListener = o -> bar.setVisible(!gauge.getSectionsAlwaysVisible());

    initGraphics();
    registerListeners();

    rotateNeedle(gauge.getCurrentValue());
}
 
示例25
public FlatSkin(Gauge gauge) {
    super(gauge);
    if (gauge.isAutoScale()) gauge.calcAutoScale();
    minValue             = gauge.getMinValue();
    range                = gauge.getRange();
    angleStep            = ANGLE_RANGE / range;
    colorGradientEnabled = gauge.isGradientBarEnabled();
    noOfGradientStops    = gauge.getGradientBarStops().size();
    sectionsVisible      = gauge.getSectionsVisible();
    sections             = gauge.getSections();
    currentValueListener = o -> setBar(gauge.getCurrentValue());

    initGraphics();
    registerListeners();

    setBar(gauge.getCurrentValue());
}
 
示例26
public TileTextKpiSkin(Gauge gauge) {
    super(gauge);
    if (gauge.isAutoScale()) gauge.calcAutoScale();
    minValue             = gauge.getMinValue();
    maxValue             = gauge.getMaxValue();
    range                = gauge.getRange();
    stepSize             = PREFERRED_WIDTH / range;
    formatString         = new StringBuilder("%.").append(Integer.toString(gauge.getDecimals())).append("f").toString();
    locale               = gauge.getLocale();
    sections             = gauge.getSections();
    sectionsVisible      = gauge.getSectionsVisible();
    barColor             = gauge.getBarColor();
    currentValueListener = o -> setBar(gauge.getCurrentValue());

    initGraphics();
    registerListeners();

    setBar(gauge.getCurrentValue());
}
 
示例27
public SlimSkin(Gauge gauge) {
    super(gauge);
    if (gauge.isAutoScale()) gauge.calcAutoScale();
    minValue             = gauge.getMinValue();
    range                = gauge.getRange();
    angleStep            = ANGLE_RANGE / range;
    colorGradientEnabled = gauge.isGradientBarEnabled();
    noOfGradientStops    = gauge.getGradientBarStops().size();
    sectionsVisible      = gauge.getSectionsVisible();
    sections             = gauge.getSections();
    currentValueListener = o -> setBar(gauge.getCurrentValue());

    initGraphics();
    registerListeners();

    setBar(gauge.getCurrentValue());
}
 
示例28
public BarSkin(Gauge gauge) {
    super(gauge);
    if (gauge.isAutoScale()) gauge.calcAutoScale();
    range                = gauge.getRange();
    angleStep            = -ANGLE_RANGE / range;
    currentValueListener = o -> redraw();
    barColorListener     = o -> {
        Color barColor = gauge.getBarColor();
        gauge.setGradientBarStops(new Stop(0.0, barColor),
                                  new Stop(0.01, barColor),
                                  new Stop(0.75, barColor.deriveColor(-10, 1, 1, 1)),
                                  new Stop(1.0, barColor.deriveColor(-20, 1, 1, 1)));
        resize();
    };
    titleListener = o -> {
        titleText.setText(gauge.getTitle());
        resizeTitleText();
    };
    unitListener = o -> {
        unitText.setText(gauge.getUnit());
        resizeUnitText();
    };

    initGraphics();
    registerListeners();
}
 
示例29
public TemplateGaugeSkin(Gauge gauge) {
    super(gauge);
    if (gauge.isAutoScale()) gauge.calcAutoScale();

    initGraphics();
    registerListeners();
}
 
示例30
private Gauge getBulletChart(final String TITLE, final String UNIT,
                             final double MAX_VALUE, final double THRESHOLD,
                             final Section... SECTIONS) {
    return GaugeBuilder.create()
                       .skinType(SkinType.BULLET_CHART)
                       .animated(true)
                       .thresholdColor(GRAY)
                       .title(TITLE)
                       .unit(UNIT)
                       .maxValue(MAX_VALUE)
                       .threshold(THRESHOLD)
                       .sectionsVisible(true)
                       .sections(SECTIONS)
                       .build();
}