下面列出了java.awt.Cursor#DEFAULT_CURSOR 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void updateMouse(MouseEvent e, boolean onContainer) {
inDivider = false;
int origCursor = cursor;
cursor = Cursor.DEFAULT_CURSOR;
if (onContainer) {
int x = e.getX();
for (int i = 0; i < dividerOffsets.size(); i++) {
int divx = dividerOffsets.get(i);
if (x >= divx && x <= divx + DIVIDER_SIZE - 1) {
inDivider = true;
offsetIdx = i;
cursor = Cursor.E_RESIZE_CURSOR;
break;
}
}
}
if (origCursor != cursor) setCursor(Cursor.getPredefinedCursor(cursor));
}
private void updateMouse(MouseEvent e, boolean onContainer) {
inDivider = false;
int origCursor = cursor;
cursor = Cursor.DEFAULT_CURSOR;
if (onContainer) {
int x = e.getX();
for (int i = 0; i < dividerOffsets.size(); i++) {
int divx = dividerOffsets.get(i);
if (x >= divx && x <= divx + DIVIDER_SIZE - 1) {
inDivider = true;
offsetIdx = i;
cursor = Cursor.E_RESIZE_CURSOR;
break;
}
}
}
if (origCursor != cursor) setCursor(Cursor.getPredefinedCursor(cursor));
}
private void createCursors() {
curDefault = new Cursor(Cursor.DEFAULT_CURSOR);
curNResize = new Cursor(Cursor.N_RESIZE_CURSOR);
curWResize = new Cursor(Cursor.W_RESIZE_CURSOR);
curEResize = new Cursor(Cursor.E_RESIZE_CURSOR);
curSResize = new Cursor(Cursor.S_RESIZE_CURSOR);
}
public void mouseDragged(MouseEvent e) {
check(e);
Window w = SwingUtilities.getWindowAncestor((Component)e.getSource());
if (Cursor.DEFAULT_CURSOR == cursorType) {
// resize only when mouse pointer in resize areas
return;
}
Rectangle newBounds = computeNewBounds(w, getScreenLoc(e));
if (!w.getBounds().equals(newBounds)) {
w.setBounds(newBounds);
}
}
@Override
public void mouseMoved(MouseEvent evt) {
if (mouseState == MouseState.DEFAULT) {
boolean textCursor = true;
int position = component.viewToModel(evt.getPoint());
if (RectangularSelectionUtils.isRectangularSelection(component)) {
List<Position> positions = RectangularSelectionUtils.regionsCopy(component);
for (int i = 0; textCursor && i < positions.size(); i += 2) {
int a = positions.get(i).getOffset();
int b = positions.get(i + 1).getOffset();
if (a == b) {
continue;
}
textCursor &= !(position >= a && position <= b || position >= b && position <= a);
}
} else {
// stream selection
if (getDot() == getMark()) {
// empty selection
textCursor = true;
} else {
int dot = getDot();
int mark = getMark();
if (position >= dot && position <= mark || position >= mark && position <= dot) {
textCursor = false;
} else {
textCursor = true;
}
}
}
if (textCursor != showingTextCursor) {
int cursorType = textCursor ? Cursor.TEXT_CURSOR : Cursor.DEFAULT_CURSOR;
component.setCursor(Cursor.getPredefinedCursor(cursorType));
showingTextCursor = textCursor;
}
}
}
@Override
public void mouseMoved(MouseEvent evt) {
if (mouseState == MouseState.DEFAULT) {
boolean textCursor = true;
int position = component.viewToModel(evt.getPoint());
if (RectangularSelectionUtils.isRectangularSelection(component)) {
List<Position> positions = RectangularSelectionUtils.regionsCopy(component);
for (int i = 0; textCursor && i < positions.size(); i += 2) {
int a = positions.get(i).getOffset();
int b = positions.get(i + 1).getOffset();
if (a == b) {
continue;
}
textCursor &= !(position >= a && position <= b || position >= b && position <= a);
}
} else // stream selection
if (getDot() == getMark()) {
// empty selection
textCursor = true;
} else {
int dot = getDot();
int mark = getMark();
if (position >= dot && position <= mark || position >= mark && position <= dot) {
textCursor = false;
} else {
textCursor = true;
}
}
if (textCursor != showingTextCursor) {
int cursorType = textCursor ? Cursor.TEXT_CURSOR : Cursor.DEFAULT_CURSOR;
component.setCursor(Cursor.getPredefinedCursor(cursorType));
showingTextCursor = textCursor;
}
}
}
/**
* v1.0.1:修复自定义拖拽区域BUG, 保存游标状态
*/
public void mouseMoved(MouseEvent e)
{
Window window = (Window)e.getSource();
int w = window.getWidth();
int h = window.getHeight();
Point point = e.getPoint();
JRootPane rootPane = LuckWindowUtil.getRootPane(window);
int cursor = 0;
if(rootPane != null && LuckWindowUtil.isResizable(window))
{
cursor = getCursor(w, h, point, rootPane.getInsets());
}
if(cursor != Cursor.DEFAULT_CURSOR)
{
window.setCursor(Cursor.getPredefinedCursor(cursor));
}
else
{
window.setCursor(lastCursor);
}
dragCursor = cursor;
}
public void mouseDragged(MouseEvent e)
{
Window w = (Window) e.getSource();
if (isMovingWindow)
{
Point prePoint = e.getLocationOnScreen();
w.setLocation(prePoint.x - dragOffsetX, prePoint.y - dragOffsetY);
}
else if(dragCursor != Cursor.DEFAULT_CURSOR)
{
updateBound(e.getPoint(), w);
}
}
public void mouseMoved(MouseEvent ev) {
JTextPane editor = (JTextPane) ev.getSource();
editor.setEditable(false);
Point pt = new Point(ev.getX(), ev.getY());
int pos = editor.viewToModel(pt);
if (pos >= 0) {
Document eDoc = editor.getDocument();
if (eDoc instanceof DefaultStyledDocument) {
DefaultStyledDocument hdoc =
(DefaultStyledDocument) eDoc;
Element e = hdoc.getCharacterElement(pos);
AttributeSet a = e.getAttributes();
AttributeSet tagA = (AttributeSet) a.getAttribute(HTML.Tag.A);
String href = null;
if (tagA!=null){
href = (String)tagA.getAttribute(HTML.Attribute.HREF);
}
if (href != null) {
editor.setToolTipText(href);
if (editor.getCursor().getType() != Cursor.HAND_CURSOR) {
editor.setCursor(new Cursor(Cursor.HAND_CURSOR));
}
}
else {
editor.setToolTipText(null);
if (editor.getCursor().getType() != Cursor.DEFAULT_CURSOR) {
editor.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
}
}
}
else {
editor.setToolTipText(null);
}
}
public static void setCursor(Container container, int cursor) {
Component[] cmps = container.getComponents();
container.setCursor(Cursor.getPredefinedCursor(cursor));
for(int i = 0; i < cmps.length; i++) {
if(cmps[i] instanceof Container)
setCursor((Container)cmps[i], cursor);
else if (cmps[i] instanceof TextComponent &&
cursor == Cursor.DEFAULT_CURSOR)
cmps[i].setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
else
cmps[i].setCursor(Cursor.getPredefinedCursor(cursor));
}
}
private int getCursorType (Rectangle b, Point p) {
int leftDist = p.x - b.x;
int rightDist = (b.x + b.width) - p.x;
int topDist = p.y - b.y;
int bottomDist = (b.y + b.height) - p.y;
boolean isNearTop = topDist >= 0 && topDist <= insets.top;
boolean isNearBottom = bottomDist >= 0 && bottomDist <= insets.bottom;
boolean isNearLeft = leftDist >= 0 && leftDist <= insets.left;
boolean isNearRight = rightDist >= 0 && rightDist <= insets.right;
boolean isInTopPart = topDist >= 0 && topDist <= insets.top + 10;
boolean isInBottomPart = bottomDist >= 0 && bottomDist <= insets.bottom + 10;
boolean isInLeftPart = leftDist >= 0 && leftDist <= insets.left + 10;
boolean isInRightPart = rightDist >= 0 && rightDist <= insets.right + 10;
if (isNearTop && isInLeftPart || isInTopPart && isNearLeft) {
return Cursor.NW_RESIZE_CURSOR;
}
if (isNearTop && isInRightPart || isInTopPart && isNearRight) {
return Cursor.NE_RESIZE_CURSOR;
}
if (isNearBottom && isInLeftPart || isInBottomPart && isNearLeft) {
return Cursor.SW_RESIZE_CURSOR;
}
if (isNearBottom && isInRightPart || isInBottomPart && isNearRight) {
return Cursor.SE_RESIZE_CURSOR;
}
if (isNearTop) {
return Cursor.N_RESIZE_CURSOR;
}
if (isNearLeft) {
return Cursor.W_RESIZE_CURSOR;
}
if (isNearRight) {
return Cursor.E_RESIZE_CURSOR;
}
if (isNearBottom) {
return Cursor.S_RESIZE_CURSOR;
}
return Cursor.DEFAULT_CURSOR;
}
public void mouseMoved(Point point) {
synchronized (mouseLock) {
if (mousePressedPosition != null)
mouseDragPosition = point;
Bounds bounds = getSelected(point);
int cursorType;
if (bounds == null)
cursorType = Cursor.DEFAULT_CURSOR;
else {
cursorType = Cursor.MOVE_CURSOR;
}
if (selection.getBounds().length == 1) {
boolean resizableX = selection.isResizeableX(diagram);
boolean resizableY = selection.isResizeableY(diagram);
if ((resizableX) && (isRightMove(point)))
cursorType = Cursor.E_RESIZE_CURSOR;
else if ((resizableX) && (isLeftMove(point)))
cursorType = Cursor.W_RESIZE_CURSOR;
else if ((resizableY) && (isTopMove(point)))
cursorType = Cursor.N_RESIZE_CURSOR;
else if ((resizableY) && (isBottomMove(point)))
cursorType = Cursor.S_RESIZE_CURSOR;
else if ((resizableY) && (resizableX)
&& (isRightBottomMove(point)))
cursorType = Cursor.SE_RESIZE_CURSOR;
else if ((resizableY) && (resizableX)
&& (isLeftBottomMove(point)))
cursorType = Cursor.SW_RESIZE_CURSOR;
else if ((resizableY) && (resizableX)
&& (isTopRightMove(point)))
cursorType = Cursor.NE_RESIZE_CURSOR;
else if ((resizableY) && (resizableX) && (isTopLeftMove(point)))
cursorType = Cursor.NW_RESIZE_CURSOR;
}
if (this.cursorType != cursorType) {
this.cursorType = cursorType;
this.setCursor(new Cursor(cursorType));
}
}
repaint();
}
/**
* v1.0.1:修复自定义拖拽区域BUG, 增加边界判断
*/
public void mousePressed(MouseEvent e)
{
Window window = (Window) e.getSource();
JRootPane root = LuckWindowUtil.getRootPane(window);
// 不包含窗体装饰直接返回
if (root == null || root.getWindowDecorationStyle() == JRootPane.NONE)
{
return;
}
if (window != null)
{
window.toFront();
}
// 如果是单击标题栏, 则标记接下来的拖动事件为移动窗口, 判断当前鼠标是否超出边界
if (dragArea.contains(e.getPoint())
&& dragCursor == Cursor.DEFAULT_CURSOR)
{
if(window instanceof JFrame)
{
JFrame frame = (JFrame)window;
// 如果当前窗体是全屏状态则直接返回
if(frame.getExtendedState() == JFrame.MAXIMIZED_BOTH)
{
return;
}
}
// 设置为可以移动并记录当前坐标
isMovingWindow = true;
dragOffsetX = e.getPoint().x;
dragOffsetY = e.getPoint().y;
}
else if(LuckWindowUtil.isResizable(window))
{
dragOffsetX = e.getPoint().x;
dragOffsetY = e.getPoint().y;
dragWidth = window.getWidth();
dragHeight = window.getHeight();
JRootPane rootPane = LuckWindowUtil.getRootPane(window);
if(rootPane != null && LuckWindowUtil.isResizable(window))
{
dragCursor = getCursor(dragWidth, dragHeight, e.getPoint(), rootPane.getInsets());
}
}
}
public int getCursor(int w, int h, Point point, Insets inset)
{
int radius = -1;
//
int startX = inset.left + radius;
int endX = w - inset.right + radius;
int startY = inset.top + radius;
int endY = h - inset.bottom + radius;
if (point.x <= startX && point.y <= startY)
{
// 左上角
return Cursor.NW_RESIZE_CURSOR;
}
else if (point.x >= endX && point.y <= startY)
{
// 右上角
return Cursor.NE_RESIZE_CURSOR;
}
else if (point.x <= startX && point.y >= endY)
{
// 左下
return Cursor.SW_RESIZE_CURSOR;
}
else if(point.x >= endX && point.y >= endY)
{
// 右下
return Cursor.SE_RESIZE_CURSOR;
}
else if(point.x <= startX && point.y > startY && point.y < endY)
{
// 西
return Cursor.W_RESIZE_CURSOR;
}
else if(point.y <= startY && point.x > startX && point.x < endX)
{
// 北
return Cursor.N_RESIZE_CURSOR;
}
else if(point.x >= endX && point.y > startY && point.y < endY)
{
// 东
return Cursor.E_RESIZE_CURSOR;
}
else if(point.y >= endY && point.x > startX && point.x < endX)
{
// 南
return Cursor.S_RESIZE_CURSOR;
}
else
{
return Cursor.DEFAULT_CURSOR;
}
}
/**
* Set file path.
*
* @param textField TextField to set the file path
* @param f File to set.
* @param imagePanel ImagePnel to set the image
* @return true - no problem / false - error occured
*/
private boolean setFilePath(JTextField textField, File f, ImagePanel imagePanel) {
final Cursor defaultCursor = new Cursor(Cursor.DEFAULT_CURSOR);
final Cursor waitCursor = new Cursor(Cursor.WAIT_CURSOR);
String prevText = textField.getText();
try {
if (textField == null || f == null) {
if (textField != null) textField.setText("");
if (imagePanel != null) imagePanel.clear();
if (imagePanel == splashImage) { this.setSplashBackgroundColor(null); }
return false;
}
this.setCursor(waitCursor);
textField.setText(f.getCanonicalPath());
if (imagePanel != null) {
ImageFile imageFile = checkFile(textField);
if (imageFile == null) {
textField.setText("");
if (imagePanel != null) imagePanel.clear();
if (imagePanel == splashImage) { this.setSplashBackgroundColor(null); }
return false;
}
if (!this.isBatchMode()) {
imagePanel.setImage(imageFile.getImage());
imagePanel.setImageFile(imageFile.getFile());
}
selectedDirectory = imageFile.getFile().getParentFile();
if (IOSImageUtil.isNullOrWhiteSpace(outputPath.getText())) {
File g = new File(f.getParentFile(), this.generateAsAssetCatalogs.isSelected() ? this.getResource("string.dir.assets", "Images.xcassets") : this.getResource("string.dir.generate", "generated"));
outputPath.setText(g.getCanonicalPath());
}
if (imagePanel == splashImage) {
Color c = imageFile.getDefaultBackgroundColor();
this.setSplashBackgroundColor(String.format("%2h%2h%2h%2h", c.getAlpha(), c.getRed(), c.getGreen(), c.getBlue()).replace(' ', '0'));
}
}
final JTextField[] paths = { icon6Path, watchPath, carplayPath, macPath, ipadIconPath, ipadLaunchPath };
for (int i = 0; i < paths.length; i++) {
if (paths[i] == textField) {
optionalImages.setSelectedIndex(i);
}
}
} catch (Throwable t) {
handleThrowable(t);
textField.setText("");
if (imagePanel != null) imagePanel.clear();
return false;
} finally {
boolean mainImageSelected = icon7Image.getImage() != null
|| splashImage.getImage() != null
|| watchImage.getImage() != null
|| icon6Image.getImage() != null;
boolean optionImageSelected = ipadIconImage.getImage() != null
|| ipadLaunchImage.getImage() != null
|| macImage.getImage() != null
|| carplayImage.getImage() != null;
forwardButton.setForeground(optionImageSelected ? COLOR_CYAN : COLOR_DARK_GRAY);
// forwardButton.setText(String.format("%s%s", optionImageSelected ? "* " : "", getResource("label.optional.forward.button", "More >>")));
// forwardButton.setBorder(new LineBorder(optionImageSelected ? COLOR_CYAN : COLOR_DARK_GRAY, 1));
backButton.setForeground(mainImageSelected ? COLOR_WINERED : COLOR_DARK_GRAY);
// backButton.setText(String.format("%s%s", getResource("label.optional.back.button", "<< Back"), mainImageSelected ? " *" : ""));
// backButton.setBorder(new LineBorder(mainImageSelected ? COLOR_WINERED : COLOR_DARK_GRAY, 1));
this.setCursor(defaultCursor);
if (!prevText.equals(textField.getText())) {
this.setStorePropertiesRequested(true);
}
}
return true;
}
public LogPanel() {
if (tailer == null) {
setPreferredSize(new Dimension(400, 300));
setLayout(new BorderLayout());
textArea = new JTextArea();
textArea.setEditable(false);
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
JScrollPane scrollPanel = new JScrollPane(textArea);
linesTextField = new JTextField();
linesTextField.setPreferredSize(dim);
linesTextField.setMinimumSize(dim);
linesTextField.setMaximumSize(dim);
linesTextField.setText(String.valueOf(LINES));
JToolBar toolBar = new JToolBar();
toolBar.setRollover(true);
toolBar.add(new ClearLogAction(textArea));
toolBar.add(new ReloadLogAction(textArea, this));
JPanel topPanel = new JPanel();
topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.X_AXIS));
topPanel.add(toolBar);
topPanel.add(Box.createHorizontalStrut(5));
topPanel.add(new JLabel(I18NSupport.getString("logpanel.last.lines")));
topPanel.add(Box.createHorizontalStrut(5));
topPanel.add(linesTextField);
topPanel.add(Box.createHorizontalGlue());
add(topPanel, BorderLayout.NORTH);
add(scrollPanel, BorderLayout.CENTER);
final File log = new File(LOG);
if (!log.exists()) {
try {
new File(LOG_DIR).mkdirs();
boolean created = log.createNewFile();
} catch (IOException ex) {
ex.printStackTrace();
}
}
// read existing text in log
Thread t = new Thread(new Runnable() {
public void run() {
Cursor hourGlassCursor = new Cursor(Cursor.WAIT_CURSOR);
setCursor(hourGlassCursor);
//@todo
//reload(log, textArea);
tailer = new LogFileTailer(log, 1000, false);
tailer.addLogFileTailerListener(LogPanel.this);
tailer.setPriority(Thread.MIN_PRIORITY);
// very consuming !!!
//tailer.start();
Cursor normalCursor = new Cursor(Cursor.DEFAULT_CURSOR);
setCursor(normalCursor);
}
}, "NEXT : " + getClass().getSimpleName());
t.start();
}
}