📄 documenteditorview.java
字号:
*/ private void setFile(File file) { File oldValue = this.file; this.file = file; String appId = getResourceMap().getString("Application.id"); getFrame().setTitle(file.getName() + " - " + appId); firePropertyChange("file", oldValue, this.file); } /** * True if the file value has been modified but not saved. The * default value of this property is false. * <p> * This is a bound read-only property. * * @return the value of the modified property. * @see #isModified */ public boolean isModified() { return modified; } /* Set the bound modified property and update the GUI. */ private void setModified(boolean modified) { boolean oldValue = this.modified; this.modified = modified; firePropertyChange("modified", oldValue, this.modified); } /** * Prompt the user for a filename and then attempt to load the file. * <p> * The file is loaded on a worker thread because we don't want to * block the EDT while the file system is accessed. To do that, * this Action method returns a new LoadFileTask instance, if the * user confirms selection of a file. The task is executed when * the "open" Action's actionPerformed method runs. The * LoadFileTask is responsible for updating the GUI after it has * successfully completed loading the file. * * @return a new LoadFileTask or null */ @Action public Task open() { JFileChooser fc = createFileChooser("openFileChooser"); int option = fc.showOpenDialog(getFrame()); Task task = null; if (JFileChooser.APPROVE_OPTION == option) { task = new LoadFileTask(fc.getSelectedFile()); } return task; } public SetChannelJDialog getSetChannelJDialog() { return setChannelJDialog; } /** * A Task that loads the contents of a file into a String. The * LoadFileTask constructor runs first, on the EDT, then the * #doInBackground methods runs on a background thread, and finally * a completion method like #succeeded or #failed runs on the EDT. * * The resources for this class, like the message format strings are * loaded from resources/LoadFileTask.properties. */ private class LoadFileTask extends DocumentEditorApp.LoadTextFileTask { /* Construct the LoadFileTask object. The constructor * will run on the EDT, so we capture a reference to the * File to be loaded here. To keep things simple, the * resources for this Task are specified to be in the same * ResourceMap as the DocumentEditorView class's resources. * They're defined in resources/DocumentEditorView.properties. */ LoadFileTask(File file) { super(DocumentEditorView.this.getApplication(), file); } /* Called on the EDT if doInBackground completes without * error and this Task isn't cancelled. We update the * GUI as well as the file and modified properties here. */ @Override protected void succeeded(String fileContents) { setFile(getFile()); textArea.setText(fileContents); setModified(false); } /* Called on the EDT if doInBackground fails because * an uncaught exception is thrown. We show an error * dialog here. The dialog is configured with resources * loaded from this Tasks's ResourceMap. */ @Override protected void failed(Throwable e) { logger.log(Level.WARNING, "couldn't load " + getFile(), e); String msg = getResourceMap().getString("loadFailedMessage", getFile()); String title = getResourceMap().getString("loadFailedTitle"); int type = JOptionPane.ERROR_MESSAGE; JOptionPane.showMessageDialog(getFrame(), msg, title, type); } } /** * Save the contents of the textArea to the current {@link #getFile file}. * <p> * The text is written to the file on a worker thread because we don't want to * block the EDT while the file system is accessed. To do that, this * Action method returns a new SaveFileTask instance. The task * is executed when the "save" Action's actionPerformed method runs. * The SaveFileTask is responsible for updating the GUI after it * has successfully completed saving the file. * * @see #getFile */ @Action(enabledProperty = "modified") public Task save() { return new SaveFileTask(getFile()); } /** * Save the contents of the textArea to the current file. * <p> * This action is nearly identical to {@link #open open}. In * this case, if the user chooses a file, a {@code SaveFileTask} * is returned. Note that the selected file only becomes the * value of the {@code file} property if the file is saved * successfully. */ @Action public Task saveAs() { JFileChooser fc = createFileChooser("saveAsFileChooser"); int option = fc.showSaveDialog(getFrame()); Task task = null; if (JFileChooser.APPROVE_OPTION == option) { task = new SaveFileTask(fc.getSelectedFile()); } return task; } /** * A Task that saves the contents of the textArea to the current file. * This class is very similar to LoadFileTask, please refer to that * class for more information. */ private class SaveFileTask extends DocumentEditorApp.SaveTextFileTask { SaveFileTask(File file) { super(DocumentEditorView.this.getApplication(), file, textArea.getText()); } @Override protected void succeeded(Void ignored) { setFile(getFile()); setModified(false); } @Override protected void failed(Throwable e) { logger.log(Level.WARNING, "couldn't save " + getFile(), e); String msg = getResourceMap().getString("saveFailedMessage", getFile()); String title = getResourceMap().getString("saveFailedTitle"); int type = JOptionPane.ERROR_MESSAGE; JOptionPane.showMessageDialog(getFrame(), msg, title, type); } } @Action public void showAboutBox() { if (aboutBox == null) { JFrame mainFrame = DocumentEditorApp.getApplication().getMainFrame(); aboutBox = new DocumentEditorAboutBox(mainFrame); aboutBox.setLocationRelativeTo(mainFrame); } DocumentEditorApp.getApplication().show(aboutBox); } private JFileChooser createFileChooser(String name) { JFileChooser fc = new JFileChooser(); fc.setDialogTitle(getResourceMap().getString(name + ".dialogTitle")); String textFilesDesc = getResourceMap().getString("txtFileExtensionDescription"); fc.setFileFilter(new TextFileFilter(textFilesDesc)); return fc; } /** This is a substitute for FileNameExtensionFilter, which is * only available on Java SE 6. */ private static class TextFileFilter extends FileFilter { private final String description; TextFileFilter(String description) { this.description = description; } @Override public boolean accept(File f) { if (f.isDirectory()) { return true; } String fileName = f.getName(); int i = fileName.lastIndexOf('.'); if ((i > 0) && (i < (fileName.length() - 1))) { String fileExt = fileName.substring(i + 1); if ("txt".equalsIgnoreCase(fileExt)) { return true; } } return false; } @Override public String getDescription() { return description; } } private class ConfirmExit implements Application.ExitListener { public boolean canExit(EventObject e) { //if (isModified()) { if (true) { //String confirmExitText = getResourceMap().getString("confirmTextExit", getFile()); String confirmExitText = "是否真的要退出GPRS无线数据传输系统?单击是退出系统,否则将最小化窗体到托盘。"; int option = JOptionPane.showConfirmDialog(getFrame(), confirmExitText); if(option == JOptionPane.YES_OPTION){ return true; }else if(option == JOptionPane.NO_OPTION){ getFrame().setVisible(false); return false; }else{ return false; } // TODO: also offer saving } else { return true; } } public void willExit(EventObject e) { } } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { mainPanel = new javax.swing.JPanel(); jSplitPane1 = new javax.swing.JSplitPane(); jScrollPane1 = new javax.swing.JScrollPane(); jTree1 = new MyTree(); jSplitPane2 = new javax.swing.JSplitPane(); jPanel1 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); MN = new javax.swing.JTextField(); IP = new javax.swing.JTextField(); jLabel3 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); SITEID = new javax.swing.JTextField(); PORT = new javax.swing.JTextField(); jLabel5 = new javax.swing.JLabel(); jLabel6 = new javax.swing.JLabel(); SITENAME = new javax.swing.JTextField(); LOGINTIME = new javax.swing.JTextField(); jScrollPane3 = new javax.swing.JScrollPane(); jTable1 = new javax.swing.JTable(); jScrollPane2 = new javax.swing.JScrollPane(); textArea = new javax.swing.JTextArea(); menuBar = new javax.swing.JMenuBar(); javax.swing.JMenu fileMenu = new javax.swing.JMenu(); javax.swing.JMenuItem openMenuItem = new javax.swing.JMenuItem(); javax.swing.JMenuItem saveMenuItem = new javax.swing.JMenuItem(); javax.swing.JMenuItem saveAsMenuItem = new javax.swing.JMenuItem(); javax.swing.JSeparator fileMenuSeparator = new javax.swing.JSeparator(); exitMenuItem = new javax.swing.JMenuItem(); javax.swing.JMenu editMenu = new javax.swing.JMenu(); javax.swing.JMenuItem cutMenuItem = new javax.swing.JMenuItem(); javax.swing.JMenuItem copyMenuItem = new javax.swing.JMenuItem(); javax.swing.JMenuItem pasteMenuItem = new javax.swing.JMenuItem(); javax.swing.JMenu helpMenu = new javax.swing.JMenu(); javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem(); toolBar = new javax.swing.JToolBar(); openToolBarButton = new javax.swing.JButton(); saveToolBarButton = new javax.swing.JButton(); cutToolBarButton = new javax.swing.JButton(); copyToolBarButton = new javax.swing.JButton(); pasteToolBarButton = new javax.swing.JButton(); jSeparator1 = new javax.swing.JToolBar.Separator(); NowDataToggleButton = new javax.swing.JToggleButton(); TimingToggleButton = new javax.swing.JToggleButton(); FixDataToggleButton = new javax.swing.JToggleButton(); statusPanel = new javax.swing.JPanel(); javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator(); statusMessageLabel = new javax.swing.JLabel(); statusAnimationLabel = new javax.swing.JLabel(); progressBar = new javax.swing.JProgressBar(); jPopupMenu1 = new javax.swing.JPopupMenu(); jMenuItem1 = new MyJMenuItem(); jMenuItem2 = new MyJMenuItem(); jMenuItem3 = new MyJMenuItem(); jMenuItem4 = new MyJMenuItem(); jMenuItem5 = new MyJMenuItem(); jMenuItem6 = new MyJMenuItem(); mainPanel.setName("mainPanel"); // NOI18N jSplitPane1.setName("jSplitPane1"); // NOI18N jScrollPane1.setName("jScrollPane1"); // NOI18N jTree1.setName("jTree1"); // NOI18N jTree1.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -