use of java.awt.event.MouseAdapter in project android by JetBrains.
the class NodeHyperlinkSupport method addHyperlinkBehaviorToSupportedNodes.
private void addHyperlinkBehaviorToSupportedNodes() {
myTree.setCellRenderer(new NodeRenderer() {
@NotNull
@Override
protected SimpleTextAttributes getSimpleTextAttributes(@NotNull PresentationData presentation, Color color, @NotNull Object node) {
List<PsIssue> issues = Collections.emptyList();
if (myShowIssues && node instanceof AbstractPsModelNode) {
AbstractPsModelNode<? extends PsModel> modelNode = (AbstractPsModelNode<? extends PsModel>) node;
issues = findIssues(modelNode, IssuesByTypeAndTextComparator.INSTANCE);
presentation.setTooltip(getTooltipText(issues, false));
}
if (myHoveredNode != null && myHoveredNode == node) {
return LINK_ATTRIBUTES;
}
SimpleTextAttributes textAttributes = super.getSimpleTextAttributes(presentation, color, node);
if (!issues.isEmpty()) {
PsIssue issue = issues.get(0);
Color waveColor = issue.getSeverity().getColor();
textAttributes = textAttributes.derive(STYLE_WAVED, null, null, waveColor);
}
return textAttributes;
}
@Override
public void customizeCellRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
if (myShowIssues) {
AbstractPsModelNode<? extends PsModel> modelNode = findModelNode(value);
if (modelNode != null) {
List<PsIssue> issues = findIssues(modelNode, null);
if (!issues.isEmpty()) {
// Force color change of the node.
modelNode.getPresentation().clearText();
}
}
}
super.customizeCellRenderer(tree, value, selected, expanded, leaf, row, hasFocus);
Object userObject = ((DefaultMutableTreeNode) value).getUserObject();
if (userObject instanceof CellAppearanceEx) {
((CellAppearanceEx) userObject).customize(this);
}
}
@Nullable
private AbstractPsModelNode<? extends PsModel> findModelNode(@Nullable Object value) {
if (value instanceof DefaultMutableTreeNode) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
Object userObject = node.getUserObject();
if (userObject instanceof AbstractPsModelNode) {
return (AbstractPsModelNode<? extends PsModel>) userObject;
}
}
return null;
}
});
MouseAdapter mouseListener = new MouseAdapter() {
@Override
public void mouseMoved(MouseEvent e) {
Cursor cursor = getDefaultCursor();
T node = getIfHyperlink(e);
if (node != null) {
cursor = getPredefinedCursor(HAND_CURSOR);
}
setHoveredNode(node);
myTree.setCursor(cursor);
}
};
myTree.addMouseMotionListener(mouseListener);
// Make the cursor change to 'hand' if the mouse pointer is over a supported node and the user presses Ctrl or Cmd.
myKeyEventDispatcher = e -> {
T node = null;
if (e.getID() == KEY_PRESSED) {
Cursor cursor = getDefaultCursor();
if (isMetaOrCtrlKeyPressed(e)) {
node = getNodeUnderMousePointer();
if (node != null) {
cursor = getPredefinedCursor(HAND_CURSOR);
}
}
setHoveredNode(node);
myTree.setCursor(cursor);
} else if (e.getID() == KEY_RELEASED) {
if (isMetaOrCtrlKeyPressed(e)) {
setHoveredNode(null);
}
myTree.setCursor(getDefaultCursor());
}
return false;
};
KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(myKeyEventDispatcher);
}
use of java.awt.event.MouseAdapter in project android by JetBrains.
the class ColorPanel method initColorFrame.
private void initColorFrame(Color color) {
myColorFrame.setBackground(color);
myColorFrame.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
super.mouseClicked(e);
ColorPicker.showDialog(myContentPane, "Edit color", color, true, new ColorPickerListener[] { new ColorPickerListener() {
@Override
public void colorChanged(Color color) {
}
@Override
public void closed(@Nullable Color color) {
if (color != null) {
myColorName.setText(getColorHexString(color.getRGB()));
}
}
} }, true);
}
@Override
public void mouseEntered(MouseEvent e) {
System.out.println("ColorPanel.mouseEntered");
for (int i = 0; i < myListeners.size(); i++) {
myListeners.get(i).entered(myExtractedColor);
}
}
@Override
public void mouseExited(MouseEvent e) {
for (int i = 0; i < myListeners.size(); i++) {
myListeners.get(i).exited();
}
}
});
}
use of java.awt.event.MouseAdapter in project jdk8u_jdk by JetBrains.
the class TSFrame method createGui.
public static Frame createGui(final boolean useSwing, final boolean useShape, final boolean useTransl, final boolean useNonOpaque, final float factor) {
Frame frame;
done = false;
if (useNonOpaque) {
if (useSwing) {
frame = new NonOpaqueJFrame();
// frame = new NonOpaqueJAppletFrame(gc);
} else {
frame = new NonOpaqueFrame();
}
animateComponent(frame);
} else if (useSwing) {
frame = new JFrame("Swing Frame");
JComponent p = new JButton("Swing!");
p.setPreferredSize(new Dimension(200, 100));
frame.add("North", p);
p = new MyJPanel();
animateComponent(p);
frame.add("Center", p);
} else {
frame = new Frame("AWT Frame") {
public void paint(Graphics g) {
g.setColor(Color.red);
g.fillRect(0, 0, 100, 100);
}
};
frame.setLayout(new BorderLayout());
Canvas c = new MyCanvas();
frame.add("North", c);
animateComponent(c);
c = new MyCanvas();
frame.add("Center", c);
animateComponent(c);
c = new MyCanvas();
frame.add("South", c);
animateComponent(c);
}
final Frame finalFrame = frame;
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
finalFrame.dispose();
done = true;
}
});
frame.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
finalFrame.dispose();
done = true;
}
});
frame.setPreferredSize(new Dimension(800, 600));
if (useShape) {
frame.setUndecorated(true);
}
frame.setLocation(450, 10);
frame.pack();
GraphicsDevice gd = frame.getGraphicsConfiguration().getDevice();
if (useShape) {
if (gd.isWindowTranslucencySupported(WindowTranslucency.PERPIXEL_TRANSPARENT)) {
System.out.println("applying PERPIXEL_TRANSPARENT");
frame.setShape(new Ellipse2D.Double(0, 0, frame.getWidth(), frame.getHeight() / 3));
frame.setTitle("PERPIXEL_TRANSPARENT");
} else {
System.out.println("Passed: PERPIXEL_TRANSPARENT unsupported");
}
}
if (useTransl) {
if (gd.isWindowTranslucencySupported(WindowTranslucency.TRANSLUCENT)) {
System.out.println("applying TRANSLUCENT");
frame.setOpacity(factor);
frame.setTitle("TRANSLUCENT");
} else {
System.out.println("Passed: TRANSLUCENT unsupported");
}
}
if (useNonOpaque) {
if (gd.isWindowTranslucencySupported(WindowTranslucency.PERPIXEL_TRANSLUCENT)) {
System.out.println("applying PERPIXEL_TRANSLUCENT");
frame.setBackground(new Color(0, 0, 0, 0));
frame.setTitle("PERPIXEL_TRANSLUCENT");
} else {
System.out.println("Passed: PERPIXEL_TRANSLUCENT unsupported");
}
}
frame.setVisible(true);
return frame;
}
use of java.awt.event.MouseAdapter in project graphhopper by graphhopper.
the class MiniGraphUI method visualize.
public void visualize() {
try {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
int frameHeight = 800;
int frameWidth = 1200;
JFrame frame = new JFrame("GraphHopper UI - Small&Ugly ;)");
frame.setLayout(new BorderLayout());
frame.add(mainPanel, BorderLayout.CENTER);
frame.add(infoPanel, BorderLayout.NORTH);
infoPanel.setPreferredSize(new Dimension(300, 100));
// scale
mainPanel.addMouseWheelListener(new MouseWheelListener() {
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
mg.scale(e.getX(), e.getY(), e.getWheelRotation() < 0);
repaintRoads();
}
});
// listener to investigate findID behavior
// MouseAdapter ml = new MouseAdapter() {
//
// @Override public void mouseClicked(MouseEvent e) {
// findIDLat = mg.getLat(e.getY());
// findIDLon = mg.getLon(e.getX());
// findIdLayer.repaint();
// mainPanel.repaint();
// }
//
// @Override public void mouseMoved(MouseEvent e) {
// updateLatLon(e);
// }
//
// @Override public void mousePressed(MouseEvent e) {
// updateLatLon(e);
// }
// };
MouseAdapter ml = new MouseAdapter() {
// for routing:
double fromLat, fromLon;
boolean fromDone = false;
boolean dragging = false;
@Override
public void mouseClicked(MouseEvent e) {
if (!fromDone) {
fromLat = mg.getLat(e.getY());
fromLon = mg.getLon(e.getX());
} else {
double toLat = mg.getLat(e.getY());
double toLon = mg.getLon(e.getX());
StopWatch sw = new StopWatch().start();
logger.info("start searching from " + fromLat + "," + fromLon + " to " + toLat + "," + toLon);
// get from and to node id
fromRes = index.findClosest(fromLat, fromLon, EdgeFilter.ALL_EDGES);
toRes = index.findClosest(toLat, toLon, EdgeFilter.ALL_EDGES);
logger.info("found ids " + fromRes + " -> " + toRes + " in " + sw.stop().getSeconds() + "s");
repaintPaths();
}
fromDone = !fromDone;
}
@Override
public void mouseDragged(MouseEvent e) {
dragging = true;
fastPaint = true;
update(e);
updateLatLon(e);
}
@Override
public void mouseReleased(MouseEvent e) {
if (dragging) {
// update only if mouse release comes from dragging! (at the moment equal to fastPaint)
dragging = false;
fastPaint = false;
update(e);
}
}
public void update(MouseEvent e) {
mg.setNewOffset(e.getX() - currentPosX, e.getY() - currentPosY);
repaintRoads();
}
@Override
public void mouseMoved(MouseEvent e) {
updateLatLon(e);
}
@Override
public void mousePressed(MouseEvent e) {
updateLatLon(e);
}
};
mainPanel.addMouseListener(ml);
mainPanel.addMouseMotionListener(ml);
// just for fun
// mainPanel.getInputMap().put(KeyStroke.getKeyStroke("DELETE"), "removedNodes");
// mainPanel.getActionMap().put("removedNodes", new AbstractAction() {
// @Override public void actionPerformed(ActionEvent e) {
// int counter = 0;
// for (CoordTrig<Long> coord : quadTreeNodes) {
// int ret = quadTree.remove(coord.lat, coord.lon);
// if (ret < 1) {
// // logger.info("cannot remove " + coord + " " + ret);
// // ret = quadTree.remove(coord.getLatitude(), coord.getLongitude());
// } else
// counter += ret;
// }
// logger.info("Removed " + counter + " of " + quadTreeNodes.size() + " nodes");
// }
// });
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(frameWidth + 10, frameHeight + 30);
frame.setVisible(true);
}
});
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
use of java.awt.event.MouseAdapter in project processdash by dtuma.
the class DefectLogEditor method constructEditPanel.
private JPanel constructEditPanel() {
JPanel retPanel = new JPanel(false);
String[] columns = new String[] { "Project", "ID", "Type", "Injected", "Removed", "Time", "Count", "Fix", "Pending", "Description", "Date" };
retPanel.setLayout(new BorderLayout());
table = new ValidatingTable(resources.getStrings("Columns.", columns, ".Name"), null, resources.getInts("Columns.", columns, ".Width_"), resources.getStrings("Columns.", columns, ".Tooltip"), null, null, 0, true, null, new boolean[] { // no columns editable
false, // no columns editable
false, // no columns editable
false, false, false, false, false, false, false, false, false });
DefectCellRenderer rend = new DefectCellRenderer();
for (int col = 2; col < 5; col++) table.table.getColumnModel().getColumn(col).setCellRenderer(rend);
table.table.getSelectionModel().addListSelectionListener(this);
table.table.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2)
editButton.doClick();
}
});
table.table.setTransferHandler(new TableTransferHandler());
table.table.setDragEnabled(true);
retPanel.add("Center", table);
JPanel btnPanel = new JPanel(false);
importButton = createImportButton();
if (importButton != null && Settings.isReadWrite()) {
btnPanel.add(importButton);
btnPanel.add(Box.createHorizontalStrut(100));
}
// Should only be available if one
// entry is selected
editButton = new JButton(resources.getString("Edit"));
editButton.setActionCommand("edit");
editButton.addActionListener(this);
editButton.setEnabled(false);
if (Settings.isReadWrite())
btnPanel.add(editButton);
// Should only be available if one
// entry is selected
deleteButton = new JButton(resources.getString("Delete"));
deleteButton.setActionCommand("delete");
deleteButton.addActionListener(this);
deleteButton.setEnabled(false);
if (Settings.isReadWrite())
btnPanel.add(deleteButton);
closeButton = new JButton(resources.getString("Close"));
closeButton.setActionCommand("close");
closeButton.addActionListener(this);
btnPanel.add(closeButton);
retPanel.add("South", btnPanel);
return retPanel;
}
Aggregations