Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
JSiteMap - Java Site Map Generator - JSiteMapApplet.java

JSiteMapApplet.java

Caricato da: Teutoburgo
Scarica il programma completo

  1. /*
  2.     JSiteMap 0.9.3 - A Java Site Map Generator
  3.     Copyright (C) 2003 Pierre Blanc
  4.     Pierre Blanc: blanc_teutoburgo@yahoo.it
  5.     http://www.site-map.tk
  6.     http://it.geocities.com/teutoburgo
  7.  
  8.     This program is free software; you can redistribute it and/or modify
  9.     it under the terms of the GNU General Public License as published by
  10.     the Free Software Foundation; either version 2 of the License, or
  11.     (at your option) any later version.
  12.  
  13.     This program is distributed in the hope that it will be useful,
  14.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.     GNU General Public License for more details.
  17.  
  18.     You should have received a copy of the GNU General Public License
  19.     along with this program; if not, write to the Free Software
  20.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  21.     or go to      http://www.gnu.org/copyleft/gpl.html
  22. */
  23.  
  24. package tk.teutoburgo.jsitemap;
  25.  
  26. import java.io.*;
  27. import java.awt.*;
  28. import java.awt.event.*;
  29. import java.applet.*;
  30. import java.util.*;
  31.  
  32. /**
  33.  * <p>Title: Java Site Map Generator</p>
  34.  * <p>Description: </p>
  35.  * <p>Copyright: Copyright (c) 2003</p>
  36.  * <p>Company: www.site-map.tk</p>
  37.  * @author Pierre Blanc
  38.  * @version 0.9.3
  39.  */
  40.  
  41. public class JSiteMapApplet extends Applet {
  42.         Vector options = new Vector();
  43.         public static final String BOOLEAN="boolean", NUMBER="number",
  44.                 STRING="string";
  45.         Parser parser = null;
  46.     ScriptGenerator sg=new ScriptGenerator();
  47.     private String startTag="<A name=sitemap>", hrefTag="",
  48.         hrefEndTag="</A>", startListTag="<UL>", endListTag="</UL>",
  49.         listItemTag="<LI>", endListItemTag="</LI>",
  50.         htmlCode="", endURLTag="",
  51.         STOPTag="", memory="", SHOW="Show license";
  52.     boolean isStandalone = false, showLicense=true, addOptions=true;
  53.     int rows=9, cols=60;
  54.     BorderLayout borderLayout1 = new BorderLayout();
  55.     Panel centerPanel = new Panel();
  56.     TextArea textArea1 = new TextArea("",rows,cols,
  57.         TextArea.SCROLLBARS_VERTICAL_ONLY);
  58.     TextArea textArea2 = new TextArea("",rows,cols);
  59.     Panel panelEast = new Panel();
  60.     Button buttonGenerate = new Button();
  61.     Button buttonClear = new Button();
  62.     Button buttonLicense = new Button();
  63.         Button buttonConfig = new Button();
  64.     Button buttonHTML = new Button();
  65.         Panel panelInfo = new Panel();
  66.     Panel panelStatus = new Panel();
  67.     GridLayout gridLayout1 = new GridLayout();
  68.     Panel panelNorth = new Panel();
  69.     Label label1 = new Label();
  70.     Label label2 = new Label();
  71.     Label labelGenerate = new Label();
  72.     Label labelAuthor = new Label();
  73.     Label labelTitle = new Label();
  74.     GridLayout gridLayout2 = new GridLayout();
  75.         Checkbox cbOptions=new Checkbox("Add user options");
  76.         PopUp window;
  77.         Util util=new Util();
  78.     //Get a parameter value
  79.     public String getParameter(String key, String def) {
  80.         return isStandalone ? System.getProperty(key, def) :
  81.             (getParameter(key) != null ? getParameter(key) : def);
  82.     }
  83.  
  84.     //Construct the applet
  85.     public JSiteMapApplet() {
  86.     }
  87.     //Initialize the applet
  88.     public void init() {
  89.         try {
  90.             if(!isStandalone){
  91.                 addOptions=false;
  92.                 startTag=getParameter("startTag");
  93.                 hrefTag=getParameter("hrefTag");
  94.                 hrefEndTag=getParameter("hrefEndTag");
  95.                 startListTag=getParameter("startListTag");
  96.                 endListTag=getParameter("endListTag");
  97.                 listItemTag=getParameter("listItemTag");
  98.                 endListItemTag=getParameter("endListItemTag");
  99.                 endURLTag=getParameter("endURLTag");
  100.                 STOPTag=getParameter("STOPTag");
  101.                 htmlCode=getParameter("htmlCode");
  102.             }else{
  103.                 Properties p=new Properties();
  104.                 FileInputStream fis=new FileInputStream(
  105.                     "./config/JSiteMap.cfg");
  106.                 p.load(fis);
  107.                 startTag=p.getProperty("startTag");
  108.                 hrefTag=p.getProperty("hrefTag");
  109.                 hrefEndTag=p.getProperty("hrefEndTag");
  110.                 startListTag=p.getProperty("startListTag");
  111.                 endListTag=p.getProperty("endListTag");
  112.                 listItemTag=p.getProperty("listItemTag");
  113.                 endListItemTag=p.getProperty("endListItemTag");
  114.                 endURLTag=p.getProperty("endURLTag");
  115.                 STOPTag=p.getProperty("STOPTag");
  116.                 htmlCode=p.getProperty("htmlCode");
  117.                 String addUserOptions=p.getProperty("addUserOptions");
  118.                 if(addUserOptions.equals("false"))
  119.                         addOptions=false;
  120.                 options=util.readOptions("./config/menuOptions.cfg");
  121.                 window=new PopUp(options);
  122.             }
  123.             jbInit();
  124.             // System.out.println("tag="+hrefTag);
  125.             parser = new Parser(startTag, hrefTag, hrefEndTag,
  126.                                 startListTag, endListTag, listItemTag,
  127.                                 endListItemTag, endURLTag, STOPTag);
  128.         }
  129.         catch(Exception e) {
  130.             e.printStackTrace();
  131.         }
  132.     }
  133.  
  134.  
  135.         //Component initialization
  136.     private void jbInit() throws Exception {
  137.         this.setLayout(borderLayout1);
  138.         /*    textArea1.setColumns(50);
  139.               textArea1.setRows(7);
  140.               textArea2.setColumns(50);
  141.               textArea2.setRows(7);*/
  142.         textArea1.setText(htmlCode);
  143.         buttonGenerate.setLabel("Dynamic");
  144.         buttonGenerate.addMouseListener(new java.awt.event.MouseAdapter() {
  145.                 public void mouseClicked(MouseEvent e) {
  146.                     buttonGenerate_mouseClicked(e);
  147.                 }
  148.             });
  149.         buttonClear.setLabel("Clear all");
  150.         buttonClear.addMouseListener(new java.awt.event.MouseAdapter() {
  151.                 public void mouseClicked(MouseEvent e) {
  152.                     buttonClear_mouseClicked(e);
  153.                 }
  154.             });
  155.         buttonLicense.setLabel(SHOW);
  156.         buttonLicense.addMouseListener(new java.awt.event.MouseAdapter() {
  157.                 public void mouseClicked(MouseEvent e) {
  158.                     buttonLicense_mouseClicked(e);
  159.                 }
  160.             });
  161.         buttonHTML.setLabel("Static");
  162.         buttonHTML.addMouseListener(new java.awt.event.MouseAdapter() {
  163.                 public void mouseClicked(MouseEvent e) {
  164.                     buttonHTML_mouseClicked(e);
  165.                 }
  166.             });
  167.         buttonConfig.setLabel("Configure");
  168.         buttonConfig.addMouseListener(new java.awt.event.MouseAdapter() {
  169.                 public void mouseClicked(MouseEvent e) {
  170.                     buttonConfig_mouseClicked(e);
  171.                 }
  172.             });
  173.         panelEast.setLayout(gridLayout1);
  174.         gridLayout1.setColumns(1);
  175.         gridLayout1.setRows(6);
  176.         label1.setText("Insert HTML report code and press \'Dynamic\' or \'Static\'");
  177.         label2.setText("Copy generated javascript code into .js file");
  178.         labelGenerate.setText("Generate map:");
  179.         labelAuthor.setText("Copyright (C) P.Blanc 2003 - blanc_teutoburgo"+
  180.             "@yahoo.it - http://www.site-map.tk");
  181.         labelTitle.setText("JSiteMap 0.9.3 - Java Site Map Generator");
  182.         panelNorth.setLayout(gridLayout2);
  183.         gridLayout2.setColumns(1);
  184.         gridLayout2.setRows(2);
  185.         centerPanel.add(label1, null);
  186.         this.add(centerPanel, BorderLayout.CENTER);
  187.         centerPanel.add(textArea1, null);
  188.         this.add(panelEast,  BorderLayout.EAST);
  189.         panelEast.add(labelGenerate, null);
  190.         panelEast.add(buttonGenerate, null);
  191.         panelEast.add(buttonHTML, null);
  192.         if(isStandalone)
  193.                 panelEast.add(buttonConfig, null);
  194.         panelEast.add(buttonClear, null);
  195.         panelStatus.setBackground(Color.lightGray);
  196.         panelEast.add(panelStatus, null);
  197.         this.add(panelNorth, BorderLayout.NORTH);
  198.         panelInfo.add(labelTitle, null);
  199.         panelInfo.add(buttonLicense, null);
  200.         panelNorth.add(panelInfo, null);
  201.         panelNorth.add(labelAuthor, null);
  202.         centerPanel.add(label2, null);
  203.         centerPanel.add(textArea2, null);
  204.         if(isStandalone){
  205.                 Panel panelSouth=new Panel();
  206.                 if(addOptions)
  207.                         cbOptions.setState(true);
  208.                 cbOptions.addMouseListener(new java.awt.event.MouseAdapter() {
  209.                         public void mouseClicked(MouseEvent e) {
  210.                                 cbOptions_mouseClicked(e);
  211.                         }
  212.                         });
  213.                 panelSouth.add(cbOptions);
  214.                 this.add(panelSouth,BorderLayout.SOUTH);
  215.         }
  216.     }
  217.     //Start the applet
  218.     public void start() {
  219.     }
  220.     //Stop the applet
  221.     public void stop() {
  222.     }
  223.     //Destroy the applet
  224.     public void destroy() {
  225.     }
  226.     //Get Applet information
  227.     public String getAppletInfo() {
  228.         return "Applet Information";
  229.     }
  230.     //Get parameter info
  231.     public String[][] getParameterInfo() {
  232.         return null;
  233.     }
  234.     //Main method
  235.     public static void main(String[] args) {
  236.         JSiteMapApplet applet = new JSiteMapApplet();
  237.         applet.isStandalone = true;
  238.         Frame frame;
  239.         frame = new Frame() {
  240.                 protected void processWindowEvent(WindowEvent e) {
  241.                     super.processWindowEvent(e);
  242.                     if (e.getID() == WindowEvent.WINDOW_CLOSING) {
  243.                         System.exit(0);
  244.                     }
  245.                 }
  246.                 public synchronized void setTitle(String title) {
  247.                     super.setTitle(title);
  248.                     enableEvents(AWTEvent.WINDOW_EVENT_MASK);
  249.                 }
  250.             };
  251.         frame.setTitle("JSiteMap");
  252.         frame.add(applet, BorderLayout.CENTER);
  253.         applet.init();
  254.         applet.start();
  255.         frame.setSize(580,500);
  256.         Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
  257.         frame.setLocation((d.width - frame.getSize().width) / 2,
  258.             (d.height - frame.getSize().height) / 2);
  259.         frame.setVisible(true);
  260.     }
  261.  
  262.     void buttonGenerate_mouseClicked(MouseEvent e) {
  263.         panelStatus.setBackground(Color.yellow);
  264.         textArea2.setText("Working..");
  265.         String htmlCode=textArea1.getText();
  266.         //    System.out.println("-------text: "+htmlCode);
  267.         TeutoTreeNode map=parser.parse(htmlCode);
  268.         if(map!=null){
  269.             String scriptCode="";
  270.                 if(addOptions){
  271.                         int n=options.size();
  272.                         for(int i=0; i<n; i++){
  273.                                 String[] option=(String[])options.elementAt(i);
  274.                                 if(option[2].equals(STRING)){
  275.                                         if(!option[1].equals(""))
  276.                                                 scriptCode+=option[0]+"=\""+option[1]+"\";\n";
  277.                                 }else
  278.                                         scriptCode+=option[0]+"="+option[1]+";\n";
  279.                         }
  280.                         scriptCode+="\n";
  281.                 }
  282.                 scriptCode+=sg.generate(map);
  283.             sg.resetNodeNumber();
  284.             textArea2.setText(scriptCode);
  285.             panelStatus.setBackground(Color.green);
  286.                 label2.setText("Copy generated javascript code into .js file");
  287.         } else{
  288.             textArea2.setText("ERROR! Invalid input code.");
  289.             panelStatus.setBackground(Color.red);
  290.         }
  291.     }
  292.  
  293.     void buttonHTML_mouseClicked(MouseEvent e) {
  294.         panelStatus.setBackground(Color.yellow);
  295.         textArea2.setText("Working..");
  296.         String htmlCode=textArea1.getText();
  297.         String htmlMap=parser.getHTMLMap(htmlCode);
  298.         if(htmlMap!=null){
  299.                 textArea2.setText(htmlMap);
  300.             panelStatus.setBackground(Color.green);
  301.                 label2.setText("Copy generated HTML code into .html file");
  302.         } else{
  303.             textArea2.setText("ERROR! Invalid input code.");
  304.             panelStatus.setBackground(Color.red);
  305.         }
  306.         }
  307.  
  308.     void buttonClear_mouseClicked(MouseEvent e) {
  309.         textArea1.setText("");
  310.         textArea2.setText("");
  311.         panelStatus.setBackground(Color.lightGray);
  312.     }
  313.  
  314.     void buttonConfig_mouseClicked(MouseEvent e) {
  315.         window.setSize(600,400);
  316.         window.show();
  317.  
  318.         }
  319.  
  320.     void buttonLicense_mouseClicked(MouseEvent e) {
  321.         if(showLicense){
  322.             memory=textArea1.getText();
  323.             textArea1.setText("This software is under the GNU GPL license v.2. This"+
  324.                               " product includes software developed by the Apache Software"+
  325.                               " Foundation (http://www.apache.org/). The Javascript Tree Menu is"+
  326.                               " copyright of Morten Wang and comes with the BSD license.");
  327.             buttonLicense.setLabel("Back");
  328.         } else {
  329.             textArea1.setText(memory);
  330.             buttonLicense.setLabel(SHOW);
  331.         }
  332.         showLicense=!showLicense;
  333.     }
  334.  
  335.         void cbOptions_mouseClicked(MouseEvent e){
  336.                 addOptions=!addOptions;
  337.         }
  338. }