use of java.awt.Cursor in project adempiere by adempiere.
the class PDFViewerBean method setCurrentPage.
public void setCurrentPage(int page) {
if (page < 1 || page > decoder.getPageCount()) {
return;
}
final Cursor oldCursor = getCursor();
try {
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
decoder.setPageParameters(zoomFactors[scaleStep], page);
decoder.decodePage(page);
setRotation(decoder.getPdfPageData().getRotation(page));
currentPage = page;
} catch (Exception e) {
e.printStackTrace();
return;
} finally {
setCursor(oldCursor);
}
goFirstAction.setEnabled(currentPage > 1);
goPreviousAction.setEnabled(currentPage > 1);
goNextAction.setEnabled(currentPage < decoder.getPageCount());
goLastAction.setEnabled(currentPage < decoder.getPageCount());
pageField.setText(Integer.toString(currentPage));
}
use of java.awt.Cursor in project adempiere by adempiere.
the class PDFViewerBean method updateZoomRotate.
protected void updateZoomRotate() {
final Cursor oldCursor = getCursor();
try {
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
decoder.setPageParameters(zoomFactors[scaleStep], currentPage, rotation);
decoder.invalidate();
decoder.repaint();
zoomInAction.setEnabled(scaleStep < zoomFactors.length - 1);
zoomOutAction.setEnabled(scaleStep > 0);
} finally {
setCursor(oldCursor);
}
}
use of java.awt.Cursor in project pcgen by PCGen.
the class InitiativePlugin method fileOpen.
/**
* Handles the clicking of the <b>Add </b> button on the GUI.
*/
public void fileOpen() {
JFileChooser chooser = ImagePreview.decorateWithImagePreview(new JFileChooser());
File defaultFile = new File(PCGenSettings.getPcgDir());
if (defaultFile.exists()) {
chooser.setCurrentDirectory(defaultFile);
}
// TODO should probably handle zip pcg
String[] pcgs = { "pcg", "pcp" };
String[] init = { "gmi", "init" };
FileFilter ff = new FileNameExtensionFilter("Initiative Export", init);
chooser.addChoosableFileFilter(ff);
chooser.addChoosableFileFilter(new FileNameExtensionFilter("PCGen File", pcgs));
chooser.removeChoosableFileFilter(chooser.getAcceptAllFileFilter());
chooser.setFileFilter(ff);
chooser.setMultiSelectionEnabled(true);
Cursor originalCursor = theView.getCursor();
theView.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
int option = chooser.showOpenDialog(theView);
if (option == JFileChooser.APPROVE_OPTION) {
File[] pcFiles = chooser.getSelectedFiles();
for (File pcFile : pcFiles) {
if (PCGFile.isPCGenCharacterOrPartyFile(pcFile)) {
messageHandler.handleMessage(new RequestOpenPlayerCharacterMessage(this, pcFile, false));
//loadPCG(pcFiles[i]);
} else if (pcFile.toString().endsWith(".init") || pcFile.toString().endsWith(".gmi")) {
loadINIT(pcFile);
}
}
/* loop through selected files */
theView.refreshTable();
} else {
/* this means the file is invalid */
}
theView.setCursor(originalCursor);
}
use of java.awt.Cursor in project pcgen by PCGen.
the class PCGTrackerPlugin method handleOpen.
/**
* Handles the clicking of the <b>Add</b> button on the GUI.
*/
public void handleOpen() {
File defaultFile = new File(PCGenSettings.getPcgDir());
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(defaultFile);
String[] pcgs = { FILENAME_PCG, FILENAME_PCP };
FileFilter ff = new FileNameExtensionFilter(LanguageBundle.getString("in_pcgen_file"), //$NON-NLS-1$
pcgs);
chooser.addChoosableFileFilter(ff);
chooser.setFileFilter(ff);
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 selectedFile : chooser.getSelectedFiles()) {
if (PCGFile.isPCGenCharacterOrPartyFile(selectedFile)) {
messageHandler.handleMessage(new RequestOpenPlayerCharacterMessage(this, selectedFile, false));
}
}
} else {
/* this means the file is invalid */
}
GMGenSystem.inst.setCursor(originalCursor);
}
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());
}
Aggregations