use of java.awt.event.MouseListener in project vcell by virtualcell.
the class DialogUtils method getDBTreePanelSelection.
/**
* Return VersionInfo from JPanels implementing SelectableTreeVersionJPanel
* including MathModelDbTreePanel, BioModelDbTreePanel, GeometryTreePanel and ImageDbTreePanel
*
* @param requester parent component for dialog
* @param selectableTreeVersionJPanel component having a JTree user can select to define a VersionInfo
* @param okString label for button user presses when selection complete
* @param dialogTitle string displayed at top of dialog
* @return VersionInfo identifies a particular VCell document
* @throws UserCancelException
* @throws IllegalArgumentException
*/
public static VersionInfo getDBTreePanelSelection(Component requester, SelectableTreeVersionJPanel selectableTreeVersionJPanel, String okString, String dialogTitle) throws UserCancelException, IllegalArgumentException {
if (!(selectableTreeVersionJPanel instanceof JPanel)) {
throw new IllegalArgumentException("selectableTreeVersionJPanel must be of type JPanel");
}
final MouseListener[] mouseListener = new MouseListener[] { null };
// final JTree[] listenToJTree = new JTree[] {null};
try {
JPanel defaultSizedJPanel = new JPanel();
defaultSizedJPanel.setLayout(new BorderLayout());
defaultSizedJPanel.add((JPanel) selectableTreeVersionJPanel, BorderLayout.CENTER);
Dimension dim = new Dimension(300, 400);
defaultSizedJPanel.setPreferredSize(dim);
defaultSizedJPanel.setMinimumSize(dim);
defaultSizedJPanel.setMaximumSize(dim);
String result = DialogUtils.showOptionsDialog(requester, defaultSizedJPanel, JOptionPane.PLAIN_MESSAGE, new String[] { okString, getCancelText() }, okString, new DialogUtils.OKEnabler() {
@Override
public void setJOptionPane(JOptionPane joptionPane) {
DialogUtils.setInternalNotCancelEnabled(joptionPane, selectableTreeVersionJPanel.getSelectedVersionInfo() != null, false);
mouseListener[0] = new MouseAdapter() {
public void mousePressed(MouseEvent e) {
Component parentComponent = (Component) e.getSource();
while (parentComponent != selectableTreeVersionJPanel && parentComponent.getParent() != null) {
parentComponent = parentComponent.getParent();
}
if (parentComponent == selectableTreeVersionJPanel) {
if (selectableTreeVersionJPanel.getSelectedVersionInfo() != null) {
if (e.getClickCount() == 2) {
// enable OK and click OK button
DialogUtils.setInternalNotCancelEnabled(joptionPane, true, true);
} else {
// enable OK button
DialogUtils.setInternalNotCancelEnabled(joptionPane, true, false);
}
} else {
// disable OK button
DialogUtils.setInternalNotCancelEnabled(joptionPane, false, false);
}
}
}
};
selectableTreeVersionJPanel.addJTreeSelectionMouseListener(mouseListener[0]);
}
}, dialogTitle);
if (result == null || !result.equals(okString)) {
throw UserCancelException.CANCEL_GENERIC;
}
return selectableTreeVersionJPanel.getSelectedVersionInfo();
} finally {
selectableTreeVersionJPanel.removeJTreeSelectionMouseListener(mouseListener[0]);
}
}
use of java.awt.event.MouseListener in project vcell by virtualcell.
the class AnnotationsPanel method getJTreeMIRIAM.
private JTree getJTreeMIRIAM() {
if (jTreeMIRIAM == null) {
try {
DefaultTreeSelectionModel ivjLocalSelectionModel;
ivjLocalSelectionModel = new DefaultTreeSelectionModel();
ivjLocalSelectionModel.setSelectionMode(1);
jTreeMIRIAM = new JTree();
jTreeMIRIAM.setName("JTree1");
jTreeMIRIAM.setToolTipText("");
jTreeMIRIAM.setBounds(0, 0, 357, 405);
jTreeMIRIAM.setMinimumSize(new java.awt.Dimension(100, 72));
jTreeMIRIAM.setSelectionModel(ivjLocalSelectionModel);
jTreeMIRIAM.setRowHeight(0);
jTreeMIRIAM.setRootVisible(false);
// Add cellRenderer
DefaultTreeCellRenderer dtcr = new BioModelCellRenderer(null) {
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
// default for LinkNode is in BioModelCellRenderer.java
JLabel component = (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
// TODO: here
component.setIcon(null);
return component;
}
};
jTreeMIRIAM.setCellRenderer(dtcr);
MouseListener mouseListener = new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
super.mouseClicked(e);
// TreePath closestMousePath =jTreeMIRIAM.getClosestPathForLocation(e.getPoint().x, e.getPoint().y);
// showPopup(e, closestMousePath);
}
@Override
public void mouseReleased(MouseEvent e) {
super.mouseReleased(e);
// TreePath closestMousePath =jTreeMIRIAM.getClosestPathForLocation(e.getPoint().x, e.getPoint().y);
// showPopup(e,closestMousePath);
}
public void mousePressed(MouseEvent e) {
TreePath closestMousePath = jTreeMIRIAM.getClosestPathForLocation(e.getPoint().x, e.getPoint().y);
jTreeMIRIAM.setSelectionPath(closestMousePath);
// showPopup(e,closestMousePath);
if (e.getClickCount() == 2) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) jTreeMIRIAM.getLastSelectedPathComponent();
if (node instanceof LinkNode) {
showBrowseToLink((LinkNode) node);
}
}
}
};
jTreeMIRIAM.addMouseListener(mouseListener);
} catch (java.lang.Throwable ivjExc) {
ivjExc.printStackTrace(System.out);
}
}
return jTreeMIRIAM;
}
use of java.awt.event.MouseListener in project vcell by virtualcell.
the class MIRIAMAnnotationEditor method getJTreeMIRIAM.
private JTree getJTreeMIRIAM() {
if (jTreeMIRIAM == null) {
try {
DefaultTreeSelectionModel ivjLocalSelectionModel;
ivjLocalSelectionModel = new DefaultTreeSelectionModel();
ivjLocalSelectionModel.setSelectionMode(1);
jTreeMIRIAM = new JTree();
jTreeMIRIAM.setName("JTree1");
jTreeMIRIAM.setToolTipText("");
jTreeMIRIAM.setBounds(0, 0, 357, 405);
jTreeMIRIAM.setMinimumSize(new java.awt.Dimension(100, 72));
jTreeMIRIAM.setSelectionModel(ivjLocalSelectionModel);
jTreeMIRIAM.setRowHeight(0);
// Add cellRenderer
DefaultTreeCellRenderer dtcr = new BioModelCellRenderer(null) {
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
// System.out.println(MIRIAMAnnotationEditor.this.getClass().getName()+".getJTreeMiriam():BioModelCellRenderer "+value.getClass()+" "+
// (value instanceof cbit.vcell.desktop.BioModelNode?
// ((cbit.vcell.desktop.BioModelNode)value).getUserObject().getClass():""));
JLabel component = (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
if (value instanceof BioModelNode && ((BioModelNode) value).getUserObject() instanceof Annotation) {
component.setToolTipText("(Double-click to edit notes)");
Annotation annotation = (Annotation) ((BioModelNode) value).getUserObject();
if (annotation.toString() == null || annotation.toString().length() == 0) {
component.setText("(Double-click to edit notes)");
}
}
return component;
}
};
jTreeMIRIAM.setCellRenderer(dtcr);
MouseListener mouseListener = new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
super.mouseClicked(e);
TreePath closestMousePath = jTreeMIRIAM.getClosestPathForLocation(e.getPoint().x, e.getPoint().y);
showPopup(e, closestMousePath);
}
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
super.mouseReleased(e);
TreePath closestMousePath = jTreeMIRIAM.getClosestPathForLocation(e.getPoint().x, e.getPoint().y);
showPopup(e, closestMousePath);
}
public void mousePressed(MouseEvent e) {
TreePath closestMousePath = jTreeMIRIAM.getClosestPathForLocation(e.getPoint().x, e.getPoint().y);
jTreeMIRIAM.setSelectionPath(closestMousePath);
showPopup(e, closestMousePath);
if (e.getClickCount() == 2) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) jTreeMIRIAM.getLastSelectedPathComponent();
if (node instanceof LinkNode) {
showBrowseToLink((LinkNode) node);
} else if (isNodeFreeHandTextEditable(node)) {
showEditFreehandText(node);
}
}
}
};
jTreeMIRIAM.addMouseListener(mouseListener);
} catch (java.lang.Throwable ivjExc) {
ivjExc.printStackTrace(System.out);
}
}
return jTreeMIRIAM;
}
use of java.awt.event.MouseListener in project vcell by virtualcell.
the class BioModelParametersPanel method initialize.
private void initialize() {
addNewButton = new JButton("New Global Parameter");
addNewButton.addActionListener(eventHandler);
addNewButton2 = new JButton("New Application Parameter");
// addNewButton2.setIcon(downArrow);
addNewButton2.setHorizontalTextPosition(SwingConstants.LEFT);
addNewButton2.addActionListener(eventHandler);
deleteButton = new JButton("Delete");
deleteButton.setEnabled(false);
deleteButton.addActionListener(eventHandler);
changeUnitsButton = new JButton("Change Unit System");
changeUnitsButton.addActionListener(eventHandler);
textFieldSearch = new JTextField(10);
textFieldSearch.getDocument().addDocumentListener(eventHandler);
textFieldSearch.putClientProperty("JTextField.variant", "search");
parametersFunctionsTable = new EditorScrollTable();
parametersFunctionsTableModel = new BioModelParametersTableModel(parametersFunctionsTable);
parametersFunctionsTable.setModel(parametersFunctionsTableModel);
globalParametersCheckBox = new JCheckBox("Global");
globalParametersCheckBox.setSelected(true);
globalParametersCheckBox.addActionListener(eventHandler);
reactionsCheckBox = new JCheckBox("Reactions and Rules");
reactionsCheckBox.setSelected(true);
reactionsCheckBox.addActionListener(eventHandler);
applicationsCheckBox = new JCheckBox("Applications");
applicationsCheckBox.setSelected(true);
applicationsCheckBox.addActionListener(eventHandler);
applicationComboBox = new JComboBox<ApplicationSelection>();
applicationComboBox.setSelectedItem("All");
applicationComboBox.addActionListener(eventHandler);
applicationComboBox.setModel(applicationComboBoxModel);
applicationComboBox.setRenderer(new ApplicationComboBoxRenderer());
constantsCheckBox = new JCheckBox("Parameters");
constantsCheckBox.setSelected(true);
constantsCheckBox.addActionListener(eventHandler);
functionsCheckBox = new JCheckBox("Functions");
functionsCheckBox.setSelected(true);
functionsCheckBox.addActionListener(eventHandler);
predefinedSymbolsTable = new EditorScrollTable();
predefinedSymbolsTableModel = new PredefinedSymbolsTableModel(predefinedSymbolsTable);
predefinedSymbolsTable.setModel(predefinedSymbolsTableModel);
GuiUtils.flexResizeTableColumns(predefinedSymbolsTable);
modelUnitSystemTable = new EditorScrollTable();
modelUnitSystemTableModel = new ModelUnitSystemTableModel(modelUnitSystemTable);
modelUnitSystemTable.setModel(modelUnitSystemTableModel);
GuiUtils.flexResizeTableColumns(modelUnitSystemTable);
tabbedPane = new JTabbedPaneEnhanced();
tabbedPane.addChangeListener(eventHandler);
ParametersPanelTab[] parametersPanelTabs = new ParametersPanelTab[ParametersPanelTabID.values().length];
parametersPanelTabs[ParametersPanelTabID.parameters_functions.ordinal()] = new ParametersPanelTab(ParametersPanelTabID.parameters_functions, getParametersFunctionsPanel(), null);
parametersPanelTabs[ParametersPanelTabID.predefined.ordinal()] = new ParametersPanelTab(ParametersPanelTabID.predefined, getPredefinedSymbolsPanel(), null);
parametersPanelTabs[ParametersPanelTabID.modelUnitSystem.ordinal()] = new ParametersPanelTab(ParametersPanelTabID.modelUnitSystem, getModelUnitSystemPanel(), null);
for (ParametersPanelTab tab : parametersPanelTabs) {
tab.component.setBorder(GuiConstants.TAB_PANEL_BORDER);
tabbedPane.addTab(tab.id.title, tab.icon, tab.component);
}
JPanel buttonPanel = new JPanel(new GridBagLayout());
int gridy = 0;
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = gridy;
gbc.insets = new Insets(4, 4, 4, 4);
gbc.anchor = GridBagConstraints.LINE_END;
buttonPanel.add(addNewButton, gbc);
gbc = new GridBagConstraints();
gbc.gridx = GridBagConstraints.RELATIVE;
gbc.insets = new Insets(4, 4, 4, 4);
gbc.gridy = gridy;
gbc.anchor = GridBagConstraints.LINE_END;
buttonPanel.add(addNewButton2, gbc);
gbc = new GridBagConstraints();
gbc.gridx = GridBagConstraints.RELATIVE;
gbc.insets = new Insets(4, 4, 4, 4);
gbc.gridy = gridy;
gbc.anchor = GridBagConstraints.LINE_END;
buttonPanel.add(deleteButton, gbc);
gbc = new GridBagConstraints();
gbc.gridx = GridBagConstraints.RELATIVE;
gbc.insets = new Insets(4, 4, 4, 4);
gbc.gridy = gridy;
gbc.anchor = GridBagConstraints.LINE_END;
buttonPanel.add(changeUnitsButton, gbc);
gbc = new GridBagConstraints();
gbc.gridx = GridBagConstraints.RELATIVE;
gbc.gridy = gridy;
gbc.anchor = GridBagConstraints.LINE_END;
gbc.insets = new Insets(4, 50, 4, 4);
buttonPanel.add(new JLabel("Search"), gbc);
gbc = new GridBagConstraints();
gbc.gridx = GridBagConstraints.RELATIVE;
gbc.gridy = gridy;
gbc.weightx = 1.0;
gbc.gridwidth = 2;
gbc.anchor = GridBagConstraints.LINE_START;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(4, 4, 4, 4);
buttonPanel.add(textFieldSearch, gbc);
setLayout(new BorderLayout());
add(tabbedPane, BorderLayout.CENTER);
add(buttonPanel, BorderLayout.SOUTH);
parametersFunctionsTable.getSelectionModel().addListSelectionListener(eventHandler);
parametersFunctionsTable.setDefaultRenderer(NameScope.class, new DefaultScrollTableCellRenderer() {
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (value instanceof NameScope) {
NameScope nameScope = (NameScope) value;
String text = nameScope.getPathDescription();
setText(text);
}
return this;
}
});
DefaultScrollTableCellRenderer nameTableCellRenderer = new DefaultScrollTableCellRenderer() {
final Color lightBlueBackground = new Color(214, 234, 248);
int PADDING = 3;
@Override
public void setBounds(int x, int y, int width, int height) {
super.setBounds(x, y, width, height);
if (getIcon() != null) {
int textWidth = getFontMetrics(getFont()).stringWidth(getText());
Insets insets = getInsets();
// TODO: check that the text width is not bigger than the cell width and truncate the name
int iconTextGap = width - textWidth - getIcon().getIconWidth() - insets.left - insets.right - PADDING;
setIconTextGap(iconTextGap);
} else {
setIconTextGap(0);
}
}
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (table.getModel() instanceof BioModelParametersTableModel) {
BioModelParametersTableModel tableModel = (BioModelParametersTableModel) table.getModel();
Object selectedObject = tableModel.getValueAt(row);
setToolTipText(null);
if (selectedObject instanceof ModelParameter || selectedObject instanceof SpeciesContext) {
SymbolTableEntry ste = (SymbolTableEntry) selectedObject;
RateRule rr = null;
AssignmentRule ar = null;
for (SimulationContext simContext : bioModel.getSimulationContexts()) {
rr = simContext.getRateRule(ste);
ar = simContext.getAssignmentRule(ste);
if (rr != null || ar != null) {
break;
}
}
Icon icon = null;
if (rr != null) {
String text = "<html>The default value of this entity is being overriden by a Rate Rule in one or more applications</html>";
icon = VCellIcons.ruleRateIcon;
setToolTipText(text);
} else if (ar != null) {
String text = "<html>The default value of this entity is being overriden by an Assignment Rule in one or more applications</html>";
icon = VCellIcons.ruleAssignIcon;
setToolTipText(text);
}
setIcon(icon);
this.setHorizontalTextPosition(SwingConstants.LEFT);
if (isSelected) {
setBackground(lightBlueBackground);
setForeground(Color.BLACK);
}
}
}
return this;
}
};
parametersFunctionsTable.getColumnModel().getColumn(BioModelParametersTableModel.COLUMN_NAME).setCellRenderer(nameTableCellRenderer);
{
// make double click on units panel bring up editing box
JPanel p = getModelUnitSystemPanel();
VCAssert.assertValid(p);
EditorScrollTable est = GuiUtils.findFirstChild(p, EditorScrollTable.class);
VCAssert.assertValid(est);
MouseListener ml = new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
changeUnitsButtonPressed();
}
}
};
est.addMouseListener(ml);
}
}
use of java.awt.event.MouseListener in project vcell by virtualcell.
the class EditorPalette method addTemplate.
/**
* @param name
* @param icon
* @param cell
*/
public void addTemplate(final String name, ImageIcon icon, mxCell cell) {
mxRectangle bounds = (mxGeometry) cell.getGeometry().clone();
final mxGraphTransferable t = new mxGraphTransferable(new Object[] { cell }, bounds);
// Scales the image if it's too large for the library
if (icon != null) {
if (icon.getIconWidth() > 32 || icon.getIconHeight() > 32) {
icon = new ImageIcon(icon.getImage().getScaledInstance(32, 32, 0));
}
}
final JLabel entry = new JLabel(icon);
entry.setPreferredSize(new Dimension(50, 50));
entry.setBackground(EditorPalette.this.getBackground().brighter());
entry.setFont(new Font(entry.getFont().getFamily(), 0, 10));
entry.setVerticalTextPosition(JLabel.BOTTOM);
entry.setHorizontalTextPosition(JLabel.CENTER);
entry.setIconTextGap(0);
entry.setToolTipText(name);
entry.setText(name);
entry.addMouseListener(new MouseListener() {
/*
* (non-Javadoc)
* @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
*/
public void mousePressed(MouseEvent e) {
setSelectionEntry(entry, t);
}
/*
* (non-Javadoc)
* @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
*/
public void mouseClicked(MouseEvent e) {
}
/*
* (non-Javadoc)
* @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
*/
public void mouseEntered(MouseEvent e) {
}
/*
* (non-Javadoc)
* @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
*/
public void mouseExited(MouseEvent e) {
}
/*
* (non-Javadoc)
* @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
*/
public void mouseReleased(MouseEvent e) {
}
});
// Install the handler for dragging nodes into a graph
DragGestureListener dragGestureListener = new DragGestureListener() {
/**
*/
public void dragGestureRecognized(DragGestureEvent e) {
e.startDrag(null, mxSwingConstants.EMPTY_IMAGE, new Point(), t, null);
}
};
DragSource dragSource = new DragSource();
dragSource.createDefaultDragGestureRecognizer(entry, DnDConstants.ACTION_COPY, dragGestureListener);
add(entry);
}
Aggregations