📄 zprintpreviewframe.java
字号:
/*
* Copyright 2002 EZCell , Inc. All rights reserved.
* Version 1.0.7.
* Author W.John
*/
package ezcell;
import java.awt.*;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.*;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JToggleButton;
import javax.swing.JToolBar;
/**
* put your documentation comment here
*/
class ZPrintPreviewFrame extends JFrame {
private _PrintPreviewToolBar toolbar = new _PrintPreviewToolBar(this);
private JLabel pageNumber = new JLabel();
// viewer
private ZPrintPreview viewer;
// current document
private ZDocument doc;
private ZPage currentPage;
// current page info
private int pageIndex;
private Dimension zoomedPageSize = new Dimension(400, 600); //
private float scale = 1.0f;
/**
* put your documentation comment here
* @param ZDocument document
*/
public ZPrintPreviewFrame(ZDocument doc) {
super();
this.doc = doc;
zoomedPageSize = new Dimension(doc.getPage(0).getWidth(),
doc.getPage(0).getHeight());
init();
// center in the desktop
}
/**
* put your documentation comment here
* @param enable
*/
public void setMarginable(boolean enable) {
viewer.setMarginable(enable);
}
/**
* put your documentation comment here
*/
public void firstPage() {
pageIndex = 0;
renderPage();
}
/**
* put your documentation comment here
*/
public void lastPage() {
pageIndex = doc.getPageCount() - 1;
renderPage();
}
/**
* put your documentation comment here
*/
public void nextPage() {
pageIndex++;
if (pageIndex > (doc.getPageCount() - 1)) {
pageIndex--;
}
renderPage();
}
/**
* put your documentation comment here
*/
public void previousPage() {
pageIndex--;
if (pageIndex < 0) {
pageIndex = 0;
}
renderPage();
}
/**
* put your documentation comment here
*/
public void print() {
try {
ZPrinter.getPrinter().print(doc, false);
} catch (Exception ex) {
}
}
/**
* put your documentation comment here
*/
public void zoomIn() {
if (scale > 5.0) {
return;
}
scale += ((scale > 0.9) ? 0.5 : 0.1);
doc.setScale(scale);
}
/**
* put your documentation comment here
*/
public void zoomOut() {
if (scale < 0.3) {
return;
}
scale -= ((scale > 1) ? 0.5 : 0.1);
doc.setScale(scale);
}
/**
* put your documentation comment here
*/
private void init() {
//--- Init this frame
this.getContentPane().setLayout(new BorderLayout());
JPanel toolbarPanel = new JPanel();
toolbarPanel.setLayout(new BorderLayout());
toolbarPanel.add(toolbar, BorderLayout.CENTER);
pageNumber.setPreferredSize(new Dimension(60, 30));
toolbarPanel.add(pageNumber, BorderLayout.EAST);
ZSheetState us = new ZSheetState(doc.getPage(0).getBody().getSheet());
viewer = new ZPrintPreview(doc, ZDocument.NONE);
this.getContentPane().add(toolbarPanel, BorderLayout.NORTH);
this.getContentPane().add(viewer, BorderLayout.CENTER);
this.setTitle("Print preview:" + doc.getTitle());
// this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
doc.setScale(.5f);
this.pack();
Dimension ss = Toolkit.getDefaultToolkit().getScreenSize();
Dimension cs = getSize();
setLocation((ss.width - cs.width) / 2, (ss.height - cs.height) / 2);
this.show();
//--- Init the pagePanel
// toolbarPanel.setBackground(Color.white);
renderPage();
}
/**
* put your documentation comment here
*/
private void renderPage() {
doc.setPage(doc.getPage(pageIndex));
pageNumber.setText((pageIndex + 1) + "/" + doc.getPageCount());
}
/**
* put your documentation comment here
*/
public class _PrintPreviewToolBar extends JToolBar
implements ActionListener {
private JButton firstPage = new ZToolButton();
private JButton lastPage = new ZToolButton();
private JButton nextPage = new ZToolButton();
private JButton previousPage = new ZToolButton();
private JButton zoomIn = new ZToolButton();
private JButton zoomOut = new ZToolButton();
private JButton print = new ZToolButton();
ZPrintPreviewFrame frame;
/**
* put your documentation comment here
* @param ZPrintPreviewFrame frame
*/
public _PrintPreviewToolBar(ZPrintPreviewFrame frame) {
super();
this.frame = frame;
// this.setRollover(true) ;// only work for jdk1.4
init();
}
/**
* Method: actionPerformed <p>
*
* @param parEvent a value of type ActionEvent
*/
public void actionPerformed(ActionEvent parEvent) {
String command = parEvent.getActionCommand();
if (command.equals("nextPage")) {
frame.nextPage();
} else if (command.equals("previousPage")) {
frame.previousPage();
} else if (command.equals("firstPage")) {
frame.firstPage();
} else if (command.equals("lastPage")) {
frame.lastPage();
} else if (command.equals("print")) {
frame.print();
} else if (command.equals("zoomIn")) {
frame.zoomIn();
} else if (command.equals("zoomOut")) {
frame.zoomOut();
} else if (command.equals("marginable")) {
frame.setMarginable(((JToggleButton) parEvent.getSource()).isSelected());
}
}
/**
* put your documentation comment here
*/
private void init() {
try {
//--- Init the buttons
firstPage.setIcon(
new ImageIcon(getClass().getResource("/icons/FirstPage.gif")));
firstPage.setActionCommand("firstPage");
firstPage.addActionListener(this);
firstPage.setMaximumSize(new Dimension(25, 25));
previousPage.setIcon(
new ImageIcon(getClass().getResource("/icons/previouspage.gif")));
previousPage.setActionCommand("previousPage");
previousPage.addActionListener(this);
nextPage.setIcon(
new ImageIcon(getClass().getResource("/icons/nextpage.gif")));
nextPage.setActionCommand("nextPage");
nextPage.addActionListener(this);
lastPage.setIcon(
new ImageIcon(getClass().getResource("/icons/lastpage.gif")));
lastPage.setActionCommand("lastPage");
lastPage.addActionListener(this);
zoomIn.setIcon(
new ImageIcon(getClass().getResource("/icons/lastpage.gif")));
zoomIn.setActionCommand("zoomIn");
zoomIn.addActionListener(this);
// zoomIn.setEnabled(false);
zoomOut.setIcon(
new ImageIcon(getClass().getResource("/icons/zoomout.gif")));
zoomOut.setActionCommand("zoomOut");
zoomOut.addActionListener(this);
// zoomOut.setEnabled(false);
JToggleButton marginable = new ZToggleToolButton();
marginable.setIcon(
new ImageIcon(getClass().getResource("/icons/marginer.gif")));
marginable.setActionCommand("marginable");
marginable.addActionListener(this);
marginable.setSelected(true);
print.setIcon(new ImageIcon(getClass().getResource("/icons/Print.gif")));
print.setActionCommand("print");
print.addActionListener(this);
//--- Init the toolbar
this.add(firstPage);
this.add(previousPage);
this.add(nextPage);
this.add(lastPage);
this.add(zoomIn);
this.add(zoomOut);
this.add(marginable);
this.add(print);
} catch (Exception e) {
}
}
}
class ZToolButton extends JButton {
public Insets getInsets() {
return new Insets(4, 4, 4, 4);
}
}
class ZToggleToolButton extends JToggleButton {
public Insets getInsets() {
return new Insets(4, 4, 4, 4);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -