Search in sources :

Example 21 with TreeSelectionEvent

use of javax.swing.event.TreeSelectionEvent in project pdfbox by apache.

the class PDFDebugger method initComponents.

/**
 * This method is called from within the constructor to initialize the form.
 */
private void initComponents() {
    jSplitPane1 = new javax.swing.JSplitPane();
    jScrollPane1 = new JScrollPane();
    tree = new Tree(this);
    jScrollPane2 = new JScrollPane();
    jTextPane1 = new javax.swing.JTextPane();
    tree.setCellRenderer(new PDFTreeCellRenderer());
    tree.setModel(null);
    setTitle("Apache PDFBox Debugger");
    addWindowListener(new java.awt.event.WindowAdapter() {

        @Override
        public void windowOpened(WindowEvent windowEvent) {
            tree.requestFocusInWindow();
            super.windowOpened(windowEvent);
        }

        @Override
        public void windowClosing(WindowEvent evt) {
            exitForm(evt);
        }
    });
    jScrollPane1.setBorder(new BevelBorder(BevelBorder.RAISED));
    jScrollPane1.setPreferredSize(new Dimension(350, 500));
    tree.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent evt) {
            jTree1ValueChanged(evt);
        }
    });
    jScrollPane1.setViewportView(tree);
    jSplitPane1.setRightComponent(jScrollPane2);
    jSplitPane1.setDividerSize(3);
    jScrollPane2.setPreferredSize(new Dimension(300, 500));
    jScrollPane2.setViewportView(jTextPane1);
    jSplitPane1.setLeftComponent(jScrollPane1);
    JScrollPane documentScroller = new JScrollPane();
    documentScroller.setViewportView(documentPanel);
    statusPane = new TreeStatusPane(tree);
    statusPane.getPanel().setBorder(new BevelBorder(BevelBorder.RAISED));
    statusPane.getPanel().setPreferredSize(new Dimension(300, 25));
    getContentPane().add(statusPane.getPanel(), BorderLayout.PAGE_START);
    getContentPane().add(jSplitPane1, BorderLayout.CENTER);
    statusBar = new ReaderBottomPanel();
    getContentPane().add(statusBar, BorderLayout.SOUTH);
    // create menus
    JMenuBar menuBar = new JMenuBar();
    menuBar.add(createFileMenu());
    menuBar.add(createEditMenu());
    ViewMenu viewMenu = ViewMenu.getInstance(this);
    menuBar.add(viewMenu.getMenu());
    setJMenuBar(menuBar);
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    int width = 1000;
    int height = 970;
    setBounds((screenSize.width - width) / 2, (screenSize.height - height) / 2, width, height);
    // drag and drop to open files
    setTransferHandler(new TransferHandler() {

        @Override
        public boolean canImport(TransferSupport transferSupport) {
            return transferSupport.isDataFlavorSupported(DataFlavor.javaFileListFlavor);
        }

        @Override
        @SuppressWarnings("unchecked")
        public boolean importData(TransferSupport transferSupport) {
            try {
                Transferable transferable = transferSupport.getTransferable();
                List<File> files = (List<File>) transferable.getTransferData(DataFlavor.javaFileListFlavor);
                readPDFFile(files.get(0), "");
                return true;
            } catch (IOException e) {
                new ErrorDialog(e).setVisible(true);
                return true;
            } catch (UnsupportedFlavorException e) {
                throw new RuntimeException(e);
            }
        }
    });
    // Mac OS X file open/quit handler
    if (IS_MAC_OS && !isMinJdk9()) {
        // TODO this needs to be rewritten for JDK9, see PDFBOX-4013
        try {
            Method osxOpenFiles = getClass().getDeclaredMethod("osxOpenFiles", String.class);
            osxOpenFiles.setAccessible(true);
            OSXAdapter.setFileHandler(this, osxOpenFiles);
            Method osxQuit = getClass().getDeclaredMethod("osxQuit");
            osxQuit.setAccessible(true);
            OSXAdapter.setQuitHandler(this, osxQuit);
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : BevelBorder(javax.swing.border.BevelBorder) TreeSelectionListener(javax.swing.event.TreeSelectionListener) TreeStatusPane(org.apache.pdfbox.debugger.treestatus.TreeStatusPane) PDFTreeCellRenderer(org.apache.pdfbox.debugger.ui.PDFTreeCellRenderer) Tree(org.apache.pdfbox.debugger.ui.Tree) ViewMenu(org.apache.pdfbox.debugger.ui.ViewMenu) List(java.util.List) JScrollPane(javax.swing.JScrollPane) Transferable(java.awt.datatransfer.Transferable) ErrorDialog(org.apache.pdfbox.debugger.ui.ErrorDialog) Dimension(java.awt.Dimension) IOException(java.io.IOException) Method(java.lang.reflect.Method) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) WindowEvent(java.awt.event.WindowEvent) TransferHandler(javax.swing.TransferHandler) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) ReaderBottomPanel(org.apache.pdfbox.debugger.ui.ReaderBottomPanel) File(java.io.File) JMenuBar(javax.swing.JMenuBar)

Example 22 with TreeSelectionEvent

use of javax.swing.event.TreeSelectionEvent in project Spark by igniterealtime.

the class JavaMixer method main.

public static void main(String[] args) {
    final JavaMixer sm = new JavaMixer();
    final JFrame jf = new JFrame("Mixer Test");
    final JPanel jp = new JPanel();
    jf.add(jp);
    jp.add(sm.getTree());
    jf.setSize(600, 500);
    jf.setVisible(true);
    jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    sm.getTree().addTreeSelectionListener(new TreeSelectionListener() {

        public void valueChanged(TreeSelectionEvent e) {
            TreePath path = e.getPath();
            if (path.getLastPathComponent() instanceof JavaMixer.ControlNode) {
                JavaMixer.ControlNode controlNode = (JavaMixer.ControlNode) path.getLastPathComponent();
                if (!(controlNode.getControl() instanceof CompoundControl)) {
                    if (jp.getComponentCount() > 1)
                        jp.remove(1);
                    jp.add(controlNode.getComponent(), 1);
                    jp.repaint();
                }
            }
        }
    });
    jp.add(sm.getPrefferedMasterVolume());
    jp.add(sm.getPrefferedMasterVolume());
    jp.add(sm.getPrefferedInputVolume());
    jp.repaint();
    sm.setMicrophoneInput();
    sm.setMuteForMicrophoneOutput();
}
Also used : JPanel(javax.swing.JPanel) CompoundControl(javax.sound.sampled.CompoundControl) TreePath(javax.swing.tree.TreePath) JFrame(javax.swing.JFrame) TreeSelectionListener(javax.swing.event.TreeSelectionListener) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Example 23 with TreeSelectionEvent

use of javax.swing.event.TreeSelectionEvent in project Spark by igniterealtime.

the class WorkgroupInvitationDialog method hasSelectedAgent.

/**
 * Returns the agent selected.
 *
 * @param chatRoom the room this roster will be used with.
 * @param transfer true if this will be a transfer.
 * @return true if a valid agent has been selected.
 */
public boolean hasSelectedAgent(ChatRoom chatRoom, boolean transfer) {
    final JiveTreeNode workgroupsNode = new JiveTreeNode("Workgroups", true);
    final JiveTreeNode queueNode = new JiveTreeNode("Queues", true);
    final String workgroupService = "workgroup." + SparkManager.getSessionManager().getServerAddress();
    final String jid = SparkManager.getSessionManager().getJID();
    String room = chatRoom.getRoomname();
    Collection agents = null;
    try {
        agents = getAvailableAgents(FastpathPlugin.getAgentSession().getAgentRoster(), room);
    } catch (SmackException.NotConnectedException e) {
        Log.warning("Unable to get agent roster.", e);
    }
    // Clear jid field
    jidField.setText("");
    String title = FpRes.getString("invite.agent");
    String acceptButton = FpRes.getString("invite");
    if (transfer) {
        title = FpRes.getString("transfer.to.agent");
        acceptButton = FpRes.getString("transfer");
    }
    String stockMessage = FpRes.getString("message.transfering.to.user");
    if (!transfer) {
        stockMessage = FpRes.getString("message.join.me.in.chat");
    }
    rootNode = new JiveTreeNode("Ask For Assistance", true);
    tree = new Tree(rootNode);
    tree.setCellRenderer(new JiveTreeCellRenderer());
    // This will remove lines from the tree and setup initial l&f
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.setRowHeight(16);
    tree.setExpandsSelectedPaths(true);
    tree.addTreeSelectionListener(new TreeSelectionListener() {

        public void valueChanged(TreeSelectionEvent e) {
            TreePath path = e.getNewLeadSelectionPath();
            Object o = path.getLastPathComponent();
            if (o instanceof JiveTreeNode) {
                JiveTreeNode node = (JiveTreeNode) o;
                JiveTreeNode parentNode = (JiveTreeNode) node.getParent();
                if (parentNode == workgroupsNode) {
                    jidField.setText(node.getUserObject().toString() + "@" + workgroupService);
                } else if (parentNode == queueNode) {
                    jidField.setText(FastpathPlugin.getWorkgroup().getWorkgroupJID() + "/" + node.getUserObject().toString());
                } else {
                    String agent = getAgent();
                    jidField.setText(agent);
                }
            }
        }
    });
    // Create message field
    messageField = new JTextArea();
    messageField.setWrapStyleWord(true);
    inviteLabel = new JLabel();
    if (transfer) {
        inviteLabel.setText(FpRes.getString("transfer.to") + ":");
    } else {
        inviteLabel.setText(FpRes.getString("invite") + ":");
    }
    if (transfer) {
        // Create the title panel for this dialog
        titlePanel = new TitlePanel(FpRes.getString("title.transfer"), FpRes.getString("message.transfer.to.another.agent"), FastpathRes.getImageIcon(FastpathRes.CHATTING_AGENT_IMAGE), true);
    } else {
        // Create the title panel for this dialog
        titlePanel = new TitlePanel(FpRes.getString("title.invitation"), FpRes.getString("message.invite.another.agent"), FastpathRes.getImageIcon(FastpathRes.CHATTING_AGENT_IMAGE), true);
    }
    // Build Tree
    String joinedWorkgroupName = XmppStringUtils.parseLocalpart(FastpathPlugin.getWorkgroup().getWorkgroupJID());
    final JiveTreeNode workgroupNode = new JiveTreeNode(joinedWorkgroupName, true);
    final Iterator agentIter = agents.iterator();
    while (agentIter.hasNext()) {
        while (agentIter.hasNext()) {
            String agentName = UserManager.unescapeJID((String) agentIter.next());
            final JiveTreeNode agentNode = new JiveTreeNode(agentName, false, FastpathRes.getImageIcon(FastpathRes.GREEN_BALL));
            workgroupNode.add(agentNode);
        }
        if (workgroupNode.getChildCount() > 0) {
            rootNode.add(workgroupNode);
        }
    }
    Collection workgroupAgents;
    try {
        workgroupAgents = Agent.getWorkgroups(workgroupService, jid, SparkManager.getConnection());
    } catch (XMPPException | SmackException e) {
        Log.error(e);
        workgroupAgents = Collections.EMPTY_LIST;
    }
    if (workgroupAgents.size() > 0) {
        // Add workgroups to combobox
        Iterator<String> workgroups = workgroupAgents.iterator();
        while (workgroups.hasNext()) {
            String workgroup = workgroups.next();
            String workgroupName = XmppStringUtils.parseLocalpart(workgroup);
            final JiveTreeNode wgNode = new JiveTreeNode(workgroupName, false, FastpathRes.getImageIcon(FastpathRes.FASTPATH_IMAGE_16x16));
            workgroupsNode.add(wgNode);
        }
        rootNode.add(workgroupsNode);
    }
    Iterator iter = FastpathPlugin.getAgentSession().getQueues();
    while (iter.hasNext()) {
        final WorkgroupQueue queue = (WorkgroupQueue) iter.next();
        if (queue.getStatus() == WorkgroupQueue.Status.OPEN) {
            final JiveTreeNode qNode = new JiveTreeNode(queue.getName(), false, FastpathRes.getImageIcon(FastpathRes.FASTPATH_IMAGE_16x16));
            queueNode.add(qNode);
        }
    }
    rootNode.add(queueNode);
    // New Roster tree. Do not show agents at all.
    final UserManager userManager = SparkManager.getUserManager();
    Collection jids = userManager.getUserJidsInRoom(room, false);
    roster = new WorkgroupRosterTree(jids, false, workgroups);
    try {
        rosterTree = roster.getRosterTree();
        JiveTreeNode node = (JiveTreeNode) rosterTree.getModel().getRoot();
        rootNode.add(node);
    } catch (Exception e) {
        Log.error("Error checking for selected agent", e);
    }
    // Construct main panel w/ layout.
    final JPanel mainPanel = new JPanel();
    mainPanel.setLayout(new BorderLayout());
    mainPanel.add(titlePanel, BorderLayout.NORTH);
    // The user should only be able to close this dialog.
    Object[] options = { acceptButton, FpRes.getString("cancel") };
    // Create objects to add to mainPanel.
    final JPanel parentPanel = new JPanel();
    final JLabel messageLabel = new JLabel();
    final JLabel agentLabel = new JLabel();
    parentPanel.setLayout(new GridBagLayout());
    // Update Labels using ResourceUtils
    ResourceUtils.resLabel(messageLabel, messageField, FpRes.getString("label.message.to.agent"));
    ResourceUtils.resLabel(agentLabel, tree, FpRes.getString("label.select.agent"));
    // Add Components to Parent Panel
    parentPanel.add(agentLabel, new GridBagConstraints(0, 0, 3, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 0, 5), 0, 0));
    parentPanel.add(new JScrollPane(tree), new GridBagConstraints(0, 1, 3, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 100));
    parentPanel.add(messageLabel, new GridBagConstraints(0, 3, 3, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 0, 5), 0, 0));
    parentPanel.add(new JScrollPane(messageField), new GridBagConstraints(0, 4, 3, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 25));
    parentPanel.add(inviteLabel, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
    parentPanel.add(jidField, new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
    // Use line wrap.
    messageField.setLineWrap(true);
    // Update MessageField with stock message
    messageField.setText(stockMessage);
    // Add Parent Object to master OptionPane
    pane = new JOptionPane(parentPanel, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, options, options[0]);
    mainPanel.add(pane, BorderLayout.CENTER);
    dlg = new JDialog(SparkManager.getChatManager().getChatContainer().getChatFrame(), title, true);
    dlg.pack();
    dlg.setSize(500, 500);
    dlg.setContentPane(mainPanel);
    dlg.setLocationRelativeTo(chatRoom);
    pane.addPropertyChangeListener(this);
    // expand the tree for displaying
    for (int i = 0; i <= tree.getRowCount(); i++) {
        tree.expandPath(tree.getPathForRow(i));
    }
    dlg.setVisible(true);
    dlg.toFront();
    dlg.requestFocus();
    if (!isValid) {
        return false;
    }
    return true;
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) JTextArea(javax.swing.JTextArea) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) TreeSelectionListener(javax.swing.event.TreeSelectionListener) WorkgroupQueue(org.jivesoftware.smackx.workgroup.agent.WorkgroupQueue) JiveTreeCellRenderer(org.jivesoftware.spark.component.JiveTreeCellRenderer) BorderLayout(java.awt.BorderLayout) JiveTreeNode(org.jivesoftware.spark.component.JiveTreeNode) Iterator(java.util.Iterator) Tree(org.jivesoftware.spark.component.Tree) JScrollPane(javax.swing.JScrollPane) SmackException(org.jivesoftware.smack.SmackException) JLabel(javax.swing.JLabel) JOptionPane(javax.swing.JOptionPane) TitlePanel(org.jivesoftware.spark.component.TitlePanel) SmackException(org.jivesoftware.smack.SmackException) XMPPException(org.jivesoftware.smack.XMPPException) TreePath(javax.swing.tree.TreePath) UserManager(org.jivesoftware.spark.UserManager) Collection(java.util.Collection) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) XMPPException(org.jivesoftware.smack.XMPPException) JDialog(javax.swing.JDialog)

Example 24 with TreeSelectionEvent

use of javax.swing.event.TreeSelectionEvent in project gate-core by GateNLP.

the class MainFrame method initListeners.

protected void initListeners() {
    Gate.getCreoleRegister().addCreoleListener(this);
    Gate.getCreoleRegister().addPluginListener(this);
    resourcesTree.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                // shows in the central tabbed pane, the selected resources
                // in the resource tree when the Enter key is pressed
                (new ShowSelectedResourcesAction()).actionPerformed(null);
            } else if (e.getKeyCode() == KeyEvent.VK_DELETE) {
                // close selected resources from GATE
                (new CloseSelectedResourcesAction()).actionPerformed(null);
            } else if (e.getKeyCode() == KeyEvent.VK_DELETE && e.getModifiers() == InputEvent.SHIFT_DOWN_MASK) {
                // close recursively selected resources from GATE
                (new CloseRecursivelySelectedResourcesAction()).actionPerformed(null);
            }
        }
    });
    resourcesTree.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            TreePath path = resourcesTree.getClosestPathForLocation(e.getX(), e.getY());
            if (e.isPopupTrigger() && !resourcesTree.isPathSelected(path)) {
                // if right click outside the selection then reset selection
                resourcesTree.getSelectionModel().setSelectionPath(path);
            }
            processMouseEvent(e);
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            processMouseEvent(e);
        }

        @Override
        public void mouseClicked(MouseEvent e) {
            processMouseEvent(e);
        }

        protected void processMouseEvent(MouseEvent e) {
            // where inside the tree?
            int x = e.getX();
            int y = e.getY();
            TreePath path = resourcesTree.getClosestPathForLocation(x, y);
            JPopupMenu popup = null;
            Handle handle = null;
            if (path != null) {
                Object value = path.getLastPathComponent();
                if (value == resourcesTreeRoot) {
                // no default item for this menu
                } else if (value == applicationsRoot) {
                    appsPopup = new XJPopupMenu();
                    LiveMenu appsMenu = new LiveMenu(LiveMenu.APP);
                    appsMenu.setText("Create New Application");
                    appsMenu.setIcon(MainFrame.getIcon("applications"));
                    appsPopup.add(appsMenu);
                    appsPopup.add(new ReadyMadeMenu());
                    appsPopup.add(new XJMenuItem(new LoadResourceFromFileAction(), MainFrame.this));
                    RecentAppsMenu recentApps = new RecentAppsMenu();
                    if (recentApps.getMenuComponentCount() > 0)
                        appsPopup.add(recentApps);
                    popup = appsPopup;
                } else if (value == languageResourcesRoot) {
                    popup = lrsPopup;
                } else if (value == processingResourcesRoot) {
                    popup = prsPopup;
                } else if (value == datastoresRoot) {
                    popup = dssPopup;
                } else {
                    value = ((DefaultMutableTreeNode) value).getUserObject();
                    if (value instanceof Handle) {
                        handle = (Handle) value;
                        fileChooser.setResource(handle.getTarget().getClass().getName());
                        if (e.isPopupTrigger()) {
                            popup = handle.getPopup();
                        }
                    }
                }
            }
            // popup menu
            if (e.isPopupTrigger()) {
                if (resourcesTree.getSelectionCount() > 1) {
                    // multiple selection in tree
                    popup = new XJPopupMenu();
                    // add a close all action
                    popup.add(new XJMenuItem(new CloseSelectedResourcesAction(), MainFrame.this));
                    // add a close recursively all action
                    TreePath[] selectedPaths = resourcesTree.getSelectionPaths();
                    for (TreePath selectedPath : selectedPaths) {
                        Object userObject = ((DefaultMutableTreeNode) selectedPath.getLastPathComponent()).getUserObject();
                        if (userObject instanceof NameBearerHandle && ((NameBearerHandle) userObject).getTarget() instanceof Controller) {
                            // there is at least one application
                            popup.add(new XJMenuItem(new CloseRecursivelySelectedResourcesAction(), MainFrame.this));
                            break;
                        }
                    }
                    // add a show all action
                    selectedPaths = resourcesTree.getSelectionPaths();
                    for (TreePath selectedPath : selectedPaths) {
                        Object userObject = ((DefaultMutableTreeNode) selectedPath.getLastPathComponent()).getUserObject();
                        if (userObject instanceof Handle && (!((Handle) userObject).viewsBuilt() || (mainTabbedPane.indexOfComponent(((Handle) userObject).getLargeView()) == -1))) {
                            // there is at least one resource not shown
                            popup.add(new XJMenuItem(new ShowSelectedResourcesAction(), MainFrame.this));
                            break;
                        }
                    }
                    // add a hide all action
                    selectedPaths = resourcesTree.getSelectionPaths();
                    for (TreePath selectedPath : selectedPaths) {
                        Object userObject = ((DefaultMutableTreeNode) selectedPath.getLastPathComponent()).getUserObject();
                        if (userObject instanceof Handle && ((Handle) userObject).viewsBuilt() && ((Handle) userObject).getLargeView() != null && (mainTabbedPane.indexOfComponent(((Handle) userObject).getLargeView()) != -1)) {
                            // there is at least one resource shown
                            popup.add(new XJMenuItem(new CloseViewsForSelectedResourcesAction(), MainFrame.this));
                            break;
                        }
                    }
                    popup.show(resourcesTree, e.getX(), e.getY());
                } else if (popup != null) {
                    if (handle != null) {
                        // add a close action
                        if (handle instanceof NameBearerHandle) {
                            popup.insert(new XJMenuItem(((NameBearerHandle) handle).getCloseAction(), MainFrame.this), 0);
                        }
                        // if application then add a close recursively action
                        if (handle instanceof NameBearerHandle && handle.getTarget() instanceof Controller) {
                            popup.insert(new XJMenuItem(((NameBearerHandle) handle).getCloseRecursivelyAction(), MainFrame.this), 1);
                        }
                        // add a show/hide action
                        if (handle.viewsBuilt() && handle.getLargeView() != null && (mainTabbedPane.indexOfComponent(handle.getLargeView()) != -1)) {
                            popup.insert(new XJMenuItem(new CloseViewAction(handle), MainFrame.this), 2);
                        } else {
                            popup.insert(new XJMenuItem(new ShowResourceAction(handle), MainFrame.this), 2);
                        }
                        // add a rename action
                        popup.insert(new XJMenuItem(new RenameResourceAction(path), MainFrame.this), 3);
                        // add a help action
                        if (handle instanceof NameBearerHandle) {
                            popup.insert(new XJMenuItem(new HelpOnItemTreeAction((NameBearerHandle) handle), MainFrame.this), 4);
                        }
                    }
                    popup.show(resourcesTree, e.getX(), e.getY());
                }
            } else if (e.getID() == MouseEvent.MOUSE_CLICKED && e.getClickCount() == 2 && handle != null) {
                // double click - show the resource
                select(handle);
            }
        }
    });
    resourcesTree.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {
            if (!Gate.getUserConfig().getBoolean(MainFrame.class.getName() + ".treeselectview")) {
                return;
            }
            // the resource tree selection
            if (resourcesTree.getSelectionPaths() != null && resourcesTree.getSelectionPaths().length == 1) {
                Object value = e.getPath().getLastPathComponent();
                Object object = ((DefaultMutableTreeNode) value).getUserObject();
                if (object instanceof Handle && ((Handle) object).viewsBuilt() && (mainTabbedPane.indexOfComponent(((Handle) object).getLargeView()) != -1)) {
                    select((Handle) object);
                }
            }
        }
    });
    // define keystrokes action bindings at the level of the main window
    InputMap inputMap = ((JComponent) this.getContentPane()).getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    inputMap.put(KeyStroke.getKeyStroke("control F4"), "Close resource");
    inputMap.put(KeyStroke.getKeyStroke("shift F4"), "Close recursively");
    inputMap.put(KeyStroke.getKeyStroke("control H"), "Hide");
    inputMap.put(KeyStroke.getKeyStroke("control shift H"), "Hide all");
    inputMap.put(KeyStroke.getKeyStroke("control S"), "Save As XML");
    // TODO: remove when Swing will take care of the context menu key
    if (inputMap.get(KeyStroke.getKeyStroke("CONTEXT_MENU")) == null) {
        inputMap.put(KeyStroke.getKeyStroke("CONTEXT_MENU"), "Show context menu");
    }
    ActionMap actionMap = ((JComponent) instance.getContentPane()).getActionMap();
    actionMap.put("Show context menu", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            KeyboardFocusManager focusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
            // get the current focused component
            Component focusedComponent = focusManager.getFocusOwner();
            if (focusedComponent != null) {
                Point menuLocation = null;
                Rectangle selectionRectangle = null;
                if (focusedComponent instanceof JTable && ((JTable) focusedComponent).getSelectedRowCount() > 0) {
                    // selection in a JTable
                    JTable table = (JTable) focusedComponent;
                    selectionRectangle = table.getCellRect(table.getSelectionModel().getLeadSelectionIndex(), table.convertColumnIndexToView(table.getSelectedColumn()), false);
                } else if (focusedComponent instanceof JTree && ((JTree) focusedComponent).getSelectionCount() > 0) {
                    // selection in a JTree
                    JTree tree = (JTree) focusedComponent;
                    selectionRectangle = tree.getRowBounds(tree.getSelectionModel().getLeadSelectionRow());
                } else {
                    // for other component set the menu location at the top left corner
                    menuLocation = new Point(focusedComponent.getX() - 1, focusedComponent.getY() - 1);
                }
                if (menuLocation == null) {
                    // menu location at the bottom left of the JTable or JTree
                    menuLocation = new Point(new Double(selectionRectangle.getMinX() + 1).intValue(), new Double(selectionRectangle.getMaxY() - 1).intValue());
                }
                // generate a right/button 3/popup menu mouse click
                focusedComponent.dispatchEvent(new MouseEvent(focusedComponent, MouseEvent.MOUSE_PRESSED, e.getWhen(), MouseEvent.BUTTON3_DOWN_MASK, menuLocation.x, menuLocation.y, 1, true, MouseEvent.BUTTON3));
            }
        }
    });
    mainTabbedPane.getModel().addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            // find the handle in the resources tree for the main view
            JComponent largeView = (JComponent) mainTabbedPane.getSelectedComponent();
            Enumeration<?> nodesEnum = resourcesTreeRoot.preorderEnumeration();
            boolean done = false;
            DefaultMutableTreeNode node = resourcesTreeRoot;
            while (!done && nodesEnum.hasMoreElements()) {
                node = (DefaultMutableTreeNode) nodesEnum.nextElement();
                done = node.getUserObject() instanceof Handle && ((Handle) node.getUserObject()).viewsBuilt() && ((Handle) node.getUserObject()).getLargeView() == largeView;
            }
            ActionMap actionMap = ((JComponent) instance.getContentPane()).getActionMap();
            if (done) {
                Handle handle = (Handle) node.getUserObject();
                if (Gate.getUserConfig().getBoolean(MainFrame.class.getName() + ".viewselecttree")) {
                    // synchronise the selection in the tabbed pane with
                    // the one in the resources tree
                    TreePath nodePath = new TreePath(node.getPath());
                    resourcesTree.setSelectionPath(nodePath);
                    resourcesTree.scrollPathToVisible(nodePath);
                }
                lowerScroll.getViewport().setView(handle.getSmallView());
                // redefine MainFrame actionMaps for the selected tab
                JComponent resource = (JComponent) mainTabbedPane.getSelectedComponent();
                actionMap.put("Close resource", resource.getActionMap().get("Close resource"));
                actionMap.put("Close recursively", resource.getActionMap().get("Close recursively"));
                actionMap.put("Hide", new CloseViewAction(handle));
                actionMap.put("Hide all", new HideAllAction());
                actionMap.put("Save As XML", resource.getActionMap().get("Save As XML"));
            } else {
                // the selected item is not a resource (maybe the log area?)
                lowerScroll.getViewport().setView(null);
                // disabled actions on the selected tabbed pane
                actionMap.put("Close resource", null);
                actionMap.put("Close recursively", null);
                actionMap.put("Hide", null);
                actionMap.put("Hide all", null);
                actionMap.put("Save As XML", null);
            }
        }
    });
    mainTabbedPane.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            processMouseEvent(e);
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            processMouseEvent(e);
        }

        protected void processMouseEvent(MouseEvent e) {
            if (e.isPopupTrigger()) {
                int index = mainTabbedPane.getIndexAt(e.getPoint());
                if (index != -1) {
                    JComponent view = (JComponent) mainTabbedPane.getComponentAt(index);
                    Enumeration<?> nodesEnum = resourcesTreeRoot.preorderEnumeration();
                    boolean done = false;
                    DefaultMutableTreeNode node = resourcesTreeRoot;
                    while (!done && nodesEnum.hasMoreElements()) {
                        node = (DefaultMutableTreeNode) nodesEnum.nextElement();
                        done = node.getUserObject() instanceof Handle && ((Handle) node.getUserObject()).viewsBuilt() && ((Handle) node.getUserObject()).getLargeView() == view;
                    }
                    if (done) {
                        Handle handle = (Handle) node.getUserObject();
                        JPopupMenu popup = handle.getPopup();
                        // add a hide action
                        CloseViewAction cva = new CloseViewAction(handle);
                        XJMenuItem menuItem = new XJMenuItem(cva, MainFrame.this);
                        popup.insert(menuItem, 0);
                        // add a hide all action
                        if (mainTabbedPane.getTabCount() > 2) {
                            HideAllAction haa = new HideAllAction();
                            menuItem = new XJMenuItem(haa, MainFrame.this);
                            popup.insert(menuItem, 1);
                        }
                        popup.show(mainTabbedPane, e.getX(), e.getY());
                    }
                }
            }
        }
    });
    addComponentListener(new ComponentAdapter() {

        @Override
        public void componentShown(ComponentEvent e) {
            leftSplit.setDividerLocation(0.7);
        }

        @Override
        public void componentResized(ComponentEvent e) {
            // resize proportionally the status bar elements
            int width = MainFrame.this.getWidth();
            statusBar.setPreferredSize(new Dimension(width * 65 / 100, statusBar.getPreferredSize().height));
            progressBar.setPreferredSize(new Dimension(width * 20 / 100, progressBar.getPreferredSize().height));
            progressBar.setMinimumSize(new Dimension(80, 0));
            globalProgressBar.setPreferredSize(new Dimension(width * 10 / 100, globalProgressBar.getPreferredSize().height));
            globalProgressBar.setMinimumSize(new Dimension(80, 0));
        }
    });
    // blink the messages tab when new information is displayed
    logArea.getDocument().addDocumentListener(new javax.swing.event.DocumentListener() {

        @Override
        public void insertUpdate(javax.swing.event.DocumentEvent e) {
            changeOccured();
        }

        @Override
        public void removeUpdate(javax.swing.event.DocumentEvent e) {
            changeOccured();
        }

        @Override
        public void changedUpdate(javax.swing.event.DocumentEvent e) {
        }

        protected void changeOccured() {
            logHighlighter.highlight();
        }
    });
    logArea.addPropertyChangeListener("document", new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            // add the document listener
            logArea.getDocument().addDocumentListener(new javax.swing.event.DocumentListener() {

                @Override
                public void insertUpdate(javax.swing.event.DocumentEvent e) {
                    changeOccured();
                }

                @Override
                public void removeUpdate(javax.swing.event.DocumentEvent e) {
                    changeOccured();
                }

                @Override
                public void changedUpdate(javax.swing.event.DocumentEvent e) {
                    changeOccured();
                }

                protected void changeOccured() {
                    logHighlighter.highlight();
                }
            });
        }
    });
    Gate.getListeners().put("gate.event.StatusListener", MainFrame.this);
    Gate.getListeners().put("gate.event.ProgressListener", MainFrame.this);
    if (Gate.runningOnMac()) {
        // mac-specific initialisation
        initMacListeners();
    }
}
Also used : ActionEvent(java.awt.event.ActionEvent) KeyAdapter(java.awt.event.KeyAdapter) Rectangle(java.awt.Rectangle) AbstractAction(javax.swing.AbstractAction) PropertyChangeEvent(java.beans.PropertyChangeEvent) JTree(javax.swing.JTree) JTable(javax.swing.JTable) InputMap(javax.swing.InputMap) ComponentEvent(java.awt.event.ComponentEvent) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) PropertyChangeListener(java.beans.PropertyChangeListener) TreeSelectionListener(javax.swing.event.TreeSelectionListener) KeyEvent(java.awt.event.KeyEvent) MenuKeyEvent(javax.swing.event.MenuKeyEvent) XJPopupMenu(gate.swing.XJPopupMenu) KeyboardFocusManager(java.awt.KeyboardFocusManager) ChangeListener(javax.swing.event.ChangeListener) PropertyChangeListener(java.beans.PropertyChangeListener) Component(java.awt.Component) JComponent(javax.swing.JComponent) ComponentAdapter(java.awt.event.ComponentAdapter) MouseEvent(java.awt.event.MouseEvent) Enumeration(java.util.Enumeration) ActionMap(javax.swing.ActionMap) MouseAdapter(java.awt.event.MouseAdapter) JComponent(javax.swing.JComponent) Point(java.awt.Point) Dimension(java.awt.Dimension) Controller(gate.Controller) ConditionalSerialAnalyserController(gate.creole.ConditionalSerialAnalyserController) PackagedController(gate.creole.PackagedController) XJPopupMenu(gate.swing.XJPopupMenu) JPopupMenu(javax.swing.JPopupMenu) TreePath(javax.swing.tree.TreePath) ChangeEvent(javax.swing.event.ChangeEvent) PropertyChangeEvent(java.beans.PropertyChangeEvent) XJMenuItem(gate.swing.XJMenuItem) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Example 25 with TreeSelectionEvent

use of javax.swing.event.TreeSelectionEvent in project sirix by sirixdb.

the class TreeView method refreshUpdate.

@Override
public void refreshUpdate(final Optional<VisualItemAxis> pAxis) {
    // Use our sirix model and renderer.
    dispose();
    final ReadDB db = mGUI.getReadDB();
    mTree.setModel(new TreeModel(db));
    mTree.setCellRenderer(new TreeCellRenderer(db));
    if (mTree.getTreeSelectionListeners().length == 0) {
        // Listen for when the selection changes.
        mTree.addTreeSelectionListener(new TreeSelectionListener() {

            @Override
            public void valueChanged(final TreeSelectionEvent paramE) {
                if (paramE.getNewLeadSelectionPath() != null && paramE.getNewLeadSelectionPath() != paramE.getOldLeadSelectionPath()) {
                    /*
						 * Returns the last path element of the selection. This method is
						 * useful only when the selection model allows a single selection.
						 */
                    final Node node = (Node) paramE.getNewLeadSelectionPath().getLastPathComponent();
                    db.setKey(node.getNodeKey());
                    mNotifier.update(mView, Optional.<VisualItemAxis>absent());
                }
            }
        });
    }
}
Also used : VisualItemAxis(org.sirix.gui.view.VisualItemAxis) Node(org.sirix.node.interfaces.Node) TreeSelectionListener(javax.swing.event.TreeSelectionListener) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) ReadDB(org.sirix.gui.ReadDB)

Aggregations

TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)85 TreeSelectionListener (javax.swing.event.TreeSelectionListener)82 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)34 TreePath (javax.swing.tree.TreePath)32 JTree (javax.swing.JTree)27 ActionEvent (java.awt.event.ActionEvent)23 JScrollPane (javax.swing.JScrollPane)23 JPanel (javax.swing.JPanel)22 ActionListener (java.awt.event.ActionListener)20 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)18 MouseEvent (java.awt.event.MouseEvent)15 BorderLayout (java.awt.BorderLayout)14 Dimension (java.awt.Dimension)13 GridBagConstraints (java.awt.GridBagConstraints)12 GridBagLayout (java.awt.GridBagLayout)12 Insets (java.awt.Insets)12 JButton (javax.swing.JButton)11 Tree (com.intellij.ui.treeStructure.Tree)9 KeyAdapter (java.awt.event.KeyAdapter)9 KeyEvent (java.awt.event.KeyEvent)9