diff --git a/core/src/main/java/hudson/model/AbstractStatusIcon.java b/core/src/main/java/hudson/model/AbstractStatusIcon.java new file mode 100644 index 0000000000000000000000000000000000000000..ea8c573ba9696ce8974f23dd81e518e686f1b8ec --- /dev/null +++ b/core/src/main/java/hudson/model/AbstractStatusIcon.java @@ -0,0 +1,33 @@ +/* + * The MIT License + * + * Copyright (c) 2010, 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 hudson.model; + +/** + * Partial base class for {@link StatusIcon}. + * + * @author Kohsuke Kawaguchi + * @since 1.390 + */ +public abstract class AbstractStatusIcon implements StatusIcon { +} diff --git a/core/src/main/java/hudson/model/BallColor.java b/core/src/main/java/hudson/model/BallColor.java index 98ff3c4adb73c1e0f0ed8647c5583a3974f7f42f..59442621b86705004d98c97f9da3595f6dc649c4 100644 --- a/core/src/main/java/hudson/model/BallColor.java +++ b/core/src/main/java/hudson/model/BallColor.java @@ -23,9 +23,12 @@ */ package hudson.model; +import hudson.Functions; import hudson.util.ColorPalette; import org.jvnet.localizer.LocaleProvider; import org.jvnet.localizer.Localizable; +import org.kohsuke.stapler.Stapler; +import org.kohsuke.stapler.StaplerRequest; import java.awt.*; import java.util.Locale; @@ -50,7 +53,7 @@ import java.util.Locale; * * @author Kohsuke Kawaguchi */ -public enum BallColor { +public enum BallColor implements StatusIcon { RED("red",Messages._BallColor_Failed(), ColorPalette.RED), RED_ANIME("red_anime",Messages._BallColor_InProgress(), ColorPalette.RED), YELLOW("yellow",Messages._BallColor_Unstable(), ColorPalette.YELLOW), @@ -86,6 +89,10 @@ public enum BallColor { return image; } + public String getImageOf(String size) { + return Stapler.getCurrentRequest().getContextPath()+'/'+Hudson.RESOURCE_PATH+'/'+size+'/'+image; + } + /** * Gets the human-readable description used as img/@alt. */ diff --git a/core/src/main/java/hudson/model/StatusIcon.java b/core/src/main/java/hudson/model/StatusIcon.java new file mode 100644 index 0000000000000000000000000000000000000000..170e232dfa61114213e5750aed83babbf1c81cd0 --- /dev/null +++ b/core/src/main/java/hudson/model/StatusIcon.java @@ -0,0 +1,58 @@ +/* + * The MIT License + * + * Copyright (c) 2010, 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 hudson.model; + +/** + * {@link Item} can return this from the "getIconColor" method so that + * its "status icon" can be shown in Hudson UI. + * + *

+ * For future compatibility, please extend from {@link AbstractStatusIcon} + * instead of implementing this directly, so that we can add methods later. + * + *

+ * This is a generalization of {@link BallColor}. + * + * @author Kohsuke Kawaguchi + * @since 1.390 + */ +public interface StatusIcon { + /** + * Returns the URL to the image. + * + * @param size + * The size specified. Must support "16x16", "24x24", and "32x32" at least. + * For forward compatibility, if you receive a size that's not supported, + * consider returning your biggest icon (and let the browser rescale.) + * @return + * The URL is rendered as is in the img @src attribute, so it must contain + * the context path, etc. + */ + String getImageOf(String size); + + /** + * Gets the human-readable description used as img/@alt. + */ + String getDescription(); +} diff --git a/core/src/main/java/hudson/views/StatusColumn.java b/core/src/main/java/hudson/views/StatusColumn.java index 919f9e7af8c56b014c0dd37c087ad94769163b0c..9d67ae1536a1b5adaca493594387716d394619ba 100644 --- a/core/src/main/java/hudson/views/StatusColumn.java +++ b/core/src/main/java/hudson/views/StatusColumn.java @@ -24,8 +24,14 @@ package hudson.views; import hudson.Extension; +import hudson.model.StatusIcon; import org.kohsuke.stapler.DataBoundConstructor; +/** + * Shows the status icon for item. It's colored ball for jobs. + * + * @see StatusIcon + */ public class StatusColumn extends ListViewColumn { @DataBoundConstructor public StatusColumn() { diff --git a/core/src/main/resources/lib/hudson/ballColorTd.jelly b/core/src/main/resources/lib/hudson/ballColorTd.jelly index be8a7808ac3c717ac558e373f18769b1bd1c6abf..d39d6f108d5ac103a043e755360ec7e19e69a6ec 100644 --- a/core/src/main/resources/lib/hudson/ballColorTd.jelly +++ b/core/src/main/resources/lib/hudson/ballColorTd.jelly @@ -32,9 +32,9 @@ THE SOFTWARE. - - ${it.description} + ${it.description} - \ No newline at end of file +