Package view.panels

Source Code of view.panels.ActorView

package view.panels;

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

import model.query.OntologyQueryer;
import view.layout.VerticalLayout;

import com.hp.hpl.jena.query.QuerySolution;
import com.hp.hpl.jena.query.ResultSet;

import controller.MainController;

public class ActorView extends HistoryPanel {
  private static final long serialVersionUID = 2479152301576045755L;

  private JLabel nameLabel, birthDatePanel;
  private JTextArea abstractText;
  private JScrollPane scroll, absScroll;
  private JPanel container;

  public ActorView(int panelNumber, String uri) {
    super(panelNumber, new BorderLayout());

    nameLabel = new JLabel("<html><h1>Name: N/A</h1></html>");

    abstractText = new JTextArea("Summary: N/A");
    abstractText.setLineWrap(true);
    abstractText.setWrapStyleWord(true);
    abstractText.setEditable(false);

    absScroll = new JScrollPane(abstractText);
    absScroll.setPreferredSize(new Dimension(500, 300));
    absScroll.getHorizontalScrollBar().setEnabled(false);

    birthDatePanel = new JLabel("<html><h2>Birth date: N/A</h2></html>");

    container = new JPanel(new VerticalLayout());
    container.add(nameLabel, BorderLayout.NORTH);
    container.add(absScroll, BorderLayout.CENTER);
    container.add(birthDatePanel, BorderLayout.SOUTH);

    scroll = new JScrollPane(container);
    scroll.getHorizontalScrollBar().setEnabled(false);
    add(container, BorderLayout.CENTER);

    ResultSet rs = getActor(uri);
    if (rs.hasNext()) {
      QuerySolution qs = rs.next();

      if (qs.contains("name"))
        nameLabel.setText(nameLabel.getText().replace("N/A", removeLiteral(qs.get("name").toString())));
      if (qs.contains("abstract"))
        abstractText.setText(removeLiteral(qs.get("abstract").toString()));
      if (qs.contains("birthdate"))
        birthDatePanel.setText(birthDatePanel.getText().replace("N/A", removeLiteral(qs.get("birthdate").toString())));

    } else
      if(MainController.DEBUG)
        System.out.println("MovieView.java QuerySolution is empty, check query. URI " + uri);

    abstractText.select(0, 1);
    MainController.getInstance().getWindow().getHistory().add(this);
  }

  private ResultSet getActor(String uri) {
    String query =  "PREFIX uri: <" + uri + "> " +
        "SELECT DISTINCT ?name ?abstract ?birthdate  " +
        "WHERE {  " +
        "OPTIONAL {uri: h2mdb:name ?name .}  " +
        "OPTIONAL {uri: h2mdb:summary ?abstract .}" +
        "OPTIONAL {uri: h2mdb:birthday ?birthdate.}" +
        "}";

    return OntologyQueryer.resultQuery(query);
  }
}
TOP

Related Classes of view.panels.ActorView

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.