ingenias.editor.rendererxml.CollectionPanel Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sociaalmled Show documentation
Show all versions of sociaalmled Show documentation
A editor for modelling scenarios for PHAT simulator
/**
* Copyright (C) 2010 Jorge J. Gomez-Sanz
*
* This file is part of the INGENME tool. INGENME is an open source meta-editor
* which produces customized editors for user-defined modeling languages
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation version 3 of the License
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see
**/
package ingenias.editor.rendererxml;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JPanel;
import java.awt.*;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import javax.swing.border.*;
import java.util.*;
import java.beans.*;
import java.io.*;
import java.net.MalformedURLException;
import ingenias.editor.*;
import ingenias.editor.entities.ModelEntity;
import javax.print.attribute.HashAttributeSet;
import javax.swing.*;
public class CollectionPanel extends JPanel {
private boolean settingcollection=false;
private JPanel box = new JPanel(new GridBagLayout());
private static Hashtable duplicatesCache=new Hashtable();
int counter=0;
Vector tobeduplicated=new Vector();
private String attname;
public String getAttName(){
return attname;
}
public CollectionPanel() {
/*final JScrollPane jsp=new JScrollPane(box,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER );
jsp.addComponentListener(new ComponentListener(){
public void componentHidden(ComponentEvent arg0) {}
public void componentMoved(ComponentEvent arg0) {}
public void componentResized(ComponentEvent arg0) {
box.revalidate();
jsp.revalidate();
System.out.println("revalidating1");
}
public void componentShown(ComponentEvent arg0) {}});
this.addComponentListener(new ComponentListener(){
public void componentHidden(ComponentEvent arg0) {}
public void componentMoved(ComponentEvent arg0) {}
public void componentResized(ComponentEvent arg0) {
box.revalidate();
revalidate();
System.out.println("revalidating2");
}
public void componentShown(ComponentEvent arg0) {}});*/
this.setLayout(new BorderLayout());
super.add(box, BorderLayout.CENTER);
}
public CollectionPanel(LayoutManager p0, boolean p1) {
super(p0, p1);
}
public CollectionPanel(LayoutManager p0) {
super(p0);
}
public CollectionPanel(boolean p0) {
super(p0);
}
public void add(Component comp,Object name){
// System.err.println("adding3 "+name.toString()+" "+comp.getClass().getName());
super.add(comp,name);
}
public Component add(String name,Component comp){
// System.err.println("adding2 "+name+" "+comp.getClass().getName());
return super.add(name,comp);
}
public Component add(Component comp){
//System.err.println("adding1 "+comp.getClass().getName()+" "+comp.getName());
if (!settingcollection){
// System.err.println("to be duplicated");
tobeduplicated.add(comp);
}
return comp;
// return super.add(comp);
}
private static Vector duplicate(ingenias.editor.TypedVector data, Vector tobeduplicated) {
Vector result;
if (duplicatesCache.containsKey(data)){
result=duplicatesCache.get(data);
if (result.size()==data.size()){
return result;
}
}
ObjectOutputStream oos = null;
Vector results = new Vector();
try {
java.io.ByteArrayOutputStream sw = new java.io.ByteArrayOutputStream(50000);
oos = new ObjectOutputStream(sw);
Enumeration enumeration = tobeduplicated.elements();
HashSet temp = new HashSet();
while (enumeration.hasMoreElements()) {
Component comp = (Component) enumeration.nextElement();
temp.add(comp);
}
oos.writeObject(temp);
oos.close();
for (int k = 0; k < data.size(); k++) {
ObjectInputStream decoder = new ObjectInputStream(new java.io.ByteArrayInputStream(sw.toByteArray()));
temp = (HashSet) decoder.readObject();
decoder.close();
results.add(temp);
}
duplicatesCache.put(data,results);
} catch (IOException ex) {
ex.printStackTrace();
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
return results;
}
public Vector fold(Component cont){
Vector result=new Vector();
result.add(cont);
if (cont instanceof Container){
Container container=(Container)cont;
Component[] components=container.getComponents();
for (int k=0;k