Package com.helger.css.decl
Class CSSMediaRule
- java.lang.Object
-
- com.helger.css.decl.AbstractHasTopLevelRules
-
- com.helger.css.decl.CSSMediaRule
-
- All Implemented Interfaces:
ICSSTopLevelRule
,ICSSSourceLocationAware
,ICSSWriteable
@NotThreadSafe public class CSSMediaRule extends AbstractHasTopLevelRules implements ICSSTopLevelRule, ICSSSourceLocationAware
Represents a single@media
rule: a list of style rules only valid for certain media.
Example:
@media print { div#footer { display: none; } }
- Author:
- Philip Helger
-
-
Field Summary
-
Fields inherited from class com.helger.css.decl.AbstractHasTopLevelRules
m_aRules
-
-
Constructor Summary
Constructors Constructor Description CSSMediaRule()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CSSMediaRule
addMediaQuery(int nIndex, CSSMediaQuery aMediaQuery)
Add a media query at the specified index.CSSMediaRule
addMediaQuery(CSSMediaQuery aMediaQuery)
Add a new media query.boolean
equals(Object o)
com.helger.commons.collection.impl.ICommonsList<CSSMediaQuery>
getAllMediaQueries()
String
getAsCSSString(ICSSWriterSettings aSettings, int nIndentLevel)
Get the contents of this object as a serialized CSS string for writing to an output.CSSMediaQuery
getMediaQueryAtIndex(int nMediumIndex)
Get the media query at the specified index ornull
.int
getMediaQueryCount()
CSSSourceLocation
getSourceLocation()
int
hashCode()
boolean
hasMediaQueries()
com.helger.commons.state.EChange
removeAllMediaQueries()
Remove all media queries.com.helger.commons.state.EChange
removeMediaQuery(int nMediumIndex)
Remove the media query at the provided index.com.helger.commons.state.EChange
removeMediaQuery(CSSMediaQuery aMediaQuery)
Remove the provided media query.void
setSourceLocation(CSSSourceLocation aSourceLocation)
Set the source location of the object, determined while parsing.String
toString()
-
Methods inherited from class com.helger.css.decl.AbstractHasTopLevelRules
addRule, addRule, getAllFontFaceRules, getAllKeyframesRules, getAllMediaRules, getAllPageRules, getAllRules, getAllRules, getAllStyleRules, getAllSupportsRules, getAllUnknownRules, getAllViewportRules, getFontFaceRuleAtIndex, getFontFaceRuleCount, getKeyframesRuleAtIndex, getKeyframesRuleCount, getMediaRuleAtIndex, getMediaRuleCount, getPageRuleAtIndex, getPageRuleCount, getRule, getRuleAtIndex, getRuleCount, getStyleRuleAtIndex, getStyleRuleCount, getSupportsRuleAtIndex, getSupportsRuleCount, getUnknownRuleAtIndex, getUnknownRuleCount, getViewportRuleAtIndex, getViewportRuleCount, hasFontFaceRules, hasKeyframesRules, hasMediaRules, hasPageRules, hasRules, hasStyleRules, hasSupportsRules, hasUnknownRules, hasViewportRules, removeAllRules, removeRule, removeRule, removeRules
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.helger.css.ICSSWriteable
getAsCSSString, getAsCSSString
-
-
-
-
Method Detail
-
hasMediaQueries
public boolean hasMediaQueries()
- Returns:
true
if at least one media query is present,false
if no media query is present.
-
getMediaQueryCount
@Nonnegative public int getMediaQueryCount()
- Returns:
- The number of contained media queries. Always ≥ 0.
-
addMediaQuery
@Nonnull public CSSMediaRule addMediaQuery(@Nonnull @Nonempty CSSMediaQuery aMediaQuery)
Add a new media query.- Parameters:
aMediaQuery
- The media query to be added. May not benull
.- Returns:
- this for chaining
-
addMediaQuery
@Nonnull public CSSMediaRule addMediaQuery(@Nonnegative int nIndex, @Nonnull @Nonempty CSSMediaQuery aMediaQuery)
Add a media query at the specified index.- Parameters:
nIndex
- The index to use. Must be ≥ 0. If the index is ≥getMediaQueryCount()
than the media query is appended like inaddMediaQuery(CSSMediaQuery)
.aMediaQuery
- The media query to be added. May not benull
.- Returns:
- this for chaining
-
removeMediaQuery
@Nonnull public com.helger.commons.state.EChange removeMediaQuery(@Nullable CSSMediaQuery aMediaQuery)
Remove the provided media query.- Parameters:
aMediaQuery
- The media query to be removed. May benull
.- Returns:
EChange
.
-
removeMediaQuery
@Nonnull public com.helger.commons.state.EChange removeMediaQuery(@Nonnegative int nMediumIndex)
Remove the media query at the provided index.- Parameters:
nMediumIndex
- The index to be removed. Should be ≥ 0.- Returns:
EChange
.
-
removeAllMediaQueries
@Nonnull public com.helger.commons.state.EChange removeAllMediaQueries()
Remove all media queries.- Returns:
EChange.CHANGED
if any media query was removed,EChange.UNCHANGED
otherwise. Nevernull
.- Since:
- 3.7.3
-
getMediaQueryAtIndex
@Nullable public CSSMediaQuery getMediaQueryAtIndex(@Nonnegative int nMediumIndex)
Get the media query at the specified index ornull
.- Parameters:
nMediumIndex
- The index to be retrieved. Should be ≥ 0.- Returns:
null
if an invalid index was provided.
-
getAllMediaQueries
@Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsList<CSSMediaQuery> getAllMediaQueries()
- Returns:
- A copy of all contained media queries. Never
null
. Maybe empty.
-
getAsCSSString
@Nonnull @Nonempty public String getAsCSSString(@Nonnull ICSSWriterSettings aSettings, @Nonnegative int nIndentLevel)
Description copied from interface:ICSSWriteable
Get the contents of this object as a serialized CSS string for writing to an output.- Specified by:
getAsCSSString
in interfaceICSSWriteable
- Parameters:
aSettings
- The settings to be used to format the output. May not benull
.nIndentLevel
- The current indentation level- Returns:
- The content of this object as CSS string. Never
null
.
-
getSourceLocation
@Nullable public final CSSSourceLocation getSourceLocation()
- Specified by:
getSourceLocation
in interfaceICSSSourceLocationAware
- Returns:
- The source location of this object when it was read by the parser.
May be
null
if an object was not read but manually created.
-
setSourceLocation
public final void setSourceLocation(@Nullable CSSSourceLocation aSourceLocation)
Description copied from interface:ICSSSourceLocationAware
Set the source location of the object, determined while parsing.- Specified by:
setSourceLocation
in interfaceICSSSourceLocationAware
- Parameters:
aSourceLocation
- The source location to use. May benull
.
-
-