List of usage examples for javax.swing JFileChooser setMultiSelectionEnabled
@BeanProperty(description = "Sets multiple file selection mode.") public void setMultiSelectionEnabled(boolean b)
From source file:com.akman.excel.view.frmExportExcel.java
private void btnAddFileActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnAddFileActionPerformed {//GEN-HEADEREND:event_btnAddFileActionPerformed JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("Excel files", "xlsx", "xlsm", "xlt", "xlsb", "xltx", "xltm", "xls", "xlt", "xls"); chooser.setFileFilter(filter);// www. j av a 2s . co m chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setDialogTitle("Select The Image"); chooser.setMultiSelectionEnabled(false); int res = chooser.showOpenDialog(null); if (res == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); // checking file extension. it must be excel file. if (file.equals(filter)) { JOptionPane.showMessageDialog(null, "Wrong File selected", "ERROR", JOptionPane.ERROR_MESSAGE); return; } fileName = file.getAbsolutePath(); txtPath.setText(fileName); } }
From source file:dotaSoundEditor.Controls.EditorPanel.java
protected File promptUserForNewFile(String wavePath) { JFileChooser chooser = new JFileChooser(new File(UserPrefs.getInstance().getWorkingDirectory())); FileNameExtensionFilter filter = new FileNameExtensionFilter("MP3s and WAVs", "mp3", "wav"); chooser.setAcceptAllFileFilterUsed((false)); chooser.setFileFilter(filter);//ww w. j a v a2 s . c om chooser.setMultiSelectionEnabled(false); int chooserRetVal = chooser.showOpenDialog(chooser); if (chooserRetVal == JFileChooser.APPROVE_OPTION) { DefaultMutableTreeNode selectedFile = (DefaultMutableTreeNode) getTreeNodeFromWavePath(wavePath); Path chosenFile = Paths.get(chooser.getSelectedFile().getAbsolutePath()); //Strip caps and spaces out of filenames. The item sound parser seems to have trouble with them. String destFileName = chosenFile.getFileName().toString().toLowerCase().replace(" ", "_"); Path destPath = Paths.get(installDir, "/dota/sound/" + getCustomSoundPathString() + destFileName); UserPrefs.getInstance().setWorkingDirectory(chosenFile.getParent().toString()); try { new File(destPath.toString()).mkdirs(); Files.copy(chosenFile, destPath, StandardCopyOption.REPLACE_EXISTING); String waveString = selectedFile.getUserObject().toString(); int startIndex = -1; int endIndex = -1; if (waveString.contains("\"wave\"")) { startIndex = Utility.nthOccurrence(selectedFile.getUserObject().toString(), '\"', 2); endIndex = Utility.nthOccurrence(selectedFile.getUserObject().toString(), '\"', 3); } else //Some wavestrings don't have the "wave" at the beginning for some reason { startIndex = Utility.nthOccurrence(selectedFile.getUserObject().toString(), '\"', 0); endIndex = Utility.nthOccurrence(selectedFile.getUserObject().toString(), '\"', 1); } String waveStringFilePath = waveString.substring(startIndex, endIndex + 1); waveString = waveString.replace(waveStringFilePath, "\"" + getCustomSoundPathString() + destFileName + "\""); selectedFile.setUserObject(waveString); //Write out modified tree to scriptfile. ScriptParser parser = new ScriptParser(this.currentTreeModel); String scriptString = getCurrentScriptString(); Path scriptPath = Paths.get(scriptString); parser.writeModelToFile(scriptPath.toString()); //Update UI ((DefaultMutableTreeNode) currentTree.getLastSelectedPathComponent()).setUserObject(waveString); ((DefaultTreeModel) currentTree.getModel()) .nodeChanged((DefaultMutableTreeNode) currentTree.getLastSelectedPathComponent()); JOptionPane.showMessageDialog(this, "Sound file successfully replaced."); } catch (IOException ex) { JOptionPane.showMessageDialog(null, "Unable to replace sound.\nDetails: " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } } return null; }
From source file:cn.labthink.ReadAccess060.java
private void jButton_OpenfileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_OpenfileActionPerformed //filter/* w w w.j a v a 2 s . c om*/ ExtensionFileFilter filter = new ExtensionFileFilter("mdb", false, true); filter.setDescription("Open DataBase File"); //? JFileChooser jfc = new JFileChooser(); FileSystemView fsv = FileSystemView.getFileSystemView(); //? jfc.setCurrentDirectory(fsv.getHomeDirectory()); jfc.setDialogTitle("Choose the mdb file"); jfc.setMultiSelectionEnabled(false); jfc.setDialogType(JFileChooser.OPEN_DIALOG); jfc.setFileSelectionMode(JFileChooser.FILES_ONLY); jfc.setFileFilter(filter); int result = jfc.showOpenDialog(this); // ""? if (result == JFileChooser.APPROVE_OPTION) { String filesrc = jfc.getSelectedFile().getAbsolutePath(); inputfile = jfc.getSelectedFile(); jLabel_dbpath.setText("DB File Path:" + filesrc); maxid = Integer.MIN_VALUE; minid = Integer.MAX_VALUE; } else { return; } // Infodata = new Vector(); Infocolumns = new Vector(); try { // String url = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=D://b.MDB"; if (inputfile == null) { return; } initDB(); sql = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); rs = sql.executeQuery("SELECT * FROM test order by testid desc"); Infocolumns.add("TestID"); Infocolumns.add("TestType"); Infocolumns.add("DeviceID"); Infocolumns.add("CellID"); Infocolumns.add("Operator"); Infocolumns.add("StartTime"); Infocolumns.add("EndTime"); Infocolumns.add("Comments"); Infocolumns.add("SetTemp."); int columnCount = Infocolumns.size(); Vector row; while (rs.next()) { row = new Vector(columnCount); int temp = 0; int ivalue = rs.getInt("TESTID"); maxid = maxid < ivalue ? ivalue : maxid; minid = minid > ivalue ? ivalue : minid; row.add(ivalue); temp = rs.getInt("TESTTYPE"); if (temp == 1) { row.add("OTR"); } else if (temp == 2) { row.add("WVTR"); } else { row.add(temp); } row.add(rs.getInt("DEVICEID")); row.add(rs.getString("CELLID")); row.add(rs.getString("OPERATOR")); row.add(rs.getDate("STARTTIME")); row.add(rs.getDate("ENDTIME")); row.add(rs.getString("COMMENTS")); row.add(rs.getDouble("SETTEMP")); // row.add(rs.getString(11)); // row.add(rs.getInt(10)); Infodata.add(row); } DefaultTableModel tableModel = new DefaultTableModel(Infodata, Infocolumns); jTable1.setModel(tableModel); //? // jTable1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); jTable1.setSelectionBackground(Color.orange); //? TableRowSorter<TableModel> tableRowSorter = new TableRowSorter<TableModel>(tableModel); jTable1.setRowSorter(tableRowSorter); // jTable1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); //table DefaultTableCellRenderer tcr = new DefaultTableCellRenderer();// table tcr.setHorizontalAlignment(SwingConstants.CENTER);// ?? jTable1.setDefaultRenderer(Object.class, tcr); // ((DefaultTableCellRenderer) jTable1.getTableHeader().getDefaultRenderer()) .setHorizontalAlignment(SwingConstants.CENTER); // DefaultTableCellRenderer rh = new DefaultTableCellRenderer(); // rh.setHorizontalAlignment(SwingConstants.CENTER); // jTable1.getTableHeader().setDefaultRenderer(rh); jTable1.getColumnModel().getColumn(0).setPreferredWidth(20); jTable1.getColumnModel().getColumn(1).setPreferredWidth(28); jTable1.getColumnModel().getColumn(2).setPreferredWidth(20); jTable1.getColumnModel().getColumn(3).setPreferredWidth(40); jTable1.getColumnModel().getColumn(4).setPreferredWidth(40); jTable1.getColumnModel().getColumn(5).setPreferredWidth(100); jTable1.getColumnModel().getColumn(6).setPreferredWidth(100); jTable1.getColumnModel().getColumn(7).setPreferredWidth(100); } catch (SQLException ee) { System.out.println(ee); } catch (ClassNotFoundException ex) { Logger.getLogger(ReadAccess060.class.getName()).log(Level.SEVERE, null, ex); } finally { try { sql.close(); } catch (Exception e) { } try { rs.close(); } catch (Exception e) { } } // validate(); }
From source file:cn.labthink.ReadAccess330.java
private void jButton_OpenfileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_OpenfileActionPerformed //filter// w ww .ja v a 2 s.com ExtensionFileFilter filter = new ExtensionFileFilter("mdb", false, true); filter.setDescription("Open DataBase File"); //? JFileChooser jfc = new JFileChooser(); FileSystemView fsv = FileSystemView.getFileSystemView(); //? jfc.setCurrentDirectory(fsv.getHomeDirectory()); jfc.setDialogTitle("Choose the mdb file"); jfc.setMultiSelectionEnabled(false); jfc.setDialogType(JFileChooser.OPEN_DIALOG); jfc.setFileSelectionMode(JFileChooser.FILES_ONLY); jfc.setFileFilter(filter); int result = jfc.showOpenDialog(this); // ""? if (result == JFileChooser.APPROVE_OPTION) { String filesrc = jfc.getSelectedFile().getAbsolutePath(); inputfile = jfc.getSelectedFile(); jLabel_dbpath.setText("DB File Path:" + filesrc); maxid = Integer.MIN_VALUE; minid = Integer.MAX_VALUE; } else { return; } // Infodata = new Vector(); Infocolumns = new Vector(); try { // String url = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=D://b.MDB"; if (inputfile == null) { return; } initDB(); sql = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); rs = sql.executeQuery("SELECT * FROM test order by testid desc"); Infocolumns.add("TestID"); Infocolumns.add("TestType"); Infocolumns.add("DeviceID"); Infocolumns.add("CellID"); Infocolumns.add("Operator"); Infocolumns.add("StartTime"); Infocolumns.add("EndTime"); Infocolumns.add("Comments"); Infocolumns.add("SetTemp."); int columnCount = Infocolumns.size(); Vector row; while (rs.next()) { row = new Vector(columnCount); int temp = 0; int ivalue = rs.getInt("TESTID"); maxid = maxid < ivalue ? ivalue : maxid; minid = minid > ivalue ? ivalue : minid; row.add(ivalue); temp = rs.getInt("TESTTYPE"); if (temp == 1) { row.add("OTR"); } else if (temp == 2) { row.add("WVTR"); } else { row.add(temp); } row.add(rs.getInt("DEVICEID")); row.add(rs.getString("CELLID")); row.add(rs.getString("OPERATOR")); row.add(rs.getDate("STARTTIME")); row.add(rs.getDate("ENDTIME")); row.add(rs.getString("COMMENTS")); row.add(rs.getDouble("SETTEMP")); // row.add(rs.getString(11)); // row.add(rs.getInt(10)); Infodata.add(row); } DefaultTableModel tableModel = new DefaultTableModel(Infodata, Infocolumns); jTable1.setModel(tableModel); //? // jTable1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); jTable1.setSelectionBackground(Color.orange); //? TableRowSorter<TableModel> tableRowSorter = new TableRowSorter<TableModel>(tableModel); jTable1.setRowSorter(tableRowSorter); // jTable1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); //table DefaultTableCellRenderer tcr = new DefaultTableCellRenderer();// table tcr.setHorizontalAlignment(SwingConstants.CENTER);// ?? jTable1.setDefaultRenderer(Object.class, tcr); // ((DefaultTableCellRenderer) jTable1.getTableHeader().getDefaultRenderer()) .setHorizontalAlignment(SwingConstants.CENTER); // DefaultTableCellRenderer rh = new DefaultTableCellRenderer(); // rh.setHorizontalAlignment(SwingConstants.CENTER); // jTable1.getTableHeader().setDefaultRenderer(rh); jTable1.getColumnModel().getColumn(0).setPreferredWidth(20); jTable1.getColumnModel().getColumn(1).setPreferredWidth(28); jTable1.getColumnModel().getColumn(2).setPreferredWidth(20); jTable1.getColumnModel().getColumn(3).setPreferredWidth(40); jTable1.getColumnModel().getColumn(4).setPreferredWidth(40); jTable1.getColumnModel().getColumn(5).setPreferredWidth(100); jTable1.getColumnModel().getColumn(6).setPreferredWidth(100); jTable1.getColumnModel().getColumn(7).setPreferredWidth(100); } catch (SQLException ee) { System.out.println(ee); } catch (ClassNotFoundException ex) { Logger.getLogger(ReadAccess330.class.getName()).log(Level.SEVERE, null, ex); } finally { try { sql.close(); } catch (Exception e) { } try { rs.close(); } catch (Exception e) { } } // validate(); }
From source file:net.sf.nmedit.nomad.core.Nomad.java
public void fileOpen() { // todo keep working directory JFileChooser chooser = new JFileChooser(); chooser.setMultiSelectionEnabled(true); FileServiceTool.addChoosableFileFilters(chooser); if (!(chooser.showOpenDialog(mainWindow) == JFileChooser.APPROVE_OPTION)) return;/* www. ja v a2 s.c om*/ final File[] selected = chooser.getSelectedFiles(); final FileService service = FileServiceTool.lookupFileService(chooser); if (service == null) { JOptionPane.showMessageDialog(mainWindow, "Could not find service to open file."); return; } Runnable run = new Runnable() { public void run() { for (File file : selected) { service.open(file); } } }; SwingUtilities.invokeLater(WorkIndicator.create(getWindow(), run)); }
From source file:gui.TheGui.java
private String saveAs() { final JFileChooser fc = new JFileChooser(); fc.setMultiSelectionEnabled(false); fc.setAcceptAllFileFilterUsed(false); OpenFileFilter m3u_filter = new OpenFileFilter(".m3u", "*.m3u, Playlist in m3u format"); OpenFileFilter xspf_filter = new OpenFileFilter(".xspf", "*.xspf, Playlist in xspf format"); if (playlistType == PlaylistType.M3U) { fc.addChoosableFileFilter(new OpenFileFilter(".m3u", "*.m3u, Playlist in m3u format")); } else {/*from w w w . j a v a 2 s . c om*/ fc.addChoosableFileFilter(new OpenFileFilter(".xspf", "*.xspf, Playlist in xspf format")); } int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); filePath = file.getPath(); jTextArea1.append("Saving: " + file.getName() + "." + newline); if (playlistType == PlaylistType.M3U) { return file.getPath() + ".m3u"; } else { return file.getPath() + ".xspf"; } } else { jTextArea1.append("Save command cancelled by user." + newline); return null; } }
From source file:gui.TheGui.java
private String saveAs() { final JFileChooser fc = new JFileChooser(); fc.setMultiSelectionEnabled(false); fc.setAcceptAllFileFilterUsed(false); OpenFileFilter m3u_filter = new OpenFileFilter(".m3u", "*.m3u, Playlist in m3u format"); OpenFileFilter xspf_filter = new OpenFileFilter(".xspf", "*.xspf, Playlist in xspf format"); if (playlistType == PlaylistType.M3U) fc.addChoosableFileFilter(new OpenFileFilter(".m3u", "*.m3u, Playlist in m3u format")); else/*from w w w .j av a 2 s.com*/ fc.addChoosableFileFilter(new OpenFileFilter(".xspf", "*.xspf, Playlist in xspf format")); int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); filePath = file.getPath(); jTextArea1.append("Saving: " + file.getName() + "." + newline); if (playlistType == PlaylistType.M3U) return file.getPath() + ".m3u"; else return file.getPath() + ".xspf"; } else { jTextArea1.append("Save command cancelled by user." + newline); return null; } }
From source file:electroStaticUI.ElectroStaticUIContainer.java
private void buildFileMenu() { //create Exit menu item exitItem = new JMenuItem("Exit"); exitItem.setMnemonic(KeyEvent.VK_X); exitItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0);/* www . j ava2s . co m*/ } }); //open open = new JMenuItem("Open"); open.setMnemonic(KeyEvent.VK_P); open.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser fChooser = new JFileChooser(); int status = fChooser.showSaveDialog(null); } }); //close close = new JMenuItem("Close"); close.setMnemonic(KeyEvent.VK_C); //export export = new JMenuItem("Export"); export.setMnemonic(KeyEvent.VK_E); export.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser fChooser = new JFileChooser(); fChooser.setMultiSelectionEnabled(false); fChooser.setAcceptAllFileFilterUsed(false); FileNameExtensionFilter svgFilter = new FileNameExtensionFilter("Save Vector Plot(svg)", ".svg"); FileNameExtensionFilter pngFilter = new FileNameExtensionFilter("Save Voltage Surface Plot(png)", ".png"); fChooser.addChoosableFileFilter(svgFilter); fChooser.addChoosableFileFilter(pngFilter); fChooser.setFileFilter(svgFilter); int status = fChooser.showSaveDialog(rootPane); if (status == JFileChooser.APPROVE_OPTION) { if (fChooser.getFileFilter() == svgFilter) { try { saveAsName = fChooser.getSelectedFile().getCanonicalPath(); Save.saveChartToSVG(DefaultValues.getChartToSave(), saveAsName, displayPanel.getWidth(), displayPanel.getHeight()); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } else if (fChooser.getFileFilter() == pngFilter) { try { saveAsName = fChooser.getSelectedFile().getCanonicalPath(); Save.saveChart3dToPNG(DefaultValues.get3dChartToSave(), saveAsName); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } } } }); //save save = new JMenuItem("Save"); save.setMnemonic(KeyEvent.VK_S); save.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser fChooser = new JFileChooser(); int status = fChooser.showSaveDialog(null); if (status == JFileChooser.APPROVE_OPTION) { try { System.out.println("Height: " + displayPanel.getWidth()); System.out.println("Width: " + displayPanel.getHeight()); saveAsName = fChooser.getSelectedFile().getCanonicalPath(); Save.saveChartToSVG(DefaultValues.getChartToSave(), saveAsName, displayPanel.getWidth(), displayPanel.getHeight()); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } } }); //saveAs saveAs = new JMenuItem("Save As"); saveAs.setMnemonic(KeyEvent.VK_A); saveAs.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser fChooser = new JFileChooser(); int status = fChooser.showSaveDialog(null); if (status == JFileChooser.APPROVE_OPTION) try { System.out.println("Height: " + displayPanel.getWidth()); System.out.println("Width: " + displayPanel.getHeight()); saveAsName = fChooser.getSelectedFile().getCanonicalPath(); System.out.println(saveAsName); Save.saveChartToSVG(DefaultValues.getChartToSave(), saveAsName, displayPanel.getWidth(), displayPanel.getHeight()); } catch (IOException e2) { // TODO Auto-generated catch block e2.printStackTrace(); } try { Save.saveChartToSVG(UserInput.getElectricFieldChart(), saveAsName, displayPanel.getWidth(), displayPanel.getHeight()); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }); //JMenu object for file menu fileMenu = new JMenu("File"); fileMenu.setMnemonic(KeyEvent.VK_F); //fileMenu.add(newFile); //fileMenu.add(open); //fileMenu.add(close); fileMenu.add(export); //fileMenu.add(save); //fileMenu.add(saveAs); fileMenu.add(exitItem); }
From source file:net.sf.nmedit.nomad.core.Nomad.java
public void fileSave(boolean saveAs) { Document d = pageContainer.getSelection(); if (d == null) return;// w ww .j a v a 2s . c o m if (!saveAs) { Iterator<FileService> iter = ServiceRegistry.getServices(FileService.class); FileService useService = null; while (iter.hasNext()) { FileService fs = iter.next(); if (fs.isDirectSaveOperationSupported(d)) { useService = fs; break; } } if (useService != null) { useService.save(d, useService.getAssociatedFile(d)); return; } } JFileChooser chooser = new JFileChooser(); chooser.setSelectedFile(lastSaveInFolderLocation); chooser.setMultiSelectionEnabled(false); Iterator<FileService> iter = ServiceRegistry.getServices(FileService.class); while (iter.hasNext()) { FileService fs = iter.next(); boolean add = (saveAs && fs.isSaveOperationSupported(d)) || ((!saveAs) && fs.isDirectSaveOperationSupported(d)); if (add) chooser.addChoosableFileFilter(fs.getFileFilter()); } File sfile = d.getFile(); if (sfile == null && d.getTitle() != null) sfile = new File(d.getTitle()); if (sfile != null) chooser.setSelectedFile(sfile); if (!(chooser.showSaveDialog(mainWindow) == JFileChooser.APPROVE_OPTION)) return; FileService service = FileServiceTool.lookupFileService(chooser); if (service != null) { File newFile = chooser.getSelectedFile(); if (newFile == null) return; if (newFile.exists() && JOptionPane.showConfirmDialog(mainWindow, "Overwrite existing file '" + newFile.getAbsolutePath() + "' ?", "File already exists.", JOptionPane.YES_NO_OPTION) == JOptionPane.NO_OPTION) return; service.save(d, newFile); lastSaveInFolderLocation = newFile.getParentFile(); } else { JOptionPane.showMessageDialog(mainWindow, "Could not find service to save file."); } }
From source file:Display.java
@SuppressWarnings("unchecked") Display() {/*from w w w . ja v a 2 s .c om*/ super(Reference.NAME); cardLayout = new CardLayout(); panel.setLayout(cardLayout); final int java7Update = Utils.Validators.java7Update.check(); final int java8Update = Utils.Validators.java8Update.check(); try { URL host = new URL(Reference.PROTOCOL, Reference.SOURCE_HOST, Reference.PORT, Reference.JSON_ARRAY); JSONParser parser = new JSONParser(); Object json = parser.parse(new URLReader(host)); final JSONArray array = (JSONArray) json; JSONObject nameObject1 = (JSONObject) array.get(0); XPackInstaller.selected_url = nameObject1.get("url").toString(); XPackInstaller.javaVersion = Integer.parseInt(nameObject1.get("version").toString()); XPackInstaller.profile = nameObject1.get("profile").toString(); XPackInstaller.canAcceptOptional = Boolean .parseBoolean(nameObject1.get("canAcceptOptional").toString()); if (!XPackInstaller.canAcceptOptional) { checkOptifine.setEnabled(false); checkOptifine.setSelected(false); zainstalujMoCreaturesCheckBox.setEnabled(false); zainstalujMoCreaturesCheckBox.setSelected(false); optionalText.setEnabled(false); } else { checkOptifine.setEnabled(true); zainstalujMoCreaturesCheckBox.setEnabled(true); optionalText.setEnabled(true); } for (Object anArray : array) { comboBox1.addItem(new JSONObject((JSONObject) anArray).get("name")); } comboBox1.addActionListener(e -> { int i = 0; while (true) { JSONObject nameObject = (JSONObject) array.get(i); String name1 = nameObject.get("name").toString(); if (name1 == comboBox1.getSelectedItem()) { XPackInstaller.canAcceptOptional = Boolean .parseBoolean(nameObject.get("canAcceptOptional").toString()); XPackInstaller.selected_url = nameObject.get("url").toString(); XPackInstaller.javaVersion = Integer.parseInt(nameObject.get("version").toString()); XPackInstaller.profile = nameObject.get("profile").toString(); if (!XPackInstaller.canAcceptOptional) { checkOptifine.setEnabled(false); checkOptifine.setSelected(false); zainstalujMoCreaturesCheckBox.setEnabled(false); zainstalujMoCreaturesCheckBox.setSelected(false); optionalText.setEnabled(false); } else { checkOptifine.setEnabled(true); zainstalujMoCreaturesCheckBox.setEnabled(true); optionalText.setEnabled(true); } break; } i++; } int javaStatus; if (XPackInstaller.javaVersion == 8) { javaStatus = java8Update; } else { javaStatus = java7Update; } if (javaStatus == 0) { javaversion.setText("TAK"); javaversion.setForeground(Reference.COLOR_DARK_GREEN); } else if (javaStatus == 1) { javaversion.setText("NIE"); javaversion.setForeground(Reference.COLOR_DARK_ORANGE); } else if (javaStatus == 2) { if (XPackInstaller.javaVersion == 8) { javaversion.setText("Nie posiadasz JRE8 w wersji 25 lub nowszej!"); } else { javaversion.setText("Nie posiadasz najnowszej wersji JRE7!"); } javaversion.setForeground(Color.RED); } if (osarch.getText().equals("TAK") && Ram.getText().equals("TAK") && javaarch.getText().equals("TAK") && (javaversion.getText().equals("TAK") || javaversion.getText().equals("NIE"))) { XPackInstaller.canGoForward = true; button2.setText("Dalej"); } else { XPackInstaller.canGoForward = false; button2.setText("Anuluj"); } }); } catch (FileNotFoundException | ParseException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); JOptionPane.showMessageDialog(panel, "Brak poczenia z Internetem!", "Bd", JOptionPane.ERROR_MESSAGE); System.exit(0); } pobierzOryginalnyLauncherMCCheckBox.addActionListener(e -> { if (pobierzOryginalnyLauncherMCCheckBox.isSelected()) { PathLauncherLabel.setEnabled(true); textField1.setEnabled(true); button3.setEnabled(true); XPackInstaller.installLauncher = true; labelLauncher.setEnabled(true); progressBar3.setEnabled(true); } else { PathLauncherLabel.setEnabled(false); textField1.setEnabled(false); button3.setEnabled(false); XPackInstaller.installLauncher = false; labelLauncher.setEnabled(false); progressBar3.setEnabled(false); } }); button3.addActionListener(e -> { JFileChooser chooser = new JFileChooser(System.getProperty("user.home")); chooser.setApproveButtonText("Wybierz"); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setMultiSelectionEnabled(false); chooser.setDialogTitle("Wybierz ciek"); int returnValue = chooser.showOpenDialog(getContentPane()); if (returnValue == JFileChooser.APPROVE_OPTION) { try { XPackInstaller.launcher_path = chooser.getSelectedFile().getCanonicalPath(); } catch (IOException x) { x.printStackTrace(); } textField1.setText(XPackInstaller.launcher_path); } }); slider1.setMaximum(Utils.Utils.humanReadableRAM() - 2); slider1.addChangeListener(e -> XPackInstaller.allocatedRAM = slider1.getValue()); button1.addActionListener(e -> { if (pobierzOryginalnyLauncherMCCheckBox.isSelected()) { File launcher = new File(XPackInstaller.launcher_path + File.separator + "Minecraft.exe"); if (textField1.getText().equals("")) { JOptionPane.showMessageDialog(panel, "Nie wybrae cieki instalacji Launcher'a!", "Bd", JOptionPane.ERROR_MESSAGE); } else if (launcher.exists()) { JOptionPane.showMessageDialog(panel, "W podanym katalogu istanieje ju plik o nazwie 'Minecraft.exe'!", "Bad", JOptionPane.ERROR_MESSAGE); } else { cardLayout.next(panel); } } else { cardLayout.next(panel); if (osarch.getText().equals("NIE") && Ram.getText().equals("TAK") && javaarch.getText().equals("NIE") && (javaversion.getText().equals("TAK") || javaversion.getText().equals("NIE"))) { XPackInstaller.canGoForward = false; button2.setText("Anuluj"); JOptionPane.showMessageDialog(gui, "Prosimy sprawdzi\u0107 czy na komputerze nie ma zainstalowanych dw\u00f3ch \u015brodowisk Java: w wersji 32-bitowej i 64-bitowej.\nJe\u015bli zainstalowane s\u0105 obie wersje prosimy o odinstalowanie wersji 32-bitowej. To rozwi\u0105\u017ce problem.", "B\u0142\u0105d konfiguracji Javy", JOptionPane.ERROR_MESSAGE); } } }); if (Utils.Validators.systemArchitecture.check()) { osarch.setText("TAK"); osarch.setForeground(Reference.COLOR_DARK_GREEN); } else { osarch.setText("NIE"); osarch.setForeground(Color.RED); } if (Utils.Validators.ramAmount.check()) { Ram.setText("TAK"); Ram.setForeground(Reference.COLOR_DARK_GREEN); } else { Ram.setText("NIE"); Ram.setForeground(Color.RED); } if (Utils.Validators.javaArchitecture.check()) { javaarch.setText("TAK"); javaarch.setForeground(Reference.COLOR_DARK_GREEN); } else { javaarch.setText("NIE"); javaarch.setForeground(Color.RED); } int javaStatus; if (XPackInstaller.javaVersion == 8) { javaStatus = java8Update; } else { javaStatus = java7Update; } if (javaStatus == 0) { javaversion.setText("TAK"); javaversion.setForeground(Reference.COLOR_DARK_GREEN); } else if (javaStatus == 1) { javaversion.setText("NIE"); javaversion.setForeground(Reference.COLOR_DARK_ORANGE); } else if (javaStatus == 2) { javaversion.setText("Nie posiadasz najnowszej wersji JRE!"); javaversion.setForeground(Color.RED); } if (osarch.getText().equals("TAK") && Ram.getText().equals("TAK") && javaarch.getText().equals("TAK") && (javaversion.getText().equals("TAK") || javaversion.getText().equals("NIE"))) { XPackInstaller.canGoForward = true; button2.setText("Dalej"); } else { XPackInstaller.canGoForward = false; button2.setText("Anuluj"); } button2.addActionListener(e -> { if (XPackInstaller.canGoForward) { cardLayout.next(panel); } else { System.exit(1); } }); wsteczButton.addActionListener(e -> cardLayout.previous(panel)); try { editorPane1.setPage("http://xpack.pl/licencja.html"); } catch (IOException e) { e.printStackTrace(); JOptionPane.showMessageDialog(panel, "Brak poczenia z Internetem!", "Bd", JOptionPane.ERROR_MESSAGE); System.exit(0); } licenseC.addActionListener(e -> { if (licenseC.isSelected()) { dalejButton.setEnabled(true); } else { dalejButton.setEnabled(false); } }); try { File mainDir = new File(System.getenv("appdata") + File.separator + "XPackInstaller"); if (mainDir.exists()) { FileUtils.deleteDirectory(mainDir); if (!mainDir.mkdir()) { JOptionPane.showMessageDialog(gui, "Nie udao si utworzy katalogu, prosimy sprbowa ponownie!", "Bd", JOptionPane.ERROR_MESSAGE); System.out.println("Nie udao si utworzy katalogu!"); System.exit(1); } } else { if (!mainDir.mkdir()) { JOptionPane.showMessageDialog(gui, "Nie udao si utworzy katalogu, prosimy sprbowa ponownie!", "Bd", JOptionPane.ERROR_MESSAGE); System.out.println("Nie udao si utworzy katalogu!"); System.exit(1); } } File optionalDir = new File(mainDir.getAbsolutePath() + File.separator + "OptionalMods"); if (!optionalDir.mkdir()) { JOptionPane.showMessageDialog(gui, "Nie udao si utworzy katalogu, prosimy sprbowa ponownie!", "Bd", JOptionPane.ERROR_MESSAGE); System.out.println("Nie udao si utworzy katalogu!"); System.exit(1); } dalejButton.addActionListener(e -> { cardLayout.next(panel); try { progressBar1.setValue(0); if (checkOptifine.isSelected() && zainstalujMoCreaturesCheckBox.isSelected()) { DownloadTask task2 = new DownloadTask(gui, "mod", Reference.downloadOptifine, optionalDir.getAbsolutePath()); task2.addPropertyChangeListener(evt -> { if (evt.getPropertyName().equals("progress")) { labelmodpack.setText("Pobieranie Optifine HD w toku..."); if (task2.isDone()) { task3(); } optifineProgress = (Integer) evt.getNewValue(); progressBar1.setValue(optifineProgress); } }); task2.execute(); } else if (checkOptifine.isSelected()) { DownloadTask task2 = new DownloadTask(gui, "mod", Reference.downloadOptifine, optionalDir.getAbsolutePath()); task2.addPropertyChangeListener(evt -> { if (evt.getPropertyName().equals("progress")) { labelmodpack.setText("Pobieranie Optifine HD w toku..."); if (task2.isDone()) { task(); } optifineProgress = (Integer) evt.getNewValue(); progressBar1.setValue(optifineProgress); } }); task2.execute(); } else if (zainstalujMoCreaturesCheckBox.isSelected()) { task3(); } else { task(); } } catch (Exception exx) { exx.printStackTrace(); } }); } catch (IOException e) { e.printStackTrace(); } final JScrollBar bar = scrollPane1.getVerticalScrollBar(); bar.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { int extent = bar.getModel().getExtent(); int total = extent + bar.getValue(); int max = bar.getMaximum(); if (total == max) { licenseC.setEnabled(true); } } @Override public void mousePressed(MouseEvent e) { } @Override public void mouseReleased(MouseEvent e) { int extent = bar.getModel().getExtent(); int total = extent + bar.getValue(); int max = bar.getMaximum(); if (total == max) { licenseC.setEnabled(true); } } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } }); bar.addMouseWheelListener(e -> { int extent = bar.getModel().getExtent(); int total = extent + bar.getValue(); int max = bar.getMaximum(); if (total == max) { licenseC.setEnabled(true); } }); scrollPane1.setWheelScrollingEnabled(true); scrollPane1.addMouseWheelListener(e -> { int extent = bar.getModel().getExtent(); int total = extent + bar.getValue(); int max = bar.getMaximum(); if (total == max) { licenseC.setEnabled(true); } }); panel.add(panel3); panel.add(panel1); panel.add(panel2); panel.add(panel4); add(panel); }