Skip to content

Commit

Permalink
Initial new icons (#5065)
Browse files Browse the repository at this point in the history
Co-authored-by: Jesse Glick <jglick@cloudbees.com>
Co-authored-by: Tim Jacomb <21194782+timja@users.noreply.github.com>
Co-authored-by: Félix Queiruga <felix.queiruga@gmail.com>
Co-authored-by: Félix Queiruga <fqueiruga@cloudbees.com>
  • Loading branch information
4 people authored Mar 9, 2021
1 parent 8ad3c8d commit 037e137
Show file tree
Hide file tree
Showing 31 changed files with 662 additions and 196 deletions.
58 changes: 58 additions & 0 deletions core/src/main/java/org/jenkins/ui/icon/BuildStatusIcon.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* The MIT License
*
* Copyright (c) 2021 CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package org.jenkins.ui.icon;

import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;

/**
* An icon used for build statuses
*/
@Restricted(NoExternalUse.class)
public class BuildStatusIcon extends Icon {
private boolean inProgress;

public BuildStatusIcon(String classSpec, String url, String style, boolean inProgress) {
super(classSpec, url, style, IconFormat.EXTERNAL_SVG_SPRITE);
this.inProgress = inProgress;
}

public BuildStatusIcon(String classSpec, String url, String style) {
this(classSpec, url, style, false);
}

@Override
public boolean isSvgSprite() {
return super.isSvgSprite();
}

public boolean isBuildStatus() {
return true;
}

public boolean isInProgress() {
return inProgress;
}
}
37 changes: 37 additions & 0 deletions core/src/main/java/org/jenkins/ui/icon/Icon.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
package org.jenkins.ui.icon;

import org.apache.commons.jelly.JellyContext;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -59,6 +61,7 @@ public class Icon {
private final String url;
private final String style;
private IconType iconType;
private IconFormat iconFormat;

/**
* Creates a {@link IconType#CORE core} icon.
Expand Down Expand Up @@ -97,11 +100,37 @@ public Icon(String classSpec, String url, String style) {
* @param iconType The icon type.
*/
public Icon(String classSpec, String url, String style, IconType iconType) {
this(classSpec, url, style, iconType, IconFormat.IMG);
}

/**
* Creates an icon.
*
* @param classSpec The icon class names.
* @param url The icon image url.
* @param style The icon style.
* @param iconFormat the {@link IconFormat}.
* @since TODO
*/
public Icon(String classSpec, String url, String style, IconFormat iconFormat) {
this(classSpec, url, style, IconType.CORE, iconFormat);
if (url != null) {
if (url.startsWith("images/")) {
this.iconType = IconType.CORE;
} else if (url.startsWith("plugin/")) {
this.iconType = IconType.PLUGIN;
}
}
}

@Restricted(NoExternalUse.class)
public Icon(String classSpec, String url, String style, IconType iconType, IconFormat iconFormat) {
this.classSpec = classSpec;
this.normalizedSelector = toNormalizedCSSSelector(classSpec);
this.url = toNormalizedIconUrl(url);
this.style = style;
this.iconType = iconType;
this.iconFormat = iconFormat;
}

/**
Expand All @@ -112,6 +141,14 @@ public String getClassSpec() {
return classSpec;
}

/**
* Is the Icon an SVG?
* @since TODO
*/
public boolean isSvgSprite() {
return iconFormat == IconFormat.EXTERNAL_SVG_SPRITE;
}

/**
* Get the icon's normalized CSS selector.
*
Expand Down
34 changes: 34 additions & 0 deletions core/src/main/java/org/jenkins/ui/icon/IconFormat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* The MIT License
*
* Copyright (c) 2021 CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package org.jenkins.ui.icon;

/**
* Format for the icon.
* @since TODO
*/
public enum IconFormat {
IMG,
EXTERNAL_SVG_SPRITE,
}
Loading

0 comments on commit 037e137

Please sign in to comment.