Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix long frame names path editor #1532

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ v4.6
- Fix issue [#1493](https://github.com/opensim-org/opensim-gui/issues/1493): Rotating experimental data fails or results an unusable file.
- Fix issue [#1516](https://github.com/opensim-org/opensim-gui/issues/1516): Chains of Physical offset frames ignored when displaying GeometryPath
- Fix issue [#1519](https://github.com/opensim-org/opensim-gui/issues/1519): Exception thrown when browsing for output folder in Inverse Dynamics Tool dialog
- Fix issue [#1526](https://github.com/opensim-org/opensim-gui/issues/1526): Handle very long frame names by showing as tooltips in path editor.

v4.5
======
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.opensim.view.nodes;

import java.awt.Component;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.plaf.basic.BasicComboBoxRenderer;

/**
*
* @author ayman
*/
public class ListCellRendererWithTooltip extends BasicComboBoxRenderer {
JComboBox combox;
public ListCellRendererWithTooltip(JComboBox comboBox){
this.combox = comboBox;
}

@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
Component comp = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); //To change body of generated methods, choose Tools | Template
((JLabel) comp).setToolTipText(value.toString());
return comp;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,16 @@
import java.util.HashMap;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.ListCellRenderer;
import javax.swing.SwingConstants;
import javax.swing.event.PopupMenuEvent;
import javax.swing.event.PopupMenuListener;
import javax.swing.plaf.basic.BasicComboBoxRenderer;
import org.opensim.modeling.AbstractPathPoint;
import org.opensim.modeling.ArrayPathPoint;
import org.opensim.modeling.Component;
Expand Down Expand Up @@ -406,13 +413,13 @@ private void updateAttachmentPanel() {
attachmentFrameLabel.setBounds(X + 300, Y - 30, 30, 16);
javax.swing.JLabel coordLabel = new javax.swing.JLabel();
coordLabel.setText("Coordinate");
coordLabel.setBounds(X + 400, Y - 30, 90, 16);
coordLabel.setBounds(X + 450, Y - 30, 90, 16);
javax.swing.JLabel rangeMinLabel = new javax.swing.JLabel();
rangeMinLabel.setText("Min");
rangeMinLabel.setBounds(X + 530, Y - 30, 60, 16);
rangeMinLabel.setBounds(X + 580, Y - 30, 60, 16);
javax.swing.JLabel rangeMaxLabel = new javax.swing.JLabel();
rangeMaxLabel.setText("Max");
rangeMaxLabel.setBounds(X + 590, Y - 30, 60, 16);
rangeMaxLabel.setBounds(X + 640, Y - 30, 60, 16);
AttachmentsPanel.add(attachmentSelLabel);
AttachmentsPanel.add(attachmentTypeLabel);
AttachmentsPanel.add(attachmentXLabel);
Expand Down Expand Up @@ -639,15 +646,17 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
javax.swing.JComboBox comboBox = new javax.swing.JComboBox();
comboBox.setModel(new javax.swing.DefaultComboBoxModel(physicalFrameNames));
comboBox.setSelectedIndex(findElement(physicalFrameNames, pathPoints.get(i).getParentFrame().getAbsolutePathString()));
comboBox.setBounds(x, height, 90, 21);
comboBox.setBounds(x, height, 140, 21);
comboBox.setToolTipText("Frame the attachment point is fixed to");
comboBox.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
AttachmentFrameChosen(((javax.swing.JComboBox)evt.getSource()), num);
}
});
comboBox.setRenderer(new ListCellRendererWithTooltip(comboBox));

AttachmentsPanel.add(comboBox);
x += 100;
x += 150;

// GUI items for via points (coord combo box, min range field, max range field)
if (via != null) {
Expand Down Expand Up @@ -825,7 +834,7 @@ private void maybeShowPopup(MouseEvent e) {
MouseListener popupListenerDelete = new PopupListenerDelete();
deleteButton.addMouseListener(popupListenerDelete);

Dimension d = new Dimension(640, Y + 45 + numGuiLines * 22);
Dimension d = new Dimension(690, Y + 45 + numGuiLines * 22);
if (anyViaPoints) {
d.width = 920;
AttachmentsPanel.add(coordLabel);
Expand All @@ -839,7 +848,17 @@ private void maybeShowPopup(MouseEvent e) {
for (int i = 0; i < selectedObjects.size(); i++)
updateAttachmentSelections(selectedObjects.get(i), true);
}


public void adjustDropdownWidth(PopupMenuEvent e) {
JComboBox comboBox = (JComboBox) e.getSource();
Object accessibleChild = comboBox.getUI().getAccessibleChild(comboBox, 0);
if (!(accessibleChild instanceof JPopupMenu)) return;
JComponent scrollPane = (JComponent) ((JPopupMenu) accessibleChild).getComponent(0);
Dimension dimension = new Dimension();
dimension.width = comboBox.getPreferredSize().width+100;
dimension.height = scrollPane.getPreferredSize().height;
scrollPane.setPreferredSize(dimension);
}
private void updateAttachmentSelections(SelectedObject selectedObject, boolean state) {
if (objectWithPath != null) {
OpenSimObject obj = selectedObject.getOpenSimObject();
Expand Down Expand Up @@ -1629,4 +1648,5 @@ void RestoreButtonActionPerformed(ActionEvent evt)
ModelVisualizationJson modelViz = ViewDB.getInstance().getModelVisualizationJson(currentModel);
ViewDB.getInstance().updatePathDisplay(currentModel, gp, EditOperation.Recreate.ordinal(), -1);
}

}
Loading