Example usage for java.awt.event MouseMotionAdapter MouseMotionAdapter

List of usage examples for java.awt.event MouseMotionAdapter MouseMotionAdapter

Introduction

In this page you can find the example usage for java.awt.event MouseMotionAdapter MouseMotionAdapter.

Prototype

MouseMotionAdapter

Source Link

Usage

From source file:com.iisigroup.ris.WebFileScanUtilBrowserUI.java

private void initGUI() {
    final SwingActionUtil swingUtil = (SwingActionUtil) SwingActionUtil.newInstance(this);
    try {/*from w ww  .  j a  v a2  s.c  o m*/
        BorderLayout thisLayout = new BorderLayout();
        getContentPane().setLayout(thisLayout);
        this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        this.setTitle("browser source code");
        {
            informationMenu = new JPopupMenu();
            setComponentPopupMenu(this, informationMenu);
        }
        {
            ListModel openFileListModel = new DefaultListModel();
            openFileList = new JList();
            openFileList.setModel(openFileListModel);
            getContentPane().add(openFileList, BorderLayout.NORTH);
            openFileList.setPreferredSize(new java.awt.Dimension(663, 281));
            openFileList.addListSelectionListener(new ListSelectionListener() {
                public void valueChanged(ListSelectionEvent evt) {
                    swingUtil.invokeAction("openFileList.valueChanged", evt);
                }
            });
            openFileList.addMouseMotionListener(new MouseMotionAdapter() {
                public void mouseMoved(MouseEvent evt) {
                    swingUtil.invokeAction("openFileList.mouseMoved", evt);
                }
            });
            openFileList.addKeyListener(new KeyAdapter() {
                public void keyPressed(KeyEvent evt) {
                    swingUtil.invokeAction("openFileList.keyPressed", evt);
                }
            });
        }
        {
            jPanel1 = new JPanel();
            GroupLayout jPanel1Layout = new GroupLayout((JComponent) jPanel1);
            jPanel1.setLayout(jPanel1Layout);
            getContentPane().add(jPanel1, BorderLayout.SOUTH);
            jPanel1.setPreferredSize(new java.awt.Dimension(478, 35));
            {
                openSelected = new JButton();
                openSelected.setText("open all");
                openSelected.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        swingUtil.invokeAction("openSelected.actionPerformed", evt);
                    }
                });
            }
            jPanel1Layout.setHorizontalGroup(jPanel1Layout.createSequentialGroup().addContainerGap(178, 178)
                    .addComponent(openSelected, GroupLayout.PREFERRED_SIZE, 126, GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(174, Short.MAX_VALUE));
            jPanel1Layout.setVerticalGroup(jPanel1Layout.createSequentialGroup().addGap(7)
                    .addComponent(openSelected, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 6, Short.MAX_VALUE));
        }
        {
            informationMenu = new JPopupMenu();
        }

        this.setSize(486, 350);
        this.setLocationRelativeTo(null);

        //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        // ?tooltip
        //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        int initialDelay = ToolTipManager.sharedInstance().getInitialDelay();
        ToolTipManager.sharedInstance().setInitialDelay(0);
        //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        // ?tooltip
        //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

        swingUtil.addAction("openFileList.mouseClicked", new Action() {
            public void action(EventObject evt) throws Exception {
                DefaultListModel model = (DefaultListModel) openFileList.getModel();
                int pos = openFileList.getLeadSelectionIndex();
                if (pos == -1) {
                    return;
                }
                setOpenFileListToolTip();
                MouseEvent eeev = (MouseEvent) evt;
                if (eeev.getClickCount() != 2) {
                    return;
                }
                MFile file = (MFile) model.elementAt(pos);
                openSource(file.file);
            }
        });
        final JListUtil jlistUtil = JListUtil.newInstance(openFileList);
        swingUtil.addAction("openFileList.keyPressed", new Action() {
            public void action(EventObject evt) throws Exception {
                jlistUtil.defaultJListKeyPressed((KeyEvent) evt);
                setOpenFileListToolTip();
            }
        });
        swingUtil.addAction("openSelected.actionPerformed", new Action() {
            public void action(EventObject evt) throws Exception {
                DefaultListModel model = (DefaultListModel) openFileList.getModel();
                for (Enumeration<?> enu = model.elements(); enu.hasMoreElements();) {
                    MFile file = (MFile) enu.nextElement();
                    openSource(file.file);
                }
            }
        });
        swingUtil.addAction("openFileList.mouseMoved", new Action() {
            public void action(EventObject evt) throws Exception {
                setOpenFileListToolTip();
            }
        });
        swingUtil.addAction("openFileList.valueChanged", new Action() {
            public void action(EventObject evt) throws Exception {
                System.out.println(evt);
                setOpenFileListToolTip();
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:ShapeTest.java

public ShapeComponent() {
    addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent event) {
            Point p = event.getPoint();
            for (int i = 0; i < points.length; i++) {
                double x = points[i].getX() - SIZE / 2;
                double y = points[i].getY() - SIZE / 2;
                Rectangle2D r = new Rectangle2D.Double(x, y, SIZE, SIZE);
                if (r.contains(p)) {
                    current = i;//from  w ww  .  j a  v a2  s .  co  m
                    return;
                }
            }
        }

        public void mouseReleased(MouseEvent event) {
            current = -1;
        }
    });
    addMouseMotionListener(new MouseMotionAdapter() {
        public void mouseDragged(MouseEvent event) {
            if (current == -1)
                return;
            points[current] = event.getPoint();
            repaint();
        }
    });
    current = -1;
}

From source file:ScreenCapture.java

public ImageArea() {
    addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            if (image == null)
                return;
            startPoint = endPoint = e.getPoint();
            repaint();//from  w  ww.  j  a  v  a 2  s.c o m
        }
    });

    addMouseMotionListener(new MouseMotionAdapter() {
        public void mouseDragged(MouseEvent e) {
            if (image == null)
                return;

            endPoint = e.getPoint();
            repaint();
        }
    });
}

From source file:org.eurocarbdb.application.glycoworkbench.plugin.PeakAnnotationCalibrationPanel.java

protected void finalSettings() {
    super.finalSettings();

    theChartPanel.addMouseMotionListener(new MouseMotionAdapter() {
        public void mouseDragged(MouseEvent e) {
            onMouseDragged(e);//from   ww  w. j a v  a  2 s .  c om
        }
    });

    theChartPanel.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            onMousePressed(e);
        }

        public void mouseReleased(MouseEvent e) {
            onMouseReleased(e);
        }

        public void mouseClicked(MouseEvent e) {
            onMouseClicked(e);
        }
    });
}

From source file:org.wso2.greg.plugin.Utils.java

/**
 * This method is used to create the Resources List UI from the given list of Resources(s).
 *
 * @param resourceInfos The list of Resources that the table is constructed.
 * @return ResourceSelectionResult which contains all the selected APIs and whether test suites and load
 * are needed to be generated.// w  ww  .  java 2s.c o m
 */
public static ResourceSelectionResult showSelectAPIDefDialog(List<ResourceInfo> resourceInfos) {

    final XFormDialog dialog = ADialogBuilder.buildDialog(ResourceModel.class);
    final Object[][] tableData = convertToTableData(resourceInfos);

    // --------------- start of API List table population section ------------------
    // We create a table model here with the converted data.
    TableModel tableModel = new AbstractTableModel() {
        Object[][] data = tableData;
        String[] columnNames = { "Name", "Version", "Provider", "Description" };

        @Override
        public int getRowCount() {
            return data.length;
        }

        @Override
        public int getColumnCount() {
            // We have a hardcoded set of columns
            return columnNames.length;
        }

        @Override
        public Object getValueAt(int rowIndex, int columnIndex) {
            return data[rowIndex][columnIndex];
        }

        @Override
        public String getColumnName(int column) {
            return columnNames[column];
        }
    };

    // We get the table that was ghttps://youtu.be/Vycy3GxbxUYenerated in the form and we set
    // some properties there.
    XFormField resourcesListFormField = dialog.getFormField(ResourceModel.RESOURCE_LIST);
    final JXTable table = ((JTableFormField) resourcesListFormField).getTable();
    table.setCellSelectionEnabled(false);
    table.setColumnSelectionAllowed(false);
    table.setRowSelectionAllowed(true);
    table.setFillsViewportHeight(true);

    // We set the preferred size of all the parent forms until we get to the JScrollPane
    table.setPreferredScrollableViewportSize(new Dimension(600, 200));
    table.getParent().setPreferredSize(new Dimension(600, 200));
    table.getParent().getParent().setPreferredSize(new Dimension(600, 200));

    // Setting the table model
    table.setModel(tableModel);

    // This is to show a toolTip when hovering over the table cells. We need this because there could be long
    // descriptions and api names.
    table.addMouseMotionListener(new MouseMotionAdapter() {
        @Override
        public void mouseMoved(MouseEvent e) {
            Point p = e.getPoint();
            int row = table.rowAtPoint(p);
            int col = table.columnAtPoint(p);

            if (row == -1 || col == -1) {
                return;
            }
            table.setToolTipText(tableData[row][col].toString());
        }
    });

    // The purpose of this validator is the check whether there are at least one API selected from the table.
    resourcesListFormField.addFormFieldValidator(new XFormFieldValidator() {
        @Override
        public ValidationMessage[] validateField(XFormField xFormField) {
            if (table.getSelectedRowCount() <= 0) {
                return new ValidationMessage[] {
                        new ValidationMessage(HelpMessageConstants.API_SELECTION_VALIDATION_MSG,
                                dialog.getFormField(ResourceModel.RESOURCE_LIST)) };
            }
            return new ValidationMessage[0];
        }
    });
    // --
    // ----------------- End of Resource(s) List Table population section ----------------------

    // We get the radio button group and add a listener there. The purpose of the listener is to 'enable',
    // 'disable' the Load test radio button group based on the selected value of this group.
    // The reason is that, there is no meaning to create a Load test without a test suite.
    XFormRadioGroup testSuiteSelection = (XFormRadioGroup) dialog.getFormField(ResourceModel.TEST_SUITE);
    testSuiteSelection.setValue(ResourceConstants.RADIO_BUTTON_OPTIONS_NO);
    testSuiteSelection.setToolTip(HelpMessageConstants.TEST_SUITE_TOOLTIP_TEXT);

    testSuiteSelection.addFormFieldListener(new XFormFieldListener() {
        @Override
        public void valueChanged(XFormField xFormField, String newValue, String oldValue) {
            XFormRadioGroup loadTestSelection = (XFormRadioGroup) dialog.getFormField(ResourceModel.LOAD_TEST);
            if (ResourceConstants.RADIO_BUTTON_OPTIONS_YES.equals(newValue)) {
                loadTestSelection.setEnabled(true);
            } else if (ResourceConstants.RADIO_BUTTON_OPTIONS_NO.equals(newValue)) {
                loadTestSelection.setEnabled(false);
            }
        }
    });

    XFormRadioGroup loadTestSelection = (XFormRadioGroup) dialog.getFormField(ResourceModel.LOAD_TEST);
    loadTestSelection.setToolTip(HelpMessageConstants.LOAD_TEST_TOOLTIP_TEXT);
    loadTestSelection.setValue(ResourceConstants.RADIO_BUTTON_OPTIONS_NO);

    if (dialog.show()) {
        int[] selected = table.getSelectedRows();
        ArrayList<ResourceInfo> selectedAPIs = new ArrayList<ResourceInfo>();
        for (int no : selected) {
            selectedAPIs.add(resourceInfos.get(no));
        }
        ResourceSelectionResult selectionResult = new ResourceSelectionResult();
        selectionResult.setResourceInfoList(selectedAPIs);
        selectionResult.setTestSuiteSelected(
                ResourceConstants.RADIO_BUTTON_OPTIONS_YES.equals(testSuiteSelection.getValue()));
        selectionResult.setLoadTestSelected(
                ResourceConstants.RADIO_BUTTON_OPTIONS_YES.equals(loadTestSelection.getValue()));

        return selectionResult;
    } else {
        return null;
    }

}

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);/*from w  w w .jav a 2  s .com*/
    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:com.xmage.launcher.XMageLauncher.java

private XMageLauncher() {
    locale = Locale.getDefault();
    //locale = new Locale("it", "IT");
    messages = ResourceBundle.getBundle("MessagesBundle", locale);
    localize();/*from  w w  w.j  a v a  2 s. co m*/

    serverConsole = new XMageConsole("XMage Server console");
    clientConsole = new XMageConsole("XMage Client console");

    frame = new JFrame(messages.getString("frameTitle") + " " + Config.getVersion());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setPreferredSize(new Dimension(800, 500));
    frame.setResizable(false);

    createToolbar();

    ImageIcon icon = new ImageIcon(XMageLauncher.class.getResource("/icon-mage-flashed.png"));
    frame.setIconImage(icon.getImage());

    Random r = new Random();
    int imageNum = 1 + r.nextInt(17);
    ImageIcon background = new ImageIcon(new ImageIcon(
            XMageLauncher.class.getResource("/backgrounds/" + Integer.toString(imageNum) + ".jpg")).getImage()
                    .getScaledInstance(800, 480, Image.SCALE_SMOOTH));
    mainPanel = new JLabel(background) {
        @Override
        public Dimension getPreferredSize() {
            Dimension size = super.getPreferredSize();
            Dimension lmPrefSize = getLayout().preferredLayoutSize(this);
            size.width = Math.max(size.width, lmPrefSize.width);
            size.height = Math.max(size.height, lmPrefSize.height);
            return size;
        }
    };
    mainPanel.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            grabPoint = e.getPoint();
            mainPanel.getComponentAt(grabPoint);
        }
    });
    mainPanel.addMouseMotionListener(new MouseMotionAdapter() {
        @Override
        public void mouseDragged(MouseEvent e) {

            // get location of Window
            int thisX = frame.getLocation().x;
            int thisY = frame.getLocation().y;

            // Determine how much the mouse moved since the initial click
            int xMoved = (thisX + e.getX()) - (thisX + grabPoint.x);
            int yMoved = (thisY + e.getY()) - (thisY + grabPoint.y);

            // Move window to this position
            int X = thisX + xMoved;
            int Y = thisY + yMoved;
            frame.setLocation(X, Y);
        }
    });
    mainPanel.setLayout(new GridBagLayout());

    GridBagConstraints constraints = new GridBagConstraints();
    constraints.insets = new Insets(10, 10, 10, 10);

    Font font16 = new Font("Arial", Font.BOLD, 16);
    Font font12 = new Font("Arial", Font.PLAIN, 12);
    Font font12b = new Font("Arial", Font.BOLD, 12);

    mainPanel.add(Box.createRigidArea(new Dimension(250, 50)));

    ImageIcon logo = new ImageIcon(new ImageIcon(XMageLauncher.class.getResource("/label-xmage.png")).getImage()
            .getScaledInstance(150, 75, Image.SCALE_SMOOTH));
    xmageLogo = new JLabel(logo);
    constraints.gridx = 3;
    constraints.gridy = 0;
    constraints.gridheight = 1;
    constraints.gridwidth = GridBagConstraints.REMAINDER;
    constraints.anchor = GridBagConstraints.EAST;
    mainPanel.add(xmageLogo, constraints);

    textArea = new JTextArea(5, 40);
    textArea.setEditable(false);
    textArea.setForeground(Color.WHITE);
    textArea.setBackground(Color.BLACK);
    DefaultCaret caret = (DefaultCaret) textArea.getCaret();
    caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
    scrollPane = new JScrollPane(textArea);
    scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
    scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    constraints.gridx = 2;
    constraints.gridy = 1;
    constraints.weightx = 1.0;
    constraints.weighty = 1.0;
    constraints.fill = GridBagConstraints.BOTH;
    mainPanel.add(scrollPane, constraints);

    labelProgress = new JLabel(messages.getString("progress"));
    labelProgress.setFont(font12);
    labelProgress.setForeground(Color.WHITE);
    constraints.gridy = 2;
    constraints.weightx = 0.0;
    constraints.weighty = 0.0;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.WEST;
    mainPanel.add(labelProgress, constraints);

    progressBar = new JProgressBar(0, 100);
    constraints.gridx = 3;
    constraints.weightx = 1.0;
    constraints.gridwidth = GridBagConstraints.REMAINDER;
    constraints.fill = GridBagConstraints.HORIZONTAL;
    mainPanel.add(progressBar, constraints);

    JPanel pnlButtons = new JPanel();
    pnlButtons.setLayout(new GridBagLayout());
    pnlButtons.setOpaque(false);
    constraints.gridx = 0;
    constraints.gridy = 3;
    constraints.gridheight = GridBagConstraints.REMAINDER;
    constraints.fill = GridBagConstraints.BOTH;
    mainPanel.add(pnlButtons, constraints);

    btnLaunchClient = new JButton(messages.getString("launchClient"));
    btnLaunchClient.setToolTipText(messages.getString("launchClient.tooltip"));
    btnLaunchClient.setFont(font16);
    btnLaunchClient.setForeground(Color.GRAY);
    btnLaunchClient.setEnabled(false);
    btnLaunchClient.setPreferredSize(new Dimension(180, 60));
    btnLaunchClient.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            handleClient();
        }
    });

    constraints.gridx = GridBagConstraints.RELATIVE;
    constraints.gridy = 0;
    constraints.gridwidth = 1;
    constraints.fill = GridBagConstraints.BOTH;
    pnlButtons.add(btnLaunchClient, constraints);

    btnLaunchClientServer = new JButton(messages.getString("launchClientServer"));
    btnLaunchClientServer.setToolTipText(messages.getString("launchClientServer.tooltip"));
    btnLaunchClientServer.setFont(font12b);
    btnLaunchClientServer.setEnabled(false);
    btnLaunchClientServer.setForeground(Color.GRAY);
    btnLaunchClientServer.setPreferredSize(new Dimension(80, 40));
    btnLaunchClientServer.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            handleServer();
            handleClient();
        }
    });

    constraints.fill = GridBagConstraints.HORIZONTAL;
    pnlButtons.add(btnLaunchClientServer, constraints);

    btnLaunchServer = new JButton(messages.getString("launchServer"));
    btnLaunchServer.setToolTipText(messages.getString("launchServer.tooltip"));
    btnLaunchServer.setFont(font12b);
    btnLaunchServer.setEnabled(false);
    btnLaunchServer.setForeground(Color.GRAY);
    btnLaunchServer.setPreferredSize(new Dimension(80, 40));
    btnLaunchServer.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            handleServer();
        }
    });

    pnlButtons.add(btnLaunchServer, constraints);

    btnUpdate = new JButton(messages.getString("update.xmage"));
    btnUpdate.setToolTipText(messages.getString("update.xmage.tooltip"));
    btnUpdate.setFont(font12b);
    btnUpdate.setForeground(Color.BLACK);
    btnUpdate.setPreferredSize(new Dimension(80, 40));
    btnUpdate.setEnabled(true);

    btnUpdate.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            handleUpdate();
        }
    });

    pnlButtons.add(btnUpdate, constraints);

    btnCheck = new JButton(messages.getString("check.xmage"));
    btnCheck.setToolTipText(messages.getString("check.xmage.tooltip"));
    btnCheck.setFont(font12b);
    btnCheck.setForeground(Color.BLACK);
    btnCheck.setPreferredSize(new Dimension(80, 40));
    btnCheck.setEnabled(true);

    btnCheck.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            handleCheckUpdates();
        }
    });

    pnlButtons.add(btnCheck, constraints);

    frame.add(mainPanel);
    frame.pack();
    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    frame.setLocation(dim.width / 2 - frame.getSize().width / 2, dim.height / 2 - frame.getSize().height / 2);
}

From source file:StrokeTest.java

public StrokeComponent() {
    addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent event) {
            Point p = event.getPoint();
            for (int i = 0; i < points.length; i++) {
                double x = points[i].getX() - SIZE / 2;
                double y = points[i].getY() - SIZE / 2;
                Rectangle2D r = new Rectangle2D.Double(x, y, SIZE, SIZE);
                if (r.contains(p)) {
                    current = i;/* www .  j a v a 2 s  .co  m*/
                    return;
                }
            }
        }

        public void mouseReleased(MouseEvent event) {
            current = -1;
        }
    });

    addMouseMotionListener(new MouseMotionAdapter() {
        public void mouseDragged(MouseEvent event) {
            if (current == -1)
                return;
            points[current] = event.getPoint();
            repaint();
        }
    });

    points = new Point2D[3];
    points[0] = new Point2D.Double(200, 100);
    points[1] = new Point2D.Double(100, 200);
    points[2] = new Point2D.Double(200, 200);
    current = -1;
    width = 8.0F;
}

From source file:picocash.Picocash.java

private JPanel initMainFrame() {
    this.accountPanel = new StandardAccountPanel();
    mainPanel = new JXPanel(new MigLayout("fill, insets 0 0 0 0", "[grow]", "[40!] 0 [31!] 0 [grow] 0 [20!]"));
    headerPanel = new HeaderPanel();
    modePanel = new ModePanel();
    accountContainer = new JXPanel(new MigLayout("fill, insets 0 0 0 0"));
    statisticPanel = new StatisticPanel();
    footerPanel = new FooterPanel();
    headerPanel.addMouseListener(new MouseAdapter() {

        @Override/*from ww w. java  2 s.  c  o  m*/
        public void mousePressed(MouseEvent arg0) {
            Point clickPoint = new Point(arg0.getPoint());
            SwingUtilities.convertPointToScreen(clickPoint, getMainFrame());
            dX = clickPoint.x - getMainFrame().getX();
            dY = clickPoint.y - getMainFrame().getY();
        }

        @Override
        public void mouseClicked(MouseEvent arg0) {
            if (System.currentTimeMillis() - lastClickOn < DOUBLE_CLICK_TIME) {
                maximize();
            }
            lastClickOn = System.currentTimeMillis();
        }
    });

    headerPanel.addMouseMotionListener(new MouseMotionAdapter() {

        @Override
        public void mouseDragged(MouseEvent arg0) {
            Point dragPoint = new Point(arg0.getPoint());
            SwingUtilities.convertPointToScreen(dragPoint, getMainFrame());
            getMainFrame().setLocation(dragPoint.x - dX, dragPoint.y - dY);
        }
    });

    modePanel.addModePanelSelectionListener(this);

    mainPanel.add(headerPanel, "aligny top, growx, h 40!, wrap");
    mainPanel.add(modePanel, "aligny top, growx, h 31!, wrap");

    splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, accountContainer, statisticPanel);
    splitPane.setDividerLocation(0.7d);
    JXPanel tmp = new JXPanel(new MigLayout("fill, insets 0 0 0 0"));
    tmp.add(splitPane, "grow");
    mainPanel.add(tmp, "growx, growy, wrap");

    mainPanel.add(footerPanel, "aligny bottom, growx, h 20!");

    return mainPanel;
}

From source file:org.openconcerto.erp.core.finance.accounting.ui.PlanComptableGPanel.java

public JTable creerJTable(ClasseCompte ccTmp) { // NO_UCD

    final PlanComptableGModel model;
    if (this.radioCompteDeveloppe.isSelected()) {
        model = new PlanComptableGModel(ccTmp, 3);
    } else if (this.radioCompteAbrege.isSelected()) {
        model = new PlanComptableGModel(ccTmp, 2);
    } else {//from w ww .j a  v a  2s .  c  o  m
        model = new PlanComptableGModel(ccTmp, 1);
    }

    final JTable table = new JTable(model) {
        public JToolTip createToolTip() {
            JMultiLineToolTip t = new JMultiLineToolTip();
            t.setFixedWidth(500);
            return t;
        }
    };

    table.getColumnModel().getColumn(0).setCellRenderer(new PlanComptableCellRenderer(0));
    table.getColumnModel().getColumn(1).setCellRenderer(new PlanComptableCellRenderer(0));

    // TODO calcul de la taille de la colone numero de compte
    table.getColumnModel().getColumn(0).setMaxWidth(90);

    table.getTableHeader().setReorderingAllowed(false);

    table.addMouseMotionListener(new MouseMotionAdapter() {
        int lastRow = -1;

        public void mouseMoved(final MouseEvent e) {

            final Point p = new Point(e.getX(), e.getY());

            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    final int row = table.rowAtPoint(p);
                    if (lastRow != row) {
                        lastRow = row;
                        String strTmp = ((Compte) (model.getComptes().get(lastRow))).getInfos();

                        if (strTmp.length() != 0) {
                            table.setToolTipText(strTmp);
                        } else {
                            table.setToolTipText(null);
                        }

                    }
                }
            });

        }
    });

    if (this.actionClickDroit != null) {
        // System.out.println("Ajout menu droit");
        table.addMouseListener(new MouseAdapter() {

            public void mousePressed(MouseEvent e) {

                if (e.getButton() == MouseEvent.BUTTON3) {
                    actionDroitTable(e, table);
                }
            }
        });
    }

    // Enable row selection (default)
    /**
     * table.setColumnSelectionAllowed(false); table.setRowSelectionAllowed(true);
     * 
     * table.setSelectionMode(table.getSelectionModel().MULTIPLE_INTERVAL_SELECTION);
     */

    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
            int selectedRow = table.getSelectedRow();
            if (selectedRow < 0) {
                // Pas de selection
                textInfos.setText("Pas de compte slctionn");
            } else {
                textInfos.setText(((Compte) (model.getComptes().get(selectedRow))).getInfos());
            }
        }
    });

    return table;
}