A
download JipeProjectManager.java
Language: Java
License: GPL
Copyright: (c) 1996-1999 Steve Lawson. E-Mail steve@e-i-s.co.uk Latest version can be
LOC: 378
Project Info
Jipe
Server: SourceForge
Type: cvs
...\j\jipe\jipe\jipe\src\jipe\
   BoxComment.java
   BrowserLauncher.java
   ClassBrowser.java
   ClassFilter.java
   DeleteLine.java
   Editor.java
   ExtensionFilter.java
   Find.java
   FindInFiles.java
   HelpConsole.java
   HtmlFilter.java
   IDEOptions.java
   JarFileManager.java
   JavaFilter.java
   JavaOptions.java
   Jipe.java
   JipeCodeCompleter.java
   JipeCompiler.java
   JipeConsole.java
   JipeDecompiler.java
   JipeMethodFinder.java
   JipeProjectManager.java
   JipeUtilities.java
   JSBeautifier.java
   JSFormatter.java
   JSLineBreaker.java
   JspFilter.java
   LeftIndent.java
   ListAllFiles.java
   MasterFilter.java
   Print.java
   PrintManager.java
   ProjectFilter.java
   PropertiesManager.java
   RemoveSpaces.java
   RightIndent.java
   SimpleComment.java
   SpecialFileFilters.java
   StatusBar.java
   StringParser.java
   TextFilter.java
   ToLowerCase.java
   ToUpperCase.java
   WingComment.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
/**
 * ProjectDialog.java - Sets project properties within the Jipe Environment.  Copyright 
 * (c) 1996-1999 Steve Lawson.  E-Mail steve@e-i-s.co.uk Latest version can be 
 * found at http://e-i-s.co.uk/jipe
 * 
 *  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., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
package jipe;

import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.tree.*;

public class JipeProjectManager extends JDialog
{
    static String PROJECTNAME, PROJECTMAIN,SOURCEDIR,CLASSDIR,BUILDSCRIPT;
    boolean OPENPROJECT,SAVEPROJECT;
    static String name;
    static JTextField projectname;
    static JTextField projectmain;
    static JTextField classpath;
    static JTextField classdirectory;
    static JTextField buildscript;
    protected static Vector projectchildren = null;
    DefaultMutableTreeNode projecttreenode;
    TreeSelectionModel selectionModel;
    DefaultTreeModel model;
    static DefaultMutableTreeNode root;
    JTree projecttree;
    JFileChooser fileChooser;

    Container container;
    Jipe jipe;
    JipeProjectManager(Jipe child)
    {
        jipe = child;
        container = this.getContentPane();
        projectchildren = new Vector(4, 4);
        root = new DefaultMutableTreeNode("Root");
        projecttree = new JTree(root);
        model = (DefaultTreeModel)projecttree.getModel();
        selectionModel = projecttree.getSelectionModel();
        projecttree.setRootVisible(false);
        projecttree.setShowsRootHandles(false);
        JScrollPane projectScrollPane=new JScrollPane(projecttree);
        jipe.tabbedPane.addTab("Project", projectScrollPane);

        selectionModel.setSelectionMode(
            TreeSelectionModel.SINGLE_TREE_SELECTION);

        model.addTreeModelListener(new TreeModelListener() {

                                       public void treeNodesInserted(TreeModelEvent e)
                                       {
                                           showInsertionOrRemoval(e, " added to ");
                                       }
                                       public void treeNodesRemoved(TreeModelEvent e)
                                       {
                                           showInsertionOrRemoval(e, " removed from ");
                                       }
                                       private void showInsertionOrRemoval(TreeModelEvent e, String s)
                                       {
                                           Object[] parentPath = e.getPath();
                                           int[] indexes = e.getChildIndices();
                                           Object[] children = e.getChildren();
                                           Object parent = parentPath[parentPath.length - 1];
                                           jipe.statusBar.msgline.setText("File: " + s);
                                       }
                                       public void treeNodesChanged(TreeModelEvent e)
                                       {
                                       }
                                       public void treeStructureChanged(TreeModelEvent e)
                                       {
                                       }
                                   });
        projecttree.addMouseListener(new MouseAdapter(){
                                         public void mousePressed(MouseEvent e)
                                         {
                                             JTree t = (JTree)e.getSource();
                                             int row = t.getRowForLocation(e.getX(), e.getY());

                                             TreePath path = t.getPathForLocation(e.getX(), e.getY());
                                             TreeNode treenode = null;
                                             File file = null;
                                             String nodeName = null;
                                             if (e.getClickCount() == 2)
                                             {
                                                 if (row != -1 && t == projecttree)
                                                 {
                                                     treenode = (TreeNode)path.getLastPathComponent();
                                                     nodeName = treenode.toString();
                                                     if (treenode.isLeaf())
                                                     {
                                                         file=(File)projectchildren.elementAt(row-1);
                                                         if (jipe.GetWindow(file) == false)
                                                             jipe.loadChild(nodeName, file);
                                                     }
                                                 }
                                             }
                                         }
                                     });
    }

    protected void addToProject()
    {
        if (projecttreenode != null)
        {
            int index = projecttreenode.getChildCount();
            File[] files=getAddChildFileName();
            if(files!=null){

                for(int i=0;i<files.length;i++){
                    projectchildren.addElement((Object)files[i]);
                    MutableTreeNode newNode = new DefaultMutableTreeNode(files[i].getName());
                    if(newNode!=null){
                        model.insertNodeInto(newNode, projecttreenode, index);
                        SAVEPROJECT=true;
                    }
                }
            }
        }
    }
    protected void removeFromProject()
    {
        if (projecttreenode != null)
        {
            TreePath path = selectionModel.getSelectionPath();
            if (path.getPathCount() == 1)
            {
                jipe.statusBar.msgline.setText("Can't remove root node!");
                return;
            }
            if (path.getPathCount() == 2)
            {
                // removeProject();
                jipe.statusBar.msgline.setText("Select ' Close Project ' option from menubar");
                return;
            }
            if (path != null)
            {
                MutableTreeNode node =
                    (MutableTreeNode)path.getLastPathComponent();
                if (node.isLeaf()){
                    projectchildren.removeElementAt(selectionModel.getLeadSelectionRow()-1);
                    model.removeNodeFromParent(node);
                    SAVEPROJECT=true;
                }
            }
        }
    }
    protected void ProjectProperties()
    {

        Font font = new Font("Dialog", Font.PLAIN, 11);
        setFont(font);
        setBackground(SystemColor.control);
        JPanel panel = new JPanel();
        GridLayout grid = new GridLayout(0, 2, 4, 0);
        panel.setBorder(
            BorderFactory.createTitledBorder(""));
        panel.setLayout(grid);
        panel.add(new JLabel("Project Name : ", JLabel.CENTER));
        panel.add(projectname = new JTextField("", 15));
        panel.add(new JLabel("Main Class/Html File : ", JLabel.CENTER));
        panel.add(projectmain = new JTextField("", 15));
        panel.add(new JLabel("ClassPath : ", JLabel.CENTER));
        panel.add(classpath = new JTextField("", 15));
        panel.add(new JLabel("Class Directory : ", JLabel.CENTER));
        panel.add(classdirectory = new JTextField("", 15));
        panel.add(new JLabel("Build Script : ", JLabel.CENTER));
        panel.add(buildscript = new JTextField("", 15));
        getContentPane().add("North", panel);

        if(PROJECTNAME!=null){
            projectname.setText(PROJECTNAME);
            projectmain.setText(PROJECTMAIN);
            classpath.setText(SOURCEDIR);
            classdirectory.setText(CLASSDIR);
            buildscript.setText(BUILDSCRIPT);
        }

        final JOptionPane pane= new JOptionPane(
                                    panel, // message
                                    JOptionPane.PLAIN_MESSAGE, // messageType
                                    JOptionPane.OK_CANCEL_OPTION); // optionType


        JDialog dialog = pane.createDialog(
                             this, // parentComponent
                             "Project Properties"); // title

        dialog.setResizable(false);
        dialog.pack();
        dialog.show();

        Integer value=(Integer)pane.getValue();
        OPENPROJECT=true;
        if(value.intValue()==JOptionPane.OK_OPTION)UpdateReferences();
        if(value.intValue()==JOptionPane.CANCEL_OPTION)OPENPROJECT=false;


    }

    protected void OpenNewProject(File projectFile)
    {
        if (projecttreenode != null)CloseProject();
        if (projecttreenode == null){
            if(projectFile==null)return;
            try
            {
                jipe.statusBar.msgline.setText("Loading Project.");
                FileReader fis = new FileReader(projectFile.getPath());
                BufferedReader br = new BufferedReader(fis);

                PROJECTNAME= br.readLine();
                projecttreenode = new DefaultMutableTreeNode(PROJECTNAME);
                PROJECTMAIN = br.readLine();
                SOURCEDIR = br.readLine();
                CLASSDIR = br.readLine();
                BUILDSCRIPT = br.readLine();
                String str = br.readLine();
                while (str != null)
                {
                    File file=new File(str);
                    projectchildren.addElement((Object)file);
                    projecttreenode.add(new DefaultMutableTreeNode(file.getName()));
                    str = br.readLine();
                }
                root.add(projecttreenode);
                model.reload(root);
                jipe.statusBar.msgline.setText("Project Loaded.");
                fis.close();
            }
            catch (Exception err)
            {
                jipe.statusBar.msgline.setText("Error : " + err);
            }
        }
    }

    protected void OpenNewProject()
    {
        if (projecttreenode != null)CloseProject();
        if (projecttreenode == null){
            File projectFile = getFileName("Open Project",3);
            if(projectFile==null)return;
            try
            {
                jipe.statusBar.msgline.setText("Loading Project.");
                FileReader fis = new FileReader(projectFile.getPath());
                BufferedReader br = new BufferedReader(fis);

                PROJECTNAME= br.readLine();
                projecttreenode = new DefaultMutableTreeNode(PROJECTNAME);
                PROJECTMAIN = br.readLine();
                SOURCEDIR = br.readLine();
                CLASSDIR = br.readLine();
                BUILDSCRIPT = br.readLine();
                String str = br.readLine();
                while (str != null)
                {
                    File file=new File(str);
                    projectchildren.addElement((Object)file);
                    projecttreenode.add(new DefaultMutableTreeNode(file.getName()));
                    str = br.readLine();
                }
                root.add(projecttreenode);
                model.reload(root);
                jipe.statusBar.msgline.setText("Project Loaded.");
                fis.close();
            }
            catch (Exception err)
            {
                jipe.statusBar.msgline.setText("Error : " + err);
            }
        }
    }
    protected void CloseProject()
    {
        if(SAVEPROJECT)SaveConfirm("Save Project", "Project not Saved, Save Now?");
        else {
            this.dispose();
            jipe.tabbedPane.removeTabAt(0);
            jipe.project=null;
        }
    }
    protected void NewProject()
    {
        if (projecttreenode != null)CloseProject();
        if (projecttreenode == null){
            ProjectProperties();
            if(OPENPROJECT){
                projecttreenode = new DefaultMutableTreeNode(PROJECTNAME);
                root.add(projecttreenode);
                model.reload(root);
                MutableTreeNode newNode = new DefaultMutableTreeNode(PROJECTNAME+".project");
                model.insertNodeInto(newNode, projecttreenode, 0);
                jipe.addChild(jipe,PROJECTNAME+".project",null);
            }
        }
    }
    protected void SaveProject()
    {
        Vector x=new Vector();
        int i=0;
        while (i < projectchildren.size())
        {
            File tempfile=(File)projectchildren.elementAt(i);
            x.addElement(tempfile.getPath());
            i++;
        }

        File file = getFileName("Save Project",1);
        TreePath selPath;
        TreeNode node;

        if (file==null)return;
        else
        {
            String filename=file.getPath();
            if(!filename.endsWith(".prj"))filename=filename+".prj";
            try
            {
                FileWriter fs = new FileWriter(filename);
                fs.write(PROJECTNAME);
                fs.write(System.getProperty("line.separator"));
                fs.write(PROJECTMAIN);
                fs.write(System.getProperty("line.separator"));
                fs.write(SOURCEDIR);
                fs.write(System.getProperty("line.separator"));
                fs.write(CLASSDIR);
                fs.write(System.getProperty("line.separator"));
                fs.write(BUILDSCRIPT);
                fs.write(System.getProperty("line.separator"));
                i = 0;
                Enumeration e=x.elements();
                while(e.hasMoreElements())
                    fs.write(e.nextElement() + System.getProperty("line.separator"));
                fs.close();
                SAVEPROJECT=false;
            }
            catch (Exception err)
            {
            }
        }
    }
    public void SaveConfirm(String confirmTitle, String confirmText)
    {
        int value = JOptionPane.showConfirmDialog(
                        getContentPane(), confirmText, confirmTitle, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
        switch (value)
        {
        case JOptionPane.YES_OPTION:
            SaveProject();
        case JOptionPane.NO_OPTION:
            this.dispose();
            jipe.tabbedPane.removeTabAt(0);
            jipe.project=null;
        case JOptionPane.CANCEL_OPTION:
        }
    }

    protected File getFileName(String title,int type){
        fileChooser = new JFileChooser(jipe.CURRENTDIR);
        fileChooser.setMultiSelectionEnabled(false);
        fileChooser.setDialogTitle(title);
        fileChooser.addChoosableFileFilter(new ProjectFilter());
        int selected=0;
        if(type==1)selected = fileChooser.showSaveDialog(container);
        else selected = fileChooser.showOpenDialog(container);
        if (selected == JFileChooser.APPROVE_OPTION){
            jipe.CURRENTDIR=fileChooser.getCurrentDirectory();
            return fileChooser.getSelectedFile();
        }
        else if (selected == JFileChooser. CANCEL_OPTION)
            return null;
        return null;
    }

    protected File[] getAddChildFileName()
    {
        fileChooser = new JFileChooser(jipe.CURRENTDIR);
        fileChooser.setMultiSelectionEnabled(true);
        fileChooser.setDialogTitle("Add Files to Project");
        fileChooser.addChoosableFileFilter(new TextFilter());
        fileChooser.addChoosableFileFilter(new JspFilter());
        fileChooser.addChoosableFileFilter(new HtmlFilter());
        fileChooser.addChoosableFileFilter(new JavaFilter());
        fileChooser.addChoosableFileFilter(new ProjectFilter());
        fileChooser.setFileFilter(new JavaFilter());
        int selected = fileChooser.showOpenDialog(container);

        if (selected == JFileChooser.APPROVE_OPTION){
            jipe.CURRENTDIR=fileChooser.getCurrentDirectory();
            return fileChooser.getSelectedFiles();
        }
        else if (selected == JFileChooser. CANCEL_OPTION)
            return null;
        return null;
    }

    public void UpdateReferences(){
        PROJECTNAME=projectname.getText().trim();
        PROJECTMAIN=projectmain.getText().trim();
        SOURCEDIR=classpath.getText().trim();
        CLASSDIR=classdirectory.getText().trim();
        BUILDSCRIPT=buildscript.getText().trim();
        SAVEPROJECT=true;
    }
}

About Koders | Resources | Downloads | Support | Black Duck | Terms of Service | DMCA | Privacy Policy | Contact Us