@Override public void mouseMoved(MouseEvent e) { final ZNode node = findZNodeAt(e.getPoint()); if (node == selectedNode) { return; } if (hoveredNode != node && hoveredNode != null) { hoveredNode.setSize(hoveredNode.getSize() * 1f / 1.1f); } if (node != null && hoveredNode != node) { node.setSize(node.getSize() * 1.1f); } hoveredNode = node; hoverText = node == null ? null : node.getName(); mouseLocation = e.getPoint(); }
ZNode findZNodeAt(Point p) { ZNode found = null; synchronized (zNodes) { for (ZNode z : zNodes) { final double hs = z.getSize() * scale * 0.5; if (translateToDisplayPoint(z.getLocation()).distance(p.x, p.y) < hs) { found = z; } } } return found; }
public void showNewEditor(final ZNode z) { removeListeners(); final Editor editor = edit.getEditorFor(z, apiFactory); display.getContentPane().add(edit.getScrollPane()); edit.getPane().setMaximumSize(new Dimension(display.getWidth(), Integer.MAX_VALUE)); final KeyListener keyAdapter = new KeyListener() { @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { endEditing(); } else if (e.getKeyCode() == KeyEvent.VK_S && e.isControlDown()) { ((ZCodeEditor) editor).save(); } else if (e.getKeyCode() == KeyEvent.VK_W && e.isControlDown()) { // close just this editor. edit.remove(editor); edit.getPane().remove(editor.getEditorPanel()); display.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); if (edit.getEditors().isEmpty()) { endEditing(); } } else if (e.getKeyCode() == KeyEvent.VK_F1) { try { display.showEditorHelp(); } catch (IOException e1) { log.error(e1.getMessage()); } display.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); } } @Override public void keyReleased(KeyEvent e) {} @Override public void keyTyped(KeyEvent e) { if (e.getKeyChar() == '\n') { SwingUtilities.invokeLater( new Runnable() { @Override public void run() { try { Thread.sleep(100); // 1/10 second } catch (InterruptedException e) { } ((ZCodeEditor) editor).save(); Swutil.flashMessage(display, "Saved " + z.getName()); } }); } } }; ((ZCodeEditor) editor).addKeyListener(keyAdapter); final int size = (int) z.getSize(); editor.getEditorPanel().setSize(new Dimension(2 * size, size)); editor .getEditorPanel() .setLocation((int) z.getLocation().x - size / 2, (int) z.getLocation().y - size / 2); editor.setScale(0.25f); state = State.SELECTING; aniCount.set(10); edit.updatePaneSize(); ThreadingUtil.runAsThread( new Runnable() { @Override public void run() { // display.stop(); display.doLayout(); display.getContentPane().doLayout(); edit.getScrollPane().doLayout(); // edit.getPane().doLayout(); } }) .start(); }
@Override public void run() { if ((state == State.ANIMATING && aniCount.incrementAndGet() >= 100) || (state == State.TIME_TRAVEL && aniCount.addAndGet(1) >= 999) || (state == State.SELECTING && aniCount.addAndGet(2) >= 100)) { if (state == State.ANIMATING || state == State.TIME_TRAVEL) { state = State.NORMAL; links.clear(); } else if (state == State.SELECTING) { if (edit.getEditors().isEmpty()) { state = State.NORMAL; } else { state = State.EDITING; updateEditorSize(edit.getEditors().get(0)); edit.updatePaneSize(); } } } count.incrementAndGet(); if (count.get() >= 20) { count.set(0); } final float time = aniCount.get() / 100f; if (getState() == State.SELECTING) { Editor ed = edit.getEditors().get(0); ZNode editorNode = edit.getNode(ed); Editor previousEd = edit.getEditors().size() == 1 ? null : edit.getEditors().get(1); int y = 8; if (previousEd != null) { JPanel previousPanel = previousEd.getEditorPanel(); y += previousPanel.getY() + previousPanel.getHeight(); } ed.setScale(0.25f + 0.75f * time); final Point2D point = animator.animate( editorNode.getLocation(), new Point2D.Float(8, y), time, AnimationType.COSINE); ed.getEditorPanel().setLocation((int) point.getX(), (int) point.getY()); } else if (getState() == State.ANIMATING) synchronized (zNodes) { for (ZNode node : zNodes) { if (pointMap.containsKey(node)) { node.getLocation() .setLocation( animator.animate( node.getLocation(), pointMap.get(node), time, AnimationType.COSINE)); } if (sizeMap.containsKey(node)) { final Float size = sizeMap.get(node); final Float currentSize = node.getSize(); node.setSize( (float) animator .animate( new Point2D.Float(currentSize, 0), new Point2D.Float(size, 0), time, AnimationType.COSINE) .getX()); } } } else if (getState() == State.TIME_TRAVEL && aniCount.get() * diffsMap.getLogSize() / 1000 > (aniCount.get() - 1) * diffsMap.getLogSize() / 1000) synchronized (zNodes) { final Collection<ZNodeLink> nodeLinks = diffsMap.getNodeLinks(aniCount.get() * diffsMap.getLogSize() / 1000, zNodes); if (!nodeLinks.isEmpty()) { links.clear(); links.addAll(nodeLinks); } } else if (getState() == State.TIME_TRAVEL) { if (diffsMap.author != null) { ZNode node = diffsMap.author; float t = aniCount.get() % 100 / 100f; node.getLocation() .setLocation( animator.animate( node.getLocation(), diffsMap.authorLocation, t, AnimationType.COSINE)); } } }