mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +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,
|
AVAILABLE_CTRL_POINTS_CHANGED,
|
||||||
/**
|
/**
|
||||||
* Called when mouse cursor is moved. Point object is passed, containing the current cursor
|
* 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,
|
MOUSE_MOVED,
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -862,7 +862,10 @@ public class Presenter implements IPlugInPort {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
messageDispatcher.dispatchMessage(EventType.MOUSE_MOVED, previousScaledPoint);
|
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, inPoint, mmPoint);
|
||||||
|
|
||||||
if (!components.equals(controlPointMap)) {
|
if (!components.equals(controlPointMap)) {
|
||||||
controlPointMap = components;
|
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.apache.log4j.Logger;
|
||||||
import org.diylc.announcements.AnnouncementProvider;
|
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.miscutils.Utils;
|
||||||
import org.diylc.appframework.update.UpdateChecker;
|
import org.diylc.appframework.update.UpdateChecker;
|
||||||
import org.diylc.appframework.update.Version;
|
import org.diylc.appframework.update.Version;
|
||||||
@@ -67,6 +69,7 @@ import org.diylc.common.ITask;
|
|||||||
import org.diylc.core.IDIYComponent;
|
import org.diylc.core.IDIYComponent;
|
||||||
import org.diylc.core.IView;
|
import org.diylc.core.IView;
|
||||||
import org.diylc.images.IconLoader;
|
import org.diylc.images.IconLoader;
|
||||||
|
import org.diylc.presenter.Presenter;
|
||||||
import org.diylc.swing.ISwingUI;
|
import org.diylc.swing.ISwingUI;
|
||||||
import org.diylc.swingframework.MemoryBar;
|
import org.diylc.swingframework.MemoryBar;
|
||||||
import org.diylc.swingframework.miscutils.PercentageListCellRenderer;
|
import org.diylc.swingframework.miscutils.PercentageListCellRenderer;
|
||||||
@@ -88,6 +91,7 @@ public class StatusBar extends JPanel implements IPlugIn {
|
|||||||
private JLabel recentChangesLabel;
|
private JLabel recentChangesLabel;
|
||||||
private MemoryBar memoryPanel;
|
private MemoryBar memoryPanel;
|
||||||
private JLabel statusLabel;
|
private JLabel statusLabel;
|
||||||
|
private JLabel positionLabel;
|
||||||
private JLabel sizeLabel;
|
private JLabel sizeLabel;
|
||||||
|
|
||||||
private IPlugInPort plugInPort;
|
private IPlugInPort plugInPort;
|
||||||
@@ -101,9 +105,14 @@ public class StatusBar extends JPanel implements IPlugIn {
|
|||||||
private List<String> selectedComponentNames;
|
private List<String> selectedComponentNames;
|
||||||
private List<String> stuckComponentNames;
|
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) {
|
public StatusBar(ISwingUI swingUI) {
|
||||||
super();
|
super();
|
||||||
this.swingUI = swingUI;
|
this.swingUI = swingUI;
|
||||||
@@ -154,6 +163,14 @@ 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() {
|
private JComboBox getZoomBox() {
|
||||||
@@ -291,6 +308,14 @@ public class StatusBar extends JPanel implements IPlugIn {
|
|||||||
return statusLabel;
|
return statusLabel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private JLabel getPositionLabel() {
|
||||||
|
if (positionLabel == null) {
|
||||||
|
positionLabel = new JLabel();
|
||||||
|
positionLabel.setBorder(BorderFactory.createEmptyBorder(0, 4, 0, 0));
|
||||||
|
}
|
||||||
|
return positionLabel;
|
||||||
|
}
|
||||||
|
|
||||||
public JLabel getSizeLabel() {
|
public JLabel getSizeLabel() {
|
||||||
if (sizeLabel == null) {
|
if (sizeLabel == null) {
|
||||||
sizeLabel = new JLabel(IconLoader.Size.getIcon()) {
|
sizeLabel = new JLabel(IconLoader.Size.getIcon()) {
|
||||||
@@ -333,6 +358,11 @@ public class StatusBar extends JPanel implements IPlugIn {
|
|||||||
gbc.weightx = 1;
|
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());
|
JPanel zoomPanel = new JPanel(new BorderLayout());
|
||||||
zoomPanel.add(new JLabel("Zoom: "), BorderLayout.WEST);
|
zoomPanel.add(new JLabel("Zoom: "), BorderLayout.WEST);
|
||||||
zoomPanel.add(getZoomBox(), BorderLayout.CENTER);
|
zoomPanel.add(getZoomBox(), BorderLayout.CENTER);
|
||||||
@@ -382,7 +412,7 @@ public class StatusBar extends JPanel implements IPlugIn {
|
|||||||
@Override
|
@Override
|
||||||
public EnumSet<EventType> getSubscribedEventTypes() {
|
public EnumSet<EventType> getSubscribedEventTypes() {
|
||||||
return EnumSet.of(EventType.ZOOM_CHANGED, EventType.SLOT_CHANGED, EventType.AVAILABLE_CTRL_POINTS_CHANGED,
|
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"})
|
@SuppressWarnings({"unchecked", "incomplete-switch"})
|
||||||
@@ -434,9 +464,27 @@ public class StatusBar extends JPanel implements IPlugIn {
|
|||||||
break;
|
break;
|
||||||
case STATUS_MESSAGE_CHANGED:
|
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() {
|
private void refreshStatusText() {
|
||||||
String statusText = this.statusMessage;
|
String statusText = this.statusMessage;
|
||||||
if (componentSlot == null) {
|
if (componentSlot == null) {
|
||||||
@@ -484,6 +532,7 @@ public class StatusBar extends JPanel implements IPlugIn {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final String finalStatus = statusText;
|
final String finalStatus = statusText;
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
|
|
||||||
|
|||||||
@@ -2398,9 +2398,13 @@
|
|||||||
<changeType>NEW_FEATURE</changeType>
|
<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>
|
<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>
|
<org.diylc.appframework.update.Change>
|
||||||
<changeType>IMPROVEMENT</changeType>
|
<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>
|
||||||
<org.diylc.appframework.update.Change>
|
<org.diylc.appframework.update.Change>
|
||||||
<changeType>IMPROVEMENT</changeType>
|
<changeType>IMPROVEMENT</changeType>
|
||||||
|
|||||||
Reference in New Issue
Block a user