/*
* KoalaCalendar.java
*
* Created on April 4, 2007, 8:53 PM
*
* by John Palermo
* VARRO media
* john.palermo@varromedia.net
*
* class version: 0.9a (r7)
*
*/
package koala;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.SpringLayout;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import varro.gui.components.general.VInternalFrame;
import varro.gui.utilities.VSpringUtilities;
import koala.api.KDay;
/**
*
* @author John Palermo
* @version 0.9a (r7)
*/
public class KoalaCalendar extends JFrame { //ID=VdayAppCLASS
// Declare Desktop Pane Object
private JDesktopPane desktop;
// Declare Window Internal Frame Object
private VInternalFrame window0; //The day Window
// Declare the day panel
private KDay day;
//Specify the look and feel to use. Valid values:
//null (use the default), "Metal", "System", "Motif", "GTK+"
final private static String LOOKANDFEEL = "System";
//Value for insetting desktop from edge of screen
final private int INSET = 50;
private Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
public KoalaCalendar() { //ID=VdayAppCONSTRUCTOR
super("VdayApp");
//Make the big window be indented 50 pixels from each edge
//of the screen.
setBounds(INSET, INSET,
screenSize.width - INSET*2,
screenSize.width - INSET*2);
//Set up the GUI
desktop = new JDesktopPane(); //a specialized layerd pane
//Set up the first internal frame; that is, the first inner window
window0 = new VInternalFrame("Calendar", 700, 300);
window0.setMinimumSize(new Dimension(300,200));
window0.getContentPane().setLayout(new SpringLayout());
//Set up the day array
String[][][] calArray =
{
//First Row - First Column
{{"9:00am", //Text to display in cell
"Row1", //ID of cell
"1", //Column span is 1
"1", //Row span is 1
"true", //Lock the cell width
"#000000", //Cell border is black
"#00FF00", //Cell background is green
"#FFFFFF", //Cell text is white
"#0000FF", //Border around text is blue
"#FF7D00"}, //Text background is organge
//Frist Row - Second Column
{"Row 1, Cell1", //Text to display
"Row1", //ID of cel
"1", //Column span is 1
"1", //Row span is 1
"false"}}, //Don't lock the cell width; make it stretch
//Second Row - First Cell (Use default day colours)
{{"Cell3", //Text to display in cell
"Row2", //ID of cell
"1", //Column span is 1
"3", //Row span is 3
"true"}, //Lock the cell width
//Second Row - Second Cell (Use default day colours)
{"Cell4", //Text to display in cell
"Row2", //ID of cell
"1", //Column span is 1
"3", //Row span is 3
"false"}}, //Don't lock the cell width; make it stretch
};
//Create the day panel
day = new KDay(Color.BLACK, 1, Color.WHITE, calArray);
//add the day panel to the internal window
window0.getContentPane().add(day);
//Apply a compact-grid type of spring layout to the window's content pane
VSpringUtilities.makeCompactGrid(window0.getContentPane(), 1, 1, 6, 6, 6, 6);
//Make the window visible
window0.setVisible(true); //necessary as of 1.3
//Add the window to the desktop
desktop.add(window0);
try {
window0.setSelected(true);
} catch (java.beans.PropertyVetoException e) {}
//Make the desktop the content pane of the root frame
setContentPane(desktop);
//Make dragging a little faster but perhaps uglier.
desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
} //ID=VdayAppCONSTRUCTOR
private static void initLookAndFeel() { //ID=initLookAndFeelMETHOD
String lookAndFeel = null;
if (LOOKANDFEEL != null) {
if (LOOKANDFEEL.equals("Metal")) {
lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
} else if (LOOKANDFEEL.equals("System")) {
lookAndFeel = UIManager.getSystemLookAndFeelClassName();
} else if (LOOKANDFEEL.equals("Motif")) {
lookAndFeel = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
} else if (LOOKANDFEEL.equals("GTK+")) { //new in 1.4.2
lookAndFeel = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
} else {
System.err.println("Unexpected value of LOOKANDFEEL specified: "
+ LOOKANDFEEL);
lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
}
try {
UIManager.setLookAndFeel(lookAndFeel);
} catch (ClassNotFoundException e) {
System.err.println("Couldn't find class for specified look and feel:"
+ lookAndFeel);
System.err.println("Did you include the L&F library in the class path?");
System.err.println("Using the default look and feel.");
} catch (UnsupportedLookAndFeelException e) {
System.err.println("Can't use the specified look and feel ("
+ lookAndFeel
+ ") on this platform.");
System.err.println("Using the default look and feel.");
} catch (Exception e) {
System.err.println("Couldn't get specified look and feel ("
+ lookAndFeel
+ "), for some reason.");
System.err.println("Using the default look and feel.");
e.printStackTrace();
}
}
} //ID=initLookAndFeelMETHOD
/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
private static void createAndShowGUI() { //ID=createAndShowGUIMETHOD
//Set the look and feel.
initLookAndFeel();
//Make sure we have nice window decorations.
JFrame.setDefaultLookAndFeelDecorated(true);
//Create and set up the window.
KoalaCalendar frame = new KoalaCalendar();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Display the window.
frame.setVisible(true);
} //ID=createAndShowGUIMETHOD
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
} //ID=VdayAppCLASS