List of usage examples for javax.swing.filechooser FileNameExtensionFilter FileNameExtensionFilter
public FileNameExtensionFilter(String description, String... extensions)
From source file:pi.bestdeal.gui.InterfacePrincipale.java
private void ButtonRapportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButtonRapportActionPerformed int idd = (int) jTable3.getModel().getValueAt(jTable3.getSelectedRow(), 0); String pattern = null;/*from w ww. jav a2 s .co m*/ String path; FileNameExtensionFilter filter = new FileNameExtensionFilter("JASPER files", "jasper"); JFileChooser chooser = new JFileChooser(); chooser.setFileFilter(filter); int returnVal = chooser.showOpenDialog(this); chooser.setMultiSelectionEnabled(false); if (returnVal == JFileChooser.APPROVE_OPTION) { pattern = chooser.getSelectedFile().getPath(); } FileNameExtensionFilter filterpath = new FileNameExtensionFilter("PDF files", "pdf"); JFileChooser chooserpath = new JFileChooser(); chooserpath.setFileFilter(filterpath); int returnSave = chooserpath.showSaveDialog(this); if (returnSave == JFileChooser.APPROVE_OPTION) { path = chooserpath.getSelectedFile().getPath(); if (!path.contains("pdf")) { path = path + ".pdf"; String a = "\\"; } pattern = pattern.replace("\\", "\\" + "\\"); path = path.replace("\\", "\\" + "\\"); ReportCreator creator = new ReportCreator(); int a = creator.CreateReportDeal(pattern, idd, path); if (a == 1) { File file = new File(path.toString()); try { Desktop.getDesktop().open(file); } catch (IOException ex) { Logger.getLogger(InterfacePrincipale.class.getName()).log(Level.SEVERE, null, ex); } } } }
From source file:net.panthema.BispanningGame.GamePanel.java
public void writePdf() throws FileNotFoundException, DocumentException { // Query user for filename JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle("Specify PDF file to save"); chooser.setCurrentDirectory(new File(".")); FileNameExtensionFilter filter = new FileNameExtensionFilter("PDF Documents", "pdf"); chooser.setFileFilter(filter);/* www . j av a2 s. com*/ if (chooser.showSaveDialog(this) != JFileChooser.APPROVE_OPTION) return; File outfile = chooser.getSelectedFile(); if (!outfile.getAbsolutePath().endsWith(".pdf")) { outfile = new File(outfile.getAbsolutePath() + ".pdf"); } // Calculate page size rectangle Dimension size = mVV.getSize(); Rectangle rsize = new Rectangle(size.width, size.height); // Open the PDF file for writing - and create a Graphics2D object Document document = new Document(rsize); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(outfile)); document.open(); PdfContentByte contentByte = writer.getDirectContent(); PdfGraphics2D graphics2d = new PdfGraphics2D(contentByte, size.width, size.height, new DefaultFontMapper()); // Create a container to hold the visualization Container container = new Container(); container.addNotify(); container.add(mVV); container.setVisible(true); container.paintComponents(graphics2d); // Dispose of the graphics and close the document graphics2d.dispose(); document.close(); // Put mVV back onto visible plane setLayout(new BorderLayout()); add(mVV, BorderLayout.CENTER); }
From source file:com.cybercom.svp.machine.gui.MachineForm.java
private void buttomLoadFirmwareSettingFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttomLoadFirmwareSettingFileActionPerformed JFileChooser fileDialog = new JFileChooser(); fileDialog.setDialogTitle("Select firmware file"); FileNameExtensionFilter filter = new FileNameExtensionFilter("XML file", "xml"); fileDialog.setFileFilter(filter);//from w w w . j a v a 2s .c om fileDialog.setDialogType(JFileChooser.OPEN_DIALOG); int result = fileDialog.showOpenDialog(this); if (result == JFileChooser.APPROVE_OPTION) { try { String xml = FileUtils.readFileToString(fileDialog.getSelectedFile()); firmwareUpdateRequestSetting = xmlToObj(FirmwareUpdateRequest.class, xml); updateFirmwareSettings(); } catch (Exception ex) { JOptionPane.showMessageDialog(this, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } } }
From source file:InternalFrame.InternalFrameproject.java
private void loadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadActionPerformed String userhome = System.getProperty(constants.getProgrampath()); JFileChooser chooser = new JFileChooser(userhome + "\\" + constants.getProject_input_folder()); FileNameExtensionFilter txtfilter = new FileNameExtensionFilter("emft files (*Emft)", "Emft"); chooser.setDialogTitle(language_internal_frame.LangLabel(constants.getLanguage_option(), 7)); chooser.setFileFilter(txtfilter);/*from w w w .j a v a 2s.co m*/ chooser.showOpenDialog(null); File f = chooser.getSelectedFile(); File subor = new File(f.getParent() + "\\" + f.getName()); int pocet_Vysok = 0; try { Scanner input = new Scanner(subor); basicInfoPanel.jTextField_mano.setText(input.nextLine()); basicInfoPanel.jTextField_mano_projektu.setText(input.nextLine()); basicSettingsPanel.jTextField_A.setText(String.valueOf(input.nextDouble())); basicSettingsPanel.jTextField_Z.setText(String.valueOf(input.nextDouble())); basicSettingsPanel.jTextField_H.setText(String.valueOf(input.nextDouble())); basicSettingsPanel.jTextField_krok.setText(String.valueOf(input.nextDouble())); basicSettingsPanel.jTextField_krok_pozorovatela.setText(String.valueOf(input.nextDouble())); input.nextLine(); pocet_Vysok = input.nextInt(); input.nextLine(); int rowCount = observerPanel1.DTMTable.getRowCount();// odsrrani riadky z DTM table for (int i = rowCount - 1; i >= 0; i--) { observerPanel1.isListener = false; observerPanel1.DTMTable.removeRow(i); observerPanel1.isListener = true; } for (int i = 0; i < pocet_Vysok; i++) { observerPanel1.isListener = false; observerPanel1.DTMTable.addRow(new Object[] { input.nextLine() }); observerPanel1.isListener = true; } observerPanel1.Table.selectAll(); // ozna? potom vetky stplce observerPanel1.isListener = false; observerPanel1.DTMTable.addRow(new Object[0]); observerPanel1.isListener = true; int pocet_catenary_riadkov = input.nextInt(); input.nextLine(); rowCount = catenaryPanel1.DTMTable.getRowCount();// odsrrani riadky z DTM table for (int i = rowCount - 1; i >= 0; i--) { catenaryPanel1.isListener = false; catenaryPanel1.DTMTable.removeRow(i); catenaryPanel1.isListener = true; } for (int i = 0; i < pocet_catenary_riadkov; i++) { catenaryPanel1.isListener = false; double V1 = input.nextDouble(); double V2 = input.nextDouble(); double I1 = input.nextDouble(); double I2 = input.nextDouble(); double W1 = input.nextDouble(); double W2 = input.nextDouble(); double X1 = input.nextDouble(); double X2 = input.nextDouble(); int zvazok = input.nextInt(); double alpha = input.nextDouble(); double d = input.nextDouble(); int CH = input.nextInt(); boolean ch = false; if (CH == 1) { ch = true; } double val = input.nextDouble(); double r = input.nextDouble(); double U = input.nextDouble(); double I = input.nextDouble(); double Phi = input.nextDouble(); int pocitaj = input.nextInt(); String lano = input.nextLine(); lano = lano.substring(1); boolean poc = false; if (pocitaj == 1) { poc = true; } // najdi lano v databaze int index = 0; for (int j = 0; j < catenaryPanel1.getConductor_Name_Matrix().size(); j++) { if (lano.equals(catenaryPanel1.getConductor_Name_Matrix().get(j))) { index = j; } } catenaryPanel1.DTMTable.addRow(new Object[] { V1, V2, I1, I2, W1, W2, X1, X2, zvazok, alpha, d, ch, val, r, U, I, Phi, "-", "-", "-", poc, false, lano }); catenaryPanel1.isListener = true; } catenaryPanel1.isListener = false; catenaryPanel1.DTMTable.addRow(new Object[0]); catenaryPanel1.isListener = true; } catch (FileNotFoundException ex) { Logger.getLogger(terenmodel_jDialog.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:net.panthema.BispanningGame.GamePanel.java
public void writeGraphML() throws IOException { // Query user for filename JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle("Specify GraphML file to save"); chooser.setCurrentDirectory(new File(".")); FileNameExtensionFilter filter = new FileNameExtensionFilter("GraphML File", "graphml"); chooser.setFileFilter(filter);/*w ww . ja v a2 s. c o m*/ if (chooser.showSaveDialog(this) != JFileChooser.APPROVE_OPTION) return; File outfile = chooser.getSelectedFile(); if (!outfile.getAbsolutePath().endsWith(".graphml")) { outfile = new File(outfile.getAbsolutePath() + ".graphml"); } // construct graphml writer GraphMLWriter<Integer, MyEdge> graphWriter = new GraphMLWriter<Integer, MyEdge>(); PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(outfile))); graphWriter.addVertexData("x", null, "0", new Transformer<Integer, String>() { public String transform(Integer v) { return Double.toString(mLayout.getX(v)); } }); graphWriter.addVertexData("y", null, "0", new Transformer<Integer, String>() { public String transform(Integer v) { return Double.toString(mLayout.getY(v)); } }); graphWriter.addEdgeData("color", null, "0", new Transformer<MyEdge, String>() { public String transform(MyEdge e) { return Integer.toString(e.color); } }); graphWriter.save(mGraph, out); }
From source file:Main.Interface_Main.java
private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed System.out.print(serialData); //Create a file chooser final JFileChooser fc = new JFileChooser(); FileFilter ft = new FileNameExtensionFilter("Comma Seperated Value (*.csv)", "csv"); fc.setFileFilter(ft);//w w w. j ava2 s . co m //In response to a button click: int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); System.out.println(file); try { /*BufferedWriter writer = null; writer = new BufferedWriter(new FileWriter(file + ".csv")); //add .txt? writer.write("time, amp, max, min, volt, max, min, wattage, mah, mwh, dp, dm"); writer.newLine(); for (int i = 0; i < csvData.size(); i++){ //String serialStringData = csvData.toString(); writer.write(csvData.get(i).toString()); writer.newLine(); } writer.close( ); */ File sFile = new File(logTmpFile); Files.copy(sFile.toPath(), file.toPath()); JOptionPane.showMessageDialog(this, "Data exported successfully!", "Success!", JOptionPane.INFORMATION_MESSAGE); } catch (java.io.IOException e) { JOptionPane.showMessageDialog(this, e); } } else { System.out.println("Save Canceled"); } }
From source file:InternalFrame.InternalFrameproject.java
private void saveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveActionPerformed String userhome = System.getProperty(constants.getProgrampath()); //userhome is home folder of program // ak je zadan pec lokaciakde uklada tak tam ak nide default prie?ion kde existuje JFileChooser chooser = new JFileChooser(userhome + "\\" + constants.getProject_input_folder()); //key files are stored in resources FileNameExtensionFilter txtfilter = new FileNameExtensionFilter("emft files (*.Emft)", "Emft"); // whitch type of files are we looking for chooser.setDialogTitle(language_internal_frame.LangLabel(constants.getLanguage_option(), 9)); // title for Jfile chooser window chooser.setFileFilter(txtfilter); // Txt filter for choosing file chooser.showSaveDialog(null);//from w w w . ja va 2 s . c o m File f = chooser.getSelectedFile(); String project_filename = f.getName() + ".Emft"; String project_filepath = f.getParent(); File subor = new File(project_filepath + "\\" + project_filename); PrintWriter fw; try { fw = new PrintWriter(subor); fw.println(basicInfoPanel.jTextField_mano.getText()); fw.println(basicInfoPanel.jTextField_mano_projektu.getText()); fw.println(basicSettingsPanel.jTextField_A.getText() + " " + basicSettingsPanel.jTextField_Z.getText() + " " + basicSettingsPanel.jTextField_H.getText() + " " + basicSettingsPanel.jTextField_krok.getText() + " " + basicSettingsPanel.jTextField_krok_pozorovatela.getText() + " "); fw.println(observerPanel1.Table.getRowCount() - 1); for (int i = 0; i < observerPanel1.Table.getRowCount() - 1; i++) { fw.println(observerPanel1.DTMTable.getValueAt(i, 0)); } fw.println(catenaryPanel1.Table.getRowCount() - 1); for (int i = 0; i < catenaryPanel1.Table.getRowCount() - 1; i++) { double V1 = help.Object_To_double(catenaryPanel1.DTMTable.getValueAt(i, 0)); double V2 = help.Object_To_double(catenaryPanel1.DTMTable.getValueAt(i, 1)); double I1 = help.Object_To_double(catenaryPanel1.DTMTable.getValueAt(i, 2)); double I2 = help.Object_To_double(catenaryPanel1.DTMTable.getValueAt(i, 3)); double W1 = help.Object_To_double(catenaryPanel1.DTMTable.getValueAt(i, 4)); double W2 = help.Object_To_double(catenaryPanel1.DTMTable.getValueAt(i, 5)); double X1 = help.Object_To_double(catenaryPanel1.DTMTable.getValueAt(i, 6)); double X2 = help.Object_To_double(catenaryPanel1.DTMTable.getValueAt(i, 7)); int zvazok = (int) help.Object_To_double(catenaryPanel1.DTMTable.getValueAt(i, 8)); double alpha = help.Object_To_double(catenaryPanel1.DTMTable.getValueAt(i, 9)); double d = help.Object_To_double(catenaryPanel1.DTMTable.getValueAt(i, 10)); int CH = 0; boolean ch = help.Object_To_Boolean(catenaryPanel1.DTMTable.getValueAt(i, 11)); if (ch == true) { CH = 1; } double val = help.Object_To_double(catenaryPanel1.DTMTable.getValueAt(i, 12)); double r = help.Object_To_double(catenaryPanel1.DTMTable.getValueAt(i, 13)); double U = help.Object_To_double(catenaryPanel1.DTMTable.getValueAt(i, 14)); double I = help.Object_To_double(catenaryPanel1.DTMTable.getValueAt(i, 15)); double Phi = help.Object_To_double(catenaryPanel1.DTMTable.getValueAt(i, 16)); int poc = 0; boolean pocitaj = help.Object_To_Boolean(catenaryPanel1.DTMTable.getValueAt(i, 20)); if (pocitaj == true) { poc = 1; } String lano = String.valueOf(catenaryPanel1.DTMTable.getValueAt(i, 22)); fw.println(V1 + " " + V2 + " " + I1 + " " + I2 + " " + W1 + " " + W2 + " " + X1 + " " + X2 + " " + zvazok + " " + alpha + " " + d + " " + CH + " " + val + " " + r + " " + U + " " + I + " " + Phi + " " + poc + " " + lano); } Date todaysDate = new Date(); DateFormat df2 = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss"); fw.println("END of file"); fw.println("time of creation :" + df2.format(todaysDate)); fw.close(); } catch (FileNotFoundException ex) { Logger.getLogger(InternalFrameproject.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:oct.analysis.application.OCTAnalysisUI.java
private void saveAnalysisMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveAnalysisMenuItemActionPerformed //allow the user to choose where to save the analysis file fc.resetChoosableFileFilters();//from w ww . j a v a2 s.co m fc.setFileFilter(new FileNameExtensionFilter("ORA analysis file", "ora")); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); fc.setSelectedFile(new File("analysis.ora")); int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File saveFile = fc.getSelectedFile(); AnalysisSaver.saveAnalysis(saveFile); } }
From source file:oct.analysis.application.OCTAnalysisUI.java
private void openAnalysisMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openAnalysisMenuItemActionPerformed //allow the user to choose where the saved analysis file is fc.resetChoosableFileFilters();/*from w ww . j a v a 2 s . c o m*/ fc.setFileSelectionMode(JFileChooser.FILES_ONLY); fc.setFileFilter(new FileNameExtensionFilter("ORA analysis file", "ora")); int returnVal = fc.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File saveFile = fc.getSelectedFile(); try { AnalysisSaveState readAnalysis = AnalysisSaver.readAnalysis(saveFile); Util.openSavedAnalysis(this, readAnalysis); //enable save saveAnalysisMenuItem.setEnabled(true); exportAnalysisResultsMenuItem.setEnabled(true); } catch (IOException ex) { Logger.getLogger(OCTAnalysisUI.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:edu.ku.brc.af.ui.forms.ViewFactory.java
protected boolean createItem(final DBTableInfo parentTableInfo, final DBTableChildIFace childInfo, final MultiView parent, final ViewDefIFace viewDef, final FormValidator validator, final ViewBuilderIFace viewBldObj, final AltViewIFace.CreationMode mode, final HashMap<String, JLabel> labelsForHash, final Object currDataObj, final FormCellIFace cell, final boolean isEditOnCreateOnly, final int rowInx, final BuildInfoStruct bi) { bi.compToAdd = null;//from w w w . j a v a 2 s . c o m bi.compToReg = null; bi.doAddToValidator = true; bi.doRegControl = true; DBRelationshipInfo relInfo = childInfo instanceof DBRelationshipInfo ? (DBRelationshipInfo) childInfo : null; if (isEditOnCreateOnly) { EditViewCompSwitcherPanel evcsp = new EditViewCompSwitcherPanel(cell); bi.compToAdd = evcsp; bi.compToReg = evcsp; if (validator != null) { //DataChangeNotifier dcn = validator.createDataChangeNotifer(cell.getIdent(), evcsp, null); DataChangeNotifier dcn = validator.hookupComponent(evcsp, cell.getIdent(), UIValidator.Type.Changed, null, false); evcsp.setDataChangeNotifier(dcn); } } else if (cell.getType() == FormCellIFace.CellType.label) { FormCellLabel cellLabel = (FormCellLabel) cell; String lblStr = cellLabel.getLabel(); if (cellLabel.isRecordObj()) { JComponent riComp = viewBldObj.createRecordIndentifier(lblStr, cellLabel.getIcon()); bi.compToAdd = riComp; } else { String lStr = " "; int align = SwingConstants.RIGHT; boolean useColon = StringUtils.isNotEmpty(cellLabel.getLabelFor()); if (lblStr.equals("##")) { //lStr = " "; bi.isDerivedLabel = true; cellLabel.setDerived(true); } else { String alignProp = cellLabel.getProperty("align"); if (StringUtils.isNotEmpty(alignProp)) { if (alignProp.equals("left")) { align = SwingConstants.LEFT; } else if (alignProp.equals("center")) { align = SwingConstants.CENTER; } else { align = SwingConstants.RIGHT; } } else if (useColon) { align = SwingConstants.RIGHT; } else { align = SwingConstants.LEFT; } if (isNotEmpty(lblStr)) { if (useColon) { lStr = lblStr + ":"; } else { lStr = lblStr; } } else { lStr = " "; } } if (lStr.indexOf(LF) > -1) { lStr = "<html>" + StringUtils.replace(lStr, LF, "<br>") + "</html>"; } JLabel lbl = createLabel(lStr, align); String colorStr = cellLabel.getProperty("fg"); if (StringUtils.isNotEmpty(colorStr)) { lbl.setForeground(UIHelper.parseRGB(colorStr)); } labelsForHash.put(cellLabel.getLabelFor(), lbl); bi.compToAdd = lbl; viewBldObj.addLabel(cellLabel, lbl); } bi.doAddToValidator = false; bi.doRegControl = false; } else if (cell.getType() == FormCellIFace.CellType.field) { FormCellField cellField = (FormCellField) cell; bi.isRequired = bi.isRequired || cellField.isRequired() || (childInfo != null && childInfo.isRequired()); DBFieldInfo fieldInfo = childInfo instanceof DBFieldInfo ? (DBFieldInfo) childInfo : null; if (fieldInfo != null && fieldInfo.isHidden()) { FormDevHelper.appendLocalizedFormDevError("ViewFactory.FORM_FIELD_HIDDEN", cellField.getIdent(), cellField.getName(), viewDef.getName()); } else { if (fieldInfo != null && fieldInfo.isHidden()) { FormDevHelper.appendLocalizedFormDevError("ViewFactory.FORM_REL_HIDDEN", cellField.getIdent(), cellField.getName(), viewDef.getName()); } } FormCellField.FieldType uiType = cellField.getUiType(); // Check to see if there is a PickList and get it if there is PickListDBAdapterIFace adapter = null; String pickListName = cellField.getPickListName(); if (childInfo != null && StringUtils.isEmpty(pickListName) && fieldInfo != null) { pickListName = fieldInfo.getPickListName(); } if (isNotEmpty(pickListName)) { adapter = PickListDBAdapterFactory.getInstance().create(pickListName, false); if (adapter == null || adapter.getPickList() == null) { FormDevHelper.appendFormDevError("PickList Adapter [" + pickListName + "] cannot be null!"); return false; } } /*if (uiType == FormCellFieldIFace.FieldType.text) { String weblink = cellField.getProperty("weblink"); if (StringUtils.isNotEmpty(weblink)) { String name = cellField.getProperty("name"); if (StringUtils.isNotEmpty(name) && name.equals("WebLink")) { uiType } } }*/ // The Default Display for combox is dsptextfield, except when there is a TableBased PickList // At the time we set the display we don't want to go get the picklist to find out. So we do it // here after we have the picklist and actually set the change into the cellField // because it uses the value to determine whether to convert the value into a text string // before setting it. if (mode == AltViewIFace.CreationMode.VIEW) { if (uiType == FormCellFieldIFace.FieldType.combobox && cellField.getDspUIType() != FormCellFieldIFace.FieldType.textpl) { if (adapter != null)// && adapter.isTabledBased()) { uiType = FormCellFieldIFace.FieldType.textpl; cellField.setDspUIType(uiType); } else { uiType = cellField.getDspUIType(); } } else { uiType = cellField.getDspUIType(); } } else if (uiType == FormCellField.FieldType.querycbx) { if (AppContextMgr.isSecurityOn()) { DBTableInfo tblInfo = childInfo != null ? DBTableIdMgr.getInstance() .getByShortClassName(childInfo.getDataClass().getSimpleName()) : null; if (tblInfo != null) { PermissionSettings perm = tblInfo.getPermissions(); if (perm != null) { //PermissionSettings.dumpPermissions("QCBX: "+tblInfo.getShortClassName(), perm.getOptions()); if (perm.isViewOnly() || !perm.canView()) { uiType = FormCellField.FieldType.textfieldinfo; } } } } } Class<?> fieldClass = childInfo != null ? childInfo.getDataClass() : null; String uiFormatName = cellField.getUIFieldFormatterName(); if (mode == AltViewIFace.CreationMode.EDIT && uiType == FormCellField.FieldType.text && fieldClass != null) { if (fieldClass == String.class && fieldInfo != null) { // check whether there's a formatter defined for this field in the schema if (fieldInfo.getFormatter() != null) { uiFormatName = fieldInfo.getFormatter().getName(); uiType = FormCellField.FieldType.formattedtext; } } else if (fieldClass == Integer.class || fieldClass == Long.class || fieldClass == Short.class || fieldClass == Byte.class || fieldClass == Double.class || fieldClass == Float.class || fieldClass == BigDecimal.class) { //log.debug(cellField.getName()+" is being changed to NUMERIC"); uiType = FormCellField.FieldType.formattedtext; uiFormatName = "Numeric" + fieldClass.getSimpleName(); } } // Create the UI Component boolean isReq = cellField.isRequired() || (fieldInfo != null && fieldInfo.isRequired()) || (relInfo != null && relInfo.isRequired()); cellField.setRequired(isReq); switch (uiType) { case text: bi.compToAdd = createTextField(validator, cellField, fieldInfo, isReq, adapter); bi.doAddToValidator = validator == null; // might already added to validator break; case formattedtext: { Class<?> tableClass = null; try { tableClass = Class.forName(viewDef.getClassName()); } catch (Exception ex) { } JComponent tfStart = createFormattedTextField(validator, cellField, tableClass, fieldInfo != null ? fieldInfo.getLength() : 0, uiFormatName, mode == AltViewIFace.CreationMode.VIEW, isReq, cellField.getPropertyAsBoolean("alledit", false)); bi.compToAdd = tfStart; if (cellField.getPropertyAsBoolean("series", false)) { JComponent tfEnd = createFormattedTextField(validator, cellField, tableClass, fieldInfo != null ? fieldInfo.getLength() : 0, uiFormatName, mode == AltViewIFace.CreationMode.VIEW, isReq, cellField.getPropertyAsBoolean("alledit", false)); // Make sure we register it like a plugin not a regular control SeriesProcCatNumPlugin plugin = new SeriesProcCatNumPlugin((ValFormattedTextFieldIFace) tfStart, (ValFormattedTextFieldIFace) tfEnd); bi.compToAdd = plugin.getUIComponent(); viewBldObj.registerPlugin(cell, plugin); bi.doRegControl = false; } bi.doAddToValidator = validator == null; // might already added to validator break; } case label: JLabel label = createLabel("", SwingConstants.LEFT); bi.compToAdd = label; break; case dsptextfield: if (StringUtils.isEmpty(cellField.getPickListName())) { JTextField text = UIHelper.createTextField(cellField.getTxtCols()); changeTextFieldUIForDisplay(text, cellField.getPropertyAsBoolean("transparent", false)); bi.compToAdd = text; } else { bi.compToAdd = createTextField(validator, cellField, fieldInfo, isReq, adapter); bi.doAddToValidator = validator == null; // might already added to validator } break; case textfieldinfo: bi.compToAdd = createTextFieldWithInfo(cellField, parent); break; case image: bi.compToAdd = createImageDisplay(cellField, mode, validator); bi.doAddToValidator = (validator != null); break; case url: BrowserLauncherBtn blb = new BrowserLauncherBtn(cellField.getProperty("title")); bi.compToAdd = blb; bi.doAddToValidator = false; break; case combobox: bi.compToAdd = createValComboBox(validator, cellField, adapter, isReq); bi.doAddToValidator = validator != null; // might already added to validator break; case checkbox: { String lblStr = cellField.getLabel(); if (lblStr.equals("##")) { bi.isDerivedLabel = true; cellField.setDerived(true); } ValCheckBox checkbox = new ValCheckBox(lblStr, isReq, cellField.isReadOnly() || mode == AltViewIFace.CreationMode.VIEW); if (validator != null) { DataChangeNotifier dcn = validator.createDataChangeNotifer(cellField.getIdent(), checkbox, validator.createValidator(checkbox, UIValidator.Type.Changed)); checkbox.addActionListener(dcn); checkbox.addItemListener(dcn); } bi.compToAdd = checkbox; break; } case tristate: { String lblStr = cellField.getLabel(); if (lblStr.equals("##")) { bi.isDerivedLabel = true; cellField.setDerived(true); } ValTristateCheckBox tristateCB = new ValTristateCheckBox(lblStr, isReq, cellField.isReadOnly() || mode == AltViewIFace.CreationMode.VIEW); if (validator != null) { DataChangeNotifier dcn = validator.createDataChangeNotifer(cellField.getIdent(), tristateCB, null); tristateCB.addActionListener(dcn); } bi.compToAdd = tristateCB; break; } case spinner: { String minStr = cellField.getProperty("min"); int min = StringUtils.isNotEmpty(minStr) ? Integer.parseInt(minStr) : 0; String maxStr = cellField.getProperty("max"); int max = StringUtils.isNotEmpty(maxStr) ? Integer.parseInt(maxStr) : 0; ValSpinner spinner = new ValSpinner(min, max, isReq, cellField.isReadOnly() || mode == AltViewIFace.CreationMode.VIEW); if (validator != null) { DataChangeNotifier dcn = validator.createDataChangeNotifer(cellField.getIdent(), spinner, validator.createValidator(spinner, UIValidator.Type.Changed)); spinner.addChangeListener(dcn); } bi.compToAdd = spinner; break; } case password: bi.compToAdd = createPasswordField(validator, cellField, isReq); bi.doAddToValidator = validator == null; // might already added to validator break; case dsptextarea: bi.compToAdd = createDisplayTextArea(cellField); break; case textarea: { JTextArea ta = createTextArea(validator, cellField, isReq, fieldInfo); JScrollPane scrollPane = new JScrollPane(ta); scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); scrollPane.setVerticalScrollBarPolicy( UIHelper.isMacOS() ? ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS : ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); ta.setLineWrap(true); ta.setWrapStyleWord(true); bi.doAddToValidator = validator == null; // might already added to validator bi.compToReg = ta; bi.compToAdd = scrollPane; break; } case textareabrief: { String title = ""; DBTableInfo ti = DBTableIdMgr.getInstance().getByClassName(viewDef.getClassName()); if (ti != null) { DBFieldInfo fi = ti.getFieldByName(cellField.getName()); if (fi != null) { title = fi.getTitle(); } } ValTextAreaBrief txBrief = createTextAreaBrief(validator, cellField, isReq, fieldInfo); txBrief.setTitle(title); bi.doAddToValidator = validator == null; // might already added to validator bi.compToReg = txBrief; bi.compToAdd = txBrief.getUIComponent(); break; } case browse: { JTextField textField = createTextField(validator, cellField, null, isReq, null); if (textField instanceof ValTextField) { ValBrowseBtnPanel bbp = new ValBrowseBtnPanel((ValTextField) textField, cellField.getPropertyAsBoolean("dirsonly", false), cellField.getPropertyAsBoolean("forinput", true)); String fileFilter = cellField.getProperty("filefilter"); String fileFilterDesc = cellField.getProperty("filefilterdesc"); String defaultExtension = cellField.getProperty("defaultExtension"); if (fileFilter != null && fileFilterDesc != null) { bbp.setUseNativeFileDlg(false); bbp.setFileFilter(new FileNameExtensionFilter(fileFilterDesc, fileFilter)); bbp.setDefaultExtension(defaultExtension); //bbp.setNativeDlgFilter(new FileNameExtensionFilter(fileFilterDesc, fileFilter)); } bi.compToAdd = bbp; } else { BrowseBtnPanel bbp = new BrowseBtnPanel(textField, cellField.getPropertyAsBoolean("dirsonly", false), cellField.getPropertyAsBoolean("forinput", true)); bi.compToAdd = bbp; } break; } case querycbx: { ValComboBoxFromQuery cbx = createQueryComboBox(validator, cellField, isReq, cellField.getPropertyAsBoolean("adjustquery", true)); cbx.setMultiView(parent); cbx.setFrameTitle(cellField.getProperty("title")); bi.compToAdd = cbx; bi.doAddToValidator = validator == null; // might already added to validator break; } case list: { JList list = createList(validator, cellField, isReq); JScrollPane scrollPane = new JScrollPane(list); scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); scrollPane.setVerticalScrollBarPolicy( UIHelper.isMacOS() ? ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS : ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); bi.doAddToValidator = validator == null; bi.compToReg = list; bi.compToAdd = scrollPane; break; } case colorchooser: { ColorChooser colorChooser = new ColorChooser(Color.BLACK); if (validator != null) { DataChangeNotifier dcn = validator.createDataChangeNotifer(cellField.getName(), colorChooser, null); colorChooser.addPropertyChangeListener("setValue", dcn); } //setControlSize(colorChooser); bi.compToAdd = colorChooser; break; } case button: JButton btn = createFormButton(cellField, cellField.getProperty("title")); bi.compToAdd = btn; break; case progress: bi.compToAdd = createProgressBar(0, 100); break; case plugin: UIPluginable uip = createPlugin(parent, validator, cellField, mode == AltViewIFace.CreationMode.VIEW, isReq); if (uip != null) { bi.compToAdd = uip.getUIComponent(); viewBldObj.registerPlugin(cell, uip); } else { bi.compToAdd = new JPanel(); log.error("Couldn't create UIPlugin [" + cellField.getName() + "] ID:" + cellField.getIdent()); } bi.doRegControl = false; break; case textpl: JTextField txt = new TextFieldFromPickListTable(adapter, cellField.getTxtCols()); changeTextFieldUIForDisplay(txt, cellField.getPropertyAsBoolean("transparent", false)); bi.compToAdd = txt; break; default: FormDevHelper.appendFormDevError("Don't recognize uitype=[" + uiType + "]"); } // switch } else if (cell.getType() == FormCellIFace.CellType.separator) { // still have compToAdd = null; FormCellSeparatorIFace fcs = (FormCellSeparatorIFace) cell; String collapsableName = fcs.getCollapseCompName(); String label = fcs.getLabel(); if (StringUtils.isEmpty(label) || label.equals("##")) { String className = fcs.getProperty("forclass"); if (StringUtils.isNotEmpty(className)) { DBTableInfo ti = DBTableIdMgr.getInstance().getByShortClassName(className); if (ti != null) { label = ti.getTitle(); } } } Component sep = viewBldObj.createSeparator(label); if (isNotEmpty(collapsableName)) { CollapsableSeparator collapseSep = new CollapsableSeparator(sep, false, null); if (bi.collapseSepHash == null) { bi.collapseSepHash = new HashMap<CollapsableSeparator, String>(); } bi.collapseSepHash.put(collapseSep, collapsableName); sep = collapseSep; } bi.doRegControl = cell.getName().length() > 0; bi.compToAdd = (JComponent) sep; bi.doRegControl = StringUtils.isNotEmpty(cell.getIdent()); bi.doAddToValidator = false; } else if (cell.getType() == FormCellIFace.CellType.command) { FormCellCommand cellCmd = (FormCellCommand) cell; JButton btn = createFormButton(cell, cellCmd.getLabel()); if (cellCmd.getCommandType().length() > 0) { btn.addActionListener(new CommandActionWrapper( new CommandAction(cellCmd.getCommandType(), cellCmd.getAction(), ""))); } bi.doAddToValidator = false; bi.compToAdd = btn; } else if (cell.getType() == FormCellIFace.CellType.iconview) { FormCellSubView cellSubView = (FormCellSubView) cell; String subViewName = cellSubView.getViewName(); ViewIFace subView = AppContextMgr.getInstance().getView(cellSubView.getViewSetName(), subViewName); if (subView != null) { if (parent != null) { int options = MultiView.VIEW_SWITCHER | (MultiView.isOptionOn(parent.getCreateOptions(), MultiView.IS_NEW_OBJECT) ? MultiView.IS_NEW_OBJECT : MultiView.NO_OPTIONS); options |= cellSubView.getPropertyAsBoolean("nosep", false) ? MultiView.DONT_USE_EMBEDDED_SEP : 0; options |= cellSubView.getPropertyAsBoolean("nosepmorebtn", false) ? MultiView.NO_MORE_BTN_FOR_SEP : 0; MultiView multiView = new MultiView(parent, cellSubView.getName(), subView, parent.getCreateWithMode(), options, null); parent.addChildMV(multiView); multiView.setClassToCreate(getClassToCreate(parent, cell)); log.debug("[" + cell.getType() + "] [" + cell.getName() + "] col: " + bi.colInx + " row: " + rowInx + " colspan: " + cell.getColspan() + " rowspan: " + cell.getRowspan()); viewBldObj.addSubView(cellSubView, multiView, bi.colInx, rowInx, cellSubView.getColspan(), 1); viewBldObj.closeSubView(cellSubView); bi.curMaxRow = rowInx; bi.colInx += cell.getColspan() + 1; } else { log.error("buildFormView - parent is NULL for subview [" + subViewName + "]"); } } else { log.error("buildFormView - Could find subview's with ViewSet[" + cellSubView.getViewSetName() + "] ViewName[" + subViewName + "]"); } // still have compToAdd = null; bi.colInx += 2; } else if (cell.getType() == FormCellIFace.CellType.subview) { FormCellSubView cellSubView = (FormCellSubView) cell; String subViewName = cellSubView.getViewName(); ViewIFace subView = AppContextMgr.getInstance().getView(cellSubView.getViewSetName(), subViewName); if (subView != null) { // Check to see this view should be "flatten" meaning we are creating a grid from a form if (!viewBldObj.shouldFlatten()) { if (parent != null) { ViewIFace parentView = parent.getView(); Properties props = cellSubView.getProperties(); boolean isSingle = cellSubView.isSingleValueFromSet(); boolean isACollection = false; try { Class<?> cls = Class.forName(parentView.getClassName()); Field fld = getFieldFromDotNotation(cellSubView, cls); if (fld != null) { isACollection = Collection.class.isAssignableFrom(fld.getType()); } else { log.error("Couldn't find field [" + cellSubView.getName() + "] in class [" + parentView.getClassName() + "]"); } } catch (Exception ex) { log.error("Couldn't find field [" + cellSubView.getName() + "] in class [" + parentView.getClassName() + "]"); edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ViewFactory.class, ex); } if (isSingle) { isACollection = true; } boolean useNoScrollbars = UIHelper.getProperty(props, "noscrollbars", false); //Assume RecsetController will always be handled correctly for one-to-one boolean hideResultSetController = relInfo == null ? false : relInfo.getType().equals(DBRelationshipInfo.RelationshipType.ZeroOrOne); /*XXX bug #9497: boolean canEdit = true; boolean addAddBtn = isEditOnCreateOnly && relInfo != null; if (AppContextMgr.isSecurityOn()) { DBTableInfo tblInfo = childInfo != null ? DBTableIdMgr.getInstance().getByShortClassName(childInfo.getDataClass().getSimpleName()) : null; if (tblInfo != null) { PermissionSettings perm = tblInfo.getPermissions(); if (perm != null) { //XXX whoa. What about view perms??? //if (perm.isViewOnly() || !perm.canView()) { if (!perm.canModify()) { canEdit = false; } } } }*/ int options = (isACollection && !isSingle ? MultiView.RESULTSET_CONTROLLER : MultiView.IS_SINGLE_OBJ) | MultiView.VIEW_SWITCHER | (MultiView.isOptionOn(parent.getCreateOptions(), MultiView.IS_NEW_OBJECT) ? MultiView.IS_NEW_OBJECT : MultiView.NO_OPTIONS) | /* XXX bug #9497:(mode == AltViewIFace.CreationMode.EDIT && canEdit ? MultiView.IS_EDITTING : MultiView.NO_OPTIONS) | (useNoScrollbars ? MultiView.NO_SCROLLBARS : MultiView.NO_OPTIONS) //| (addAddBtn ? MultiView.INCLUDE_ADD_BTN : MultiView.NO_OPTIONS) ; */ (mode == AltViewIFace.CreationMode.EDIT ? MultiView.IS_EDITTING : MultiView.NO_OPTIONS) | (useNoScrollbars ? MultiView.NO_SCROLLBARS : MultiView.NO_OPTIONS) | (hideResultSetController ? MultiView.HIDE_RESULTSET_CONTROLLER : MultiView.NO_OPTIONS); //MultiView.printCreateOptions("HERE", options); options |= cellSubView.getPropertyAsBoolean("nosep", false) ? MultiView.DONT_USE_EMBEDDED_SEP : 0; options |= cellSubView.getPropertyAsBoolean("nosepmorebtn", false) ? MultiView.NO_MORE_BTN_FOR_SEP : 0; options |= cellSubView.getPropertyAsBoolean("collapse", false) ? MultiView.COLLAPSE_SEPARATOR : 0; if (!(isACollection && !isSingle)) { options &= ~MultiView.ADD_SEARCH_BTN; } else { options |= cellSubView.getPropertyAsBoolean("addsearch", false) ? MultiView.ADD_SEARCH_BTN : 0; } //MultiView.printCreateOptions("_______________________________", parent.getCreateOptions()); //MultiView.printCreateOptions("_______________________________", options); boolean useBtn = UIHelper.getProperty(props, "btn", false); if (useBtn) { SubViewBtn.DATA_TYPE dataType; if (isSingle) { dataType = SubViewBtn.DATA_TYPE.IS_SINGLESET_ITEM; } else if (isACollection) { dataType = SubViewBtn.DATA_TYPE.IS_SET; } else { dataType = cellSubView.getName().equals("this") ? SubViewBtn.DATA_TYPE.IS_THIS : SubViewBtn.DATA_TYPE.IS_SET; } SubViewBtn subViewBtn = getInstance().createSubViewBtn(parent, cellSubView, subView, dataType, options, props, getClassToCreate(parent, cell), mode); subViewBtn.setHelpContext(props.getProperty("hc", null)); bi.doAddToValidator = false; bi.compToAdd = subViewBtn; String visProp = cell.getProperty("visible"); if (StringUtils.isNotEmpty(visProp) && visProp.equalsIgnoreCase("false") && bi.compToAdd != null) { bi.compToAdd.setVisible(false); } try { addControl(validator, viewBldObj, rowInx, cell, bi); } catch (java.lang.IndexOutOfBoundsException ex) { String msg = "Error adding control type: `" + cell.getType() + "` id: `" + cell.getIdent() + "` name: `" + cell.getName() + "` on row: " + rowInx + " column: " + bi.colInx + "\n" + ex.getMessage(); UIRegistry.showError(msg); return false; } bi.doRegControl = false; bi.compToAdd = null; } else { Color bgColor = getBackgroundColor(props, parent.getBackground()); //log.debug(cellSubView.getName()+" "+UIHelper.getProperty(props, "addsearch", false)); if (UIHelper.getProperty(props, "addsearch", false)) { options |= MultiView.ADD_SEARCH_BTN; } if (UIHelper.getProperty(props, "addadd", false)) { options |= MultiView.INCLUDE_ADD_BTN; } //MultiView.printCreateOptions("SUBVIEW", options); MultiView multiView = new MultiView(parent, cellSubView.getName(), subView, parent.getCreateWithMode(), cellSubView.getDefaultAltViewType(), options, bgColor, cellSubView); multiView.setClassToCreate(getClassToCreate(parent, cell)); setBorder(multiView, cellSubView.getProperties()); parent.addChildMV(multiView); //log.debug("["+cell.getType()+"] ["+cell.getName()+"] col: "+bi.colInx+" row: "+rowInx+" colspan: "+cell.getColspan()+" rowspan: "+cell.getRowspan()); viewBldObj.addSubView(cellSubView, multiView, bi.colInx, rowInx, cellSubView.getColspan(), 1); viewBldObj.closeSubView(cellSubView); Viewable viewable = multiView.getCurrentView(); if (viewable != null) { if (viewable instanceof TableViewObj) { ((TableViewObj) viewable).setVisibleRowCount(cellSubView.getTableRows()); } if (viewable.getValidator() != null && childInfo != null) { viewable.getValidator().setRequired(childInfo.isRequired()); } } bi.colInx += cell.getColspan() + 1; } bi.curMaxRow = rowInx; //if (hasColor) //{ // setMVBackground(multiView, multiView.getBackground()); //} } else { log.error("buildFormView - parent is NULL for subview [" + subViewName + "]"); bi.colInx += 2; } } else { //log.debug("["+cell.getType()+"] ["+cell.getName()+"] col: "+bi.colInx+" row: "+rowInx+" colspan: "+cell.getColspan()+" rowspan: "+cell.getRowspan()); viewBldObj.addSubView(cellSubView, parent, bi.colInx, rowInx, cellSubView.getColspan(), 1); AltViewIFace altView = subView.getDefaultAltView(); DBTableInfo sbTableInfo = DBTableIdMgr.getInstance().getByClassName(subView.getClassName()); ViewDefIFace altsViewDef = (ViewDefIFace) altView.getViewDef(); if (altsViewDef instanceof FormViewDefIFace) { FormViewDefIFace fvd = (FormViewDefIFace) altsViewDef; processRows(sbTableInfo, parent, viewDef, validator, viewBldObj, altView.getMode(), labelsForHash, currDataObj, fvd.getRows()); } else if (altsViewDef == null) { // This error is bad enough to have it's own dialog String msg = String.format("The Altview '%s' has a null ViewDef!", altView.getName()); FormDevHelper.appendFormDevError(msg); UIRegistry.showError(msg); } viewBldObj.closeSubView(cellSubView); bi.colInx += cell.getColspan() + 1; } } else { log.error("buildFormView - Could find subview's with ViewSet[" + cellSubView.getViewSetName() + "] ViewName[" + subViewName + "]"); } // still have compToAdd = null; } else if (cell.getType() == FormCellIFace.CellType.statusbar) { bi.compToAdd = new JStatusBar(); bi.doRegControl = true; bi.doAddToValidator = false; } else if (cell.getType() == FormCellIFace.CellType.panel) { bi.doRegControl = false; bi.doAddToValidator = false; cell.setIgnoreSetGet(true); FormCellPanel cellPanel = (FormCellPanel) cell; PanelViewable.PanelType panelType = PanelViewable.getType(cellPanel.getPanelType()); if (panelType == PanelViewable.PanelType.Panel) { PanelViewable panelViewable = new PanelViewable(viewBldObj, cellPanel); processRows(parentTableInfo, parent, viewDef, validator, panelViewable, mode, labelsForHash, currDataObj, cellPanel.getRows()); panelViewable.setVisible(cellPanel.getPropertyAsBoolean("visible", true)); setBorder(panelViewable, cellPanel.getProperties()); if (parent != null) { Color bgColor = getBackgroundColor(cellPanel.getProperties(), parent.getBackground()); if (bgColor != null && bgColor != parent.getBackground()) { panelViewable.setOpaque(true); panelViewable.setBackground(bgColor); } } bi.compToAdd = panelViewable; bi.doRegControl = true; bi.compToReg = panelViewable; } else if (panelType == PanelViewable.PanelType.ButtonBar) { bi.compToAdd = PanelViewable.buildButtonBar(processRows(viewBldObj, cellPanel.getRows())); } else { FormDevHelper.appendFormDevError("Panel Type is not implemented."); return false; } } String visProp = cell.getProperty("visible"); if (StringUtils.isNotEmpty(visProp) && visProp.equalsIgnoreCase("false") && bi.compToAdd != null) { bi.compToAdd.setVisible(false); } return true; }