/*
 * @(#)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 20030726
 * @author Jörg P. M. Haeger
 */
class Mode {
	final public static String
		CDR74 = "CD-R/RW 74",
		CDR80 = "CD-R/RW 80",
		CDR90 = "CD-R 90";

	static String medium = "CD-R";
	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 };
	static DefaultComboBoxModel media
		= new DefaultComboBoxModel(mediaLabels) {
			public void setSelectedItem(Object anObject) {
//				System.out.println("setSelectedItem " + anObject);

				super.setSelectedItem(anObject);

				Options.overburn = false;
				String name = (String) anObject;
				if (name.startsWith("CD-R"))
					medium = "CD-R";
				else
					medium = name;

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

				if (CDcreator.mainWin != null) {
					CDcreator.mainWin.createMenuBar();
					if (CDcreator.mainWin.sessionSizeView != null) {
						CDcreator.mainWin.sessionSizeView.repaint();
						CDcreator.mainWin.sessionSizeView.setToolTipText(
							CDcreator.i18n("TTsessionSize"));
					}
				}
			}
		};

	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 isMediumDVD() {
		return medium.startsWith("DVD");
	}

	static boolean isMediumDVDRW() {
		return medium.equals("DVD-RW") || medium.equals("DVD+RW");
	}

	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) {
		int p = media.getIndexOf(name);
		if (p < 0) {
			System.out.println("Invalid medium: <" + name + ">");
			return;
		}

		media.setSelectedItem(name);
	}
}
