Java Code Examples for javax.swing.JFileChooser#addPropertyChangeListener()

The following examples show how to use javax.swing.JFileChooser#addPropertyChangeListener() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
private static void track(JFileChooser chooser, final String key) {
  // get the path for the given filechooser
  String path = node().get(key, null);
  if (path != null) {
    File file = new File(path);
    if (file.exists()) {
      chooser.setCurrentDirectory(file);
    }
  }

  PropertyChangeListener trackPath = new PropertyChangeListener() {
    public void propertyChange(PropertyChangeEvent evt) {
      /* everytime the path change, update the preferences */
      if (evt.getNewValue() instanceof File) {
        node().put(key, ((File) evt.getNewValue()).getAbsolutePath());
      }
    }
  };

  chooser.addPropertyChangeListener(JFileChooser.DIRECTORY_CHANGED_PROPERTY,
      trackPath);
}
 
Example 2
/** Creates new form ProjectChooserAccessory */
public ProjectChooserAccessory(JFileChooser chooser, boolean isOpenSubprojects) {
    initComponents();

    modelUpdater = new ModelUpdater();
    //#98080
    RP = new RequestProcessor(ModelUpdater.class.getName(), 1);
    RP2 = new RequestProcessor(ModelUpdater.class.getName(), 1);
    updateSubprojectsTask = RP.create(modelUpdater);
    updateSubprojectsTask.setPriority( Thread.MIN_PRIORITY );

    // Listen on the subproject checkbox to change the option accordingly
    jCheckBoxSubprojects.setSelected( isOpenSubprojects );
    jCheckBoxSubprojects.addActionListener( this );

    // Listen on the chooser to update the Accessory
    chooser.addPropertyChangeListener( this );

    // Set default list model for the subprojects list
    jListSubprojects.setModel( new DefaultListModel() );

    // Disable the Accessory. JFileChooser does not select a file
    // by default
    setAccessoryEnablement( false, 0 );
}
 
Example 3
public static String showDialog(Component parent, String title, String initialImage) {
			
	JFileChooser fc = new JFileChooser();
       ImagePreviewPanel previewPane = new ImagePreviewPanel();
       fc.setAccessory(previewPane);
       fc.addPropertyChangeListener(previewPane);
       fc.setDialogTitle(I18NSupport.getString("image.title"));
       fc.setAcceptAllFileFilterUsed(false);
       fc.addChoosableFileFilter(new ImageFilter());
       
       int returnVal = fc.showOpenDialog(Globals.getMainFrame());
       if (returnVal == JFileChooser.APPROVE_OPTION) {
           final File f = fc.getSelectedFile();
           if (f != null) {
           	 try {
                    FileUtil.copyToDir(f, new File(Globals.getCurrentReportAbsolutePath()).getParentFile(), true);                
                } catch (IOException e) {
                    e.printStackTrace();  
                }
           	return f.getName();
           }            
       } 
       return null;        		       
}
 
Example 4
Source Project: netbeans   File: AntArtifactChooser.java    License: Apache License 2.0 5 votes vote down vote up
/** Creates new form JarArtifactChooser */
public AntArtifactChooser( String[] artifactTypes, JFileChooser chooser ) {
    this.artifactTypes = artifactTypes;
    
    initComponents();
    jListArtifacts.setModel( new DefaultListModel() );
    chooser.addPropertyChangeListener( this );
}
 
Example 5
public OutDirWizardPage () {
   super( PAGE_OUT_DIR, getDescription(), CPSWizardPage.WIZ_TYPE_PRE_INIT );

   setLongDescription( getDescription() );

   setPreferredSize( panelDim );
   setMaximumSize( panelDim );

   JLabel lblOutDir = new JLabel( "<html><body style='width: 300px'>" +
                                  "<b>Select a folder or directory to store all of your crop planning data.</b>" +
                                  "<p><p>If you have already used this program to create crop plans and would like to load that information, " +
                                  "please select the folder or directory which contains your existing data. " +
                                  "(The data files have names that start with \"CPSdb\".)" +
                                  "" );
   lblOutDir.setAlignmentX( Component.CENTER_ALIGNMENT );

   String defaultDirectory = CPSGlobalSettings.getOutputDir();
   flchOutDir = new JFileChooser();
   flchOutDir.setSelectedFile( new File( defaultDirectory ) );
   flchOutDir.setName( SETTING_OUT_DIR );
   flchOutDir.setFileSelectionMode( JFileChooser.DIRECTORIES_ONLY );
   flchOutDir.setMultiSelectionEnabled( false );
   flchOutDir.setControlButtonsAreShown( false );
   flchOutDir.addPropertyChangeListener( new PropertyChangeListener() {

      public void propertyChange ( PropertyChangeEvent evt ) {
         if ( evt.getPropertyName().equals( JFileChooser.SELECTED_FILE_CHANGED_PROPERTY ) ) {
            outDirIsSelected = ( evt.getNewValue() != null ) ? true : false;
            userInputReceived( flchOutDir, evt );
         }
      }
   } ); // new PropChangeListener
   flchOutDir.setPreferredSize( fileDim );
   flchOutDir.setMaximumSize( fileDim );

   add( lblOutDir );
   add( flchOutDir );
}
 
Example 6
public PreviewPane(JFileChooser chooser) {
    chooser.setAccessory(this);
    chooser.addPropertyChangeListener(this);
    setLayout(new BorderLayout(5, 5));
    setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    previewDetails = new JLabel("Preview:");
    add(previewDetails, BorderLayout.NORTH);
    label = new JLabel();
    label.setBackground(Color.WHITE);
    label.setPreferredSize(new Dimension(200, 200));
    maxImgWidth = 195;
    label.setOpaque(false);
    label.setBorder(BorderFactory.createEtchedBorder());
    add(label, BorderLayout.CENTER);
}
 
Example 7
DeckDescriptionPreview(JFileChooser fc) {
    setPreferredSize(new Dimension(200, 50));
    setLayout(new BorderLayout());
    textArea.setEditable(false);
    textArea.setLineWrap(true);
    textArea.setWrapStyleWord(true);
    add(scrollPane, BorderLayout.CENTER);
    fc.addPropertyChangeListener(this);
}
 
Example 8
@SuppressWarnings("LeakingThisInConstructor")
public FilePreviewer(JFileChooser fc) {
    setPreferredSize(new Dimension(100, 50));
    fc.addPropertyChangeListener(this);
}
 
Example 9
/** Constructs a preview pane for the given file chooser. */
public PreviewPane(final Context context, final JFileChooser jc) {
	super();

	context.inject(this);

	// create view
	setBorder(new EmptyBorder(0, 10, 0, 10));
	setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
	iconLabel = new JLabel();
	iconLabel.setMinimumSize(new java.awt.Dimension(128, -1));
	iconLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
	add(iconLabel);
	add(Box.createVerticalStrut(7));
	formatLabel = new JLabel();
	formatLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
	add(formatLabel);
	add(Box.createVerticalStrut(5));
	resLabel = new JLabel();
	resLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
	add(resLabel);
	zctLabel = new JLabel();
	zctLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
	add(zctLabel);
	typeLabel = new JLabel();
	typeLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
	add(typeLabel);

	// smaller font for most labels
	Font font = formatLabel.getFont();
	font = font.deriveFont(font.getSize2D() - 3);
	formatLabel.setFont(font);
	resLabel.setFont(font);
	zctLabel.setFont(font);
	typeLabel.setFont(font);

	// populate model
	icon = null;
	iconText = formatText = resText = npText = typeText = "";
	iconTip = formatTip = resTip = zctTip = typeTip = null;

	if (jc != null) {
		jc.setAccessory(this);
		jc.addPropertyChangeListener(this);

		refresher = new Runnable() {

			@Override
			public void run() {
				iconLabel.setIcon(icon);
				iconLabel.setText(iconText);
				iconLabel.setToolTipText(iconTip);
				formatLabel.setText(formatText);
				formatLabel.setToolTipText(formatTip);
				resLabel.setText(resText);
				resLabel.setToolTipText(resTip);
				zctLabel.setText(npText);
				zctLabel.setToolTipText(zctTip);
				typeLabel.setText(typeText);
				typeLabel.setToolTipText(typeTip);
			}
		};

		// start separate loader thread
		loaderAlive = true;
		loader = new Thread(this, "Preview");
		loader.start();
	}
}
 
Example 10
public ImagePreview(JFileChooser fc) {
    setPreferredSize(new Dimension(200, 200));
    fc.addPropertyChangeListener(this);
}
 
Example 11
@SuppressWarnings("LeakingThisInConstructor")
public FilePreviewer(JFileChooser fc) {
    setPreferredSize(new Dimension(100, 50));
    fc.addPropertyChangeListener(this);
}
 
Example 12
@SuppressWarnings("LeakingThisInConstructor")
public FilePreviewer(JFileChooser fc) {
    setPreferredSize(new Dimension(100, 50));
    fc.addPropertyChangeListener(this);
}
 
Example 13
@SuppressWarnings("LeakingThisInConstructor")
public FilePreviewer(JFileChooser fc) {
    setPreferredSize(new Dimension(100, 50));
    fc.addPropertyChangeListener(this);
}
 
Example 14
@SuppressWarnings("LeakingThisInConstructor")
public FilePreviewer(JFileChooser fc) {
    setPreferredSize(new Dimension(100, 50));
    fc.addPropertyChangeListener(this);
}
 
Example 15
@SuppressWarnings("LeakingThisInConstructor")
public FilePreviewer(JFileChooser fc) {
    setPreferredSize(new Dimension(100, 50));
    fc.addPropertyChangeListener(this);
}
 
Example 16
public void attachTo(JFileChooser chooser) {
    chooser.setAccessory(this);
    chooser.addPropertyChangeListener(this);
}
 
Example 17
Source Project: chipster   File: RemoteSessionAccessory.java    License: MIT License 4 votes vote down vote up
public RemoteSessionAccessory(JFileChooser fileChooser, SessionManager sessionManager, SwingClientApplication app) throws AuthCancelledException {
		
		this.fileChooser = fileChooser;
		this.sessionManager = sessionManager;
		this.app = app;
		
		fileChooser.addPropertyChangeListener(this);		
		
		panel.setLayout(new MigLayout("", "[fill]", ""));
		panel.setBackground(Color.white);
		panel.setBorder(new LineBorder(VisualConstants.TOOL_LIST_BORDER_COLOR));		

		removeButton.addActionListener(this);
		
		disclaimerText.setLineWrap(true);
		lowDiskUsageText.setLineWrap(true);
		highDiskUsageText.setLineWrap(true);
		
		disclaimerText.setWrapStyleWord(true);
		lowDiskUsageText.setWrapStyleWord(true);
		highDiskUsageText.setWrapStyleWord(true);
		
		disclaimerText.setEditable(false);
		lowDiskUsageText.setEditable(false);
		highDiskUsageText.setEditable(false);
		
		disclaimerText.setOpaque(false);
		lowDiskUsageText.setOpaque(false);
		highDiskUsageText.setOpaque(false);
		
		quotaBar.setStringPainted(true);
		quotaBar.setBackground(Color.white);
		// get rid of a blue shadow by removing the border of the JProggresBar
		// and using JPanel to show the border
		quotaBar.setBorderPainted(false);
		quotaBar.setBorder(null);
		JPanel quotaPanel = new JPanel(new MigLayout("fill, gap 0!, insets 0"));
		quotaPanel.setBorder(new LineBorder(Color.GRAY));
		quotaPanel.add(quotaBar, "growx, width 300px");
		
		manageTitle.setFont(UIManager.getFont("TitledBorder.font"));
		diskUsageTitle.setFont(UIManager.getFont("TitledBorder.font"));
		disclaimerTitle.setFont(UIManager.getFont("TitledBorder.font"));
		cloudTitle.setFont(UIManager.getFont("TitledBorder.font"));
		temporaryTitle.setFont(UIManager.getFont("TitledBorder.font"));
		
		manageTitle.setForeground(UIManager.getColor("TitledBorder.titleColor"));
		diskUsageTitle.setForeground(UIManager.getColor("TitledBorder.titleColor"));		
		disclaimerTitle.setForeground(UIManager.getColor("TitledBorder.titleColor"));
		cloudTitle.setForeground(UIManager.getColor("TitledBorder.titleColor"));
		temporaryTitle.setForeground(UIManager.getColor("TitledBorder.titleColor"));
		

		panel.add(cloudTitle, "span, wrap");
		panel.add(new JLabel(cloudInfo), "skip, wrap");

//		panel.add(disclaimerTitle, "span, wrap, gap top 15");
//		panel.add(disclaimerText, "skip, wrap");

		panel.add(manageTitle, "span, wrap, gap top 15");
		panel.add(previewLabel, "skip, wrap");
		panel.add(removeButton, "sizegroup actions, skip, growx 0, wrap");
		
		panel.add(diskUsageTitle, "span, wrap, gap top 15");
		panel.add(quotaPanel, "skip, wrap");
//		panel.add(lowDiskUsageIcon, "aligny top, gap top 5");
//		panel.add(lowDiskUsageText, "wrap");
//		panel.add(highDiskUsageIcon, "aligny top, gap top 5");
//		panel.add(highDiskUsageText, "wrap");
				
		
		this.setLayout(new MigLayout("fill, insets 0 0 1 1"));
		this.add(panel, "grow");

		update();
	}
 
Example 18
Source Project: javamelody   File: ImageFileChooser.java    License: Apache License 2.0 4 votes vote down vote up
ImageFilePreviewer(JFileChooser fc) {
	super();
	setPreferredSize(new Dimension(100, 85));
	fc.addPropertyChangeListener(this);
	setBorder(BorderFactory.createLoweredBevelBorder());
}
 
Example 19
public ImagePreview(JFileChooser fc) {
	setPreferredSize(new Dimension(200, 100));
	if (fc != null)
		fc.addPropertyChangeListener(this);
	setBorder(new LineBorder(Color.black));
}
 
Example 20
@SuppressWarnings("LeakingThisInConstructor")
public FilePreviewer(JFileChooser fc) {
    setPreferredSize(new Dimension(100, 50));
    fc.addPropertyChangeListener(this);
}