Author: dandre
Date: Tue Sep 24 00:46:50 2013
New Revision: 4584
Log:
more dialog box refactoring
Modified:
trunk/AncestrisCore/core/src/ancestris/util/swing/DialogManager.java
trunk/AncestrisCore/core/src/genj/option/CustomOption.java
trunk/AncestrisCore/core/src/genj/print/PrintAction.java
trunk/AncestrisCore/core/src/genj/renderer/BlueprintEditor.java
trunk/AncestrisCore/core/src/genj/renderer/ChooseBlueprintAction.java
trunk/AncestrisCore/modules.views.tree/src/genj/tree/TreeView.java
Modified: trunk/AncestrisCore/core/src/ancestris/util/swing/DialogManager.java
==============================================================================
--- trunk/AncestrisCore/core/src/ancestris/util/swing/DialogManager.java
(original)
+++ trunk/AncestrisCore/core/src/ancestris/util/swing/DialogManager.java
Tue Sep 24 00:46:50 2013
@@ -26,6 +26,9 @@
WARNING_MESSAGE = NotifyDescriptor.WARNING_MESSAGE,
QUESTION_MESSAGE = NotifyDescriptor.QUESTION_MESSAGE,
PLAIN_MESSAGE = NotifyDescriptor.PLAIN_MESSAGE;
+ public static final int OK_CANCEL_OPTION =
DialogDescriptor.OK_CANCEL_OPTION;
+ /** Return value if OK is chosen. */
+ public static final Object OK_OPTION = DialogDescriptor.OK_OPTION;
private static DialogManager instance = null;
public static DialogManager getInstance() {
if (instance == null) {
@@ -54,10 +57,22 @@
*
* @return
*/
- public Object show(String title, int messageType, JComponent content,
Object[] options, String dialogId) {
+ //TODO: redesign API with less functions
+ public Object show(String title, int messageType, JComponent content,int
optionType, String dialogId) {
+ return show(title, messageType, content, optionType, null, dialogId);
+ }
+ public Object show(String title, int messageType, JComponent
content,Object[] options, String dialogId) {
+ return show(title, messageType, content, 0, options, dialogId);
+ }
+ public Object show(String title, JComponent content,String dialogId) {
+ return show(title, QUESTION_MESSAGE, content, 0,new Object[]{
DialogDescriptor.OK_OPTION}, dialogId);
+ }
+
+ private Object show(String title, int messageType, JComponent content,int
optionType, Object[] options, String dialogId) {
DialogDescriptor d = new DialogDescriptor(content, title);
d.setMessageType(messageType);
- d.setOptions(options);
+ if (options!=null)
+ d.setOptions(options);
final Dialog dialog = DialogDisplayer.getDefault().createDialog(d);
// restore bounds
if (dialogId != null) {
@@ -86,4 +101,58 @@
}
return null;
}
+
+ public static ADialog create(String title, JComponent content){
+ return new ADialog(title, content);
+ }
+
+ public static class ADialog{
+ private DialogDescriptor dd;
+ private String dialogId = null;
+
+ public ADialog(String title, JComponent content) {
+ dd = new DialogDescriptor(content, title);
+ dd.setMessageType(DialogDescriptor.QUESTION_MESSAGE);
+ dd.setOptions(new Object[]{ DialogDescriptor.OK_OPTION});
+ }
+
+ public ADialog setOptions(Object[] newOptions) {
+ dd.setOptions(newOptions);
+ return this;
+ }
+
+ public ADialog setOptionType(int newType) {
+ dd.setOptions(null);
+ dd.setOptionType(newType);
+ return this;
+ }
+
+ public ADialog setMessageType(int newType) {
+ dd.setMessageType(newType);
+ return this;
+ }
+
+ public ADialog setDialogId(String id) {
+ dialogId = id;
+ return this;
+ }
+ public Object show() {
+ final Dialog dialog = DialogDisplayer.getDefault().createDialog(dd);
+ // restore bounds
+ if (dialogId != null) {
+ final Registry registry = Registry.get(DialogManager.class);
+ Dimension bounds = registry.get(dialogId+".dialog", (Dimension)
null);
+ if (bounds != null) {
+ Rectangle prev = dialog.getBounds();
+ prev.grow((bounds.width - prev.width) / 2, (bounds.height -
prev.height) / 2);
+ dialog.setBounds(prev);
+ }
+ dialog.setVisible(true);
+ registry.put(dialogId+".dialog", dialog.getSize());
+ } else {
+ dialog.setVisible(true);
+ }
+ return dd.getValue();
+ }
+ }
}
Modified: trunk/AncestrisCore/core/src/genj/option/CustomOption.java
==============================================================================
--- trunk/AncestrisCore/core/src/genj/option/CustomOption.java (original)
+++ trunk/AncestrisCore/core/src/genj/option/CustomOption.java Tue Sep 24
00:46:50 2013
@@ -22,12 +22,14 @@
package genj.option;
import ancestris.core.actions.AbstractAncestrisAction;
+import ancestris.util.swing.DialogManager;
import genj.util.swing.ButtonHelper;
import genj.util.swing.DialogHelper;
import java.awt.event.ActionEvent;
import javax.swing.JComponent;
+import org.openide.DialogDescriptor;
/**
* A custom option with custom UI
@@ -50,8 +52,10 @@
protected void edit() {
JComponent editor = getEditor();
- int rc = DialogHelper.openDialog(getName(), DialogHelper.QUESTION_MESSAGE,
editor, AbstractAncestrisAction.okCancel(), widget);
- if (rc==0)
+ Object rc = DialogManager.create(getName(), editor).
+ setOptionType(DialogDescriptor.OK_CANCEL_OPTION).
+ setDialogId("customoption").show();
+ if (rc==DialogDescriptor.OK_OPTION)
commit(editor);
}
Modified: trunk/AncestrisCore/core/src/genj/print/PrintAction.java
==============================================================================
--- trunk/AncestrisCore/core/src/genj/print/PrintAction.java (original)
+++ trunk/AncestrisCore/core/src/genj/print/PrintAction.java Tue Sep 24
00:46:50 2013
@@ -21,6 +21,7 @@
import genj.util.Resources;
import ancestris.core.actions.AbstractAncestrisAction;
+import ancestris.util.swing.DialogManager;
import genj.util.swing.DialogHelper;
import genj.util.swing.ImageIcon;
@@ -30,6 +31,7 @@
import javax.print.PrintException;
import javax.swing.Action;
+import org.openide.DialogDescriptor;
/**
* An action for printing
@@ -72,20 +74,15 @@
// show dialog
PrintWidget widget = new PrintWidget(task);
- // prepare actions
- Action[] actions = {
- new AbstractAncestrisAction(RES.getString("print")),
- AbstractAncestrisAction.cancel()
- };
-
// show it in dialog
- int choice = DialogHelper.openDialog(
- title,
- DialogHelper.QUESTION_MESSAGE,
- widget, actions, e);
-
+ String printChoice = new String(RES.getString("print"));
+ Object choice = DialogManager.create(title, widget).
+ setOptions(new
Object[]{printChoice,DialogDescriptor.CANCEL_OPTION})
+ .setDialogId("printaction")
+ .show();
+
// check choice
- if (choice != 0 || task.getPages().width == 0 || task.getPages().height ==
0)
+ if (choice != printChoice || task.getPages().width == 0 ||
task.getPages().height == 0)
return;
widget.commit();
Modified: trunk/AncestrisCore/core/src/genj/renderer/BlueprintEditor.java
==============================================================================
--- trunk/AncestrisCore/core/src/genj/renderer/BlueprintEditor.java
(original)
+++ trunk/AncestrisCore/core/src/genj/renderer/BlueprintEditor.java Tue Sep
24 00:46:50 2013
@@ -31,6 +31,7 @@
import genj.gedcom.TagPath;
import genj.util.Resources;
import ancestris.core.actions.AbstractAncestrisAction;
+import ancestris.util.swing.DialogManager;
import genj.util.swing.DialogHelper;
import java.awt.BorderLayout;
@@ -60,6 +61,7 @@
import javax.swing.SwingUtilities;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
+import org.openide.DialogDescriptor;
/**
* An editor component for changing a rendering scheme
@@ -299,9 +301,12 @@
TagPath[] paths = grammar.getAllPaths(blueprint.getTag(),
Property.class);
tree.setPaths(paths, new TagPath[0]);
// Recheck with the user
- int option =
DialogHelper.openDialog(resources.getString("prop.insert.tip"),DialogHelper.QUESTION_MESSAGE,tree,AbstractAncestrisAction.okCancel(),BlueprintEditor.this);
+ Object option =
DialogManager.create(resources.getString("prop.insert.tip"),tree).
+ setOptionType(DialogDescriptor.OK_CANCEL_OPTION).
+ setDialogId("genj.renderer.blueprinteditor").
+ show();
// .. OK?
- if (option!=0) return;
+ if (option!=DialogDescriptor.OK_OPTION) return;
// add those properties
paths = tree.getSelection();
for (int p=0;p<paths.length; p++) {
Modified: trunk/AncestrisCore/core/src/genj/renderer/ChooseBlueprintAction.java
==============================================================================
--- trunk/AncestrisCore/core/src/genj/renderer/ChooseBlueprintAction.java
(original)
+++ trunk/AncestrisCore/core/src/genj/renderer/ChooseBlueprintAction.java
Tue Sep 24 00:46:50 2013
@@ -41,6 +41,7 @@
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
+import org.openide.DialogDescriptor;
/**
* Action for picking/editing a blueprint
@@ -111,12 +112,9 @@
content.add(bh.create(del));
content.add(editor);
- DialogHelper.openDialog(
- RESOURCES.getString("blueprint"),
- DialogHelper.QUESTION_MESSAGE,
- content,
- AbstractAncestrisAction.okOnly(),
- e);
+ DialogManager.create(RESOURCES.getString("blueprint"), content).
+ setDialogId("genj.renderer.blueprint").
+ show();
editor.commit();
Modified: trunk/AncestrisCore/modules.views.tree/src/genj/tree/TreeView.java
==============================================================================
--- trunk/AncestrisCore/modules.views.tree/src/genj/tree/TreeView.java
(original)
+++ trunk/AncestrisCore/modules.views.tree/src/genj/tree/TreeView.java Tue Sep
24 00:46:50 2013
@@ -1246,8 +1246,11 @@
// let the user choose an individual
SelectEntityWidget select = new
SelectEntityWidget(context.getGedcom(), Gedcom.INDI, null);
- int rc = DialogHelper.openDialog(getText(),
DialogHelper.QUESTION_MESSAGE, select, AbstractAncestrisAction.okCancel(),
TreeView.this);
- if (rc == 0) {
+ Object rc = DialogManager.create(getText(), select)
+ .setOptionType(DialogManager.OK_CANCEL_OPTION)
+// .setDialogId("select.root")
+ .show();
+ if (rc == DialogManager.OK_OPTION) {
setRoot(select.getSelection());
}
---------------------------------------------------------------------
Site Web Ancestris : http://www.ancestris.org
<*> Pour vous desinscrire de cette liste, envoyez un mail a :
[email protected]
<*> Pour obtenir de l'aide sur les commandes de la liste :
[email protected]
Pour obtenir tous les messages lies a ce fil de discussion, cliquez sur le
lien ci-dessous, cela ouvrira votre logiciel de messagerie. Il vous suffira
d'envoyer le message :
[email protected]