File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\hudson\model\BallColor.java.html

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Simon Wiest
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24 package hudson.model;
25
26 import hudson.util.ColorPalette;
27 import jenkins.model.Jenkins;
28 import org.jvnet.localizer.LocaleProvider;
29 import org.jvnet.localizer.Localizable;
30 import org.kohsuke.stapler.Stapler;
31
32 import java.awt.*;
33 import java.util.Locale;
34
35 /**
36 * Ball color used for the build status indication.
37 *
38 * <p>
39 * There are four basic colors, plus their animated "bouncy" versions.
40 * {@link #ordinal()} is the sort order.
41 *
42 * <p>
43 * Note that multiple {@link BallColor} instances may map to the same
44 * RGB color, to avoid the rainbow effect.
45 *
46 * <h2>Historical Note</h2>
47 * <p>
48 * Hudson started to overload colors &mdash; for example grey could mean
49 * either disabled, aborted, or not yet built. As a result, {@link BallColor}
50 * becomes more like a "logical" color, in the sense that different {@link BallColor}
51 * values can map to the same RGB color. See issue #956.
52 *
53 * @author Kohsuke Kawaguchi
54 */
55 public enum BallColor implements StatusIcon {
56 RED("red",Messages._BallColor_Failed(), ColorPalette.RED),
57 RED_ANIME("red_anime",Messages._BallColor_InProgress(), ColorPalette.RED),
58 YELLOW("yellow",Messages._BallColor_Unstable(), ColorPalette.YELLOW),
59 YELLOW_ANIME("yellow_anime",Messages._BallColor_InProgress(), ColorPalette.YELLOW),
60 BLUE("blue",Messages._BallColor_Success(), ColorPalette.BLUE),
61 BLUE_ANIME("blue_anime",Messages._BallColor_InProgress(), ColorPalette.BLUE),
62 // for historical reasons they are called grey.
63 GREY("grey",Messages._BallColor_Pending(), ColorPalette.GREY),
64 GREY_ANIME("grey_anime",Messages._BallColor_InProgress(), ColorPalette.GREY),
65
66 DISABLED("grey",Messages._BallColor_Disabled(), ColorPalette.GREY),
67 DISABLED_ANIME("grey_anime",Messages._BallColor_InProgress(), ColorPalette.GREY),
68 ABORTED("grey",Messages._BallColor_Aborted(), ColorPalette.GREY),
69 ABORTED_ANIME("grey_anime",Messages._BallColor_InProgress(), ColorPalette.GREY),
70 NOTBUILT("grey",Messages._BallColor_NotBuilt(), ColorPalette.GREY),
71 NOTBUILT_ANIME("grey_anime",Messages._BallColor_InProgress(), ColorPalette.GREY),
72 ;
73
74 private final Localizable description;
75 private final String image;
76 private final Color baseColor;
77
78 BallColor(String image, Localizable description, Color baseColor) {
79 this.baseColor = baseColor;
80 // name() is not usable in the constructor, so I have to repeat the name twice
81 // in the constants definition.
82 this.image = image+ (image.endsWith("_anime")?".gif":".png");
83 this.description = description;
84 }
85
86 /**
87 * String like "red.png" that represents the file name of the image.
88 */
89 public String getImage() {
90 return image;
91 }
92
93 public String getImageOf(String size) {
94 return Stapler.getCurrentRequest().getContextPath()+ Jenkins.RESOURCE_PATH+"/images/"+size+'/'+image;
95 }
96
97 /**
98 * Gets the human-readable description used as img/@alt.
99 */
100 public String getDescription() {
101 return description.toString(LocaleProvider.getLocale());
102 }
103
104 /**
105 * Gets the RGB color of this color. Animation effect is not reflected to this value.
106 */
107 public Color getBaseColor() {
108 return baseColor;
109 }
110
111 /**
112 * Returns the {@link #getBaseColor()} in the "#RRGGBB" format.
113 */
114 public String getHtmlBaseColor() {
115 return String.format("#%06X",baseColor.getRGB()&0xFFFFFF);
116 }
117
118 /**
119 * Also used as a final name.
120 */
121 @Override
122 public String toString() {
123 return name().toLowerCase(Locale.ENGLISH);
124 }
125
126 /**
127 * Gets the animated version.
128 */
129 public BallColor anime() {
130 if(isAnimated()) return this;
131 else return valueOf(name()+"_ANIME");
132 }
133
134 /**
135 * Gets the unanimated version.
136 */
137 public BallColor noAnime() {
138 if(isAnimated()) return valueOf(name().substring(0,name().length()-6));
139 else return this;
140 }
141
142 /**
143 * True if the icon is animated.
144 */
145 public boolean isAnimated() {
146 return name().endsWith("_ANIME");
147 }
148 }
149