xlawrence 2004/12/08 17:02:30 CET
Added files:
src/java/org/jahia/suite/calendar/test DummyCalServerGUI.java
Log:
Added GUI form for the dummy calendar server test
Revision Changes Path
1.1 +432 -0
uwcal_JSR168/src/java/org/jahia/suite/calendar/test/DummyCalServerGUI.java (new)
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/uwcal_JSR168/src/java/org/jahia/suite/calendar/test/DummyCalServerGUI.java?rev=1.1&content-type=text/plain
Index: DummyCalServerGUI.java
====================================================================
/*
* ____.
* __/\ ______| |__/\. _______
* __ .____| | \ | +----+ \
* _______| /--| | | - \ _ | : - \_________
* \\______: :---| : : | : | \________>
* |__\---\_____________:______: :____|____:_____\
* /_____|
*
* . . . i n j a h i a w e t r u s t . . .
*
*
*
* ----- BEGIN LICENSE BLOCK -----
* Version: JCSL 1.0
*
* The contents of this file are subject to the Jahia Community Source License
* 1.0 or later (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.jahia.org/license
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the rights, obligations and limitations governing use of the contents
* of the file. The Original and Upgraded Code is the Jahia CMS and Portal
* Server. The developer of the Original and Upgraded Code is JAHIA Ltd. JAHIA
* Ltd. owns the copyrights in the portions it created. All Rights Reserved.
*
* The Shared Modifications are Jahia View Helper.
*
* The Developer of the Shared Modifications is Jahia Solution S�rl.
* Portions created by the Initial Developer are Copyright (C) 2002 by the
* Initial Developer. All Rights Reserved.
*
* ----- END LICENSE BLOCK -----
*/
package org.jahia.suite.calendar.test;
import org.jahia.suite.calendar.framework.model.SyncEvent;
import org.jahia.suite.calendar.util.StateValueConverter;
import javax.swing.*;
import java.awt.*;
/**
*
* @author Xavier Lawrence
*/
public class DummyCalServerGUI extends JFrame {
private DummyCalendarServer server;
private DefaultListModel listContent;
private static final String[] comboValues = {"NEW", "MODIFIED", "DELETED",
"SYNCHRONIZED", "UNKNOWN"};
/**
* Creates new form DummyCalServerGUI
* @param server The DummyCalendarServer owner of this GUI
*/
public DummyCalServerGUI(DummyCalendarServer server) {
this.server = server;
listContent = new DefaultListModel();
SyncEvent[] events = server.getCalendar().getEvents();
for (int i=0; i<events.length; i++) {
listContent.addElement(events[i].getKey());
}
initComponents();
keyList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
keyList.setLayoutOrientation(JList.HORIZONTAL_WRAP);
keyList.setModel(listContent);
keyListValueChanged(null);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
private void initComponents() {//GEN-BEGIN:initComponents
java.awt.GridBagConstraints gridBagConstraints;
calContainer = new javax.swing.JScrollPane();
calArea = new javax.swing.JTextArea();
printButton = new javax.swing.JButton();
clearButton = new javax.swing.JButton();
stateSelecter = new javax.swing.JComboBox(comboValues);
keysContainer = new javax.swing.JScrollPane();
keyList = new javax.swing.JList();
keysName = new javax.swing.JLabel();
calendarName = new javax.swing.JLabel();
stateName = new javax.swing.JLabel();
setButton = new javax.swing.JButton();
editButton = new javax.swing.JButton();
newButton = new javax.swing.JButton();
deleteButton = new javax.swing.JButton();
menu = new javax.swing.JMenuBar();
fileMEnu = new javax.swing.JMenu();
exitItem = new javax.swing.JMenuItem();
getContentPane().setLayout(new java.awt.GridBagLayout());
setTitle("Dummy Calendar Server");
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm(evt);
}
});
calContainer.setPreferredSize(new java.awt.Dimension(300, 350));
calArea.setEditable(false);
calArea.setFont(new java.awt.Font("Arial", 0, 11));
calContainer.setViewportView(calArea);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 4;
gridBagConstraints.gridwidth = 5;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.ipadx = 177;
gridBagConstraints.ipady = 77;
gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 1.0;
getContentPane().add(calContainer, gridBagConstraints);
printButton.setText("Print");
printButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
printButtonActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 5;
gridBagConstraints.gridwidth = 3;
gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
getContentPane().add(printButton, gridBagConstraints);
clearButton.setText("Clear");
clearButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
clearButtonActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 3;
gridBagConstraints.gridy = 5;
gridBagConstraints.gridwidth = 2;
gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
getContentPane().add(clearButton, gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 1;
gridBagConstraints.gridwidth = 3;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.ipadx = 66;
gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
getContentPane().add(stateSelecter, gridBagConstraints);
keysContainer.setPreferredSize(new java.awt.Dimension(80, 80));
keyList.addListSelectionListener(new
javax.swing.event.ListSelectionListener() {
public void valueChanged(javax.swing.event.ListSelectionEvent
evt) {
keyListValueChanged(evt);
}
});
keysContainer.setViewportView(keyList);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
gridBagConstraints.gridheight = 2;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.ipadx = 47;
gridBagConstraints.ipady = 27;
gridBagConstraints.insets = new java.awt.Insets(3, 3, 0, 3);
getContentPane().add(keysContainer, gridBagConstraints);
keysName.setFont(new java.awt.Font("Arial", 1, 12));
keysName.setText("Keys");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
gridBagConstraints.insets = new java.awt.Insets(3, 5, 3, 3);
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
getContentPane().add(keysName, gridBagConstraints);
calendarName.setFont(new java.awt.Font("Arial", 1, 12));
calendarName.setText("Calendar");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 3;
gridBagConstraints.insets = new java.awt.Insets(20, 5, 0, 0);
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
getContentPane().add(calendarName, gridBagConstraints);
stateName.setFont(new java.awt.Font("Arial", 1, 12));
stateName.setText("State");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridwidth = 3;
gridBagConstraints.insets = new java.awt.Insets(3, 5, 0, 0);
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
getContentPane().add(stateName, gridBagConstraints);
setButton.setText("Set state");
setButton.setMinimumSize(new java.awt.Dimension(75, 20));
setButton.setPreferredSize(new java.awt.Dimension(75, 20));
setButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
setButtonActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 4;
gridBagConstraints.gridy = 1;
gridBagConstraints.insets = new java.awt.Insets(3, 3, 0, 0);
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
getContentPane().add(setButton, gridBagConstraints);
editButton.setText("Edit");
editButton.setMaximumSize(new java.awt.Dimension(49, 20));
editButton.setMinimumSize(new java.awt.Dimension(49, 20));
editButton.setPreferredSize(new java.awt.Dimension(49, 20));
editButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
editButtonActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 2;
gridBagConstraints.insets = new java.awt.Insets(0, 3, 0, 0);
gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST;
getContentPane().add(editButton, gridBagConstraints);
newButton.setText("New");
newButton.setMaximumSize(new java.awt.Dimension(55, 20));
newButton.setMinimumSize(new java.awt.Dimension(55, 20));
newButton.setPreferredSize(new java.awt.Dimension(55, 20));
newButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
newButtonActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 2;
gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST;
getContentPane().add(newButton, gridBagConstraints);
deleteButton.setText("Delete");
deleteButton.setMaximumSize(new java.awt.Dimension(63, 20));
deleteButton.setMinimumSize(new java.awt.Dimension(63, 20));
deleteButton.setPreferredSize(new java.awt.Dimension(63, 20));
deleteButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
deleteButtonActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 3;
gridBagConstraints.gridy = 2;
gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST;
getContentPane().add(deleteButton, gridBagConstraints);
fileMEnu.setText("File");
exitItem.setText("Exit");
exitItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
exitItemActionPerformed(evt);
}
});
fileMEnu.add(exitItem);
menu.add(fileMEnu);
setJMenuBar(menu);
pack();
}//GEN-END:initComponents
private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt)
{//GEN-FIRST:event_deleteButtonActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_deleteButtonActionPerformed
private void newButtonActionPerformed(java.awt.event.ActionEvent evt)
{//GEN-FIRST:event_newButtonActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_newButtonActionPerformed
private void editButtonActionPerformed(java.awt.event.ActionEvent evt)
{//GEN-FIRST:event_editButtonActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_editButtonActionPerformed
private void clearButtonActionPerformed(java.awt.event.ActionEvent evt)
{//GEN-FIRST:event_clearButtonActionPerformed
calArea.setText("");
}//GEN-LAST:event_clearButtonActionPerformed
private void exitItemActionPerformed(java.awt.event.ActionEvent evt)
{//GEN-FIRST:event_exitItemActionPerformed
exitForm(null);
}//GEN-LAST:event_exitItemActionPerformed
private void printButtonActionPerformed(java.awt.event.ActionEvent evt)
{//GEN-FIRST:event_printButtonActionPerformed
SyncEvent[] events = server.getCalendar().getEvents();
for (int i=0; i<events.length; i++) {
calArea.append("Key -> "+events[i].getKey()+"\n");
calArea.append(new String(events[i].getContent())+"\n");
calArea.append("State ->
"+StateValueConverter.toUWCalString(events[i].
getState())+"\n\n");
}
}//GEN-LAST:event_printButtonActionPerformed
private void keyListValueChanged(javax.swing.event.ListSelectionEvent
evt) {//GEN-FIRST:event_keyListValueChanged
if (evt == null) {
stateSelecter.setSelectedItem(comboValues[comboValues.length-1]);
return;
}
if (evt.getValueIsAdjusting() == false) {
if (keyList.getSelectedIndex() == -1) {
// No selection
stateSelecter.setSelectedItem(comboValues[comboValues.length-1]);
} else {
// Selection
String key = (String)keyList.getSelectedValue();
int state = server.getCalendar().getEvent(key).getState();
String stateValue = StateValueConverter.toUWCalString(state);
stateSelecter.setSelectedItem(stateValue);
}
}
}//GEN-LAST:event_keyListValueChanged
private void exitForm(java.awt.event.WindowEvent evt)
{//GEN-FIRST:event_exitForm
System.exit(0);
}//GEN-LAST:event_exitForm
private void setButtonActionPerformed(java.awt.event.ActionEvent evt)
{//GEN-FIRST:event_setButtonActionPerformed
String state = (String)stateSelecter.getSelectedItem();
String key = (String)keyList.getSelectedValue();
if (key == null) {
JOptionPane.showMessageDialog(this,
"You must first select a key in the list", "Error",
JOptionPane.ERROR_MESSAGE);
return;
}
server.setState(key, StateValueConverter.toUWCalInt(state));
}//GEN-LAST:event_setButtonActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JTextArea calArea;
private javax.swing.JScrollPane calContainer;
private javax.swing.JLabel calendarName;
private javax.swing.JButton clearButton;
private javax.swing.JButton deleteButton;
private javax.swing.JButton editButton;
private javax.swing.JMenuItem exitItem;
private javax.swing.JMenu fileMEnu;
private javax.swing.JList keyList;
private javax.swing.JScrollPane keysContainer;
private javax.swing.JLabel keysName;
private javax.swing.JMenuBar menu;
private javax.swing.JButton newButton;
private javax.swing.JButton printButton;
private javax.swing.JButton setButton;
private javax.swing.JLabel stateName;
private javax.swing.JComboBox stateSelecter;
// End of variables declaration//GEN-END:variables
/**
* Sets the Look and Feel of the Swing components depending on the
* platform where the program is running.
*/
public static void setLookAndFeel() {
try {
UIManager.setLookAndFeel(
"com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch (Exception e) {
try {
UIManager.setLookAndFeel(
"com.sun.java.swing.plaf.mac.MacLookAndFeel");
} catch (Exception ee) {
try {
UIManager.setLookAndFeel("plaf.metal.MetalLookAndFeel");
} catch (Exception eee) {}
}
}
}
/**
*
*/
public void setFrameLocation() {
Dimension screenSize = Toolkit.getDefaultToolkit().
getScreenSize();
Dimension frameSize = this.getSize();
if (frameSize.height > screenSize.height)
frameSize.height = screenSize.height;
if (frameSize.width > screenSize.width)
frameSize.width = screenSize.width;
this.setLocation((screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
}
/**
*
*/
public void addItem(String key) {
listContent.addElement(key);
}
/**
*
*/
public void removeItem(String key) {
listContent.removeElement(key);
}
}