All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ingenias.editor.rendererxml.HorizontalCollectionPanel Maven / Gradle / Ivy

There is a newer version: 1.0.11
Show newest version

/** 
 * 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 ingenias.editor.*;
import javax.print.attribute.HashAttributeSet;
import javax.swing.*;

public class HorizontalCollectionPanel 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();
	public HorizontalCollectionPanel() {
		/*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 HorizontalCollectionPanel(LayoutManager p0, boolean p1) {
		super(p0, p1);
	}

	public HorizontalCollectionPanel(LayoutManager p0) {
		super(p0);
	}

	public HorizontalCollectionPanel(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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy