Show mouse position in the status bar

This commit is contained in:
Branislav Stojkovic
2019-02-08 09:56:48 +01:00
parent fbf2569a7e
commit 0cb4377830
6 changed files with 69 additions and 12 deletions
Binary file not shown.
Binary file not shown.
@@ -55,6 +55,8 @@ import net.java.balloontip.styles.EdgedBalloonStyle;
import org.apache.log4j.Logger;
import org.diylc.announcements.AnnouncementProvider;
import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.appframework.miscutils.IConfigListener;
import org.diylc.appframework.miscutils.Utils;
import org.diylc.appframework.update.UpdateChecker;
import org.diylc.appframework.update.Version;
@@ -67,6 +69,7 @@ import org.diylc.common.ITask;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IView;
import org.diylc.images.IconLoader;
import org.diylc.presenter.Presenter;
import org.diylc.swing.ISwingUI;
import org.diylc.swingframework.MemoryBar;
import org.diylc.swingframework.miscutils.PercentageListCellRenderer;
@@ -87,7 +90,8 @@ public class StatusBar extends JPanel implements IPlugIn {
private JLabel announcementLabel;
private JLabel recentChangesLabel;
private MemoryBar memoryPanel;
private JLabel statusLabel;
private JLabel statusLabel;
private JLabel positionLabel;
private JLabel sizeLabel;
private IPlugInPort plugInPort;
@@ -100,9 +104,14 @@ public class StatusBar extends JPanel implements IPlugIn {
private List<String> componentNamesUnderCursor;
private List<String> selectedComponentNames;
private List<String> stuckComponentNames;
private String statusMessage;
private String statusMessage;
private Point mousePosition;
private AnnouncementProvider announcementProvider;
private AnnouncementProvider announcementProvider;
private Point2D mousePositionIn;
private Point2D mousePositionMm;
public StatusBar(ISwingUI swingUI) {
super();
@@ -153,7 +162,15 @@ public class StatusBar extends JPanel implements IPlugIn {
}
}
}, false);
}, false);
ConfigurationManager.getInstance().addConfigListener(IPlugInPort.METRIC_KEY, new IConfigListener() {
@Override
public void valueChanged(String key, Object value) {
refreshPosition((Boolean)value);
}
});
}
private JComboBox getZoomBox() {
@@ -289,6 +306,14 @@ public class StatusBar extends JPanel implements IPlugIn {
statusLabel.setBorder(BorderFactory.createEmptyBorder(0, 4, 0, 0));
}
return statusLabel;
}
private JLabel getPositionLabel() {
if (positionLabel == null) {
positionLabel = new JLabel();
positionLabel.setBorder(BorderFactory.createEmptyBorder(0, 4, 0, 0));
}
return positionLabel;
}
public JLabel getSizeLabel() {
@@ -331,7 +356,12 @@ public class StatusBar extends JPanel implements IPlugIn {
gbc.gridy = 0;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.weightx = 1;
add(getStatusLabel(), gbc);
add(getStatusLabel(), gbc);
gbc.gridx++;
gbc.fill = GridBagConstraints.BOTH;
gbc.weightx = 0;
add(getPositionLabel(), gbc);
JPanel zoomPanel = new JPanel(new BorderLayout());
zoomPanel.add(new JLabel("Zoom: "), BorderLayout.WEST);
@@ -382,7 +412,7 @@ public class StatusBar extends JPanel implements IPlugIn {
@Override
public EnumSet<EventType> getSubscribedEventTypes() {
return EnumSet.of(EventType.ZOOM_CHANGED, EventType.SLOT_CHANGED, EventType.AVAILABLE_CTRL_POINTS_CHANGED,
EventType.SELECTION_CHANGED, EventType.STATUS_MESSAGE_CHANGED);
EventType.SELECTION_CHANGED, EventType.STATUS_MESSAGE_CHANGED, EventType.MOUSE_MOVED);
}
@SuppressWarnings({"unchecked", "incomplete-switch"})
@@ -433,10 +463,28 @@ public class StatusBar extends JPanel implements IPlugIn {
refreshStatusText();
break;
case STATUS_MESSAGE_CHANGED:
statusMessage = (String) params[0];
statusMessage = (String) params[0];
break;
case MOUSE_MOVED:
mousePositionIn = (Point2D) params[1];
mousePositionMm = (Point2D) params[2];
refreshPosition(ConfigurationManager.getInstance().readBoolean(Presenter.METRIC_KEY, true));
break;
}
}
private void refreshPosition(boolean metric) {
Point2D mousePosition;
if (metric)
mousePosition = mousePositionMm;
else
mousePosition = mousePositionIn;
if (mousePosition == null)
getPositionLabel().setText(null);
else
getPositionLabel().setText(String.format("@%.2f %.2f " + (metric ? "mm" : "in"), mousePosition.getX(), mousePosition.getY()));
}
private void refreshStatusText() {
String statusText = this.statusMessage;
if (componentSlot == null) {
@@ -483,7 +531,8 @@ public class StatusBar extends JPanel implements IPlugIn {
+ "</font> or press <b>Esc</b> to cancel</html>";
break;
}
}
}
final String finalStatus = statusText;
SwingUtilities.invokeLater(new Runnable() {
+6 -2
View File
@@ -2397,10 +2397,14 @@
<org.diylc.appframework.update.Change>
<changeType>NEW_FEATURE</changeType>
<description>Added extra work space around the layout that can be used to store additional components and helpers, but does not get exported to a file. Configurable from the menu</description>
</org.diylc.appframework.update.Change>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>NEW_FEATURE</changeType>
<description>Show mouse position in the status bar</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType>
<description>Vast improvement of rendering performance, especially with large layouts</description>
<description>Vast improvement of rendering performance and memory management, especially with large layouts</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType>