List of usage examples for java.awt.event MouseEvent getSource
public Object getSource()
From source file:mulavito.gui.control.AbstractPopupMousePlugin.java
/** * Reduced functionality of super class method and extended by own * content-aware editing./* w w w . j a v a 2 s . c om*/ */ @SuppressWarnings("unchecked") @Override protected final void handlePopup(final MouseEvent e) { if (checkModifiers(e)) { final LV vv = (LV) e.getSource(); final Layout<V, E> layout = vv.getGraphLayout(); final L graph = (L) layout.getGraph(); final Point p = e.getPoint(); final List<V> sel_vertices = getSelectedVertices(); final List<E> sel_edges = getSelectedEdges(); GraphElementAccessor<V, E> pickSupport = vv.getPickSupport(); if (pickSupport != null) { V vertex = pickSupport.getVertex(layout, p.getX(), p.getY()); E edge = pickSupport.getEdge(layout, p.getX(), p.getY()); if (vertex != null && !sel_vertices.contains(vertex)) sel_vertices.add(vertex); if (edge != null && !sel_edges.contains(edge)) sel_edges.add(edge); } popup.removeAll(); if (sel_vertices.size() > 0) createVertexMenuEntries(p, graph, vv, sel_vertices); else if (sel_edges.size() > 0) createEdgeMenuEntries(p, graph, vv, sel_edges); else createGeneralMenuEntries(p, graph, vv); if (popup.getComponentCount() > 0) popup.show(vv, e.getX(), e.getY()); } }
From source file:com.limegroup.gnutella.gui.tables.ActionIconAndNameEditor.java
protected void component_mousePressed(MouseEvent e) { if (action != null) { try {//from w w w.j a va 2 s . co m action.actionPerformed(new ActionEvent(e.getSource(), e.getID(), "")); } catch (Throwable e1) { LOG.error("Error performing action", e1); } } }
From source file:org.isatools.gui.optionselector.OptionGroup.java
public void mouseExited(MouseEvent mouseEvent) { if (mouseEvent.getSource() instanceof OptionItem) { OptionItem<T> item = (OptionItem<T>) mouseEvent.getSource(); item.setOpaque(false);//from w w w. j a v a 2 s . c o m } }
From source file:Transfer.java
public Transfer() { // Establish the GUI Container cp = new Box(BoxLayout.X_AXIS); setContentPane(cp);/*from ww w . ja v a2s . c o m*/ JPanel firstPanel = new JPanel(); propertyComboBox = new JComboBox(); propertyComboBox.addItem("text"); propertyComboBox.addItem("font"); propertyComboBox.addItem("background"); propertyComboBox.addItem("foreground"); firstPanel.add(propertyComboBox); cp.add(firstPanel); cp.add(Box.createGlue()); tf = new JTextField("Hello"); tf.setForeground(Color.RED); tf.setDragEnabled(true); cp.add(tf); cp.add(Box.createGlue()); l = new JLabel("Hello"); l.setBackground(Color.YELLOW); cp.add(l); cp.add(Box.createGlue()); JSlider stryder = new JSlider(SwingConstants.VERTICAL); stryder.setMinimum(10); stryder.setValue(14); stryder.setMaximum(72); stryder.setMajorTickSpacing(10); stryder.setPaintTicks(true); cp.add(stryder); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(500, 300); // Add Listeners and Converters setMyTransferHandlers((String) propertyComboBox.getSelectedItem()); // Mousing in the Label starts a Drag. MouseListener myDragListener = new MouseAdapter() { public void mousePressed(MouseEvent e) { JComponent c = (JComponent) e.getSource(); TransferHandler handler = c.getTransferHandler(); handler.exportAsDrag(c, e, TransferHandler.COPY); } }; l.addMouseListener(myDragListener); // Selecting in the ComboBox makes that the property that is xfered. propertyComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ce) { JComboBox bx = (JComboBox) ce.getSource(); String prop = (String) bx.getSelectedItem(); setMyTransferHandlers(prop); } }); // Typing a word and pressing enter in the TextField tries // to set that as the font name. tf.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { JTextField jtf = (JTextField) evt.getSource(); String fontName = jtf.getText(); Font font = new Font(fontName, Font.BOLD, 18); tf.setFont(font); } }); // Setting the Slider sets that font into the textfield. stryder.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { JSlider sl = (JSlider) evt.getSource(); Font oldf = tf.getFont(); Font newf = oldf.deriveFont((float) sl.getValue()); tf.setFont(newf); } }); }
From source file:Demo.ScatterGraph.java
@Override public void mouseReleased(MouseEvent e) { if (e.getSource() == xSelector || e.getSource() == ySelector) { int x = xSelector.getSelectedIndex(); int y = ySelector.getSelectedIndex(); if (charts[x][y] == null) { charts[x][y] = CreateChart(x, y); }/*from w w w . j av a 2 s. c o m*/ chartPane.setChart(charts[x][y]); } }
From source file:org.isatools.gui.optionselector.OptionGroup.java
public void mouseEntered(MouseEvent mouseEvent) { if (mouseEvent.getSource() instanceof OptionItem) { final OptionItem<T> item = (OptionItem<T>) mouseEvent.getSource(); item.setForeground(item.getOverBackgroundColor()); final Timer[] timers = new Timer[1]; timers[0] = new Timer(750, new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { item.setForeground(item.getNormalBackground()); timers[0].stop();// w w w .java 2 s . com } }); timers[0].start(); } }
From source file:org.isatools.gui.optionselector.OptionGroup.java
public void mousePressed(MouseEvent mouseEvent) { if (mouseEvent.getSource() instanceof OptionItem) { OptionItem<T> item = (OptionItem<T>) mouseEvent.getSource(); if (singleSelection) { if (!item.getSelectedIcon()) { clearSelections();// ww w .j av a 2 s .c om item.setSelectedIcon(!item.getSelectedIcon()); fireItemSelectionEventToListeners(); } } else { if (checkForSelectedItems(item)) { item.setSelectedIcon(!item.getSelectedIcon()); fireItemSelectionEventToListeners(); } } } }
From source file:imageviewer.tools.HistogramTool.java
public void plot(MouseEvent e) { if (e.getSource() instanceof ImagePanel) { Image image = ((ImagePanel) e.getSource()).getSource(); Histogram h = image.getHistogram(); SimpleHistogramDataset shd = new SimpleHistogramDataset("Voxel distribution"); for (int i = 0, numBands = h.getNumBands(); i < numBands; i++) { int[] binData = h.getBins(i); for (int j = 0; j < binData.length; j++) { SimpleHistogramBin shb = new SimpleHistogramBin(j - 0.5, j + 0.5, true, false); shb.setItemCount(binData[j]); shd.addBin(shb);//from w w w .ja v a2 s . co m } } double[] domainBounds = null, rangeBounds = null; if (chart != null) { ValueAxis va = chart.getXYPlot().getDomainAxis(); domainBounds = new double[] { va.getLowerBound(), va.getUpperBound() }; va = chart.getXYPlot().getRangeAxis(); rangeBounds = new double[] { va.getLowerBound(), va.getUpperBound() }; } chart = ChartFactory.createHistogram(null, "Voxel value", "Count", shd, PlotOrientation.VERTICAL, false, true, false); chart.setBackgroundPaint(new Color(20, 30, 45)); chart.setAntiAlias(true); ValueAxis domainAxis = chart.getXYPlot().getDomainAxis(); domainAxis.setLabelFont(axisFont); domainAxis.setTickLabelFont(tickFont); domainAxis.setAxisLinePaint(Color.white); domainAxis.setTickLabelPaint(Color.white); domainAxis.setLabelPaint(Color.white); if (domainBounds != null) { domainAxis.setAutoRange(false); domainAxis.setLowerBound(domainBounds[0]); domainAxis.setUpperBound(domainBounds[1]); } else { domainAxis.setLowerBound(0); } ValueAxis rangeAxis = chart.getXYPlot().getRangeAxis(); rangeAxis.setLabelFont(axisFont); rangeAxis.setTickLabelFont(tickFont); rangeAxis.setAxisLinePaint(Color.white); rangeAxis.setTickLabelPaint(Color.white); rangeAxis.setLabelPaint(Color.white); if (rangeBounds != null) { rangeAxis.setAutoRange(false); rangeAxis.setLowerBound(rangeBounds[0]); rangeAxis.setUpperBound(rangeBounds[1]); } chart.getXYPlot().getRenderer().setSeriesPaint(0, new Color(0, 51, 113)); ((XYBarRenderer) chart.getXYPlot().getRenderer()).setDrawBarOutline(false); chart.getXYPlot().setBackgroundAlpha(0.05f); double[] mean = h.getMean(); double[] sd = h.getStandardDeviation(); IntervalMarker im = new IntervalMarker(mean[0] - sd[0] / 2, mean[0] + sd[0] / 2); im.setPaint(new Color(200, 200, 200, 128)); chart.getXYPlot().addDomainMarker(0, im, Layer.BACKGROUND); cp.setChart(chart); } }
From source file:fi.smaa.jsmaa.gui.SMAA2GUIFactory.java
@Override protected JButton buildToolBarAddCriterionButton() { JButton button = new JButton(ImageFactory.IMAGELOADER.getIcon(FileNames.ICON_ADDCRITERION)); button.setToolTipText("Add criterion"); final JPopupMenu addMenu = new JPopupMenu(); addUtilityAddItemsToMenu(addMenu);/* w w w.j av a2s . c o m*/ button.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent evt) { addMenu.show((Component) evt.getSource(), evt.getX(), evt.getY()); } }); return button; }