Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ FixVersionConflictPanel.fixPossibL.text=Fix possibilities:
FixVersionConflictPanel.summaryL.text=Fix Summary:

ERR_UpdateModel=Cannot update POM: {0}
DependencyGraphTopComponent.btnGraph.text=Show Graph
DependencyGraphTopComponent.btnGraph.text=Show Graph
DependencyGraphTopComponent.btnBigger.toolTipText=CTRL + +
DependencyGraphTopComponent.btnSmaller.toolTipText=CTRL + -
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
<SubComponents>
<Container class="javax.swing.JToolBar" name="jToolBar1">
<Properties>
<Property name="floatable" type="boolean" value="false"/>
<Property name="rollover" type="boolean" value="true"/>
</Properties>

Expand All @@ -74,6 +73,9 @@
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="ImageUtilities.loadImageIcon(ZOOM_IN_ICON, true)" type="code"/>
</Property>
<Property name="toolTipText" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/netbeans/modules/maven/graph/Bundle.properties" key="DependencyGraphTopComponent.btnBigger.toolTipText" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
<Property name="focusable" type="boolean" value="false"/>
<Property name="horizontalTextPosition" type="int" value="0"/>
<Property name="verticalTextPosition" type="int" value="3"/>
Expand All @@ -87,6 +89,9 @@
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="ImageUtilities.loadImageIcon(ZOOM_OUT_ICON, true)" type="code"/>
</Property>
<Property name="toolTipText" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/netbeans/modules/maven/graph/Bundle.properties" key="DependencyGraphTopComponent.btnSmaller.toolTipText" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
<Property name="focusable" type="boolean" value="false"/>
<Property name="horizontalTextPosition" type="int" value="0"/>
<Property name="verticalTextPosition" type="int" value="3"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
import java.awt.Stroke;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.IOException;
Expand All @@ -41,6 +44,7 @@
import java.util.Optional;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.AbstractAction;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListCellRenderer;
import javax.swing.Icon;
Expand All @@ -51,6 +55,7 @@
import javax.swing.JProgressBar;
import javax.swing.JScrollPane;
import javax.swing.JToolBar;
import javax.swing.KeyStroke;
import javax.swing.SpinnerNumberModel;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
Expand Down Expand Up @@ -94,7 +99,7 @@
* component showing graph of dependencies for project.
* @author Milos Kleint
*/
public class DependencyGraphTopComponent extends TopComponent implements LookupListener, MultiViewElement {
public class DependencyGraphTopComponent extends TopComponent implements LookupListener, MultiViewElement, MouseWheelListener {

private static final @StaticResource String ZOOM_IN_ICON = "org/netbeans/modules/maven/graph/zoomin.gif";
private static final @StaticResource String ZOOM_OUT_ICON = "org/netbeans/modules/maven/graph/zoomout.gif";
Expand Down Expand Up @@ -326,6 +331,93 @@ public void componentActivated() {
}
}

/**
* Adds key bindings to move the graph with the cursor-keys around.
* Zoom-in/-out with CTRL + + and CTRL + - or the mouse wheel.
*/
public void addKeyboardBindings() {

getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, KeyEvent.CTRL_DOWN_MASK), "zoomIn");
getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ADD, KeyEvent.CTRL_DOWN_MASK), "zoomIn");
getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_MINUS, KeyEvent.CTRL_DOWN_MASK), "zoomOut");
getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_SUBTRACT, KeyEvent.CTRL_DOWN_MASK), "zoomOut");

getActionMap().put("left", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
pane.getHorizontalScrollBar().setValue(pane.getHorizontalScrollBar().getValue() - 10);
}
});

getActionMap().put("right", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
pane.getHorizontalScrollBar().setValue(pane.getHorizontalScrollBar().getValue() + 10);
}
});

getActionMap().put("up", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
pane.getVerticalScrollBar().setValue(pane.getVerticalScrollBar().getValue() - 10);
}
});

getActionMap().put("down", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
pane.getVerticalScrollBar().setValue(pane.getVerticalScrollBar().getValue() + 10);
}
});

getActionMap().put("zoomIn", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
btnBiggerActionPerformed(e);
}
});

getActionMap().put("zoomOut", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
btnSmallerActionPerformed(e);
}
});

if (scene != null) {
pane.setWheelScrollingEnabled(false);
JComponent sceneView = scene.getView();
if (sceneView == null) {
sceneView = scene.createView();
}
pane.setViewportView(sceneView);
sceneView.addMouseWheelListener(this);

sceneView.setFocusable(true);
sceneView.requestFocusInWindow();

sceneView.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, KeyEvent.CTRL_DOWN_MASK), "left");
sceneView.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, KeyEvent.CTRL_DOWN_MASK), "right");
sceneView.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), "up");
sceneView.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), "down");

}
}


@Override
public void mouseWheelMoved(MouseWheelEvent evt) {

final int notches = evt.getWheelRotation();
if (notches < 0) {
// mouse wheel moved up, zoom in
btnBiggerActionPerformed(null);
} else {
// mouse wheel moved down, zoom out
btnSmallerActionPerformed(null);
}
}

@Override
public void componentClosed() {
super.componentClosed();
Expand Down Expand Up @@ -371,7 +463,6 @@ private void initComponents() {

jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

jToolBar1.setFloatable(false);
jToolBar1.setRollover(true);

org.openide.awt.Mnemonics.setLocalizedText(btnGraph, org.openide.util.NbBundle.getMessage(DependencyGraphTopComponent.class, "DependencyGraphTopComponent.btnGraph.text")); // NOI18N
Expand All @@ -386,6 +477,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
jToolBar1.add(btnGraph);

btnBigger.setIcon(ImageUtilities.loadImageIcon(ZOOM_IN_ICON, true));
btnBigger.setToolTipText(org.openide.util.NbBundle.getMessage(DependencyGraphTopComponent.class, "DependencyGraphTopComponent.btnBigger.toolTipText")); // NOI18N
btnBigger.setFocusable(false);
btnBigger.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
btnBigger.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
Expand All @@ -397,6 +489,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
jToolBar1.add(btnBigger);

btnSmaller.setIcon(ImageUtilities.loadImageIcon(ZOOM_OUT_ICON, true));
btnSmaller.setToolTipText(org.openide.util.NbBundle.getMessage(DependencyGraphTopComponent.class, "DependencyGraphTopComponent.btnSmaller.toolTipText")); // NOI18N
btnSmaller.setFocusable(false);
btnSmaller.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
btnSmaller.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
Expand Down Expand Up @@ -621,6 +714,7 @@ public Stroke getStroke(MavenDependencyNode source, MavenDependencyNode target)
sceneView = scene.createView();
// vlv: print
sceneView.putClientProperty("print.printable", true); // NOI18N
addKeyboardBindings();
}
pane.setViewportView(sceneView);
scene.setSurroundingScrollPane(pane);
Expand Down