Example usage for javax.swing JViewport BLIT_SCROLL_MODE

List of usage examples for javax.swing JViewport BLIT_SCROLL_MODE

Introduction

In this page you can find the example usage for javax.swing JViewport BLIT_SCROLL_MODE.

Prototype

int BLIT_SCROLL_MODE

To view the source code for javax.swing JViewport BLIT_SCROLL_MODE.

Click Source Link

Document

Use graphics.copyArea to implement scrolling.

Usage

From source file:tk.tomby.tedit.core.Buffer.java

/**
 * Creates a new Buffer object.//from w  w w .  j  av a2 s. c o m
 */
public Buffer() {
    super();

    setLayout(new BorderLayout());

    JPanel internalPanel = new JPanel();
    internalPanel.setLayout(new BorderLayout());

    editor = new ColourTextArea();

    int red = PreferenceManager.getInt("general.editor.background.red", 0);
    int green = PreferenceManager.getInt("general.editor.background.green", 0);
    int blue = PreferenceManager.getInt("general.editor.background.blue", 0);
    editor.setBackground(new Color(red, green, blue));

    red = PreferenceManager.getInt("general.editor.foreground.red", 0);
    green = PreferenceManager.getInt("general.editor.foreground.green", 0);
    blue = PreferenceManager.getInt("general.editor.foreground.blue", 0);
    editor.setForeground(new Color(red, green, blue));

    red = PreferenceManager.getInt("general.editor.selection.red", 0);
    green = PreferenceManager.getInt("general.editor.selection.green", 0);
    blue = PreferenceManager.getInt("general.editor.selection.blue", 0);
    editor.setSelectionColor(new Color(red, green, blue));

    String font = PreferenceManager.getString("general.editor.font", "Monospaced");
    int size = PreferenceManager.getInt("general.editor.fontSize", 12);
    editor.setFont(new Font(font, Font.PLAIN, size));

    editor.setEditable(true);
    editor.setDragEnabled(true);
    editor.setEditorKit(EditorKitManager.createEditorKit(getExtension(DEFAULT_FILE_NAME)));

    InputMap map = editor.getInputMap(JComponent.WHEN_FOCUSED);

    for (InputMap imap = map; imap != null; imap = imap.getParent()) {
        imap.remove(KeyStroke.getKeyStroke('V', InputEvent.CTRL_MASK, false));
        imap.remove(KeyStroke.getKeyStroke('C', InputEvent.CTRL_MASK, false));
        imap.remove(KeyStroke.getKeyStroke('X', InputEvent.CTRL_MASK, false));
        imap.remove(KeyStroke.getKeyStroke('A', InputEvent.CTRL_MASK, false));
    }

    editor.setInputMap(JComponent.WHEN_FOCUSED, map);

    editor.addCaretListener(new CaretListener() {
        public void caretUpdate(CaretEvent evt) {
            MessageManager.sendMessage(new BufferMessage(evt.getSource(), BufferMessage.CARET_EVENT));
        }
    });

    internalPanel.add(BorderLayout.CENTER, editor);

    if (PreferenceManager.getBoolean("general.editor.lineNumbers", false)) {
        lines = new LineNumbering();
        lines.setPreferredSize(new Dimension(50, 0));
        lines.setFont(new Font(font, Font.PLAIN, size));
        lines.setFocusable(false);
        lines.setDocument(editor.getDocument());

        internalPanel.add(BorderLayout.WEST, lines);
    }

    JScrollPane scroll = new JScrollPane(internalPanel);
    scroll.getVerticalScrollBar().setUnitIncrement(10);
    scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    scroll.getViewport().setScrollMode(JViewport.BLIT_SCROLL_MODE);

    add(BorderLayout.CENTER, scroll);

    editor.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent evt) {
            if (evt.isPopupTrigger()) {
                WorkspaceManager.getPopupMenu().show(evt.getComponent(), evt.getX(), evt.getY());
            }
        }

        public void mouseReleased(MouseEvent evt) {
            if (evt.isPopupTrigger()) {
                WorkspaceManager.getPopupMenu().show(evt.getComponent(), evt.getX(), evt.getY());
            }
        }
    });

    undo = new UndoManager();

    undoableListener = new UndoableEditListener() {
        public void undoableEditHappened(UndoableEditEvent evt) {
            undo.addEdit(evt.getEdit());

            MessageManager.sendMessage(new BufferMessage(evt.getSource(), BufferMessage.UNDOABLE_EDIT_EVENT));

            if (!modifiedState) {
                setModifiedState(true);
            }
        }
    };

    editor.getDocument().addUndoableEditListener(undoableListener);

    MessageManager.addMessageListener(MessageManager.PREFERENCE_GROUP_NAME, this);

    fileName = DEFAULT_FILE_NAME;
}

From source file:tk.tomby.tedit.plugins.explorer.Explorer.java

/**
 * Creates a new Explorer object.//from  ww w .ja  v  a 2  s.  c om
 */
public Explorer() {
    super("Explorer");

    File rootDir = new File(PreferenceManager.getString("explorer.directory", System.getProperty("user.home")));

    JPanel internalPanel = new JPanel();
    internalPanel.setLayout(new BorderLayout());

    topPanel = new TopPanel(rootDir.getAbsolutePath());
    topPanel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            JComboBox combo = (JComboBox) evt.getSource();
            TaskManager.execute(new ReadDirectoryWorker(combo));
        }
    });

    internalPanel.add(BorderLayout.NORTH, topPanel);

    DefaultMutableTreeNode directoryRoot = new DefaultMutableTreeNode(rootDir);

    directoryTreeModel = new ShortedTreeModel(directoryRoot, new ToStringComparator());
    directoryTree = new JTree(directoryTreeModel);
    directoryTree.setCellRenderer(new DirectoryCellRenderer());
    directoryTree.setRootVisible(true);
    directoryTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    directoryTree.setEnabled(true);
    directoryTree.setEditable(false);
    directoryTree.setShowsRootHandles(true);
    directoryTree.addTreeSelectionListener(new TreeSelectionListener() {
        public void valueChanged(TreeSelectionEvent evt) {
            TreePath path = evt.getPath();
            TreePath leadPath = evt.getNewLeadSelectionPath();

            if ((path != null) && (leadPath != null)) {
                TaskManager.execute(new RefreshWorker(leadPath, false));
            }
        }
    });
    directoryTree.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent evt) {
            if (evt.getClickCount() == 2) {
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) directoryTree
                        .getLastSelectedPathComponent();

                if (!node.isRoot()) {
                    File dir = (File) node.getUserObject();

                    topPanel.setDirectory(dir.getAbsolutePath());
                }
            }
        }
    });

    JScrollPane directoryScroll = new JScrollPane(directoryTree);
    directoryScroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    directoryScroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
    directoryScroll.getViewport().setScrollMode(JViewport.BLIT_SCROLL_MODE);

    fileListModel = new ShortedListModel(new ToStringComparator());
    fileList = new JList(fileListModel);
    fileList.setDragEnabled(true);
    fileList.setCellRenderer(new FileCellRenderer());
    fileList.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent evt) {
            if (evt.getClickCount() == 2) {
                final int index = fileList.locationToIndex(evt.getPoint());

                TaskManager.execute(new Runnable() {
                    public void run() {
                        File file = (File) fileListModel.getElementAt(index);

                        if (log.isDebugEnabled()) {
                            log.debug(file);
                        }

                        IBuffer buffer = new BufferFactory().createBuffer();
                        buffer.open(file);

                        WorkspaceManager.addBuffer(buffer);
                    }
                });
            }
        }
    });

    JScrollPane filesScroll = new JScrollPane(fileList);
    filesScroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    filesScroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
    filesScroll.getViewport().setScrollMode(JViewport.BLIT_SCROLL_MODE);

    splitPane = new StrippedSplitPane(JSplitPane.VERTICAL_SPLIT, directoryScroll, filesScroll);
    splitPane.setBorder(BorderFactory.createEmptyBorder());
    splitPane.setOneTouchExpandable(false);
    splitPane.setDividerSize(5);
    splitPane.setDividerLocation(PreferenceManager.getInt("explorer.divider", 0));

    List<MutableTreeNode> dirs = openDirectory(rootDir);
    directoryTreeModel.insertAllInto(dirs, directoryRoot);

    List<File> files = getFiles(rootDir);
    fileListModel.addAll(files);

    directoryTree.expandRow(0);

    internalPanel.add(splitPane, BorderLayout.CENTER);

    setContent(internalPanel);
}