use of javax.swing.event.TreeSelectionEvent in project CCDD by nasa.
the class CcddAssignmentTreeHandler method createTreePanel.
/**
********************************************************************************************
* Create an assignment tree panel. The table tree is placed in a scroll pane. A check box is
* added that allows tree expansion/collapse
*
* @param label
* assignment tree title
*
* @param selectionMode
* tree item selection mode (single versus multiple)
*
* @return JPanel containing the assignment tree components
********************************************************************************************
*/
protected JPanel createTreePanel(int selectionMode) {
// Create an empty border
Border emptyBorder = BorderFactory.createEmptyBorder();
// Set the initial layout manager characteristics
GridBagConstraints gbc = new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2, ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing() / 2, ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2, ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing() / 2), 0, 0);
// Set the table tree selection mode
getSelectionModel().setSelectionMode(selectionMode);
// Create a panel to contain the table tree
JPanel treePnl = new JPanel(new GridBagLayout());
treePnl.setBorder(emptyBorder);
// Create the tree scroll pane
JScrollPane treeScroll = new JScrollPane(this);
treeScroll.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED, Color.LIGHT_GRAY, Color.GRAY), BorderFactory.createEmptyBorder(ModifiableSpacingInfo.INPUT_FIELD_PADDING.getSpacing(), ModifiableSpacingInfo.INPUT_FIELD_PADDING.getSpacing(), ModifiableSpacingInfo.INPUT_FIELD_PADDING.getSpacing(), ModifiableSpacingInfo.INPUT_FIELD_PADDING.getSpacing())));
// Add the tree to the panel
treePnl.add(treeScroll, gbc);
// Set the table tree font and number of rows to display
setFont(ModifiableFontInfo.TREE_NODE.getFont());
setVisibleRowCount(10);
// Add a listener for changes to the assignment tree
addTreeSelectionListener(new TreeSelectionListener() {
/**
************************************************************************************
* Handle a change to the assignment tree selection
************************************************************************************
*/
@Override
public void valueChanged(TreeSelectionEvent lse) {
// triggers tree selection value changes that should not be processed
if (!isBuilding) {
// Update the assignment dialog based on the assignment(s) selected
updateTableSelection();
}
}
});
// Create a tree expansion check box
final JCheckBox expandChkBx = new JCheckBox("Expand all");
expandChkBx.setBorder(emptyBorder);
expandChkBx.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
expandChkBx.setSelected(false);
gbc.weighty = 0.0;
gbc.gridy++;
treePnl.add(expandChkBx, gbc);
// Create a listener for changes in selection of the tree expansion check box
expandChkBx.addActionListener(new ActionListener() {
/**
************************************************************************************
* Handle a change to the tree expansion check box selection
************************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
// Set the flag indicating if the tree is fully expanded
isExpanded = expandChkBx.isSelected();
// Set the tree expansion based on the check box status
setTreeExpansion(isExpanded);
}
});
// Create a hide data type check box
final JCheckBox hideTypeChkBx = new JCheckBox("Hide data type");
hideTypeChkBx.setBorder(emptyBorder);
hideTypeChkBx.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
hideTypeChkBx.setSelected(false);
gbc.insets.top = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2;
gbc.weighty = 0.0;
gbc.gridy++;
treePnl.add(hideTypeChkBx, gbc);
// Create a listener for changes in selection of the hide data type check box
hideTypeChkBx.addActionListener(new ActionListener() {
/**
************************************************************************************
* Handle a change to the hide data type check box selection
************************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
setEnableDataType(!hideTypeChkBx.isSelected());
// Store the tree's current expansion state
String expState = getExpansionState();
// Force the root node to draw with the node additions
((DefaultTreeModel) treeModel).nodeStructureChanged(getRootNode());
setExpansionState(expState);
}
});
return treePnl;
}
use of javax.swing.event.TreeSelectionEvent in project mafscaling by vimsh.
the class VVTCalc method createTreePanel.
protected void createTreePanel() {
DefaultMutableTreeNode wotTreeRoot = new DefaultMutableTreeNode("Root");
DefaultTreeModel treeModel = new DefaultTreeModel(wotTreeRoot);
pullTree = new JTree(treeModel);
pullTree.setCellRenderer(new PullNodeRenderer());
pullTree.setCellEditor(new CheckBoxNodeEditor(pullTree));
pullTree.setEditable(true);
pullTree.setRootVisible(false);
pullTree.setOpaque(false);
pullTree.setBackground(null);
pullTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
pullTree.addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
Object obj = ((DefaultMutableTreeNode) e.getPath().getLastPathComponent()).getUserObject();
if (obj instanceof CheckBoxNodeData) {
CheckBoxNodeData checkBoxNode = (CheckBoxNodeData) obj;
XYSeriesCollection dataset;
XYSeries series;
for (int i = 0; i < hiddenSeries.size(); ++i) {
dataset = (XYSeriesCollection) chartPanels[i].getChart().getXYPlot().getDataset(0);
if (checkBoxNode.isChecked()) {
series = hiddenSeries.get(i).get(checkBoxNode.getText());
if (series != null) {
dataset.addSeries(series);
hiddenSeries.get(i).remove(checkBoxNode.getText());
}
} else {
for (int j = 0; j < dataset.getSeriesCount(); ++j) {
series = dataset.getSeries(j);
if (series.getDescription().equals(checkBoxNode.getText())) {
hiddenSeries.get(i).put(checkBoxNode.getText(), series);
dataset.removeSeries(j);
}
}
}
}
}
}
});
}
use of javax.swing.event.TreeSelectionEvent in project airavata by apache.
the class AmazonS3UtilsWindow method initGUI.
@SuppressWarnings("serial")
protected void initGUI() {
/* Upload Panel */
this.fileTextField = new XBayaTextField();
XBayaLabel fileLabel = new XBayaLabel("Upload File Path", this.fileTextField);
this.uploadBucketTextField = new XBayaTextField();
XBayaLabel uploadBucketLabel = new XBayaLabel("Bucket Name", this.uploadBucketTextField);
GridPanel uploadPanel = new GridPanel();
uploadPanel.getSwingComponent().setBorder(BorderFactory.createTitledBorder("Upload"));
uploadPanel.add(fileLabel);
uploadPanel.add(this.fileTextField);
uploadPanel.add(uploadBucketLabel);
uploadPanel.add(this.uploadBucketTextField);
uploadPanel.layout(2, 2, GridPanel.WEIGHT_NONE, 1);
/* Download Panel */
if (AmazonCredential.getInstance().getAwsAccessKeyId().equals("AKIAI3GNMQVYA5LSQNEQ")) {
// Avoid to use default Aws Access Key
JOptionPane.showMessageDialog(AmazonS3UtilsWindow.this.dialog.getDialog(), "Aws Access Key not set!", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
this.downloadBucketTextField = new XBayaTextField();
XBayaLabel downloadBucketLabel = new XBayaLabel("Bucket Name", this.downloadBucketTextField);
this.keyTextField = new XBayaTextField();
XBayaLabel keyLabel = new XBayaLabel("Key Name", this.keyTextField);
this.folderTextField = new XBayaTextField();
XBayaLabel folderLabel = new XBayaLabel("Download Location", this.folderTextField);
GridPanel downloadPanel = new GridPanel();
downloadPanel.getSwingComponent().setBorder(BorderFactory.createTitledBorder("Download"));
downloadPanel.add(downloadBucketLabel);
downloadPanel.add(this.downloadBucketTextField);
downloadPanel.add(keyLabel);
downloadPanel.add(this.keyTextField);
downloadPanel.add(folderLabel);
downloadPanel.add(this.folderTextField);
downloadPanel.layout(3, 2, GridPanel.WEIGHT_NONE, 1);
/* Button Panel */
JButton refreshButton = new JButton("Connect/Refresh");
refreshButton.addActionListener(new AbstractAction() {
private ChangeCredentialWindow credentialWindow;
@Override
public void actionPerformed(ActionEvent e) {
if (AmazonCredential.getInstance().getAwsAccessKeyId().isEmpty() || AmazonCredential.getInstance().getAwsSecretAccessKey().isEmpty()) {
JOptionPane.showMessageDialog(AmazonS3UtilsWindow.this.dialog.getDialog(), "Aws Access Key not set!", "Error", JOptionPane.ERROR_MESSAGE);
if (this.credentialWindow == null) {
this.credentialWindow = new ChangeCredentialWindow(AmazonS3UtilsWindow.this.dialog.getDialog());
}
try {
this.credentialWindow.show();
} catch (Exception e1) {
xBayaEngine.getGUI().getErrorWindow().error(e1);
}
return;
}
AmazonS3UtilsWindow.this.s3Tree.clean();
BucketsLoader bucketsLoader = new BucketsLoader(xBayaEngine.getGUI(), window.dialog.getDialog());
bucketsLoader.load(getS3Service(), AmazonS3UtilsWindow.this.s3Tree);
}
});
JButton uploadButton = new JButton("Upload");
uploadButton.addActionListener(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
if ((window.fileTextField.getText().length() != 0) && (window.uploadBucketTextField.getText().length() != 0)) {
S3Uploader s3Uploader = new S3Uploader(xBayaEngine, window.dialog.getDialog());
s3Uploader.upload(getS3Service(), AmazonS3UtilsWindow.this.s3Tree, window.uploadBucketTextField.getText(), window.fileTextField.getText());
window.fileTextField.setText("");
window.folderTextField.setText("");
} else {
xBayaEngine.getGUI().getErrorWindow().error(window.dialog.getDialog(), "Please give input to every upload fields");
}
}
});
JButton downloadButton = new JButton("Download");
downloadButton.addActionListener(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
if ((window.downloadBucketTextField.getText().length() != 0) && (window.keyTextField.getText().length() != 0) && (window.folderTextField.getText().length() != 0)) {
S3Downloader s3Downloader = new S3Downloader(xBayaEngine, window.dialog.getDialog());
s3Downloader.download(getS3Service(), window.downloadBucketTextField.getText(), window.keyTextField.getText(), window.folderTextField.getText());
window.downloadBucketTextField.setText("");
window.keyTextField.setText("");
window.folderTextField.setText("");
} else {
xBayaEngine.getGUI().getErrorWindow().error(window.dialog.getDialog(), "Please give input to every download fields");
}
}
});
JButton fileButton = new JButton("Choose File & Flolder");
fileButton.addActionListener(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
final JFileChooser fc = new JFileChooser();
fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
int returnVal = fc.showOpenDialog(AmazonS3UtilsWindow.this.dialog.getDialog());
if (returnVal == JFileChooser.APPROVE_OPTION) {
String filePath = fc.getSelectedFile().getAbsolutePath();
File file = fc.getSelectedFile();
if (file.isFile()) {
window.fileTextField.setText(filePath);
window.folderTextField.setText("");
} else if (file.isDirectory()) {
window.folderTextField.setText(filePath);
window.fileTextField.setText("");
}
}
}
});
JButton cancelButton = new JButton("Cancel");
cancelButton.addActionListener(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
hide();
}
});
JPanel buttonPanel = new JPanel();
buttonPanel.add(refreshButton);
buttonPanel.add(uploadButton);
buttonPanel.add(downloadButton);
buttonPanel.add(fileButton);
buttonPanel.add(cancelButton);
/* Main Panel */
GridPanel mainPanel = new GridPanel(true);
this.s3Tree = new S3Tree();
mainPanel.add(new JScrollPane(this.s3Tree));
mainPanel.add(uploadPanel);
mainPanel.add(downloadPanel);
mainPanel.layout(3, 1, 0, GridPanel.WEIGHT_EQUALLY);
this.s3Tree.addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
DefaultMutableTreeNode node = AmazonS3UtilsWindow.this.s3Tree.getSelectedNode();
if (node == null)
return;
Object nodeInfo = node.getUserObject();
String bucketName;
String downloadPanelBucketName = "";
if (node.isLeaf() && node.getParent() != null) {
// Node is probably a key
DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) node.getParent();
bucketName = (String) parentNode.getUserObject();
if (!bucketName.equals("S3 Contents")) {
// Node is indeed a key
downloadPanelBucketName = (String) parentNode.getUserObject();
String currentNodeName = (String) node.getUserObject();
int index = currentNodeName.lastIndexOf('/');
index = index >= 0 ? index : 0;
if (index > 0) {
bucketName = bucketName + "/" + currentNodeName.substring(0, index);
}
String keyName = (String) nodeInfo;
window.keyTextField.setText(keyName);
} else // Node is a bucket
{
bucketName = (String) nodeInfo;
window.keyTextField.setText("");
}
} else {
// Node is a bucket
bucketName = (String) nodeInfo;
window.keyTextField.setText("");
}
window.uploadBucketTextField.setText(bucketName);
window.downloadBucketTextField.setText(downloadPanelBucketName);
}
});
this.dialog = new XBayaDialog(xBayaEngine.getGUI(), "Amazon S3 Upload/Download Tool", mainPanel, buttonPanel);
}
use of javax.swing.event.TreeSelectionEvent in project netbeans-mmd-plugin by raydac.
the class KnowledgeViewPane method initTree.
private void initTree() {
myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
UIUtil.setLineStyleAngled(myTree);
myTree.setRootVisible(false);
myTree.setShowsRootHandles(true);
myTree.expandPath(new TreePath(myTree.getModel().getRoot()));
myTree.setSelectionPath(new TreePath(myTree.getModel().getRoot()));
EditSourceOnDoubleClickHandler.install(myTree);
ToolTipManager.sharedInstance().registerComponent(myTree);
TreeUtil.installActions(myTree);
myTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
fireTreeChangeListener();
}
});
myTree.getModel().addTreeModelListener(new TreeModelListener() {
@Override
public void treeNodesChanged(TreeModelEvent e) {
fireTreeChangeListener();
}
@Override
public void treeNodesInserted(TreeModelEvent e) {
fireTreeChangeListener();
}
@Override
public void treeNodesRemoved(TreeModelEvent e) {
fireTreeChangeListener();
}
@Override
public void treeStructureChanged(TreeModelEvent e) {
fireTreeChangeListener();
}
});
new SpeedSearch(myTree);
myTree.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (KeyEvent.VK_ENTER == e.getKeyCode()) {
final DefaultMutableTreeNode selectedNode = ((ProjectViewTree) myTree).getSelectedNode();
if (selectedNode != null && !selectedNode.isLeaf()) {
return;
}
DataContext dataContext = DataManager.getInstance().getDataContext(myTree);
OpenSourceUtil.openSourcesFrom(dataContext, false);
} else if (KeyEvent.VK_ESCAPE == e.getKeyCode()) {
if (e.isConsumed())
return;
PsiCopyPasteManager copyPasteManager = PsiCopyPasteManager.getInstance();
boolean[] isCopied = new boolean[1];
if (copyPasteManager.getElements(isCopied) != null && !isCopied[0]) {
copyPasteManager.clear();
e.consume();
}
}
}
});
CustomizationUtil.installPopupHandler(myTree, IdeActions.GROUP_PROJECT_VIEW_POPUP, ActionPlaces.PROJECT_VIEW_POPUP);
}
use of javax.swing.event.TreeSelectionEvent in project antlr4 by antlr.
the class TreeViewer method showInDialog.
protected static JFrame showInDialog(final TreeViewer viewer) {
final JFrame dialog = new JFrame();
dialog.setTitle("Parse Tree Inspector");
final Preferences prefs = Preferences.userNodeForPackage(TreeViewer.class);
// Make new content panes
final Container mainPane = new JPanel(new BorderLayout(5, 5));
final Container contentPane = new JPanel(new BorderLayout(0, 0));
contentPane.setBackground(Color.white);
// Wrap viewer in scroll pane
JScrollPane scrollPane = new JScrollPane(viewer);
// Make the scrollpane (containing the viewer) the center component
contentPane.add(scrollPane, BorderLayout.CENTER);
JPanel wrapper = new JPanel(new FlowLayout());
// Add button to bottom
JPanel bottomPanel = new JPanel(new BorderLayout(0, 0));
contentPane.add(bottomPanel, BorderLayout.SOUTH);
JButton ok = new JButton("OK");
ok.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dialog.dispatchEvent(new WindowEvent(dialog, WindowEvent.WINDOW_CLOSING));
}
});
wrapper.add(ok);
// Add an export-to-png button right of the "OK" button
JButton png = new JButton("Export as PNG");
png.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
generatePNGFile(viewer, dialog);
}
});
wrapper.add(png);
// Add an export-to-png button right of the "OK" button
JButton svg = new JButton("Export as SVG");
svg.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
generateSVGFile(viewer, dialog);
}
});
wrapper.add(svg);
bottomPanel.add(wrapper, BorderLayout.SOUTH);
// Add scale slider
double lastKnownViewerScale = prefs.getDouble(DIALOG_VIEWER_SCALE_PREFS_KEY, viewer.getScale());
viewer.setScale(lastKnownViewerScale);
int sliderValue = (int) ((lastKnownViewerScale - 1.0) * 1000);
final JSlider scaleSlider = new JSlider(JSlider.HORIZONTAL, -999, 1000, sliderValue);
scaleSlider.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
int v = scaleSlider.getValue();
viewer.setScale(v / 1000.0 + 1.0);
}
});
bottomPanel.add(scaleSlider, BorderLayout.CENTER);
// Add a JTree representing the parser tree of the input.
JPanel treePanel = new JPanel(new BorderLayout(5, 5));
// An "empty" icon that will be used for the JTree's nodes.
Icon empty = new EmptyIcon();
UIManager.put("Tree.closedIcon", empty);
UIManager.put("Tree.openIcon", empty);
UIManager.put("Tree.leafIcon", empty);
Tree parseTreeRoot = viewer.getTree().getRoot();
TreeNodeWrapper nodeRoot = new TreeNodeWrapper(parseTreeRoot, viewer);
fillTree(nodeRoot, parseTreeRoot, viewer);
final JTree tree = new JTree(nodeRoot);
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
tree.addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
JTree selectedTree = (JTree) e.getSource();
TreePath path = selectedTree.getSelectionPath();
if (path != null) {
TreeNodeWrapper treeNode = (TreeNodeWrapper) path.getLastPathComponent();
// Set the clicked AST.
viewer.setTree((Tree) treeNode.getUserObject());
}
}
});
treePanel.add(new JScrollPane(tree));
// Create the pane for both the JTree and the AST
final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, treePanel, contentPane);
mainPane.add(splitPane, BorderLayout.CENTER);
dialog.setContentPane(mainPane);
// make viz
WindowListener exitListener = new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
prefs.putInt(DIALOG_WIDTH_PREFS_KEY, (int) dialog.getSize().getWidth());
prefs.putInt(DIALOG_HEIGHT_PREFS_KEY, (int) dialog.getSize().getHeight());
prefs.putDouble(DIALOG_X_PREFS_KEY, dialog.getLocationOnScreen().getX());
prefs.putDouble(DIALOG_Y_PREFS_KEY, dialog.getLocationOnScreen().getY());
prefs.putInt(DIALOG_DIVIDER_LOC_PREFS_KEY, splitPane.getDividerLocation());
prefs.putDouble(DIALOG_VIEWER_SCALE_PREFS_KEY, viewer.getScale());
dialog.setVisible(false);
dialog.dispose();
}
};
dialog.addWindowListener(exitListener);
dialog.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
int width = prefs.getInt(DIALOG_WIDTH_PREFS_KEY, 600);
int height = prefs.getInt(DIALOG_HEIGHT_PREFS_KEY, 500);
dialog.setPreferredSize(new Dimension(width, height));
dialog.pack();
// After pack(): set the divider at 1/3 (200/600) of the frame.
int dividerLocation = prefs.getInt(DIALOG_DIVIDER_LOC_PREFS_KEY, 200);
splitPane.setDividerLocation(dividerLocation);
if (prefs.getDouble(DIALOG_X_PREFS_KEY, -1) != -1) {
dialog.setLocation((int) prefs.getDouble(DIALOG_X_PREFS_KEY, 100), (int) prefs.getDouble(DIALOG_Y_PREFS_KEY, 100));
} else {
dialog.setLocationRelativeTo(null);
}
dialog.setVisible(true);
return dialog;
}
Aggregations