Hallo,
also ich habe 3 Klassen Main, FigureMover und SensorProperties
mein Programm erstellt 3 Rechtecke in einem Canvas welche untereinander verbunden sind und mit Hilfe der FigureMover Classe kann man diese Rechtecke per Maus innerhalb des Canvas verschieben.
ich habe in der SensorProperties Classe mittels WindowBuilder ein neues Fenster erstellt, wo man verschiedene Einstellungen tätigen kann.
Ich will jetzt per public void mouseDoubleClicked(MouseEvent e) dieses Fenster aufrufen, jedoch funktioniert das nicht und ich weiß nicht wo der Fehler liegt :-(
Fehler wird auch keiner ausgegeben....
Main:
FigureMover
also ich habe 3 Klassen Main, FigureMover und SensorProperties
mein Programm erstellt 3 Rechtecke in einem Canvas welche untereinander verbunden sind und mit Hilfe der FigureMover Classe kann man diese Rechtecke per Maus innerhalb des Canvas verschieben.
ich habe in der SensorProperties Classe mittels WindowBuilder ein neues Fenster erstellt, wo man verschiedene Einstellungen tätigen kann.
Ich will jetzt per public void mouseDoubleClicked(MouseEvent e) dieses Fenster aufrufen, jedoch funktioniert das nicht und ich weiß nicht wo der Fehler liegt :-(
Fehler wird auch keiner ausgegeben....
Main:
Code:
package com.qualityeclipse.genealogy.view;
import org.eclipse.draw2d.*;
import org.eclipse.draw2d.geometry.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Shell;
import com.qualityeclipse.genealogy.listener.FigureMover;
public class main {
public static void main(String[] args) {
Shell shell= new Shell(new Display());
shell.setSize(1024, 720);
shell.setText("DTF Parametereingabe mit Drag and Drop Funktion");
shell.setLayout(new GridLayout());
FigureCanvas canvas = createDiagram(shell);
canvas.setLayoutData(new GridData(GridData.FILL_BOTH));
Display display = shell.getDisplay();
shell.open();
while (!shell.isDisposed()) {
while (!display.readAndDispatch()) {
display.sleep();
}
}
}
//static FreeformLayer primary;
//static FreeformLayeredPane root;
static ScalableFreeformLayeredPane root;
private static FigureCanvas createDiagram(Composite parent) {
//root = new FreeformLayeredPane();
//root.setFont(parent.getFont());
root = new ScalableFreeformLayeredPane();
root.setFont(parent.getFont());
Figure root = new Figure();//root Figure und simples Layout erzeugen
root.setFont(parent.getFont()); //setze Font für root Figure, dass jedes Lable korrekt kalkuliert wird
XYLayout layout = new XYLayout();
root.setLayoutManager(layout);
FigureCanvas canvas = new FigureCanvas(parent, SWT.DOUBLE_BUFFERED);//canvas erzeugen um root Figur zu erzeugen
//canvas.setViewport(new FreeformViewport());
canvas.setBounds(10, 10, 100, 100); //groeße und position von Canvas festlegen funktioneirt nicht!
canvas.setBackground(ColorConstants.white); // Hintergrundfarbe bestimmen
canvas.setContents(root);
//LightweightSystem lws = new LightweightSystem(canvas);
//create Sensor Figure
IFigure sensor = createSensorFigure("Sensor");
root.add(sensor);
layout.setConstraint(sensor,
new Rectangle (new Point(300, 200), sensor.getPreferredSize()));
//create AKtuator Figure
IFigure aktuator = createAktuatorFigure("Aktuator");
root.add(aktuator);
layout.setConstraint(aktuator,
new Rectangle (new Point(700, 200), aktuator.getPreferredSize()));
//create Super Element
IFigure Super = createSuperFigure("Super Element");
root.add(Super,
new Rectangle(new Point (450, 50),
Super.getPreferredSize()));
//primary = new FreeformLayer();
//primary.setLayoutManager(new FreeformLayout());
root.add(connect(sensor, Super));
root.add(connect(Super, aktuator));
//root.add(primary, "Primary");
Group group = new Group(canvas, 0);
group.setBounds(5, 5, 200, 600);
//group.setBackground(ColorConstants.gray);
group.setText("Auswahl der Elemente:");
//lws.setContents(root);
return canvas;
}
private static IFigure connect(IFigure figure1, IFigure figure2) {
PolylineConnection connection = new PolylineConnection();
//PolylineConnection connection = newFigureAndConnection();
//connection.setConnectionRouter(new ManhattanConnectionRouter());
connection.setSourceAnchor(new ChopboxAnchor(figure1));
connection.setTargetAnchor(new ChopboxAnchor(figure2));
return connection;
}
private static RectangleFigure createSuperFigure(String name) {
RectangleFigure rectangleFigure = new RectangleFigure();
rectangleFigure.setBackgroundColor(ColorConstants.darkGray);
rectangleFigure.setLayoutManager(new ToolbarLayout());
rectangleFigure.setPreferredSize(150, 350);
rectangleFigure.add(new Label(name));
new FigureMover(rectangleFigure);
return rectangleFigure;
}
private static RectangleFigure createAktuatorFigure(String name) {
RectangleFigure rectangleFigure = new RectangleFigure();
rectangleFigure.setBackgroundColor(ColorConstants.lightBlue);
rectangleFigure.setLayoutManager(new ToolbarLayout());
rectangleFigure.setPreferredSize(50, 50);
rectangleFigure.add(new Label(name));
new FigureMover(rectangleFigure);
return rectangleFigure;
}
private static RectangleFigure createSensorFigure(String name) {
RectangleFigure rectangleFigure = new RectangleFigure();
rectangleFigure.setBackgroundColor(ColorConstants.lightGray);
rectangleFigure.setLayoutManager(new ToolbarLayout());
rectangleFigure.setPreferredSize(50, 50);
rectangleFigure.add(new Label(name));
new FigureMover(rectangleFigure);
return rectangleFigure;
}
}
FigureMover
Code:
package com.qualityeclipse.genealogy.listener;
import org.eclipse.draw2d.*;
import org.eclipse.draw2d.geometry.*;
import com.qualityeclipse.genealogy.Properties.*;
public class FigureMover
implements MouseListener, MouseMotionListener
{
private final IFigure figure;
public FigureMover(IFigure figure) {
this.figure = figure;
figure.addMouseListener(this);
figure.addMouseMotionListener(this);
}
private Point location;
public void mousePressed(MouseEvent event) {
location = event.getLocation();
event.consume();
}
public void mouseDragged(MouseEvent event) {
if(location == null)
return;
Point newLocation = event.getLocation();
if (newLocation == null)
return;
Dimension offset = newLocation.getDifference(location);
if (offset.width == 0 && offset.height == 0)
return;
location = newLocation;
UpdateManager updateMgr = figure.getUpdateManager();
LayoutManager layoutMgr = figure.getParent().getLayoutManager();
Rectangle bounds = figure.getBounds();
updateMgr.addDirtyRegion(figure.getParent(), bounds);
bounds = bounds.getCopy().translate(offset.width, offset.height);
layoutMgr.setConstraint(figure, bounds);
figure.translate(offset.width, offset.height);
updateMgr.addDirtyRegion(figure.getParent(), bounds);
event.consume();
}
public void mouseReleased(MouseEvent event) {
if(location == null)
return;
location = null;
event.consume();
}
@Override
public void mouseEntered(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseHover(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseMoved(MouseEvent arg0) {
// TODO Auto-generated method stub
}
public void mouseDoubleClicked(MouseEvent e) {
// System.out.println("Mouse event doubleclick");
new SensorProperties();
return;
}
}
Code:
package com.qualityeclipse.genealogy.Properties;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JLabel;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class SensorProperties extends JFrame {
private JPanel contentPane;
private final JTextField txtElement = new JTextField();
private final JTextField txtLatency = new JTextField();
private final JTextField txtJitter = new JTextField();
private final JTextField txtActivationType = new JTextField();
private final JTextField txtTimeTriggerPeriod = new JTextField();
private final JTextField txtinputbuffer = new JTextField();
private final JTextField txtActionRoutineBehaviour = new JTextField();
private final JTextField txtSelfSize = new JTextField();
private final JTextField txtActionRoutine = new JTextField();
private final JTextField txtOutputType = new JTextField();
private final JTextField txtLatencyInt = new JTextField();
private final JButton btnBestaetigen = new JButton("Best\u00E4tigen");
private final JButton btnReset = new JButton("Reset");
private final JLabel lblelement = new JLabel("#Element:");
private final JLabel lbllatency = new JLabel("#Latency:");
private final JLabel lbljitter = new JLabel("#Jitter:");
private final JLabel lblactivationtype = new JLabel("#ActivationType:");
private final JLabel lbltimetriggerperiod = new JLabel("#TimeTriggerPeriod:");
private final JLabel lblinputbuffer = new JLabel("#Input_Buffer:");
private final JLabel lblactionroutinebehaviour = new JLabel("#ActionRoutineBehaviour:");
private final JLabel lblselfsize = new JLabel("#SelfSize:");
private final JLabel lblactionroutine = new JLabel("#ActionRoutine:");
private final JLabel lbloutputtype = new JLabel("#Output_Type:");
private final JLabel lbllatencyint = new JLabel("#Latency_Int:");
private final JButton btnFertig = new JButton("Fertig");
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
SensorProperties frame = new SensorProperties();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public SensorProperties() {
txtLatencyInt.setBounds(254, 241, 100, 20);
txtLatencyInt.setColumns(10);
txtOutputType.setBounds(254, 218, 100, 20);
txtOutputType.setColumns(10);
txtActionRoutine.setBounds(254, 195, 100, 20);
txtActionRoutine.setColumns(10);
txtSelfSize.setBounds(254, 172, 100, 20);
txtSelfSize.setColumns(10);
txtActionRoutineBehaviour.setBounds(254, 149, 100, 20);
txtActionRoutineBehaviour.setColumns(10);
txtinputbuffer.setBounds(254, 126, 100, 20);
txtinputbuffer.setColumns(10);
txtTimeTriggerPeriod.setBounds(254, 103, 100, 20);
txtTimeTriggerPeriod.setColumns(10);
txtActivationType.setBounds(254, 80, 100, 20);
txtActivationType.setColumns(10);
txtJitter.setBounds(254, 57, 100, 20);
txtJitter.setColumns(10);
txtLatency.setBounds(254, 34, 100, 20);
txtLatency.setColumns(10);
txtElement.setBounds(254, 11, 100, 20);
txtElement.setColumns(10);
initGUI();
}
private void initGUI() {
setTitle("Sensor Parameters");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 380, 350);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
contentPane.add(txtElement);
contentPane.add(txtLatency);
contentPane.add(txtJitter);
contentPane.add(txtActivationType);
contentPane.add(txtTimeTriggerPeriod);
contentPane.add(txtinputbuffer);
contentPane.add(txtActionRoutineBehaviour);
contentPane.add(txtSelfSize);
contentPane.add(txtActionRoutine);
contentPane.add(txtOutputType);
contentPane.add(txtLatencyInt);
btnBestaetigen.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int Element, Latency, Jitter, ActivationType, TimeTriggerPeriod, Input_Buffer,
ActionRoutineBehaviour, SelfSize, Action_Routine, OutputType, Latency_Int;
try {
Element= Integer.parseInt(txtElement.getText());
lblelement.setText("#Element: "+Element);
} catch (Exception e2) {
JOptionPane.showMessageDialog(null, "bitte überprüfen Sie Ihre Eingabe", "Error", JOptionPane.ERROR_MESSAGE);
}
try {
Latency= Integer.parseInt(txtLatency.getText());
lbllatency.setText("#Latency: "+Latency);
} catch (Exception e2) {
JOptionPane.showMessageDialog(null, "bitte überprüfen Sie Ihre Eingabe", "Error", JOptionPane.ERROR_MESSAGE);
}
try {
Jitter= Integer.parseInt(txtJitter.getText());
lbljitter.setText("#Jitter: "+Jitter);
} catch (Exception e2) {
JOptionPane.showMessageDialog(null, "bitte überprüfen Sie Ihre Eingabe" , "Error", JOptionPane.ERROR_MESSAGE);
}
}
});
btnBestaetigen.setBounds(10, 278, 110, 23);
contentPane.add(btnBestaetigen);
btnReset.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
lblelement.setText("#Element: ");
}
});
btnReset.setBounds(128, 278, 110, 23);
contentPane.add(btnReset);
lblelement.setBounds(10, 14, 110, 14);
contentPane.add(lblelement);
lbllatency.setBounds(10, 37, 110, 14);
contentPane.add(lbllatency);
lbljitter.setBounds(10, 60, 110, 14);
contentPane.add(lbljitter);
lblactivationtype.setBounds(10, 83, 110, 14);
contentPane.add(lblactivationtype);
lbltimetriggerperiod.setBounds(10, 106, 120, 14);
contentPane.add(lbltimetriggerperiod);
lblinputbuffer.setBounds(10, 129, 143, 14);
contentPane.add(lblinputbuffer);
lblactionroutinebehaviour.setBounds(10, 152, 168, 14);
contentPane.add(lblactionroutinebehaviour);
lblselfsize.setBounds(10, 175, 120, 14);
contentPane.add(lblselfsize);
lblactionroutine.setBounds(10, 198, 153, 14);
contentPane.add(lblactionroutine);
lbloutputtype.setBounds(10, 221, 200, 14);
contentPane.add(lbloutputtype);
lbllatencyint.setBounds(10, 244, 120, 14);
contentPane.add(lbllatencyint);
btnFertig.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
setVisible(false);
}
});
btnFertig.setBounds(248, 278, 110, 23);
contentPane.add(btnFertig);
}
}