use of javax.swing.event.TreeSelectionEvent in project vcell by virtualcell.
the class VCellConfigurationPanel method initialize.
private void initialize() {
generalConfigurationPanel = new GeneralConfigurationPanel();
generalConfigurationPanel.setName("generalConfigurationPanel");
pythonConfigurationPanel = new PythonConfigurationPanel3();
pythonConfigurationPanel.setName("pythonConfigurationPanel");
comsolConfigurationPanel = new ComsolConfigurationPanel();
comsolConfigurationPanel.setName("comsolConfigurationPanel");
bioNetGenConfigurationPanel = new BioNetGenConfigurationPanel();
bioNetGenConfigurationPanel.setName("bioNetGenConfigurationPanel");
configurationOptionsTree = new javax.swing.JTree();
configurationOptionsTreeModel = new ConfigurationOptionsTreeModel(configurationOptionsTree);
configurationOptionsTree.setModel(configurationOptionsTreeModel);
configurationOptionsTree.setEditable(false);
configurationOptionsTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
configurationOptionsTree.setRootVisible(false);
configurationOptionsTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
ConfigurationModelNode cmn = (ConfigurationModelNode) e.getNewLeadSelectionPath().getLastPathComponent();
ConfigurationOptionsTreeFolderNode cotfn = (ConfigurationOptionsTreeFolderNode) cmn.getUserObject();
switch(cotfn.getFolderClass()) {
case GENERAL_NODE:
splitPane.setRightComponent(generalConfigurationPanel);
break;
case PYTHON_NODE:
splitPane.setRightComponent(pythonConfigurationPanel);
break;
case COMSOL_NODE:
splitPane.setRightComponent(comsolConfigurationPanel);
break;
case BIONETGEN_NODE:
splitPane.setRightComponent(bioNetGenConfigurationPanel);
break;
}
}
});
JScrollPane treePanel = new javax.swing.JScrollPane(configurationOptionsTree);
// Border margin = new EmptyBorder(5,3,1,1);
// treePanel.setBorder(margin);
Dimension dim = new Dimension(150, 300);
// code that contributes to prevent resizing horizontally
treePanel.setPreferredSize(dim);
treePanel.setMinimumSize(dim);
treePanel.setMaximumSize(dim);
splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT) {
// all code below to make it impossible to move the divider
private final int location = 150;
{
// so that the left component cannot be resized
setDividerLocation(location);
// left component is fixed width
setResizeWeight(0);
// this also makes resizing impossible
setDividerSize(0);
// no UI widget on the divider to quickly expand / collapse
setOneTouchExpandable(false);
}
@Override
public int getDividerLocation() {
return location;
}
@Override
public int getLastDividerLocation() {
return location;
}
};
splitPane.setLeftComponent(treePanel);
splitPane.setRightComponent(generalConfigurationPanel);
// ---------------------------------------------------------------------------
JPanel okCancelPanel = new JPanel();
okCancelPanel.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.weightx = 1;
// fake cell used for filling all the vertical empty space
gbc.weighty = 1;
gbc.fill = GridBagConstraints.BOTH;
gbc.anchor = GridBagConstraints.WEST;
okCancelPanel.add(new JLabel(""), gbc);
// gbc = new GridBagConstraints();
// gbc.gridx = 1;
// gbc.gridy = 0;
// gbc.insets = new Insets(0, 0, 4, 2); // top, left, bottom, right
// okCancelPanel.add(getOkButton(), gbc);
gbc = new GridBagConstraints();
gbc.gridx = 2;
gbc.gridy = 0;
gbc.insets = new Insets(0, 2, 4, 4);
okCancelPanel.add(getCloseButton(), gbc);
// --------------------------------------------------------------------------------
setLayout(new GridBagLayout());
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.weightx = 1.0;
gbc.weighty = 1.0;
gbc.fill = GridBagConstraints.BOTH;
gbc.insets = new Insets(1, 1, 1, 1);
add(splitPane, gbc);
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 1;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(1, 1, 1, 1);
add(okCancelPanel, gbc);
// configurationOptionsTree.addTreeSelectionListener(eventHandler);
// configurationOptionsTree.addMouseListener(eventHandler);
configurationOptionsTreeModel.populateTree();
}
use of javax.swing.event.TreeSelectionEvent in project binnavi by google.
the class TypeSubstitutionDialog method createControls.
private void createControls(final BaseType stackFrame) {
setBounds(100, 100, 691, 470);
final JPanel panel = new JPanel();
getContentPane().add(panel, BorderLayout.SOUTH);
panel.setLayout(new FlowLayout(FlowLayout.RIGHT));
final JButton buttonOk = new JButton("OK");
buttonOk.addActionListener(new OkActionListener());
panel.add(buttonOk);
final JButton buttonCancel = new JButton("Cancel");
buttonCancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
dispose();
}
});
buttonCancel.setActionCommand("Cancel");
panel.add(buttonCancel);
final JPanel panel1 = new JPanel();
getContentPane().add(panel1, BorderLayout.NORTH);
final GridBagLayout gblPanel1 = new GridBagLayout();
gblPanel1.columnWidths = new int[] { 0, 143, 114, 0 };
gblPanel1.rowHeights = new int[] { 23, 0 };
gblPanel1.columnWeights = new double[] { 0.0, 0.0, 1.0, Double.MIN_VALUE };
gblPanel1.rowWeights = new double[] { 0.0, Double.MIN_VALUE };
panel1.setLayout(gblPanel1);
JCheckBox onlyFitting = new JCheckBox("Only show structs that fit immediate offset");
onlyFitting.setEnabled(false);
GridBagConstraints gbcOnlyFitting = new GridBagConstraints();
gbcOnlyFitting.anchor = GridBagConstraints.WEST;
gbcOnlyFitting.insets = new Insets(0, 0, 0, 5);
gbcOnlyFitting.gridx = 0;
gbcOnlyFitting.gridy = 0;
panel1.add(onlyFitting, gbcOnlyFitting);
types = new TypesTree();
types.setModel(new TypesTreeModel(typeManager, new LocalTypesFilter(stackFrame)));
types.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
types.addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent event) {
final TypeSelectionPath path = types.determineTypePath();
if (validateUserInput(path)) {
updatePreview(path);
}
}
});
final JPanel centerPanel = new JPanel();
centerPanel.setLayout(new BoxLayout(centerPanel, BoxLayout.PAGE_AXIS));
centerPanel.add(new JScrollPane(types));
centerPanel.add(preview);
getContentPane().add(centerPanel, BorderLayout.CENTER);
}
use of javax.swing.event.TreeSelectionEvent in project airavata by apache.
the class ComponentSelector method initGUI.
private void initGUI() {
this.treeModel = new ComponentTreeModel(new ComponentTreeNode("Components"));
this.tree = new JTree(this.treeModel);
// Add a tool tip.
ToolTipManager.sharedInstance().registerComponent(this.tree);
DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer() {
@Override
public java.awt.Component getTreeCellRendererComponent(JTree t, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean focus) {
super.getTreeCellRendererComponent(t, value, sel, expanded, leaf, row, focus);
ComponentTreeNode node = (ComponentTreeNode) value;
if (node.getComponentReference() == null) {
setToolTipText(null);
} else {
setToolTipText("Drag a component to the composer to add");
}
return this;
}
};
// Change icons
try {
renderer.setOpenIcon(SwingUtil.createImageIcon("opened.gif"));
renderer.setClosedIcon(SwingUtil.createImageIcon("closed.gif"));
renderer.setLeafIcon(SwingUtil.createImageIcon("leaf.gif"));
} catch (RuntimeException e) {
logger.warn("Failed to load image icons. " + "It will use the default icons instead.", e);
}
this.tree.setCellRenderer(renderer);
this.tree.setShowsRootHandles(true);
this.tree.setEditable(false);
this.tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
this.tree.addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent event) {
// update.
if (event.isAddedPath()) {
TreePath path = event.getPath();
select(path);
}
}
});
// Drag and dtop
DragGestureListener dragGestureListener = new DragGestureListener() {
public void dragGestureRecognized(DragGestureEvent event) {
ComponentSelector.this.dragGestureRecognized(event);
}
};
DragSource dragSource = DragSource.getDefaultDragSource();
dragSource.createDefaultDragGestureRecognizer(this.tree, DnDConstants.ACTION_COPY_OR_MOVE, dragGestureListener);
this.dragSourceListener = new DragSourceAdapter() {
};
// Popup
this.tree.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent event) {
if (event.isPopupTrigger()) {
showPopupIfNecessary(event);
}
}
});
createNodePopupMenu();
}
use of javax.swing.event.TreeSelectionEvent in project tetrad by cmu-phil.
the class CategorizingModelChooser method setModelConfigs.
public void setModelConfigs(List<SessionNodeModelConfig> configs) {
ChooserTreeModel model = new ChooserTreeModel(configs);
this.tree = new JTree(model);
this.tree.setCellRenderer(new ChooserRenderer());
this.tree.setRootVisible(false);
this.tree.setEditable(false);
this.tree.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
for (int i = 0; i < this.tree.getRowCount(); i++) {
this.tree.expandRow(i);
}
this.tree.addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent e) {
TreePath path = e.getPath();
Object selected = path.getLastPathComponent();
if (selected instanceof ModelWrapper) {
String name = ((ModelWrapper) selected).name;
Preferences.userRoot().put(nodeId, name);
}
}
});
// select a default value, if one exists
String storedModelType = getModelTypeFromSessionNode(sessionNode, model);
if (storedModelType == null) {
storedModelType = Preferences.userRoot().get(this.nodeId, "");
}
System.out.println("Stored model type = " + storedModelType);
if (storedModelType.length() != 0) {
for (Map.Entry<String, List<ModelWrapper>> entry : model.map.entrySet()) {
for (ModelWrapper wrapper : entry.getValue()) {
if (storedModelType.equals(wrapper.name)) {
Object[] path = new Object[] { ChooserTreeModel.ROOT, entry.getKey(), wrapper };
this.tree.setSelectionPath(new TreePath(path));
break;
}
}
}
}
}
use of javax.swing.event.TreeSelectionEvent in project antlr4 by tunnelvisionlabs.
the class TreeViewer method showInDialog.
@NotNull
protected static JDialog showInDialog(final TreeViewer viewer) {
final JDialog dialog = new JDialog();
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