com.jwebmp.plugins.bootstrap.progressbar.BSProgressBar Maven / Gradle / Ivy
Show all versions of jwebmp-bootstrap Show documentation
/*
* Copyright (C) 2017 Marc Magon
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
package com.jwebmp.plugins.bootstrap.progressbar;
import com.jwebmp.core.base.html.Div;
import com.jwebmp.core.base.interfaces.IComponentHierarchyBase;
import com.jwebmp.core.plugins.ComponentInformation;
import com.jwebmp.plugins.bootstrap.progressbar.bar.BSProgressBarDisplay;
import java.util.Objects;
/**
* Progress
*
* Use our custom progress component for displaying simple or complex progress bars.
* We don’t use the HTML5 progress element, ensuring you can stack progress bars, animate them, and place text
* labels over them.
*
*
* @param
*
* @author Marc Magon
* @version 1.0
* @since 29 Aug 2015
*/
@ComponentInformation(name = "Bootstrap Progress Bars",
description = "Use our custom progress component for displaying simple or complex progress bars.",
url = "https://v4-alpha.getbootstrap.com/components/progress/",
wikiUrl = "https://github.com/GedMarc/JWebSwing-BootstrapPlugin/wiki")
public class BSProgressBar>
extends Div
implements IBSProgressBar
{
private static final long serialVersionUID = 1L;
/**
* Whether or not the progress bar is striped
*/
private boolean striped;
/**
* Whether or not this progress bar should display as active
*/
private boolean active;
/**
* if animated
*/
private boolean animated;
/**
* The actual progress bar
*/
private BSProgressBarDisplay progressBar;
/**
* Use our custom progress component for displaying simple or complex progress bars.
*/
public BSProgressBar()
{
this(false);
}
/**
* Creates a new instance of a progress bar
*
* @param striped
* If the progress bar is striped or not
*/
public BSProgressBar(boolean striped)
{
this(striped, false);
}
/**
* Creates a new instance of a progress bar
*
* @param striped
* If the progress bar is striped or not
* @param active
* if the progress bar is active or not
*/
public BSProgressBar(boolean striped, boolean active)
{
this(striped, active, null);
}
/**
* Creates a new instance of a progress bar
*
* @param striped
* If the progress bar is striped or not
* @param active
* if the progress bar is active or not
* @param progressBar
* The actual progress bar
*/
public BSProgressBar(boolean striped, boolean active, BSProgressBarDisplay progressBar)
{
addClass(BSComponentProgressBarOptions.Progress);
setStriped(striped);
setActive(active);
setProgressBar(progressBar);
}
/**
* Returns a new progress bar
*
* @return
*/
public IBSProgressBar asMe()
{
return this;
}
@Override
public int hashCode()
{
return Objects.hash(super.hashCode(), isStriped(), isActive(), isAnimated(), getProgressBar());
}
@Override
public boolean equals(Object o)
{
if (this == o)
{
return true;
}
if (!(o instanceof BSProgressBar))
{
return false;
}
if (!super.equals(o))
{
return false;
}
BSProgressBar> that = (BSProgressBar>) o;
return isStriped() == that.isStriped() && isActive() == that.isActive() && isAnimated() == that.isAnimated() && Objects.equals(getProgressBar(), that.getProgressBar());
}
/**
* Returns the actual progress bar
*
* @return
*/
@Override
public BSProgressBarDisplay getProgressBar()
{
if (progressBar == null)
{
progressBar = new BSProgressBarDisplay();
setProgressBar(progressBar);
}
return progressBar;
}
/**
* Sets the actual progress bar
*
* @param progressBar
*/
@Override
public final void setProgressBar(BSProgressBarDisplay progressBar)
{
remove(this.progressBar);
this.progressBar = progressBar;
if (progressBar != null)
{
add(progressBar);
}
}
/**
* Returns if this progress bar should return as active
*
* @return
*/
@Override
public boolean isActive()
{
return active;
}
/**
* Sets if this component should return as active
*
* @param active
*/
@Override
public final void setActive(boolean active)
{
this.active = active;
if (active)
{
getProgressBar().addClass("active");
}
else
{
getProgressBar().removeClass("active");
}
}
/**
* If is animated
*
* @return
*/
@Override
public boolean isAnimated()
{
return animated;
}
/**
* Sets if animated
*
* @param animated
*/
@Override
public void setAnimated(boolean animated)
{
this.animated = animated;
if (animated)
{
getProgressBar().addClass(BSComponentProgressBarOptions.Progress_Bar_Animated);
}
else
{
getProgressBar().removeClass(BSComponentProgressBarOptions.Progress_Bar_Animated);
}
}
/**
* Sets if this component is striped or not
*
* @return
*/
@Override
public boolean isStriped()
{
return striped;
}
/**
* Sets if this components is striped or not
*
* @param striped
*/
@Override
public final void setStriped(boolean striped)
{
this.striped = striped;
if (striped)
{
getProgressBar().addClass(BSComponentProgressBarOptions.Progress_Bar_Striped);
}
else
{
getProgressBar().removeClass(BSComponentProgressBarOptions.Progress_Bar_Striped);
}
}
/**
* Sets the given percentage
*
* @param percent
*
* @return
*/
@Override
public J setPercentage(double percent)
{
getProgressBar().setValue(percent);
return (J) this;
}
}