|
@@ -19,10 +19,12 @@ import com.jme3.shader.UniformBinding;
|
|
|
import com.jme3.shader.VarType;
|
|
|
import java.awt.Color;
|
|
|
import java.awt.Component;
|
|
|
+import java.awt.Cursor;
|
|
|
import java.awt.Dimension;
|
|
|
import java.awt.Font;
|
|
|
import java.awt.Graphics;
|
|
|
import java.awt.Point;
|
|
|
+import java.awt.Rectangle;
|
|
|
import java.awt.event.ActionEvent;
|
|
|
import java.awt.event.ActionListener;
|
|
|
import java.awt.event.ComponentEvent;
|
|
@@ -39,6 +41,7 @@ import javax.swing.JMenuItem;
|
|
|
import javax.swing.JOptionPane;
|
|
|
import javax.swing.JPanel;
|
|
|
import javax.swing.JPopupMenu;
|
|
|
+import javax.swing.JScrollPane;
|
|
|
import javax.swing.JSeparator;
|
|
|
import javax.swing.JViewport;
|
|
|
import javax.swing.SwingUtilities;
|
|
@@ -67,7 +70,7 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
|
|
|
|
|
|
addMouseListener(this);
|
|
|
addMouseMotionListener(this);
|
|
|
- createPopupMenu();
|
|
|
+ createPopupMenu();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -77,64 +80,79 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
|
|
|
@Override
|
|
|
public void mousePressed(MouseEvent e) {
|
|
|
|
|
|
- for (OutBusPanel outBusPanel : outBuses) {
|
|
|
- Point p = SwingUtilities.convertPoint(this, e.getX(), e.getY(), outBusPanel);
|
|
|
- if (outBusPanel.contains(p)) {
|
|
|
- MouseEvent me = SwingUtilities.convertMouseEvent(this, e, outBusPanel);
|
|
|
- outBusPanel.dispatchEvent(me);
|
|
|
+ if (e.getButton() == MouseEvent.BUTTON1) {
|
|
|
+ for (OutBusPanel outBusPanel : outBuses) {
|
|
|
+ Point p = SwingUtilities.convertPoint(this, e.getX(), e.getY(), outBusPanel);
|
|
|
+ if (outBusPanel.contains(p)) {
|
|
|
+ MouseEvent me = SwingUtilities.convertMouseEvent(this, e, outBusPanel);
|
|
|
+ outBusPanel.dispatchEvent(me);
|
|
|
+ if (me.isConsumed()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (Connection connection : connections) {
|
|
|
+ MouseEvent me = SwingUtilities.convertMouseEvent(this, e, connection);
|
|
|
+ connection.select(me);
|
|
|
if (me.isConsumed()) {
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- for (Connection connection : connections) {
|
|
|
- MouseEvent me = SwingUtilities.convertMouseEvent(this, e, connection);
|
|
|
- connection.select(me);
|
|
|
- if (me.isConsumed()) {
|
|
|
- return;
|
|
|
- }
|
|
|
+ selectedItem = null;
|
|
|
+ repaint();
|
|
|
+ } else if (e.getButton() == MouseEvent.BUTTON2) {
|
|
|
+ setCursor(hndCursor);
|
|
|
+ pp.setLocation(e.getPoint());
|
|
|
+ ((JScrollPane)getParent().getParent()).setWheelScrollingEnabled(false);
|
|
|
}
|
|
|
-
|
|
|
- selectedItem = null;
|
|
|
- repaint();
|
|
|
}
|
|
|
|
|
|
public void refreshPreviews(Material mat) {
|
|
|
for (OutBusPanel outBusPanel : outBuses) {
|
|
|
- outBusPanel.updatePreview(mat);
|
|
|
+ outBusPanel.updatePreview(mat);
|
|
|
}
|
|
|
- if(backDrop.isVisible()){
|
|
|
+ if (backDrop.isVisible()) {
|
|
|
backDrop.showMaterial(mat);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- public void displayBackdrop(){
|
|
|
- if(backDrop.getParent()== null){
|
|
|
+
|
|
|
+ public void displayBackdrop() {
|
|
|
+ if (backDrop.getParent() == null) {
|
|
|
add(backDrop);
|
|
|
- ((JViewport)getParent()).addChangeListener(backDrop);
|
|
|
+ ((JViewport) getParent()).addChangeListener(backDrop);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
backDrop.setVisible(true);
|
|
|
- backDrop.update(((JViewport)getParent()));
|
|
|
+ backDrop.update(((JViewport) getParent()));
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
Point clickLoc = new Point(0, 0);
|
|
|
|
|
|
@Override
|
|
|
public void mouseReleased(MouseEvent e) {
|
|
|
- if (draggedFrom != null && draggedFrom.getNode() instanceof OutBusPanel) {
|
|
|
- MouseEvent me = SwingUtilities.convertMouseEvent(this, e, draggedFrom.getNode());
|
|
|
- draggedFrom.getNode().dispatchEvent(me);
|
|
|
- if (me.isConsumed()) {
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
- if (e.getButton() != MouseEvent.BUTTON3) {
|
|
|
- dispatchToOutBuses(e);
|
|
|
- } else {
|
|
|
- contextMenu.show(this, e.getX(), e.getY());
|
|
|
- clickLoc.setLocation(e.getX(), e.getY());
|
|
|
+
|
|
|
+ switch (e.getButton()) {
|
|
|
+ case MouseEvent.BUTTON1:
|
|
|
+ if (draggedFrom != null && draggedFrom.getNode() instanceof OutBusPanel) {
|
|
|
+ MouseEvent me = SwingUtilities.convertMouseEvent(this, e, draggedFrom.getNode());
|
|
|
+ draggedFrom.getNode().dispatchEvent(me);
|
|
|
+ if (me.isConsumed()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ dispatchToOutBuses(e);
|
|
|
+ break;
|
|
|
+ case MouseEvent.BUTTON2:
|
|
|
+ setCursor(defCursor);
|
|
|
+ ((JScrollPane)getParent().getParent()).setWheelScrollingEnabled(true);
|
|
|
+ break;
|
|
|
+ case MouseEvent.BUTTON3:
|
|
|
+ contextMenu.show(this, e.getX(), e.getY());
|
|
|
+ clickLoc.setLocation(e.getX(), e.getY());
|
|
|
+ break;
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -151,11 +169,11 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
|
|
|
}
|
|
|
repaint();
|
|
|
}
|
|
|
-
|
|
|
- protected void showEdit(NodePanel node) {
|
|
|
- parent.showShaderEditor(node.getName(),node.getType(),node.filePaths);
|
|
|
+
|
|
|
+ protected void showEdit(NodePanel node) {
|
|
|
+ parent.showShaderEditor(node.getName(), node.getType(), node.filePaths);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public void notifyMappingCreation(Connection conn) {
|
|
|
parent.makeMapping(conn);
|
|
|
}
|
|
@@ -284,14 +302,28 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private final Cursor defCursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
|
|
|
+ private final Cursor hndCursor = Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR);
|
|
|
+ private final Point pp = new Point();
|
|
|
+
|
|
|
@Override
|
|
|
public void mouseDragged(MouseEvent e) {
|
|
|
- if (draggedFrom == null) {
|
|
|
- if (selectedItem instanceof OutBusPanel) {
|
|
|
- OutBusPanel bus = (OutBusPanel) selectedItem;
|
|
|
- MouseEvent me = SwingUtilities.convertMouseEvent(this, e, bus);
|
|
|
- bus.dispatchEvent(me);
|
|
|
+ if (SwingUtilities.isLeftMouseButton(e)) {
|
|
|
+ if (draggedFrom == null) {
|
|
|
+ if (selectedItem instanceof OutBusPanel) {
|
|
|
+ OutBusPanel bus = (OutBusPanel) selectedItem;
|
|
|
+ MouseEvent me = SwingUtilities.convertMouseEvent(this, e, bus);
|
|
|
+ bus.dispatchEvent(me);
|
|
|
+ }
|
|
|
}
|
|
|
+ } else if (SwingUtilities.isMiddleMouseButton(e)) {
|
|
|
+ JViewport vport = (JViewport) getParent();
|
|
|
+ Point cp = e.getPoint();
|
|
|
+ Point vp = vport.getViewPosition();
|
|
|
+ vp.translate(pp.x - cp.x, pp.y - cp.y);
|
|
|
+ scrollRectToVisible(new Rectangle(vp, vport.getSize()));
|
|
|
+ //pp.setLocation(cp);
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -313,7 +345,6 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
|
|
|
start.connect(conn);
|
|
|
end.connect(conn);
|
|
|
|
|
|
-
|
|
|
addConnection(conn);
|
|
|
|
|
|
return conn;
|
|
@@ -401,14 +432,13 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
|
|
|
return item;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- public void clear(){
|
|
|
+ public void clear() {
|
|
|
removeAll();
|
|
|
outBuses.clear();
|
|
|
connections.clear();
|
|
|
nodes.clear();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private void createPopupMenu() {
|
|
|
contextMenu.setFont(new Font("Tahoma", 1, 10)); // NOI18N
|
|
|
contextMenu.setOpaque(true);
|
|
@@ -421,7 +451,6 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
|
|
|
contextMenu.setBorder(BorderFactory.createCompoundBorder(contextMenu.getBorder(),
|
|
|
labelBorder));
|
|
|
|
|
|
-
|
|
|
JMenuItem nodeItem = createMenuItem("Node", Icons.node);
|
|
|
nodeItem.addActionListener(new ActionListener() {
|
|
|
@Override
|