📄 mainwindow.java
字号:
if (cmd.fetchLimit > 0) { echoBuffer.append(cmd.fetchLimit).append(" "); } echoBuffer.append("\"").append(cmd.qual).append("\""); break; case LibgistCommand.CREATE: echoBuffer.append("create ").append(cmd.indexName); echoBuffer.append(" ").append(cmd.extension); break; case LibgistCommand.OPEN: echoBuffer.append("open ").append(cmd.indexName); break; case LibgistCommand.CLOSE: echoBuffer.append("close"); break; case LibgistCommand.FLUSH: echoBuffer.append("flush"); break; case LibgistCommand.OPENANL: echoBuffer.append("openanl ").append(cmd.analysisFile.getPath()); break; case LibgistCommand.CLOSEANL: echoBuffer.append("closeanl"); break; case LibgistCommand.CREATEANL: echoBuffer.append("createanl"); break; case LibgistCommand.SCRIPT: echoBuffer.append("executing script..."); break; default: // something wrong here } consoleFrame.echoCmd(echoBuffer.toString());}///////////////////////////////////////////////////////////////////////////////// updateGuiState - update state of GUI after executed operation//// Description:// - if create/open/openanl was unsuccessful, go to INITSTATE// - insert, delete and search don't change the state, so we // restore the old state//// Exceptions: none///////////////////////////////////////////////////////////////////////////////public voidupdateGuiState(int priorState, LibgistCommand cmd, boolean success){ switch(cmd.cmdType) { case LibgistCommand.CREATE: case LibgistCommand.OPEN: resetState(); if (!success) return; // done setGuiState(IDXOPENSTATE); isOpen = true; idxName = cmd.indexName.toString(); if (cmd.cmdType == LibgistCommand.CREATE) { resetConfig(); } else { restoreConfig(); } //setTitle("amdb: " + filename); setTree(idxName); try { treeView = new TreeView(desktop); // creates a display of the opened index desktop.add(treeView, JLayeredPane.PALETTE_LAYER); } catch (LibgistException e) { // what to do now? consoleFrame.echoInfo("new TreeView() failed"); } break; case LibgistCommand.CLOSE: saveConfig(); resetState(); break; case LibgistCommand.OPENANL: resetState(); if (!success) return; // done // enable menu items and open tree view setGuiState(ANLOPENSTATE); //setTitle("amdb: " + filename); setTree(idxName); try { treeView = new TreeView(desktop); // creates a display of the opened index desktop.add(treeView, JLayeredPane.PALETTE_LAYER); } catch (LibgistException e) { // what to do now? consoleFrame.echoInfo("new TreeView() failed"); } // get ready to display dialogs if (analysisInfo.actualHasWkldStats) { wkldStatsDlg.init(treeView); } if (analysisInfo.actualHasSplitStats) { splitStatsDlg.init(treeView); } if (analysisInfo.actualHasPenaltyStats) { penaltyStatsDlg.init(treeView); } break; case LibgistCommand.CLOSEANL: treeView.dispose(); treeView = null; setGuiState(INITSTATE); setTree(""); break; // if these didn't work, we don't care case LibgistCommand.INSERT: case LibgistCommand.REMOVE: case LibgistCommand.FETCH: case LibgistCommand.FLUSH: case LibgistCommand.CREATEANL: case LibgistCommand.SCRIPT: setGuiState(priorState); break; }}private intstrlen(char[] str){ int len = 0; while (len < str.length && str[len] != '\0') len++; return len;}// ask user for script file and name of new profile// return false if user cancelled operationprivate booleangetNewWkldInput( JFileChooser chooser, Object[] optionDlgMsg, StringBuffer name, StringBuffer scriptFile){ // let user select script file with queries boolean fileOk = false; int retval; File file = null; FileReader reader = null; while (!fileOk) { if ((retval = chooser.showDialog(this, "Ok")) != 0) { return false; } file = chooser.getSelectedFile(); try { reader = new FileReader(file.getPath()); fileOk = true; scriptFile.append(file.getPath()); } catch (FileNotFoundException e) { JOptionPane.showMessageDialog(this, "Selected script file does not exist", "Error: New Profile", JOptionPane.ERROR_MESSAGE); } } // let user select filename for profile int response = JOptionPane.showOptionDialog(this, optionDlgMsg, "New Profile", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, null); if (response != JOptionPane.OK_OPTION) { return false; } JTextField textFld = (JTextField) optionDlgMsg[1]; name.append(file.getParent() + "/" + textFld.getText()); return true;}// create a new profile: read the script and possibly execute the queries,// save the stats (if 'import' == true, we assume the profile already exists// and don't run the queries)public voidcreateWkld(String name, String scriptFile, boolean runQueries){ System.gc(); Workload wkld = new Workload(name); if (showCmdsItem.getState()) { consoleFrame.echoCmd((!runQueries ? "importprof " : "newwkld ") + name + " " + scriptFile); } // construct the Workload object from the script; // first, check if the file exists try { FileReader reader = new FileReader(scriptFile); reader.close(); } catch (FileNotFoundException e) { System.out.println("couldn't open " + scriptFile); return; } catch (IOException e) { System.out.println("couldn't close " + scriptFile); } // now, check if it contains only queries int scriptId = 0; try { scriptId = Libgist.openScript(scriptFile); } catch (LibgistException e) { System.out.println("couldn't open (C) " + scriptFile); return; } char[] arg1 = new char[64*1024]; StringBuffer arg1Buf = new StringBuffer(); char[] arg2 = new char[64*1024]; StringBuffer arg2Buf = new StringBuffer(); //for (;;) { //int cmd = Libgist.getCommand(scriptId, arg1, arg2); //if (cmd == Libgist.EOF) break; //if (cmd != Libgist.FETCH) { // there should only be queries //System.out.println("Script file contains non-SELECT command"); //return; //} //} if (runQueries) { // turn profiling on and execute queries //Libgist.setProfilingEnabled(true); Libgist.disableBps(true); // we don't want to stop at breakpoints // rescan queries try { scriptId = Libgist.openScript(scriptFile); } catch (LibgistException e) { System.out.println("couldn't open (C) " + scriptFile); return; } int cnt = 1; //for (;;) { //int cmd = Libgist.getCommand(scriptId, arg1, arg2); //if (cmd == Libgist.EOF) break; //arg1Buf.setLength(0); //arg1Buf.append(arg1, 0, strlen(arg1)); //arg2Buf.setLength(0); //arg2Buf.append(arg2, 0, strlen(arg2)); //OpThread.execCmd(LibgistCommand.FETCH, arg1Buf.toString(), //arg2Buf.toString(), false); //System.out.print(cnt + " "); //System.out.println(cnt + ": execute " + arg2Buf.toString() + " " //+ arg1Buf.toString()); //cnt++; //} System.out.println(); Libgist.disableBps(false); // compute optimal clustering and some more statistics //Libgist.computeMetrics(wkld.filename); } // save profile try { // we're saving Java and C++ data in separate files (filename and filename.prof) // the profile object only contains the filename, the queries will be // read in from the file when the profile is opened (faster that way) ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(wkld.filename)); out.writeObject(wkld); out.close(); System.out.println("copy query file"); Runtime.getRuntime().exec("cp " + scriptFile + " " + wkld.filename + ".queries"); System.out.println("saving tree and profile"); Libgist.saveToFile(wkld.filename + ".idx"); if (runQueries) { //Libgist.saveProfile(wkld.filename + ".prof"); } } catch (Exception e) { System.out.println("Error saving profile: " + e); return; } if (runQueries) { // turn profiling off (after the metrics were computed and // the profile saved) //Libgist.setProfilingEnabled(false); }}publicMainWindow(){ JMenuItem showTextItem, showContentItem, showStatsItem; JMenuItem consoleWinItem, treeWinItem, traceWinItem; // our libgist execution thread opThread = new OpThread(this); Libgist.setBreakHandler(opThread); opThread.start(); cmd = new LibgistCommand(); menuBar = new JMenuBar(); setJMenuBar(menuBar); // create toolbar and console window with text area getContentPane().removeAll(); getContentPane().setLayout(new BorderLayout()); JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); // desktop pane + console frame desktop = new JDesktopPane(); desktop.setOpaque(true); desktop.setBackground(Color.lightGray); consoleFrame = new ConsoleWindow(200, desktop); desktop.add(consoleFrame, JLayeredPane.PALETTE_LAYER); // debugging actions for toolbar: // notify opThread of what to do when it hits a breakpoint stepAction = new AbstractAction("Step") { public void actionPerformed(ActionEvent e) { opThread.step(); } }; cancelAction = new AbstractAction("Cancel") { public void actionPerformed(ActionEvent e) { scriptWasCancelled = true; // don't call it after next line! opThread.cancel(); } }; nextAction = new AbstractAction("Next") { public void actionPerformed(ActionEvent e) { opThread.next(); } }; contAction = new AbstractAction("Continue") { public void actionPerformed(ActionEvent e) { opThread.cont(); } }; // opThread is currently executing a script and we want it to stop: // tell libgist directly to suspend execution once opThread is done // with the current operation stopAction = new AbstractAction("Stop") { public void actionPerformed(ActionEvent e) { Libgist.singleStep(); } }; // toolbar JToolBar toolbar = new JToolBar(); toolbar.add(stepAction).setText("Step"); toolbar.add(nextAction).setText("Next"); toolbar.add(contAction).setText("Continue"); toolbar.add(stopAction).setText("Stop"); toolbar.add(cancelAction).setText("Cancel"); panel.add(toolbar, BorderLayout.NORTH); panel.add(desktop, BorderLayout.CENTER); getContentPane().add(panel); createFileMenu(); createOpsMenu(); createDebugMenu(); createTreeStatsMenu(); createAnalysisMenu(); createWindowsMenu(); setGuiState(INITSTATE); // nothing opened yet //addWindowListener(this); // So we do the right thing on window closing.}private voidcreateFileMenu(){ fileMenu = new JMenu("File"); menuBar.add(fileMenu); newItem = new JMenuItem("New..."); fileMenu.add(newItem); // construct components of option pane to input name and type of new AM final Object[] newMsg = new Object[3]; newMsg[0] = "Name for new AM:"; final JTextField newName = new JTextField("new-am"); newMsg[1] = newName; final JComboBox cb = new JComboBox(); for (int i = 0; i < Libgist.extInfo.length; i++) { cb.addItem(Libgist.extInfo[i].name); } newMsg[2] = cb; newItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // first close the currently opened index int response = JOptionPane.showOptionDialog(MainWindow.this, newMsg, "New", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, null); if (response != JOptionPane.OK_OPTION) { return; } // create new AM cmd.reset(); cmd.cmdType = LibgistCommand.CREATE; cmd.indexName.append(newName.getText()); cmd.extension.append(Libgist.extInfo[cb.getSelectedIndex()]);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -