Merge branch 'master' into PBRisComing

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

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

@ -55,7 +55,7 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
protected Dot draggedFrom;
protected Dot draggedTo;
protected Selectable selectedItem;
protected List<Selectable> selectedItems = new ArrayList<Selectable>();
protected List<Connection> connections = new ArrayList<Connection>();
protected List<NodePanel> nodes = new ArrayList<NodePanel>();
protected List<OutBusPanel> outBuses = new ArrayList<OutBusPanel>();
@ -63,6 +63,9 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
private MatDefEditorlElement parent;
private String currentTechniqueName;
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")
public Diagram() {
@ -99,7 +102,7 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
}
}
selectedItem = null;
selectedItems.clear();
repaint();
} else if (e.getButton() == MouseEvent.BUTTON2) {
setCursor(hndCursor);
@ -204,13 +207,10 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
public void mouseExited(MouseEvent e) {
}
protected void removeSelectedConnection() {
if (selectedItem instanceof Connection) {
Connection selectedConnection = (Connection) selectedItem;
removeConnection(selectedConnection);
selectedItem = null;
parent.notifyRemoveConnection(selectedConnection);
}
protected void removeSelectedConnection(Selectable selectedItem) {
Connection selectedConnection = (Connection) selectedItem;
removeConnection(selectedConnection);
parent.notifyRemoveConnection(selectedConnection);
}
private String fixNodeName(String name) {
@ -277,43 +277,57 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
repaint();
}
protected void removeSelectedNode() {
if (selectedItem instanceof NodePanel) {
int result = JOptionPane.showConfirmDialog(null, "Delete this node and all its mappings?", "Delete Shader Node", JOptionPane.OK_CANCEL_OPTION);
if (result == JOptionPane.OK_OPTION) {
NodePanel selectedNode = (NodePanel) selectedItem;
nodes.remove(selectedNode);
for (Iterator<Connection> it = connections.iterator(); it.hasNext();) {
Connection conn = it.next();
if (conn.start.getNode() == selectedNode || conn.end.getNode() == selectedNode) {
it.remove();
conn.end.disconnect();
conn.start.disconnect();
remove(conn);
}
protected void removeSelected(){
int result = JOptionPane.showConfirmDialog(null, "Delete all selected items, nodes and mappings?", "Delete Selected", JOptionPane.OK_CANCEL_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) {
selectedNode.cleanup();
remove(selectedNode);
selectedItem = null;
repaint();
parent.notifyRemoveNode(selectedNode);
NodePanel selectedNode = (NodePanel) selectedItem;
nodes.remove(selectedNode);
for (Iterator<Connection> it = connections.iterator(); it.hasNext();) {
Connection conn = it.next();
if (conn.start.getNode() == selectedNode || conn.end.getNode() == selectedNode) {
it.remove();
conn.end.disconnect();
conn.start.disconnect();
remove(conn);
}
}
selectedNode.cleanup();
remove(selectedNode);
repaint();
parent.notifyRemoveNode(selectedNode);
}
private final Cursor defCursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
private final Cursor hndCursor = Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR);
private final Point pp = new Point();
public List<Selectable> getSelectedItems() {
return selectedItems;
}
@Override
public void mouseDragged(MouseEvent e) {
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);
for (Selectable selectedItem : selectedItems) {
if (selectedItem instanceof OutBusPanel) {
OutBusPanel bus = (OutBusPanel) selectedItem;
MouseEvent me = SwingUtilities.convertMouseEvent(this, e, bus);
bus.dispatchEvent(me);
}
}
}
} else if (SwingUtilities.isMiddleMouseButton(e)) {
@ -373,8 +387,29 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
*
* @param selectable
*/
public void select(Selectable selectable) {
parent.selectionChanged(doSelect(selectable));
public void select(Selectable selectable, boolean multi) {
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
* @return
*/
private Selectable doSelect(Selectable selectable) {
this.selectedItem = selectable;
private Selectable doSelect(Selectable selectable, boolean multi) {
if (!multi && !selectedItems.contains(selectable)) {
selectedItems.clear();
}
if (selectable != null) {
selectedItems.add(selectable);
}
if (selectable instanceof Component) {
((Component) selectable).requestFocusInWindow();
}
repaint();
return selectable;
}
@ -403,23 +448,23 @@ public class Diagram extends JPanel implements MouseListener, MouseMotionListene
for (NodePanel nodePanel : nodes) {
if (nodePanel.getKey().equals(key)) {
return doSelect(nodePanel);
return doSelect(nodePanel, false);
}
}
for (Connection connection : connections) {
if (connection.getKey().equals(key)) {
return doSelect(connection);
return doSelect(connection, false);
}
}
for (OutBusPanel outBusPanel : outBuses) {
if (outBusPanel.getKey().equals(key)) {
return doSelect(outBusPanel);
return doSelect(outBusPanel, false);
}
}
return doSelect(null);
return null;
}
@Override

@ -37,16 +37,22 @@ public class DraggablePanel extends JPanel implements MouseListener, MouseMotion
@Override
public void mousePressed(MouseEvent e) {
if (e.getButton() != MouseEvent.BUTTON2) {
svdx = getLocation().x;
if (!vertical) {
svdex = e.getXOnScreen();
}
svdy = getLocation().y;
svdey = e.getYOnScreen();
saveLocation();
diagram.multiStartDrag(this);
e.consume();
}
}
protected void saveLocation() {
svdy = getLocation().y;
svdx = getLocation().x;
}
@Override
public void mouseReleased(MouseEvent e) {
}
@ -71,11 +77,19 @@ public class DraggablePanel extends JPanel implements MouseListener, MouseMotion
xoffset = e.getLocationOnScreen().x - svdex;
}
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();
}
}
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() {
return diagram;
}

@ -56,23 +56,6 @@ public class NodePanel extends DraggablePanel implements Selectable, PropertyCha
protected List<String> filePaths = new ArrayList<String>();
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 {
Vertex(new Color(220, 220, 70)),//yellow
@ -201,13 +184,13 @@ public class NodePanel extends DraggablePanel implements Selectable, PropertyCha
protected void paintComponent(Graphics g1) {
Graphics2D g = (Graphics2D) g1;
Color boderColor = Color.BLACK;
if (diagram.selectedItem == this) {
if (getDiagram().getSelectedItems().contains(this)) {
boderColor = Color.WHITE;
}
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, // Anti-alias!
RenderingHints.VALUE_ANTIALIAS_ON);
// 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)};
float[] factors = {0f, 1f};
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
public void mousePressed(MouseEvent e) {
super.mousePressed(e);
diagram.select(this);
diagram.select(this, e.isShiftDown() || e.isControlDown());
showToolBar();
}
@ -442,9 +425,7 @@ public class NodePanel extends DraggablePanel implements Selectable, PropertyCha
public void delete() {
Diagram diag = getDiagram();
if (diag.selectedItem == this) {
diag.removeSelectedNode();
}
diag.removeSelected();
}
public void keyReleased(KeyEvent e) {

@ -110,7 +110,7 @@ public class OutBusPanel extends DraggablePanel implements ComponentListener, Se
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[] 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;
}
super.mousePressed(e);
diagram.select(this);
diagram.select(this, e.isShiftDown() || e.isControlDown());
}
@Override

Loading…
Cancel
Save