Click here to Skip to main content
15,892,199 members
Articles / Desktop Programming / MFC

A Java Language IDE

Rate me:
Please Sign up or sign in to vote.
4.33/5 (26 votes)
13 May 2004CPOL3 min read 80.6K   3.4K   41  
This is a partially implemented IDE for the Java platform.
#include "stdafx.h"
#include "resource.h"
#include "editcmd.h"
#include "worksbar.h"
#include "wm.h"
#include "FileViewTree.h"
#include "ClassBrowserTree.h"

#include  "xGuiTabWnd.h"
#include "JavaDeclManager.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#pragma warning ( disable : 4711 )
/////////////////////////////////////////////////////////////////////////////
// CWorkspaceBar

#define ACCESS_IMAGE(nAccess) \
(nAccess == IS_PUBLIC)?0:(nAccess == IS_PROTECTED)?2: 1

CFileViewTree*      CWorkSpaceBar::m_pwndFileView;
CClassBrowserTree*  CWorkSpaceBar::m_pwndClassView;
CTreeCtrl*          CWorkSpaceBar::m_pwndResView;
CWizBarComboBox*    CWorkSpaceBar::m_pwndWizbarClass;
CWizBarComboBox*    CWorkSpaceBar::m_pwndWizbarMethod;

#define ID_CLASSVIEW_CONTAINER 0x45
#define ID_SOLVIEW_CONTAINER   0x55



CWorkSpaceBar::CWorkSpaceBar () //: CBaseDockBar()
{	
  m_bShow = TRUE;
  m_pwndFileView     = new CFileViewTree;
  m_pwndClassView    = new CClassBrowserTree;
  m_pwndResView      = new CTreeCtrl;
}

CWorkSpaceBar::~CWorkSpaceBar ()
{
  //delete m_pwndFileView;
  //delete m_pwndClassView;
  delete m_pwndResView;
}

BEGIN_MESSAGE_MAP (CWorkSpaceBar, CBaseDockBar)
      //{{AFX_MSG_MAP( CWorkspaceBar )
        ON_WM_CREATE ()
	    ON_WM_SIZE()
      //}}AFX_MSG_MAP
	  ON_WM_NCLBUTTONUP()
END_MESSAGE_MAP ()


/////////////////////////////////////////////////////////////////////////////
// CWorkspaceBar message handlers

int CWorkSpaceBar::OnCreate (LPCREATESTRUCT lpCreateStruct)
{
  if (CBaseDockBar::OnCreate (lpCreateStruct) == -1)
                return -1;
  CreateViews();
  return 0;
}

void CWorkSpaceBar::OnNcLButtonUp(UINT nHitTest, CPoint point)
{
    if (nHitTest == HTCLOSE)
         m_bShow = !m_bShow;
    CBaseDockBar::OnNcLButtonUp(nHitTest, point);
}


CString CWorkSpaceBar::GetName()
{
  return _T ("Workspace");
}

/////////////////////////////////////////////////////////////////////////////
#pragma warning ( default : 4711 )


void CWorkSpaceBar::CreateViews()
{

   if(!m_TabSolExplorer.Create(WS_VISIBLE|WS_CHILD,CRect(0,0,0,0),this,0x9999))
		return ;

   m_imgList.Create(IDB_EXPLORER,16,20,RGB(255,0,0));
   m_TabSolExplorer.SetImageList(&m_imgList);


   CreateSolView();
   m_TabSolExplorer.Addtab(&m_wndSolViewTabCont,"Solution Explorer",0);

   CreateClassView();
   m_TabSolExplorer.Addtab(&m_wndClassViewTabCont,"Class View",1);
}



HTREEITEM CWorkSpaceBar::AddItem(CString pszItem,HTREEITEM hParent /*=0*/,
									 UINT ntype /*= 0*/,UINT naccess /*=0*/
									 ,DWORD dwData /*= 0*/)
{
	HTREEITEM hItem= NULL;
	switch(ntype)
	{
	  case IS_CLASS:
		  {
		    if(m_pwndClassView->GetItemText(hParent).Find("Source:",0) != -1)
             hItem= m_pwndClassView->InsertItem(pszItem,0,0,hParent,TVI_LAST);//always keep imports at top.
			else
             hItem= m_pwndClassView->InsertItem(pszItem,0,0,hParent,TVI_SORT);

			m_pwndClassView->SetItemData(hItem,dwData);
			
            CJavaClassDecl* pClass = (CJavaClassDecl*)dwData;
	        int index     = m_pwndWizbarClass->AddString(pClass->getQualifiedName());
            m_pwndWizbarClass->SetItemData(index,dwData);
            m_pwndWizbarClass->SetCurSel(index);
	        return hItem;
		  }
	  case IS_INTERFACE:
		  {
		    if(m_pwndClassView->GetItemText(hParent).Find("Source:",0) != -1)
             hItem= m_pwndClassView->InsertItem(pszItem,16,16,hParent,TVI_LAST);
			else
             hItem= m_pwndClassView->InsertItem(pszItem,16,16,hParent,TVI_SORT);

			m_pwndClassView->SetItemData(hItem,dwData);			
			CJavaInterfaceDecl* pInterface = (CJavaInterfaceDecl*)dwData;

	        int index     = m_pwndWizbarClass->AddString(pInterface->getQualifiedName());
            m_pwndWizbarClass->SetItemData(index,dwData);
            m_pwndWizbarClass->SetCurSel(index);
	        return hItem;
		  }
	  case IS_FUNC:
		  {
            return CWorkSpaceBar::AddFunc(pszItem,hParent,naccess,dwData);
		  }
	  case IS_VAR:
		  {
             return CWorkSpaceBar::AddVar(pszItem,hParent,naccess,dwData);
		  }
	  case IS_LOCAL:
		  {
		    hItem= m_pwndClassView->InsertItem(pszItem,2,2,hParent);
			m_pwndClassView->SetItemData(hItem,dwData);
		    return hItem;
		  }
	  case IS_IMPORT:
		  {
		    hItem= m_pwndClassView->InsertItem(pszItem,12,12,hParent);
			m_pwndClassView->SetItemData(hItem,dwData);
		    return hItem;
		  }
	  case IS_PACKAGE:
		  {


		  }
	  case IS_BLOCK:
		  {
		    hItem = m_pwndClassView->InsertItem(pszItem,10,10,hParent);
			m_pwndClassView->SetItemData(hItem,dwData);
		    return hItem;
		  }
	  default:;
        m_pwndClassView->InsertItem(pszItem,8,8);
		return 0;
	}
  return 0;
}


void CWorkSpaceBar::RemoveItem(HTREEITEM hItem,UINT nType /*= -1*/)
{
   //CString strDebug =
   //m_pwndClassView->GetItemText(hItem);
   m_pwndClassView->DeleteItem(hItem);
}

HTREEITEM CWorkSpaceBar::AddFunc(CString pszItem,HTREEITEM hParent,
								 UINT naccess,DWORD dwData /*= 0*/)
{

  HTREEITEM  hItem = NULL;
  switch(naccess)
  {
     case  IS_PUBLIC:
		 {
            hItem = m_pwndClassView->InsertItem(pszItem,1,1,hParent,TVI_SORT);
			m_pwndClassView->SetItemData(hItem,dwData);
	          if(hItem == NULL)
		    m_pwndClassView->InsertItem("NULL PARENT:AddFunc IS_PUBLIC",8,8,TVI_ROOT,TVI_LAST);

			CJavaMethodDecl* pMethod = (CJavaMethodDecl*)dwData;
			CJavaClassDecl* pClass = GetFocusClass();
			CJavaClassDecl* pParent = (CJavaClassDecl*)pMethod->getParent();
            if(pClass == pMethod->getParent())
			{
              m_pwndWizbarMethod->AddString(pMethod->getDeclName(),ACCESS_IMAGE(pMethod->getAccess()));
			}
		    return hItem;
		 }
     case  IS_PROTECTED:
		 {
	        hItem = m_pwndClassView->InsertItem(pszItem,6,6,hParent,TVI_SORT);
		    m_pwndClassView->SetItemData(hItem,dwData);
	        if(hItem == NULL)
		    m_pwndClassView->InsertItem("NULL PARENT AddFunc IS_PROTECTED",8,8,TVI_ROOT,TVI_LAST);
			
			CJavaMethodDecl* pMethod = (CJavaMethodDecl*)dwData;
            if(GetFocusClass() == pMethod->getParent())
			{
              m_pwndWizbarMethod->AddString(pMethod->getDeclName(),ACCESS_IMAGE(pMethod->getAccess()));
			}
		   return hItem;
		 }
     default:;
		{
           hItem = m_pwndClassView->InsertItem(pszItem,4,4,hParent,TVI_SORT);
		   m_pwndClassView->SetItemData(hItem,dwData);
	         if(hItem == NULL)
		   m_pwndClassView->InsertItem("NULL PARENT AddFunc IS_PRIVATE",8,8,TVI_ROOT,TVI_LAST);

		   CJavaMethodDecl* pMethod = (CJavaMethodDecl*)dwData;
           if(GetFocusClass() == pMethod->getParent())
		   {
              m_pwndWizbarMethod->AddString(pMethod->getDeclName(),ACCESS_IMAGE(pMethod->getAccess()));
		   }
		   return hItem;
		}
  }return 0;
}


HTREEITEM CWorkSpaceBar::AddVar(CString pszItem,HTREEITEM hParent,
									              UINT naccess,DWORD dwData /*= 0*/)
{
  HTREEITEM hItem = NULL;
  switch(naccess)
  {
     case  IS_PUBLIC:
		 {
           hItem = m_pwndClassView->InsertItem(pszItem,3,3,hParent,TVI_SORT);
		   m_pwndClassView->SetItemData(hItem,dwData);
	        if(hItem == NULL)
		   m_pwndClassView->InsertItem("NULL PARENT",8,8,TVI_ROOT,TVI_LAST);
		   return hItem;
		 }
     case  IS_PROTECTED:
		 {
	       hItem = m_pwndClassView->InsertItem(pszItem,7,7,hParent,TVI_SORT);
		   m_pwndClassView->SetItemData(hItem,dwData);
	   	    if(hItem == NULL)
		   m_pwndClassView->InsertItem("NULL PARENT",8,8,TVI_ROOT,TVI_LAST);
		   return hItem;
		 }
     default:;
		{
           hItem= m_pwndClassView->InsertItem(pszItem,5,5,hParent,TVI_SORT);
		   m_pwndClassView->SetItemData(hItem,dwData);
	   	     if(hItem == NULL)
		   m_pwndClassView->InsertItem("NULL PARENT",8,8,TVI_ROOT,TVI_LAST);
		 return hItem;
	   }
  }
	return 0;
}
#include "DropDownButton.h"

void CWorkSpaceBar::CreateClassView()
{
  m_wndClassViewTabCont.Create(NULL,NULL,
	  WS_BORDER|WS_CHILD|WS_CLIPCHILDREN|WS_VISIBLE,CRect(),&m_TabSolExplorer,
	  ID_CLASSVIEW_CONTAINER);

  //return;

  const DWORD dwStyle =	WS_BORDER|WS_CHILD | WS_VISIBLE | TVS_HASLINES 
	                             | TVS_LINESATROOT | TVS_HASBUTTONS ;

  m_pwndClassView->Create(dwStyle,CRect(), &m_wndClassViewTabCont,ID_CLASSVIEW);
  m_wndClassViewTabCont.addComponent(m_pwndClassView,CPoint(1,30),CPoint(1,1));
  //m_pwndClassView = (CClassBrowserTree*)
  //	                 m_wndClassViewTabCont.addComponent(RUNTIME_CLASS(CClassBrowserTree)
  //	                ,0,dwStyle,CPoint(1,30),CPoint(1,1));


  m_classImg.Create(16,16,ILC_COLOR24|ILC_MASK,7,2);
  CBitmap bm;
  bm.LoadBitmap(IDB_CLASSIMG);
  m_classImg.Add(&bm,RGB(255,0,0));

  m_pwndClassView->SetImageList(&m_classImg,TVSIL_NORMAL);

  CDropDownButton* pDropDownMenu = new CDropDownButton;
  pDropDownMenu->Create(_T(""), WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | BS_OWNERDRAW, 
		CRect(0,4,40,27), &m_wndClassViewTabCont,0x1);
  //m_wndClassViewTabCont.addComponent(pDropDownMenu,CRect(0,0,30,10));
  m_wndClassViewTabCont.SetImageList(IDB_EXPLORER,16,24,RGB(255,0,0));
  m_wndClassViewTabCont.addButton(22,pDropDownMenu);
}

void CWorkSpaceBar::CreateSolView()
{
  m_wndSolViewTabCont.Create(NULL,NULL,
	  WS_BORDER|WS_CHILD|WS_CLIPCHILDREN|WS_VISIBLE,CRect(),&m_TabSolExplorer,
	  ID_SOLVIEW_CONTAINER);

  //return;
  const DWORD dwStyle =	WS_BORDER|WS_CHILD | WS_VISIBLE | TVS_HASLINES
	                             | TVS_LINESATROOT | TVS_HASBUTTONS ;
  
  
  m_pwndFileView->Create(dwStyle,CRect(), &m_wndSolViewTabCont,ID_FILEVIEW);

  m_wndSolViewTabCont.addComponent(m_pwndFileView,CPoint(1,30),CPoint(1,1));
  
  /**
  CTreeCtrl* pwndFileView = (CTreeCtrl*)
	               m_wndSolViewTabCont.addComponent(RUNTIME_CLASS(CTreeCtrl)
	               ,ID_FILEVIEW,dwStyle,CPoint(1,30),CPoint(1,1));
  m_pwndFileView->SubclassWindow(pwndFileView->Detach());
  **/
    
  m_fileImg.Create(16,16,ILC_COLOR24|ILC_MASK,7,2);
  CBitmap bm;
  bm.LoadBitmap(IDB_FILE_BUNDLE);
  m_fileImg.Add(&bm,RGB(255,0,255));

  m_pwndFileView->SetImageList(&m_fileImg,TVSIL_NORMAL);

  _CGuiToolButton* pBtn = new _CGuiToolButton;
  pBtn->Create(_T(""), WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | BS_OWNERDRAW, 
		       CRect(0,4,25,27), &m_wndSolViewTabCont,0x1);
  m_wndSolViewTabCont.SetImageList(IDB_EXPLORER,16,24,RGB(255,0,0));
  m_wndSolViewTabCont.addButton(23,pBtn);
}

void CWorkSpaceBar::CreateResView()
{


}



HTREEITEM AddFunc(CString pszItem,HTREEITEM hParent,
				               UINT naccess,DWORD dwData /*= 0*/)
{
  return CWorkSpaceBar::AddFunc(pszItem,hParent,naccess,dwData);
}

HTREEITEM AddVar(CString pszItem,HTREEITEM hParent, UINT naccess,
				                                              DWORD dwData /*= 0*/)
{
  return CWorkSpaceBar::AddVar(pszItem,hParent,naccess,dwData);
}


void RemoveItem(HTREEITEM hItem,UINT nType /*= -1*/)
{

  CWorkSpaceBar::RemoveItem(hItem,nType);
}

HTREEITEM AddItem(CString pszItem,HTREEITEM hParent,
		                                              UINT ntype,UINT naccess,
													  DWORD dwData /*= 0*/)
{

  return CWorkSpaceBar::AddItem(pszItem,hParent,ntype,naccess,dwData);
}

HTREEITEM addProject(CString strProj)
{
  HTREEITEM hFirst = CWorkSpaceBar::m_pwndClassView->GetFirstVisibleItem();
  for(hFirst; hFirst != NULL;)
  {
    CString strItem = CWorkSpaceBar::m_pwndClassView->GetItemText(hFirst);
	if(strItem.Compare(strProj+" classes") == 0)
		return hFirst;
    hFirst = CWorkSpaceBar::m_pwndClassView->GetNextVisibleItem(hFirst);
  }  
  return CWorkSpaceBar::m_pwndClassView->InsertItem(strProj+" classes",15,15);
}

HTREEITEM addSource(HTREEITEM hParent,CString strSource)
{
  return CWorkSpaceBar::m_pwndClassView->InsertItem(strSource,14,14,hParent);
}

HTREEITEM addImports(HTREEITEM hParent,CString strImports)
{
  return CWorkSpaceBar::m_pwndClassView->InsertItem(strImports,11,11,hParent,0);
}

HTREEITEM removeOnContainZero(HTREEITEM hItem)
{
  if(CWorkSpaceBar::m_pwndClassView->ItemHasChildren(hItem))
	  return hItem;
  else
    CWorkSpaceBar::m_pwndClassView->DeleteItem(hItem);
  return NULL;
}

void CWorkSpaceBar::OnSelchangeClass()
{
  //fill the method combobox
  CJavaClassDecl* pClass = GetFocusClass();

  CWorkSpaceBar::m_pwndWizbarMethod->ResetContent();

  DECL_LIST* pList = pClass->getMembers();
  for(POSITION pos = pList->GetHeadPosition(); pos != NULL;)
  {
    __CBaseDecl* pDecl = pList->GetNext(pos);
	if(pDecl->getKind() == METHOD_DECL)
	{
	   int index = m_pwndWizbarMethod->AddString(pDecl->getDeclName(),ACCESS_IMAGE(pDecl->getAccess()));
       m_pwndWizbarMethod->SetItemData(index,(DWORD)pDecl);
	}
  }
}

void CWorkSpaceBar::SelectMethod(__CBaseDecl* pMethod)
{
  //fill the method combobox
  CJavaClassDecl* pClass = GetFocusClass();


  DECL_LIST* pList = pClass->getMembers();
  for(POSITION pos = pList->GetHeadPosition(); pos != NULL;)
  {
    __CBaseDecl* pDecl = pList->GetNext(pos);
	if(pMethod == pDecl)
	{
	  CWorkSpaceBar::m_pwndWizbarMethod->SelectString(-1,pDecl->getDeclName());
	  return;
	}
  }
}

void CWorkSpaceBar::SelectClass(__CBaseDecl* pDecl)
{
  int count = m_pwndWizbarClass->GetCount();
  for(int i=0; i<count; i++)
  {
    CJavaClassDecl* pClass = (CJavaClassDecl*)
		CWorkSpaceBar::m_pwndWizbarClass->GetItemData(i);
	if(pClass == pDecl)
	{
      m_pwndWizbarClass->SetCurSel(i);break;

	}
  }
}


CJavaClassDecl* CWorkSpaceBar::GetFocusClass()
{
  int sel = CWorkSpaceBar::m_pwndWizbarClass->GetCurSel();
  return (CJavaClassDecl*)CWorkSpaceBar::m_pwndWizbarClass->GetItemData(sel);
}

void CWorkSpaceBar::OnSelchangeFunction()
{


}


void PrintBound(int nStartIndex,int nStartLine,int nEndIndex,int nEndLine,
				                                   CString strLabel /*= ""*/)
{
  if(!strLabel.IsEmpty())
  CWorkSpaceBar::AddItem(strLabel);
  CString fm;
  fm.Format("%d",nStartLine);
  CWorkSpaceBar::AddItem("   StartLine:"+fm);
  fm.Format("%d",nStartIndex);
  CWorkSpaceBar::AddItem("   StartIndex:"+fm);
  fm.Format("%d",nEndLine);
  CWorkSpaceBar::AddItem("   EndLine:"+fm);
  fm.Format("%d",nEndIndex);
  CWorkSpaceBar::AddItem("   EndIndex:"+fm);
  CWorkSpaceBar::AddItem("************************");
}

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
United States United States
biography? I am not that old yet.

Comments and Discussions