List of usage examples for java.awt.event MouseWheelListener MouseWheelListener
MouseWheelListener
From source file:Main.java
public Main() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(200, 200);/*from w w w . j a v a 2s. com*/ JTextArea textArea = new JTextArea(); textArea.addMouseWheelListener(new MouseWheelListener() { public void mouseWheelMoved(MouseWheelEvent e) { if (e.getWheelRotation() < 0) { System.out.println("Up... " + e.getWheelRotation()); } else { System.out.println("Down... " + e.getWheelRotation()); } System.out.println("ScrollAmount: " + e.getScrollAmount()); if (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) { System.out.println("MouseWheelEvent.WHEEL_UNIT_SCROLL"); } if (e.getScrollType() == MouseWheelEvent.WHEEL_BLOCK_SCROLL) { System.out.println("MouseWheelEvent.WHEEL_BLOCK_SCROLL"); } } }); getContentPane().add(textArea); }
From source file:MouseWheelTest.java
public MouseWheelTest() { super();//from w w w .j a v a 2 s. c om final Container contentPane = getContentPane(); MouseWheelListener listener = new MouseWheelListener() { int colorCounter; private static final int UP = 1; private static final int DOWN = 2; public void mouseWheelMoved(MouseWheelEvent e) { int count = e.getWheelRotation(); int direction = (Math.abs(count) > 0) ? UP : DOWN; changeBackground(direction); } private void changeBackground(int direction) { contentPane.setBackground(colors[colorCounter]); if (direction == UP) { colorCounter++; } else { --colorCounter; } if (colorCounter == colors.length) { colorCounter = 0; } else if (colorCounter < 0) { colorCounter = colors.length - 1; } } }; contentPane.addMouseWheelListener(listener); }
From source file:Main.java
public Main(String filename) { setDefaultCloseOperation(EXIT_ON_CLOSE); try {/* www . j ava 2s .c o m*/ bi = ImageIO.read(new File(filename)); } catch (Exception e) { e.printStackTrace(); } sizeToZoom(); addMouseWheelListener(new MouseWheelListener() { public void mouseWheelMoved(MouseWheelEvent e) { int steps = e.getWheelRotation(); zoom += steps; sizeToZoom(); } }); }
From source file:Main.java
/** * Creates a JSlider built/* w w w. ja va 2s . c o m*/ * using a {@link DefaultBoundedRangeModel} and * containing a {@link MouseWheelListener} * and some usual default settings * * @param model * @return the corresponding {@link JSlider} */ public static JSlider createJSlider(final BoundedRangeModel model) { final JSlider slider = new JSlider(model); slider.addMouseWheelListener(new MouseWheelListener() { @Override public void mouseWheelMoved(MouseWheelEvent e) { slider.setValue(-e.getWheelRotation() * model.getMaximum() / 100 + model.getValue()); } }); slider.setPaintTicks(true); slider.setPaintLabels(true); // slider.setMajorTickSpacing(model.getMaximum()/2); // slider.setMinorTickSpacing(model.getMaximum()/10); // slider.setSnapToTicks(true); return slider; }
From source file:org.fhaes.fhrecorder.view.GraphPanel.java
/** * Constructor for the Graphics Panel. Sets up layout and settings of all components. *//* w w w . ja v a 2s.co m*/ public GraphPanel() { data = FileController.getYearSummaryList(); setLayout(new MigLayout("", "[grow,right]", "[fill][300px,grow,fill][][]")); JButton customizeButton = new JButton("Customize"); customizeButton.setIcon(Builder.getImageIcon("configure.png")); customizeButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { showCustomizeWindow(); } }); zoomOutButton = new JButton(""); zoomOutButton.setIcon(Builder.getImageIcon("zoom_out.png")); zoomOutButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { setZoomLevel(zoomLevel + 1); } }); add(zoomOutButton, "flowx,cell 0 0"); zoomInButton = new JButton(""); zoomInButton.setIcon(Builder.getImageIcon("zoom_in.png")); zoomInButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { setZoomLevel(zoomLevel - 1); } }); add(zoomInButton, "cell 0 0"); add(customizeButton, "cell 0 0,alignx right"); rigidArea = Box.createRigidArea(new Dimension(20, 20)); rigidArea.setMaximumSize(new Dimension(200, 20)); rigidArea.setMinimumSize(new Dimension(1, 20)); add(rigidArea, "cell 0 1"); colorPane = new ColorBarGraph(data); colorPane.addMouseWheelListener(new MouseWheelListener() { @Override public void mouseWheelMoved(MouseWheelEvent e) { int notches = e.getWheelRotation(); setZoomLevel(zoomLevel + notches); } }); add(colorPane, "cell 0 1,growx"); scrollBar = new JScrollBar(); scrollBar.setMinimum(0); scrollBar.setMaximum(data.size()); scrollBar.addAdjustmentListener(new AdjustmentListener() { @Override public void adjustmentValueChanged(AdjustmentEvent event) { setChartsFirstCategoryIndex(event.getValue()); } }); overlayPane = new GraphSummaryOverlay(data); overlayPane.addMouseWheelListener(new MouseWheelListener() { @Override public void mouseWheelMoved(MouseWheelEvent e) { int notches = e.getWheelRotation(); setZoomLevel(zoomLevel + notches); } }); add(overlayPane, "cell 0 2,growx"); scrollBar.setOrientation(JScrollBar.HORIZONTAL); add(scrollBar, "cell 0 3,growx"); refreshCharts(false); }
From source file:com.anrisoftware.prefdialog.miscswing.multichart.freechart.FreechartXYChart.java
private Object resolveObject() { this.p = new PropertyChangeSupport(this); this.mouseScrollListener = new MouseWheelListener() { @Override//from ww w. j av a 2 s . c o m public void mouseWheelMoved(MouseWheelEvent e) { if (model == null) { return; } if (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) { int offset = model.getOffset(); setOffset(offset + e.getUnitsToScroll()); } } }; this.modelListener = new ChartModelListener() { @Override public void chartChanged(ChartModelEvent e) { updateChart(e); } }; return this; }
From source file:com.nbt.TileCanvas.java
public TileCanvas(final World world) { Validate.notNull(world, "world must not be null"); this.world = world; setFocusable(true);// w w w . ja v a 2s.c o m addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { int tileWidth = calculateWidth(); setTileWidth(tileWidth); int tileHeight = calculateHeight(); setTileHeight(tileHeight); save(); } }); addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { TileCanvas.this.keyPressed(e); } }); addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { Point point = e.getPoint(); int x = pixelsToTile(point.x); int z = pixelsToTile(point.y); int tileX = x + getTileX(); int tileZ = z + getTileZ(); int y = getAltitude(); Block block = world.getBlock(tileX, y, tileZ); blockClicked(block); } }); addMouseWheelListener(new MouseWheelListener() { @Override public void mouseWheelMoved(MouseWheelEvent e) { int amount = e.getWheelRotation(); int altitude = getAltitude(); setAltitude(amount + altitude); updateXYZ(); doRepaint(); save(); } }); addMouseMotionListener(new MouseMotionAdapter() { @Override public void mouseMoved(MouseEvent e) { updateXYZ(); } }); new MouseDragAndDrop(this) { private int tileX, tileZ; @Override public void selected(MouseEvent e) { this.tileX = getTileX(); this.tileZ = getTileZ(); } @Override public void dragged(MouseEvent e) { MouseEvent startEvent = getStartEvent(); Point startPt = startEvent.getPoint(); Point releasePt = e.getPoint(); int x = tileX + (pixelsToTile(startPt.x) - pixelsToTile(releasePt.x)); int z = tileZ + (pixelsToTile(startPt.y) - pixelsToTile(releasePt.y)); setTileX(x); setTileZ(z); updateXYZ(); doRepaint(); } @Override public void dropped(MouseEvent press, MouseEvent release) { // Point startPt = press.getPoint(); // Point releasePt = release.getPoint(); // int x = getTileX() + pixelsToTile(startPt.x - releasePt.x); // int z = getTileZ() + pixelsToTile(startPt.y - releasePt.y); // setTileX(x); // setTileZ(z); // // updateXYZ(); // doRepaint(); save(); } }.install(); setLayout(null); hud = new HUD(); int width = 200, height = 200; hud.setSize(width, height); add(hud); }
From source file:api3.transform.PlotWave.java
private MouseWheelListener addZoomWheel() { return new MouseWheelListener() { private void zoomChartAxis(ChartPanel chartP, boolean increase) { int width = chartP.getMaximumDrawWidth() - chartP.getMinimumDrawWidth(); int height = chartP.getMaximumDrawHeight() - chartP.getMinimumDrawWidth(); if (increase) { chartP.zoomInDomain(width / 2, height / 2); } else { chartP.zoomOutDomain(width / 2, height / 2); }/*w w w . j ava 2 s . c o m*/ lastValue = SLIDER_DEFAULT_VALUE; slider.setValue(lastValue); } public synchronized void decreaseZoom(JComponent chart, boolean saveAction) { ChartPanel ch = (ChartPanel) chart; zoomChartAxis(ch, false); } public synchronized void increaseZoom(JComponent chart, boolean saveAction) { ChartPanel ch = (ChartPanel) chart; zoomChartAxis(ch, true); } @Override public void mouseWheelMoved(MouseWheelEvent e) { if (e.getScrollType() != MouseWheelEvent.WHEEL_UNIT_SCROLL) { return; } if (e.getWheelRotation() < 0) { increaseZoom((ChartPanel) e.getComponent(), true); } else { decreaseZoom((ChartPanel) e.getComponent(), true); } } }; }
From source file:com.epiq.bitshark.ui.TimeDomainPanel.java
/** * Initializes the graph//w w w . j av a 2s .co m */ private void initGraph() { dataset = new XYSeriesCollection(); realSeries = new BasicSeries("Real"); imaginarySeries = new BasicSeries("Imaginary"); dataset.addSeries(realSeries); dataset.addSeries(imaginarySeries); graph = ChartFactory.createXYLineChart(null, // no title "", // no x-axis label "", // no y-axis label dataset, // data PlotOrientation.VERTICAL, false, // no legend false, // no tooltips false // no URLs ); graph.setBorderVisible(false); graph.setPadding(new RectangleInsets(-5, -5, 0, -7)); graph.setBackgroundPaint(null); graph.setAntiAlias(true); plot = (XYPlot) graph.getPlot(); plot.setBackgroundAlpha(0.0f); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); plot.setAxisOffset(new RectangleInsets(0, 0, 0, 0)); plot.setDomainCrosshairVisible(false); plot.setRangeCrosshairVisible(false); XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setBaseShapesVisible(false); renderer.setBaseShapesFilled(true); renderer.setSeriesPaint(0, I_COLOR); renderer.setSeriesPaint(1, Q_COLOR); } // X-axis setup plot.getDomainAxis().setAutoRange(false); plot.getDomainAxis().setVisible(true); plot.getDomainAxis().setRange(0, FMCUartClient.BLOCK_SIZE - 1); // Y-axis setup plot.getRangeAxis().setAutoRange(false); plot.getRangeAxis().setVisible(true); plot.getRangeAxis().setUpperBound(Math.pow(2, 13)); plot.getRangeAxis().setLowerBound(-Math.pow(2, 13)); // setup chart panel chartPanel = new ChartPanel(graph, false); chartPanel.setMouseZoomable(false); chartPanel.setOpaque(false); chartPanel.setMaximumDrawWidth(Integer.MAX_VALUE); chartPanel.setMaximumDrawHeight(Integer.MAX_VALUE); chartPanel.setMinimumDrawWidth(0); chartPanel.setMinimumDrawHeight(0); chartPanel.setDomainZoomable(true); // mouse wheel zooming chartPanel.addMouseWheelListener(new MouseWheelListener() { @Override public void mouseWheelMoved(MouseWheelEvent e) { int clicks = e.getWheelRotation(); plot.getRangeAxis().setUpperBound(plot.getRangeAxis().getUpperBound() - (clicks * 100)); plot.getRangeAxis().setLowerBound(plot.getRangeAxis().getLowerBound() + (clicks * 100)); } }); }
From source file:com.epiq.bitshark.ui.IVQPanel.java
/** * Initialized the graph/*from w ww . ja va 2 s .co m*/ */ private void initGraph() { dataset = new XYSeriesCollection(); ivqSeries = new BasicSeries("I Versus Q"); dataset.addSeries(ivqSeries); graph = ChartFactory.createXYLineChart(null, // no title "", // no x-axis label "", // no y-axis label dataset, // data PlotOrientation.VERTICAL, false, // no legend false, // no tooltips false // no URLs ); graph.setBorderVisible(false); graph.setPadding(new RectangleInsets(-5, 0, 0, -0)); graph.setBackgroundPaint(null); graph.setAntiAlias(true); plot = (XYPlot) graph.getPlot(); plot.setBackgroundAlpha(0.0f); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); plot.setAxisOffset(new RectangleInsets(0, 0, 0, 0)); plot.setDomainCrosshairVisible(false); plot.setRangeCrosshairVisible(false); XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setBaseShapesVisible(false); renderer.setBaseShapesFilled(true); renderer.setSeriesPaint(0, Common.EPIQ_GREEN); } // X-axis setup plot.getDomainAxis().setAutoRange(false); plot.getDomainAxis().setVisible(true); plot.getDomainAxis().setUpperBound(Math.pow(2, 13)); plot.getDomainAxis().setLowerBound(-Math.pow(2, 13)); // Y-axis setup plot.getRangeAxis().setAutoRange(false); plot.getRangeAxis().setVisible(true); plot.getRangeAxis().setUpperBound(Math.pow(2, 13)); plot.getRangeAxis().setLowerBound(-Math.pow(2, 13)); chartPanel = new ChartPanel(graph, true, // properties true, // save false, true, // zoom false); chartPanel.setMaximumDrawWidth(Integer.MAX_VALUE); chartPanel.setMaximumDrawHeight(Integer.MAX_VALUE); chartPanel.setMinimumDrawWidth(0); chartPanel.setMinimumDrawHeight(0); chartPanel.setOpaque(false); // enable zoom control via mouse wheel chartPanel.addMouseWheelListener(new MouseWheelListener() { @Override public void mouseWheelMoved(MouseWheelEvent e) { int clicks = e.getWheelRotation(); plot.getRangeAxis().setUpperBound(plot.getRangeAxis().getUpperBound() - (clicks * 100)); plot.getRangeAxis().setLowerBound(plot.getRangeAxis().getLowerBound() + (clicks * 100)); } }); }