added a drag and drop to scroll feature to the node editor with the mouse wheel click.

experimental
Nehon 10 years ago
parent 661f4c6d2e
commit 0351f9e60f
  1. 27
      sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/BackdropPanel.java
  2. 131
      sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/Diagram.java
  3. 34
      sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/DraggablePanel.java

@ -8,12 +8,14 @@ package com.jme3.gde.materialdefinition.editor;
import com.jme3.gde.materials.MaterialPreviewRenderer; import com.jme3.gde.materials.MaterialPreviewRenderer;
import com.jme3.material.Material; import com.jme3.material.Material;
import java.awt.Container; import java.awt.Container;
import java.awt.Point;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter; import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent; import java.awt.event.ComponentEvent;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.event.MouseListener; import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import javax.swing.JScrollPane; import javax.swing.JScrollPane;
import javax.swing.JViewport; import javax.swing.JViewport;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
@ -25,7 +27,7 @@ import javax.swing.event.ChangeListener;
* *
* @author Nehon * @author Nehon
*/ */
public class BackdropPanel extends javax.swing.JPanel implements MouseListener, ChangeListener { public class BackdropPanel extends javax.swing.JPanel implements MouseListener, ChangeListener,MouseMotionListener {
private final MaterialPreviewRenderer renderer; private final MaterialPreviewRenderer renderer;
private Material mat; private Material mat;
@ -40,6 +42,7 @@ public class BackdropPanel extends javax.swing.JPanel implements MouseListener,
setLayout(null); setLayout(null);
toolBar.setVisible(false); toolBar.setVisible(false);
addMouseListener(this); addMouseListener(this);
addMouseMotionListener(this);
renderer = new MaterialPreviewRenderer(previewLabel); renderer = new MaterialPreviewRenderer(previewLabel);
recalculateTimer.setRepeats(false); recalculateTimer.setRepeats(false);
addComponentListener(new ComponentAdapter() { addComponentListener(new ComponentAdapter() {
@ -399,6 +402,10 @@ public class BackdropPanel extends javax.swing.JPanel implements MouseListener,
@Override @Override
public void mousePressed(MouseEvent e) { public void mousePressed(MouseEvent e) {
Container c = getParent();
if (c != null) {
((MouseListener) c).mousePressed(SwingUtilities.convertMouseEvent(this, e, c));
}
} }
@Override @Override
@ -448,8 +455,8 @@ public class BackdropPanel extends javax.swing.JPanel implements MouseListener,
int size = Math.min(width, height) - 25; int size = Math.min(width, height) - 25;
setSize(size, size); setSize(size, size);
setBounds(0, 0, size, size); setBounds(0, 0, size, size);
Point pos= viewPort.getViewPosition();
setLocation(pane.getHorizontalScrollBar().getValue() + width / 2 - size / 2, pane.getVerticalScrollBar().getValue() + height / 2 - size / 2); setLocation(pos.x + width / 2 - size / 2, pos.y + height / 2 - size / 2);
repaint(); repaint();
if (recalculateTimer.isRunning()) { if (recalculateTimer.isRunning()) {
@ -467,4 +474,18 @@ public class BackdropPanel extends javax.swing.JPanel implements MouseListener,
} }
} }
public void mouseDragged(MouseEvent e) {
Container c = getParent();
if (c != null) {
((MouseMotionListener) c).mouseDragged(SwingUtilities.convertMouseEvent(this, e, c));
}
}
public void mouseMoved(MouseEvent e) {
Container c = getParent();
if (c != null) {
((MouseMotionListener) c).mouseMoved(SwingUtilities.convertMouseEvent(this, e, c));
}
}
} }

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

@ -8,6 +8,7 @@ import java.awt.event.MouseEvent;
import java.awt.event.MouseListener; import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener; import java.awt.event.MouseMotionListener;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.SwingUtilities;
/** /**
* *
@ -18,8 +19,7 @@ public class DraggablePanel extends JPanel implements MouseListener, MouseMotion
protected int svdx, svdy, svdex, svdey; protected int svdx, svdy, svdex, svdey;
private boolean vertical = false; private boolean vertical = false;
protected Diagram diagram; protected Diagram diagram;
public DraggablePanel(boolean vertical) { public DraggablePanel(boolean vertical) {
this(); this();
this.vertical = vertical; this.vertical = vertical;
@ -36,15 +36,17 @@ public class DraggablePanel extends JPanel implements MouseListener, MouseMotion
@Override @Override
public void mousePressed(MouseEvent e) { public void mousePressed(MouseEvent e) {
svdx = getLocation().x; if (e.getButton() != MouseEvent.BUTTON2) {
if (!vertical) { svdx = getLocation().x;
svdex = e.getXOnScreen(); if (!vertical) {
svdex = e.getXOnScreen();
}
svdy = getLocation().y;
svdey = e.getYOnScreen();
e.consume();
} }
svdy = getLocation().y;
svdey = e.getYOnScreen();
e.consume();
} }
@Override @Override
public void mouseReleased(MouseEvent e) { public void mouseReleased(MouseEvent e) {
} }
@ -63,13 +65,15 @@ public class DraggablePanel extends JPanel implements MouseListener, MouseMotion
@Override @Override
public void mouseDragged(MouseEvent e) { public void mouseDragged(MouseEvent e) {
int xoffset = 0; if (!SwingUtilities.isMiddleMouseButton(e)) {
if (!vertical) { int xoffset = 0;
xoffset = e.getLocationOnScreen().x - svdex; if (!vertical) {
xoffset = e.getLocationOnScreen().x - svdex;
}
int yoffset = e.getLocationOnScreen().y - svdey;
setLocation(Math.max(0, svdx + xoffset), Math.max(0, svdy + yoffset));
e.consume();
} }
int yoffset = e.getLocationOnScreen().y - svdey;
setLocation(Math.max(0, svdx + xoffset), Math.max(0,svdy + yoffset));
e.consume();
} }
public Diagram getDiagram() { public Diagram getDiagram() {

Loading…
Cancel
Save