htmlexportdialog.java

来自「swing编写的库存管理程序。毕业设计类」· Java 代码 · 共 1,476 行 · 第 1/3 页

JAVA
1,476
字号
    gbc.weightx = 1;
    gbc.gridx = 1;
    gbc.gridy = 1;
    gbc.ipadx = 120;
    gbc.insets = new Insets(1, 1, 1, 1);
    contentPane.add(txAuthor, gbc);

    gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.weightx = 1;
    gbc.gridx = 1;
    gbc.gridy = 2;
    gbc.ipadx = 120;
    gbc.insets = new Insets(1, 1, 1, 1);
    contentPane.add(cbEncoding, gbc);

    gbc = new GridBagConstraints();
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.gridx = 1;
    gbc.gridy = 3;
    gbc.ipadx = 120;
    gbc.insets = new Insets(1, 1, 1, 1);
    contentPane.add(cbxStrictLayout, gbc);

    gbc = new GridBagConstraints();
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.gridx = 1;
    gbc.gridy = 4;
    gbc.ipadx = 120;
    gbc.insets = new Insets(1, 1, 1, 1);
    contentPane.add(rbGenerateHTML4, gbc);

    gbc = new GridBagConstraints();
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.gridx = 1;
    gbc.gridy = 5;
    gbc.ipadx = 120;
    gbc.insets = new Insets(1, 1, 1, 1);
    contentPane.add(rbGenerateXHTML, gbc);

    exportSelection = new JTabbedPane();
    exportSelection.add(getResources().getString
        ("htmlexportdialog.stream-export"), createStreamExportPanel());
    exportSelection.add(getResources().getString
        ("htmlexportdialog.directory-export"), createDirExportPanel());
    exportSelection.add(getResources().getString
        ("htmlexportdialog.zip-export"), createZipExportPanel());

    gbc = new GridBagConstraints();
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridx = 0;
    gbc.gridy = 6;
    gbc.gridwidth = 2;
    gbc.weightx = 1;
    gbc.weighty = 1;
    gbc.insets = new Insets(1, 1, 1, 1);
    contentPane.add(exportSelection, gbc);

    setContentPane(contentPane);

  }

  /**
   * Creates a panel for the directory export.
   *
   * @return The panel.
   */
  private JPanel createDirExportPanel()
  {
    final JPanel contentPane = new JPanel();
    contentPane.setLayout(new GridBagLayout());

    final JLabel lblDirFileName = new JLabel(getResources().getString("htmlexportdialog.filename"));
    final JLabel lblDirDataFileName = new JLabel(
        getResources().getString("htmlexportdialog.datafilename"));
    cbxCopyExternalReferencesDir = new JCheckBox(
        getResources().getString("htmlexportdialog.copy-external-references"));

    txDirDataFilename = new JTextField();
    txDirFilename = new JTextField();

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.NONE;
    gbc.gridx = 0;
    gbc.gridy = 0;
    contentPane.add(lblDirFileName, gbc);

    gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.NONE;
    gbc.gridx = 0;
    gbc.gridy = 1;
    contentPane.add(lblDirDataFileName, gbc);

    gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.weightx = 1;
    gbc.gridx = 1;
    gbc.gridy = 0;
    contentPane.add(txDirFilename, gbc);

    gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.weightx = 1;
    gbc.gridx = 1;
    gbc.gridy = 1;
    contentPane.add(txDirDataFilename, gbc);

    gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.weightx = 1;
    gbc.gridx = 1;
    gbc.gridy = 2;
    contentPane.add(cbxCopyExternalReferencesDir, gbc);

    gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.gridx = 2;
    gbc.gridy = 0;
    contentPane.add(new ActionButton(new ActionSelectDirFile()), gbc);

    final Action actionConfirm = new ActionConfirmDir();
    final JButton btnCancel = new ActionButton(actionCancel);
    final JButton btnConfirm = new ActionButton(actionConfirm);
    final JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new GridLayout());
    buttonPanel.add(btnConfirm);
    buttonPanel.add(btnCancel);
    btnConfirm.setDefaultCapable(true);
    buttonPanel.registerKeyboardAction(actionConfirm, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),
        JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.NONE;
    gbc.weightx = 1;
    gbc.gridx = 0;
    gbc.gridwidth = 3;
    gbc.gridy = 3;
    gbc.insets = new Insets(10, 0, 0, 0);
    contentPane.add(buttonPanel, gbc);

    return contentPane;
  }

  /**
   * Creates a panel for the ZIP file export.
   *
   * @return The panel.
   */
  private JPanel createZipExportPanel()
  {
    final JPanel contentPane = new JPanel();
    contentPane.setLayout(new GridBagLayout());

    final JLabel lblZipFileName = new JLabel(getResources().getString("htmlexportdialog.filename"));
    final JLabel lblZipDataFileName = new JLabel(
        getResources().getString("htmlexportdialog.datafilename"));
    cbxCopyExternalReferencesZip = new JCheckBox(
        getResources().getString("htmlexportdialog.copy-external-references"));

    txZipDataFilename = new JTextField();
    txZipFilename = new JTextField();

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.NONE;
    gbc.gridx = 0;
    gbc.gridy = 0;
    contentPane.add(lblZipFileName, gbc);

    gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.NONE;
    gbc.gridx = 0;
    gbc.gridy = 1;
    contentPane.add(lblZipDataFileName, gbc);

    gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.weightx = 1;
    gbc.gridx = 1;
    gbc.gridy = 0;
    contentPane.add(txZipFilename, gbc);

    gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.weightx = 1;
    gbc.gridx = 1;
    gbc.gridy = 1;
    contentPane.add(txZipDataFilename, gbc);

    gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.weightx = 1;
    gbc.gridx = 1;
    gbc.gridy = 2;
    contentPane.add(cbxCopyExternalReferencesZip, gbc);

    gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.gridx = 2;
    gbc.gridy = 0;
    contentPane.add(new ActionButton(new ActionSelectZipFile()), gbc);

    final Action actionConfirm = new ActionConfirmZip();
    final JButton btnCancel = new ActionButton(actionCancel);
    final JButton btnConfirm = new ActionButton(actionConfirm);
    final JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new GridLayout());
    buttonPanel.add(btnConfirm);
    buttonPanel.add(btnCancel);
    btnConfirm.setDefaultCapable(true);
    buttonPanel.registerKeyboardAction(actionConfirm, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),
        JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.NONE;
    gbc.weightx = 1;
    gbc.gridx = 0;
    gbc.gridwidth = 3;
    gbc.gridy = 6;
    gbc.insets = new Insets(10, 0, 0, 0);
    contentPane.add(buttonPanel, gbc);

    return contentPane;
  }

  /**
   * Creates a panel for the stream export.
   *
   * @return The panel.
   */
  private JPanel createStreamExportPanel()
  {
    final JPanel contentPane = new JPanel();
    contentPane.setLayout(new GridBagLayout());

    final JLabel lblStreamFileName =
        new JLabel(getResources().getString("htmlexportdialog.filename"));
    txStreamFilename = new JTextField();

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.NONE;
    gbc.gridx = 0;
    gbc.gridy = 0;
    contentPane.add(lblStreamFileName, gbc);

    gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.weightx = 1;
    gbc.gridx = 1;
    gbc.gridy = 0;
    contentPane.add(txStreamFilename, gbc);

    gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.gridx = 2;
    gbc.gridy = 0;
    contentPane.add(new ActionButton(new ActionSelectStreamFile()), gbc);

    final Action actionConfirm = new ActionConfirmStream();
    final JButton btnCancel = new ActionButton(actionCancel);
    final JButton btnConfirm = new ActionButton(actionConfirm);
    final JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new GridLayout());
    buttonPanel.add(btnConfirm);
    buttonPanel.add(btnCancel);
    btnConfirm.setDefaultCapable(true);
    buttonPanel.registerKeyboardAction(actionConfirm, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),
        JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.NONE;
    gbc.weightx = 1;
    gbc.gridx = 0;
    gbc.gridwidth = 3;
    gbc.gridy = 6;
    gbc.insets = new Insets(10, 0, 0, 0);
    contentPane.add(buttonPanel, gbc);

    return contentPane;
  }

  /**
   * Returns the title of the HTML file.
   *
   * @return the title
   */
  public String getHTMLTitle()
  {
    return txTitle.getText();
  }

  /**
   * Defines the title of the HTML file.
   *
   * @param title the title
   */
  public void setHTMLTitle(final String title)
  {
    this.txTitle.setText(title);
  }

  /**
   * Gets the author of the dialog. This is not yet implemented in the HTML-Target.
   *
   * @return the name of the author of this report.
   */
  public String getAuthor()
  {
    return txAuthor.getText();
  }

  /**
   * Defines the Author of the report. Any freeform text is valid. This defaults to the value of
   * the systemProperty "user.name".
   *
   * @param author the name of the author.
   */
  public void setAuthor(final String author)
  {
    this.txAuthor.setText(author);
  }

  /**
   * Gets the confirmation state of the dialog. A confirmed dialog has no invalid
   * settings and the user confirmed any resource conflicts.
   *
   * @return true, if the dialog has been confirmed and the HTML file should be saved,
   * false otherwise.
   */
  public boolean isConfirmed()
  {
    return confirmed;
  }

  /**
   * Defines whether this dialog has been finished using the 'OK' or the 'Cancel' option.
   *
   * @param confirmed set to true, if OK was pressed, false otherwise
   */
  protected void setConfirmed(final boolean confirmed)
  {
    this.confirmed = confirmed;
  }

  /**
   * Clears all selections and input fields.
   */
  public void clear()
  {
    txAuthor.setText(System.getProperty("user.name"));
    txDirFilename.setText("");
    txDirDataFilename.setText("");
    txZipFilename.setText("");
    txZipDataFilename.setText("");
    txStreamFilename.setText("");
    txTitle.setText("");
    cbEncoding.setSelectedIndex(
        encodingModel.indexOf(System.getProperty("file.encoding", "Cp1251")));
    cbxCopyExternalReferencesDir.setSelected(false);
    cbxCopyExternalReferencesZip.setSelected(false);
    cbxStrictLayout.setSelected(false);
    rbGenerateHTML4.setSelected(true);
  }

  /**
   * Returns the directory data file name.
   *
   * @return The file name.
   */
  public String getDirDataFilename()
  {
    return txDirDataFilename.getText();
  }

  /**
   * Sets the directory data file name.
   *
   * @param dirFilename  the file name.
   */
  public void setDirDataFilename(final String dirFilename)
  {
    this.txDirDataFilename.setText(dirFilename);
  }

  /**
   * Returns the directory file name.
   *
   * @return The directory file name.
   */
  public String getDirFilename()
  {
    return txDirFilename.getText();
  }

  /**
   * Sets the directory file name.
   *
   * @param dirFilename  the file name.
   */
  public void setDirFilename(final String dirFilename)
  {
    this.txDirFilename.setText(dirFilename);
  }

  /**
   * Returns the zip file name.
   *
   * @return The file name.
   */
  public String getZipFilename()
  {
    return txZipFilename.getText();
  }

  /**
   * Sets the zip file name.
   *
   * @param zipFilename  the zip file name.
   */
  public void setZipFilename(final String zipFilename)
  {
    this.txZipFilename.setText(zipFilename);
  }

  /**
   * Returns the zip data file name.
   *
   * @return The zip data file name.
   */
  public String getZipDataFilename()
  {
    return txZipDataFilename.getText();
  }

  /**
   * Sets the zip data file name.
   *
   * @param zipFilename  the file name.
   */
  public void setZipDataFilename(final String zipFilename)
  {
    this.txZipDataFilename.setText(zipFilename);
  }

  /**
   * Returns the stream file name.
   *
   * @return The file name.
   */
  public String getStreamFilename()
  {
    return txStreamFilename.getText();
  }

  /**
   * Sets the stream file name.
   *
   * @param streamFilename  the file name.
   */
  public void setStreamFilename(final String streamFilename)
  {
    this.txStreamFilename.setText(streamFilename);
  }

  /**
   * Sets the radio buttons for XHTML or HTML4 generation.
   *
   * @param generateXHTML  boolean.
   */
  public void setGenerateXHTML(final boolean generateXHTML)
  {
    if (generateXHTML)
    {
      this.rbGenerateXHTML.setSelected(true);
    }
    else
    {
      this.rbGenerateHTML4.setSelected(true);
    }
  }

  /**
   * Returns true if XHTML is selected, false if HTML4.
   *
   * @return A boolean.
   */
  public boolean isGenerateXHTML()
  {
    return rbGenerateXHTML.isSelected();

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?