Skip to content

Commit

Permalink
console/ConsolePanel: Using new Popup interface annotation and fix mo…
Browse files Browse the repository at this point in the history
…dal popup dialog position.
  • Loading branch information
paulosousadias committed Jul 27, 2024
1 parent 2e8d388 commit 75dc4bf
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/java/pt/lsts/neptus/console/ConsolePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
package pt.lsts.neptus.console;

import java.awt.Container;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Point;
Expand Down Expand Up @@ -125,6 +126,7 @@ public abstract class ConsolePanel extends JPanel implements PropertiesProvider,
protected JDialog dialog = null;
protected Action popUpAction = null;
private JMenuItem menuItem = null;
private boolean alwaysResetPopupPosition = false;

private double percentXPos, percentYPos, percentWidth, percentHeight;

Expand Down Expand Up @@ -299,6 +301,7 @@ private void buildPopup() {
String iconPath = cAction.icon().isEmpty() ? PluginUtils.getPluginIcon(this.getClass()) : cAction.icon();
int width = cAction.width();
int height = cAction.height();
Dialog.ModalityType modality = cAction.modality();
KeyStroke accelerator = null;
if (cAction.accelerator() != KeyEvent.VK_UNDEFINED) {
int key = cAction.accelerator();
Expand All @@ -317,6 +320,7 @@ private void buildPopup() {
getConsole().updateJMenuView(); //order view menu items

// Build Dialog
alwaysResetPopupPosition = cAction.alwaysResetPopupPosition();
dialog = new JDialog(getConsole());
dialog.setTitle(name2);
dialog.setIconImage(icon.getImage());
Expand All @@ -341,6 +345,11 @@ public void actionPerformed(ActionEvent e) {
if (res)
menuItem.setAccelerator(accelerator);
}

if (modality != null && modality != Dialog.ModalityType.MODELESS) {
dialog.setModalityType(modality);
}

// dialog.add(this); This cannot be done here, because if the component is on the initial layout it will not
// show
}
Expand Down Expand Up @@ -424,6 +433,16 @@ private void decideToShowPopupDialog(final POSITION popupPosition) {
dialog.add(ConsolePanel.this);

if (SwingUtilities.isDescendingFrom(ConsolePanel.this.getParent(), dialog)) {
boolean wasVisible = dialog.isVisible();
Dialog.ModalityType modality = dialog.getModalityType();
boolean isModal = modality != Dialog.ModalityType.MODELESS;
if (isModal && !wasVisible) {
dialog.setModalityType(Dialog.ModalityType.MODELESS);
dialog.setVisible(true);
setPopupPosition(popupPosition);
dialog.setVisible(false);
dialog.setModalityType(modality);
}
dialog.setVisible(!dialog.isVisible());
if (dialog.isVisible())
popupShown();
Expand Down Expand Up @@ -906,7 +925,7 @@ public void setFixedSize(boolean fixedSize) {
}

protected void setPopupPosition(final POSITION popupPosition) {
if (dialog.isVisible() && popupPositionFlag == false) {
if (dialog.isVisible() && !popupPositionFlag) {
Point p = getConsole().getLocationOnScreen();
switch (popupPosition) {
case TOP_LEFT:
Expand Down Expand Up @@ -942,7 +961,7 @@ protected void setPopupPosition(final POSITION popupPosition) {
break;
}
dialog.setLocation(p);
this.popupPositionFlag = true;
this.popupPositionFlag = !alwaysResetPopupPosition;
}
}

Expand Down

0 comments on commit 75dc4bf

Please sign in to comment.