📄 settingsdialog.java
字号:
/*
* Copyright (c) 2002-2008 TeamDev Ltd. All rights reserved.
*
* Use is subject to license terms.
*
* The complete licence text can be found at
* http://www.teamdev.com/winpack/license.jsf
*/
package teamdev.jxcapture.samples.demo;
import teamdev.jxdesktop.PlatformContext;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.io.File;
import java.util.ResourceBundle;
/**
* @author Ikryanov Vladimir
*/
public abstract class SettingsDialog extends EscapeDialog {
protected static SettingsDialog instance;
protected JCheckBox includeCursor = new JCheckBox();
protected JCheckBox transparentWindows = new JCheckBox();
protected JCheckBox delay = new JCheckBox();
protected JCheckBox autoSave = new JCheckBox();
//may be add action?
protected JLabel folderLabel = new JLabel();
protected JLabel formatLabel = new JLabel();
protected JLabel delayTimeLabel = new JLabel();
protected JTextField outputFolder;
protected JTextField templateName;
protected JSpinner templateNumber = new JSpinner();
protected JSpinner delayTime = new JSpinner();
protected JComboBox formats;
protected JButton chooseFolder = new JButton("...");
protected ApplicationSettings settings = ApplicationSettings.getInstance();
protected ResourceBundle resource = ApplicationSettings.getResourceBundle();
protected SettingsDialog() {
createGUI();
pack();
setTitle(resource.getString("SettingsDialog.Title"));
setLocationRelativeTo(null);
setResizable(false);
}
public static SettingsDialog getInstance() {
if (instance == null) {
if (PlatformContext.isWindows()) {
instance = new WindowsSettingsDialog();
} else {
instance = new MacOSSettingsDialog();
}
}
return instance;
}
private void createGUI() {
setContentPane(createSettingsPane());
}
protected JPanel createSettingsPane() {
JPanel settingsPane = new JPanel(new GridBagLayout());
settingsPane.add(createContentPane(), new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0,
GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
settingsPane.add(Box.createGlue(), new GridBagConstraints(0, 1, 1, 1, 0.0, 1.0,
GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
settingsPane.setBorder(new EmptyBorder(10, 10, 10, 10));
return settingsPane;
}
abstract protected JPanel createContentPane();
abstract protected JPanel createFilePane();
abstract protected JPanel createCapturePane();
protected JPanel createDelayTimePane() {
int value = settings.getDelayTime() / 1000;
int maximum = settings.getMaxDelayTime() / 1000;
delayTime.setModel(new SpinnerNumberModel(value, 1, maximum, 1));
delayTime.setPreferredSize(new Dimension(50, 20));
delay.setText(resource.getString("SettingsDialog.Action.DelayBefore.Text"));
delay.setSelected(settings.isDelayBeforeCapture());
delayTimeLabel.setText(resource.getString("SettingsDialog.Label.Seconds.Text"));
JPanel delayTimePane = layoutDelayTimePane();
updateDelayArea();
return delayTimePane;
}
abstract protected JPanel layoutDelayTimePane();
protected void updateDelayArea() {
boolean selected = delay.isSelected();
delayTime.setEnabled(selected);
delayTimeLabel.setEnabled(selected);
}
protected void updateAutoSave() {
boolean selected = autoSave.isSelected();
folderLabel.setEnabled(selected);
formatLabel.setEnabled(selected);
outputFolder.setEnabled(selected);
chooseFolder.setEnabled(selected);
formats.setEnabled(selected);
}
protected String getOutputFolder() {
String outputPath = outputFolder.getText();
if (outputPath.length() == 0) {
String title = resource.getString("SettingsDialog.Error.EmptyFolder.Title");
String message = resource.getString("SettingsDialog.Error.EmptyFolder.Message");
JOptionPane.showMessageDialog(SettingsDialog.this, message, title, JOptionPane.ERROR_MESSAGE);
return null;
} else if (!new File(outputPath).exists()) {
String title = resource.getString("SettingsDialog.Error.ExistFolder.Title");
String message = resource.getString("SettingsDialog.Error.ExistFolder.Message");
JOptionPane.showMessageDialog(SettingsDialog.this, message, title, JOptionPane.ERROR_MESSAGE);
return null;
}
return outputPath;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -