Added multi selection to the ShaderNode editor.

One can now select several items by left clicking with ctrl or shit held.
One can now move all selected items at once.
One can now delete all selected items at once.
experimental
Nehon 10 years ago
parent 129faf00d7
commit 5989711f73
  1. 10
      sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/ConnectionCurve.java
  2. 8
      sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/ConnectionStraight.java
  3. 91
      sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/Diagram.java
  4. 20
      sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/DraggablePanel.java
  5. 27
      sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/NodePanel.java
  6. 4
      sdk/jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/OutBusPanel.java

@ -123,7 +123,7 @@ public class ConnectionCurve extends JPanel implements ComponentListener, MouseI
g2.setStroke(new BasicStroke(4)); g2.setStroke(new BasicStroke(4));
Path2D.Double path1 = new Path2D.Double(); Path2D.Double path1 = new Path2D.Double();
if (getDiagram().selectedItem == this) { if (getDiagram().getSelectedItems().contains(this)) {
g.setColor(SELECTED_COLOR); g.setColor(SELECTED_COLOR);
} else { } else {
g.setColor(VERY_DARK_GREY); g.setColor(VERY_DARK_GREY);
@ -162,7 +162,7 @@ public class ConnectionCurve extends JPanel implements ComponentListener, MouseI
((Graphics2D) g).draw(path1); ((Graphics2D) g).draw(path1);
g2.setStroke(new BasicStroke(2)); g2.setStroke(new BasicStroke(2));
if (getDiagram().selectedItem == this) { if (getDiagram().getSelectedItems().contains(this)) {
g.setColor(Color.WHITE); g.setColor(Color.WHITE);
} else { } else {
g.setColor(LIGHT_GREY); g.setColor(LIGHT_GREY);
@ -385,7 +385,7 @@ public class ConnectionCurve extends JPanel implements ComponentListener, MouseI
} }
if (selected) { if (selected) {
getDiagram().select(this); getDiagram().select(this, e.isShiftDown() || e.isControlDown());
e.consume(); e.consume();
} }
} }
@ -407,9 +407,7 @@ public class ConnectionCurve extends JPanel implements ComponentListener, MouseI
if (e.getKeyCode() == KeyEvent.VK_DELETE) { if (e.getKeyCode() == KeyEvent.VK_DELETE) {
Diagram diag = getDiagram(); Diagram diag = getDiagram();
if (diag.selectedItem == this) { diag.removeSelected();
diag.removeSelectedConnection();
}
} }
} }

@ -209,7 +209,7 @@ public class ConnectionStraight extends JPanel implements ComponentListener, Mou
g.drawLine(p1.x, p1.y, p2.x, p2.y); g.drawLine(p1.x, p1.y, p2.x, p2.y);
if (getDiagram().selectedItem == this) { if (getDiagram().getSelectedItems().contains(this)) {
g.setColor(Color.CYAN); g.setColor(Color.CYAN);
} else { } else {
g.setColor(Color.GRAY); g.setColor(Color.GRAY);
@ -489,7 +489,7 @@ public class ConnectionStraight extends JPanel implements ComponentListener, Mou
} }
if (selected) { if (selected) {
getDiagram().select(this); getDiagram().select(this, e.isShiftDown() || e.isControlDown());
e.consume(); e.consume();
} }
} }
@ -511,9 +511,7 @@ public class ConnectionStraight extends JPanel implements ComponentListener, Mou
if (e.getKeyCode() == KeyEvent.VK_DELETE) { if (e.getKeyCode() == KeyEvent.VK_DELETE) {
Diagram diag = getDiagram(); Diagram diag = getDiagram();
if (diag.selectedItem == this) { diag.removeSelected();
diag.removeSelectedConnection();
}
} }
} }

@ -55,7 +55,7 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
protected Dot draggedFrom; protected Dot draggedFrom;
protected Dot draggedTo; protected Dot draggedTo;
protected Selectable selectedItem; protected List<Selectable> selectedItems = new ArrayList<Selectable>();
protected List<Connection> connections = new ArrayList<Connection>(); protected List<Connection> connections = new ArrayList<Connection>();
protected List<NodePanel> nodes = new ArrayList<NodePanel>(); protected List<NodePanel> nodes = new ArrayList<NodePanel>();
protected List<OutBusPanel> outBuses = new ArrayList<OutBusPanel>(); protected List<OutBusPanel> outBuses = new ArrayList<OutBusPanel>();
@ -63,6 +63,9 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
private MatDefEditorlElement parent; private MatDefEditorlElement parent;
private String currentTechniqueName; private String currentTechniqueName;
private final BackdropPanel backDrop = new BackdropPanel(); private final BackdropPanel backDrop = new BackdropPanel();
private final Cursor defCursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
private final Cursor hndCursor = Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR);
private final Point pp = new Point();
@SuppressWarnings("LeakingThisInConstructor") @SuppressWarnings("LeakingThisInConstructor")
public Diagram() { public Diagram() {
@ -99,7 +102,7 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
} }
} }
selectedItem = null; selectedItems.clear();
repaint(); repaint();
} else if (e.getButton() == MouseEvent.BUTTON2) { } else if (e.getButton() == MouseEvent.BUTTON2) {
setCursor(hndCursor); setCursor(hndCursor);
@ -204,14 +207,11 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
public void mouseExited(MouseEvent e) { public void mouseExited(MouseEvent e) {
} }
protected void removeSelectedConnection() { protected void removeSelectedConnection(Selectable selectedItem) {
if (selectedItem instanceof Connection) {
Connection selectedConnection = (Connection) selectedItem; Connection selectedConnection = (Connection) selectedItem;
removeConnection(selectedConnection); removeConnection(selectedConnection);
selectedItem = null;
parent.notifyRemoveConnection(selectedConnection); parent.notifyRemoveConnection(selectedConnection);
} }
}
private String fixNodeName(String name) { private String fixNodeName(String name) {
return fixNodeName(name, 0); return fixNodeName(name, 0);
@ -277,10 +277,25 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
repaint(); repaint();
} }
protected void removeSelectedNode() { protected void removeSelected(){
if (selectedItem instanceof NodePanel) {
int result = JOptionPane.showConfirmDialog(null, "Delete this node and all its mappings?", "Delete Shader Node", JOptionPane.OK_CANCEL_OPTION); int result = JOptionPane.showConfirmDialog(null, "Delete all selected items, nodes and mappings?", "Delete Selected", JOptionPane.OK_CANCEL_OPTION);
if (result == JOptionPane.OK_OPTION) { if (result == JOptionPane.OK_OPTION) {
for (Selectable selectedItem : selectedItems) {
if (selectedItem instanceof NodePanel) {
removeSelectedNode(selectedItem);
}
if (selectedItem instanceof Connection) {
removeSelectedConnection(selectedItem);
}
}
selectedItems.clear();
}
}
private void removeSelectedNode(Selectable selectedItem) {
NodePanel selectedNode = (NodePanel) selectedItem; NodePanel selectedNode = (NodePanel) selectedItem;
nodes.remove(selectedNode); nodes.remove(selectedNode);
for (Iterator<Connection> it = connections.iterator(); it.hasNext();) { for (Iterator<Connection> it = connections.iterator(); it.hasNext();) {
@ -295,27 +310,26 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
selectedNode.cleanup(); selectedNode.cleanup();
remove(selectedNode); remove(selectedNode);
selectedItem = null;
repaint(); repaint();
parent.notifyRemoveNode(selectedNode); parent.notifyRemoveNode(selectedNode);
} }
}
}
private final Cursor defCursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR); public List<Selectable> getSelectedItems() {
private final Cursor hndCursor = Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR); return selectedItems;
private final Point pp = new Point(); }
@Override @Override
public void mouseDragged(MouseEvent e) { public void mouseDragged(MouseEvent e) {
if (SwingUtilities.isLeftMouseButton(e)) { if (SwingUtilities.isLeftMouseButton(e)) {
if (draggedFrom == null) { if (draggedFrom == null) {
for (Selectable selectedItem : selectedItems) {
if (selectedItem instanceof OutBusPanel) { if (selectedItem instanceof OutBusPanel) {
OutBusPanel bus = (OutBusPanel) selectedItem; OutBusPanel bus = (OutBusPanel) selectedItem;
MouseEvent me = SwingUtilities.convertMouseEvent(this, e, bus); MouseEvent me = SwingUtilities.convertMouseEvent(this, e, bus);
bus.dispatchEvent(me); bus.dispatchEvent(me);
} }
} }
}
} else if (SwingUtilities.isMiddleMouseButton(e)) { } else if (SwingUtilities.isMiddleMouseButton(e)) {
JViewport vport = (JViewport) getParent(); JViewport vport = (JViewport) getParent();
Point cp = e.getPoint(); Point cp = e.getPoint();
@ -373,8 +387,29 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
* *
* @param selectable * @param selectable
*/ */
public void select(Selectable selectable) { public void select(Selectable selectable, boolean multi) {
parent.selectionChanged(doSelect(selectable)); parent.selectionChanged(doSelect(selectable, multi));
}
public void multiMove(DraggablePanel movedPanel ,int xOffset, int yOffset){
for (Selectable selectedItem : selectedItems) {
if(selectedItem != movedPanel){
if(selectedItem instanceof DraggablePanel){
((DraggablePanel)selectedItem).movePanel(xOffset, yOffset);
}
}
}
}
public void multiStartDrag(DraggablePanel movedPanel){
for (Selectable selectedItem : selectedItems) {
if(selectedItem != movedPanel){
if(selectedItem instanceof DraggablePanel){
((DraggablePanel)selectedItem).saveLocation();
}
}
}
} }
/** /**
@ -383,12 +418,22 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
* @param selectable * @param selectable
* @return * @return
*/ */
private Selectable doSelect(Selectable selectable) { private Selectable doSelect(Selectable selectable, boolean multi) {
this.selectedItem = selectable;
if (!multi && !selectedItems.contains(selectable)) {
selectedItems.clear();
}
if (selectable != null) {
selectedItems.add(selectable);
}
if (selectable instanceof Component) { if (selectable instanceof Component) {
((Component) selectable).requestFocusInWindow(); ((Component) selectable).requestFocusInWindow();
} }
repaint(); repaint();
return selectable; return selectable;
} }
@ -403,23 +448,23 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
for (NodePanel nodePanel : nodes) { for (NodePanel nodePanel : nodes) {
if (nodePanel.getKey().equals(key)) { if (nodePanel.getKey().equals(key)) {
return doSelect(nodePanel); return doSelect(nodePanel, false);
} }
} }
for (Connection connection : connections) { for (Connection connection : connections) {
if (connection.getKey().equals(key)) { if (connection.getKey().equals(key)) {
return doSelect(connection); return doSelect(connection, false);
} }
} }
for (OutBusPanel outBusPanel : outBuses) { for (OutBusPanel outBusPanel : outBuses) {
if (outBusPanel.getKey().equals(key)) { if (outBusPanel.getKey().equals(key)) {
return doSelect(outBusPanel); return doSelect(outBusPanel, false);
} }
} }
return doSelect(null); return null;
} }
@Override @Override

@ -37,16 +37,22 @@ public class DraggablePanel extends JPanel implements MouseListener, MouseMotion
@Override @Override
public void mousePressed(MouseEvent e) { public void mousePressed(MouseEvent e) {
if (e.getButton() != MouseEvent.BUTTON2) { if (e.getButton() != MouseEvent.BUTTON2) {
svdx = getLocation().x;
if (!vertical) { if (!vertical) {
svdex = e.getXOnScreen(); svdex = e.getXOnScreen();
} }
svdy = getLocation().y;
svdey = e.getYOnScreen(); svdey = e.getYOnScreen();
saveLocation();
diagram.multiStartDrag(this);
e.consume(); e.consume();
} }
} }
protected void saveLocation() {
svdy = getLocation().y;
svdx = getLocation().x;
}
@Override @Override
public void mouseReleased(MouseEvent e) { public void mouseReleased(MouseEvent e) {
} }
@ -71,11 +77,19 @@ public class DraggablePanel extends JPanel implements MouseListener, MouseMotion
xoffset = e.getLocationOnScreen().x - svdex; xoffset = e.getLocationOnScreen().x - svdex;
} }
int yoffset = e.getLocationOnScreen().y - svdey; int yoffset = e.getLocationOnScreen().y - svdey;
setLocation(Math.max(0, svdx + xoffset), Math.max(0, svdy + yoffset)); movePanel(xoffset, yoffset);
diagram.multiMove(this, xoffset, yoffset);
e.consume(); e.consume();
} }
} }
protected void movePanel(int xoffset, int yoffset) {
if (vertical) {
xoffset = 0;
}
setLocation(Math.max(0, svdx + xoffset), Math.max(0, svdy + yoffset));
}
public Diagram getDiagram() { public Diagram getDiagram() {
return diagram; return diagram;
} }

@ -56,23 +56,6 @@ public class NodePanel extends DraggablePanel implements Selectable, PropertyCha
protected List<String> filePaths = new ArrayList<String>(); protected List<String> filePaths = new ArrayList<String>();
protected Shader.ShaderType shaderType; protected Shader.ShaderType shaderType;
// private List listeners = Collections.synchronizedList(new LinkedList());
//
// public void addPropertyChangeListener(PropertyChangeListener pcl) {
// listeners.add(pcl);
// }
//
// public void removePropertyChangeListener(PropertyChangeListener pcl) {
// listeners.remove(pcl);
// }
//
// protected void fire(String propertyName, Object old, Object nue) {
// //Passing 0 below on purpose, so you only synchronize for one atomic call:
// PropertyChangeListener[] pcls = (PropertyChangeListener[]) listeners.toArray(new PropertyChangeListener[0]);
// for (int i = 0; i < pcls.length; i++) {
// pcls[i].propertyChange(new PropertyChangeEvent(this, propertyName, old, nue));
// }
// }
public enum NodeType { public enum NodeType {
Vertex(new Color(220, 220, 70)),//yellow Vertex(new Color(220, 220, 70)),//yellow
@ -201,13 +184,13 @@ public class NodePanel extends DraggablePanel implements Selectable, PropertyCha
protected void paintComponent(Graphics g1) { protected void paintComponent(Graphics g1) {
Graphics2D g = (Graphics2D) g1; Graphics2D g = (Graphics2D) g1;
Color boderColor = Color.BLACK; Color boderColor = Color.BLACK;
if (diagram.selectedItem == this) { if (getDiagram().getSelectedItems().contains(this)) {
boderColor = Color.WHITE; boderColor = Color.WHITE;
} }
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, // Anti-alias! g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, // Anti-alias!
RenderingHints.VALUE_ANTIALIAS_ON); RenderingHints.VALUE_ANTIALIAS_ON);
// Color[] colors = {new Color(0, 0, 0, 0.7f), new Color(0, 0, 0, 0.15f)}; // Color[] colors = {new Color(0, 0, 0, 0.7f), new Color(0, 0, 0, 0.15f)};
if (diagram.selectedItem == this) { if (getDiagram().getSelectedItems().contains(this)) {
Color[] colors = new Color[]{new Color(0.6f, 0.6f, 1.0f, 0.8f), new Color(0.6f, 0.6f, 1.0f, 0.5f)}; Color[] colors = new Color[]{new Color(0.6f, 0.6f, 1.0f, 0.8f), new Color(0.6f, 0.6f, 1.0f, 0.5f)};
float[] factors = {0f, 1f}; float[] factors = {0f, 1f};
g.setPaint(new RadialGradientPaint(getWidth() / 2, getHeight() / 2, getWidth() / 2, factors, colors)); g.setPaint(new RadialGradientPaint(getWidth() / 2, getHeight() / 2, getWidth() / 2, factors, colors));
@ -261,7 +244,7 @@ public class NodePanel extends DraggablePanel implements Selectable, PropertyCha
@Override @Override
public void mousePressed(MouseEvent e) { public void mousePressed(MouseEvent e) {
super.mousePressed(e); super.mousePressed(e);
diagram.select(this); diagram.select(this, e.isShiftDown() || e.isControlDown());
showToolBar(); showToolBar();
} }
@ -442,9 +425,7 @@ public class NodePanel extends DraggablePanel implements Selectable, PropertyCha
public void delete() { public void delete() {
Diagram diag = getDiagram(); Diagram diag = getDiagram();
if (diag.selectedItem == this) { diag.removeSelected();
diag.removeSelectedNode();
}
} }
public void keyReleased(KeyEvent e) { public void keyReleased(KeyEvent e) {

@ -110,7 +110,7 @@ public class OutBusPanel extends DraggablePanel implements ComponentListener, Se
Polygon p = new Polygon(xs, ys, 8); Polygon p = new Polygon(xs, ys, 8);
if (diagram.selectedItem == this) { if (getDiagram().getSelectedItems().contains(this)) {
int[] xs2 = {0, width - 30, width - 30, width, width - 32, width - 32, 0, 0}; int[] xs2 = {0, width - 30, width - 30, width, width - 32, width - 32, 0, 0};
int[] ys2 = {10, 10, 0, getHeight() / 2 + 2, getHeight(), getHeight() - 8, getHeight() - 8, 10}; int[] ys2 = {10, 10, 0, getHeight() / 2 + 2, getHeight(), getHeight() - 8, getHeight() - 8, 10};
@ -154,7 +154,7 @@ public class OutBusPanel extends DraggablePanel implements ComponentListener, Se
return; return;
} }
super.mousePressed(e); super.mousePressed(e);
diagram.select(this); diagram.select(this, e.isShiftDown() || e.isControlDown());
} }
@Override @Override

Loading…
Cancel
Save