📄 propertydialog2.java
字号:
new Insets(0, 0, 0, 0), 0, 0)); cont.add(contextEngineIdLabel, getGridBagConstraints2(0, 5, 1, 1, 0.5, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cont.add(contextEngineIdText, getGridBagConstraints2(1, 5, 1, 1, 0.5, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cont.add(contextNameLabel, getGridBagConstraints2(0, 6, 1, 1, 0.5, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cont.add(contextNameText, getGridBagConstraints2(1, 6, 1, 1, 0.5, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cont.add(userNameLabel, getGridBagConstraints2(0, 7, 1, 1, 0.5, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cont.add(userNameText, getGridBagConstraints2(1, 7, 1, 1, 0.5, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cont.add(authenticationChoice, getGridBagConstraints2(0, 8, 2, 1, 0.5, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cont.add(userAuthPasswLabel, getGridBagConstraints2(0, 9, 1, 1, 0.5, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cont.add(userAuthPasswText, getGridBagConstraints2(1, 9, 1, 1, 0.5, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cont.add(protocolPanel, getGridBagConstraints2(0, 10, 2, 1, 1.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); cont.add(privacyChoice, getGridBagConstraints2(0, 11, 2, 1, 0.5, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cont.add(userPrivPasswLabel, getGridBagConstraints2(0, 12, 1, 1, 0.5, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cont.add(userPrivPasswText, getGridBagConstraints2(1, 12, 1, 1, 0.5, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); cont.add(buttonPanel, getGridBagConstraints2(0, 13, 3, 1, 1.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 5, 5, 5), 0, 0)); buttonPanel.add(okButton, null); buttonPanel.add(applyButton, null); buttonPanel.add(cancelButton, null); socketPanel.setLayout(gridBagLayout2); socketPanel.add(standardSocketChoice, getGridBagConstraints2(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); socketPanel.add(tcpSocketChoice, getGridBagConstraints2(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); protocolPanel.setLayout(gridBagLayout3); protocolPanel.add(md5ProtocolChoice, getGridBagConstraints2(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); protocolPanel.add(sha1ProtocolChoice, getGridBagConstraints2(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); this.addWindowListener(this);}public void actionPerformed(ActionEvent evt){ Object src = evt.getSource(); if (src == okButton) { okButton_actionPerformed(evt); } else if (src == applyButton) { applyButton_actionPerformed(evt); } else if (src == cancelButton) { cancelButton_actionPerformed(evt); } else if (src == fileButton) { fileButton_actionPerformed(evt); } else if (src == fileChooser) { fileChooser_actionPerformed(evt); }}public void itemStateChanged(ItemEvent evt){ Object src = evt.getSource(); if (src == authenticationChoice) { authenticationChoice_itemStateChanged(evt); } else if (src == privacyChoice) { privacyChoice_itemStateChanged(evt); }}public void fillinFromUtil(Util u){ util = u; String host = util.getHost(); String bindAddr = util.getBindAddress(); int port = util.getPort(SnmpContextBasisFace.DEFAULT_PORT); String socketType = util.getSocketType(); byte[] engineId = util.getContextEngineId(); String contextName = util.getContextName(); String userName = util.getUserName(); int auth = util.getUseAuth(); String authPassw = util.getUserAuthPassword(); int proto = util.getAuthProcotol(); int priv = util.getUsePriv(); String privPassw = util.getUserPrivPassword(); setHost(host); setBindAddress(bindAddr); setPort(""+port); setSocketType(socketType); setContextEngineId(engineId); setContextName(contextName); setUserName(userName); setAuthentication((auth == 1)); setUserAuthPassw(authPassw); setProtocol(proto); setPrivacy((priv == 1)); setUserPrivPassw(privPassw);}void fileChooser_actionPerformed(ActionEvent evt){ String command = evt.getActionCommand(); if (command.equals(JFileChooser.APPROVE_SELECTION)) { File file = fileChooser.getSelectedFile(); if (file != null) { if (util != null) { util.loadPropfile(file); } else { util = new Util(file.getName(), null); } fillinFromUtil(util); } }}void fileButton_actionPerformed(ActionEvent evt){ if (fileChooser == null) { fileChooser = new JFileChooser(); fileChooser.setDialogTitle("Choose properties file:"); fileChooser.setDialogType(JFileChooser.OPEN_DIALOG); fileChooser.setFileFilter(new IsPropertiesFilter()); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); fileChooser.setMultiSelectionEnabled(false); fileChooser.addActionListener(this); File dir = new File(System.getProperty("user.dir")); if (util != null) { File propFile = util.getPropertiesFile(); if (propFile != null) { fileChooser.setCurrentDirectory(propFile); fileChooser.setSelectedFile(propFile); } else { fileChooser.setCurrentDirectory(dir); } } else { fileChooser.setCurrentDirectory(dir); } } fileChooser.showOpenDialog(this);}void cancelButton_actionPerformed(ActionEvent evt){ this.setVisible(false);}void okButton_actionPerformed(ActionEvent evt){ this.setVisible(false); setAllVars(); fireActionPerformed(evt);}void applyButton_actionPerformed(ActionEvent evt){ setAllVars(); fireActionPerformed(evt);}void authenticationChoice_itemStateChanged(ItemEvent evt){ int state = evt.getStateChange(); boolean selected = (state == ItemEvent.SELECTED); userAuthPasswLabel.setEnabled(selected); userAuthPasswText.setEnabled(selected); md5ProtocolChoice.setEnabled(selected); sha1ProtocolChoice.setEnabled(selected);}void privacyChoice_itemStateChanged(ItemEvent evt){ int state = evt.getStateChange(); boolean selected = (state == ItemEvent.SELECTED); userPrivPasswLabel.setEnabled(selected); userPrivPasswText.setEnabled(selected);}private void setAllVars(){ host = hostText.getText(); port = portText.getText(); bindAddr = bindText.getText(); if (bindAddr.length() == 0) { bindAddr = null; } if (standardSocketChoice.isSelected()) { socketType = SnmpContextv3Face.STANDARD_SOCKET; } else if (tcpSocketChoice.isSelected()) { socketType = SnmpContextv3Face.TCP_SOCKET; } contextName = contextNameText.getText(); userName = userNameText.getText(); userAuthPassw = userAuthPasswText.getText(); userPrivPassw = userPrivPasswText.getText(); doAuthentication = authenticationChoice.isSelected(); doPrivacy = privacyChoice.isSelected(); if (md5ProtocolChoice.isSelected()) { protocol = SnmpContextv3Face.MD5_PROTOCOL; } else { protocol = SnmpContextv3Face.SHA1_PROTOCOL; } String hexString = contextEngineIdText.getText(); contextEngineId = SnmpUtilities.toBytes(hexString);}/** * Adds an action listener to be notified when the "Apply" or "OK" button * is pressed. * @see #removeActionListener */public void addActionListener(ActionListener l){ actionPerformedListener.addElement(l);}/** * Removes an action listener. * @see #addActionListener */public void removeActionListener(ActionListener l){ actionPerformedListener.removeElement(l);} /** * Fires a action event when the "Apply" or "OK" * button is pressed. * * @see #removeActionListener * @see #addActionListener * @see ActionEvent * @see ActionListener */protected void fireActionPerformed(ActionEvent evt){ Vector listeners = (Vector) actionPerformedListener.clone(); ActionEvent event = new ActionEvent(this, evt.getID(), evt.getActionCommand(), evt.getModifiers()); int sz = listeners.size(); for (int i=0; i<sz; i++) { ActionListener l = (ActionListener) listeners.elementAt(i); l.actionPerformed(event); }}public static GridBagConstraints getGridBagConstraints2( int x, int y, int w, int h, double wx, double wy, int anchor, int fill, Insets ins, int ix, int iy){ GridBagConstraints gc = new GridBagConstraints(); gc.gridx = x; gc.gridy = y; gc.gridwidth = w; gc.gridheight = h; gc.weightx = wx; gc.weighty = wy; gc.anchor = anchor; gc.fill = fill; gc.insets = ins; gc.ipadx = ix; gc.ipady = iy; return gc;}public void windowActivated(WindowEvent evt){}public void windowDeactivated(WindowEvent evt){}public void windowClosing(WindowEvent evt){ ActionEvent evt2 = new ActionEvent( cancelButton, // source ActionEvent.ACTION_PERFORMED, // id cancelButton.getText() // command ); cancelButton_actionPerformed(evt2);}public void windowClosed(WindowEvent evt){}public void windowIconified(WindowEvent evt){}public void windowDeiconified(WindowEvent evt){}public void windowOpened(WindowEvent evt){} /** * IsPropertiesFilter filters all the properties files. * A file is a properties file if it ends with ".properties". */class IsPropertiesFilter extends javax.swing.filechooser.FileFilter{ public final static String TAIL = ".properties";public boolean accept(File test){ boolean ret = false; String name = test.getName(); if (test.isFile()) { if (name.endsWith(TAIL)) { ret = true; } } else if (test.isDirectory()) { ret = true; } return ret;}public String getDescription(){ return "Properties Files (*.properties)";}}}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -