Search in sources :

Example 66 with MouseEvent

use of java.awt.event.MouseEvent in project android by JetBrains.

the class NlPreviewImagePanelTest method mousePressed.

private void mousePressed() {
    int x = 10;
    int y = 10;
    MouseEvent event = new MouseEvent(myPanel, MOUSE_PRESSED, System.currentTimeMillis(), BUTTON1_MASK | BUTTON1_DOWN_MASK, x, y, 1, false);
    for (MouseListener listener : myPanel.getMouseListeners()) {
        listener.mousePressed(event);
    }
}
Also used : MouseEvent(java.awt.event.MouseEvent) MouseListener(java.awt.event.MouseListener)

Example 67 with MouseEvent

use of java.awt.event.MouseEvent in project android by JetBrains.

the class CpuMonitorView method populateUi.

@Override
protected void populateUi(JPanel container, Choreographer choreographer) {
    container.setLayout(new TabularLayout("*", "*"));
    Range viewRange = getMonitor().getTimeline().getViewRange();
    Range dataRange = getMonitor().getTimeline().getDataRange();
    final JLabel label = new JLabel(getMonitor().getName());
    label.setBorder(MONITOR_LABEL_PADDING);
    label.setVerticalAlignment(JLabel.TOP);
    // Cpu usage is shown as percentages (e.g. 0 - 100) and no range animation is needed.
    Range leftYRange = new Range(0, 100);
    final JPanel axisPanel = new JBPanel(new BorderLayout());
    axisPanel.setOpaque(false);
    AxisComponent.Builder builder = new AxisComponent.Builder(leftYRange, CPU_USAGE_AXIS, AxisComponent.AxisOrientation.RIGHT).showAxisLine(false).showMax(true).showUnitAtMax(true).setMarkerLengths(MARKER_LENGTH, MARKER_LENGTH).clampToMajorTicks(true).setMargins(0, Y_AXIS_TOP_MARGIN);
    final AxisComponent leftAxis = builder.build();
    axisPanel.add(leftAxis, BorderLayout.WEST);
    final JPanel lineChartPanel = new JBPanel(new BorderLayout());
    lineChartPanel.setOpaque(false);
    lineChartPanel.setBorder(BorderFactory.createEmptyBorder(Y_AXIS_TOP_MARGIN, 0, 0, 0));
    final LineChart lineChart = new LineChart();
    RangedContinuousSeries cpuSeries = new RangedContinuousSeries("CPU", viewRange, leftYRange, getMonitor().getThisProcessCpuUsage());
    lineChart.addLine(cpuSeries, new LineConfig(ProfilerColors.CPU_USAGE).setFilled(true));
    lineChartPanel.add(lineChart, BorderLayout.CENTER);
    final LegendComponent legend = new LegendComponent(LegendComponent.Orientation.HORIZONTAL, LEGEND_UPDATE_FREQUENCY_MS);
    legend.setLegendData(Collections.singletonList(lineChart.createLegendRenderData(cpuSeries, CPU_USAGE_AXIS, dataRange)));
    final JPanel legendPanel = new JBPanel(new BorderLayout());
    legendPanel.setOpaque(false);
    legendPanel.add(label, BorderLayout.WEST);
    legendPanel.add(legend, BorderLayout.EAST);
    choreographer.register(lineChart);
    choreographer.register(leftAxis);
    choreographer.register(legend);
    container.add(legendPanel, new TabularLayout.Constraint(0, 0));
    container.add(leftAxis, new TabularLayout.Constraint(0, 0));
    container.add(lineChartPanel, new TabularLayout.Constraint(0, 0));
    container.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseReleased(MouseEvent e) {
            getMonitor().expand();
        }
    });
}
Also used : MouseEvent(java.awt.event.MouseEvent) TabularLayout(com.android.tools.adtui.TabularLayout) MouseAdapter(java.awt.event.MouseAdapter) AxisComponent(com.android.tools.adtui.AxisComponent) Range(com.android.tools.adtui.model.Range) LineConfig(com.android.tools.adtui.chart.linechart.LineConfig) JBPanel(com.intellij.ui.components.JBPanel) RangedContinuousSeries(com.android.tools.adtui.model.RangedContinuousSeries) LegendComponent(com.android.tools.adtui.LegendComponent) LineChart(com.android.tools.adtui.chart.linechart.LineChart)

Example 68 with MouseEvent

use of java.awt.event.MouseEvent in project android by JetBrains.

the class NlOldPalettePanel method enableClickToLoadMissingDependency.

private void enableClickToLoadMissingDependency() {
    myPaletteTree.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent event) {
            Palette.BaseItem object = getItemForPath(myPaletteTree.getPathForLocation(event.getX(), event.getY()));
            if (needsLibraryLoad(object)) {
                Palette.Item item = (Palette.Item) object;
                String coordinate = item.getGradleCoordinateId();
                assert coordinate != null;
                Module module = getModule();
                assert module != null;
                GradleDependencyManager manager = GradleDependencyManager.getInstance(myProject);
                manager.ensureLibraryIsIncluded(module, toGradleCoordinates(Collections.singletonList(coordinate)), null);
            }
        }
    });
    GradleSyncState.subscribe(myProject, new GradleSyncListener.Adapter() {

        @Override
        public void syncSucceeded(@NotNull Project project) {
            if (checkForNewMissingDependencies()) {
                repaint();
            }
        }
    }, this);
}
Also used : DnDTransferItem(com.android.tools.idea.uibuilder.model.DnDTransferItem) Project(com.intellij.openapi.project.Project) MouseEvent(java.awt.event.MouseEvent) GradleSyncListener(com.android.tools.idea.gradle.project.sync.GradleSyncListener) MouseAdapter(java.awt.event.MouseAdapter) Module(com.intellij.openapi.module.Module) GradleDependencyManager(com.android.tools.idea.gradle.dependencies.GradleDependencyManager)

Example 69 with MouseEvent

use of java.awt.event.MouseEvent in project android by JetBrains.

the class GradleEditorCellComponentImpl method onMouseMove.

@Nullable
@Override
public Rectangle onMouseMove(@NotNull MouseEvent event) {
    if (myEditor) {
        return null;
    }
    if (!myToolBarPanel.isVisible() && !myTimer.isRunning()) {
        onMouseEntered(event);
        return null;
    }
    int row = myTable.getRowByComponent(this);
    if (row < 0) {
        return null;
    }
    int topY = 0;
    for (int i = 0; i < row; i++) {
        topY += myTable.getRowHeight(i);
    }
    setBounds(0, 0, myTable.getWidth(), myTable.getRowHeight(row));
    Point pointInCurrentControl = new Point(event.getX(), event.getY() - topY);
    Component c = SwingUtilities.getDeepestComponentAt(this, pointInCurrentControl.x, pointInCurrentControl.y);
    boolean dirty = false;
    if (myLastComponentUnderMouse != null && myLastComponentUnderMouse != c) {
        Point p = SwingUtilities.convertPoint(this, pointInCurrentControl, myLastComponentUnderMouse);
        MouseEvent e = new MouseEvent(c, MouseEvent.MOUSE_EXITED, event.getWhen(), event.getModifiers(), p.x, p.y, event.getClickCount(), event.isPopupTrigger(), event.getButton());
        myLastComponentUnderMouse.dispatchEvent(e);
        dirty = true;
        Cursor cursor = myLastComponentUnderMouse.getCursor();
        if (cursor != null && cursor == myTable.getCursor()) {
            myTable.setCursor(null);
        }
    }
    if (c != myLastComponentUnderMouse) {
        Point p = SwingUtilities.convertPoint(this, pointInCurrentControl, c);
        MouseEvent e = new MouseEvent(c, MouseEvent.MOUSE_ENTERED, event.getWhen(), event.getModifiers(), p.x, p.y, event.getClickCount(), event.isPopupTrigger(), event.getButton());
        c.dispatchEvent(e);
        dirty = true;
        myTable.setCursor(c.getCursor());
    }
    myLastComponentUnderMouse = c;
    Point tableLocationOnScreen = myTable.getLocationOnScreen();
    if (!dirty) {
        return null;
    }
    if (myToolBarPanelBounds == null) {
        // Repaint the whole row.
        return new Rectangle(tableLocationOnScreen.x, tableLocationOnScreen.y + topY, myTable.getWidth(), myTable.getRowHeight(row));
    } else {
        return new Rectangle(tableLocationOnScreen.x + myToolBarPanelBounds.x, tableLocationOnScreen.y + topY + myToolBarPanelBounds.y, myToolBarPanelBounds.width, myToolBarPanelBounds.height);
    }
}
Also used : MouseEvent(java.awt.event.MouseEvent) Nullable(org.jetbrains.annotations.Nullable)

Example 70 with MouseEvent

use of java.awt.event.MouseEvent in project android by JetBrains.

the class WorkBenchTest method fireButtonDragged.

private void fireButtonDragged(@NotNull JComponent dragImage, int xStart, int yStart, int x, int y) {
    AbstractButton button = myToolWindow1.getMinimizedButton();
    MouseEvent mouseEvent = new MouseEvent(button, MouseEvent.MOUSE_DRAGGED, 1, InputEvent.BUTTON1_MASK, x, y, 1, false);
    DragEvent event = new DragEvent(mouseEvent, dragImage, new Point(xStart, yStart));
    myToolWindow1.fireButtonDragged(event);
}
Also used : DragEvent(com.android.tools.adtui.workbench.AttachedToolWindow.DragEvent) MouseEvent(java.awt.event.MouseEvent)

Aggregations

MouseEvent (java.awt.event.MouseEvent)918 MouseAdapter (java.awt.event.MouseAdapter)595 Dimension (java.awt.Dimension)183 JPanel (javax.swing.JPanel)174 ActionEvent (java.awt.event.ActionEvent)172 JLabel (javax.swing.JLabel)169 Point (java.awt.Point)143 ActionListener (java.awt.event.ActionListener)123 BorderLayout (java.awt.BorderLayout)119 JScrollPane (javax.swing.JScrollPane)113 JButton (javax.swing.JButton)109 KeyEvent (java.awt.event.KeyEvent)85 ChangeEvent (javax.swing.event.ChangeEvent)85 ChangeListener (javax.swing.event.ChangeListener)83 Insets (java.awt.Insets)79 MouseListener (java.awt.event.MouseListener)72 KeyAdapter (java.awt.event.KeyAdapter)65 JPopupMenu (javax.swing.JPopupMenu)64 JSlider (javax.swing.JSlider)63 GridBagConstraints (java.awt.GridBagConstraints)62