# HG changeset patch # User Thomas Wuerthinger # Date 1328031538 -3600 # Node ID 3bbc6d6d7465d9aa2cca1419ac552022fb71f474 # Parent aae5b3773e6384a28fc3e0b929d7bbae83089b84 New range slider version. diff -r aae5b3773e63 -r 3bbc6d6d7465 src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/FolderNode.java --- a/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/FolderNode.java Tue Jan 31 00:23:10 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Coordinator/src/com/sun/hotspot/igv/coordinator/FolderNode.java Tue Jan 31 18:38:58 2012 +0100 @@ -23,14 +23,21 @@ */ package com.sun.hotspot.igv.coordinator; +import com.sun.hotspot.igv.coordinator.actions.DiffGraphAction; import com.sun.hotspot.igv.coordinator.actions.RemoveCookie; import com.sun.hotspot.igv.data.*; +import com.sun.hotspot.igv.data.services.GraphViewer; import java.awt.Image; +import java.util.ArrayList; import java.util.List; +import javax.swing.Action; +import org.openide.actions.OpenAction; +import org.openide.cookies.OpenCookie; import org.openide.nodes.AbstractNode; import org.openide.nodes.Children; import org.openide.nodes.Node; import org.openide.util.ImageUtilities; +import org.openide.util.Lookup; import org.openide.util.lookup.AbstractLookup; import org.openide.util.lookup.InstanceContent; @@ -38,12 +45,16 @@ * * @author Thomas Wuerthinger */ -public class FolderNode extends AbstractNode { +public class FolderNode extends AbstractNode implements ChangedListener { - private InstanceContent content; - private FolderChildren children; + @Override + public void changed(Object folder) { + if (this.getChildren() == Children.LEAF) { + setChildren(createFolderChildren((Folder)folder)); + } + } - private static class FolderChildren extends Children.Keys implements ChangedListener { + private static class FolderChildren extends Children.Keys implements ChangedListener { private final Folder folder; @@ -53,25 +64,25 @@ } @Override - protected Node[] createNodes(FolderElement e) { - if (e instanceof InputGraph) { - return new Node[]{new GraphNode((InputGraph) e)}; - } else if (e instanceof Folder) { - return new Node[]{new FolderNode((Folder) e)}; - } else { - return null; - } + protected Node[] createNodes(Folder e) { + return new Node[]{new FolderNode(e)}; } @Override public void addNotify() { - this.setKeys(folder.getElements()); + List result = new ArrayList<>(); + for (FolderElement o : folder.getElements()) { + if (o instanceof Folder) { + result.add((Folder) o); + } + } + this.setKeys(result); } - + @Override public void changed(Object source) { addNotify(); - } + } } @Override @@ -80,35 +91,55 @@ } protected FolderNode(Folder folder) { - this(folder, new FolderChildren(folder), new InstanceContent()); + this(folder, createFolderChildren(folder), new InstanceContent()); } - private FolderNode(final Folder folder, FolderChildren children, InstanceContent content) { + private static Children createFolderChildren(Folder folder) { + for (FolderElement elem : folder.getElements()) { + if (elem instanceof Folder) { + return new FolderChildren(folder); + } + } + return Children.LEAF; + } + + private FolderNode(final Folder folder, Children children, InstanceContent content) { super(children, new AbstractLookup(content)); - this.content = content; - this.children = children; if (folder instanceof FolderElement) { final FolderElement folderElement = (FolderElement) folder; this.setDisplayName(folderElement.getName()); content.add(new RemoveCookie() { + @Override public void remove() { folderElement.getParent().removeElement(folderElement); } }); } + + if (folder instanceof Group) { + content.add(new OpenCookie() { + @Override + public void open() { + Lookup.getDefault().lookup(GraphViewer.class).view(((Group) folder).getGraphs().get(0)); + } + }); + } + folder.getChangedEvent().addListener(this); } - public void init(String name, List groups) { - this.setDisplayName(name); - children.addNotify(); - for (Group g : groups) { - content.add(g); - } + @Override + public Action[] getActions(boolean b) { + return new Action[]{(Action) OpenAction.findObject(OpenAction.class, true)}; } @Override + public Action getPreferredAction() { + return (Action) OpenAction.findObject(OpenAction.class, true); + } + + @Override public Image getOpenedIcon(int i) { return getIcon(i); } diff -r aae5b3773e63 -r 3bbc6d6d7465 src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/RangeSlider.java --- a/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/RangeSlider.java Tue Jan 31 00:23:10 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/Util/src/com/sun/hotspot/igv/util/RangeSlider.java Tue Jan 31 18:38:58 2012 +0100 @@ -38,34 +38,21 @@ */ public class RangeSlider extends JComponent implements ChangedListener, MouseListener, MouseMotionListener { - public static final int HEIGHT = 40; - public static final int BAR_HEIGHT = 22; - public static final int BAR_SELECTION_ENDING_HEIGHT = 16; - public static final int BAR_SELECTION_HEIGHT = 10; public static final int BAR_THICKNESS = 2; public static final int BAR_CIRCLE_SIZE = 9; public static final int MOUSE_ENDING_OFFSET = 3; public static final Color BACKGROUND_COLOR = Color.white; public static final Color BAR_COLOR = Color.black; public static final Color BAR_SELECTION_COLOR = new Color(255, 0, 0, 120); - public static final Color BAR_SELECTION_COLOR_ROLLOVER = new Color(255, 0, 255, 120); - public static final Color BAR_SELECTION_COLOR_DRAG = new Color(0, 0, 255, 120); + public static final Color TEXT_SELECTION_COLOR = new Color(200, 200, 200, 255); + public static final int ITEM_HEIGHT = 30; + public static final int ITEM_WIDTH = 30; private RangeSliderModel model; - private State state; private Point startPoint; private RangeSliderModel tempModel; - private boolean isOverBar; - - private enum State { - - Initial, - DragBar, - DragFirstPosition, - DragSecondPosition - } + private Point lastMouseMove; public RangeSlider() { - state = State.Initial; this.addMouseMotionListener(this); this.addMouseListener(this); } @@ -93,7 +80,21 @@ @Override public Dimension getPreferredSize() { Dimension d = super.getPreferredSize(); - d.height = HEIGHT; + Graphics g = this.getGraphics(); + + int maxWidth = 0; + List list = getPaintingModel().getPositions(); + for (int i = 0; i < list.size(); i++) { + + String curS = list.get(i); + if (curS != null && curS.length() > 0) { + FontMetrics metrics = g.getFontMetrics(); + Rectangle bounds = metrics.getStringBounds(curS, g).getBounds(); + maxWidth = Math.max(maxWidth, (int) bounds.getWidth()); + } + } + d.width = maxWidth + ITEM_WIDTH; + d.height = ITEM_HEIGHT * list.size(); return d; } @@ -106,23 +107,13 @@ this.repaint(); } - private int getXPosition(int index) { - assert index >= 0 && index < getPaintingModel().getPositions().size(); - return getXOffset() * (index + 1); - } - - private int getXOffset() { - int size = getPaintingModel().getPositions().size(); - int width = getWidth(); - return (width / (size + 1)); - } - - private int getEndXPosition(int index) { - return getXPosition(index) + getXOffset() / 2; - } - - private int getStartXPosition(int index) { - return getXPosition(index) - getXOffset() / 2; + private Rectangle getItemBounds(int index) { + Rectangle r = new Rectangle(); + r.width = ITEM_WIDTH; + r.height = ITEM_HEIGHT; + r.x = 0; + r.y = ITEM_HEIGHT * index; + return r; } @Override @@ -138,214 +129,113 @@ g2.fillRect(0, 0, width, height); // Nothing to paint? - if (getPaintingModel() == null || getPaintingModel().getPositions().size() == 0) { + if (getPaintingModel() == null || getPaintingModel().getPositions().isEmpty()) { return; } - int firstPos = getPaintingModel().getFirstPosition(); - int secondPos = getPaintingModel().getSecondPosition(); - - paintSelected(g2, firstPos, secondPos); + paintSelected(g2); paintBar(g2); } - private int getBarStartY() { - return getHeight() - BAR_HEIGHT; + private void fillRect(Graphics2D g, int startX, int startY, int endY, int thickness) { + g.fillRect(startX - thickness / 2, startY, thickness, endY - startY); } private void paintBar(Graphics2D g) { List list = getPaintingModel().getPositions(); - int barStartY = getBarStartY(); g.setColor(BAR_COLOR); - g.fillRect(getXPosition(0), barStartY + BAR_HEIGHT / 2 - BAR_THICKNESS / 2, getXPosition(list.size() - 1) - getXPosition(0), BAR_THICKNESS); + Rectangle firstItemBounds = getItemBounds(0); + Rectangle lastItemBounds = getItemBounds(list.size() - 1); + fillRect(g, (int) firstItemBounds.getCenterX(), (int) firstItemBounds.getCenterY(), (int) lastItemBounds.getCenterY(), BAR_THICKNESS); - int circleCenterY = barStartY + BAR_HEIGHT / 2; for (int i = 0; i < list.size(); i++) { - int curX = getXPosition(i); + Rectangle curItemBounds = getItemBounds(i); g.setColor(getPaintingModel().getColors().get(i)); - g.fillOval(curX - BAR_CIRCLE_SIZE / 2, circleCenterY - BAR_CIRCLE_SIZE / 2, BAR_CIRCLE_SIZE, BAR_CIRCLE_SIZE); + g.fillOval((int) curItemBounds.getCenterX() - BAR_CIRCLE_SIZE / 2, (int) curItemBounds.getCenterY() - BAR_CIRCLE_SIZE / 2, BAR_CIRCLE_SIZE, BAR_CIRCLE_SIZE); g.setColor(Color.black); - g.drawOval(curX - BAR_CIRCLE_SIZE / 2, circleCenterY - BAR_CIRCLE_SIZE / 2, BAR_CIRCLE_SIZE, BAR_CIRCLE_SIZE); - + g.drawOval((int) curItemBounds.getCenterX() - BAR_CIRCLE_SIZE / 2, (int) curItemBounds.getCenterY() - BAR_CIRCLE_SIZE / 2, BAR_CIRCLE_SIZE, BAR_CIRCLE_SIZE); String curS = list.get(i); if (curS != null && curS.length() > 0) { - int startX = getStartXPosition(i); - int endX = getEndXPosition(i); FontMetrics metrics = g.getFontMetrics(); Rectangle bounds = metrics.getStringBounds(curS, g).getBounds(); - if (bounds.width < endX - startX && bounds.height < barStartY) { - g.setColor(Color.black); - g.drawString(curS, startX + (endX - startX) / 2 - bounds.width / 2, barStartY / 2 + bounds.height / 2); - } + g.setColor(Color.black); + g.drawString(curS, curItemBounds.x + curItemBounds.width, (int) curItemBounds.getCenterY() + bounds.height / 2 - 2); } } } - private void paintSelected(Graphics2D g, int start, int end) { - - int startX = getStartXPosition(start); - int endX = getEndXPosition(end); - int barStartY = getBarStartY(); - int barSelectionEndingStartY = barStartY + BAR_HEIGHT / 2 - BAR_SELECTION_ENDING_HEIGHT / 2; - paintSelectedEnding(g, startX, barSelectionEndingStartY); - paintSelectedEnding(g, endX, barSelectionEndingStartY); + private void paintSelected(Graphics2D g) { + List list = getPaintingModel().getPositions(); + for (int i = 0; i < list.size(); i++) { + Rectangle curItemBounds = getItemBounds(i); + if (lastMouseMove != null && curItemBounds.y <= lastMouseMove.y && curItemBounds.y + curItemBounds.height >= lastMouseMove.y) { + g.setColor(TEXT_SELECTION_COLOR); + g.fillRect(0, curItemBounds.y, getWidth(), curItemBounds.height); + } + } + final Rectangle barBounds = getBarBounds(); g.setColor(BAR_SELECTION_COLOR); - if (state == State.DragBar) { - g.setColor(BAR_SELECTION_COLOR_DRAG); - } else if (isOverBar) { - g.setColor(BAR_SELECTION_COLOR_ROLLOVER); - } - g.fillRect(startX, barStartY + BAR_HEIGHT / 2 - BAR_SELECTION_HEIGHT / 2, endX - startX, BAR_SELECTION_HEIGHT); - } - - private void paintSelectedEnding(Graphics g, int x, int y) { - g.setColor(BAR_COLOR); - g.fillRect(x - BAR_THICKNESS / 2, y, BAR_THICKNESS, BAR_SELECTION_ENDING_HEIGHT); + g.fill(barBounds); } - private boolean isOverSecondPosition(Point p) { - if (p.y >= getBarStartY()) { - int destX = getEndXPosition(getPaintingModel().getSecondPosition()); - int off = Math.abs(destX - p.x); - return off <= MOUSE_ENDING_OFFSET; - } - return false; - } - - private boolean isOverFirstPosition(Point p) { - if (p.y >= getBarStartY()) { - int destX = getStartXPosition(getPaintingModel().getFirstPosition()); - int off = Math.abs(destX - p.x); - return off <= MOUSE_ENDING_OFFSET; - } - return false; - } - - private boolean isOverSelection(Point p) { - if (p.y >= getBarStartY() && !isOverFirstPosition(p) && !isOverSecondPosition(p)) { - return p.x > getStartXPosition(getPaintingModel().getFirstPosition()) && p.x < getEndXPosition(getPaintingModel().getSecondPosition()); - } - return false; + private Rectangle getBarBounds() { + final Rectangle startItemBounds = getItemBounds(getPaintingModel().getFirstPosition()); + final Rectangle endItemBounds = getItemBounds(getPaintingModel().getSecondPosition()); + int startY = startItemBounds.y; + int endY = endItemBounds.y + endItemBounds.height; + return new Rectangle(0, startY, getWidth(), endY - startY); } @Override public void mouseDragged(MouseEvent e) { - if (state == State.DragBar) { - int firstX = this.getStartXPosition(model.getFirstPosition()); - int newFirstX = firstX + e.getPoint().x - startPoint.x; - int newIndex = getIndexFromPosition(newFirstX) + 1; - if (newIndex + model.getSecondPosition() - model.getFirstPosition() >= model.getPositions().size()) { - newIndex = model.getPositions().size() - (model.getSecondPosition() - model.getFirstPosition()) - 1; - } - int secondPosition = newIndex + model.getSecondPosition() - model.getFirstPosition(); - tempModel.setPositions(newIndex, secondPosition); - update(); - } else if (state == State.DragFirstPosition) { - int firstPosition = getIndexFromPosition(e.getPoint().x) + 1; - int secondPosition = model.getSecondPosition(); - if (firstPosition > secondPosition) { - firstPosition--; - } - tempModel.setPositions(firstPosition, secondPosition); - update(); - } else if (state == State.DragSecondPosition) { - int firstPosition = model.getFirstPosition(); - int secondPosition = getIndexFromPosition(e.getPoint().x); - if (secondPosition < firstPosition) { - secondPosition++; - } - tempModel.setPositions(firstPosition, secondPosition); - update(); + if (startPoint != null) { + int startIndex = getIndexFromPosition(startPoint.y); + int curIndex = getIndexFromPosition(e.getPoint().y); + tempModel.setPositions(startIndex, curIndex); } } - private int getIndexFromPosition(int x) { - if (x < getXPosition(0)) { - return -1; - } + private int getIndexFromPosition(int y) { for (int i = 0; i < getPaintingModel().getPositions().size() - 1; i++) { - int startX = getXPosition(i); - int endX = getXPosition(i + 1); - if (x >= startX && x <= endX) { + Rectangle bounds = getItemBounds(i); + if (bounds.y <= y && bounds.y + bounds.height >= y) { return i; } } return getPaintingModel().getPositions().size() - 1; } - private int getCircleIndexFromPosition(int x) { - int result = 0; - for (int i = 1; i < getPaintingModel().getPositions().size() - 1; i++) { - if (x > getStartXPosition(i)) { - result = i; - } - } - return result; - } - @Override public void mouseMoved(MouseEvent e) { - isOverBar = false; - if (model == null) { - return; - } - - - Point p = e.getPoint(); - if (isOverFirstPosition(p) || isOverSecondPosition(p)) { - setCursor(Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR)); - } else if (isOverSelection(p)) { - isOverBar = true; - setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); - } else { - this.setCursor(Cursor.getDefaultCursor()); - } - repaint(); + lastMouseMove = e.getPoint(); + update(); } @Override public void mouseClicked(MouseEvent e) { - if (e.getClickCount() > 1) { - // Double click - int index = getCircleIndexFromPosition(e.getPoint().x); - model.setPositions(index, index); - } + int index = getIndexFromPosition(e.getPoint().y); + model.setPositions(index, index); } @Override public void mousePressed(MouseEvent e) { - if (model == null) { - return; - } - - Point p = e.getPoint(); - if (isOverFirstPosition(p)) { - state = State.DragFirstPosition; - } else if (isOverSecondPosition(p)) { - state = State.DragSecondPosition; - } else if (isOverSelection(p)) { - state = State.DragBar; - } else { - return; - } - + int index = getIndexFromPosition(e.getPoint().y); startPoint = e.getPoint(); tempModel = model.copy(); + tempModel.getChangedEvent().addListener(this); + tempModel.setPositions(index, index); } @Override public void mouseReleased(MouseEvent e) { - if (model == null || tempModel == null) { - return; - } - state = State.Initial; model.setPositions(tempModel.getFirstPosition(), tempModel.getSecondPosition()); tempModel = null; + startPoint = null; } @Override @@ -354,7 +244,7 @@ @Override public void mouseExited(MouseEvent e) { - isOverBar = false; + lastMouseMove = null; repaint(); } } diff -r aae5b3773e63 -r 3bbc6d6d7465 src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/EditorTopComponent.java --- a/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/EditorTopComponent.java Tue Jan 31 00:23:10 2012 +0100 +++ b/src/share/tools/IdealGraphVisualizer/View/src/com/sun/hotspot/igv/view/EditorTopComponent.java Tue Jan 31 18:38:58 2012 +0100 @@ -187,15 +187,12 @@ Toolbar toolBar = new Toolbar(); Border b = (Border) UIManager.get("Nb.Editor.Toolbar.border"); //NOI18N toolBar.setBorder(b); - JPanel container = new JPanel(); - this.add(container, BorderLayout.NORTH); - container.setLayout(new BorderLayout()); - container.add(BorderLayout.NORTH, toolBar); + this.add(BorderLayout.NORTH, toolBar); rangeSliderModel = new DiagramViewModel(diagram.getGraph().getGroup(), filterChain, sequence); rangeSlider = new RangeSlider(); rangeSlider.setModel(rangeSliderModel); - container.add(BorderLayout.CENTER, rangeSlider); + // this.add(BorderLayout.WEST, rangeSlider); scene = new DiagramScene(actions, rangeSliderModel); content = new InstanceContent(); @@ -258,7 +255,13 @@ toolBar.add(quicksearch); centerPanel = new JPanel(); - this.add(centerPanel, BorderLayout.CENTER); + + JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, + new JScrollPane(rangeSlider), centerPanel); + splitPane.setOneTouchExpandable(true); + splitPane.setDividerLocation(250); + this.add(splitPane, BorderLayout.CENTER); + cardLayout = new CardLayout(); centerPanel.setLayout(cardLayout); centerPanel.add(SCENE_STRING, scene.getComponent());