Example usage for javax.swing.tree DefaultTreeModel DefaultTreeModel

List of usage examples for javax.swing.tree DefaultTreeModel DefaultTreeModel

Introduction

In this page you can find the example usage for javax.swing.tree DefaultTreeModel DefaultTreeModel.

Prototype

@ConstructorProperties({ "root" })
public DefaultTreeModel(TreeNode root) 

Source Link

Document

Creates a tree in which any node can have children.

Usage

From source file:pa_SymposiumPlanner.RuleML2010ProgramChair.java

public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html; charset=UTF-8");
    PrintWriter out = response.getWriter();
    try {//from w  w  w  .j av  a  2 s.  com
        address = PAConfiguration.getAddress();
        port = PAConfiguration.getPort(instantiation);
        poslAddress = PAConfiguration.getPOSL(instantiation, topic);
        rdfAddress = PAConfiguration.getRDFTaxonomy(instantiation);
        messageEndpoint = PAConfiguration.getEndpointName(instantiation, topic);
    } catch (BadConfigurationException e) {
        System.out.println(e.getMessage());
        e.printStackTrace();
        System.exit(0);
    }
    try {
        System.out.println("Panel Chair Servlet");
        System.out.println(response.toString());

        BufferedReader brd = request.getReader();

        String input = "";
        String message = "";

        while (!input.equals("</RuleML>")) {

            input = brd.readLine();

            message = message + input;
        }
        String[] varOrder = getVariableOrder(message);
        System.out.println("Received Message: " + message);

        //   BackwardReasoner br = new BackwardReasoner();
        //   Iterator solit =null;
        //   DefiniteClause dc = null;
        //   SymbolTable.reset();

        POSLParser pp = new POSLParser();
        // String contents = "c(a).\nc(b).\nc(c).";

        Date t1 = new GregorianCalendar().getTime();
        //System.out.println(t1.getHours() + ":" + t1.getMinutes());
        //append time to contents

        //System.out.println("day: " + t1.getDay());
        //System.out.println("day: " + t1.getYear());
        //System.out.println("day: " + t1.getMonth());

        //time
        String time = "time(" + t1.getHours() + ":integer).";
        System.out.println(time);

        String url = poslAddress;

        //String url = "http://www.jdrew.org/oojdrew/test.posl";
        String contents = "";

        //day of the week
        int day = t1.getDay();
        boolean weekday = true;

        if (day == 0 || day == 6) {
            weekday = false;
        }

        String dayOfWeek;

        if (weekday) {
            dayOfWeek = "day(weekday).";
        } else {
            dayOfWeek = "day(weekend).";
        }
        //full date
        Calendar cal = new GregorianCalendar();

        int year = cal.get(Calendar.YEAR);
        int month = cal.get(Calendar.MONTH) + 1;
        int day2 = cal.get(Calendar.DAY_OF_MONTH);

        String date;

        String day3 = "" + day2;

        if (day2 == 1 || day2 == 2 || day2 == 3 || day2 == 4 || day2 == 5 || day2 == 6 || day2 == 7 || day2 == 8
                || day2 == 9) {

            day3 = "0" + day2;
        }

        if (month == 10 || month == 11 || month == 12) {
            date = "" + year + month + day3;
        } else {
            date = "" + year + "0" + month + day3;
        }

        date = "date(" + date + ":integer).";

        System.out.println(date);

        String url2 = rdfAddress;
        HttpClient client2 = new HttpClient();
        GetMethod method2 = new GetMethod(url2);
        method2.setFollowRedirects(true);
        String typestr = "";
        // Execute the GET method
        int statusCode2 = client2.executeMethod(method2);
        if (statusCode2 != -1) {
            typestr = method2.getResponseBodyAsString();
        }
        System.out.println("Types: " + typestr);
        Types.reset();
        RDFSParser.parseRDFSString(typestr);

        try {
            HttpClient client = new HttpClient();
            GetMethod method = new GetMethod(url);
            method.setFollowRedirects(true);

            // Execute the GET method
            int statusCode = client.executeMethod(method);
            if (statusCode != -1) {
                contents = method.getResponseBodyAsString();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        contents = contents + "\n" + time;
        contents = contents + "\n" + dayOfWeek;
        contents = contents + "\n" + date;

        BackwardReasoner br = new BackwardReasoner();
        Iterator solit = null;
        DefiniteClause dc = null;
        SymbolTable.reset();

        pp.parseDefiniteClauses(contents);

        br.loadClauses(pp.iterator());

        Iterator it = pp.iterator();
        while (it.hasNext()) {
            DefiniteClause d = (DefiniteClause) it.next();
            System.out.println("Loaded clause: " + d.toPOSLString());
        }

        br = new BackwardReasoner(br.clauses, br.oids);

        MessageParser m = new MessageParser(message);
        Element atom = null;

        try {

            atom = m.parseForContent();

        } catch (Exception e) {

            System.out.println("Invalid Message");
            //out.flush();

        }

        QueryBuilder q = new QueryBuilder(atom);
        String query = q.generateDoc();
        System.out.println("ABOUT TO INPUT THIS QUERY:" + query);
        RuleMLParser qp = new RuleMLParser();

        try {

            dc = qp.parseRuleMLQuery(query);

        } catch (Exception e) {
            System.out.println("Invalid Query");
            //out.flush();
        }

        //solit = br.iterativeDepthFirstSolutionIterator(dc);

        solit = br.iterativeDepthFirstSolutionIterator(dc);

        int varSize = 0;

        while (solit.hasNext()) {

            Vector data = new Vector();

            BackwardReasoner.GoalList gl = (BackwardReasoner.GoalList) solit.next();

            Hashtable varbind = gl.varBindings;
            javax.swing.tree.DefaultMutableTreeNode root = br.toTree();
            root.setAllowsChildren(true);

            javax.swing.tree.DefaultTreeModel dtm = new DefaultTreeModel(root);

            int i = 0;
            Object[][] rowdata = new Object[varbind.size()][2];
            varSize = varbind.size();

            Enumeration e = varbind.keys();
            while (e.hasMoreElements()) {
                Object k = e.nextElement();
                Object val = varbind.get(k);
                String ks = (String) k;
                rowdata[i][0] = ks;
                rowdata[i][1] = val;

                i++;
            }

            data.addElement(rowdata);
            String[] messages = new String[data.size()];
            MessageGenerator g = new MessageGenerator(data, varSize, messageEndpoint, m.getId(),
                    m.getProtocol(), m.getRel(), varOrder);
            messages = g.Messages2();

            String appender = "";

            URL sender = new URL(address + ":" + port);
            HttpMessage msg = new HttpMessage(sender);
            Properties props = new Properties();

            for (int i1 = 0; i1 < data.size(); i1++) {
                System.out.println(i1 + ")" + messages[i1].toString());
                props.put("text", messages[i1].toString());
                InputStream in = msg.sendGetMessage(props);
            }
            System.out.println("NEXT MESSAGE");
        }

        MessageGenerator g = new MessageGenerator(null, varSize, messageEndpoint, m.getId(), m.getProtocol(),
                m.getRel());

        URL sender = new URL(address + ":" + port);
        HttpMessage msg = new HttpMessage(sender);
        Properties props = new Properties();

        String finalMessage = g.finalMessage(query);

        System.out.println(finalMessage);

        props.put("text", finalMessage);
        InputStream in = msg.sendGetMessage(props);

        System.out.println("Stop_Communication");

    } catch (Exception e) {
        System.out.println("ERROR has occured : " + e.toString());

    }
    out.close();
}

From source file:pa_SymposiumPlanner.RuleML2010PublicityChair.java

public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html; charset=UTF-8");
    PrintWriter out = response.getWriter();
    try {//w ww  .ja v  a 2s . c  om
        address = PAConfiguration.getAddress();
        port = PAConfiguration.getPort(instantiation);
        poslAddress = PAConfiguration.getPOSL(instantiation, topic);
        rdfAddress = PAConfiguration.getRDFTaxonomy(instantiation);
        messageEndpoint = PAConfiguration.getEndpointName(instantiation, topic);
    } catch (BadConfigurationException e) {
        System.out.println(e.getMessage());
        e.printStackTrace();
        System.exit(0);
    }
    try {
        System.out.println("Publicty Chair Servlet");
        System.out.println(response.toString());

        BufferedReader brd = request.getReader();

        String input = "";
        String message = "";

        while (!input.equals("</RuleML>")) {

            input = brd.readLine();

            message = message + input;
        }
        String[] varOrder = getVariableOrder(message);
        System.out.println("Received Message: " + message);

        POSLParser pp = new POSLParser();
        // String contents = "c(a).\nc(b).\nc(c).";

        Date t1 = new GregorianCalendar().getTime();
        System.out.println(t1.getHours() + ":" + t1.getMinutes());
        //append time to contents

        System.out.println("day: " + t1.getDay());
        System.out.println("day: " + t1.getYear());
        System.out.println("day: " + t1.getMonth());

        //time
        String time = "time(" + t1.getHours() + ":integer).";
        System.out.println(time);

        String url = poslAddress;

        //String url = "http://www.jdrew.org/oojdrew/test.posl";
        String contents = "";

        //day of the week
        int day = t1.getDay();
        boolean weekday = true;

        if (day == 0 || day == 6) {
            weekday = false;
        }

        String dayOfWeek;

        if (weekday) {
            dayOfWeek = "day(weekday).";
        } else {
            dayOfWeek = "day(weekend).";
        }
        //full date
        Calendar cal = new GregorianCalendar();

        int year = cal.get(Calendar.YEAR);
        int month = cal.get(Calendar.MONTH) + 1;
        int day2 = cal.get(Calendar.DAY_OF_MONTH);

        String date;

        String day3 = "" + day2;

        if (day2 == 1 || day2 == 2 || day2 == 3 || day2 == 4 || day2 == 5 || day2 == 6 || day2 == 7 || day2 == 8
                || day2 == 9) {

            day3 = "0" + day2;
        }

        if (month == 10 || month == 11 || month == 12) {
            date = "" + year + month + day3;
        } else {
            date = "" + year + "0" + month + day3;
        }

        date = "date(" + date + ":integer).";

        System.out.println(date);

        String url2 = rdfAddress;
        HttpClient client2 = new HttpClient();
        GetMethod method2 = new GetMethod(url2);
        method2.setFollowRedirects(true);
        String typestr = "";
        // Execute the GET method
        int statusCode2 = client2.executeMethod(method2);
        if (statusCode2 != -1) {
            typestr = method2.getResponseBodyAsString();
        }
        System.out.println("Types: " + typestr);
        Types.reset();
        RDFSParser.parseRDFSString(typestr);
        System.out.println("11111111111111111111111111111");

        try {
            HttpClient client = new HttpClient();
            GetMethod method = new GetMethod(url);
            method.setFollowRedirects(true);

            //Execute the GET method
            int statusCode = client.executeMethod(method);
            if (statusCode != -1) {
                contents = method.getResponseBodyAsString();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        contents = contents + "\n" + time;
        contents = contents + "\n" + dayOfWeek;
        contents = contents + "\n" + date;

        BackwardReasoner br = new BackwardReasoner();
        Iterator solit = null;
        DefiniteClause dc = null;
        SymbolTable.reset();

        pp.parseDefiniteClauses(contents);
        System.out.println("33333333333333333333333");
        br.loadClauses(pp.iterator());
        //System.out.println("TEST");
        Iterator it = pp.iterator();
        while (it.hasNext()) {
            DefiniteClause d = (DefiniteClause) it.next();
            System.out.println("Loaded clause: " + d.toPOSLString());
        }

        br = new BackwardReasoner(br.clauses, br.oids);

        MessageParser m = new MessageParser(message);
        Element atom = null;

        try {

            atom = m.parseForContent();

        } catch (Exception e) {

            System.out.println("Invalid Message");
            //out.flush();

        }
        System.out.println("222222222222222222222222222222222");
        QueryBuilder q = new QueryBuilder(atom);
        String query = q.generateDoc();
        System.out.println("ABOUT TO INPUT THIS QUERY:" + query);
        RuleMLParser qp = new RuleMLParser();

        try {

            dc = qp.parseRuleMLQuery(query);

        } catch (Exception e) {
            System.out.println("Invalid Query");
            //out.flush();
        }

        //solit = br.iterativeDepthFirstSolutionIterator(dc);

        solit = br.iterativeDepthFirstSolutionIterator(dc);
        System.out.println("444444444444444444444444444444444444");
        int varSize = 0;

        while (solit.hasNext()) {

            Vector data = new Vector();

            BackwardReasoner.GoalList gl = (BackwardReasoner.GoalList) solit.next();

            Hashtable varbind = gl.varBindings;
            javax.swing.tree.DefaultMutableTreeNode root = br.toTree();
            root.setAllowsChildren(true);

            javax.swing.tree.DefaultTreeModel dtm = new DefaultTreeModel(root);

            int i = 0;
            Object[][] rowdata = new Object[varbind.size()][2];
            varSize = varbind.size();

            Enumeration e = varbind.keys();
            while (e.hasMoreElements()) {
                Object k = e.nextElement();
                Object val = varbind.get(k);
                String ks = (String) k;
                rowdata[i][0] = ks;
                rowdata[i][1] = val;
                i++;
            }
            System.out.println("55555555555555555555555555555");
            data.addElement(rowdata);
            String[] messages = new String[data.size()];
            MessageGenerator g = new MessageGenerator(data, varSize, messageEndpoint, m.getId(),
                    m.getProtocol(), m.getRel(), varOrder);
            messages = g.Messages2();

            String appender = "";

            URL sender = new URL(address + ":" + port);
            HttpMessage msg = new HttpMessage(sender);
            Properties props = new Properties();

            for (int i1 = 0; i1 < data.size(); i1++) {
                System.out.println(i1 + ")" + messages[i1].toString());
                props.put("text", messages[i1].toString());
                InputStream in = msg.sendGetMessage(props);
            }
            System.out.println("NEXT MESSAGE");
        }
        System.out.println("6666666666666666666666666666");
        MessageGenerator g = new MessageGenerator(null, varSize, messageEndpoint, m.getId(), m.getProtocol(),
                m.getRel());

        URL sender = new URL(address + ":" + port);
        HttpMessage msg = new HttpMessage(sender);
        Properties props = new Properties();

        String finalMessage = g.finalMessage(query);

        System.out.println(finalMessage);

        props.put("text", finalMessage);
        InputStream in = msg.sendGetMessage(props);

        System.out.println("Stop_Communication");

    } catch (Exception e) {
        System.out.println("ERROR has occured : " + e.toString());

    }
    out.close();
}

From source file:pa_SymposiumPlanner.RuleML2010RRChair.java

public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html; charset=UTF-8");
    PrintWriter out = response.getWriter();
    try {/*w w  w. j  av  a 2  s .  co  m*/
        address = PAConfiguration.getAddress();
        port = PAConfiguration.getPort(instantiation);
        poslAddress = PAConfiguration.getPOSL(instantiation, topic);
        rdfAddress = PAConfiguration.getRDFTaxonomy(instantiation);
        messageEndpoint = PAConfiguration.getEndpointName(instantiation, topic);
    } catch (BadConfigurationException e) {
        System.out.println(e.getMessage());
        e.printStackTrace();
        System.exit(0);
    }
    try {
        System.out.println("RR Chair Servlet");
        System.out.println(response.toString());

        BufferedReader brd = request.getReader();

        String input = "";
        String message = "";

        while (!input.equals("</RuleML>")) {

            input = brd.readLine();

            message = message + input;
        }
        String[] varOrder = getVariableOrder(message);
        System.out.println("Received Message: " + message);

        //   BackwardReasoner br = new BackwardReasoner();
        //   Iterator solit =null;
        //   DefiniteClause dc = null;
        //   SymbolTable.reset();

        POSLParser pp = new POSLParser();
        // String contents = "c(a).\nc(b).\nc(c).";

        Date t1 = new GregorianCalendar().getTime();
        System.out.println(t1.getHours() + ":" + t1.getMinutes());
        //append time to contents

        System.out.println("day: " + t1.getDay());
        System.out.println("day: " + t1.getYear());
        System.out.println("day: " + t1.getMonth());

        //time
        String time = "time(" + t1.getHours() + ":integer).";
        System.out.println(time);

        String url = poslAddress;

        //String url = "http://www.jdrew.org/oojdrew/test.posl";
        String contents = "";

        //day of the week
        int day = t1.getDay();
        boolean weekday = true;

        if (day == 0 || day == 6) {
            weekday = false;
        }

        String dayOfWeek;

        if (weekday) {
            dayOfWeek = "day(weekday).";
        } else {
            dayOfWeek = "day(weekend).";
        }
        //full date
        Calendar cal = new GregorianCalendar();

        int year = cal.get(Calendar.YEAR);
        int month = cal.get(Calendar.MONTH) + 1;
        int day2 = cal.get(Calendar.DAY_OF_MONTH);

        String date;

        String day3 = "" + day2;

        if (day2 == 1 || day2 == 2 || day2 == 3 || day2 == 4 || day2 == 5 || day2 == 6 || day2 == 7 || day2 == 8
                || day2 == 9) {

            day3 = "0" + day2;
        }

        if (month == 10 || month == 11 || month == 12) {
            date = "" + year + month + day3;
        } else {
            date = "" + year + "0" + month + day3;
        }

        date = "date(" + date + ":integer).";

        System.out.println(date);

        String url2 = rdfAddress;
        HttpClient client2 = new HttpClient();
        GetMethod method2 = new GetMethod(url2);
        method2.setFollowRedirects(true);
        String typestr = "";
        // Execute the GET method
        int statusCode2 = client2.executeMethod(method2);
        if (statusCode2 != -1) {
            typestr = method2.getResponseBodyAsString();
        }
        try {
            Types.reset();

            RDFSParser.parseRDFSString(typestr);
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            HttpClient client = new HttpClient();
            GetMethod method = new GetMethod(url);
            method.setFollowRedirects(true);

            // Execute the GET method
            int statusCode = client.executeMethod(method);
            if (statusCode != -1) {
                contents = method.getResponseBodyAsString();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        contents = contents + "\n" + time;
        contents = contents + "\n" + dayOfWeek;
        contents = contents + "\n" + date;

        BackwardReasoner br = new BackwardReasoner();
        Iterator solit = null;
        DefiniteClause dc = null;
        SymbolTable.reset();
        pp.parseDefiniteClauses(contents);

        br.loadClauses(pp.iterator());

        Iterator it = pp.iterator();
        while (it.hasNext()) {
            DefiniteClause d = (DefiniteClause) it.next();
            System.out.println("Loaded clause: " + d.toPOSLString());
        }

        br = new BackwardReasoner(br.clauses, br.oids);

        MessageParser m = new MessageParser(message);
        Element atom = null;

        try {
            atom = m.parseForContent();
        } catch (Exception e) {
            System.out.println("Invalid Message");
            //out.flush();
        }
        QueryBuilder q = new QueryBuilder(atom);
        String query = q.generateDoc();
        System.out.println("ABOUT TO INPUT THIS QUERY:" + query);
        RuleMLParser qp = new RuleMLParser();

        try {
            dc = qp.parseRuleMLQuery(query);
        } catch (Exception e) {
            System.out.println("Invalid Query");
            //out.flush();
        }

        //solit = br.iterativeDepthFirstSolutionIterator(dc);

        solit = br.iterativeDepthFirstSolutionIterator(dc);
        int varSize = 0;
        while (solit.hasNext()) {
            Vector data = new Vector();
            BackwardReasoner.GoalList gl = (BackwardReasoner.GoalList) solit.next();

            Hashtable varbind = gl.varBindings;
            javax.swing.tree.DefaultMutableTreeNode root = br.toTree();
            root.setAllowsChildren(true);

            javax.swing.tree.DefaultTreeModel dtm = new DefaultTreeModel(root);

            int i = 0;
            Object[][] rowdata = new Object[varbind.size()][2];
            varSize = varbind.size();

            Enumeration e = varbind.keys();
            while (e.hasMoreElements()) {
                Object k = e.nextElement();
                Object val = varbind.get(k);
                String ks = (String) k;
                rowdata[i][0] = ks;
                rowdata[i][1] = val;

                i++;
            }
            data.addElement(rowdata);
            String[] messages = new String[data.size()];
            MessageGenerator g = new MessageGenerator(data, varSize, messageEndpoint, m.getId(),
                    m.getProtocol(), m.getRel(), varOrder);
            messages = g.Messages2();

            String appender = "";

            URL sender = new URL(address + ":" + port);
            HttpMessage msg = new HttpMessage(sender);
            Properties props = new Properties();

            for (int i1 = 0; i1 < data.size(); i1++) {
                System.out.println(i1 + ")" + messages[i1].toString());
                props.put("text", messages[i1].toString());
                InputStream in = msg.sendGetMessage(props);
            }
            System.out.println("NEXT MESSAGE");
        }

        MessageGenerator g = new MessageGenerator(null, varSize, messageEndpoint, m.getId(), m.getProtocol(),
                m.getRel());

        URL sender = new URL(address + ":" + port);
        HttpMessage msg = new HttpMessage(sender);
        Properties props = new Properties();

        String finalMessage = g.finalMessage(query);
        System.out.println("nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn");
        System.out.println(finalMessage);

        props.put("text", finalMessage);
        InputStream in = msg.sendGetMessage(props);

        System.out.println("Stop_Communication");

    } catch (Exception e) {
        System.out.println("ERROR has occured : " + e.toString());
    }
    out.close();
}

From source file:pa_SymposiumPlanner.RuleML2012TGAgent.java

public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    try {/*from ww  w .  j  a v a2s .  c  o  m*/
        address = PAConfiguration.getAddress();
        port = PAConfiguration.getPort(instantiation);
        poslAddress = PAConfiguration.getPOSL(instantiation, topic);
        rdfAddress = PAConfiguration.getRDFTaxonomy(instantiation);
        messageEndpoint = PAConfiguration.getEndpointName(instantiation, topic);
    } catch (BadConfigurationException e) {
        System.out.println(e.getMessage());
        e.printStackTrace();
        System.exit(0);
    }
    response.setContentType("text/html; charset=UTF-8");
    PrintWriter out = response.getWriter();

    try {
        System.out.println("TG Agent Servlet");
        System.out.println(response.toString());

        BufferedReader brd = request.getReader();

        String input = "";
        String message = "";

        while (!input.equals("</RuleML>")) {

            input = brd.readLine();

            message = message + input;
        }
        String[] varOrder = getVariableOrder(message);
        System.out.println("Received Message: " + message);

        //   BackwardReasoner br = new BackwardReasoner();
        //   Iterator solit =null;
        //   DefiniteClause dc = null;
        //   SymbolTable.reset();

        POSLParser pp = new POSLParser();
        // String contents = "c(a).\nc(b).\nc(c).";

        Date t1 = new GregorianCalendar().getTime();
        System.out.println(t1.getHours() + ":" + t1.getMinutes());
        //append time to contents

        System.out.println("day: " + t1.getDay());
        System.out.println("day: " + t1.getYear());
        System.out.println("day: " + t1.getMonth());

        //time
        String time = "time(" + t1.getHours() + ":integer).";
        System.out.println(time);

        String url = poslAddress;

        //String url = "http://www.jdrew.org/oojdrew/test.posl";
        String contents = "";

        //day of the week
        int day = t1.getDay();
        boolean weekday = true;

        if (day == 0 || day == 6) {
            weekday = false;
        }

        String dayOfWeek;

        if (weekday) {
            dayOfWeek = "day(weekday).";
        } else {
            dayOfWeek = "day(weekend).";
        }
        //full date 
        Calendar cal = new GregorianCalendar();

        int year = cal.get(Calendar.YEAR);
        int month = cal.get(Calendar.MONTH) + 1;
        int day2 = cal.get(Calendar.DAY_OF_MONTH);

        String date;

        String day3 = "" + day2;

        if (day2 == 1 || day2 == 2 || day2 == 3 || day2 == 4 || day2 == 5 || day2 == 6 || day2 == 7 || day2 == 8
                || day2 == 9) {

            day3 = "0" + day2;
        }

        if (month == 10 || month == 11 || month == 12)
            date = "" + year + month + day3;
        else
            date = "" + year + "0" + month + day3;

        date = "date(" + date + ":integer).";

        System.out.println(date);

        String url2 = rdfAddress;
        HttpClient client2 = new HttpClient();
        GetMethod method2 = new GetMethod(url2);
        method2.setFollowRedirects(true);
        String typestr = "";
        // Execute the GET method
        int statusCode2 = client2.executeMethod(method2);
        if (statusCode2 != -1) {
            typestr = method2.getResponseBodyAsString();
        }
        System.out.println("Types: " + typestr);
        Types.reset();
        RDFSParser.parseRDFSString(typestr);

        try {
            HttpClient client = new HttpClient();
            GetMethod method = new GetMethod(url);
            method.setFollowRedirects(true);

            //Execute the GET method
            int statusCode = client.executeMethod(method);
            if (statusCode != -1) {
                contents = method.getResponseBodyAsString();
            }
        }

        catch (Exception e) {
            e.printStackTrace();
        }
        contents = contents + "\n" + time;
        contents = contents + "\n" + dayOfWeek;
        contents = contents + "\n" + date;

        BackwardReasoner br = new BackwardReasoner();
        Iterator solit = null;
        DefiniteClause dc = null;
        SymbolTable.reset();

        pp.parseDefiniteClauses(contents);

        br.loadClauses(pp.iterator());
        System.out.println("TEST");
        Iterator it = pp.iterator();
        while (it.hasNext()) {
            DefiniteClause d = (DefiniteClause) it.next();
            System.out.println("Loaded clause: " + d.toPOSLString());
        }

        br = new BackwardReasoner(br.clauses, br.oids);

        MessageParser m = new MessageParser(message);
        Element atom = null;

        try {

            atom = m.parseForContent();

        } catch (Exception e) {

            System.out.println("Invalid Message");
            //out.flush();

        }

        QueryBuilder q = new QueryBuilder(atom);
        String query = q.generateDoc();
        System.out.println("ABOUT TO INPUT THIS QUERY:" + query);
        RuleMLParser qp = new RuleMLParser();

        try {

            dc = qp.parseRuleMLQuery(query);

        }

        catch (Exception e) {
            System.out.println("Invalid Query");
            //out.flush();
        }

        //solit = br.iterativeDepthFirstSolutionIterator(dc);

        solit = br.iterativeDepthFirstSolutionIterator(dc);

        int varSize = 0;

        while (solit.hasNext()) {

            Vector data = new Vector();

            BackwardReasoner.GoalList gl = (BackwardReasoner.GoalList) solit.next();

            Hashtable varbind = gl.varBindings;
            javax.swing.tree.DefaultMutableTreeNode root = br.toTree();
            root.setAllowsChildren(true);

            javax.swing.tree.DefaultTreeModel dtm = new DefaultTreeModel(root);

            int i = 0;
            Object[][] rowdata = new Object[varbind.size()][2];
            varSize = varbind.size();

            Enumeration e = varbind.keys();
            while (e.hasMoreElements()) {
                Object k = e.nextElement();
                Object val = varbind.get(k);
                String ks = (String) k;
                rowdata[i][0] = ks;
                rowdata[i][1] = val;
                i++;
            }

            data.addElement(rowdata);
            String[] messages = new String[data.size()];
            MessageGenerator g = new MessageGenerator(data, varSize, messageEndpoint, m.getId(),
                    m.getProtocol(), m.getRel(), varOrder);
            messages = g.Messages2();

            String appender = "";

            URL sender = new URL(address + ":" + port);
            HttpMessage msg = new HttpMessage(sender);
            Properties props = new Properties();

            for (int i1 = 0; i1 < data.size(); i1++) {
                System.out.println(i1 + ")" + messages[i1].toString());
                props.put("text", messages[i1].toString());
                InputStream in = msg.sendGetMessage(props);
            }
            System.out.println("NEXT MESSAGE");
        }

        MessageGenerator g = new MessageGenerator(null, varSize, messageEndpoint, m.getId(), m.getProtocol(),
                m.getRel());

        URL sender = new URL(address + ":" + port);
        HttpMessage msg = new HttpMessage(sender);
        Properties props = new Properties();

        String finalMessage = g.finalMessage(query);

        System.out.println(finalMessage);

        props.put("text", finalMessage);
        InputStream in = msg.sendGetMessage(props);

        System.out.println("Stop_Communication");

    } catch (Exception e) {
        System.out.println("ERROR has occured : " + e.toString());

    }
    out.close();
}

From source file:plptool.gui.ProjectDriver.java

/**
 * GUI: update the develop window to reflect the current state of the
 * project driver (open file, etc.)//from w  w w.java2s.co m
 *
 * @param commitCurrentAsm Whether to commit currently open asm file
 * in the editor before refreshing.
 * @return PLP_OK
 */
public int refreshProjectView(boolean commitCurrentAsm) {
    Msg.D("Project view refresh...", 3, this);

    if (plpfile == null) {
        g_dev.disableBuildControls();
        g_dev.catchyPLP();

        g_dev.getProjectTree()
                .setModel(new DefaultTreeModel(new DefaultMutableTreeNode("No project file open.")));

        return Constants.PLP_OK;
    }

    if (commitCurrentAsm)
        updateAsm(open_asm, g_dev.getEditorText());

    updateWindowTitle();

    DefaultMutableTreeNode root = new DefaultMutableTreeNode(plpfile.getName());
    DefaultMutableTreeNode srcRoot = new DefaultMutableTreeNode("Source Files");
    DefaultMutableTreeNode metaRoot = new DefaultMutableTreeNode("Meta Information");
    root.add(srcRoot);
    root.add(metaRoot);
    for (int i = 0; i < asms.size(); i++)
        srcRoot.add(new DefaultMutableTreeNode(i + ": " + asms.get(i).getAsmFilePath()));

    Scanner metaScanner = new Scanner(meta);
    metaScanner.findWithinHorizon("DIRTY=", 0);
    int meta_dirty = metaScanner.nextInt();
    metaRoot.add(new DefaultMutableTreeNode("meta.DIRTY=" + meta_dirty));
    metaRoot.add(new DefaultMutableTreeNode("ISA=" + ArchRegistry.getStringID(arch.getID())));

    g_dev.getProjectTree().setModel(new DefaultTreeModel(root));
    for (int i = 0; i < g_dev.getProjectTree().getRowCount(); i++)
        g_dev.getProjectTree().expandRow(i);

    if (!asms.get(open_asm).getAsmString().equals(g_dev.getEditorText()))
        g_dev.setEditorText(asms.get(open_asm).getAsmString());

    g_dev.getEditor().setEnabled(true);
    g_dev.getEditor().setVisible(true);
    g_dev.getEditor().setCaretPosition(0);
    g_dev.enableBuildControls();

    String header = asms.get(open_asm).getAsmFilePath();

    if (open_asm == 0)
        header += " <main program>";

    g_dev.setCurFile(header);

    CallbackRegistry.callback(CallbackRegistry.GUI_VIEW_REFRESH, commitCurrentAsm);
    Msg.D("Done.", 3, this);
    return Constants.PLP_OK;
}

From source file:plugin.notes.gui.NotesView.java

private void initTree() {
    dataDir.listFiles();//from  w w w. ja  v  a2 s.com
    root = new NotesTreeNode(dataDir.getName(), dataDir, notesTree);

    TreeModel model = new DefaultTreeModel(root);
    notesTree.setModel(model);
    notesTree.addTreeSelectionListener(new TreeSelectionListener() {
        @Override
        public void valueChanged(TreeSelectionEvent evt) {
            notesTreeActionPerformed();
        }
    });
    notesTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    notesTree.setEditable(true);
    model.addTreeModelListener(new TreeModelListener() {
        @Override
        public void treeNodesChanged(TreeModelEvent e) {
            notesTreeNodesChanged();
        }

        @Override
        public void treeNodesInserted(TreeModelEvent e) {
            // TODO:  Method does nothing?
        }

        @Override
        public void treeNodesRemoved(TreeModelEvent e) {
            // TODO:  Method does nothing?
        }

        @Override
        public void treeStructureChanged(TreeModelEvent e) {
            // TODO:  Method does nothing?
        }
    });
}

From source file:psidev.psi.mi.filemakers.xsd.AbstractXsdTreeStruct.java

/**
 * create the tree according to the schema loaded. The root node is displayed
 *
 *//* w ww  .j av a 2  s.  c o  m*/
public void createTree() {
    Enumeration<ElementDecl> elts = schema.getElementDecls();
    ElementDecl elt = elts.nextElement();
    XsdNode node = new XsdNode(elt);
    /* rootNode is mandatory */
    rootNode = node;
    rootNode.use();
    treeModel = new DefaultTreeModel(rootNode);
    tree.setModel(treeModel);
}

From source file:pt.ua.dicoogle.rGUI.client.windows.MainWindow.java

/** Creates new form MainWindow */
private MainWindow() {
    this.ranges = new ArrayList<javax.swing.JCheckBox>();
    List<String> names = null;
    try {//from  w ww.  ja  va 2 s.co  m
        names = PluginController4user.getInstance().getPluginNames();
        for (String name : names) {
            JCheckBox newJCB = new JCheckBox(name);
            if (PluginController4user.getInstance().isLocalPlugin(name)) {
                newJCB.setSelected(true);
            }
            this.ranges.add(newJCB);
        }
    } catch (RemoteException ex) {
        Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
    }

    initComponents();

    javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
    jPanel6.setLayout(jPanel6Layout);
    SequentialGroup groupBoxesH = jPanel6Layout.createSequentialGroup().addComponent(jLabel2);
    ParallelGroup groupBoxesV = jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
            .addComponent(jLabel2);

    for (JCheckBox cbox : this.ranges) {
        groupBoxesH.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED).addComponent(cbox);
        groupBoxesV.addComponent(cbox);
    }

    Group groupH = jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(groupBoxesH.addContainerGap(10, Short.MAX_VALUE));

    Group groupV = jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
            jPanel6Layout.createSequentialGroup().addGroup(groupBoxesV).addContainerGap(5, Short.MAX_VALUE));

    jPanel6Layout.setHorizontalGroup(groupH);
    jPanel6Layout.setVerticalGroup(groupV);

    Image image = Toolkit.getDefaultToolkit()
            .getImage(Main.class.getResource("/pt/ua/dicoogle/gfx/trayicon.gif"));
    this.setIconImage(image);

    clientCore = ClientCore.getInstance();

    if (!clientCore.isAdmin()) {
        jMenu10.setVisible(false);
        jMenuItemShutdown.setVisible(false);
        jMenuDirScan2.setVisible(false);

        //jPanel8.setVisible(false);
        jButtonServices.setVisible(false);
        jButtonPreferences.setVisible(false);
        jButtonLogs.setVisible(false);
    }

    if (!clientCore.isUser()) {
        jPanel5.setVisible(false);
        jButtonClientPreferences.setVisible(false);
    } else {
        searchTree = Result2Tree.getInstance();
    }

    if (Main.isFixedClient()) {
        jMenuItemShutdown.setVisible(false);

    } else {
        jMenuItem7.setVisible(false);
    }

    jLabelResults.setText("Enter your terms and hit the button.");
    SelectDefaultSearch.setSelected(true);
    SelectAdvancedSearch.setSelected(false);
    jPanel2.setVisible(false);
    ModalSelectNone.setSelected(false);
    ModalSelectAll.setSelected(true);
    ModalCR.setSelected(true);
    ModalCT.setSelected(true);
    ModalDX.setSelected(true);
    ModalES.setSelected(true);
    ModalMG.setSelected(true);
    ModalMR.setSelected(true);
    ModalNM.setSelected(true);
    ModalOT.setSelected(true);
    ModalPT.setSelected(true);
    ModalRF.setSelected(true);
    ModalSC.setSelected(true);
    ModalUS.setSelected(true);
    ModalXA.setSelected(true);

    StudyDateRangeInitialBoundary.setEnabled(false);
    StudyDateRangeTerminalBoundary.setEnabled(false);
    DateRange.setSelected(false);
    ExactDate.setSelected(true);

    StudyDateRangeInitialBoundaryActivation.setEnabled(false);
    StudyDateRangeTerminalBoundaryActivation.setEnabled(false);
    StudyDateRangeInitialBoundary.setEnabled(false);
    StudyDateRangeTerminalBoundary.setEnabled(false);

    //tree view init
    jTreeResults.setModel(new DefaultTreeModel(Result2Tree.getInstance().getTop()));
    jTreeResults.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

    jButtonDownload.setEnabled(false);
    jButtonView.setEnabled(false);
    jButtonDump.setEnabled(false);
    this.resizeWindow();
    registerForMacOSXEvents();
    centerWindow();

    //////////////////////////////////////////////////////////////
    /**
     * This search is needed to autocomplete
     */
    /*
    QueryResults q = new QueryResults("*:*");
            
            
    List<String> items = q.getFields();
            
            
            
    boolean strictMatching = false;
    AutoCompleteDecorator.decorate(jTextFieldQuery, items, strictMatching);
     *
     */

}

From source file:ubic.basecode.dataStructure.graph.DirectedGraph.java

/**
 * Generate a JTree corresponding to this graph.
 * /* w ww.  j a  va2s .  c om*/
 * @param nodeClass The class to be used for TreeNodes. Defaults to DefaultMutableTreeNode.
 * @return javax.swing.JTree
 */
@SuppressWarnings("unchecked")
public JTree treeView(Class<? extends DefaultMutableTreeNode> nodeClass) {
    log.debug("Constructing tree view of graph");
    DirectedGraphNode<K, V> root = getRoot();
    Constructor<DefaultMutableTreeNode> constructor;
    DefaultMutableTreeNode top = null;
    treeView = null;
    try {
        constructor = (Constructor<DefaultMutableTreeNode>) nodeClass
                .getConstructor(new Class[] { root.getClass() });
        top = constructor.newInstance(new Object[] { root });
        log.debug("Starting tree with: " + top.getClass().getName());
        root.mark();
        addJTreeNode(top, root, constructor);
        dtm = new DefaultTreeModel(top);
        treeView = new JTree(dtm);

    } catch (Exception e) {
        log.error(e, e);
    }
    return treeView;
}

From source file:unikn.dbis.univis.navigation.tree.VTree.java

public void refresh(VDiceBox diceBox) {
    setRootVisible(true);
    setModel(new DefaultTreeModel(VTreeHelper.createDefaultTree(diceBox)));
}