Dépôt officiel du code source de l'ERP OpenConcerto
/trunk/Modules/Module Product Label/.project |
---|
New file |
0,0 → 1,17 |
<?xml version="1.0" encoding="UTF-8"?> |
<projectDescription> |
<name>Module Product Label</name> |
<comment></comment> |
<projects> |
</projects> |
<buildSpec> |
<buildCommand> |
<name>org.eclipse.jdt.core.javabuilder</name> |
<arguments> |
</arguments> |
</buildCommand> |
</buildSpec> |
<natures> |
<nature>org.eclipse.jdt.core.javanature</nature> |
</natures> |
</projectDescription> |
/trunk/Modules/Module Product Label/src/org/openconcerto/modules/label/SQLElementNames_en.xml |
---|
New file |
0,0 → 1,2 |
<translations> |
</translations> |
/trunk/Modules/Module Product Label/src/org/openconcerto/modules/label/LabelPanel.java |
---|
New file |
0,0 → 1,167 |
package org.openconcerto.modules.label; |
import java.awt.BasicStroke; |
import java.awt.Color; |
import java.awt.Dimension; |
import java.awt.Graphics; |
import java.awt.Graphics2D; |
import java.awt.event.MouseAdapter; |
import java.awt.event.MouseEvent; |
import java.awt.print.PageFormat; |
import java.awt.print.Printable; |
import java.awt.print.PrinterException; |
import java.util.List; |
import javax.swing.JPanel; |
import org.openconcerto.sql.model.SQLRowAccessor; |
public class LabelPanel extends JPanel implements Printable { |
private List<? extends SQLRowAccessor> list; |
private int lines; |
private int columns; |
private Boolean[][] mask; |
private final Color VERY_LIGHT_GRAY = new Color(230, 230, 230); |
private LabelRenderer renderer; |
private boolean ignoreMargins = false; |
public LabelPanel(List<? extends SQLRowAccessor> list, int l, int c, LabelRenderer labelRenderer) { |
this.list = list; |
this.renderer = labelRenderer; |
setSizeLayoutSize(l, c); |
this.addMouseListener(new MouseAdapter() { |
@Override |
public void mousePressed(MouseEvent e) { |
int w = getWidth() / columns; |
int h = getHeight() / lines; |
int j = e.getX() / w; |
int i = e.getY() / h; |
if (i >= 0 && i < lines && j >= 0 && j < columns) { |
mask[i][j] = !mask[i][j]; |
} |
repaint(); |
} |
}); |
} |
private void setSizeLayoutSize(int l, int c) { |
this.lines = l; |
this.columns = c; |
this.mask = new Boolean[l][c]; |
for (int i = 0; i < l; i++) { |
for (int j = 0; j < c; j++) { |
this.mask[i][j] = Boolean.FALSE; |
} |
} |
} |
public void setIgnoreMargins(boolean ignoreMargins) { |
this.ignoreMargins = ignoreMargins; |
} |
@Override |
public void paint(Graphics g) { |
g.setColor(Color.WHITE); |
g.fillRect(0, 0, this.getWidth(), this.getHeight()); |
int w = this.getWidth() / this.columns; |
int h = this.getHeight() / this.lines; |
Graphics2D g2 = (Graphics2D) g; |
float dash1[] = { 10.0f }; |
BasicStroke dashed = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash1, 0.0f); |
BasicStroke n = new BasicStroke(1.0f); |
int rowIndex = 0; |
for (int i = 0; i < this.lines; i++) { |
for (int j = 0; j < this.columns; j++) { |
boolean mask = this.mask[i][j]; |
if (mask) { |
// Disabled |
g.setColor(VERY_LIGHT_GRAY); |
g.fillRect(j * w, i * h, w, h); |
} else { |
// Dashed borders |
g.setColor(Color.WHITE); |
g2.setStroke(n); |
g.drawRect(j * w, i * h, w, h); |
g.setColor(Color.GRAY); |
g2.setStroke(dashed); |
g.drawRect(j * w, i * h, w, h); |
// Label |
if (rowIndex < list.size()) { |
SQLRowAccessor row = list.get(rowIndex); |
renderer.paintLabel(g, row, j * w, i * h, w, h); |
} |
rowIndex++; |
} |
} |
} |
} |
@Override |
public Dimension getPreferredSize() { |
return new Dimension(400, 600); |
} |
public void setLineCount(int l) { |
setSizeLayoutSize(l, this.columns); |
repaint(); |
} |
public void setColumnCount(int c) { |
setSizeLayoutSize(this.lines, c); |
repaint(); |
} |
@Override |
public int print(Graphics g, PageFormat pageFormat, int pageIndex) throws PrinterException { |
int nbLabelPerPage = 0; |
for (int i = 0; i < this.lines; i++) { |
for (int j = 0; j < this.columns; j++) { |
boolean mask = this.mask[i][j]; |
if (!mask) { |
nbLabelPerPage++; |
} |
} |
} |
if (nbLabelPerPage < 1) { |
return NO_SUCH_PAGE; |
} |
int labelCount = this.list.size(); |
if (nbLabelPerPage * pageIndex > labelCount) { |
return NO_SUCH_PAGE; |
} |
int imageableWidth = (int) pageFormat.getImageableWidth(); |
int imageableHeight = (int) pageFormat.getImageableHeight(); |
int imageableX = (int) pageFormat.getImageableX(); |
int imageableY = (int) pageFormat.getImageableY(); |
if (ignoreMargins) { |
imageableWidth = (int) pageFormat.getWidth(); |
imageableHeight = (int) pageFormat.getHeight(); |
imageableX = 0; |
imageableY = 0; |
} |
int w = imageableWidth / this.columns; |
int h = imageableHeight / this.lines; |
// print labels |
int rowIndex = pageIndex * nbLabelPerPage; |
for (int i = 0; i < this.lines; i++) { |
for (int j = 0; j < this.columns; j++) { |
boolean mask = this.mask[i][j]; |
if (!mask && rowIndex < list.size()) { |
SQLRowAccessor row = list.get(rowIndex); |
renderer.paintLabel(g, row, j * w + imageableX, i * h + imageableY, w, h); |
} |
rowIndex++; |
} |
} |
return PAGE_EXISTS; |
} |
} |
/trunk/Modules/Module Product Label/src/org/openconcerto/modules/label/ModuleResources_fr.properties |
---|
New file |
0,0 → 1,2 |
name=Etiquettes de produits |
description=Impression des étiquettes des articles |
/trunk/Modules/Module Product Label/src/org/openconcerto/modules/label/SQLElementNames_fr.xml |
---|
New file |
0,0 → 1,2 |
<translations> |
</translations> |
/trunk/Modules/Module Product Label/src/org/openconcerto/modules/label/labels_en.xml |
---|
New file |
0,0 → 1,2 |
<?xml version="1.0" encoding="UTF-8" ?> |
<ROOT /> |
/trunk/Modules/Module Product Label/src/org/openconcerto/modules/label/ModuleLabel.java |
---|
New file |
0,0 → 1,88 |
package org.openconcerto.modules.label; |
import java.awt.Color; |
import java.awt.Graphics; |
import java.awt.event.ActionEvent; |
import java.awt.geom.Rectangle2D; |
import java.io.IOException; |
import java.util.List; |
import javax.swing.AbstractAction; |
import org.openconcerto.erp.modules.AbstractModule; |
import org.openconcerto.erp.modules.ComponentsContext; |
import org.openconcerto.erp.modules.ModuleFactory; |
import org.openconcerto.sql.model.SQLRowAccessor; |
import org.openconcerto.sql.view.list.IListe; |
import org.openconcerto.sql.view.list.IListeAction.IListeEvent; |
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction; |
import org.openconcerto.utils.ExceptionHandler; |
import org.openconcerto.utils.GestionDevise; |
import org.openconcerto.utils.StringUtils; |
public final class ModuleLabel extends AbstractModule { |
public ModuleLabel(ModuleFactory f) throws IOException { |
super(f); |
} |
@Override |
protected void setupComponents(ComponentsContext ctxt) { |
final String actionName = "Imprimer les étiquettes"; |
final PredicateRowAction predicateRowAction = new PredicateRowAction(new AbstractAction(actionName) { |
@Override |
public void actionPerformed(ActionEvent arg0) { |
try { |
final IListe list = IListe.get(arg0); |
final LabelFrame f = new LabelFrame(list.getSelectedRows(), new LabelRenderer() { |
@Override |
public void paintLabel(Graphics g, SQLRowAccessor row, int x, int y, int gridWith, int gridHeight) { |
// Default font at 10pt black |
g.setColor(Color.BLACK); |
final float fontSize = 10f; |
g.setFont(g.getFont().deriveFont(fontSize)); |
// Labels borders |
final int hBorder = 12; |
final int vBorder = 8; |
// Product name |
final String text = row.getString("NOM"); |
final List<String> l = StringUtils.wrap(text, g.getFontMetrics(), gridWith - 2 * hBorder); |
final int lineHeight = g.getFontMetrics().getHeight(); |
int lineY = y + (int) ((gridHeight - l.size() * lineHeight) / 2); |
for (String line : l) { |
g.drawString(line, x + hBorder, lineY); |
lineY += lineHeight; |
} |
// Price |
g.setFont(g.getFont().deriveFont(fontSize + 2)); |
final String price = GestionDevise.currencyToString(row.getBigDecimal("PV_TTC")) + " € TTC"; |
final Rectangle2D r2 = g.getFont().getStringBounds(price, g.getFontMetrics().getFontRenderContext()); |
g.drawString(price, x + (int) (gridWith - hBorder - r2.getWidth()), y + gridHeight - vBorder); |
} |
}); |
f.setTitle(actionName); |
f.setLocationRelativeTo(null); |
f.pack(); |
f.setVisible(true); |
} catch (Exception e) { |
ExceptionHandler.handle("Erreur d'impression", e); |
} |
} |
}, true, false); |
predicateRowAction.setPredicate(IListeEvent.createSelectionCountPredicate(1, Integer.MAX_VALUE)); |
ctxt.getElement("ARTICLE").getRowActions().add(predicateRowAction); |
} |
@Override |
protected void start() { |
} |
@Override |
protected void stop() { |
} |
} |
/trunk/Modules/Module Product Label/src/org/openconcerto/modules/label/LabelRenderer.java |
---|
New file |
0,0 → 1,9 |
package org.openconcerto.modules.label; |
import java.awt.Graphics; |
import org.openconcerto.sql.model.SQLRowAccessor; |
public interface LabelRenderer { |
public void paintLabel(Graphics g, SQLRowAccessor row, int x, int y, int gridWith, int gridHeight); |
} |
/trunk/Modules/Module Product Label/src/org/openconcerto/modules/label/labels_fr.xml |
---|
New file |
0,0 → 1,2 |
<?xml version="1.0" encoding="UTF-8" ?> |
<ROOT /> |
/trunk/Modules/Module Product Label/src/org/openconcerto/modules/label/LabelFrame.java |
---|
New file |
0,0 → 1,126 |
package org.openconcerto.modules.label; |
import java.awt.GridBagConstraints; |
import java.awt.GridBagLayout; |
import java.awt.Insets; |
import java.awt.event.ActionEvent; |
import java.awt.event.ActionListener; |
import java.awt.print.PrinterException; |
import java.awt.print.PrinterJob; |
import java.util.List; |
import javax.swing.JButton; |
import javax.swing.JCheckBox; |
import javax.swing.JFrame; |
import javax.swing.JLabel; |
import javax.swing.JPanel; |
import javax.swing.JSeparator; |
import javax.swing.JSpinner; |
import javax.swing.SpinnerNumberModel; |
import javax.swing.event.ChangeEvent; |
import javax.swing.event.ChangeListener; |
import org.openconcerto.sql.model.SQLRowAccessor; |
import org.openconcerto.ui.DefaultGridBagConstraints; |
import org.openconcerto.utils.ExceptionHandler; |
public class LabelFrame extends JFrame { |
private static final boolean IGNORE_MARGINS = true; |
private static final int DEFAULT_LINES = 10; |
private static final int DEFAULT_COLS = 4; |
final LabelPanel labelPanel; |
public LabelFrame(List<? extends SQLRowAccessor> list, LabelRenderer labelRenderer) { |
final JPanel p = new JPanel(); |
p.setLayout(new GridBagLayout()); |
final GridBagConstraints c = new DefaultGridBagConstraints(); |
p.add(createToolBar(), c); |
c.gridy++; |
c.insets = new Insets(0, 0, 0, 0); |
p.add(new JSeparator(JSeparator.HORIZONTAL), c); |
c.gridy++; |
c.weightx = 1; |
c.weighty = 1; |
c.fill = GridBagConstraints.BOTH; |
labelPanel = new LabelPanel(list, DEFAULT_LINES, DEFAULT_COLS, labelRenderer); |
labelPanel.setIgnoreMargins(IGNORE_MARGINS); |
p.add(labelPanel, c); |
this.setContentPane(p); |
} |
public JPanel createToolBar() { |
final JPanel toolbar = new JPanel(); |
toolbar.setLayout(new GridBagLayout()); |
final GridBagConstraints c = new DefaultGridBagConstraints(); |
toolbar.add(new JLabel("Lignes"), c); |
c.gridx++; |
final JSpinner sLines = new JSpinner(new SpinnerNumberModel(DEFAULT_LINES, 1, 100, 1)); |
toolbar.add(sLines, c); |
c.gridx++; |
toolbar.add(new JLabel("Colonnes"), c); |
c.gridx++; |
final JSpinner sColums = new JSpinner(new SpinnerNumberModel(DEFAULT_COLS, 1, 50, 1)); |
toolbar.add(sColums, c); |
c.gridx++; |
final JCheckBox ck = new JCheckBox("Ignorer les marges"); |
ck.setSelected(IGNORE_MARGINS); |
toolbar.add(ck, c); |
c.gridx++; |
c.weightx = 1; |
c.fill = GridBagConstraints.NONE; |
c.anchor = GridBagConstraints.EAST; |
final JButton printButton = new JButton("Imprimer"); |
toolbar.add(printButton, c); |
c.gridx++; |
sLines.addChangeListener(new ChangeListener() { |
@Override |
public void stateChanged(ChangeEvent e) { |
Number n = (Number) sLines.getValue(); |
if (n != null) { |
labelPanel.setLineCount(n.intValue()); |
} |
} |
}); |
sColums.addChangeListener(new ChangeListener() { |
@Override |
public void stateChanged(ChangeEvent e) { |
Number n = (Number) sColums.getValue(); |
if (n != null) { |
labelPanel.setColumnCount(n.intValue()); |
} |
} |
}); |
printButton.addActionListener(new ActionListener() { |
@Override |
public void actionPerformed(ActionEvent e) { |
final PrinterJob job = PrinterJob.getPrinterJob(); |
job.setPrintable(labelPanel); |
boolean ok = job.printDialog(); |
if (ok) { |
try { |
job.print(); |
} catch (PrinterException ex) { |
ExceptionHandler.handle("Print error", ex); |
} |
} |
} |
}); |
ck.addActionListener(new ActionListener() { |
@Override |
public void actionPerformed(ActionEvent e) { |
labelPanel.setIgnoreMargins(ck.isSelected()); |
} |
}); |
return toolbar; |
} |
} |
/trunk/Modules/Module Product Label/src/org/openconcerto/modules/label/ModuleResources.properties |
---|
New file |
0,0 → 1,2 |
name=Product Label |
description=Print products labels |
/trunk/Modules/Module Product Label/.classpath |
---|
New file |
0,0 → 1,7 |
<?xml version="1.0" encoding="UTF-8"?> |
<classpath> |
<classpathentry kind="src" path="src"/> |
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> |
<classpathentry combineaccessrules="false" kind="src" path="/OpenConcerto"/> |
<classpathentry kind="output" path="bin"/> |
</classpath> |
/trunk/Modules/Module Product Label/module.properties |
---|
New file |
0,0 → 1,6 |
# [\p{Alnum}_.]{3,} |
id=org.openconcerto.modules.label |
entryPoint=ModuleLabel |
# \p{Digit}(\.\p{Digit}+)? |
version=1.0 |
contact=ILM Informatique |