⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vdiff.java

📁 用来二进制文件比较
💻 JAVA
字号:
/*
 *   VDiff - Sample Application for JLibDiff
 *   (C)2001 ECOO Team
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 *
 *   Gerald OSTER
 *   <oster@loria.fr>
 *
 */
package VDiff;

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.File;

public class VDiff extends JFrame {

    private HelpFrame helpFrame = null;

    public VDiff(String oldfilename, String newfilename) {
	super("VisualDiff");

	this.getContentPane().setLayout(new BorderLayout());

	/* -- add diff widget -- */
	JPanel diffPanel = new DiffWidget(oldfilename, newfilename);
	this.getContentPane().add(diffPanel, BorderLayout.CENTER);

	/* -- add toolbar -- */
	JToolBar toolBar = new JToolBar(JToolBar.HORIZONTAL);
	this.getContentPane().add(toolBar, BorderLayout.NORTH);
	toolBar.addSeparator();

	JButton exitButton = new JButton(getResource("icons/Exit.png"));
	exitButton.setBorderPainted(false);
	exitButton.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent e) {
		    System.exit(0);
		}
	    });      
	toolBar.add(exitButton);
	toolBar.addSeparator();

// 	JButton saveButton = new JButton(getResource("icons/Save.png"));
// 	saveButton.setBorderPainted(false);
// 	saveButton.addActionListener(new ActionListener() {
// 		public void actionPerformed(ActionEvent e) {
//  		    JOptionPane.showMessageDialog(null,
// 						  "Not yet Implemented...");
// 		}
// 	    });      
// 	toolBar.add(saveButton);
// 	toolBar.addSeparator();

	JButton helpButton = new JButton(getResource("icons/Help.png"));
	helpButton.setBorderPainted(false);
	helpButton.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent e) {
		    if (helpFrame == null) {
			helpFrame = new HelpFrame();
		    } else {
			helpFrame.dispose();
			helpFrame = null;
		    }
		}
	    });      
	toolBar.add(helpButton);

	/* -- some greetings ;) -- */
	Font font = new Font("helvetica", Font.PLAIN, 10);
	JLabel label = new JLabel("Powered by JLibDiff ;)", JLabel.RIGHT);
	label.setForeground(Color.black);
	label.setFont(font);
	this.getContentPane().add(label, BorderLayout.SOUTH);

	/* -- exit window listener -- */
	this.addWindowListener(new WindowAdapter() {
 		public void windowClosing(WindowEvent event) {
 		    dispose();
 		    System.exit(0);
 		}
 	    });
	
	/* -- pack and show */
	this.pack();
	this.show();
	this.toFront();
    }


    public ImageIcon getResource(String filename) {
	return new ImageIcon(Toolkit.getDefaultToolkit().getImage(filename));
    }

    private static String USAGE = "java VDiff  file_r1  file_r2";

    public static void main(String args[]) {
	if ((args.length < 2) || (args.length > 2)) {
	    JOptionPane.showMessageDialog(null,
					  USAGE,
					  "Usage",
					  JOptionPane.WARNING_MESSAGE);
	    System.exit(1);
	} else {
	    for (int i=0 ; i<args.length ; i++) {
		if (! (new File(args[0])).exists()) {
		    JOptionPane.showMessageDialog(null,
				    "could not find file called "+args[0]+".",
				    "Error",
				    JOptionPane.WARNING_MESSAGE);
		    System.exit(1);
		}
	    }

	    new VDiff(args[0], args[1]);
	}
    }


    public class HelpFrame extends JFrame {
	public HelpFrame() {
	    super("Help");
	    this.getContentPane().setLayout(new BorderLayout());


	    JPanel panel = new JPanel();
	    this.getContentPane().add(panel, BorderLayout.CENTER);
	    panel.setLayout(new GridLayout(0,1));
	    panel.setBackground(Color.black);

	    JLabel label;
	    label = new JLabel("block text added", JLabel.CENTER);
	    label.setForeground(HunkColorVisitor.ADDED_COLOR);
	    panel.add(label);
	    label = new JLabel("block text removed", JLabel.CENTER);
	    label.setForeground(HunkColorVisitor.DELETED_COLOR);
	    panel.add(label);
	    label = new JLabel("block text changed", JLabel.CENTER);
	    label.setForeground(HunkColorVisitor.MODIFIED_COLOR);
	    panel.add(label);

	    JButton closeButton = new JButton("Close");
	    closeButton.addActionListener(new ActionListener() {
		    public void actionPerformed(ActionEvent e) {
			VDiff.this.helpFrame.dispose();
			VDiff.this.helpFrame = null;
		    }
		});      
	    this.getContentPane().add(closeButton, BorderLayout.SOUTH);


	    this.addWindowListener(new WindowAdapter() {
		    public void windowClosing(WindowEvent event) {
			HelpFrame.this.dispose();
		    }
		});

	    this.pack();
	    this.setSize(250,150);
	    this.show();
	    this.toFront();
	}

    }


}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -