Package org.sintef.umt.systemfamily

Source Code of org.sintef.umt.systemfamily.VariabilityChecker

package org.sintef.umt.systemfamily;


import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.util.Enumeration;
import java.util.Vector;

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

import org.w3c.dom.Element;

public class VariabilityChecker extends JPanel implements Runnable   
{
    private volatile Element modelRoot;
    private JLabel label = new JLabel ("Not checked");
    private volatile boolean checked = false;
    VariabilityCheckEngine engine = null;
    final JFrame frame = new JFrame ();
    final JTextArea output = new JTextArea ();
   
    public VariabilityChecker () {
        super (new BorderLayout());
        setBackground (VariabilityManager.bgColor);
        label.setBackground(VariabilityManager.bgColor);
        add (label);
        init ();
    }
   
    public void setModel (Element model) {
        modelRoot = model;
    }
   
    private void init () {
        frame.getContentPane().setLayout(new BorderLayout ());
        frame.setUndecorated(true);
        output.setBackground(VariabilityManager.bgColor);
        output.setForeground(Color.gray);           
        frame.getContentPane().add(new JScrollPane(output), BorderLayout.CENTER);
        JPanel buttonPanel = new JPanel(new FlowLayout (FlowLayout.RIGHT));
        buttonPanel.setBackground(VariabilityManager.bgColor);
        frame.getContentPane().add(buttonPanel, BorderLayout.SOUTH);
        JButton close = new JButton ("close");
        close.setOpaque(true);
        close.setContentAreaFilled(false);
        close.addActionListener(new ActionListener() {
            public void actionPerformed (ActionEvent ae) {
                frame.setVisible(false);
                frame.dispose();
            }
         })
       
        buttonPanel.add(close);
        frame.setSize(500,400);
        output.addFocusListener(new FocusListener () {
            public void focusGained (FocusEvent fe){
            }
            public void focusLost (FocusEvent fe){
                frame.setVisible(false);
                frame.dispose();
            }
        });
    }
   
    public void startCheck () {
        Point loc = getLocationOnScreen();
        // frame.setLocationRelativeTo(this);
        frame.setLocation(loc.x - 400, loc.y + 40);
        frame.setVisible(true);           
        output.setText("");
        checked = false;           
        Thread t = new Thread (this);          
        engine = VariabilityFactory.createVariabilityCheckEngine();           
        t.start();
        engine.checkModel(modelRoot);
        checked = true;  
        reportErrors ();
    }
   
   
    private void reportErrors () {
        // JOptionPane.showMessageDialog(this, "Reporting Errors ....");           
       
        // Do the actual report writing...
        Vector errors = engine.getErrors();

       
        if (errors.size() > 0) {
            label.setText("Model Not Complete Resolved.");
            label.setToolTipText("Model has unresolved variation points or inconsistencies.");
            label.setForeground(Color.red);
            output.append("Model has " + errors.size() + " Unresolved Variabilities:\n");
        } else {
            label.setText("Model resolved.");
            label.setToolTipText("All variation points resolved.");
            label.setForeground(Color.black);
            output.append("All variabilities resolved.");
        }
       
        for (Enumeration _enum = errors.elements();_enum.hasMoreElements();) {
            VariabilityError error = (VariabilityError) _enum.nextElement();               
           output.append(error.description );
           output.append(": '" + error.ownerName + "': " + error.sourceType + " - " + error.sourceName);
           output.append("\n");
        }
    }
   
    public void run () {
        label.setText("Checking model");
        while (!checked) {               
            try {
                Thread.sleep(50);
            } catch (InterruptedException iex) {                   
            }
            if (label.getForeground() == Color.lightGray)
                label.setForeground(Color.black);
            else label.setForeground(Color.lightGray);
        }
        label.setText("Model Checked");
    }       
}
TOP

Related Classes of org.sintef.umt.systemfamily.VariabilityChecker

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.