Package net.fp.rp.search.ui.command

Source Code of net.fp.rp.search.ui.command.RpGui

/*
* Copyright (C) 2004 Paul Browne, http://www.firstpartners.net,
* built with the help of Fast-Soft (fastsoftdev@yahoo.com)
*
* released under terms of the GPL license
* http://www.opensource.org/licenses/gpl-license.php
*
* This product includes software developed by the
* Apache Software Foundation (http://www.apache.org)."
*
* This product includes software developed by the
* Spring Framework Project (http://www.springframework.org)."
*
*/
package net.fp.rp.search.ui.command;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileNotFoundException;
import java.util.List;
import java.util.Map;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JEditorPane;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JTextField;

import net.fp.rp.search.back.struct.DocumStruct;
import net.fp.rp.search.mid.global.Config;
import net.fp.rp.search.mid.global.KnowledgeSphereManager;
import net.fp.rp.search.mid.global.ModelView;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.util.Log4jConfigurer;


/**
* Gui interface for the application
*
* @author Firstpartners.net
* @version 1.
* Copyright @link www.firstpartners.net/red
*/
public class RpGui extends javax.swing.JDialog {
    /** Knowledge manager responsable for handling the requests */
    private final KnowledgeSphereManager m_manager;

    /** Gui components */
    private JMenuItem helpMenuItem;
    private JMenu jMenu5;
    private JMenuItem deleteMenuItem;
    private JSeparator jSeparator1;
    private JMenuItem pasteMenuItem;
    private JPanel jPanel4;
    private JPanel jPanel2;
    private JButton Add;
    private JButton Search;
    private JTextField Query;
    private JLabel SearchLabel;
    private JPanel jPanel1;
    private JMenuItem copyMenuItem;
    private JMenuItem cutMenuItem;
    private JMenu jMenu4;
    private JMenuItem exitMenuItem;
    private JSeparator jSeparator2;
    private JEditorPane statusMessage;
    private JEditorPane resultDocuments;
    private JScrollPane jScrollPane2;
    private JScrollPane jScrollPane1;
    private JPanel jPanel7;
    private JPanel jPanel6;
    private JLabel statusResult;
    private JPanel jPanel3;
    private JPanel jPanel5;
    private JMenuItem closeFileMenuItem;
    private JMenuItem saveAsMenuItem;
    private JMenuItem saveMenuItem;
    private JMenuItem openFileMenuItem;
    private JMenuItem newFileMenuItem;
    private JMenu jMenu3;
    private JMenuBar jMenuBar1;

    /**
     * Creates a new AppDialog object.
     *
     * @param manager KnowledgeManager responsable for add/search operations
     */
    public RpGui(KnowledgeSphereManager manager) {
        super();
        initGUI();
        m_manager = manager;
    }

    /**
     * Initialization of the gui
     */
    private void initGUI() {
        try {
            this.setSize(752, 477);

            {
                jPanel2 = new JPanel();

                BoxLayout jPanel2Layout = new BoxLayout(jPanel2,
                        javax.swing.BoxLayout.Y_AXIS);
                jPanel2.setLayout(jPanel2Layout);
                this.getContentPane().add(jPanel2, BorderLayout.CENTER);
            }

            {
                jPanel4 = new JPanel();
                this.getContentPane().add(jPanel4, BorderLayout.CENTER);

                FlowLayout jPanel4Layout = new FlowLayout();
                jPanel4.setLayout(jPanel4Layout);

                {
                    jPanel5 = new JPanel();
                    jPanel4.add(jPanel5);

                    BoxLayout jPanel5Layout = new BoxLayout(jPanel5,
                            javax.swing.BoxLayout.X_AXIS);
                    jPanel5.setLayout(jPanel5Layout);

                    {
                        jPanel1 = new JPanel();

                        FlowLayout jPanel1Layout = new FlowLayout();
                        jPanel1.setLayout(jPanel1Layout);
                        jPanel5.add(jPanel1);
                        jPanel1.setPreferredSize(new java.awt.Dimension(744, 36));
                        SearchLabel = new JLabel();
                        jPanel1.add(SearchLabel);
                        SearchLabel.setText("Search");
                        Query = new JTextField();
                        jPanel1.add(Query);
                        Query.setPreferredSize(new java.awt.Dimension(433, 21));
                        Search = new JButton();
                        jPanel1.add(Search);
                        Search.setText("Search");
                        Search.addActionListener(new ActionListener() {
                                public void actionPerformed(ActionEvent evt) {
                                    String query = Query.getText();

                                    if (query.trim().length() != 0) {
                                        Map model = m_manager.search(query,+1);
                                        String modelError = (String) model.get(ModelView.ERROR);

                                        if ("true".equals(modelError)) {
                                            String modelStatus = (String) model.get(ModelView.STATUS);
                                            statusMessage.setText(modelStatus);
                                            clearResult();
                                        } else {
                                            try {
                                                StringBuffer text = new StringBuffer();

                                                text.append(Config.NEW_LINE);
                                                text.append(
                                                    "            Results for Search " +
                                                    query + " ");
                                                text.append(Config.NEW_LINE);
                                                text.append(Config.NEW_LINE);

                                                int nodocums = Integer.valueOf((String) model.get(
                                                        ModelView.DOCUMENTSNO)).intValue();
                                                List list = (List) model.get(ModelView.DOCUMENTS);

                                                for (int i = 0; i < nodocums;
                                                        i++) {
                                                    DocumStruct docum = (DocumStruct) list.get(i);

                                                    text.append(Config.NEW_LINE);
                                                    text.append("Pos. " + i +
                                                        " " + docum.getTitle() +
                                                        " " + docum.getTitle());
                                                    text.append(Config.NEW_LINE);
                                                    text.append(docum.getPath() +
                                                        " " +
                                                        docum.getLastUpdate());
                                                    text.append(Config.NEW_LINE);
                                                }

                                                resultDocuments.setText(text.toString());
                                                statusMessage.setText(
                                                    "Search complete." +
                                                    nodocums +
                                                    " documents found it ");
                                            } catch (NumberFormatException e) {
                                                statusMessage.setText(
                                                    "Error in retrieving the documents ");
                                                clearResult();
                                            }
                                        }
                                    } else {
                                        statusMessage.setText(statusMessage.getText() +
                                            " \n" +
                                            "Please specify something in order to seach!!");
                                        clearResult();
                                    }
                                }
                            });
                        Add = new JButton();
                        jPanel1.add(Add);
                        Add.setText("Add Information");
                        Add.addActionListener(new ActionListener() {
                                public void actionPerformed(ActionEvent evt) {
                                    String location = Query.getText();

                                    if (location.trim().length() != 0) {
                                        String responseAddOperation = m_manager.add(location);
                                        statusMessage.setText(responseAddOperation);
                                        clearResult();
                                    } else {
                                        statusMessage.setText(
                                            "Please specify something in order to add!!");
                                        clearResult();
                                    }
                                }
                            });
                    }
                }

                jPanel3 = new JPanel();
                jPanel4.add(jPanel3);
                jPanel3.setPreferredSize(new java.awt.Dimension(724, 84));
                statusResult = new JLabel();
                jPanel3.add(statusResult);
                statusResult.setText("Result status");
                jScrollPane1 = new JScrollPane();
                jPanel3.add(jScrollPane1);
                jScrollPane1.setPreferredSize(new java.awt.Dimension(616, 75));
                statusMessage = new JEditorPane();
                jScrollPane1.setViewportView(statusMessage);
                statusMessage.setPreferredSize(new java.awt.Dimension(581, 54));
                statusMessage.setEditable(false);
                jPanel6 = new JPanel();
                jPanel4.add(jPanel6);
                jPanel7 = new JPanel();
                jPanel4.add(jPanel7);
                jPanel7.setPreferredSize(new java.awt.Dimension(682, 280));
                jScrollPane2 = new JScrollPane();
                jPanel7.add(jScrollPane2);
                jScrollPane2.setPreferredSize(new java.awt.Dimension(644, 278));
                resultDocuments = new JEditorPane();
                jScrollPane2.setViewportView(resultDocuments);
                resultDocuments.setEditable(false);
            }

            jMenuBar1 = new JMenuBar();
            setJMenuBar(jMenuBar1);
            jMenu3 = new JMenu();
            jMenuBar1.add(jMenu3);
            jMenu3.setText("File");
            newFileMenuItem = new JMenuItem();
            jMenu3.add(newFileMenuItem);
            newFileMenuItem.setText("New");
            openFileMenuItem = new JMenuItem();
            jMenu3.add(openFileMenuItem);
            openFileMenuItem.setText("Open");
            saveMenuItem = new JMenuItem();
            jMenu3.add(saveMenuItem);
            saveMenuItem.setText("Save");
            saveAsMenuItem = new JMenuItem();
            jMenu3.add(saveAsMenuItem);
            saveAsMenuItem.setText("Save As ...");
            closeFileMenuItem = new JMenuItem();
            jMenu3.add(closeFileMenuItem);
            closeFileMenuItem.setText("Close");
            jSeparator2 = new JSeparator();
            jMenu3.add(jSeparator2);
            exitMenuItem = new JMenuItem();
            jMenu3.add(exitMenuItem);
            exitMenuItem.setText("Exit");
            jMenu4 = new JMenu();
            jMenuBar1.add(jMenu4);
            jMenu4.setText("Edit");
            cutMenuItem = new JMenuItem();
            jMenu4.add(cutMenuItem);
            cutMenuItem.setText("Cut");
            copyMenuItem = new JMenuItem();
            jMenu4.add(copyMenuItem);
            copyMenuItem.setText("Copy");
            pasteMenuItem = new JMenuItem();
            jMenu4.add(pasteMenuItem);
            pasteMenuItem.setText("Paste");
            jSeparator1 = new JSeparator();
            jMenu4.add(jSeparator1);
            deleteMenuItem = new JMenuItem();
            jMenu4.add(deleteMenuItem);
            deleteMenuItem.setText("Delete");
            jMenu5 = new JMenu();
            jMenuBar1.add(jMenu5);
            jMenu5.setText("Help");
            helpMenuItem = new JMenuItem();
            jMenu5.add(helpMenuItem);
            helpMenuItem.setText("Help");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * Clear the result text component
     */
    public void clearResult() {
        resultDocuments.setText("");
    }

    /**
     * Use the application in the standalone mode to add/search information
     *
     * @param args
     */
    public static void main(String[] args) {
        String contextDir = "";

        if ((args.length > 0) && !"".equals(args[0])) {
            contextDir = args[0];
        }

        System.out.println("Execution context is : " + contextDir);

        //set the application context root the current directory
        //in case of web application this is already set in the web.xml (as webaprootkey)
        System.setProperty( Config.RP_ROOT, contextDir);

        //set-up the log4j xml configuration
        try {
            Log4jConfigurer.initLogging( Config.WEBINF + "/" +
                    Config.LOG4J_XML);
        }
        catch (FileNotFoundException e ){
            e.printStackTrace(System.out);
        }
       
        ApplicationContext context = new FileSystemXmlApplicationContext(Config.WEBINF +
                "/" + Config.APPCONTEXT);

        //call the dialog
        RpGui dialog = new RpGui((KnowledgeSphereManager) context.getBean(
                    Config.KNOWLEDGEMANAGER_PLUGINNAME));
        dialog.setModal(true);
        dialog.setVisible(true);
    }
}
TOP

Related Classes of net.fp.rp.search.ui.command.RpGui

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.