wizarddialog.java
来自「优秀的打印控件全源代码,类似水晶表的设计器!」· Java 代码 · 共 1,696 行 · 第 1/5 页
JAVA
1,696 行
this.jLabelStep4.setFont(f); this.jLabelStep5.setFont(f); switch (panel) { case 1: this.jPanelRoot.add(jPanelStep1); this.jLabelStep1.setFont(f2); break; case 2: this.jPanelRoot.add(jPanelStep2); this.jLabelStep2.setFont(f2); break; case 3: this.jPanelRoot.add(jPanelStep3); this.jLabelStep3.setFont(f2); break; case 4: this.jPanelRoot.add(jPanelStep4); this.jLabelStep4.setFont(f2); break; case 5: this.jPanelRoot.add(jPanelStep5); this.jLabelStep5.setFont(f2); break; } jPanelRoot.updateUI(); } /** When an object implementing interface <code>Runnable</code> is used * to create a thread, starting the thread causes the object's * <code>run</code> method to be called in that separately executing * thread. * <p> * The general contract of the method <code>run</code> is that it may * take any action whatsoever. * * @see java.lang.Thread#run() * */ public void run() { // This method is invoked to read fields.... try { IReportConnection irc = (IReportConnection)((MainFrame)this.getParent()).getProperties().get("DefaultConnection"); Connection c = irc.getConnection(); Statement stmt = c.createStatement(); ResultSet rs = stmt.executeQuery( jRSQLExpressionArea1.getText()); ((javax.swing.DefaultListModel)jList1.getModel()).removeAllElements(); ((javax.swing.DefaultListModel)jList2.getModel()).removeAllElements(); ResultSetMetaData rsmd = rs.getMetaData(); javax.swing.DefaultListModel dlm1 = (javax.swing.DefaultListModel)jList1.getModel(); javax.swing.DefaultListModel dlm2 = (javax.swing.DefaultListModel)jList2.getModel(); for (int i=1; i <=rsmd.getColumnCount(); ++i) { it.businesslogic.ireport.JRField field = new it.businesslogic.ireport.JRField(rsmd.getColumnLabel(i), Misc.getJdbcTypeClass(rsmd.getColumnType(i) )); // Check if parameter already exists... boolean found = false; for (int k=0; i< dlm1.size(); ++k) { it.businesslogic.ireport.JRField f = (it.businesslogic.ireport.JRField)dlm1.getElementAt(k); if (f.getName().equalsIgnoreCase(field.getName())) { found = true; break; } } if (!found) { //this.getJReportFrame().getReport().getFields().addElement(field); dlm1.addElement(field); } } setStep(2, 2); } catch (Exception ex) { java.io.StringWriter sw = new java.io.StringWriter(); ex.printStackTrace(new java.io.PrintWriter( sw )); javax.swing.JOptionPane.showMessageDialog(getParent(),sw.getBuffer()+"","SQL Error", javax.swing.JOptionPane.ERROR_MESSAGE); this.cancelElaborationStep1(); return; } } public void cancelElaborationStep1() { this.jButtonNext.setEnabled(true); this.jButtonPrev.setEnabled(false); } /* * * */ public Report createTabularReport(String templateFileName) { Report template = new Report(templateFileName); template.setDirty(true); template.setFilename(null); //2. Find detail and column header bands... Band detail=null; Band columns=null; Enumeration e = template.getBands().elements(); while (e.hasMoreElements()) { Band band = (Band)e.nextElement(); if (band.getName().equals("detail")) { detail = band; } else if (band.getName().equals("columnHeader")) { columns = band; } } // 1. Normalize position to band... e = template.getElements().elements(); while (e.hasMoreElements()) { ReportElement rElement = (ReportElement)e.nextElement(); rElement.trasform(new java.awt.Point(0,- template.getBandYLocation( rElement.getBand() )),TransformationType.TRANSFORMATION_MOVE ); } //1. Adding groups... if (this.jComboBox1.getSelectedIndex() > 0) { Group g = template.getGroupByName("Group1"); Group g1 = new Group( template, ""+jComboBox1.getSelectedItem(), g.getGroupFooter().getHeight(),g.getGroupHeader().getHeight()); g1.setGroupExpression("$F{"+ jComboBox1.getSelectedItem() + "}" ); template.addGroup(g1); // Add to g1 all elements attached to g.header and g.footer... e = template.getElements().elements(); while (e.hasMoreElements()) { ReportElement rElement = (ReportElement)e.nextElement(); if (rElement.getBand() == g.getGroupHeader()) rElement.setBand(g1.getGroupHeader() ); else if (rElement.getBand() == g.getGroupFooter()) rElement.setBand(g1.getGroupFooter() ); // Set text to Group1 label... if (rElement instanceof StaticTextReportElement) { StaticTextReportElement stre = (StaticTextReportElement)rElement; if (stre.getText().equals("G1Label")) stre.setText( ""+jComboBox1.getSelectedItem()); } else if (rElement instanceof TextFieldReportElement) { TextFieldReportElement tfre = (TextFieldReportElement)rElement; if (tfre.getText().equals("G1Field")) tfre.setText("$F{"+jComboBox1.getSelectedItem()+"}"); } } } if (this.jComboBox2.getSelectedIndex() > 0) { Group g = template.getGroupByName("Group2"); Group g2 = new Group( template, ""+jComboBox2.getSelectedItem(), g.getGroupFooter().getHeight(),g.getGroupHeader().getHeight()); g2.setGroupExpression("$F{"+ jComboBox2.getSelectedItem() + "}" ); template.addGroup(g2); // Add to g2 all elements attached to g.header and g.footer... e = template.getElements().elements(); while (e.hasMoreElements()) { ReportElement rElement = (ReportElement)e.nextElement(); if (rElement.getBand() == g.getGroupHeader()) rElement.setBand(g2.getGroupHeader() ); else if (rElement.getBand() == g.getGroupFooter()) rElement.setBand(g2.getGroupFooter() ); // Set text to Group2 label... if (rElement instanceof StaticTextReportElement) { StaticTextReportElement stre = (StaticTextReportElement)rElement; if (stre.getText().equals("G2Label")) stre.setText( ""+jComboBox2.getSelectedItem()); } else if (rElement instanceof TextFieldReportElement) { TextFieldReportElement tfre = (TextFieldReportElement)rElement; if (tfre.getText().equals("G2Field")) tfre.setText("$F{"+jComboBox2.getSelectedItem()+"}"); } } } if (this.jComboBox3.getSelectedIndex() > 0) { Group g = template.getGroupByName("Group3"); Group g3 = new Group( template, ""+jComboBox3.getSelectedItem(), g.getGroupFooter().getHeight(),g.getGroupHeader().getHeight()); g3.setGroupExpression("$F{"+ jComboBox3.getSelectedItem() + "}" ); template.addGroup(g3); // Add to g3 all elements attached to g.header and g.footer... e = template.getElements().elements(); while (e.hasMoreElements()) { ReportElement rElement = (ReportElement)e.nextElement(); if (rElement.getBand() == g.getGroupHeader()) rElement.setBand(g3.getGroupHeader() ); else if (rElement.getBand() == g.getGroupFooter()) rElement.setBand(g3.getGroupFooter() ); // Set text to Group3 label... if (rElement instanceof StaticTextReportElement) { StaticTextReportElement stre = (StaticTextReportElement)rElement; if (stre.getText().equals("G3Label")) stre.setText( ""+jComboBox3.getSelectedItem()); } else if (rElement instanceof TextFieldReportElement) { TextFieldReportElement tfre = (TextFieldReportElement)rElement; if (tfre.getText().equals("G3Field")) tfre.setText("$F{"+jComboBox3.getSelectedItem()+"}"); } } } if (this.jComboBox4.getSelectedIndex() > 0) { Group g = template.getGroupByName("Group4"); Group g4 = new Group( template, ""+jComboBox4.getSelectedItem(), g.getGroupFooter().getHeight(),g.getGroupHeader().getHeight()); g4.setGroupExpression("$F{"+ jComboBox4.getSelectedItem() + "}" ); template.addGroup(g4); // Add to g4 all elements attached to g.header and g.footer... e = template.getElements().elements(); while (e.hasMoreElements()) { ReportElement rElement = (ReportElement)e.nextElement(); if (rElement.getBand() == g.getGroupHeader()) rElement.setBand(g4.getGroupHeader() ); else if (rElement.getBand() == g.getGroupFooter()) rElement.setBand(g4.getGroupFooter() ); // Set text to Group4 label... if (rElement instanceof StaticTextReportElement) { StaticTextReportElement stre = (StaticTextReportElement)rElement; if (stre.getText().equals("G4Label")) stre.setText( ""+jComboBox4.getSelectedItem()); } else if (rElement instanceof TextFieldReportElement) { TextFieldReportElement tfre = (TextFieldReportElement)rElement; if (tfre.getText().equals("G4Field")) tfre.setText("$F{"+jComboBox4.getSelectedItem()+"}"); } } } //1. Adding fields... int currentx = template.getLeftMargin()+10; int currenty = 10; e = template.getElements().elements(); StaticTextReportElement detailLabel = null; TextFieldReportElement detailField = null; while (e.hasMoreElements() && (detailLabel==null || detailField == null) ) { ReportElement rElement = (ReportElement)e.nextElement(); if (rElement instanceof StaticTextReportElement) { StaticTextReportElement stre = (StaticTextReportElement)rElement; if (stre.getText().equalsIgnoreCase("DetailLabel")) detailLabel =stre; } else if (rElement instanceof TextFieldReportElement) { TextFieldReportElement tfre = (TextFieldReportElement)rElement; if (tfre.getText().equalsIgnoreCase("DetailField")) detailField = tfre; } } if (detailField != null) template.getElements().removeElement(detailField); if (detailLabel != null) template.getElements().removeElement(detailLabel); if (detailField == null) detailField = new TextFieldReportElement(0,0,100,20); if (detailLabel == null) detailLabel = new StaticTextReportElement(0,0,100,18); int nfields = jList2.getModel().getSize(); if (jComboBox1.getSelectedIndex()>0) nfields--; if (jComboBox2.getSelectedIndex()>0) nfields--; if (jComboBox3.getSelectedIndex()>0) nfields--; if (jComboBox4.getSelectedIndex()>0) nfields--; int fwidth = template.getColumnWidth()/nfields; for (int i=0; i<jList2.getModel().getSize(); ++i) { // FIELD it.businesslogic.ireport.JRField f = (it.businesslogic.ireport.JRField)jList2.getModel().getElementAt(i); template.addField(f); if (jComboBox1.getSelectedIndex()>0 && f.getName().equalsIgnoreCase( ""+jComboBox1.getSelectedItem() )) continue; if (jComboBox2.getSelectedIndex()>0 && f.getName().equalsIgnoreCase( ""+jComboBox2.getSelectedItem() )) continue; if (jComboBox3.getSelectedIndex()>0 && f.getName().equalsIgnoreCase( ""+jComboBox3.getSelectedItem() )) continue; if (jComboBox4.getSelectedIndex()>0 && f.getName().equalsIgnoreCase( ""+jComboBox4.getSelectedItem() )) continue; TextFieldReportElement re = (TextFieldReportElement)detailField.cloneMe(); re.setPosition(new java.awt.Point(currentx,detailField.getPosition().y)); re.setWidth( fwidth); re.updateBounds(); re.setText("$F{"+ f.getName() +"}"); re.setBand(detail); re.setClassExpression(f.getClassType()); template.getElements().addElement(re); // COLUMN LABEL... StaticTextReportElement sre = (StaticTextReportElement)detailLabel.cloneMe(); sre.setPosition(new java.awt.Point(currentx,detailLabel.getPosition().y)); sre.setWidth(fwidth); sre.updateBounds(); sre.setText(""+ f.getName() +"");
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?