Show simple classes in Visual Editor [message #616922] |
Sat, 12 January 2008 18:32 |
Marco Messages: 27 Registered: July 2009 |
Junior Member |
|
|
Hi all,
can somebody give me a hint to show following classes in VE?
I use:
Eclipse 3.2.2
Visual Editor 1.2.1
GEF 3.2.2
EMF 2.2.3
1. How can I pass a object, e.g. the owner, to the constructor of a visual
class
so that the visual editor works?
Here a simple example:
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRootPane;
public class MyVisualEditorMain extends JPanel {
private static final long serialVersionUID = 1L;
private JButton btnMyButton = null;
private TestClass lblMyLabel = null;
private JRootPane owner = null;
public MyVisualEditorMain(JRootPane owner) {
super();
this.owner = owner;
initialize();
}
private void initialize() {
GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
gridBagConstraints1.gridx = 1;
gridBagConstraints1.gridy = 0;
lblMyLabel = new TestClass(this.owner);
// lblMyLabel = new TestClass(owner);
GridBagConstraints gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
this.setSize(300, 200);
this.setLayout(new GridBagLayout());
this.add(getBtnMyButton(), gridBagConstraints);
this.add(lblMyLabel, gridBagConstraints1);
}
public class TestClass extends JLabel{
public TestClass(JRootPane owner){
super("hallo");
}
}
private JButton getBtnMyButton() {
if (btnMyButton == null) {
btnMyButton = new JButton();
btnMyButton.setText("Close");
}
return btnMyButton;
}
}
My second question:
How can I view the visual components from a extended abstract class?
Here a simple example again:
public abstract class AbstractVisualEditor extends JToolBar{
private JPanel pnlRoot = null;
private JButton btnEnd = null;
private JButton btnHelp = null;
public abstract void end();
public abstract void help();
public AbstractVisualEditor() {
super();
initialize();
}
protected final void initialize() {
this.setFloatable(false);
this.add(getPnlRoot());
}
private JPanel getPnlRoot() {
if (pnlRoot == null) {
pnlRoot = new JPanel();
pnlRoot.setLayout(new GridBagLayout());
pnlRoot.add(getBtnEnd(), new GridBagConstraints());
pnlRoot.add(getBtnHelp(), new GridBagConstraints());
}
return pnlRoot;
}
private JButton getBtnEnd() {
if (btnEnd == null) {
btnEnd = new JButton();
btnEnd.setText("End");
btnEnd.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
end();
}
});
}
return btnEnd;
}
private JButton getBtnHelp() {
if (btnHelp == null) {
btnHelp = new JButton();
btnHelp.setText("Help");
btnHelp.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
help();
}
});
}
return btnHelp;
}
}
public class MyAbstractVisualEditor extends AbstractVisualEditor{
private JButton btnNew = null;
public MyAbstractVisualEditor(){
super();
initComponents();
}
public void initComponents() {
this.add(getBtnNew());
}
@Override
public void end() {
// TODO Auto-generated method stub
}
@Override
public void help() {
// TODO Auto-generated method stub
}
private JButton getBtnNew() {
if (btnNew == null) {
btnNew = new JButton();
btnNew.setText("New");
}
return btnNew;
}
} // @jve:decl-index=0:visual-constraint="10,10"
If I want to open MyAbstractVisualEditor .java with the visual editor I
can't see
the visual components of AbstractVisualEditor. Can someone give me a hint
how
to make this components visible?
Thank you very much for every help!
Marco
|
|
|
Powered by
FUDForum. Page generated in 0.02571 seconds