List of usage examples for javax.swing JFileChooser showOpenDialog
public int showOpenDialog(Component parent) throws HeadlessException
From source file:com.floreantpos.ui.model.MenuItemForm.java
protected void doSelectImageFile() { JFileChooser fileChooser = new JFileChooser(); fileChooser.setMultiSelectionEnabled(false); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); int option = fileChooser.showOpenDialog(POSUtil.getBackOfficeWindow()); if (option == JFileChooser.APPROVE_OPTION) { File imageFile = fileChooser.getSelectedFile(); try {// w ww. j a v a2s. c o m byte[] itemImage = FileUtils.readFileToByteArray(imageFile); int imageSize = itemImage.length / 1024; if (imageSize > 20) { POSMessageDialog.showMessage(Messages.getString("MenuItemForm.0")); //$NON-NLS-1$ itemImage = null; return; } ImageIcon imageIcon = new ImageIcon( new ImageIcon(itemImage).getImage().getScaledInstance(80, 80, Image.SCALE_SMOOTH)); lblImagePreview.setIcon(imageIcon); MenuItem menuItem = (MenuItem) getBean(); menuItem.setImageData(itemImage); } catch (IOException e) { PosLog.error(getClass(), e); } } }
From source file:edu.ku.brc.specify.tasks.subpane.wb.ImageFrame.java
protected File[] askUserForImageFiles() { ImageFilter imageFilter = new ImageFilter(); JFileChooser fileChooser = new JFileChooser( WorkbenchTask.getDefaultDirPath(WorkbenchTask.IMAGES_FILE_PATH)); fileChooser.setFileFilter(imageFilter); fileChooser.setDialogTitle(getResourceString("WB_CHOOSE_IMAGES")); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); fileChooser.setMultiSelectionEnabled(true); int userAction = fileChooser.showOpenDialog(this); AppPreferences localPrefs = AppPreferences.getLocalPrefs(); // remember the directory the user was last in localPrefs.put(WorkbenchTask.IMAGES_FILE_PATH, fileChooser.getCurrentDirectory().getAbsolutePath()); if (userAction == JFileChooser.APPROVE_OPTION) { return fileChooser.getSelectedFiles(); }// w w w. ja va2 s . c o m // if for any reason we got to this point... return null; }
From source file:fr.eurecom.hybris.demogui.HybrisDemoGui.java
public void actionPerformed(ActionEvent e) { String cmd = e.getActionCommand(); if (cmd.equals("Get")) { if (lstHybris.getSelectedIndex() >= 0) { try { System.out.println("Retrieving " + lstHybris.getSelectedValue() + "..."); byte[] retrieved = cm.hybris.get(lstHybris.getSelectedValue()); if (retrieved != null) { JFileChooser fc = new JFileChooser( System.getProperty("user.home") + File.separator + "Desktop"); fc.setSelectedFile(new File("RETRIEVED_" + lstHybris.getSelectedValue())); int returnVal = fc.showSaveDialog(frame); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); FileUtils.writeByteArrayToFile(file, retrieved); System.out.println("Saved: " + file.getName() + "."); }/*from www. j av a2 s . co m*/ } else JOptionPane.showMessageDialog(frame, "Hybris could not download the file.", "Error", JOptionPane.ERROR_MESSAGE); } catch (Exception e1) { e1.printStackTrace(); } } } if (cmd.equals("Put")) { JFileChooser fc = new JFileChooser(System.getProperty("user.home") + File.separator + "Desktop"); int returnVal = fc.showOpenDialog(frame); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); System.out.println("Putting: " + file.getName() + "."); byte[] array; try { array = FileUtils.readFileToByteArray(file); new Thread(cm.new BackgroundWorker(OperationType.PUT, ClientType.HYBRIS, file.getName(), array)) .start(); } catch (Exception e1) { e1.printStackTrace(); } } } if (cmd.equals("Delete")) { if (lstHybris.getSelectedIndex() >= 0) { new Thread(cm.new BackgroundWorker(OperationType.DELETE, ClientType.HYBRIS, lstHybris.getSelectedValue(), null)).start(); System.out.println("Removed " + lstHybris.getSelectedValue() + " from Hybris."); } } }
From source file:info.puzz.trackprofiler.gui.TrackProfilerFrame.java
private void loadFilesActionPerformed(ActionEvent evt) throws TrackProfilerException { JFileChooser chooser = null; if (this.folderWithTracks != null) { chooser = new JFileChooser(this.folderWithTracks); } else {//from w w w . ja v a 2 s .c o m chooser = new JFileChooser(); } TrackFileFilter filter = new TrackFileFilter(); filter.addExtension(PLT_EXTENSION); filter.addExtension(WPT_EXTENSION); filter.setDescription(new Message(Messages.PLT_AND_WPT_FILES).toString()); chooser.setFileFilter(filter); chooser.setMultiSelectionEnabled(true); int returnVal = chooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File[] selectedFiles = chooser.getSelectedFiles(); for (int i = 0; i < selectedFiles.length; i++) { File selectedFile = selectedFiles[i]; this.folderWithTracks = selectedFile.getParentFile(); if (selectedFile.getName().toLowerCase().endsWith("." + PLT_EXTENSION)) { //$NON-NLS-1$ try { loadTrack(selectedFile); } catch (FileNotFoundException e) { throw new TrackProfilerException( new Message(Messages.ERROR_WHEN_LOADING).toString() + selectedFile.getName()); } } } for (int i = 0; i < selectedFiles.length; i++) { File selectedFile = selectedFiles[i]; this.folderWithTracks = selectedFile.getParentFile(); if (selectedFile.getName().toLowerCase().endsWith("." + WPT_EXTENSION)) { //$NON-NLS-1$ try { loadWaypoints(selectedFile); } catch (FileNotFoundException e) { throw new TrackProfilerException( new Message(Messages.ERROR_WHEN_LOADING).toString() + selectedFile.getName()); } } } } }
From source file:lejos.pc.charting.LogChartFrame.java
private void selectFolderButton_actionPerformed(ActionEvent e) { this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); JFileChooser jfc = new JFileChooser(new File(FQPathTextArea.getText(), "")); jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); jfc.setApproveButtonText("Select"); jfc.setDialogTitle("Select Directory"); jfc.setDialogType(JFileChooser.OPEN_DIALOG); this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); int returnVal = jfc.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { FQPathTextArea.setText(getCanonicalName(jfc.getSelectedFile())); jfc.setCurrentDirectory(jfc.getSelectedFile()); System.out.println("folder set to \"" + getCanonicalName(jfc.getSelectedFile()) + "\""); }//w w w . j a va 2s . com }
From source file:cs.cirg.cida.CIDAView.java
@Action public void exportSynopsisTable() { JFileChooser chooser = new JFileChooser(experimentController.getDataDirectory()); //model.getActiveExperiment().getName() + ".csv" chooser.setSelectedFile(new File(CIDAConstants.DEFAULT_TABLE_NAME)); int returnVal = chooser.showOpenDialog(this.getComponent()); if (returnVal == JFileChooser.APPROVE_OPTION) { experimentController.exportSynopsisTable(chooser.getSelectedFile()); }/*from w w w.ja v a 2 s.co m*/ }
From source file:com.lp.client.frame.component.PanelDokumentenablage.java
private boolean chooseFile() throws Throwable { final JFileChooser fc = new JFileChooser(); if (defaultEinlesePfad != null) { fc.setCurrentDirectory(new File(defaultEinlesePfad)); }/* w w w . java2s . c o m*/ int retVal = fc.showOpenDialog(this); if (retVal == JFileChooser.APPROVE_OPTION) { file = fc.getSelectedFile(); try { wmcMedia.setOMedia(Helper.getBytesFromFile(file)); return true; } catch (IOException e) { return false; } catch (Throwable e) { return false; } } else { return false; } }
From source file:io.github.jeremgamer.editor.panels.components.ButtonPanel.java
public ButtonPanel(JFrame frame) { this.frame = frame; this.setSize(new Dimension(395, frame.getHeight() - 27 - 23)); this.setLocation(300, 0); this.setBorder(BorderFactory.createTitledBorder("Edition du bouton")); this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); JLabel nameLabel = new JLabel("Nom : "); name.setPreferredSize(new Dimension(this.getWidth() - 285, 30)); name.setEditable(false);/*from w w w.ja v a 2 s . co m*/ JPanel namePanel = new JPanel(); namePanel.add(nameLabel); namePanel.add(name); JPanel textPanel = new JPanel(); JPanel nameAndTextPanel = new JPanel(); JLabel textLabel = new JLabel("Texte :"); CaretListener caretUpdateText = new CaretListener() { public void caretUpdate(javax.swing.event.CaretEvent e) { JTextField text = (JTextField) e.getSource(); bs.set("text", text.getText()); preview.setText(text.getText()); preview2.setText(text.getText()); } }; text.addCaretListener(caretUpdateText); text.setPreferredSize(new Dimension(this.getWidth() - 283, 30)); textPanel.add(textLabel); textPanel.add(text); nameAndTextPanel.setLayout(new BoxLayout(nameAndTextPanel, BoxLayout.PAGE_AXIS)); nameAndTextPanel.add(namePanel); nameAndTextPanel.add(textPanel); JPanel policePanel = new JPanel(); JLabel policeLabel = new JLabel("Police : "); police.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @SuppressWarnings("unchecked") JComboBox<String> combo = (JComboBox<String>) e.getSource(); fontStyle = (String) combo.getSelectedItem(); preview.setFont(new Font(fontStyle, Font.PLAIN, fontSize)); preview2.setFont(new Font(fontStyle, Font.PLAIN, fontSize)); bs.set("police", fontStyle); } }); police.setPreferredSize(new Dimension(105, 30)); GraphicsEnvironment e = GraphicsEnvironment.getLocalGraphicsEnvironment(); Font[] fonts = e.getAllFonts(); for (Font f : fonts) { police.addItem(f.getName()); } police.setSelectedItem("Arial"); policePanel.add(policeLabel); policePanel.add(police); JPanel sizePanel = new JPanel(); size.setPreferredSize(new Dimension(60, 25)); JLabel sizeLabel = new JLabel("Taille : "); sizePanel.add(sizeLabel); sizePanel.add(size); JButton colorButton = new JButton("Couleur"); colorButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { colorFrame.setModal(false); JButton finish = new JButton("Terminer"); finish.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { colorFrame.dispose(); } }); colorFrame.setLayout(new BorderLayout()); colorFrame.add(color, BorderLayout.CENTER); colorFrame.add(finish, BorderLayout.SOUTH); colorFrame.pack(); colorFrame.setLocation(SwingUtilities.windowForComponent(imagedButton).getX() + 325, SwingUtilities.windowForComponent(imagedButton).getY() - colorFrame.getHeight() + 40); colorFrame.setVisible(true); } }); sizePanel.add(colorButton); size.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { JSpinner spinner = (JSpinner) e.getSource(); fontSize = (int) spinner.getValue(); preview.setFont(new Font(fontStyle, Font.PLAIN, fontSize)); preview2.setFont(new Font(fontStyle, Font.PLAIN, fontSize)); bs.set("size", fontSize); } }); JPanel policeAndSize = new JPanel(); policeAndSize.setLayout(new BoxLayout(policeAndSize, BoxLayout.PAGE_AXIS)); policeAndSize.add(policePanel); policeAndSize.add(sizePanel); JPanel top = new JPanel(); top.add(nameAndTextPanel); top.add(policeAndSize); top.setPreferredSize(new Dimension(395, 20)); this.add(top); JPanel images = new JPanel(); images.setBorder(BorderFactory.createTitledBorder("Images")); images.setLayout(new GridLayout(2, 3)); images.setPreferredSize(new Dimension(395, this.getHeight() - 320)); JPanel imaged = new JPanel(); imaged.setLayout(new BorderLayout()); imaged.setBorder(BorderFactory.createTitledBorder("Icne interne")); imagedButton.setSelected(true); imagedButton.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent ev) { if (ev.getStateChange() == ItemEvent.SELECTED) { bs.set("strings", true); preview.setBorderPainted(true); } else if (ev.getStateChange() == ItemEvent.DESELECTED) { bs.set("strings", false); preview.setBorderPainted(false); } } }); JButton browseInternal = new JButton("Parcourir"); browseInternal.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { String path = null; JFileChooser chooser = new JFileChooser(Editor.lastPath); FileNameExtensionFilter filter = new FileNameExtensionFilter("Images", "jpg", "png", "gif", "jpeg", "bmp"); chooser.setFileFilter(filter); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); int option = chooser.showOpenDialog(null); if (option == JFileChooser.APPROVE_OPTION) { path = chooser.getSelectedFile().getAbsolutePath(); Editor.lastPath = chooser.getSelectedFile().getParent(); copyImage(new File(path), "internal.png"); nameInternal.setText(new File(path).getName()); nameInternal.setPreferredSize(new Dimension(imgBasic.getWidth() - 10, 30)); preview.setIcon(new ImageIcon(path)); preview.repaint(); bs.set("imageInternal", new File(path).getName()); } } }); JPanel northImaged = new JPanel(); northImaged.setLayout(new BorderLayout()); northImaged.add(imagedButton, BorderLayout.NORTH); northImaged.add(browseInternal, BorderLayout.SOUTH); imaged.add(northImaged, BorderLayout.NORTH); imaged.add(nameInternal, BorderLayout.CENTER); JButton removeInternal = null; try { removeInternal = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png")))); } catch (IOException e1) { e1.printStackTrace(); } removeInternal.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { File file = new File( "projects/" + Editor.getProjectName() + "/buttons/" + name.getText() + "/internal.png"); file.delete(); nameInternal.setText(""); bs.set("imageInternal", ""); preview.setIcon(null); } }); imaged.add(removeInternal, BorderLayout.SOUTH); images.add(imaged); imgBasic.setBorder(BorderFactory.createTitledBorder("Base")); JButton browseBasic = new JButton("Parcourir"); browseBasic.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { String path = null; JFileChooser chooser = new JFileChooser(Editor.lastPath); FileNameExtensionFilter filter = new FileNameExtensionFilter("Images", "jpg", "png", "gif", "jpeg", "bmp"); chooser.setFileFilter(filter); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); int option = chooser.showOpenDialog(null); if (option == JFileChooser.APPROVE_OPTION) { path = chooser.getSelectedFile().getAbsolutePath(); Editor.lastPath = chooser.getSelectedFile().getParent(); copyImage(new File(path), "basic.png"); nameBasic.setText(new File(path).getName()); nameBasic.setPreferredSize(new Dimension(imgBasic.getWidth() - 10, 30)); previewPanel.remove(preview); previewPanel.remove(preview2); previewPanel.add(preview2); color.changePreview(preview2); bs.set("imageBasic", new File(path).getName()); preview2.update(); previewPanel.repaint(); } } }); imgBasic.setLayout(new BorderLayout()); imgBasic.add(browseBasic, BorderLayout.NORTH); imgBasic.add(nameBasic, BorderLayout.CENTER); JButton removeBasic = null; try { removeBasic = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png")))); } catch (IOException e1) { e1.printStackTrace(); } removeBasic.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { File file = new File( "projects/" + Editor.getProjectName() + "/buttons/" + name.getText() + "/basic.png"); file.delete(); nameBasic.setText(""); bs.set("imageBasic", ""); preview2.update(); previewPanel.repaint(); if (bs.getString("imageBasic").equals("") && bs.getString("imageEntered").equals("") && bs.getString("imageExited").equals("") && bs.getString("imagePressed").equals("") && bs.getString("imageReleased").equals("")) { previewPanel.remove(preview2); previewPanel.add(preview); } } }); imgBasic.add(removeBasic, BorderLayout.SOUTH); images.add(imgBasic); imgEntered.setBorder(BorderFactory.createTitledBorder("Survol")); JButton browseEntered = new JButton("Parcourir"); browseEntered.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { String path = null; JFileChooser chooser = new JFileChooser(Editor.lastPath); FileNameExtensionFilter filter = new FileNameExtensionFilter("Images", "jpg", "png", "gif", "jpeg", "bmp"); chooser.setFileFilter(filter); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); int option = chooser.showOpenDialog(null); if (option == JFileChooser.APPROVE_OPTION) { path = chooser.getSelectedFile().getAbsolutePath(); Editor.lastPath = chooser.getSelectedFile().getParent(); copyImage(new File(path), "entered.png"); nameEntered.setText(new File(path).getName()); nameEntered.setPreferredSize(new Dimension(imgEntered.getWidth() - 10, 30)); bs.set("imageEntered", new File(path).getName()); preview2.update(); previewPanel.repaint(); } } }); imgEntered.setLayout(new BorderLayout()); imgEntered.add(browseEntered, BorderLayout.NORTH); imgEntered.add(nameEntered, BorderLayout.CENTER); JButton removeEntered = null; try { removeEntered = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png")))); } catch (IOException e1) { e1.printStackTrace(); } removeEntered.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { File file = new File( "projects/" + Editor.getProjectName() + "/buttons/" + name.getText() + "/entered.png"); file.delete(); nameEntered.setText(""); bs.set("imageEntered", ""); preview2.update(); previewPanel.repaint(); if (bs.getString("imageBasic").equals("") && bs.getString("imageEntered").equals("") && bs.getString("imageExited").equals("") && bs.getString("imagePressed").equals("") && bs.getString("imageReleased").equals("")) { previewPanel.remove(preview2); previewPanel.add(preview); } } }); imgEntered.add(removeEntered, BorderLayout.SOUTH); images.add(imgEntered); imgExited.setBorder(BorderFactory.createTitledBorder("Sortie")); JButton browseExited = new JButton("Parcourir"); browseExited.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { String path = null; JFileChooser chooser = new JFileChooser(Editor.lastPath); FileNameExtensionFilter filter = new FileNameExtensionFilter("Images", "jpg", "png", "gif", "jpeg", "bmp"); chooser.setFileFilter(filter); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); int option = chooser.showOpenDialog(null); if (option == JFileChooser.APPROVE_OPTION) { path = chooser.getSelectedFile().getAbsolutePath(); Editor.lastPath = chooser.getSelectedFile().getParent(); copyImage(new File(path), "exited.png"); nameExited.setText(new File(path).getName()); nameExited.setPreferredSize(new Dimension(imgExited.getWidth() - 10, 30)); bs.set("imageExited", new File(path).getName()); preview2.update(); previewPanel.repaint(); } } }); imgExited.setLayout(new BorderLayout()); imgExited.add(browseExited, BorderLayout.NORTH); imgExited.add(nameExited, BorderLayout.CENTER); JButton removeExited = null; try { removeExited = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png")))); } catch (IOException e1) { e1.printStackTrace(); } removeExited.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { File file = new File( "projects/" + Editor.getProjectName() + "/buttons/" + name.getText() + "/exited.png"); file.delete(); nameExited.setText(""); bs.set("imageExited", ""); preview2.update(); previewPanel.repaint(); if (bs.getString("imageBasic").equals("") && bs.getString("imageEntered").equals("") && bs.getString("imageExited").equals("") && bs.getString("imagePressed").equals("") && bs.getString("imageReleased").equals("")) { previewPanel.remove(preview2); previewPanel.add(preview); } } }); imgExited.add(removeExited, BorderLayout.SOUTH); images.add(imgExited); imgPressed.setBorder(BorderFactory.createTitledBorder("Clic")); JButton browsePressed = new JButton("Parcourir"); browsePressed.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { String path = null; JFileChooser chooser = new JFileChooser(Editor.lastPath); FileNameExtensionFilter filter = new FileNameExtensionFilter("Images", "jpg", "png", "gif", "jpeg", "bmp"); chooser.setFileFilter(filter); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); int option = chooser.showOpenDialog(null); if (option == JFileChooser.APPROVE_OPTION) { path = chooser.getSelectedFile().getAbsolutePath(); Editor.lastPath = chooser.getSelectedFile().getParent(); copyImage(new File(path), "pressed.png"); namePressed.setText(new File(path).getName()); namePressed.setPreferredSize(new Dimension(imgPressed.getWidth() - 10, 30)); bs.set("imagePressed", new File(path).getName()); preview2.update(); previewPanel.repaint(); } } }); imgPressed.setLayout(new BorderLayout()); imgPressed.add(browsePressed, BorderLayout.NORTH); imgPressed.add(namePressed, BorderLayout.CENTER); JButton removePressed = null; try { removePressed = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png")))); } catch (IOException e1) { e1.printStackTrace(); } removePressed.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { File file = new File( "projects/" + Editor.getProjectName() + "/buttons/" + name.getText() + "/pressed.png"); file.delete(); namePressed.setText(""); bs.set("imagePressed", ""); preview2.update(); previewPanel.repaint(); if (bs.getString("imageBasic").equals("") && bs.getString("imageEntered").equals("") && bs.getString("imageExited").equals("") && bs.getString("imagePressed").equals("") && bs.getString("imageReleased").equals("")) { previewPanel.remove(preview2); previewPanel.add(preview); } } }); imgPressed.add(removePressed, BorderLayout.SOUTH); images.add(imgPressed); imgReleased.setBorder(BorderFactory.createTitledBorder("Relachement")); JButton browseReleased = new JButton("Parcourir"); browseReleased.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { String path = null; JFileChooser chooser = new JFileChooser(Editor.lastPath); FileNameExtensionFilter filter = new FileNameExtensionFilter("Images", "jpg", "png", "gif", "jpeg", "bmp"); chooser.setFileFilter(filter); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); int option = chooser.showOpenDialog(null); if (option == JFileChooser.APPROVE_OPTION) { path = chooser.getSelectedFile().getAbsolutePath(); Editor.lastPath = chooser.getSelectedFile().getParent(); copyImage(new File(path), "released.png"); nameReleased.setText(new File(path).getName()); nameReleased.setPreferredSize(new Dimension(imgReleased.getWidth() - 10, 30)); bs.set("imageReleased", new File(path).getName()); preview2.update(); previewPanel.repaint(); } } }); imgReleased.setLayout(new BorderLayout()); imgReleased.add(browseReleased, BorderLayout.NORTH); imgReleased.add(nameReleased, BorderLayout.CENTER); JButton removeReleased = null; try { removeReleased = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png")))); } catch (IOException e1) { e1.printStackTrace(); } removeReleased.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { File file = new File( "projects/" + Editor.getProjectName() + "/buttons/" + name.getText() + "/released.png"); file.delete(); nameReleased.setText(""); bs.set("imageReleased", ""); preview2.update(); previewPanel.repaint(); if (bs.getString("imageBasic").equals("") && bs.getString("imageEntered").equals("") && bs.getString("imageExited").equals("") && bs.getString("imagePressed").equals("") && bs.getString("imageReleased").equals("")) { previewPanel.remove(preview2); previewPanel.add(preview); } } }); imgReleased.add(removeReleased, BorderLayout.SOUTH); images.add(imgReleased); this.add(images); JPanel action = new JPanel(); action.setPreferredSize(new Dimension(395, -20)); JLabel labelAction = new JLabel("Action : "); action.add(labelAction); actionList.removeAllItems(); actionList.addItem("Aucune"); for (String s : Actions.getActions()) { actionList.addItem(s); } actionList.setPreferredSize(new Dimension(this.getWidth() - 100, 30)); actionList.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { @SuppressWarnings("unchecked") JComboBox<String> combo = (JComboBox<String>) event.getSource(); bs.set("action", combo.getSelectedItem()); } }); action.add(actionList); this.add(action); JScrollPane previewScroll = new JScrollPane(previewPanel); previewScroll.getVerticalScrollBar().setUnitIncrement(Editor.SCROLL_SPEED); previewPanel.setBorder(BorderFactory.createTitledBorder("Aperu")); previewPanel.add(preview); previewScroll.setPreferredSize(new Dimension(395, 40)); previewScroll.setBorder(null); this.add(previewScroll); }
From source file:be.ugent.maf.cellmissy.gui.controller.analysis.doseresponse.generic.LoadGenericDRDataController.java
/** * Private methods//from w ww . j ava 2 s .c o m */ //init view private void initDataLoadingPanel() { dataLoadingPanel = new DRDataLoadingPanel(); /** * Action Listeners. */ //Popup file selector and import and parse the file dataLoadingPanel.getChooseFileButton().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // Open a JFile Chooser JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle( "Choose a tabular file (XLS, XLSX, CSV, TSV) for the import of the experiment"); // to select only appropriate files fileChooser.setFileFilter(new FileFilter() { @Override public boolean accept(File f) { if (f.isDirectory()) { return true; } int index = f.getName().lastIndexOf("."); String extension = f.getName().substring(index + 1); return extension.equals("xls") || extension.equals("xlsx") || extension.equals("csv") || extension.equals("tsv"); } @Override public String getDescription() { return (".xls, .xlsx, .csv and .tsv files"); } }); fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); fileChooser.setAcceptAllFileFilterUsed(false); // in response to the button click, show open dialog int returnVal = fileChooser.showOpenDialog(dataLoadingPanel); if (returnVal == JFileChooser.APPROVE_OPTION) { File chosenFile = fileChooser.getSelectedFile(); // // create and execute a new swing worker with the selected file for the import // ImportExperimentSwingWorker importExperimentSwingWorker = new ImportExperimentSwingWorker(chosenFile); // importExperimentSwingWorker.execute(); parseDRFile(chosenFile); if (doseResponseController.getImportedDRDataHolder().getDoseResponseData() != null) { dataLoadingPanel.getFileLabel().setText(chosenFile.getAbsolutePath()); doseResponseController.getGenericDRParentPanel().getNextButton().setEnabled(true); } } else { JOptionPane.showMessageDialog(dataLoadingPanel, "Command cancelled by user", "", JOptionPane.INFORMATION_MESSAGE); } } }); dataLoadingPanel.getLogTransformCheckBox().addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { doseResponseController.setLogTransform(true); } else { doseResponseController.setLogTransform(false); } } }); }
From source file:com.opendoorlogistics.studio.AppFrame.java
private void importFile(SupportedFileType option) { // to do.. excel import needs to show progress dialog (as its slow) final JFileChooser chooser = option.createFileChooser(); IOUtils.setFile(PreferencesManager.getSingleton().getLastImportFile(option), chooser); final ExecutionReport report = new ExecutionReportImpl(); if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { try {//from w w w . ja v a 2 s . c o m PreferencesManager.getSingleton().setLastImportFile(chooser.getSelectedFile(), option); ODLDatastoreAlterable<ODLTableAlterable> imported = TableIOUtils .importFile(chooser.getSelectedFile(), option, report); if (imported == null) { throw new RuntimeException(); } if (loaded == null) { openEmptyDatastore(); } if (!TableUtils.addDatastores(loaded.getDs(), imported, true)) { throw new RuntimeException(); } for (int i = 0; i < imported.getTableCount(); i++) { ODLTableReadOnly table = imported.getTableAt(i); report.log("Imported table \"" + table.getName() + "\" with " + table.getRowCount() + " rows and " + table.getColumnCount() + " columns."); } report.log("Imported " + imported.getTableCount() + " tables."); } catch (Throwable e) { report.setFailed(e); report.log("Error importing " + Strings.convertEnumToDisplayFriendly(option)); report.log("Could not import file: " + chooser.getSelectedFile().getAbsolutePath()); String message = report.getReportString(true, false); if (message.length() > 0) { message += System.lineSeparator(); } } ExecutionReportDialog.show(this, "Import result", report); } }