/////////////////////////////////////////////////////////////////////////////
//
// Module Name : Upload file dialog 
// Class Name  : CUploadDlg
// File Name   : "UploadDlg.h"
//
#if !defined(AFX_UPLOADDLG_H__CF78EF8D_8200_4D6B_9839_00AE9C4DCB31__INCLUDED_)
#define AFX_UPLOADDLG_H__CF78EF8D_8200_4D6B_9839_00AE9C4DCB31__INCLUDED_#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000//////////////////////////////////
// Specify the Class
class CUploadDlg : public CDialog
{
// コンストラクション
public:
CString m_strSelFileName;
CMap<HTREEITEM,HTREEITEM&,CStringList*,CStringList*&> m_mapFiles; CStringList m_strFolderList;
HTREEITEM m_hPopupItem;
CString m_strPathName;
CString GetTreePath();
CString m_strPrjName;
CUploadDlg(int nFlag,CWnd* pParent = NULL);   // 標準のコンストラクタ// ダイアログ データ
//{{AFX_DATA(CUploadDlg)
enum { IDD = IDD_UPLOAD_VIEW };
CHotKeyCtrl m_hotKey;
CListBox m_FileList;
CTreeCtrl m_FileTree;
CString m_strFileName;
//}}AFX_DATA
// オーバーライド
// ClassWizard は仮想関数のオーバーライドを生成します。
//{{AFX_VIRTUAL(CUploadDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV サポート
//}}AFX_VIRTUAL// インプリメンテーション
protected: // 生成されたメッセージ マップ関数
//{{AFX_MSG(CUploadDlg)
virtual BOOL OnInitDialog();
afx_msg void OnHotKey(WPARAM wParam,LPARAM lParam);
virtual void OnOK();
virtual void OnCancel();
afx_msg void OnRclickTrDir(NMHDR* pNMHDR, LRESULT* pResult);
afx_msg void OnFolderNew();
afx_msg void OnFolderDel();
afx_msg void OnEndlabeleditTrDir(NMHDR* pNMHDR, LRESULT* pResult);
afx_msg void OnSelchangedTrDir(NMHDR* pNMHDR, LRESULT* pResult);
afx_msg void OnBeginlabeleditTrDir(NMHDR* pNMHDR, LRESULT* pResult);
afx_msg void OnSelchangeLbFile();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
private:
int m_nFlag;
BOOL CheckFolderName(CString strNewName);
BOOL RenameFolder(CString strNewName,CString strOldName);
void FreeMaps();
BOOL DeleteFolder(CString strFolder);
BOOL CreateFolder(CString strFolder);

BOOL InitTree(CString strPathName, HTREEITEM hRootNode);

void SetCtrlHotKey();
void DelCtrlHotKey();
void AppendNode(CString strPathName, HTREEITEM hRootNode);
CImageList m_imageList;
int m_nFolderIcon;
int m_nFolderSelIcon;
};//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ は前行の直前に追加の宣言を挿入します。#endif // !defined(AFX_UPLOADDLG_H__CF78EF8D_8200_4D6B_9839_00AE9C4DCB31__INCLUDED_)

解决方案 »

  1.   


    //////////////////////CPP///////////////////////////////
    // CUploadDlg メッセージ ハンドラBOOL CUploadDlg::OnInitDialog() 
    {
    CString strFileTypeInfo;
    CStringList *pstrNewList;
    CDialog::OnInitDialog();

    if(0 == m_nFlag)
    {
    SetWindowText("アップロードファイルの指定");
    }
    else
    {
    SetWindowText("ダウンロードファイルの指定");
    ((CEdit *)GetDlgItem(IDC_ED_FILENAME))->ShowWindow(SW_HIDE);
    GetDlgItem(IDC_ST_NAME)->ShowWindow(SW_HIDE);
    GetDlgItem(IDOK)->EnableWindow(FALSE);
    }
    //m_btnOk.EnableWindow(FALSE);
    long style = ::GetWindowLong(m_FileTree.GetSafeHwnd(),GWL_STYLE);
    style = style|TVS_HASBUTTONS|TVS_HASLINES|TVS_LINESATROOT;
    ::SetWindowLong(m_FileTree.GetSafeHwnd(),GWL_STYLE,style);

    m_imageList.Create( GetSystemMetrics(SM_CXSMICON), 
              GetSystemMetrics(SM_CYSMICON), 
      ILC_COLOR24, 50, 50);
    m_imageList.SetBkColor( GetSysColor(COLOR_WINDOW) ); CBitmap bitmap;
    bitmap.LoadBitmap(IDB_BM_FOLDER);
    m_nFolderIcon = m_imageList.Add(&bitmap, RGB(0, 0, 0));
    bitmap.DeleteObject();
    bitmap.LoadBitmap(IDB_BM_FOLDEROPEN);
    m_nFolderSelIcon = m_imageList.Add(&bitmap, RGB(0, 0, 0));
    bitmap.DeleteObject();

    // m_nFolderIcon = m_imageList.Add(ExtractIcon( AfxGetApp()->m_hInstance, 
    // "shell32.dll", 3));
    // m_nFolderSelIcon = m_imageList.Add(ExtractIcon( AfxGetApp()->m_hInstance,
    // "shell32.dll", 4));
    m_FileTree.SetImageList(&m_imageList, TVSIL_NORMAL); int nRet = Com_GetFileTypeName(m_strPrjName, "1_0", strFileTypeInfo);
    if(nRet == -1)
    {
    if(503 == ComC_GetErrorCode())
    {
    g_bConnect = TRUE;
    }
    ComC_ShowErrorMsg(nRet);
    return FALSE;
    }
    m_FileTree.DeleteAllItems();
    HTREEITEM hRootNode = m_FileTree.InsertItem(strFileTypeInfo,
    m_nFolderIcon, m_nFolderSelIcon,TVI_ROOT); pstrNewList = new CStringList;
    if(NULL == pstrNewList)
    {
    DisplayMessage(this,TEST_ERR_MALLOC_NG,MB_ICONWARNING);
    return FALSE;
    }
    // pstrNewList->AddTail(strFileTypeInfo);
    m_mapFiles[hRootNode] = pstrNewList; InitTree(" ", hRootNode);
    m_FileTree.Expand(hRootNode, TVE_EXPAND);
    m_FileTree.SelectItem(hRootNode);
    HTREEITEM hNode = m_FileTree.GetSelectedItem();
    SetCtrlHotKey(); return TRUE; 
    }/////////////////////////////////////////////////////////////////////////////
    // 
    // Function Name : OnCancel
    // Parameters    : -
    // Return Value  : -
    //
    void CUploadDlg::OnCancel() 
    {
    FreeMaps();
    DelCtrlHotKey();

    CDialog::OnCancel();
    }/////////////////////////////////////////////////////////////////////////////
    // 
    // Function Name : InitTree
    // Parameters    : strPathName : Path
    //               : hRootNode   : Root node
    // Return Value  : -
    //
    BOOL CUploadDlg::InitTree(CString strPathName, HTREEITEM hRootNode)
    {
    CStringList strFlag, strFileName;
    CStringList *pstrFiles; if(0 != m_nFlag)
    GetDlgItem(IDOK)->EnableWindow(FALSE); pstrFiles = m_mapFiles[hRootNode];
    int nRet = Com_RefreshFileList(strPathName, "1_0", m_strPrjName,
    strFlag, strFileName);
    if(nRet == -1)
    {
    if(503 == ComC_GetErrorCode())
    {
    g_bConnect = TRUE;
    }
    ComC_ShowErrorMsg(nRet);
    return FALSE;
    }
    for(int i = 0; i < strFileName.GetCount();i++)
    {
    if(strFlag.GetAt(strFlag.FindIndex(i)) == "true")
    {
    HTREEITEM hNode = 
    m_FileTree.InsertItem(strFileName.GetAt(strFileName.FindIndex(i)), 
    m_nFolderIcon, m_nFolderSelIcon, hRootNode);
    pstrFiles->AddTail(strFileName.GetAt(strFileName.FindIndex(i))); m_mapFiles[hNode] = new CStringList;
    if(NULL == m_mapFiles[hNode])
    {
    DisplayMessage(this,TEST_ERR_MALLOC_NG,MB_ICONWARNING);
    return FALSE;
    } if(m_FileTree.ItemHasChildren(hRootNode))
    {
    CString strTemp;
    if(strPathName != " ")
    {
    strTemp = strPathName+ "/" +
    strFileName.GetAt(strFileName.FindIndex(i));
    }
    else
    {
    strTemp = strFileName.GetAt(strFileName.FindIndex(i));
    }
    InitTree(strTemp, hNode);
    }
    }
    }
    return TRUE;
    }
      

  2.   

    package pced.main;import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.tree.*;
    import javax.swing.plaf.ColorUIResource;
    import pced.common.*;
    public class ItemCellRenderer extends JPanel
            implements TreeCellRenderer {
        protected TreeLabel label;
        ImageIcon iconWhite = null;
        ImageIcon iconBlack = null;
        public ItemCellRenderer() {
            String strPath = PcedSysProp.getHomePath();
            iconWhite = new ImageIcon(strPath + "\\icon\\whitepoint.gif");
            iconBlack = new ImageIcon(strPath + "\\icon\\blackpoint.gif");
            setLayout(null);
            add(label = new TreeLabel());
            label.setForeground(UIManager.getColor(TestDefine.TREE_TEXTFOREGROUND));
        }    public Component getTreeCellRendererComponent(JTree tree, Object value,
                boolean isSelected, boolean expanded,
                boolean leaf, int row, boolean hasFocus) {
            String  stringValue = tree.convertValueToText(value, isSelected,
                    expanded, leaf, row, hasFocus);
            setEnabled(tree.isEnabled());
            label.setFont(tree.getFont());
            label.setText(stringValue);
            label.setSelected(isSelected);
            label.setFocus(hasFocus);
            if(isSelected)
            {
                label.setIcon(iconBlack);
            }
            else
            {
                label.setIcon(iconWhite);
            }
            return this;
        } 
        public Dimension getPreferredSize() {
            Dimension d_label = label.getPreferredSize();
            return new Dimension(d_label.width, d_label.height);
        }
        public void doLayout() {
            Dimension d_label = label.getPreferredSize();
            int y_check = 0;
            int y_label = 0;
            y_label = (d_label.height)/2;
            label.setLocation(0,y_label);
            label.setBounds(0,0,d_label.width,d_label.height);
        }
        public void setBackground(Color color) {
            if (color instanceof ColorUIResource)
            {
                color = null;
            }
            super.setBackground(color);
        }    public class TreeLabel extends JLabel {
            boolean isSelected;
            boolean hasFocus;        public TreeLabel() {
            }
            public void setBackground(Color color) {
                if(color instanceof ColorUIResource)
                {
                    color = null;
                }
                super.setBackground(color);
            }
            public void paint(Graphics g) {
                String str;
                if ((str = getText()) != null)
                {
                    if (0 < str.length())
                    {
                        if (isSelected)
                        {
                            label.setForeground(Color.white);
                            g.setColor(Color.BLUE);
                        }
                        else
                        {
                            label.setForeground(Color.black);
                            g.setColor(UIManager.getColor(TestDefine.TREE_TEXTBACKGROUND));
                        }
                        Dimension d = getPreferredSize();
                        int imageOffset = 0;
                        Icon currentI = getIcon();
                        if (currentI != null)
                        {
                            imageOffset = currentI.getIconWidth() + Math.max(0,
                                    getIconTextGap() - 1);
                        }
                        g.fillRect(imageOffset, 0, d.width -1 - imageOffset, d.height);
                        if (hasFocus)
                        {
                            g.setColor(UIManager.getColor(TestDefine.TREE_SELBORDERCOLOR));
                            g.drawRect(imageOffset, 0, d.width -1 - imageOffset,
                                       d.height -1);
                        }
                    }
                }
                super.paint(g);
            }        public Dimension getPreferredSize() {
                Dimension retDimension = super.getPreferredSize();
                if (retDimension != null)
                {
                    retDimension = new Dimension(retDimension.width + 3,
                            retDimension.height);
                }
                return retDimension;
            }        public void setSelected(boolean isSelected) {
                this.isSelected = isSelected;
            }        public void setFocus(boolean hasFocus) {
                this.hasFocus = hasFocus;
            }
        }
    }
      

  3.   

    private void initJTree()
        {
            jt = new JTree(buildTreeNode());
            //jt.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
            jt.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
            jt.setCellRenderer(new ItemCellRenderer());
            jt.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
                public void propertyChange(PropertyChangeEvent e) {
                    jt_propertyChange(e);
                }
            });
    刚才发错了!:)