001: /*
002: * Copyright 2002-2005 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package info.jtrac.wicket;
018:
019: import info.jtrac.util.SvnUtils;
020: import java.util.ArrayList;
021: import java.util.List;
022: import java.util.Map;
023: import org.jfree.chart.ChartFactory;
024: import org.jfree.chart.JFreeChart;
025: import org.jfree.chart.plot.PlotOrientation;
026: import org.jfree.data.category.DefaultCategoryDataset;
027: import org.apache.wicket.behavior.SimpleAttributeModifier;
028: import org.apache.wicket.markup.html.WebMarkupContainer;
029: import org.apache.wicket.markup.html.basic.Label;
030: import org.apache.wicket.markup.html.form.Form;
031: import org.apache.wicket.markup.html.form.PasswordTextField;
032: import org.apache.wicket.markup.html.form.TextField;
033: import org.apache.wicket.markup.html.image.Image;
034: import org.apache.wicket.markup.html.image.resource.BufferedDynamicImageResource;
035: import org.apache.wicket.markup.html.list.ListItem;
036: import org.apache.wicket.markup.html.list.ListView;
037: import org.apache.wicket.model.BoundCompoundPropertyModel;
038:
039: /**
040: * subversion statistics chart
041: */
042: public class SvnStatsPage extends BasePage {
043:
044: private WebMarkupContainer hide = new WebMarkupContainer("hide");
045: private Form form;
046:
047: public SvnStatsPage() {
048: setVersioned(false);
049: form = new SvnForm("form");
050: add(form);
051: add(hide);
052: hide.setVisible(false);
053: }
054:
055: /**
056: * wicket form
057: */
058: private class SvnForm extends Form {
059:
060: private String url;
061: private String loginName;
062: private String password;
063:
064: public String getUrl() {
065: return url;
066: }
067:
068: public void setUrl(String url) {
069: this .url = url;
070: }
071:
072: public String getLoginName() {
073: return loginName;
074: }
075:
076: public void setLoginName(String loginName) {
077: this .loginName = loginName;
078: }
079:
080: public String getPassword() {
081: return password;
082: }
083:
084: public void setPassword(String password) {
085: this .password = password;
086: }
087:
088: public SvnForm(String id) {
089: super (id);
090: final BoundCompoundPropertyModel model = new BoundCompoundPropertyModel(
091: this );
092: setModel(model);
093: add(new TextField("url").setRequired(true));
094: add(new TextField("loginName"));
095: add(new PasswordTextField("password").setRequired(false));
096: }
097:
098: @Override
099: protected void onSubmit() {
100: final Map<String, Integer> commitsPerCommitter = SvnUtils
101: .getCommitsPerCommitter(SvnUtils.getRepository(url,
102: loginName, password));
103: DefaultCategoryDataset dataset = new DefaultCategoryDataset();
104: for (Map.Entry<String, Integer> entry : commitsPerCommitter
105: .entrySet()) {
106: dataset.addValue(entry.getValue(), "Commits", entry
107: .getKey());
108: }
109: List<String> users = new ArrayList(commitsPerCommitter
110: .keySet());
111: final SimpleAttributeModifier sam = new SimpleAttributeModifier(
112: "class", "alt");
113: hide.add(new ListView("users", users) {
114: protected void populateItem(ListItem listItem) {
115: if (listItem.getIndex() % 2 == 1) {
116: listItem.add(sam);
117: }
118: String user = (String) listItem.getModelObject();
119: listItem.add(new Label("user", user));
120: listItem.add(new Label("commits",
121: commitsPerCommitter.get(user) + ""));
122:
123: }
124: });
125: JFreeChart chart = ChartFactory.createBarChart(null, null,
126: null, dataset, PlotOrientation.VERTICAL, false,
127: false, false);
128: BufferedDynamicImageResource resource = new BufferedDynamicImageResource();
129: resource.setImage(chart.createBufferedImage(600, 300));
130: hide.add(new Image("chart", resource));
131: hide.setVisible(true);
132: form.setVisible(false);
133: }
134:
135: }
136:
137: }
|