Package org.mizartools.example.ui

Source Code of org.mizartools.example.ui.RegistrationFrame

/*
   Copyright (c) 2011 Mizar Tools Contributors (mizartools.org)

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
/*  Contributors :
*  2011-03-05 Marco Riccardi - initial implementation
*
*/
package org.mizartools.example.ui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.util.LinkedList;

import javax.swing.JInternalFrame;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;

import org.mizartools.dli.DliException;
import org.mizartools.dli.utility.ItemFactory;
import org.mizartools.system.Article;
import org.mizartools.system.ArticleFactory;
import org.mizartools.system.IClusterRegistration;
import org.mizartools.system.utility.RegistrationsSignature;
import org.mizartools.system.utility.UniqueIdentifier;
import org.mizartools.system.utility.UniqueIdentifierException;
import org.mizartools.system.xml.ArticleID;
import org.mizartools.system.xml.CCluster;
import org.mizartools.system.xml.FCluster;
import org.mizartools.system.xml.RCluster;
import org.mizartools.utility.Html;

@SuppressWarnings("serial")
public class RegistrationFrame extends JInternalFrame implements Runnable {

  private JTextPane textPane;
  private JPanel panel;
  private JScrollPane scroller;
  private JProgressBar progressBar;
  private String articleID;
 
  public RegistrationFrame(String aid) {
      super("Registration - " + aid, true, true, true, true);
      this.articleID = aid;
      panel = new JPanel();
      panel.setLayout(new BorderLayout());
    panel.setPreferredSize(new Dimension(500, 350));
    textPane = new JTextPane();
        scroller = new JScrollPane();
    scroller.getViewport().add(textPane);
    panel.add(scroller, BorderLayout.CENTER);
    getContentPane().add(panel, BorderLayout.CENTER);
    progressBar = new JProgressBar();
    pack();
  }
 
  private String getHtml() {
      StringBuilder html = new StringBuilder();
      html.append("<html>");
      html.append("<body>");
      html.append("<table width=100% border=1>");
    html.append("<tr>");
    html.append("<td>ARTICLEID</td>");
    html.append("<td>Signature</td>");
    html.append("</tr>");
      Article article = ArticleFactory.getInstance().getArticle(articleID);
      StringBuilder stringBuilder;
    if (article.hasRegistrations()) {
      html.append("<tr>");
        html.append("<td>");
          html.append("<font face=\"monospace\"><b>");
          html.append(article.getAid());
          html.append("</b></font");
        html.append("</td>");
        stringBuilder = new StringBuilder();
        for (ArticleID articleID : article.getRegistrations().getSignature().getArticleIDList()){
          if (stringBuilder.length()>0) stringBuilder.append(", ");
          stringBuilder.append(articleID.getName());
        }
      html.append("<td>" + stringBuilder.toString() + "</td>");
     
      html.append("</tr>");
    }
      html.append("</table>");

      LinkedList<IClusterRegistration> clusterRegistrationList = article.getRegistrations().getIClusterRegistrationList();
      progressBar.setMaximum(clusterRegistrationList.size()+1);
      progressBar.setValue(0);
      progressBar.setIndeterminate(false);
    html.append("<h2>List of registrations</h2>");
     
      html.append("<table width=100% border=1>");
    html.append("<tr>");
    html.append("<td>UniqueIdentifier</td>");
    html.append("<td>Aid</td>");
    html.append("<td>Nr</td>");
    html.append("<td>ArgTypes</td>");
    html.append("<td>Cluster1</td>");
    html.append("<td>Cluster2</td>");
    html.append("<td>Cluster3</td>");
    html.append("<td>Typ</td>");
    html.append("<td>Term</td>");
    html.append("</tr>");

    RegistrationsSignature registrationSignature = article.getRegistrationsSignature();
      int i = 0;
    for (IClusterRegistration iClusterRegistration : clusterRegistrationList){
        progressBar.setValue(i++);
        progressBar.repaint();
      html.append("<tr>");
      html.append("<td><b>");
      try {
        html.append(UniqueIdentifier.getInstance(registrationSignature, article.getAid(), iClusterRegistration.getClusterRegistrationKind(), iClusterRegistration.getClusterRegistrationNr()).toString());
      } catch (UniqueIdentifierException e) {}
      html.append("</b></td>");
      CCluster cCluster = null;
      FCluster fCluster = null;
      RCluster rCluster = null;
      if (iClusterRegistration instanceof CCluster) {
        cCluster = (org.mizartools.system.xml.CCluster)iClusterRegistration;
        html.append("<td>");
        html.append(cCluster.getAid());
        html.append("</td>");
        html.append("<td>");
        html.append(cCluster.getNr());
        html.append("</td>");
        html.append("<td>");
        if (cCluster.getArgTypes() != null)
          html.append(Html.changeChars(cCluster.getArgTypes().getXMLElementList().toString()));
        html.append("</td>");
        html.append("<td>");
        if (cCluster.getCluster1() != null)
          html.append(Html.changeChars(cCluster.getCluster1().getXMLElementList().toString()));
        html.append("</td>");
        html.append("<td>");
        if (cCluster.getCluster2() != null)
          html.append(Html.changeChars(cCluster.getCluster2().getXMLElementList().toString()));
        html.append("</td>");
        html.append("<td>");
        if (cCluster.getCluster3() != null)
          html.append(Html.changeChars(cCluster.getCluster3().getXMLElementList().toString()));
        html.append("</td>");
        html.append("<td>");
        if (cCluster.getTyp() != null)
          html.append(Html.changeChars(cCluster.getTyp().getXMLElementList().toString()));
        html.append("</td>");
        html.append("<td>");
        html.append("</td>");
       
       
      }
      if (iClusterRegistration instanceof FCluster) {
        fCluster = (org.mizartools.system.xml.FCluster)iClusterRegistration;
        html.append("<td>");
        html.append(fCluster.getAid());
        html.append("</td>");
        html.append("<td>");
        html.append(fCluster.getNr());
        html.append("</td>");
        html.append("<td>");
        if (fCluster.getArgTypes() != null)
          html.append(Html.changeChars(fCluster.getArgTypes().getXMLElementList().toString()));
        html.append("</td>");
        html.append("<td>");
        if (fCluster.getCluster1() != null)
          html.append(Html.changeChars(fCluster.getCluster1().getXMLElementList().toString()));
        html.append("</td>");
        html.append("<td>");
        if (fCluster.getCluster2() != null)
          html.append(Html.changeChars(fCluster.getCluster2().getXMLElementList().toString()));
        html.append("</td>");
        html.append("<td>");
        html.append("</td>");
        html.append("<td>");
        if (fCluster.getTyp() != null)
          html.append(Html.changeChars(fCluster.getTyp().getXMLElementList().toString()));
        html.append("</td>");
        html.append("<td>");
        if (fCluster.getTerm() != null)
          html.append(Html.changeChars(fCluster.getTerm().getXMLElementList().toString()));
        html.append("</td>");

      }
      if (iClusterRegistration instanceof RCluster) {
        rCluster = (org.mizartools.system.xml.RCluster)iClusterRegistration;
        html.append("<td>");
        html.append(rCluster.getAid());
        html.append("</td>");
        html.append("<td>");
        html.append(rCluster.getNr());
        html.append("</td>");
        html.append("<td>");
        if (rCluster.getArgTypes() != null)
          html.append(Html.changeChars(rCluster.getArgTypes().getXMLElementList().toString()));
        html.append("</td>");
        html.append("<td>");
        if (rCluster.getCluster1() != null)
          html.append(Html.changeChars(rCluster.getCluster1().getXMLElementList().toString()));
        html.append("</td>");
        html.append("<td>");
        if (rCluster.getCluster2() != null)
          html.append(Html.changeChars(rCluster.getCluster2().getXMLElementList().toString()));
        html.append("</td>");
        html.append("<td>");
        html.append("</td>");
        html.append("<td>");
        if (rCluster.getTyp() != null)
          html.append(Html.changeChars(rCluster.getTyp().getXMLElementList().toString()));
        html.append("</td>");
        html.append("<td>");
        html.append("</td>");
      }
      html.append("</tr>");
    }
    html.append("</table>");

   
    html.append("<h2>List of registrations in dli format</h2>");
     
      html.append("<table width=100% border=1>");
    html.append("<tr>");
    html.append("<td>UniqueIdentifier</td>");
    html.append("<td>UniqueId</td>");
    html.append("<td>Dli</td>");
    html.append("</tr>");
     
      i = 0;
    for (IClusterRegistration iClusterRegistration : clusterRegistrationList){
        progressBar.setValue(i++);
        progressBar.repaint();
      html.append("<tr>");
      try {
        html.append("<td><b>");
        html.append(UniqueIdentifier.getInstance(registrationSignature, article.getAid(), iClusterRegistration.getClusterRegistrationKind(), iClusterRegistration.getClusterRegistrationNr()).toString());
        html.append("</b></td>");
        html.append("<td>");
        html.append(UniqueIdentifier.getInstance(registrationSignature, article.getAid(), iClusterRegistration.getClusterRegistrationKind(), iClusterRegistration.getClusterRegistrationNr()).id);
        html.append("</td>");
      } catch (UniqueIdentifierException e) {}
      html.append("<td>");
      try {
        html.append(ItemFactory.getItem(registrationSignature, iClusterRegistration).toString());
      } catch (DliException e) {
        html.append(e.toString());
      }
      html.append("</td>");

      html.append("</tr>");
    }
    html.append("</table>");
   
   
    html.append("</body>");
      html.append("</html>");
      return html.toString();
  }

  @Override
  public void run() {
      progressBar.setIndeterminate(true);
      getContentPane().add(progressBar, BorderLayout.SOUTH);
    panel.setVisible(false);
    textPane.setContentType("text/html");
    textPane.setText(getHtml());
      progressBar.setIndeterminate(true);
    textPane.setEditable(false);
    getContentPane().remove(progressBar);
    panel.setVisible(true);
  }
}
TOP

Related Classes of org.mizartools.example.ui.RegistrationFrame

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.