⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 windowssettingsdialog.java

📁 Java版本的屏幕截图 工具,可以自己放到系统托盘使用
💻 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 javax.swing.*;import javax.swing.border.EmptyBorder;import javax.swing.plaf.BorderUIResource;import java.awt.*;import java.awt.event.ActionEvent;/** * @author slavapak */public class WindowsSettingsDialog extends SettingsDialog {        public WindowsSettingsDialog() {        delay.setAction(new DelayBeforeCaptureAction());    }    protected JPanel createContentPane() {        settings.setCaptureTransparentWindows(true);        JPanel mainPane = new JPanel(new GridBagLayout());        mainPane.add(createCapturePane(), new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0,                GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));        mainPane.add(createFilePane(), new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0,                GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));        return mainPane;    }    protected JPanel createSettingsPane() {        JPanel settingsPane = super.createSettingsPane();        settingsPane.add(createActionPane(), new GridBagConstraints(0, 2, 1, 1, 1.0, 0.0,                GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));        return settingsPane;    }    private JPanel createActionPane() {        Dimension buttonSize = new Dimension(75, 23);        JButton okButton = new JButton(new ApplyAction());        okButton.setPreferredSize(buttonSize);        JButton cancelButton = new JButton(new CancelAction());        cancelButton.setPreferredSize(buttonSize);        JPanel actionPane = new JPanel(new GridBagLayout());        actionPane.add(Box.createHorizontalGlue(), new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0,                GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));        actionPane.add(okButton, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,                GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));        actionPane.add(cancelButton, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0,                GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 6, 0, 0), 0, 0));        actionPane.setBorder(new EmptyBorder(10, 0, 0, 0));        return actionPane;    }    protected JPanel createCapturePane() {        includeCursor.setText(resource.getString("SettingsDialog.Label.IncludeCursor.Text"));        includeCursor.setSelected(settings.isIncludeCursor());        transparentWindows.setText(resource.getString("SettingsDialog.Label.CaptureTransparentWindows.Text"));        transparentWindows.setSelected(settings.isCaptureTransparentWindows());        JPanel contentPane = new JPanel(new GridBagLayout());        String title = resource.getString("SettingsDialog.Border.Capture.Text");        contentPane.setBorder(new BorderUIResource.TitledBorderUIResource(title));        contentPane.add(includeCursor, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0,                GridBagConstraints.WEST, GridBagConstraints.WEST, new Insets(0, 10, 3, 10), 0, 0));        contentPane.add(transparentWindows, new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0,                GridBagConstraints.WEST, GridBagConstraints.WEST, new Insets(0, 10, 3, 10), 0, 0));        contentPane.add(createDelayTimePane(), new GridBagConstraints(0, 2, 1, 1, 1.0, 0.0,                GridBagConstraints.WEST, GridBagConstraints.WEST, new Insets(0, 0, 0, 0), 0, 0));        return contentPane;    }    protected JPanel layoutDelayTimePane() {        JPanel delayTimePane = new JPanel(new GridBagLayout());        delayTimePane.add(delay, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,                GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 10, 10, 0), 0, 0));        delayTimePane.add(delayTime, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,                GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 3, 10, 3), 0, 0));        delayTimePane.add(delayTimeLabel, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0,                GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 3, 10, 10), 0, 0));        return delayTimePane;    }    protected JPanel createFilePane() {        JPanel contentPane = new JPanel(new GridBagLayout());        String title = resource.getString("SettingsDialog.Border.File.Text");        contentPane.setBorder(new BorderUIResource.TitledBorderUIResource(title));        templateName = new JTextField(settings.getTemplateFileName(), 10);        int value = settings.getTemplateNumber();        SpinnerModel spinnerModel = new SpinnerNumberModel(value < 1 ? 1 : value, 1, 1000, 1);        templateNumber.setModel(spinnerModel);        templateNumber.setPreferredSize(new Dimension(45, 20));        outputFolder = new JTextField(settings.getOutputFolder(), 20);        chooseFolder.setPreferredSize(new Dimension(20, 20));        formats = new JComboBox(settings.getImageFormats());        formats.setPreferredSize(new Dimension(60, 20));        formats.setSelectedIndex(settings.getImageFormatIndex());        JPanel fileChoosePane = new JPanel(new GridBagLayout());        fileChoosePane.add(outputFolder, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0,                GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 3), 0, 0));        fileChoosePane.add(chooseFolder, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,                GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 3, 0, 0), 0, 0));        chooseFolder.setAction(new ChooseFolderAction());        folderLabel.setText(resource.getString("SettingsDialog.Label.Folder.Text"));        formatLabel.setText(resource.getString("SettingsDialog.Label.Format.Text"));        autoSave.setAction(new AutoSaveAction());        autoSave.setSelected(settings.isAutoSave());        JLabel fileNameTemplate = new JLabel(resource.getString("SettingsDialog.Label.FileNameTmp.Text"));        JLabel startsFrom = new JLabel(resource.getString("SettingsDialog.Label.StartsFrom.Text"));        contentPane.add(fileNameTemplate, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,                GridBagConstraints.WEST, GridBagConstraints.WEST, new Insets(0, 10, 0, 0), 0, 0));        contentPane.add(templateName, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0,                GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 6, 0, 3), 0, 0));        contentPane.add(startsFrom, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0,                GridBagConstraints.WEST, GridBagConstraints.WEST, new Insets(0, 3, 0, 3), 0, 0));        contentPane.add(this.templateNumber, new GridBagConstraints(3, 0, 2, 1, 0.0, 0.0,                GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 3, 0, 10), 0, 0));        contentPane.add(autoSave, new GridBagConstraints(0, 1, 4, 1, 1.0, 0.0,                GridBagConstraints.WEST, GridBagConstraints.WEST, new Insets(11, 10, 0, 0), 0, 0));        contentPane.add(folderLabel, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0,                GridBagConstraints.EAST, GridBagConstraints.EAST, new Insets(7, 3, 0, 3), 0, 0));        contentPane.add(fileChoosePane, new GridBagConstraints(1, 2, 4, 1, 0.0, 0.0,                GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(7, 3, 0, 10), 0, 0));        contentPane.add(formatLabel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0,                GridBagConstraints.EAST, GridBagConstraints.EAST, new Insets(7, 3, 10, 3), 0, 0));        contentPane.add(formats, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0,                GridBagConstraints.WEST, GridBagConstraints.WEST, new Insets(7, 3, 10, 10), 0, 0));        updateAutoSave();        return contentPane;    }    private class ApplyAction extends AbstractAction {        private ApplyAction() {            putValue(Action.NAME, resource.getString("SettingsDialog.Action.Apply.Text"));        }        public void actionPerformed(ActionEvent e) {            String fileNameTemplate = templateName.getText();            if (fileNameTemplate.length() == 0) {                String title = resource.getString("SettingsDialog.Error.EmptyFileName.Title");                String message = resource.getString("SettingsDialog.Error.EmptyFileName.Message");                JOptionPane.showMessageDialog(WindowsSettingsDialog.this, message, title, JOptionPane.ERROR_MESSAGE);                return;            }            if (autoSave.isSelected()) {                String outputPath = getOutputFolder();                if (outputPath == null) return;                settings.setOutputFolder(outputPath);                settings.setImageFormatIndex(formats.getSelectedIndex());            }            settings.setIncludeCursor(includeCursor.isSelected());            settings.setCaptureTransparentWindows(transparentWindows.isSelected());            settings.setAutoSave(autoSave.isSelected());            settings.setTemplateFileName(fileNameTemplate);            settings.setTemplateNumber(((Integer) templateNumber.getValue()).intValue());            settings.setDelayBeforeCapture(WindowsSettingsDialog.this.delay.isSelected());            if (settings.isDelayBeforeCapture()) {                settings.setDelayTime(((Integer) delayTime.getValue()).intValue() * 1000);            }            instance.dispose();            instance = null;        }    }    private class CancelAction extends AbstractAction {        private CancelAction() {            putValue(Action.NAME, resource.getString("SettingsDialog.Action.Cancel.Text"));        }        public void actionPerformed(ActionEvent e) {            instance.dispose();            instance = null;        }    }    private class AutoSaveAction extends AbstractAction {        protected AutoSaveAction() {            putValue(Action.NAME, resource.getString("SettingsDialog.Action.AutoSave.Text"));        }        public void actionPerformed(ActionEvent e) {            updateAutoSave();        }    }    private class DelayBeforeCaptureAction extends AbstractAction {        protected DelayBeforeCaptureAction() {            putValue(Action.NAME, resource.getString("SettingsDialog.Action.DelayBefore.Text"));        }        public void actionPerformed(ActionEvent e) {            updateDelayArea();        }    }    private class ChooseFolderAction extends AbstractAction {        protected ChooseFolderAction() {            putValue(Action.NAME, "...");        }        public void actionPerformed(ActionEvent e) {            JFileChooser chooser = new JFileChooser();            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);            int result = chooser.showOpenDialog(WindowsSettingsDialog.this);            if (result == JFileChooser.APPROVE_OPTION) {                String absolutePath = chooser.getSelectedFile().getAbsolutePath();                outputFolder.setText(absolutePath);            }        }    }}

⌨️ 快捷键说明

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