/jincron/trunk/CHANGELOG |
---|
0,0 → 1,3 |
0.1.0 2006-12-28 |
* first release |
/jincron/trunk/COPYING |
---|
0,0 → 1,339 |
GNU GENERAL PUBLIC LICENSE |
Version 2, June 1991 |
Copyright (C) 1989, 1991 Free Software Foundation, Inc. |
675 Mass Ave, Cambridge, MA 02139, USA |
Everyone is permitted to copy and distribute verbatim copies |
of this license document, but changing it is not allowed. |
Preamble |
The licenses for most software are designed to take away your |
freedom to share and change it. By contrast, the GNU General Public |
License is intended to guarantee your freedom to share and change free |
software--to make sure the software is free for all its users. This |
General Public License applies to most of the Free Software |
Foundation's software and to any other program whose authors commit to |
using it. (Some other Free Software Foundation software is covered by |
the GNU Library General Public License instead.) You can apply it to |
your programs, too. |
When we speak of free software, we are referring to freedom, not |
price. Our General Public Licenses are designed to make sure that you |
have the freedom to distribute copies of free software (and charge for |
this service if you wish), that you receive source code or can get it |
if you want it, that you can change the software or use pieces of it |
in new free programs; and that you know you can do these things. |
To protect your rights, we need to make restrictions that forbid |
anyone to deny you these rights or to ask you to surrender the rights. |
These restrictions translate to certain responsibilities for you if you |
distribute copies of the software, or if you modify it. |
For example, if you distribute copies of such a program, whether |
gratis or for a fee, you must give the recipients all the rights that |
you have. You must make sure that they, too, receive or can get the |
source code. And you must show them these terms so they know their |
rights. |
We protect your rights with two steps: (1) copyright the software, and |
(2) offer you this license which gives you legal permission to copy, |
distribute and/or modify the software. |
Also, for each author's protection and ours, we want to make certain |
that everyone understands that there is no warranty for this free |
software. If the software is modified by someone else and passed on, we |
want its recipients to know that what they have is not the original, so |
that any problems introduced by others will not reflect on the original |
authors' reputations. |
Finally, any free program is threatened constantly by software |
patents. We wish to avoid the danger that redistributors of a free |
program will individually obtain patent licenses, in effect making the |
program proprietary. To prevent this, we have made it clear that any |
patent must be licensed for everyone's free use or not licensed at all. |
The precise terms and conditions for copying, distribution and |
modification follow. |
GNU GENERAL PUBLIC LICENSE |
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION |
0. This License applies to any program or other work which contains |
a notice placed by the copyright holder saying it may be distributed |
under the terms of this General Public License. The "Program", below, |
refers to any such program or work, and a "work based on the Program" |
means either the Program or any derivative work under copyright law: |
that is to say, a work containing the Program or a portion of it, |
either verbatim or with modifications and/or translated into another |
language. (Hereinafter, translation is included without limitation in |
the term "modification".) Each licensee is addressed as "you". |
Activities other than copying, distribution and modification are not |
covered by this License; they are outside its scope. The act of |
running the Program is not restricted, and the output from the Program |
is covered only if its contents constitute a work based on the |
Program (independent of having been made by running the Program). |
Whether that is true depends on what the Program does. |
1. You may copy and distribute verbatim copies of the Program's |
source code as you receive it, in any medium, provided that you |
conspicuously and appropriately publish on each copy an appropriate |
copyright notice and disclaimer of warranty; keep intact all the |
notices that refer to this License and to the absence of any warranty; |
and give any other recipients of the Program a copy of this License |
along with the Program. |
You may charge a fee for the physical act of transferring a copy, and |
you may at your option offer warranty protection in exchange for a fee. |
2. You may modify your copy or copies of the Program or any portion |
of it, thus forming a work based on the Program, and copy and |
distribute such modifications or work under the terms of Section 1 |
above, provided that you also meet all of these conditions: |
a) You must cause the modified files to carry prominent notices |
stating that you changed the files and the date of any change. |
b) You must cause any work that you distribute or publish, that in |
whole or in part contains or is derived from the Program or any |
part thereof, to be licensed as a whole at no charge to all third |
parties under the terms of this License. |
c) If the modified program normally reads commands interactively |
when run, you must cause it, when started running for such |
interactive use in the most ordinary way, to print or display an |
announcement including an appropriate copyright notice and a |
notice that there is no warranty (or else, saying that you provide |
a warranty) and that users may redistribute the program under |
these conditions, and telling the user how to view a copy of this |
License. (Exception: if the Program itself is interactive but |
does not normally print such an announcement, your work based on |
the Program is not required to print an announcement.) |
These requirements apply to the modified work as a whole. If |
identifiable sections of that work are not derived from the Program, |
and can be reasonably considered independent and separate works in |
themselves, then this License, and its terms, do not apply to those |
sections when you distribute them as separate works. But when you |
distribute the same sections as part of a whole which is a work based |
on the Program, the distribution of the whole must be on the terms of |
this License, whose permissions for other licensees extend to the |
entire whole, and thus to each and every part regardless of who wrote it. |
Thus, it is not the intent of this section to claim rights or contest |
your rights to work written entirely by you; rather, the intent is to |
exercise the right to control the distribution of derivative or |
collective works based on the Program. |
In addition, mere aggregation of another work not based on the Program |
with the Program (or with a work based on the Program) on a volume of |
a storage or distribution medium does not bring the other work under |
the scope of this License. |
3. You may copy and distribute the Program (or a work based on it, |
under Section 2) in object code or executable form under the terms of |
Sections 1 and 2 above provided that you also do one of the following: |
a) Accompany it with the complete corresponding machine-readable |
source code, which must be distributed under the terms of Sections |
1 and 2 above on a medium customarily used for software interchange; or, |
b) Accompany it with a written offer, valid for at least three |
years, to give any third party, for a charge no more than your |
cost of physically performing source distribution, a complete |
machine-readable copy of the corresponding source code, to be |
distributed under the terms of Sections 1 and 2 above on a medium |
customarily used for software interchange; or, |
c) Accompany it with the information you received as to the offer |
to distribute corresponding source code. (This alternative is |
allowed only for noncommercial distribution and only if you |
received the program in object code or executable form with such |
an offer, in accord with Subsection b above.) |
The source code for a work means the preferred form of the work for |
making modifications to it. For an executable work, complete source |
code means all the source code for all modules it contains, plus any |
associated interface definition files, plus the scripts used to |
control compilation and installation of the executable. However, as a |
special exception, the source code distributed need not include |
anything that is normally distributed (in either source or binary |
form) with the major components (compiler, kernel, and so on) of the |
operating system on which the executable runs, unless that component |
itself accompanies the executable. |
If distribution of executable or object code is made by offering |
access to copy from a designated place, then offering equivalent |
access to copy the source code from the same place counts as |
distribution of the source code, even though third parties are not |
compelled to copy the source along with the object code. |
4. You may not copy, modify, sublicense, or distribute the Program |
except as expressly provided under this License. Any attempt |
otherwise to copy, modify, sublicense or distribute the Program is |
void, and will automatically terminate your rights under this License. |
However, parties who have received copies, or rights, from you under |
this License will not have their licenses terminated so long as such |
parties remain in full compliance. |
5. You are not required to accept this License, since you have not |
signed it. However, nothing else grants you permission to modify or |
distribute the Program or its derivative works. These actions are |
prohibited by law if you do not accept this License. Therefore, by |
modifying or distributing the Program (or any work based on the |
Program), you indicate your acceptance of this License to do so, and |
all its terms and conditions for copying, distributing or modifying |
the Program or works based on it. |
6. Each time you redistribute the Program (or any work based on the |
Program), the recipient automatically receives a license from the |
original licensor to copy, distribute or modify the Program subject to |
these terms and conditions. You may not impose any further |
restrictions on the recipients' exercise of the rights granted herein. |
You are not responsible for enforcing compliance by third parties to |
this License. |
7. If, as a consequence of a court judgment or allegation of patent |
infringement or for any other reason (not limited to patent issues), |
conditions are imposed on you (whether by court order, agreement or |
otherwise) that contradict the conditions of this License, they do not |
excuse you from the conditions of this License. If you cannot |
distribute so as to satisfy simultaneously your obligations under this |
License and any other pertinent obligations, then as a consequence you |
may not distribute the Program at all. For example, if a patent |
license would not permit royalty-free redistribution of the Program by |
all those who receive copies directly or indirectly through you, then |
the only way you could satisfy both it and this License would be to |
refrain entirely from distribution of the Program. |
If any portion of this section is held invalid or unenforceable under |
any particular circumstance, the balance of the section is intended to |
apply and the section as a whole is intended to apply in other |
circumstances. |
It is not the purpose of this section to induce you to infringe any |
patents or other property right claims or to contest validity of any |
such claims; this section has the sole purpose of protecting the |
integrity of the free software distribution system, which is |
implemented by public license practices. Many people have made |
generous contributions to the wide range of software distributed |
through that system in reliance on consistent application of that |
system; it is up to the author/donor to decide if he or she is willing |
to distribute software through any other system and a licensee cannot |
impose that choice. |
This section is intended to make thoroughly clear what is believed to |
be a consequence of the rest of this License. |
8. If the distribution and/or use of the Program is restricted in |
certain countries either by patents or by copyrighted interfaces, the |
original copyright holder who places the Program under this License |
may add an explicit geographical distribution limitation excluding |
those countries, so that distribution is permitted only in or among |
countries not thus excluded. In such case, this License incorporates |
the limitation as if written in the body of this License. |
9. The Free Software Foundation may publish revised and/or new versions |
of the General Public License from time to time. Such new versions will |
be similar in spirit to the present version, but may differ in detail to |
address new problems or concerns. |
Each version is given a distinguishing version number. If the Program |
specifies a version number of this License which applies to it and "any |
later version", you have the option of following the terms and conditions |
either of that version or of any later version published by the Free |
Software Foundation. If the Program does not specify a version number of |
this License, you may choose any version ever published by the Free Software |
Foundation. |
10. If you wish to incorporate parts of the Program into other free |
programs whose distribution conditions are different, write to the author |
to ask for permission. For software which is copyrighted by the Free |
Software Foundation, write to the Free Software Foundation; we sometimes |
make exceptions for this. Our decision will be guided by the two goals |
of preserving the free status of all derivatives of our free software and |
of promoting the sharing and reuse of software generally. |
NO WARRANTY |
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY |
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN |
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES |
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED |
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS |
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE |
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, |
REPAIR OR CORRECTION. |
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING |
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR |
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, |
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING |
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED |
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY |
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER |
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE |
POSSIBILITY OF SUCH DAMAGES. |
END OF TERMS AND CONDITIONS |
Appendix: How to Apply These Terms to Your New Programs |
If you develop a new program, and you want it to be of the greatest |
possible use to the public, the best way to achieve this is to make it |
free software which everyone can redistribute and change under these terms. |
To do so, attach the following notices to the program. It is safest |
to attach them to the start of each source file to most effectively |
convey the exclusion of warranty; and each file should have at least |
the "copyright" line and a pointer to where the full notice is found. |
<one line to give the program's name and a brief idea of what it does.> |
Copyright (C) 19yy <name of author> |
This program is free software; you can redistribute it and/or modify |
it under the terms of the GNU General Public License as published by |
the Free Software Foundation; either version 2 of the License, or |
(at your option) any later version. |
This program is distributed in the hope that it will be useful, |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
GNU General Public License for more details. |
You should have received a copy of the GNU General Public License |
along with this program; if not, write to the Free Software |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
Also add information on how to contact you by electronic and paper mail. |
If the program is interactive, make it output a short notice like this |
when it starts in an interactive mode: |
Gnomovision version 69, Copyright (C) 19yy name of author |
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. |
This is free software, and you are welcome to redistribute it |
under certain conditions; type `show c' for details. |
The hypothetical commands `show w' and `show c' should show the appropriate |
parts of the General Public License. Of course, the commands you use may |
be called something other than `show w' and `show c'; they could even be |
mouse-clicks or menu items--whatever suits your program. |
You should also get your employer (if you work as a programmer) or your |
school, if any, to sign a "copyright disclaimer" for the program, if |
necessary. Here is a sample; alter the names: |
Yoyodyne, Inc., hereby disclaims all copyright interest in the program |
`Gnomovision' (which makes passes at compilers) written by James Hacker. |
<signature of Ty Coon>, 1 April 1989 |
Ty Coon, President of Vice |
This General Public License does not permit incorporating your program into |
proprietary programs. If your program is a subroutine library, you may |
consider it more useful to permit linking proprietary applications with the |
library. If this is what you want to do, use the GNU Library General |
Public License instead of this License. |
/jincron/trunk/cz/aiken/util/jincron/ICConfig.java |
---|
0,0 → 1,120 |
/* |
* ICConfig.java - jIncron configuration management |
* |
* Copyright (c) 2006 Lukas Jelinek, http://www.aiken.cz |
* |
* ========================================================================== |
* |
* This program is free software; you can redistribute it and/or modify |
* it under the terms of the GNU General Public License Version 2 as |
* published by the Free Software Foundation. |
* |
* This program is distributed in the hope that it will be useful, |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* GNU General Public License for more details. |
* |
* You should have received a copy of the GNU General Public License |
* along with this program; if not, write to the Free Software |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* |
* ========================================================================== |
*/ |
package cz.aiken.util.jincron; |
import java.io.*; |
import java.util.*; |
import java.awt.*; |
import javax.swing.JOptionPane; |
/** |
* |
* @author luk |
*/ |
public class ICConfig { |
private static final String cfgFile = ".jincron.xml"; |
private static Properties props = new Properties(); |
static { |
init(); |
} |
public static void load() { |
File f = new File(System.getProperty("user.home"), cfgFile); |
if (!f.exists()) |
return; |
try { |
BufferedInputStream is = new BufferedInputStream(new FileInputStream(f)); |
try { |
props.loadFromXML(is); |
} finally { |
is.close(); |
} |
} catch (Exception e) { |
JOptionPane.showMessageDialog(null, "Cannot load configuration: " + e.getMessage(), |
"Error", JOptionPane.ERROR_MESSAGE); |
} |
} |
public static void save() { |
File f = new File(System.getProperty("user.home"), cfgFile); |
try { |
BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(f)); |
try { |
props.storeToXML(os, "jIncron configuration file"); |
} finally { |
os.close(); |
} |
} catch (Exception e) { |
JOptionPane.showMessageDialog(null, "Cannot save configuration: " + e.getMessage(), |
"Error", JOptionPane.ERROR_MESSAGE); |
} |
} |
public static void init() { |
props.setProperty("window.width", Integer.toString(500)); |
props.setProperty("window.height", Integer.toString(300)); |
props.setProperty("window.x", Integer.toString(100)); |
props.setProperty("window.y", Integer.toString(100)); |
} |
public static int getInt(String key, int dflt) { |
try { |
return Integer.parseInt(props.getProperty(key)); |
} catch (NumberFormatException e) { |
return dflt; |
} |
} |
public static void setInt(String key, int val) { |
props.setProperty(key, Integer.toString(val)); |
} |
public static Dimension getWindowSize() { |
return new Dimension(getInt("window.width", 0), getInt("window.height", 0)); |
} |
public static Point getWindowLocation() { |
return new Point(getInt("window.x", 0), getInt("window.y", 0)); |
} |
public static void setWindowSize(Dimension d) { |
setInt("window.width", d.width); |
setInt("window.height", d.height); |
} |
public static void setWindowLocation(Point p) { |
setInt("window.x", p.x); |
setInt("window.y", p.y); |
} |
} |
/jincron/trunk/cz/aiken/util/jincron/ICRow.java |
---|
0,0 → 1,108 |
/* |
* ICRow.java - jIncron table row class |
* |
* Copyright (c) 2006 Lukas Jelinek, http://www.aiken.cz |
* |
* ========================================================================== |
* |
* This program is free software; you can redistribute it and/or modify |
* it under the terms of the GNU General Public License Version 2 as |
* published by the Free Software Foundation. |
* |
* This program is distributed in the hope that it will be useful, |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* GNU General Public License for more details. |
* |
* You should have received a copy of the GNU General Public License |
* along with this program; if not, write to the Free Software |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* |
* ========================================================================== |
*/ |
package cz.aiken.util.jincron; |
import java.util.regex.*; |
/** |
* |
* @author luk |
*/ |
public class ICRow { |
protected static final Pattern splitter = Pattern.compile("[^\\\\](\\s)+"); |
private String path = ""; |
private InotifyEvent event = null; |
private String command = ""; |
ICRow(String path, InotifyEvent event, String command) { |
this.path = path; |
this.event = event; |
this.command = command; |
} |
String getPath() { |
return path; |
} |
void setPath(String path) { |
this.path = path; |
} |
InotifyEvent getEvent() { |
return event; |
} |
void setEvent(InotifyEvent event) { |
this.event = event; |
} |
String getCommand() { |
return command; |
} |
void setCommand(String command) { |
this.command = command; |
} |
static int getFieldCount() { |
return 3; |
} |
static ICRow parse(String text) { |
if (text == null || text.equals("")) |
return null; |
Matcher m = splitter.matcher(text); |
if (!m.find()) |
return null; |
int pos = m.start() + 1; |
String path = text.substring(0, pos).trim().replace("\\ ", " ").replace("\\\\", "\\"); |
if (!m.find()) |
return null; |
int oldpos = pos; |
pos = m.start() + 1; |
InotifyEvent evt = InotifyEvent.parse(text.substring(oldpos, pos)); |
if (evt == null) |
return null; |
String cmd = text.substring(pos).trim(); |
return new ICRow(path, evt, cmd); |
} |
public String toString() { |
StringBuilder sb = new StringBuilder(); |
sb.append(getPath().replace("\\", "\\\\").replace(" ", "\\ ")); |
sb.append(' '); |
sb.append(getEvent().toString()); |
sb.append(' '); |
sb.append(getCommand()); |
return sb.toString(); |
} |
} |
/jincron/trunk/cz/aiken/util/jincron/InotifyEvent.java |
---|
0,0 → 1,291 |
/* |
* InotifyEvent.java - inotify event class |
* |
* Copyright (c) 2006 Lukas Jelinek, http://www.aiken.cz |
* |
* ========================================================================== |
* |
* This program is free software; you can redistribute it and/or modify |
* it under the terms of the GNU General Public License Version 2 as |
* published by the Free Software Foundation. |
* |
* This program is distributed in the hope that it will be useful, |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* GNU General Public License for more details. |
* |
* You should have received a copy of the GNU General Public License |
* along with this program; if not, write to the Free Software |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* |
* ========================================================================== |
*/ |
package cz.aiken.util.jincron; |
import java.util.*; |
/** |
* |
* @author luk |
*/ |
public class InotifyEvent { |
private int mask = 0; |
private int flags = 0; |
public static final int IN_ACCESS = 0x00000001; |
public static final int IN_MODIFY = 0x00000002; |
public static final int IN_ATTRIB = 0x00000004; |
public static final int IN_CLOSE_WRITE = 0x00000008; |
public static final int IN_CLOSE_NOWRITE = 0x00000010; |
public static final int IN_OPEN = 0x00000020; |
public static final int IN_MOVED_FROM = 0x00000040; |
public static final int IN_MOVED_TO = 0x00000080; |
public static final int IN_CREATE = 0x00000100; |
public static final int IN_DELETE = 0x00000200; |
public static final int IN_DELETE_SELF = 0x00000400; |
public static final int IN_MOVE_SELF = 0x00000800; |
public static final int IN_ONLYDIR = 0x01000000; |
public static final int IN_DONT_FOLLOW = 0x02000000; |
public static final int IN_ONESHOT = 0x80000000; |
public static final int IN_CLOSE = IN_CLOSE_WRITE | IN_CLOSE_NOWRITE; |
public static final int IN_MOVE = IN_MOVED_FROM | IN_MOVED_TO; |
public static final int IN_ALL_EVENTS = IN_ACCESS | IN_MODIFY | IN_ATTRIB | IN_CLOSE |
| IN_OPEN | IN_MOVE | IN_CREATE | IN_DELETE | IN_DELETE_SELF | IN_MOVE_SELF; |
public static final int IN_NO_LOOP = 0x00000001; |
private static HashMap<String, Integer> nameToMask = new HashMap<String, Integer>(); |
private static HashMap<String, Integer> flagsToMask = new HashMap<String, Integer>(); |
static { |
nameToMask.put("IN_ACCESS", IN_ACCESS); |
nameToMask.put("IN_MODIFY", IN_MODIFY); |
nameToMask.put("IN_ATTRIB", IN_ATTRIB); |
nameToMask.put("IN_CLOSE_WRITE", IN_CLOSE_WRITE); |
nameToMask.put("IN_CLOSE_NOWRITE", IN_CLOSE_NOWRITE); |
nameToMask.put("IN_OPEN", IN_OPEN); |
nameToMask.put("IN_MOVED_FROM", IN_MOVED_FROM); |
nameToMask.put("IN_MOVED_TO", IN_MOVED_TO); |
nameToMask.put("IN_CREATE", IN_CREATE); |
nameToMask.put("IN_DELETE", IN_DELETE); |
nameToMask.put("IN_DELETE_SELF", IN_DELETE_SELF); |
nameToMask.put("IN_MOVE_SELF", IN_MOVE_SELF); |
nameToMask.put("IN_ONLYDIR", IN_ONLYDIR); |
nameToMask.put("IN_DONT_FOLLOW", IN_DONT_FOLLOW); |
nameToMask.put("IN_ONESHOT", IN_ONESHOT); |
nameToMask.put("IN_CLOSE", IN_CLOSE); |
nameToMask.put("IN_MOVE", IN_MOVE); |
nameToMask.put("IN_ALL_EVENTS", IN_ALL_EVENTS); |
flagsToMask.put("IN_NO_LOOP", IN_NO_LOOP); |
} |
/** Creates a new instance of InotifyEvent */ |
public InotifyEvent(int mask, int flags) { |
this.mask = mask; |
this.flags = flags; |
} |
public InotifyEvent(InotifyEvent src) { |
this(src.getMask(), src.getFlags()); |
} |
public static InotifyEvent parse(String text) { |
int mask = 0; |
int flags = 0; |
try { |
mask = Integer.parseInt(text); |
} catch (NumberFormatException e) { |
String sa[] = text.split(","); |
for (int i=0; i<sa.length; i++) { |
String s = sa[i].trim(); |
mask |= getMaskByName(s); |
flags |= getFlagsByName(s); |
} |
} |
return new InotifyEvent(mask, flags); |
} |
public int getMask() { |
return mask; |
} |
public void setMask(int mask) { |
this.mask = mask; |
} |
public boolean hasMask(int mask) { |
return (mask & this.mask) == mask; |
} |
public void changeMask(int mask, boolean add) { |
if (add) { |
this.mask |= mask; |
} |
else { |
this.mask &= ~mask; |
} |
} |
public int getFlags() { |
return flags; |
} |
public void setFlags(int flags) { |
this.flags = flags; |
} |
public boolean hasFlags(int flags) { |
return (flags & this.flags) == flags; |
} |
public void changeFlags(int flags, boolean add) { |
if (add) { |
this.flags |= flags; |
} |
else { |
this.flags &= ~flags; |
} |
} |
public String toString() { |
StringBuilder sb = new StringBuilder(); |
if ((mask & IN_ALL_EVENTS) == IN_ALL_EVENTS) { |
if (sb.length() > 0) |
sb.append(','); |
sb.append("IN_ALL_EVENTS"); |
} |
else { |
if ((mask & IN_MOVE) == IN_MOVE) { |
if (sb.length() > 0) |
sb.append(','); |
sb.append("IN_MOVE"); |
} |
else { |
if ((mask & IN_MOVED_FROM) == IN_MOVED_FROM) { |
if (sb.length() > 0) |
sb.append(','); |
sb.append("IN_MOVED_FROM"); |
} |
else if ((mask & IN_MOVED_TO) == IN_MOVED_TO) { |
if (sb.length() > 0) |
sb.append(','); |
sb.append("IN_MOVED_TO"); |
} |
} |
if ((mask & IN_CLOSE) == IN_CLOSE) { |
if (sb.length() > 0) |
sb.append(','); |
sb.append("IN_CLOSE"); |
} |
else { |
if ((mask & IN_CLOSE_WRITE) == IN_CLOSE_WRITE) { |
if (sb.length() > 0) |
sb.append(','); |
sb.append("IN_CLOSE_WRITE"); |
} |
else if ((mask & IN_CLOSE_NOWRITE) == IN_CLOSE_NOWRITE) { |
if (sb.length() > 0) |
sb.append(','); |
sb.append("IN_CLOSE_NOWRITE"); |
} |
} |
if ((mask & IN_ACCESS) == IN_ACCESS) { |
if (sb.length() > 0) |
sb.append(','); |
sb.append("IN_ACCESS"); |
} |
if ((mask & IN_MODIFY) == IN_MODIFY) { |
if (sb.length() > 0) |
sb.append(','); |
sb.append("IN_MODIFY"); |
} |
if ((mask & IN_ATTRIB) == IN_ATTRIB) { |
if (sb.length() > 0) |
sb.append(','); |
sb.append("IN_ATTRIB"); |
} |
if ((mask & IN_OPEN) == IN_OPEN) { |
if (sb.length() > 0) |
sb.append(','); |
sb.append("IN_OPEN"); |
} |
if ((mask & IN_CREATE) == IN_CREATE) { |
if (sb.length() > 0) |
sb.append(','); |
sb.append("IN_CREATE"); |
} |
if ((mask & IN_DELETE) == IN_DELETE) { |
if (sb.length() > 0) |
sb.append(','); |
sb.append("IN_DELETE"); |
} |
if ((mask & IN_DELETE_SELF) == IN_DELETE_SELF) { |
if (sb.length() > 0) |
sb.append(','); |
sb.append("IN_DELETE_SELF"); |
} |
if ((mask & IN_MOVE_SELF) == IN_MOVE_SELF) { |
if (sb.length() > 0) |
sb.append(','); |
sb.append("IN_MOVE_SELF"); |
} |
} |
if ((mask & IN_ONLYDIR) == IN_ONLYDIR) { |
if (sb.length() > 0) |
sb.append(','); |
sb.append("IN_ONLYDIR"); |
} |
if ((mask & IN_DONT_FOLLOW) == IN_DONT_FOLLOW) { |
if (sb.length() > 0) |
sb.append(','); |
sb.append("IN_DONT_FOLLOW"); |
} |
if ((mask & IN_ONESHOT) == IN_ONESHOT) { |
if (sb.length() > 0) |
sb.append(','); |
sb.append("IN_ONESHOT"); |
} |
if ((flags & IN_NO_LOOP) == IN_NO_LOOP) { |
if (sb.length() > 0) |
sb.append(','); |
sb.append("IN_NO_LOOP"); |
} |
return sb.toString(); |
} |
public static int getMaskByName(String name) { |
Integer i = nameToMask.get(name); |
return i != null ? i.intValue() : 0; |
} |
public static int getFlagsByName(String name) { |
Integer i = flagsToMask.get(name); |
return i != null ? i.intValue() : 0; |
} |
} |
/jincron/trunk/cz/aiken/util/jincron/ICTableModel.java |
---|
0,0 → 1,152 |
/* |
* ICTableModel.java - jIncron table model class |
* |
* Copyright (c) 2006 Lukas Jelinek, http://www.aiken.cz |
* |
* ========================================================================== |
* |
* This program is free software; you can redistribute it and/or modify |
* it under the terms of the GNU General Public License Version 2 as |
* published by the Free Software Foundation. |
* |
* This program is distributed in the hope that it will be useful, |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* GNU General Public License for more details. |
* |
* You should have received a copy of the GNU General Public License |
* along with this program; if not, write to the Free Software |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* |
* ========================================================================== |
*/ |
package cz.aiken.util.jincron; |
import javax.swing.table.*; |
import java.util.*; |
import java.io.*; |
/** |
* |
* @author luk |
*/ |
public class ICTableModel extends AbstractTableModel { |
private ArrayList<ICRow> rows = new ArrayList<ICRow>(); |
/** Creates a new instance of ICTableModel */ |
public ICTableModel() { |
} |
public Object getValueAt(int rowIndex, int columnIndex) { |
ICRow r = rows.get(rowIndex); |
Object o = null; |
switch (columnIndex) { |
case 0: o = r.getPath(); |
break; |
case 1: o = r.getEvent().toString(); |
break; |
case 2: o = r.getCommand(); |
break; |
default:; |
} |
return o; |
} |
public int getRowCount() { |
return rows.size(); |
} |
public int getColumnCount() { |
return ICRow.getFieldCount(); |
} |
public String getColumnName(int column) { |
switch (column) { |
case 0: return "Path"; |
case 1: return "Events"; |
case 2: return "Command"; |
default: return ""; |
} |
} |
public ICRow getRow(int index) { |
return rows.get(index); |
} |
public void updateRow(int index, ICRow row) { |
rows.set(index, row); |
fireTableRowsUpdated(index, index); |
} |
public void addRow(ICRow r) { |
rows.add(r); |
int index = rows.size() - 1; |
fireTableRowsInserted(index, index); |
} |
public void removeRows(int start, int end) { |
for (int i=end; i>=start; i--) |
rows.remove(i); |
fireTableRowsDeleted(start, end); |
} |
public void clear() { |
int size = rows.size(); |
rows.clear(); |
fireTableRowsDeleted(0, size - 1); |
} |
public String toString() { |
StringBuilder sb = new StringBuilder(); |
Iterator<ICRow> it = rows.iterator(); |
String sep = System.getProperty("line.separator"); |
while (it.hasNext()) { |
ICRow r = it.next(); |
sb.append(r.toString()); |
sb.append(sep); |
} |
return sb.toString(); |
} |
public void exportTable(Writer w) throws IOException { |
w.write(toString()); |
} |
public void importTable(Reader r) throws IOException { |
BufferedReader br = new BufferedReader(r); |
int end = rows.size() - 1; |
if (end > -1) { |
rows.clear(); |
fireTableRowsDeleted(0, end); |
} |
String s = ""; |
while ((s = br.readLine()) != null) { |
ICRow row = ICRow.parse(s); |
if (row != null) |
rows.add(row); |
} |
end = rows.size() - 1; |
if (end > -1) { |
fireTableRowsInserted(0, end); |
} |
} |
public void exportToFile(File f) throws IOException { |
FileWriter fw = new FileWriter(f); |
exportTable(fw); |
fw.close(); |
} |
public void importFromFile(File f) throws IOException { |
FileReader fr = new FileReader(f); |
importTable(fr); |
fr.close(); |
} |
} |
/jincron/trunk/cz/aiken/util/jincron/Main.java |
---|
0,0 → 1,53 |
/* |
* Main.java - jIncron main class |
* |
* Copyright (c) 2006 Lukas Jelinek, http://www.aiken.cz |
* |
* ========================================================================== |
* |
* This program is free software; you can redistribute it and/or modify |
* it under the terms of the GNU General Public License Version 2 as |
* published by the Free Software Foundation. |
* |
* This program is distributed in the hope that it will be useful, |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* GNU General Public License for more details. |
* |
* You should have received a copy of the GNU General Public License |
* along with this program; if not, write to the Free Software |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* |
* ========================================================================== |
*/ |
package cz.aiken.util.jincron; |
import javax.swing.*; |
/** |
* |
* @author luk |
*/ |
public class Main implements Runnable { |
/** Creates a new instance of Main */ |
public Main() { |
} |
public void run() { |
ICFrame f = new ICFrame(); |
f.setVisible(true); |
} |
/** |
* @param args the command line arguments |
*/ |
public static void main(String[] args) { |
ICConfig.load(); |
Main m = new Main(); |
SwingUtilities.invokeLater(m); |
} |
} |
/jincron/trunk/cz/aiken/util/jincron/ICFrame.java |
---|
0,0 → 1,343 |
/* |
* ICFrame.java - jIncron application GUI frame |
* |
* Copyright (c) 2006 Lukas Jelinek, http://www.aiken.cz |
* |
* ========================================================================== |
* |
* This program is free software; you can redistribute it and/or modify |
* it under the terms of the GNU General Public License Version 2 as |
* published by the Free Software Foundation. |
* |
* This program is distributed in the hope that it will be useful, |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* GNU General Public License for more details. |
* |
* You should have received a copy of the GNU General Public License |
* along with this program; if not, write to the Free Software |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* |
* ========================================================================== |
*/ |
package cz.aiken.util.jincron; |
import java.awt.*; |
import java.awt.event.*; |
import java.io.*; |
import javax.swing.*; |
import javax.swing.event.*; |
import javax.swing.table.*; |
/** |
* |
* @author luk |
*/ |
public class ICFrame extends JFrame implements ActionListener, ListSelectionListener { |
private static final String pgmName = "jIncron"; |
private JMenuBar menubar = new JMenuBar(); |
private JMenuItem editRowItem = null; |
private JMenuItem removeRowItem = null; |
private JButton addBut = new JButton("Add..."); |
private JButton editBut = new JButton("Edit..."); |
private JButton removeBut = new JButton("Remove"); |
private JPanel butPanel = new JPanel(); |
private ICTableModel model = new ICTableModel(); |
private JTable table = null; |
private boolean changed = false; |
/** Creates a new instance of ICFrame */ |
public ICFrame() { |
super(); |
init(); |
} |
protected void init() { |
setSize(ICConfig.getWindowSize()); |
setLocation(ICConfig.getWindowLocation()); |
setDefaultCloseOperation(DISPOSE_ON_CLOSE); |
updateTitle(); |
initMenus(); |
initButtons(); |
table = new JTable(model); |
table.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); |
table.getSelectionModel().addListSelectionListener(this); |
JScrollPane jsp = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); |
JSplitPane spl = new JSplitPane(JSplitPane.VERTICAL_SPLIT, butPanel, jsp); |
setContentPane(spl); |
load(); |
updateMenus(); |
updateButtons(); |
} |
protected void initButtons() { |
butPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); |
initButton(addBut, "add", "Add a new rule"); |
initButton(editBut, "edit", "Edit the selected rule"); |
initButton(removeBut, "remove", "Remove the selected rule(s)"); |
} |
protected void initButton(JButton but, String cmd, String tooltip) { |
but.setActionCommand(cmd); |
but.addActionListener(this); |
but.setToolTipText(tooltip); |
butPanel.add(but); |
} |
protected void initMenus() { |
JMenu menu = new JMenu("File"); |
initMenuItem("New", 'n', KeyStroke.getKeyStroke(KeyEvent.VK_N, InputEvent.CTRL_MASK), "new", this, menu); |
initMenuItem("Load", 'l', KeyStroke.getKeyStroke(KeyEvent.VK_L, InputEvent.CTRL_MASK), "load", this, menu); |
initMenuItem("Save", 's', KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK), "save", this, menu); |
menu.addSeparator(); |
initMenuItem("Import...", 'i', KeyStroke.getKeyStroke(KeyEvent.VK_I, InputEvent.CTRL_MASK), "import", this, menu); |
initMenuItem("Export...", 'x', KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK), "export", this, menu); |
menu.addSeparator(); |
initMenuItem("Quit", 'q', KeyStroke.getKeyStroke(KeyEvent.VK_Q, InputEvent.ALT_MASK), "quit", this, menu); |
menubar.add(menu); |
menu = new JMenu("Action"); |
initMenuItem("Add...", 'a', KeyStroke.getKeyStroke(KeyEvent.VK_A, InputEvent.CTRL_MASK), "add", this, menu); |
editRowItem = initMenuItem("Edit...", 'e', KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.CTRL_MASK), "edit", this, menu); |
removeRowItem = initMenuItem("Remove", 'v', KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_MASK), "remove", this, menu); |
menubar.add(menu); |
menu = new JMenu("Help"); |
initMenuItem("About", 'b', KeyStroke.getKeyStroke(KeyEvent.VK_B, InputEvent.CTRL_MASK), "about", this, menu); |
menubar.add(menu); |
setJMenuBar(menubar); |
} |
protected JMenuItem initMenuItem(String text, int mnemo, KeyStroke accel, String cmd, ActionListener al, JMenu menu) { |
JMenuItem it = new JMenuItem(text, mnemo); |
it.setAccelerator(accel); |
it.setActionCommand(cmd); |
it.addActionListener(al); |
menu.add(it); |
return it; |
} |
protected void updateTitle() { |
if (changed) { |
setTitle(pgmName + " (modified)"); |
} |
else { |
setTitle(pgmName); |
} |
} |
protected void updateButtons() { |
int cnt = table.getSelectedRowCount(); |
editBut.setEnabled(cnt == 1); |
removeBut.setEnabled(cnt > 0); |
} |
protected void updateMenus() { |
int cnt = table.getSelectedRowCount(); |
editRowItem.setEnabled(cnt == 1); |
removeRowItem.setEnabled(cnt > 0); |
} |
protected void setModified(boolean b) { |
changed = b; |
updateTitle(); |
} |
protected void load() { |
ProcessBuilder pb = new ProcessBuilder("incrontab", "--list"); |
try { |
Process p = pb.start(); |
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); |
model.importTable(br); |
br.close(); |
boolean end = false; |
while (!end) { |
try { |
p.waitFor(); |
end = true; |
} catch (InterruptedException ex) {} |
} |
setModified(false); |
} catch (IOException e) { |
JOptionPane.showMessageDialog(this, "Loading incron table failed: " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); |
} |
} |
protected void save() { |
ProcessBuilder pb = new ProcessBuilder("incrontab", "-"); |
try { |
Process p = pb.start(); |
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(p.getOutputStream())); |
model.exportTable(bw); |
bw.close(); |
boolean end = false; |
while (!end) { |
try { |
int ev = p.waitFor(); |
if (ev != 0) |
throw new IOException("incrontab return value: " + ev); |
end = true; |
} catch (InterruptedException ex) {} |
} |
JOptionPane.showMessageDialog(this, "Table successfully saved.", "Success", JOptionPane.INFORMATION_MESSAGE); |
setModified(false); |
} catch (IOException e) { |
JOptionPane.showMessageDialog(this, "Saving incron table failed: " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); |
} |
} |
protected void doExport() { |
try { |
JFileChooser fc = new JFileChooser(); |
fc.setDialogTitle("Export incron table"); |
fc.setDialogType(JFileChooser.SAVE_DIALOG); |
fc.setMultiSelectionEnabled(false); |
int res = fc.showSaveDialog(this); |
if (res == JFileChooser.APPROVE_OPTION) { |
File f = fc.getSelectedFile(); |
if (f.exists()) { |
res = JOptionPane.showConfirmDialog(this, "Selected file already exists. Overwrite?", "File exists", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); |
if (res != JOptionPane.YES_OPTION) |
return; |
} |
model.exportToFile(f); |
JOptionPane.showMessageDialog(this, "Table successfully exported.", "Success", JOptionPane.INFORMATION_MESSAGE); |
} |
else if (res == JFileChooser.ERROR_OPTION) { |
JOptionPane.showMessageDialog(this, "Error occurred while selecting file for export.", "Error", JOptionPane.ERROR_MESSAGE); |
} |
} catch (IOException e) { |
JOptionPane.showMessageDialog(this, "Cannot export table to file: " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); |
} |
} |
protected void doImport() { |
try { |
JFileChooser fc = new JFileChooser(); |
fc.setDialogTitle("Import incron table"); |
fc.setDialogType(JFileChooser.OPEN_DIALOG); |
fc.setMultiSelectionEnabled(false); |
int res = fc.showOpenDialog(this); |
if (res == JFileChooser.APPROVE_OPTION) { |
File f = fc.getSelectedFile(); |
model.importFromFile(f); |
JOptionPane.showMessageDialog(this, "Table successfully imported.", "Success", JOptionPane.INFORMATION_MESSAGE); |
setModified(true); |
} |
else if (res == JFileChooser.ERROR_OPTION) { |
JOptionPane.showMessageDialog(this, "Error occurred while selecting file for import.", "Error", JOptionPane.ERROR_MESSAGE); |
} |
} catch (IOException e) { |
JOptionPane.showMessageDialog(this, "Cannot import table from file: " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); |
setModified(true); |
} |
} |
protected void addRow() { |
ICPropDialog dg = new ICPropDialog(new ICRow("", new InotifyEvent(0, 0), "")); |
dg.setVisible(true); |
dg.dispose(); |
if (dg.isCommitted() && dg.isModified()) { |
model.addRow(dg.getData()); |
setModified(true); |
} |
} |
protected void editRow() { |
int ia[] = table.getSelectedRows(); |
if (ia.length == 1) { |
ICPropDialog dg = new ICPropDialog(model.getRow(ia[0])); |
dg.setVisible(true); |
dg.dispose(); |
if (dg.isCommitted() && dg.isModified()) { |
model.updateRow(ia[0], dg.getData()); |
setModified(true); |
} |
} |
} |
protected void removeRow() { |
int ia[] = table.getSelectedRows(); |
if (ia.length > 0) { |
model.removeRows(ia[0], ia[ia.length-1]); |
setModified(true); |
} |
} |
protected void doDispose() { |
ICConfig.setWindowSize(getSize()); |
ICConfig.setWindowLocation(getLocation()); |
ICConfig.save(); |
super.dispose(); |
} |
public void dispose() { |
if (changed) { |
int opt = JOptionPane.showConfirmDialog(this, |
"Table data has been modified but not saved.\nDo you want to save it before closing?", "Unsaved data", |
JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE); |
switch (opt) { |
case JOptionPane.YES_OPTION: |
save(); |
case JOptionPane.NO_OPTION: |
doDispose(); |
default:; |
} |
} |
else { |
doDispose(); |
} |
} |
public void actionPerformed(ActionEvent e) { |
String s = e.getActionCommand(); |
if (s.equals("new")) { |
model.clear(); |
setModified(true); |
} |
else if (s.equals("load")) { |
load(); |
} |
else if (s.equals("save")) { |
save(); |
} |
else if (s.equals("import")) { |
doImport(); |
} |
else if (s.equals("export")) { |
doExport(); |
} |
else if (s.equals("quit")) { |
dispose(); |
} |
else if (s.equals("add")) { |
addRow(); |
} |
else if (s.equals("edit")) { |
editRow(); |
} |
else if (s.equals("remove")) { |
removeRow(); |
} |
else if (s.equals("about")) { |
JOptionPane.showMessageDialog(this, "jIncron 0.1.0", "About jIncron", JOptionPane.INFORMATION_MESSAGE); |
} |
} |
public void valueChanged(ListSelectionEvent e) { |
updateMenus(); |
updateButtons(); |
} |
} |
/jincron/trunk/cz/aiken/util/jincron/ICPropDialog.java |
---|
0,0 → 1,361 |
/* |
* ICPropDialog.java - incron table rule properties dialog |
* |
* Copyright (c) 2006 Lukas Jelinek, http://www.aiken.cz |
* |
* ========================================================================== |
* |
* This program is free software; you can redistribute it and/or modify |
* it under the terms of the GNU General Public License Version 2 as |
* published by the Free Software Foundation. |
* |
* This program is distributed in the hope that it will be useful, |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* GNU General Public License for more details. |
* |
* You should have received a copy of the GNU General Public License |
* along with this program; if not, write to the Free Software |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* |
* ========================================================================== |
*/ |
package cz.aiken.util.jincron; |
import java.awt.*; |
import java.awt.event.*; |
import javax.swing.*; |
import javax.swing.event.*; |
import javax.swing.text.*; |
import java.io.*; |
import java.util.*; |
/** |
* |
* @author luk |
*/ |
public class ICPropDialog extends JDialog implements ActionListener, UndoableEditListener { |
private static final String title = "Rule properties"; |
private boolean changed = false; |
private boolean commit = false; |
private JTextField path = new JTextField(); |
private JButton pathBut = new JButton("Browse..."); |
private JPanel events = new JPanel(); |
private JPanel cmd = new JPanel(); |
private JTextField cmdText = new JTextField(); |
private InotifyEvent evt = null; |
private HashMap<Integer, JCheckBox> mask = new HashMap<Integer, JCheckBox>(); |
private HashMap<Integer, JCheckBox> flags = new HashMap<Integer, JCheckBox>(); |
/** Creates a new instance of ICPropDialog */ |
public ICPropDialog(ICRow row) { |
super(); |
init(row); |
} |
protected void init(ICRow row) { |
Container c = getContentPane(); |
c.setLayout(null); |
setSize(480, 470); |
setLocation(200, 200); |
setModal(true); |
setResizable(false); |
updateTitle(); |
JLabel lab = new JLabel("Path"); |
lab.setSize(55, 20); |
lab.setLocation(20, 20); |
c.add(lab); |
path.setSize(280, 20); |
path.setLocation(60, 20); |
path.setText(row.getPath()); |
path.getDocument().addUndoableEditListener(this); |
path.setToolTipText("Specify the path to be watched"); |
c.add(path); |
pathBut.setSize(100, 20); |
pathBut.setLocation(350, 20); |
pathBut.setActionCommand("path"); |
pathBut.addActionListener(this); |
pathBut.setToolTipText("Browse the filesystem for a watch path"); |
c.add(pathBut); |
evt = new InotifyEvent(row.getEvent()); |
events.setSize(435, 200); |
events.setLocation(20, 50); |
events.setLayout(null); |
events.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Events")); |
c.add(events); |
createCheckbox("all events", 130, 20, 20, 20, "IN_ALL_EVENTS", "Watch all events", events, mask, InotifyEvent.IN_ALL_EVENTS); |
createCheckbox("access", 130, 20, 20, 45, "IN_ACCESS", "Watch accesses to file(s)", events, mask, InotifyEvent.IN_ACCESS); |
createCheckbox("modify", 130, 20, 20, 70, "IN_MODIFY", "Watch file(s) modifications", events, mask, InotifyEvent.IN_MODIFY); |
createCheckbox("attr. change", 130, 20, 20, 95, "IN_ATTRIB", "Watch attribute (metadata) changes", events, mask, InotifyEvent.IN_ATTRIB); |
createCheckbox("close", 130, 20, 20, 120, "IN_CLOSE", "Watch close events", events, mask, InotifyEvent.IN_CLOSE); |
createCheckbox("close (write)", 130, 20, 20, 145, "IN_CLOSE_WRITE", "Watch close events with writing", events, mask, InotifyEvent.IN_CLOSE_WRITE); |
createCheckbox("close (no write)", 130, 20, 20, 170, "IN_CLOSE_NOWRITE", "Watch close events without writing", events, mask, InotifyEvent.IN_CLOSE_NOWRITE); |
createCheckbox("open", 130, 20, 160, 45, "IN_OPEN", "Watch open events", events, mask, InotifyEvent.IN_OPEN); |
createCheckbox("move", 130, 20, 160, 70, "IN_MOVE", "Watch file moves", events, mask, InotifyEvent.IN_MOVE); |
createCheckbox("moved from", 130, 20, 160, 95, "IN_MOVED_FROM", "Watch events on file(s) moved out", events, mask, InotifyEvent.IN_MOVED_FROM); |
createCheckbox("moved to", 130, 20, 160, 120, "IN_MOVED_TO", "Watch events on file(s) moved in", events, mask, InotifyEvent.IN_MOVED_TO); |
createCheckbox("create", 130, 20, 160, 145, "IN_CREATE", "Watch creations", events, mask, InotifyEvent.IN_CREATE); |
createCheckbox("delete", 130, 20, 160, 170, "IN_DELETE", "Watch deletions (unlinks)", events, mask, InotifyEvent.IN_DELETE); |
createCheckbox("delete self", 130, 20, 300, 45, "IN_DELETE_SELF", "Watch the watched path is destroyed", events, mask, InotifyEvent.IN_DELETE_SELF); |
createCheckbox("dir only", 130, 20, 300, 70, "IN_ONLYDIR", "Watch only directory events", events, mask, InotifyEvent.IN_ONLYDIR); |
createCheckbox("don't follow", 130, 20, 300, 95, "IN_DONT_FOLLOW", "Don't follow symbolic links", events, mask, InotifyEvent.IN_DONT_FOLLOW); |
createCheckbox("oneshot", 130, 20, 300, 120, "IN_ONESHOT", "Watch exactly one event", events, mask, InotifyEvent.IN_ONESHOT); |
createCheckbox("no loop", 130, 20, 300, 170, "IN_NO_LOOP", "Avoid looping", events, flags, InotifyEvent.IN_NO_LOOP); |
updateCheckboxes(); |
cmd.setSize(435, 130); |
cmd.setLocation(20, 260); |
cmd.setLayout(null); |
cmd.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Command")); |
c.add(cmd); |
cmdText.setSize(390, 20); |
cmdText.setLocation(20, 30); |
cmdText.setText(row.getCommand()); |
cmdText.getDocument().addUndoableEditListener(this); |
cmdText.setToolTipText("Specify a command here"); |
cmd.add(cmdText); |
JButton but = new JButton("Watch path"); |
but.setSize(190, 20); |
but.setLocation(20, 60); |
but.setActionCommand("watch_path"); |
but.addActionListener(this); |
but.setToolTipText("Insert a symbol for watch path"); |
cmd.add(but); |
but = new JButton("Event name"); |
but.setSize(190, 20); |
but.setLocation(220, 60); |
but.setActionCommand("event_name"); |
but.addActionListener(this); |
but.setToolTipText("Insert a symbol for watch name"); |
cmd.add(but); |
but = new JButton("Mask (symbolic)"); |
but.setSize(190, 20); |
but.setLocation(20, 90); |
but.setActionCommand("symbolic_mask"); |
but.addActionListener(this); |
but.setToolTipText("Insert a symbol for symbolic event mask"); |
cmd.add(but); |
but = new JButton("Mask (numeric)"); |
but.setSize(190, 20); |
but.setLocation(220, 90); |
but.setActionCommand("numeric_mask"); |
but.addActionListener(this); |
but.setToolTipText("Insert a symbol for numeric event mask"); |
cmd.add(but); |
but = new JButton("OK"); |
but.setSize(80, 20); |
but.setLocation(150, 400); |
but.setActionCommand("ok"); |
but.addActionListener(this); |
but.setToolTipText("Apply changes if any"); |
c.add(but); |
but = new JButton("Cancel"); |
but.setSize(80, 20); |
but.setLocation(240, 400); |
but.setActionCommand("cancel"); |
but.addActionListener(this); |
but.setToolTipText("Leave the dialog without applying changes"); |
c.add(but); |
} |
protected void createCheckbox(String text, int width, int height, int x, int y, String cmd, String tooltip, Container c, HashMap<Integer, JCheckBox> map, int mapVal) { |
JCheckBox cb = new JCheckBox(text); |
cb.setLocation(x, y); |
cb.setSize(width, height); |
cb.addActionListener(this); |
cb.setActionCommand(cmd); |
cb.setToolTipText(tooltip); |
c.add(cb); |
map.put(new Integer(mapVal), cb); |
} |
protected void browsePath() { |
JFileChooser fc = new JFileChooser(); |
fc.setDialogTitle("Watch path"); |
fc.setDialogType(JFileChooser.OPEN_DIALOG); |
fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); |
fc.setMultiSelectionEnabled(false); |
fc.setSelectedFile(new File(path.getText())); |
int res = fc.showDialog(this, "Select"); |
if (res == JFileChooser.APPROVE_OPTION) { |
path.setText(fc.getSelectedFile().getAbsolutePath()); |
} |
} |
protected void addCmdText(String txt) { |
String s = cmdText.getText(); |
int start = cmdText.getSelectionStart(); |
int end = cmdText.getSelectionEnd(); |
if (start != -1 || end != -1) { |
cmdText.setText(s.substring(0, start) + txt + s.substring(end)); |
cmdText.setCaretPosition(start + txt.length()); |
} |
else { |
int pos = cmdText.getCaretPosition(); |
if (pos != -1) { |
cmdText.setText(s.substring(0, pos) + txt + s.substring(pos)); |
cmdText.setCaretPosition(pos + txt.length()); |
} |
else { |
cmdText.setText(s + txt); |
cmdText.setCaretPosition(s.length() + txt.length()); |
} |
} |
cmdText.requestFocusInWindow(); |
} |
protected void updateTitle() { |
if (changed) |
setTitle(title + " (modified)"); |
else |
setTitle(title); |
} |
protected void updateCheckboxes() { |
Iterator<Integer> it = mask.keySet().iterator(); |
while (it.hasNext()) { |
Integer i = it.next(); |
JCheckBox cb = mask.get(i); |
if (cb != null) { |
cb.getModel().setSelected(evt.hasMask(i.intValue())); |
} |
} |
it = flags.keySet().iterator(); |
while (it.hasNext()) { |
Integer i = it.next(); |
JCheckBox cb = flags.get(i); |
if (cb != null) { |
cb.getModel().setSelected(evt.hasFlags(i.intValue())); |
} |
} |
} |
protected void modifyEvent(int val, boolean fl) { |
if (fl) { |
JCheckBox cb = flags.get(val); |
if (cb != null) { |
evt.changeFlags(val, cb.getModel().isSelected()); |
} |
} |
else { |
JCheckBox cb = mask.get(val); |
if (cb != null) { |
evt.changeMask(val, cb.getModel().isSelected()); |
} |
} |
updateCheckboxes(); |
changed = true; |
updateTitle(); |
} |
public ICRow getData() { |
return new ICRow(path.getText(), evt, cmdText.getText()); |
} |
public boolean isModified() { |
return changed; |
} |
public boolean isCommitted() { |
return commit; |
} |
protected boolean validateData() { |
if (path.getText().length() == 0) { |
JOptionPane.showMessageDialog(this, "The watch path must not be empty.", "Error", JOptionPane.ERROR_MESSAGE); |
return false; |
} |
if (!(new File(path.getText())).exists()) { |
JOptionPane.showMessageDialog(this, "The watch path does not exist.\nThis is not an error but incrond will ignore such rules.", "Warning", JOptionPane.WARNING_MESSAGE); |
} |
if (evt.getMask() == 0) { |
JOptionPane.showMessageDialog(this, "At least one event type must be watched.", "Error", JOptionPane.ERROR_MESSAGE); |
return false; |
} |
if (cmdText.getText().length() == 0) { |
JOptionPane.showMessageDialog(this, "The command must not be empty.", "Error", JOptionPane.ERROR_MESSAGE); |
return false; |
} |
return true; |
} |
public void actionPerformed(ActionEvent e) { |
String s = e.getActionCommand(); |
if (s.equals("path")) { |
browsePath(); |
} |
else if (s.equals("watch_path")) { |
addCmdText("$@"); |
} |
else if (s.equals("event_name")) { |
addCmdText("$#"); |
} |
else if (s.equals("symbolic_mask")) { |
addCmdText("$%"); |
} |
else if (s.equals("numeric_mask")) { |
addCmdText("$&"); |
} |
else if (s.equals("ok")) { |
if (validateData()) { |
commit = true; |
setVisible(false); |
} |
} |
else if (s.equals("cancel")) { |
setVisible(false); |
} |
else { |
int i = InotifyEvent.getMaskByName(s); |
if (i != 0) { |
modifyEvent(i, false); |
return; |
} |
i = InotifyEvent.getFlagsByName(s); |
if (i != 0) { |
modifyEvent(i, true); |
} |
} |
} |
public void undoableEditHappened(UndoableEditEvent e) { |
changed = true; |
updateTitle(); |
} |
} |
/jincron/trunk/README |
---|
0,0 → 1,55 |
jIncron - incron graphical interface |
(c) Lukas Jelinek, 2006 |
1. About |
2. Requirements |
3. How to run |
4. Bugs, suggestions |
5. Licensing |
6. Documentation |
======================================================================== |
1. About |
This program is a incron graphical interface. It is intended for |
simplier use of incron on graphical desktops. |
2. Requirements |
* Linux kernel 2.6.13 or later (with inotify compiled in) |
* graphical environment (X11) |
* incron installed |
* Java installed (at least Java 5 a.k.a. 1.5.0) |
3. How to run |
Go into the directory with jincron.jar and type: |
java -jar jincron.jar |
That's all. Enjoy! |
4. Bugs, suggestions |
THIS PROGRAM IS AN ALPHA VERSION. IT PROBABLY CONTAINS BUGS AND |
THEREFORE IT IS NOT INTENDED FOR PRODUCTION USE. |
If you find a bug or have a suggestion how to improve the program, |
please use the bug tracking system at http://bts.aiken.cz. |
This version assumes your incron has been compiled with all |
available inotify flags. |
5. Licensing |
This program is free software; you can redistribute it and/or |
modify it under the terms of the GNU General Public License, |
version 2. See COPYING for details. |
6. Documentation |
Documentation is not yet available. Please be patient. |