use of javax.swing.event.TreeSelectionListener in project sldeditor by robward-scisys.
the class FilterPanelv2 method createUI.
/**
* Creates the ui.
*/
private void createUI() {
JPanel treePanel = new JPanel();
getContentPane().add(treePanel, BorderLayout.WEST);
treePanel.setLayout(new BorderLayout(0, 0));
JScrollPane scrollPane = new JScrollPane();
treePanel.add(scrollPane);
Dimension preferredSize = new Dimension(400, 350);
scrollPane.setPreferredSize(preferredSize);
model = new ExpressionTreeModel(rootNode);
tree = new JTree(model);
tree.addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent e) {
selectedNode = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
CardLayout cardLayout = (CardLayout) dataPanel.getLayout();
if (selectedNode instanceof ExpressionNode) {
ExpressionNode expressionNode = (ExpressionNode) selectedNode;
if (expressionNode.getExpressionType() == ExpressionTypeEnum.LITERAL) {
cardLayout.show(dataPanel, literalPanel.getClass().getName());
literalPanel.setSelectedNode(selectedNode);
} else if (expressionNode.getExpressionType() == ExpressionTypeEnum.PROPERTY) {
cardLayout.show(dataPanel, propertyPanel.getClass().getName());
propertyPanel.setSelectedNode(selectedNode);
} else if (expressionNode.getExpressionType() == ExpressionTypeEnum.ENVVAR) {
cardLayout.show(dataPanel, envVarPanel.getClass().getName());
envVarPanel.setSelectedNode(selectedNode);
} else {
cardLayout.show(dataPanel, expressionPanel.getClass().getName());
expressionPanel.setSelectedNode(selectedNode);
}
} else if (selectedNode instanceof FilterNode) {
cardLayout.show(dataPanel, filterPanel.getClass().getName());
filterPanel.setSelectedNode(selectedNode);
} else {
cardLayout.show(dataPanel, EMPTY_PANEL);
}
}
});
scrollPane.setViewportView(tree);
dataPanel = new JPanel(new CardLayout());
dataPanel.add(emptyPanel, EMPTY_PANEL);
expressionPanel = new ExpressionSubPanel(this);
dataPanel.add(expressionPanel, ExpressionSubPanel.class.getName());
filterPanel = new FilterSubPanel(this);
dataPanel.add(filterPanel, FilterSubPanel.class.getName());
literalPanel = new LiteralPanel(this);
dataPanel.add(literalPanel, LiteralPanel.class.getName());
propertyPanel = new PropertyPanel(this);
dataPanel.add(propertyPanel, PropertyPanel.class.getName());
envVarPanel = new EnvVarPanel(this);
dataPanel.add(envVarPanel, EnvVarPanel.class.getName());
getContentPane().add(dataPanel, BorderLayout.CENTER);
JPanel buttonPanel = new JPanel();
FlowLayout flowLayout = (FlowLayout) buttonPanel.getLayout();
flowLayout.setAlignment(FlowLayout.TRAILING);
getContentPane().add(buttonPanel, BorderLayout.SOUTH);
btnOk = new JButton(Localisation.getString(ExpressionPanelv2.class, "common.ok"));
btnOk.setEnabled(false);
btnOk.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
closeDialog(true);
}
});
buttonPanel.add(btnOk);
JButton btnCancel = new JButton(Localisation.getString(ExpressionPanelv2.class, "common.cancel"));
btnCancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
closeDialog(false);
}
});
buttonPanel.add(btnCancel);
JPanel resultPanel = new JPanel();
getContentPane().add(resultPanel, BorderLayout.NORTH);
resultPanel.setLayout(new BorderLayout(0, 0));
JScrollPane scrollPane_1 = new JScrollPane();
resultPanel.add(scrollPane_1);
textArea = new JTextArea();
textArea.setEditable(false);
scrollPane_1.setViewportView(textArea);
}
use of javax.swing.event.TreeSelectionListener in project sldeditor by robward-scisys.
the class GeoServerStyleTree method createUI.
/**
* Creates the ui.
*/
private void createUI() {
setLayout(new BorderLayout());
styleCardPanel = new JPanel();
styleCardPanel.setLayout(new CardLayout(0, 0));
add(styleCardPanel, BorderLayout.CENTER);
JPanel styleTreePanel = new JPanel();
styleTreePanel.setLayout(new BorderLayout());
styleCardPanel.add(styleTreePanel, STYLE_PANEL);
geoserverStyleTree = new JTree(treeModel);
geoserverStyleTree.addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
if (!populating) {
setButtonState(true);
}
}
});
JScrollPane scrollPane = new JScrollPane(geoserverStyleTree);
styleTreePanel.add(scrollPane, BorderLayout.CENTER);
JPanel styleButtonsPanel = new JPanel();
styleTreePanel.add(styleButtonsPanel, BorderLayout.SOUTH);
btnApply = new JButton("Apply");
btnApply.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
LayerStyleNode node = (LayerStyleNode) geoserverStyleTree.getLastSelectedPathComponent();
if (parentObj != null) {
parentObj.selectedStyle(node.getStyleWrapper());
}
}
});
styleButtonsPanel.add(btnApply);
btnRevert = new JButton("Revert");
btnRevert.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
showSelectedStyle(originalStyleWrapper);
}
});
styleButtonsPanel.add(btnRevert);
//
// Empty panel
//
JPanel emptyPanel = new JPanel();
emptyPanel.setLayout(new BorderLayout());
styleCardPanel.add(emptyPanel, EMPTY_PANEL);
}
use of javax.swing.event.TreeSelectionListener 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();
}
use of javax.swing.event.TreeSelectionListener 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;
}
use of javax.swing.event.TreeSelectionListener 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();
}
}
Aggregations