Example usage for javax.swing DefaultBoundedRangeModel getExtent

List of usage examples for javax.swing DefaultBoundedRangeModel getExtent

Introduction

In this page you can find the example usage for javax.swing DefaultBoundedRangeModel getExtent.

Prototype

public int getExtent() 

Source Link

Document

Returns the model's extent.

Usage

From source file:Main.java

public static void main(String args[]) {
    try {/*from   www  .  j a  v a  2 s  .  c  o m*/
        DefaultBoundedRangeModel model = new DefaultBoundedRangeModel();
        ChangeListener myListener = new MyChangeListener();
        model.addChangeListener(myListener);

        System.out.println(model.toString());
        System.out.println("Now setting minimum to 50 . . .");
        model.setMinimum(50);
        System.out.println(model.toString());
        System.out.println("Now setting maximum to 40 . . .");
        model.setMaximum(40);
        System.out.println(model.toString());
        System.out.println("Now setting maximum to 50 . . .");
        model.setMaximum(50);
        System.out.println(model.toString());
        System.out.println("Now setting extent to 30 . . .");
        model.setExtent(30);
        System.out.println(model.toString());

        System.out.println(model.getExtent());

        System.out.println("Now setting several properties . . .");
        if (!model.getValueIsAdjusting()) {
            model.setValueIsAdjusting(true);
            System.out.println(model.toString());
            model.setMinimum(0);
            model.setMaximum(100);
            model.setExtent(20);
            model.setValueIsAdjusting(false);
        }
        System.out.println(model.toString());
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.nuclos.client.genericobject.GenericObjectCollectController.java

private void setupKeyActionsForResultPanelVerticalScrollBar() {
    // maps the default key strokes for JTable to set the vertical scrollbar, so we can intervent:
    final InputMap inputmap = getResultTable().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    inputmap.put(KeyStroke.getKeyStroke(KeyEvent.VK_END, InputEvent.CTRL_MASK), "last");
    inputmap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), "nextrow");
    inputmap.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, 0), "nextpage");

    final JScrollBar scrlbarVertical = getResultPanel().getResultTableScrollPane().getVerticalScrollBar();
    final DefaultBoundedRangeModel model = (DefaultBoundedRangeModel) scrlbarVertical.getModel();

    getResultTable().getActionMap().put("last", new AbstractAction() {

        @Override/*w  w  w .  j  av  a 2s .c om*/
        public void actionPerformed(ActionEvent ev) {
            final int iSupposedValue = model.getMaximum() - model.getExtent();
            model.setValue(iSupposedValue);
            // this causes the necessary rows to be loaded. Loading may be cancelled by the user.
            LOG.debug("NOW it's time to select the row...");
            if (model.getValue() == iSupposedValue)
                getCollectNavigationModel().selectLastElement();
        }
    });

    getResultTable().getActionMap().put("nextrow", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent ev) {
            final int iSelectedRow = getResultTable().getSelectedRow();
            final int iLastVisibleRow = TableUtils.getLastVisibleRow(getResultTable());
            if (iSelectedRow + 1 < iLastVisibleRow) {
                // next row is still visible: just select it:
                if (!getCollectNavigationModel().isLastElementSelected())
                    getCollectNavigationModel().selectNextElement();
            } else {
                // we have to move the viewport before we can select the next row:
                final int iSupposedValue = Math.min(model.getValue() + getResultTable().getRowHeight(),
                        model.getMaximum() - model.getExtent());
                model.setValue(iSupposedValue);
                // this causes the necessary rows to be loaded. Loading may be cancelled by the user.
                LOG.debug("NOW it's time to select the row...");
                if (model.getValue() == iSupposedValue)
                    if (!getCollectNavigationModel().isLastElementSelected())
                        getCollectNavigationModel().selectNextElement();
            }
        }
    });

    getResultTable().getActionMap().put("nextpage", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent ev) {
            final int iSupposedValue = Math.min(model.getValue() + model.getExtent(),
                    model.getMaximum() - model.getExtent());
            model.setValue(iSupposedValue);
            // this causes the necessary rows to be loaded. Loading may be cancelled by the user.
            LOG.debug("NOW it's time to select the row...");
            if (model.getValue() == iSupposedValue) {
                final int iShiftRowCount = (int) Math
                        .ceil((double) model.getExtent() / (double) getResultTable().getRowHeight());
                final int iRow = Math.min(
                        getResultTable().getSelectionModel().getAnchorSelectionIndex() + iShiftRowCount,
                        getResultTable().getRowCount() - 1);
                getResultTable().setRowSelectionInterval(iRow, iRow);
            }
        }
    });

    final Action actShowLogBook = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent ev) {
            cmdShowLogBook();
            getDetailsPanel().grabFocus();
        }
    };
    KeyBindingProvider.bindActionToComponent(KeyBindingProvider.SHOW_LOGBOOK, actShowLogBook,
            getDetailsPanel());

    final Action actShowStateHistory = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent ev) {
            cmdShowStateHistory();
            getDetailsPanel().grabFocus();
        }
    };
    KeyBindingProvider.bindActionToComponent(KeyBindingProvider.SHOW_STATE_HISTORIE, actShowStateHistory,
            getDetailsPanel());

    final Action actPrintCurrentGenericObject = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent ev) {
            cmdPrintCurrentGenericObject();
            getDetailsPanel().grabFocus();
        }
    };
    KeyBindingProvider.bindActionToComponent(KeyBindingProvider.PRINT_LEASED_OBJECT,
            actPrintCurrentGenericObject, getDetailsPanel());
}