Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [platform-swt-dev] Swing

Rodrigo,
It is achievable,
You can try searching this issue on eclipse.org website and you will
find lot of things about this floating around out there.

Maybe If you still need help you can try looking the demo I created
using sun jdk 1.4.2 & eclipse 2.1 API's(Not sure will work on
eclispe 3.0 or not)
Hope this helps
-Regds Hemant


Rodrigo Cal wrote:

Hi friends,

I’m having some problems and I would be glad if somebody out there could give me a little help.

I’m wondering to start writing plug-ins for the Eclipse, JBuilder and Sun One IDEs. But I would like to reuse the same GUI screens among all of these IDEs. What I have in mind is to create each screen in a JPanel component and add the necessary Swing component into it. Then I would use the same JPanels to create the plug-in for JBuilder, Eclipse and Sun One. But I’m not sure if I really can achieve that. Can I use Swing panels and components to write a plug-in for Eclipse? Or I must use only SWT components?

Any comments are appreciated.

Thanks in advance

Best Regards

Rodrigo


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.550 / Virus Database: 342 - Release Date: 9/12/2003


/*
 * Created on Nov 29, 2003
 * IDE: Eclipse
 * @author Hemant.Singh@xxxxxxx
 */

import java.awt.EventQueue;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Panel;
import java.awt.Window;
import java.util.Collection;

import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.JScrollPane;

import org.eclipse.swt.SWT;
import org.eclipse.swt.interop.SWT_AWT;
import org.eclipse.swt.layout.RowData;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;

public class SwingSWTDemo extends Shell {

	private SWTAdaperList swtList1;
	private SwingAdapterList swingList1;
	private java.util.Collection initSWTListContents1;
	private java.util.Collection initSwingListContents1;

	public static void main(String[] args) {
		Display display = new Display();
		final SwingSWTDemo test = new SwingSWTDemo(display);
		test.setSize(400, 400);
		test.setBackground(display.getSystemColor(SWT.COLOR_DARK_BLUE));
		test.makegui();
		test.setVisible(true);
		test.setFocus();
		while (!test.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
	}

	public SwingSWTDemo(Display display) {
		super(display);
		populateListData();
	}

	private void populateListData() {
		initSWTListContents1 = new java.util.TreeSet();
		initSwingListContents1 = new java.util.TreeSet();

		// Now populate them.
		// Populate SWT List 1
		initSWTListContents1.add("2 X 1 = 2");
		initSWTListContents1.add("3 X 1 = 3");
		initSWTListContents1.add("4 X 1 = 4");

		//Populate Swing List 1
		initSwingListContents1.add("2 X 3 = 6");
		initSwingListContents1.add("3 X 3 = 9");
		initSwingListContents1.add("4 X 3 = 12");
	}

	public void makegui() {
		RowLayout layout = new RowLayout();
		layout.spacing = 40;
		layout.marginBottom = 400;
		layout.marginTop = 20;
		layout.marginLeft = 20;
		layout.marginRight = 6;
		layout.wrap = true;

		this.setLayout(layout);

		swtList1 = new SWTAdaperList(this, SWT.SINGLE);
		swtList1.setListContents(initSWTListContents1);
		swtList1.setLayoutData(new RowData(149, 120));

		final Composite bottomPanel = new Composite(this, SWT.NONE);
		bottomPanel.setLayoutData(new RowData(349, 150));
		bottomPanel.setBackground(
			this.getDisplay().getSystemColor(SWT.COLOR_YELLOW));
		this.addListener(SWT.Show, new Listener() {

			public void handleEvent(Event e) {
				Panel awtPanel = SWT_AWT.new_Panel(bottomPanel);
				GridBagLayout awtlayout = new GridBagLayout();
				awtPanel.setLayout(awtlayout);
				GridBagConstraints constraints = new GridBagConstraints();
				swingList1 = new SwingAdapterList();
				swingList1.setListContents(initSwingListContents1);
				JScrollPane scrollPane1 = new JScrollPane();
				scrollPane1.setVerticalScrollBarPolicy(
					JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
				scrollPane1.getViewport().setView(swingList1);
				constraints.gridx = 0;
				constraints.gridy = 5;
				constraints.weightx = 0.3;

				awtPanel.add(scrollPane1, constraints);

				constraints.gridx = 8;
				constraints.gridy = 5;
				constraints.weightx = 0.2;

				final Window frame = (Window) awtPanel.getParent();
				final org.eclipse.swt.graphics.Rectangle rect =
					bottomPanel.getClientArea();
				EventQueue.invokeLater(new Runnable() {
					public void run() {
						frame.setBackground(java.awt.Color.yellow);
						frame.setSize(rect.width, rect.height);
						frame.validate();
					}
				});

			}

		});
	}

	public void checkSubclass() {
		System.out.println(" A Blank Implementation to Allow Sub Class");
	}

	class SwingAdapterList
		extends JList{

		public SwingAdapterList() {
			super(new DefaultListModel());
		}

		/*
		 * (non-Javadoc)
		 * 
		 * @see SwingSWT.TestList#getListContents()
		 */
		public Collection getListContents() {
			Collection toReturn = new java.util.TreeSet();
			DefaultListModel dlm = (DefaultListModel) this.getModel();
			for (int i = 0, size = dlm.getSize(); i < size; i++) {
				toReturn.add(dlm.get(i));
			}
			return toReturn;
		}

		/*
		 * (non-Javadoc)
		 * 
		 * @see SwingSWT.TestList#setListContents(java.util.Collection)
		 */
		public void setListContents(Collection data) {
			java.util.Iterator iterator = data.iterator();
			DefaultListModel dlm = (DefaultListModel) this.getModel();
			while (iterator.hasNext()) {
				dlm.addElement(iterator.next());
			}
		}
	}

	class SWTAdaperList
		extends List{

		public SWTAdaperList(Composite c, int style) {
			super(c, style);
		}
		public void checkSubclass() {
			System.out.println(" A Blank Implementation to Allow Sub Class");
		}

		/*
		 * (non-Javadoc)
		 * 
		 * @see SwingSWT.TestList#getListContents()
		 */
		public Collection getListContents() {
			Collection toReturn = new java.util.TreeSet();
			String strArr[] = this.getItems();
			for (int i = 0; i < strArr.length; i++) {
				toReturn.add(strArr[i]);
			}
			return toReturn;
		}

		/*
		 * (non-Javadoc)
		 * 
		 * @see SwingSWT.TestList#setListContents(java.util.Collection)
		 */
		public void setListContents(Collection data) {
			java.util.Iterator iterator = data.iterator();
			while (iterator.hasNext()) {
				this.add((String) iterator.next());
			}
		}
	}

	private interface TestList {
		java.util.Collection getListContents();
		void setListContents(java.util.Collection data);
	}
}

Back to the top