/** * Create a default filename given the current date selection. If custom dates are selected, use * those dates; otherwise, use year and week numbers. * * @return The default filename. */ private String getDefaultFilename() { if (yearCB.getSelectedIndex() == 0 || weekCB.getSelectedIndex() == 0) return "timesheet-" + dateFormat.format(fromDate.getDate()).replaceAll("/", "") + "-" + dateFormat.format(toDate.getDate()).replaceAll("/", "") + ".txt"; return "timesheet-" + yearCB.getSelectedItem() + "wk" + weekCB.getSelectedItem() + ".txt"; }
private void copyFile() throws Exception { // Load the JDBC driver Class.forName(((String) jcboDriver.getSelectedItem()).trim()); System.out.println("Driver loaded"); // Establish a connection Connection conn = DriverManager.getConnection( ((String) jcboURL.getSelectedItem()).trim(), jtfUsername.getText().trim(), String.valueOf(jtfPassword.getPassword()).trim()); System.out.println("Database connected"); // Read each line from the text file and insert it to the table insertRows(conn); }
public void testModulesSelector() throws ConfigurationException { if (PlatformTestUtil.COVERAGE_ENABLED_BUILD) return; Module module1 = getModule1(); Module module2 = getModule2(); JUnitConfigurable editor = new JUnitConfigurable(myProject); try { JUnitConfiguration configuration = createConfiguration(findTestA(module2)); editor.getComponent(); // To get all the watchers installed. Configurable configurable = new RunConfigurationConfigurableAdapter(editor, configuration); JComboBox comboBox = editor.getModulesComponent(); configurable.reset(); assertFalse(configurable.isModified()); assertEquals(module2.getName(), ((Module) comboBox.getSelectedItem()).getName()); assertEquals( ModuleManager.getInstance(myProject).getModules().length + 1, comboBox.getModel().getSize()); // no module comboBox.setSelectedItem(module1); assertTrue(configurable.isModified()); configurable.apply(); assertFalse(configurable.isModified()); assertEquals( Collections.singleton(module1), ContainerUtilRt.newHashSet(configuration.getModules())); } finally { Disposer.dispose(editor); } }
/** * Get the Lincese text from a text file specified in the PropertyBox. * * @return String - License text. */ public String getLicenseText() { StringBuffer textBuffer = new StringBuffer(); try { String fileName = RuntimeProperties.GPL_EN_LICENSE_FILE_NAME; if (cbLang != null && cbLang.getSelectedItem() != null && cbLang.getSelectedItem().toString().equalsIgnoreCase("Eesti")) { fileName = RuntimeProperties.GPL_EE_LICENSE_FILE_NAME; } InputStream is = this.getClass().getClassLoader().getResourceAsStream(fileName); if (is == null) return ""; BufferedReader in = new BufferedReader(new InputStreamReader(is)); String str; while ((str = in.readLine()) != null) { textBuffer.append(str); textBuffer.append("\n"); } in.close(); } catch (IOException e) { logger.error(null, e); } return textBuffer.toString(); } // getLicenseText
/** * Create preview component. * * @param type type * @param comboBox the options. * @param prefSize the preferred size * @return the component. */ private static Component createPreview(int type, final JComboBox comboBox, Dimension prefSize) { JComponent preview = null; if (type == DeviceConfigurationComboBoxModel.AUDIO) { Object selectedItem = comboBox.getSelectedItem(); if (selectedItem instanceof AudioSystem) { AudioSystem audioSystem = (AudioSystem) selectedItem; if (!NoneAudioSystem.LOCATOR_PROTOCOL.equalsIgnoreCase(audioSystem.getLocatorProtocol())) { preview = new TransparentPanel(new GridBagLayout()); createAudioSystemControls(audioSystem, preview); } } } else if (type == DeviceConfigurationComboBoxModel.VIDEO) { JLabel noPreview = new JLabel( NeomediaActivator.getResources().getI18NString("impl.media.configform.NO_PREVIEW")); noPreview.setHorizontalAlignment(SwingConstants.CENTER); noPreview.setVerticalAlignment(SwingConstants.CENTER); preview = createVideoContainer(noPreview); preview.setPreferredSize(prefSize); Object selectedItem = comboBox.getSelectedItem(); CaptureDeviceInfo device = null; if (selectedItem instanceof DeviceConfigurationComboBoxModel.CaptureDevice) device = ((DeviceConfigurationComboBoxModel.CaptureDevice) selectedItem).info; Exception exception; try { createVideoPreview(device, preview); exception = null; } catch (IOException ex) { exception = ex; } catch (MediaException ex) { exception = ex; } if (exception != null) { logger.error("Failed to create preview for device " + device, exception); device = null; } } return preview; }
public void actionPerformed(ActionEvent evt) { JComboBox cb = (JComboBox) evt.getSource(); String format = (String) cb.getSelectedItem(); if (format.equals("all formats")) { format = null; } fileList.setListData(findFiles(AUDIO_DIR, format)); }
public void actionPerformed(ActionEvent e) { parent .getParent() .getGrid() .setHeatMap(species.getSelectedItem().toString()); // I now regret the parent model parent.getParent().refresh(); }
private void setamount() { try { ResultSet rst = DBConnection.getDBConnection() .createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE) .executeQuery( "SELECT Amount FROM BOOKING where Pass_No='" + combo1.getSelectedItem() + "'"); while (rst.next()) { combo8.addItem(rst.getString(1)); } } catch (Exception n) { n.printStackTrace(); } }
public void actionPerformed(ActionEvent e) { String item = (String) displaySelector.getSelectedItem(); treeMode = item; // We want to respond to the changing of the combobox selectio if (item == PBTREE_ID) { // Display the tree treeScroller.getViewport().setView(treeView); } else if (item == STRAT_ID) { // Display strategies treeScroller.getViewport().setView(stratView); } else if (item == FORM_ID) { // Display formations treeScroller.getViewport().setView(formView); } else if (item == ROLE_ID) { // Display roles treeScroller.getViewport().setView(roleView); } else if (item == SUBROLE_ID) { // Display SubRoles treeScroller.getViewport().setView(subRoleView); } }
protected void enterLogin() { char[] password = m_passwordField.getPassword(); String strUser = (String) m_cmbUser.getSelectedItem(); setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); boolean blogin = WUserUtil.isOperatorNameok(strUser, false); if (blogin) { blogin = vnmrjPassword(strUser, password); if (!blogin) blogin = unixPassword(strUser, password); } if (blogin) { m_lblLogin.setForeground(Color.black); m_lblLogin.setText("Login Successful"); m_lblLogin.setVisible(true); // Get the Email column string for access to the operator data String emStr = vnmr.util.Util.getLabel("_admin_Email"); String stremail = WUserUtil.getOperatordata(strUser, emStr); // Get the Panel Level column string for access to the operator data String plStr = vnmr.util.Util.getLabel("_admin_Panel_Level"); String strPanel = WUserUtil.getOperatordata(strUser, plStr); if (stremail == null || stremail.equals("null")) stremail = ""; try { Integer.parseInt(strPanel); } catch (Exception e) { strPanel = WGlobal.PANELLEVEL; } m_trayTimer.stop(); Messages.postDebug(" Login: "******"appdir('reset','") .append(strUser) .append("','") .append(stremail) .append("',") .append(strPanel) .append(")") .toString()); exp.sendToVnmr("vnmrjcmd('util', 'bgReady')\n"); } setVisible(false); // Save the current position and size of this panel in case it // was changed Dimension size = getSize(); width = size.width; height = size.height; position = getLocation(); writePersistence(); // Call the macro to update this operator's // ExperimentSelector_operatorName.xml file // from the protocols themselves. This macro will // cause an update of the ES when it is finished // Util.getAppIF().sendToVnmr("updateExpSelector"); // I am not sure why we need to force updates since updateExpSelector // should have caused an update by writing to ES_op.xml file. // However, it works better if we do the force update. // ExpSelector.setForceUpdate(true); } else { m_lblLogin.setForeground(DisplayOptions.getColor("Error")); // m_lblLogin.setText("<HTML>Incorrect username/password <p> Please try again </HTML>"); m_lblLogin.setVisible(true); } setCursor(Cursor.getDefaultCursor()); }
public String getAbsolutePath() { return _txtPath.getText() + File.separatorChar + _txtFilename.getSelectedItem() + _txtFileExt.getText(); }
/** * Returns the unique ID of a week prefixed with the year. * * @return Selected week's ID. */ String getSelectedWeekID() { String weekNo = weekCB.getSelectedItem().toString(); if (weekNo.length() == 1) weekNo = "0" + weekNo; return yearCB.getSelectedItem() + "wk" + weekNo; }
public boolean isDirty() { String newFilename = (String) _txtFilename.getSelectedItem(); return !_oldFilename.equals(newFilename); }
MyCustomizableGUI() { this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); textField = new JTextField(20); buttonPref = new JButton("Preferences"); this.add(textField); this.add(buttonPref); buttonPref.addActionListener(evt -> prefDialog.setVisible(true)); frame = new JFrame("My text editor"); frame.setContentPane(this); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); // Preferences dialog box prefDialog = new JDialog(frame, "Dialog", true); prefDialog.setLayout(new BorderLayout()); JPanel p1 = new JPanel(); p1.setLayout(new GridLayout(3, 2)); JPanel p2 = new JPanel(); p2.setLayout(new BoxLayout(p2, BoxLayout.X_AXIS)); buttonSave = new JButton("Save"); buttonCancel = new JButton("Cancel"); buttonSave.addActionListener( evtSave -> { String fontChosen; int fontSizeChosen; prefDialog.setVisible(false); if ((String) color.getSelectedItem() == "Red") { textField.setForeground(Color.red); } else if ((String) color.getSelectedItem() == "Green") { textField.setForeground(Color.green); } else if ((String) color.getSelectedItem() == "Blue") { textField.setForeground(Color.blue); } else if ((String) color.getSelectedItem() == "Cyan") { textField.setForeground(Color.cyan); } else if ((String) color.getSelectedItem() == "Magenta") { textField.setForeground(Color.magenta); } else if ((String) color.getSelectedItem() == "Yellow") { textField.setForeground(Color.yellow); } else if ((String) color.getSelectedItem() == "Black") { textField.setForeground(Color.black); } fontChosen = (String) font.getSelectedItem(); fontSizeChosen = Integer.parseInt((String) fontSize.getSelectedItem()); textField.setFont(new Font(fontChosen, Font.PLAIN, fontSizeChosen)); UserPreferences userPrefs = new UserPreferences(); userPrefs.setColor((String) color.getSelectedItem()); userPrefs.setFont(fontChosen); userPrefs.setFontSize(fontSizeChosen); try (FileOutputStream fileOut = new FileOutputStream("preferences.ser"); ObjectOutputStream objectOut = new ObjectOutputStream(fileOut); ) { objectOut.writeObject(userPrefs); } catch (IOException ioe) { System.out.println("I/O error: " + ioe.getMessage()); } }); buttonCancel.addActionListener(evt -> prefDialog.setVisible(false)); colorLabel = new JLabel("Color:"); fontLabel = new JLabel("Font:"); fontSizeLabel = new JLabel("Font size:"); color = new JComboBox(colorList); font = new JComboBox(fontList); fontSize = new JComboBox(fontSizeList); p1.add(colorLabel); p1.add(color); p1.add(fontLabel); p1.add(font); p1.add(fontSizeLabel); p1.add(fontSize); p2.add(buttonCancel); p2.add(buttonSave); prefDialog.add(BorderLayout.NORTH, p1); prefDialog.add(BorderLayout.SOUTH, p2); prefDialog.pack(); }
public void actionPerformed(ActionEvent evt) { String arg = evt.getActionCommand(); if (arg.equals("Query")) { // 用户按下Query按钮 ResultSet rs = null; try { String author = (String) authors.getSelectedItem(); String publisher = (String) publishers.getSelectedItem(); if (!author.equals("Any") && !publisher.equals("Any")) { if (authorPublisherQueryStmt == null) { // 根据用户选择的出版社名和作者名查询相关的书名和书价 String authorPublisherQuery = "SELECT Books.Price, Books.Title " + "FROM Books, BooksAuthors, Authors, Publishers " + "WHERE Authors.Author_Id = BooksAuthors.Author_Id AND " + "BooksAuthors.ISBN = Books.ISBN AND " + "Books.Publisher_Id = Publishers.Publisher_Id AND " + "Authors.Name = ? AND " + "Publishers.Name = ?"; authorPublisherQueryStmt = con.prepareStatement(authorPublisherQuery); } authorPublisherQueryStmt.setString(1, author); authorPublisherQueryStmt.setString(2, publisher); rs = authorPublisherQueryStmt.executeQuery(); } else if (!author.equals("Any") && publisher.equals("Any")) { if (authorQueryStmt == null) { // 根据用户选择的作者名查询相关的书名和书价 String authorQuery = "SELECT Books.Price, Books.Title " + "FROM Books, BooksAuthors, Authors " + "WHERE Authors.Author_Id = BooksAuthors.Author_Id AND " + "BooksAuthors.ISBN = Books.ISBN AND " + "Authors.Name = ?"; authorQueryStmt = con.prepareStatement(authorQuery); } authorQueryStmt.setString(1, author); rs = authorQueryStmt.executeQuery(); } else if (author.equals("Any") && !publisher.equals("Any")) { if (publisherQueryStmt == null) { // 根据用户选择的出版社名查询相关的书名和书价 String publisherQuery = "SELECT Books.Price, Books.Title " + "FROM Books, Publishers " + "WHERE Books.Publisher_Id = Publishers.Publisher_Id AND " + "Publishers.Name = ?"; publisherQueryStmt = con.prepareStatement(publisherQuery); } publisherQueryStmt.setString(1, publisher); rs = publisherQueryStmt.executeQuery(); } else { if (allQueryStmt == null) { // 若用户未选任何信息,则输出所有的书名和对应的书价 String allQuery = "SELECT Books.Price, Books.Title FROM Books"; allQueryStmt = con.prepareStatement(allQuery); } rs = allQueryStmt.executeQuery(); } result.setText(""); while (rs.next()) result.append(rs.getString(1) + " | " + rs.getString(2) + "\n"); rs.close(); } catch (Exception e) { result.setText("Error " + e); } } else if (arg.equals("Change prices")) { // 用户选择“Change prices”按钮 String publisher = (String) publishers.getSelectedItem(); if (publisher.equals("Any")) result.setText("I am sorry, but I cannot do that."); else try { // 根据用户输入的新的书价更新Books表的数据 String updateStatement = "UPDATE Books " + "SET Price = Price + " + priceChange.getText() + " WHERE Books.Publisher_Id = " + "(SELECT Publisher_Id FROM Publishers WHERE Name = '" + publisher + "')"; int r = stmt.executeUpdate(updateStatement); result.setText(r + " records updated."); } catch (Exception e) { result.setText("Error " + e); } } }
protected void updateFilename() { _oldFilename = (String) _txtFilename.getSelectedItem(); }
private void process() { int width = Integer.parseInt(xres.getText()); int height = Integer.parseInt(yres.getText()); boolean preserveAspect = aspect.isSelected(); Color bg = new Color(red.getValue(), green.getValue(), blue.getValue()); String outDir = output.getText(); String suffix = ((String) format.getSelectedItem()).toLowerCase(); String preText = prepend.getText(); String appText = append.getText(); int scaleType = -1; String alg = (String) algorithm.getSelectedItem(); if (alg.equals("Smooth")) scaleType = Image.SCALE_SMOOTH; else if (alg.equals("Standard")) scaleType = Image.SCALE_DEFAULT; else if (alg.equals("Fast")) scaleType = Image.SCALE_FAST; else if (alg.equals("Replicate")) scaleType = Image.SCALE_REPLICATE; else if (alg.equals("Area averaging")) { scaleType = Image.SCALE_AREA_AVERAGING; } DefaultListModel model = (DefaultListModel) list.getModel(); int size = model.size(); progress.setValue(0); progress.setMaximum(4 * size); for (int i = 0; i < size; i++) { ThumbFile tf = (ThumbFile) model.elementAt(i); list.setSelectedValue(tf, true); String tail = " (" + (i + 1) + " of " + size + ")"; progress.setValue(4 * i); progress.setString("Reading" + tail); // construct input and output filenames String inFile = tf.getPath(); String outFile = outDir + SLASH + tf.getName(); int ndx = outFile.lastIndexOf(SLASH); String s1 = outFile.substring(0, ndx + SLASH.length()); String s2 = outFile.substring(ndx + SLASH.length()); int dot_ndx = s2.lastIndexOf("."); if (dot_ndx >= 0) s2 = s2.substring(0, dot_ndx); // make the thumbnail file name outFile = s1 + preText + s2 + appText + "." + suffix; // read in the file to an image BufferedImage image = null; try { image = ImageIO.read(new File(inFile)); } catch (IOException exc) { exc.printStackTrace(); } progress.setValue(4 * i + 1); progress.setString("Resizing" + tail); // resize image int w, h; if (preserveAspect) { int ow = image.getWidth(); int oh = image.getHeight(); double oasp = (double) ow / oh; double tasp = (double) width / height; if (oasp > tasp) { w = width; h = (int) (w / oasp); } else { h = height; w = (int) (oasp * h); } } else { w = width; h = height; } Image resized = image.getScaledInstance(w, h, scaleType); progress.setValue(4 * i + 2); progress.setString("Painting" + tail); // create thumbnail BufferedImage thumb = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D g2d = thumb.createGraphics(); g2d.setColor(bg); g2d.fillRect(0, 0, width, height); g2d.drawImage(resized, (width - w) / 2, (height - h) / 2, this); g2d.dispose(); progress.setValue(4 * i + 3); progress.setString("Writing" + tail); // save thumbnail to disk File out = new File(outFile); File parent = out.getParentFile(); if (parent != null && !parent.exists()) parent.mkdirs(); try { ImageIO.write(thumb, suffix, out); } catch (IOException exc) { exc.printStackTrace(); } } list.setSelectedIndices(new int[0]); progress.setValue(4 * size); progress.setString("Complete"); }