001: /**
002: * LibreSource
003: * Copyright (C) 2004-2008 Artenum SARL / INRIA
004: * http://www.libresource.org - contact@artenum.com
005: *
006: * This file is part of the LibreSource software,
007: * which can be used and distributed under license conditions.
008: * The license conditions are provided in the LICENSE.TXT file
009: * at the root path of the packaging that enclose this file.
010: * More information can be found at
011: * - http://dev.libresource.org/home/license
012: *
013: * Initial authors :
014: *
015: * Guillaume Bort / INRIA
016: * Francois Charoy / Universite Nancy 2
017: * Julien Forest / Artenum
018: * Claude Godart / Universite Henry Poincare
019: * Florent Jouille / INRIA
020: * Sebastien Jourdain / INRIA / Artenum
021: * Yves Lerumeur / Artenum
022: * Pascal Molli / Universite Henry Poincare
023: * Gerald Oster / INRIA
024: * Mariarosa Penzi / Artenum
025: * Gerard Sookahet / Artenum
026: * Raphael Tani / INRIA
027: *
028: * Contributors :
029: *
030: * Stephane Bagnier / Artenum
031: * Amadou Dia / Artenum-IUP Blois
032: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
033: */package org.libresource.so6.core.exec.ui;
034:
035: import org.libresource.so6.core.WsConnection;
036: import org.libresource.so6.core.interfaces.Closer;
037: import org.libresource.so6.core.ui.BasicMenu;
038: import org.libresource.so6.core.ui.BasicProgressView;
039: import org.libresource.so6.core.ui.TextView;
040: import org.libresource.so6.core.ui.util.StyledUI;
041: import org.libresource.so6.core.ui.util.Wizard;
042: import org.libresource.so6.core.ui.util.WizardComponent;
043: import org.libresource.so6.core.ui.util.WizardListener;
044:
045: import java.awt.BorderLayout;
046: import java.awt.Color;
047: import java.awt.Toolkit;
048: import java.awt.event.WindowAdapter;
049: import java.awt.event.WindowEvent;
050:
051: import javax.swing.JFrame;
052: import javax.swing.JPanel;
053:
054: /**
055: * @author smack
056: */
057: public class Commit extends JPanel implements WizardListener, StyledUI {
058: private BasicMenu menuBar;
059:
060: //
061: private TextView commentView;
062: private TextView reportView;
063: private BasicProgressView progressView;
064:
065: //
066: private boolean jobDone = false;
067:
068: //
069: private Wizard wizard;
070:
071: public Commit(String wscPath) throws Exception {
072: // Make views
073: commentView = new TextView("Comment for commit");
074: progressView = new BasicProgressView(wscPath);
075: reportView = new TextView("Report");
076: reportView.setEditable(false);
077:
078: // Make menu
079: menuBar = new BasicMenu();
080: menuBar.setProgressView(progressView);
081:
082: //
083: wizard = new Wizard(this );
084: wizard.setMenuBar(menuBar);
085: wizard.addComponent(commentView);
086: wizard.addComponent(progressView);
087: wizard.addComponent(reportView);
088: wizard.renderView(0);
089: wizard.renderButtons();
090:
091: //
092: setLayout(new BorderLayout());
093: add(wizard, BorderLayout.CENTER);
094: }
095:
096: public BasicMenu getMenu() {
097: return menuBar;
098: }
099:
100: public WizardComponent getCommentView() {
101: return commentView;
102: }
103:
104: public WizardComponent getProgressView() {
105: return progressView;
106: }
107:
108: public WizardComponent getReportView() {
109: return reportView;
110: }
111:
112: public void doTheJob() {
113: if (!jobDone) {
114: progressView.commit(commentView.getContent());
115: }
116:
117: jobDone = true;
118:
119: if (progressView.getReport().length() > 0) {
120: reportView.setContent(progressView.getReport());
121: } else {
122: reportView.setContent("Nothing done...");
123: }
124:
125: progressView.getWizard().renderButtons();
126: }
127:
128: public static void main(String[] args) throws Exception {
129: if (args.length != 1) {
130: System.err.println("Usage: wsPath");
131: System.err.println(" (1) wsPath: path of the file "
132: + WsConnection.SO6_WSC_FILE);
133: System.exit(0);
134: }
135:
136: String wscPath = args[0];
137: Commit commit = new Commit(wscPath);
138: commit.setStyle(Color.white, Color.decode("#eeeeee"));
139:
140: // Make frame
141: JFrame f = new JFrame("Commit on connection: " + wscPath);
142: f.getContentPane().add(commit, BorderLayout.CENTER);
143: f.setSize(400, 215);
144: f.addWindowListener(new WindowAdapter() {
145: public void windowClosing(WindowEvent e) {
146: System.exit(0);
147: }
148: });
149: f.setLocation(((int) Toolkit.getDefaultToolkit()
150: .getScreenSize().getWidth() - f.getWidth()) / 2,
151: ((int) Toolkit.getDefaultToolkit().getScreenSize()
152: .getHeight() - f.getHeight()) / 2);
153: f.setVisible(true);
154: }
155:
156: public boolean setCurrentPosition(int currentHistoryPosition) {
157: // ask comment -> commit <-> report
158: if (currentHistoryPosition == 1) {
159: Thread thread = new Thread(new Runnable() {
160: public void run() {
161: doTheJob();
162: }
163: });
164: thread.setPriority(Thread.NORM_PRIORITY);
165: thread.start();
166: } else {
167: reportView.getWizard().renderButtons();
168: }
169:
170: return currentHistoryPosition > 1;
171: }
172:
173: public void setStyle(Color back, Color forground) {
174: wizard.setStyle(back, forground);
175: }
176:
177: public void setCloser(Closer closer) {
178: wizard.setCloser(closer);
179: menuBar.setCloser(closer);
180: }
181: }
|