📄 textwizardform.java
字号:
}
Vector elements = it.businesslogic.ireport.gui.MainFrame.getMainInstance().getActiveReportFrame().getReport().getElements();
Enumeration enum_elements = elements.elements();
Vector elements_to_remove = new Vector();
while (enum_elements.hasMoreElements())
{
ReportElement element = (ReportElement)enum_elements.nextElement();
if (element.getBand().getName().equalsIgnoreCase("columnHeader") ||
element.getBand().getName().equalsIgnoreCase("detail"))
{
elements_to_remove.add(element);
}
}
it.businesslogic.ireport.gui.MainFrame.getMainInstance().getActiveReportFrame().setSelectedElements( elements_to_remove );
it.businesslogic.ireport.gui.MainFrame.getMainInstance().getActiveReportFrame().deleteSelectedElements();
int left_char = 0;
Band columnHeader = it.businesslogic.ireport.gui.MainFrame.getMainInstance().getActiveReportFrame().getReport().getBandByName("columnHeader");
Band detail = it.businesslogic.ireport.gui.MainFrame.getMainInstance().getActiveReportFrame().getReport().getBandByName("detail");
for (int i=0; i<jTable1.getSelectedRowCount(); ++i)
{
// Aggiungiamo un elemento di etichetta e uno di testo....
int cut_to = ((Integer)jTable1.getValueAt(selectedRows[i],2)).intValue();
StaticTextReportElement stre = new StaticTextReportElement(left_char*10 + 10, columnHeader.getBandYLocation()+10, 10*cut_to, 20);
stre.setBand( columnHeader);
stre.setText( jTable1.getValueAt(selectedRows[i],0) + "");
stre.setFontName("Monospaced");
stre.setFontSize(14);
it.businesslogic.ireport.gui.MainFrame.getMainInstance().getActiveReportFrame().fireReportListenerReportElementsChanged(new ReportElementChangedEvent(it.businesslogic.ireport.gui.MainFrame.getMainInstance().getActiveReportFrame(), stre , ReportElementChangedEvent.ADDED));
it.businesslogic.ireport.gui.MainFrame.getMainInstance().getActiveReportFrame().addUndoOperation( new InsertElementOperation( it.businesslogic.ireport.gui.MainFrame.getMainInstance().getActiveReportFrame(), stre ) );
it.businesslogic.ireport.gui.MainFrame.getMainInstance().getActiveReportFrame().getReport().getElements().add(stre);
TextFieldReportElement tfre = new TextFieldReportElement(left_char*10 + 10, detail.getBandYLocation() + 10, 10*cut_to , 20);
tfre.setBand( detail);
tfre.setFontName("Monospaced");
tfre.setFontSize(14);
String name = "$F{" + jTable1.getValueAt(selectedRows[i],0) + "}";
// cerchiamo il campo e vediamo se e numerico...
Enumeration fields = it.businesslogic.ireport.gui.MainFrame.getMainInstance().getActiveReportFrame().getReport().getFields().elements();
boolean is_string = false;
String type = "";
while (fields.hasMoreElements())
{
JRField field = (JRField)fields.nextElement();
if (field.getName().equalsIgnoreCase( jTable1.getValueAt(selectedRows[i],0)+"" ))
{
if (field.getClassType().equalsIgnoreCase("java.lang.String"))
is_string = true;
type = field.getClassType();
break;
}
}
if (is_string)
{
tfre.setText( "( ((" + name + "!=null) && (" +name+".length() > " + cut_to + ")) ? " + name + ".substring(0,"+ cut_to +") : " + name + ")");
}
else
{
tfre.setText( name );
}
tfre.setClassExpression( type );
it.businesslogic.ireport.gui.MainFrame.getMainInstance().getActiveReportFrame().fireReportListenerReportElementsChanged(new ReportElementChangedEvent(it.businesslogic.ireport.gui.MainFrame.getMainInstance().getActiveReportFrame(), tfre , ReportElementChangedEvent.ADDED));
it.businesslogic.ireport.gui.MainFrame.getMainInstance().getActiveReportFrame().addUndoOperation( new InsertElementOperation( it.businesslogic.ireport.gui.MainFrame.getMainInstance().getActiveReportFrame(), tfre ) );
it.businesslogic.ireport.gui.MainFrame.getMainInstance().getActiveReportFrame().getReport().getElements().add(tfre);
left_char += cut_to+1;
}
}//GEN-LAST:event_jButton2ActionPerformed
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// TODO add your handling code here:
DefaultTableModel dtm = (DefaultTableModel)jTable1.getModel();
dtm.setRowCount(0);
if (it.businesslogic.ireport.gui.MainFrame.getMainInstance().getActiveReportFrame() == null)
{
javax.swing.JOptionPane.showMessageDialog(this,"No report frame selected!");
return;
}
int chars = it.businesslogic.ireport.gui.MainFrame.getMainInstance().getActiveReportFrame().getReport().getWidth() / 10;
((javax.swing.SpinnerNumberModel)jSpinner1.getModel()).setValue( new Integer(chars) );
IReportConnection conn = (IReportConnection)it.businesslogic.ireport.gui.MainFrame.getMainInstance().getProperties().get("DefaultConnection");
if (!conn.isJDBCConnection()) {
javax.swing.JOptionPane.showMessageDialog(this,"The active connection is not of type JDBC. Activate a JDBC connection first." );
return;
}
String query = it.businesslogic.ireport.gui.MainFrame.getMainInstance().getActiveReportFrame().getReport().getQuery();
if (query.toLowerCase().indexOf("where") >= 0)
{
query = query.substring(0, query.toLowerCase().lastIndexOf("where"));
}
//
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
ResultSetMetaData rsmd = null;
try {
con = conn.getConnection();
stmt = con.createStatement();
try {
stmt.setMaxRows(1);
} catch (Exception ex) { }
rs = stmt.executeQuery(query);
rsmd = rs.getMetaData();
for (int i=1; i<=rsmd.getColumnCount(); ++i)
{
String name = rsmd.getColumnName( i );
TextColumn ct = new TextColumn(name, rsmd.getColumnDisplaySize( i ));
Enumeration fields = it.businesslogic.ireport.gui.MainFrame.getMainInstance().getActiveReportFrame().getReport().getFields().elements();
boolean found = false;
while (fields.hasMoreElements())
{
JRField field = (JRField)fields.nextElement();
if (field.getName().equalsIgnoreCase( name ))
{
found = true;
}
}
if (found)
dtm.addRow(new Object[]{ct, new Integer(ct.getSize()), new Integer(ct.getSize())});
}
} catch (Exception ex)
{
javax.swing.JOptionPane.showMessageDialog(this,"error during query execution: " + ex.getMessage());
ex.printStackTrace();
} finally
{
try { if (stmt != null) stmt.close(); } catch (Exception ex){}
try { if (con != null) con.close(); } catch (Exception ex){}
}
}//GEN-LAST:event_jButton1ActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
new TextWizardForm(new javax.swing.JFrame(), true).show();
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel4;
private javax.swing.JPanel jPanel5;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JSpinner jSpinner1;
private javax.swing.JTable jTable1;
// End of variables declaration//GEN-END:variables
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -