mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
Show mouse position in the status bar
This commit is contained in:
@@ -85,7 +85,8 @@ public enum EventType {
|
||||
AVAILABLE_CTRL_POINTS_CHANGED,
|
||||
/**
|
||||
* Called when mouse cursor is moved. Point object is passed, containing the current cursor
|
||||
* location (not taking zoom into account).
|
||||
* location (not taking zoom into account) in pixels and two {@link Point2D} objects with coordinates in
|
||||
* inches and mm
|
||||
*/
|
||||
MOUSE_MOVED,
|
||||
/**
|
||||
|
||||
@@ -861,8 +861,11 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Point2D inPoint = new Point2D.Double(1.0d * previousScaledPoint.x / Constants.PIXELS_PER_INCH, 1.0d * previousScaledPoint.y / Constants.PIXELS_PER_INCH);
|
||||
Point2D mmPoint = new Point2D.Double(inPoint.getX() * SizeUnit.in.getFactor() / SizeUnit.cm.getFactor() * 10d, inPoint.getY() * SizeUnit.in.getFactor() / SizeUnit.cm.getFactor() * 10d);
|
||||
|
||||
messageDispatcher.dispatchMessage(EventType.MOUSE_MOVED, previousScaledPoint);
|
||||
messageDispatcher.dispatchMessage(EventType.MOUSE_MOVED, previousScaledPoint, inPoint, mmPoint);
|
||||
|
||||
if (!components.equals(controlPointMap)) {
|
||||
controlPointMap = components;
|
||||
|
||||
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() {
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user