List of usage examples for java.awt.event MouseMotionListener MouseMotionListener
MouseMotionListener
From source file:Main.java
public static void main(String[] args) throws Exception { if (!SystemTray.isSupported()) { return;// ww w. ja v a 2 s . c o m } SystemTray tray = SystemTray.getSystemTray(); Dimension size = tray.getTrayIconSize(); BufferedImage bi = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB); Graphics g = bi.getGraphics(); g.setColor(Color.blue); g.fillRect(0, 0, size.width, size.height); PopupMenu popup = new PopupMenu(); MenuItem miExit = new MenuItem("Exit"); ActionListener al; al = new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }; miExit.addActionListener(al); popup.add(miExit); TrayIcon ti = new TrayIcon(bi, "System Tray Demo #2"); ti.setPopupMenu(popup); al = new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println(e.getActionCommand()); } }; ti.setActionCommand("My Icon"); ti.addActionListener(al); MouseListener ml = new MouseListener() { public void mouseClicked(MouseEvent e) { System.out.println("Tray icon: Mouse clicked"); } public void mouseEntered(MouseEvent e) { System.out.println("Tray icon: Mouse entered"); } public void mouseExited(MouseEvent e) { System.out.println("Tray icon: Mouse exited"); } public void mousePressed(MouseEvent e) { System.out.println("Tray icon: Mouse pressed"); } public void mouseReleased(MouseEvent e) { System.out.println("Tray icon: Mouse released"); } }; ti.addMouseListener(ml); MouseMotionListener mml = new MouseMotionListener() { public void mouseDragged(MouseEvent e) { System.out.println("Tray icon: Mouse dragged"); } public void mouseMoved(MouseEvent e) { System.out.println("Tray icon: Mouse moved"); } }; ti.addMouseMotionListener(mml); MouseListener[] mouseListeners = ti.getMouseListeners(); for (MouseListener ac : mouseListeners) { ti.removeMouseListener(ac); } tray.add(ti); }
From source file:Main.java
public static void main(String[] args) throws Exception { if (!SystemTray.isSupported()) { return;//from w w w . j av a 2 s . co m } SystemTray tray = SystemTray.getSystemTray(); Dimension size = tray.getTrayIconSize(); BufferedImage bi = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB); Graphics g = bi.getGraphics(); g.setColor(Color.blue); g.fillRect(0, 0, size.width, size.height); PopupMenu popup = new PopupMenu(); MenuItem miExit = new MenuItem("Exit"); ActionListener al; al = new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }; miExit.addActionListener(al); popup.add(miExit); TrayIcon ti = new TrayIcon(bi, "System Tray Demo #2"); ti.setPopupMenu(popup); al = new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println(e.getActionCommand()); } }; ti.setActionCommand("My Icon"); ti.addActionListener(al); MouseListener ml = new MouseListener() { public void mouseClicked(MouseEvent e) { System.out.println("Tray icon: Mouse clicked"); } public void mouseEntered(MouseEvent e) { System.out.println("Tray icon: Mouse entered"); } public void mouseExited(MouseEvent e) { System.out.println("Tray icon: Mouse exited"); } public void mousePressed(MouseEvent e) { System.out.println("Tray icon: Mouse pressed"); } public void mouseReleased(MouseEvent e) { System.out.println("Tray icon: Mouse released"); } }; ti.addMouseListener(ml); MouseMotionListener mml = new MouseMotionListener() { public void mouseDragged(MouseEvent e) { System.out.println("Tray icon: Mouse dragged"); } public void mouseMoved(MouseEvent e) { System.out.println("Tray icon: Mouse moved"); } }; ti.addMouseMotionListener(mml); MouseMotionListener[] mouseMotionListeners = ti.getMouseMotionListeners(); for (MouseMotionListener ac : mouseMotionListeners) { ti.removeMouseMotionListener(ac); } tray.add(ti); }
From source file:Main.java
public static void main(String[] args) throws Exception { if (!SystemTray.isSupported()) { return;/*from w ww . jav a 2 s. c o m*/ } SystemTray tray = SystemTray.getSystemTray(); Dimension size = tray.getTrayIconSize(); BufferedImage bi = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB); Graphics g = bi.getGraphics(); g.setColor(Color.blue); g.fillRect(0, 0, size.width, size.height); PopupMenu popup = new PopupMenu(); MenuItem miExit = new MenuItem("Exit"); ActionListener al; al = new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }; miExit.addActionListener(al); popup.add(miExit); TrayIcon ti = new TrayIcon(bi, "System Tray Demo #2"); ti.setPopupMenu(popup); al = new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println(e.getActionCommand()); } }; ti.setActionCommand("My Icon"); ti.addActionListener(al); MouseListener ml = new MouseListener() { public void mouseClicked(MouseEvent e) { System.out.println("Tray icon: Mouse clicked"); } public void mouseEntered(MouseEvent e) { System.out.println("Tray icon: Mouse entered"); } public void mouseExited(MouseEvent e) { System.out.println("Tray icon: Mouse exited"); } public void mousePressed(MouseEvent e) { System.out.println("Tray icon: Mouse pressed"); } public void mouseReleased(MouseEvent e) { System.out.println("Tray icon: Mouse released"); } }; ti.addMouseListener(ml); MouseMotionListener mml = new MouseMotionListener() { public void mouseDragged(MouseEvent e) { System.out.println("Tray icon: Mouse dragged"); } public void mouseMoved(MouseEvent e) { System.out.println("Tray icon: Mouse moved"); } }; ti.addMouseMotionListener(mml); Image image = ti.getImage(); tray.add(ti); }
From source file:SystemTrayDemo2.java
public static void main(String[] args) { if (!SystemTray.isSupported()) { return;/* w w w.j av a2 s. c o m*/ } SystemTray tray = SystemTray.getSystemTray(); Dimension size = tray.getTrayIconSize(); BufferedImage bi = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB); Graphics g = bi.getGraphics(); g.setColor(Color.blue); g.fillRect(0, 0, size.width, size.height); g.setColor(Color.yellow); int ovalSize = (size.width < size.height) ? size.width : size.height; ovalSize /= 2; g.fillOval(size.width / 4, size.height / 4, ovalSize, ovalSize); try { PopupMenu popup = new PopupMenu(); MenuItem miExit = new MenuItem("Exit"); ActionListener al; al = new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Goodbye"); System.exit(0); } }; miExit.addActionListener(al); popup.add(miExit); TrayIcon ti = new TrayIcon(bi, "System Tray Demo #2", popup); al = new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println(e.getActionCommand()); } }; ti.setActionCommand("My Icon"); ti.addActionListener(al); MouseListener ml; ml = new MouseListener() { public void mouseClicked(MouseEvent e) { System.out.println("Tray icon: Mouse clicked"); } public void mouseEntered(MouseEvent e) { System.out.println("Tray icon: Mouse entered"); } public void mouseExited(MouseEvent e) { System.out.println("Tray icon: Mouse exited"); } public void mousePressed(MouseEvent e) { System.out.println("Tray icon: Mouse pressed"); } public void mouseReleased(MouseEvent e) { System.out.println("Tray icon: Mouse released"); } }; ti.addMouseListener(ml); MouseMotionListener mml; mml = new MouseMotionListener() { public void mouseDragged(MouseEvent e) { System.out.println("Tray icon: Mouse dragged"); } public void mouseMoved(MouseEvent e) { System.out.println("Tray icon: Mouse moved"); } }; ti.addMouseMotionListener(mml); tray.add(ti); } catch (AWTException e) { System.out.println(e.getMessage()); return; } }
From source file:MouseTest.java
public MouseTest() { super();//ww w. jav a2 s .co m final JPopupMenu pop = new JPopupMenu(); pop.add(new JMenuItem("Cut")); pop.add(new JMenuItem("Copy")); pop.add(new JMenuItem("Paste")); pop.addSeparator(); pop.add(new JMenuItem("Select All")); pop.setInvoker(this); MouseListener popup = new MouseListener() { public void mouseClicked(MouseEvent e) { } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mousePressed(MouseEvent e) { if (e.isPopupTrigger()) { showPopup(e); } } public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { showPopup(e); } } private void showPopup(MouseEvent e) { pop.show(e.getComponent(), e.getX(), e.getY()); } }; addMouseListener(popup); MouseListener drawing1 = new MouseListener() { public void mouseClicked(MouseEvent e) { } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mousePressed(MouseEvent e) { color = Color.RED; startX = endX = e.getX(); startY = endY = e.getY(); repaint(); } public void mouseReleased(MouseEvent e) { color = Color.BLACK; repaint(); } }; addMouseListener(drawing1); MouseMotionListener drawing2 = new MouseMotionListener() { public void mouseDragged(MouseEvent e) { endX = e.getX(); endY = e.getY(); repaint(); } public void mouseMoved(MouseEvent e) { } }; addMouseMotionListener(drawing2); }
From source file:ui.frame.KAIQRFrame.java
public KAIQRFrame() { // init frames super("KAI QR Code Generator"); mouseDownCompCoords = null;/* ww w . java 2 s .c om*/ addMouseListener(new MouseListener() { public void mouseReleased(MouseEvent e) { mouseDownCompCoords = null; } public void mousePressed(MouseEvent e) { mouseDownCompCoords = e.getPoint(); } public void mouseExited(MouseEvent e) { } public void mouseEntered(MouseEvent e) { } public void mouseClicked(MouseEvent e) { } }); addMouseMotionListener(new MouseMotionListener() { public void mouseMoved(MouseEvent e) { } public void mouseDragged(MouseEvent e) { Point currCoords = e.getLocationOnScreen(); setLocation(currCoords.x - mouseDownCompCoords.x, currCoords.y - mouseDownCompCoords.y); } }); Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); menuPanel = p.createPanel(Layouts.grid, 5, 1); btnLogOut = b.createButton("Logout"); btnLogOut.setPreferredSize(new Dimension(100, 50)); btnLogOut.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { APICall api = new APICall(); try { JSONObject response = new JSONObject(api.logout(Data.targetURL, Data.sessionKey)); if (response.getString("result").equals("ok")) { UILogin login = new UILogin(); Data.mainFrame.setVisible(false); } } catch (JSONException e1) { e1.printStackTrace(); } } }); menuPanel.add(btnLogOut); cardPanel = p.createPanel(Layouts.card); cardLayout = new CardLayout(); cardPanel.setLayout(cardLayout); getContentPane().setBackground(CustomColor.NavyBlue.returnColor()); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLayout(new BorderLayout()); setLocationRelativeTo(null); add(menuPanel, BorderLayout.WEST); add(cardPanel, BorderLayout.CENTER); pack(); }
From source file:de.tor.tribes.ui.algo.TimeFrameVisualizer.java
/** Creates new form TimeFrameVisualizer */ public TimeFrameVisualizer() { initComponents();/* w w w. j a v a 2s. co m*/ try { STROKED = new BufferedImage(3, 3, BufferedImage.TYPE_INT_RGB); Graphics2D g2d = STROKED.createGraphics(); g2d.setColor(Constants.DS_BACK_LIGHT); g2d.fillRect(0, 0, 3, 3); g2d.setColor(Constants.DS_BACK); g2d.drawLine(0, 2, 2, 0); g2d.dispose(); DAILY_START_FRAME_FILL = new BufferedImage(3, 3, BufferedImage.TYPE_INT_RGB); g2d = DAILY_START_FRAME_FILL.createGraphics(); g2d.setColor(Color.CYAN); g2d.fillRect(0, 0, 3, 3); g2d.setColor(Color.BLUE); g2d.drawLine(0, 2, 2, 0); g2d.dispose(); EXACT_START_FRAME_FILL = new BufferedImage(3, 3, BufferedImage.TYPE_INT_RGB); g2d = EXACT_START_FRAME_FILL.createGraphics(); g2d.setColor(Color.CYAN); g2d.fillRect(0, 0, 3, 3); g2d.dispose(); ONE_DAY_START_FRAME_FILL = new BufferedImage(3, 3, BufferedImage.TYPE_INT_RGB); g2d = ONE_DAY_START_FRAME_FILL.createGraphics(); g2d.setColor(Color.CYAN); g2d.fillRect(0, 0, 3, 3); g2d.setColor(Color.BLUE); g2d.drawLine(1, 0, 1, 2); g2d.dispose(); ARRIVE_FRAME_FILL = new BufferedImage(3, 3, BufferedImage.TYPE_INT_RGB); g2d = ARRIVE_FRAME_FILL.createGraphics(); g2d.setColor(Color.RED); g2d.fillRect(0, 0, 3, 3); g2d.setColor(Color.BLACK); g2d.drawLine(0, 2, 2, 0); g2d.dispose(); } catch (Exception e) { } popupInfo = new HashMap<String, Object>(); addMouseMotionListener(new MouseMotionListener() { @Override public void mouseDragged(MouseEvent e) { } @Override public void mouseMoved(MouseEvent e) { repaint(); } }); addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { fireClickEvent(e); } @Override public void mousePressed(MouseEvent e) { } @Override public void mouseReleased(MouseEvent e) { } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } }); }
From source file:vteaexploration.plottools.panels.XYChartPanel.java
public void process(int x, int y, int l, String xText, String yText, String lText) { chartPanel = createChart(x, y, l, xText, yText, lText, imageGateOutline); JFrame f = new JFrame(title); f.setTitle(title);//from w w w . j a v a 2 s. com f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setLayout(new BorderLayout(0, 5)); f.add(chartPanel, BorderLayout.CENTER); chartPanel.setOpaque(false); chartPanel.setMouseWheelEnabled(false); chartPanel.setDomainZoomable(false); chartPanel.setRangeZoomable(false); chartPanel.setPreferredSize(new Dimension(550, 485)); chartPanel.setBackground(new Color(0, 0, 0, 0)); chartPanel.revalidate(); chartPanel.repaint(); //chartPanel.set chartPanel.addChartMouseListener(new ChartMouseListener() { @Override public void chartMouseClicked(ChartMouseEvent cme) { chartPanel.getParent().repaint(); } @Override public void chartMouseMoved(ChartMouseEvent cme) { } }); chartPanel.addMouseMotionListener(new MouseMotionListener() { @Override public void mouseDragged(MouseEvent e) { chartPanel.getParent().repaint(); } @Override public void mouseMoved(MouseEvent e) { chartPanel.getParent().repaint(); } }); chartPanel.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { } @Override public void mousePressed(MouseEvent e) { //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void mouseReleased(MouseEvent e) { //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void mouseEntered(MouseEvent e) { //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public void mouseExited(MouseEvent e) { //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }); f.pack(); }
From source file:es.emergya.ui.gis.ControlPanel.java
public ControlPanel(final CustomMapView view) { super(new FlowLayout(FlowLayout.LEADING, 12, 0)); this.view = view; // Posicion: panel con un label de icono y un textfield JPanel posPanel = new JPanel(); posPanel.setOpaque(true);//w ww .ja va 2 s . c o m posPanel.setVisible(true); JLabel mouseLocIcon = new JLabel(LogicConstants.getIcon("map_icon_coordenadas")); posPanel.add(mouseLocIcon); final JTextField posField = new JTextField(15); posField.setEditable(false); posField.setBorder(null); posField.setForeground(UIManager.getColor("Label.foreground")); posField.setFont(UIManager.getFont("Label.font")); posPanel.add(posField); view.addMouseMotionListener(new MouseMotionListener() { @Override public void mouseMoved(MouseEvent e) { LatLon ll = ((ICustomMapView) e.getSource()).getLatLon(e.getX(), e.getY()); String position = ""; String format = LogicConstants.get("FORMATO_COORDENADAS_MAPA", "UTM"); if (format.equals(LogicConstants.COORD_UTM)) { UTM u = new UTM(LogicConstants.getInt("ZONA_UTM")); EastNorth en = u.latlon2eastNorth(ll); position = String.format("x: %.1f y: %.1f", en.getX(), en.getY()); } else { position = String.format("Lat: %.4f Lon: %.4f", ll.lat(), ll.lon()); } posField.setText(position); validate(); } @Override public void mouseDragged(MouseEvent e) { } }); posPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); add(posPanel); // Panel de centrado: label, desplegable y parte cambiante JPanel centerPanel = new JPanel(); centerPanel.add(new JLabel(i18n.getString("map.centerIn"))); centerOptions = new JComboBox(new String[] { i18n.getString("map.street"), i18n.getString("map.resource"), i18n.getString("map.incidence"), i18n.getString("map.location") }); centerPanel.add(centerOptions); centerData = new JPanel(new CardLayout()); centerPanel.add(centerData); JPanel centerStreet = new JPanel(); street = new JTextField(30); street.setName(i18n.getString("map.street")); autocompleteKeyListener = new AutocompleteKeyListener(street); street.addKeyListener(autocompleteKeyListener); street.addActionListener(this); centerStreet.add(street); centerData.add(centerStreet, i18n.getString("map.street")); JPanel centerResource = new JPanel(); resources = new JComboBox(avaliableResources); resources.setName(i18n.getString("map.resource")); resources.setPrototypeDisplayValue("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); resources.addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { isComboResourcesShowing = true; } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { isComboResourcesShowing = false; } @Override public void popupMenuCanceled(PopupMenuEvent e) { // view.repaint(); } }); centerResource.add(resources); centerData.add(centerResource, i18n.getString("map.resource")); centerResource = new JPanel(); incidences = new JComboBox(avaliableIncidences); incidences.setPrototypeDisplayValue("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); incidences.setName(i18n.getString("map.incidence")); incidences.addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { isComboIncidencesShowing = true; } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { isComboIncidencesShowing = false; } @Override public void popupMenuCanceled(PopupMenuEvent e) { } }); centerResource.add(incidences); centerData.add(centerResource, i18n.getString("map.incidence")); JPanel centerLocation = new JPanel(); cx = new JTextField(10); cx.setName("x"); cx.addActionListener(this); centerLocation.add(cx); cy = new JTextField(10); cy.setName("y"); cy.addActionListener(this); centerLocation.add(cy); centerData.add(centerLocation, i18n.getString("map.location")); centerOptions.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { ((CardLayout) centerData.getLayout()).show(centerData, (String) e.getItem()); } }); JButton centerButton = new JButton(i18n.getString("map.center")); centerButton.addActionListener(this); centerPanel.add(centerButton); add(centerPanel); }
From source file:de.tor.tribes.ui.panels.MinimapPanel.java
/** * Creates new form MinimapPanel//from w w w . jav a 2 s . com */ MinimapPanel() { initComponents(); setSize(300, 300); mMinimapListeners = new LinkedList<>(); mToolChangeListeners = new LinkedList<>(); setCursor(ImageManager.getCursor(iCurrentCursor)); mScreenshotPanel = new ScreenshotPanel(); minimapButtons.put(ID_MINIMAP, new Rectangle(2, 2, 26, 26)); minimapButtons.put(ID_ALLY_CHART, new Rectangle(30, 2, 26, 26)); minimapButtons.put(ID_TRIBE_CHART, new Rectangle(60, 2, 26, 26)); try { minimapIcons.put(ID_MINIMAP, ImageIO.read(new File("./graphics/icons/minimap.png"))); minimapIcons.put(ID_ALLY_CHART, ImageIO.read(new File("./graphics/icons/ally_chart.png"))); minimapIcons.put(ID_TRIBE_CHART, ImageIO.read(new File("./graphics/icons/tribe_chart.png"))); } catch (Exception ignored) { } jPanel1.add(mScreenshotPanel); rVisiblePart = new Rectangle(ServerSettings.getSingleton().getMapDimension()); zoomed = false; MarkerManager.getSingleton().addManagerListener(this); TagManager.getSingleton().addManagerListener(this); MinimapRepaintThread.getSingleton().setVisiblePart(rVisiblePart); if (!GlobalOptions.isMinimal()) { MinimapRepaintThread.getSingleton().start(); } addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { if (!showControls && e.getButton() != MouseEvent.BUTTON1) { //show controls Point p = e.getPoint(); p.translate(-5, -5); showControls(p); return; } if (!showControls && iCurrentView == ID_MINIMAP) { Point p = mousePosToMapPosition(e.getX(), e.getY()); DSWorkbenchMainFrame.getSingleton().centerPosition(p.getX(), p.getY()); MapPanel.getSingleton().getMapRenderer().initiateRedraw(MapRenderer.ALL_LAYERS); if (MinimapZoomFrame.getSingleton().isVisible()) { MinimapZoomFrame.getSingleton().toFront(); } } else { if (minimapButtons.get(ID_MINIMAP).contains(e.getPoint())) { iCurrentView = ID_MINIMAP; mBuffer = null; showControls = false; MinimapRepaintThread.getSingleton().update(); } else if (minimapButtons.get(ID_ALLY_CHART).contains(e.getPoint())) { iCurrentView = ID_ALLY_CHART; lastHash = 0; showControls = false; updateComplete(); } else if (minimapButtons.get(ID_TRIBE_CHART).contains(e.getPoint())) { iCurrentView = ID_TRIBE_CHART; lastHash = 0; showControls = false; updateComplete(); } } } @Override public void mousePressed(MouseEvent e) { if (iCurrentView != ID_MINIMAP) { return; } if (iCurrentCursor == ImageManager.CURSOR_SHOT || iCurrentCursor == ImageManager.CURSOR_ZOOM) { iXDown = e.getX(); iYDown = e.getY(); } } @Override public void mouseReleased(MouseEvent e) { if (iCurrentView != ID_MINIMAP) { return; } if (rDrag == null) { return; } if (iCurrentCursor == ImageManager.CURSOR_SHOT) { try { BufferedImage i = MinimapRepaintThread.getSingleton().getImage(); double widthFactor = ((double) ServerSettings.getSingleton().getMapDimension().width) / getWidth(); double heightFactor = ((double) ServerSettings.getSingleton().getMapDimension().height) / getHeight(); int x = (int) Math.rint(widthFactor * rDrag.getX()); int y = (int) Math.rint(heightFactor * rDrag.getY()); int w = (int) Math.rint(widthFactor * (rDrag.getWidth() - rDrag.getX())); int h = (int) Math.rint(heightFactor * (rDrag.getHeight() - rDrag.getY())); BufferedImage sub = i.getSubimage(x, y, w, h); mScreenshotPanel.setBuffer(sub); jPanel1.setSize(mScreenshotPanel.getSize()); jPanel1.setPreferredSize(mScreenshotPanel.getSize()); jPanel1.setMinimumSize(mScreenshotPanel.getSize()); jPanel1.setMaximumSize(mScreenshotPanel.getSize()); jScreenshotPreview.pack(); jScreenshotControl.pack(); jScreenshotPreview.setVisible(true); jScreenshotControl.setVisible(true); } catch (Exception ie) { logger.error("Failed to initialize mapshot", ie); } } else if (iCurrentCursor == ImageManager.CURSOR_ZOOM) { if (!zoomed) { Rectangle mapDim = ServerSettings.getSingleton().getMapDimension(); double widthFactor = ((double) mapDim.width) / getWidth(); double heightFactor = ((double) mapDim.height) / getHeight(); int x = (int) Math.rint(widthFactor * rDrag.getX() + mapDim.getMinX()); int y = (int) Math.rint(heightFactor * rDrag.getY() + mapDim.getMinY()); int w = (int) Math.rint(widthFactor * (rDrag.getWidth() - rDrag.getX())); if (w >= 10) { rVisiblePart = new Rectangle(x, y, w, w); MinimapRepaintThread.getSingleton().setVisiblePart(rVisiblePart); redraw(); zoomed = true; } } else { rVisiblePart = new Rectangle(ServerSettings.getSingleton().getMapDimension()); MinimapRepaintThread.getSingleton().setVisiblePart(rVisiblePart); redraw(); zoomed = false; } MinimapZoomFrame.getSingleton().setVisible(false); } iXDown = 0; iYDown = 0; rDrag = null; } @Override public void mouseEntered(MouseEvent e) { if (iCurrentView != ID_MINIMAP) { return; } switch (iCurrentCursor) { case ImageManager.CURSOR_ZOOM: { MinimapZoomFrame.getSingleton().setVisible(true); } } } @Override public void mouseExited(MouseEvent e) { if (MinimapZoomFrame.getSingleton().isVisible()) { MinimapZoomFrame.getSingleton().setVisible(false); } iXDown = 0; iYDown = 0; rDrag = null; } }); addMouseMotionListener(new MouseMotionListener() { @Override public void mouseDragged(MouseEvent e) { if (iCurrentView != ID_MINIMAP) { return; } switch (iCurrentCursor) { case ImageManager.CURSOR_MOVE: { Point p = mousePosToMapPosition(e.getX(), e.getY()); DSWorkbenchMainFrame.getSingleton().centerPosition(p.x, p.y); rDrag = null; break; } case ImageManager.CURSOR_SHOT: { rDrag = new Rectangle2D.Double(iXDown, iYDown, e.getX(), e.getY()); break; } case ImageManager.CURSOR_ZOOM: { rDrag = new Rectangle2D.Double(iXDown, iYDown, e.getX(), e.getY()); break; } } } @Override public void mouseMoved(MouseEvent e) { if (iCurrentView == ID_MINIMAP) { switch (iCurrentCursor) { case ImageManager.CURSOR_ZOOM: { if (!MinimapZoomFrame.getSingleton().isVisible()) { MinimapZoomFrame.getSingleton().setVisible(true); } int mapWidth = (int) ServerSettings.getSingleton().getMapDimension().getWidth(); int mapHeight = (int) ServerSettings.getSingleton().getMapDimension().getHeight(); int x = (int) Math.rint((double) mapWidth / (double) getWidth() * (double) e.getX()); int y = (int) Math.rint((double) mapHeight / (double) getHeight() * (double) e.getY()); MinimapZoomFrame.getSingleton().updatePosition(x, y); break; } default: { if (MinimapZoomFrame.getSingleton().isVisible()) { MinimapZoomFrame.getSingleton().setVisible(false); } } } } Point location = minimapButtons.get(ID_MINIMAP).getLocation(); location.translate(-2, -2); if (!new Rectangle(location.x, location.y, 88, 30).contains(e.getPoint())) { //hide controls showControls = false; repaint(); } } }); addMouseWheelListener(new MouseWheelListener() { @Override public void mouseWheelMoved(MouseWheelEvent e) { if (iCurrentView != ID_MINIMAP) { return; } iCurrentCursor += e.getWheelRotation(); if (iCurrentCursor == ImageManager.CURSOR_DEFAULT + e.getWheelRotation()) { if (e.getWheelRotation() < 0) { iCurrentCursor = ImageManager.CURSOR_SHOT; } else { iCurrentCursor = ImageManager.CURSOR_MOVE; } } else if (iCurrentCursor < ImageManager.CURSOR_MOVE) { iCurrentCursor = ImageManager.CURSOR_DEFAULT; } else if (iCurrentCursor > ImageManager.CURSOR_SHOT) { iCurrentCursor = ImageManager.CURSOR_DEFAULT; } if (iCurrentCursor != ImageManager.CURSOR_ZOOM) { if (MinimapZoomFrame.getSingleton().isVisible()) { MinimapZoomFrame.getSingleton().setVisible(false); } } else { MinimapZoomFrame.getSingleton().setVisible(true); } setCurrentCursor(iCurrentCursor); } }); }