📄 generatewizardselectdirectorycard.java
字号:
package org.dbgen.view;import java.awt.*;import java.awt.event.*;import java.io.*;import javax.swing.*;import org.dbgen.*;import org.dbgen.gui.*;/** * This class was generated by a SmartGuide. * */public class GenerateWizardSelectDirectoryCard extends JPanel implements ActionListener, org.dbgen.view.TextFieldListener, org.dbgen.gui.WizardCard { TextField fieldOutputDirectoryField = null; JRadioButton fieldCreateSubDirectoryOption = null; JRadioButton fieldOneDirectoryOption = null; protected FileDialog fileDialog = null; /** * GenerateWizardSelectDirectoryCard constructor comment. */ public GenerateWizardSelectDirectoryCard() { super(); initialize(); } /** * This method was created by a SmartGuide. * @param event java.awt.event.ActionEvent */ public void actionPerformed(ActionEvent event) { // Swing 1.0.2 only! try { JFileChooser filechooser = new JFileChooser(); filechooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (filechooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { File dir = filechooser.getSelectedFile(); getOutputDirectoryField().setText(dir.getAbsolutePath()); } } catch (Exception exp) { CommonDialog.showError(DbGenPro.mainWindow, "Error Message", "Cannot browse directories.\nAre you running Swing version 1.0.2 or above?"); } return; } /** * This method was created by a SmartGuide. * @param wizard org.dbgen.gui.Wizard */ public void cardShown(Wizard wizard) { wizard.setMessage("Enter an existing output directory and press ENTER."); String dir = ((GenerateWizardSelectTableCard) wizard.getPreviousCard()).getCurrentProject().getOutputDirectory(); getOutputDirectoryField().setText(dir); getOutputDirectoryField().requestFocus(); return; } /** * This method was created by a SmartGuide. * @param path java.lang.String */ public boolean createDirectory(String path) { /* If current path exists and is a directory, then we are fine. */ File file = new File(path); if (file.exists()) { if (file.isDirectory()) { //System.out.println("CreateDirectory: done with " + path); return true; } } /* Create directory in parent */ int lastIndex = path.lastIndexOf(File.separator); if (lastIndex > 0) { //System.out.println("CreateDirectory: trying " + path.substring(0, lastIndex)); if (createDirectory(path.substring(0, lastIndex))) { return file.mkdir(); } } return true; } /** * This method was created by a SmartGuide. * @return boolean */ public boolean enableFinishButton() { return false; } /** * This method was created by a SmartGuide. * @return boolean */ public boolean enableNextButton() { return true; } /** * This method was created by a SmartGuide. * @return java.lang.String */ public String getCardName() { return "Select Directory"; } /** * Gets the createSubDirectoryOption property (javax.swing.JRadioButton) value. * @return The createSubDirectoryOption property value. */ public JRadioButton getCreateSubDirectoryOption() { /* Returns the createSubDirectoryOption property value. */ if (fieldCreateSubDirectoryOption == null) { try { fieldCreateSubDirectoryOption = new JRadioButton("Create package sub-directories (recommended)", true); } catch (Throwable exception) { System.err.println("Exception creating createSubDirectoryOption property."); } }; return fieldCreateSubDirectoryOption; } /** * Gets the oneDirectoryOption property (javax.swing.JRadioButton) value. * @return The oneDirectoryOption property value. */ public JRadioButton getOneDirectoryOption() { /* Returns the oneDirectoryOption property value. */ if (fieldOneDirectoryOption == null) { try { fieldOneDirectoryOption = new JRadioButton("Use one directory for all source codes."); } catch (Throwable exception) { System.err.println("Exception creating oneDirectoryOption property."); } }; return fieldOneDirectoryOption; } /** * Gets the outputDirectoryField property (org.dbgen.view.TextField) value. * @return The outputDirectoryField property value. */ public TextField getOutputDirectoryField() { /* Returns the outputDirectoryField property value. */ if (fieldOutputDirectoryField == null) { try { fieldOutputDirectoryField = new TextField(); } catch (Throwable exception) { System.err.println("Exception creating outputDirectoryField property."); } }; return fieldOutputDirectoryField; } /** * This method was created by a SmartGuide. */ public void initialize() { GridBagConstraints gbc = new GridBagConstraints(); GridBagConstraints gbc2 = new GridBagConstraints(); Insets insets = new Insets(2, 2, 2, 2); int row = 1; setLayout(new GridBagLayout()); Util.addgbc(this, new JLabel("Please enter the output directory below:"), gbc, row++, 1, 1f, 0f, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST, insets); JPanel dirPanel = new JPanel(new GridBagLayout()); JButton browseButton = new JButton("Browse..."); browseButton.addActionListener(this); //browseButton.setEnabled(false); /* XXX - need directory browser */ getOutputDirectoryField().addSetFieldListener(this, 1); Util.addgbc(dirPanel, new JLabel("Output Directory:"), gbc2, 1, 1, 0f, 0f, GridBagConstraints.NONE, GridBagConstraints.WEST, insets); Util.addgbc(dirPanel, getOutputDirectoryField(), gbc2, 1, 2, 1f, 0f, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER, insets); Util.addgbc(dirPanel, browseButton, gbc2, 1, 3, 0f, 0f, GridBagConstraints.NONE, GridBagConstraints.WEST, insets); Util.addgbc(this, dirPanel, gbc, row++, 1, 1f, 0f, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST, insets); ButtonGroup group = new ButtonGroup(); Util.addgbc(this, getCreateSubDirectoryOption(), gbc, row++, 1, 1f, 0f, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST, insets); Util.addgbc(this, getOneDirectoryOption(), gbc, row++, 1, 1f, 0f, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST, insets); group.add(getCreateSubDirectoryOption()); group.add(getOneDirectoryOption()); Util.addgbc(this, new JLabel("Press NEXT after selecting a directory."), gbc, row++, 1, 1f, 0f, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST, insets); return; } /** * This method was created by a SmartGuide. * @return boolean */ public boolean proceedNext() { String path = getOutputDirectoryField().getText(); File file = new File(path); if (file.isDirectory()) { return true; } int ans = JOptionPane.showConfirmDialog(this, "Directory does not exist.\nDo you want to create " + path + "?", "Create Directory Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (ans == JOptionPane.YES_OPTION) { return createDirectory(path); } return false; } /** * setField method comment. */ public void setField(int id, String value) { Wizard wizard = Wizard.findWizard(this); // Do this after pressing FINISH. //Project project = ((GenerateWizardSelectTableCard) wizard.getPreviousCard()).getCurrentProject(); //project.setOutputDirectory(value); wizard.updateSensitivities(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -