Search in sources :

Example 1 with FileObject

use of php.runtime.ext.core.classes.stream.FileObject in project jphp by jphp-compiler.

the class UIFileChooser method addChoosableFilter.

@Signature({ @Arg(value = "filter", type = HintType.CALLABLE), @Arg(value = "description") })
public Memory addChoosableFilter(final Environment env, Memory... args) {
    final Invoker invoker = Invoker.valueOf(env, null, args[0]);
    final String description = args[1].toString();
    component.addChoosableFileFilter(new FileFilter() {

        @Override
        public boolean accept(File f) {
            return invoker.callNoThrow(new ObjectMemory(new FileObject(env, f))).toBoolean();
        }

        @Override
        public String getDescription() {
            return description;
        }
    });
    return Memory.NULL;
}
Also used : Invoker(php.runtime.invoke.Invoker) FileObject(php.runtime.ext.core.classes.stream.FileObject) FileFilter(javax.swing.filechooser.FileFilter) File(java.io.File)

Example 2 with FileObject

use of php.runtime.ext.core.classes.stream.FileObject in project jphp by jphp-compiler.

the class UIFileChooser method onFileView.

@Signature({ @Arg(value = "field"), @Arg(value = "callback", type = HintType.CALLABLE, optional = @Optional("null")) })
public Memory onFileView(final Environment env, final Memory... args) {
    final FileView oldFileView = component.getFileView();
    final Invoker invoker = Invoker.valueOf(env, null, args[1]);
    final String field = args[0].toString().toLowerCase();
    component.setFileView(new FileView() {

        @Override
        public String getName(File f) {
            if (invoker != null && field.equals("name")) {
                Memory r = invoker.callNoThrow(new ObjectMemory(new FileObject(env, f)));
                if (!r.isNull())
                    return r.toString();
            }
            return oldFileView == null ? super.getName(f) : oldFileView.getName(f);
        }

        @Override
        public String getDescription(File f) {
            if (invoker != null && field.equals("description")) {
                Memory r = invoker.callNoThrow(new ObjectMemory(new FileObject(env, f)));
                if (!r.isNull())
                    return r.toString();
            }
            return oldFileView == null ? super.getDescription(f) : oldFileView.getDescription(f);
        }

        @Override
        public String getTypeDescription(File f) {
            return super.getTypeDescription(f);
        }

        @Override
        public Icon getIcon(File f) {
            if (invoker != null && field.equals("icon")) {
                Memory r = invoker.callNoThrow(new ObjectMemory(new FileObject(env, f)));
                if (r.instanceOf(WrapImage.class))
                    return r.toObject(WrapImage.class).getImageIcon();
            }
            return oldFileView == null ? super.getIcon(f) : oldFileView.getIcon(f);
        }

        @Override
        public Boolean isTraversable(File f) {
            if (invoker != null && field.equals("traversable")) {
                Memory r = invoker.callNoThrow(new ObjectMemory(new FileObject(env, f)));
                if (!r.isNull())
                    return r.toBoolean();
            }
            return oldFileView == null ? super.isTraversable(f) : oldFileView.isTraversable(f);
        }
    });
    return Memory.NULL;
}
Also used : FileView(javax.swing.filechooser.FileView) Invoker(php.runtime.invoke.Invoker) Memory(php.runtime.Memory) FileObject(php.runtime.ext.core.classes.stream.FileObject) WrapImage(org.develnext.jphp.swing.classes.WrapImage) File(java.io.File)

Aggregations

File (java.io.File)2 FileObject (php.runtime.ext.core.classes.stream.FileObject)2 Invoker (php.runtime.invoke.Invoker)2 FileFilter (javax.swing.filechooser.FileFilter)1 FileView (javax.swing.filechooser.FileView)1 WrapImage (org.develnext.jphp.swing.classes.WrapImage)1 Memory (php.runtime.Memory)1