Java examples for Swing:Cursor
Given two sides (at most one can be Null) returns the appropriate type of cursor for resizing.
/*// w ww . j av a 2s.c om * Copyright (C) 2011 Trilarion * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.awt.Color; import java.awt.Component; import java.awt.Cursor; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.GraphicsConfiguration; import java.awt.GraphicsEnvironment; import java.awt.Image; import java.awt.Insets; import java.awt.Rectangle; import java.awt.Shape; import java.awt.Toolkit; import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.geom.Path2D; import java.awt.geom.Rectangle2D; import java.awt.geom.RoundRectangle2D; import javax.swing.AbstractAction; import javax.swing.Action; import javax.swing.ActionMap; import javax.swing.ImageIcon; import javax.swing.InputMap; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.KeyStroke; import javax.swing.border.Border; public class Main{ /** * Given two sides (at most one can be Null) returns the appropriate type of * cursor for resizing. * * @param vertical North or South * @param horizontal East or West * @return */ public static int getResizeCursorForSide(WindowSide vertical, WindowSide horizontal) { int type = -1; switch (vertical) { case North: switch (horizontal) { case East: // N+E type = Cursor.NE_RESIZE_CURSOR; break; case West: // N+W type = Cursor.NW_RESIZE_CURSOR; break; case None: // N alone type = Cursor.N_RESIZE_CURSOR; break; } break; case South: switch (horizontal) { case East: // S+E type = Cursor.SE_RESIZE_CURSOR; break; case West: // S+W type = Cursor.SW_RESIZE_CURSOR; break; case None: // S alone type = Cursor.S_RESIZE_CURSOR; break; } break; case None: // assume that neither North nor South, most probably Null switch (horizontal) { case East: // E alone type = Cursor.E_RESIZE_CURSOR; break; case West: // W alone type = Cursor.W_RESIZE_CURSOR; break; } break; } return type; } }