hzzz
7 years ago
102 changed files with 7912 additions and 1388 deletions
@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE |
||||
Version 3, 29 June 2007 |
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> |
||||
Everyone is permitted to copy and distribute verbatim copies |
||||
of this license document, but changing it is not allowed. |
||||
|
||||
Preamble |
||||
|
||||
The GNU General Public License is a free, copyleft license for |
||||
software and other kinds of works. |
||||
|
||||
The licenses for most software and other practical works are designed |
||||
to take away your freedom to share and change the works. By contrast, |
||||
the GNU General Public License is intended to guarantee your freedom to |
||||
share and change all versions of a program--to make sure it remains free |
||||
software for all its users. We, the Free Software Foundation, use the |
||||
GNU General Public License for most of our software; it applies also to |
||||
any other work released this way by its authors. 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 |
||||
them 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 prevent others from denying you |
||||
these rights or asking you to surrender the rights. Therefore, you have |
||||
certain responsibilities if you distribute copies of the software, or if |
||||
you modify it: responsibilities to respect the freedom of others. |
||||
|
||||
For example, if you distribute copies of such a program, whether |
||||
gratis or for a fee, you must pass on to the recipients the same |
||||
freedoms that you received. 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. |
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps: |
||||
(1) assert copyright on the software, and (2) offer you this License |
||||
giving you legal permission to copy, distribute and/or modify it. |
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains |
||||
that there is no warranty for this free software. For both users' and |
||||
authors' sake, the GPL requires that modified versions be marked as |
||||
changed, so that their problems will not be attributed erroneously to |
||||
authors of previous versions. |
||||
|
||||
Some devices are designed to deny users access to install or run |
||||
modified versions of the software inside them, although the manufacturer |
||||
can do so. This is fundamentally incompatible with the aim of |
||||
protecting users' freedom to change the software. The systematic |
||||
pattern of such abuse occurs in the area of products for individuals to |
||||
use, which is precisely where it is most unacceptable. Therefore, we |
||||
have designed this version of the GPL to prohibit the practice for those |
||||
products. If such problems arise substantially in other domains, we |
||||
stand ready to extend this provision to those domains in future versions |
||||
of the GPL, as needed to protect the freedom of users. |
||||
|
||||
Finally, every program is threatened constantly by software patents. |
||||
States should not allow patents to restrict development and use of |
||||
software on general-purpose computers, but in those that do, we wish to |
||||
avoid the special danger that patents applied to a free program could |
||||
make it effectively proprietary. To prevent this, the GPL assures that |
||||
patents cannot be used to render the program non-free. |
||||
|
||||
The precise terms and conditions for copying, distribution and |
||||
modification follow. |
||||
|
||||
TERMS AND CONDITIONS |
||||
|
||||
0. Definitions. |
||||
|
||||
"This License" refers to version 3 of the GNU General Public License. |
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of |
||||
works, such as semiconductor masks. |
||||
|
||||
"The Program" refers to any copyrightable work licensed under this |
||||
License. Each licensee is addressed as "you". "Licensees" and |
||||
"recipients" may be individuals or organizations. |
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work |
||||
in a fashion requiring copyright permission, other than the making of an |
||||
exact copy. The resulting work is called a "modified version" of the |
||||
earlier work or a work "based on" the earlier work. |
||||
|
||||
A "covered work" means either the unmodified Program or a work based |
||||
on the Program. |
||||
|
||||
To "propagate" a work means to do anything with it that, without |
||||
permission, would make you directly or secondarily liable for |
||||
infringement under applicable copyright law, except executing it on a |
||||
computer or modifying a private copy. Propagation includes copying, |
||||
distribution (with or without modification), making available to the |
||||
public, and in some countries other activities as well. |
||||
|
||||
To "convey" a work means any kind of propagation that enables other |
||||
parties to make or receive copies. Mere interaction with a user through |
||||
a computer network, with no transfer of a copy, is not conveying. |
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices" |
||||
to the extent that it includes a convenient and prominently visible |
||||
feature that (1) displays an appropriate copyright notice, and (2) |
||||
tells the user that there is no warranty for the work (except to the |
||||
extent that warranties are provided), that licensees may convey the |
||||
work under this License, and how to view a copy of this License. If |
||||
the interface presents a list of user commands or options, such as a |
||||
menu, a prominent item in the list meets this criterion. |
||||
|
||||
1. Source Code. |
||||
|
||||
The "source code" for a work means the preferred form of the work |
||||
for making modifications to it. "Object code" means any non-source |
||||
form of a work. |
||||
|
||||
A "Standard Interface" means an interface that either is an official |
||||
standard defined by a recognized standards body, or, in the case of |
||||
interfaces specified for a particular programming language, one that |
||||
is widely used among developers working in that language. |
||||
|
||||
The "System Libraries" of an executable work include anything, other |
||||
than the work as a whole, that (a) is included in the normal form of |
||||
packaging a Major Component, but which is not part of that Major |
||||
Component, and (b) serves only to enable use of the work with that |
||||
Major Component, or to implement a Standard Interface for which an |
||||
implementation is available to the public in source code form. A |
||||
"Major Component", in this context, means a major essential component |
||||
(kernel, window system, and so on) of the specific operating system |
||||
(if any) on which the executable work runs, or a compiler used to |
||||
produce the work, or an object code interpreter used to run it. |
||||
|
||||
The "Corresponding Source" for a work in object code form means all |
||||
the source code needed to generate, install, and (for an executable |
||||
work) run the object code and to modify the work, including scripts to |
||||
control those activities. However, it does not include the work's |
||||
System Libraries, or general-purpose tools or generally available free |
||||
programs which are used unmodified in performing those activities but |
||||
which are not part of the work. For example, Corresponding Source |
||||
includes interface definition files associated with source files for |
||||
the work, and the source code for shared libraries and dynamically |
||||
linked subprograms that the work is specifically designed to require, |
||||
such as by intimate data communication or control flow between those |
||||
subprograms and other parts of the work. |
||||
|
||||
The Corresponding Source need not include anything that users |
||||
can regenerate automatically from other parts of the Corresponding |
||||
Source. |
||||
|
||||
The Corresponding Source for a work in source code form is that |
||||
same work. |
||||
|
||||
2. Basic Permissions. |
||||
|
||||
All rights granted under this License are granted for the term of |
||||
copyright on the Program, and are irrevocable provided the stated |
||||
conditions are met. This License explicitly affirms your unlimited |
||||
permission to run the unmodified Program. The output from running a |
||||
covered work is covered by this License only if the output, given its |
||||
content, constitutes a covered work. This License acknowledges your |
||||
rights of fair use or other equivalent, as provided by copyright law. |
||||
|
||||
You may make, run and propagate covered works that you do not |
||||
convey, without conditions so long as your license otherwise remains |
||||
in force. You may convey covered works to others for the sole purpose |
||||
of having them make modifications exclusively for you, or provide you |
||||
with facilities for running those works, provided that you comply with |
||||
the terms of this License in conveying all material for which you do |
||||
not control copyright. Those thus making or running the covered works |
||||
for you must do so exclusively on your behalf, under your direction |
||||
and control, on terms that prohibit them from making any copies of |
||||
your copyrighted material outside their relationship with you. |
||||
|
||||
Conveying under any other circumstances is permitted solely under |
||||
the conditions stated below. Sublicensing is not allowed; section 10 |
||||
makes it unnecessary. |
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law. |
||||
|
||||
No covered work shall be deemed part of an effective technological |
||||
measure under any applicable law fulfilling obligations under article |
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or |
||||
similar laws prohibiting or restricting circumvention of such |
||||
measures. |
||||
|
||||
When you convey a covered work, you waive any legal power to forbid |
||||
circumvention of technological measures to the extent such circumvention |
||||
is effected by exercising rights under this License with respect to |
||||
the covered work, and you disclaim any intention to limit operation or |
||||
modification of the work as a means of enforcing, against the work's |
||||
users, your or third parties' legal rights to forbid circumvention of |
||||
technological measures. |
||||
|
||||
4. Conveying Verbatim Copies. |
||||
|
||||
You may convey 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; |
||||
keep intact all notices stating that this License and any |
||||
non-permissive terms added in accord with section 7 apply to the code; |
||||
keep intact all notices of the absence of any warranty; and give all |
||||
recipients a copy of this License along with the Program. |
||||
|
||||
You may charge any price or no price for each copy that you convey, |
||||
and you may offer support or warranty protection for a fee. |
||||
|
||||
5. Conveying Modified Source Versions. |
||||
|
||||
You may convey a work based on the Program, or the modifications to |
||||
produce it from the Program, in the form of source code under the |
||||
terms of section 4, provided that you also meet all of these conditions: |
||||
|
||||
a) The work must carry prominent notices stating that you modified |
||||
it, and giving a relevant date. |
||||
|
||||
b) The work must carry prominent notices stating that it is |
||||
released under this License and any conditions added under section |
||||
7. This requirement modifies the requirement in section 4 to |
||||
"keep intact all notices". |
||||
|
||||
c) You must license the entire work, as a whole, under this |
||||
License to anyone who comes into possession of a copy. This |
||||
License will therefore apply, along with any applicable section 7 |
||||
additional terms, to the whole of the work, and all its parts, |
||||
regardless of how they are packaged. This License gives no |
||||
permission to license the work in any other way, but it does not |
||||
invalidate such permission if you have separately received it. |
||||
|
||||
d) If the work has interactive user interfaces, each must display |
||||
Appropriate Legal Notices; however, if the Program has interactive |
||||
interfaces that do not display Appropriate Legal Notices, your |
||||
work need not make them do so. |
||||
|
||||
A compilation of a covered work with other separate and independent |
||||
works, which are not by their nature extensions of the covered work, |
||||
and which are not combined with it such as to form a larger program, |
||||
in or on a volume of a storage or distribution medium, is called an |
||||
"aggregate" if the compilation and its resulting copyright are not |
||||
used to limit the access or legal rights of the compilation's users |
||||
beyond what the individual works permit. Inclusion of a covered work |
||||
in an aggregate does not cause this License to apply to the other |
||||
parts of the aggregate. |
||||
|
||||
6. Conveying Non-Source Forms. |
||||
|
||||
You may convey a covered work in object code form under the terms |
||||
of sections 4 and 5, provided that you also convey the |
||||
machine-readable Corresponding Source under the terms of this License, |
||||
in one of these ways: |
||||
|
||||
a) Convey the object code in, or embodied in, a physical product |
||||
(including a physical distribution medium), accompanied by the |
||||
Corresponding Source fixed on a durable physical medium |
||||
customarily used for software interchange. |
||||
|
||||
b) Convey the object code in, or embodied in, a physical product |
||||
(including a physical distribution medium), accompanied by a |
||||
written offer, valid for at least three years and valid for as |
||||
long as you offer spare parts or customer support for that product |
||||
model, to give anyone who possesses the object code either (1) a |
||||
copy of the Corresponding Source for all the software in the |
||||
product that is covered by this License, on a durable physical |
||||
medium customarily used for software interchange, for a price no |
||||
more than your reasonable cost of physically performing this |
||||
conveying of source, or (2) access to copy the |
||||
Corresponding Source from a network server at no charge. |
||||
|
||||
c) Convey individual copies of the object code with a copy of the |
||||
written offer to provide the Corresponding Source. This |
||||
alternative is allowed only occasionally and noncommercially, and |
||||
only if you received the object code with such an offer, in accord |
||||
with subsection 6b. |
||||
|
||||
d) Convey the object code by offering access from a designated |
||||
place (gratis or for a charge), and offer equivalent access to the |
||||
Corresponding Source in the same way through the same place at no |
||||
further charge. You need not require recipients to copy the |
||||
Corresponding Source along with the object code. If the place to |
||||
copy the object code is a network server, the Corresponding Source |
||||
may be on a different server (operated by you or a third party) |
||||
that supports equivalent copying facilities, provided you maintain |
||||
clear directions next to the object code saying where to find the |
||||
Corresponding Source. Regardless of what server hosts the |
||||
Corresponding Source, you remain obligated to ensure that it is |
||||
available for as long as needed to satisfy these requirements. |
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided |
||||
you inform other peers where the object code and Corresponding |
||||
Source of the work are being offered to the general public at no |
||||
charge under subsection 6d. |
||||
|
||||
A separable portion of the object code, whose source code is excluded |
||||
from the Corresponding Source as a System Library, need not be |
||||
included in conveying the object code work. |
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any |
||||
tangible personal property which is normally used for personal, family, |
||||
or household purposes, or (2) anything designed or sold for incorporation |
||||
into a dwelling. In determining whether a product is a consumer product, |
||||
doubtful cases shall be resolved in favor of coverage. For a particular |
||||
product received by a particular user, "normally used" refers to a |
||||
typical or common use of that class of product, regardless of the status |
||||
of the particular user or of the way in which the particular user |
||||
actually uses, or expects or is expected to use, the product. A product |
||||
is a consumer product regardless of whether the product has substantial |
||||
commercial, industrial or non-consumer uses, unless such uses represent |
||||
the only significant mode of use of the product. |
||||
|
||||
"Installation Information" for a User Product means any methods, |
||||
procedures, authorization keys, or other information required to install |
||||
and execute modified versions of a covered work in that User Product from |
||||
a modified version of its Corresponding Source. The information must |
||||
suffice to ensure that the continued functioning of the modified object |
||||
code is in no case prevented or interfered with solely because |
||||
modification has been made. |
||||
|
||||
If you convey an object code work under this section in, or with, or |
||||
specifically for use in, a User Product, and the conveying occurs as |
||||
part of a transaction in which the right of possession and use of the |
||||
User Product is transferred to the recipient in perpetuity or for a |
||||
fixed term (regardless of how the transaction is characterized), the |
||||
Corresponding Source conveyed under this section must be accompanied |
||||
by the Installation Information. But this requirement does not apply |
||||
if neither you nor any third party retains the ability to install |
||||
modified object code on the User Product (for example, the work has |
||||
been installed in ROM). |
||||
|
||||
The requirement to provide Installation Information does not include a |
||||
requirement to continue to provide support service, warranty, or updates |
||||
for a work that has been modified or installed by the recipient, or for |
||||
the User Product in which it has been modified or installed. Access to a |
||||
network may be denied when the modification itself materially and |
||||
adversely affects the operation of the network or violates the rules and |
||||
protocols for communication across the network. |
||||
|
||||
Corresponding Source conveyed, and Installation Information provided, |
||||
in accord with this section must be in a format that is publicly |
||||
documented (and with an implementation available to the public in |
||||
source code form), and must require no special password or key for |
||||
unpacking, reading or copying. |
||||
|
||||
7. Additional Terms. |
||||
|
||||
"Additional permissions" are terms that supplement the terms of this |
||||
License by making exceptions from one or more of its conditions. |
||||
Additional permissions that are applicable to the entire Program shall |
||||
be treated as though they were included in this License, to the extent |
||||
that they are valid under applicable law. If additional permissions |
||||
apply only to part of the Program, that part may be used separately |
||||
under those permissions, but the entire Program remains governed by |
||||
this License without regard to the additional permissions. |
||||
|
||||
When you convey a copy of a covered work, you may at your option |
||||
remove any additional permissions from that copy, or from any part of |
||||
it. (Additional permissions may be written to require their own |
||||
removal in certain cases when you modify the work.) You may place |
||||
additional permissions on material, added by you to a covered work, |
||||
for which you have or can give appropriate copyright permission. |
||||
|
||||
Notwithstanding any other provision of this License, for material you |
||||
add to a covered work, you may (if authorized by the copyright holders of |
||||
that material) supplement the terms of this License with terms: |
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the |
||||
terms of sections 15 and 16 of this License; or |
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or |
||||
author attributions in that material or in the Appropriate Legal |
||||
Notices displayed by works containing it; or |
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or |
||||
requiring that modified versions of such material be marked in |
||||
reasonable ways as different from the original version; or |
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or |
||||
authors of the material; or |
||||
|
||||
e) Declining to grant rights under trademark law for use of some |
||||
trade names, trademarks, or service marks; or |
||||
|
||||
f) Requiring indemnification of licensors and authors of that |
||||
material by anyone who conveys the material (or modified versions of |
||||
it) with contractual assumptions of liability to the recipient, for |
||||
any liability that these contractual assumptions directly impose on |
||||
those licensors and authors. |
||||
|
||||
All other non-permissive additional terms are considered "further |
||||
restrictions" within the meaning of section 10. If the Program as you |
||||
received it, or any part of it, contains a notice stating that it is |
||||
governed by this License along with a term that is a further |
||||
restriction, you may remove that term. If a license document contains |
||||
a further restriction but permits relicensing or conveying under this |
||||
License, you may add to a covered work material governed by the terms |
||||
of that license document, provided that the further restriction does |
||||
not survive such relicensing or conveying. |
||||
|
||||
If you add terms to a covered work in accord with this section, you |
||||
must place, in the relevant source files, a statement of the |
||||
additional terms that apply to those files, or a notice indicating |
||||
where to find the applicable terms. |
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the |
||||
form of a separately written license, or stated as exceptions; |
||||
the above requirements apply either way. |
||||
|
||||
8. Termination. |
||||
|
||||
You may not propagate or modify a covered work except as expressly |
||||
provided under this License. Any attempt otherwise to propagate or |
||||
modify it is void, and will automatically terminate your rights under |
||||
this License (including any patent licenses granted under the third |
||||
paragraph of section 11). |
||||
|
||||
However, if you cease all violation of this License, then your |
||||
license from a particular copyright holder is reinstated (a) |
||||
provisionally, unless and until the copyright holder explicitly and |
||||
finally terminates your license, and (b) permanently, if the copyright |
||||
holder fails to notify you of the violation by some reasonable means |
||||
prior to 60 days after the cessation. |
||||
|
||||
Moreover, your license from a particular copyright holder is |
||||
reinstated permanently if the copyright holder notifies you of the |
||||
violation by some reasonable means, this is the first time you have |
||||
received notice of violation of this License (for any work) from that |
||||
copyright holder, and you cure the violation prior to 30 days after |
||||
your receipt of the notice. |
||||
|
||||
Termination of your rights under this section does not terminate the |
||||
licenses of parties who have received copies or rights from you under |
||||
this License. If your rights have been terminated and not permanently |
||||
reinstated, you do not qualify to receive new licenses for the same |
||||
material under section 10. |
||||
|
||||
9. Acceptance Not Required for Having Copies. |
||||
|
||||
You are not required to accept this License in order to receive or |
||||
run a copy of the Program. Ancillary propagation of a covered work |
||||
occurring solely as a consequence of using peer-to-peer transmission |
||||
to receive a copy likewise does not require acceptance. However, |
||||
nothing other than this License grants you permission to propagate or |
||||
modify any covered work. These actions infringe copyright if you do |
||||
not accept this License. Therefore, by modifying or propagating a |
||||
covered work, you indicate your acceptance of this License to do so. |
||||
|
||||
10. Automatic Licensing of Downstream Recipients. |
||||
|
||||
Each time you convey a covered work, the recipient automatically |
||||
receives a license from the original licensors, to run, modify and |
||||
propagate that work, subject to this License. You are not responsible |
||||
for enforcing compliance by third parties with this License. |
||||
|
||||
An "entity transaction" is a transaction transferring control of an |
||||
organization, or substantially all assets of one, or subdividing an |
||||
organization, or merging organizations. If propagation of a covered |
||||
work results from an entity transaction, each party to that |
||||
transaction who receives a copy of the work also receives whatever |
||||
licenses to the work the party's predecessor in interest had or could |
||||
give under the previous paragraph, plus a right to possession of the |
||||
Corresponding Source of the work from the predecessor in interest, if |
||||
the predecessor has it or can get it with reasonable efforts. |
||||
|
||||
You may not impose any further restrictions on the exercise of the |
||||
rights granted or affirmed under this License. For example, you may |
||||
not impose a license fee, royalty, or other charge for exercise of |
||||
rights granted under this License, and you may not initiate litigation |
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that |
||||
any patent claim is infringed by making, using, selling, offering for |
||||
sale, or importing the Program or any portion of it. |
||||
|
||||
11. Patents. |
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this |
||||
License of the Program or a work on which the Program is based. The |
||||
work thus licensed is called the contributor's "contributor version". |
||||
|
||||
A contributor's "essential patent claims" are all patent claims |
||||
owned or controlled by the contributor, whether already acquired or |
||||
hereafter acquired, that would be infringed by some manner, permitted |
||||
by this License, of making, using, or selling its contributor version, |
||||
but do not include claims that would be infringed only as a |
||||
consequence of further modification of the contributor version. For |
||||
purposes of this definition, "control" includes the right to grant |
||||
patent sublicenses in a manner consistent with the requirements of |
||||
this License. |
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free |
||||
patent license under the contributor's essential patent claims, to |
||||
make, use, sell, offer for sale, import and otherwise run, modify and |
||||
propagate the contents of its contributor version. |
||||
|
||||
In the following three paragraphs, a "patent license" is any express |
||||
agreement or commitment, however denominated, not to enforce a patent |
||||
(such as an express permission to practice a patent or covenant not to |
||||
sue for patent infringement). To "grant" such a patent license to a |
||||
party means to make such an agreement or commitment not to enforce a |
||||
patent against the party. |
||||
|
||||
If you convey a covered work, knowingly relying on a patent license, |
||||
and the Corresponding Source of the work is not available for anyone |
||||
to copy, free of charge and under the terms of this License, through a |
||||
publicly available network server or other readily accessible means, |
||||
then you must either (1) cause the Corresponding Source to be so |
||||
available, or (2) arrange to deprive yourself of the benefit of the |
||||
patent license for this particular work, or (3) arrange, in a manner |
||||
consistent with the requirements of this License, to extend the patent |
||||
license to downstream recipients. "Knowingly relying" means you have |
||||
actual knowledge that, but for the patent license, your conveying the |
||||
covered work in a country, or your recipient's use of the covered work |
||||
in a country, would infringe one or more identifiable patents in that |
||||
country that you have reason to believe are valid. |
||||
|
||||
If, pursuant to or in connection with a single transaction or |
||||
arrangement, you convey, or propagate by procuring conveyance of, a |
||||
covered work, and grant a patent license to some of the parties |
||||
receiving the covered work authorizing them to use, propagate, modify |
||||
or convey a specific copy of the covered work, then the patent license |
||||
you grant is automatically extended to all recipients of the covered |
||||
work and works based on it. |
||||
|
||||
A patent license is "discriminatory" if it does not include within |
||||
the scope of its coverage, prohibits the exercise of, or is |
||||
conditioned on the non-exercise of one or more of the rights that are |
||||
specifically granted under this License. You may not convey a covered |
||||
work if you are a party to an arrangement with a third party that is |
||||
in the business of distributing software, under which you make payment |
||||
to the third party based on the extent of your activity of conveying |
||||
the work, and under which the third party grants, to any of the |
||||
parties who would receive the covered work from you, a discriminatory |
||||
patent license (a) in connection with copies of the covered work |
||||
conveyed by you (or copies made from those copies), or (b) primarily |
||||
for and in connection with specific products or compilations that |
||||
contain the covered work, unless you entered into that arrangement, |
||||
or that patent license was granted, prior to 28 March 2007. |
||||
|
||||
Nothing in this License shall be construed as excluding or limiting |
||||
any implied license or other defenses to infringement that may |
||||
otherwise be available to you under applicable patent law. |
||||
|
||||
12. No Surrender of Others' Freedom. |
||||
|
||||
If 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 convey a |
||||
covered work so as to satisfy simultaneously your obligations under this |
||||
License and any other pertinent obligations, then as a consequence you may |
||||
not convey it at all. For example, if you agree to terms that obligate you |
||||
to collect a royalty for further conveying from those to whom you convey |
||||
the Program, the only way you could satisfy both those terms and this |
||||
License would be to refrain entirely from conveying the Program. |
||||
|
||||
13. Use with the GNU Affero General Public License. |
||||
|
||||
Notwithstanding any other provision of this License, you have |
||||
permission to link or combine any covered work with a work licensed |
||||
under version 3 of the GNU Affero General Public License into a single |
||||
combined work, and to convey the resulting work. The terms of this |
||||
License will continue to apply to the part which is the covered work, |
||||
but the special requirements of the GNU Affero General Public License, |
||||
section 13, concerning interaction through a network will apply to the |
||||
combination as such. |
||||
|
||||
14. Revised Versions of this License. |
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of |
||||
the GNU 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 that a certain numbered version of the GNU General |
||||
Public License "or any later version" applies to it, you have the |
||||
option of following the terms and conditions either of that numbered |
||||
version or of any later version published by the Free Software |
||||
Foundation. If the Program does not specify a version number of the |
||||
GNU General Public License, you may choose any version ever published |
||||
by the Free Software Foundation. |
||||
|
||||
If the Program specifies that a proxy can decide which future |
||||
versions of the GNU General Public License can be used, that proxy's |
||||
public statement of acceptance of a version permanently authorizes you |
||||
to choose that version for the Program. |
||||
|
||||
Later license versions may give you additional or different |
||||
permissions. However, no additional obligations are imposed on any |
||||
author or copyright holder as a result of your choosing to follow a |
||||
later version. |
||||
|
||||
15. Disclaimer of Warranty. |
||||
|
||||
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. |
||||
|
||||
16. Limitation of Liability. |
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING |
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS |
||||
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. |
||||
|
||||
17. Interpretation of Sections 15 and 16. |
||||
|
||||
If the disclaimer of warranty and limitation of liability provided |
||||
above cannot be given local legal effect according to their terms, |
||||
reviewing courts shall apply local law that most closely approximates |
||||
an absolute waiver of all civil liability in connection with the |
||||
Program, unless a warranty or assumption of liability accompanies a |
||||
copy of the Program in return for a fee. |
||||
|
||||
END OF TERMS AND CONDITIONS |
||||
|
||||
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 |
||||
state 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) {year} {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 3 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, see <http://www.gnu.org/licenses/>. |
||||
|
||||
Also add information on how to contact you by electronic and paper mail. |
||||
|
||||
If the program does terminal interaction, make it output a short |
||||
notice like this when it starts in an interactive mode: |
||||
|
||||
{project} Copyright (C) {year} {fullname} |
||||
This program 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, your program's commands |
||||
might be different; for a GUI interface, you would use an "about box". |
||||
|
||||
You should also get your employer (if you work as a programmer) or school, |
||||
if any, to sign a "copyright disclaimer" for the program, if necessary. |
||||
For more information on this, and how to apply and follow the GNU GPL, see |
||||
<http://www.gnu.org/licenses/>. |
||||
|
||||
The GNU 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 Lesser General |
||||
Public License instead of this License. But first, please read |
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>. |
@ -0,0 +1,50 @@
|
||||
package com.fr.design.mainframe; |
||||
|
||||
import com.fr.design.gui.frpane.HyperlinkGroupPane; |
||||
import com.fr.grid.selection.CellSelection; |
||||
import com.fr.grid.selection.FloatSelection; |
||||
import com.fr.grid.selection.Selection; |
||||
import com.fr.js.NameJavaScriptGroup; |
||||
import com.fr.report.cell.CellElement; |
||||
import com.fr.report.cell.FloatElement; |
||||
import com.fr.report.elementcase.TemplateElementCase; |
||||
|
||||
/** |
||||
* Created by plough on 2017/7/21. |
||||
*/ |
||||
public class ReportHyperlinkGroupPane extends HyperlinkGroupPane { |
||||
private static ReportHyperlinkGroupPane singleton; |
||||
|
||||
private ReportHyperlinkGroupPane() { |
||||
super(); |
||||
} |
||||
|
||||
public synchronized static ReportHyperlinkGroupPane getInstance() { |
||||
if (singleton == null) { |
||||
singleton = new ReportHyperlinkGroupPane(); |
||||
} |
||||
return singleton; |
||||
} |
||||
|
||||
public void populate(ElementCasePane reportPane) { |
||||
final TemplateElementCase report = reportPane.getEditingElementCase(); |
||||
NameJavaScriptGroup nameHyperlinks = getNameJSGroup(reportPane, report); |
||||
populate(nameHyperlinks); |
||||
} |
||||
|
||||
private NameJavaScriptGroup getNameJSGroup(ElementCasePane reportPane, final TemplateElementCase report) { |
||||
NameJavaScriptGroup nameHyperlinks = null; |
||||
final Selection sel = reportPane.getSelection(); |
||||
if (sel instanceof FloatSelection) { |
||||
FloatElement selectedFloatElement = report.getFloatElement(((FloatSelection)sel).getSelectedFloatName()); |
||||
nameHyperlinks = selectedFloatElement.getNameHyperlinkGroup(); |
||||
} else { |
||||
CellElement editCellElement = report.getCellElement(((CellSelection)sel).getColumn(), ((CellSelection)sel).getRow()); |
||||
if (editCellElement != null) { |
||||
nameHyperlinks = editCellElement.getNameHyperlinkGroup(); |
||||
} |
||||
} |
||||
|
||||
return nameHyperlinks; |
||||
} |
||||
} |
After Width: | Height: | Size: 15 KiB |
After Width: | Height: | Size: 15 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 15 KiB |
After Width: | Height: | Size: 14 KiB |
@ -0,0 +1,130 @@
|
||||
package com.fr.design.mainframe.errorinfo; |
||||
|
||||
import com.fr.base.FRContext; |
||||
import com.fr.general.IOUtils; |
||||
import com.fr.json.JSONException; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.stable.EncodeConstants; |
||||
import com.fr.stable.ProductConstants; |
||||
import com.fr.stable.StableUtils; |
||||
import com.fr.stable.core.UUID; |
||||
|
||||
import java.io.*; |
||||
import java.text.DateFormat; |
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* Created by Administrator on 2017/7/24 0024. |
||||
*/ |
||||
public class ErrorInfo { |
||||
|
||||
private String username; |
||||
private String uuid; |
||||
private String activekey; |
||||
private String uploadtime; |
||||
private String templateid; |
||||
private String logid; |
||||
private String log; |
||||
|
||||
public ErrorInfo(String username, String uuid, String activekey) { |
||||
this.username = username; |
||||
this.uuid = uuid; |
||||
this.activekey = activekey; |
||||
this.uploadtime = dateToString(); |
||||
} |
||||
|
||||
public String getUsername() { |
||||
return username; |
||||
} |
||||
|
||||
public void setUsername(String username) { |
||||
this.username = username; |
||||
} |
||||
|
||||
public String getUuid() { |
||||
return uuid; |
||||
} |
||||
|
||||
public void setUuid(String uuid) { |
||||
this.uuid = uuid; |
||||
} |
||||
|
||||
public String getActivekey() { |
||||
return activekey; |
||||
} |
||||
|
||||
public void setActivekey(String activekey) { |
||||
this.activekey = activekey; |
||||
} |
||||
|
||||
public String getUploadtime() { |
||||
return uploadtime; |
||||
} |
||||
|
||||
public void setUploadtime(String uploadtime) { |
||||
this.uploadtime = uploadtime; |
||||
} |
||||
|
||||
public String getTemplateid() { |
||||
return templateid; |
||||
} |
||||
|
||||
public void setTemplateid(String templateid) { |
||||
this.templateid = templateid; |
||||
} |
||||
|
||||
public String getLogid() { |
||||
return logid; |
||||
} |
||||
|
||||
public void setLogid(String logid) { |
||||
this.logid = logid; |
||||
} |
||||
|
||||
public String getLog() { |
||||
return log; |
||||
} |
||||
|
||||
public void setLog(String log) { |
||||
this.log = log; |
||||
} |
||||
|
||||
private String dateToString(){ |
||||
DateFormat df = FRContext.getDefaultValues().getDateTimeFormat(); |
||||
return df.format(new Date()); |
||||
} |
||||
|
||||
/** |
||||
* 将出错对象存为json字符串, 并放到设计器缓存目录. |
||||
* 等下一次上传到云中心. |
||||
*/ |
||||
public void saveAsJSON(){ |
||||
JSONObject jo = JSONObject.create(); |
||||
try { |
||||
jo.put("username", username); |
||||
jo.put("uuid", uuid); |
||||
jo.put("activekey", activekey); |
||||
jo.put("templateid", templateid); |
||||
jo.put("uploadtime", uploadtime); |
||||
jo.put("logid", logid); |
||||
jo.put("log", log); |
||||
} catch (JSONException ignore) { |
||||
} |
||||
|
||||
saveFileToCache(jo); |
||||
} |
||||
|
||||
private void saveFileToCache(JSONObject jo) { |
||||
String content = jo.toString(); |
||||
String fileName = UUID.randomUUID() + ErrorInfoUploader.SUFFIX; |
||||
File file = new File(StableUtils.pathJoin(ProductConstants.getEnvHome(), ErrorInfoUploader.FOLDER_NAME, fileName)); |
||||
try { |
||||
StableUtils.makesureFileExist(file); |
||||
FileOutputStream out = new FileOutputStream(file); |
||||
InputStream in = new ByteArrayInputStream(content.getBytes(EncodeConstants.ENCODING_UTF_8)); |
||||
IOUtils.copyBinaryTo(in, out); |
||||
out.close(); |
||||
} catch (IOException ignore) { |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,139 @@
|
||||
package com.fr.design.mainframe.errorinfo; |
||||
|
||||
import com.fr.base.FRContext; |
||||
import com.fr.base.io.IOFile; |
||||
import com.fr.base.io.XMLReadHelper; |
||||
import com.fr.design.DesignerEnvManager; |
||||
import com.fr.general.FRLogLevel; |
||||
import com.fr.general.FRLogManager; |
||||
import com.fr.general.LogDuration; |
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.stable.project.ProjectConstants; |
||||
import com.fr.stable.xml.XMLPrintWriter; |
||||
import com.fr.stable.xml.XMLableReader; |
||||
import com.fr.web.core.SessionDealWith; |
||||
import com.fr.web.core.SessionIDInfor; |
||||
import org.apache.log4j.AppenderSkeleton; |
||||
import org.apache.log4j.Level; |
||||
import org.apache.log4j.spi.LoggingEvent; |
||||
|
||||
import java.io.InputStream; |
||||
|
||||
/** |
||||
* 收集设计器报错信息的appender. |
||||
* <p> |
||||
* Created by Administrator on 2017/7/24 0024. |
||||
*/ |
||||
public class ErrorInfoLogAppender extends AppenderSkeleton { |
||||
|
||||
private static final int ERROR_LEN = 8; |
||||
|
||||
// 缓存下不变的, 没必要频繁取.
|
||||
private String username; |
||||
private String uuid; |
||||
private String activekey; |
||||
|
||||
public ErrorInfoLogAppender() { |
||||
this.layout = new org.apache.log4j.PatternLayout("%d{HH:mm:ss} %t %p [%c] %m%n"); |
||||
|
||||
DesignerEnvManager envManager = DesignerEnvManager.getEnvManager(); |
||||
this.username = envManager.getBBSName(); |
||||
this.uuid = envManager.getUUID(); |
||||
this.activekey = envManager.getActivationKey(); |
||||
} |
||||
|
||||
protected void append(LoggingEvent event) { |
||||
this.subAppend(event); |
||||
} |
||||
|
||||
public boolean requiresLayout() { |
||||
return true; |
||||
} |
||||
|
||||
public synchronized void close() { |
||||
if (this.closed) { |
||||
return; |
||||
} |
||||
this.closed = true; |
||||
|
||||
} |
||||
|
||||
public void subAppend(LoggingEvent event) { |
||||
Level level = event.getLevel(); |
||||
// 只分析上传记录error以上的.
|
||||
if (level.isGreaterOrEqual(FRLogLevel.ERROR)) { |
||||
String msg = this.layout.format(event); |
||||
// 这个id并不是一定会有的, 有就记录下, 说明是预览模板出的错.
|
||||
String templateid = readTemplateID(); |
||||
String logid = readLogID(msg); |
||||
ErrorInfo errorInfo = new ErrorInfo(username, uuid, activekey); |
||||
errorInfo.setTemplateid(templateid); |
||||
errorInfo.setLog(msg); |
||||
errorInfo.setLogid(logid); |
||||
errorInfo.saveAsJSON(); |
||||
} |
||||
} |
||||
|
||||
private String readLogID(String log) { |
||||
int dotIndex = log.lastIndexOf(":"); |
||||
if (dotIndex != -1) { |
||||
int end = Math.min(dotIndex + ERROR_LEN, log.length()); |
||||
String logid = log.substring(dotIndex + 1, end).trim(); |
||||
try { |
||||
Long.parseLong(logid); |
||||
return logid; |
||||
} catch (Exception ignore) { |
||||
|
||||
} |
||||
} |
||||
|
||||
return StringUtils.EMPTY; |
||||
} |
||||
|
||||
private String readTemplateID() { |
||||
LogDuration logDuration = FRLogManager.getSession(); |
||||
if (logDuration == null) { |
||||
return StringUtils.EMPTY; |
||||
} |
||||
|
||||
String sessionID = logDuration.getSessionID(); |
||||
SessionIDInfor infor = SessionDealWith.getSessionIDInfor(sessionID); |
||||
if (infor == null) { |
||||
return StringUtils.EMPTY; |
||||
} |
||||
|
||||
String bookPath = infor.getBookPath(); |
||||
// 这个iofile只读一个templateid, 其他以后有需要再读.
|
||||
IOFile file = new IOFile() { |
||||
@Override |
||||
public void readStream(InputStream in) throws Exception { |
||||
XMLableReader xmlReader = XMLReadHelper.createXMLableReader(in, XMLPrintWriter.XML_ENCODER); |
||||
xmlReader.readXMLObject(this); |
||||
xmlReader.close(); |
||||
in.close(); |
||||
} |
||||
|
||||
@Override |
||||
public void readXML(XMLableReader reader) { |
||||
super.readXML(reader); |
||||
readDesign(reader); |
||||
} |
||||
|
||||
@Override |
||||
protected String openTag() { |
||||
return StringUtils.EMPTY; |
||||
} |
||||
|
||||
@Override |
||||
protected void mainContent(XMLPrintWriter writer) { |
||||
} |
||||
}; |
||||
try { |
||||
file.readStream(FRContext.getCurrentEnv().readBean(bookPath, ProjectConstants.REPORTLETS_NAME)); |
||||
return file.getTemplateID(); |
||||
} catch (Exception ignore) { |
||||
} |
||||
|
||||
return StringUtils.EMPTY; |
||||
} |
||||
} |
@ -0,0 +1,98 @@
|
||||
package com.fr.design.mainframe.errorinfo; |
||||
|
||||
import com.fr.general.*; |
||||
import com.fr.general.http.HttpClient; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.stable.CodeUtils; |
||||
import com.fr.stable.EnvChangedListener; |
||||
import com.fr.stable.ProductConstants; |
||||
import com.fr.stable.StableUtils; |
||||
|
||||
import java.io.File; |
||||
import java.io.FileInputStream; |
||||
import java.text.SimpleDateFormat; |
||||
import java.util.Calendar; |
||||
import java.util.HashMap; |
||||
|
||||
/** |
||||
* Created by Administrator on 2017/7/24 0024. |
||||
*/ |
||||
public class ErrorInfoUploader { |
||||
|
||||
public static final String SUFFIX = ".json"; |
||||
public static final String FOLDER_NAME = "errorInfo"; |
||||
|
||||
private static ErrorInfoUploader collector; |
||||
|
||||
static { |
||||
GeneralContext.addEnvChangedListener(new EnvChangedListener() { |
||||
@Override |
||||
public void envChanged() { |
||||
FRLogger.getLogger().addLogAppender(new ErrorInfoLogAppender()); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
private ErrorInfoUploader() { |
||||
FRLogger.getLogger().addLogAppender(new ErrorInfoLogAppender()); |
||||
} |
||||
|
||||
public static ErrorInfoUploader getInstance() { |
||||
if (collector == null) { |
||||
collector = new ErrorInfoUploader(); |
||||
} |
||||
|
||||
return collector; |
||||
} |
||||
|
||||
public void sendErrorInfo(){ |
||||
//读取文件夹里的json, 加入上传队列中.
|
||||
File folder = new File(StableUtils.pathJoin(ProductConstants.getEnvHome(), FOLDER_NAME)); |
||||
if (!folder.exists()) { |
||||
return; |
||||
} |
||||
|
||||
File[] files = folder.listFiles(); |
||||
try { |
||||
for (File file : files) { |
||||
String filePath = file.getPath(); |
||||
String suffix = filePath.substring(filePath.lastIndexOf(".")); |
||||
|
||||
if (suffix.endsWith(SUFFIX)) { |
||||
Thread.sleep(1000L); |
||||
String content = IOUtils.inputStream2String(new FileInputStream(file)); |
||||
String url = SiteCenter.getInstance().acquireUrlByKind("design.error"); |
||||
if (sendErroInfo(url, content)) { |
||||
file.delete(); |
||||
} |
||||
} |
||||
} |
||||
} catch (Exception ignore) { |
||||
|
||||
} |
||||
} |
||||
|
||||
private boolean sendErroInfo(String url, String content) { |
||||
HashMap<String, String> para = new HashMap<>(); |
||||
String date = new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime()); |
||||
para.put("token", CodeUtils.md5Encode(date, "", "MD5")); |
||||
para.put("content", content); |
||||
HttpClient httpClient = new HttpClient(url, para, true); |
||||
httpClient.asGet(); |
||||
|
||||
if (!httpClient.isServerAlive()) { |
||||
return false; |
||||
} |
||||
|
||||
String res = httpClient.getResponseText(); |
||||
boolean success; |
||||
try { |
||||
success = ComparatorUtils.equals(new JSONObject(res).get("status"), "success"); |
||||
} catch (Exception ex) { |
||||
success = false; |
||||
} |
||||
return success; |
||||
} |
||||
|
||||
|
||||
} |
@ -1,15 +1,29 @@
|
||||
package com.fr.poly; |
||||
|
||||
|
||||
import javax.swing.JComponent; |
||||
|
||||
public class PolyArea extends JComponent { |
||||
private PolyDesigner polyDesigner; |
||||
private int resolution; |
||||
|
||||
public PolyArea(PolyDesigner polyDesigner) { |
||||
public PolyArea(PolyDesigner polyDesigner, int resolution) { |
||||
this.polyDesigner = polyDesigner; |
||||
setUI(new PolyDesignUI()); |
||||
this.resolution = resolution; |
||||
this.setUI(new PolyDesignUI(resolution)); |
||||
// setUI(new PolyDesignUI());
|
||||
} |
||||
|
||||
|
||||
public void setResolution(int resolution) { |
||||
this.resolution = resolution; |
||||
} |
||||
|
||||
public int getResolution() { |
||||
return this.resolution; |
||||
} |
||||
|
||||
|
||||
public PolyDesigner getPolyDesigner() { |
||||
return polyDesigner; |
||||
} |
||||
|
@ -1 +1 @@
|
||||
package com.fr.design.actions;
import com.fr.base.BaseUtils;
import com.fr.design.constants.UIConstants;
import com.fr.design.menu.KeySetUtils;
import com.fr.design.roleAuthority.ReportAndFSManagePane;
import com.fr.design.roleAuthority.RolesAlreadyEditedPane;
import com.fr.design.designer.TargetComponent;
import com.fr.design.file.HistoryTemplateListPane;
import com.fr.design.mainframe.*;
/**
* Author : daisy
* Date: 13-8-30
* Time: 上午10:12
*/
public class AllowAuthorityEditAction extends TemplateComponentAction {
public AllowAuthorityEditAction(TargetComponent t) {
super(t);
this.setMenuKeySet(KeySetUtils.ALLOW_AUTHORITY_EDIT);
this.setName(getMenuKeySet().getMenuName());
this.setMnemonic(getMenuKeySet().getMnemonic());
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_report/allow_authority_edit.png"));
}
/**
* 撤销
*/
public void prepare4Undo() {
HistoryTemplateListPane.getInstance().getCurrentEditingTemplate().iniAuthorityUndoState();
}
/**
* 执行动作
*
* @return 是否执行成功
*/
public boolean executeActionReturnUndoRecordNeeded() {
TargetComponent tc = getEditingComponent();
if (tc == null) {
return false;
}
cleanAuthorityCondition();
//进入时是格式刷则取消格式刷
if (DesignerContext.getFormatState() != DesignerContext.FORMAT_STATE_NULL) {
tc.cancelFormat();
}
BaseUtils.setAuthorityEditing(true);
ReportAndFSManagePane.getInstance().refreshDockingView();
RolesAlreadyEditedPane.getInstance().refreshDockingView();
WestRegionContainerPane.getInstance().replaceDownPane(ReportAndFSManagePane.getInstance());
DesignerContext.getDesignerFrame().setCloseMode(UIConstants.CLOSE_OF_AUTHORITY);
DesignerContext.getDesignerFrame().resetToolkitByPlus(tc.getToolBarMenuDockPlus());
DesignerContext.getDesignerFrame().needToAddAuhtorityPaint();
EastRegionContainerPane.getInstance().replaceUpPane(tc.getEastUpPane());
DesignerContext.getDesignerFrame().refreshDottedLine();
EastRegionContainerPane.getInstance().replaceDownPane(RolesAlreadyEditedPane.getInstance());
EastRegionContainerPane.getInstance().removeParameterPane();
//画虚线
return true;
}
/**
* 进入权限编辑之前将权限编辑界面重置一下工具栏
*/
private void cleanAuthorityCondition() {
java.util.List<JTemplate<?, ?>> opendedTemplate = HistoryTemplateListPane.getInstance().getHistoryList();
for (int i = 0; i < opendedTemplate.size(); i++) {
opendedTemplate.get(i).cleanAuthorityUndo();
}
}
} |
||||
package com.fr.design.actions;
import com.fr.base.BaseUtils;
import com.fr.design.constants.UIConstants;
import com.fr.design.menu.KeySetUtils;
import com.fr.design.roleAuthority.ReportAndFSManagePane;
import com.fr.design.roleAuthority.RolesAlreadyEditedPane;
import com.fr.design.designer.TargetComponent;
import com.fr.design.file.HistoryTemplateListPane;
import com.fr.design.mainframe.*;
/**
* Author : daisy
* Date: 13-8-30
* Time: 上午10:12
*/
public class AllowAuthorityEditAction extends TemplateComponentAction {
public AllowAuthorityEditAction(TargetComponent t) {
super(t);
this.setMenuKeySet(KeySetUtils.ALLOW_AUTHORITY_EDIT);
this.setName(getMenuKeySet().getMenuName());
this.setMnemonic(getMenuKeySet().getMnemonic());
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_report/allow_authority_edit.png"));
}
/**
* 撤销
*/
public void prepare4Undo() {
HistoryTemplateListPane.getInstance().getCurrentEditingTemplate().iniAuthorityUndoState();
}
/**
* 执行动作
*
* @return 是否执行成功
*/
public boolean executeActionReturnUndoRecordNeeded() {
TargetComponent tc = getEditingComponent();
if (tc == null) {
return false;
}
cleanAuthorityCondition();
//进入时是格式刷则取消格式刷
if (DesignerContext.getFormatState() != DesignerContext.FORMAT_STATE_NULL) {
tc.cancelFormat();
}
BaseUtils.setAuthorityEditing(true);
ReportAndFSManagePane.getInstance().refreshDockingView();
RolesAlreadyEditedPane.getInstance().refreshDockingView();
WestRegionContainerPane.getInstance().replaceDownPane(ReportAndFSManagePane.getInstance());
DesignerContext.getDesignerFrame().setCloseMode(UIConstants.CLOSE_OF_AUTHORITY);
DesignerContext.getDesignerFrame().resetToolkitByPlus(tc.getToolBarMenuDockPlus());
DesignerContext.getDesignerFrame().needToAddAuhtorityPaint();
EastRegionContainerPane.getInstance().switchMode(EastRegionContainerPane.PropertyMode.AUTHORITY_EDITION);
EastRegionContainerPane.getInstance().replaceAuthorityEditionPane(tc.getEastUpPane());
DesignerContext.getDesignerFrame().refreshDottedLine();
EastRegionContainerPane.getInstance().replaceConfiguredRolesPane(RolesAlreadyEditedPane.getInstance());
EastRegionContainerPane.getInstance().removeParameterPane();
//画虚线
return true;
}
/**
* 进入权限编辑之前将权限编辑界面重置一下工具栏
*/
private void cleanAuthorityCondition() {
java.util.List<JTemplate<?, ?>> opendedTemplate = HistoryTemplateListPane.getInstance().getHistoryList();
for (int i = 0; i < opendedTemplate.size(); i++) {
opendedTemplate.get(i).cleanAuthorityUndo();
}
}
} |
@ -0,0 +1,111 @@
|
||||
package com.fr.design.foldablepane; |
||||
|
||||
import com.fr.design.constants.UIConstants; |
||||
|
||||
import java.awt.*; |
||||
import java.awt.image.BufferedImage; |
||||
import javax.swing.JPanel; |
||||
|
||||
/** |
||||
* Created by MoMeak on 2017/7/5. |
||||
*/ |
||||
public class HeaderPane extends JPanel { |
||||
private static final long serialVersionUID = 1L; |
||||
private int headWidth = 280; |
||||
private int headHeight = 25; |
||||
private Color bgColor; |
||||
private boolean isShow; |
||||
private String title; |
||||
private Image image; |
||||
private int fontSize = 13; |
||||
public void setShow(boolean isShow) { |
||||
this.isShow = isShow; |
||||
} |
||||
|
||||
public void setTitle(String title) |
||||
{ |
||||
this.title = title; |
||||
} |
||||
|
||||
public void setHeadWidth(int headwidth){ |
||||
this.headWidth = headwidth; |
||||
} |
||||
|
||||
public void setheadHeight(int headHeight){ |
||||
this.headHeight = headHeight; |
||||
} |
||||
|
||||
public void setFontSize(int fontSize){ |
||||
this.fontSize = fontSize; |
||||
} |
||||
|
||||
|
||||
@Override |
||||
protected void paintComponent(Graphics g) { |
||||
Graphics2D g2d = (Graphics2D) g.create(); |
||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, |
||||
RenderingHints.VALUE_ANTIALIAS_ON); |
||||
BufferedImage panelImage = createPanelImage(); |
||||
g2d.drawImage(panelImage, null, 0, 0); |
||||
} |
||||
|
||||
private BufferedImage createPanelImage() { |
||||
BufferedImage panelImage = new BufferedImage(getWidth(), headHeight, BufferedImage.TYPE_INT_ARGB); |
||||
Graphics2D g2d = panelImage.createGraphics(); |
||||
|
||||
g2d.fillRect(0, 0, headWidth, headHeight); |
||||
g2d.drawImage(UIConstants.DRAG_BAR, 0, 0, headWidth, headHeight, null); |
||||
g2d.setFont(new Font("SimSun", 0, fontSize)); |
||||
g2d.setPaint(bgColor); |
||||
// g2d.drawString(this.title, fontSize/2, headHeight-fontSize/3);
|
||||
g2d.drawString(this.title, 0, headHeight-fontSize/3); |
||||
if(this.isShow) |
||||
{ |
||||
image = UIConstants.DRAG_DOWN_PRESS; |
||||
g2d.drawImage(image, title.length() * fontSize, headHeight/2-1, null); |
||||
} |
||||
else |
||||
{ |
||||
image = UIConstants.DRAG_RIGHT_PRESS; |
||||
g2d.drawImage(image, title.length() * fontSize, headHeight/3, null); |
||||
} |
||||
|
||||
|
||||
return panelImage; |
||||
} |
||||
|
||||
@Override |
||||
public Dimension getPreferredSize() { |
||||
return new Dimension(this.getWidth(), headHeight); |
||||
} |
||||
|
||||
@Override |
||||
public Dimension getSize() { |
||||
return new Dimension(this.getWidth(), headHeight); |
||||
} |
||||
|
||||
public HeaderPane(Color bgColor) { |
||||
this.bgColor = bgColor; |
||||
this.isShow = true; |
||||
|
||||
} |
||||
|
||||
public HeaderPane(Color bgColor, String title , int headWidth, int headHeight) { |
||||
this(bgColor); |
||||
this.title = title; |
||||
this.headHeight = headHeight; |
||||
this.headWidth = headWidth; |
||||
} |
||||
|
||||
public static void main(String[] args) |
||||
{ |
||||
// JFrame mainFrame = new JFrame("UI Demo - Gloomyfish");
|
||||
// mainFrame.getContentPane().setLayout(new BorderLayout());
|
||||
// mainFrame.getContentPane().add(new HeaderPane(Color.black, "基本",280,25), BorderLayout.CENTER);
|
||||
// mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
// mainFrame.pack();
|
||||
// mainFrame.setSize(280, 400);
|
||||
// mainFrame.setVisible(true);
|
||||
} |
||||
|
||||
} |
@ -0,0 +1,95 @@
|
||||
package com.fr.design.foldablepane; |
||||
|
||||
import java.awt.*; |
||||
import java.awt.event.MouseAdapter; |
||||
import java.awt.event.MouseEvent; |
||||
|
||||
import javax.swing.*; |
||||
|
||||
|
||||
/** |
||||
* Created by MoMeak on 2017/7/5. |
||||
*/ |
||||
public class UIExpandablePane extends JPanel { |
||||
private static final long serialVersionUID = 1L; |
||||
private HeaderPane headerPanel; |
||||
private JPanel contentPanel; |
||||
private Color color = Color.black; |
||||
private String title; |
||||
private int headWidth; |
||||
private int headHeight; |
||||
|
||||
|
||||
public UIExpandablePane(String title,int headWidth,int headHeight,JPanel contentPanel) |
||||
{ |
||||
super(); |
||||
this.title = title; |
||||
this.headWidth = headWidth; |
||||
this.headHeight = headHeight; |
||||
this.contentPanel = contentPanel; |
||||
initComponents(); |
||||
} |
||||
|
||||
private void initComponents() { |
||||
this.setLayout(new BorderLayout()); |
||||
|
||||
headerPanel = new HeaderPane(color, title,headWidth,headHeight); |
||||
headerPanel.addMouseListener(new PanelAction()); |
||||
this.add(headerPanel, BorderLayout.NORTH); |
||||
this.add(contentPanel, BorderLayout.CENTER); |
||||
setOpaque(false); |
||||
} |
||||
|
||||
class PanelAction extends MouseAdapter |
||||
{ |
||||
public void mousePressed(MouseEvent e) |
||||
{ |
||||
HeaderPane hp = (HeaderPane)e.getSource(); |
||||
if(contentPanel.isShowing()) |
||||
{ |
||||
contentPanel.setVisible(false); |
||||
hp.setShow(false); |
||||
} |
||||
else |
||||
{ |
||||
contentPanel.setVisible(true); |
||||
hp.setShow(true); |
||||
} |
||||
hp.getParent().validate(); |
||||
hp.getParent().repaint(); |
||||
} |
||||
} |
||||
|
||||
|
||||
public static void main(String[] args) |
||||
{ |
||||
// JFrame jf = new JFrame("test");
|
||||
// jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
// JPanel content = (JPanel) jf.getContentPane();
|
||||
// content.setLayout(new BorderLayout());
|
||||
//
|
||||
// JPanel myPanel = new JPanel();
|
||||
// myPanel.setLayout(new BorderLayout());
|
||||
// JPanel Panel = new JPanel();
|
||||
// Panel.setBackground(Color.blue);
|
||||
// myPanel.add(new UIExpandablePane("基本",280,25,Panel),BorderLayout.CENTER);
|
||||
//// myPanel.setLayout(new GridBagLayout());
|
||||
//// myPanel.add(new JExpandablePanel());
|
||||
//// GridBagConstraints gbc = new GridBagConstraints();
|
||||
//// JPanel[] panels = new JPanel[4]; //
|
||||
//// gbc.insets = new Insets(1,3,0,3);
|
||||
//// gbc.weightx = 1.0;
|
||||
//// gbc.fill = GridBagConstraints.HORIZONTAL;
|
||||
//// gbc.gridwidth = GridBagConstraints.REMAINDER;
|
||||
//// for(int j = 0; j < panels.length; j++)
|
||||
//// {
|
||||
//// panels[j] = new JExpandablePanel();
|
||||
//// myPanel.add(panels[j], gbc);
|
||||
//// }
|
||||
// content.add(myPanel, BorderLayout.CENTER);
|
||||
// GUICoreUtils.centerWindow(jf);
|
||||
// jf.setSize(280, 400);
|
||||
// jf.setVisible(true);
|
||||
} |
||||
|
||||
} |
@ -0,0 +1,286 @@
|
||||
package com.fr.design.gui.controlpane; |
||||
|
||||
import com.fr.design.dialog.BasicPane; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.gui.itoolbar.UIToolbar; |
||||
import com.fr.design.layout.FRGUIPaneFactory; |
||||
import com.fr.design.layout.TableLayout; |
||||
import com.fr.design.layout.TableLayoutHelper; |
||||
import com.fr.design.mainframe.EastRegionContainerPane; |
||||
import com.fr.design.menu.ShortCut; |
||||
import com.fr.design.menu.ToolBarDef; |
||||
import com.fr.design.utils.gui.GUICoreUtils; |
||||
import com.fr.general.Inter; |
||||
import com.fr.stable.ArrayUtils; |
||||
import com.fr.stable.Nameable; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
|
||||
/** |
||||
* Created by plough on 2017/7/21. |
||||
*/ |
||||
public abstract class UIControlPane extends BasicPane implements UnrepeatedNameHelper { |
||||
protected static final int SHORT_WIDTH = 30; //每加一个short Divider位置加30
|
||||
protected JPanel controlUpdatePane; |
||||
|
||||
private ShortCut4JControlPane[] shorts; |
||||
private NameableCreator[] creators; |
||||
private ToolBarDef toolbarDef; |
||||
|
||||
private UIToolbar toolBar; |
||||
protected PopupEditPane popupEditPane; |
||||
// peter:这是整体的一个cardLayout Pane
|
||||
protected CardLayout cardLayout; |
||||
|
||||
protected JPanel cardPane; |
||||
|
||||
public UIControlPane() { |
||||
this.initComponentPane(); |
||||
} |
||||
|
||||
/** |
||||
* 生成添加按钮的NameableCreator |
||||
* |
||||
* @return 按钮的NameableCreator |
||||
*/ |
||||
public abstract NameableCreator[] createNameableCreators(); |
||||
|
||||
public ShortCut4JControlPane[] getShorts() { |
||||
return shorts; |
||||
} |
||||
|
||||
public void setShorts(ShortCut4JControlPane[] shorts) { |
||||
this.shorts = shorts; |
||||
} |
||||
|
||||
public void setCreators(NameableCreator[] creators) { |
||||
this.creators = creators; |
||||
} |
||||
|
||||
public ToolBarDef getToolbarDef() { |
||||
return toolbarDef; |
||||
} |
||||
|
||||
public void setToolbarDef(ToolBarDef toolbarDef) { |
||||
this.toolbarDef = toolbarDef; |
||||
} |
||||
|
||||
public UIToolbar getToolBar() { |
||||
return toolBar; |
||||
} |
||||
|
||||
public void setToolBar(UIToolbar toolBar) { |
||||
this.toolBar = toolBar; |
||||
} |
||||
|
||||
public CardLayout getCardLayout() { |
||||
return cardLayout; |
||||
} |
||||
|
||||
public void setCardLayout(CardLayout cardLayout) { |
||||
this.cardLayout = cardLayout; |
||||
} |
||||
|
||||
public JPanel getCardPane() { |
||||
return cardPane; |
||||
} |
||||
|
||||
public void setCardPane(JPanel cardPane) { |
||||
this.cardPane = cardPane; |
||||
} |
||||
|
||||
protected void initComponentPane() { |
||||
this.setLayout(FRGUIPaneFactory.createBorderLayout()); |
||||
this.creators = this.createNameableCreators(); |
||||
this.controlUpdatePane = createControlUpdatePane(); |
||||
|
||||
// p: edit card layout
|
||||
this.cardLayout = new CardLayout(); |
||||
cardPane = FRGUIPaneFactory.createCardLayout_S_Pane(); |
||||
cardPane.setLayout(this.cardLayout); |
||||
// p:选择的Label
|
||||
UILabel selectLabel = new UILabel(); |
||||
cardPane.add(selectLabel, "SELECT"); |
||||
cardPane.add(controlUpdatePane, "EDIT"); |
||||
popupEditPane = new PopupEditPane(cardPane); |
||||
// SplitPane
|
||||
// JSplitPane mainSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, getLeftPane(), cardPane);
|
||||
// mainSplitPane.setBorder(BorderFactory.createLineBorder(GUICoreUtils.getTitleLineBorderColor()));
|
||||
// mainSplitPane.setOneTouchExpandable(true);
|
||||
|
||||
this.add(getLeftPane(), BorderLayout.CENTER); |
||||
this.setBorder(BorderFactory.createEmptyBorder(0, 10, 12, 10)); |
||||
// mainSplitPane.setDividerLocation(getLeftPreferredSize());
|
||||
this.checkButtonEnabled(); |
||||
} |
||||
|
||||
protected abstract JPanel createControlUpdatePane(); |
||||
|
||||
protected JPanel getLeftPane() { |
||||
// LeftPane
|
||||
JPanel leftPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
||||
|
||||
JPanel leftContentPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
||||
initLeftPane(leftContentPane); |
||||
leftPane.add(leftContentPane, BorderLayout.CENTER); |
||||
|
||||
shorts = this.createShortcuts(); |
||||
if (ArrayUtils.isEmpty(shorts)) { |
||||
return leftPane; |
||||
} |
||||
|
||||
toolbarDef = new ToolBarDef(); |
||||
for (ShortCut4JControlPane sj : shorts) { |
||||
toolbarDef.addShortCut(sj.getShortCut()); |
||||
} |
||||
toolBar = ToolBarDef.createJToolBar(); |
||||
// toolBar.setLayout(new FlowLayout(FlowLayout.LEFT));
|
||||
toolbarDef.updateToolBar(toolBar); |
||||
// 封装一层,加边框
|
||||
JPanel toolBarPane = new JPanel(new BorderLayout()); |
||||
toolBarPane.add(toolBar, BorderLayout.CENTER); |
||||
toolBarPane.setBorder(BorderFactory.createMatteBorder(1, 1, 0, 1, new Color(201, 198, 184))); |
||||
leftContentPane.add(toolBarPane, BorderLayout.NORTH); |
||||
// leftContentPane.setBorder(BorderFactory.createLineBorder(new Color(201, 198, 184)));
|
||||
|
||||
// 顶部标签及add按钮
|
||||
UIToolbar topToolBar = new UIToolbar(); |
||||
topToolBar.setLayout(new BorderLayout()); |
||||
ShortCut addItem = addItemShortCut().getShortCut(); |
||||
addItem.intoJToolBar(topToolBar); |
||||
topToolBar.setBorder(BorderFactory.createEmptyBorder(2, 0, 2, 0)); |
||||
double p = TableLayout.PREFERRED; |
||||
double f = TableLayout.FILL; |
||||
double[] columnSize = { p, f }; |
||||
double[] rowSize = { p}; |
||||
Component[][] components = new Component[][]{ |
||||
new Component[]{new UILabel("add hyperlink "), topToolBar}, |
||||
}; |
||||
JPanel leftTopPane = TableLayoutHelper.createTableLayoutPane(components,rowSize,columnSize); |
||||
leftTopPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 6, 0)); |
||||
leftPane.add(leftTopPane, BorderLayout.NORTH); |
||||
|
||||
return leftPane; |
||||
} |
||||
|
||||
/** |
||||
* 初始化左边面板 |
||||
*/ |
||||
protected void initLeftPane(JPanel leftPane) { |
||||
|
||||
} |
||||
|
||||
protected int getLeftPreferredSize() { |
||||
return shorts.length * SHORT_WIDTH; |
||||
} |
||||
|
||||
|
||||
protected ShortCut4JControlPane[] createShortcuts() { |
||||
return new ShortCut4JControlPane[]{ |
||||
// addItemShortCut(),
|
||||
copyItemShortCut(), |
||||
moveUpItemShortCut(), |
||||
moveDownItemShortCut(), |
||||
sortItemShortCut(), |
||||
removeItemShortCut() |
||||
}; |
||||
} |
||||
|
||||
protected abstract ShortCut4JControlPane addItemShortCut(); |
||||
|
||||
protected abstract ShortCut4JControlPane removeItemShortCut(); |
||||
|
||||
protected abstract ShortCut4JControlPane copyItemShortCut(); |
||||
|
||||
protected abstract ShortCut4JControlPane moveUpItemShortCut(); |
||||
|
||||
protected abstract ShortCut4JControlPane moveDownItemShortCut(); |
||||
|
||||
protected abstract ShortCut4JControlPane sortItemShortCut(); |
||||
|
||||
public abstract Nameable[] update(); |
||||
|
||||
|
||||
public void populate(Nameable[] nameableArray) { |
||||
} |
||||
|
||||
/** |
||||
* 检查按钮可用状态 Check button enabled. |
||||
*/ |
||||
public void checkButtonEnabled() { |
||||
} |
||||
|
||||
protected void doBeforeRemove() { |
||||
} |
||||
|
||||
protected void doAfterRemove() { |
||||
} |
||||
|
||||
public NameableCreator[] creators() { |
||||
return creators == null ? new NameableCreator[0] : creators; |
||||
} |
||||
|
||||
protected abstract boolean hasInvalid(boolean isAdd); |
||||
|
||||
/** |
||||
* 刷新 NameableCreator |
||||
* |
||||
* @param creators 生成器 |
||||
*/ |
||||
public void refreshNameableCreator(NameableCreator[] creators) { |
||||
this.creators = creators; |
||||
shorts = this.createShortcuts(); |
||||
toolbarDef.clearShortCuts(); |
||||
for (ShortCut4JControlPane sj : shorts) { |
||||
toolbarDef.addShortCut(sj.getShortCut()); |
||||
} |
||||
|
||||
toolbarDef.updateToolBar(toolBar); |
||||
toolBar.validate(); |
||||
toolBar.repaint(); |
||||
this.repaint(); |
||||
} |
||||
|
||||
// 点击"编辑"按钮,弹出面板
|
||||
protected class PopupEditPane extends JPopupMenu { |
||||
private JComponent contentPane; |
||||
private static final int WIDTH = 460; |
||||
private static final int HEIGHT = 500; |
||||
// private PopupToolPane popupToolPane;
|
||||
// private int fixedHeight;
|
||||
|
||||
PopupEditPane(JComponent pane) { |
||||
contentPane = pane; |
||||
this.setLayout(new BorderLayout()); |
||||
this.add(contentPane, BorderLayout.CENTER); |
||||
this.setOpaque(false); |
||||
contentPane.setPreferredSize(new Dimension(WIDTH, HEIGHT)); |
||||
// fixedHeight = getPreferredSize().height - contentPane.getPreferredSize().height;
|
||||
// updateSize();
|
||||
} |
||||
|
||||
// private void updateSize() {
|
||||
// int newHeight = fixedHeight + contentPane.getPreferredSize().height;
|
||||
// this.setPreferredSize(new Dimension(CONTAINER_WIDTH - TAB_WIDTH, newHeight));
|
||||
// }
|
||||
|
||||
public JComponent getContentPane() { |
||||
return contentPane; |
||||
} |
||||
|
||||
public void replaceContentPane(JComponent pane) { |
||||
// remove(pane);
|
||||
this.remove(this.contentPane); |
||||
this.add(this.contentPane = pane); |
||||
// updateSize();
|
||||
refreshContainer(); |
||||
} |
||||
|
||||
private void refreshContainer() { |
||||
validate(); |
||||
repaint(); |
||||
revalidate(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,974 @@
|
||||
package com.fr.design.gui.controlpane; |
||||
|
||||
import com.fr.base.BaseUtils; |
||||
import com.fr.base.FRContext; |
||||
import com.fr.design.actions.UpdateAction; |
||||
import com.fr.design.beans.BasicBeanPane; |
||||
import com.fr.design.data.tabledata.tabledatapane.GlobalMultiTDTableDataPane; |
||||
import com.fr.design.data.tabledata.tabledatapane.GlobalTreeTableDataPane; |
||||
import com.fr.design.data.tabledata.tabledatapane.MultiTDTableDataPane; |
||||
import com.fr.design.data.tabledata.tabledatapane.TreeTableDataPane; |
||||
import com.fr.design.file.HistoryTemplateListPane; |
||||
import com.fr.design.gui.ibutton.UIButton; |
||||
import com.fr.design.gui.icontainer.UIScrollPane; |
||||
import com.fr.design.gui.ilist.UINameEdList; |
||||
import com.fr.design.gui.ilist.ListModelElement; |
||||
import com.fr.design.gui.ilist.ModNameActionListener; |
||||
import com.fr.design.layout.FRGUIPaneFactory; |
||||
import com.fr.design.mainframe.JTemplate; |
||||
import com.fr.design.menu.LineSeparator; |
||||
import com.fr.design.menu.MenuDef; |
||||
import com.fr.design.menu.ShortCut; |
||||
import com.fr.design.menu.ToolBarDef; |
||||
import com.fr.design.utils.gui.GUICoreUtils; |
||||
import com.fr.general.ComparatorUtils; |
||||
import com.fr.general.Inter; |
||||
import com.fr.stable.ArrayUtils; |
||||
import com.fr.stable.Nameable; |
||||
import com.fr.stable.core.PropertyChangeAdapter; |
||||
import sun.swing.DefaultLookup; |
||||
|
||||
import javax.swing.*; |
||||
import javax.swing.border.Border; |
||||
import javax.swing.event.ListSelectionEvent; |
||||
import javax.swing.event.ListSelectionListener; |
||||
import java.awt.*; |
||||
import java.awt.event.ActionEvent; |
||||
import java.awt.event.MouseAdapter; |
||||
import java.awt.event.MouseEvent; |
||||
import java.awt.event.MouseListener; |
||||
import java.lang.reflect.Constructor; |
||||
import java.lang.reflect.InvocationTargetException; |
||||
import java.util.Arrays; |
||||
import java.util.Comparator; |
||||
|
||||
/** |
||||
* Created by plough on 2017/7/19. |
||||
*/ |
||||
|
||||
public abstract class UIListControlPane extends UIControlPane { |
||||
public static final String LIST_NAME = "UIControl_List"; |
||||
private static final int EDIT_RANGE = 25; // 编辑按钮的x坐标范围
|
||||
|
||||
protected UINameEdList nameableList; |
||||
protected int editingIndex; |
||||
protected String selectedName; |
||||
private boolean isNameRepeated = false; |
||||
|
||||
public UIListControlPane() { |
||||
this.initComponentPane(); |
||||
} |
||||
|
||||
@Override |
||||
protected JPanel createControlUpdatePane() { |
||||
return new JControlUpdatePane(); |
||||
} |
||||
|
||||
/** |
||||
* 生成添加按钮的NameableCreator |
||||
* |
||||
* @return 按钮的NameableCreator |
||||
*/ |
||||
@Override |
||||
public abstract NameableCreator[] createNameableCreators(); |
||||
|
||||
|
||||
@Override |
||||
protected void initLeftPane(JPanel leftPane) { |
||||
nameableList = createJNameList(); |
||||
nameableList.setName(LIST_NAME); |
||||
leftPane.add(new UIScrollPane(nameableList), BorderLayout.CENTER); |
||||
|
||||
|
||||
nameableList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); |
||||
nameableList.addMouseListener(listMouseListener); |
||||
nameableList.addListSelectionListener(new ListSelectionListener() { |
||||
public void valueChanged(ListSelectionEvent evt) { |
||||
// richie:避免多次update和populate大大降低效率
|
||||
if (!evt.getValueIsAdjusting()) { |
||||
// shoc 切换的时候加检验
|
||||
if (hasInvalid(false)) { |
||||
return; |
||||
} |
||||
((JControlUpdatePane) UIListControlPane.this.controlUpdatePane).update(); |
||||
((JControlUpdatePane) UIListControlPane.this.controlUpdatePane).populate(); |
||||
UIListControlPane.this.checkButtonEnabled(); |
||||
} |
||||
} |
||||
}); |
||||
} |
||||
|
||||
public UINameEdList createJNameList() { |
||||
UINameEdList nameEdList = new UINameEdList(new DefaultListModel()) { |
||||
@Override |
||||
protected void doAfterLostFocus() { |
||||
UIListControlPane.this.updateControlUpdatePane(); |
||||
} |
||||
}; |
||||
nameEdList.setCellRenderer(new UINameableListCellRenderer(this)); |
||||
return nameEdList; |
||||
} |
||||
|
||||
public void updateControlUpdatePane() { |
||||
((JControlUpdatePane) controlUpdatePane).update(); |
||||
} |
||||
|
||||
protected void doWhenPopulate(BasicBeanPane beanPane) { |
||||
|
||||
} |
||||
|
||||
protected void doBeforePopulate(ListModelElement el, Object obj) { |
||||
|
||||
} |
||||
|
||||
@Override |
||||
protected ShortCut4JControlPane addItemShortCut() { |
||||
ShortCut addItemShortCut; |
||||
NameableCreator[] creators = creators(); |
||||
if (creators.length == 1) { |
||||
addItemShortCut = new AddItemUpdateAction(creators); |
||||
} else { |
||||
addItemShortCut = new AddItemMenuDef(creators); |
||||
} |
||||
return new AbsoluteEnableShortCut(addItemShortCut); |
||||
} |
||||
|
||||
@Override |
||||
protected ShortCut4JControlPane removeItemShortCut() { |
||||
return new NormalEnableShortCut(new RemoveItemAction()); |
||||
} |
||||
|
||||
@Override |
||||
protected ShortCut4JControlPane copyItemShortCut() { |
||||
return new NormalEnableShortCut(new CopyItemAction()); |
||||
} |
||||
|
||||
@Override |
||||
protected ShortCut4JControlPane moveUpItemShortCut() { |
||||
return new NormalEnableShortCut(new MoveUpItemAction()); |
||||
} |
||||
|
||||
@Override |
||||
protected ShortCut4JControlPane moveDownItemShortCut() { |
||||
return new NormalEnableShortCut(new MoveDownItemAction()); |
||||
} |
||||
|
||||
@Override |
||||
protected ShortCut4JControlPane sortItemShortCut() { |
||||
return new NormalEnableShortCut(new SortItemAction()); |
||||
} |
||||
|
||||
public void setNameListEditable(boolean editable) { |
||||
this.nameableList.setEditable(editable); |
||||
} |
||||
|
||||
@Override |
||||
public Nameable[] update() { |
||||
java.util.List<Nameable> res = new java.util.ArrayList<Nameable>(); |
||||
((JControlUpdatePane) this.controlUpdatePane).update(); |
||||
DefaultListModel listModel = (DefaultListModel) this.nameableList.getModel(); |
||||
for (int i = 0, len = listModel.getSize(); i < len; i++) { |
||||
res.add(((ListModelElement) listModel.getElementAt(i)).wrapper); |
||||
} |
||||
|
||||
return res.toArray(new Nameable[res.size()]); |
||||
} |
||||
|
||||
@Override |
||||
public void populate(Nameable[] nameableArray) { |
||||
DefaultListModel listModel = (DefaultListModel) this.nameableList.getModel(); |
||||
listModel.removeAllElements(); |
||||
if (ArrayUtils.isEmpty(nameableArray)) { |
||||
return; |
||||
} |
||||
|
||||
for (Nameable aNameableArray : nameableArray) { |
||||
listModel.addElement(new ListModelElement(aNameableArray)); |
||||
} |
||||
|
||||
if (listModel.size() > 0) { |
||||
this.nameableList.setSelectedIndex(0); |
||||
} |
||||
this.checkButtonEnabled(); |
||||
} |
||||
|
||||
/** |
||||
* 添加名字改变时的listener |
||||
* |
||||
* @param l 名字改变时的监听 |
||||
*/ |
||||
public void addModNameActionListener(ModNameActionListener l) { |
||||
this.nameableList.addModNameActionListener(l); |
||||
} |
||||
|
||||
/** |
||||
* 添加Editinglistener |
||||
* |
||||
* @param l 监听 |
||||
*/ |
||||
public void addEditingListner(PropertyChangeAdapter l) { |
||||
this.nameableList.addEditingListner(l); |
||||
} |
||||
|
||||
/* |
||||
* 刷新当前的选中的UpdatePane |
||||
*/ |
||||
protected void populateSelectedValue() { |
||||
((JControlUpdatePane) UIListControlPane.this.controlUpdatePane).populate(); |
||||
} |
||||
|
||||
/** |
||||
* 根据name,选中UINameEdList中的item |
||||
*/ |
||||
public void setSelectedName(String name) { |
||||
DefaultListModel listModel = (DefaultListModel) this.nameableList.getModel(); |
||||
for (int i = 0, len = listModel.getSize(); i < len; i++) { |
||||
Nameable item = ((ListModelElement) listModel.getElementAt(i)).wrapper; |
||||
if (ComparatorUtils.equals(name, item.getName())) { |
||||
this.nameableList.setSelectedIndex(i); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
|
||||
public String getEditingName() { |
||||
return this.nameableList.getEditingName(); |
||||
} |
||||
|
||||
public Object getEditingType() { |
||||
return this.nameableList.getAllTypes()[editingIndex]; |
||||
} |
||||
|
||||
public void setWarnigText(int index) { |
||||
this.nameableList.setWarnigText(index); |
||||
} |
||||
|
||||
/** |
||||
* 获取选中的名字 |
||||
*/ |
||||
public String getSelectedName() { |
||||
ListModelElement el = (ListModelElement) this.nameableList.getSelectedValue(); |
||||
|
||||
return el == null ? null : el.wrapper.getName(); |
||||
} |
||||
|
||||
protected boolean isNameRepeted(java.util.List[] list, String name) { |
||||
for (int i = 0; i < list.length; i++) { |
||||
if (list[i].contains(name)) { |
||||
isNameRepeated = true; |
||||
return true; |
||||
} |
||||
} |
||||
isNameRepeated = false; |
||||
return false; |
||||
} |
||||
|
||||
/** |
||||
* 名字是否重复 |
||||
* |
||||
* @return 重复则返回true |
||||
*/ |
||||
public boolean isNameRepeated() { |
||||
return isNameRepeated; |
||||
} |
||||
|
||||
/** |
||||
* 添加 Nameable |
||||
* |
||||
* @param nameable 添加的Nameable |
||||
* @param index 序号 |
||||
*/ |
||||
public void addNameable(Nameable nameable, int index) { |
||||
UINameEdList nameEdList = UIListControlPane.this.nameableList; |
||||
DefaultListModel model = (DefaultListModel) nameEdList.getModel(); |
||||
|
||||
ListModelElement el = new ListModelElement(nameable); |
||||
model.add(index, el); |
||||
nameableList.setSelectedIndex(index); |
||||
nameableList.ensureIndexIsVisible(index); |
||||
|
||||
nameEdList.repaint(); |
||||
} |
||||
|
||||
/** |
||||
* 是否重命名 |
||||
* |
||||
* @return 是则true |
||||
*/ |
||||
public boolean isContainsRename() { |
||||
String rename = Inter.getLocText("FR-Please_Rename") + "!"; |
||||
String[] names = this.nameableList.getAllNames(); |
||||
for (int i = names.length - 1; i >= 0; i--) { |
||||
if (ComparatorUtils.equals(names[i], rename)) { |
||||
return true; |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
protected DefaultListModel getModel() { |
||||
return (DefaultListModel) UIListControlPane.this.nameableList.getModel(); |
||||
} |
||||
|
||||
private String createUnrepeatedCopyName(String suffix) { |
||||
DefaultListModel model = this.getModel(); |
||||
String[] names = new String[model.getSize()]; |
||||
for (int i = 0; i < model.size(); i++) { |
||||
names[i] = ((ListModelElement) model.get(i)).wrapper.getName(); |
||||
} |
||||
String lastName = "CopyOf" + suffix; |
||||
while (ArrayUtils.contains(names, lastName)) { |
||||
lastName = "CopyOf" + lastName; |
||||
} |
||||
return lastName; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 生成不重复的名字 |
||||
* |
||||
* @param prefix 名字前缀 |
||||
* @return 名字 |
||||
*/ |
||||
@Override |
||||
public String createUnrepeatedName(String prefix) { |
||||
DefaultListModel model = this.getModel(); |
||||
Nameable[] all = new Nameable[model.getSize()]; |
||||
for (int i = 0; i < model.size(); i++) { |
||||
all[i] = ((ListModelElement) model.get(i)).wrapper; |
||||
} |
||||
// richer:生成的名字从1开始. kunsnat: 添加属性从0开始.
|
||||
int count = all.length + 1; |
||||
while (true) { |
||||
String name_test = prefix + count; |
||||
boolean repeated = false; |
||||
for (int i = 0, len = model.size(); i < len; i++) { |
||||
Nameable nameable = all[i]; |
||||
if (ComparatorUtils.equals(nameable.getName(), name_test)) { |
||||
repeated = true; |
||||
break; |
||||
} |
||||
} |
||||
|
||||
if (!repeated) { |
||||
return name_test; |
||||
} |
||||
|
||||
count++; |
||||
} |
||||
} |
||||
|
||||
private void popupEditPane() { |
||||
if (editingIndex < 0) { |
||||
return; |
||||
} |
||||
GUICoreUtils.showPopupMenu(popupEditPane, this, |
||||
- popupEditPane.getPreferredSize().width, editingIndex * EDIT_RANGE); |
||||
} |
||||
|
||||
/** |
||||
* 增加项的UpdateAction |
||||
*/ |
||||
protected class AddItemUpdateAction extends UpdateAction { |
||||
final NameableCreator creator; |
||||
|
||||
public AddItemUpdateAction(NameableCreator[] creators) { |
||||
this.creator = creators[0]; |
||||
this.setName(Inter.getLocText("FR-Action_Add")); |
||||
this.setMnemonic('A'); |
||||
this.setSmallIcon(BaseUtils.readIcon("/com/fr/base/images/cell/control/add.png")); |
||||
} |
||||
|
||||
@Override |
||||
public void actionPerformed(ActionEvent e) { |
||||
Nameable nameable = creator.createNameable(UIListControlPane.this); |
||||
|
||||
UIListControlPane.this.addNameable(nameable, getModel().getSize()); |
||||
} |
||||
} |
||||
|
||||
/* |
||||
* 增加项的MenuDef |
||||
*/ |
||||
protected class AddItemMenuDef extends MenuDef { |
||||
public AddItemMenuDef(NameableCreator[] creators) { |
||||
this.setName(Inter.getLocText("FR-Action_Add")); |
||||
this.setMnemonic('A'); |
||||
this.setIconPath("/com/fr/design/images/control/addPopup.png"); |
||||
wrapActionListener(creators); |
||||
} |
||||
|
||||
/** |
||||
* 生成UIButton |
||||
* @return 菜单按钮 |
||||
*/ |
||||
public UIButton createUIButton() { |
||||
createdButton = super.createUIButton(); |
||||
// 此按钮单独抽出,不应使用工具栏外观
|
||||
if (!createdButton.isOpaque()) { |
||||
createdButton.setOpaque(true); |
||||
createdButton.setNormalPainted(true); |
||||
createdButton.setBorderPaintedOnlyWhenPressed(false); |
||||
} |
||||
return createdButton; |
||||
} |
||||
|
||||
private void wrapActionListener(NameableCreator[] creators) { |
||||
for (final NameableCreator creator : creators) { |
||||
if (!whetherAdd(creator.menuName())) { |
||||
continue; |
||||
} |
||||
boolean isTrue = ComparatorUtils.equals(creator.menuName(), Inter.getLocText("Datasource-Stored_Procedure")) || |
||||
ComparatorUtils.equals(creator.menuName(), Inter.getLocText("DS-Relation_TableData")) || ComparatorUtils.equals(creator.menuName(), Inter.getLocText("DS-Multi_Dimensional_Database")); |
||||
if (isTrue) { |
||||
this.addShortCut(new LineSeparator()); |
||||
} |
||||
this.addShortCut(new UpdateAction() { |
||||
{ |
||||
this.setName(creator.menuName()); |
||||
Icon icon = creator.menuIcon(); |
||||
if (icon != null) { |
||||
this.setSmallIcon(icon); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void actionPerformed(ActionEvent e) { |
||||
if (hasInvalid(true)) { |
||||
return; |
||||
} |
||||
|
||||
Nameable nameable = creator.createNameable(UIListControlPane.this); |
||||
|
||||
UIListControlPane.this.addNameable(nameable, getModel().getSize()); |
||||
} |
||||
}); |
||||
} |
||||
} |
||||
|
||||
private boolean whetherAdd(String itemName) { |
||||
JTemplate jTemplate = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate(); |
||||
if (jTemplate == null) { |
||||
return false; |
||||
} |
||||
//先屏蔽掉这个,之后还有别的
|
||||
String[] names = {Inter.getLocText("FR-Hyperlink_Chart_Float")}; |
||||
for (String name : names) { |
||||
if (!jTemplate.isJWorkBook() && ComparatorUtils.equals(itemName, name)) { |
||||
return false; |
||||
} |
||||
} |
||||
String formName = Inter.getLocText("Hyperlink-Form_link"); |
||||
return !(jTemplate.isJWorkBook() && ComparatorUtils.equals(itemName, formName)); |
||||
} |
||||
} |
||||
|
||||
/* |
||||
* 移除item |
||||
*/ |
||||
private class RemoveItemAction extends UpdateAction { |
||||
public RemoveItemAction() { |
||||
this.setName(Inter.getLocText("FR-Action_Remove")); |
||||
this.setMnemonic('R'); |
||||
this.setSmallIcon(BaseUtils |
||||
.readIcon("/com/fr/base/images/cell/control/remove.png")); |
||||
} |
||||
|
||||
@Override |
||||
public void actionPerformed(ActionEvent evt) { |
||||
try { |
||||
UIListControlPane.this.nameableList.getCellEditor() |
||||
.stopCellEditing(); |
||||
} catch (Exception ignored) { |
||||
} |
||||
// bug:在选中一个NameObject并删除,会遗留下Name.
|
||||
doBeforeRemove(); |
||||
if (GUICoreUtils.removeJListSelectedNodes(SwingUtilities |
||||
.getWindowAncestor(UIListControlPane.this), nameableList)) { |
||||
checkButtonEnabled(); |
||||
doAfterRemove(); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/* |
||||
* CopyItem |
||||
*/ |
||||
private class CopyItemAction extends UpdateAction { |
||||
public CopyItemAction() { |
||||
this.setName(Inter.getLocText("FR-Action_Copy")); |
||||
this.setMnemonic('C'); |
||||
this.setSmallIcon(BaseUtils |
||||
.readIcon("/com/fr/base/images/cell/control/copy.png")); |
||||
} |
||||
|
||||
@Override |
||||
public void actionPerformed(ActionEvent evt) { |
||||
// p:选中的值.
|
||||
ListModelElement selectedValue = (ListModelElement) nameableList.getSelectedValue(); |
||||
if (selectedValue == null) { |
||||
return; |
||||
} |
||||
|
||||
((JControlUpdatePane) controlUpdatePane).update(); |
||||
|
||||
Nameable selectedNameable = selectedValue.wrapper; |
||||
|
||||
// p: 用反射机制实现
|
||||
try { |
||||
Nameable newNameable = (Nameable) BaseUtils.cloneObject(selectedNameable); |
||||
newNameable.setName(createUnrepeatedCopyName(selectedNameable.getName())); |
||||
|
||||
UIListControlPane.this.addNameable(newNameable, nameableList.getSelectedIndex() + 1); |
||||
} catch (Exception e) { |
||||
FRContext.getLogger().error(e.getMessage(), e); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/* |
||||
* 上移Item |
||||
*/ |
||||
private class MoveUpItemAction extends UpdateAction { |
||||
public MoveUpItemAction() { |
||||
this.setName(Inter.getLocText("Utils-Move_Up")); |
||||
this.setMnemonic('U'); |
||||
this.setSmallIcon(BaseUtils |
||||
.readIcon("/com/fr/design/images/control/up.png")); |
||||
} |
||||
|
||||
@Override |
||||
public void actionPerformed(ActionEvent evt) { |
||||
int selectedIndex = nameableList.getSelectedIndex(); |
||||
if (selectedIndex == -1) { |
||||
return; |
||||
} |
||||
|
||||
// 上移
|
||||
if (selectedIndex > 0) { |
||||
DefaultListModel listModel = (DefaultListModel) nameableList |
||||
.getModel(); |
||||
|
||||
Object selecteObj1 = listModel.get(selectedIndex - 1); |
||||
listModel.set(selectedIndex - 1, listModel.get(selectedIndex)); |
||||
listModel.set(selectedIndex, selecteObj1); |
||||
|
||||
nameableList.setSelectedIndex(selectedIndex - 1); |
||||
nameableList.ensureIndexIsVisible(selectedIndex - 1); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/* |
||||
* 下移Item |
||||
*/ |
||||
private class MoveDownItemAction extends UpdateAction { |
||||
public MoveDownItemAction() { |
||||
this.setName(Inter.getLocText("Utils-Move_Down")); |
||||
this.setMnemonic('D'); |
||||
this.setSmallIcon(BaseUtils |
||||
.readIcon("/com/fr/design/images/control/down.png")); |
||||
} |
||||
|
||||
@Override |
||||
public void actionPerformed(ActionEvent evt) { |
||||
int selectedIndex = nameableList.getSelectedIndex(); |
||||
if (selectedIndex == -1) { |
||||
return; |
||||
} |
||||
|
||||
if (selectedIndex < nameableList.getModel().getSize() - 1) { |
||||
DefaultListModel listModel = (DefaultListModel) nameableList |
||||
.getModel(); |
||||
|
||||
Object selecteObj1 = listModel.get(selectedIndex + 1); |
||||
listModel.set(selectedIndex + 1, listModel.get(selectedIndex)); |
||||
listModel.set(selectedIndex, selecteObj1); |
||||
|
||||
nameableList.setSelectedIndex(selectedIndex + 1); |
||||
nameableList.ensureIndexIsVisible(selectedIndex + 1); |
||||
} |
||||
} |
||||
} |
||||
|
||||
private class SortItemAction extends UpdateAction { |
||||
private boolean isAtoZ = false; |
||||
|
||||
public SortItemAction() { |
||||
this.setName(Inter.getLocText("FR-Action_Sort")); |
||||
this.setMnemonic('S'); |
||||
this.setSmallIcon(BaseUtils |
||||
.readIcon("/com/fr/design/images/control/sortAsc.png")); |
||||
} |
||||
|
||||
@Override |
||||
public void actionPerformed(ActionEvent evt) { |
||||
// p:选中的值.
|
||||
Object selectedValue = nameableList.getSelectedValue(); |
||||
|
||||
DefaultListModel listModel = (DefaultListModel) nameableList |
||||
.getModel(); |
||||
Nameable[] nameableArray = new Nameable[listModel.getSize()]; |
||||
if (nameableArray.length <= 0) { |
||||
return; |
||||
} |
||||
|
||||
for (int i = 0; i < listModel.getSize(); i++) { |
||||
nameableArray[i] = ((ListModelElement) listModel.getElementAt(i)).wrapper; |
||||
} |
||||
|
||||
// p:排序.
|
||||
if (isAtoZ) { |
||||
Comparator<Nameable> nameableComparator = new Comparator<Nameable>() { |
||||
@Override |
||||
public int compare(Nameable o1, Nameable o2) { |
||||
return -ComparatorUtils.compare(o1.getName(), o2 |
||||
.getName()); |
||||
} |
||||
}; |
||||
isAtoZ = !isAtoZ; |
||||
Arrays.sort(nameableArray, nameableComparator); |
||||
} else { |
||||
Comparator<Nameable> nameableComparator = new Comparator<Nameable>() { |
||||
@Override |
||||
public int compare(Nameable o1, Nameable o2) { |
||||
return ComparatorUtils.compare(o1.getName(), o2 |
||||
.getName()); |
||||
} |
||||
}; |
||||
isAtoZ = !isAtoZ; |
||||
Arrays.sort(nameableArray, nameableComparator); |
||||
} |
||||
|
||||
for (int i = 0; i < nameableArray.length; i++) { |
||||
listModel.set(i, new ListModelElement(nameableArray[i])); |
||||
} |
||||
|
||||
// p:需要选中以前的那个值.
|
||||
if (selectedValue != null) { |
||||
nameableList.setSelectedValue(selectedValue, true); |
||||
} |
||||
|
||||
checkButtonEnabled(); |
||||
// p:需要repaint.
|
||||
nameableList.repaint(); |
||||
} |
||||
} |
||||
|
||||
/* |
||||
* UINameEdList的鼠标事件 |
||||
*/ |
||||
private MouseListener listMouseListener = new MouseAdapter() { |
||||
@Override |
||||
public void mouseReleased(MouseEvent evt) { |
||||
nameableList.stopEditing(); |
||||
if (evt.getClickCount() >= 2 |
||||
&& SwingUtilities.isLeftMouseButton(evt) && evt.getX() > EDIT_RANGE) { |
||||
editingIndex = nameableList.getSelectedIndex(); |
||||
selectedName = nameableList.getNameAt(editingIndex); |
||||
nameableList.editItemAt(nameableList.getSelectedIndex()); |
||||
} else if (SwingUtilities.isLeftMouseButton(evt) && evt.getX() <= EDIT_RANGE) { |
||||
editingIndex = nameableList.getSelectedIndex(); |
||||
popupEditPane(); |
||||
} |
||||
|
||||
// peter:处理右键的弹出菜单
|
||||
if (!SwingUtilities.isRightMouseButton(evt)) { |
||||
return; |
||||
} |
||||
|
||||
// peter: 注意,在checkButtonEnabled()方法里面,设置了所有的Action的Enabled.
|
||||
checkButtonEnabled(); |
||||
|
||||
// p:右键菜单.
|
||||
JPopupMenu popupMenu = new JPopupMenu(); |
||||
|
||||
for (ShortCut4JControlPane sj : getShorts()) { |
||||
sj.getShortCut().intoJPopupMenu(popupMenu); |
||||
} |
||||
|
||||
// peter: 只有弹出菜单有子菜单的时候,才需要弹出来.
|
||||
GUICoreUtils.showPopupMenu(popupMenu, nameableList, evt.getX() - 1, |
||||
evt.getY() - 1); |
||||
} |
||||
|
||||
@Override |
||||
public void mouseMoved(MouseEvent e) { |
||||
|
||||
} |
||||
}; |
||||
|
||||
/** |
||||
* 检查按钮可用状态 Check button enabled. |
||||
*/ |
||||
@Override |
||||
public void checkButtonEnabled() { |
||||
|
||||
int selectedIndex = nameableList.getSelectedIndex(); |
||||
if (selectedIndex == -1) { |
||||
this.cardLayout.show(cardPane, "SELECT"); |
||||
} else { |
||||
this.cardLayout.show(cardPane, "EDIT"); |
||||
} |
||||
for (ShortCut4JControlPane sj : getShorts()) { |
||||
sj.checkEnable(); |
||||
} |
||||
} |
||||
|
||||
|
||||
public class AbsoluteEnableShortCut extends ShortCut4JControlPane { |
||||
public AbsoluteEnableShortCut(ShortCut shortCut) { |
||||
this.shortCut = shortCut; |
||||
} |
||||
|
||||
/** |
||||
* 检查是否可用 |
||||
*/ |
||||
@Override |
||||
public void checkEnable() { |
||||
this.shortCut.setEnabled(true); |
||||
} |
||||
} |
||||
|
||||
public class NormalEnableShortCut extends ShortCut4JControlPane { |
||||
public NormalEnableShortCut(ShortCut shortCut) { |
||||
this.shortCut = shortCut; |
||||
} |
||||
|
||||
/** |
||||
* 检查是否可用 |
||||
*/ |
||||
@Override |
||||
public void checkEnable() { |
||||
this.shortCut.setEnabled(getModel() |
||||
.getSize() > 0 |
||||
&& UIListControlPane.this.nameableList.getSelectedIndex() != -1); |
||||
} |
||||
} |
||||
|
||||
public class SortEnableShortCut extends ShortCut4JControlPane { |
||||
public SortEnableShortCut(ShortCut shortCut) { |
||||
this.shortCut = shortCut; |
||||
} |
||||
|
||||
/** |
||||
* 检查是否可用 |
||||
*/ |
||||
@Override |
||||
public void checkEnable() { |
||||
this.shortCut.setEnabled(getModel().getSize() > 1); |
||||
} |
||||
|
||||
} |
||||
|
||||
public class MoveUpEnableShortCut extends ShortCut4JControlPane { |
||||
public MoveUpEnableShortCut(ShortCut shortCut) { |
||||
this.shortCut = shortCut; |
||||
} |
||||
|
||||
/** |
||||
* 检查是否可用 |
||||
*/ |
||||
@Override |
||||
public void checkEnable() { |
||||
this.shortCut.setEnabled(getModel().getSize() > 1 |
||||
&& UIListControlPane.this.nameableList.getSelectedIndex() > 0); |
||||
} |
||||
|
||||
} |
||||
|
||||
public class MoveDownEnableShortCut extends ShortCut4JControlPane { |
||||
public MoveDownEnableShortCut(ShortCut shortCut) { |
||||
this.shortCut = shortCut; |
||||
} |
||||
|
||||
/** |
||||
* 检查是否可用 |
||||
*/ |
||||
@Override |
||||
public void checkEnable() { |
||||
this.shortCut.setEnabled(getModel().getSize() > 1 |
||||
&& UIListControlPane.this.nameableList.getSelectedIndex() < UIListControlPane.this.nameableList.getModel().getSize() - 1); |
||||
} |
||||
|
||||
} |
||||
|
||||
private class JControlUpdatePane extends JPanel { |
||||
private CardLayout card; |
||||
private JPanel cardPane; |
||||
private BasicBeanPane[] updatePanes; |
||||
|
||||
private ListModelElement elEditing; |
||||
|
||||
public JControlUpdatePane() { |
||||
initUpdatePane(); |
||||
} |
||||
|
||||
private void initUpdatePane() { |
||||
NameableCreator[] creators = creators(); |
||||
if (creators == null) { |
||||
return; |
||||
} |
||||
card = new CardLayout(); |
||||
cardPane = FRGUIPaneFactory.createCardLayout_S_Pane(); |
||||
cardPane.setLayout(card); |
||||
this.setLayout(FRGUIPaneFactory.createBorderLayout()); |
||||
this.add(cardPane); |
||||
int len = creators.length; |
||||
updatePanes = new BasicBeanPane[len]; |
||||
} |
||||
|
||||
public void populate() { |
||||
ListModelElement el = (ListModelElement) UIListControlPane.this.nameableList.getSelectedValue(); |
||||
if (el == null) { |
||||
return; |
||||
} |
||||
|
||||
elEditing = el; |
||||
NameableCreator[] creators = creators(); |
||||
|
||||
for (int i = 0, len = updatePanes.length; i < len; i++) { |
||||
Object ob2Populate = creators[i].acceptObject2Populate(el.wrapper); |
||||
if (ob2Populate != null) { |
||||
if (updatePanes[i] == null) { |
||||
if (isMulti(creators[i].getUpdatePane()) || isTree(creators[i].getUpdatePane())) { |
||||
updatePanes[i] = createPaneByCreators(creators[i], el.wrapper.getName()); |
||||
} else { |
||||
updatePanes[i] = createPaneByCreators(creators[i]); |
||||
} |
||||
cardPane.add(updatePanes[i], String.valueOf(i)); |
||||
} |
||||
card.show(cardPane, String.valueOf(i)); |
||||
doBeforePopulate(el, ob2Populate); |
||||
updatePanes[i].populateBean(ob2Populate); |
||||
doWhenPopulate(updatePanes[i]); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
|
||||
public boolean isMulti(Class _class) { |
||||
return ComparatorUtils.equals(_class, GlobalMultiTDTableDataPane.class) || ComparatorUtils.equals(_class, MultiTDTableDataPane.class); |
||||
} |
||||
|
||||
public boolean isTree(Class _class) { |
||||
return ComparatorUtils.equals(_class, GlobalTreeTableDataPane.class) || ComparatorUtils.equals(_class, TreeTableDataPane.class); |
||||
} |
||||
|
||||
public void update() { |
||||
NameableCreator[] creators = creators(); |
||||
for (int i = 0; i < updatePanes.length; i++) { |
||||
BasicBeanPane pane = updatePanes[i]; |
||||
|
||||
if (pane != null && pane.isVisible()) { |
||||
Object bean = pane.updateBean(); |
||||
if (i < creators.length) { |
||||
creators[i].saveUpdatedBean(elEditing, bean); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
public void checkValid() throws Exception { |
||||
if (updatePanes != null) { |
||||
for (int i = 0; i < updatePanes.length; i++) { |
||||
if (updatePanes[i] != null) { |
||||
updatePanes[i].checkValid(); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
protected BasicBeanPane createPaneByCreators(NameableCreator creator) { |
||||
try { |
||||
return creator.getUpdatePane().newInstance(); |
||||
} catch (InstantiationException e) { |
||||
throw new RuntimeException(e); |
||||
} catch (IllegalAccessException e) { |
||||
throw new RuntimeException(e); |
||||
} |
||||
} |
||||
|
||||
protected BasicBeanPane createPaneByCreators(NameableCreator creator, String string) { |
||||
Constructor constructor = null; |
||||
try { |
||||
constructor = creator.getUpdatePane().getDeclaredConstructor(new Class[]{String.class}); |
||||
constructor.setAccessible(true); |
||||
return (BasicBeanPane) constructor.newInstance(string); |
||||
} catch (NoSuchMethodException e) { |
||||
throw new RuntimeException(e); |
||||
} catch (InstantiationException e) { |
||||
throw new RuntimeException(e); |
||||
} catch (IllegalAccessException e) { |
||||
throw new RuntimeException(e); |
||||
} catch (InvocationTargetException e) { |
||||
throw new RuntimeException(e); |
||||
} |
||||
|
||||
} |
||||
|
||||
// 选项添加个数有限制等情况下 要求能控制快捷按钮的状态
|
||||
protected void setToolbarDefEnable(int shortCutIndex, int itemIndex, boolean enabled) { |
||||
ToolBarDef toolbarDef = getToolbarDef(); |
||||
if (toolbarDef.getShortCutCount() > shortCutIndex) { |
||||
ShortCut sc = toolbarDef.getShortCut(shortCutIndex); |
||||
if (sc instanceof AddItemMenuDef) { |
||||
AddItemMenuDef am = (AddItemMenuDef) sc; |
||||
if (am.getShortCutCount() > itemIndex) { |
||||
am.getShortCut(itemIndex).setEnabled(enabled); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 检查是否符合规范 |
||||
* |
||||
* @throws Exception |
||||
*/ |
||||
@Override |
||||
public void checkValid() throws Exception { |
||||
((JControlUpdatePane) this.controlUpdatePane).checkValid(); |
||||
} |
||||
|
||||
private int getInValidIndex() { |
||||
BasicBeanPane[] p = ((JControlUpdatePane) controlUpdatePane).updatePanes; |
||||
if (p != null) { |
||||
for (int i = 0; i < p.length; i++) { |
||||
if (p[i] != null) { |
||||
try { |
||||
p[i].checkValid(); |
||||
} catch (Exception e) { |
||||
return i; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
return -1; |
||||
} |
||||
|
||||
@Override |
||||
protected boolean hasInvalid(boolean isAdd) { |
||||
int idx = UIListControlPane.this.getInValidIndex(); |
||||
if (isAdd || nameableList.getSelectedIndex() != idx) { |
||||
try { |
||||
checkValid(); |
||||
} catch (Exception exp) { |
||||
JOptionPane.showMessageDialog(UIListControlPane.this, exp.getMessage()); |
||||
nameableList.setSelectedIndex(idx); |
||||
return true; |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
/** |
||||
* 设置选中项 |
||||
* |
||||
* @param index 选中项的序列号 |
||||
*/ |
||||
public void setSelectedIndex(int index) { |
||||
nameableList.setSelectedIndex(index); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,162 @@
|
||||
package com.fr.design.gui.controlpane; |
||||
|
||||
import com.fr.base.BaseUtils; |
||||
import com.fr.design.gui.ibutton.UIButton; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.gui.ilist.ListModelElement; |
||||
import com.fr.design.gui.itextfield.UITextField; |
||||
import com.fr.design.utils.gui.GUICoreUtils; |
||||
import com.fr.stable.Nameable; |
||||
import sun.swing.DefaultLookup; |
||||
|
||||
import javax.swing.*; |
||||
import javax.swing.border.Border; |
||||
import javax.swing.border.EmptyBorder; |
||||
import java.awt.*; |
||||
import java.awt.event.ActionEvent; |
||||
import java.awt.event.ActionListener; |
||||
|
||||
/** |
||||
* Nameable的ListCellRenerer |
||||
* Created by plough on 2017/7/21. |
||||
*/ |
||||
|
||||
public class UINameableListCellRenderer extends |
||||
JPanel implements ListCellRenderer { |
||||
private static final Border SAFE_NO_FOCUS_BORDER = new EmptyBorder(1, 1, 1, 1); |
||||
private static final Border DEFAULT_NO_FOCUS_BORDER = new EmptyBorder(1, 1, 1, 1); |
||||
private static final Color BORDER_COLOR = new Color(201, 198, 184); |
||||
protected static Border noFocusBorder = DEFAULT_NO_FOCUS_BORDER; |
||||
private static final int BUTTON_WIDTH = 25; |
||||
private UILabel editButton; // "编辑按钮",实际上是一个 UILabel,由列表项(UIListControlPane)统一处理点击事件
|
||||
private UILabel label; |
||||
private UIListControlPane listControlPane; |
||||
|
||||
public UINameableListCellRenderer(UIListControlPane listControlPane) { |
||||
super(); |
||||
this.listControlPane = listControlPane; |
||||
initComponents(); |
||||
setOpaque(true); |
||||
setBorder(getNoFocusBorder()); |
||||
setName("List.cellRenderer"); |
||||
} |
||||
|
||||
private void initComponents() { |
||||
editButton = new UILabel() { |
||||
public Dimension getPreferredSize() { |
||||
return new Dimension(BUTTON_WIDTH, BUTTON_WIDTH); |
||||
} |
||||
}; |
||||
// editButton.set4LargeToolbarButton();
|
||||
editButton.setIcon(BaseUtils.readIcon("/com/fr/base/images/cell/control/add.png")); |
||||
editButton.setBorder(BorderFactory.createMatteBorder(0, 0, 0, 1, BORDER_COLOR)); |
||||
editButton.setHorizontalAlignment(SwingConstants.CENTER); |
||||
// editButton.addActionListener(new ActionListener() {
|
||||
// @Override
|
||||
// public void actionPerformed(ActionEvent e) {
|
||||
// popupEditPane();
|
||||
// }
|
||||
// });
|
||||
label = new UILabel(); |
||||
label.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0)); |
||||
// label.setEditable(false);
|
||||
this.setLayout(new BorderLayout()); |
||||
this.add(editButton, BorderLayout.WEST); |
||||
this.add(label, BorderLayout.CENTER); |
||||
} |
||||
|
||||
private Border getNoFocusBorder() { |
||||
// return BorderFactory.createLineBorder(new Color(201, 198, 184));
|
||||
return BorderFactory.createMatteBorder(0, 0, 1, 0, BORDER_COLOR); |
||||
// Border border = DefaultLookup.getBorder(this, ui, "List.cellNoFocusBorder");
|
||||
// if (System.getSecurityManager() != null) {
|
||||
// if (border != null) return border;
|
||||
// return SAFE_NO_FOCUS_BORDER;
|
||||
// } else {
|
||||
// if (border != null &&
|
||||
// (noFocusBorder == null ||
|
||||
// noFocusBorder == DEFAULT_NO_FOCUS_BORDER)) {
|
||||
// return border;
|
||||
// }
|
||||
// return noFocusBorder;
|
||||
// }
|
||||
} |
||||
|
||||
private void setText(String t) { |
||||
label.setText(t); |
||||
} |
||||
|
||||
@Override |
||||
public Component getListCellRendererComponent(JList list, Object value, |
||||
int index, boolean isSelected, boolean cellHasFocus) { |
||||
setComponentOrientation(list.getComponentOrientation()); |
||||
|
||||
Color bg = null; |
||||
Color fg = null; |
||||
|
||||
JList.DropLocation dropLocation = list.getDropLocation(); |
||||
if (dropLocation != null |
||||
&& !dropLocation.isInsert() |
||||
&& dropLocation.getIndex() == index) { |
||||
|
||||
bg = DefaultLookup.getColor(this, ui, "List.dropCellBackground"); |
||||
fg = DefaultLookup.getColor(this, ui, "List.dropCellForeground"); |
||||
|
||||
isSelected = true; |
||||
} |
||||
|
||||
if (isSelected) { |
||||
setBackground(bg == null ? list.getSelectionBackground() : bg); |
||||
setForeground(fg == null ? list.getSelectionForeground() : fg); |
||||
} |
||||
else { |
||||
setBackground(list.getBackground()); |
||||
setForeground(list.getForeground()); |
||||
} |
||||
|
||||
// if (value instanceof Icon) {
|
||||
// setIcon((Icon)value);
|
||||
// setText("");
|
||||
// }
|
||||
// else {
|
||||
// setIcon(null);
|
||||
setText((value == null) ? "" : value.toString()); |
||||
// }
|
||||
|
||||
setEnabled(list.isEnabled()); |
||||
setFont(list.getFont()); |
||||
|
||||
Border border = null; |
||||
if (cellHasFocus) { |
||||
if (isSelected) { |
||||
border = DefaultLookup.getBorder(this, ui, "List.focusSelectedCellHighlightBorder"); |
||||
} |
||||
if (border == null) { |
||||
border = DefaultLookup.getBorder(this, ui, "List.focusCellHighlightBorder"); |
||||
} |
||||
} else { |
||||
border = getNoFocusBorder(); |
||||
} |
||||
setBorder(border); |
||||
|
||||
if (value instanceof ListModelElement) { |
||||
Nameable wrappee = ((ListModelElement) value).wrapper; |
||||
this.setText(((ListModelElement) value).wrapper.getName()); |
||||
|
||||
boolean iconSet = false; |
||||
for (NameableCreator creator : listControlPane.creators()) { |
||||
if (creator.menuIcon() != null && creator.acceptObject2Populate(wrappee) != null) { |
||||
// this.setIcon(creator.menuIcon());
|
||||
this.setToolTipText(creator.createTooltip()); |
||||
iconSet = true; |
||||
break; |
||||
} |
||||
} |
||||
// if (!iconSet) {
|
||||
// this.setIcon(BaseUtils.readIcon("/com/fr/base/images/oem/cpt.png"));
|
||||
// }
|
||||
} |
||||
|
||||
return this; |
||||
} |
||||
} |
@ -0,0 +1,311 @@
|
||||
package com.fr.design.gui.icontainer; |
||||
|
||||
import com.fr.base.BaseUtils; |
||||
import com.fr.design.constants.UIConstants; |
||||
import com.fr.design.gui.ibutton.UIButton; |
||||
import com.fr.design.mainframe.DesignerContext; |
||||
import com.fr.design.utils.gui.GUICoreUtils; |
||||
import com.fr.stable.Constants; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
import java.awt.event.MouseAdapter; |
||||
import java.awt.event.MouseEvent; |
||||
import java.awt.event.MouseMotionListener; |
||||
|
||||
/** |
||||
* Created by plough on 2017/7/7. |
||||
*/ |
||||
public class UIEastResizableContainer extends JPanel { |
||||
private static final long serialVersionUID = 1854340560790476907L; |
||||
private int containerWidth = 240; |
||||
private int preferredWidth = 240; |
||||
private int topToolPaneHeight = 20; |
||||
private int leftPaneWidth = 40; |
||||
|
||||
private JComponent leftPane; |
||||
private JComponent rightPane; |
||||
|
||||
// private HorizotalToolPane horizontToolPane;
|
||||
private TopToolPane topToolPane; |
||||
|
||||
|
||||
private static final int ARROW_MARGIN = 15; |
||||
private static final int ARROW_RANGE = 35; |
||||
|
||||
// private boolean isRightPaneVisible = true;
|
||||
|
||||
public UIEastResizableContainer() { |
||||
this(new JPanel(), new JPanel()); |
||||
} |
||||
|
||||
/** |
||||
* 设置面板宽度 |
||||
* |
||||
* @param width |
||||
*/ |
||||
public void setContainerWidth(int width) { |
||||
this.containerWidth = width; |
||||
this.preferredWidth = width; |
||||
} |
||||
|
||||
public boolean isRightPaneVisible() { |
||||
return containerWidth > leftPaneWidth; |
||||
} |
||||
|
||||
|
||||
// public void setRightPaneVisible(boolean isVisible){
|
||||
// this.isRightPaneVisible = isVisible;
|
||||
// }
|
||||
|
||||
private void setPreferredWidth(int width) { |
||||
this.preferredWidth = width; |
||||
} |
||||
|
||||
public UIEastResizableContainer(JComponent leftPane, JComponent rightPane) { |
||||
setBackground(UIConstants.NORMAL_BACKGROUND); |
||||
this.leftPane = leftPane; |
||||
this.rightPane = rightPane; |
||||
|
||||
this.topToolPane = new TopToolPane(); |
||||
|
||||
setLayout(containerLayout); |
||||
add(topToolPane); |
||||
add(leftPane); |
||||
add(rightPane); |
||||
} |
||||
|
||||
public static void main(String... args) { |
||||
JFrame jf = new JFrame("test"); |
||||
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
||||
JPanel content = (JPanel) jf.getContentPane(); |
||||
content.setLayout(new BorderLayout()); |
||||
|
||||
JPanel leftPane = new JPanel(); |
||||
leftPane.setBackground(Color.yellow); |
||||
JPanel rightPane = new JPanel(); |
||||
rightPane.setBackground(Color.green); |
||||
|
||||
UIButton b1, b2; |
||||
b1 = new UIButton("b1"); |
||||
b2 = new UIButton("b2"); |
||||
b1.setPreferredSize(new Dimension(40, 40)); |
||||
b2.setPreferredSize(new Dimension(40, 40)); |
||||
leftPane.add(b1); |
||||
leftPane.add(b2); |
||||
|
||||
|
||||
UIEastResizableContainer bb = new UIEastResizableContainer(leftPane, rightPane); |
||||
|
||||
JPanel cc = new JPanel(); |
||||
cc.setBackground(Color.white); |
||||
|
||||
content.add(bb, BorderLayout.EAST); |
||||
content.add(cc, BorderLayout.CENTER); |
||||
GUICoreUtils.centerWindow(jf); |
||||
jf.setSize(500, 500); |
||||
jf.setVisible(true); |
||||
} |
||||
|
||||
/** |
||||
* 将面板设置成最佳的宽度 |
||||
*/ |
||||
public void setWindow2PreferWidth() { |
||||
if (containerWidth == leftPaneWidth) { |
||||
containerWidth = preferredWidth; |
||||
refreshContainer(); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 得到容器的宽度 |
||||
* |
||||
* @return |
||||
*/ |
||||
public int getContainerWidth() { |
||||
return this.containerWidth; |
||||
} |
||||
|
||||
/** |
||||
* 设置关闭设计器前最后一次面板的宽度 |
||||
* |
||||
* @param containerWidth |
||||
*/ |
||||
public void setLastContainerWidth(int containerWidth) { |
||||
this.containerWidth = containerWidth; |
||||
} |
||||
|
||||
private LayoutManager containerLayout = new LayoutManager() { |
||||
|
||||
@Override |
||||
public void removeLayoutComponent(Component comp) { |
||||
// TODO Auto-generated method stub
|
||||
|
||||
} |
||||
|
||||
@Override |
||||
public Dimension preferredLayoutSize(Container parent) { |
||||
return parent.getPreferredSize(); |
||||
} |
||||
|
||||
@Override |
||||
public Dimension minimumLayoutSize(Container parent) { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public void layoutContainer(Container parent) { |
||||
if (topToolPane == null || rightPane == null) { |
||||
return; |
||||
} |
||||
|
||||
// topToolPane.setBounds(0, 0, containerWidth, topToolPaneHeight);//0,0,10,462
|
||||
topToolPane.setBounds(0, 0, leftPaneWidth, topToolPaneHeight);//0,0,10,462
|
||||
leftPane.setBounds(0, topToolPaneHeight, leftPaneWidth, getHeight() - topToolPaneHeight); |
||||
|
||||
// parameterPane.setBounds(20, 0, 230, getParameterPaneHeight());//10,0,230,462
|
||||
rightPane.setBounds(leftPaneWidth, 0, containerWidth-leftPaneWidth, getHeight());//20,0,230,0
|
||||
} |
||||
|
||||
@Override |
||||
public void addLayoutComponent(String name, Component comp) { |
||||
} |
||||
}; |
||||
|
||||
@Override |
||||
/** |
||||
* 得到最佳大小 |
||||
*/ |
||||
public Dimension getPreferredSize() { |
||||
return new Dimension(containerWidth, 400); |
||||
} |
||||
|
||||
/** |
||||
* 替换左子面板 |
||||
* |
||||
* @param pane 面板 |
||||
*/ |
||||
public void replaceLeftPane(JComponent pane) { |
||||
remove(pane); |
||||
remove(this.leftPane); |
||||
add(this.leftPane = pane); |
||||
refreshContainer(); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 替换右子面板 |
||||
* |
||||
* @param pane 面板 |
||||
*/ |
||||
public void replaceRightPane(JComponent pane) { |
||||
remove(pane); |
||||
remove(this.rightPane); |
||||
add(this.rightPane = pane); |
||||
refreshContainer(); |
||||
} |
||||
|
||||
/** |
||||
* 得到左子面板 |
||||
* |
||||
* @return |
||||
*/ |
||||
public JComponent getLeftPane() { |
||||
return this.leftPane; |
||||
} |
||||
|
||||
/** |
||||
* 得到右子面板 |
||||
* |
||||
* @return |
||||
*/ |
||||
public JComponent getRightPane() { |
||||
return this.rightPane; |
||||
} |
||||
|
||||
private void refreshContainer() { |
||||
validate(); |
||||
repaint(); |
||||
revalidate(); |
||||
} |
||||
|
||||
/** |
||||
* 伸缩右子面板时,触发此方法 |
||||
*/ |
||||
public void onResize() { |
||||
} |
||||
|
||||
private class TopToolPane extends JPanel { |
||||
private int model = UIConstants.MODEL_NORMAL; |
||||
|
||||
public TopToolPane() { |
||||
super(); |
||||
addMouseMotionListener(new MouseMotionListener() { |
||||
|
||||
@Override |
||||
public void mouseMoved(MouseEvent e) { |
||||
if (e.getX() <= ARROW_RANGE) { |
||||
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
||||
model = UIConstants.MODEL_PRESS; |
||||
} else { |
||||
setCursor(Cursor.getDefaultCursor()); |
||||
model = UIConstants.MODEL_NORMAL; |
||||
} |
||||
repaint(); |
||||
} |
||||
|
||||
@Override |
||||
public void mouseDragged(MouseEvent e) { |
||||
} |
||||
}); |
||||
addMouseListener(new MouseAdapter() { |
||||
@Override |
||||
public void mouseExited(MouseEvent e) { |
||||
setCursor(Cursor.getDefaultCursor()); |
||||
model = UIConstants.MODEL_NORMAL; |
||||
repaint(); |
||||
} |
||||
|
||||
@Override |
||||
public void mouseClicked(MouseEvent e) { |
||||
if (e.getX() <= ARROW_RANGE) { |
||||
if (containerWidth == leftPaneWidth) { |
||||
containerWidth = preferredWidth; |
||||
} else { |
||||
setPreferredWidth(containerWidth); |
||||
containerWidth = leftPaneWidth; |
||||
} |
||||
onResize(); |
||||
refreshContainer(); |
||||
if (BaseUtils.isAuthorityEditing()) { |
||||
DesignerContext.getDesignerFrame().doResize(); |
||||
} |
||||
} |
||||
} |
||||
}); |
||||
} |
||||
|
||||
@Override |
||||
public void paint(Graphics g) { |
||||
Image button; |
||||
|
||||
g.drawImage(UIConstants.DRAG_BAR, 0, 0, containerWidth, topToolPaneHeight, null); |
||||
if (containerWidth == leftPaneWidth) { |
||||
if (model == UIConstants.MODEL_NORMAL) { |
||||
button = UIConstants.DRAG_LEFT_NORMAL; |
||||
} else { |
||||
button = UIConstants.DRAG_LEFT_PRESS; |
||||
} |
||||
} else { |
||||
if (model == UIConstants.MODEL_NORMAL) { |
||||
button = UIConstants.DRAG_RIGHT_NORMAL; |
||||
} else { |
||||
button = UIConstants.DRAG_RIGHT_PRESS; |
||||
} |
||||
} |
||||
// g.drawImage(button, 2, ARROW_MARGIN_VERTICAL, 5, toolPaneHeight, null);
|
||||
g.drawImage(button, 18, 7, 5, 5, null); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,398 @@
|
||||
package com.fr.design.gui.ilist; |
||||
|
||||
import com.fr.base.Utils; |
||||
import com.fr.design.gui.itextfield.UITextField; |
||||
import com.fr.general.Inter; |
||||
import com.fr.general.NameObject; |
||||
import com.fr.stable.Nameable; |
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.stable.core.PropertyChangeAdapter; |
||||
|
||||
import javax.swing.*; |
||||
import javax.swing.event.CellEditorListener; |
||||
import javax.swing.event.ChangeEvent; |
||||
import java.awt.*; |
||||
import java.awt.event.FocusEvent; |
||||
import java.awt.event.FocusListener; |
||||
import java.awt.event.MouseAdapter; |
||||
import java.awt.event.MouseEvent; |
||||
import java.util.ArrayList; |
||||
import java.util.Vector; |
||||
|
||||
/** |
||||
* Created by plough on 2017/7/23. |
||||
*/ |
||||
public class UINameEdList extends UIList implements CellEditorListener { |
||||
private static final int TEST_LIST_LENTH = 20; |
||||
private static final int BUTTON_WIDTH = 25; |
||||
private boolean editable = true; |
||||
|
||||
// kunsnat: 是否强制ListName是数字 (int型)
|
||||
private boolean isNameShouldNumber = false; |
||||
|
||||
transient protected ListCellEditor cellEditor; |
||||
transient protected Component editorComp; |
||||
transient protected int editingIndex; |
||||
private PropertyChangeAdapter editingListner; |
||||
private java.util.List<ModNameActionListener> ll = new ArrayList<ModNameActionListener>(); |
||||
|
||||
public UINameEdList(ListModel dataModel) { |
||||
super(dataModel); |
||||
} |
||||
|
||||
public UINameEdList(final Object[] listData) { |
||||
super(listData); |
||||
} |
||||
|
||||
public UINameEdList(final Vector<?> listData) { |
||||
super(listData); |
||||
} |
||||
|
||||
public UINameEdList() { |
||||
super(); |
||||
} |
||||
|
||||
/* |
||||
* Sets是否可编辑 |
||||
*/ |
||||
public void setEditable(boolean editable) { |
||||
this.editable = editable; |
||||
} |
||||
|
||||
/** |
||||
* 是否可编辑 |
||||
* |
||||
* @return 是则返回true |
||||
*/ |
||||
public boolean isEditable() { |
||||
return this.editable; |
||||
} |
||||
|
||||
public void setNameShouldNumber(boolean isNameShouldNumber) { |
||||
this.isNameShouldNumber = isNameShouldNumber; |
||||
} |
||||
|
||||
/** |
||||
* 是否强制ListName是数字 (int型) |
||||
* |
||||
* @return 是则返回true |
||||
*/ |
||||
public boolean isNameShouldNumber() { |
||||
return isNameShouldNumber; |
||||
} |
||||
|
||||
/** |
||||
* 添加名字改变时的listener |
||||
* |
||||
* @param l 监听器 |
||||
*/ |
||||
public void addModNameActionListener(ModNameActionListener l) { |
||||
ll.add(l); |
||||
} |
||||
|
||||
/** |
||||
* 编辑时的监听器 |
||||
* |
||||
* @param l 监听器 |
||||
*/ |
||||
public void addEditingListner(PropertyChangeAdapter l) { |
||||
this.editingListner = l; |
||||
} |
||||
|
||||
/** |
||||
* 移除某名字改变时的listener |
||||
* |
||||
* @param l 监听器 |
||||
*/ |
||||
public void removeModNameActionListener(ModNameActionListener l) { |
||||
ll.remove(l); |
||||
} |
||||
|
||||
public ListCellEditor getCellEditor() { |
||||
if (cellEditor == null) { |
||||
UITextField editField = new UITextField(); |
||||
if (editingListner != null) { |
||||
editField.addFocusListener(new FocusListener() { |
||||
|
||||
@Override |
||||
public void focusLost(FocusEvent e) { |
||||
editingListner.propertyChange(); |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public void focusGained(FocusEvent e) { |
||||
// TODO Auto-generated method stub
|
||||
|
||||
} |
||||
}); |
||||
} |
||||
cellEditor = new DefaultListCellEditor(editField) { |
||||
public boolean stopCellEditing() { |
||||
boolean isTrue = super.stopCellEditing(); |
||||
stopEditing(); |
||||
|
||||
return isTrue; |
||||
} |
||||
}; |
||||
cellEditor.addCellEditorListener(this); |
||||
} |
||||
|
||||
return cellEditor; |
||||
} |
||||
|
||||
protected void doAfterLostFocus() { |
||||
|
||||
} |
||||
|
||||
public void setCellEditor(ListCellEditor editor) { |
||||
this.cellEditor = editor; |
||||
} |
||||
|
||||
/* |
||||
* 取得index节点的名字 |
||||
*/ |
||||
public String getNameAt(int index) { |
||||
Nameable nameable = ((ListModelElement) getModel().getElementAt(index)).wrapper; |
||||
if (nameable != null) { |
||||
return nameable.getName(); |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
|
||||
public Object getType(int index) { |
||||
Nameable nameable = ((ListModelElement) getModel().getElementAt(index)).wrapper; |
||||
if (nameable != null && nameable instanceof NameObject) { |
||||
return ((NameObject) nameable).getObject(); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
|
||||
public void setWarnigText() { |
||||
setWarnigText(this.getSelectedIndex()); |
||||
} |
||||
|
||||
public void setWarnigText(int index) { |
||||
setNameAt(Inter.getLocText("Please_Rename") + "!", index); |
||||
this.repaint(); |
||||
} |
||||
|
||||
/* |
||||
* 设置index节点的名字 |
||||
*/ |
||||
// b:edit改变name的时候怎么办?
|
||||
public void setNameAt(String name, int index) { |
||||
Nameable nameable = ((ListModelElement) getModel().getElementAt(index)).wrapper; |
||||
if (nameable != null) { |
||||
String oldName = nameable.getName(); |
||||
|
||||
if (isNameShouldNumber()) { |
||||
// kunsnat: 限制只能是数字(int型)
|
||||
Number number = Utils.string2Number(name); |
||||
if (number == null) { |
||||
nameable.setName(oldName); |
||||
} else { |
||||
int newName = number.intValue(); |
||||
nameable.setName(String.valueOf(newName)); |
||||
} |
||||
} else { |
||||
nameable.setName(name); |
||||
} |
||||
|
||||
for (int i = 0, len = ll.size(); i < len; i++) { |
||||
ll.get(i).nameModed(index, oldName, name); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/* |
||||
* 编辑第index个item |
||||
*/ |
||||
private String oldName; |
||||
|
||||
/** |
||||
* 编辑第index项 |
||||
* |
||||
* @param index 序号 |
||||
* @return 成功返回true |
||||
*/ |
||||
public boolean editItemAt(int index) { |
||||
// 如果不可编辑,返回
|
||||
if (!this.editable) { |
||||
return false; |
||||
} |
||||
|
||||
if (cellEditor != null && !cellEditor.stopCellEditing()) { |
||||
return false; |
||||
} |
||||
if (index < 0 || index >= this.getModel().getSize()) { |
||||
return false; |
||||
} |
||||
|
||||
ListCellEditor editor = getCellEditor(); |
||||
Object value = editor.getCellEditorValue(); |
||||
if (!StringUtils.isBlank(value.toString())) { |
||||
oldName = value.toString(); |
||||
} |
||||
editorComp = prepareEditor(editor, index); |
||||
if (editorComp == null) { |
||||
return false; |
||||
} |
||||
Rectangle rect = this.getCellBounds(index, index); |
||||
// alex:所有的UINameEdList都有Icon,空出前面20 * 20的位置就是放的Icon
|
||||
rect.setRect(createRect(rect, BUTTON_WIDTH)); |
||||
|
||||
editorComp.setBounds(rect); |
||||
add(editorComp); |
||||
editorComp.validate(); |
||||
editorComp.requestFocus(); |
||||
if (editorComp instanceof UITextField) { |
||||
((UITextField) editorComp).selectAll(); |
||||
} |
||||
|
||||
setEditingIndex(index); |
||||
|
||||
return true; |
||||
} |
||||
|
||||
public Rectangle createRect(Rectangle rect, int iconWidth) { |
||||
return new Rectangle(rect.x + iconWidth, rect.y, rect.width - iconWidth, rect.height); |
||||
} |
||||
|
||||
public String getEditingName() { |
||||
return (String) getCellEditor().getCellEditorValue(); |
||||
} |
||||
|
||||
/* |
||||
* 根据ListCellEditor取得编辑器的Component |
||||
*/ |
||||
private Component prepareEditor(ListCellEditor cellEditor, int index) { |
||||
String name = getNameAt(index); |
||||
boolean isSelected = this.isSelectedIndex(index); |
||||
Component comp = cellEditor.getListCellEditorComponent(this, name, isSelected, index); |
||||
|
||||
return comp; |
||||
} |
||||
|
||||
/* |
||||
* 记录正在编辑的index |
||||
*/ |
||||
private void setEditingIndex(int idx) { |
||||
editingIndex = idx; |
||||
} |
||||
|
||||
/** |
||||
* 编辑取消 |
||||
* |
||||
* @param e 事件 |
||||
*/ |
||||
public void editingCanceled(ChangeEvent e) { |
||||
removeComp(); |
||||
} |
||||
|
||||
/** |
||||
* 编辑结束 |
||||
* |
||||
* @param e 事件 |
||||
*/ |
||||
public void editingStopped(ChangeEvent e) { |
||||
doAfterLostFocus(); |
||||
stopEditing(); |
||||
} |
||||
|
||||
/** |
||||
* 停止编辑事件 |
||||
*/ |
||||
public void stopEditing() { |
||||
ListCellEditor editor = getCellEditor(); |
||||
if (editor != null && editorComp != null) { |
||||
Object value = editor.getCellEditorValue(); |
||||
String name = StringUtils.isBlank(value.toString()) ? oldName : value.toString(); |
||||
setNameAt(name, editingIndex); |
||||
removeComp(); |
||||
} |
||||
} |
||||
|
||||
public String[] getAllNames() { |
||||
int length = this.getModel().getSize(); |
||||
String[] names = new String[length]; |
||||
for (int i = 0; i < length; i++) { |
||||
names[i] = getNameAt(i); |
||||
} |
||||
return names; |
||||
} |
||||
|
||||
public Object[] getAllTypes() { |
||||
int length = this.getModel().getSize(); |
||||
Object[] types = new Object[length]; |
||||
for (int i = 0; i < length; i++) { |
||||
types[i] = getType(i); |
||||
} |
||||
return types; |
||||
} |
||||
|
||||
|
||||
/* |
||||
* 移除编辑器的Component |
||||
*/ |
||||
private void removeComp() { |
||||
if (editorComp != null) { |
||||
remove(editorComp); |
||||
} |
||||
Rectangle cellRect = this.getCellBounds(editingIndex, editingIndex); |
||||
setEditingIndex(-1); |
||||
editorComp = null; |
||||
repaint(cellRect); |
||||
} |
||||
|
||||
/** |
||||
* 主函数 |
||||
* |
||||
* @param args 参数 |
||||
*/ |
||||
public static void main(String... args) { |
||||
JFrame f = new JFrame(); |
||||
JPanel c = (JPanel) f.getContentPane(); |
||||
c.setLayout(new BorderLayout()); |
||||
ListModelElement[] data = new ListModelElement[TEST_LIST_LENTH]; |
||||
for (int i = 0; i < TEST_LIST_LENTH; i++) { |
||||
data[i] = new ListModelElement(new NameObject(i + 1 + "", i)); |
||||
} |
||||
final UINameEdList list = new UINameEdList(data); |
||||
list.setEditable(true); |
||||
list.addMouseListener(new MouseAdapter() { |
||||
public void mouseReleased(MouseEvent evt) { |
||||
list.stopEditing(); |
||||
if (evt.getClickCount() >= 2 |
||||
&& SwingUtilities.isLeftMouseButton(evt)) { |
||||
list.editItemAt(list.getSelectedIndex()); |
||||
} |
||||
} |
||||
}) |
||||
; |
||||
|
||||
list.setCellEditor(new DefaultListCellEditor(new UITextField())); |
||||
list.setCellRenderer(new NameableListCellRenderer()); |
||||
c.add(list, BorderLayout.CENTER); |
||||
f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); |
||||
f.setSize(400, 600); |
||||
f.setVisible(true); |
||||
} |
||||
|
||||
private static class NameableListCellRenderer extends DefaultListCellRenderer { |
||||
@Override |
||||
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, |
||||
boolean cellHasFocus) { |
||||
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); |
||||
|
||||
if (value instanceof Nameable) { |
||||
Nameable wrappee = (Nameable) value; |
||||
this.setText(wrappee.getName()); |
||||
} |
||||
return this; |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,370 @@
|
||||
package com.fr.design.mainframe; |
||||
|
||||
import com.fr.base.BaseUtils; |
||||
import com.fr.design.gui.ibutton.UIButton; |
||||
import com.fr.design.gui.ibutton.UIRadioButton; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.gui.islider.UISlider; |
||||
import com.fr.design.gui.ispinner.UIBasicSpinner; |
||||
import com.fr.design.gui.itextfield.UITextField; |
||||
import com.fr.design.layout.TableLayout; |
||||
import com.fr.design.layout.TableLayoutHelper; |
||||
import com.fr.design.utils.gui.GUICoreUtils; |
||||
import com.fr.general.Inter; |
||||
|
||||
import javax.swing.*; |
||||
import javax.swing.border.MatteBorder; |
||||
import javax.swing.event.ChangeEvent; |
||||
import javax.swing.event.ChangeListener; |
||||
import java.awt.*; |
||||
import java.awt.event.ActionEvent; |
||||
import java.awt.event.ActionListener; |
||||
import java.awt.event.ItemEvent; |
||||
import java.awt.event.ItemListener; |
||||
import java.math.BigDecimal; |
||||
|
||||
/** |
||||
* Created by MoMeak on 2017/7/13. |
||||
*/ |
||||
public class JFormSliderPane extends JPanel { |
||||
|
||||
private static final double ONEPOINTEIGHT = 1.8; |
||||
private static final int SIX = 6; |
||||
private static final int TEN = 10; |
||||
private static final int ONE_EIGHT = 18; |
||||
private static final int FONT_SIZE = 14; |
||||
private static final int SPINNER_WIDTH = 45; |
||||
private static final int SPINNER_HEIGHT = 20; |
||||
private static final int HALF_HUNDRED = 50; |
||||
private static final int HUNDRED = 100; |
||||
private static final int TWO_HUNDRED = 200; |
||||
private static final int THREE_HUNDRED = 300; |
||||
private static final int FOUR_HUNDRED = 400; |
||||
private static final int DIALOG_WIDTH = 150; |
||||
private static final int DIALOG_HEIGHT = 240; |
||||
private static final int SHOWVALBUTTON_WIDTH = 70; |
||||
private static final int SHOWVALBUTTON_HEIGHTH = 25; |
||||
public int showValue = 100; |
||||
public double resolutionTimes = 1.0; |
||||
private static JFormSliderPane THIS; |
||||
private UITextField showVal; |
||||
private JSpinner showValSpinner; |
||||
private UISlider slider; |
||||
private int times; |
||||
private int sliderValue; |
||||
private UIButton downButton; |
||||
private UIButton upButton; |
||||
private UIButton showValButton; |
||||
private UIRadioButton twoHundredButton; |
||||
private UIRadioButton oneHundredButton; |
||||
private UIRadioButton SevenFiveButton; |
||||
private UIRadioButton fiveTenButton; |
||||
private UIRadioButton twoFiveButton; |
||||
private UIRadioButton selfAdaptButton; |
||||
private UIRadioButton customButton; |
||||
//拖动条处理和button、直接输入不一样
|
||||
private boolean isButtonOrIsTxt = true; |
||||
private FormPopupPane dialog; |
||||
private int upButtonX; |
||||
private JPanel dialogContentPanel; |
||||
|
||||
|
||||
public JFormSliderPane() { |
||||
this.setLayout(new BorderLayout()); |
||||
slider = new UISlider(0, HUNDRED, HALF_HUNDRED); |
||||
slider.setUI(new JSliderPaneUI(slider)); |
||||
slider.addChangeListener(listener); |
||||
|
||||
showValSpinner = new UIBasicSpinner(new SpinnerNumberModel(HUNDRED, TEN, FOUR_HUNDRED, 1)); |
||||
showValSpinner.setEnabled(true); |
||||
showValSpinner.addChangeListener(showValSpinnerChangeListener); |
||||
showValSpinner.setPreferredSize(new Dimension(SPINNER_WIDTH, SPINNER_HEIGHT)); |
||||
//MoMeak:控制只能输入10-400,但是用起来感觉不舒服,先注释掉吧
|
||||
// JSpinner.NumberEditor editor = new JSpinner.NumberEditor(showValSpinner, "0");
|
||||
// showValSpinner.setEditor(editor);
|
||||
// JFormattedTextField textField = ((JSpinner.NumberEditor) showValSpinner.getEditor()).getTextField();
|
||||
// textField.setEditable(true);
|
||||
// DefaultFormatterFactory factory = (DefaultFormatterFactory) textField .getFormatterFactory();
|
||||
// NumberFormatter formatter = (NumberFormatter) factory.getDefaultFormatter();
|
||||
// formatter.setAllowsInvalid(false);
|
||||
downButton = new UIButton(BaseUtils.readIcon("com/fr/design/images/data/source/moveDown.png")); |
||||
upButton = new UIButton(BaseUtils.readIcon("com/fr/design/images/data/source/moveUp.png")); |
||||
downButton.setActionCommand("less"); |
||||
upButton.setActionCommand("more"); |
||||
downButton.addActionListener(buttonActionListener); |
||||
upButton.addActionListener(buttonActionListener); |
||||
|
||||
showValButton = new UIButton(showValSpinner.getValue() + "%"); |
||||
showValButton.setBorderPainted(false); |
||||
showValButton.setPreferredSize(new Dimension(SHOWVALBUTTON_WIDTH, SHOWVALBUTTON_HEIGHTH)); |
||||
showValButton.addActionListener(showValButtonActionListener); |
||||
|
||||
initUIRadioButton(); |
||||
initPane(); |
||||
JPanel panel = new JPanel(new FlowLayout(1, 1, 0)); |
||||
panel.add(downButton); |
||||
panel.add(slider); |
||||
panel.add(upButton); |
||||
panel.add(showValButton); |
||||
this.add(panel, BorderLayout.NORTH); |
||||
this.setBounds(0, 0, THREE_HUNDRED, ONE_EIGHT); |
||||
} |
||||
|
||||
public static final JFormSliderPane getInstance() { |
||||
// if (THIS == null) {
|
||||
// THIS = new JFormSliderPane();
|
||||
// }
|
||||
THIS = new JFormSliderPane(); |
||||
return THIS; |
||||
} |
||||
|
||||
private void initUIRadioButton() { |
||||
twoHundredButton = new UIRadioButton("200%"); |
||||
oneHundredButton = new UIRadioButton("100%"); |
||||
SevenFiveButton = new UIRadioButton("75%"); |
||||
fiveTenButton = new UIRadioButton("50%"); |
||||
twoFiveButton = new UIRadioButton("25%"); |
||||
// selfAdaptButton = new UIRadioButton(Inter.getLocText("FR-Designer_Scale_selfAdaptButton"));
|
||||
customButton = new UIRadioButton(Inter.getLocText("FR-Designer_Scale_customButton")); |
||||
twoHundredButton.addItemListener(radioButtonItemListener); |
||||
oneHundredButton.addItemListener(radioButtonItemListener); |
||||
SevenFiveButton.addItemListener(radioButtonItemListener); |
||||
fiveTenButton.addItemListener(radioButtonItemListener); |
||||
twoFiveButton.addItemListener(radioButtonItemListener); |
||||
//TODO
|
||||
// selfAdaptButton.addItemListener();
|
||||
|
||||
ButtonGroup bg = new ButtonGroup();// 初始化按钮组
|
||||
bg.add(twoHundredButton);// 加入按钮组
|
||||
bg.add(oneHundredButton); |
||||
bg.add(SevenFiveButton); |
||||
bg.add(fiveTenButton); |
||||
bg.add(twoFiveButton); |
||||
// bg.add(selfAdaptButton);
|
||||
bg.add(customButton); |
||||
customButton.setSelected(true); |
||||
} |
||||
|
||||
private void initPane() { |
||||
double p = TableLayout.PREFERRED; |
||||
double f = TableLayout.FILL; |
||||
double[] columnSize = {p, f}; |
||||
double[] rowSize = {p, p, p, p, p, p, p}; |
||||
Component[][] components = new Component[][]{ |
||||
new Component[]{twoHundredButton, null}, |
||||
new Component[]{oneHundredButton, null}, |
||||
new Component[]{SevenFiveButton, null}, |
||||
new Component[]{fiveTenButton, null}, |
||||
new Component[]{twoFiveButton, null}, |
||||
// new Component[]{selfAdaptButton,null},
|
||||
new Component[]{customButton, createSpinnerPanel()} |
||||
}; |
||||
dialogContentPanel = TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); |
||||
} |
||||
|
||||
private JPanel createSpinnerPanel() { |
||||
JPanel spinnerPanel = new JPanel(new FlowLayout()); |
||||
spinnerPanel.add(showValSpinner); |
||||
UILabel percent = new UILabel("%"); |
||||
percent.setFont(new Font("Dialog", Font.PLAIN, FONT_SIZE)); |
||||
spinnerPanel.add(percent); |
||||
return spinnerPanel; |
||||
} |
||||
|
||||
ActionListener showValButtonActionListener = new ActionListener() { |
||||
@Override |
||||
public void actionPerformed(ActionEvent e) { |
||||
popupDialog(); |
||||
} |
||||
}; |
||||
|
||||
ChangeListener showValSpinnerChangeListener = new ChangeListener() { |
||||
@Override |
||||
public void stateChanged(ChangeEvent e) { |
||||
int val = (int) ((UIBasicSpinner) e.getSource()).getValue(); |
||||
isButtonOrIsTxt = true; |
||||
resolutionTimes = divide(showValue, 100, 2); |
||||
if (val > FOUR_HUNDRED) { |
||||
showValSpinner.setValue(FOUR_HUNDRED); |
||||
val = FOUR_HUNDRED; |
||||
} |
||||
if (val < TEN) { |
||||
showValSpinner.setValue(TEN); |
||||
val = TEN; |
||||
} |
||||
refreshSlider(val); |
||||
refreshBottun(val); |
||||
} |
||||
}; |
||||
|
||||
|
||||
//定义一个监听器,用于监听所有滑动条
|
||||
ChangeListener listener = new ChangeListener() { |
||||
public void stateChanged(ChangeEvent event) { |
||||
//取出滑动条的值,并在文本中显示出来
|
||||
if (!isButtonOrIsTxt) { |
||||
customButton.setSelected(true); |
||||
EventQueue.invokeLater(new Runnable() { |
||||
public void run() { |
||||
sliderValue = slider.getValue(); |
||||
getTimes(sliderValue); |
||||
showValue = times; |
||||
showValSpinner.setValue(times); |
||||
} |
||||
}); |
||||
} else { |
||||
isButtonOrIsTxt = false; |
||||
} |
||||
} |
||||
}; |
||||
|
||||
ItemListener radioButtonItemListener = new ItemListener() { |
||||
@Override |
||||
public void itemStateChanged(ItemEvent e) { |
||||
JRadioButton temp = (JRadioButton) e.getSource(); |
||||
if (temp.isSelected()) { |
||||
showValSpinner.setValue(Integer.valueOf(temp.getText().substring(0, temp.getText().indexOf("%")))); |
||||
} |
||||
} |
||||
}; |
||||
|
||||
private void refreshSlider(int val) { |
||||
showValue = val; |
||||
if (showValue > HUNDRED) { |
||||
slider.setValue((int) (showValue + TWO_HUNDRED) / SIX); |
||||
} else if (showValue < HUNDRED) { |
||||
slider.setValue((int) ((showValue - TEN) / ONEPOINTEIGHT)); |
||||
} else if (showValue == HUNDRED) { |
||||
slider.setValue(HALF_HUNDRED); |
||||
} |
||||
} |
||||
|
||||
|
||||
private void refreshBottun(int val) { |
||||
showValButton.setText(val + "%"); |
||||
} |
||||
|
||||
public double getResolutionTimes() { |
||||
return this.resolutionTimes; |
||||
} |
||||
|
||||
public int getshowValue() { |
||||
return this.showValue; |
||||
} |
||||
|
||||
public static double divide(double v1, double v2, int scale) { |
||||
BigDecimal b1 = new BigDecimal(Double.toString(v1)); |
||||
BigDecimal b2 = new BigDecimal(Double.toString(v2)); |
||||
return b1.divide(b2, scale).doubleValue(); |
||||
} |
||||
|
||||
ActionListener buttonActionListener = new ActionListener() { |
||||
@Override |
||||
public void actionPerformed(ActionEvent e) { |
||||
showValue = (int) showValSpinner.getValue(); |
||||
isButtonOrIsTxt = true; |
||||
if (e.getActionCommand().equals("less")) { |
||||
int newDownVal = showValue - TEN; |
||||
if (newDownVal >= TEN) { |
||||
showValue = newDownVal; |
||||
showValSpinner.setValue(newDownVal); |
||||
} else { |
||||
showValue = newDownVal; |
||||
showValSpinner.setValue(TEN); |
||||
} |
||||
} |
||||
if (e.getActionCommand().equals("more")) { |
||||
int newUpVal = showValue + TEN; |
||||
if (newUpVal <= FOUR_HUNDRED) { |
||||
showValue = newUpVal; |
||||
showValSpinner.setValue(newUpVal); |
||||
} else { |
||||
showValue = newUpVal; |
||||
showValSpinner.setValue(FOUR_HUNDRED); |
||||
} |
||||
} |
||||
isButtonOrIsTxt = true; |
||||
customButton.setSelected(true); |
||||
} |
||||
}; |
||||
|
||||
|
||||
private void getTimes(int value) { |
||||
if (value == HALF_HUNDRED) { |
||||
times = HUNDRED; |
||||
} else if (value < HALF_HUNDRED) { |
||||
times = (int) Math.round(ONEPOINTEIGHT * value + TEN); |
||||
} else { |
||||
times = (int) (SIX * value - TWO_HUNDRED); |
||||
} |
||||
} |
||||
|
||||
|
||||
public JSpinner getShowVal() { |
||||
return this.showValSpinner; |
||||
} |
||||
|
||||
public UIRadioButton getSelfAdaptButton() { |
||||
return this.selfAdaptButton; |
||||
} |
||||
|
||||
private void popupDialog() { |
||||
Point btnCoords = upButton.getLocationOnScreen(); |
||||
if (dialog == null) { |
||||
dialog = new FormPopupPane(upButton, dialogContentPanel); |
||||
if (upButtonX == 0) { |
||||
upButtonX = btnCoords.x; |
||||
GUICoreUtils.showPopupMenu(dialog, upButton, -DIALOG_WIDTH + upButton.getWidth() + SHOWVALBUTTON_WIDTH, -DIALOG_HEIGHT); |
||||
} |
||||
} else { |
||||
if (upButtonX == 0) { |
||||
upButtonX = btnCoords.x; |
||||
GUICoreUtils.showPopupMenu(dialog, upButton, -DIALOG_WIDTH + upButton.getWidth() + SHOWVALBUTTON_WIDTH, -DIALOG_HEIGHT); |
||||
} else { |
||||
GUICoreUtils.showPopupMenu(dialog, upButton, -DIALOG_WIDTH + upButton.getWidth() + SHOWVALBUTTON_WIDTH, -DIALOG_HEIGHT); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public static void main(String[] args) { |
||||
JFrame jf = new JFrame("test"); |
||||
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
||||
JPanel content = (JPanel) jf.getContentPane(); |
||||
content.setLayout(new BorderLayout()); |
||||
content.add(JFormSliderPane.getInstance(), BorderLayout.CENTER); |
||||
GUICoreUtils.centerWindow(jf); |
||||
jf.setSize(400, 80); |
||||
jf.setVisible(true); |
||||
|
||||
} |
||||
} |
||||
|
||||
|
||||
class FormPopupPane extends JPopupMenu { |
||||
private JComponent contentPane; |
||||
private static final int UPLABEL_HEIGHT = 25; |
||||
private static final int DIALOG_WIDTH = 150; |
||||
private static final int DIALOG_HEIGHT = 220; |
||||
private static final int UPLABEL_WIDTH = 300; |
||||
private JComponent centerPane; |
||||
private UILabel upLabel; |
||||
|
||||
FormPopupPane(UIButton b, JPanel dialogContentPanel) { |
||||
contentPane = new JPanel(new BorderLayout()); |
||||
centerPane = new JPanel(new BorderLayout()); |
||||
upLabel = new UILabel(" " + Inter.getLocText("FR-Designer_Scale_EnlargeOrReduce")); |
||||
upLabel.setOpaque(true); |
||||
upLabel.setPreferredSize(new Dimension(UPLABEL_WIDTH, UPLABEL_HEIGHT)); |
||||
upLabel.setBackground(Color.LIGHT_GRAY); |
||||
upLabel.setBorder(new MatteBorder(0, 0, 1, 0, Color.gray)); |
||||
centerPane.add(dialogContentPanel, BorderLayout.NORTH); |
||||
contentPane.add(upLabel, BorderLayout.NORTH); |
||||
contentPane.add(centerPane, BorderLayout.CENTER); |
||||
// contentPane.setBorder(new MatteBorder(1,1,1,1,Color.darkGray));
|
||||
this.add(contentPane, BorderLayout.CENTER); |
||||
this.setPreferredSize(new Dimension(DIALOG_WIDTH, DIALOG_HEIGHT)); |
||||
this.setOpaque(false); |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,436 @@
|
||||
package com.fr.design.mainframe; |
||||
|
||||
import com.fr.base.BaseUtils; |
||||
import com.fr.design.gui.ibutton.UIButton; |
||||
import com.fr.design.gui.ibutton.UIRadioButton; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.gui.islider.UISlider; |
||||
import com.fr.design.gui.ispinner.UIBasicSpinner; |
||||
import com.fr.design.gui.itextfield.UITextField; |
||||
import com.fr.design.layout.TableLayout; |
||||
import com.fr.design.layout.TableLayoutHelper; |
||||
import com.fr.design.utils.gui.GUICoreUtils; |
||||
import com.fr.general.Inter; |
||||
|
||||
import javax.swing.*; |
||||
import javax.swing.border.MatteBorder; |
||||
import javax.swing.event.ChangeEvent; |
||||
import javax.swing.event.ChangeListener; |
||||
import javax.swing.plaf.basic.BasicSliderUI; |
||||
import java.awt.*; |
||||
import java.awt.event.ActionEvent; |
||||
import java.awt.event.ActionListener; |
||||
import java.awt.event.ItemEvent; |
||||
import java.awt.event.ItemListener; |
||||
import java.math.BigDecimal; |
||||
|
||||
/** |
||||
* Created by MoMeak on 2017/7/13. |
||||
*/ |
||||
public class JSliderPane extends JPanel { |
||||
|
||||
private static final double ONEPOINTEIGHT = 1.8; |
||||
private static final int SIX = 6; |
||||
private static final int TEN = 10; |
||||
private static final int ONE_EIGHT = 18; |
||||
private static final int FONT_SIZE = 14; |
||||
private static final int SPINNER_WIDTH = 45; |
||||
private static final int SPINNER_HEIGHT = 20; |
||||
private static final int HALF_HUNDRED = 50; |
||||
private static final int HUNDRED = 100; |
||||
private static final int TWO_HUNDRED = 200; |
||||
private static final int THREE_HUNDRED = 300; |
||||
private static final int FOUR_HUNDRED = 400; |
||||
private static final int DIALOG_WIDTH = 150; |
||||
private static final int DIALOG_HEIGHT = 240; |
||||
private static final int SHOWVALBUTTON_WIDTH = 70; |
||||
private static final int SHOWVALBUTTON_HEIGHTH = 25; |
||||
public int showValue = 100; |
||||
public double resolutionTimes = 1.0; |
||||
private static JSliderPane THIS; |
||||
private UITextField showVal; |
||||
private JSpinner showValSpinner; |
||||
private UISlider slider; |
||||
private int times; |
||||
private int sliderValue; |
||||
private UIButton downButton; |
||||
private UIButton upButton; |
||||
private UIButton showValButton; |
||||
private UIRadioButton twoHundredButton; |
||||
private UIRadioButton oneHundredButton; |
||||
private UIRadioButton SevenFiveButton; |
||||
private UIRadioButton fiveTenButton; |
||||
private UIRadioButton twoFiveButton; |
||||
private UIRadioButton selfAdaptButton; |
||||
private UIRadioButton customButton; |
||||
//拖动条处理和button、直接输入不一样
|
||||
private boolean isButtonOrIsTxt = true; |
||||
private PopupPane dialog; |
||||
private int upButtonX; |
||||
private JPanel dialogContentPanel; |
||||
|
||||
|
||||
public JSliderPane() { |
||||
this.setLayout(new BorderLayout()); |
||||
slider = new UISlider(0, HUNDRED, HALF_HUNDRED); |
||||
slider.setUI(new JSliderPaneUI(slider)); |
||||
slider.addChangeListener(listener); |
||||
|
||||
showValSpinner = new UIBasicSpinner(new SpinnerNumberModel(HUNDRED, TEN, FOUR_HUNDRED, 1)); |
||||
showValSpinner.setEnabled(true); |
||||
showValSpinner.addChangeListener(showValSpinnerChangeListener); |
||||
showValSpinner.setPreferredSize(new Dimension(SPINNER_WIDTH, SPINNER_HEIGHT)); |
||||
//MoMeak:控制只能输入10-400,但是用起来感觉不舒服,先注释掉吧
|
||||
// JSpinner.NumberEditor editor = new JSpinner.NumberEditor(showValSpinner, "0");
|
||||
// showValSpinner.setEditor(editor);
|
||||
// JFormattedTextField textField = ((JSpinner.NumberEditor) showValSpinner.getEditor()).getTextField();
|
||||
// textField.setEditable(true);
|
||||
// DefaultFormatterFactory factory = (DefaultFormatterFactory) textField .getFormatterFactory();
|
||||
// NumberFormatter formatter = (NumberFormatter) factory.getDefaultFormatter();
|
||||
// formatter.setAllowsInvalid(false);
|
||||
downButton = new UIButton(BaseUtils.readIcon("com/fr/design/images/data/source/moveDown.png")); |
||||
upButton = new UIButton(BaseUtils.readIcon("com/fr/design/images/data/source/moveUp.png")); |
||||
downButton.setActionCommand("less"); |
||||
upButton.setActionCommand("more"); |
||||
downButton.addActionListener(buttonActionListener); |
||||
upButton.addActionListener(buttonActionListener); |
||||
|
||||
showValButton = new UIButton(showValSpinner.getValue() + "%"); |
||||
showValButton.setBorderPainted(false); |
||||
showValButton.setPreferredSize(new Dimension(SHOWVALBUTTON_WIDTH, SHOWVALBUTTON_HEIGHTH)); |
||||
showValButton.addActionListener(showValButtonActionListener); |
||||
initUIRadioButton(); |
||||
initPane(); |
||||
JPanel panel = new JPanel(new FlowLayout(1, 1, 0)); |
||||
panel.add(downButton); |
||||
panel.add(slider); |
||||
panel.add(upButton); |
||||
panel.add(showValButton); |
||||
this.add(panel, BorderLayout.NORTH); |
||||
this.setBounds(0, 0, THREE_HUNDRED, ONE_EIGHT); |
||||
} |
||||
|
||||
public static final JSliderPane getInstance() { |
||||
// if (THIS == null) {
|
||||
// THIS = new JSliderPane();
|
||||
// }
|
||||
THIS = new JSliderPane(); |
||||
return THIS; |
||||
} |
||||
|
||||
private void initUIRadioButton() { |
||||
twoHundredButton = new UIRadioButton("200%"); |
||||
oneHundredButton = new UIRadioButton("100%"); |
||||
SevenFiveButton = new UIRadioButton("75%"); |
||||
fiveTenButton = new UIRadioButton("50%"); |
||||
twoFiveButton = new UIRadioButton("25%"); |
||||
selfAdaptButton = new UIRadioButton(Inter.getLocText("FR-Designer_Scale_selfAdaptButton")); |
||||
customButton = new UIRadioButton(Inter.getLocText("FR-Designer_Scale_customButton")); |
||||
twoHundredButton.addItemListener(radioButtonItemListener); |
||||
oneHundredButton.addItemListener(radioButtonItemListener); |
||||
SevenFiveButton.addItemListener(radioButtonItemListener); |
||||
fiveTenButton.addItemListener(radioButtonItemListener); |
||||
twoFiveButton.addItemListener(radioButtonItemListener); |
||||
//TODO
|
||||
// selfAdaptButton.addItemListener();
|
||||
|
||||
ButtonGroup bg = new ButtonGroup();// 初始化按钮组
|
||||
bg.add(twoHundredButton);// 加入按钮组
|
||||
bg.add(oneHundredButton); |
||||
bg.add(SevenFiveButton); |
||||
bg.add(fiveTenButton); |
||||
bg.add(twoFiveButton); |
||||
bg.add(selfAdaptButton); |
||||
bg.add(customButton); |
||||
customButton.setSelected(true); |
||||
} |
||||
|
||||
private void initPane() { |
||||
double p = TableLayout.PREFERRED; |
||||
double f = TableLayout.FILL; |
||||
double[] columnSize = {p, f}; |
||||
double[] rowSize = {p, p, p, p, p, p, p}; |
||||
Component[][] components = new Component[][]{ |
||||
new Component[]{twoHundredButton, null}, |
||||
new Component[]{oneHundredButton, null}, |
||||
new Component[]{SevenFiveButton, null}, |
||||
new Component[]{fiveTenButton, null}, |
||||
new Component[]{twoFiveButton, null}, |
||||
new Component[]{selfAdaptButton, null}, |
||||
new Component[]{customButton, createSpinnerPanel()} |
||||
}; |
||||
dialogContentPanel = TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); |
||||
} |
||||
|
||||
private JPanel createSpinnerPanel() { |
||||
JPanel spinnerPanel = new JPanel(new FlowLayout()); |
||||
spinnerPanel.add(showValSpinner); |
||||
UILabel percent = new UILabel("%"); |
||||
percent.setFont(new Font("Dialog", Font.PLAIN, FONT_SIZE)); |
||||
spinnerPanel.add(percent); |
||||
return spinnerPanel; |
||||
} |
||||
|
||||
ActionListener showValButtonActionListener = new ActionListener() { |
||||
@Override |
||||
public void actionPerformed(ActionEvent e) { |
||||
popupDialog(); |
||||
} |
||||
}; |
||||
|
||||
ChangeListener showValSpinnerChangeListener = new ChangeListener() { |
||||
@Override |
||||
public void stateChanged(ChangeEvent e) { |
||||
int val = (int) ((UIBasicSpinner) e.getSource()).getValue(); |
||||
isButtonOrIsTxt = true; |
||||
resolutionTimes = divide(showValue, 100, 2); |
||||
if (val > FOUR_HUNDRED) { |
||||
showValSpinner.setValue(FOUR_HUNDRED); |
||||
val = FOUR_HUNDRED; |
||||
} |
||||
if (val < TEN) { |
||||
showValSpinner.setValue(TEN); |
||||
val = TEN; |
||||
} |
||||
refreshSlider(val); |
||||
refreshBottun(val); |
||||
} |
||||
}; |
||||
|
||||
|
||||
//定义一个监听器,用于监听所有滑动条
|
||||
ChangeListener listener = new ChangeListener() { |
||||
public void stateChanged(ChangeEvent event) { |
||||
//取出滑动条的值,并在文本中显示出来
|
||||
if (!isButtonOrIsTxt) { |
||||
customButton.setSelected(true); |
||||
EventQueue.invokeLater(new Runnable() { |
||||
public void run() { |
||||
sliderValue = slider.getValue(); |
||||
getTimes(sliderValue); |
||||
showValue = times; |
||||
showValSpinner.setValue(times); |
||||
} |
||||
}); |
||||
} else { |
||||
isButtonOrIsTxt = false; |
||||
} |
||||
} |
||||
}; |
||||
|
||||
ItemListener radioButtonItemListener = new ItemListener() { |
||||
@Override |
||||
public void itemStateChanged(ItemEvent e) { |
||||
JRadioButton temp = (JRadioButton) e.getSource(); |
||||
if (temp.isSelected()) { |
||||
showValSpinner.setValue(Integer.valueOf(temp.getText().substring(0, temp.getText().indexOf("%")))); |
||||
} |
||||
} |
||||
}; |
||||
|
||||
private void refreshSlider(int val) { |
||||
showValue = val; |
||||
if (showValue > HUNDRED) { |
||||
slider.setValue((int) (showValue + TWO_HUNDRED) / SIX); |
||||
} else if (showValue < HUNDRED) { |
||||
slider.setValue((int) ((showValue - TEN) / ONEPOINTEIGHT)); |
||||
} else if (showValue == HUNDRED) { |
||||
slider.setValue(HALF_HUNDRED); |
||||
} |
||||
} |
||||
|
||||
|
||||
private void refreshBottun(int val) { |
||||
showValButton.setText(val + "%"); |
||||
} |
||||
|
||||
public double getResolutionTimes() { |
||||
return this.resolutionTimes; |
||||
} |
||||
|
||||
public int getshowValue() { |
||||
return this.showValue; |
||||
} |
||||
|
||||
public static double divide(double v1, double v2, int scale) { |
||||
BigDecimal b1 = new BigDecimal(Double.toString(v1)); |
||||
BigDecimal b2 = new BigDecimal(Double.toString(v2)); |
||||
return b1.divide(b2, scale).doubleValue(); |
||||
} |
||||
|
||||
ActionListener buttonActionListener = new ActionListener() { |
||||
@Override |
||||
public void actionPerformed(ActionEvent e) { |
||||
showValue = (int) showValSpinner.getValue(); |
||||
isButtonOrIsTxt = true; |
||||
if (e.getActionCommand().equals("less")) { |
||||
int newDownVal = showValue - TEN; |
||||
if (newDownVal >= TEN) { |
||||
showValue = newDownVal; |
||||
showValSpinner.setValue(newDownVal); |
||||
} else { |
||||
showValue = newDownVal; |
||||
showValSpinner.setValue(TEN); |
||||
} |
||||
} |
||||
if (e.getActionCommand().equals("more")) { |
||||
int newUpVal = showValue + TEN; |
||||
if (newUpVal <= FOUR_HUNDRED) { |
||||
showValue = newUpVal; |
||||
showValSpinner.setValue(newUpVal); |
||||
} else { |
||||
showValue = newUpVal; |
||||
showValSpinner.setValue(FOUR_HUNDRED); |
||||
} |
||||
} |
||||
isButtonOrIsTxt = true; |
||||
customButton.setSelected(true); |
||||
} |
||||
}; |
||||
|
||||
|
||||
private void getTimes(int value) { |
||||
if (value == HALF_HUNDRED) { |
||||
times = HUNDRED; |
||||
} else if (value < HALF_HUNDRED) { |
||||
times = (int) Math.round(ONEPOINTEIGHT * value + TEN); |
||||
} else { |
||||
times = (int) (SIX * value - TWO_HUNDRED); |
||||
} |
||||
} |
||||
|
||||
|
||||
public JSpinner getShowVal() { |
||||
return this.showValSpinner; |
||||
} |
||||
|
||||
public UIRadioButton getSelfAdaptButton() { |
||||
return this.selfAdaptButton; |
||||
} |
||||
|
||||
private void popupDialog() { |
||||
Point btnCoords = upButton.getLocationOnScreen(); |
||||
if (dialog == null) { |
||||
dialog = new PopupPane(upButton, dialogContentPanel); |
||||
if (upButtonX == 0) { |
||||
upButtonX = btnCoords.x; |
||||
GUICoreUtils.showPopupMenu(dialog, upButton, -DIALOG_WIDTH + upButton.getWidth() + SHOWVALBUTTON_WIDTH, -DIALOG_HEIGHT); |
||||
} |
||||
} else { |
||||
if (upButtonX == 0) { |
||||
upButtonX = btnCoords.x; |
||||
GUICoreUtils.showPopupMenu(dialog, upButton, -DIALOG_WIDTH + upButton.getWidth() + SHOWVALBUTTON_WIDTH, -DIALOG_HEIGHT); |
||||
} else { |
||||
GUICoreUtils.showPopupMenu(dialog, upButton, -DIALOG_WIDTH + upButton.getWidth() + SHOWVALBUTTON_WIDTH, -DIALOG_HEIGHT); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public static void main(String[] args) { |
||||
JFrame jf = new JFrame("test"); |
||||
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
||||
JPanel content = (JPanel) jf.getContentPane(); |
||||
content.setLayout(new BorderLayout()); |
||||
content.add(JSliderPane.getInstance(), BorderLayout.CENTER); |
||||
GUICoreUtils.centerWindow(jf); |
||||
jf.setSize(400, 80); |
||||
jf.setVisible(true); |
||||
|
||||
} |
||||
} |
||||
|
||||
class JSliderPaneUI extends BasicSliderUI { |
||||
|
||||
private static final int VERTICAL_WIDTH = 11; |
||||
private static final int VERTICAL_HEIGHT = 16; |
||||
private static final int FOUR = 4; |
||||
private static final int FIVE = 5; |
||||
private static final int SIX = 6; |
||||
|
||||
public JSliderPaneUI(UISlider b) { |
||||
super(b); |
||||
} |
||||
|
||||
/** */ |
||||
/** |
||||
* 绘制指示物 |
||||
*/ |
||||
|
||||
public Dimension getThumbSize() { |
||||
Dimension size = new Dimension(); |
||||
|
||||
if (slider.getOrientation() == JSlider.VERTICAL) { |
||||
size.width = VERTICAL_WIDTH; |
||||
size.height = VERTICAL_HEIGHT; |
||||
} else { |
||||
size.width = VERTICAL_WIDTH; |
||||
size.height = VERTICAL_HEIGHT; |
||||
} |
||||
|
||||
return size; |
||||
} |
||||
|
||||
public void paintThumb(Graphics g) { |
||||
Rectangle knobBounds = thumbRect; |
||||
int w = knobBounds.width; |
||||
int h = knobBounds.height; |
||||
|
||||
g.translate(knobBounds.x, knobBounds.y); |
||||
if (slider.isEnabled()) { |
||||
g.setColor(slider.getBackground()); |
||||
} else { |
||||
g.setColor(slider.getBackground().darker()); |
||||
} |
||||
g.setColor(Color.darkGray); |
||||
g.fillRect(0, 1, w - SIX, h + 1); |
||||
} |
||||
|
||||
/** */ |
||||
/** |
||||
* 绘制刻度轨迹 |
||||
*/ |
||||
public void paintTrack(Graphics g) { |
||||
int cy, cw; |
||||
Rectangle trackBounds = trackRect; |
||||
if (slider.getOrientation() == UISlider.HORIZONTAL) { |
||||
Graphics2D g2 = (Graphics2D) g; |
||||
cy = (trackBounds.height / 2); |
||||
cw = trackBounds.width; |
||||
g.setColor(Color.lightGray); |
||||
g.drawLine(0, cy, cw + FIVE, cy); |
||||
g.drawLine(FIVE + cw / 2, cy - FOUR, FIVE + cw / 2, cy + FOUR); |
||||
} else { |
||||
super.paintTrack(g); |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
class PopupPane extends JPopupMenu { |
||||
private JComponent contentPane; |
||||
private static final int UPLABEL_HEIGHT = 25; |
||||
private static final int DIALOG_WIDTH = 150; |
||||
private static final int DIALOG_HEIGHT = 240; |
||||
private static final int UPLABEL_WIDTH = 300; |
||||
private JComponent centerPane; |
||||
private UILabel upLabel; |
||||
|
||||
PopupPane(UIButton b, JPanel dialogContentPanel) { |
||||
contentPane = new JPanel(new BorderLayout()); |
||||
centerPane = new JPanel(new BorderLayout()); |
||||
upLabel = new UILabel(" " + Inter.getLocText("FR-Designer_Scale_EnlargeOrReduce")); |
||||
upLabel.setOpaque(true); |
||||
upLabel.setPreferredSize(new Dimension(UPLABEL_WIDTH, UPLABEL_HEIGHT)); |
||||
upLabel.setBackground(Color.LIGHT_GRAY); |
||||
upLabel.setBorder(new MatteBorder(0, 0, 1, 0, Color.gray)); |
||||
centerPane.add(dialogContentPanel, BorderLayout.NORTH); |
||||
contentPane.add(upLabel, BorderLayout.NORTH); |
||||
contentPane.add(centerPane, BorderLayout.CENTER); |
||||
// contentPane.setBorder(new MatteBorder(1,1,1,1,Color.darkGray));
|
||||
this.add(contentPane, BorderLayout.CENTER); |
||||
this.setPreferredSize(new Dimension(DIALOG_WIDTH, DIALOG_HEIGHT)); |
||||
this.setOpaque(false); |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,42 @@
|
||||
package com.fr.design.mainframe.loghandler; |
||||
|
||||
import org.apache.log4j.AppenderSkeleton; |
||||
import org.apache.log4j.Level; |
||||
import org.apache.log4j.spi.LoggingEvent; |
||||
|
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* Created by Administrator on 2017/7/18 0018. |
||||
*/ |
||||
public class DesignerLogAppender extends AppenderSkeleton { |
||||
|
||||
public DesignerLogAppender() { |
||||
this.layout = new org.apache.log4j.PatternLayout("%d{HH:mm:ss} %t %p [%c] %m%n"); |
||||
} |
||||
|
||||
protected void append(LoggingEvent event) { |
||||
this.subAppend(event); |
||||
} |
||||
|
||||
public boolean requiresLayout() { |
||||
return true; |
||||
} |
||||
|
||||
public synchronized void close() { |
||||
if (this.closed) { |
||||
return; |
||||
} |
||||
this.closed = true; |
||||
|
||||
} |
||||
|
||||
public void subAppend(LoggingEvent event) { |
||||
synchronized (DesignerLogHandler.getInstance()) { |
||||
Level level = event.getLevel(); |
||||
String msg = this.layout.format(event); |
||||
DesignerLogHandler.getInstance().printRemoteLog(msg, level, new Date()); |
||||
} |
||||
} |
||||
} |
||||
|
@ -0,0 +1,40 @@
|
||||
package com.fr.design.preview; |
||||
|
||||
import com.fr.base.io.IOFile; |
||||
import com.fr.design.fun.impl.AbstractPreviewProvider; |
||||
import com.fr.general.Inter; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* Created by loy on 2017/7/7. |
||||
*/ |
||||
public class WriteEnhancePreview extends AbstractPreviewProvider { |
||||
@Override |
||||
public String nameForPopupItem() { |
||||
return Inter.getLocText("FR-Designer_Write_Enhance_Preview"); |
||||
} |
||||
|
||||
@Override |
||||
public String iconPathForPopupItem() { |
||||
return "com/fr/design/images/buttonicon/writes.png"; |
||||
} |
||||
|
||||
@Override |
||||
public String iconPathForLarge() { |
||||
return "com/fr/design/images/buttonicon/writeb24.png"; |
||||
} |
||||
|
||||
@Override |
||||
public int previewTypeCode() { |
||||
return IOFile.WRITE_PREVIEW_TYPE; |
||||
} |
||||
|
||||
@Override |
||||
public Map<String, Object> parametersForPreview() { |
||||
Map<String, Object> map = new HashMap<String, Object>(); |
||||
map.put("op", "write_ex"); |
||||
return map; |
||||
} |
||||
} |
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue