Click here to Skip to main content
15,885,947 members
Articles / Programming Languages / Java / Java SE

Free "tail -f" Tool for all Platforms: Tail for Windows, Tail for Linux and Tail for Mac

Rate me:
Please Sign up or sign in to vote.
2.08/5 (8 votes)
19 Jul 2006CPOL3 min read 55.9K   1.1K   24  
MakeLogic Tail is a freeware similar to " tail -f " of Linux. It is Tail for Windows, Tail for Linux and Tail for Mac
/******************************************************************************
 
Copyright (C) 2006  MakeLogic

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

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.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA


Date		: 14th December 2005
Authors		: MakeLogic

Design		: Ujjwal
Developer	: Dharma

********************************************************************************/

package com.makeLogic.utils;

import java.awt.Container;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import java.io.IOException;
import java.io.File;

import javax.swing.ImageIcon;
import javax.swing.JMenuItem;
import javax.swing.JEditorPane;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.KeyStroke;

import javax.swing.filechooser.FileFilter;

import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.MutableTreeNode;

import java.util.Hashtable;

import com.makeLogic.MLTreeNode;
import com.makeLogic.TailMDI;

import com.makeLogic.utils.MLInternalFrame;

/**
 * NewMenuItem is one of the MenuItems of FileMenu.<br>
 * Itis to Open a new JInternalFrame whenever user clicks on it.
 */
public class NewMenuItem extends JMenuItem implements ActionListener
{	
	//.. variables declaration
	Container container;
	Hashtable internalFramesNewFileNames;
	JEditorPane editorPane;

	JFileChooser fileChooser;
	File file[];
	String tempFileName;
	TailMDI tailMDI;
	
	static int index=0;
	
	NewMenuItem(Container container)
	{	
		//..calls the super class constructor with string as parameter
		super("New Project");

		Trace.enter("NewMenuItem.NewMenuItem");
		
		//..Get current classloader 
		ClassLoader cl = this.getClass().getClassLoader();

		try
		{
			setIcon(new ImageIcon(cl.getResource("createProject_icon.png")));			
		}
		catch(Exception excpt)
		{
			Trace.exception(excpt);			
		}

		//this.container=container;
		tailMDI = (TailMDI)container;

		//..sets the Default accelerator as CTRL+N for the NewMenuItem
		setAccelerator(KeyStroke.getKeyStroke('N',java.awt.Event.CTRL_MASK,false));

		//..Adds the ActionListerner to handle the Event
		addActionListener(this);

		this.container=container;

		Trace.exit("NewMenuItem.NewMenuItem");
	}


	public void setKeyStrokeForNewMenuItem(KeyStroke newMenuItemKeyStroke)
	{
		Trace.enter("NewMenuItem.setKeyStrokeForNewMenuItem");
		
		//..sets user defined Accelerator for the NewMenuItem
		setAccelerator(newMenuItemKeyStroke);

		Trace.exit("NewMenuItem.setKeyStrokeForNewMenuItem");
	}
	public void actionPerformed(ActionEvent evt)
	{
		/* Creates a New mlproj when this event is generated */

		Trace.enter("NewMenuItem.actionPerformed");
		
		boolean createProject = false;

		if(fileChooser == null)
		{
			fileChooser = new JFileChooser();

			fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
			fileChooser.setMultiSelectionEnabled(false);
			fileChooser.setFileFilter(new CreateProjectFileFilter());
		}
		
		//...................................................
		fileChooser.setDialogTitle("Create New Project");
		int returnValue = fileChooser.showDialog(tailMDI,"Create Project");

		//..Debug
		//System.out.println("..ML.. Return Val ->"+returnValue);

		if(returnValue == JFileChooser.APPROVE_OPTION)
		{
			File projFile = fileChooser.getSelectedFile();

			if(!projFile.getName().toLowerCase().endsWith(".mlproj"))
			{
				String fileName = projFile.getAbsolutePath() + ".mlproj";
				projFile = new File(fileName);
			}

			if(projFile.exists())
			{
				int result = JOptionPane.showConfirmDialog(tailMDI,"Project "+fileChooser.getSelectedFile().getName()+" already exists.\n\nDo you want to overwrite?","MakeLogic Tail",JOptionPane.YES_NO_OPTION);

				if(result == JOptionPane.YES_OPTION)
				{
					createProject = true;
				}
				else
				{
					createProject = false;
				}
			}
			else
			{
				createProject = true;
			}
		}
		else if(returnValue == JFileChooser.ERROR_OPTION)
		{
			//..TODO
			createProject = false;
		}
		else if(returnValue == JFileChooser.CANCEL_OPTION)
		{
			//..DO NOTHING
			createProject = false;
		}

		try
		{
			if(createProject)
			{
				//System.out.println("..ML.. Creating Project");

				File projFile = fileChooser.getSelectedFile();

				if(!projFile.getName().toLowerCase().endsWith(".mlproj"))
				{
					String fileName = projFile.getAbsolutePath() + ".mlproj";
					projFile = new File(fileName);
				}

				if(projFile.exists())
				{
					projFile.delete();
					projFile.createNewFile();
				}
				else
				{
					projFile.createNewFile();
				}

				//..add the project
				tailMDI.addProject(projFile.getAbsolutePath());

				//..add to the tree

				//..Get the selected node
				MLTreeNode node = (MLTreeNode)tailMDI.projPanel.mainTree.getLastSelectedPathComponent();

				//..Create a new - tree node
				MLTreeNode childNode = new MLTreeNode(projFile.getAbsolutePath());
				childNode.setIsProject(true);

				//..If node is root node than add 
				//..else get the root node and add
				/*
				if(node.isRoot())
				{
					//node.insert(childNode,0);
					DefaultTreeModel treeModel = (DefaultTreeModel)tailMDI.projPanel.mainTree.getModel();

					//..Verify if node present or not
					if(tailMDI.searchNode((MLTreeNode)treeModel.getRoot(),projFile.getAbsolutePath()) == null )
					{
						treeModel.insertNodeInto(childNode,(MutableTreeNode)node,0);
					}
				}
				else*/
				{
					//node = (MLTreeNode)node.getRoot();
					DefaultTreeModel treeModel = (DefaultTreeModel)tailMDI.projPanel.mainTree.getModel();
					
					//..Verify if node present or not
					if(tailMDI.searchNode((MLTreeNode)treeModel.getRoot(),projFile.getAbsolutePath()) == null )
					{
						treeModel.insertNodeInto(childNode,(MutableTreeNode)treeModel.getRoot(),0);
					}
				}
			}
			else
			{
				//System.out.println("..ML.. Not Creating Project");
				Trace.message("Not Creating Project");
			}
		}
		catch(IOException ioe)
		{
			Trace.exception(ioe);
		}

		Trace.exit("NewMenuItem.actionPerformed");
	}
}

class CreateProjectFileFilter extends FileFilter
{
	public boolean accept(File file)
	{
		Trace.enter("CreateProjectFileFilter.accept");
		
		String fileName = file.getName();
		
		//..return if Directory , else return if log file
		if(!file.isDirectory())
		{
			Trace.exit("CreateProjectFileFilter.accept");
			return fileName.endsWith(".mlproj");
		}
		else
		{
			Trace.exit("CreateProjectFileFilter.accept");
			return true;
		}
	}
	public String getDescription() 
	{
		Trace.enter("CreateProjectFileFilter.getDescription");
		Trace.exit("CreateProjectFileFilter.getDescription");

		return "MakeLogicTail Projects(*.mlproj)";
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
India India
Founder of MakeLogic - A Mobile Solutions and XML Web Services Company. B-Tech engineer from India's reputed IITs.

Designed and Authored products like MicroGraphs, MakeLogic VersionManager and MakeLogic Device Broker. Pls see http://www.makelogic.com

MakeLogic is a strategic business partner of Microsoft, Sun, IBM, HP and Citrix.

Contact : madanuuk@makelogic.com OR +91 - 40 - 55322433

Comments and Discussions