pdfsavedialog.java

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

JAVA
1,499
字号
    gbc.gridwidth = 2;
    gbc.gridy = 5;
    gbc.anchor = GridBagConstraints.WEST;
    securityPanel.add(cxAllowModifyAnnotations, gbc);

    gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridwidth = 1;
    gbc.gridy = 6;
    gbc.anchor = GridBagConstraints.WEST;
    securityPanel.add(lbAllowPrinting, gbc);

    gbc = new GridBagConstraints();
    gbc.gridx = 1;
    gbc.gridwidth = 3;
    gbc.gridy = 6;
    gbc.anchor = GridBagConstraints.WEST;
    securityPanel.add(cbAllowPrinting, gbc);

    return securityPanel;
  }

  /**
   * Creates the security config panel. This panel is used to select the level of the
   * PDF security.
   *
   * @return the created security config panel.
   */
  private JPanel createSecurityConfigPanel()
  {
    rbSecurityNone = new JRadioButton(getResources().getString("pdfsavedialog.securityNone"));
    rbSecurity40Bit = new JRadioButton(getResources().getString("pdfsavedialog.security40bit"));
    rbSecurity128Bit = new JRadioButton(getResources().getString("pdfsavedialog.security128bit"));

    rbSecurityNone.addActionListener(getActionSecuritySelection());
    rbSecurity40Bit.addActionListener(getActionSecuritySelection());
    rbSecurity128Bit.addActionListener(getActionSecuritySelection());

    rbSecurity128Bit.setSelected(true);

    final JPanel pnlSecurityConfig = new JPanel();
    pnlSecurityConfig.setLayout(new GridLayout());
    pnlSecurityConfig.add(rbSecurityNone);
    pnlSecurityConfig.add(rbSecurity40Bit);
    pnlSecurityConfig.add(rbSecurity128Bit);

    final ButtonGroup btGrpSecurity = new ButtonGroup();
    btGrpSecurity.add(rbSecurity128Bit);
    btGrpSecurity.add(rbSecurity40Bit);
    btGrpSecurity.add(rbSecurityNone);

    return pnlSecurityConfig;
  }

  /**
   * returns the defined user password for the pdf file. The user password limits read-only access
   * to the pdf in the PDF-Viewer. The reader/user has to enter the password when opening the file.
   *
   * @return the defined password. The password can be null.
   */
  public String getUserPassword()
  {
    final String txt = txUserPassword.getText();
    if (txt.equals(""))
    {
      return null;
    }
    return txt;
  }

  /**
   * Defines the user password for the pdf file. The user password limits read-only access
   * to the pdf in the PDF-Viewer. The reader/user has to enter the password when opening the file.
   *
   * @param userPassword the defined password. The password can be null.
   */
  public void setUserPassword(final String userPassword)
  {
    txUserPassword.setText(userPassword);
    txConfUserPassword.setText(userPassword);
  }

  /**
   * Returns the owner password for the pdf file. The owner password limits writing access
   * to the pdf in the PDF-Editor. The user has to enter the password when opening the file
   * to enable editing functionality or to modify the file.
   *
   * @return the defined password. The password can be null.
   */
  public String getOwnerPassword()
  {
    final String txt = txOwnerPassword.getText();
    if (txt.equals(""))
    {
      return null;
    }
    return txt;
  }

  /**
   * Defines the owner password for the pdf file. The owner password limits writing access
   * to the pdf in the PDF-Editor. The user has to enter the password when opening the file
   * to enable editing functionality or to modify the file.
   *
   * @param ownerPassword the defined password. The password can be null.
   */
  public void setOwnerPassword(final String ownerPassword)
  {
    txOwnerPassword.setText(ownerPassword);
    txConfOwnerPassword.setText(ownerPassword);
  }

  /**
   * Returns the selected encoding.
   *
   * @return The encoding.
   */
  public String getEncoding()
  {
    if (cbEncoding.getSelectedIndex() == -1)
    {
      return System.getProperty("file.encoding");
    }
    else
    {
      return encodingModel.getEncoding(cbEncoding.getSelectedIndex());
    }
  }

  /**
   * Sets the encoding.
   *
   * @param encoding  the encoding (name).
   */
  public void setEncoding(final String encoding)
  {
    cbEncoding.setSelectedIndex(encodingModel.indexOf(encoding));
  }

  /**
   * Gets the AllowDegradedPrinting permission for the generated PDF-file.
   * @return true if a low quality printing is allowed, false otherwise.
   */
  public boolean isAllowDegradedPrinting()
  {
    return cbAllowPrinting.getSelectedIndex() == CBMODEL_DEGRADED;
  }

  /**
   * Gets the AllowAssembly permission for the generated PDF-file.
   *
   * @return true, if the generated pdf may be reassembled using an pdf editor.
   */
  public boolean isAllowAssembly()
  {
    return cxAllowAssembly.isSelected();
  }

  /**
   * Defines whether the generated pdf may be reassembled.
   *
   * @param allowAssembly the flag.
   */
  public void setAllowAssembly(final boolean allowAssembly)
  {
    this.cxAllowAssembly.setSelected(allowAssembly);
  }

  /**
   * Defines whether the generated pdf may accessed using screenreaders. Screenreaders are
   * used to make pdf files accessible for disabled people.
   *
   * @return true, if screenreaders are allowed for accessing this file
   */
  public boolean isAllowScreenreaders()
  {
    return cxAllowScreenReaders.isSelected();
  }

  /**
   * Defines whether the generated pdf may accessed using screenreaders. Screenreaders are
   * used to make pdf files accessible for disabled people.
   *
   * @param allowScreenreaders a flag containing true, if screenreaders are allowed to access the
   * content of this file, false otherwise
   */
  public void setAllowScreenreaders(final boolean allowScreenreaders)
  {
    this.cxAllowScreenReaders.setSelected(allowScreenreaders);
  }

  /**
   * Defines whether the contents of form fields may be changed by the user.
   *
   * @return true, if the user may change the contents of formulars.
   */
  public boolean isAllowFillIn()
  {
    return cxAllowFillIn.isSelected();
  }

  /**
   * Defines whether the contents of form fields may be changed by the user.
   *
   * @param allowFillIn set to true to allow the change/filling of form fields
   */
  public void setAllowFillIn(final boolean allowFillIn)
  {
    this.cxAllowFillIn.setSelected(allowFillIn);
  }

  /**
   * Defines whether the contents of the file are allowed to be copied.
   *
   * @return true, if the user is allowed to copy the contents of the file.
   */
  public boolean isAllowCopy()
  {
    return cxAllowCopy.isSelected();
  }

  /**
   * Defines whether the contents of the file are allowed to be copied.
   *
   * @param allowCopy set to true, if the user is allowed to copy the contents of the file.
   */
  public void setAllowCopy(final boolean allowCopy)
  {
    this.cxAllowCopy.setSelected(allowCopy);
  }

  /**
   * Defines whether the user is allowed to add or modify annotations in this file.
   *
   * @return true, if this files annotations can be modified, false otherwise
   */
  public boolean isAllowModifyAnnotations()
  {
    return cxAllowModifyAnnotations.isSelected();
  }

  /**
   * Defines whether the user is allowed to add or modify annotations in this file.
   *
   * @param allowModifyAnnotations the flag.
   */
  public void setAllowModifyAnnotations(final boolean allowModifyAnnotations)
  {
    this.cxAllowModifyAnnotations.setSelected(allowModifyAnnotations);
  }

  /**
   * Defines whether the user is allowed to modify the contents of this file.
   *
   * @return true, if this files content can be modified, false otherwise
   */
  public boolean isAllowModifyContents()
  {
    return cxAllowModifyContents.isSelected();
  }

  /**
   * Defines whether the user is allowed to modify the contents of this file.
   *
   * @param allowModifyContents set to true, if this files content can be modified, false otherwise
   */
  public void setAllowModifyContents(final boolean allowModifyContents)
  {
    this.cxAllowModifyContents.setSelected(allowModifyContents);
  }

  /**
   * Defines whether the user is allowed to print the file. If this right is granted, the
   * user is also able to print a degraded version of the file, regardless of the
   * allowDegradedPrinting property
   *
   * @return true, if this file can be printed, false otherwise
   */
  public boolean isAllowPrinting()
  {
    return cbAllowPrinting.getSelectedIndex() == CBMODEL_FULL;
  }

  /**
   * Defines whether the user is allowed to print the file.  If this right is granted, the
   * user is also able to print a degraded version of the file, regardless of the
   * <code>allowDegradedPrinting</code< property. If you disabled printing but enabled degraded
   * printing, then the user is able to print a low-quality version of the document.
   *
   * @param allowPrinting  set to <code>true</code>, if this file can be printed,
   *                       <code>false</code> otherwise.
   * @param degraded  set to <code>true</code>, to allow degraded printing, and <code>false</code>
   *                  otherwise.
   */
  public void setPrintLevel(final boolean allowPrinting, final boolean degraded)
  {
    if (allowPrinting == true)
    {
      this.cbAllowPrinting.setSelectedIndex(CBMODEL_FULL);
    }
    else
    {
      if (degraded)
      {
        this.cbAllowPrinting.setSelectedIndex(CBMODEL_DEGRADED);
      }
      else
      {
        this.cbAllowPrinting.setSelectedIndex(CBMODEL_NOPRINTING);
      }
    }
  }

  /**
   * Defines the filename of the pdf file.
   *
   * @return the name of the file where to save the pdf file.
   */
  public String getFilename()
  {
    return txFilename.getText();
  }

  /**
   * Defines the filename of the pdf file.
   *
   * @param filename the filename of the pdf file
   */
  public void setFilename(final String filename)
  {
    this.txFilename.setText(filename);
  }

  /**
   * Defines the title of the pdf file.
   *
   * @return the title
   */
  public String getPDFTitle()
  {
    return txTitle.getText();
  }

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

  /**
   * Gets the author of this report.
   *
   * @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);
  }

  /**

⌨️ 快捷键说明

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