tag:blogger.com,1999:blog-6603919244192643172024-03-05T11:24:44.745+02:00Michael Kazarian's blog about IT-related thingsMichael Kazarianhttp://www.blogger.com/profile/08626392846438054040noreply@blogger.comBlogger71125tag:blogger.com,1999:blog-660391924419264317.post-59503745983477335692021-08-30T15:29:00.003+03:002021-08-30T15:29:29.742+03:00Ардуінкове<p> <span class="poster entry-poster "><span class="ljuser" style="white-space: nowrap;"></span></span></p><div class="entry-content"><a href="https://www.quora.com/How-prevalent-is-Arduino-in-the-industry-for-embedded-systems">Тут на Кворі лають Ардуїнку</a>.
Втім, я б не сказав, що вона така вже й погана. Основна вигода від неї —
це купа сумісного з нею заліза. Як правило, коли говорять про ардуїнку,
мають на увазі <a href="https://uk.wikipedia.org/wiki/Arduino_Uno">учбову плату Arduino Uno</a>. </div><div class="separator" style="clear: both; text-align: center;"><a href="https://upload.wikimedia.org/wikipedia/commons/3/38/Arduino_Uno_-_R3.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="600" data-original-width="600" height="324" src="https://upload.wikimedia.org/wikipedia/commons/3/38/Arduino_Uno_-_R3.jpg" width="324" /></a></div><br /><div class="entry-content"><br /></div><div class="entry-content">Це, як на мене, доволі безтолкова, в практичному застосуванні, плата:
вона чималенька, страшенно незручна в монтажі та обвішана непотрібними
елементами на кшталт програматора чи роз’єма живлення. Якщо брати саме
ці пункти, то лають справедливо. Але Arduino це далеко не тільки Uno. У них є <a href="https://www.arduino.cc/en/pmwiki.php?n=Main/ArduinoBoardProMini">Arduino Pro Mini</a>. </div><div class="entry-content"><div class="separator" style="clear: both; text-align: center;"><a href="https://upload.wikimedia.org/wikipedia/commons/0/01/Arduino_Pro_Mini_(2).jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="552" data-original-width="800" height="261" src="https://upload.wikimedia.org/wikipedia/commons/0/01/Arduino_Pro_Mini_(2).jpg" width="378" /></a></div><br /> </div><div class="entry-content">Це, по суті, та ж сама Uno, але без програматора та роз’ємів живлення.
Програматор не проблема, він коштує 2–3$. А тут вже можна робити багато
чого, наприклад всунути на свою плату та опитувати купу периферії. А
якщо ще й сполучити з якимось мікрокомп’ютером для красивого інтерфейсу
чи потужних обчислень, то виходить доволі практично.<br />Крім того, ніхто не заставляє користуватися C++ та фірмовим середовищем для розробки. Це, дійсно, біль. Замість нього є C та <a href="https://platformio.org/">Platform IO</a>. Причому, останній прикручується до чого завгодно.<br />Зрозуміло, що є ще купа достойних альтернатив, <a href="https://www.st.com/en/microcontrollers-microprocessors/stm32f103c8.html">наприклад, ця</a>, <a href="https://www.raspberrypi.org/products/raspberry-pi-pico/">чи ця</a>. Але за ціною та розмірами Pro Mini поки що попереду.</div>Michael Kazarianhttp://www.blogger.com/profile/08626392846438054040noreply@blogger.com0tag:blogger.com,1999:blog-660391924419264317.post-71137177636704926642021-04-20T16:24:00.002+03:002021-04-20T16:24:19.305+03:00Ардуїнне<p> </p><div dir="auto" style="text-align: start;">Вовтужуся зараз з опитуванням заліза. Опитує Arduino Pro Mini. Це ота маленька плата з червоним вогником і купою проводів.</div><div dir="auto" style="text-align: start;"><div class="separator" style="clear: both; text-align: center;"><a href="https://miro.medium.com/max/700/0*CHvPO9NQfwemekdh" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="525" data-original-width="700" height="300" src="https://miro.medium.com/max/700/0*CHvPO9NQfwemekdh" width="400" /></a></div> <br /></div><div dir="auto" style="text-align: start;">На зараз опитується кілька входів. Опитування дуже просте, які саме контакти увімкнено. На стендові видно, що дві нажаті кнопки відповідають двом одиничкам. Решта — нулі. Це — відображення у двійковій системі числення. Нижній рядок — теж саме, але у десятковій. Всі принципові моменти вирішено, залишилося тільки зчитати аналоговий сигнал та відправити це все на більш потужне залізо для обробки.</div><div dir="auto" googl="true" style="text-align: start;"> <div class="separator" style="clear: both; text-align: center;"><a href="https://miro.medium.com/max/700/0*QOzn9EcH7iZVZGEC" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="525" data-original-width="700" height="300" src="https://miro.medium.com/max/700/0*QOzn9EcH7iZVZGEC" width="400" /></a></div><br /></div><div dir="auto" style="text-align: start;">Тепер по Ардуїнці. Скажу наперед, мені сподобалось попри бридкий С++ на якому там все пишеться. Ця крихітка, що менша за половину сірникової коробки, дозволяє зробити чимало корисного: нескладне управляння верстатом, умнодім і т.і. Апаратна платформа там продумана і вдала. І коштує копійки. Що не сподобалось. Як це часто буває, гарні залізячники є поганими програмістами. Програмувати фірмовими засобами — це біль. На щастя, існує така штука, як PlatformIO. Це набір утиліт командного рядка, які беруть на себе всю основну роботу по прошивці Ардуїнки. І вони прикручуються куди хочеш. У правій частині редактора коду видно, як я прикрутив їх. Це, власне, і всі налаштування редактору, які я робив. Нема проблем прикрутити їх і до іншого редактора. До речі, автори PlatformIO зробили годну IDE на базі Visual Studio Code.</div><div dir="auto" style="text-align: start;"><div class="separator" style="clear: both; text-align: center;"><a href="https://miro.medium.com/max/2400/0*GGSW6NlWxhrnicrH" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="427" data-original-width="800" height="213" src="https://miro.medium.com/max/2400/0*GGSW6NlWxhrnicrH" width="400" /></a></div><br /> </div><div dir="auto" style="text-align: start;">Наразі ідеальне поєднання Ардуїнки і якогось мікрокомп'ютера на кшталт Raspberry PI. Ардуїнка взаємодіє з датчиками чи виконавчими механізмами, а Raspberry бере на себе складні обчислення, інтерфейс і т.і.</div>Michael Kazarianhttp://www.blogger.com/profile/08626392846438054040noreply@blogger.com0tag:blogger.com,1999:blog-660391924419264317.post-59258480940047995422021-04-05T10:10:00.000+03:002021-04-05T10:10:23.531+03:00Воскресение Христово: реальное историческое событие?<p>Вчора більша частина християн відмічала Христове Воскресіння. Це та подія, без якої все християнство не має сенсу. Саме про Воскресіння Христа було сказано "вірую, бо абсурдно". Втім, ця фраза не зовсім коректна, бо деякі непрямі докази воскресіння існують. Свого часу я задумався: чому християнство відбулося? Для цього не було жодних передумов. У ті часи були інші харизматичні проповідники. За них щось знають вузькі спеціалісти, а широкий загал знає двох: Іоана Хрестителя та, власне, Христа. Вони мали послідовників, але про них відомо ще менше. А про Христа і його послідовників відомо. Але цього не повинно було б бути! Ісуса розіп'яли і він помер, послідовники зреклися, розгублені і перелякані. Все повинно піти за стандартним сценарієм: життя показало нікчемність їх переконань, а самі учні приречені на смерть і забуття.<br />Але щось пішло не так! Вони почали нести Благу Звістку і страх вже не мав влади над ними. Майже всі вони загинули і, досить болісно. Але не відмовились від своєї місії. Їм вдалося: світ не встояв перед їх проповіддю!<br />Чудес не буває 🙂 Якщо щось пішло не так, як повинно, то у цього є причина. Не можливо піти на смерть за змовою! Не могли неграмотні дядьки і тьотьки донести вчення різним народам! Не можливо абстрактній ідеї заволодіти умами людей та ще й у дуже ворожому оточенні! Отже, у цього була причина. Точніше, цих причин було дві. Перша: вони на власному досвіді переконалися у воскресінні Христа. Друга — їм було надано підтримку, щоб вони прожили досить довго і добратися хтозна-куди, аж до Києва!<br />Саме ці міркування і змусили мене визнати надприродність тих подій. Про все це, але більш аргументовано і цікаво розповів <a href="https://www.facebook.com/andriibaumeister" target="_blank">Andrii Baumeister</a>. Enjoy!</p><p><iframe frameborder="0" height="270" src="https://youtube.com/embed/fe8agy1pb44" style="background-image: url(https://i.ytimg.com/vi/fe8agy1pb44/hqdefault.jpg);" width="480"></iframe></p>Michael Kazarianhttp://www.blogger.com/profile/08626392846438054040noreply@blogger.com0tag:blogger.com,1999:blog-660391924419264317.post-49414112084938360602020-02-25T09:01:00.001+02:002020-02-25T09:05:17.320+02:00Інтерактивна англійська. Базовий курс 1.0.5<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="-webkit-text-stroke-width: 0px; background-color: white; color: #1c1e21; display: block; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: 400; letter-spacing: normal; margin: 0px 0px 6px; orphans: 2; text-align: start; text-decoration-color: initial; text-decoration-style: initial; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
Оновлено додаток "<a href="https://play.google.com/store/apps/details?id=com.kazarian.lessonassistant" target="_blank">Інтерактивна англійська. Базовий курс"</a>.<br />
Покращено паузи між завданнями, додано варіанти перекладу. Окрема подяка <a class="profileLink" data-hovercard-prefer-more-content-show="1" data-hovercard="/ajax/hovercard/user.php?id=100039114607719&extragetparams=%7B%22__tn__%22%3A%22%2CdK-R-R%22%2C%22eid%22%3A%22ARByXvWiTC2AX6fMnvNuJK9uqF1qEfuWZeFvjbfE92lYkxw97bdZQQ8jZ-IOgTeYvm6F7jIJS-sqqQIF%22%2C%22fref%22%3A%22mentions%22%7D" href="https://www.facebook.com/profile.php?id=100039114607719&__tn__=%2CdK-R-R&eid=ARByXvWiTC2AX6fMnvNuJK9uqF1qEfuWZeFvjbfE92lYkxw97bdZQQ8jZ-IOgTeYvm6F7jIJS-sqqQIF&fref=mentions" style="color: #385898; cursor: pointer; font-family: inherit; text-decoration: none;" title="Алла Овчаренко">Алла Овчаренко</a> за виявлену помилку.<br />
<br />
Coming soon¹: буде додано нові уроки та покращено user experience².</div>
<div style="-webkit-text-stroke-width: 0px; background-color: white; color: #1c1e21; display: block; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: 400; letter-spacing: normal; margin: 6px 0px; orphans: 2; text-align: start; text-decoration-color: initial; text-decoration-style: initial; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<hr />
<br />
¹ — незабаром<span class="text_exposed_show" style="display: inline; font-family: inherit;"><br />² — означає зручність роботи з додатком, продуктивність користувача.</span></div>
</div>
Michael Kazarianhttp://www.blogger.com/profile/08626392846438054040noreply@blogger.com0tag:blogger.com,1999:blog-660391924419264317.post-67389741062320332722020-02-19T08:35:00.002+02:002020-02-19T08:45:02.898+02:00Курс "Базова англійська"<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="background-color: white; color: #1c1e21; display: inline; float: none; font-family: "helvetica" , "arial" , sans-serif; font-size: 14px; font-style: normal; font-weight: 400; letter-spacing: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;">Власне, кілька місяців роботи на пару з </span><a class="profileLink" data-hovercard-prefer-more-content-show="1" data-hovercard="/ajax/hovercard/user.php?id=100009574986058&extragetparams=%7B%22__tn__%22%3A%22%2CdK-R-R%22%2C%22eid%22%3A%22ARBwWixkLjG3BNpkWifjFYTy0FWySkk7zZTUrh3jln-i7IRnLTvs-i8lVBk1e4ih6f4vUzKl9Y9mkIn-%22%2C%22fref%22%3A%22mentions%22%7D" href="https://www.facebook.com/kimkol.kimkol?__tn__=%2CdK-R-R&eid=ARBwWixkLjG3BNpkWifjFYTy0FWySkk7zZTUrh3jln-i7IRnLTvs-i8lVBk1e4ih6f4vUzKl9Y9mkIn-&fref=mentions" style="-webkit-text-stroke-width: 0px; background-color: white; color: #385898; cursor: pointer; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-decoration: none; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;" title="Tetiana Kazarian">Tetiana Kazarian</a><span style="background-color: white; color: #1c1e21; display: inline; float: none; font-family: "helvetica" , "arial" , sans-serif; font-size: 14px; font-style: normal; font-weight: 400; letter-spacing: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;"> і ось перший результат — курс "Базова англійська". Ви можете проходити його на YouTube</span><span style="background-color: white; color: #1c1e21; display: inline; float: none; font-family: "helvetica" , "arial" , sans-serif; font-size: 14px; font-style: normal; font-weight: 400; letter-spacing: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;"><span style="background-color: white; color: #1c1e21; display: inline; float: none; font-family: "helvetica" , "arial" , sans-serif; font-size: 14px; font-style: normal; font-weight: 400; letter-spacing: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;">, або на телефоні, чи планшеті за допомогою <a href="https://play.google.com/store/apps/details?id=com.kazarian.lessonassistant" target="_blank">спеціального додатка</a>. Власне, цей додаток і робить курс ефективним оскільки поєднує функції підручника і надає елементи комунікації.</span></span><br />
<br />
<iframe allowfullscreen="" frameborder="0" height="270" src="https://www.youtube.com/embed/O2GnlVYdrqE" width="480"></iframe><br />
<br />
<br />
<br />
<span style="background-color: white; color: #1c1e21; display: inline; float: none; font-family: "helvetica" , "arial" , sans-serif; font-size: 14px; font-style: normal; font-weight: 400; letter-spacing: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;">Я рекомендую спочатку продивитися весь урок, вивчити незнайомі слова, а потім увімкнути вправи та пройти урок ще раз. Курс розроблено таким чином, щоб дати необхідний граматичний та лекси</span><span class="text_exposed_show" style="background-color: white; color: #1c1e21; display: inline; font-family: "helvetica" , "arial" , sans-serif; font-size: 14px; font-style: normal; font-weight: 400; letter-spacing: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;">чний мінімум. Ми усвідомлюємо, що ми всі зайняті люди, тому зробили уроки короткими настільки, наскільки це було можливо.<br />І пару слів про додаток. Він дуже новий, тому можливі деякі глюки, але, в цілому, працює непогано. Втім, є два моменти:<br />• – для розпізнавання вашої вимови використовуються сервіси Google. Якщо вони не зовсім коректно розпізнають вашу вимову, просто виправте результат у полі для відповіді. Крім того, дуже рекомендуємо ПИСАТИ речення. Це дуже дієва практика вивчення будь-якої мови;<br />• – автоматичне перемикання програвача відео з портретної у альбомну орієнтацію поки що не працює. Щоб перемкнутися, натисніть ▭ або ▯.<br />Приємного навчання.</span></div>
Michael Kazarianhttp://www.blogger.com/profile/08626392846438054040noreply@blogger.com0tag:blogger.com,1999:blog-660391924419264317.post-4264001240428849732019-01-28T10:09:00.002+02:002019-01-28T10:09:39.316+02:00What is Python's biggest disadvantage?<div dir="ltr" style="text-align: left;" trbidi="on">
<span class="inline_editor_value" id="__w2_wXyo7F0B53_answer_content"></span><br />
<div class="u-serif-font-main--regular">
<div class="ui_qtext_expanded">
<span class="ui_qtext_rendered_qtext"><div class="ui_qtext_para">
<a href="https://www.quora.com/What-is-Pythons-biggest-disadvantage/answer/Michael-Kazarian?__nsrc__=4&__snid3__=3834371122" target="_blank">Most important for me are</a>:</div>
<div class="ui_qtext_para">
1)
Python seems simple at first glance. There are a lot of points that
always need to keep in mind. Since 2003 I used Python because it was
simple. Since 2016 I use Emacs Lisp instead of Python for disposable
tasks, prototypes and text processing.</div>
<div class="ui_qtext_para">
2) Backward incompatibility of language and libraries more than of Java, Delphi or Emacs.</div>
<div class="ui_qtext_para">
3)
Dynamic typing per se. This is good for little project/team but, it is a
pain in another case. I wrote a library for type checking in a big
project.</div>
<div class="ui_qtext_para">
4) Dynamic typing implementation
makes Python slow. Even slower than Emacs Lisp. Common Lisp
implementations prove that dynamically typed languages could be faster.</div>
</span></div>
</div>
</div>
Michael Kazarianhttp://www.blogger.com/profile/08626392846438054040noreply@blogger.com1tag:blogger.com,1999:blog-660391924419264317.post-3452423272592509842018-01-22T13:28:00.000+02:002018-01-22T13:28:16.412+02:00Word Dolphin 1.2 was released<div dir="ltr" style="text-align: left;" trbidi="on">
What new:<br />
• normal and slower speed of word pronunciation.<br />
• tablet layout was improved.<br />
• user experience was improved.<br />
• performance improvement and bug fixing.<br />
<br />
<a href="http://worddolphin.blogspot.com/2018/01/word-dolphin-12-was-released.html">More...</a></div>
Michael Kazarianhttp://www.blogger.com/profile/08626392846438054040noreply@blogger.com0tag:blogger.com,1999:blog-660391924419264317.post-48708787391906210222017-06-03T14:54:00.003+03:002017-06-03T14:54:54.678+03:00Word Dolphin 1.0.3<div dir="ltr" style="text-align: left;" trbidi="on">
Word Dolphin 1.0.3 was released. <a href="http://worddolphin.blogspot.com/2017/06/word-dolphin-103.html" target="_blank">See details</a>.</div>
Michael Kazarianhttp://www.blogger.com/profile/08626392846438054040noreply@blogger.com0tag:blogger.com,1999:blog-660391924419264317.post-72128957728081968562017-05-10T14:42:00.001+03:002017-05-10T15:04:19.681+03:00Word Dolphin first release<div dir="ltr" style="text-align: left;" trbidi="on">
I'm glad to tell you about Word Dolphin. It's my new Android application designed for memorizing words. Some time ago I wanted to improve my English vocabulary. I wrote unknown words to a notebook and learned them. It worked fine but in the learning process, I found next inconveniences:<br />
<ul style="text-align: left;">
<li>learned words will forget fast; so you must create review calendar;</li>
<li>different words remember differently and you must extra pay attention to them</li>
<li>transcription gives an idea about pronunciation. For good learning, you need to listen to a native speaker</li>
<li>personal paper vocabulary is not good for learning and writing extra information such as comments or samples of usages. Especially it is hard to write between written rows. Of course, you can write necessary things but the extra text in front of the eyes will complicate learning</li>
<li>because of you learn the words written by hand you will have problems to recognize printed words</li>
<li>too hard to find necessary word among many pages of words</li>
<li>adding the words into a notebook makes to learn added words. It is not convenient when you need to learn some words</li>
<li>often notebook with words is absent when you need to add a new word. Also, this approach has words duplicate problem</li>
<li>you can forget or loose a paper notebook</li>
<li>to edit the words written by hand will clog vocabulary because it interferes with learning</li>
<li>eventually, notebook just tears</li>
</ul>
I started to search the application which fixes all these problems but did not find exact because some applications were too complicated especially for children. Another was too slow on my phone or was developed only for one language. Finally, I started to create a Word Dolphin which would be free of these problems. I made an effort for application to work fast and easy to use. I hope it has happened and you like it.<br />
You can get it on<a href="https://play.google.com/store/apps/details?id=com.waverunner.wordrunner" target="_blank"> Google Play</a> and read <a href="http://worddolphin.blogspot.com/" target="_blank">Word Dolphin blog</a>.</div>
Michael Kazarianhttp://www.blogger.com/profile/08626392846438054040noreply@blogger.com0tag:blogger.com,1999:blog-660391924419264317.post-43943590843614048112014-11-06T17:01:00.002+02:002014-11-10T13:54:17.290+02:00JasperReport scriptlet example.<div dir="ltr" style="text-align: left;" trbidi="on">
JasperReport can manipulate some views in depend from calculated data through <a href="http://www.tutorialspoint.com/jasper_reports/jasper_report_expression.htm">report expression</a> mechanism. But report expression has restriction - it must one-string code. So, you can't perform more complex functionality e.g. string manipulation. For such cases JasperReports provides scriptlets. Scriptlets - it java code which executed every time when report request.<br />
<br />
Below I explain how obtain such result:<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqUnY8d50ZrKunBxMkPB6zFncSceYEcnzAHMro878aMKjJvwPtKKs8dfaMrRvrY3Qp66-hGGqKqnbymP-kx9S9EKlB52o-45ckAvXGP-gEPE8SN6QJFUlJQNCu3NMbIOoDOqBMv76oManl/s1600/jr-scriplet-result.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqUnY8d50ZrKunBxMkPB6zFncSceYEcnzAHMro878aMKjJvwPtKKs8dfaMrRvrY3Qp66-hGGqKqnbymP-kx9S9EKlB52o-45ckAvXGP-gEPE8SN6QJFUlJQNCu3NMbIOoDOqBMv76oManl/s1600/jr-scriplet-result.png" height="246" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><i>Picture 1: Obtain data through scriplet.</i> </td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: center;">
</div>
<a name='more'></a>For create scriptlet you must do following:<br />
<ol style="text-align: left;">
<li>Create class which extended <a href="http://jasperreports.sourceforge.net/api/net/sf/jasperreports/engine/JRAbstractScriptlet.html">net.sf.jasperreports.engine.JRAbstractScriptlet</a> or <a href="http://jasperreports.sourceforge.net/api/net/sf/jasperreports/engine/JRDefaultScriptlet.html">net.sf.jasperreports.engine.JRDefaultScriptlet</a>.</li>
<li>Add compiled class to JasperReport classpath. In this article I will use code and datasource <a href="http://mkazarian.blogspot.com/2014/09/runing-jasperreport-subreport-from-java.html">from this article</a>, so my class will added to classpath automatically.</li>
</ol>
Get code with datasource and java code, which run report from <a href="https://bitbucket.org/m_kazarian/ireport-subreport">my bitbucket repository</a> or copy from article. Now add new class which extends <b>JRDefaultScriptlet</b>. JRAbstractScriptlet contains methods which called by event (e.g. <b>callAfterDetailEval</b>), methods which obtain data (<b>getFieldValue</b>, <b>getParameterValue</b>, <b>getVariableValue</b>) and methods for pass data into report (<b>setData</b>, <b>setVariableValue</b>).<br />
Below code for manipulate values of <b>NDoc</b> field:<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: blue;">package</span> com.blogspot.mkazarian;
<span style="color: blue;">import</span> net.sf.jasperreports.engine.JRDefaultScriptlet;
<span style="color: blue;">import</span> net.sf.jasperreports.engine.JRScriptletException;
<span style="color: green;">/**</span>
<span style="color: green;"> * Class for demonstrate scriplet uses with master report.</span>
<span style="color: green;"> */</span>
<span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">ScripletMR</span> <span style="color: blue;">extends</span> JRDefaultScriptlet{
<span style="color: green;">/**</span>
<span style="color: green;"> * @return string with NDoc value.</span>
<span style="color: green;"> */</span>
<span style="color: blue;">public</span> String getDataSourceField() <span style="color: blue;">throws</span> JRScriptletException {
<span style="color: blue;">return</span> <span style="color: #a31515;">"Obtain NDoc field value from scriptlet. It is "</span> + <span style="color: blue;">this</span>.getFieldValue(<span style="color: #a31515;">"NDoc"</span>);
}
}
</pre>
</div>
Now you must compile and register this code in JasperReport. In iReport go to <span style="font-family: "Courier New",Courier,monospace;">java_beans_datasource_report</span> properties and set <b>Scriplet Class</b> property to <span style="font-family: "Courier New",Courier,monospace;">com.blogspot.mkazarian.ScripletMR</span>. Next create <b>scripletVar</b> variable and set <b>Variable Expression</b> property to <span style="font-family: "Courier New",Courier,monospace;">$P{REPORT_SCRIPTLET}.getDataSourceField()</span>.<br />
Finally drag <b>scripletVar </b>from report inspector to <b>Datail1</b> band. Save report and compile it with next command:<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;">cd /path/to/ireport-subreport; mvn compile; mvn exec:java
</pre>
</div>
If you do all right then will get result from Picture1.<br />
<span id="fullpost"></span><br />
<h3 style="text-align: left;">
Source code:</h3>
You can download <a href="https://bitbucket.org/m_kazarian/ireport-scriptlet" target="_blank">source code from BitBucket</a>.<br />
<h3 style="text-align: left;">
Related posts:</h3>
<ul style="text-align: left;">
<li><span id="fullpost"><a href="http://mkazarian.blogspot.com/2014/08/using-javabean-datasource-for-report.html" target="_blank">Using JavaBean datasource for report and subreport in iReport</a>.</span></li>
<li><span id="fullpost"><span id="fullpost"><a href="http://mkazarian.blogspot.com/2014/09/runing-jasperreport-subreport-from-java.html" target="_blank">Runing JasperReport subreport from java code</a>. </span> </span> </li>
</ul>
<h3 style="text-align: left;">
Resources</h3>
<ul style="text-align: left;">
<li> <a href="http://www.tutorialspoint.com/jasper_reports/jasper_report_scriptlets.htm">JasperReports - Report Scriptlets</a></li>
<li><a href="http://blog.sacaluta.com/2007/07/jasperreports-scriptlet-example.html"> JasperReports Scriptlet Example</a> by Rodrigo De Castro</li>
<li><a href="http://morgb.blogspot.com/2011/06/create-java-scriptlets-for-jasper.html">Create Java Scriptlets for Jasper Reports</a></li>
</ul>
<br />
<br />
<br /></div>
Michael Kazarianhttp://www.blogger.com/profile/08626392846438054040noreply@blogger.com1tag:blogger.com,1999:blog-660391924419264317.post-34306540575450003962014-10-14T15:37:00.000+03:002014-10-14T15:51:55.161+03:00JasperReport and Maven for creating distributive<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
In previous articles we created some projects with reports which generated with JasperReport. It's time to create distributive and give it to end user. <a href="http://mkazarian.blogspot.com/2014/09/runing-jasperreport-subreport-from-java.html" target="_blank">Here</a> I told about running JasperReport reports from <span style="font-family: "Courier New",Courier,monospace;">java</span> code and used <a href="http://www.vogella.com/tutorials/ApacheMaven/article.html" target="_blank">maven</a> to compile and run it. Here I will use maven for perform next tasks:<br />
<ul>
<li>Clear unnecessary generated <span style="font-family: "Courier New",Courier,monospace;">*.jasper</span> files.</li>
<li>Create result folder with result <span style="font-family: "Courier New",Courier,monospace;">jar </span>file, report templates and all necessary dependencies, but exclude extra dependencies such as <span style="font-family: "Courier New",Courier,monospace;">junit</span>.
</li>
</ul>
<a name='more'></a><span id="fullpost">
But the first thing I advice set project encoding to utf-8. In project section of <span style="font-family: "Courier New",Courier,monospace;">pom.xml</span> write next:<br />
</span><br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span id="fullpost"><project>
...
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
...
</project>
</span></pre>
</div>
<span id="fullpost">
<br />
<h3 style="text-align: left;">
Cleaning unnecessary files.</h3>
Templates of report stored in root of <span style="font-family: "Courier New",Courier,monospace;">report</span> directory. After compilation generated <span style="font-family: "Courier New",Courier,monospace;">jasper</span> and <span style="font-family: "Courier New",Courier,monospace;">pdf</span> files puts into <b>jaspers</b> folder :<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;">├── pom.xml
├── reports
│ ├── jaspers
│ │ ├── java_beans_datasource_report.jasper
│ │ └── java_beans_datasource_report_subreport1.jasper
│ ├── java_beans_datasource_report.jrxml
│ └── java_beans_datasource_report_subreport1.jrxml
</pre>
</div>
<br />
For remove jaspers directory with all content with <span style="font-family: "Courier New",Courier,monospace;">mvn clean</span> command add next code to <span style="font-family: "Courier New",Courier,monospace;">build</span> section of <span style="font-family: "Courier New",Courier,monospace;">pom.xml</span>:<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
<configuration>
<filesets>
<fileset>
<directory>reports</directory>
<includes>
<directory>jaspers</directory>
<include>**/*.pdf</include>
<include>**/*.jasper</include>
</includes>
<excludes>
<exclude>**/*.jrxml</exclude>
</excludes>
<followSymlinks>false</followSymlinks>
</fileset>
</filesets>
</configuration>
</plugin>
</pre>
</div>
<h3 style="text-align: left;">
Set output directory.</h3>
Now, I need directory for distributibe. Let it be <span style="font-family: "Courier New",Courier,monospace;">result</span> folder in maven generated <span style="font-family: "Courier New",Courier,monospace;">target</span> directory. pom.xml contain configuration for <b>maven-jar-plugin</b>. Add to configuration section of it next code:<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><outputDirectory>${project.build.directory}/result</outputDirectory>
</pre>
</div>
<h3 style="text-align: left;">
Add <i>lib</i>* directory into <i>result</i> folder.</h3>
In <b>maven-jar-plugin</b> <span style="font-family: "Courier New",Courier,monospace;">configuration/archive/manifest</span> add next strings:<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</pre>
</div>
<br />
Now my <b>maven-jar-plugin</b> configuretion looks like below:<br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.5</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.blogspot.mkazarian.Demo</mainClass>
</manifest>
</archive>
<outputDirectory>${project.build.directory}/result</outputDirectory>
</configuration>
</plugin>
</pre>
</div>
<h3 style="text-align: left;">
Copy dependencies to <i>lib</i> folder.</h3>
In package stage you can copy necessary dependencies to <b>lib</b> folder with maven-dependency-plugin:<br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/result/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
<includeScope>runtime</includeScope>
</configuration>
</execution>
</executions>
</plugin>
</pre>
</div>
<br />
In this code below instruction <!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><includeScope>runtime</includeScope>
</pre>
</div>
allow include to <b>lib</b> folder only necessary for correct work dependencies.<br />
<h3 style="text-align: left;">
Copy reports templates to <i>reports</i> folder.</h3>
You can do it with <b>maven-resources-plugin</b>.<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/result/reports</outputDirectory>
<resources>
<resource>
<directory>reports</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</pre>
</div>
<br />
Result.<br />
After run <!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;">mvn clean package
</pre>
</div>
I obtain next result:<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;">├── ireport-experiments-1.0-SNAPSHOT.jar
├── lib
│ ├── bcmail-jdk14-1.38.jar
│ ├── bcmail-jdk14-138.jar
│ ├── bcprov-jdk14-1.38.jar
│ ├── bcprov-jdk14-138.jar
│ ├── bctsp-jdk14-1.38.jar
│ ├── castor-1.2.jar
│ ├── commons-beanutils-1.8.0.jar
│ ├── commons-collections-3.2.1.jar
│ ├── commons-digester-2.1.jar
│ ├── commons-logging-1.1.1.jar
│ ├── groovy-all-2.3.6.jar
│ ├── itext-2.1.7.js2.jar
│ ├── jackson-annotations-2.1.4.jar
│ ├── jackson-core-2.1.4.jar
│ ├── jackson-databind-2.1.4.jar
│ ├── jakarta-regexp-1.4.jar
│ ├── jasperreports-5.6.0.jar
│ ├── jcommon-1.0.15.jar
│ ├── jdtcore-3.1.0.jar
│ ├── jfreechart-1.0.12.jar
│ ├── lucene-analyzers-common-4.5.1.jar
│ ├── lucene-core-4.5.1.jar
│ ├── lucene-queries-4.5.1.jar
│ ├── lucene-queryparser-4.5.1.jar
│ ├── lucene-sandbox-4.5.1.jar
│ ├── olap4j-0.9.7.309-JS-3.jar
│ └── xml-apis-1.3.02.jar
└── reports
├── java_beans_datasource_report.jrxml
└── java_beans_datasource_report_subreport1.jrxml
</pre>
</div>
<br />
<h3 style="text-align: left;">
Source code:</h3>
You can download <a href="https://bitbucket.org/m_kazarian/ireport-subreport-mvn-dist" target="_blank">source code from BitBucket</a>.<br />
<h3 style="text-align: left;">
Related posts:</h3>
<ul style="text-align: left;">
<li><span id="fullpost"><a href="http://mkazarian.blogspot.com/2014/08/using-javabean-datasource-for-report.html" target="_blank">Using JavaBean datasource for report and subreport in iReport</a>.</span></li>
<li><span id="fullpost"><span id="fullpost"><a href="http://mkazarian.blogspot.com/2014/09/runing-jasperreport-subreport-from-java.html" target="_blank">Runing JasperReport subreport from java code</a>. </span> </span> </li>
</ul>
<h3 style="text-align: left;">
Resources</h3>
<ul style="text-align: left;">
<li><a href="http://maven.apache.org/general.html#encoding-warning" target="_blank">Using platform encoding</a></li>
<li><a href="http://maven.apache.org/plugins/maven-clean-plugin/examples/delete_additional_files.html" target="_blank">Delete Additional Files Not Exposed to Maven</a></li>
<li><a href="http://maven.apache.org/plugins/maven-jar-plugin/examples/manifest-customization.html" target="_blank">Manifest customization</a>. <a href="http://maven.apache.org/shared/maven-archiver/examples/classpath.html#aPrefix" target="_blank">Set Up The Classpath</a>.</li>
<li><a href="http://maven.apache.org/plugins/maven-resources-plugin/examples/copy-resources.html" target="_blank">Copy Resources</a></li>
</ul>
<hr width="75%" />
* - Here I repeat NetBeans output structure for compatibility with my current projects but it demonstrate way to create your own result struture . </span></div>
<br />
<ul style="text-align: left;">
</ul>
</div>
Michael Kazarianhttp://www.blogger.com/profile/08626392846438054040noreply@blogger.com0tag:blogger.com,1999:blog-660391924419264317.post-6110291274117216772014-09-29T16:45:00.001+03:002014-09-29T17:20:21.902+03:00Row counting with JasperReport<div dir="ltr" style="text-align: left;" trbidi="on">
JasperReport has simple way to count row in report. In this report I will tell about counting records from main and sub-report. I take for base report from <a href="http://mkazarian.blogspot.com/2014/08/using-javabean-datasource-for-report.html" target="_blank">"Using JavaBean datasource for report and subreport in iReport" article</a> and add necessary changes for obtain next result:<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhutSU64VxF-8DXkfwXZB2qg9EpvtokT2jbE-4UzPkKtg9vUxiRE-7clbaRddCYKZln4qK678Y0Ae0wuCY02N2Y_AKxO9Fuod82wPXF1_uTR8sDsmgo1FJTPH2-R-po0CUl6-P5EkDWmmH9/s1600/sb-numbering-result.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhutSU64VxF-8DXkfwXZB2qg9EpvtokT2jbE-4UzPkKtg9vUxiRE-7clbaRddCYKZln4qK678Y0Ae0wuCY02N2Y_AKxO9Fuod82wPXF1_uTR8sDsmgo1FJTPH2-R-po0CUl6-P5EkDWmmH9/s1600/sb-numbering-result.png" height="291" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><i>Picture 1: Line numbering result.</i></td></tr>
</tbody></table>
<a name='more'></a><span id="fullpost">
</span>
<div class="separator" style="clear: both; text-align: center;">
</div>
<span id="fullpost">
<br />
In main report (<span style="font-family: "Courier New",Courier,monospace;">java_beans_datasource_report.jrxml</span> in this example) add internal variable <span style="font-family: "Courier New",Courier,monospace;">REPORT_COUNT</span> to <span style="font-family: "Courier New",Courier,monospace;">Detail1</span> band:<br />
<br /><table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: left; margin-right: 1em; text-align: left;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEheDVuQLZAbM0oH3DuPqCYsHcduT-UQjJT-x_mMJTInZSvTXCaKP_ruZLgIBSL87DQepITBdrspY04U_sYcu5zC3sEmPG14uwDEPpSonngpIISOcKEtVw5CtpyvM4Cda_BdYt4twtMMlS15/s1600/sb-numbering0.png" imageanchor="1" style="clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEheDVuQLZAbM0oH3DuPqCYsHcduT-UQjJT-x_mMJTInZSvTXCaKP_ruZLgIBSL87DQepITBdrspY04U_sYcu5zC3sEmPG14uwDEPpSonngpIISOcKEtVw5CtpyvM4Cda_BdYt4twtMMlS15/s1600/sb-numbering0.png" height="88" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><i>Picture 2: Add REPORT_COUNT variavle to master report.</i></td></tr>
</tbody></table>
Repeat this one for subreport (<span style="font-family: "Courier New",Courier,monospace;">java_beans_datasource_report_subreport1.jrxml</span>).<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjSyUxJmMSzVhtI1zR5jKN0cxNObzNy6rfEGjtEP5QIE1WEsSpj-f95r23rSZVspkrhJNUjBD56_q7mvC4s66i5jC4w_inYhyphenhyphenwmh4PQX-wCWkB_goUiXyT0zTWQuBt3Wam_kcvNfmtqPXnV/s1600/sb-numbering1.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjSyUxJmMSzVhtI1zR5jKN0cxNObzNy6rfEGjtEP5QIE1WEsSpj-f95r23rSZVspkrhJNUjBD56_q7mvC4s66i5jC4w_inYhyphenhyphenwmh4PQX-wCWkB_goUiXyT0zTWQuBt3Wam_kcvNfmtqPXnV/s1600/sb-numbering1.png" height="171" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><i>Picture 3: Numbering row in subreport.</i></td></tr>
</tbody></table>
After compile and preview it you must see numbering record in master and subreport. <br />
<br />
For obtain total records count from main report and subreport we must add two variables <span style="font-family: "Courier New",Courier,monospace;">masterRecordCounter</span> and <span style="font-family: "Courier New",Courier,monospace;">detailRecordCounter</span>. Set next parameters for its:<br />
<ul style="text-align: left;">
<li><span style="font-family: "Courier New",Courier,monospace;">masterRecordCounter</span> - <b>Variable Class:</b> <span style="font-family: "Courier New",Courier,monospace;">java.lang.Integer</span>; <b>Calculation</b>: <span style="font-family: "Courier New",Courier,monospace;">Count</span>; <b>Reset type:</b> <span style="font-family: "Courier New",Courier,monospace;">Report</span>; <b>Increment type:</b> <span style="font-family: "Courier New",Courier,monospace;">None</span>; <b>Variable Expression:</b> <span style="font-family: "Courier New",Courier,monospace;">$V{REPORT_COUNT}</span></li>
<li><span style="font-family: "Courier New",Courier,monospace;">detailRecordCounter</span> - <b>Variable Class:</b> <span style="font-family: "Courier New",Courier,monospace;">java.lang.Integer</span>; <b>Calculation</b>: <span style="font-family: "Courier New",Courier,monospace;">Count</span>; <b>Reset type:</b> <span style="font-family: "Courier New",Courier,monospace;">Report</span>; <b>Increment type:</b> <span style="font-family: "Courier New",Courier,monospace;">None</span></li>
</ul>
Now <span style="font-family: "Courier New",Courier,monospace;">REPORT_COUNT </span>of master report accumulating in <span style="font-family: "Courier New",Courier,monospace;">masterRecordCounter</span> but for <span style="font-family: "Courier New",Courier,monospace;">detailRecordCounter</span> we can bind it with <span style="font-family: "Courier New",Courier,monospace;">REPORT_COUNT</span> from subreport. For it select <b>Subreport</b> component and change <b>Return values</b> parameter to this maner:<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVEfB1SX8WJynfeFaaAUIf4PFqGKVgJkMAAwYHu583_7QPrBura-LwZFPr_VT53oBQ5n9Djo9fwSMZ1Wi9WxG7ss9pcSqiR2OZm_9J_oMJ5HOJnMEn0c_TjR1bo_7elhRvKQFrgGtzrk1g/s1600/sb-numbering5.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVEfB1SX8WJynfeFaaAUIf4PFqGKVgJkMAAwYHu583_7QPrBura-LwZFPr_VT53oBQ5n9Djo9fwSMZ1Wi9WxG7ss9pcSqiR2OZm_9J_oMJ5HOJnMEn0c_TjR1bo_7elhRvKQFrgGtzrk1g/s1600/sb-numbering5.png" height="272" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><i>Picture 4: Binding subreport variables.</i></td></tr>
</tbody></table>
Enable <b>Summary</b> band and add to it <span style="font-family: "Courier New",Courier,monospace;">masterRecordCounter and </span><span style="font-family: "Courier New",Courier,monospace;">detailRecordCounter</span> as shown on <b>Picture 2</b>, compile and enjoy of result.<br />
<br />
<h3 style="text-align: left;">
Related posts:</h3>
<span id="fullpost"></span><br />
<div style="text-align: left;">
<a href="http://mkazarian.blogspot.com/2014/08/using-javabean-datasource-for-report.html" target="_blank">Using JavaBean datasource for report and subreport in iReport</a>.</div>
<div style="text-align: left;">
<a href="http://mkazarian.blogspot.com/2014/09/runing-jasperreport-subreport-from-java.html" target="_blank">Runing JasperReport subreport from java code</a>. </div>
<br />
<h3>
<span id="fullpost"><div style="text-align: left;">
Downloads:</div>
</span></h3>
<span id="fullpost"></span><br />
<div style="text-align: left;">
You can download sources with samples <a href="https://bitbucket.org/m_kazarian/ireport-subreport-line-counting" target="_blank">from BitBucket</a>.</div>
</span></div>
Michael Kazarianhttp://www.blogger.com/profile/08626392846438054040noreply@blogger.com0tag:blogger.com,1999:blog-660391924419264317.post-29645110805516497852014-09-15T15:58:00.001+03:002014-09-29T17:20:21.900+03:00Correct way to wrap text in iReport<div dir="ltr" style="text-align: left;" trbidi="on">
Default behaviour of JasperReport with long string is cut by accord to element length. You can change this behaviour by set <b>"Stretch With Overflow"</b> to <span style="font-family: "Courier New",Courier,monospace;">True</span>.<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFSsHU3Vyq7yjrqhJNg6tslvQZ6p2wPNkkYVYJfzsyqWrqi4z6Tv2DPcmJ2zjX7CISuDkOXaCjAvL91sq9Rg6QD-K5G8iC4dKII5TGWLeArxnV9Uswu7VHVFFo5i8I7AzVvYK78JO-O-In/s1600/set-stretch-with-owerflow.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFSsHU3Vyq7yjrqhJNg6tslvQZ6p2wPNkkYVYJfzsyqWrqi4z6Tv2DPcmJ2zjX7CISuDkOXaCjAvL91sq9Rg6QD-K5G8iC4dKII5TGWLeArxnV9Uswu7VHVFFo5i8I7AzVvYK78JO-O-In/s1600/set-stretch-with-owerflow.png" height="50" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><i>Picture 1: Set property for wrap long string.</i></td></tr>
</tbody></table>
<br />
This solution will bring to ugly result: wrapped element will excel among all <span class="gt-card-ttl-txt" style="direction: ltr;">neighboring elements</span>:<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEib1iY0cZmq_iYHgoy2scWiY7bffk7Fje3XHCLVwOHJevkhSc7V1-Ob67ZWii9JI9AU7syrJR03SeGrjFeFHiPsUpi9Cq9jh2GE9DxDGAVQ7TyKntl5E_6LYFeYTcVFZRcmi9Vi06YQHUgC/s1600/stretch-with-owerflow-bug.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEib1iY0cZmq_iYHgoy2scWiY7bffk7Fje3XHCLVwOHJevkhSc7V1-Ob67ZWii9JI9AU7syrJR03SeGrjFeFHiPsUpi9Cq9jh2GE9DxDGAVQ7TyKntl5E_6LYFeYTcVFZRcmi9Vi06YQHUgC/s1600/stretch-with-owerflow-bug.png" height="90" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><i>Picture 2: Not suitable wrap.</i></td></tr>
</tbody></table>
If such behaviour is not suitable you can fix it in simple way.<a name='more'></a><span id="fullpost">For all element in row you must set "Stretch Type" to "Relative to Tallest Object"<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOjQcdH4TFkJ0IEDA-pvHxNMeUZ8VkLsPH_DBmoqL4fGrJA1eNj9U2VxwPg6IRKLzLJPSVbuazMkWHQF1ttAybrDRw-VcSxL4JlYuiFU3POgulnjgMRmD2yNmKimCUWJvadQa4n768f6IE/s1600/fix.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOjQcdH4TFkJ0IEDA-pvHxNMeUZ8VkLsPH_DBmoqL4fGrJA1eNj9U2VxwPg6IRKLzLJPSVbuazMkWHQF1ttAybrDRw-VcSxL4JlYuiFU3POgulnjgMRmD2yNmKimCUWJvadQa4n768f6IE/s1600/fix.png" height="98" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><i>Picture 3: Fixing.</i></td></tr>
</tbody></table>
Now height of other elements will accord to wrapped string.<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4BiGohhMpPUY_D8xr3Ysujee4GIoAQaQQqDRa-6VnCp0aRyzYQok7iQFEvhv8kLJzNQHNZvzmg2Y3VIoorNXyz1DmxlUkgTS9gFixp5c4HSHdl2er-PRtNNw4Qx78MUcVXwoNHcMcgiMu/s1600/result.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4BiGohhMpPUY_D8xr3Ysujee4GIoAQaQQqDRa-6VnCp0aRyzYQok7iQFEvhv8kLJzNQHNZvzmg2Y3VIoorNXyz1DmxlUkgTS9gFixp5c4HSHdl2er-PRtNNw4Qx78MUcVXwoNHcMcgiMu/s1600/result.png" height="328" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><i>Picture 4: Required result.</i></td></tr>
</tbody></table>
<h3 style="text-align: left;">
Related posts:</h3>
<div style="text-align: left;">
<a href="http://mkazarian.blogspot.com/2014/08/using-javabean-datasource-for-report.html" target="_blank">Using JavaBean datasource for report and subreport in iReport</a>.</div>
<div style="text-align: left;">
<a href="http://mkazarian.blogspot.com/2014/09/runing-jasperreport-subreport-from-java.html" target="_blank">Runing JasperReport subreport from java code</a>. </div>
<h3 style="text-align: left;">
Credits:</h3>
Ankur Gupta for <a href="http://community.jaspersoft.com/questions/815800/wrap-text-report-ireport-designer-510" target="_blank">suggest</a>.</span></div>
Michael Kazarianhttp://www.blogger.com/profile/08626392846438054040noreply@blogger.com0tag:blogger.com,1999:blog-660391924419264317.post-11834591224567075352014-09-12T12:12:00.001+03:002014-09-29T17:20:21.898+03:00Summarize from subreports in JasperReport<div dir="ltr" style="text-align: left;" trbidi="on">
<div>
One from typically reporting tasks is calculate aggregate operations: summarize, counting, averaging. JasperReport allow run this operation. But if you work with subreports you can meet with <a href="http://community.jaspersoft.com/questions/518955/sum-incorrect-not-adding-last-subreport-value" target="_blank">strange behavior</a>. Below I will tell about one aggregate operations - calculating sums and pay attention upon not evident moments.<br />
<br />
Main principle of summarizing is passing sum value from subreport to main report and accumulate it in accord value on main report. We can modify sample from <a href="http://mkazarian.blogspot.com/2014/08/using-javabean-datasource-for-report.html" target="_blank">previous article</a> for get such result:<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgT9TcV88RaGW1M6o0I1w84DuC7sR6hm1f550jZu5HJjl4AMGBBHq9qB3jPz73GcN855w8PxKQqGyG5QqLDstmYSvYvwBtirmlVfwjffI_QthgH6YzmT4xCROsIKJ0APzRxjSrRdemMtvF2/s1600/report-result.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgT9TcV88RaGW1M6o0I1w84DuC7sR6hm1f550jZu5HJjl4AMGBBHq9qB3jPz73GcN855w8PxKQqGyG5QqLDstmYSvYvwBtirmlVfwjffI_QthgH6YzmT4xCROsIKJ0APzRxjSrRdemMtvF2/s1600/report-result.png" height="304" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><i>Picture1: Report with sums.</i></td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: center;">
</div>
<a name='more'></a><span id="fullpost">
<br />
</span><br />
<h3 style="text-align: left;">
<span id="fullpost">
Modify subreport.</span></h3>
<span id="fullpost">
Open<span style="font-family: "Courier New",Courier,monospace;"> java_beans_datasource_report_subreport1.jrxml</span> with iReport. In <span style="font-family: "Courier New",Courier,monospace;">Variables</span> branch add values with such parameters:<br />
<ul style="text-align: left;">
<li><b>Name</b>: <span style="font-family: "Courier New",Courier,monospace;">Sum</span>; <b>Variable class</b>: <span style="font-family: "Courier New",Courier,monospace;">java.lang.Double</span> ;<b> Calculation: </b><span style="font-family: "Courier New",Courier,monospace;">Nothing</span><b> ; Variable Expression:</b> <span style="font-family: "Courier New",Courier,monospace;">$F{price}*$F{quantity} ; <i>Tis variable for calculating sum of position</i>.</span></li>
<li><b>Name</b>: sumAllQ; <b>Variable class</b>: <span style="font-family: "Courier New",Courier,monospace;">java.lang.Integer</span> ; <b> <span style="color: red;">Calculation: </span></b><span style="color: red;"><span style="font-family: "Courier New",Courier,monospace;">Sum</span></span><b> ;</b><b> Variable Expression:</b> <span style="font-family: "Courier New",Courier,monospace;">$F{quantity} ; </span><span style="font-family: "Courier New",Courier,monospace;"><i>This variable for accumulate sum of quantiy</i>.</span></li>
<li><b>Name</b>: sumAllS; <b>Variable class</b>: <span style="font-family: "Courier New",Courier,monospace;">java.lang.</span><span style="font-family: "Courier New",Courier,monospace;">Double</span> ; <b> <span style="color: red;">Calculation: </span></b><span style="color: red;"><span style="font-family: "Courier New",Courier,monospace;">Sum</span></span><b> ;</b><b> Variable Expression:</b> <span style="font-family: "Courier New",Courier,monospace;">$V{Sum} ; </span><span style="font-family: "Courier New",Courier,monospace;"><i>This variable for accumulate sum of Sum variable</i>.</span></li>
<li><span style="font-family: "Courier New",Courier,monospace;"><b>Name</b>: <span style="font-family: "Courier New",Courier,monospace;">vFormattedSumAllS</span>; <b>Variable class</b>: <span style="font-family: "Courier New",Courier,monospace;">java.lang.String</span> ;<b> Calculation: </b><span style="font-family: "Courier New",Courier,monospace;">Nothing</span><b> ; Variable Expression:</b> </span><!-- HTML generated using hilite.me --><div style="background: none repeat scroll 0% 0% rgb(255, 255, 255); border: medium solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0px;"><span style="color: blue;">new</span> java.text.DecimalFormat(<span style="color: #a31515;">"#,##0.00"</span>).format($V{sumAllS}.doubleValue())
</pre>
</div>
<span style="font-family: "Courier New",Courier,monospace;"><i>This variable for setting double variable pretty view.</i></span></li>
</ul>
</span></div>
<div>
<ul style="text-align: left;">
</ul>
</div>
Next modify subreport design as below:<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgs4LPT0-YJYkuhRNuyw4BKCQiVkbu1nSw33Yw8noH0Y4aFFTHXv_fmauL83iAfQ7P3GCMa2Zoodfs2aw8kOAe2NCzdXwam2qebhyphenhyphenmpNyTmlveJ5BzXMK5vpSgW-482gHFnrQwrN41kXc5s/s1600/subreport+design.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgs4LPT0-YJYkuhRNuyw4BKCQiVkbu1nSw33Yw8noH0Y4aFFTHXv_fmauL83iAfQ7P3GCMa2Zoodfs2aw8kOAe2NCzdXwam2qebhyphenhyphenmpNyTmlveJ5BzXMK5vpSgW-482gHFnrQwrN41kXc5s/s1600/subreport+design.png" height="178" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><i>Picture 2: Add variables to subreport.</i></td></tr>
</tbody></table>
<br />
After compile report and we must<br />
<h3 style="text-align: left;">
Modify main report</h3>
Open java_beans_datasource_report.jrxml and add next variables:<br />
<ul>
<li><b>Name</b>: <span style="font-family: "Courier New",Courier,monospace;">totalSumQ</span>; <b>Variable class</b>: <span style="font-family: "Courier New",Courier,monospace;">java.lang.Integer</span> ; <b> <span style="color: red;">Calculation: </span></b><span style="color: red;"><span style="font-family: "Courier New",Courier,monospace;">Sum</span></span><b> ;</b><b> </b><span style="font-family: "Courier New",Courier,monospace;"> </span><span style="font-family: "Courier New",Courier,monospace;"><i>This variable for accumulate quantity</i> from subreport. Note: </span><b>Variable Expression </b>is empty.</li>
<li><b>Name</b>: <span style="font-family: "Courier New",Courier,monospace;">totalSumS</span>; <b>Variable class</b>: <span style="font-family: "Courier New",Courier,monospace;">java.lang.</span><span style="font-family: "Courier New",Courier,monospace;">Double</span> ; <b> <span style="color: red;">Calculation: </span></b><span style="color: red;"><span style="font-family: "Courier New",Courier,monospace;">Sum</span></span><b> </b><span style="font-family: "Courier New",Courier,monospace;">; </span><span style="font-family: "Courier New",Courier,monospace;"><i>This variable for accumulate sum from subreport. </i></span><br /><span style="font-family: "Courier New",Courier,monospace;">Note: </span><b>Variable Expression </b>is empty.</li>
<li><span style="font-family: "Courier New",Courier,monospace;"><b>Name</b>: formattedTotalSumS; <b>Variable class</b>: <span style="font-family: "Courier New",Courier,monospace;">java.lang.String</span> ;<b> Calculation: </b><span style="font-family: "Courier New",Courier,monospace;">Nothing</span><b> ; Variable Expression<i>:</i></b></span><span style="font-family: "Courier New",Courier,monospace;"><!-- HTML generated using hilite.me --><div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: blue;">new</span> java.text.DecimalFormat(<span style="color: #a31515;">"#,##0.00"</span>).format($V{totalSumS}.doubleValue())
</pre>
</div>
<i>This variable for setting double variable pretty view.</i></span></li>
</ul>
Now we can setup variables exchange between subreport and main report. Select <span style="font-family: "Courier New",Courier,monospace;">Subreport</span> component and go to <span style="font-family: "Courier New",Courier,monospace;">Properties</span>. Find <span style="font-family: "Courier New",Courier,monospace;">Return Values</span> and press button. In appropriate dialog press <span style="font-family: "Courier New",Courier,monospace;">Add</span> button. Set<br />
<ul style="text-align: left;">
<li> Set the <span style="font-family: "Courier New",Courier,monospace;">Subreport variable</span> to <span style="font-family: "Courier New",Courier,monospace;">sumAllQ</span> and the <span style="font-family: "Courier New",Courier,monospace;">Local destination variable </span>to <span style="font-family: "Courier New",Courier,monospace;">totalSumQ</span>. Also set <span style="font-family: "Courier New",Courier,monospace;">Calculation type</span> to <span style="font-family: "Courier New",Courier,monospace;">Sum</span>.</li>
<li>Set the <span style="font-family: "Courier New",Courier,monospace;">Subreport variable</span> to <span style="font-family: "Courier New",Courier,monospace;">sumAllS</span> and the <span style="font-family: "Courier New",Courier,monospace;">Local destination variable </span>to <span style="font-family: "Courier New",Courier,monospace;">totalSumS</span>. Also set <span style="font-family: "Courier New",Courier,monospace;">Calculation type</span> to <span style="font-family: "Courier New",Courier,monospace;">Sum</span>.</li>
</ul>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJupT2YssWk3-ynAKk2ToFQUYtN3SQu2DWRR-S7i4NWAohSDchvENdZYo_Nekrdge5iTndD68yKY0pDaq8VnE5A9og1ohmjtFZQuWKJnqg492uvOLMF5fyF8upMjsTo5Fzxzc7FmLZLlfu/s1600/Add-modify+variable.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJupT2YssWk3-ynAKk2ToFQUYtN3SQu2DWRR-S7i4NWAohSDchvENdZYo_Nekrdge5iTndD68yKY0pDaq8VnE5A9og1ohmjtFZQuWKJnqg492uvOLMF5fyF8upMjsTo5Fzxzc7FmLZLlfu/s1600/Add-modify+variable.png" height="272" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><i>Picture 3: Setup variables exchange.</i></td></tr>
</tbody></table>
<br />
<b>Important</b>: Properties <span style="font-family: "Courier New",Courier,monospace;">Calculation</span> of <span style="font-family: "Courier New",Courier,monospace;">totalSumQ</span>, <span style="font-family: "Courier New",Courier,monospace;">totalSumS</span> and <span style="font-family: "Courier New",Courier,monospace;">Subreport variable</span> of Subreport ReturnValues must be <span style="font-family: "Courier New",Courier,monospace;">Sum</span>.<br />
<br />
Enable Summary band and add <span style="font-family: "Courier New",Courier,monospace;">totalSumQ</span> and <span style="font-family: "Courier New",Courier,monospace;">formattedTotalSumS</span> vatiables.<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEisjqiGyNgnP6yLXX1Pt_11t6wS5gwzsQOkfBDBqoX9ialLq4b386jL3ZSAZBpGAM50ItglVtkshJu9FUCquFM21vlG4b-jOOBPuObhl8ERgSGtZzlQkUjMuOzrjmyW9FFEBPdCclZWmPaH/s1600/summarize-mainreport-design.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEisjqiGyNgnP6yLXX1Pt_11t6wS5gwzsQOkfBDBqoX9ialLq4b386jL3ZSAZBpGAM50ItglVtkshJu9FUCquFM21vlG4b-jOOBPuObhl8ERgSGtZzlQkUjMuOzrjmyW9FFEBPdCclZWmPaH/s1600/summarize-mainreport-design.png" height="138" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><i>Picture 4: Add variables to Summary band.</i></td></tr>
</tbody></table>
<br />
Now, after press Preview button you can see result from Picture1.<br />
<br />
<h3 style="text-align: left;">
Downloads:</h3>
You can download <a href="https://bitbucket.org/m_kazarian/ireport-subreport-sums" target="_blank">source code from BitBucket</a>.<br />
<h3 style="text-align: left;">
Related posts:</h3>
<div style="text-align: left;">
<a href="http://mkazarian.blogspot.com/2014/08/using-javabean-datasource-for-report.html" target="_blank">Using JavaBean datasource for report and subreport in iReport</a>.</div>
<div style="text-align: left;">
<a href="http://mkazarian.blogspot.com/2014/09/runing-jasperreport-subreport-from-java.html" target="_blank">Runing JasperReport subreport from java code</a>. </div>
<h3 style="text-align: left;">
Credits:</h3>
<a href="http://rajendratambat.blogspot.com/2010/10/creating-jasper-sub-report-using.html" target="_blank">Creating jasper sub-report using iReport</a> by Rajendra M. Tambat. <br />
<ul>
</ul>
</div>
Michael Kazarianhttp://www.blogger.com/profile/08626392846438054040noreply@blogger.com1tag:blogger.com,1999:blog-660391924419264317.post-82448262317023358172014-09-08T16:19:00.000+03:002014-10-14T15:54:34.614+03:00Runing JasperReport subreport from java code<div dir="ltr" style="text-align: left;" trbidi="on">
In <a href="http://mkazarian.blogspot.com/2014/08/using-javabean-datasource-for-report.html" target="_blank">previous post </a>I created JasperReport report with subreport and runned it from through iReport. But, I think, more interesting is way to run it from java code.<br />
<a name='more'></a><span id="fullpost">
<br />
</span><br />
<h3 style="text-align: left;">
<span id="fullpost">
Preparing to work.</span></h3>
<span id="fullpost">
Because JasperReport has lot of dependencies I use maven for<br />
satisfy it and for building runnable jar. If you never used maven then can read <a href="http://www.vogella.com/tutorials/ApacheMaven/article.html" target="_blank">this short and easy tutorial</a>. If you not worry about dependencies and build tools you can skip prepare part and go to main part. Otherwise, you can create initial maven project with next command:<br />
<!-- HTML generated using hilite.me --><br />
</span><br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span id="fullpost">mvn archetype:create -DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=com.blogspot.mkazarian -DartifactId=ireport-experiments
</span></pre>
</div>
<span id="fullpost">
Result of command will creating new file objects:<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;">.
└── ireport-experiments
├── pom.xml
└── src
├── main
│ └── java
│ └── com
│ └── blogspot
│ └── mkazarian
│ └── App.java
└── test
└── java
└── com
└── blogspot
└── mkazarian
└── AppTest.java
12 directories, 3 files
</pre>
</div>
Rename <span style="font-family: "Courier New",Courier,monospace;">App.java</span> to <span style="font-family: "Courier New",Courier,monospace;">Demo.java</span> and <span style="font-family: "Courier New",Courier,monospace;">AppTest.java</span> to <span style="font-family: "Courier New",Courier,monospace;">DemoTest.java</span> and change <span style="font-family: "Courier New",Courier,monospace;">pom.xml</span> as bellow:<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><project xmlns=<span style="color: #a31515;">"http://maven.apache.org/POM/4.0.0"</span> xmlns:xsi=<span style="color: #a31515;">"http://www.w3.org/2001/XMLSchema-instance"</span>
xsi:schemaLocation=<span style="color: #a31515;">"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"</span>>
<modelVersion>4.0.0</modelVersion>
<groupId>com.blogspot.mkazarian</groupId>
<artifactId>ireport-experiments</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>ireport-experiments</name>
<url>http://maven.apache.org</url>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.5</version>
<configuration>
<archive>
<manifest>
<mainClass>com.blogspot.mkazarian.Demo</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<mainClass>com.blogspot.mkazarian.Demo</mainClass>
<executable>java</executable>
<arguments>
<argument>-a</argument>
<argument>${argumentA}</argument>
<argument>-b</argument>
<argument>${argumentB}</argument>
</arguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
<configuration>
<filesets>
<fileset>
<directory>reports</directory>
<includes>
<directory>jaspers</directory>
<include>**/*.pdf</include>
<include>**/*.jasper</include>
</includes>
<excludes>
<exclude>**/*.jrxml</exclude>
</excludes>
<followSymlinks>false</followSymlinks>
</fileset>
</filesets>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>5.6.0</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.3.6</version>
</dependency>
</dependencies>
</project>
</pre>
</div>
Execute <span style="font-family: "Courier New",Courier,monospace;">mvn compile</span> command and <span style="font-family: "Courier New",Courier,monospace;">mvn exec:java</span> for test.<br />
<br />
<h3 style="text-align: left;">
Running reports from java.</h3>
Add <span style="font-family: "Courier New",Courier,monospace;">OrderBean.java</span>, <span style="font-family: "Courier New",Courier,monospace;">OrderDetailBean.java</span> and <span style="font-family: "Courier New",Courier,monospace;">OrderFactory.java</span> from this article beside <span style="font-family: "Courier New",Courier,monospace;">Demo.java</span>. Create <span style="font-family: "Courier New",Courier,monospace;">reports</span> directory with <span style="font-family: "Courier New",Courier,monospace;">java_beans_datasource_report.jrxml</span> and <span style="font-family: "Courier New",Courier,monospace;">java_beans_datasource_report_subreport1.jrxml</span> . In result must view similat this:<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;">.
├── pom.xml
├── reports
│ ├── java_beans_datasource_report.jrxml
│ └── java_beans_datasource_report_subreport1.jrxml
└── src
├── main
│ └── java
│ └── com
│ └── blogspot
│ └── mkazarian
│ ├── Demo.java
│ ├── OrderBean.java
│ ├── OrderDetailBean.java
│ └── OrderFactory.java
└── test
└── java
</pre>
</div>
<br />
Ok, now we can write our code. Change <span style="font-family: "Courier New",Courier,monospace;">Demo.java</span>:<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: blue;">package</span> com.blogspot.mkazarian;
<span style="color: green;">/**</span>
<span style="color: green;"> * Subreporting demo. It compile jrxml to jasper-files and pass it to</span>
<span style="color: green;"> * generate report.</span>
<span style="color: green;"> */</span>
<span style="color: blue;">import</span> java.io.File;
<span style="color: blue;">import</span> java.io.FileInputStream;
<span style="color: blue;">import</span> java.util.HashMap;
<span style="color: blue;">import</span> java.util.List;
<span style="color: blue;">import</span> net.sf.jasperreports.engine.JRException;
<span style="color: blue;">import</span> net.sf.jasperreports.engine.JasperCompileManager;
<span style="color: blue;">import</span> net.sf.jasperreports.engine.JasperFillManager;
<span style="color: blue;">import</span> net.sf.jasperreports.engine.JasperPrint;
<span style="color: blue;">import</span> net.sf.jasperreports.engine.JasperReport;
<span style="color: blue;">import</span> net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
<span style="color: blue;">import</span> net.sf.jasperreports.view.JasperViewer;
<span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">Demo</span>
{
<span style="color: blue;">public</span> <span style="color: blue;">static</span> JasperPrint jasperPrint;
<span style="color: blue;">public</span> <span style="color: blue;">static</span> JasperReport mainReport;
<span style="color: blue;">final</span> <span style="color: blue;">static</span> String reportsDirName = System.getProperty(<span style="color: #a31515;">"user.dir"</span>)+<span style="color: #a31515;">"/reports"</span>;
<span style="color: blue;">final</span> <span style="color: blue;">static</span> String jasperDirName = <span style="color: #a31515;">"/jaspers"</span>;
<span style="color: blue;">final</span> <span style="color: blue;">static</span> String [] jrxmlFiles = {<span style="color: #a31515;">"java_beans_datasource_report"</span>,
<span style="color: #a31515;">"java_beans_datasource_report_subreport1"</span>};
<span style="color: blue;">public</span> <span style="color: blue;">static</span> String getJasperDir(String jrxmldir){
<span style="color: green;">/**</span>
<span style="color: green;"> * Retutn directory for compiled report. Normally it jaspers directory</span>
<span style="color: green;"> * into reports directory. If jasper directoty missing it will create.</span>
<span style="color: green;"> */</span>
String result = System.getProperty(<span style="color: #a31515;">"user.home"</span>);
File jrxmlDir = <span style="color: blue;">new</span> File(jrxmldir);
File jasperDir = <span style="color: blue;">new</span> File(jrxmldir + jasperDirName);
<span style="color: blue;">if</span> (jrxmlDir.exists() && jrxmlDir.isDirectory()){
<span style="color: #2b91af;">boolean</span> cdres = <span style="color: blue;">true</span>;
<span style="color: blue;">if</span> (!jasperDir.exists()) {
cdres = <span style="color: blue;">false</span>;
<span style="color: blue;">try</span> {
jasperDir.mkdir();
cdres = <span style="color: blue;">true</span>;
} <span style="color: blue;">catch</span>(SecurityException se){}
}
<span style="color: blue;">if</span> (cdres) result = jrxmldir + jasperDirName;
}
<span style="color: blue;">return</span> result;
}
<span style="color: blue;">public</span> <span style="color: blue;">static</span> <span style="color: #2b91af;">boolean</span> compileJRXML(){
<span style="color: green;">/**</span>
<span style="color: green;"> * Compile all jrxml from reports to jasper and pur it to getJasperDir result.</span>
<span style="color: green;"> */</span>
<span style="color: #2b91af;">boolean</span> result = <span style="color: blue;">false</span>;
String jdn = getJasperDir(reportsDirName);
String s, o;
File outf;
<span style="color: blue;">try</span>{
<span style="color: blue;">for</span> (String rep: jrxmlFiles){
s = reportsDirName+<span style="color: #a31515;">"/"</span>+rep+<span style="color: #a31515;">".jrxml"</span>;
o = jdn+<span style="color: #a31515;">"/"</span>+rep+<span style="color: #a31515;">".jasper"</span>;
JasperCompileManager.compileReportToFile(s, o);
outf = <span style="color: blue;">new</span> File(o);
<span style="color: blue;">if</span> (!outf.exists()) <span style="color: blue;">return</span> <span style="color: blue;">false</span>;
}
} <span style="color: blue;">catch</span> (JRException e) {<span style="color: blue;">return</span> <span style="color: blue;">false</span>;}
result = <span style="color: blue;">true</span>;
<span style="color: blue;">return</span> result;
}
<span style="color: blue;">public</span> <span style="color: blue;">static</span> <span style="color: #2b91af;">void</span> main( String[] args ){
<span style="color: blue;">try</span>{
<span style="color: green;">//Parameters for pass to report</span>
HashMap<String,Object> parameters = <span style="color: blue;">new</span> HashMap<String,Object>();
<span style="color: green;">//Organize datasource</span>
OrderFactory of = <span style="color: blue;">new</span> OrderFactory();
List<OrderBean> dataSource = of.create();
JRBeanCollectionDataSource beanDataSource = <span style="color: blue;">new</span> JRBeanCollectionDataSource(dataSource);
<span style="color: green;">//Compile jrxml to jasper-files.</span>
FileInputStream mainReportFile = <span style="color: blue;">null</span>;
<span style="color: blue;">if</span> (compileJRXML()){
<span style="color: green;">//If you haven't plans to compile jrxml scip this call. Alternate</span>
<span style="color: green;">//way to create a mainReportFile</span>
<span style="color: green;">//import net.sf.jasperreports.engine.design.JasperDesign mainDesign = JRXmlLoader.load("/path/to/jrxml");</span>
<span style="color: green;">//JasperReport mainReportFile = JasperCompileManager.compileReport(mainDesign);</span>
<span style="color: blue;">try</span>{
String s = getJasperDir(reportsDirName)+<span style="color: #a31515;">"/"</span>+jrxmlFiles[0]+<span style="color: #a31515;">".jasper"</span>;
mainReportFile = <span style="color: blue;">new</span> FileInputStream(s);
<span style="color: green;">//pass directory with jasper-files as parameters</span>
parameters.put(<span style="color: #a31515;">"SUBREPORT_DIR"</span>, getJasperDir(reportsDirName)+<span style="color: #a31515;">"/"</span>);
<span style="color: green;">//Fill report and view report.</span>
jasperPrint = JasperFillManager.fillReport(mainReportFile, parameters, beanDataSource);
JasperViewer.viewReport(jasperPrint);
} <span style="color: blue;">catch</span> (Exception fise){fise.printStackTrace();}
<span style="color: blue;">finally</span> {
<span style="color: blue;">if</span> (mainReportFile != <span style="color: blue;">null</span>) mainReportFile.close();
}
}
} <span style="color: blue;">catch</span> (Exception e) {
e.printStackTrace();
}
}
} </pre>
</div>
Go to root directory and compile project with <span style="font-family: "Courier New",Courier,monospace;">mvn compile</span> and run it with <span style="font-family: "Courier New",Courier,monospace;">mvn exec:java</span> commands.<br />
<br />
<h3 style="text-align: left;">
Related posts:</h3>
<a href="http://mkazarian.blogspot.com/2014/08/using-javabean-datasource-for-report.html">Using JavaBean datasource for report and subreport in iReport</a></span><br />
<span id="fullpost"><a href="http://mkazarian.blogspot.com/2014/10/jasperreport-and-maven-for-creating.html" target="_blank">JasperReport and Maven for creating distributive</a><br />
</span><br />
<h3 style="text-align: left;">
<span id="fullpost">
Downloads:</span></h3>
<span id="fullpost">
Source code (java and jrxms) <a href="https://bitbucket.org/m_kazarian/ireport-subreport" target="_blank">on BitBucket</a>.</span><br />
</div>
Michael Kazarianhttp://www.blogger.com/profile/08626392846438054040noreply@blogger.com2tag:blogger.com,1999:blog-660391924419264317.post-76384242165864152982014-08-06T16:06:00.004+03:002014-10-14T15:57:26.091+03:00Using JavaBean datasource for report and subreport in iReport<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div>
<div style="text-align: left;">
Usually I prefer use pure SQL as datasource for various database-related tasks, e.g. reporting. But for some tasks is better way to use JavaBean as datasource model. Below I will write sample such datasource and reveal how use it for obtain such result.</div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSsW8V6aRWSecjLCl4PIfiBwkZoAhuGcG5KjS1C3C1s_uCdTAYqQyy1xDFZwy2U5HIgmnHb_P1MJygCWryp1sHztyA1gOuxsa9Rjz_cgdzCCDR4KbvvThG1-D-YYOWEng5TKUv_idI1ytN/s1600/final-report.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSsW8V6aRWSecjLCl4PIfiBwkZoAhuGcG5KjS1C3C1s_uCdTAYqQyy1xDFZwy2U5HIgmnHb_P1MJygCWryp1sHztyA1gOuxsa9Rjz_cgdzCCDR4KbvvThG1-D-YYOWEng5TKUv_idI1ytN/s1600/final-report.png" height="331" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><i>Picture 1: Report, based on JavaBean datasource.</i></td></tr>
</tbody></table>
<a name='more'></a><span id="fullpost">
</span>
<h3 style="text-align: left;">
<span id="fullpost">
Create JavaBean datasource.</span></h3>
<span id="fullpost">
<div style="text-align: left;">
</div>
<div style="text-align: left;">
Below we will simulate master and detail tables. For master table we will use model of order documents; for detail table we will use model of records, related with master. And, at last, we will incorporate these models in factory which return data for iReport.</div>
<div style="text-align: left;">
<!-- HTML generated using hilite.me --><br /></div>
<div style="background: none repeat scroll 0% 0% rgb(255, 255, 255); border: medium solid gray; overflow: auto; padding: 0.2em 0.6em; text-align: left; width: auto;">
<pre style="line-height: 125%; margin: 0px;"><span style="color: green;">/**</span>
<span style="color: green;"> * OrderBean.java. Created Tuesday, August 5 2014</span>
<span style="color: green;"> * @author Michael Kazarian</span>
<span style="color: green;"> * Tags:</span>
<span style="color: green;"> */</span>
<span style="color: blue;">package</span> com.blogspot.mkazarian;
<span style="color: blue;">import</span> java.util.Date;
<span style="color: blue;">import</span> java.util.List;
<span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">OrderBean</span>{
<span style="color: green;">/**</span>
<span style="color: green;"> *This class describes master records.</span>
<span style="color: green;"> */</span>
<span style="color: blue;">private</span> String nDoc; <span style="color: green;">//Document number</span>
<span style="color: blue;">private</span> Date date; <span style="color: green;">//Document date</span>
<span style="color: blue;">private</span> List<OrderDetailBean> orderDetails;
<span style="color: blue;">public</span> Date getDate() {
<span style="color: blue;">return</span> date;
}
<span style="color: blue;">public</span> <span style="color: #2b91af;">void</span> setDate(Date date) {
<span style="color: blue;">this</span>.date = date;
}
<span style="color: blue;">public</span> String getNDoc() {
<span style="color: blue;">return</span> nDoc;
}
<span style="color: blue;">public</span> <span style="color: #2b91af;">void</span> setNDoc(String nDoc) {
<span style="color: blue;">this</span>.nDoc = nDoc;
}
<span style="color: blue;">public</span> List<OrderDetailBean> getOrderDetails() {
<span style="color: blue;">return</span> orderDetails;
}
<span style="color: blue;">public</span> <span style="color: #2b91af;">void</span> setOrderDetails(List<OrderDetailBean> orderDetails) {
<span style="color: blue;">this</span>.orderDetails = orderDetails;
}
}
<span style="color: green;">//File: OrderBean.java ends here.</span>
</pre>
</div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
<!-- HTML generated using hilite.me --><br /></div>
<div style="background: none repeat scroll 0% 0% rgb(255, 255, 255); border: medium solid gray; overflow: auto; padding: 0.2em 0.6em; text-align: left; width: auto;">
<pre style="line-height: 125%; margin: 0px;"><span style="color: green;">/**</span>
<span style="color: green;"> * OrderDetailBean.java. Created Tuesday, August 5 2014</span>
<span style="color: green;"> * @author Michael Kazarian</span>
<span style="color: green;"> * Tags:</span>
<span style="color: green;"> */</span>
<span style="color: blue;">package</span> com.blogspot.mkazarian;
<span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">OrderDetailBean</span>{
<span style="color: green;">/**</span>
<span style="color: green;"> * This class describes detail records for OrderBean.</span>
<span style="color: green;"> */</span>
<span style="color: blue;">private</span> String name;
<span style="color: blue;">private</span> <span style="color: #2b91af;">int</span> quantity;
<span style="color: blue;">private</span> Double price;
<span style="color: blue;">public</span> String getName() {
<span style="color: blue;">return</span> name;
}
<span style="color: blue;">public</span> <span style="color: #2b91af;">void</span> setName(String name) {
<span style="color: blue;">this</span>.name = name;
}
<span style="color: blue;">public</span> <span style="color: #2b91af;">int</span> getQuantity() {
<span style="color: blue;">return</span> quantity;
}
<span style="color: blue;">public</span> <span style="color: #2b91af;">void</span> setQuantity(<span style="color: #2b91af;">int</span> quantity) {
<span style="color: blue;">this</span>.quantity = quantity;
}
<span style="color: blue;">public</span> Double getPrice() {
<span style="color: blue;">return</span> price;
}
<span style="color: blue;">public</span> <span style="color: #2b91af;">void</span> setPrice(Double price) {
<span style="color: blue;">this</span>.price = price;
}
}
<span style="color: green;">//File: OrderDetailBean.java ends here.</span>
</pre>
</div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
<!-- HTML generated using hilite.me --><br /></div>
<div style="background: none repeat scroll 0% 0% rgb(255, 255, 255); border: medium solid gray; overflow: auto; padding: 0.2em 0.6em; text-align: left; width: auto;">
<pre style="line-height: 125%; margin: 0px;"><span style="color: green;">/**</span>
<span style="color: green;"> * OrderFactory.java. Created Tuesday, August 5 2014</span>
<span style="color: green;"> * @author Michael Kazarian</span>
<span style="color: green;"> * Tags:</span>
<span style="color: green;"> */</span>
<span style="color: blue;">package</span> com.blogspot.mkazarian;
<span style="color: blue;">import</span> java.util.List;
<span style="color: blue;">import</span> java.util.Arrays;
<span style="color: blue;">import</span> java.text.SimpleDateFormat;
<span style="color: blue;">import</span> java.text.ParseException;
<span style="color: blue;">import</span> java.util.Date;
<span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">OrderFactory</span>{
<span style="color: green;">/**</span>
<span style="color: green;"> * This class incorporate master and detail records.</span>
<span style="color: green;"> * For master records used OrderBean class; OrderDetailBean for detail record.</span>
<span style="color: green;"> */</span>
<span style="color: blue;">public</span> <span style="color: blue;">static</span> List<OrderBean> create(){
<span style="color: green;">/**</span>
<span style="color: green;"> * Factory-method for get datasource.</span>
<span style="color: green;"> */</span>
<span style="color: green;">//Add two master records</span>
OrderBean order1 = <span style="color: blue;">new</span> OrderBean();
order1.setNDoc(<span style="color: #a31515;">"1"</span>);
OrderBean order2 = <span style="color: blue;">new</span> OrderBean();
order2.setNDoc(<span style="color: #a31515;">"2"</span>);
<span style="color: green;">//Set Date format</span>
SimpleDateFormat textDate = <span style="color: blue;">new</span> SimpleDateFormat(<span style="color: #a31515;">"dd.MM.yyyy"</span>);
<span style="color: blue;">try</span>{
order1.setDate(textDate.parse(<span style="color: #a31515;">"05.08.2014"</span>));
order2.setDate(textDate.parse(<span style="color: #a31515;">"10.08.2014"</span>));
} <span style="color: blue;">catch</span> (ParseException pe){
order1.setDate(<span style="color: blue;">new</span> Date());
order2.setDate(<span style="color: blue;">new</span> Date());
}
<span style="color: green;">//Detail records for master record 1</span>
OrderDetailBean detail1 = <span style="color: blue;">new</span> OrderDetailBean();
detail1.setName(<span style="color: #a31515;">"Position one for document1"</span>);
detail1.setQuantity(10);
detail1.setPrice(123.45);
OrderDetailBean detail2 = <span style="color: blue;">new</span> OrderDetailBean();
detail2.setName(<span style="color: #a31515;">"Position two for document1"</span>);
detail2.setQuantity(7);
detail2.setPrice(23.52);
<span style="color: green;">//Detail records for master record 2</span>
OrderDetailBean detail3 = <span style="color: blue;">new</span> OrderDetailBean();
detail3.setName(<span style="color: #a31515;">"Position one for document2"</span>);
detail3.setQuantity(76);
detail3.setPrice(0.34);
OrderDetailBean detail4 = <span style="color: blue;">new</span> OrderDetailBean();
detail4.setName(<span style="color: #a31515;">"Position two for document2"</span>);
detail4.setQuantity(22);
detail4.setPrice(1.12);
<span style="color: green;">//Add detail records</span>
order1.setOrderDetails(Arrays.asList(detail1, detail2));
order2.setOrderDetails(Arrays.asList(detail3, detail4));
<span style="color: blue;">return</span> Arrays.asList(order1, order2);
}
}
<span style="color: green;">//File: OrderFactory.java ends here.</span>
</pre>
</div>
<div style="text-align: left;">
I advice create jar file for have our datasource as one file . Also you can <a href="https://drive.google.com/file/d/0B-xf0XG2s62RamtkYXctRmNmbkU/edit?usp=sharing" target="_blank">download my jar-file</a>.</div>
<div style="text-align: left;">
<br /></div>
<h3 style="text-align: left;">
Creating main reports.</h3>
<div style="text-align: left;">
Before creating reports we must register our datasource. It include two clauses:</div>
<ul style="text-align: left;">
<li>Add datasource to CLASSPATH. In iReport case open "Tools/Options" and add class or jar files in appropriate place.</li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
</div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjyiZGrnLhjv2Hk_X2EpdjuPJHeRb9dtZe556FwXuVRnJ4DpcZgkW0g-o1q-BwPSfeXT6uR-ScFu9P3AQZeG4SqpbhjR4yI5P4y1Nl7j_kgdMZIcYOXrR6BGh1ELS_NRv2dIEKUhMOo6rY/s1600/1-add-jar-to-classpath.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjyiZGrnLhjv2Hk_X2EpdjuPJHeRb9dtZe556FwXuVRnJ4DpcZgkW0g-o1q-BwPSfeXT6uR-ScFu9P3AQZeG4SqpbhjR4yI5P4y1Nl7j_kgdMZIcYOXrR6BGh1ELS_NRv2dIEKUhMOo6rY/s1600/1-add-jar-to-classpath.png" height="299" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><i>Picture 2: Set CLASSPATH</i></td><td class="tr-caption" style="text-align: center;"><br /></td></tr>
</tbody></table>
<div style="text-align: left;">
</div>
<ul style="text-align: left;">
<li> For register datasource press <b>Report Datasourced</b> button. Next press <b>New</b> button and select <b>JavaBeans set datasource</b> item. In next window fill all fields as on the picture:</li>
</ul>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhB-kDb-jIR4EsPEjI43T7Hk5f1HSRfVdzCJNwXXBay2F9ljVQVk2GWApJlMcvnW4gyOSiqzKzfhcIBwybxr_REEEB0DnKUIqkOLdlVZ99dyjRsNEfklHVSrfox4cTGaaVX9xkIVF_iF0kv/s1600/2-add-JB-datasource.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhB-kDb-jIR4EsPEjI43T7Hk5f1HSRfVdzCJNwXXBay2F9ljVQVk2GWApJlMcvnW4gyOSiqzKzfhcIBwybxr_REEEB0DnKUIqkOLdlVZ99dyjRsNEfklHVSrfox4cTGaaVX9xkIVF_iF0kv/s640/2-add-JB-datasource.png" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><i>Picture 3: Set datasource properties</i></td></tr>
</tbody></table>
<ul style="text-align: left;">
<li> Now we can create report. In new report disable all bands except Detail and save as <span style="font-family: "Courier New",Courier,monospace;">java_beans_datasource_report.jrxml</span>.</li>
<li>Next we must register our datafields. Call "Edit query" and fill parameters as on the picture:</li>
</ul>
</span></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhM3Qzo7tU3oekEojJ7EYVdNDcjOn8TvDu0TleG3ZNIrFCBdFekiv8Eyp-D1Jiao6k15ZHVIWsspAl_TnnH3Nax-Dpca-n-s67X9ZQX5wdb_4TwKSbLbYwM1ib5zOtngec7sJkSxps9pzPW/s1600/4-get-necessary-fields-from-DS.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhM3Qzo7tU3oekEojJ7EYVdNDcjOn8TvDu0TleG3ZNIrFCBdFekiv8Eyp-D1Jiao6k15ZHVIWsspAl_TnnH3Nax-Dpca-n-s67X9ZQX5wdb_4TwKSbLbYwM1ib5zOtngec7sJkSxps9pzPW/s1600/4-get-necessary-fields-from-DS.png" height="377" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><i>Picture 4: Set datafields</i></td></tr>
</tbody></table>
<div style="text-align: left;">
<ul style="text-align: left;">
<li>Add <span style="font-family: "Courier New",Courier,monospace;"><b>Ndoc</b></span> and <span style="font-family: "Courier New",Courier,monospace;"><b>Date</b></span> fields on <span style="font-family: "Courier New",Courier,monospace;"><b>Detail</b></span> band:</li>
</ul>
</div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjE_dXAP27ERriT1Wzel_xgdJyCjGvPu4wgV-avPsxYe0V0gK33VCRRuI0G3SbpLnwUqLCcLEeveyzirEyQboYeEbba6NFwOzZ7jWk57CLcQxuA7-xyDfRlJLopASy0K6gets82aSwC7Zj/s1600/5-create-main-report-1.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjE_dXAP27ERriT1Wzel_xgdJyCjGvPu4wgV-avPsxYe0V0gK33VCRRuI0G3SbpLnwUqLCcLEeveyzirEyQboYeEbba6NFwOzZ7jWk57CLcQxuA7-xyDfRlJLopASy0K6gets82aSwC7Zj/s1600/5-create-main-report-1.png" height="193" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><i>Picture 5: Adding fields on main report</i></td></tr>
</tbody></table>
<div style="text-align: left;">
<span class="short_text" id="result_box" lang="en"><span class="hps">If</span> <span class="hps">you did everything correctly you can see next result:</span></span></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgoQ1apz9kC3Lbj_r93gpbMKcnMlDeburA6Ui-j-Q2F2XEvcjwb2ySS82P6BM5o6RJlrX2r89AdvnaQOXxwrGqAGYugbSsDSsPpbVp3nbuOhmfUvJsq57EJXqj2aTAoEvZVIPuzv8GqYW1w/s1600/6-test-main-report1.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgoQ1apz9kC3Lbj_r93gpbMKcnMlDeburA6Ui-j-Q2F2XEvcjwb2ySS82P6BM5o6RJlrX2r89AdvnaQOXxwrGqAGYugbSsDSsPpbVp3nbuOhmfUvJsq57EJXqj2aTAoEvZVIPuzv8GqYW1w/s1600/6-test-main-report1.png" height="192" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><i>Picture 6: Our first result.</i></td></tr>
</tbody></table>
<div style="text-align: left;">
<h3 style="text-align: left;">
<span class="short_text" id="result_box" lang="en"><span class="hps">Creating subreport.</span></span></h3>
</div>
<div style="text-align: left;">
Add <b>subreport</b> component from <b>Pallete</b> and save it as <span style="font-family: "Courier New",Courier,monospace;">java_beans_datasource_report_subreport1.jrxml</span>. Next, call edit query and fill parameters as on the picture:</div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjchkWLqbQnX64E02OBrq-pcsgd6-4j7uOl6BmukMmG4iM1dKloJAyeRdTsmbcVTN6BzdmP5X0BsU48h9NxaVsVRHpt6tNQUdfC4psDxSErqle2f5levTkj7I0gzAHqGZUxa9MPKrknGdoP/s1600/8-get-necessary-fields-for-subreport.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjchkWLqbQnX64E02OBrq-pcsgd6-4j7uOl6BmukMmG4iM1dKloJAyeRdTsmbcVTN6BzdmP5X0BsU48h9NxaVsVRHpt6tNQUdfC4psDxSErqle2f5levTkj7I0gzAHqGZUxa9MPKrknGdoP/s1600/8-get-necessary-fields-for-subreport.png" height="378" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><i>Picture 6: Set datafields for subreport.</i></td></tr>
</tbody></table>
<div style="text-align: left;">
In subreport disable all bands except <b>Detail</b> and <b>Title</b>. For me it looks like below:</div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEisgW6uzv_GmmgmluzxdnXznuecpxCag1lnwbZnpMwb3MMwCRRSMskpsP4DEr_XgZGteIEJEi4fRZJTqZ2ciOPBYDI7KD0PV-4ADevjqBBP7b9dJTiHNiw2OZKgLrd6pusw8tpUaZ4G1YPL/s1600/9-mastering-subreport1.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEisgW6uzv_GmmgmluzxdnXznuecpxCag1lnwbZnpMwb3MMwCRRSMskpsP4DEr_XgZGteIEJEi4fRZJTqZ2ciOPBYDI7KD0PV-4ADevjqBBP7b9dJTiHNiw2OZKgLrd6pusw8tpUaZ4G1YPL/s1600/9-mastering-subreport1.png" height="136" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><i>Picture 7: Mastering subreport.</i></td></tr>
</tbody></table>
<div style="text-align: left;">
Now need tune subreport datasource. Switch to main (master) report and select Subreport component on Detail band. Set subreport properties:</div>
<div style="text-align: left;">
<ol style="text-align: left;">
<li><b>Expression class</b> to <span style="font-family: "Courier New",Courier,monospace;">java.util.List</span></li>
<li><b>Connection type</b> to <span style="font-family: "Courier New",Courier,monospace;">Use datasource expression</span></li>
<li><span style="font-family: "Courier New",Courier,monospace;"><b>Subreport Expression</b> to <!-- HTML generated using hilite.me --><div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;">$P{SUBREPORT_DIR} + "java_beans_datasource_report_subreport1.jasper"
</pre>
</div>
</span></li>
<li><b>Data source expression</b> to <!-- HTML generated using hilite.me --><div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: blue;">new</span> net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{orderDetails})
</pre>
</div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgn982yVKUBirKoaWSaFdNZevyK6Gh8PeNoVaubcCiKv6S8Rm-bDpNB9s5RdS8N9xF22cSLzkQOe8U4H2frFa8AnTEW5Ihpd0OaZcZlftgMJ2J_lkZa2HXtVlCJvQ0evvEAKKTRomtcW41B/s1600/10-set-subreport-datasource1.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgn982yVKUBirKoaWSaFdNZevyK6Gh8PeNoVaubcCiKv6S8Rm-bDpNB9s5RdS8N9xF22cSLzkQOe8U4H2frFa8AnTEW5Ihpd0OaZcZlftgMJ2J_lkZa2HXtVlCJvQ0evvEAKKTRomtcW41B/s1600/10-set-subreport-datasource1.png" height="296" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><i>Picture 8: Tune subreport datasource.</i></td></tr>
</tbody></table>
</li>
</ol>
</div>
<div>
Last step it save and compile subreport and main report. Press Preview button and enjoy result from Picture1.<br />
<br />
<b>Downloads</b>:<br />
<ol style="text-align: left;">
<li><a href="https://drive.google.com/file/d/0B-xf0XG2s62RamtkYXctRmNmbkU/edit?usp=sharing" target="_blank">jar-file</a> with JavaBean datasource.</li>
<li>Master report <a href="https://drive.google.com/file/d/0B-xf0XG2s62RTkJXOUl6Z1g4clE/edit?usp=sharing">java_beans_datasource_report.jrxml</a> <b>Note</b>: <i>perhaps you need to change <span style="font-family: "Courier New",Courier,monospace;">Default Value Expression</span> of <b>SUBREPORT_DIR</b> parameter to other, than <span style="font-family: "Courier New",Courier,monospace;">"./"</span>. Set it corresponding to directory what contains jrxml files</i>. </li>
<li>Subreport <a href="https://drive.google.com/file/d/0B-xf0XG2s62RNWJSY0UzVkk2QW8/edit?usp=sharing">java_beans_datasource_report_subreport1.jrxml</a></li>
<li><a href="https://drive.google.com/file/d/0B-xf0XG2s62RVi1VQXFDdXh0ODQ/edit?usp=sharing">Source code</a> (include all <span style="font-family: "Courier New",Courier,monospace;">jar, java</span> and <span style="font-family: "Courier New",Courier,monospace;">jrxml</span> files).</li>
<li>Source code from <a href="https://bitbucket.org/m_kazarian/ireport-subreport" target="_blank">BitBucket repository</a>. </li>
</ol>
</div>
<div>
<h3 style="text-align: left;">
Related articles:</h3>
<ul style="text-align: left;">
<li><a href="http://mkazarian.blogspot.com/2014/09/runing-jasperreport-subreport-from-java.html" target="_blank">Runing JasperReport subreport from java code</a> tell you about running this sample from java code.</li>
<li><a href="http://mkazarian.blogspot.com/2014/10/jasperreport-and-maven-for-creating.html" target="_blank">JasperReport and Maven for creating distributive </a></li>
</ul>
<h3 style="text-align: left;">
Credits:</h3>
<ul style="text-align: left;">
<li>Richard Nichols for <a href="http://www.richardnichols.net/2010/02/simple-guide-to-sub-reports-in-jasperreports-ireport/" target="_blank">idea</a> </li>
<li>Sandeep Ujjwal for solutions of connect to JavaBean datasource in <a href="http://hamroblog-sristi.blogspot.com/2012/10/using-javabean-datasource-in-subreport.html" target="_blank">his article</a>. </li>
<li>David Hamilton for <a href="http://stackoverflow.com/questions/13273640/ireport-sub-report-on-list-using-beans/13274138#13274138" target="_blank">answer</a> about subreport datasource.</li>
</ul>
</div>
</div>
Michael Kazarianhttp://www.blogger.com/profile/08626392846438054040noreply@blogger.com9tag:blogger.com,1999:blog-660391924419264317.post-5702346961315523952014-06-24T11:43:00.000+03:002014-09-29T17:17:59.844+03:00Minus one crutch<div dir="ltr" style="text-align: left;" trbidi="on">
<div>
I migrated one of my projects used Firebird1.5 to version 2.5. Main problem of this migration was broken backward compability of Firebird SQL-dialect. Because in this project is more than 500 SQL-queries I wrote text analyser for:<br />
<br />
<ol style="text-align: left;">
<li>get sql from java, python, pascal and self-written DSL.</li>
<li>analyzed sql queries and show recommendation for new version.</li>
</ol>
So, I migrated FB2.5 month ago and now have some infers:<br />
<ul style="text-align: left;">
<li>now I haven't problems related with FB1.5 will not work on modern platforms.</li>
<li>now don't need external extension (UDF in FB terminology). FB2.5 has own good tools.</li>
<li>in FB2.5 have increased performance.</li>
</ul>
But I have revealed two bad surprises. First surprise: because I can't test queries results I was caught sorting problems with null values. So, new syntax is more strict. The second problem - on Linux one query works very slow. At the same time on WinXP on VirtualBox this query works in 5 times faster. May be it is only Ubuntu problem, need test on other distros.<br />
<br />
Useful link: <a href="http://www.firebirdsql.org/file/community/ppts/fbcon11/Firebird_Migration_75Gb_IBSurgeon.pdf" target="_blank">From Firebird 1.5 to 2.5</a></div>
</div>
Michael Kazarianhttp://www.blogger.com/profile/08626392846438054040noreply@blogger.com0tag:blogger.com,1999:blog-660391924419264317.post-37309312775999152812012-06-15T12:36:00.003+03:002014-09-29T17:17:59.833+03:00mkv 2 avi<div dir="ltr" style="text-align: left;" trbidi="on">
Для всей папки с mkv:<br /><code>for f in *.mkv; do mencoder "$f" -oac mp3lame -ovc copy -o "avi/${f%.mkv}.avi"; done</code><span id="fullpost"></span></div>Michael Kazarianhttp://www.blogger.com/profile/08626392846438054040noreply@blogger.com0tag:blogger.com,1999:blog-660391924419264317.post-16977029011525344602012-06-05T11:17:00.002+03:002014-09-29T17:21:47.000+03:00Хоть я и не люблю Java<div dir="ltr" style="text-align: left;" trbidi="on">
но временами она меня радует. Недавно порадовала либка для обработки опций коммандной строки <a href="http://args4j.kohsuke.org/" rel="nofollow">args4j</a>.
На данный момент эта библиотечка самая простая в использовании вещь из
всех мной перепробованных и не тянет за собой никаких зависимостей.</div>
Michael Kazarianhttp://www.blogger.com/profile/08626392846438054040noreply@blogger.com0tag:blogger.com,1999:blog-660391924419264317.post-71512427368372933202012-05-17T15:54:00.000+03:002014-09-29T17:17:59.858+03:00Предыдущий пост заставил меня вспомнить не менее прекрасный <a href="http://www.linux.org.ru/news/opensource/7029354">тред</a> на ту же тему. Тут избранные цитаты:<br /><br /><i><a href="http://www.linux.org.ru/news/opensource/7029354?cid=7029787" rel="nofollow">Ну можете и подождать - мы, пользователи, Fedora, выступим early adopters (мы постоянно проверяем за вас опенсоурс новинки, это нормально), проверим, чтоб все работало, а мэйнтейнеры ваших дистров подберут уже готовое и отлаженное. Главное, чтоб они ничего не попортили.</a><br />...<br /><a href="http://www.linux.org.ru/news/opensource/7029354?cid=7029800" rel="nofollow">Я просто читать умею, в отличие от, и представляю, зачем все эти улучшения - avahi, pulse, systemd, теперь вот это. Кстати, бойтесь, Леннарт примерно с год назад нащупал еще одну тему, которая требует переделки :), но это уж пусть он сам анонсирует, когда придет время</a>.</i><br />Ну и самое вкусное:<br /><i><a href="http://www.linux.org.ru/news/opensource/7029354?cid=7029816" rel="nofollow">Да тут почти все камменты написаны неграмотными троллигна ради, а ты цепляешься ко мне, человеку почти без троек закончившему советскую школу, т.е. интеллектуальному элитарию на фоне дикарей, рожденных в 1990е</a></i>.Michael Kazarianhttp://www.blogger.com/profile/08626392846438054040noreply@blogger.com0tag:blogger.com,1999:blog-660391924419264317.post-22002548053851653042012-05-17T15:52:00.001+03:002014-09-29T17:17:59.823+03:00<div dir="ltr" style="text-align: left;" trbidi="on">
Срачи на тему systemd и поттерлога по ходу выявляют дивное. Вот, например, один из горячих сторонников systemd <a href="http://www.linux.org.ru/forum/talks/7754516?cid=7757143">предлагает переписать все скрипты загрузки системы на С</a>* (как на новом, соответствующем времени, инструменте), а другие <a href="http://www.linux.org.ru/forum/talks/7754516?cid=7759122">обещают</a> немерянный профит в скорости работы и анализе логов от перевода его в бинарное состояние**.<br />
<br />
<b>UPD:</b> А вообще, по вредоносности, Поттеринг имеет все шансы затмить де Иказу, как луна звезду.<br />
<div class="quote">
<hr />
<br />
* - Кто не в курсе: сейчас используется гораздо более подходящий для этих целей bash<br />
** - Кто не в курсе: в случае логов бинарный формат противопоказан и по скорости выгребания логов, и по гибкости их обработки.</div>
</div>Michael Kazarianhttp://www.blogger.com/profile/08626392846438054040noreply@blogger.com0tag:blogger.com,1999:blog-660391924419264317.post-58746958565643249162012-03-14T10:45:00.000+02:002014-09-29T17:17:59.846+03:00Компьютерная типография LaTeX в свободном доступе<div dir="ltr" style="text-align: left;" trbidi="on">
Евгений Балдин дописал-таки свою книгу "компьютерная типография" и <a href="http://ctan.org/tex-archive/info/russian/Computer_Typesetting_Using_LaTeX" rel="nofollow">выложил ее в открытый доступ</a>.</div>Michael Kazarianhttp://www.blogger.com/profile/08626392846438054040noreply@blogger.com0tag:blogger.com,1999:blog-660391924419264317.post-78139235577228209142011-12-21T14:08:00.000+02:002014-09-29T17:17:59.861+03:00python-mode, памятка<div dir="ltr" style="text-align: left;" trbidi="on">
cedet из cvs теперь принудительно дергает python.el (он у меня в /usr/share/emacs/23.1/lisp/progmodes), который конфликтует с python-mode.el, который мне нравится больше. Лечится правкой cedet/semantic/wisent/wisent-python.el Находится строчка (require 'python nil t) и комментируется. При желании перекомпилируется.<br />
Нормальная работа восстановлена и глюков пока не замечено.<br /></div>Michael Kazarianhttp://www.blogger.com/profile/08626392846438054040noreply@blogger.com3tag:blogger.com,1999:blog-660391924419264317.post-63855797959623365902011-11-25T09:22:00.001+02:002014-09-29T17:17:59.849+03:00Почему лучше не связываться с wxPython<div dir="ltr" style="text-align: left;" trbidi="on">
Если вы начинаете проект на Python и в качестве GUI думаете использовать wxPython, то я не советую вам это делать по причинам переносимости. Ниже мой <a href="http://ru-python.livejournal.com/315134.html?thread=3063038#t3063038">комментарий</a> в теме, где такая проблема всплыла.
<br />
<hr />
Тема wxPython на Linux вылазит, как правило в начале работы, когда вовсю вылазят косяки сборки wxPython. В свое время мы отказались от wx по двум причинам:<br />
<ul style="text-align: left;">
<li>у wx (по крайней мере с wxPython) была проблема с обратной совместимостью на неосновных версиях.</li>
<li>wx, под Linux, дергает GTK. Но, работая с GTK напрямую еще есть шансы на то, что на другой конфигураци* версия библиотеки будет совместима с той, которая используется для разработки. С wх, и в особенности с wxPython, такие шансы невысоки и вот почему. wxPython представляет собой связку четырех сущностей упомянутые выше GTK и wx, плюс wxPython и Python. Пакеты с GTK, wx, wxPython и Python собирают разные люди. Насколько они договорятся между собой о используемых версиях (<b>UPD</b>: и насколько большое рукожопие проявят в процессе сборки) - большой вопрос. </li>
</ul>
Если вы только начинаете проект я бы рекомендовал использовать более популярные альтернативы: pyQT или pyGTK**. Они вовсю используются в дистрибутивах, потому вероятность поиметь проблем с кривыми сборками и переносимостью на порядок меньше.
Перед этим, для GUI, я использовал связку TkInter+Tile. Теперь, я предпочитаю вариант Java+Jython.
<br />
<hr />
* - например, апгрейд дистрибутива или его смена <br />
** - pyQT, пожалуй, самое лучшее. Но для коммерческих проектов надо лицензироваться, причем - недешево. Вместо него можно попробовать <a href="http://www.pyside.org/">PySide</a>, если он присутствует в вашем дистрибутиве. Вариант с GTK тоже имеет свои нюансы. Не так давно вышла GTK3. Я не знаю, совместимы ли GTK2 и GTK3, есть ли биндинг к GTK3, насколько он совместим с GTK2 и насколько вообще стабильна эта связка.</div>Michael Kazarianhttp://www.blogger.com/profile/08626392846438054040noreply@blogger.com0tag:blogger.com,1999:blog-660391924419264317.post-30709706283236103022011-10-13T14:15:00.003+03:002014-09-29T17:17:59.828+03:00Хозяйке на заметку. Выдрать кусок видео<div dir="ltr" style="text-align: left;" trbidi="on">
mencoder your_movie.flv -ss <b>START_TIME</b> -endpos <b>LENGTH_IN_SECONDS</b> -ovc xvid -xvidencopts chroma_opt:vhq=2:bvhq=1:quant_type=mpeg:b<br />
<wbr></wbr>itrate=2000 -oac mp3lame -lameopts cbr:br=192 -o your_movie.flv<br /><br />Схожий <a href="http://b-al-u.livejournal.com/50270.html">рецепт</a>, но выдрать только звук.</div>Michael Kazarianhttp://www.blogger.com/profile/08626392846438054040noreply@blogger.com0