📄 htmlexportdialog.java
字号:
* 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();
}
/**
* Returns the setting of the 'strict layout' check-box.
*
* @return A boolean.
*/
public boolean isStrictLayout()
{
return cbxStrictLayout.isSelected();
}
/**
* Sets the 'strict layout' check-box.
*
* @param s boolean.
*/
public void setStrictLayout(final boolean s)
{
cbxStrictLayout.setSelected(s);
}
/**
* Returns the selected encoding.
*
* @return The encoding name.
*/
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));
}
/**
* Selects a file to use as target for the report processing.
*/
protected void performSelectFileStream()
{
final File file = new File(getStreamFilename());
if (fileChooserStream == null)
{
fileChooserStream = new JFileChooser();
fileChooserStream.addChoosableFileFilter(new FilesystemFilter(new String[]{".html", ".htm"},
"Html Documents", true));
fileChooserStream.setMultiSelectionEnabled(false);
}
fileChooserStream.setCurrentDirectory(file);
fileChooserStream.setSelectedFile(file);
final int option = fileChooserStream.showSaveDialog(this);
if (option == JFileChooser.APPROVE_OPTION)
{
final File selFile = fileChooserStream.getSelectedFile();
String selFileName = selFile.getAbsolutePath();
// Test if ends on html
if ((StringUtil.endsWithIgnoreCase(selFileName, ".html") == false)
&& (StringUtil.endsWithIgnoreCase(selFileName, ".htm") == false))
{
selFileName = selFileName + ".html";
}
setStreamFilename(selFileName);
}
}
/**
* Selects a file to use as target for the report processing.
*/
protected void performSelectFileZip()
{
final File file = new File(getZipFilename());
if (fileChooserZip == null)
{
fileChooserZip = new JFileChooser();
fileChooserZip.addChoosableFileFilter(new FilesystemFilter(new String[]{".zip", ".jar"},
"Zip Archives", true));
fileChooserZip.setMultiSelectionEnabled(false);
}
fileChooserZip.setCurrentDirectory(file);
fileChooserZip.setSelectedFile(file);
final int option = fileChooserZip.showSaveDialog(this);
if (option == JFileChooser.APPROVE_OPTION)
{
final File selFile = fileChooserZip.getSelectedFile();
String selFileName = selFile.getAbsolutePath();
// Test if ends on xls
if (StringUtil.endsWithIgnoreCase(selFileName, ".zip") == false)
{
selFileName = selFileName + ".zip";
}
setZipFilename(selFileName);
}
}
/**
* Selects a file to use as target for the report processing.
*/
protected void performSelectFileDir()
{
if (fileChooserDir == null)
{
fileChooserDir = new JFileChooser();
fileChooserDir.addChoosableFileFilter(new FilesystemFilter(new String[]{".html", ".htm"},
"Html Documents", true));
fileChooserDir.setMultiSelectionEnabled(false);
}
final File file = new File(getDirFilename());
fileChooserDir.setCurrentDirectory(file);
fileChooserDir.setSelectedFile(file);
final int option = fileChooserDir.showSaveDialog(this);
if (option == JFileChooser.APPROVE_OPTION)
{
final File selFile = fileChooserDir.getSelectedFile();
String selFileName = selFile.getAbsolutePath();
// Test if ends on html
if ((StringUtil.endsWithIgnoreCase(selFileName, ".html") == false)
&& (StringUtil.endsWithIgnoreCase(selFileName, ".htm") == false))
{
selFileName = selFileName + ".html";
}
setDirFilename(selFileName);
}
}
/**
* Validates the contents of the dialog's input fields. If the selected file exists, it is also
* checked for validity.
*
* @return true, if the input is valid, false otherwise
*/
public boolean performValidateStream()
{
final String filename = getStreamFilename();
if (filename.trim().length() == 0)
{
JOptionPane.showMessageDialog(this,
getResources().getString("htmlexportdialog.targetIsEmpty"),
getResources().getString("htmlexportdialog.errorTitle"),
JOptionPane.ERROR_MESSAGE);
return false;
}
final File f = new File(filename);
if (f.exists())
{
if (f.isFile() == false)
{
JOptionPane.showMessageDialog(this,
getResources().getString("htmlexportdialog.targetIsNoFile"),
getResources().getString("htmlexportdialog.errorTitle"),
JOptionPane.ERROR_MESSAGE);
return false;
}
if (f.canWrite() == false)
{
JOptionPane.showMessageDialog(this,
getResources().getString(
"htmlexportdialog.targetIsNotWritable"),
getResources().getString("htmlexportdialog.errorTitle"),
JOptionPane.ERROR_MESSAGE);
return false;
}
final String key1 = "htmlexportdialog.targetOverwriteConfirmation";
final String key2 = "htmlexportdialog.targetOverwriteTitle";
if (JOptionPane.showConfirmDialog(this,
MessageFormat.format(getResources().getString(key1),
new Object[]{getStreamFilename()}
),
getResources().getString(key2),
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE)
== JOptionPane.NO_OPTION)
{
return false;
}
}
return true;
}
/**
* Validates the contents of the dialog's input fields. If the selected file exists, it is also
* checked for validity.
*
* @return true, if the input is valid, false otherwise
*/
public boolean performValidateZip()
{
final String filename = getZipFilename();
if (filename.trim().length() == 0)
{
JOptionPane.showMessageDialog(this,
getResources().getString("htmlexportdialog.targetIsEmpty"),
getResources().getString("htmlexportdialog.errorTitle"),
JOptionPane.ERROR_MESSAGE);
return false;
}
final File f = new File(filename);
if (f.exists())
{
if (f.isFile() == false)
{
JOptionPane.showMessageDialog(this,
getResources().getString("htmlexportdialog.targetIsNoFile"),
getResources().getString("htmlexportdialog.errorTitle"),
JOptionPane.ERROR_MESSAGE);
return false;
}
if (f.canWrite() == false)
{
JOptionPane.showMessageDialog(this,
getResources().getString(
"htmlexportdialog.targetIsNotWritable"),
getResources().getString("htmlexportdialog.errorTitle"),
JOptionPane.ERROR_MESSAGE);
return false;
}
final String key1 = "htmlexportdialog.targetOverwriteConfirmation";
final String key2 = "htmlexportdialog.targetOverwriteTitle";
if (JOptionPane.showConfirmDialog(this,
MessageFormat.format(getResources().getString(key1),
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -