Java Code Examples for javax.swing.JFrame#setCursor()

The following examples show how to use javax.swing.JFrame#setCursor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CursorController.java    From audiveris with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Launch the provided runnable with a busy cursor displayed if processing does not
 * complete within delay.
 *
 * @param runnable the processing to perform
 */
public static void launchWithDelayedCursor (Runnable runnable)
{
    final JFrame frame = OmrGui.getApplication().getMainFrame();
    final TimerTask timerTask = new TimerTask()
    {
        @Override
        public void run ()
        {
            frame.setCursor(busyCursor);
        }
    };

    Timer timer = new Timer();

    try {
        timer.schedule(timerTask, delay);
        runnable.run(); // Here is the real stuff
    } finally {
        timer.cancel();
        frame.setCursor(defaultCursor);
    }
}
 
Example 2
Source File: MapCanvas.java    From EdgeSim with MIT License 5 votes vote down vote up
public void mouseEntered(MouseEvent e) { // Mouse to enter
	if(Signal.Button_BS_Click){
		JFrame jframe = (JFrame) getRootPane().getParent();
		jframe.setCursor(Toolkit.getDefaultToolkit().createCustomCursor(
				new ImageIcon("src/main/resources/images/BS.png").getImage(),
				new Point(10, 20), "stick"));
		
	}
}
 
Example 3
Source File: CHelpManager.java    From binnavi with Apache License 2.0 5 votes vote down vote up
/**
 * Starts context-sensitive mode in a given window.
 *
 * @param window The window in which context-sensitive mode is activated.
 */
public void start(final JFrame window)
{
	if (m_activeWindow != window) 
	{
		window.getGlassPane().setVisible(true);
		window.getGlassPane().addMouseListener(m_listener);
		window.setCursor(m_helpCursor);

		m_activeWindow = window;
	}
}
 
Example 4
Source File: MapCanvas.java    From EdgeSim with MIT License 4 votes vote down vote up
@SuppressWarnings("deprecation")
		public void mousePressed(MouseEvent e) { // Press the left mouse button
			if(e.getButton() == MouseEvent.BUTTON1){
				if (Signal.Button_BS_Click) {
					String radiusText = controller.getOperationPanel().getRadiusText().getText().trim();
					String cacheSizeText = controller.getOperationPanel().getCacheSizeText().getText().trim();
					if(!radiusText.equals("") && !cacheSizeText.equals("") &&radiusText!=null&&cacheSizeText !=null){
						int radius = Integer.parseInt(radiusText);
						int cacheSize = (int)(Float.parseFloat(cacheSizeText)*1024*1024);
						
						System.out.println(cacheSize);
						
						controller.getWirelessNetworkGroup().BS.addWirelessNetwork(new BaseStation(new Point2D.Double(e.getX(), e.getY()),true,cacheSize,radius));
						controller.appendLog(null,"Add base station��Coordinates("+e.getX()+","+e.getY()+")  Cache size "+controller.getOperationPanel().getCacheSizeText().getText(),null);
					}else{
						JOptionPane.showMessageDialog(null, "Radius or Cache size can not be empty", "Prompt", JOptionPane.ERROR_MESSAGE);
					}
				}else if(e.getSource().equals(clear)){
					controller.clearAll();
				}else if(e.getSource().equals(delete) && selectedNetwork !=null){
		
					controller.getWirelessNetworkGroup().BS.removeNetwork(selectedNetwork);
					selectedNetwork = null;

				}else if(e.getSource().equals(configure) && selectedNetwork !=null){
					NetworkAdjust wirelessNetworkAdjust = new NetworkAdjust(selectedNetwork);
					wirelessNetworkAdjust.setNetworkAdjust(wirelessNetworkAdjust);
				}
			}
			if(e.getButton() == MouseEvent.BUTTON3){
				JFrame jframe = (JFrame) getRootPane().getParent();
				if(Signal.Button_BS_Click){
					jframe.setCursor(Cursor.DEFAULT_CURSOR);
					controller.getOperationPanel().getAddBS().setText(Operator.addBSName);
					Signal.Button_BS_Click = false;
				}else{
					Iterator<WirelessNetwork> it = controller.getWirelessNetworkGroup().BS.getIterator();
					double temp = Double.POSITIVE_INFINITY;
					selectedNetwork = null;
					while(it.hasNext()){
						WirelessNetwork network = it.next();
						double x = network.getLocation().getX();
						double y = network.getLocation().getY();

						double distance  = Math.sqrt(Math.pow((e.getX() - x), 2) + Math.pow((e.getY() - y), 2));
						if(distance < temp && distance <= network.getRadius()){
							temp = distance;
							selectedNetwork = network;
						}
					}
					if(selectedNetwork != null){
						popupMenu.removeAll();
						popupMenu.add(delete);
						popupMenu.add(configure);
				        popupMenu.show(e.getComponent(),e.getX(),e.getY());
//				        System.out.println("�����ʱ"+wirelessNetwork.getNumber());
					}else{
						popupMenu.removeAll();
						popupMenu.add(clear);
				        popupMenu.show(e.getComponent(),e.getX(),e.getY());
					}	
				}
			}
		}
 
Example 5
Source File: MapCanvas.java    From EdgeSim with MIT License 4 votes vote down vote up
@SuppressWarnings("deprecation")
public void mouseExited(MouseEvent e) { // Mouse to exit
	JFrame jframe = (JFrame) getRootPane().getParent();
	jframe.setCursor(Cursor.DEFAULT_CURSOR);
}
 
Example 6
Source File: SplashWindow.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
public SplashWindow() {
	window = new JFrame() {
		/** default serial id. */
		private static final long serialVersionUID = 1L;

		@Override
		public void paint(Graphics g) {

			// Draw splash image and superimposed text
			Graphics2D g2d = (Graphics2D) g;
			g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
			g2d.drawImage(splashImage, 0, 0, this);
			g2d.setColor(Color.WHITE);
			g2d.setFont(new Font("SansSerif", Font.PLAIN, 36));
			g2d.drawString(MSP_STRING, 30, 60);
			g2d.setFont(versionStringFont);
			g2d.drawString(VERSION_STRING, splashImage.getWidth(this) - versionStringWidth - 16, 24);
		}
	};

	splashImage = ImageLoader.getImage(IMAGE_NAME);
	ImageIcon splashIcon = new ImageIcon(splashImage);
	width = splashIcon.getIconWidth();
	height = splashIcon.getIconHeight();
	window.setSize(width, height);

	// Center the splash window on the screen.
	Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
	Dimension windowSize = new Dimension(width, height);
	window.setLocation(((screenSize.width - windowSize.width) / 2), ((screenSize.height - windowSize.height) / 2));

	window.setBackground(Color.black);

	window.setUndecorated(true);

	// Set icon image for window.
	setIconImage();

	// Set cursor style.
	window.setCursor(new Cursor(Cursor.WAIT_CURSOR));

	// Display the splash window.
	window.setVisible(true);
}