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 jlibdiff.vdiff.VDiff;
036:
037: import org.libresource.so6.core.interfaces.Closer;
038: import org.libresource.so6.core.ui.MultipleView;
039: import org.libresource.so6.core.ui.TextFieldView;
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.WizardListener;
043:
044: import java.awt.BorderLayout;
045: import java.awt.Color;
046: import java.awt.Toolkit;
047: import java.awt.event.WindowAdapter;
048: import java.awt.event.WindowEvent;
049:
050: import java.io.File;
051:
052: import javax.swing.JFrame;
053: import javax.swing.JPanel;
054:
055: /**
056: * @author smack
057: */
058: public class Diff extends JPanel implements WizardListener, StyledUI {
059: private TextFieldView oldPath;
060: private TextFieldView newPath;
061: private MultipleView view;
062: private String wscPath;
063:
064: //
065: private boolean jobDone = false;
066:
067: //
068: private Wizard wizard;
069:
070: public Diff(String from, String to) throws Exception {
071: // Make views
072: view = new MultipleView("View diff between");
073: oldPath = new TextFieldView("file");
074: newPath = new TextFieldView("file");
075:
076: //
077: if (from != null) {
078: oldPath.setContent(from);
079: }
080:
081: if (to != null) {
082: newPath.setContent(to);
083: }
084:
085: //
086: view.addView(oldPath);
087: view.addView(newPath);
088:
089: //
090: wizard = new Wizard(this );
091: wizard.addComponent(view);
092: wizard.renderView(0);
093: wizard.renderButtons();
094:
095: //
096: setLayout(new BorderLayout());
097: add(wizard, BorderLayout.CENTER);
098: }
099:
100: public static void main(String[] args) throws Exception {
101: if (args.length != 0) {
102: System.exit(0);
103: }
104:
105: String src = "";
106: String dst = "";
107: Diff diff = new Diff(src, dst);
108: diff.setStyle(Color.white, Color.decode("#eeeeee"));
109:
110: // Make frame
111: JFrame f = new JFrame("Compute diff on text files");
112: f.getContentPane().add(diff, BorderLayout.CENTER);
113: f.setSize(400, 180);
114: f.addWindowListener(new WindowAdapter() {
115: public void windowClosing(WindowEvent e) {
116: System.exit(0);
117: }
118: });
119: f.setLocation(((int) Toolkit.getDefaultToolkit()
120: .getScreenSize().getWidth() - f.getWidth()) / 2,
121: ((int) Toolkit.getDefaultToolkit().getScreenSize()
122: .getHeight() - f.getHeight()) / 2);
123: f.setVisible(true);
124: }
125:
126: public boolean setCurrentPosition(int currentHistoryPosition) {
127: // ask comment -> commit <-> report
128: if (currentHistoryPosition == 1) {
129: File src = new File(oldPath.getContent());
130: File dst = new File(newPath.getContent());
131:
132: if (src.exists() && src.isFile() && dst.exists()
133: && dst.isFile()) {
134: String[] param = new String[] { oldPath.getContent(),
135: newPath.getContent() };
136: JFrame f = new VDiff(oldPath.getContent(), newPath
137: .getContent());
138:
139: for (int i = 0; i < f.getWindowListeners().length; i++)
140: f.removeWindowListener(f.getWindowListeners()[i]);
141:
142: f.setVisible(true);
143: }
144: } else {
145: wizard.renderButtons();
146: }
147:
148: return false;
149: }
150:
151: public void setStyle(Color back, Color forground) {
152: wizard.setStyle(back, forground);
153: }
154:
155: public void setCloser(Closer closer) {
156: wizard.setCloser(closer);
157: }
158: }
|