package org.vmasterdiff.gui; import org.swing.GraphPaperLayout; import org.swing.GraphPaperConstraints; import org.swing.PaneConstraints; import org.swing.JPanesContainer; import org.swing.JDragPane; import org.dhiller.presentation.gui.*; import org.dhiller.common.Tools; import org.dhiller.adapters.event.Adapter; import org.vmasterdiff.lib.*; import org.vmasterdiff.gui.swing.*; /** * FILL IN JAVADOC HERE */ /* should be put around any references to a class, interface, or method * {@link reference alternate-text} An inline reference used in your description of a * class or description of a method. *

a paragraph break * * @author $Author: deanhiller $ * @version $Revision: 1.1 $ $Date: 2002/08/13 12:34:45 $ * @since $ProductVersion$ * @website http://sourceforge.net/projects/vmaster * @deprecated * @see reference alternative-text * A reference is any of the following... * package packageName * Class packageName.ClassName * InnerClass packageName.ClassName.InnerClassName * Method in other class packageName.ClassName#methodName(type1, type2,...) * Field in other class packageName.ClassName#fieldName * Method in this class #methodName(type1, type2, ...) * Field in this class #fieldName * where each type is * type1 packageName.ClassName */ public class DiffMainView extends WindowView { private final static String className = DiffMainView.class.getName(); private final static Logger log = Logger.getLogger(className); private JPanesContainer panesCont; protected static Adapter adapter = new Adapter( new Class[] {WindowListener.class, ActionListener.class, FileSelectionListener.class}); /** * FILL IN JAVADOC HERE */ /* @param paramName description(JAVADOC input paramter here) * @return description (JAVADOC return value here) * @throws exception description(JAVADOC throws method here) * @see reference alternative-text(JAVADOC references here) */ protected String getClassName() { return className; } public void addComponents(JFrameJDialog f) { f.setLocation(150,150); f.setSize(500, 400); Container cont = f.getContentPane(); cont.setLayout(new BorderLayout()); panesCont = new JPanesContainer(); cont.add(panesCont, BorderLayout.CENTER); //setup menus and toolbars addMenu(f); JDragPane pane = new JDragPane(); JDragPane pane2 = new JDragPane(); JDiffToolBar toolBar1 = new JDiffToolBar(); JSettingsToolBar toolBar2 = new JSettingsToolBar(); pane.add(toolBar1); pane2.add(toolBar2); panesCont.add(pane, new PaneConstraints(PaneConstraints.NORTH,0)); panesCont.add(pane2, new PaneConstraints(PaneConstraints.NORTH,0,1)); adapter.registerEventHandler(toolBar1.getDiff2Button(), "actionPerformed", this, "onDiff2Files"); adapter.registerEventHandler(toolBar1.getDiff3Button(), "actionPerformed", this, "onNotImplemented"); adapter.registerEventHandler(toolBar1.getDiff2DirButton(), "actionPerformed", this, "onDiff2Dirs"); adapter.registerEventHandler(toolBar1.getDiff3DirButton(), "actionPerformed", this, "onNotImplemented"); adapter.registerEventHandler(toolBar1.getMerge2Button(), "actionPerformed", this, "onNotImplemented"); adapter.registerEventHandler(toolBar1.getMerge3Button(), "actionPerformed", this, "onNotImplemented"); } public void addMenu(JFrameJDialog frame) { JMenuBar menuBar = new JMenuBar(); frame.setJMenuBar(menuBar); //**************FILE MENU********************************** JMenu fileMenu = new JMenu(bundle.getString("menu.file.title")); menuBar.add(fileMenu); JMenuItem exit = new JMenuItem(bundle.getString("menu.file.exit")); fileMenu.add(exit); adapter.registerEventHandler(exit, "actionPerformed", this, "onExitWindow"); //**************VIEW MENU********************************* JMenu adminMenu = new JMenu(bundle.getString("menu.view.title")); menuBar.add(adminMenu); JMenuItem mdisdi = new JMenuItem(bundle.getString("menu.view.mdi-sdi")); adminMenu.add(mdisdi); adapter.registerEventHandler(mdisdi, "actionPerformed", this, "onNotImplemented"); //**************DIFF MENU***************************** JMenu diffMenu = new JMenu(bundle.getString("menu.diff.title")); menuBar.add(diffMenu); JMenuItem diff2 = new JMenuItem(bundle.getString("menu.diff.diff2")); JMenuItem diff3 = new JMenuItem(bundle.getString("menu.diff.diff3")); JMenuItem diff2Dir = new JMenuItem(bundle.getString("menu.diff.diff2Dir")); JMenuItem diff3Dir = new JMenuItem(bundle.getString("menu.diff.diff3Dir")); JMenuItem merge2 = new JMenuItem(bundle.getString("menu.diff.merge2")); JMenuItem merge3 = new JMenuItem(bundle.getString("menu.diff.merge3")); diffMenu.add(diff2Dir); diffMenu.add(diff2); diffMenu.add(merge2); diffMenu.add(diff3Dir); diffMenu.add(diff3); diffMenu.add(merge3); adapter.registerEventHandler(diff2, "actionPerformed", this, "onDiff2Files"); adapter.registerEventHandler(diff3, "actionPerformed", this, "onNotImplemented"); adapter.registerEventHandler(diff2Dir, "actionPerformed", this, "onDiff2Dirs"); adapter.registerEventHandler(diff3Dir, "actionPerformed", this, "onNotImplemented"); adapter.registerEventHandler(merge2, "actionPerformed", this, "onNotImplemented"); adapter.registerEventHandler(merge3, "actionPerformed", this, "onNotImplemented"); //**************LANGUAGES MENU***************************** menuBar.add(languagesMenu); //**************HELP MENU********************************** JMenu helpMenu = new JMenu(bundle.getString("menu.help.title")); menuBar.add(helpMenu); JMenuItem helpAbout = new JMenuItem(bundle.getString("menu.help.about")); helpMenu.add(helpAbout); //w = new HelpAboutView(); //w.setParent(window); //adapter.registerEventHandler(helpAbout, "actionPerformed", w, "onCreateWindow"); } /** * Only opens files, any files(not directories) */ protected String getFileName(Component parent) { String path = System.getProperty("user.dir"); JFileChooser chooser = new JFileChooser(path); int returnVal = chooser.showOpenDialog(parent); if(returnVal == JFileChooser.APPROVE_OPTION) return chooser.getSelectedFile().getAbsolutePath(); return null; } /** * Only opens directories, not files. */ protected String getDirectoryName(Component parent) { String path = System.getProperty("user.dir"); JFileChooser chooser = new JFileChooser(path); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int returnVal = chooser.showOpenDialog(parent); if(returnVal == JFileChooser.APPROVE_OPTION) return chooser.getSelectedFile().getAbsolutePath(); return null; } protected void diff2Files(File file1, File file2) { JDragPane pane = new JDragPane("Diff of Two Files"); pane.setPreferredSize(new Dimension(50,50)); JTwoFileDiff comp = new JTwoFileDiff(); comp.setLeftTitle(file1.getAbsolutePath()); comp.setRightTitle(file2.getAbsolutePath()); pane.add(comp); panesCont.add(pane, new PaneConstraints(PaneConstraints.CENTER)); comp.diffTwoFiles(file1, file2); } /*********************************************************************************** EVENT HANDLERS BELOW ***********************************************************************************/ public void onDiff2Files(EventObject event) { String fileName1 = getFileName(WindowView.getTopMostWindow()); if(fileName1 == null) return; String fileName2 = getFileName(WindowView.getTopMostWindow()); if(fileName2 == null) return; File file1 = new File(fileName1); File file2 = new File(fileName2); if(!file1.exists()) { JOptionPane.showMessageDialog(WindowView.getTopMostWindow(), "File 1 '"+file2.getAbsolutePath()+ "' had some error", "Error", JOptionPane.ERROR_MESSAGE); return; } else if(!file2.exists()) { JOptionPane.showMessageDialog(WindowView.getTopMostWindow(), "File 2 '"+file2.getAbsolutePath()+ "' had some error", "Error", JOptionPane.ERROR_MESSAGE); return; } diff2Files(file1, file2); } public void onDiff2Dirs(EventObject event) { String dirName1 = getDirectoryName(WindowView.getTopMostWindow()); if(dirName1 == null) return; String dirName2 = getDirectoryName(WindowView.getTopMostWindow()); if(dirName2 == null) return; File dir1 = new File(dirName1); File dir2 = new File(dirName2); if(!dir1.exists()) { JOptionPane.showMessageDialog(WindowView.getTopMostWindow(), "File 1 '"+dir1.getAbsolutePath()+ "' had some error", "Error", JOptionPane.ERROR_MESSAGE); return; } else if(!dir2.exists()) { JOptionPane.showMessageDialog(WindowView.getTopMostWindow(), "File 2 '"+dir2.getAbsolutePath()+ "' had some error", "Error", JOptionPane.ERROR_MESSAGE); return; } JDragPane pane = new JDragPane("Diff of Two Directories"); pane.setPreferredSize(new Dimension(50,50)); JTwoDirDiff comp = new JTwoDirDiff(); adapter.registerEventHandler(comp, "fileSelected", this, "onFileSelected"); comp.setTitle(dir1.getAbsolutePath()+"(old) vs. (new)"+dir2.getAbsolutePath()); pane.add(comp); panesCont.add(pane, new PaneConstraints(PaneConstraints.CENTER)); comp.diffTwoDirectories(dir1, dir2); } public void onNotImplemented(EventObject event) { JOptionPane.showMessageDialog((Component)window, "This function is not implemented yet"); } public void onFileSelected(FileSelectionEvent event) { String fileOld = event.getOldFilePath(); String fileNew = event.getNewFilePath(); File file1 = new File(fileOld); File file2 = new File(fileNew); if(!file1.exists()) { JOptionPane.showMessageDialog(WindowView.getTopMostWindow(), "File 1 '"+file2.getAbsolutePath()+ "' had some error", "Error", JOptionPane.ERROR_MESSAGE); return; } else if(!file2.exists()) { JOptionPane.showMessageDialog(WindowView.getTopMostWindow(), "File 2 '"+file2.getAbsolutePath()+ "' had some error", "Error", JOptionPane.ERROR_MESSAGE); return; } diff2Files(file1, file2); } }