Package org.mizartools.example.ui

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

/*
   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.DecodedLibraryItem;
import org.mizartools.dli.DliException;
import org.mizartools.dli.utility.ItemFactory;
import org.mizartools.dli.utility.SchemeId;
import org.mizartools.system.Article;
import org.mizartools.system.ArticleFactory;
import org.mizartools.system.utility.SchemesSignature;
import org.mizartools.system.utility.UniqueIdentifier;
import org.mizartools.system.utility.UniqueIdentifierException;
import org.mizartools.system.utility.UniqueIdentifierType;
import org.mizartools.system.xml.ArticleID;
import org.mizartools.system.xml.Formula;
import org.mizartools.system.xml.Scheme;
import org.mizartools.utility.Html;

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

  private JTextPane textPane;
  private JPanel panel;
  private JScrollPane scroller;
  private JProgressBar progressBar;
  private String articleID;
 
  public SchemeFrame(String aid) {
      super("Scheme - " + 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.hasSchemes()) {
      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.getSchemes().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<Scheme> schemeList = article.getSchemes().getSchemeList();
      progressBar.setMaximum(schemeList.size()+1);
      progressBar.setValue(0);
      progressBar.setIndeterminate(false);
    html.append("<h2>List of schemes</h2>");
     
      html.append("<table width=100% border=1>");
    html.append("<tr>");
    html.append("<td>UniqueIdentifier</td>");
    html.append("<td>Nr</td>");
    html.append("<td>ArgTypes</td>");
    html.append("<td>Formula1</td>");
    html.append("<td>formula2List</td>");
    html.append("</tr>");

    SchemesSignature schemesSignature = article.getSchemesSignature();
    UniqueIdentifierType type = UniqueIdentifierType.sch;
      int i = 0;
    SchemeId schemeId = new SchemeId();
    for (Scheme scheme : schemeList ){
      int nr = 0;
      schemeId.increment();
      nr = schemeId.getId();
      if (scheme.getNr() != null) nr = scheme.getNr();
     
      progressBar.setValue(i++);
        progressBar.repaint();
      html.append("<tr>");
      html.append("<td><b>");
      try {
        html.append(UniqueIdentifier.getInstance(article.getAid(), type, nr).toString());
      } catch (UniqueIdentifierException e) {}
      html.append("</b></td>");
      html.append("<td>");
      if (scheme.getNr() != null)
        html.append(scheme.getNr().toString());
      html.append("</td>");
      html.append("<td>");
      if (scheme.getArgTypes() != null)
        html.append(Html.changeChars(scheme.getArgTypes().getXMLElementList().toString()));
      html.append("</td>");
      html.append("<td>");
      if (scheme.getFormula1() != null)
        html.append(Html.changeChars(scheme.getFormula1().getXMLElementList().toString()));
      html.append("</td>");

      html.append("<td>");
      if (scheme.getFormula2List() != null){
          stringBuilder = new StringBuilder();
        for (Formula formula : scheme.getFormula2List()){
            if (stringBuilder.length()>0) stringBuilder.append(", ");
          stringBuilder.append(formula.getXMLElementList().toString());
        }
        html.append(Html.changeChars(stringBuilder.toString()));
      }
      html.append("</td>");
      html.append("</tr>");
    }
    html.append("</table>");

   
    html.append("<h2>List of schemes 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;
    schemeId = new SchemeId();
    for (Scheme scheme : schemeList){
        progressBar.setValue(i++);
        progressBar.repaint();
      html.append("<tr>");
      try {
        DecodedLibraryItem decodedLibraryItem = ItemFactory.getItem(schemesSignature, scheme, schemeId);
        int nr = schemeId.getId();
        if (scheme.getNr() != null) nr = scheme.getNr();
        html.append("<td><b>");
        try {
          html.append(UniqueIdentifier.getInstance(article.getAid(), type, nr).toString());
          html.append("</b></td>");
          html.append("<td>");
          html.append(UniqueIdentifier.getInstance(article.getAid(), type, nr).id);
          html.append("</td>");
        } catch (UniqueIdentifierException e) {}
        html.append("<td>");
        html.append(decodedLibraryItem.toString());
        html.append("</td>");
      } catch (DliException e) {
        html.append(e.toString());
      }

      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.SchemeFrame

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.