package outlook;
import com.ultraswing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Outlook
{
private static TitlePanel _treePanel;
private static CFrame _frame;
private static ToolBarToggleButton _folderListButton;
private static CFrame createFrame()
{
CFrame frame = new CFrame();
initFrame(frame);
frame.setSize(800, 600);
frame.centerOnScreen();
frame.setVisible(true);
frame.setExitOnClose();
return frame;
}
private static void initFrame(CFrame frame)
{
frame.setTitle( "Outlook demo" );
JMenuBar menuBar = createMenus();
frame.setJMenuBar( menuBar );
JPanel content = new JPanel();
content.setLayout(new BorderLayout());
frame.getContentPane().add( content, BorderLayout.CENTER );
content.add( createToolBar(), BorderLayout.NORTH);
content.add(createMainWindow(), BorderLayout.CENTER);
StatusBar status = new StatusBar( new JComponent[]
{StatusBar.INDICATOR_STATUS,
StatusBar.SEPARATOR,
StatusBar.INDICATOR_DATE,
StatusBar.SEPARATOR,
StatusBar.INDICATOR_TIME
});
frame.addStatusBar(status);
}
private static CToolBar createToolBar()
{
CToolBar toolbar = new CToolBar();
toolbar.setFloatable(false);
DropDownButton dropBtn = new DropDownButton("new", getImage("new.gif"));
dropBtn.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.out.println( "new button clicked" );
}
});
dropBtn.setSeparateButton(true);
JPopupMenu popup = new JPopupMenu();
popup.add(new JMenuItem("test1"));
popup.add(new JMenuItem("test2"));
popup.add(new JMenuItem("test3"));
JMenuItem item4 = new JMenuItem("test4");
popup.add(item4);
item4.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.out.println( "test4 menu item clicked" );
}
});
dropBtn.setPopupMenu(popup);
toolbar.add(dropBtn);
ToolBarToggleButton folderList = new ToolBarToggleButton("Folder List");
_folderListButton = folderList;
folderList.setState(false);
folderList.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.out.println( "treePanel isVisible=" + _treePanel.isVisible());
if(_treePanel.isVisible())
{
_treePanel.removeFromParentPanel();
}
else
{
_treePanel.restore();
}
}
});
toolbar.add(folderList);
return toolbar;
}
private static JPanel createMainWindow()
{
CSplitPane mainWinSplitPane = new CSplitPane(true, 4);
mainWinSplitPane.addPane(createOutlookBar(), 1);
JPanel rightPanel = new JPanel();
mainWinSplitPane.addPane(rightPanel, 5);
rightPanel.setLayout(new BorderLayout());
CLabel northHeader = new CLabel("Inbox");
northHeader.setBorder(SwingUtil.createRaisedBorder());
northHeader.setOpaque(true);
northHeader.setBackground(Color.gray);
northHeader.setForeground(Color.white);
rightPanel.add(northHeader, BorderLayout.NORTH);
CSplitPane panel = new CSplitPane(true, 4);
rightPanel.add(panel, BorderLayout.CENTER);
panel.addPane(createFolderList(panel, 1), 1);
CSplitPane panel2 = new CSplitPane(false, 4);
panel2.addPane(createMessageHeaderPanel());
JPanel southPanel = new JPanel();
southPanel.setLayout(new BorderLayout());
JLabel label = new JLabel("header:");
label.setBorder(SwingUtil.createRaisedBorder());
southPanel.add(label, BorderLayout.NORTH);
JTextArea jta = new JTextArea();
jta.setBorder(SwingUtil.createLoweredBorder());
southPanel.add(jta, BorderLayout.CENTER);
panel2.addPane(southPanel);
panel.addPane(panel2, 5);
return mainWinSplitPane;
}
private static JPanel createFolderList(CSplitPane split, int weight)
{
TitlePanel panel = new TitlePanel(split, "Folder List", true, weight)
{
public void onClose()
{
_folderListButton.setState(true);
}
};
JTree tree = new JTree();
tree.setBorder(SwingUtil.createLoweredBorder());
panel.add(tree, BorderLayout.CENTER);
_treePanel = panel;
return panel;
}
private static CListView createMessageHeaderPanel()
{
CListView listview = new CListView();
CListReportCtrl ctrl = listview.getReportCtrl();
ctrl.setSortEnabled(true);
ctrl.setHorizontalScrollBarEnabled(false);
ctrl.addColumnHeader(null, getImage("outlook_importance.gif"), SwingConstants.CENTER, 24);
ctrl.addColumnHeader(null, getImage("outlook_viewip.gif"), SwingConstants.CENTER, 24);
ctrl.setFixedWidth(0, true);
ctrl.setFixedWidth(1, true);
ctrl.addColumnHeader("From");
ctrl.addColumnHeader("Subject", SwingConstants.LEFT, 100);
ctrl.addColumnHeader("Received");
for (int i = 0; i < 4 ; i++)
{
if(i == 2)
{
ctrl.addItem(null, getImage("outlook_highimportance.gif"));
}
else
{
ctrl.addEmptyItem();
}
if(i == 1)
{
ctrl.addItem(null, getImage("outlook_viewip.gif"));
}
else
{
ctrl.addEmptyItem();
}
ctrl.addItem("Name " + i, null);
ctrl.addItem("Subject " + i, null);
ctrl.addItem("2002 " + i, null);
}
ctrl.addEventListener(new CListCtrlEventListenerImpl());
return listview;
}
static class CListCtrlEventListenerImpl implements CListReportCtrlEventListener
{
public void valueChanged(CListReportCtrlEvent e)
{
CListReportCtrl ctrl = (CListReportCtrl) e.getSource();
int [] selected = ctrl.getSelectedRows();
for (int i = 0; i < selected.length ; i++)
{
String text = ((JLabel)ctrl.getCellAt(selected[i], 3)).getText();
System.out.println( "valueChanged:" + text);
System.out.println( "Subject column:" + ctrl.getCellAt(selected[i], "Subject"));
_frame.getStatusBar().setStatusMessage(text);
}
}
}
private static OutlookBar createOutlookBar()
{
OutlookBar outlook = new OutlookBar();
OutlookBarItem item = new OutlookBarItem("Outlook Shortcuts", true);
FlatButton inbox = item.addButton("Inbox", getImage("outlook_inbox.gif"), getImage("outlook_inbox16.gif"));
OutlookBarButtonListener listener = new OutlookBarButtonListener(item);
inbox.addActionListener(listener);
item.addButton("Calendar", getImage("outlook_calendar.gif"), getImage("outlook_calendar16.gif"));
item.addButton("Contacts", getImage("outlook_contacts.gif"), getImage("outlook_contacts16.gif"));
outlook.addItem(item);
item = new OutlookBarItem("My Shortcuts", false);
for (int i = 0; i < 6; i++)
{
item.addButton("outlook" + i, getImage("outlook_calendar.gif"), getImage("outlook_contacts16.gif") );
}
outlook.addItem(item);
item = new OutlookBarItem("Other Shortcuts", true);
item.addButton("Inbox", getImage("outlook_inbox.gif"), getImage("outlook_inbox16.gif"));
item.addButton("Calendar", getImage("outlook_calendar.gif"), getImage("outlook_calendar16.gif"));
outlook.addItem(item);
return outlook;
}
static class OutlookBarButtonListener implements ActionListener
{
OutlookBarItem _item;
public OutlookBarButtonListener(OutlookBarItem item)
{
_item = item;
}
public void actionPerformed(ActionEvent e)
{
System.out.println( "button clicked" );
}
}
private static JMenuBar createMenus()
{
JMenuBar menuBar = new JMenuBar();
JMenu fileMenu = menuBar.add( new JMenu( "File" ) );
createMenuItem( fileMenu, "new", "new.gif");
createMenuItem( fileMenu, "open", "open.gif");
createMenuItem( fileMenu, "save", "save.gif");
return menuBar;
}
private static ImageIcon getImage(String imageFileName)
{
return new ImageIcon(Outlook.class.getResource( "/images/" + imageFileName ) );
}
private static JMenuItem createMenuItem( JMenu menu, String label, String icon)
{
JMenuItem mi = menu.add( new JMenuItem( label ) );
mi.setIcon(getImage(icon));
return mi;
}
public static CFrame getFrame()
{
return _frame;
}
public static void setFrame(CFrame f)
{
_frame = f;
}
public static void main(String[] args)
{
try
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e)
{
System.out.println( "setLookAndFeel failed..................." );
}
_frame = createFrame();
}
}