下面列出了怎么用java.awt.Cursor的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Collection process complete.
*
* @see org.apache.uima.collection.base_cpm.BaseStatusCallbackListener#collectionProcessComplete()
*/
@Override
public void collectionProcessComplete() {
// invoke ProcessingCompleteRunnable in Swing event handler thread
// SwingUtilities.invokeLater(new ProcessingCompleteRunnable());
// hide progress bar dialog if it is visible
if (!progressMonitor.isCanceled()) {
progressMonitor.close();
progressTimer.stop();
}
// Re-enable frame:
setEnabled(true);
// reset cursor
setCursor(Cursor.getDefaultCursor());
// if everything works, output performance stats and print them to a
// pane. Allow users to open generated files.
showAnalysisResults(new AnalysisEnginePerformanceReports(mCPM.getPerformanceReport()),
outputDirectory);
}
private JPanel createLinkPanel() {
linkPanel = new JPanel();
linkPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
todayLink = new JLabel();
todayLink.setForeground(new Color(16, 66, 104));
todayLink.setCursor(new Cursor(Cursor.HAND_CURSOR));
linkPanel.add(todayLink);
todayLink.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (SwingUtilities.isLeftMouseButton(e)) {
Action delegate = getActionMap().get(e.getClickCount() != 2 ? JXDatePicker.HOME_NAVIGATE_KEY : JXDatePicker.HOME_COMMIT_KEY);
if (delegate != null && delegate.isEnabled())
delegate.actionPerformed(null);
}
}
});
return linkPanel;
}
public void mouseMoved(MouseEvent e) {
isOverBar = false;
if (model == null) {
return;
}
Point p = e.getPoint();
if (isOverFirstPosition(p) || isOverSecondPosition(p)) {
setCursor(Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR));
} else if (isOverSelection(p)) {
isOverBar = true;
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
} else {
this.setCursor(Cursor.getDefaultCursor());
}
repaint();
}
/**
*
* @param e
*/
@Override
public void mouseDragged(MouseEvent e) {
if (mouseIsPressedInPullTab) {
currentMouseX = e.getX();
currentMouseY = e.getY();
if (pullFrom == PULL_FROM_LEFT) {
setShadeCover(Math.max(WIDTH_OF_PULLTAB, getWidth() + (currentMouseX - pressedMouseX)));
pressedMouseX = currentMouseX;
} else {
setShadeCover(Math.max(WIDTH_OF_PULLTAB, getWidth() + (pressedMouseX - currentMouseX)));
pressedMouseX = WIDTH_OF_PULLTAB / 2;
}
if (!mouseInPullTab()) {
processMouseExitedPullTab();
setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
}
}
}
/**
* Creates a new instance of WeightedMeanGraphPanel
*
* @param sample
*/
public WeightedMeanGraphPanel(SampleInterface sample) {
super();
this.sample = sample;
setOpaque(true);
setBackground(Color.white);
graphWidth = 775;
graphHeight = 600;
selectedSampleDateModels = new Object[0][0];
weightedMeanCursor = Cursor.getDefaultCursor();
imageMode = "PAN";
// setInRandomMode( false );
weightedMeanOptions = new SampleDateInterpretationGUIOptions().getWeightedMeanOptions();
addMouseListener(this);
addMouseMotionListener(this);
}
private OperationResponse execute(ModelNode request, boolean useWaitCursor) throws IOException {
if(request.get(Util.OPERATION).asString().equals(Util.COMPOSITE) &&
(!request.get(Util.STEPS).isDefined() || request.get(Util.STEPS).asList().isEmpty())) {
return OperationResponse.Factory.createSimple(new ModelNode("WARN: no request was sent as there were no server-side operations to execute"));
}
try {
if (useWaitCursor) {
cliGuiCtx.getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
}
return client.get().executeOperation(OperationBuilder.create(request).build(), OperationMessageHandler.DISCARD);
} finally {
if (useWaitCursor) {
cliGuiCtx.getMainWindow().setCursor(Cursor.getDefaultCursor());
}
}
}
/**
* �t���X�N���[�����[�h�̏�����
*
*/
private void initFullScreen() {
GraphicsEnvironment env = GraphicsEnvironment
.getLocalGraphicsEnvironment();
device = env.getDefaultScreenDevice();
// �^�C�g���o�[������
setUndecorated(true);
// �}�E�X�J�[�\��������
Cursor cursor = Toolkit.getDefaultToolkit().createCustomCursor(
new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB),
new Point(), "");
setCursor(cursor);
if (!device.isFullScreenSupported()) {
System.out.println("�t���X�N���[�����[�h�̓T�|�[�g����Ă��܂���B");
System.exit(0);
}
device.setFullScreenWindow(this); // �t���X�N���[�����I
DisplayMode mode = new DisplayMode(640, 480, 16,
DisplayMode.REFRESH_RATE_UNKNOWN);
device.setDisplayMode(mode);
}
/**
* Saves the board in PNG image format.
*/
private void boardSaveImage(boolean ignoreUnits) {
if (curfileImage == null) {
boardSaveAsImage(ignoreUnits);
return;
}
JDialog waitD = new JDialog(frame, Messages.getString("BoardEditor.waitDialog.title")); //$NON-NLS-1$
waitD.add(new JLabel(Messages.getString("BoardEditor.waitDialog.message"))); //$NON-NLS-1$
waitD.setSize(250, 130);
// move to middle of screen
waitD.setLocation(
(frame.getSize().width / 2) - (waitD.getSize().width / 2),
(frame.getSize().height / 2) - (waitD.getSize().height / 2));
waitD.setVisible(true);
frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
waitD.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
// save!
try {
ImageIO.write(bv.getEntireBoardImage(ignoreUnits), "png", curfileImage);
} catch (IOException e) {
e.printStackTrace();
}
waitD.setVisible(false);
frame.setCursor(Cursor.getDefaultCursor());
}
public void pSetCursor(Cursor cursor, boolean ignoreSubComponents) {
XToolkit.awtLock();
try {
long xcursor = XGlobalCursorManager.getCursor(cursor);
XSetWindowAttributes xwa = new XSetWindowAttributes();
xwa.set_cursor(xcursor);
long valuemask = XConstants.CWCursor;
XlibWrapper.XChangeWindowAttributes(XToolkit.getDisplay(),getWindow(),valuemask,xwa.pData);
XlibWrapper.XFlush(XToolkit.getDisplay());
xwa.dispose();
} finally {
XToolkit.awtUnlock();
}
}
/**
*
* @param evt
*/
@Override
public void mouseMoved(MouseEvent evt) {
int myX = evt.getX();
int myY = evt.getY();
eastResizing = isEastResize(myX);
southResizing = isSouthResize(myY);
setCursor(Cursor.getDefaultCursor());
if (eastResizing ^ southResizing) {
if (eastResizing) {
setCursor(Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR));
} else {
setCursor(Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR));
}
}
if (eastResizing && southResizing) {
setCursor(Cursor.getPredefinedCursor(Cursor.SE_RESIZE_CURSOR));
}
}
/**
* This method will show or hide the splash screen. Once the splash
* screen is hidden, the splash screen window will be disposed. This means
* the splash screen cannot become visible again.
*/
public void setVisible(boolean show) {
if (show == true && dialog != null && f != null && !dialog.isVisible()) {
dialog.setVisible(true);
}
else {
if (dialog != null) {
updateProgress(steps + 1);
dialog.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
dialog.dispose();
}
if (f != null) {
f.dispose();
}
dialog = null;
f = null;
}
}
public void mouseMoved(MouseEvent e) {
isOverBar = false;
if (model == null) {
return;
}
Point p = e.getPoint();
if (isOverFirstPosition(p) || isOverSecondPosition(p)) {
setCursor(Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR));
} else if (isOverSelection(p)) {
isOverBar = true;
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
} else {
this.setCursor(Cursor.getDefaultCursor());
}
repaint();
}
public void pSetCursor(Cursor cursor, boolean ignoreSubComponents) {
XToolkit.awtLock();
try {
long xcursor = XGlobalCursorManager.getCursor(cursor);
XSetWindowAttributes xwa = new XSetWindowAttributes();
xwa.set_cursor(xcursor);
long valuemask = XConstants.CWCursor;
XlibWrapper.XChangeWindowAttributes(XToolkit.getDisplay(),getWindow(),valuemask,xwa.pData);
XlibWrapper.XFlush(XToolkit.getDisplay());
xwa.dispose();
} finally {
XToolkit.awtUnlock();
}
}
private void setCursor (MouseEvent e)
{
if (isDragWanted(e)) {
e.getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
} else if (isAdditionWanted(e)) {
e.getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
} else if (isContextWanted(e)) {
e.getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
} else if (isRubberWanted(e)) {
e.getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.SE_RESIZE_CURSOR));
} else if (isRezoomWanted(e)) {
e.getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.SE_RESIZE_CURSOR));
} else {
e.getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
}
/**
*
* @param sampleSessionDataView
* @param dataPresentationMode
* @param timeArray
* @param bounds
* @param meanOnly the value of meanOnly
*/
public DataPresentationModeChooserPanel(//
JLayeredPane sampleSessionDataView, //
DataPresentationModeEnum dataPresentationMode, //
double[] timeArray, //
Rectangle bounds, //
boolean meanOnly) {
super(bounds);
this.sampleSessionDataView = sampleSessionDataView;
this.dataPresentationMode = dataPresentationMode;
this.myOnPeakNormalizedAquireTimes = timeArray;
this.meanOnly = meanOnly;
setOpaque(true);
setBackground(new Color(250, 240, 230));
setCursor(Cursor.getDefaultCursor());
dataViewModeButtonGroup = new ButtonGroup();
}
protected void setNativeCursor(long nativeCtxt, Cursor c, int cType) {
assert XToolkit.isAWTLockHeldByCurrentThread();
if (c == null) {
return;
}
long xcursor = XGlobalCursorManager.getCursor(c);
if (xcursor == 0) {
return;
}
XlibWrapper.XChangeActivePointerGrab(XToolkit.getDisplay(),
GRAB_EVENT_MASK,
xcursor,
XConstants.CurrentTime);
}
/**
* Disable the User Interface.
*/
public void disableUI() {
// turn on the wait cursor
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
// hide jTable (disabling show out of bound exception ! ! !)
jTable_Browser.setVisible(false);
// disable input
jComboBox_Path.setEnabled(false);
jTextField_Filter.setEnabled(false);
// disable buttons
mButton_Copy.setEnabled(false);
mButton_Delete.setEnabled(false);
mButton_GoUp.setEnabled(false);
mButton_MakeDirectory.setEnabled(false);
mButton_MakeFile.setEnabled(false);
mButton_Paste.setEnabled(false);
mButton_Refresh.setEnabled(false);
mButton_Rename.setEnabled(false);
}
/**
* Load an application
*
* @param plugin Application
*/
public void loadApplication(Application plugin) {
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
try {
PythonInterpreter interp = this.getConsoleDockable().getInterpreter();
String path = plugin.getPath();
interp.exec("import " + path);
interp.exec("from " + path + ".loadApp import LoadApp");
PyObject loadClass = interp.get("LoadApp");
PyObject loadObj = loadClass.__call__();
IPlugin instance = (IPlugin) loadObj.__tojava__(IPlugin.class);
instance.setApplication(FrmMain.this);
instance.setName(plugin.getName());
plugin.setPluginObject(instance);
plugin.setLoad(true);
instance.load();
} catch (Exception e) {
e.printStackTrace();
}
this.setCursor(Cursor.getDefaultCursor());
}
public void stopProgress() {
stopRunner();
updateProgress(0);
perc = 0;
msg = "";
repaint();
setCursor(Cursor.DEFAULT_CURSOR);
}
/**
* Completes the initialization of the dialog.
* @param url URL of the page to be displayed
* @param preferredSize optional preferred size of the browser component
*/
private void completeInit( final String url, final Dimension preferredSize ) {
final JEditorPane browserPane = GuiUtils.createEditorPane();
browserPane.setPreferredSize( preferredSize );
final JScrollPane scrollPane = new JScrollPane( browserPane );
scrollPane.setBorder( BorderFactory.createEmptyBorder( 10, 10, 10, 10 ) );
getContentPane().add( scrollPane, BorderLayout.CENTER );
final JButton okButton = createCloseButton( "button.close" );
getContentPane().add( GuiUtils.wrapInPanel( okButton ), BorderLayout.SOUTH );
// Load page content in a new thread to not block the AWT event dispatcher thread
new NormalThread( "Browser dialog content loader" ) {
@Override
public void run() {
try {
browserPane.setCursor( Cursor.getPredefinedCursor( Cursor.WAIT_CURSOR ) );
browserPane.setPage( url );
} catch ( final IOException ie ) {
ie.printStackTrace();
browserPane.setContentType( "text/html" );
browserPane.setText( "<html><body style='font-family:arial;font-size:10px;font-style:italic;background:#ffffff;'>"
+ "<p>This content is currently unavailable. Please try again later.</p></body></html>" );
} finally {
browserPane.setCursor( null );
}
}
}.start();
packAndShow( okButton, false );
}
public void setWaitingState(boolean wait) {
Component rootPane = getRootPane();
enableInput(! wait);
if (rootPane != null) {
rootPane.setCursor(wait ? Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR) : null);
}
}
void updateProjectAndBugCollection(BugCollection bugCollection) {
if (bugCollection != null) {
displayer.clearCache();
BugSet bs = new BugSet(bugCollection);
// Don't clear data, the data's correct, just get the tree off the
// listener lists.
BugTreeModel model = (BugTreeModel) mainFrameTree.getTree().getModel();
model.getOffListenerList();
model.changeSet(bs);
// curProject=BugLoader.getLoadedProject();
setProjectChanged(true);
}
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
public void mouseMoved(MouseEvent e)
{
JRPrintImageAreaHyperlink imageArea = getImageMapArea(e);
if (imageArea != null
&& imageArea.getHyperlink().getHyperlinkTypeValue() != HyperlinkTypeEnum.NONE)
{
e.getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}
else
{
e.getComponent().setCursor(Cursor.getDefaultCursor());
}
}
public void mouseMoved(MouseEvent e) {
if (e.getSource().equals(textPane)) {
textPane.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
linkerSupport.computeBounds(textPane, 0);
linkerSupport.mouseMoved(e.getPoint(), textPane, messageOffset);
}
textPane.setToolTipText(""); // NOI18N
}
public Cursor get(StendhalCursor stendhalCursor) {
Cursor res = cursorMap.get(stendhalCursor);
if (res == null) {
res = loadCursor(stendhalCursor);
}
return res;
}
/**
*
*
* @param rawDataModelViews
* @param sampleSessionDataView
* @param backgroundColor
* @param minY
* @param maxY
* @param bounds
* @param floating
* @param forStandards the value of forStandards
*/
public YAxisView(//
AbstractRawDataView[] rawDataModelViews, //
JLayeredPane sampleSessionDataView, //
Color backgroundColor, //
double minY, //
double maxY, //
Rectangle bounds, //
boolean floating, //
boolean forStandards) {
super(bounds);
this.rawDataModelViews = rawDataModelViews;
this.dataViewsOverlay = null;
this.sampleSessionDataView = sampleSessionDataView;
this.backgroundColor = backgroundColor;
this.yOnMousePress = 0;
this.minY = minY;
this.maxY = maxY;
this.floating = floating;
this.forStandards = forStandards;
// horizontal layout arbitrarily fixed
this.minX = 0;
this.maxX = bounds.getWidth();//100;
setOpaque(true);
setBackground(Color.white);
setBounds(bounds);
graphWidth = bounds.width - leftMargin;
graphHeight = bounds.height - topMargin;
addMeAsMouseListener();
addMeAsMouseMotionListener();
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}
/**
* Save the selected data to disk in CGX format
*/
private void SavePartCGX() {
String s;
if (Track.data.isEmpty())
return;
s = Utils.SaveDialog(this, Settings.previousCGXDirectory, "", ".cgx", bundle.getString("frmMain.CGXFile"), true,
bundle.getString("frmMain.FileExist"));
if (!s.isEmpty()) {
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
// -- Save track
int start = panelTrackData.getSelectedRow();
int end = start + panelTrackData.getSelectedRowCount() - 1;
Track.SaveCGX(s, start, end, false);
// -- Store the directory
Settings.previousCGXDirectory = Utils.GetDirFromFilename(s);
// -- Update GPX MRU
AddMruCGX(s);
RefreshMruCGX();
// -- We don't reset the track modified flag because we save only a
// part of the track!
Track.isModified = false;
// -- Refresh info panel
RefreshStatusbar(Track);
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
}
private void doGenerateEtlHtmlDoc() {
String directoryName = chooseSaveDirectory();
if (directoryName != null) {
frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
ETLMarkupDocumentGenerator generator = new ETLMarkupDocumentGenerator(ObjectExchange.etl);
generator.generate(directoryName, DocumentType.HTML);
frame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
}
@Override
public void mouseReleased(MouseEvent e) {
if( null == draggingDivider )
return;
final Point p = new Point( e.getPoint() );
draggingDivider.finishDraggingTo( p );
draggingDivider = null;
setCursor( Cursor.getDefaultCursor() );
e.consume();
}
public static void main(final String[] args) throws AWTException {
// This list is copied from cursors.properties
String[] names = {"CopyDrop.32x32", "MoveDrop.32x32", "LinkDrop.32x32",
"CopyNoDrop.32x32", "MoveNoDrop.32x32",
"LinkNoDrop.32x32", "Invalid.32x32"};
for (final String name : names) {
if (Cursor.getSystemCustomCursor(name) == null) {
throw new RuntimeException("Cursor is null: " + name);
}
}
System.out.println("Test passed");
}