A
download Jipe.java
Language: Java
License: GPL
Copyright: (c) 1996-2000 Steve Lawson. E-Mail
LOC: 887
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
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
/**
 * Jipe.java - Main Class for Jipe.  Copyright (c) 1996-2000 Steve Lawson.  E-Mail 
 * steve@e-i-s.co.uk Latest version 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.util.List;		//DnD
//import java.util.Iterator;	//Dnd
//import java.awt.dnd.*;		//Dnd
//import java.awt.datatransfer.*;//Dnd

import java.util.*;
import java.io.*;
import javax.swing.text.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.tree.*;
import java.net.URL;
import java.util.Date;
import java.text.SimpleDateFormat;

import org.gjt.sp.jedit.syntax.*;
import org.gjt.sp.jedit.textarea.*;

/**
 * The main Jipe application class.
 * 
 * history:
 * 12 July 2000 mgh: in displayFindDialog(), added correct curly braces for if not null check
 * 12 July 2000 mgh: renamed Find() method to displayFindDialog()
 */
public class Jipe extends JFrame implements ActionListener  //,DropTargetListener

{
    JipeCompiler compile;
    PropertiesManager props;
    JipeConsole jipeconsole;
    JipeMethodFinder speedbar;
    IDEOptions optiondialog;
    JavaOptions optionJavadialog;
    JipeProjectManager project;
    Find find;
    FindInFiles findin;
    StatusBar statusBar;
    JarFileManager jarFileManager;
    JFileChooser fileChooser;
    HelpConsole helpConsole;
    static String lnfName = null;
    File CURRENTDIR;

    Container container;
    static JMenu window;
    protected static Vector children = null;
    protected static Editor activeChild = null;

    JTree directorytree;


    TreeSelectionModel dirselectionModel;

    public JList errorlistPanel,filesearchlistPanel;
    public DefaultListModel errorModel,filesearchModel;

    private static Properties jipeProperties;
    private Hashtable commands;
    private JMenuBar menubar;

    private JToolBar toolbar,toolbar1,toolbar2;
    static JTabbedPane tabbedPane;
    static JTabbedPane tabbedPane2;
    static JTabbedPane tabbedPane3;

    JPopupMenu popup, popup2;
    static JSplitPane sp,sp2,sp3;
    protected static int window_num = 0;
    static JMenuItem windowitem;
    static JCheckBoxMenuItem view;
    String textcache = "";
    static int saveorquitoption = 0;
    protected int Buttonswitch = 0;
    static int screenHeight;

    static String ABOUTMSG =
        "      Jipe Version 0.92\n      ---------------------------\n"+
        "Written by Steve Lawson \nemail: steve@e-i-s.co.uk \n   Visit : e-i-s.co.uk\\jipe \n"+
        "\n  Copyright 1996-2000.";
    static String gplLicence =
        "/*\n *  <one line to give the program's name and a brief idea of what it does.>\n"+
        " *  Copyright (C) 20yy  <name of author>\n *\n *  This program is free software;"+
        " you can redistribute it and/or modify\n *  it under the terms of the GNU General "+
        "Public License as published by\n *  the Free Software Foundation; either version 2 of"+
        " the License, or\n *  (at your option) any later version.\n *\n *  This program is "+
        "distributed in the hope that it will be useful,\n *  but WITHOUT ANY WARRANTY; without"+
        " even the implied warranty of\n *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."+
        "  See the\n *  GNU General Public License for more details.\n *\n *  You should have"+
        " received a copy of the GNU General Public License\n *  along with this program; if not, "+
        "write to the Free Software\n *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n */ ";

    /**
     * Suffix applied to the key used in resource file lookups for an image.
     */
    public static final String imageSuffix = "Image";

    /**
     * Suffix applied to the key used in resource file lookups for a label.
     */
    public static final String labelSuffix = "Label";

    /**
     * Suffix applied to the key used in resource file lookups for tooltip 
     * text.
     */
    public static final String tipSuffix = "Tooltip";
    public Jipe()
    {
        super("Jipe");
        container = this.getContentPane();
        props=new PropertiesManager(this);

        // Force SwingSet to come up in the Cross Platform L&F
        try
        {
            if (props.LOOKANDFEEL.startsWith("Metal"))
                lnfName = "javax.swing.plaf.metal.MetalLookAndFeel";
            else if (props.LOOKANDFEEL.startsWith("Window"))
                lnfName ="com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
            else if (props.LOOKANDFEEL.startsWith("CDE/Motif"))
                lnfName = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
            else
                lnfName = UIManager.getCrossPlatformLookAndFeelClassName();
            UIManager.setLookAndFeel(lnfName);
        }
        catch (Exception exc)
        {
            System.err.println("Error loading L&F: " + exc);
        }
        try
        {
            jipeProperties = new Properties();
            String userdir = System.getProperty("user.home");
            userdir = userdir + System.getProperty("file.separator") +
                      "jipecontrol.properties";
            File file = new File(userdir);
            if (file.exists())
                jipeProperties.load(new FileInputStream(userdir));
            else
            {
                InputStream is = getClass().getResourceAsStream(
                                     "resources/jipecontrol.properties");
                jipeProperties.load(is);
            }
        }
        catch (Exception e)
        {
            System.out.println(e);
        }
        

        
        CURRENTDIR=new File(System.getProperty("user.dir"));
        tabbedPane = new JTabbedPane();
        tabbedPane2 = new JTabbedPane();
        tabbedPane3 = new JTabbedPane();
        speedbar=new JipeMethodFinder(this);
        sp = new JSplitPane(JSplitPane.VERTICAL_SPLIT, tabbedPane, (new JScrollPane
                            (speedbar.results)));
        sp.setOneTouchExpandable(true);
        errorlistPanel = new JList();
        errorModel = new DefaultListModel();
        errorlistPanel.setVisibleRowCount(10);
        errorlistPanel.setFont(new Font(props.FONTSTYLE, 0, props.FONTSIZE));

        filesearchlistPanel= new JList();
        filesearchModel= new DefaultListModel();
        filesearchlistPanel.setVisibleRowCount(10);
        filesearchlistPanel.setFont(new Font(props.FONTSTYLE, 0, props.FONTSIZE));

        sp3 = new JSplitPane(
                  JSplitPane.VERTICAL_SPLIT, tabbedPane2, tabbedPane3);
        sp3.setOneTouchExpandable(true);
        sp2 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, sp, sp3);
        sp2.setOneTouchExpandable(true);
        menubar = new JMenuBar();
        popup = createPopupMenu("popup");
        popup2 = createPopupMenu("popup2");
        JPanel panel = new JPanel();
        panel.setLayout(new GridLayout(3, 1));
        statusBar = new StatusBar();


        menubar = createMenubar();


        panel.add(menubar);
        panel.add(createToolbar(1));
        panel.add(createToolbar(2));
        getContentPane().add(panel, BorderLayout.NORTH);
        getContentPane().add(sp2, BorderLayout.CENTER);
        getContentPane().add(statusBar, BorderLayout.SOUTH);
        children = new Vector(4, 4);
        tabbedPane.setFont(new Font("dialog", Font.PLAIN, 11));
        tabbedPane2.setFont(new Font("dialog", Font.PLAIN, 11));
        tabbedPane3.setFont(new Font("dialog", Font.PLAIN, 11));
        jipeconsole=new JipeConsole(this);
        tabbedPane3.addTab("Console", new JScrollPane(jipeconsole.jipeConsole));
        tabbedPane3.addTab("Errors", new JScrollPane(errorlistPanel));
        tabbedPane3.addTab("Search",new JScrollPane(filesearchlistPanel));
        tabbedPane3.setTabPlacement(JTabbedPane.BOTTOM);

//        tabbedPane2.setDropTarget(new DropTarget(this,this));

        tabbedPane2.addChangeListener(new ChangeListener() {

                                          public void stateChanged(ChangeEvent e)
                                          {
                                              JTabbedPane tp = (JTabbedPane)e.getSource();
                                              int index = tp.getSelectedIndex();
                                              if (index >= 0)
                                              {
                                                  String s = tp.getTitleAt(index);
                                                  GetWindow(new File(s));
                                              }
                                          }
                                      });

        tabbedPane2.addMouseListener(new MouseAdapter() {
                                         public void mouseClicked(MouseEvent me) {
                                             if ((me.getModifiers() & me.BUTTON3_MASK) != 0)popup2.show(tabbedPane2, me.getX(), me.getY());
                                         }
                                     });

        setBounds(props.XPOS,props.YPOS,props.XSIZE,props.YSIZE);
        sp2.setDividerLocation(props.DIV2);
        sp.setDividerLocation(props.DIV1);
        sp3.setDividerLocation(props.DIV3);
        this.setIconImage(JipeIcon());

        setVisible(true);


        this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);

        this.addWindowListener(new WindowAdapter() {

                                   public void windowClosing(WindowEvent e)
                                   {
                                       close();
                                   }
                               });
    }
    ////////////////// Start of DnD Code /////////////////////
/*    public void dragEnter (DropTargetDragEvent evt) { }
    public void dragOver (DropTargetDragEvent evt) { }
    public void dragExit (DropTargetEvent evt) { }
    public void dragScroll (DropTargetDragEvent evt) { }
    public void dropActionChanged (DropTargetDragEvent evt) { }

    public void drop (DropTargetDropEvent evt)
    {
        DataFlavor[] flavors = evt.getCurrentDataFlavors();
        if (flavors == null)
            return;

        boolean dropCompleted = false;
        for (int i = flavors.length - 1; i >= 0; i--)
        {
            if (flavors[i].isFlavorJavaFileListType())
            {
                evt.acceptDrop(DnDConstants.ACTION_COPY);
                Transferable transferable = evt.getTransferable();
                try
                {
                    Iterator iterator = ((List) transferable.getTransferData(flavors[0])).iterator();
                    while (iterator.hasNext())
                    {
                        loadChild( "Open",((File) iterator.next()));
                    }
                    dropCompleted = true;
                } catch (Exception e) { }
            }
        }
        evt.dropComplete(dropCompleted);
    }*/
    ////////////////// End of DnD Code /////////////////////
    
    
    public Image JipeIcon(){
        Image imageIcon=getToolkit().getImage(getClass().getResource("resources/jipeicon.gif"));
        return imageIcon;
    }

    /**
     * Converts a string to a keystroke.
     * 
     * The string should be of the form <i>modifiers</i>+<i>shortcut</i> where 
     * <i>modifiers</i> is any combination of A for Alt, C for Control, S for 
     * Shift or M for Meta, and <i>shortcut</i> is either a single character, 
     * or a keycode name from the <code>KeyEvent</code> class, without the 
     * <code>VK_</code> prefix.
     * 
     * @param keyStroke A string description of the key stroke
     */
    public static KeyStroke parseKeyStroke(String keyStroke)
    {
        if (keyStroke == null)
            return null;
        int modifiers = 0;
        int ch = '\0';
        int index = keyStroke.indexOf('+');
        if (index != -1)
        {
            for (int i = 0; i < index; i++)
            {
                switch (Character.toUpperCase(keyStroke.charAt(i)))
                {
                case 'A':
                    modifiers |= InputEvent.ALT_MASK;
                    break;
                case 'C':
                    modifiers |= InputEvent.CTRL_MASK;
                    break;
                case 'M':
                    modifiers |= InputEvent.META_MASK;
                    break;
                case 'S':
                    modifiers |= InputEvent.SHIFT_MASK;
                    break;
                }
            }
        }
        String key = keyStroke.substring(index + 1);
        if (key.length() == 1)
            ch = Character.toUpperCase(key.charAt(0));
        else if (key.length() == 0)
        {
            System.err.println("Invalid key stroke: " + keyStroke);
            return null;
        }
        else
        {
            try
            {
                ch = KeyEvent.class.getField("VK_".concat(key)).getInt(null);
            }
            catch (Exception e)
            {
                System.err.println("Invalid key stroke: " + keyStroke);
                return null;
            }
        }
        return KeyStroke.getKeyStroke(ch, modifiers);
    }

    /**
     * Create the menubar for the app.
     * 
     * By default this pulls the definition of the menu from the associated 
     * resource file.
     */
    protected JMenuBar createMenubar()
    {
        JMenuBar mb = new JMenuBar();
        String[] menuKeys = tokenize(jipeProperties.getProperty("menulist"));
        for (int i = 0; i < menuKeys.length; i++)
        {
            JMenu m = createMenu(menuKeys[i]);
            if (m != null)
            {
                m.setFont(new Font("dialog", Font.PLAIN, 11));
                mb.add(m);
            }
        }
        return mb;
    }

    /**
     * Create a menu for the app.
     * 
     * By default this pulls the definition of the menu from the associated 
     * resource file.
     */
    protected JMenu createMenu(String key)
    {
        String[] itemKeys = tokenize(jipeProperties.getProperty(key));
        JMenu menu = new JMenu(jipeProperties.getProperty(key + "Label"));
        if(jipeProperties.getProperty(key + "Label").equals("Windows"))window=menu;

        menu.setMnemonic(jipeProperties.getProperty(key + "Label").charAt(0));
        for (int i = 0; i < itemKeys.length; i++)
        {
            if (itemKeys[i].equals("-"))
            {
                menu.addSeparator();
            }
            else
            {
                if(key.startsWith("view")){
                    JMenuItem mi = createCheckBoxMenuItem(itemKeys[i]);
                    mi.setEnabled(false);
                    menu.add(mi);
                }
                else
                {
                    JMenuItem mi = createMenuItem(itemKeys[i]);
                    menu.add(mi);
                }
            }
        }
        return menu;
    }

    /**
     * This is the hook through which all menu items are created.
     * 
     * It registers the result with the menuitem hashtable so that it can be 
     * fetched with getMenuItem().
     * 
     * @see #getMenuItem
     */
    protected JMenuItem createMenuItem(String cmd)
    {
        JMenuItem mi = new JMenuItem(jipeProperties.getProperty(cmd + labelSuffix));
        KeyStroke keyStroke = parseKeyStroke(jipeProperties.getProperty(cmd + "Key"));
        mi.setFont(new Font("dialog", Font.PLAIN, 11));
        mi.setAccelerator(keyStroke);
        URL url = getResource(cmd + imageSuffix);
        if (url == null)url = getResource("blankItemImage");
        mi.setHorizontalTextPosition(JButton.RIGHT);
        mi.setIcon(new ImageIcon(url));
        mi.addActionListener(this);
        mi.setActionCommand(cmd);
        return mi;
    }

    /**
     * This is the hook through which all CheckBox menu items are created.
     * 
     * It registers the result with the menuitem hashtable so that it can be 
     * fetched with getMenuItem().
     * 
     * @see #getMenuItem
     */
    protected JMenuItem createCheckBoxMenuItem(String cmd)
    {
        view = new JCheckBoxMenuItem(jipeProperties.getProperty(cmd + labelSuffix));
        KeyStroke keyStroke = parseKeyStroke(jipeProperties.getProperty(cmd + "Key"));
        view.setFont(new Font("dialog", Font.PLAIN, 11));
        view.setAccelerator(keyStroke);
        URL url = getResource(cmd + imageSuffix);
        if (url == null)url = getResource("blankItemImage");
        view.setHorizontalTextPosition(JButton.RIGHT);
        view.setIcon(new ImageIcon(url));
        view.addActionListener(this);
        view.setActionCommand(cmd);
        return view;
    }

    protected URL getResource(String key)
    {
        String name = jipeProperties.getProperty(key);
        if (name != null)
        {
            URL url = this.getClass().getResource(name);
            return url;
        }
        return null;
    }
    protected Container getToolbar()
    {
        return toolbar;

    }
    protected JMenuBar getMenubar()
    {
        return menubar;
    }

    /**
     * Create the toolbar.
     * 
     * By default this reads the resource file for the definition of the 
     * toolbar.
     */
    private Component createToolbar(int toolrow)
    {
        toolbar = new JToolBar();
        toolbar.setFloatable(false);
        toolbar.putClientProperty("JToolBar.isRollover",Boolean.TRUE);
        String[] toolKeys = tokenize(jipeProperties.getProperty("toolbar" + toolrow));
        for (int i = 0; i < toolKeys.length; i++)
        {
            if (toolKeys[i].equals("-"))toolbar.add(Box.createHorizontalStrut(5));
            else toolbar.add(createTool(toolKeys[i]));
        }
        return toolbar;
    }

    /**
     * Hook through which every toolbar item is created.
     */
    protected Component createTool(String key)
    {
        return createToolbarButton(key);
    }

    /**
     * Create a button to go inside of the toolbar.
     * 
     * By default this will load an image resource.  The image filename is 
     * relative to the classpath (including the '.' directory if its a part of 
     * the classpath), and may either be in a JAR file or a separate file.
     * 
     * @param key The key in the resource file to serve as the basis of 
     *            lookups.
     */
    protected JButton createToolbarButton(String key)
    {
        URL url = getResource(key + imageSuffix);
        JButton b = new JButton(new ImageIcon(url)) {

                        public float getAlignmentY()
                        {
                            return 0.5f;
                        }
                    };
        b.setRequestFocusEnabled(false);
        b.setMargin(new Insets(1, 1, 1, 1));
        b.setActionCommand(key);
        b.addActionListener(this);
        String tip = jipeProperties.getProperty(key + tipSuffix);
        if (tip != null)
        {
            b.setToolTipText(tip);
        }
        return b;
    }

    /**
     * Take the given string and chop it up into a series of strings on 
     * whitespace boundries.
     * 
     * This is useful for trying to get an array of strings out of the 
     * resource file.
     */
    protected String[] tokenize(String input)
    {
        Vector v = new Vector();
        StringTokenizer t = new StringTokenizer(input);
        String[] cmd;
        while (t.hasMoreTokens())
            v.addElement(t.nextToken());
        cmd = new String[v.size()];
        for (int i = 0; i < cmd.length; i++)
            cmd[i] = (String)v.elementAt(i);
        return cmd;
    }

    /**
    * Create the popupMenu.
    * 
    * By default this reads the resource file for the definition of the 
    * toolbar.
    */
    private JPopupMenu createPopupMenu(String popupType)
    {
        JPopupMenu popUp = new JPopupMenu();
        String[] toolKeys = tokenize(jipeProperties.getProperty(popupType));
        for (int i = 0; i < toolKeys.length; i++)
        {
            if (toolKeys[i].equals("-"))
            {
                popUp.addSeparator();
            }
            else
            {
                popUp.add(createMenuItem(toolKeys[i]));
            }
        }
        return popUp;
    }


    /**
     * Respond to users requests
     */
    public void actionPerformed(ActionEvent e)
    {
        String source = e.getActionCommand();
        if (source.equals("opendocument"))
            loadChild("Load", null);
        else if (source.equals("newplain"))
            addChild(this, "Untitled", null);
        if (source.equals("quitItem"))
            close();
        else if (source.equals("newhtml"))
            addChild(this, "Html", null);
        else if (source.equals("newjava"))
            addChild(this, "Java", null);
        else if (project!=null && source.equals("addprojectItem"))
            project.addToProject();
        else if (project!=null && source.equals("removeprojectItem"))
            project.removeFromProject();
        else if (project!=null && source.equals("projectproperties"))
            project.ProjectProperties();
        else if (source.equals("jarFileManagerItem"))
        {
            jarFileManager = new JarFileManager(
                                 this, "Jipe JarFileManager");
        }
        else if (source.equals("classBrowserItem"))OpenClassBrowser();
        else if (source.equals("decompileItem"))DecompileClass();
        else if (source.equals("aboutItem"))
        {
            JOptionPane aboutPane = new JOptionPane();
            aboutPane.setFont(new Font("dialog", Font.PLAIN, 11));
            aboutPane.showMessageDialog(this, ABOUTMSG, "About Jipe", JOptionPane.INFORMATION_MESSAGE, new ImageIcon
                                        (getClass().getResource("resources/jipe.gif")));
        }
        else if (source.equals("helpItem"))
        {
            if (helpConsole == null)
                helpConsole = new HelpConsole(this);
        }
        else if (source.equals("javadocsItem"))
            OpenJavaDoc();
        else if (source.equals("closeallItem"))
            CloseAll();
        else if (project!=null && source.equals("closeprojectItem"))CloseProject();
        else if (source.equals("openproject")){
            if(project!=null)CloseProject();
            project=new JipeProjectManager(this);
            project.OpenNewProject();
        }
        else if (source.equals("newprojectItem")){
            if(project!=null)CloseProject();
            project=new JipeProjectManager(this);
            project.NewProject();
        }
        else if (project!=null && source.equals("saveprojectItem"))
            project.SaveProject();
        else if (source.equals("optionsItem")){
            //        try{
            optiondialog = new IDEOptions(this);
            //        } catch(Exception ex){}
        }

        else if (source.equals("optionsJavaItem")){
            //        try{
            optionJavadialog = new JavaOptions(this);
            //        } catch(Exception ex){}
        }
        else if (source.equals("compileallItem"))
            CompileAll();
        else if (source.equals("runScriptItem"))
            RunScript();
        else if (source.equals("debugItem"))
            RunCommandLine(props.DEBUG, "");
        else if (source.equals("debugapplicationItem"))
            RunCommandLine("java -debug",activeChild.file.getPath());
        else if (source.equals("debugappletItem"))
        {
            if((System.getProperty("file.separator")).equals("\\")){
                StringParser ps = new StringParser();
                RunCommandLine("appletviewer -debug",ps.makeAppletCommand(activeChild.file.getPath()));
            }
            else
                RunCommandLine("appletviewer -debug",activeChild.file.getPath());
        }
        else if(source.equals("codeCompleterItem")){
            JipeCodeCompleter codeCompleter=new JipeCodeCompleter(this,activeChild.textarea);
        }
        else if (source.equals("findinfilesItem"))
            FindInFiles();
        /*        else if(source.equals("viewpmanagerItem"))sp.getBottomComponent();
                else if(source.equals("viewSpeedBarItem"))System.exit(0);
                else if(source.equals("viewStatusBarItem"))System.exit(0);
                else if(source.equals("viewConsoleItem"))System.exit(0);
                //               else if(source.equals("viewToolBar1Item"))
                //               else if(source.equals("viewToolBar2Item"))      */
        else if (source.equals("closeItem")){
            if(tabbedPane2.getTitleAt(tabbedPane2.getSelectedIndex()).equals("- Help -")){
                helpConsole.close();
                helpConsole=null;
            }
            else if (activeChild!=null)activeChild.close();
        }
        if (activeChild != null)
        {
            if (source.equals("findItem"))
                displayFindDialog();
            else if (source.equals("findNextItem"))
                FindNext();
            else if (source.equals("parseItem") && activeChild.file.getPath().endsWith
                     (".java"))
                speedbar.parse();
            else if (source.equals("gotoItem"))
                activeChild.Goto();
            else if (source.equals("saveItem"))
                activeChild.SaveFile(false);
            else if (source.equals("saveasItem"))
                activeChild.SaveFile(true);
            else if (source.equals("printItem"))
                Print();
            else if (source.equals("applicationItem"))
                RunCommandLine(props.JAVA, activeChild.getTitle());
            else if (source.equals("appletviewerItem")){
                if((System.getProperty("file.separator")).equals("\\")){
                    StringParser ps = new StringParser();
                    RunCommandLine(props.APPLETVIEWER,ps.makeAppletCommand(activeChild.file.getPath()));
                }
                else
                    RunCommandLine(props.APPLETVIEWER,activeChild.file.getPath());
            }
            else if (source.equals("compilerItem")){
                if((System.getProperty("file.separator")).equals("\\")){
                    StringParser ps = new StringParser();
                    RunCompiler(ps.ModifyPath(activeChild.file.getPath()));
                }
                else RunCompiler(activeChild.file.getPath());
            }
            else if (source.equals("browserItem"))
                RunCommandLine(props.BROWSER, activeChild.file.getPath());
            else if (source.equals("undoItem"))
                activeChild.undoAction();
            else if (source.equals("redoItem"))
                activeChild.redoAction();
            else if (source.equals("cutItem"))
                activeChild.textarea.cut();
            else if (source.equals("copyItem"))
                activeChild.textarea.copy();
            else if (source.equals("pasteItem"))
                activeChild.textarea.paste();
            else if (source.equals("selectItem"))
                activeChild.textarea.selectAll();
            else if (source.equals("deletelineItem")){
            	DeleteLine deleteLine;
            	deleteLine=new DeleteLine(activeChild.textarea);
            }
            else if (source.equals("lowercaseItem")){
            	ToLowerCase toLowerCase;
            	toLowerCase=new ToLowerCase(activeChild.textarea);
            }
            else if (source.equals("uppercaseItem")){
            	ToUpperCase toUpperCase;
            	toUpperCase=new ToUpperCase(activeChild.textarea);
            }
            else if (source.equals("commentItem")){
            	SimpleComment simpleComment;
            	simpleComment=new SimpleComment(activeChild.textarea);
            }
            else if (source.equals("boxcommentItem")){
            	BoxComment boxComment;
            	boxComment=new BoxComment(activeChild.textarea);
            }
            else if (source.equals("wingcommentItem")){
            	WingComment wingComment;
            	wingComment=new WingComment(activeChild.textarea);
            }
            else if( source.equals("removespacesItem")){
            	RemoveSpaces removespaces;
            	removespaces=new RemoveSpaces(activeChild.textarea);
            }
            else if( source.equals("indentleftItem")){
            	LeftIndent leftIndent;
            	leftIndent=new LeftIndent(activeChild.textarea);
            }
            else if( source.equals("indentrightItem")){
            	RightIndent rightIndent;
            	rightIndent=new RightIndent(activeChild.textarea);
            }
            else if (source.equals("indentItem"))
            {
                activeChild.indent();
                speedbar.parse();
                activeChild.textarea.setDirty();
                tabbedPane2.setForegroundAt(tabbedPane2.getSelectedIndex(), Color.red.darker());
            }
            else if (source.equals("insertDateItem"))
            {
                Date date = new Date();
                SimpleDateFormat sdf = new SimpleDateFormat(
                                           "dd/MMM/yyyy - HH:mm:ss");
                activeChild.textarea.setSelectedText(sdf.format(date));
                activeChild.textarea.setDirty();
                tabbedPane2.setForegroundAt(tabbedPane2.getSelectedIndex(), Color.red.darker());
            }
            else if (source.equals("gplLicenceItem"))
            {
                activeChild.textarea.setSelectedText(gplLicence);
                activeChild.textarea.setDirty();
                tabbedPane2.setForegroundAt(tabbedPane2.getSelectedIndex(), Color.red.darker());
            }
            else
                GetWindow(new File(source));
        }
        else
            GetWindow(new File(source));
    }
    public void displayFindDialog()
    {
        if (find == null)
        {
            find = new Find(this, activeChild.textarea);
        }
        if (find != null)
            Find.editor = activeChild.textarea;
        find.setVisible(true);
    }
    public void FindNext(){
        if(find==null){
        	displayFindDialog();
        }
        else find.find();
    }
    public void FindInFiles()
    {
        if (findin == null)
        {
            findin = new FindInFiles(this);
        }
        if (findin != null)
            findin.setVisible(true);
        findin.requestFocus();
    }
    public void close()
    {
        CloseAll();
        props.SaveOptions();
        if(children.isEmpty())System.exit(0);
    }
    public boolean GetWindow(File windowname)
    {
        for (int i = 0; i < window.getItemCount(); i++)
        {
            if (window.getItem(i) == null || children.isEmpty())
            {
                continue;
            }
            if (windowname.getName().equals(window.getItem(i).getText()))
            {
                if(windowname.getName().equals("- Help -")){
                    tabbedPane2.setSelectedIndex(tabbedPane2.indexOfTab("- Help -"));
                    statusBar.msgline.setText("Help Window");
                    activeChild=null;
                }
                else{
                    Editor child = (Editor)children.elementAt(i - 4);
                    if (child != null)
                    {
                        activeChild = child;
                        tabbedPane2.setSelectedIndex(tabbedPane2.indexOfTab(
                                                         activeChild.getTitle()));
                        statusBar.msgline.setText("Current Window : " +
                                                  activeChild.getTitle());
                        if (activeChild.getTitle().endsWith(".java"))
                            speedbar.parse();
                        else
                            speedbar.removeList();
                    }
                    statusBar.updateStatus(activeChild.textarea);
                    return true;
                }
            }
        }
        return false;
    }

    // This method used to update the details for an existing child

    public void addChild(Jipe parent, Editor child)
    {
        children.addElement((Object)child);
        statusBar.msgline.setText("Current Window : " + child.getTitle());
        window.add(windowitem = new JMenuItem(child.getTitle()));
        windowitem.setFont(new Font("dialog", Font.PLAIN, 11));
        windowitem.addActionListener(parent);
        activeChild = child;
        if (child.getTitle().endsWith(".java"))
            speedbar.parse();
    }


    public void loadChild(String title, File importfile)
    {
        File file = importfile;
        if (title == "Load" || file != null)
        {
            if (title == "Load")file = getAddChildFileName("Open File");
            if (file != null)
            {
                if(fileChooser!=null)CURRENTDIR=fileChooser.getCurrentDirectory();
                if (GetWindow(file) == false)
                    addChild(this, file.getName(), file);
            }
        }
    }

    protected File getAddChildFileName(String title)
    {
        fileChooser = new JFileChooser();
        fileChooser.setCurrentDirectory(CURRENTDIR);
        fileChooser.setMultiSelectionEnabled(false);
        fileChooser.setDialogTitle(title);
        fileChooser.addChoosableFileFilter(new TextFilter());
        fileChooser.addChoosableFileFilter(new JspFilter());
        fileChooser.addChoosableFileFilter(new HtmlFilter());
        fileChooser.addChoosableFileFilter(new ProjectFilter());
        fileChooser.setFileFilter(new JavaFilter());
        int selected = fileChooser.showOpenDialog(container);
        if (selected == JFileChooser.APPROVE_OPTION)
            return fileChooser.getSelectedFile();
        else if (selected == JFileChooser. CANCEL_OPTION)
            return null;
        return null;
    }

    public void addChild(Jipe parent, String title, File importfile)
    {
        Editor child;
        if (title == "Untitled" || title == "Html" || title == "Java")
        {
            child = new Editor(parent, title, null);
            if (title.equals("Html"))
                child.textarea.setText(
                    "\n<HTML>\n<HEAD>\n<TITLE> Your Title here</TITLE>\n</HEAD>\n<BODY>\n<H1>Your heading"+
                    " here</H1>\n<applet code=\"Your.class\" width=350 height=350>\n</applet>\n</BODY>\n</HTML>");
            title = title + window_num;
            child.setTitle(title);
            window_num++;
        }
        else if(title.endsWith(".project")){
            child = new Editor(parent, title, null);
            child.setTitle(title);
            child.textarea.setText("Project Details:\nAuthor:\nDate:\nProject Description\n\nNotes:");
            child.textarea.setDirty();
        }

        else
        {
            child = new Editor(parent, title, importfile);
            child.file = importfile;
            child.load(title);
        }
        child.setLocation(200, 0);
        child.setSize(440, screenHeight - 200);
        tabbedPane2.add(child.textarea, child.getTitle());
        tabbedPane2.setSelectedIndex(tabbedPane2.getTabCount() - 1);
        children.addElement((Object)child);
        statusBar.msgline.setText("Current Window : " + child.getTitle());
        window.add(windowitem = new JMenuItem(child.getTitle()));
        windowitem.setFont(new Font("dialog", Font.PLAIN, 11));
        windowitem.addActionListener(parent);
        activeChild = child;
        activeChild.textarea.setCaretPosition(0);
        statusBar.updateStatus(activeChild.textarea);
        if (child.getTitle().endsWith(".java"))
            speedbar.parse();

    }

    public void Print()
    {
        String vers = System.getProperty("java.version");

        if (vers.compareTo("1.2") < 0)
        {
            PrintManager print = new PrintManager(this, activeChild.textarea.getText());
        }
        else
        {
            Print print;
            print = new Print((PlainDocument)activeChild.textarea.getDocument(), new Font
                              (props.FONTSTYLE, 0, props.FONTSIZE));
        }

    }

    public void RunCommandLine(String nameOption, String nameExtension)
    {
        if ((nameOption.endsWith("java.exe") || nameOption.endsWith("java"))&&(nameExtension.endsWith(".java"))){

            nameExtension = nameExtension.substring(0,
                                                    nameExtension.length() - 5);
            if(props.OUTPUTDIR.trim().length()>=1)nameExtension="-classpath "+props.OUTPUTDIR+" " +nameExtension;
            else nameExtension="-classpath "+activeChild.file.getParent()+" "+nameExtension;

        }
        tabbedPane3.setSelectedIndex(0);
        System.out.println(nameOption+" "+nameExtension);
        try
        {
            jipeconsole.RunCommand(nameOption+" "+nameExtension);

        }
        catch (IOException e)
        {
            jipeconsole.jipeConsole.append(e+ System.getProperty("line.separator"));
        }
    }

    public void RunScript(){
        JFileChooser chooser=new JFileChooser();
        int state=chooser.showOpenDialog(null);
        File file=chooser.getSelectedFile();
        if(file!=null && state==JFileChooser.APPROVE_OPTION) {
            try
            {
                jipeconsole.RunCommand(file.getPath().toString());
            }
            catch (IOException e)
            {
                jipeconsole.jipeConsole.append(e+ System.getProperty("line.separator"));
            }
        }

    }
    protected void RunCompiler(String compileFile)
    {
        errorModel.removeAllElements();
        if(props.JAVAOPTIONSTRING.trim().length()>=1)compileFile=props.JAVAOPTIONSTRING+" " + compileFile;
        if(props.OUTPUTDIR.trim().length()>=1)compileFile="-d "+props.OUTPUTDIR+" " +compileFile;
        if(props.CLASSPATH.trim().length()>=1)compileFile="-classpath "+props.CLASSPATH+" " +compileFile;
        else compileFile="-classpath "+activeChild.file.getParent()+" "+compileFile;
        compile = new JipeCompiler(this, compileFile, props.COMPILER+ " ");
    }
    protected void CompileAll()
    {
        if (compile != null)
        {
            compile = null;
        }
        String[] files = new File(System.getProperty("user.dir")).list();
        for (int i = 1; i < files.length; i++)
        {
            if (files[i].endsWith(".java"))
            {
                try
                {
                    jipeconsole.jipeConsole.append("Compiling:" + files[i]+ System.getProperty("line.separator"));
                    RunCompiler(files[i]);
                }
                catch (Exception err)
                {
                }
            }
            break;
        }
    }

    public void OpenClassBrowser(){
        ClassBrowser classBrowser=new ClassBrowser(this);
        classBrowser.init();
        JFrame f = new JFrame("Class Browser");
        f.getContentPane().add(classBrowser);
        classBrowser.setFrame(f);
        f.setSize(new Dimension(700, 450));
        f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        f.setIconImage(JipeIcon());
        f.setVisible(true);
    }

    public void DecompileClass(){
        addChild(this, "Java", null);
        JipeDecompiler decompiler=new JipeDecompiler(this, activeChild.textarea);
    }
    void OpenJavaDoc()
    {
        String separator = System.getProperty("file.separator");
        try
        {
            Process ps = Runtime.getRuntime().exec(props.BROWSER + " " +props.JAVADOCS);
        }
        catch (Exception err)
        {
            jipeconsole.jipeConsole.append("Error could not open browser " + err + System.getProperty("line.separator"));
        }
    }

    void CloseAll()
    {
        int count;
        if(helpConsole!=null){
            helpConsole.close();
            helpConsole=null;
        }
        while ((count = children.size()) > 0)
        {

            Editor child = (Editor)children.elementAt(0);
            if (child != null)
                child.close();
            if (count == children.size())
                break;
        }
    }
    void CloseProject(){
        project.CloseProject();
    }
    public static void main(String[] args)
    {
        Jipe window = new Jipe();
        System.out.println("Java version:"+System.getProperty("java.version"));
        System.out.println("OS Name:"+System.getProperty("os.name"));
        System.out.println("OS version:"+System.getProperty("os.version"));
        System.out.println("OS arch:"+System.getProperty("os.arch"));
        if (args.length > 0)
        {
            File file = new File(args[0]);
            if (file.getName().endsWith(".java") || file.getName().endsWith(
                        ".html") || file.getName().endsWith("htm"))
                window.loadChild(file.getName(), file);
            if (file.getName().endsWith(".prj"))
                window.project.OpenNewProject(file);
        }
    }
}

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