Kaynağa Gözat

* synchronizacja z local repo

Ranides Atterwim 13 yıl önce
ebeveyn
işleme
1b1ad94bda
21 değiştirilmiş dosya ile 89 ekleme ve 2250 silme
  1. 24 1
      src/main/java/net/ranides/assira/awt/AWTInvoker.java
  2. 37 0
      src/main/java/net/ranides/assira/collection/ArrayUtils.java
  3. 14 0
      src/main/java/net/ranides/assira/io/PathHelper.java
  4. 14 2
      src/main/java/net/ranides/assira/math/MathUtils.java
  5. 0 112
      src/main/java/net/ranides/assira/swing/DocumentUtils.java
  6. 0 151
      src/main/java/net/ranides/assira/swing/QButtonManager.java
  7. 0 216
      src/main/java/net/ranides/assira/swing/QFileChooser.java
  8. 0 78
      src/main/java/net/ranides/assira/swing/QIcon.java
  9. 0 89
      src/main/java/net/ranides/assira/swing/QImageFileChooser.java
  10. 0 344
      src/main/java/net/ranides/assira/swing/QPanel.java
  11. 0 86
      src/main/java/net/ranides/assira/swing/QSelect.java
  12. 0 242
      src/main/java/net/ranides/assira/swing/QSelectPopup.java
  13. 0 50
      src/main/java/net/ranides/assira/swing/QWindow.java
  14. 0 75
      src/main/java/net/ranides/assira/swing/UIManager.java
  15. 0 79
      src/main/java/net/ranides/assira/swing/listeners/QListSelectionListener.java
  16. 0 47
      src/main/java/net/ranides/assira/swing/renderers/QCellDecorator.java
  17. 0 65
      src/main/java/net/ranides/assira/swing/renderers/QImageFileView.java
  18. 0 203
      src/main/java/net/ranides/assira/swing/renderers/QLineRenderer.java
  19. 0 195
      src/main/java/net/ranides/assira/swing/renderers/QListItem.java
  20. 0 157
      src/main/java/net/ranides/assira/swing/renderers/QListItemEditor.java
  21. 0 58
      src/test/java/net/ranides/assira/io/IndentWriterTest.java

+ 24 - 1
src/main/java/net/ranides/assira/awt/AWTInvoker.java

@@ -6,7 +6,11 @@
  */
 package net.ranides.assira.awt;
 
+import java.applet.Applet;
 import java.awt.EventQueue;
+import java.awt.Frame;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
 import java.lang.reflect.Method;
 import javax.swing.SwingUtilities;
 import net.ranides.assira.collection.ArrayUtils;
@@ -36,7 +40,7 @@ import net.ranides.assira.trace.LoggerUtils;
  */
 public final class AWTInvoker {
     
-    public static final AdvLogger LOGGER = LoggerUtils.getLogger();
+    private static final AdvLogger LOGGER = LoggerUtils.getLogger();
     
     private AWTInvoker() {
         // utility class
@@ -135,4 +139,23 @@ public final class AWTInvoker {
         });
     }
     
+    public static void runApplet(final Applet applet, final String title, final int width, final int height) {
+        final Frame frame = new Frame(title);
+        // allow some extra room for the frame title bar.
+        frame.setSize(width + 16, height + 36);
+        frame.addWindowListener(new WindowAdapter() {
+            @Override
+            public void windowClosing(WindowEvent e) {
+                applet.stop();
+                applet.destroy();
+                System.exit(0);
+            }
+        });
+        frame.add(applet);
+        applet.init();
+        frame.validate();
+        frame.setVisible(true);
+        applet.start();
+    }
+    
 }

+ 37 - 0
src/main/java/net/ranides/assira/collection/ArrayUtils.java

@@ -912,5 +912,42 @@ public final class ArrayUtils {
     public static <T> boolean contains(T[] array, T value) {
         return indexOf(array, value) >= 0;
     }
+    
+    public static boolean isEqual(byte[] array1, byte[] array2) {
+        if (array1==array2) {
+            return true;
+        }
+        if (array1==null || array2==null) {
+            return false;
+        }
+        int n = array1.length;
+        if (array2.length != n) {
+            return false;
+        }
+
+        for (int i=0; i<n; i++) {
+            if (array1[i] != array2[i]) { return false; }
+        }
+        return true;
+    }
+    
+    public static boolean isEqual(int size, byte[] array1, byte[] array2) {
+        if (array1==array2) {
+            return true;
+        }
+        if (array1==null || array2==null) {
+            return false;
+        }
+        if(array1.length != array2.length) {
+            if(array1.length < size || array2.length < size) {
+                return false;
+            }
+        }
+        
+        for (int i=0, n=Math.min(array1.length, size); i<n; i++) {
+            if (array1[i] != array2[i]) { return false; }
+        }
+        return true;
+    }
 
 }

+ 14 - 0
src/main/java/net/ranides/assira/io/PathHelper.java

@@ -14,6 +14,7 @@ import java.util.LinkedList;
 import java.util.List;
 import net.ranides.assira.collection.list.VirtualList;
 import net.ranides.assira.text.StringUtils;
+import net.ranides.assira.text.Strings;
 
 /**
  * Klasa pomocnicza do przekształcania i parsowania ścieżek w systemie plików.
@@ -302,4 +303,17 @@ public final class PathHelper {
         int index = name.lastIndexOf(".");
         return index<0 ? name : name.substring(0, index);
     }
+    
+    public static File getParent(File file) throws PathConvertException {
+        String parent = file.getParent();
+        if(Strings.isEmpty(parent)) {
+            String path = file.getAbsolutePath();
+            String name = Strings.or(file.getName(),"");
+            parent = path.substring(0, path.length() - name.length());
+            if( Strings.isEmpty(parent) ) {
+                throw new PathConvertException("file has no parent");
+            }
+        }
+        return new File(parent);
+    }
 }

+ 14 - 2
src/main/java/net/ranides/assira/math/MathUtils.java

@@ -12,6 +12,18 @@ public final class MathUtils {
         // utility class
     }
     
+    public static boolean inRange(int value, int min, int max) {
+        return value >= min && value <= max;
+    }
+    
+    public static boolean inRange(byte value, byte min, byte max) {
+        return value >= min && value <= max;
+    }
+    
+    public static boolean inRange(long value, long min, long max) {
+        return value >= min && value <= max;
+    }
+    
     public static int clip(int value, int min, int max) {
         assert min <= max;
         return value < min ? min : value > max ? max : value;
@@ -27,12 +39,12 @@ public final class MathUtils {
         return value < min ? min : value > max ? max : value;
     }
     
-    public static int iclip(double value, int min, int max) {
+    public static int roundClip(double value, int min, int max) {
         assert min <= max;
         return (int)Math.round(value < min ? min : value > max ? max : value);
     }
     
-    public static long lclip(double value, long min, long max) {
+    public static long roundClip(double value, long min, long max) {
         assert min <= max;
         return Math.round(value < min ? min : value > max ? max : value);
     }

+ 0 - 112
src/main/java/net/ranides/assira/swing/DocumentUtils.java

@@ -1,112 +0,0 @@
-/*
- *  @author Ranides Atterwim <ranides@gmail.com>
- *  @copyright Ranides Atterwim
- *  @license WTFPL
- *  @url http://ranides.net/projects/assira
- */
-
-package net.ranides.assira.swing;
-
-import java.io.IOException;
-import java.io.StringReader;
-import javax.swing.JEditorPane;
-import javax.swing.JTextField;
-import javax.swing.event.DocumentEvent;
-import javax.swing.event.DocumentListener;
-import javax.swing.text.BadLocationException;
-import javax.swing.text.Element;
-import javax.swing.text.JTextComponent;
-import javax.swing.text.StyleConstants;
-import javax.swing.text.html.HTML;
-import javax.swing.text.html.HTMLDocument;
-
-/**
- *
- * @author ranides
- */
-public final class DocumentUtils {
-
-    private DocumentUtils() { }
-
-    public static abstract class ChangeListener implements DocumentListener {
-
-        public abstract void onChange(DocumentEvent event);
-
-        @Override
-        public final void insertUpdate(DocumentEvent event) {
-            onChange(event);
-        }
-        @Override
-        public void removeUpdate(DocumentEvent event) {
-            onChange(event);
-        }
-        @Override
-        public void changedUpdate(DocumentEvent event) {
-            onChange(event);
-        }
-    }
-    
-    public static void addChangeListener(JEditorPane editor, DocumentListener listener) {
-        editor.getDocument().addDocumentListener(listener);
-    }
-    
-    public static void addChangeListener(JTextField field, DocumentListener listener) {
-        field.getDocument().addDocumentListener(listener);
-    }
-    
-    public static void removeChangeListener(JEditorPane editor, DocumentListener listener) {
-        editor.getDocument().removeDocumentListener(listener);
-    }
-    
-    public static void removeChangeListener(JTextField field, DocumentListener listener) {
-        field.getDocument().removeDocumentListener(listener);
-    }
-    
-    
-    public static void setContent(JTextComponent view, String css, String text) {
-        setText(view, text);
-        setStyle(view, css);
-    }
-    
-    public static void setStyle(JTextComponent view, String css) {
-        try {
-            HTMLDocument doc = (HTMLDocument)view.getDocument();
-            doc.getStyleSheet().loadRules(new StringReader(css), null);
-        } catch (IOException cause) {
-            throw new AssertionError(cause);
-        } catch (ClassCastException cause) {
-            throw new IllegalStateException("editor must support text/html", cause);
-        }
-    }
-    
-public static void appendText(JTextComponent view, String text) {
-    try {
-        HTMLDocument doc = (HTMLDocument)view.getDocument();
-        Element root     = doc.getDefaultRootElement();
-        Element body     = doc.getElement(root, StyleConstants.NameAttribute, HTML.Tag.BODY);
-        doc.insertBeforeEnd(body, text);
-    } catch(IOException cause) {
-        throw new AssertionError(cause);
-    } catch(BadLocationException cause) {
-        throw new AssertionError(cause);
-    } catch (ClassCastException cause) {
-        throw new IllegalStateException("editor must support text/html", cause);
-    }
-}
-
-public static void setText(JTextComponent view, String text) {
-    try {
-        HTMLDocument doc = (HTMLDocument)view.getDocument();
-        Element root     = doc.getDefaultRootElement();
-        Element body     = doc.getElement(root, StyleConstants.NameAttribute, HTML.Tag.BODY);
-        doc.setInnerHTML(body, text);
-    } catch(IOException cause) {
-        throw new AssertionError(cause);
-    } catch(BadLocationException cause) {
-        throw new AssertionError(cause);
-    } catch (ClassCastException cause) {
-        throw new IllegalStateException("editor must support text/html", cause);
-    }
-}
-    
-}

+ 0 - 151
src/main/java/net/ranides/assira/swing/QButtonManager.java

@@ -1,151 +0,0 @@
-/*
- *  @author Ranides Atterwim <ranides@gmail.com>
- *  @copyright Ranides Atterwim
- *  @license WTFPL
- *  @url http://ranides.net/projects/assira
- */
-
-package net.ranides.assira.swing;
-
-import java.awt.Graphics2D;
-import java.awt.Image;
-import java.awt.Rectangle;
-import java.awt.SystemColor;
-import java.awt.event.MouseEvent;
-import java.util.ArrayList;
-import javax.swing.JComponent;
-
-/**
- *
- * @author ranides
- */
-public class QButtonManager {
-
-    public abstract static class ButtonEntry {
-        protected boolean pushable;
-        protected Image   icon;
-        protected boolean down;
-        protected boolean pressed;
-
-        public ButtonEntry(boolean pushable, Image icon) {
-            this.pushable = pushable;
-            this.icon = icon;
-        }
-
-        public abstract void action(QButtonManager manager);
-    }
-
-/* ************************************************************************** */
-
-    private final ArrayList<ButtonEntry> buttons = new ArrayList<ButtonEntry>();
-    private ButtonEntry active;
-    private int top;
-    private int right;
-    private int bottom;
-    private int left;
-
-    private final JComponent parent;
-
-    public QButtonManager(JComponent parent) {
-        this.parent = parent;
-    }
-
-    public void doLayout(int top, int right, int bottom, int left) {
-        this.top = top;
-        this.right = right;
-        this.bottom = bottom;
-        this.left = left;
-    }
-
-    public boolean hitTest(MouseEvent event) {
-        Rectangle caption = getCaptionArea();
-        int bs = caption.height+2;
-        int dx = caption.width+2 - buttons.size()*bs;
-        int px = event.getPoint().x;
-
-        hitRelease(event);
-
-        if(caption.contains( event.getPoint() ) ) {
-            if(px < dx) { return true; }
-            if(event.getID() == MouseEvent.MOUSE_PRESSED ) {
-                int a = buttons.size() - (px-dx)/bs - 1;
-                active = buttons.get(a);
-                active.pressed = true;
-                parent.repaint();
-            }
-            return false;
-        }
-        return false;
-    }
-
-    public void hitRelease(MouseEvent event) {
-        if( null == active) { return; }
-        if(event.getID() == MouseEvent.MOUSE_RELEASED) {
-            if(active.pushable) { active.down = !active.down; }
-            active.action(this);
-        }
-        active.pressed = false;
-        active = null;
-        parent.repaint();
-    }
-
-    public Rectangle getCaptionArea() {
-        int w = parent.getWidth();
-        int h = parent.getHeight();
-        int cx = caBegin(left, w);
-        int cy = caBegin(top, h);
-        int cw = caRange(right, w-cx);
-        int ch = caRange(bottom, h-cy);
-        return new Rectangle(cx,cy,cw,ch);
-    }
-
-    private int caBegin(int start, int range) {
-        return start<0 ? start+range : start;
-    }
-
-    private int caRange(int end, int range) {
-        return end<0 ? -end : range-end;
-    }
-
-    public void draw(Graphics2D canvas) {
-        Rectangle caption = getCaptionArea();
-        boolean lowered;
-        Image icon;
-
-        int by = caption.y+1;
-        int bh = caption.height-3;
-        int bx = caption.width+2;
-        int bw = caption.height-1;
-        int bs = bw+3;
-
-        canvas.setColor( SystemColor.control );
-        for(int i=0, n=buttons.size(); i<n; i++) {
-            bx -= bs;
-            lowered = buttons.get(i).pressed || buttons.get(i).down;
-            icon = buttons.get(i).icon;
-
-            canvas.fillRect(bx, by, bw, bh );
-            if(null!=icon) {
-                int ix = Math.round( bx + (bw-icon.getWidth(null))/2.0f );
-                int iy = Math.round( by + (bh-icon.getHeight(null))/2.0f );
-                if(lowered) {
-                    ix++;
-                    iy++;
-                }
-                canvas.drawImage(icon, ix, iy, null);
-            }
-            canvas.draw3DRect( bx, by, bw, bh, !lowered );
-        }
-    }
-
-    public void add(ButtonEntry value) {
-        buttons.add(value);
-        parent.repaint();
-    }
-
-    public void remove(int index) {
-        buttons.remove(index);
-        parent.repaint();
-    }
-
-}

+ 0 - 216
src/main/java/net/ranides/assira/swing/QFileChooser.java

@@ -1,216 +0,0 @@
-/*
- *  @author Ranides Atterwim <ranides@gmail.com>
- *  @copyright Ranides Atterwim
- *  @license WTFPL
- *  @url http://ranides.net/projects/assira
- */
-
-package net.ranides.assira.swing;
-
-/**
- *
- * @author ranides
- */
-
-import java.awt.HeadlessException;
-import java.io.File;
-import java.io.FileFilter;
-import java.io.FilenameFilter;
-import java.io.IOException;
-import java.net.URI;
-import javax.swing.Icon;
-import javax.swing.JFileChooser;
-import javax.swing.filechooser.FileSystemView;
-import net.ranides.assira.io.PathHelper;
-
-
-public class QFileChooser extends JFileChooser {
-
-/* ************************************************************************** */
-
-    private static final class FileWrapper extends File {
-        
-        private static final long serialVersionUID = 3L;
-
-        public FileWrapper(File from) {
-            this(from.getPath());
-        }
-        public FileWrapper(String path) {
-            super(path);
-        }
-        public FileWrapper(URI uri) {
-            super(uri);
-        }
-
-        public static File wrap(File file) {
-            if (file instanceof FileWrapper) {
-                return file;
-            } else
-            if (file instanceof File) {
-                return new FileWrapper(file);
-            } else {
-                return null;
-            }
-        }
-
-        public static File[] wrap(File[] files) {
-            if (files != null) {
-                for (int i = 0; i < files.length; i++) { files[i] = wrap(files[i]); }
-            }
-            return files;
-        }
-
-        @Override public File getCanonicalFile() throws IOException {
-            return wrap( PathHelper.asNormalized(this));
-        }
-        @Override public String getCanonicalPath() throws IOException {
-            return PathHelper.asNormalized(this).getAbsolutePath();
-        }
-        @Override public File getParentFile() {
-            return wrap(super.getParentFile());
-        }
-        @Override public File getAbsoluteFile() {
-            return wrap(super.getAbsoluteFile());
-        }
-        @Override public File[] listFiles() {
-            return wrap(super.listFiles());
-        }
-        @Override public File[] listFiles(FileFilter filter) {
-            return wrap(super.listFiles(filter));
-        }
-        @Override public File[] listFiles(FilenameFilter filter) {
-            return wrap(super.listFiles(filter));
-        }
-    }
-
-/* ************************************************************************** */
-
-    @SuppressWarnings("PMD.TooManyDifferentMethods")
-    private static final class FileSystemViewWrapper extends FileSystemView {
-        private final FileSystemView delegate;
-
-        public FileSystemViewWrapper() {
-            delegate = FileSystemView.getFileSystemView();
-        }
-
-        public FileSystemViewWrapper(FileSystemView from) {
-            delegate = from;
-        }
-
-        public static FileSystemView wrap(FileSystemView fsv) {
-            if (fsv instanceof FileSystemViewWrapper) {
-                return fsv;
-            } else if (fsv instanceof FileSystemView) {
-                return new FileSystemViewWrapper(fsv);
-            } else {
-                return null;
-            }
-        }
-
-        @Override public boolean isFloppyDrive(File dir) {
-            return delegate.isFloppyDrive(dir);
-        }
-        @Override public boolean isComputerNode(File dir) {
-            return delegate.isComputerNode(dir);
-        }
-        @Override public File createNewFolder(File containingDir) throws IOException {
-            return FileWrapper.wrap(delegate.createNewFolder(containingDir));
-        }
-        @Override public boolean isDrive(File dir) {
-            return delegate.isDrive(dir);
-        }
-        @Override public boolean isFileSystemRoot(File dir) {
-            return delegate.isFileSystemRoot(dir);
-        }
-        @Override public File getHomeDirectory() {
-            return FileWrapper.wrap(delegate.getHomeDirectory());
-        }
-        @Override public File createFileObject(File dir, String filename) {
-            return FileWrapper.wrap(delegate.createFileObject(dir, filename));
-        }
-        @Override public Boolean isTraversable(File file) {
-            return delegate.isTraversable(file);
-        }
-        @Override public boolean isFileSystem(File file) {
-            return delegate.isFileSystem(file);
-        }
-
-        @Override public File getChild(File parent, String fileName) {
-            return FileWrapper.wrap(delegate.getChild(parent, fileName));
-        }
-        @Override public File getParentDirectory(File dir) {
-            return FileWrapper.wrap(delegate.getParentDirectory(dir));
-        }
-        @Override public Icon getSystemIcon(File file) {
-            return delegate.getSystemIcon(file);
-        }
-        @Override public boolean isParent(File folder, File file) {
-            return delegate.isParent(folder, file);
-        }
-        @Override public String getSystemTypeDescription(File file) {
-            return delegate.getSystemTypeDescription(file);
-        }
-        @Override public File getDefaultDirectory() {
-            return FileWrapper.wrap(delegate.getDefaultDirectory());
-        }
-        @Override public String getSystemDisplayName(File file) {
-            return delegate.getSystemDisplayName(file);
-        }
-        @Override public File[] getRoots() {
-            return FileWrapper.wrap(delegate.getRoots());
-        }
-        @Override public boolean isHiddenFile(File file) {
-            return delegate.isHiddenFile(file);
-        }
-        @Override public File[] getFiles(File dir, boolean useFileHiding) {
-            return FileWrapper.wrap(delegate.getFiles(dir, useFileHiding));
-        }
-        @Override public boolean isRoot(File file) {
-            return delegate.isRoot(file);
-        }
-        @Override public File createFileObject(String path) {
-            return FileWrapper.wrap(delegate.createFileObject(path));
-        }
-    }
-
-/* ************************************************************************** */
-
-    public QFileChooser() {
-        setFileSystemView(new FileSystemViewWrapper());
-    }
-
-    public QFileChooser(File currentDirectory) {
-        super( FileWrapper.wrap(currentDirectory) );
-        setFileSystemView(new FileSystemViewWrapper());
-    }
-
-    public QFileChooser(File currentDirectory, FileSystemView fsv){
-        super( FileWrapper.wrap(currentDirectory) );
-        setFileSystemView( FileSystemViewWrapper.wrap(fsv) );
-    }
-
-    public QFileChooser(FileSystemView fsv) {
-        super();
-        setFileSystemView( FileSystemViewWrapper.wrap(fsv) );
-    }
-
-    public QFileChooser(String currentDir) {
-        super( new FileWrapper(currentDir) );
-        setFileSystemView(new FileSystemViewWrapper());
-    }
-
-    public QFileChooser(String currentDir, FileSystemView fsv) {
-        super( new FileWrapper(currentDir) );
-        setFileSystemView( FileSystemViewWrapper.wrap(fsv) );
-    }
-
-    public int showOpenDialog() throws HeadlessException {
-        return super.showOpenDialog(null);
-    }
-    
-    public static void repairView(JFileChooser chooser) {
-        chooser.setFileSystemView( FileSystemViewWrapper.wrap(chooser.getFileSystemView()) );
-    }
-
-}
-

+ 0 - 78
src/main/java/net/ranides/assira/swing/QIcon.java

@@ -1,78 +0,0 @@
-/*
- *  @author Ranides Atterwim <ranides@gmail.com>
- *  @copyright Ranides Atterwim
- *  @license WTFPL
- *  @url http://ranides.net/projects/assira
- */
-
-package net.ranides.assira.swing;
-
-import java.awt.Component;
-import java.awt.Graphics;
-import java.awt.Image;
-import java.io.File;
-import javax.swing.ImageIcon;
-
-/**
- *
- * @author ranides
- */
-public class QIcon extends ImageIcon {
-
-    private static final long serialVersionUID = 1L;
-
-    private static int dw = 16;
-    private static int dh = 16;
-    private int width;
-    private int height;
-
-/* ************************************************************************** */
-
-    public QIcon(/*Component owner, */File file, int width, int height) {
-        super( file.getAbsolutePath() );
-        this.height = height;
-        this.width = width;
-        setImage( getImage().getScaledInstance(width, height, Image.SCALE_AREA_AVERAGING) );
-    }
-
-    public QIcon(/*Component owner,*/ File file, int size) {
-        this(/*owner, */file, size, size);
-    }
-
-    public QIcon(/*Component owner,*/ File file) {
-        this(/*owner, */file, dw, dh);
-    }
-
-/* ************************************************************************** */
-
-    @Override
-    public int getIconHeight() {
-        return height;
-    }
-
-    @Override
-    public int getIconWidth() {
-        return width;
-    }
-
-    public int getIconDefaultHeight() {
-        return dh;
-    }
-
-    public int getIconDefaultWidth() {
-        return dw;
-    }
-
-    public static void setIconDefaultHeight(int height) {
-        dh = height;
-    }
-
-    public static void getIconDefaultWidth(int width) {
-        dw = width;
-    }
-
-    @Override
-    public void paintIcon(Component component, Graphics icon, int x, int y) {
-        icon.drawImage(getImage(), x, y, component);
-    }
-}

+ 0 - 89
src/main/java/net/ranides/assira/swing/QImageFileChooser.java

@@ -1,89 +0,0 @@
-/*
- *  @author Ranides Atterwim <ranides@gmail.com>
- *  @copyright Ranides Atterwim
- *  @license WTFPL
- *  @url http://ranides.net/projects/assira
- */
-
-package net.ranides.assira.swing;
-
-import edu.umd.cs.findbugs.annotations.SuppressWarnings;
-import java.awt.Component;
-import java.io.File;
-import java.util.List;
-import java.util.Locale;
-import javax.swing.JFileChooser;
-import net.ranides.assira.generic.Function;
-import net.ranides.assira.swing.renderers.QImageFileView;
-import net.ranides.assira.text.LexicalCast;
-import net.ranides.assira.text.StringUtils;
-import net.ranides.assira.text.Strings;
-
-/**
- *
- * @author ranides
- */
-public class QImageFileChooser extends JFileChooser {
-
-    private static final long serialVersionUID = 1L;
-
-    private final String[] supported = {
-        ".png",
-        ".gif",
-        ".jpg",
-        ".jpeg"
-    };
-    private final QImageFileView view = new QImageFileView();
-
-/* ************************************************************************** */
-
-    public QImageFileChooser() {
-        setFileView(view);
-
-        setFileFilter(new javax.swing.filechooser.FileFilter() {
-
-            @SuppressWarnings("DM_CONVERT_CASE")
-            @Override
-            public boolean accept(File file) {
-                if( file.isDirectory() ) { return true; }
-                String path = file.getAbsolutePath().toLowerCase();
-                for(String s : supported) { if( path.endsWith(s) ) { return true; } }
-                return false;
-            }
-
-            @Override
-            public String getDescription() {
-                return getFilterName();
-            }
-        });
-    }
-
-    protected String getFilterName() {
-        List<String> exts = LexicalCast.asList(supported, new Function<String,String>(){
-            @Override
-            public String apply(String source) {
-                return source.substring( Math.min(1, source.length()) ).toUpperCase(Locale.ROOT);
-            }
-        });
-        return Strings.sprintf("Supported image formats (%s)",  StringUtils.join(exts,", ") );
-    }
-
-/* ************************************************************************** */
-
-    public boolean save() {
-        return APPROVE_OPTION==showSaveDialog(null);
-    }
-
-    public boolean open() {
-        return APPROVE_OPTION==showOpenDialog(null);
-    }
-
-    public boolean save(Component parent) {
-        return APPROVE_OPTION==showSaveDialog(parent);
-    }
-
-    public boolean open(Component parent) {
-        return APPROVE_OPTION==showOpenDialog(parent);
-    }
-
-}

+ 0 - 344
src/main/java/net/ranides/assira/swing/QPanel.java

@@ -1,344 +0,0 @@
-/*
- *  @author Ranides Atterwim <ranides@gmail.com>
- *  @copyright Ranides Atterwim
- *  @license WTFPL
- *  @url http://ranides.net/projects/assira
- */
-
-package net.ranides.assira.swing;
-
-import java.awt.*;
-import java.awt.event.MouseAdapter;
-import java.awt.event.MouseEvent;
-import javax.swing.BorderFactory;
-import javax.swing.JComponent;
-import javax.swing.JPanel;
-import javax.swing.border.Border;
-import net.ranides.assira.swing.QButtonManager.ButtonEntry;
-import net.ranides.assira.time.AutoTimerFrame;
-import net.ranides.assira.time.AutoTimerTask;
-import net.ranides.assira.time.TimeUtils;
-
-/**
- *
- * @author ranides
- */
-@SuppressWarnings({"PMD.TooManyDifferentMethods","PMD.TooManyFields"})
-public class QPanel extends JPanel {
-
-    private static final long serialVersionUID = 1L;
-
-    private transient AutoTimerTask<QPanel> animation;
-    private final QButtonManager buttons;
-
-    private boolean rolled          = false;
-    private int expanded            = 0;
-
-    protected int titleSize         = 20;
-    protected int animFrames        = 10;
-    protected int animInterval      = 25;
-    protected int animJump          = 150;
-    protected Border outsideBorder  = BorderFactory.createEmptyBorder();
-    protected Border insideBorder   = BorderFactory.createEmptyBorder();
-    protected int margin            = 2;
-    protected Color titleBack       = new Color(64,96,160);
-    protected MouseHandler handler  = new MouseHandler();
-    protected boolean cmove         = false;
-    protected boolean croll         = true;
-    protected int cclicks           = 2;
-
-
-/* ************************************************************************** */
-
-    class AnimationUp extends AutoTimerFrame<QPanel> {
-
-        private final int target;
-
-        public AnimationUp() {
-            this.target = getRolledSize();
-        }
-
-        @Override
-        public void run(QPanel panel, int now, int max) {
-            float i = expanded - ((now+1.0f)/max)*(expanded-target);
-            animStep( (int)i, true);
-        }
-
-        @Override
-        public void started(QPanel panel) {
-            rolled = true;
-            setMinimumSize(null);
-            setMaximumSize(null);
-        }
-
-        @Override
-        public void finished(QPanel panel) {
-            animStep(target, true);
-            panel.repaint();
-            animation = null;
-
-            TimeUtils.runAfter(animJump, new Runnable() {
-                @Override
-                public void run() {
-                    Container parent = getParent();
-                    if(parent instanceof JComponent) { ((JComponent)parent).revalidate(); }
-                    parent.doLayout();
-                    parent.repaint();
-                }
-            });
-
-        }
-
-        @Override
-        public void canceled(QPanel panel) {
-            animation = null;
-        }
-    }
-
-
-    class AnimationDn extends AutoTimerFrame<QPanel> {
-
-        private final int target;
-
-        public AnimationDn() {
-            this.target = getRolledSize();
-        }
-
-        @Override
-        public void run(QPanel panel, int now, int max) {
-            float i = target + ((now+1.0f)/max)*(expanded-target);
-            animStep( (int)i, false);
-        }
-
-        @Override
-        public void started(QPanel panel) {
-            panel.rolled = false;
-            panel.setMinimumSize(null);
-            panel.setMaximumSize(null);
-        }
-
-        @Override
-        public void finished(QPanel panel) {
-            animStep(expanded, false);
-
-            TimeUtils.runAfter(animJump, new Runnable() {
-                @Override
-                public void run() {
-                    Container parent = getParent();
-                    animation = null;
-
-                    if(parent instanceof JComponent) { ((JComponent)parent).revalidate(); }
-                    parent.doLayout();
-                    parent.repaint();
-                }
-            });
-        }
-
-        @Override
-        public void canceled(QPanel panel) {
-            animation = null;
-        }
-    }
-
-/* ************************************************************************** */
-
-    protected class MouseHandler extends MouseAdapter {
-
-        private Point drag = null;
-
-        @Override
-        public void mouseDragged(MouseEvent event) {
-            if( null == drag ) { return; }
-            getTopLevelAncestor().setLocation(
-                event.getXOnScreen() + drag.x,
-                event.getYOnScreen() + drag.y
-                );
-        }
-
-        @Override
-        public void mouseClicked(MouseEvent event) {
-            if(buttons.hitTest(event) && croll && event.getClickCount()>=cclicks) { toggleRolled(); }
-        }
-
-        @Override
-        public void mouseReleased(MouseEvent event) {
-            buttons.hitRelease(event);
-            drag = null;
-        }
-
-        @Override
-        public void mousePressed(MouseEvent event) {
-            if( !buttons.hitTest(event) ) { return; }
-            if(cmove) {
-                Point point = getTopLevelAncestor().getLocation();
-                drag = new Point(point.x - event.getXOnScreen(), point.y - event.getYOnScreen() );
-            }
-        }
-    }
-
-
-/* ************************************************************************** */
-
-    private void animStep(int height, boolean lock) {
-        Dimension size = new Dimension(getWidth(), height );
-        setSize(size);
-        setPreferredSize(size);
-        setMinimumSize(size);
-        if(lock) { setMaximumSize(size); }
-    }
-
-    private int getRolledSize() {
-        Insets insets = getBorder().getBorderInsets(this);
-        return titleSize + insets.bottom + insets.top;
-    }
-
-/* ************************************************************************** */
-
-    public QPanel() {
-        this.setBackground(new java.awt.Color(192, 224, 255));
-        this.addMouseMotionListener(handler);
-        this.addMouseListener(handler);
-        buttons = new QButtonManager(this);
-    }
-
-    @Override
-    public void paint(Graphics jcanvas) {
-        super.paint(jcanvas);
-        Graphics2D canvas = (Graphics2D)jcanvas;
-        Insets insets = getBorder().getBorderInsets(this);
-        int x = insets.left;
-        int y = insets.top;
-        int w = getWidth()-insets.left-insets.right;
-        int h = getHeight()-insets.top-insets.bottom - titleSize;
-
-        canvas.setColor( titleBack );
-        canvas.fillRect(x, y, w, titleSize);
-        if( null != insideBorder && (!rolled || null!=animation) ) {
-            insideBorder.paintBorder(this, jcanvas, x, y+titleSize, w, h);
-        }
-        buttons.doLayout(insets.top, insets.right, -titleSize, insets.left);
-        buttons.draw(canvas);
-    }
-
-/* ************************************************************************** */
-
-    public void setRolled(boolean rolled) {
-        if(rolled == this.rolled) { return; }
-
-        if(null == animation) {
-            if(rolled) { expanded = getHeight(); }
-        } else {
-            animation.cancel();
-        }
-
-        animation = TimeUtils.runRepeat(animFrames, animInterval, this, rolled ? new AnimationUp() : new AnimationDn());
-    }
-
-    public boolean getRolled() {
-        return rolled;
-    }
-
-    public boolean toggleRolled() {
-        setRolled(!rolled);
-        return rolled;
-    }
-
-    @Override
-    public Border getBorder() {
-        return outsideBorder;
-    }
-
-    @Override
-    public void setBorder(Border border) {
-        outsideBorder = border;
-        super.setBorder(BorderFactory.createCompoundBorder(
-            outsideBorder,
-            BorderFactory.createEmptyBorder(titleSize+margin, margin, margin, margin)
-            ));
-    }
-
-    public Border getInsideBorder() {
-        return insideBorder;
-    }
-
-    public void setInsideBorder(Border insideBorder) {
-        this.insideBorder = insideBorder;
-    }
-
-    public int getMarginSize() {
-        return margin;
-    }
-
-    public void setMarginSize(int margin) {
-        this.margin = margin;
-        setBorder(getBorder());
-    }
-
-
-
-    public int getAnimFrames() {
-        return animFrames;
-    }
-
-    public void setAnimFrames(int animFrames) {
-        this.animFrames = animFrames;
-    }
-
-    public int getAnimFPS() {
-        return Math.round(1000.0f / animInterval);
-    }
-
-    public void setAnimFPS(int animInterval) {
-        this.animInterval =  Math.round(1000.0f / animInterval);
-    }
-
-    public int getAnimJump() {
-        return animJump;
-    }
-
-    public void setAnimJump(int animJump) {
-        this.animJump = animJump;
-    }
-
-    public Color getTitleBackground() {
-        return titleBack;
-    }
-
-    public void setTitleBackground(Color titleBack) {
-        this.titleBack = titleBack;
-        repaint();
-    }
-
-    public boolean isCaptionDrag() {
-        return cmove;
-    }
-
-    public void setCaptionDrag(boolean cmove) {
-        this.cmove = cmove;
-    }
-
-    public boolean isCaptionRoll() {
-        return croll;
-    }
-
-    public void setCaptionRoll(boolean croll) {
-        this.croll = croll;
-    }
-
-    public int getCaptionClicks() {
-        return cclicks;
-    }
-
-    public void setCaptionClicks(int cclicks) {
-        this.cclicks = cclicks;
-    }
-
-    public void addCaptionButton(ButtonEntry value) {
-        buttons.add(value);
-    }
-
-    public void removeCaptionButton(int index) {
-        buttons.remove(index);
-    }
-
-};

+ 0 - 86
src/main/java/net/ranides/assira/swing/QSelect.java

@@ -1,86 +0,0 @@
-/*
- *  @author Ranides Atterwim <ranides@gmail.com>
- *  @copyright Ranides Atterwim
- *  @license WTFPL
- *  @url http://ranides.net/projects/assira
- */
-
-package net.ranides.assira.swing;
-
-import net.ranides.assira.swing.renderers.QListItem;
-
-/**
- *
- * @author ranides
- */
-public class QSelect<T> extends javax.swing.JComboBox {
-
-    private static final long serialVersionUID = 2L;
-
-    private int columns = 6;
-    private int rows = 3;
-    private int cellWidth = 25;
-    private int cellHeight = 21;
-    private boolean gridAutoSize = false;
-
-    private final QSelectPopup.UIAdapter adapter;
-
-
-    @SuppressWarnings("unchecked") // JDK 1.6 SWING compatibility
-    public QSelect() {
-        adapter = new QSelectPopup.UIAdapter(this);
-        setEditable(true);
-        setUI(adapter);
-        setRenderer( new QListItem() ); // JDK 1.6 SWING compatibility
-        setEditor( new QListItem() );
-    }
-
-    public int getGridColumns() {
-        if(!gridAutoSize) { return columns; }
-        return (getPreferredSize().width- getPreferredSize().height ) / getCellWidth();
-    }
-
-    public int getGridRows() {
-        if(!gridAutoSize) { return rows; }
-        return getGridColumns();
-    }
-
-    public void setGridColumns(int value) {
-        columns = value;
-        adapter.update();
-    }
-
-    public void setGridRows(int value) {
-        rows = value;
-        adapter.update();
-    }
-
-    public boolean isGridAutoSize() {
-        return gridAutoSize;
-    }
-
-    public void setGridAutoSize(boolean gridAutoSize) {
-        this.gridAutoSize = gridAutoSize;
-    }
-
-
-    public int getCellWidth() {
-        return cellWidth;
-    }
-
-    public int getCellHeight() {
-        return cellHeight;
-    }
-
-    public void setCellWidth(int value) {
-        cellWidth = value;
-        adapter.update();
-    }
-
-    public void setCellHeight(int value) {
-        cellHeight = value;
-        adapter.update();
-    }
-
-
-}

+ 0 - 242
src/main/java/net/ranides/assira/swing/QSelectPopup.java

@@ -1,242 +0,0 @@
-/*
- *  @author Ranides Atterwim <ranides@gmail.com>
- *  @copyright Ranides Atterwim
- *  @license WTFPL
- *  @url http://ranides.net/projects/assira
- */
-
-package net.ranides.assira.swing;
-
-import java.awt.*;
-import java.awt.event.*;
-import javax.swing.*;
-import javax.swing.plaf.basic.BasicComboBoxUI;
-import javax.swing.plaf.basic.ComboPopup;
-import javax.swing.table.AbstractTableModel;
-import javax.swing.table.TableCellRenderer;
-import javax.swing.table.TableColumnModel;
-
-/**
- *
- * @author ranides
- */
-@SuppressWarnings("PMD.TooManyDifferentMethods")
-public class QSelectPopup extends JDialog implements ComboPopup {
-
-
-    static public class UIAdapter extends BasicComboBoxUI {
-        private final QSelectPopup selectPopup;
-
-        public UIAdapter(JComboBox owner) {
-            selectPopup = new QSelectPopup(owner);
-        }
-        @Override
-        protected ComboPopup createPopup() {
-            return selectPopup;
-        }
-
-        public void update() {
-           selectPopup.updateGrid();
-        }
-    }
-
-/* ************************************************************************** */
-
-    static class RendererAdapter implements TableCellRenderer {
-
-        private final JComboBox owner;
-
-        public RendererAdapter(JComboBox owner) {
-            this.owner = owner;
-        }
-
-        @Override
-        @SuppressWarnings("unchecked")
-        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
-            return owner.getRenderer().getListCellRendererComponent(null, value, row, isSelected, hasFocus);
-        }
-
-    }
-
-/* ************************************************************************** */
-
-    static class ModelAdapter extends AbstractTableModel {
-
-        private final JComboBox owner;
-        private int columns = 8;
-
-        public ModelAdapter(JComboBox owner) {
-            this.owner = owner;
-        }
-
-        @Override
-        public int getRowCount() {
-            ComboBoxModel model = owner.getModel();
-            return (int)Math.ceil( (double)model.getSize() / getColumnCount() );
-        }
-
-        @Override
-        public int getColumnCount() {
-            return columns;
-        }
-
-        public void setColumns(int value) {
-            columns = value;
-        }
-
-        @Override
-        public Object getValueAt(int y, int x) {
-            ComboBoxModel model = owner.getModel();
-            int n = x + y*getColumnCount();
-            return n < model.getSize() ? model.getElementAt(n) : null;
-        }
-
-    }
-
-/* ************************************************************************** */
-
-    private final JComboBox owner;
-    private final ModelAdapter tableModel;
-
-    private final JScrollPane uiScrolls;
-    private final JTable uiTable;
-    private static final JList EMPTY_LIST = new JList();
-
-    public int getGridColumns() {
-        return (owner instanceof QSelect) ? ((QSelect)owner).getGridColumns() : 5;
-    }
-
-    public int getGridRows() {
-        return (owner instanceof QSelect) ? ((QSelect)owner).getGridRows() : 5;
-    }
-
-    public int getCellHeight() {
-        return (owner instanceof QSelect) ? ((QSelect)owner).getCellHeight() : 18;
-    }
-
-    public int getCellWidth() {
-        return (owner instanceof QSelect) ? ((QSelect)owner).getCellWidth() : 18;
-    }
-
-/* ************************************************************************** */
-
-    @SuppressWarnings("PMD.ConstructorCallsOverridableMethod")
-    public QSelectPopup(JComboBox _owner) {
-        this.owner = _owner;
-
-        tableModel  = new ModelAdapter(owner);
-        uiTable     = new JTable();
-        uiScrolls   = new JScrollPane(uiTable);
-
-        uiScrolls.setBorder( BorderFactory.createEmptyBorder(1,1,1,1) );
-        uiScrolls.setHorizontalScrollBarPolicy( JScrollPane.HORIZONTAL_SCROLLBAR_NEVER );
-        uiScrolls.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_ALWAYS );
-
-        uiTable.setCellSelectionEnabled(true);
-        uiTable.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );
-        uiTable.setTableHeader(null);
-        uiTable.setAutoResizeMode( JTable.AUTO_RESIZE_OFF );
-
-        uiTable.addMouseListener(new MouseAdapter() {
-            @Override
-            public void mouseReleased(MouseEvent event) {
-                int x = uiTable.getSelectedColumn();
-                int y = uiTable.getSelectedRow();
-                owner.getEditor().setItem(tableModel.getValueAt(y, x));
-                setVisible(false);
-            }
-        });
-
-        JPanel content = (JPanel)getContentPane();
-        content.setLayout(new BorderLayout());
-        content.add(uiScrolls, BorderLayout.CENTER );
-        content.setBorder(BorderFactory.createLineBorder(Color.black));
-
-
-        this.setVisible(false);
-        this.setUndecorated(true);
-
-        this.addWindowFocusListener(new WindowAdapter() {
-            @Override public void windowLostFocus(WindowEvent event) {
-                setVisible(false);
-            }
-        });
-
-        updateGrid();
-
-    }
-
-    public void updateGrid() {
-        int gw = getGridColumns();
-        int gh = getGridRows();
-        int cw = getCellWidth();
-        int ch = getCellHeight();
-        int delta = uiScrolls.getVerticalScrollBar().getPreferredSize().width;
-
-        tableModel.setColumns(gw);
-
-        uiTable.setModel(tableModel);
-        uiTable.setRowHeight( ch );
-
-        TableColumnModel model = uiTable.getColumnModel();
-        for(int i=0, n=model.getColumnCount(); i<n; i++) {
-            model.getColumn(i).setCellRenderer( new RendererAdapter(owner) );
-            model.getColumn(i).setPreferredWidth( this.getCellWidth() );
-        }
-
-        setSize(4 + delta +  gw*cw, 4 + gh*ch );
-        this.validate();
-    }
-
-    @Override
-    public void setVisible(boolean show) {
-        if(show) {
-            this.setLocation( getPopupLocation() );
-        }
-        super.setVisible(show);
-    }
-
-    public Point getPopupLocation() {
-        Point     point     = owner.getLocationOnScreen();
-        Rectangle rect      = owner.getBounds();
-        Dimension screen    = Toolkit.getDefaultToolkit().getScreenSize();
-        Dimension window    = this.getSize();
-
-        boolean ox = (point.x + window.width) > screen.width;
-        boolean oy = (point.y + rect.height + window.height) > screen.height;
-
-        int x = ox ? (point.x+rect.width-window.width) : point.x;
-        int y = oy ? (point.y-window.height) :(point.y+rect.height);
-
-        return new Point( Math.max(0,x), Math.max(0,y) );
-    }
-
-/* ************************************************************************** */
-
-    public void uninstallingUI() {
-        /* do nothing */
-    }
-
-    public MouseMotionListener getMouseMotionListener() {
-        return null;
-    }
-
-    public KeyListener getKeyListener() {
-        return null;
-    }
-
-    public MouseListener getMouseListener() {
-        return new MouseAdapter() {
-            @Override
-            public void mousePressed(MouseEvent event) {
-                setVisible( !isVisible());
-            };
-        };
-    }
-
-    public JList getList() {
-        return EMPTY_LIST;
-    }
-
-
-}

+ 0 - 50
src/main/java/net/ranides/assira/swing/QWindow.java

@@ -1,50 +0,0 @@
-/*
- *  @author Ranides Atterwim <ranides@gmail.com>
- *  @copyright Ranides Atterwim
- *  @license WTFPL
- *  @url http://ranides.net/projects/assira
- */
-
-package net.ranides.assira.swing;
-
-import java.awt.Component;
-import java.awt.Container;
-import java.awt.Dimension;
-import java.awt.Toolkit;
-import javax.swing.JDesktopPane;
-import javax.swing.JInternalFrame;
-
-/**
- *
- * @author ranides
- */
-public final class QWindow {
-
-    private QWindow() { }
-
-    public static void center(Component window, Dimension container) {
-        int x = (container.width- window.getWidth() )/2;
-        int y = (container.height-window.getHeight() )/2;
-        window.setLocation(x, y);
-    }
-
-    public static void center(Component window) {
-        if( window.getParent() instanceof Container ) {
-            center(window, window.getParent().getSize() );
-        } else {
-            center(window, Toolkit.getDefaultToolkit().getScreenSize() );
-        }
-    }
-
-    public static void center(JInternalFrame window) {
-        if( window.getDesktopPane() instanceof JDesktopPane ) {
-            center(window, window.getDesktopPane().getSize() );
-        }  else
-        if( window.getParent() instanceof Container ) {
-            center(window, window.getParent().getSize() );
-        } else {
-            center(window, Toolkit.getDefaultToolkit().getScreenSize() );
-        }
-    }
-
-}

+ 0 - 75
src/main/java/net/ranides/assira/swing/UIManager.java

@@ -1,75 +0,0 @@
-/*
- *  @author Ranides Atterwim <ranides@gmail.com>
- *  @copyright Ranides Atterwim
- *  @license WTFPL
- *  @url http://ranides.net/projects/assira
- */
-
-package net.ranides.assira.swing;
-
-import edu.umd.cs.findbugs.annotations.SuppressWarnings;
-import javax.swing.LookAndFeel;
-import javax.swing.UnsupportedLookAndFeelException;
-import net.ranides.assira.trace.AdvLogger;
-import net.ranides.assira.trace.LoggerUtils;
-
-/**
- *
- * @author ranides
- */
-@SuppressWarnings({
-    "NM_SAME_SIMPLE_NAME_AS_SUPERCLASS"
-})
-public final class UIManager extends javax.swing.UIManager {
-
-    private static final AdvLogger LOGGER = LoggerUtils.getLogger();
-
-    private UIManager() {
-        super();
-    }
-
-    @SuppressWarnings({"DLS_DEAD_LOCAL_STORE", "REC_CATCH_EXCEPTION"})
-    public static boolean setNativeLF() {
-        try {
-            setLookAndFeel(getSystemLookAndFeelClassName());
-            return true;
-        } catch(Exception _) {
-            return false;
-        }
-    }
-
-    public static boolean setLF(LookAndFeel laf) {
-        try {
-            UIManager.setLookAndFeel(laf);
-            return true;
-        } catch (UnsupportedLookAndFeelException ex) {
-            LOGGER.fwarn("SWING L&F not supported", ex);
-            return false;
-        }
-    }
-
-    public static boolean setLF(String lfname) {
-        
-        
-        
-        try {
-            for( LookAndFeelInfo lfi : javax.swing.UIManager.getInstalledLookAndFeels() ) {
-                if(lfi.getName().equalsIgnoreCase(lfname)) {
-                    javax.swing.UIManager.setLookAndFeel(lfi.getClassName());
-                    return true;
-                }
-            }
-            return false;
-        } catch (UnsupportedLookAndFeelException ex) {
-            LOGGER.warn("SWING L&F not installed", ex);
-        } catch (ClassNotFoundException ex) {
-            LOGGER.warn("SWING L&F not installed", ex);
-        } catch (IllegalAccessException ex) {
-            LOGGER.warn("SWING L&F internal error", ex);
-        } catch (InstantiationException ex) {
-            LOGGER.warn("SWING L&F internal error", ex);
-        } 
-        return false;
-    }
-
-}

+ 0 - 79
src/main/java/net/ranides/assira/swing/listeners/QListSelectionListener.java

@@ -1,79 +0,0 @@
-/*
- *  @author Ranides Atterwim <ranides@gmail.com>
- *  @copyright Ranides Atterwim
- *  @license WTFPL
- *  @url http://ranides.net/projects/assira
- */
-
-package net.ranides.assira.swing.listeners;
-
-import javax.swing.JList;
-import javax.swing.ListModel;
-import javax.swing.event.ListSelectionEvent;
-import javax.swing.event.ListSelectionListener;
-import org.apache.log4j.Logger;
-
-/**
- *
- * @author ranides
- */
-public abstract class QListSelectionListener<Element> implements ListSelectionListener {
-
-    private final JList owner;
-
-    protected JList getOwner() {
-        return owner;
-    }
-
-    protected ListModel getModel() {
-        return owner.getModel();
-    }
-
-    @SuppressWarnings("unchecked")
-    protected Element getElement(int index) {
-        return (Element)getModel().getElementAt(index);
-        }
-
-/* ************************************************************************** */
-
-    public QListSelectionListener(JList list) {
-        this.owner = list;
-    }
-
-    @Override
-    public void valueChanged(ListSelectionEvent event) {
-        if( event.getValueIsAdjusting() ) { return; }
-        int index = getOwner().getAnchorSelectionIndex();
-        try {
-            if(-1 == index) {
-                if( !onClear(event) ) { return; }
-            } else {
-                if( !onSelect(event, index, getElement(index) ) ) { return; }
-            }
-        } catch(Exception cause) {
-            if( !onError(cause) ) { return; }
-        }
-
-        try {
-            onChange(event);
-        } catch(Exception cause) {
-            if( !onError(cause) ) { return; }
-        }
-    }
-
-/* ************************************************************************** */
-
-    public abstract boolean onSelect(ListSelectionEvent event, int index, Element value) throws Exception;
-
-    public abstract boolean onClear(ListSelectionEvent event) throws Exception;
-
-    public boolean onChange(ListSelectionEvent event) throws Exception {
-        return true;
-    }
-
-    public boolean onError(Throwable cause) {
-        Logger.getLogger(this.getClass()).error(null, cause);
-        return true;
-    }
-
-}

+ 0 - 47
src/main/java/net/ranides/assira/swing/renderers/QCellDecorator.java

@@ -1,47 +0,0 @@
-/*
- * @author Ranides Atterwim <ranides@gmail.com>
- * @copyright Ranides Atterwim
- * @license WTFPL
- * @url http://ranides.net/projects/twshelper
- */
-package net.ranides.assira.swing.renderers;
-
-import java.awt.Component;
-import javax.swing.JTable;
-import javax.swing.table.TableCellRenderer;
-import javax.swing.table.TableColumn;
-import net.ranides.assira.generic.ValueUtils;
-
-/**
- *
- * @author ranides
- */
-public abstract class QCellDecorator implements TableCellRenderer {
-
-    private TableCellRenderer prev;
-
-    public QCellDecorator() {
-        // do nothing
-    }
-    
-    public abstract Component decorate(Component component, JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column);
-
-    public final void connect(JTable table, TableColumn column) {
-        TableCellRenderer old = ValueUtils.or(
-            column.getHeaderRenderer(), table.getTableHeader().getDefaultRenderer()
-        );
-        while( old.getClass().equals( getClass() ) ) {
-            old = ((QCellDecorator)old).prev;
-        }
-        prev = old;
-        column.setHeaderRenderer(this);    
-    }
-
-    @Override
-    public final Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
-        assert prev != null;
-        Component result = prev.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
-        return decorate(result, table, value, isSelected, hasFocus, row, column);
-    }
-    
-}

+ 0 - 65
src/main/java/net/ranides/assira/swing/renderers/QImageFileView.java

@@ -1,65 +0,0 @@
-/*
- *  @author Ranides Atterwim <ranides@gmail.com>
- *  @copyright Ranides Atterwim
- *  @license WTFPL
- *  @url http://ranides.net/projects/assira
- */
-
-package net.ranides.assira.swing.renderers;
-
-import java.io.File;
-import java.io.Serializable;
-import java.util.HashMap;
-import java.util.Locale;
-import javax.swing.Icon;
-import javax.swing.filechooser.FileView;
-import net.ranides.assira.swing.QIcon;
-
-/**
- *
- * @author ranides
- */
-public class QImageFileView extends FileView implements Serializable {
-    
-    private static final long serialVersionUID = 3L;
-
-    private final HashMap<String, Icon> cache = new HashMap<String, Icon>();
-    private final String[] images = { ".gif", ".jpg", ".png", ".bmp" };
-
-    protected boolean isImage(File file) {
-        if( file.isDirectory() ) { return false; }
-        if( file.length() > 256*1024) { return false; }
-
-        String path = file.getAbsolutePath().toLowerCase(Locale.ROOT);
-        for(String s : images) { if(path.endsWith(s)) { return true; } }
-        return false;
-    }
-
-    public QImageFileView() {
-        /* do nothing */
-    }
-
-/* ************************************************************************** */
-
-    @Override
-    public Icon getIcon(File file) {
-        if(file.isDirectory() || !isImage(file) ) { 
-            return super.getIcon(file); 
-        }
-        String key = file.getAbsolutePath();
-        Icon value = cache.get(key);
-        if( null == value ) {
-            try {
-                value = new QIcon(file);
-            }
-            catch(Exception cause) {
-                value = super.getIcon(file);
-            }
-        }
-        if( null != value) {
-            cache.put(key, value);
-        }
-        return value;
-    }
-
-}

+ 0 - 203
src/main/java/net/ranides/assira/swing/renderers/QLineRenderer.java

@@ -1,203 +0,0 @@
-/*
- *  @author Ranides Atterwim <ranides@gmail.com>
- *  @copyright Ranides Atterwim
- *  @license WTFPL
- *  @url http://ranides.net/projects/
- */
-package net.ranides.assira.swing.renderers;
-
-import java.awt.*;
-import java.util.Set;
-import javax.swing.JComponent;
-import javax.swing.JList;
-import javax.swing.JTable;
-import javax.swing.ListCellRenderer;
-import javax.swing.table.TableCellRenderer;
-import net.ranides.assira.awt.ColorUtils;
-import net.ranides.assira.collection.SetUtils;
-import net.ranides.assira.math.Bitwise;
-import net.ranides.assira.text.format.AnsiAttr;
-import net.ranides.assira.text.format.AnsiCharSequence;
-import net.ranides.assira.text.format.AnsiColorScheme;
-import net.ranides.assira.text.format.AnsiString;
-
-/**
- * Renderer oferujący proste formatowanie regionów tekstu (kolor,tło) znacznie
- * szybciej niż JLabel formatowany HTMLem
- * @author ranides
- */
-public class QLineRenderer extends JComponent implements TableCellRenderer, ListCellRenderer {
-
-    private boolean selected;
-    private AnsiString text;
-    private int extended;
-    private final AnsiColorScheme scheme = AnsiColorScheme.make(null, Color.BLACK);
-    
-    private final static Color SHADOW = new Color(0x40000000, true);
-    private final static Color LIGHT = new Color(0x40FFFFFF, true);
-
-    public QLineRenderer() {
-        setOpaque(true);
-        setPreferredSize( new Dimension(0, 24) );
-        extended = 0;
-    }
-    
-    public QLineRenderer(Set<Integer> options) {
-        setOpaque(true);
-        setPreferredSize( new Dimension(0, 24) );
-        extended = SetUtils.asInt(options);
-    }
-
-    @Override
-    public void paint(Graphics jcanvas) {
-        Graphics2D canvas = (Graphics2D)jcanvas;
-        FontMetrics metrics = canvas.getFontMetrics(getFont());
-
-        canvas.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
-        canvas.setFont(getFont());
-
-        int h = getHeight();
-        int y = (h + metrics.getHeight())/2 - metrics.getDescent();
-        int x = 0;
-        for(AnsiCharSequence item : text.split(AnsiAttr.SPLIT_ALL) ) {
-            if(null != item.getFonts()) {
-                canvas.setFont( item.getComputedFont() );
-                metrics = canvas.getFontMetrics();
-            }
-            
-            int dx = metrics.stringWidth( item.toString() );
-            if(null != item.getComputedBack()) {
-                canvas.setColor(item.getComputedBack());
-                canvas.fillRect(x, 0, dx, h);
-            }
-            
-            canvas.setColor( item.getComputedFore() );
-            canvas.drawString( item.toString(), x, y);
-            
-            if( attrEnabled(item, AnsiAttr.SYMBOL) ) {
-                canvas.setPaint( makeGradient(item.getComputedFore(), h) );
-                canvas.fillRect(x, 0, dx, this.getHeight());
-            }
-            if( attrEnabled(item, AnsiAttr.UNDERLINE) ) {
-                canvas.setColor( item.getComputedFore() );
-                canvas.drawLine(x, h-1, x+dx, h-1);
-            }
-            if( attrEnabled(item, AnsiAttr.FRESH)  ) {
-                canvas.setColor(LIGHT);
-                canvas.fillRect(x, 0, x+dx, this.getHeight());
-            }
-            
-            x += dx;            
-        }
-        if( isSelected() ) {
-            canvas.setColor(SHADOW);
-            canvas.fillRect(0, 0, this.getWidth(), this.getHeight());
-        }
-    }
-    
-    private boolean attrEnabled(AnsiCharSequence sequence, int attr) {
-        return Bitwise.has(extended, attr) && Bitwise.has(sequence.getFlags(), attr);
-    }
-    
-    @Override
-    public Component getTableCellRendererComponent(JTable table, Object object, boolean isSelected, boolean hasFocus, int row, int column) {
-        AnsiString value;
-        if(object instanceof AnsiString) {
-            value = (AnsiString)object;
-        } else {
-            value = new AnsiString(scheme, String.valueOf(object));
-        }
-        this.setText(value);
-        this.setSelected(isSelected);
-        this.setBackground(table.getBackground());
-        this.setFont(table.getFont());
-        return this;
-    }
-    
-    @Override
-    public Component getListCellRendererComponent(JList list, Object object, int index, boolean isSelected, boolean cellHasFocus) {
-        AnsiString value;
-        if(object instanceof AnsiString) {
-            value = (AnsiString)object;
-        } else {
-            value = new AnsiString(scheme, String.valueOf(object));
-        }
-        this.setText(value);
-        this.setSelected(isSelected);
-        this.setBackground(list.getBackground());
-        this.setFont(list.getFont());
-        return this;
-    }
-    
-    private static Paint makeGradient(Color color, int h) {
-        return new GradientPaint(
-            0.0f, 0.0f,   ColorUtils.alpha(color, 32),
-            0.0f, h/2.0f, ColorUtils.alpha(color, 144),
-            true);
-    };
-
-    // <editor-fold defaultstate="collapsed" desc=" ( properties ) ">
-
-    public final boolean isSelected() {
-        return selected;
-    }
-
-    public final void setSelected(boolean selected) {
-        this.selected = selected;
-    }
-    
-    public final AnsiString getText() {
-        return text;
-    }
-
-    public final void setText(AnsiString text) {
-        this.text = text;
-    }
-    
-    public final void setTextColor(Color color) {
-        this.scheme.setForeColor(color);
-    }
-    
-    public final Color getTextColor() {
-        return this.scheme.getBackColor();
-    }
-    
-    public boolean isExtended(int attribute) {
-        return Bitwise.has(extended, attribute);
-    }
-
-    public void setExtended(int attribute, boolean mode) {
-        if(mode) {
-            extended |= attribute;
-        } else {
-            extended &= ~attribute;
-        }
-    }
-
-    // </editor-fold>
-
-    //<editor-fold defaultstate="collapsed" desc=" ( performance ) ">
-    
-    @Override
-    public void validate() {
-        // do nothing
-    }
-
-    @Override
-    public void revalidate() {
-        // do nothing
-    }
-
-    @Override
-    protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
-        // do nothing
-    }
-
-    @Override
-    public void firePropertyChange(String propertyName, boolean oldValue, boolean newValue) {
-        // do nothing
-    }
-
-    //</editor-fold>
-    
-}

+ 0 - 195
src/main/java/net/ranides/assira/swing/renderers/QListItem.java

@@ -1,195 +0,0 @@
-/*
- *  @author Ranides Atterwim <ranides@gmail.com>
- *  @copyright Ranides Atterwim
- *  @license WTFPL
- *  @url http://ranides.net/projects/assira
- */
-
-package net.ranides.assira.swing.renderers;
-
-import java.awt.*;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.geom.Rectangle2D;
-import javax.swing.*;
-import net.ranides.assira.awt.ColorUtils;
-
-/**
- *
- * @author ranides
- */
-public class QListItem extends QListItemEditor implements ListCellRenderer, ComboBoxEditor {
-
-    private static final long serialVersionUID = 1L;
-
-    private Object value;
-
-    private boolean selected = false;
-    private Color clrForeNormal = SystemColor.textText;
-    private Color clrBackNormal = SystemColor.text;
-    private Color clrForeSelect = SystemColor.textHighlightText;
-    private Color clrBackSelect = SystemColor.textHighlight;
-    private Color clrStroke     = ColorUtils.invert(SystemColor.textHighlight);
-    private Stroke stroke       = new BasicStroke(
-        1.0f,
-        BasicStroke.CAP_BUTT,
-        BasicStroke.JOIN_MITER,
-        1.0f,
-        new float[]{1.0f},
-        1.0f
-    );
-
-/* ************************************************************************** */
-
-    @Override
-    public void paint(Graphics jcanvas) {
-        Graphics2D canvas = (Graphics2D)jcanvas;
-        paintBefore(canvas);
-        super.paint(jcanvas);
-        paintAfter(canvas);
-    }
-
-    @Override
-    protected void paintAfter(Graphics2D canvas) {
-        if( isSelected() ) {
-            canvas.setColor( clrStroke );
-            canvas.setStroke( stroke );
-            canvas.draw( getBorderRect() );
-        }
-    }
-
-    @Override
-    protected void paintBefore(Graphics2D canvas) {
-        this.setBackground( isSelected() ? clrBackSelect : clrBackNormal );
-        this.setForeground( isSelected() ? clrForeSelect : clrForeNormal );
-    }
-
-/* ************************************************************************** */
-
-    @SuppressWarnings("PMD.ConstructorCallsOverridableMethod")
-    public QListItem() {
-        this.setPreferredSize( new Dimension(0, 22) );
-        this.setOpaque(true);
-        this.setBorder( BorderFactory.createEmptyBorder(0, 4, 0, 0));
-    }
-
-    //<editor-fold defaultstate="collapsed" desc=" ( properties ) ">
-    
-    @Override
-    protected Stroke getDefaultBorder() {
-        return stroke;
-    }
-
-    @Override
-    protected Rectangle2D getBorderRect() {
-        Rectangle2D rect = new Rectangle2D.Float();
-        rect.setRect(0,0, getWidth()-1, getHeight()-1 );
-        return rect;
-    }
-
-    @Override
-    public void setSelected(boolean selected) {
-        this.selected = selected;
-        this.repaint();
-    }
-
-    @Override
-    public boolean isSelected() {
-        return selected;
-    }
-
-    @Override
-    public void setNormalAttr(Color back, Color fore) {
-        clrBackNormal = back;
-        clrForeNormal = fore;
-        this.repaint();
-    }
-
-    @Override
-    public void setSelectAttr(Color back, Color fore) {
-        clrBackSelect = back;
-        clrForeSelect = fore;
-        this.repaint();
-    }
-
-    @Override
-    public void setSelectBorder(Stroke stroke) {
-        this.stroke = (null==stroke) ? getDefaultBorder() : stroke;
-        this.repaint();
-    }
-
-    @Override
-    public void setSelectBorder(Color color) {
-        this.clrStroke = color;
-        this.repaint();
-    }
-
-    @Override
-    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
-        this.setSelected(isSelected);
-        return this;
-    }
-
-    @Override
-    public Component getEditorComponent() {
-        return this;
-    }
-
-    @Override
-    public void setItem(Object value) {
-        this.value = value;
-    }
-
-    @Override
-    public Object getItem() {
-        return value;
-    }
-    
-    //</editor-fold>
-
-    @Override
-    public void selectAll() {
-        /* do nothing */
-    }
-
-    @Override
-    public void addActionListener(ActionListener listener) {
-        listenerList.add(ActionListener.class, listener);
-    }
-
-    @Override
-    public void removeActionListener(ActionListener listener) {
-        listenerList.remove(ActionListener.class, listener);
-    }
-
-    @Override
-    protected void fireActionEvent() {
-        for (ActionListener listener : listenerList.getListeners(ActionListener.class)) {
-            listener.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, ""));
-        }
-    }
-
-    //<editor-fold defaultstate="collapsed" desc=" ( performance ) ">
-    
-    @Override
-    public void validate() {
-        // do nothing
-    }
-
-    @Override
-    public void revalidate() {
-        // do nothing
-    }
-
-    @Override
-    protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
-        // do nothing
-    }
-
-    @Override
-    public void firePropertyChange(String propertyName, boolean oldValue, boolean newValue) {
-        // do nothing
-    }
-
-    //</editor-fold>
-}

+ 0 - 157
src/main/java/net/ranides/assira/swing/renderers/QListItemEditor.java

@@ -1,157 +0,0 @@
-/*
- *  @author Ranides Atterwim <ranides@gmail.com>
- *  @copyright Ranides Atterwim
- *  @license WTFPL
- *  @url http://ranides.net/projects/assira
- */
-
-package net.ranides.assira.swing.renderers;
-
-import java.awt.*;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.geom.Rectangle2D;
-import javax.swing.*;
-import net.ranides.assira.awt.ColorUtils;
-
-/**
- *
- * @author ranides
- */
-public class QListItemEditor extends JLabel implements ListCellRenderer, ComboBoxEditor {
-
-    private static final long serialVersionUID = 1L;
-
-    private Object value;
-
-    private boolean selected = false;
-    private Color clrForeNormal = SystemColor.textText;
-    private Color clrBackNormal = SystemColor.text;
-    private Color clrForeSelect = SystemColor.textHighlightText;
-    private Color clrBackSelect = SystemColor.textHighlight;
-    private Color clrStroke     = ColorUtils.invert(SystemColor.textHighlight);
-    private Stroke stroke       = new BasicStroke(
-        1.0f,
-        BasicStroke.CAP_BUTT,
-        BasicStroke.JOIN_MITER,
-        1.0f,
-        new float[]{1.0f},
-        1.0f
-    );
-
-    protected Stroke getDefaultBorder() {
-        return stroke;
-    }
-
-    protected Rectangle2D getBorderRect() {
-        Rectangle2D rect = new Rectangle2D.Float();
-        rect.setRect(0,0, getWidth()-1, getHeight()-1 );
-        return rect;
-    }
-
-/* ************************************************************************** */
-
-    @Override
-    public void paint(Graphics jcanvas) {
-        Graphics2D canvas = (Graphics2D)jcanvas;
-        paintBefore(canvas);
-        super.paint(jcanvas);
-        paintAfter(canvas);
-    }
-
-    protected void paintAfter(Graphics2D canvas) {
-        if( isSelected() ) {
-            canvas.setColor( clrStroke );
-            canvas.setStroke( stroke );
-            canvas.draw( getBorderRect() );
-        }
-    }
-
-    protected void paintBefore(Graphics2D canvas) {
-        this.setBackground( isSelected() ? clrBackSelect : clrBackNormal );
-        this.setForeground( isSelected() ? clrForeSelect : clrForeNormal );
-    }
-
-/* ************************************************************************** */
-
-    @SuppressWarnings("PMD.ConstructorCallsOverridableMethod")
-    public QListItemEditor() {
-        this.setPreferredSize( new Dimension(0, 22) );
-        this.setOpaque(true);
-        this.setBorder( BorderFactory.createEmptyBorder(0, 4, 0, 0));
-    }
-
-    public void setSelected(boolean selected) {
-        this.selected = selected;
-        this.repaint();
-    }
-
-    public boolean isSelected() {
-        return selected;
-    }
-
-    public void setNormalAttr(Color back, Color fore) {
-        clrBackNormal = back;
-        clrForeNormal = fore;
-        this.repaint();
-    }
-
-    public void setSelectAttr(Color back, Color fore) {
-        clrBackSelect = back;
-        clrForeSelect = fore;
-        this.repaint();
-    }
-
-    public void setSelectBorder(Stroke stroke) {
-        this.stroke = (null==stroke) ? getDefaultBorder() : stroke;
-        this.repaint();
-    }
-
-    public void setSelectBorder(Color color) {
-        this.clrStroke = color;
-        this.repaint();
-    }
-
-    @Override
-    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
-        this.setSelected(isSelected);
-        return this;
-    }
-
-    @Override
-    public Component getEditorComponent() {
-        return this;
-    }
-
-    @Override
-    public void setItem(Object value) {
-        this.value = value;
-    }
-
-    @Override
-    public Object getItem() {
-        return value;
-    }
-
-    @Override
-    public void selectAll() {
-        /* do nothing */
-    }
-
-    @Override
-    public void addActionListener(ActionListener listener) {
-        listenerList.add(ActionListener.class, listener);
-    }
-
-    @Override
-    public void removeActionListener(ActionListener listener) {
-        listenerList.remove(ActionListener.class, listener);
-    }
-
-    protected void fireActionEvent() {
-        for (ActionListener listener : listenerList.getListeners(ActionListener.class)) {
-            listener.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, ""));
-        }
-    }
-
-}

+ 0 - 58
src/test/java/net/ranides/assira/io/IndentWriterTest.java

@@ -1,58 +0,0 @@
-/*
- *  @author Ranides Atterwim <ranides@gmail.com>
- *  @copyright Ranides Atterwim
- *  @license WTFPL
- *  @url http://ranides.net/projects/assira
- */
-
-package net.ranides.assira.io;
-
-import java.io.IOException;
-import org.junit.Test;
-import static org.junit.Assert.*;
-
-/**
- *
- * @author ranides
- */
-public class IndentWriterTest {
-    
-    @Test
-    public void testIndenter() throws IOException {
-        StringBuilder builder = new StringBuilder();
-
-        IndentWriter writer = new IndentWriter(builder);
-        try {
-            writer.write("Hello {\n");
-            writer.indent();
-            writer.write("1\n");
-            writer.write("sub {\n");
-            writer.indent();
-            writer.write("2 ");
-            writer.write("3 ");
-            writer.write("4\n");
-            writer.write("5\n");
-            writer.outdent();
-            writer.write("sub }\n");
-            writer.write("6 ");
-            writer.write("7\n");
-            writer.outdent();
-            writer.write("8\n");
-        } finally {
-            writer.close();
-            String expected = 
-                "Hello {\n"+
-                "    1\n"+
-                "    sub {\n"+
-                "        2 3 4\n"+
-                "        5\n"+
-                "    sub }\n"+
-                "    6 7\n"+
-                "8\n";
-            assertEquals(expected, builder.toString());
-        }
-        
-        
-
-    }
-}