?? reogviewer.java
字號:
package com.sutternow.swingkar;
import com.sutternow.swingkar.ConfigManager;
import com.sutternow.swingkar.help.HelpViewer;
import com.sutternow.swingkar.gui.*;
import com.sutternow.swingkar.tree.*;
import com.incors.plaf.kunststoff.KunststoffLookAndFeel;
import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.io.PrintStream;
import java.io.PipedOutputStream;
import java.io.PipedInputStream;
import java.io.IOException;
import org.dom4j.Element;
import org.dom4j.Node;
public class ReogViewer implements Runnable, ActionListener {
public JFrame getViewFrame() {
return this.reogFrame;
}
public ReogViewer(String configFileName) {
try {
cm = new ConfigManager(configFileName);
} catch (Exception e) {
e.printStackTrace();
}
this.initializeLookAndFeel();
this.initGUI();
this.addListeners();
}
public ReogViewer() {
cm = new ConfigManager();
cm.loadEmptyTree();
this.initializeLookAndFeel();
this.initGUI();
this.addListeners();
}
public final void initializeLookAndFeel () {
try {
KunststoffLookAndFeel lnf = new KunststoffLookAndFeel();
lnf.setCurrentTheme(new com.incors.plaf.kunststoff.KunststoffTheme());
UIManager.setLookAndFeel(lnf);
} catch (Exception e) {
e.printStackTrace();
}
}
private void initGUI() {
reogFrame = new JFrame();
reogFrame.setTitle("Reog Configuration");
Dimension screenSize =
Toolkit.getDefaultToolkit().getScreenSize();
reogFrame.setSize(screenSize.width - 250, screenSize.height - 300);
// set up menu
JMenuBar menuBar = new JMenuBar();
reogFrame.setJMenuBar(menuBar);
JMenu fileMenu = new JMenu("File");
menuBar.add(fileMenu);
newItem = new JMenuItem("New");
fileMenu.add(newItem);
openItem = new JMenuItem("Open");
fileMenu.add(openItem);
saveItem = new JMenuItem("Save");
fileMenu.add(saveItem);
saveAsItem = new JMenuItem("Save As");
fileMenu.add(saveAsItem);
fileMenu.addSeparator();
generateAppItem = new JMenuItem("Generate");
fileMenu.add(generateAppItem);
reverseDBItem = new JMenuItem("Reverse");
fileMenu.add(reverseDBItem);
fileMenu.addSeparator();
exitItem = new JMenuItem("Exit");
fileMenu.add(exitItem);
JMenu optionsMenu = new JMenu("Options");
menuBar.add(optionsMenu);
preferencesItem = new JMenuItem("Preferences");
optionsMenu.add(preferencesItem);
templatesItem = new JMenuItem("Bean Templates");
optionsMenu.add(templatesItem);
dumpItem = new JMenuItem("Dump");
optionsMenu.add(dumpItem);
JMenu helpMenu = new JMenu("Help");
menuBar.add(helpMenu);
helpIndexItem = new JMenuItem("Index");
helpMenu.add(helpIndexItem);
helpAboutItem = new JMenuItem("About");
helpMenu.add(helpAboutItem);
try {
// cm = new ConfigManager(configFileName);
tree = prepareXmlTree();
} catch (Exception e) {
e.printStackTrace();
}
tabPane = new JTabbedPane();
consoleArea = new JTextArea();
JScrollPane textScroll = new JScrollPane(consoleArea);
consoleMenu = new JPopupMenu();
clearItem = new JMenuItem("Clear");
selectAllItem = new JMenuItem("Select All");
consoleMenu.add(clearItem);
consoleMenu.add(selectAllItem);
consoleArea.add(consoleMenu);
JSplitPane hsplit;
hsplit = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(tree),
tabPane);
hsplit.setDividerLocation(200);
JSplitPane vsplit;
vsplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT, hsplit, textScroll);
vsplit.setDividerLocation(reogFrame.getHeight() - (reogFrame.getHeight() / 4));
reogFrame.getContentPane().add(vsplit);
pp = new ProjectProperties(cm);
dbEditPane = new DatabaseEditPane(cm);
gvep = new GlobalValueEditPane(cm);
buildEditPane = new BuildEditPane(cm);
scp = new SecurityConstraintPane(cm);
bep = new BeanEditPane(cm);
cep = new ColumnEditPane(cm);
gref = new GlobalReferencePane(cm);
qep = new QueryEditPane(cm);
pep = new ProcessEditPane(cm);
mep = new MenuEditPane(cm);
tabMap = new HashMap();
tabMap.put("ProjectPropertiesEditTab", pp);
tabMap.put("BuildEditTab", buildEditPane);
tabMap.put("DatabaseEditTab", dbEditPane);
tabMap.put("GlobalValueEditTab", gvep);
tabMap.put("BeanEditTab", bep);
tabMap.put("SecurityEditTab", scp);
tabMap.put("ColumnEditTab", cep);
tabMap.put("GlobalRefTab", gref);
tabMap.put("QueryEditTab", qep);
tabMap.put("ProcessEditTab", pep);
tabMap.put("MenuEditTab", mep);
this.loadEditPane(ProjectPropertiesEditTab, (Element)cm.getBaseDocument().selectSingleNode("/strutscreator/property"));
}
private void addListeners() {
openItem.addActionListener(new
ActionListener() {
public void actionPerformed(ActionEvent event) {
String configFileName = XmlFileChooser.doChoose("Reog Files");
if (configFileName != null) {
try {
tree.removeAll();
DefaultMutableTreeNode oldRoot = (DefaultMutableTreeNode) tree.getModel().getRoot();
oldRoot.removeFromParent();
cm.loadNewConfig(configFileName);
refillModel();
} catch (Exception e) {
e.printStackTrace();
}
}
}
});
newItem.addActionListener(this);
saveItem.addActionListener(this);
saveAsItem.addActionListener(this);
reverseDBItem.addActionListener(this);
generateAppItem.addActionListener(this);
exitItem.addActionListener(this);
dumpItem.addActionListener(this);
preferencesItem.addActionListener(this);
templatesItem.addActionListener(this);
helpIndexItem.addActionListener(this);
consoleArea.addMouseListener(new consoleMenuListener());
clearItem.addActionListener(this);
selectAllItem.addActionListener(this);
changeMonitor = new Timer(500, new
ActionListener() {
public void actionPerformed(ActionEvent event) {
if (cm.isRefreshNeeded()) {
tree.revalidate();
tree.repaint();
try {
//tree = prepareXmlTree();
// refillModel();
} catch (Exception e) {
e.printStackTrace(); //To change body of catch statement use Options | File Templates.
}
cm.doRefresh();
System.out.println("Doing Refresh");
}
}
});
/* setup pipe to redirect System.out to consoleArea */
try {
PipedOutputStream pout = new PipedOutputStream(this.pin);
System.setOut(new PrintStream(pout, true));
} catch (java.io.IOException io) {
consoleArea.append("Couldn't redirect STDOUT to this console\n" + io.getMessage());
} catch (SecurityException se) {
consoleArea.append("Couldn't redirect STDOUT to this console\n" + se.getMessage());
}
reader = new Thread(this);
reader.setDaemon(true);
reader.start();
changeMonitor.start();
}
public void actionPerformed(ActionEvent ae) {
Object eventSource = ae.getSource();
if (eventSource == newItem) {
cm.loadEmptyTree();
this.refillModel();
} else if (eventSource == reverseDBItem) {
cm.doReverse();
cm.doRefresh();
} else if (eventSource == dumpItem) {
synchronized(consoleArea) {
consoleArea.setText(cm.getBaseDocument().asXML());
}
} else if (eventSource == preferencesItem) {
PreferencesFrame prefFrame = new PreferencesFrame(cm);
prefFrame.setValues();
prefFrame.showEditForm();
} else if (eventSource == templatesItem) {
TemplateManagerPane tm = new TemplateManagerPane(cm.getTemplateDefinitions());
tm.showEditForm();
} else if (eventSource == generateAppItem) {
cm.doGeneration();
} else if(eventSource == helpIndexItem) {
HelpViewer browser = new HelpViewer();
browser.setSize( 640, 480 );
browser.setVisible( true );
} else if (eventSource == exitItem) {
quit = true;
// this.notify();// stop all threads
try {
reader.join(1000);
pin.close();
} catch (Exception e) {
}
System.exit(0);
} else if (eventSource == saveItem) {
cm.saveChanges();
} else if (eventSource == saveAsItem) {
JFileChooser fc = new JFileChooser();
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -