Package javax.swing

Examples of javax.swing.JViewport


            public void actionPerformed(ActionEvent event)
            {
                if (m_zoom != 0.0f)
                {
                    Dimension size = getSize();
                    JViewport viewPort = (JViewport)getParent();
                    assert viewPort != null;
                    Dimension dimView = viewPort.getExtentSize();
                    setViewPosition(new Point((int)(size.width/2 - dimView.width/2), (int)(size.height/2 - dimView.height)));
                }
            }
        });

        getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_NUMPAD0, 0), "ctrl_scrollhome");
        getActionMap().put("ctrl_scrollhome", new AbstractAction()
        {
            public void actionPerformed(ActionEvent event)
            {
                if (m_zoom != 0.0f)
                    setViewPosition(new Point(0, 0));
            }
        });

        getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_DECIMAL, 0), "ctrl_scrollend");
        getActionMap().put("ctrl_scrollend", new AbstractAction()
        {
            public void actionPerformed(ActionEvent event)
            {
                if (m_zoom != 0.0f)
                {
                    Dimension size = getSize();
                    setViewPosition(new Point((int)size.width, (int)size.height));
                }
            }
        });

        // Mouse
        addMouseListener(new MouseAdapter()
        {
            public void mousePressed(MouseEvent ev)
            {
                if (getZoom() != 0.0f)
                {
                    m_moveStartPoint = ev.getPoint();
                    setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
                    m_bMoveOutSide = false;
                    m_bMove = true;
                }
            }

            public void mouseReleased(MouseEvent ev)
            {
                if (m_bMove)
                {
                    setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
                    m_bMove = false;
                }
            }

            public void mouseExited(MouseEvent ev)
            {
                if (m_bMove)
                {
                    setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
                    m_bMoveOutSide = true;
                }
            }

            public void mouseEntered(MouseEvent ev)
            {
                if (m_bMove)
                {
                    if (m_bMoveOutSide)
                    {
                        setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
                        m_bMoveOutSide = false;
                    }
                }
            }
        });
        addMouseMotionListener(new MouseMotionAdapter()
        {
            public void mouseDragged(MouseEvent ev)
            {
                if (m_bMove && !m_bMoveOutSide)
                {
                    JViewport viewPort = (JViewport)getParent();
                    assert viewPort != null;
                    Rectangle rect = viewPort.getViewRect();
                    if (rect.contains(ev.getPoint()))
                    {
                        Point pt = new Point(viewPort.getViewPosition());
                        pt.translate(m_moveStartPoint.x - ev.getPoint().x, m_moveStartPoint.y - ev.getPoint().y);
                        setViewPosition(pt);
                    }
                }
            }
View Full Code Here


        });
    }
   
    private void scrollImg(int dx, int dy)
    {
        JViewport viewPort = (JViewport)getParent();
        assert viewPort != null;
        Point pt = new Point(viewPort.getViewPosition());
        pt.translate(dx, dy);
        setViewPosition(pt);
    }
View Full Code Here

    }
   
    private boolean doSetViewPosition(Point _pt, boolean bForceSet)
    {
        boolean flag = true;
        JViewport viewPort = (JViewport)getParent();
        assert viewPort != null;
        Point pt = new Point(_pt);
        if (pt.x < 0) pt.x = 0;
        if (pt.y < 0 ) pt.y = 0;

        Dimension dimCtrl = getSize();
        Dimension dimView = viewPort.getExtentSize();
        if (pt.x > dimCtrl.width - dimView.width)
        {
            pt.x = dimCtrl.width - dimView.width;
            flag = false;
        }
        if (pt.y > dimCtrl.height - dimView.height)
        {
            pt.y = dimCtrl.height - dimView.height;
            flag = false;
        }
        if (flag || bForceSet)
            viewPort.setViewPosition(pt);
        return flag;
    }
View Full Code Here

     */
    private void adjustViewPosByZoom(float oldZoom)
    {
        float zoom = getRealZoom();
        float zoomDelta = zoom - oldZoom;
        final JViewport viewPort = (JViewport)getParent();
        assert viewPort != null;
        Dimension dimView = viewPort.getExtentSize();
        m_viewPos = viewPort.getViewPosition();
        m_viewPos.translate(Math.round((m_viewPos.x + (float)dimView.width/2.0f)*zoomDelta/oldZoom), Math.round((m_viewPos.y + (float)dimView.height/2.0f)*zoomDelta/oldZoom));
        if (!setViewPosition(m_viewPos, false))
        {
            SwingUtilities.invokeLater(new Runnable()
            {
View Full Code Here

                return true;
            }
            else
            {
                g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
                JViewport viewPort = (JViewport)getParent();
                assert (viewPort != null);

                Point pt = viewPort.getViewPosition();
                dim = viewPort.getExtentSize();
                String str = Main.getString("img_wait");
                Rectangle2D rect = g2d.getFontMetrics().getStringBounds(str, g2d);
                g2d.drawString(str, (int)pt.getX() + (int)((dim.getWidth() - rect.getWidth())/2), (int)pt.getY() + (int)((dim.getHeight() + rect.getHeight())/2));
                if (Main.m_settings.isDebug())
                    System.err.println("no image !");
View Full Code Here

            if (!chartPanelView.isMinimized()) {
                noMaximizedChartPanelView = false;
                final boolean isLastMaximizedChartPanelView = lastMaximizedChartPanelView == chartPanelView;
                // lock viewports with each other...
                // remove old master listeners
                final JViewport viewport = modelChart.getViewport();
                lockChartsToOneScrollbar(viewport, isLastMaximizedChartPanelView, modelChart, masterViewPortChangeListener);

                final JScrollBar horizontalScrollBar = modelChart.getHorizontalScrollBar();
                // clean old change listeners
                ChangeListener[] changeListeners = ((DefaultBoundedRangeModel) horizontalScrollBar.getModel()).getChangeListeners();
View Full Code Here

        public void addSlaveViewport(JViewport viewPort) {
            slaveViewPorts.add(viewPort);
        }

        public void stateChanged(ChangeEvent e) {
            JViewport master = (JViewport) e.getSource();
            final int x = master.getViewPosition().x;
            for (JViewport slave : slaveViewPorts) {
                slave.setViewPosition(new Point(x, slave.getViewPosition().y));
            }
        }
View Full Code Here

         *
         */
        private static final long serialVersionUID = 6256786451390655839L;

        {
                    JViewport vp = this.getViewport();
                    vp.add(editor);
                }
            });
            //this.add(BorderLayout.NORTH, toolbar);
        } catch (MalformedURLException e) {
            this.add(new JLabel( Utilities.getLangueMessage( Constantes.MESSAGE_CHARGEMENT_AIDE_ECHEC ) )  );
View Full Code Here

        p.add(BorderLayout.CENTER, new JPanel(new BorderLayout()) {
            {
                this.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
                this.add(BorderLayout.CENTER, new JScrollPane(editor) {
                    {
                        JViewport vp = this.getViewport();
                        vp.add(editor);
                    }
                });
            }
        });
        p.add(BorderLayout.SOUTH, MyPanelFactory.createBottomWhitePanel(new JButton(close)));
View Full Code Here

     colmodel.getColumn(0).setPreferredWidth(100);
     colmodel.getColumn(1).setPreferredWidth(350);
     colmodel.getColumn(2).setPreferredWidth(80);

     final JScrollPane scrollPane = new JScrollPane();
     final JViewport vp = scrollPane.getViewport();
     vp.add(table);

    okB.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(final ActionEvent e) {
        setVisible(false);
View Full Code Here

TOP

Related Classes of javax.swing.JViewport

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.