use of java.awt.Cursor in project jdk8u_jdk by JetBrains.
the class TestDragSourceAdapter method main.
public static void main(String[] args) throws Exception {
DragSource ds = new DragSource();
TestDragSourceAdapter dsa1 = new TestDragSourceAdapter(1);
TestDragSourceAdapter dsa2 = new TestDragSourceAdapter(2);
Component c = new Button();
DragGestureRecognizer dgr = ds.createDefaultDragGestureRecognizer(c, DnDConstants.ACTION_COPY, e -> e.startDrag(null, null));
MouseEvent me = new MouseEvent(c, MouseEvent.MOUSE_PRESSED, 0, InputEvent.CTRL_MASK, 100, 100, 0, false);
DragGestureEvent dge = new DragGestureEvent(dgr, DnDConstants.ACTION_COPY, new Point(100, 100), Arrays.asList(me));
DragSourceContext dsc = new DragSourceContext(Toolkit.getDefaultToolkit().createDragSourceContextPeer(dge), dge, new Cursor(Cursor.HAND_CURSOR), null, null, new StringSelection("TEXT"), null);
ds.addDragSourceListener(dsa1);
ds.addDragSourceListener(dsa2);
ds.addDragSourceListener(dsa2);
ds.addDragSourceMotionListener(dsa1);
ds.addDragSourceMotionListener(dsa1);
ds.addDragSourceMotionListener(dsa2);
dsc.addDragSourceListener(dsa2);
byte[] serialized;
try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos)) {
oos.writeObject(dsc);
serialized = bos.toByteArray();
}
DragSourceContext dsc_copy;
try (ByteArrayInputStream bis = new ByteArrayInputStream(serialized);
ObjectInputStream ois = new ObjectInputStream(bis)) {
dsc_copy = (DragSourceContext) ois.readObject();
}
try {
dsc_copy.addDragSourceListener(dsa1);
throw new RuntimeException("Test failed. Listener addition succeeded");
} catch (TooManyListenersException ignored) {
}
try {
dsc_copy.addDragSourceListener(dsa2);
throw new RuntimeException("Test failed. Listener addition succeeded");
} catch (TooManyListenersException ignored) {
}
try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos)) {
oos.writeObject(ds);
serialized = bos.toByteArray();
}
DragSource ds_copy;
try (ByteArrayInputStream bis = new ByteArrayInputStream(serialized);
ObjectInputStream ois = new ObjectInputStream(bis)) {
ds_copy = (DragSource) ois.readObject();
}
DragSourceListener[] dsls = ds_copy.getDragSourceListeners();
assertEquals(3, dsls.length, "DragSourceListeners number");
assertEquals(1, Stream.of(dsls).filter(dsa1::equals).collect(Collectors.counting()).intValue());
assertEquals(2, Stream.of(dsls).filter(dsa2::equals).collect(Collectors.counting()).intValue());
DragSourceMotionListener[] dsmls = ds_copy.getDragSourceMotionListeners();
assertEquals(3, dsmls.length, "DragSourceMotionListeners number");
assertEquals(2, Stream.of(dsmls).filter(dsa1::equals).collect(Collectors.counting()).intValue());
assertEquals(1, Stream.of(dsmls).filter(dsa2::equals).collect(Collectors.counting()).intValue());
}
use of java.awt.Cursor in project JMRI by JMRI.
the class RosterFrame method startProgrammer.
protected void startProgrammer(DecoderFile decoderFile, RosterEntry re, String filename) {
if (inStartProgrammer) {
log.debug("Call to start programmer has been called twice when the first call hasn't opened");
return;
}
if (!checkIfEntrySelected()) {
return;
}
try {
setCursor(new Cursor(Cursor.WAIT_CURSOR));
inStartProgrammer = true;
String title = re.getId();
JFrame progFrame = null;
if (edit.isSelected()) {
progFrame = new PaneProgFrame(decoderFile, re, title, "programmers" + File.separator + filename + ".xml", null, false) {
@Override
protected JPanel getModePane() {
return null;
}
};
} else if (service.isSelected()) {
progFrame = new PaneServiceProgFrame(decoderFile, re, title, "programmers" + File.separator + filename + ".xml", modePanel.getProgrammer()) {
};
} else if (ops.isSelected()) {
int address = Integer.parseInt(re.getDccAddress());
boolean longAddr = re.isLongAddress();
Programmer pProg = InstanceManager.getDefault(AddressedProgrammerManager.class).getAddressedProgrammer(longAddr, address);
progFrame = new PaneOpsProgFrame(decoderFile, re, title, "programmers" + File.separator + filename + ".xml", pProg);
}
if (progFrame == null) {
return;
}
progFrame.pack();
progFrame.setVisible(true);
} finally {
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
inStartProgrammer = false;
}
use of java.awt.Cursor in project JMRI by JMRI.
the class FirstTimeStartUpWizard method dispose.
public void dispose() {
Cursor normalCursor = new Cursor(Cursor.DEFAULT_CURSOR);
parent.setCursor(normalCursor);
app.createAndDisplayFrame();
parent.setVisible(false);
parent.dispose();
}
use of java.awt.Cursor in project pcgen by PCGen.
the class NotesView method handleOpen.
/**
* {@literal handle File->Open.} Will open any .gmn files, and import them into your
* notes structure
*/
public void handleOpen() {
// TODO fix
String sFile = SettingsHandler.getGMGenOption(OPTION_NAME_LASTFILE, System.getProperty("user.dir"));
File defaultFile = new File(sFile);
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(defaultFile);
chooser.addChoosableFileFilter(NotesPlugin.getFileType());
chooser.setFileFilter(NotesPlugin.getFileType());
chooser.setMultiSelectionEnabled(true);
Component component = GMGenSystem.inst;
Cursor originalCursor = component.getCursor();
component.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
int option = chooser.showOpenDialog(GMGenSystem.inst);
if (option == JFileChooser.APPROVE_OPTION) {
for (File noteFile : chooser.getSelectedFiles()) {
SettingsHandler.setGMGenOption(OPTION_NAME_LASTFILE, noteFile.toString());
if (noteFile.toString().endsWith(EXTENSION)) {
openGMN(noteFile);
}
}
}
GMGenSystem.inst.setCursor(originalCursor);
refreshTree();
}
use of java.awt.Cursor in project n2a by frothga.
the class FixedParameterSpacePanel method dragGestureRecognized.
public void dragGestureRecognized(DragGestureEvent event) {
Cursor cursor = null;
SimpleTree list = (SimpleTree) event.getComponent();
TreePath[] paths = list.getSelectionPaths();
if (paths == null) {
return;
}
List<ParameterBundle> bundles = getSelectedParamsAsBundles(paths);
if (bundles == null) {
return;
}
if (event.getDragAction() == DnDConstants.ACTION_LINK) {
cursor = DragCursors.getGrabhandcursor();
}
event.startDrag(cursor, new TransferableParameterBundles(bundles));
}
Aggregations