Search in sources :

Example 1 with PropertySheetDialog

use of automenta.vivisect.swing.property.propertysheet.PropertySheetDialog in project opennars by opennars.

the class PropertyUtils method editProperties.

public static void editProperties(Window parent, Object obj, boolean editable) {
    final PropertySheetPanel psp = getPropsPanel(obj, editable);
    final PropertySheetDialog propertySheetDialog = createWindow(parent, editable, psp, "Properties of " + obj.getClass().getSimpleName());
    if (!propertySheetDialog.ask()) {
        // cancelled
        return;
    }
    LinkedHashMap<String, SerializableProperty> newProps = new LinkedHashMap<>();
    for (automenta.vivisect.swing.property.propertysheet.Property p : psp.getProperties()) newProps.put(p.getName(), new SerializableProperty(p));
    setProperties(obj, newProps, true);
}
Also used : PropertySheetPanel(automenta.vivisect.swing.property.propertysheet.PropertySheetPanel) PropertySheetDialog(automenta.vivisect.swing.property.propertysheet.PropertySheetDialog) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with PropertySheetDialog

use of automenta.vivisect.swing.property.propertysheet.PropertySheetDialog in project opennars by opennars.

the class PropertyUtils method createWindow.

public static PropertySheetDialog createWindow(Window parent, boolean editable, final PropertySheetPanel psp, String title) {
    final PropertySheetDialog propertySheetDialog;
    if (parent instanceof Dialog) {
        Dialog pDialog = (Dialog) parent;
        propertySheetDialog = new PropertySheetDialog(pDialog);
    } else if (parent instanceof Frame) {
        Frame pFrame = (Frame) parent;
        propertySheetDialog = new PropertySheetDialog(pFrame);
    } else {
        propertySheetDialog = new PropertySheetDialog() {

            private static final long serialVersionUID = 1L;

            @Override
            public void ok() {
                if (psp.getTable().getEditorComponent() != null)
                    psp.getTable().commitEditing();
                super.ok();
            }
        };
    }
    if (editable) {
        propertySheetDialog.setDialogMode(PropertySheetDialog.OK_CANCEL_DIALOG);
    } else {
        propertySheetDialog.setDialogMode(PropertySheetDialog.CLOSE_DIALOG);
    }
    int sb = 1;
    for (Component compL0 : propertySheetDialog.getRootPane().getComponents()) {
        if (compL0 instanceof JLayeredPane) {
            for (Component compL01 : ((JLayeredPane) compL0).getComponents()) {
                if (!(compL01 instanceof JPanel))
                    continue;
                for (Component compL1 : ((JPanel) compL01).getComponents()) {
                    if (compL1 instanceof BannerPanel)
                        continue;
                    if (compL1 instanceof JPanel) {
                        for (Component compL2 : ((JPanel) compL1).getComponents()) {
                            for (Component compL3 : ((JPanel) compL2).getComponents()) {
                                if (compL3 instanceof JButton) {
                                    if (propertySheetDialog.getDialogMode() == PropertySheetDialog.OK_CANCEL_DIALOG && sb == 1) {
                                        ((JButton) compL3).setText("OK");
                                        sb--;
                                    } else if (propertySheetDialog.getDialogMode() == PropertySheetDialog.CLOSE_DIALOG || sb == 0) {
                                        ((JButton) compL3).setText(propertySheetDialog.getDialogMode() == PropertySheetDialog.CLOSE_DIALOG ? "Close" : "Cancel");
                                        sb--;
                                        break;
                                    }
                                    if (sb < 0)
                                        break;
                                }
                            }
                            if (sb < 0)
                                break;
                        }
                    }
                }
            }
        }
    }
    if (title != null) {
        propertySheetDialog.getBanner().setTitle(title);
        propertySheetDialog.setTitle(title);
    }
    // propertySheetDialog.setIconImage(ImageUtils.getImage("images/menus/settings.png"));
    // propertySheetDialog.getBanner().setIcon(ImageUtils.getIcon("images/settings.png"));
    propertySheetDialog.getContentPane().add(psp);
    propertySheetDialog.pack();
    propertySheetDialog.setLocationRelativeTo(null);
    propertySheetDialog.setModalityType(ModalityType.DOCUMENT_MODAL);
    return propertySheetDialog;
}
Also used : JPanel(javax.swing.JPanel) Frame(java.awt.Frame) PropertySheetDialog(automenta.vivisect.swing.property.propertysheet.PropertySheetDialog) Dialog(java.awt.Dialog) JLayeredPane(javax.swing.JLayeredPane) JButton(javax.swing.JButton) Component(java.awt.Component) BannerPanel(automenta.vivisect.swing.property.swing.BannerPanel) PropertySheetDialog(automenta.vivisect.swing.property.propertysheet.PropertySheetDialog)

Aggregations

PropertySheetDialog (automenta.vivisect.swing.property.propertysheet.PropertySheetDialog)2 PropertySheetPanel (automenta.vivisect.swing.property.propertysheet.PropertySheetPanel)1 BannerPanel (automenta.vivisect.swing.property.swing.BannerPanel)1 Component (java.awt.Component)1 Dialog (java.awt.Dialog)1 Frame (java.awt.Frame)1 LinkedHashMap (java.util.LinkedHashMap)1 JButton (javax.swing.JButton)1 JLayeredPane (javax.swing.JLayeredPane)1 JPanel (javax.swing.JPanel)1