/*
 * @(#)Mode.java
 *
 * This file is part of webCDwriter - Network CD Writing.
 *
 * Copyright (C) 1999-2003 Jörg P. M. Haeger
 *
 * webCDwriter is free software. See CDcreator.java for details.
 *
 * Jörg Haeger, 31.03.2001
 */

import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;

/**
 * The mode of webCDcreator.
 *
 * @version 20030306
 * @author Jörg P. M. Haeger
 */
class Mode {
	final public static String
		CDR = "CD-R",
		CDR74 = "CD-R/RW 74",
		CDR80 = "CD-R/RW 80",
		CDR90 = "CD-R 90",
		DVDPLUSRW = "DVD+RW";

	static int mediumSize = 650;

	final public static int
		audio = 0,
		data = 1;

	final public static int
		copy = 0,
		current = 1,
		server = 2;

	static int
		source = current,
		type = data;

	static boolean
		makeImage = true,
		store = false;

	final private static String[] mediaLabels
		= { CDR74, CDR80, DVDPLUSRW };
	static DefaultComboBoxModel media
		= new DefaultComboBoxModel(mediaLabels) {
			public void setSelectedItem(Object anObject) {
//				System.out.println("setSelectedItem " + anObject);

				String name = (String) anObject;
				if (name == DVDPLUSRW && !CDcreator.DVDplusRWSupport) {
					JOptionPane.showMessageDialog(
						CDcreator.mainWin,
						CDcreator.i18n("MWNoDVDplusRWDrive"),
						CDcreator.i18n("error"),
						JOptionPane.ERROR_MESSAGE);
					return;
				}

				super.setSelectedItem(anObject);

				Options.overburn = false;
				if (name == CDR74)
					mediumSize = 650;
				else
				if (name == CDR80)
					mediumSize = 700;
				else
				if (name == CDR90) {
					mediumSize = 800;
					Options.overburn = true;
				}
				else
				if (name == DVDPLUSRW)
					mediumSize = 4482;

				if (CDcreator.mainWin != null) {
					CDcreator.mainWin.createMenuBar();
					if (CDcreator.mainWin.sessionSizeView != null)
						CDcreator.mainWin.sessionSizeView.repaint();
				}
			}
		};

	static void addMedium(String name) {
		if (media.getIndexOf(name) < 0)
			if (name == CDR90)
				media.insertElementAt(name, media.getSize() - 1);
			else
				media.addElement(name);
	}

	static boolean audioCD() {
		return type == audio;
	}

	static boolean burnImageFile() {
		return type == data && !makeImage;
	}

	static boolean copyCD() {
		return source == copy;
	}

	static boolean isDVDPlusRW() {
		return isMedium(DVDPLUSRW);
	}

	static boolean isMedium(String name) {
		return ((String) media.getSelectedItem()).startsWith(name);
	}

	static boolean makeISOImage() {
		return source != copy && type == data && makeImage;
	}

	static void reset() {
		source = current;
		type = data;
		makeImage = true;
		store = false;
	}

	static boolean serverSession() {
		return source == server;
	}

	static void setMedium(String name) {
		if (media.getIndexOf(name) < 0)
			System.out.println("Invalid medium: <" + name + ">");
		else
			media.setSelectedItem(name);
	}
}
