001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019: package org.netbeans.modules.bpel.design.decoration.components;
020:
021: import java.awt.Color;
022: import java.awt.Graphics;
023: import java.util.ArrayList;
024: import java.util.List;
025: import javax.swing.ButtonModel;
026: import javax.swing.Icon;
027: import javax.swing.ImageIcon;
028:
029: import org.netbeans.modules.bpel.design.decoration.Decoration;
030: import org.netbeans.modules.xml.xam.spi.Validator.ResultItem;
031: import org.netbeans.modules.xml.xam.spi.Validator.ResultType;
032: import org.openide.util.NbBundle;
033:
034: /**
035: * @author aa160298
036: */
037: public class ShowGlassPaneButton extends AbstractGlassPaneButton {
038:
039: public ShowGlassPaneButton(List<ResultItem> resultItems) {
040: super (ERROR_ICON);
041: fillGlassPaneHeader(resultItems);
042: fillGlassPaneContent(resultItems);
043: updatePreferredSize();
044: }
045:
046: public void setResultItems(List<ResultItem> resultItems) {
047: getGlassPane().removeHeaders();
048: getGlassPane().removeHTML();
049: fillGlassPaneHeader(resultItems);
050: fillGlassPaneContent(resultItems);
051: }
052:
053: private void fillGlassPaneHeader(List<ResultItem> resultItems) {
054: int errorsCount = 0;
055: int warningsCount = 0;
056: int advicesCount = 0;
057:
058: for (ResultItem item : resultItems) {
059: switch (item.getType()) {
060: case ERROR:
061: errorsCount++;
062: break;
063: case WARNING:
064: warningsCount++;
065: break;
066: case ADVICE:
067: advicesCount++;
068: break;
069: }
070: }
071:
072: if (errorsCount > 0) {
073: if (errorsCount > 1) {
074: getGlassPane()
075: .addHeader(
076: ERROR_ICON,
077: ""
078: + errorsCount
079: + " "
080: + NbBundle
081: .getMessage(getClass(),
082: "LBL_ShowGlassPaneButton_N_Errors")
083: .trim()); // NOI18N
084: } else {
085: getGlassPane().addHeader(
086: ERROR_ICON,
087: NbBundle.getMessage(getClass(),
088: "LBL_ShowGlassPaneButton_1_Error")
089: .trim()); // NOI18N
090: }
091: }
092:
093: if (warningsCount > 0) {
094: if (warningsCount > 1) {
095: getGlassPane()
096: .addHeader(
097: WARNING_ICON,
098: ""
099: + warningsCount
100: + " "
101: + NbBundle
102: .getMessage(getClass(),
103: "LBL_ShowGlassPaneButton_N_Warnings")
104: .trim()); // NOI18N
105: } else {
106: getGlassPane().addHeader(
107: WARNING_ICON,
108: NbBundle.getMessage(getClass(),
109: "LBL_ShowGlassPaneButton_1_Warning")
110: .trim()); // NOI18N
111: }
112: }
113:
114: if (advicesCount > 0) {
115: if (advicesCount > 1) {
116: getGlassPane()
117: .addHeader(
118: ADVICE_ICON,
119: ""
120: + advicesCount
121: + " "
122: + NbBundle
123: .getMessage(getClass(),
124: "LBL_ShowGlassPaneButton_N_Advices")
125: .trim()); // NOI18N
126: } else {
127: getGlassPane().addHeader(
128: ADVICE_ICON,
129: NbBundle.getMessage(getClass(),
130: "LBL_ShowGlassPaneButton_1_Advice")
131: .trim()); // NOI18N
132: }
133: }
134:
135: if (errorsCount > 0) {
136: setMyIcon(ERROR_ICON);
137: } else if (warningsCount > 0) {
138: setMyIcon(WARNING_ICON);
139: } else if (advicesCount > 0) {
140: setMyIcon(ADVICE_ICON);
141: }
142: }
143:
144: private void fillGlassPaneContent(List<ResultItem> resultItems) {
145: addToGlassPane(resultItems, ResultType.ERROR);
146: addToGlassPane(resultItems, ResultType.ADVICE);
147: addToGlassPane(resultItems, ResultType.WARNING);
148: getGlassPane().updateHTML();
149: }
150:
151: private void addToGlassPane(List<ResultItem> resultItems,
152: ResultType type) {
153: List<ResultItem> items = filterResultItems(resultItems, type);
154:
155: String icon = null;
156: String slowIcon = null;
157:
158: switch (type) {
159: case ERROR:
160: icon = ERROR_ICON_PATH;
161: slowIcon = ERROR_SLOW_ICON_PATH;
162: break;
163: case WARNING:
164: icon = WARNING_ICON_PATH;
165: slowIcon = WARNING_SLOW_ICON_PATH;
166: break;
167: case ADVICE:
168: icon = ADVICE_ICON_PATH;
169: slowIcon = ADVICE_SLOW_ICON_PATH;
170: }
171:
172: for (ResultItem item : items) {
173: if ("BPELSchemaValidator".equals(item.getValidator()
174: .getName())) { // NOI18N
175: getGlassPane().addListItem(slowIcon,
176: item.getDescription());
177: } else {
178: getGlassPane().addListItem(icon, item.getDescription());
179: }
180: }
181: }
182:
183: private List<ResultItem> filterResultItems(
184: List<ResultItem> resultItems, ResultType type) {
185: List<ResultItem> result = new ArrayList<ResultItem>();
186: for (ResultItem item : resultItems) {
187: if (item.getType() == type) {
188: result.add(item);
189: }
190: }
191: return result;
192: }
193:
194: protected void paintComponent(Graphics g) {
195: ButtonModel model = getModel();
196:
197: if (model.isPressed()) {
198: ButtonRenderer.paintButton(this , g,
199: ButtonRenderer.PRESSED_FILL_COLOR, false,
200: ButtonRenderer.PRESSED_BORDER_COLOR,
201: ButtonRenderer.PRESSED_STROKE_WIDTH, getMyIcon());
202: } else if (model.isRollover()) {
203: ButtonRenderer.paintButton(this , g,
204: ButtonRenderer.ROLLOVER_FILL_COLOR, true,
205: ButtonRenderer.ROLLOVER_BORDER_COLOR,
206: ButtonRenderer.ROLLOVER_STROKE_WIDTH, getMyIcon());
207:
208: } else if (model.isSelected()) {
209: ButtonRenderer.paintButton(this , g, BACKGROUND, false,
210: ButtonRenderer.PRESSED_BORDER_COLOR,
211: ButtonRenderer.PRESSED_STROKE_WIDTH, getMyIcon());
212: } else {
213: ButtonRenderer.paintButton(this , g, BACKGROUND, false,
214: null, ButtonRenderer.NORMAL_STROKE_WIDTH,
215: getMyIcon());
216: }
217: }
218:
219: private static Color BACKGROUND = new Color(0xCCFFFFFF, true);
220:
221: private static final String ERROR_ICON_PATH = "resources/error.png"; // NOI18N
222: private static final String ERROR_SLOW_ICON_PATH = "resources/error_explicit.png"; // NOI18N
223:
224: private static final String WARNING_ICON_PATH = "resources/warning.png"; // NOI18N
225: private static final String WARNING_SLOW_ICON_PATH = "resources/warning_explicit.png"; // NOI18N
226:
227: private static final String ADVICE_ICON_PATH = "resources/advice.png"; // NOI18N
228: private static final String ADVICE_SLOW_ICON_PATH = "resources/advice_explicit.png"; // NOI18N
229:
230: private static final Icon ERROR_ICON;
231: private static final Icon ERROR_SLOW_ICON;
232:
233: private static final Icon WARNING_ICON;
234: private static final Icon WARNING_SLOW_ICON;
235:
236: private static final Icon ADVICE_ICON;
237: private static final Icon ADVICE_SLOW_ICON;
238:
239: static {
240: ERROR_ICON = new ImageIcon(Decoration.class
241: .getResource(ERROR_ICON_PATH));
242: ERROR_SLOW_ICON = new ImageIcon(Decoration.class
243: .getResource(ERROR_SLOW_ICON_PATH));
244: WARNING_ICON = new ImageIcon(Decoration.class
245: .getResource(WARNING_ICON_PATH));
246: WARNING_SLOW_ICON = new ImageIcon(Decoration.class
247: .getResource(WARNING_SLOW_ICON_PATH));
248: ADVICE_ICON = new ImageIcon(Decoration.class
249: .getResource(ADVICE_ICON_PATH));
250: ADVICE_SLOW_ICON = new ImageIcon(Decoration.class
251: .getResource(ADVICE_SLOW_ICON_PATH));
252: }
253: }
|