/*
* Licensed Materials - Property of Perforce Software, Inc.
* © Copyright Perforce Software, Inc. 2014, 2021
* © Copyright IBM Corp. 2009, 2014
* © Copyright ILOG 1996, 2009
* All Rights Reserved.
*
* Note to U.S. Government Users Restricted Rights:
* The Software and Documentation were developed at private expense and
* are "Commercial Items" as that term is defined at 48 CFR 2.101,
* consisting of "Commercial Computer Software" and
* "Commercial Computer Software Documentation", as such terms are
* used in 48 CFR 12.212 or 48 CFR 227.7202-1 through 227.7202-4,
* as applicable.
*/
package print;
import ilog.views.schedule.IlvResourceDataChart;
import resourceDataChart.ResourceDataChartExample;
import shared.swing.ExampleFrame;
import java.awt.ComponentOrientation;
import java.awt.Window;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JToolBar;
import javax.swing.UIManager;
/**
* This example illustrates the printing capabilities of the Resource Data chart.
*/
public class ResourceDataPrintExample extends ResourceDataChartExample {
/**
* The various menu and toolbar actions.
*/
protected ResourceDataPrintActions.PrintAction printAction;
protected ResourceDataPrintActions.PrintSetupAction printSetupAction;
protected ResourceDataPrintActions.PrintPreviewAction printPreviewAction;
protected ResourceDataPrintActions.SavePDFAction savePDFAction;
/**
* Creates the "File" menu.
*/
Override
public JMenu createFileMenu() {
JMenu menu = super.createFileMenu();
// Temporarily remove the "Exit" item.
int last = menu.getItemCount() - 1;
JMenuItem exitItem = menu.getItem(last);
if (isExitAllowed()) {
menu.remove(exitItem);
}
if (isPrintingConfigured()) {
IlvResourceDataChart chart = getChart();
// Menu item for "Print".
printAction = new ResourceDataPrintActions.PrintAction(chart);
addAction(menu, printAction);
// Menu item for "Print Setup...".
printSetupAction = new ResourceDataPrintActions.PrintSetupAction(chart);
addAction(menu, printSetupAction);
// Menu item for "Preview...".
printPreviewAction = new ResourceDataPrintActions.PrintPreviewAction(chart);
addAction(menu, printPreviewAction);
if (isLocalFileAccessAllowed()) {
// Menu item for "Save As PDF...".
savePDFAction =
new ResourceDataPrintActions.SavePDFAction(chart,
(Window)getTopLevelAncestor());
addAction(menu, savePDFAction);
}
menu.addSeparator();
}
// Append the "Exit" item, if allowed.
if (isExitAllowed()) {
menu.add(exitItem);
}
return menu;
}
/**
* Sets the look-and-feel of the example.
*/
Override
protected void setLookAndFeel(UIManager.LookAndFeelInfo laf) {
super.setLookAndFeel(laf);
// Sets the look & feel on the printing controller too.
if (ResourceDataPrintActions.printController != null) {
ResourceDataPrintActions.printController.setLookAndFeel(laf);
}
}
/**
* Sets the language-sensitive orientation of the example.
* @param o The orientation.
*/
Override
public void setComponentOrientation(ComponentOrientation o) {
super.setComponentOrientation(o);
// Sets the orientation on the printing controller too.
if (ResourceDataPrintActions.printController != null) {
ResourceDataPrintActions.printController.setComponentOrientation(o);
}
}
// =========================================
// Toolbar
// =========================================
/**
* Populates the toolbar file actions.
*/
Override
protected void populateToolBarFileActions(JToolBar toolbar) {
int initialActionCount = toolbar.getComponentCount();
super.populateToolBarFileActions(toolbar);
int fileActions = toolbar.getComponentCount() - initialActionCount;
if (isPrintingConfigured()) {
if (fileActions > 0) {
toolbar.addSeparator();
}
addAction(toolbar, printAction);
addAction(toolbar, printSetupAction);
addAction(toolbar, printPreviewAction);
if (isLocalFileAccessAllowed()) {
addAction(toolbar, savePDFAction);
}
}
}
// =========================================
// Example Application
// =========================================
/**
* Returns the title of the example.
*
* @return The title of the example.
*/
Override
public String getTitle() {
return "Resource Data Chart Print Sample";
}
/**
* Application mainline.
*
* @param args The command line arguments.
*/
public static void main (String[] args) {
ExampleFrame.createAndShowGUI(ResourceDataPrintExample.class);
}
}