use of java.awt.event.MouseMotionAdapter in project azure-tools-for-java by Microsoft.
the class SurveyPopUpDialog method addDragListener.
private void addDragListener() {
addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
dragPosition = new Point(e.getX(), e.getY());
}
});
addMouseMotionListener(new MouseMotionAdapter() {
public void mouseDragged(MouseEvent e) {
SurveyPopUpDialog.this.setLocation(e.getX() + getX() - dragPosition.x, e.getY() + getY() - dragPosition.y);
}
});
}
use of java.awt.event.MouseMotionAdapter in project Botnak by Gocnak.
the class BaseTableHeaderUI method installListeners.
public void installListeners() {
super.installListeners();
myMouseAdapter = new MouseAdapter() {
public void mouseReleased(MouseEvent e) {
if ((header == null) || (header.getTable() == null)) {
return;
}
boolean rolloverEnabled = Boolean.TRUE.equals(header.getClientProperty("rolloverEnabled"));
boolean sortingAllowed = false;
if (JTattooUtilities.getJavaVersion() >= 1.6) {
sortingAllowed = header.getTable().getRowSorter() != null;
}
if (rolloverEnabled || sortingAllowed || header.getReorderingAllowed()) {
if (header.getBounds().contains(e.getPoint())) {
int oldRolloverCol = rolloverCol;
rolloverCol = header.getColumnModel().getColumnIndexAtX(e.getX());
updateRolloverColumn(oldRolloverCol, rolloverCol);
} else {
int oldRolloverCol = rolloverCol;
rolloverCol = -1;
updateRolloverColumn(oldRolloverCol, rolloverCol);
}
}
}
public void mouseEntered(MouseEvent e) {
if ((header == null) || (header.getTable() == null)) {
return;
}
boolean rolloverEnabled = Boolean.TRUE.equals(header.getClientProperty("rolloverEnabled"));
boolean sortingAllowed = false;
if (JTattooUtilities.getJavaVersion() >= 1.6) {
sortingAllowed = header.getTable().getRowSorter() != null;
}
if (rolloverEnabled || sortingAllowed || header.getReorderingAllowed()) {
int oldRolloverCol = rolloverCol;
rolloverCol = header.getColumnModel().getColumnIndexAtX(e.getX());
updateRolloverColumn(oldRolloverCol, rolloverCol);
}
}
public void mouseExited(MouseEvent e) {
if ((header == null) || (header.getTable() == null)) {
return;
}
boolean rolloverEnabled = Boolean.TRUE.equals(header.getClientProperty("rolloverEnabled"));
boolean sortingAllowed = false;
if (JTattooUtilities.getJavaVersion() >= 1.6) {
sortingAllowed = header.getTable().getRowSorter() != null;
}
if (rolloverEnabled || sortingAllowed || header.getReorderingAllowed()) {
int oldRolloverCol = rolloverCol;
rolloverCol = -1;
updateRolloverColumn(oldRolloverCol, rolloverCol);
}
}
};
myMouseMotionAdapter = new MouseMotionAdapter() {
public void mouseMoved(MouseEvent e) {
if ((header == null) || (header.getTable() == null)) {
return;
}
boolean rolloverEnabled = Boolean.TRUE.equals(header.getClientProperty("rolloverEnabled"));
boolean sortingAllowed = false;
if (JTattooUtilities.getJavaVersion() >= 1.6) {
sortingAllowed = header.getTable().getRowSorter() != null;
}
if (rolloverEnabled || sortingAllowed || header.getReorderingAllowed()) {
if (header.getDraggedColumn() == null) {
int oldRolloverCol = rolloverCol;
rolloverCol = header.getColumnModel().getColumnIndexAtX(e.getX());
updateRolloverColumn(oldRolloverCol, rolloverCol);
}
}
}
public void mouseDragged(MouseEvent e) {
if ((header == null) || (header.getTable() == null)) {
return;
}
boolean rolloverEnabled = Boolean.TRUE.equals(header.getClientProperty("rolloverEnabled"));
boolean sortingAllowed = false;
if (JTattooUtilities.getJavaVersion() >= 1.6) {
sortingAllowed = header.getTable().getRowSorter() != null;
}
if (rolloverEnabled || sortingAllowed || header.getReorderingAllowed()) {
if (header.getDraggedColumn() != null && header.getDraggedColumn().getIdentifier() != null) {
rolloverCol = header.getColumnModel().getColumnIndex(header.getDraggedColumn().getIdentifier());
} else if (header.getResizingColumn() != null) {
rolloverCol = -1;
}
}
}
};
header.addMouseListener(myMouseAdapter);
header.addMouseMotionListener(myMouseMotionAdapter);
}
use of java.awt.event.MouseMotionAdapter in project yyl_example by Relucent.
the class IGOBoard method addControlListener.
protected void addControlListener() {
this.addMouseMotionListener(new MouseMotionAdapter() {
public void mouseMoved(MouseEvent event) {
int x = event.getX();
int y = event.getY();
if (((preMousePoint.x - x) > 2) || ((preMousePoint.x - x) < 2) && ((preMousePoint.y - y) > 2) || ((preMousePoint.y - y) < 2)) {
int cside = accountCellSide();
repaint(preMousePoint.x - cside, preMousePoint.y - cside, cside * 2, cside * 2);
preMousePoint = new Point(x, y);
}
}
});
addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent event) {
int event_x = event.getX();
int event_y = event.getY();
Point point = getToPoint(event_x, event_y);
if (point == null)
return;
switch(event.getButton()) {
case MouseEvent.BUTTON1:
{
gogo(point.y, point.x, YIN);
}
break;
case MouseEvent.BUTTON2:
{
gogo(point.y, point.x, VOID);
}
break;
case MouseEvent.BUTTON3:
{
gogo(point.y, point.x, YANG);
}
break;
default:
{
}
break;
}
repaint();
}
public void mouseExited(MouseEvent event) {
int cside = accountCellSide();
repaint(preMousePoint.x - cside, preMousePoint.y - cside, cside * 2, cside * 2);
preMousePoint = new Point(-255, -255);
repaint(event.getX() - cside, event.getY() - cside, cside * 2, cside * 2);
System.out.println(event.getX());
}
});
}
use of java.awt.event.MouseMotionAdapter in project vcell by virtualcell.
the class ReactionRuleEditorPropertiesPanel method initialize.
private void initialize() {
try {
shapePanel = new RulesShapePanel() {
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
reactantShape.paintSelf(g);
productShape.paintSelf(g);
}
};
shapePanel.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
super.mouseClicked(e);
if (getViewSingleRowButton().isSelected()) {
return;
}
if (e.getButton() == 1) {
// left click selects the object (we highlight it)
Point whereClicked = e.getPoint();
PointLocationInShapeContext locationContext = new PointLocationInShapeContext(whereClicked);
reactantShape.setPointLocationInShapeContext(locationContext);
productShape.setPointLocationInShapeContext(locationContext);
manageMouseActivity(locationContext);
} else if (e.getButton() == 3) {
// right click invokes popup menu (only if the object is highlighted)
Point whereClicked = e.getPoint();
PointLocationInShapeContext locationContext = new PointLocationInShapeContext(whereClicked);
reactantShape.setPointLocationInShapeContext(locationContext);
productShape.setPointLocationInShapeContext(locationContext);
manageMouseActivity(locationContext);
if (locationContext.getDeepestShape() != null && !locationContext.getDeepestShape().isHighlighted()) {
// TODO: (maybe) add code here to highlight the shape if it's not highlighted already but don't show the menu
// return;
}
showPopupMenu(e, locationContext);
}
}
private void manageMouseActivity(PointLocationInShapeContext locationContext) {
Graphics g = shapePanel.getGraphics();
reactantShape.turnHighlightOffRecursive(g);
productShape.turnHighlightOffRecursive(g);
boolean found = false;
if (reactantShape.contains(locationContext)) {
found = true;
}
if (!found) {
if (productShape.contains(locationContext)) {
// we just need to initialize the location context with the proper shapes under the cursor by calling "contains"
;
}
}
locationContext.highlightDeepestShape();
// if(locationContext.getDeepestShape() == null) {
// // nothing selected means all the reactant bar or all the product bar is selected
int xExtent = SpeciesPatternLargeShape.calculateXExtent(shapePanel);
Rectangle2D reactantRectangle = new Rectangle2D.Double(xOffsetInitial - xExtent, yOffsetReactantInitial - 3, 3000, 80 - 2 + GraphConstants.ReactionRuleDisplay_ReservedSpaceForNameOnYAxis);
Rectangle2D productRectangle = new Rectangle2D.Double(xOffsetInitial - xExtent, yOffsetProductInitial - 3, 3000, 80 - 2 + GraphConstants.ReactionRuleDisplay_ReservedSpaceForNameOnYAxis);
if (locationContext.isInside(reactantRectangle)) {
reactantShape.paintSelf(g, true);
} else if (locationContext.isInside(productRectangle)) {
productShape.paintSelf(g, true);
// } else {
//
// }
// } else {
// locationContext.paintDeepestShape(g);
}
}
});
shapePanel.addMouseMotionListener(new MouseMotionAdapter() {
public void mouseMoved(MouseEvent e) {
if (getViewSingleRowButton().isSelected()) {
shapePanel.setToolTipText("Single Row is view-only. To edit, unselect the 'Single Row Viewer' check box.");
return;
}
Point overWhat = e.getPoint();
PointLocationInShapeContext locationContext = new PointLocationInShapeContext(overWhat);
boolean inReactant = reactantShape.contains(locationContext);
boolean inProduct = productShape.contains(locationContext);
HighlightableShapeInterface hsi = locationContext.getDeepestShape();
if (hsi == null) {
shapePanel.setToolTipText(null);
} else {
shapePanel.setToolTipText("Right click for " + hsi.getDisplayType() + " menus");
}
List<SpeciesPatternLargeShape> spsList = null;
if (inReactant) {
spsList = reactantShape.getSpeciesPatternShapeList();
} else if (inProduct) {
spsList = productShape.getSpeciesPatternShapeList();
}
if (spsList != null) {
for (SpeciesPatternLargeShape sps : spsList) {
for (MolecularTypeLargeShape mtls : sps.getMolecularTypeLargeShapes()) {
Rectangle r = mtls.getAnchorHotspot();
if (r != null && r.contains(overWhat)) {
mtls.getMolecularType();
shapePanel.setToolTipText(mtls.getAnchorsHTML());
break;
}
}
}
}
}
});
shapePanel.setLayout(new GridBagLayout());
shapePanel.setBackground(Color.white);
shapePanel.zoomSmaller();
shapePanel.zoomSmaller();
getZoomSmallerButton().setEnabled(true);
getZoomLargerButton().setEnabled(true);
scrollPane = new JScrollPane(shapePanel);
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
isReversibleCheckBox = new JCheckBox("Reversible");
isReversibleCheckBox.setHorizontalTextPosition(SwingConstants.LEFT);
isReversibleCheckBox.addActionListener(eventHandler);
isReversibleCheckBox.setEnabled(true);
JPanel optionsPanel = new JPanel();
optionsPanel.setPreferredSize(new Dimension(156, 200));
optionsPanel.setLayout(new GridBagLayout());
int gridy = 0;
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = gridy;
gbc.insets = new Insets(6, 1, 2, 2);
gbc.anchor = GridBagConstraints.WEST;
optionsPanel.add(isReversibleCheckBox, gbc);
gbc = new GridBagConstraints();
gbc.gridx = 1;
gbc.gridy = gridy;
gbc.insets = new Insets(0, 0, 0, 0);
// empty cell to take all available horizontal space and push the next 2 buttons to the right
gbc.weightx = 1;
gbc.anchor = GridBagConstraints.WEST;
gbc.fill = GridBagConstraints.HORIZONTAL;
optionsPanel.add(new JLabel(""), gbc);
gbc = new GridBagConstraints();
gbc.gridx = 2;
gbc.gridy = gridy;
gbc.insets = new Insets(6, 2, 2, 2);
gbc.anchor = GridBagConstraints.EAST;
optionsPanel.add(getZoomLargerButton(), gbc);
gbc = new GridBagConstraints();
gbc.gridx = 3;
gbc.gridy = gridy;
gbc.insets = new Insets(6, 2, 2, 4);
gbc.anchor = GridBagConstraints.EAST;
optionsPanel.add(getZoomSmallerButton(), gbc);
gridy++;
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = gridy;
gbc.gridwidth = 4;
// top, left bottom, right
gbc.insets = new Insets(4, 4, 2, 4);
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.anchor = GridBagConstraints.NORTHWEST;
optionsPanel.add(getAddReactantButton(), gbc);
gridy++;
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = gridy;
gbc.gridwidth = 4;
gbc.insets = new Insets(2, 4, 4, 4);
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.anchor = GridBagConstraints.NORTHWEST;
optionsPanel.add(getAddProductButton(), gbc);
gridy++;
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = gridy;
gbc.gridwidth = 4;
gbc.weightx = 1;
// fake cell used for filling all the vertical empty space
gbc.weighty = 1;
gbc.anchor = GridBagConstraints.WEST;
gbc.insets = new Insets(4, 4, 4, 10);
optionsPanel.add(new JLabel(""), gbc);
// -----------------------------------------------------------
gridy++;
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = gridy;
gbc.gridwidth = 4;
gbc.insets = new Insets(2, 4, 0, 4);
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.anchor = GridBagConstraints.SOUTHWEST;
optionsPanel.add(getViewSingleRowButton(), gbc);
gridy++;
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = gridy;
gbc.gridwidth = 4;
gbc.insets = new Insets(0, 4, 4, 4);
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.anchor = GridBagConstraints.SOUTHWEST;
optionsPanel.add(getShowMoleculeColorButton(), gbc);
gridy++;
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = gridy;
gbc.gridwidth = 4;
gbc.insets = new Insets(0, 4, 4, 4);
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.anchor = GridBagConstraints.SOUTHWEST;
optionsPanel.add(getShowNonTrivialButton(), gbc);
gridy++;
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = gridy;
gbc.gridwidth = 3;
gbc.insets = new Insets(0, 4, 4, 4);
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.anchor = GridBagConstraints.SOUTHWEST;
optionsPanel.add(getShowDifferencesButton(), gbc);
// set initial buttons' state
getViewSingleRowButton().setSelected(false);
getShowMoleculeColorButton().setSelected(true);
getShowNonTrivialButton().setSelected(true);
getShowDifferencesButton().setSelected(false);
shapePanel.setViewSingleRow(getViewSingleRowButton().isSelected());
shapePanel.setShowMoleculeColor(getShowMoleculeColorButton().isSelected());
shapePanel.setShowNonTrivialOnly(getShowNonTrivialButton().isSelected());
shapePanel.setShowDifferencesOnly(getShowDifferencesButton().isSelected());
// ----------------------------------------------------------
containerOfScrollPanel = new JPanel();
containerOfScrollPanel.setLayout(new BorderLayout());
containerOfScrollPanel.add(optionsPanel, BorderLayout.WEST);
containerOfScrollPanel.add(scrollPane, BorderLayout.CENTER);
reactantTree = new BioModelNodeEditableTree();
reactantTreeModel = new ReactionRulePropertiesTreeModel(reactantTree, ReactionRuleParticipantType.Reactant);
reactantTree.setModel(reactantTreeModel);
productTree = new BioModelNodeEditableTree();
productTreeModel = new ReactionRulePropertiesTreeModel(productTree, ReactionRuleParticipantType.Product);
productTree.setModel(productTreeModel);
setLayout(new BorderLayout());
add(containerOfScrollPanel, BorderLayout.CENTER);
setBackground(Color.white);
} catch (java.lang.Throwable ivjExc) {
handleException(ivjExc);
}
}
use of java.awt.event.MouseMotionAdapter in project vcell by virtualcell.
the class ScrollTable method initialize.
private void initialize() {
autoResizeMode = AUTO_RESIZE_OFF;
// make it bigger on Mac
setRowHeight(getRowHeight() + 4);
putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
putClientProperty("JTable.autoStartsEdit", Boolean.FALSE);
scrollTableActionManager = new DefaultScrollTableActionManager(this);
enclosingScrollPane = new JScrollPane(this);
enclosingScrollPane.getViewport().setBackground(Color.WHITE);
contentPanel = new JPanel(new BorderLayout());
contentPanel.add(enclosingScrollPane, BorderLayout.CENTER);
setPreferredScrollableViewportSize(new Dimension(200, 100));
setIntercellSpacing(new Dimension(2, 2));
defaultTableCellRenderer = new DefaultScrollTableCellRenderer();
setDefaultRenderer(Object.class, defaultTableCellRenderer);
setDefaultRenderer(Number.class, defaultTableCellRenderer);
setDefaultRenderer(Double.class, defaultTableCellRenderer);
setDefaultRenderer(Boolean.class, new ScrollTableBooleanCellRenderer());
setDefaultEditor(Boolean.class, new ScrollTableBooleanEditor());
final TableCellRenderer defaultTableCellHeaderRenderer = getTableHeader().getDefaultRenderer();
TableCellRenderer defaultTableHeaderRenderer = new TableCellRenderer() {
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
Component component = defaultTableCellHeaderRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (component instanceof JLabel) {
JLabel label = (JLabel) component;
label.setHorizontalAlignment(SwingConstants.CENTER);
label.setBackground(tableHeaderColor);
label.setBorder(BorderFactory.createCompoundBorder(tableCellHeaderBorder, new EmptyBorder(1, 0, 1, 0)));
}
return component;
}
};
getTableHeader().setDefaultRenderer(defaultTableHeaderRenderer);
MouseAdapter mouseListener = new MouseAdapter() {
@Override
public void mouseClicked(final MouseEvent e) {
if (!javaVersion.startsWith("1.5")) {
if (!hasFocus()) {
if (e.getButton() == MouseEvent.BUTTON1) {
addFocusListener(new FocusListener() {
public void focusLost(FocusEvent e) {
}
public void focusGained(FocusEvent e) {
removeFocusListener(this);
Robot robot;
try {
robot = new Robot();
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
} catch (AWTException ex) {
ex.printStackTrace();
}
}
});
}
requestFocusInWindow();
}
}
}
@Override
public void mousePressed(MouseEvent e) {
scrollTableActionManager.triggerPopup(e);
}
@Override
public void mouseReleased(MouseEvent e) {
scrollTableActionManager.triggerPopup(e);
}
@Override
public void mouseEntered(MouseEvent e) {
hoverRow = rowAtPoint(e.getPoint());
hoverColumn = columnAtPoint(e.getPoint());
repaint();
}
@Override
public void mouseExited(MouseEvent e) {
hoverRow = -1;
hoverColumn = -1;
repaint();
}
};
MouseMotionAdapter mouseMotionListener = new MouseMotionAdapter() {
@Override
public void mouseMoved(MouseEvent e) {
hoverRow = rowAtPoint(e.getPoint());
hoverColumn = columnAtPoint(e.getPoint());
repaint();
}
};
addMouseListener(mouseListener);
addMouseMotionListener(mouseMotionListener);
}
Aggregations