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.application.studio;
034:
035: import org.libresource.so6.application.studio.history.viewer.ui.ColorManagerImpl;
036: import org.libresource.so6.application.studio.history.viewer.ui.FileHistoryPlayerImpl;
037: import org.libresource.so6.application.studio.history.viewer.ui.FileHistoryPlayerImplList;
038: import org.libresource.so6.application.studio.history.viewer.ui.HistorySlideBar;
039: import org.libresource.so6.application.studio.history.viewer.ui.Menu;
040: import org.libresource.so6.application.studio.history.viewer.util.CommandFinder;
041: import org.libresource.so6.application.studio.history.viewer.util.FileHistoryPlayer;
042: import org.libresource.so6.application.studio.history.viewer.util.PlayerDispatcher;
043: import org.libresource.so6.application.studio.history.viewer.util.WorkspaceColorManager;
044: import org.libresource.so6.core.WsConnection;
045: import org.libresource.so6.core.command.Command;
046: import org.libresource.so6.core.engine.OpVectorFsImpl;
047: import org.libresource.so6.core.engine.PatchFile;
048: import org.libresource.so6.core.engine.util.FileUtils;
049:
050: import java.awt.BorderLayout;
051: import java.awt.Toolkit;
052: import java.awt.event.WindowAdapter;
053: import java.awt.event.WindowEvent;
054:
055: import java.io.File;
056:
057: import java.util.ArrayList;
058: import java.util.ListIterator;
059:
060: import javax.swing.JComponent;
061: import javax.swing.JFrame;
062: import javax.swing.JPanel;
063: import javax.swing.JSplitPane;
064:
065: /**
066: * @author smack
067: */
068: public class FileHistoryViewer extends JPanel implements CommandFinder {
069: private WsConnection wsc;
070: private OpVectorFsImpl cmds;
071: private FileHistoryPlayer player;
072: private WorkspaceColorManager colorManager;
073: private JSplitPane split;
074:
075: public FileHistoryViewer(String wscPath, String fileName)
076: throws Exception {
077: wsc = new WsConnection(wscPath);
078:
079: ArrayList filter = new ArrayList();
080: filter.add(fileName);
081:
082: File tmpDir = FileUtils.createTmpDir();
083: File attachDir = FileUtils.createTmpDir();
084: cmds = new OpVectorFsImpl(tmpDir.getPath());
085:
086: //
087: File[] patchList = wsc.getAppliedPatch().list();
088:
089: for (int i = 0; i < patchList.length; i++) {
090: PatchFile pf = new PatchFile(patchList[i].getPath());
091: pf.buildOpVector(cmds, attachDir.getPath(), filter);
092: }
093:
094: ListIterator i = cmds.getCommands();
095: Command cmd;
096: ArrayList wsNameList = new ArrayList();
097:
098: while ((cmd = (Command) i.next()) != null) {
099: //System.out.println(cmd);
100: if (!wsNameList.contains(cmd.getWsName())) {
101: wsNameList.add(cmd.getWsName());
102: }
103: }
104:
105: //
106: colorManager = new ColorManagerImpl(wsNameList);
107: player = new PlayerDispatcher();
108: player.setWorkspaceColorManager(colorManager);
109: ((PlayerDispatcher) player).addPlayer(
110: new FileHistoryPlayerImplList(this ), "Progress view");
111: ((PlayerDispatcher) player).addPlayer(
112: new FileHistoryPlayerImpl(this ), "State view");
113:
114: //
115: setLayout(new BorderLayout());
116: split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
117: (JComponent) colorManager, (JComponent) player);
118: split.setOneTouchExpandable(true);
119: add(new Menu(wsc.getPath(), player), BorderLayout.NORTH);
120: add(split, BorderLayout.CENTER);
121: add(new HistorySlideBar(player, cmds.size()),
122: BorderLayout.SOUTH);
123: }
124:
125: public void computeDividerLocation() {
126: if (split.getDividerLocation() < 100) {
127: split.setDividerLocation(100);
128: }
129: }
130:
131: public static void main(String[] args) throws Exception {
132: FileHistoryViewer fh = new FileHistoryViewer(args[0], args[1]);
133: JFrame f = new JFrame("Local undo redo on " + args[1]);
134: f.setSize(500, 500);
135: f.getContentPane().add(fh);
136: f.addWindowListener(new WindowAdapter() {
137: public void windowClosing(WindowEvent e) {
138: System.exit(0);
139: }
140: });
141: fh.computeDividerLocation();
142: f.setLocation(((int) Toolkit.getDefaultToolkit()
143: .getScreenSize().getWidth() - f.getWidth()) / 2,
144: ((int) Toolkit.getDefaultToolkit().getScreenSize()
145: .getHeight() - f.getHeight()) / 2);
146: f.setVisible(true);
147: }
148:
149: public Command getOp(int i) throws Exception {
150: return cmds.getCommand(i);
151: }
152: }
|