use of javax.swing.event.MouseInputAdapter in project jbehave-core by jbehave.
the class JFrameContextView method initialize.
protected void initialize() {
frame = new JFrame();
label = new JLabel();
frame.setAlwaysOnTop(true);
frame.setSize(width, height);
frame.setLocation(x, y);
frame.setUndecorated(true);
JPanel panel = new JPanel();
frame.setContentPane(panel);
panel.setLayout(new BorderLayout());
label.setBorder(new EmptyBorder(3, 3, 3, 3));
panel.add(label, BorderLayout.CENTER);
MouseInputAdapter mia = new MouseInputAdapter() {
private Point mousePressedScreenCoords;
private Point mousePressedCompCoords;
public void mouseReleased(MouseEvent e) {
mousePressedScreenCoords = null;
mousePressedCompCoords = null;
}
public void mousePressed(MouseEvent e) {
mousePressedScreenCoords = e.getLocationOnScreen();
mousePressedCompCoords = e.getPoint();
}
public void mouseDragged(MouseEvent e) {
Point currCoords = e.getLocationOnScreen();
x = mousePressedScreenCoords.x + (currCoords.x - mousePressedScreenCoords.x) - mousePressedCompCoords.x;
y = mousePressedScreenCoords.y + (currCoords.y - mousePressedScreenCoords.y) - mousePressedCompCoords.y;
frame.setLocation(x, y);
}
};
frame.addMouseListener(mia);
frame.addMouseMotionListener(mia);
frame.setVisible(true);
}
use of javax.swing.event.MouseInputAdapter in project CoreNLP by stanfordnlp.
the class DisplayMatchesPanel method addMatch.
/**
* Adds the given tree to the display without removing already
* displayed trees
* @param match tree to be added
*/
private void addMatch(TreeFromFile match, List<Tree> matchedParts) {
JPanel treeDisplay = new JPanel(new BorderLayout());
JTextField filename = new JTextField("From file: " + match.getFilename());
filename.setEditable(false);
MouseInputAdapter listener = new FilenameMouseInputAdapter(filename);
filename.addMouseListener(listener);
filename.addMouseMotionListener(listener);
treeDisplay.add(filename, BorderLayout.NORTH);
if (TregexGUI.getInstance().isTdiffEnabled()) {
tjp = getTreeJPanel(match.getDiffDecoratedTree(), matchedParts);
tjp.setDiffConstituents(match.getDiffConstituents());
} else {
tjp = getTreeJPanel(match.getTree(), matchedParts);
}
matchedPartCoordinates = tjp.getMatchedPartCoordinates();
matchedPartCoordinateIdx = -1;
treeDisplay.add(tjp, BorderLayout.CENTER);
filename.setOpaque(true);
filename.setBackground(tjp.getBackground());
filename.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0));
scroller.setViewportView(treeDisplay);
this.revalidate();
this.repaint();
}
use of javax.swing.event.MouseInputAdapter in project java-swing-tips by aterai.
the class DesktopLayerUI method createFrame2.
private static JInternalFrame createFrame2() {
JInternalFrame f = new JInternalFrame("WindowsInternalFrameUI", true, true, true, true) {
@Override
public void updateUI() {
super.updateUI();
setUI(new WindowsInternalFrameUI(this) {
@Override
protected MouseInputAdapter createBorderListener(JInternalFrame w) {
return new BorderListener() {
@Override
public void mouseClicked(MouseEvent e) {
if (SwingUtilities.isLeftMouseButton(e)) {
super.mouseClicked(e);
}
}
@Override
public void mousePressed(MouseEvent e) {
if (SwingUtilities.isLeftMouseButton(e)) {
super.mousePressed(e);
}
}
};
}
});
}
};
f.setSize(200, 100);
f.setLocation(5 + 40, 5 + 50);
EventQueue.invokeLater(() -> f.setVisible(true));
return f;
}
Aggregations