/*
 * This file is part of libbluray
 * Copyright (C) 2010  William Hahne
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library. If not, see
 * <http://www.gnu.org/licenses/>.
 */

package org.havi.ui;

import org.videolan.Logger;

public class HGraphicsDevice extends HScreenDevice {
    protected HGraphicsDevice() {
        int length = HScreenConfigTemplate.defaultConfig.length;
        hgcArray = new HGraphicsConfiguration[length];
        for (int i = 0; i < length; i++) {
            HGraphicsConfigTemplate hgct = new HGraphicsConfigTemplate();
            HScreenConfigTemplate.initDefaultConfigTemplate(hgct, i);
            hgcArray[i] = new HGraphicsConfiguration(hgct);
        }
        hgc = hgcArray[0];
    }

    public HGraphicsConfiguration[] getConfigurations() {
        return hgcArray;
    }

    public HGraphicsConfiguration getDefaultConfiguration() {
        return hgcArray[0];
    }

    public HGraphicsConfiguration getBestConfiguration(HGraphicsConfigTemplate hgct) {
        int score = -1;
        HGraphicsConfiguration hgc = null;
        for (int i = 0; i < hgcArray.length; i++)
            if (hgct.match(hgcArray[i]) > score)
                hgc = hgcArray[i];
        return hgc;
    }

    public HGraphicsConfiguration getBestConfiguration(HGraphicsConfigTemplate hgcta[]) {
        int score = -1;
        HGraphicsConfiguration hgc = null;
        for (int i = 0; i < hgcArray.length; i++)
            for (int j = 0; j < hgcta.length; j++)
                if (hgcta[j].match(hgcArray[i]) > score)
                    hgc = hgcArray[i];
        return hgc;
    }

    public HGraphicsConfiguration getCurrentConfiguration() {
        return hgc;
    }

    public boolean setGraphicsConfiguration(HGraphicsConfiguration hgc)
            throws SecurityException, HPermissionDeniedException,
            HConfigurationException {
        this.hgc = hgc;

        logger.unimplemented("setGraphicsConfiguration");

        //org.videolan.GUIManager.getInstance().setBounds(0, 0, 960, 540);
        // -- not enough ...

        return true;
    }

    private HGraphicsConfiguration[] hgcArray;
    private HGraphicsConfiguration hgc;

    private static final Logger logger = Logger.getLogger(HGraphicsDevice.class.getName());
}

@@ -768,16 +768,76 @@
 vi.ui;%0A%0A
+import java.awt.Dimension;%0A%0Aimport org.videolan.GUIManager;%0A
 import o
@@ -2506,32 +2506,8 @@
 on %7B
-%0A        this.hgc = hgc;
 %0A%0A  
@@ -2575,104 +2575,1066 @@
     
-//org.videolan.GUIManager.getInstance().setBounds(0, 0, 960, 540);%0A        // -- not enough ...%0A
+GUIManager mgr = GUIManager.getInstance();%0A        Dimension d = hgc.getPixelResolution();%0A        int curWidth = mgr.getWidth();%0A        int curHeight = mgr.getHeight();%0A%0A        if (curWidth != d.width %7C%7C curHeight != d.height) %7B%0A            logger.info(%22Request to switch graphics resolution from %22 + curWidth + %22x%22 + curHeight +%0A                        %22 to %22 + d.width + %22x%22 + d.height);%0A%0A            if (mgr.isVisible()) %7B%0A                mgr.setVisible(false);%0A                mgr.setBounds(0, 0, d.width, d.height);%0A                mgr.setVisible(true);%0A            %7D else %7B%0A                mgr.setBounds(0, 0, d.width, d.height);%0A            %7D%0A%0A            curWidth = mgr.getWidth();%0A            curHeight = mgr.getHeight();%0A            if (curWidth != d.width %7C%7C curHeight != d.height) %7B%0A                logger.error(%22Request to switch graphics resolution from %22 + curWidth + %22x%22 + curHeight +%0A                            %22 to %22 + d.width + %22x%22 + d.height + %22 FAILED%22);%0A                return false;%0A            %7D%0A        %7D%0A%0A        this.hgc = hgc;
 %0A   

Support for graphics resolution change