JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION,
null, new Object [] {this.createButton, this.saveButton, this.closeButton}, this.createButton);
if (parentView != null) {
optionPane.setComponentOrientation(((JComponent)parentView).getComponentOrientation());
}
final JDialog dialog = optionPane.createDialog(SwingUtilities.getRootPane((Component)parentView), this.dialogTitle);
dialog.setModal(false);
Component homeRoot = SwingUtilities.getRoot((Component)parentView);
if (homeRoot != null) {
// Restore location if it exists
Integer x = (Integer)this.home.getVisualProperty(PHOTO_DIALOG_X_VISUAL_PROPERTY);
Integer y = (Integer)this.home.getVisualProperty(PHOTO_DIALOG_Y_VISUAL_PROPERTY);
int windowRightBorder = homeRoot.getX() + homeRoot.getWidth();
Dimension screenSize = getToolkit().getScreenSize();
Insets screenInsets = getToolkit().getScreenInsets(getGraphicsConfiguration());
int screenRightBorder = screenSize.width - screenInsets.right;
// Check dialog isn't too high
int screenHeight = screenSize.height - screenInsets.top - screenInsets.bottom;
if (OperatingSystem.isLinux() && screenHeight == screenSize.height) {
// Let's consider that under Linux at least an horizontal bar exists
screenHeight -= 30;
}
int screenBottomBorder = screenSize.height - screenInsets.bottom;
int dialogWidth = dialog.getWidth();
if (dialog.getHeight() > screenHeight) {
dialog.setSize(dialogWidth, screenHeight);
}
int dialogHeight = dialog.getHeight();
if (x != null && y != null
&& x + dialogWidth <= screenRightBorder
&& y + dialogHeight <= screenBottomBorder) {
dialog.setLocation(x, y);
} else if (screenRightBorder - windowRightBorder > dialogWidth / 2
|| dialogHeight == screenHeight) {
// If there some space left at the right of the window,
// move the dialog to the right of window
dialog.setLocation(Math.min(windowRightBorder + 5, screenRightBorder - dialogWidth),
Math.max(Math.min(homeRoot.getY(), screenSize.height - dialogHeight - screenInsets.bottom), screenInsets.top));
} else {
dialog.setLocationByPlatform(true);
}
} else {
dialog.setLocationByPlatform(true);
}
// Add a listener on 3D view to be notified when its size changes
final JComponent view3D = (JComponent)this.controller.get3DView();
final ComponentAdapter view3DSizeListener = new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent ev) {
controller.set3DViewAspectRatio((float)view3D.getWidth() / view3D.getHeight());
}
};
view3D.addComponentListener(view3DSizeListener);
dialog.addWindowListener(new WindowAdapter() {
public void windowClosed(WindowEvent ev) {
((JComponent)controller.get3DView()).removeComponentListener(view3DSizeListener);
stopPhotoCreation(false);
currentPhotoPanel = null;
}
});
updateAdvancedComponents();
ToolTipManager.sharedInstance().registerComponent(this.qualitySlider);
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.addComponentListener(new ComponentAdapter() {
@Override
public void componentHidden(ComponentEvent ev) {
if (optionPane.getValue() != null
&& optionPane.getValue() != JOptionPane.UNINITIALIZED_VALUE) {
close();
}
}
@Override
public void componentMoved(ComponentEvent ev) {
controller.setVisualProperty(PHOTO_DIALOG_X_VISUAL_PROPERTY, dialog.getX());
controller.setVisualProperty(PHOTO_DIALOG_Y_VISUAL_PROPERTY, dialog.getY());
}
});
dialog.setVisible(true);
currentPhotoPanel = this;
}
}