📄 ezcelldemo.java
字号:
* DOCUMENT ME!
*
* @param e DOCUMENT ME!
*/
void onViewZoomTo(ActionEvent e) {
float scale = 1.0f;
if (e.getSource() instanceof JRadioButtonMenuItem) {
switch (Integer.parseInt(e.getActionCommand())) {
case VIEW_ZOOM_TO_200:
scale = 2.0f;
break;
case VIEW_ZOOM_TO_100:
scale = 1.0f;
break;
case VIEW_ZOOM_TO_75:
scale = .75f;
break;
case VIEW_ZOOM_TO_50:
scale = .50f;
break;
case VIEW_ZOOM_TO_25:
scale = .25f;
break;
}
} else if (e.getSource() instanceof JComboBox) {
String text = (String) ((JComboBox) e.getSource()).getSelectedItem();
text = text.substring(0, text.length() - 1);
scale = Float.parseFloat(text) / 100;
}
cellBean.zoom(scale);
}
/**
* DOCUMENT ME!
*
* @return DOCUMENT ME!
*/
private JFileChooser getFileChooser() {
if (fileChooser == null) {
// prepare file chooser
fileChooser = new JFileChooser();
fileChooser.setCurrentDirectory(new File("."));
fileChooser.setFileFilter(new SimpleFilter("cell", "ZCell Document"));
ZToolkit.moveCenter(this, fileChooser);
}
return fileChooser;
}
/**
* DOCUMENT ME!
*
* @param message DOCUMENT ME!
*/
private void alert(String message) {
JOptionPane.showMessageDialog(null, message, "alert", JOptionPane.ERROR_MESSAGE);
}
/**
* DOCUMENT ME!
*
* @param comp DOCUMENT ME!
*
* @return DOCUMENT ME!
*/
private boolean contain(JComponent comp) {
Component[] comps = getContentPane().getComponents();
for (int i = 0; i < comps.length; i++)
if (comps[i] == comp) {
return true;
}
return false;
}
/**
* DOCUMENT ME!
*/
private void init() {
setSize(800, 600);
((JMenuItem) ahs[EDIT_UNDO].getValue("MENU")).setEnabled(false);
((JButton) ahs[EDIT_UNDO].getValue("BUTTON")).setEnabled(false);
((JMenuItem) ahs[EDIT_REDO].getValue("MENU")).setEnabled(false);
((JButton) ahs[EDIT_REDO].getValue("BUTTON")).setEnabled(false);
// 初始化缩放菜单位项及按钮
JComboBox scales = new JComboBox(
new String[] { "200%", "100%", "75%", "50%", "25%" });
scales.setMaximumSize(scales.getPreferredSize());
scales.setEditable(false);
scales.setSelectedIndex(1);
ahs[VIEW_ZOOM_TO].addButton(scales);
//创建字体选择组合框
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
String[] names = ge.getAvailableFontFamilyNames();
JComboBox fontNames = new JComboBox(names);
fontNames.setMaximumSize(fontNames.getPreferredSize());
fontNames.setEditable(false);
ahs[FORMAT_FONT_NAME].addButton(fontNames);
// 创建字体大小选择框
JComboBox fontSizes = new JComboBox(
new String[] {
"8", "9", "10", "11", "12", "14", "16", "18", "20", "22", "24", "26", "28",
"36", "48", "72"
});
fontSizes.setMaximumSize(fontSizes.getPreferredSize());
fontSizes.setEditable(false);
ahs[FORMAT_FONT_SIZE].addButton(fontSizes);
// 创建前景背景色选择框
JComboBox textColor = new ZColorPicker(
new ImageIcon("/icons/forecolor.gif").getImage());
JComboBox backColor = new ZColorPicker(
new ImageIcon("/icons/backcolor.gif").getImage());
ahs[FORMAT_TEXT_COLOR].addButton(textColor);
ahs[FORMAT_BACK_COLOR].addButton(backColor);
// 创建数字格式化选择框
String[] fis = new String[] {
"None", "###,##0.0", "###,##0.00", "###,##0.000", "###,##0.0000",
"###,##0.00000"
};
JComboBox formatter = new JComboBox(fis);
formatter.setMaximumSize(formatter.getPreferredSize());
ahs[FORMAT_NUMBER_FORMAT].addButton(formatter);
setJMenuBar(loadMenus());
toolpane = loadTools();
// 创建EZCell JavaBean ,并加入侦听器,便于让框架类更改相应的菜单及按钮设置
cellBean = new EZCell();
cellBean.addListener(this);
getContentPane().add(toolpane, BorderLayout.NORTH);
getContentPane().add(cellBean, BorderLayout.CENTER);
//
// window event
WindowListener wndCloser = new WindowAdapter() {
/**
* put your documentation comment here
* @param e
*/
public void windowClosing(WindowEvent e) {
System.exit(0);
}
};
addWindowListener(wndCloser);
updateUI();
setVisible(true);
//this.pack() ;
this.setTitle("ZCell v1.00 [" + cellBean.getFileName() + "]");
// 使bean 获得焦点
cellBean.requestFocus();
}
/**
* DOCUMENT ME!
*
* @return DOCUMENT ME!
*/
private JMenuBar loadMenus() {
fileMN = new JMenu("File");
editMN = new JMenu("Edit");
searchMN = new JMenu("Search");
viewMN = new JMenu("View");
formatMN = new JMenu("Format");
databaseMN = new JMenu("Database");
// file //////////////////////////////////////////////
////////////////////////////////////////////////////////
fileMN.add((JMenuItem) ahs[FILE_NEW].getValue("MENU"));
fileMN.add((JMenuItem) ahs[FILE_OPEN].getValue("MENU"));
fileMN.add((JMenuItem) ahs[FILE_SAVE].getValue("MENU"));
fileMN.add((JMenuItem) ahs[FILE_SAVEAS].getValue("MENU"));
fileMN.addSeparator();
fileMN.add((JMenuItem) ahs[FILE_PRINT].getValue("MENU"));
fileMN.add((JMenuItem) ahs[FILE_PRRINTSETUP].getValue("MENU"));
fileMN.add((JMenuItem) ahs[FILE_PRINTPREVIEW].getValue("MENU"));
fileMN.addSeparator();
fileMN.add((JMenuItem) ahs[FILE_EXPORT_AS_POSTSCRIPT].getValue("MENU"));
fileMN.addSeparator();
fileMN.add((JMenuItem) ahs[FILE_EXIT].getValue("MENU"));
// edit //////////////////////////////////////////////
////////////////////////////////////////////////////////
editMN.add((JMenuItem) ahs[EDIT_UNDO].getValue("MENU"));
editMN.add((JMenuItem) ahs[EDIT_REDO].getValue("MENU"));
editMN.addSeparator();
editMN.add((JMenuItem) ahs[EDIT_COPY].getValue("MENU"));
editMN.add((JMenuItem) ahs[EDIT_CUT].getValue("MENU"));
editMN.add((JMenuItem) ahs[EDIT_PASTE].getValue("MENU"));
editMN.add((JMenuItem) ahs[EDIT_PASTE_WITH_FORMAT].getValue("MENU"));
editMN.add((JMenuItem) ahs[EDIT_CLEAR].getValue("MENU"));
editMN.add((JMenuItem) ahs[EDIT_CLEAR_WITH_FORMAT].getValue("MENU"));
editMN.addSeparator();
editMN.add((JMenuItem) ahs[EDIT_CHECK_SPELL].getValue("MENU"));
editMN.addSeparator();
editMN.add((JMenuItem) ahs[EDIT_DELETE_ROW].getValue("MENU"));
editMN.add((JMenuItem) ahs[EDIT_INSERT_ROW].getValue("MENU"));
editMN.add((JMenuItem) ahs[EDIT_DELETE_COL].getValue("MENU"));
editMN.add((JMenuItem) ahs[EDIT_INSERT_COL].getValue("MENU"));
editMN.addSeparator();
editMN.add((JMenuItem) ahs[EDIT_DELETE_SHEET].getValue("MENU"));
editMN.add((JMenuItem) ahs[EDIT_INSERT_SHEET].getValue("MENU"));
editMN.addSeparator();
editMN.add((JMenuItem) ahs[EDIT_SHEET_PROPERTY].getValue("MENU"));
editMN.add((JMenuItem) ahs[EDIT_BOOK_PROPERTY].getValue("MENU"));
// view //////////////////////////////////////////////
////////////////////////////////////////////////////////
viewMN.add((JMenuItem) ahs[VIEW_TOGGLE_TOOLBAR].getValue("MENU"));
viewMN.add((JMenuItem) ahs[VIEW_TOGGLE_SCROLLBAR].getValue("MENU"));
viewMN.add((JMenuItem) ahs[VIEW_TOGGLE_TOP_HEADER].getValue("MENU"));
viewMN.add((JMenuItem) ahs[VIEW_TOGGLE_LEFT_HEADER].getValue("MENU"));
viewMN.add((JMenuItem) ahs[VIEW_TOGGLE_GRID_X].getValue("MENU"));
viewMN.add((JMenuItem) ahs[VIEW_TOGGLE_GRID_Y].getValue("MENU"));
viewMN.add((JMenuItem) ahs[VIEW_TOGGLE_SELECTION].getValue("MENU"));
viewMN.addSeparator();
viewMN.add((JMenuItem) ahs[VIEW_ZOOM_IN].getValue("MENU"));
viewMN.add((JMenuItem) ahs[VIEW_ZOOM_OUT].getValue("MENU"));
ButtonGroup group = new ButtonGroup();
JMenu zoomTo = (JMenu) ahs[VIEW_ZOOM_TO].getValue("MENU");
zoomTo.add((JMenuItem) ahs[VIEW_ZOOM_TO_200].getValue("MENU"));
zoomTo.add((JMenuItem) ahs[VIEW_ZOOM_TO_100].getValue("MENU"));
zoomTo.add((JMenuItem) ahs[VIEW_ZOOM_TO_75].getValue("MENU"));
zoomTo.add((JMenuItem) ahs[VIEW_ZOOM_TO_50].getValue("MENU"));
zoomTo.add((JMenuItem) ahs[VIEW_ZOOM_TO_25].getValue("MENU"));
group.add((JRadioButtonMenuItem) ahs[VIEW_ZOOM_TO_200].getValue("MENU"));
group.add((JRadioButtonMenuItem) ahs[VIEW_ZOOM_TO_100].getValue("MENU"));
group.add((JRadioButtonMenuItem) ahs[VIEW_ZOOM_TO_75].getValue("MENU"));
group.add((JRadioButtonMenuItem) ahs[VIEW_ZOOM_TO_50].getValue("MENU"));
group.add((JRadioButtonMenuItem) ahs[VIEW_ZOOM_TO_25].getValue("MENU"));
viewMN.add(zoomTo);
viewMN.addSeparator();
viewMN.add((JMenuItem) ahs[VIEW_PAGE].getValue("MENU"));
viewMN.addSeparator();
viewMN.add((JMenuItem) ahs[VIEW_OPTION].getValue("MENU"));
// search //////////////////////////////////////////////
////////////////////////////////////////////////////////
searchMN.add((JMenuItem) ahs[SEARCH_FIND].getValue("MENU"));
searchMN.add((JMenuItem) ahs[SEARCH_REPLACE].getValue("MENU"));
searchMN.add((JMenuItem) ahs[SEARCH_FIND_NEXT].getValue("MENU"));
searchMN.add((JMenuItem) ahs[SEARCH_GOTO].getValue("MENU"));
// format //////////////////////////////////////////////
////////////////////////////////////////////////////////
formatMN.add((JMenuItem) ahs[FORMAT_FONT].getValue("MENU"));
formatMN.add((JMenuItem) ahs[FORMAT_TEXT_BRUSH].getValue("MENU"));
formatMN.add((JMenuItem) ahs[FORMAT_BACK_BRUSH].getValue("MENU"));
group = new ButtonGroup();
JMenu alignMenu = (JMenu) ahs[FORMAT_ALIGN_X].getValue("MENU");
alignMenu.add((JMenuItem) ahs[FORMAT_ALIGN_LEFT].getValue("MENU"));
alignMenu.add((JMenuItem) ahs[FORMAT_ALIGN_X_CENTER].getValue("MENU"));
alignMenu.add((JMenuItem) ahs[FORMAT_ALIGN_RIGHT].getValue("MENU"));
group.add((JRadioButtonMenuItem) ahs[FORMAT_ALIGN_LEFT].getValue("MENU"));
group.add((JRadioButtonMenuItem) ahs[FORMAT_ALIGN_X_CENTER].getValue("MENU"));
group.add((JRadioButtonMenuItem) ahs[FORMAT_ALIGN_RIGHT].getValue("MENU"));
formatMN.add(alignMenu);
///// FORMAT_ALIGN_Y group
group = new ButtonGroup();
alignMenu = (JMenu) ahs[FORMAT_ALIGN_Y].getValue("MENU");
alignMenu.add((JMenuItem) ahs[FORMAT_ALIGN_TOP].getValue("MENU"));
alignMenu.add((JMenuItem) ahs[FORMAT_ALIGN_Y_CENTER].getValue("MENU"));
alignMenu.add((JMenuItem) ahs[FORMAT_ALIGN_BOTTOM].getValue("MENU"));
group.add((JRadioButtonMenuItem) ahs[FORMAT_ALIGN_TOP].getValue("MENU"));
group.add((JRadioButtonMenuItem) ahs[FORMAT_ALIGN_Y_CENTER].getValue("MENU"));
group.add((JRadioButtonMenuItem) ahs[FORMAT_ALIGN_BOTTOM].getValue("MENU"));
formatMN.add(alignMenu);
formatMN.add((JMenuItem) ahs[FORMAT_ALIGN_X].getValue("MENU"));
formatMN.add((JMenuItem) ahs[FORMAT_ALIGN_Y].getValue("MENU"));
formatMN.add((JMenuItem) ahs[FORMAT_WORD_WRAP].getValue("MENU"));
formatMN.add((JMenuItem) ahs[FORMAT_BORDER].getValue("MENU"));
formatMN.add((JMenuItem) ahs[FORMAT_MERGE].getValue("MENU"));
formatMN.add((JMenuItem) ahs[FORMAT_NUMBER_FORMAT].getValue("MENU"));
formatMN.addSeparator();
formatMN.add((JMenuItem) ahs[FORMAT_ROWS_HEIGHT].getValue("MENU"));
formatMN.add((JMenuItem) ahs[FORMAT_COLS_WIDTH].getValue("MENU"));
// edit //////////////////////////////////////////////
////////////////////////////////////////////////////////
databaseMN.add((JMenuItem) ahs[DATABASE_IMPORT_DATASET].getValue("MENU"));
JMenuBar mb = new JMenuBar();
mb.add(fileMN);
mb.add(editMN);
mb.add(searchMN);
mb.add(viewMN);
mb.add(formatMN);
mb.add(databaseMN);
return mb;
}
/**
* DOCUMENT ME!
*
* @return DOCUMENT ME!
*/
private JPanel loadTools() {
fileTB = new JToolBar();
editTB = new JToolBar();
searchTB = new JToolBar();
viewTB = new JToolBar();
formatTB = new JToolBar();
//file ////////////////////////////////////////////////
///////////////////////////////////////////////////////
fileTB.add((JComponent) ahs[FILE_NEW].getValue("BUTTON"));
fileTB.add((JComponent) ahs[FILE_OPEN].getValue("BUTTON"));
fileTB.add((JComponent) ahs[FILE_SAVE].getValue("BUTTON"));
fileTB.add((JComponent) ahs[FILE_PRINT].getValue("BUTTON"));
fileTB.add((JComponent) ahs[FILE_PRINTPREVIEW].getValue("BUTTON"));
//edit /////////////////////////////////////////////////
///////////////////////////////////////////////////////
editTB.add((JComponent) ahs[EDIT_UNDO].getValue("BUTTON"));
editTB.add((JComponent) ahs[EDIT_REDO].getValue("BUTTON"));
editTB.add((JComponent) ahs[EDIT_COPY].getValue("BUTTON"));
editTB.add((JComponent) ahs[EDIT_CUT].getValue("BUTTON"));
editTB.add((JComponent) ahs[EDIT_PASTE].getValue("BUTTON"));
editTB.add((JComponent) ahs[EDIT_CLEAR].getValue("BUTTON"));
editTB.addSeparator();
editTB.add((JComponent) ahs[EDIT_DELETE_ROW].getValue("BUTTON"));
editTB.add((JComponent) ahs[EDIT_INSERT_ROW].getValue("BUTTON"));
editTB.add((JComponent) ahs[EDIT_DELETE_COL].getValue("BUTTON"));
editTB.add((JComponent) ahs[EDIT_INSERT_COL].getValue("BUTTON"));
//view ////////////////////////////////////////////////
///////////////////////////////////////////////////////
viewTB.add((JComponent) ahs[VIEW_ZOOM_IN].getValue("BUTTON"));
viewTB.add((JComponent) ahs[VIEW_ZOOM_TO].getValue("BUTTON"));
viewTB.add((JComponent) ahs[VIEW_ZOOM_OUT].getValue("BUTTON"));
viewTB.addSeparator();
viewTB.add((JComponent) ahs[VIEW_PAGE].getValue("BUTTON"));
// viewTB.add(new JLabel("<html><body><blockquote><p><a href=\"http://www.ezcell.net\">www.ezcell.net</a></p></blockquote></body></html>"));
//search ////////////////////////////////////////////////
///////////////////////////////////////////////////////
searchTB.add((JComponent) ahs[SEARCH_FIND].getValue("BUTTON"));
//format ////////////////////////////////////////////////
///////////////////////////////////////////////////////
formatTB.add((JComponent) ahs[FORMAT_FONT_NAME].getValue("BUTTON"));
formatTB.add((JComponent) ahs[FORMAT_FONT_SIZE].getValue("BUTTON"));
formatTB.add((JComponent) ahs[FORMAT_FONT_BOLD].getValue("BUTTON"));
formatTB.add((JComponent) ahs[FORMAT_FONT_ITALIC].getValue("BUTTON"));
formatTB.add((JComponent) ahs[FORMAT_FONT_PLAIN].getValue("BUTTON"));
formatTB.add((JComponent) ahs[FORMAT_FONT_OUTLINE].getValue("BUTTON"));
formatTB.addSeparator();
formatTB.add((JComponent) ahs[FORMAT_TEXT_COLOR].getValue("BUTTON"));
formatTB.add((JComponent) ahs[FORMAT_BACK_COLOR].getValue("BUTTON"));
formatTB.addSeparator();
formatTB.add((JComponent) ahs[FORMAT_ALIGN_LEFT].getValue("BUTTON"));
formatTB.add((JComponent) ahs[FORMAT_ALIGN_RIGHT].getValue("BUTTON"));
formatTB.add((JComponent) ahs[FORMAT_ALIGN_X_CENTER].getValue("BUTTON"));
ButtonGroup group = new ButtonGroup();
group.add(ahs[FORMAT_ALIGN_LEFT].getButton());
group.add(ahs[FORMAT_ALIGN_RIGHT].getButton());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -