本文整理汇总了Java中javax.swing.JFileChooser.setAccessory方法的典型用法代码示例。如果您正苦于以下问题:Java JFileChooser.setAccessory方法的具体用法?Java JFileChooser.setAccessory怎么用?Java JFileChooser.setAccessory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JFileChooser
的用法示例。
在下文中一共展示了JFileChooser.setAccessory方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createProjectChooser
import javax.swing.JFileChooser; //导入方法依赖的package包/类
/** Factory method for project chooser
*/
public static JFileChooser createProjectChooser( boolean defaultAccessory ) {
ProjectManager.getDefault().clearNonProjectCache(); // #41882
OpenProjectListSettings opls = OpenProjectListSettings.getInstance();
JFileChooser chooser = new ProjectFileChooser();
chooser.setFileSelectionMode( JFileChooser.DIRECTORIES_ONLY );
if ("GTK".equals(javax.swing.UIManager.getLookAndFeel().getID())) { // NOI18N
// see BugTraq #5027268
chooser.putClientProperty("GTKFileChooser.showDirectoryIcons", Boolean.TRUE); // NOI18N
//chooser.putClientProperty("GTKFileChooser.showFileIcons", Boolean.TRUE); // NOI18N
}
chooser.setApproveButtonText( NbBundle.getMessage( ProjectChooserAccessory.class, "BTN_PrjChooser_ApproveButtonText" ) ); // NOI18N
chooser.setApproveButtonMnemonic( NbBundle.getMessage( ProjectChooserAccessory.class, "MNM_PrjChooser_ApproveButtonText" ).charAt (0) ); // NOI18N
chooser.setApproveButtonToolTipText (NbBundle.getMessage( ProjectChooserAccessory.class, "BTN_PrjChooser_ApproveButtonTooltipText")); // NOI18N
// chooser.setMultiSelectionEnabled( true );
chooser.setDialogTitle( NbBundle.getMessage( ProjectChooserAccessory.class, "LBL_PrjChooser_Title" ) ); // NOI18N
//#61789 on old macosx (jdk 1.4.1) these two method need to be called in this order.
chooser.setAcceptAllFileFilterUsed( false );
chooser.setFileFilter( ProjectDirFilter.INSTANCE );
// A11Y
chooser.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(ProjectChooserAccessory.class, "AN_ProjectChooserAccessory"));
chooser.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ProjectChooserAccessory.class, "AD_ProjectChooserAccessory"));
if ( defaultAccessory ) {
chooser.setAccessory(new ProjectChooserAccessory(chooser, opls.isOpenSubprojects()));
}
File currDir = null;
String dir = opls.getLastOpenProjectDir();
if ( dir != null ) {
File d = new File( dir );
if ( d.exists() && d.isDirectory() ) {
currDir = d;
}
}
FileUtil.preventFileChooserSymlinkTraversal(chooser, currDir);
new ProjectFileView(chooser);
return chooser;
}
示例2: showDialog
import javax.swing.JFileChooser; //导入方法依赖的package包/类
/** Shows dialog with the artifact chooser
* @return null if canceled selected jars if some jars selected
*/
static AntArtifactItem[] showDialog( String[] artifactTypes, Project master, Component parent ) {
JFileChooser chooser = ProjectChooser.projectChooser();
chooser.setDialogTitle( NbBundle.getMessage( AntArtifactChooser.class, "LBL_AACH_Title" ) ); // NOI18N
chooser.setApproveButtonText( NbBundle.getMessage( AntArtifactChooser.class, "LBL_AACH_SelectProject" ) ); // NOI18N
chooser.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage (AntArtifactChooser.class,"AD_AACH_SelectProject"));
AntArtifactChooser accessory = new AntArtifactChooser( artifactTypes, chooser );
chooser.setAccessory( accessory );
chooser.setPreferredSize( new Dimension( 650, 380 ) );
File defaultFolder = null;
FileObject defFo = master.getProjectDirectory();
if (defFo != null) {
defFo = defFo.getParent();
if (defFo != null) {
defaultFolder = FileUtil.toFile(defFo);
}
}
chooser.setCurrentDirectory (getLastUsedArtifactFolder(defaultFolder));
int option = chooser.showOpenDialog( parent ); // Show the chooser
if ( option == JFileChooser.APPROVE_OPTION ) {
File dir = chooser.getSelectedFile();
dir = FileUtil.normalizeFile (dir);
Project selectedProject = accessory.getProject( dir );
if ( selectedProject == null ) {
return null;
}
if ( selectedProject.getProjectDirectory().equals( master.getProjectDirectory() ) ) {
DialogDisplayer.getDefault().notify( new NotifyDescriptor.Message(
NbBundle.getMessage( AntArtifactChooser.class, "MSG_AACH_RefToItself" ),
NotifyDescriptor.INFORMATION_MESSAGE ) );
return null;
}
if ( ProjectUtils.hasSubprojectCycles( master, selectedProject ) ) {
DialogDisplayer.getDefault().notify( new NotifyDescriptor.Message(
NbBundle.getMessage( AntArtifactChooser.class, "MSG_AACH_Cycles" ),
NotifyDescriptor.INFORMATION_MESSAGE ) );
return null;
}
boolean noSuitableOutput = true;
for (String type : artifactTypes) {
if (AntArtifactQuery.findArtifactsByType(selectedProject, type).length > 0) {
noSuitableOutput = false;
break;
}
}
if (noSuitableOutput) {
DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(
NbBundle.getMessage (AntArtifactChooser.class,"MSG_NO_JAR_OUTPUT")));
return null;
}
setLastUsedArtifactFolder (FileUtil.normalizeFile(chooser.getCurrentDirectory()));
Object[] tmp = new Object[accessory.jListArtifacts.getModel().getSize()];
int count = 0;
for(int i = 0; i < tmp.length; i++) {
if (accessory.jListArtifacts.isSelectedIndex(i)) {
tmp[count] = accessory.jListArtifacts.getModel().getElementAt(i);
count++;
}
}
AntArtifactItem artifactItems[] = new AntArtifactItem[count];
System.arraycopy(tmp, 0, artifactItems, 0, count);
return artifactItems;
}
else {
return null;
}
}
示例3: importDiff
import javax.swing.JFileChooser; //导入方法依赖的package包/类
private static void importDiff(VCSContext ctx) {
final File roots[] = HgUtils.getActionRoots(ctx);
if (roots == null || roots.length == 0) return;
final File root = Mercurial.getInstance().getRepositoryRoot(roots[0]);
final JFileChooser fileChooser = new AccessibleJFileChooser(NbBundle.getMessage(ImportDiffAction.class, "ACSD_ImportBrowseFolder"), null); // NO I18N
fileChooser.setDialogTitle(NbBundle.getMessage(ImportDiffAction.class, "ImportBrowse_title")); // NO I18N
fileChooser.setMultiSelectionEnabled(false);
fileChooser.setDialogType(JFileChooser.OPEN_DIALOG);
fileChooser.setApproveButtonMnemonic(NbBundle.getMessage(ImportDiffAction.class, "Import").charAt(0)); // NO I18N
fileChooser.setApproveButtonText(NbBundle.getMessage(ImportDiffAction.class, "Import")); // NO I18N
fileChooser.setCurrentDirectory(new File(HgModuleConfig.getDefault().getImportFolder()));
JPanel panel = new JPanel();
final JRadioButton asPatch = new JRadioButton(NbBundle.getMessage(ImportDiffAction.class, "CTL_Import_PatchOption")); //NOI18N
org.openide.awt.Mnemonics.setLocalizedText(asPatch, asPatch.getText()); // NOI18N
final JRadioButton asBundle = new JRadioButton(NbBundle.getMessage(ImportDiffAction.class, "CTL_Import_BundleOption")); //NOI18N
org.openide.awt.Mnemonics.setLocalizedText(asBundle, asBundle.getText()); // NOI18N
ButtonGroup buttonGroup = new ButtonGroup();
buttonGroup.add(asBundle);
buttonGroup.add(asPatch);
asPatch.setSelected(true);
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.add(asPatch);
panel.add(asBundle);
fileChooser.setAccessory(panel);
DialogDescriptor dd = new DialogDescriptor(fileChooser, NbBundle.getMessage(ImportDiffAction.class, "ImportBrowse_title")); // NO I18N
dd.setOptions(new Object[0]);
final Dialog dialog = DialogDisplayer.getDefault().createDialog(dd);
fileChooser.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String state = e.getActionCommand();
if (state.equals(JFileChooser.APPROVE_SELECTION)) {
final File patchFile = fileChooser.getSelectedFile();
HgModuleConfig.getDefault().setImportFolder(patchFile.getParent());
RequestProcessor rp = Mercurial.getInstance().getRequestProcessor(root);
ImportDiffProgressSupport.Kind kind;
if (asBundle.isSelected()) {
kind = ImportDiffProgressSupport.Kind.BUNDLE;
} else if (asPatch.isSelected()) {
kind = ImportDiffProgressSupport.Kind.PATCH;
} else {
kind = null;
}
HgProgressSupport support = new ImportDiffProgressSupport(root, patchFile, true, kind);
support.start(rp, root, org.openide.util.NbBundle.getMessage(ImportDiffAction.class, "LBL_ImportDiff_Progress")); // NOI18N
}
dialog.dispose();
}
});
dialog.setVisible(true);
}
示例4: exportAsImage
import javax.swing.JFileChooser; //导入方法依赖的package包/类
/**
* Export the current graph as image by using a file selection dialog.
*/
private void exportAsImage() {
String currentFolder = null;
if (Application.getGlobalInfo() != null) {
// --- Get the last selected folder of Agent.GUI ---
currentFolder = Application.getGlobalInfo().getLastSelectedFolderAsString();
}
// --- Create instance of JFileChooser -----------------
JFileChooser jfc = new JFileChooser();
jfc.setMultiSelectionEnabled(false);
jfc.setAcceptAllFileFilterUsed(false);
// --- Add custom icons for file types. ----------------
jfc.setFileView(new ImageFileView());
// --- Add the preview pane. ---------------------------
jfc.setAccessory(new ImagePreview(jfc));
// --- Set the file filter -----------------------------
String[] extensionsJPEG = { ImageUtils.jpg, ImageUtils.jpeg };
ConfigurableFileFilter filterJPG = new ConfigurableFileFilter(extensionsJPEG, "JPEG - Image");
ConfigurableFileFilter filterPNG = new ConfigurableFileFilter(ImageUtils.png, "PNG - File");
ConfigurableFileFilter filterGIF = new ConfigurableFileFilter(ImageUtils.gif, "GIF - Image");
jfc.addChoosableFileFilter(filterGIF);
jfc.addChoosableFileFilter(filterJPG);
jfc.addChoosableFileFilter(filterPNG);
jfc.setFileFilter(filterPNG);
// --- Maybe set the current directory -----------------
if (currentFolder != null) {
jfc.setCurrentDirectory(new File(currentFolder));
}
// === Show dialog and wait on user action =============
int state = jfc.showSaveDialog(this);
if (state == JFileChooser.APPROVE_OPTION) {
ConfigurableFileFilter cff = (ConfigurableFileFilter) jfc.getFileFilter();
String selectedExtension = cff.getFileExtension()[0];
String mustExtension = "." + selectedExtension;
File selectedFile = jfc.getSelectedFile();
if (selectedFile != null) {
String selectedPath = selectedFile.getAbsolutePath();
if (selectedPath.endsWith(mustExtension) == false) {
selectedPath = selectedPath + mustExtension;
}
// ---------------------------------------------
// --- Export current display to image ---------
// ---------------------------------------------
this.exportAsImage(this.getVisualizationViewer(), selectedPath, selectedExtension);
// ---------------------------------------------
if (Application.getGlobalInfo() != null) {
Application.getGlobalInfo().setLastSelectedFolder(jfc.getCurrentDirectory());
}
}
} // end APPROVE_OPTION
}
示例5: saveAsImage
import javax.swing.JFileChooser; //导入方法依赖的package包/类
private void saveAsImage(){
// --- Determine image size ----------------------------
Integer imageWidth = Integer.parseInt(this.getTfImageWidth().getText());
if (imageWidth==0) {
JOptionPane.showMessageDialog(this, Language.translate("Bitte nur ganze Zahlen größer 0 eingeben!"), Language.translate("Fehlerhafte Eingabe"), JOptionPane.ERROR_MESSAGE);
this.setImageDefaultValues();
return;
}
Integer imageHeight = Integer.parseInt(this.getTfImageHeight().getText());
if (imageHeight==0) {
JOptionPane.showMessageDialog(this, Language.translate("Bitte nur ganze Zahlen größer 0 eingeben!"), Language.translate("Fehlerhafte Eingabe"), JOptionPane.ERROR_MESSAGE);
this.setImageDefaultValues();
return;
}
String currentFolder = null;
if (Application.getGlobalInfo()!=null) {
// --- Get the last selected folder of Agent.GUI ---
currentFolder = Application.getGlobalInfo().getLastSelectedFolderAsString();
}
// --- Create instance of JFileChooser -----------------
JFileChooser jfc = new JFileChooser();
jfc.setMultiSelectionEnabled(false);
jfc.setAcceptAllFileFilterUsed(false);
// --- Add custom icons for file types. ----------------
jfc.setFileView(new ImageFileView());
// --- Add the preview pane. ---------------------------
jfc.setAccessory(new ImagePreview(jfc));
// --- Set the file filter -----------------------------
String[] extensionsJPEG = {ImageUtils.jpg, ImageUtils.jpeg};
ConfigurableFileFilter filterJPG = new ConfigurableFileFilter(extensionsJPEG, "JPEG - Image");
ConfigurableFileFilter filterPNG = new ConfigurableFileFilter(ImageUtils.png, "PNG - File");
ConfigurableFileFilter filterGIF = new ConfigurableFileFilter(ImageUtils.gif, "GIF - Image");
jfc.addChoosableFileFilter(filterGIF);
jfc.addChoosableFileFilter(filterJPG);
jfc.addChoosableFileFilter(filterPNG);
jfc.setFileFilter(filterPNG);
// --- Maybe set the current directory -----------------
if (currentFolder != null) {
jfc.setCurrentDirectory(new File(currentFolder));
}
// === Show dialog and wait on user action =============
int state = jfc.showSaveDialog(this);
if (state == JFileChooser.APPROVE_OPTION) {
ConfigurableFileFilter cff = (ConfigurableFileFilter) jfc.getFileFilter();
String selectedExtension = cff.getFileExtension()[0];
String mustExtension = "." + selectedExtension;
File selectedFile = jfc.getSelectedFile();
if (selectedFile != null) {
String selectedPath = selectedFile.getAbsolutePath();
if (selectedPath.endsWith(mustExtension) == false) {
selectedPath = selectedPath + mustExtension;
}
BufferedImage image = this.exportChartAsImage(imageWidth, imageHeight);
this.writeImageFile(image, selectedPath, selectedExtension);
if (Application.getGlobalInfo() != null) {
Application.getGlobalInfo().setLastSelectedFolder(jfc.getCurrentDirectory());
}
}
}
}
示例6: sequenceMenuItemActionPerformed
import javax.swing.JFileChooser; //导入方法依赖的package包/类
private void sequenceMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sequenceMenuItemActionPerformed
if (evt.getActionCommand().equals("start")) {
float oldScale = chipCanvas.getScale();
AESequencerInterface aemonseq = (AESequencerInterface) chip.getHardwareInterface();
try {
if ((aemonseq != null) && (aemonseq instanceof AEMonitorSequencerInterface)) {
((AEMonitorSequencerInterface) aemonseq).stopMonitoringSequencing();
}
} catch (HardwareInterfaceException e) {
e.printStackTrace();
}
JFileChooser fileChooser = new JFileChooser();
ChipDataFilePreview preview = new ChipDataFilePreview(fileChooser, chip); // from book swing hacks
fileChooser.addPropertyChangeListener(preview);
fileChooser.setAccessory(preview);
String lastFilePath = prefs.get("AEViewer.lastFile", ""); // getString the last folder
lastFile = new File(lastFilePath);
DATFileFilter datFileFilter = new DATFileFilter();
fileChooser.addChoosableFileFilter(datFileFilter);
fileChooser.setCurrentDirectory(lastFile); // sets the working directory of the chooser
// boolean wasPaused=isPaused();
// setPaused(true);
int retValue = fileChooser.showOpenDialog(this);
if (retValue == JFileChooser.APPROVE_OPTION) {
lastFile = fileChooser.getSelectedFile();
if (lastFile != null) {
recentFiles.addFile(lastFile);
}
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
sequenceFile(lastFile);
}
});
}
fileChooser = null;
// setPaused(false);
// chipCanvas.setScale(oldScale);
} else if (evt.getActionCommand().equals("stop")) {
setPlayMode(PlayMode.LIVE);
stopSequencing();
}
}
示例7: openAEInputFileDialog
import javax.swing.JFileChooser; //导入方法依赖的package包/类
/**
* Called when user asks to open data file file dialog.
*/
@Override
public void openAEInputFileDialog() {
// try{Thread.currentThread().sleep(200);}catch(InterruptedException e){}
float oldScale = viewer.chipCanvas.getScale();
fileChooser = new JFileChooser();
// new TypeAheadSelector(fileChooser);
//com.sun.java.plaf.windows.WindowsFileChooserUI;
// fileChooser.addKeyListener(new KeyAdapter() {
// public void keyTyped(KeyEvent e){
// System.out.println("keycode="+e.getKeyCode());
// }
// });
// System.out.println("fileChooser.getUIClassID()="+fileChooser.getUIClassID());
// KeyListener[] keyListeners=fileChooser.getKeyListeners();
ChipDataFilePreview preview = new ChipDataFilePreview(fileChooser, viewer.getChip());
// from book swing hacks
new FileDeleter(fileChooser, preview);
fileChooser.addPropertyChangeListener(preview);
fileChooser.setAccessory(preview);
String lastFilePath = AEViewer.prefs.get("AEViewer.lastFile", "");
// get the last folder
viewer.lastFile = new File(lastFilePath);
// fileChooser.setFileFilter(datFileFilter);
IndexFileFilter indexFileFilter = new IndexFileFilter();
fileChooser.addChoosableFileFilter(indexFileFilter);
DATFileFilter datFileFilter = new DATFileFilter();
fileChooser.addChoosableFileFilter(datFileFilter);
if (lastFilter == null) {
fileChooser.setFileFilter(datFileFilter);
} else {
fileChooser.setFileFilter(lastFilter);
}
fileChooser.setCurrentDirectory(viewer.lastFile);
// sets the working directory of the chooser
// boolean wasPaused=isPaused();
setPaused(true);
try {
int retValue = fileChooser.showOpenDialog(viewer);
if (retValue == JFileChooser.APPROVE_OPTION) {
lastFilter = fileChooser.getFileFilter();
try {
viewer.lastFile = fileChooser.getSelectedFile();
if (viewer.lastFile != null) {
viewer.recentFiles.addFile(viewer.lastFile);
}
startPlayback(viewer.lastFile);
} catch (IOException fnf) {
log.warning(fnf.toString());
}
} else {
preview.showFile(null);
}
} catch (GLException e) {
log.warning(e.toString());
preview.showFile(null);
}
fileChooser = null;
// viewer.chipCanvas.setScale(oldScale);
// restore persistent scale so that we don't get tiny size on next startup
setPaused(false);
}