OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Comparer les révisions

Ignorer les espaces blanc Révision 167 → Révision 168

/trunk/jOpenCalendar/src/org/jopencalendar/print/CalendarItemPrinter.java
31,20 → 31,20
 
public class CalendarItemPrinter implements Printable, Pageable {
 
private static final int RIGHT_MARGIN = 50;
public static final Font FONT_NORMAL = new Font("Arial", Font.PLAIN, 11);
public static final Font FONT_BOLD = FONT_NORMAL.deriveFont(Font.BOLD);
 
private List<JCalendarItem> items;
 
private List<CalendarItemPage> pages = null;
 
private String title;
 
private boolean showDuration = true;
private PageFormat calendarPageFormat;
 
private PageFormat pf;
 
public CalendarItemPrinter(String title, List<JCalendarItem> items, PageFormat pf) {
this.title = title;
this.items = items;
this.pf = pf;
this.calendarPageFormat = pf;
}
 
public String getTitle() {
51,11 → 51,8
return title;
}
 
public static final Font FONT_NORMAL = new Font("Arial", Font.PLAIN, 11);
public static final Font FONT_BOLD = FONT_NORMAL.deriveFont(Font.BOLD);
 
@Override
public int print(Graphics g, PageFormat pf, int pageIndex) throws PrinterException {
 
if (pages == null) {
computeLayout(g, pf);
}
68,13 → 65,16
g2d.translate(pf.getImageableX(), pf.getImageableY());
final CalendarItemPage page = this.pages.get(pageIndex);
 
printPage(g, pf, page);
printPage(g, page);
 
/* tell the caller that this page is part of the printed document */
return PAGE_EXISTS;
}
 
public void printPage(Graphics g, PageFormat pf, final CalendarItemPage page) {
public void printPage(Graphics g, final CalendarItemPage page) {
// We use our own page format to avoid issue between formatting and printing
PageFormat pf = this.calendarPageFormat;
 
final Graphics2D g2d = (Graphics2D) g;
// Title
g.setFont(getTitleFont());
92,6 → 92,7
g.drawString(strPages, xStrPages, g2d.getFontMetrics().getHeight());
 
final double hourColumnWidth = getHourColumnWidth();
final double maxWidth = pf.getImageableWidth() - hourColumnWidth - getMarginRight();
for (int i = 0; i < size; i++) {
final JCalendarItem item = page.getItems().get(i);
final double lineHeight = page.getHeights().get(i);
124,7 → 125,6
g2d.drawString(formatDuration(dtStart, dtEnd), 3, durationY);
}
 
final double maxWidth = pf.getImageableWidth() - hourColumnWidth;
// Summary
g.setFont(getLine1Font(item));
 
131,7 → 131,7
final List<String> l1 = LayoutUtils.wrap(getLine1Text(item), g.getFontMetrics(), (int) maxWidth);
if (item.hasFlag(Flag.getFlag("warning"))) {
g2d.setColor(new Color(255, 249, 144));
g2d.fillRect((int) hourColumnWidth - 1, lY + 3, (int) maxWidth, (int) g2d.getFontMetrics().getHeight() * l1.size());
g2d.fillRect((int) hourColumnWidth - 1, lY + 3, (int) maxWidth, g2d.getFontMetrics().getHeight() * l1.size());
}
g.setColor(getLine1Color(item));
for (String string : l1) {
151,6 → 151,10
}
}
 
private int getMarginRight() {
return RIGHT_MARGIN;
}
 
public String getDate(final DateFormat df, final JCalendarItem item) {
return LayoutUtils.firstUp(df.format(item.getDtStart().getTime()));
}
255,9 → 259,12
}
 
private void computeLayout(Graphics g, PageFormat pf) {
int pageIndex = 0;
pages = new ArrayList<CalendarItemPage>();
CalendarItemPage page = new CalendarItemPage();
page.setPageIndex(pageIndex);
this.pages.add(page);
pageIndex++;
if (items.isEmpty()) {
return;
}
275,9 → 282,12
double secureMargin = 20D;
if (remainingHeight < h + secureMargin) {
page = new CalendarItemPage();
page.setPageIndex(pageIndex);
showDate = true;
remainingHeight = pf.getImageableHeight() - getTitleHeight();
this.pages.add(page);
pageIndex++;
 
}
if (showDate) {
g.setFont(getHourFont(item));
301,12 → 311,17
}
 
private double getPrintHeight(Graphics g, PageFormat pf, JCalendarItem item) {
double maxWidth = pf.getImageableWidth() - getHourColumnWidth();
double heigth = 0;
int maxWidth = (int) pf.getImageableWidth() - getHourColumnWidth() - getMarginRight();
// Line 1
g.setFont(this.getLine1Font(item));
int l1 = LayoutUtils.wrap(getLine1Text(item), g.getFontMetrics(), (int) maxWidth).size();
int l1 = LayoutUtils.wrap(getLine1Text(item), g.getFontMetrics(), maxWidth).size();
heigth += l1 * g.getFontMetrics().getHeight();
// Line 2
g.setFont(this.getLine2Font(item));
int l2 = LayoutUtils.wrap(getLine2Text(item), g.getFontMetrics(), (int) maxWidth).size();
return (l1 + l2) * g.getFontMetrics().getHeight();
int l2 = LayoutUtils.wrap(getLine2Text(item), g.getFontMetrics(), maxWidth).size();
heigth += l2 * g.getFontMetrics().getHeight();
return heigth;
}
 
public List<CalendarItemPage> getPages() {
313,7 → 328,7
return pages;
}
 
public static void main(String args[]) {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
 
@Override
331,7 → 346,7
@Override
public void actionPerformed(ActionEvent e) {
PrinterJob job = PrinterJob.getPrinterJob();
List<JCalendarItem> items = new ArrayList<JCalendarItem>();
List<JCalendarItem> cItems = new ArrayList<JCalendarItem>();
Calendar c = Calendar.getInstance();
Flag.register(new Flag("warning", null, "Warning", "A default warning"));
for (int i = 0; i < 50; i++) {
343,22 → 358,27
if (i % 2 == 0)
d.append(" Hello");
else
d.append(" World");
d.append(" Wo");
}
d.append("END");
if (i % 6 == 0) {
item.addFlag(Flag.getFlag("warning"));
}
item.setDescription(d.toString());
if (i != 5) {
item.setDescription(d.toString());
} else {
item.setDescription(
"Escalier Ménage Complet - 2 escaliers : Interrupteurs, poignées portes, mains courantes côté route, traces de doigts sur vitres et ascenseur, aspiration moquettes et carrelage, lavage des halls.");
}
item.setDtStart(c);
c.add(Calendar.HOUR_OF_DAY, 1);
item.setDtEnd(c);
c.add(Calendar.HOUR_OF_DAY, 1);
items.add(item);
cItems.add(item);
}
final PrintRequestAttributeSet printAttributes = new HashPrintRequestAttributeSet();
printAttributes.add(PrintQuality.HIGH);
job.setPrintable(new CalendarItemPrinter("OpenConcerto", items, job.getPageFormat(printAttributes)));
job.setPrintable(new CalendarItemPrinter("OpenConcerto", cItems, job.getPageFormat(printAttributes)));
boolean ok = job.printDialog();
if (ok) {
try {
386,20 → 406,20
@Override
public int getNumberOfPages() {
if (this.pages == null) {
BufferedImage off_Image = new BufferedImage((int) pf.getHeight(), (int) pf.getWidth(), BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = off_Image.createGraphics();
computeLayout(g2, pf);
BufferedImage offImage = new BufferedImage((int) calendarPageFormat.getHeight(), (int) calendarPageFormat.getWidth(), BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = offImage.createGraphics();
computeLayout(g2, calendarPageFormat);
}
return this.pages.size();
}
 
@Override
public PageFormat getPageFormat(int pageIndex) throws IndexOutOfBoundsException {
return this.pf;
public PageFormat getPageFormat(int pageIndex) {
return this.calendarPageFormat;
}
 
@Override
public Printable getPrintable(int pageIndex) throws IndexOutOfBoundsException {
public Printable getPrintable(int pageIndex) {
final CalendarItemPage page = this.pages.get(pageIndex);
return new Printable() {
 
406,8 → 426,8
@Override
public int print(Graphics graphics, PageFormat pageFormat, int i) throws PrinterException {
final Graphics2D g2d = (Graphics2D) graphics;
g2d.translate(pf.getImageableX(), pf.getImageableY());
printPage(graphics, pageFormat, page);
g2d.translate(calendarPageFormat.getImageableX(), calendarPageFormat.getImageableY());
printPage(graphics, page);
return PAGE_EXISTS;
}
};
/trunk/jOpenCalendar/src/org/jopencalendar/ui/MultipleDayView.java
29,9 → 29,9
 
public abstract class MultipleDayView extends JPanel implements Scrollable {
public static final String CALENDARD_ITEMS_PROPERTY = "calendard_items_changed";
public final static Color WHITE_TRANSPARENCY_COLOR = new Color(255, 255, 255, 180);
public static final Color WHITE_TRANSPARENCY_COLOR = new Color(255, 255, 255, 180);
public static final Color LIGHT_BLUE = new Color(202, 212, 220);
public final static Color LIGHT = new Color(222, 222, 222);
public static final Color LIGHT = new Color(222, 222, 222);
public static final int TITLE_HEIGHT = 20;
public static final int HOURS_LABEL_WIDTH = 50;
 
391,9 → 391,7
}
 
public int getColumnWidth(int column) {
final int c = (this.getWidth() - HOURS_LABEL_WIDTH) / getColumnCount();
 
return c;
return (this.getWidth() - HOURS_LABEL_WIDTH) / getColumnCount();
}
 
public int getColumnX(int column) {
538,7 → 536,7
}
 
public final void setRowHeight(final int v) {
if (this.rowHeight != v && v < 200 && v > 20) {
if (this.rowHeight != v && v > 20 && v < 250) {
this.rowHeight = v;
// update size
final int w = this.getSize().width;
585,11 → 583,11
this.hListeners.remove(l);
}
 
abstract public String getColumnTitle(int index);
public abstract String getColumnTitle(int index);
 
abstract public int getColumnCount();
public abstract int getColumnCount();
 
abstract public void reload();
public abstract void reload();
 
public void deselectAll() {
for (ItemPartView p : selectedItems) {
/trunk/jOpenCalendar/src/org/jopencalendar/ui/CalendarWithToolBar.java
182,7 → 182,7
}
 
public static JSlider createZoomSlider(final MultipleDayView mdview) {
final JSlider zoomSlider = new JSlider(1, 9, 1);
final JSlider zoomSlider = new JSlider(1, 10, 1);
zoomSlider.setSnapToTicks(true);
zoomSlider.setMajorTickSpacing(1);
zoomSlider.setPaintTicks(true);
/trunk/jOpenCalendar/src/org/jopencalendar/ui/JCalendarItemProvider.java
29,10 → 29,23
cal.set(Calendar.YEAR, year);
cal.set(Calendar.DAY_OF_YEAR, dayOfYear);
cal.add(Calendar.HOUR_OF_DAY, 8);
 
int gCount = 0;
JCalendarItemGroup g = new JCalendarItemGroup();
g.setName("Group " + gCount);
Flag flag = new Flag("planned", new ImageIcon(JCalendarItemProvider.class.getResource("calendar_small.png")), "Planned", "planned item");
 
JCalendarItem item0 = new JCalendarItem();
item0.addFlag(flag);
item0.setSummary("5 minutes");
item0.setDtStart(cal);
Calendar c2 = (Calendar) cal.clone();
c2.add(Calendar.MINUTE, 5);
item0.setDtEnd(c2);
item0.setDayOnly(false);
g.addItem(item0);
l.add(item0);
 
for (int d = 0; d < 8; d++) {
JCalendarItem i = new JCalendarItem();
i.addFlag(flag);
80,6 → 93,16
JCalendarItemGroup g = new JCalendarItemGroup();
g.setName("Group " + gCount);
final Flag flag = new Flag("planned", new ImageIcon(JCalendarItemProvider.class.getResource("calendar_small.png")), "Planned", "planned item");
JCalendarItem item0 = new JCalendarItem();
item0.addFlag(flag);
item0.setSummary("5 minutes");
item0.setDtStart(cal);
Calendar cal3 = (Calendar) cal.clone();
cal3.add(Calendar.MINUTE, 5);
item0.setDtEnd(cal3);
item0.setDayOnly(false);
g.addItem(item0);
l.add(item0);
 
for (int d = 1; d < 6; d++) {
{