first commit
This commit is contained in:
commit
4d332ef662
27586 changed files with 3281783 additions and 0 deletions
4
rus/WEB-INF/lib/jcommon-1.0.12_src/META-INF/MANIFEST.MF
Normal file
4
rus/WEB-INF/lib/jcommon-1.0.12_src/META-INF/MANIFEST.MF
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
Manifest-Version: 1.0
|
||||
Ant-Version: Apache Ant 1.6.2
|
||||
Created-By: 1.4.2_10-b03 (Sun Microsystems Inc.)
|
||||
|
||||
342
rus/WEB-INF/lib/jcommon-1.0.12_src/com/keypoint/PngEncoder.java
Normal file
342
rus/WEB-INF/lib/jcommon-1.0.12_src/com/keypoint/PngEncoder.java
Normal file
|
|
@ -0,0 +1,342 @@
|
|||
package com.keypoint;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.awt.image.PixelGrabber;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.zip.CRC32;
|
||||
import java.util.zip.Deflater;
|
||||
import java.util.zip.DeflaterOutputStream;
|
||||
|
||||
public class PngEncoder {
|
||||
public static final boolean ENCODE_ALPHA = true;
|
||||
|
||||
public static final boolean NO_ALPHA = false;
|
||||
|
||||
public static final int FILTER_NONE = 0;
|
||||
|
||||
public static final int FILTER_SUB = 1;
|
||||
|
||||
public static final int FILTER_UP = 2;
|
||||
|
||||
public static final int FILTER_LAST = 2;
|
||||
|
||||
protected static final byte[] IHDR = new byte[] { 73, 72, 68, 82 };
|
||||
|
||||
protected static final byte[] IDAT = new byte[] { 73, 68, 65, 84 };
|
||||
|
||||
protected static final byte[] IEND = new byte[] { 73, 69, 78, 68 };
|
||||
|
||||
protected static final byte[] PHYS = new byte[] { 112, 72, 89, 115 };
|
||||
|
||||
protected byte[] pngBytes;
|
||||
|
||||
protected byte[] priorRow;
|
||||
|
||||
protected byte[] leftBytes;
|
||||
|
||||
protected Image image;
|
||||
|
||||
protected int width;
|
||||
|
||||
protected int height;
|
||||
|
||||
protected int bytePos;
|
||||
|
||||
protected int maxPos;
|
||||
|
||||
protected CRC32 crc = new CRC32();
|
||||
|
||||
protected long crcValue;
|
||||
|
||||
protected boolean encodeAlpha;
|
||||
|
||||
protected int filter;
|
||||
|
||||
protected int bytesPerPixel;
|
||||
|
||||
private int xDpi = 0;
|
||||
|
||||
private int yDpi = 0;
|
||||
|
||||
private static float INCH_IN_METER_UNIT = 0.0254F;
|
||||
|
||||
protected int compressionLevel;
|
||||
|
||||
public PngEncoder() {
|
||||
this(null, false, 0, 0);
|
||||
}
|
||||
|
||||
public PngEncoder(Image image) {
|
||||
this(image, false, 0, 0);
|
||||
}
|
||||
|
||||
public PngEncoder(Image image, boolean encodeAlpha) {
|
||||
this(image, encodeAlpha, 0, 0);
|
||||
}
|
||||
|
||||
public PngEncoder(Image image, boolean encodeAlpha, int whichFilter) {
|
||||
this(image, encodeAlpha, whichFilter, 0);
|
||||
}
|
||||
|
||||
public PngEncoder(Image image, boolean encodeAlpha, int whichFilter, int compLevel) {
|
||||
this.image = image;
|
||||
this.encodeAlpha = encodeAlpha;
|
||||
setFilter(whichFilter);
|
||||
if (compLevel >= 0 && compLevel <= 9)
|
||||
this.compressionLevel = compLevel;
|
||||
}
|
||||
|
||||
public void setImage(Image image) {
|
||||
this.image = image;
|
||||
this.pngBytes = null;
|
||||
}
|
||||
|
||||
public Image getImage() {
|
||||
return this.image;
|
||||
}
|
||||
|
||||
public byte[] pngEncode(boolean encodeAlpha) {
|
||||
byte[] pngIdBytes = { -119, 80, 78, 71, 13, 10, 26, 10 };
|
||||
if (this.image == null)
|
||||
return null;
|
||||
this.width = this.image.getWidth(null);
|
||||
this.height = this.image.getHeight(null);
|
||||
this.pngBytes = new byte[(this.width + 1) * this.height * 3 + 200];
|
||||
this.maxPos = 0;
|
||||
this.bytePos = writeBytes(pngIdBytes, 0);
|
||||
writeHeader();
|
||||
writeResolution();
|
||||
if (writeImageData()) {
|
||||
writeEnd();
|
||||
this.pngBytes = resizeByteArray(this.pngBytes, this.maxPos);
|
||||
} else {
|
||||
this.pngBytes = null;
|
||||
}
|
||||
return this.pngBytes;
|
||||
}
|
||||
|
||||
public byte[] pngEncode() {
|
||||
return pngEncode(this.encodeAlpha);
|
||||
}
|
||||
|
||||
public void setEncodeAlpha(boolean encodeAlpha) {
|
||||
this.encodeAlpha = encodeAlpha;
|
||||
}
|
||||
|
||||
public boolean getEncodeAlpha() {
|
||||
return this.encodeAlpha;
|
||||
}
|
||||
|
||||
public void setFilter(int whichFilter) {
|
||||
this.filter = 0;
|
||||
if (whichFilter <= 2)
|
||||
this.filter = whichFilter;
|
||||
}
|
||||
|
||||
public int getFilter() {
|
||||
return this.filter;
|
||||
}
|
||||
|
||||
public void setCompressionLevel(int level) {
|
||||
if (level >= 0 && level <= 9)
|
||||
this.compressionLevel = level;
|
||||
}
|
||||
|
||||
public int getCompressionLevel() {
|
||||
return this.compressionLevel;
|
||||
}
|
||||
|
||||
protected byte[] resizeByteArray(byte[] array, int newLength) {
|
||||
byte[] newArray = new byte[newLength];
|
||||
int oldLength = array.length;
|
||||
System.arraycopy(array, 0, newArray, 0, Math.min(oldLength, newLength));
|
||||
return newArray;
|
||||
}
|
||||
|
||||
protected int writeBytes(byte[] data, int offset) {
|
||||
this.maxPos = Math.max(this.maxPos, offset + data.length);
|
||||
if (data.length + offset > this.pngBytes.length)
|
||||
this.pngBytes = resizeByteArray(this.pngBytes, this.pngBytes.length + Math.max(1000, data.length));
|
||||
System.arraycopy(data, 0, this.pngBytes, offset, data.length);
|
||||
return offset + data.length;
|
||||
}
|
||||
|
||||
protected int writeBytes(byte[] data, int nBytes, int offset) {
|
||||
this.maxPos = Math.max(this.maxPos, offset + nBytes);
|
||||
if (nBytes + offset > this.pngBytes.length)
|
||||
this.pngBytes = resizeByteArray(this.pngBytes, this.pngBytes.length + Math.max(1000, nBytes));
|
||||
System.arraycopy(data, 0, this.pngBytes, offset, nBytes);
|
||||
return offset + nBytes;
|
||||
}
|
||||
|
||||
protected int writeInt2(int n, int offset) {
|
||||
byte[] temp = { (byte)(n >> 8 & 0xFF), (byte)(n & 0xFF) };
|
||||
return writeBytes(temp, offset);
|
||||
}
|
||||
|
||||
protected int writeInt4(int n, int offset) {
|
||||
byte[] temp = { (byte)(n >> 24 & 0xFF), (byte)(n >> 16 & 0xFF), (byte)(n >> 8 & 0xFF), (byte)(n & 0xFF) };
|
||||
return writeBytes(temp, offset);
|
||||
}
|
||||
|
||||
protected int writeByte(int b, int offset) {
|
||||
byte[] temp = { (byte)b };
|
||||
return writeBytes(temp, offset);
|
||||
}
|
||||
|
||||
protected void writeHeader() {
|
||||
int startPos = this.bytePos = writeInt4(13, this.bytePos);
|
||||
this.bytePos = writeBytes(IHDR, this.bytePos);
|
||||
this.width = this.image.getWidth(null);
|
||||
this.height = this.image.getHeight(null);
|
||||
this.bytePos = writeInt4(this.width, this.bytePos);
|
||||
this.bytePos = writeInt4(this.height, this.bytePos);
|
||||
this.bytePos = writeByte(8, this.bytePos);
|
||||
this.bytePos = writeByte(this.encodeAlpha ? 6 : 2, this.bytePos);
|
||||
this.bytePos = writeByte(0, this.bytePos);
|
||||
this.bytePos = writeByte(0, this.bytePos);
|
||||
this.bytePos = writeByte(0, this.bytePos);
|
||||
this.crc.reset();
|
||||
this.crc.update(this.pngBytes, startPos, this.bytePos - startPos);
|
||||
this.crcValue = this.crc.getValue();
|
||||
this.bytePos = writeInt4((int)this.crcValue, this.bytePos);
|
||||
}
|
||||
|
||||
protected void filterSub(byte[] pixels, int startPos, int width) {
|
||||
int offset = this.bytesPerPixel;
|
||||
int actualStart = startPos + offset;
|
||||
int nBytes = width * this.bytesPerPixel;
|
||||
int leftInsert = offset;
|
||||
int leftExtract = 0;
|
||||
for (int i = actualStart; i < startPos + nBytes; i++) {
|
||||
this.leftBytes[leftInsert] = pixels[i];
|
||||
pixels[i] = (byte)((pixels[i] - this.leftBytes[leftExtract]) % 256);
|
||||
leftInsert = (leftInsert + 1) % 15;
|
||||
leftExtract = (leftExtract + 1) % 15;
|
||||
}
|
||||
}
|
||||
|
||||
protected void filterUp(byte[] pixels, int startPos, int width) {
|
||||
int nBytes = width * this.bytesPerPixel;
|
||||
for (int i = 0; i < nBytes; i++) {
|
||||
byte currentByte = pixels[startPos + i];
|
||||
pixels[startPos + i] = (byte)((pixels[startPos + i] - this.priorRow[i]) % 256);
|
||||
this.priorRow[i] = currentByte;
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean writeImageData() {
|
||||
int rowsLeft = this.height;
|
||||
int startRow = 0;
|
||||
this.bytesPerPixel = this.encodeAlpha ? 4 : 3;
|
||||
Deflater scrunch = new Deflater(this.compressionLevel);
|
||||
ByteArrayOutputStream outBytes = new ByteArrayOutputStream(1024);
|
||||
DeflaterOutputStream compBytes = new DeflaterOutputStream(outBytes, scrunch);
|
||||
try {
|
||||
while (rowsLeft > 0) {
|
||||
int nRows = Math.min(32767 / (this.width * (this.bytesPerPixel + 1)), rowsLeft);
|
||||
nRows = Math.max(nRows, 1);
|
||||
int[] pixels = new int[this.width * nRows];
|
||||
PixelGrabber pg = new PixelGrabber(this.image, 0, startRow, this.width, nRows, pixels, 0, this.width);
|
||||
try {
|
||||
pg.grabPixels();
|
||||
} catch (Exception e) {
|
||||
System.err.println("interrupted waiting for pixels!");
|
||||
return false;
|
||||
}
|
||||
if ((pg.getStatus() & 0x80) != 0) {
|
||||
System.err.println("image fetch aborted or errored");
|
||||
return false;
|
||||
}
|
||||
byte[] scanLines = new byte[this.width * nRows * this.bytesPerPixel + nRows];
|
||||
if (this.filter == 1)
|
||||
this.leftBytes = new byte[16];
|
||||
if (this.filter == 2)
|
||||
this.priorRow = new byte[this.width * this.bytesPerPixel];
|
||||
int scanPos = 0;
|
||||
int startPos = 1;
|
||||
for (int i = 0; i < this.width * nRows; i++) {
|
||||
if (i % this.width == 0) {
|
||||
scanLines[scanPos++] = (byte)this.filter;
|
||||
startPos = scanPos;
|
||||
}
|
||||
scanLines[scanPos++] = (byte)(pixels[i] >> 16 & 0xFF);
|
||||
scanLines[scanPos++] = (byte)(pixels[i] >> 8 & 0xFF);
|
||||
scanLines[scanPos++] = (byte)(pixels[i] & 0xFF);
|
||||
if (this.encodeAlpha)
|
||||
scanLines[scanPos++] = (byte)(pixels[i] >> 24 & 0xFF);
|
||||
if (i % this.width == this.width - 1 && this.filter != 0) {
|
||||
if (this.filter == 1)
|
||||
filterSub(scanLines, startPos, this.width);
|
||||
if (this.filter == 2)
|
||||
filterUp(scanLines, startPos, this.width);
|
||||
}
|
||||
}
|
||||
compBytes.write(scanLines, 0, scanPos);
|
||||
startRow += nRows;
|
||||
rowsLeft -= nRows;
|
||||
}
|
||||
compBytes.close();
|
||||
byte[] compressedLines = outBytes.toByteArray();
|
||||
int nCompressed = compressedLines.length;
|
||||
this.crc.reset();
|
||||
this.bytePos = writeInt4(nCompressed, this.bytePos);
|
||||
this.bytePos = writeBytes(IDAT, this.bytePos);
|
||||
this.crc.update(IDAT);
|
||||
this.bytePos = writeBytes(compressedLines, nCompressed, this.bytePos);
|
||||
this.crc.update(compressedLines, 0, nCompressed);
|
||||
this.crcValue = this.crc.getValue();
|
||||
this.bytePos = writeInt4((int)this.crcValue, this.bytePos);
|
||||
scrunch.finish();
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
System.err.println(e.toString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected void writeEnd() {
|
||||
this.bytePos = writeInt4(0, this.bytePos);
|
||||
this.bytePos = writeBytes(IEND, this.bytePos);
|
||||
this.crc.reset();
|
||||
this.crc.update(IEND);
|
||||
this.crcValue = this.crc.getValue();
|
||||
this.bytePos = writeInt4((int)this.crcValue, this.bytePos);
|
||||
}
|
||||
|
||||
public void setXDpi(int xDpi) {
|
||||
this.xDpi = Math.round((float)xDpi / INCH_IN_METER_UNIT);
|
||||
}
|
||||
|
||||
public int getXDpi() {
|
||||
return Math.round((float)this.xDpi * INCH_IN_METER_UNIT);
|
||||
}
|
||||
|
||||
public void setYDpi(int yDpi) {
|
||||
this.yDpi = Math.round((float)yDpi / INCH_IN_METER_UNIT);
|
||||
}
|
||||
|
||||
public int getYDpi() {
|
||||
return Math.round((float)this.yDpi * INCH_IN_METER_UNIT);
|
||||
}
|
||||
|
||||
public void setDpi(int xDpi, int yDpi) {
|
||||
this.xDpi = Math.round((float)xDpi / INCH_IN_METER_UNIT);
|
||||
this.yDpi = Math.round((float)yDpi / INCH_IN_METER_UNIT);
|
||||
}
|
||||
|
||||
protected void writeResolution() {
|
||||
if (this.xDpi > 0 && this.yDpi > 0) {
|
||||
int startPos = this.bytePos = writeInt4(9, this.bytePos);
|
||||
this.bytePos = writeBytes(PHYS, this.bytePos);
|
||||
this.bytePos = writeInt4(this.xDpi, this.bytePos);
|
||||
this.bytePos = writeInt4(this.yDpi, this.bytePos);
|
||||
this.bytePos = writeByte(1, this.bytePos);
|
||||
this.crc.reset();
|
||||
this.crc.update(this.pngBytes, startPos, this.bytePos - startPos);
|
||||
this.crcValue = this.crc.getValue();
|
||||
this.bytePos = writeInt4((int)this.crcValue, this.bytePos);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
rus/WEB-INF/lib/jcommon-1.0.12_src/org/jfree/JCommon.java
Normal file
11
rus/WEB-INF/lib/jcommon-1.0.12_src/org/jfree/JCommon.java
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
package org.jfree;
|
||||
|
||||
import org.jfree.ui.about.ProjectInfo;
|
||||
|
||||
public final class JCommon {
|
||||
public static final ProjectInfo INFO = JCommonInfo.getInstance();
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(INFO.toString());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
package org.jfree;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.ResourceBundle;
|
||||
import org.jfree.base.BaseBoot;
|
||||
import org.jfree.base.Library;
|
||||
import org.jfree.ui.about.Contributor;
|
||||
import org.jfree.ui.about.Licences;
|
||||
import org.jfree.ui.about.ProjectInfo;
|
||||
|
||||
public class JCommonInfo extends ProjectInfo {
|
||||
private static JCommonInfo singleton;
|
||||
|
||||
public static synchronized JCommonInfo getInstance() {
|
||||
if (singleton == null)
|
||||
singleton = new JCommonInfo();
|
||||
return singleton;
|
||||
}
|
||||
|
||||
private JCommonInfo() {
|
||||
String baseResourceClass = "org.jfree.resources.JCommonResources";
|
||||
ResourceBundle resources = ResourceBundle.getBundle("org.jfree.resources.JCommonResources");
|
||||
setName(resources.getString("project.name"));
|
||||
setVersion(resources.getString("project.version"));
|
||||
setInfo(resources.getString("project.info"));
|
||||
setCopyright(resources.getString("project.copyright"));
|
||||
setLicenceName("LGPL");
|
||||
setLicenceText(Licences.getInstance().getLGPL());
|
||||
setContributors(Arrays.asList(new Contributor[] {
|
||||
new Contributor("Anthony Boulestreau", "-"), new Contributor("Jeremy Bowman", "-"), new Contributor("J. David Eisenberg", "-"), new Contributor("Paul English", "-"), new Contributor("David Gilbert", "david.gilbert@object-refinery.com"), new Contributor("Hans-Jurgen Greiner", "-"), new Contributor("Arik Levin", "-"), new Contributor("Achilleus Mantzios", "-"), new Contributor("Thomas Meier", "-"), new Contributor("Aaron Metzger", "-"),
|
||||
new Contributor("Thomas Morgner", "-"), new Contributor("Krzysztof Paz", "-"), new Contributor("Nabuo Tamemasa", "-"), new Contributor("Mark Watson", "-"), new Contributor("Matthew Wright", "-"), new Contributor("Hari", "-"), new Contributor("Sam (oldman)", "-") }));
|
||||
addOptionalLibrary(new Library("JUnit", "3.8", "IBM Public Licence", "http://www.junit.org/"));
|
||||
setBootClass(BaseBoot.class.getName());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,166 @@
|
|||
package org.jfree.base;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import org.jfree.base.config.HierarchicalConfiguration;
|
||||
import org.jfree.base.config.PropertyFileConfiguration;
|
||||
import org.jfree.base.config.SystemPropertyConfiguration;
|
||||
import org.jfree.base.modules.PackageManager;
|
||||
import org.jfree.base.modules.SubSystem;
|
||||
import org.jfree.util.Configuration;
|
||||
import org.jfree.util.ExtendedConfiguration;
|
||||
import org.jfree.util.ExtendedConfigurationWrapper;
|
||||
import org.jfree.util.Log;
|
||||
import org.jfree.util.ObjectUtilities;
|
||||
|
||||
public abstract class AbstractBoot implements SubSystem {
|
||||
private ExtendedConfigurationWrapper extWrapper;
|
||||
|
||||
private PackageManager packageManager;
|
||||
|
||||
private Configuration globalConfig;
|
||||
|
||||
private boolean bootInProgress;
|
||||
|
||||
private boolean bootDone;
|
||||
|
||||
public synchronized PackageManager getPackageManager() {
|
||||
if (this.packageManager == null)
|
||||
this.packageManager = PackageManager.createInstance(this);
|
||||
return this.packageManager;
|
||||
}
|
||||
|
||||
public synchronized Configuration getGlobalConfig() {
|
||||
if (this.globalConfig == null)
|
||||
this.globalConfig = loadConfiguration();
|
||||
return this.globalConfig;
|
||||
}
|
||||
|
||||
public final synchronized boolean isBootInProgress() {
|
||||
return this.bootInProgress;
|
||||
}
|
||||
|
||||
public final synchronized boolean isBootDone() {
|
||||
return this.bootDone;
|
||||
}
|
||||
|
||||
public final void start() {
|
||||
synchronized (this) {
|
||||
if (isBootDone())
|
||||
return;
|
||||
while (isBootInProgress()) {
|
||||
try {
|
||||
wait();
|
||||
} catch (InterruptedException e) {}
|
||||
}
|
||||
if (isBootDone())
|
||||
return;
|
||||
this.bootInProgress = true;
|
||||
}
|
||||
BootableProjectInfo bootableProjectInfo = getProjectInfo();
|
||||
if (bootableProjectInfo != null) {
|
||||
BootableProjectInfo[] childs = bootableProjectInfo.getDependencies();
|
||||
for (int i = 0; i < childs.length; i++) {
|
||||
AbstractBoot boot = loadBooter(childs[i].getBootClass());
|
||||
if (boot != null)
|
||||
synchronized (boot) {
|
||||
boot.start();
|
||||
while (!boot.isBootDone()) {
|
||||
try {
|
||||
boot.wait();
|
||||
} catch (InterruptedException e) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
performBoot();
|
||||
if (bootableProjectInfo != null) {
|
||||
Log.info(bootableProjectInfo.getName() + " " + bootableProjectInfo.getVersion() + " started.");
|
||||
} else {
|
||||
Log.info(getClass() + " started.");
|
||||
}
|
||||
synchronized (this) {
|
||||
this.bootInProgress = false;
|
||||
this.bootDone = true;
|
||||
notifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
protected AbstractBoot loadBooter(String classname) {
|
||||
if (classname == null)
|
||||
return null;
|
||||
try {
|
||||
Class c = ObjectUtilities.getClassLoader(getClass()).loadClass(classname);
|
||||
Method m = c.getMethod("getInstance", null);
|
||||
return (AbstractBoot)m.invoke(null, null);
|
||||
} catch (Exception e) {
|
||||
Log.info("Unable to boot dependent class: " + classname);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected Configuration createDefaultHierarchicalConfiguration(String staticConfig, String userConfig, boolean addSysProps) {
|
||||
return createDefaultHierarchicalConfiguration(staticConfig, userConfig, addSysProps, PropertyFileConfiguration.class);
|
||||
}
|
||||
|
||||
protected Configuration createDefaultHierarchicalConfiguration(String staticConfig, String userConfig, boolean addSysProps, Class source) {
|
||||
HierarchicalConfiguration globalConfig = new HierarchicalConfiguration();
|
||||
if (staticConfig != null) {
|
||||
PropertyFileConfiguration rootProperty = new PropertyFileConfiguration();
|
||||
rootProperty.load(staticConfig, getClass());
|
||||
globalConfig.insertConfiguration(rootProperty);
|
||||
globalConfig.insertConfiguration(getPackageManager().getPackageConfiguration());
|
||||
}
|
||||
if (userConfig != null) {
|
||||
String userConfigStripped;
|
||||
if (userConfig.startsWith("/")) {
|
||||
userConfigStripped = userConfig.substring(1);
|
||||
} else {
|
||||
userConfigStripped = userConfig;
|
||||
}
|
||||
try {
|
||||
Enumeration userConfigs = ObjectUtilities.getClassLoader(getClass()).getResources(userConfigStripped);
|
||||
ArrayList configs = new ArrayList();
|
||||
while (userConfigs.hasMoreElements()) {
|
||||
URL url = (URL)userConfigs.nextElement();
|
||||
try {
|
||||
PropertyFileConfiguration baseProperty = new PropertyFileConfiguration();
|
||||
InputStream in = url.openStream();
|
||||
baseProperty.load(in);
|
||||
in.close();
|
||||
configs.add(baseProperty);
|
||||
} catch (IOException ioe) {
|
||||
Log.warn("Failed to load the user configuration at " + url, ioe);
|
||||
}
|
||||
}
|
||||
for (int i = configs.size() - 1; i >= 0; i--) {
|
||||
PropertyFileConfiguration baseProperty = (PropertyFileConfiguration)configs.get(i);
|
||||
globalConfig.insertConfiguration(baseProperty);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.warn("Failed to lookup the user configurations.", e);
|
||||
}
|
||||
}
|
||||
if (addSysProps) {
|
||||
SystemPropertyConfiguration systemConfig = new SystemPropertyConfiguration();
|
||||
globalConfig.insertConfiguration(systemConfig);
|
||||
}
|
||||
return globalConfig;
|
||||
}
|
||||
|
||||
public synchronized ExtendedConfiguration getExtendedConfig() {
|
||||
if (this.extWrapper == null)
|
||||
this.extWrapper = new ExtendedConfigurationWrapper(getGlobalConfig());
|
||||
return this.extWrapper;
|
||||
}
|
||||
|
||||
protected abstract Configuration loadConfiguration();
|
||||
|
||||
protected abstract void performBoot();
|
||||
|
||||
protected abstract BootableProjectInfo getProjectInfo();
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
package org.jfree.base;
|
||||
|
||||
import org.jfree.JCommon;
|
||||
import org.jfree.base.config.ModifiableConfiguration;
|
||||
import org.jfree.base.log.DefaultLogModule;
|
||||
import org.jfree.util.Configuration;
|
||||
import org.jfree.util.ObjectUtilities;
|
||||
|
||||
public class BaseBoot extends AbstractBoot {
|
||||
private static BaseBoot singleton;
|
||||
|
||||
private BootableProjectInfo bootableProjectInfo = JCommon.INFO;
|
||||
|
||||
public static ModifiableConfiguration getConfiguration() {
|
||||
return (ModifiableConfiguration)getInstance().getGlobalConfig();
|
||||
}
|
||||
|
||||
protected synchronized Configuration loadConfiguration() {
|
||||
return createDefaultHierarchicalConfiguration("/org/jfree/base/jcommon.properties", "/jcommon.properties", true, BaseBoot.class);
|
||||
}
|
||||
|
||||
public static synchronized AbstractBoot getInstance() {
|
||||
if (singleton == null)
|
||||
singleton = new BaseBoot();
|
||||
return singleton;
|
||||
}
|
||||
|
||||
protected void performBoot() {
|
||||
ObjectUtilities.setClassLoaderSource(getConfiguration().getConfigProperty("org.jfree.ClassLoader"));
|
||||
getPackageManager().addModule(DefaultLogModule.class.getName());
|
||||
getPackageManager().load("org.jfree.jcommon.modules.");
|
||||
getPackageManager().initializeModules();
|
||||
}
|
||||
|
||||
protected BootableProjectInfo getProjectInfo() {
|
||||
return this.bootableProjectInfo;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,134 @@
|
|||
package org.jfree.base;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.jfree.util.ObjectUtilities;
|
||||
|
||||
public class BasicProjectInfo extends Library {
|
||||
private String copyright;
|
||||
|
||||
private List libraries;
|
||||
|
||||
private List optionalLibraries;
|
||||
|
||||
private static class OptionalLibraryHolder {
|
||||
private String libraryClass;
|
||||
|
||||
private transient Library library;
|
||||
|
||||
public OptionalLibraryHolder(String libraryClass) {
|
||||
if (libraryClass == null)
|
||||
throw new NullPointerException("LibraryClass must not be null.");
|
||||
this.libraryClass = libraryClass;
|
||||
}
|
||||
|
||||
public OptionalLibraryHolder(Library library) {
|
||||
if (library == null)
|
||||
throw new NullPointerException("Library must not be null.");
|
||||
this.library = library;
|
||||
this.libraryClass = library.getClass().getName();
|
||||
}
|
||||
|
||||
public String getLibraryClass() {
|
||||
return this.libraryClass;
|
||||
}
|
||||
|
||||
public Library getLibrary() {
|
||||
if (this.library == null)
|
||||
this.library = loadLibrary(this.libraryClass);
|
||||
return this.library;
|
||||
}
|
||||
|
||||
protected Library loadLibrary(String classname) {
|
||||
if (classname == null)
|
||||
return null;
|
||||
try {
|
||||
Class c = ObjectUtilities.getClassLoader(getClass()).loadClass(classname);
|
||||
try {
|
||||
Method m = c.getMethod("getInstance", null);
|
||||
return (Library)m.invoke(null, null);
|
||||
} catch (Exception e) {
|
||||
return (Library)c.newInstance();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public BasicProjectInfo() {
|
||||
this.libraries = new ArrayList();
|
||||
this.optionalLibraries = new ArrayList();
|
||||
}
|
||||
|
||||
public BasicProjectInfo(String name, String version, String licence, String info) {
|
||||
this();
|
||||
setName(name);
|
||||
setVersion(version);
|
||||
setLicenceName(licence);
|
||||
setInfo(info);
|
||||
}
|
||||
|
||||
public BasicProjectInfo(String name, String version, String info, String copyright, String licenceName) {
|
||||
this(name, version, licenceName, info);
|
||||
setCopyright(copyright);
|
||||
}
|
||||
|
||||
public String getCopyright() {
|
||||
return this.copyright;
|
||||
}
|
||||
|
||||
public void setCopyright(String copyright) {
|
||||
this.copyright = copyright;
|
||||
}
|
||||
|
||||
public void setInfo(String info) {
|
||||
super.setInfo(info);
|
||||
}
|
||||
|
||||
public void setLicenceName(String licence) {
|
||||
super.setLicenceName(licence);
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
super.setName(name);
|
||||
}
|
||||
|
||||
public void setVersion(String version) {
|
||||
super.setVersion(version);
|
||||
}
|
||||
|
||||
public Library[] getLibraries() {
|
||||
return (Library[])this.libraries.toArray(new Library[this.libraries.size()]);
|
||||
}
|
||||
|
||||
public void addLibrary(Library library) {
|
||||
if (library == null)
|
||||
throw new NullPointerException();
|
||||
this.libraries.add(library);
|
||||
}
|
||||
|
||||
public Library[] getOptionalLibraries() {
|
||||
ArrayList libraries = new ArrayList();
|
||||
for (int i = 0; i < this.optionalLibraries.size(); i++) {
|
||||
OptionalLibraryHolder holder = (OptionalLibraryHolder)this.optionalLibraries.get(i);
|
||||
Library l = holder.getLibrary();
|
||||
if (l != null)
|
||||
libraries.add(l);
|
||||
}
|
||||
return (Library[])libraries.toArray(new Library[libraries.size()]);
|
||||
}
|
||||
|
||||
public void addOptionalLibrary(String libraryClass) {
|
||||
if (libraryClass == null)
|
||||
throw new NullPointerException("Library classname must be given.");
|
||||
this.optionalLibraries.add(new OptionalLibraryHolder(libraryClass));
|
||||
}
|
||||
|
||||
public void addOptionalLibrary(Library library) {
|
||||
if (library == null)
|
||||
throw new NullPointerException("Library must be given.");
|
||||
this.optionalLibraries.add(new OptionalLibraryHolder(library));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
package org.jfree.base;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class BootableProjectInfo extends BasicProjectInfo {
|
||||
private String bootClass;
|
||||
|
||||
private boolean autoBoot = true;
|
||||
|
||||
public BootableProjectInfo() {}
|
||||
|
||||
public BootableProjectInfo(String name, String version, String licence, String info) {
|
||||
this();
|
||||
setName(name);
|
||||
setVersion(version);
|
||||
setLicenceName(licence);
|
||||
setInfo(info);
|
||||
}
|
||||
|
||||
public BootableProjectInfo(String name, String version, String info, String copyright, String licenceName) {
|
||||
this();
|
||||
setName(name);
|
||||
setVersion(version);
|
||||
setLicenceName(licenceName);
|
||||
setInfo(info);
|
||||
setCopyright(copyright);
|
||||
}
|
||||
|
||||
public BootableProjectInfo[] getDependencies() {
|
||||
ArrayList dependencies = new ArrayList();
|
||||
Library[] libraries = getLibraries();
|
||||
for (int i = 0; i < libraries.length; i++) {
|
||||
Library lib = libraries[i];
|
||||
if (lib instanceof BootableProjectInfo)
|
||||
dependencies.add(lib);
|
||||
}
|
||||
Library[] optionalLibraries = getOptionalLibraries();
|
||||
for (int j = 0; j < optionalLibraries.length; j++) {
|
||||
Library lib = optionalLibraries[j];
|
||||
if (lib instanceof BootableProjectInfo)
|
||||
dependencies.add(lib);
|
||||
}
|
||||
return (BootableProjectInfo[])dependencies.toArray(new BootableProjectInfo[dependencies.size()]);
|
||||
}
|
||||
|
||||
public void addDependency(BootableProjectInfo projectInfo) {
|
||||
if (projectInfo == null)
|
||||
throw new NullPointerException();
|
||||
addLibrary(projectInfo);
|
||||
}
|
||||
|
||||
public String getBootClass() {
|
||||
return this.bootClass;
|
||||
}
|
||||
|
||||
public void setBootClass(String bootClass) {
|
||||
this.bootClass = bootClass;
|
||||
}
|
||||
|
||||
public boolean isAutoBoot() {
|
||||
return this.autoBoot;
|
||||
}
|
||||
|
||||
public void setAutoBoot(boolean autoBoot) {
|
||||
this.autoBoot = autoBoot;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
package org.jfree.base;
|
||||
|
||||
import java.util.Enumeration;
|
||||
import org.jfree.util.ObjectUtilities;
|
||||
|
||||
public class ClassPathDebugger {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Listing the various classloaders:");
|
||||
System.out.println("Defined classloader source: " + ObjectUtilities.getClassLoaderSource());
|
||||
System.out.println("User classloader: " + ObjectUtilities.getClassLoader());
|
||||
System.out.println("Classloader for ObjectUtilities.class: " + ObjectUtilities.getClassLoader(ObjectUtilities.class));
|
||||
System.out.println("Classloader for String.class: " + ObjectUtilities.getClassLoader(String.class));
|
||||
System.out.println("Thread-Context Classloader: " + Thread.currentThread().getContextClassLoader());
|
||||
System.out.println("Defined System classloader: " + ClassLoader.getSystemClassLoader());
|
||||
System.out.println();
|
||||
try {
|
||||
System.out.println("Listing sources for '/jcommon.properties':");
|
||||
Enumeration resources = ObjectUtilities.getClassLoader(ObjectUtilities.class).getResources("jcommon.properties");
|
||||
while (resources.hasMoreElements())
|
||||
System.out.println(" " + resources.nextElement());
|
||||
System.out.println();
|
||||
System.out.println("Listing sources for 'org/jfree/JCommonInfo.class':");
|
||||
resources = ObjectUtilities.getClassLoader(ObjectUtilities.class).getResources("org/jfree/JCommonInfo.class");
|
||||
while (resources.hasMoreElements())
|
||||
System.out.println(" " + resources.nextElement());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
package org.jfree.base;
|
||||
|
||||
public class Library {
|
||||
private String name;
|
||||
|
||||
private String version;
|
||||
|
||||
private String licenceName;
|
||||
|
||||
private String info;
|
||||
|
||||
public Library(String name, String version, String licence, String info) {
|
||||
this.name = name;
|
||||
this.version = version;
|
||||
this.licenceName = licence;
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
protected Library() {}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return this.version;
|
||||
}
|
||||
|
||||
public String getLicenceName() {
|
||||
return this.licenceName;
|
||||
}
|
||||
|
||||
public String getInfo() {
|
||||
return this.info;
|
||||
}
|
||||
|
||||
protected void setInfo(String info) {
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
protected void setLicenceName(String licenceName) {
|
||||
this.licenceName = licenceName;
|
||||
}
|
||||
|
||||
protected void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
protected void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
Library library = (Library)o;
|
||||
if ((this.name != null) ? !this.name.equals(library.name) : (library.name != null))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return (this.name != null) ? this.name.hashCode() : 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,135 @@
|
|||
package org.jfree.base.config;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Iterator;
|
||||
import java.util.Properties;
|
||||
import java.util.TreeSet;
|
||||
import org.jfree.util.Configuration;
|
||||
import org.jfree.util.PublicCloneable;
|
||||
|
||||
public class HierarchicalConfiguration implements ModifiableConfiguration, PublicCloneable {
|
||||
private Properties configuration = new Properties();
|
||||
|
||||
private transient Configuration parentConfiguration;
|
||||
|
||||
public HierarchicalConfiguration() {}
|
||||
|
||||
public HierarchicalConfiguration(Configuration parentConfiguration) {
|
||||
this();
|
||||
this.parentConfiguration = parentConfiguration;
|
||||
}
|
||||
|
||||
public String getConfigProperty(String key) {
|
||||
return getConfigProperty(key, null);
|
||||
}
|
||||
|
||||
public String getConfigProperty(String key, String defaultValue) {
|
||||
String value = this.configuration.getProperty(key);
|
||||
if (value == null)
|
||||
if (isRootConfig()) {
|
||||
value = defaultValue;
|
||||
} else {
|
||||
value = this.parentConfiguration.getConfigProperty(key, defaultValue);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setConfigProperty(String key, String value) {
|
||||
if (key == null)
|
||||
throw new NullPointerException();
|
||||
if (value == null) {
|
||||
this.configuration.remove(key);
|
||||
} else {
|
||||
this.configuration.setProperty(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isRootConfig() {
|
||||
return (this.parentConfiguration == null);
|
||||
}
|
||||
|
||||
public boolean isLocallyDefined(String key) {
|
||||
return this.configuration.containsKey(key);
|
||||
}
|
||||
|
||||
protected Properties getConfiguration() {
|
||||
return this.configuration;
|
||||
}
|
||||
|
||||
public void insertConfiguration(HierarchicalConfiguration config) {
|
||||
config.setParentConfig(getParentConfig());
|
||||
setParentConfig(config);
|
||||
}
|
||||
|
||||
protected void setParentConfig(Configuration config) {
|
||||
if (this.parentConfiguration == this)
|
||||
throw new IllegalArgumentException("Cannot add myself as parent configuration.");
|
||||
this.parentConfiguration = config;
|
||||
}
|
||||
|
||||
protected Configuration getParentConfig() {
|
||||
return this.parentConfiguration;
|
||||
}
|
||||
|
||||
public Enumeration getConfigProperties() {
|
||||
return this.configuration.keys();
|
||||
}
|
||||
|
||||
public Iterator findPropertyKeys(String prefix) {
|
||||
TreeSet keys = new TreeSet();
|
||||
collectPropertyKeys(prefix, this, keys);
|
||||
return Collections.unmodifiableSet(keys).iterator();
|
||||
}
|
||||
|
||||
private void collectPropertyKeys(String prefix, Configuration config, TreeSet collector) {
|
||||
Enumeration enum1 = config.getConfigProperties();
|
||||
while (enum1.hasMoreElements()) {
|
||||
String key = (String)enum1.nextElement();
|
||||
if (key.startsWith(prefix))
|
||||
if (!collector.contains(key))
|
||||
collector.add(key);
|
||||
}
|
||||
if (config instanceof HierarchicalConfiguration) {
|
||||
HierarchicalConfiguration hconfig = (HierarchicalConfiguration)config;
|
||||
if (hconfig.parentConfiguration != null)
|
||||
collectPropertyKeys(prefix, hconfig.parentConfiguration, collector);
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isParentSaved() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void configurationLoaded() {}
|
||||
|
||||
private void writeObject(ObjectOutputStream out) throws IOException {
|
||||
out.defaultWriteObject();
|
||||
if (!isParentSaved()) {
|
||||
out.writeBoolean(false);
|
||||
} else {
|
||||
out.writeBoolean(true);
|
||||
out.writeObject(this.parentConfiguration);
|
||||
}
|
||||
}
|
||||
|
||||
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
in.defaultReadObject();
|
||||
boolean readParent = in.readBoolean();
|
||||
if (readParent) {
|
||||
this.parentConfiguration = (ModifiableConfiguration)in.readObject();
|
||||
} else {
|
||||
this.parentConfiguration = null;
|
||||
}
|
||||
configurationLoaded();
|
||||
}
|
||||
|
||||
public Object clone() throws CloneNotSupportedException {
|
||||
HierarchicalConfiguration config = (HierarchicalConfiguration)super.clone();
|
||||
config.configuration = (Properties)this.configuration.clone();
|
||||
return config;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package org.jfree.base.config;
|
||||
|
||||
import java.util.Enumeration;
|
||||
import java.util.Iterator;
|
||||
import org.jfree.util.Configuration;
|
||||
|
||||
public interface ModifiableConfiguration extends Configuration {
|
||||
void setConfigProperty(String paramString1, String paramString2);
|
||||
|
||||
Enumeration getConfigProperties();
|
||||
|
||||
Iterator findPropertyKeys(String paramString);
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
package org.jfree.base.config;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
import org.jfree.util.Log;
|
||||
import org.jfree.util.ObjectUtilities;
|
||||
|
||||
public class PropertyFileConfiguration extends HierarchicalConfiguration {
|
||||
public void load(String resourceName) {
|
||||
load(resourceName, PropertyFileConfiguration.class);
|
||||
}
|
||||
|
||||
public void load(String resourceName, Class resourceSource) {
|
||||
InputStream in = ObjectUtilities.getResourceRelativeAsStream(resourceName, resourceSource);
|
||||
if (in != null) {
|
||||
try {
|
||||
load(in);
|
||||
} finally {
|
||||
try {
|
||||
in.close();
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
} else {
|
||||
Log.debug("Configuration file not found in the classpath: " + resourceName);
|
||||
}
|
||||
}
|
||||
|
||||
public void load(InputStream in) {
|
||||
if (in == null)
|
||||
throw new NullPointerException();
|
||||
try {
|
||||
BufferedInputStream bin = new BufferedInputStream(in);
|
||||
Properties p = new Properties();
|
||||
p.load(bin);
|
||||
getConfiguration().putAll(p);
|
||||
bin.close();
|
||||
} catch (IOException ioe) {
|
||||
Log.warn("Unable to read configuration", ioe);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
package org.jfree.base.config;
|
||||
|
||||
import java.util.Enumeration;
|
||||
import java.util.Vector;
|
||||
|
||||
public class SystemPropertyConfiguration extends HierarchicalConfiguration {
|
||||
public void setConfigProperty(String key, String value) {
|
||||
throw new UnsupportedOperationException("The SystemPropertyConfiguration is readOnly");
|
||||
}
|
||||
|
||||
public String getConfigProperty(String key, String defaultValue) {
|
||||
try {
|
||||
String value = System.getProperty(key);
|
||||
if (value != null)
|
||||
return value;
|
||||
} catch (SecurityException se) {}
|
||||
return super.getConfigProperty(key, defaultValue);
|
||||
}
|
||||
|
||||
public boolean isLocallyDefined(String key) {
|
||||
try {
|
||||
return System.getProperties().containsKey(key);
|
||||
} catch (SecurityException se) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public Enumeration getConfigProperties() {
|
||||
try {
|
||||
return System.getProperties().keys();
|
||||
} catch (SecurityException se) {
|
||||
return new Vector().elements();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
#
|
||||
# The minimum loglevel that is logged
|
||||
org.jfree.base.LogLevel=Debug
|
||||
|
||||
#
|
||||
# Where to log. Give a classname of a valid LogTarget implementation.
|
||||
# If the name is invalid, no logging is done.
|
||||
org.jfree.base.LogTarget=*none*
|
||||
|
||||
#
|
||||
# Do not initialize the logging.
|
||||
org.jfree.base.LogAutoInit=false
|
||||
|
||||
#
|
||||
# Should the debugging system be disabled by default. This option will suppress all
|
||||
# output, no single line of debug information will be printed. If you want to remove
|
||||
# System.out-debugging on the server side, try to switch to a Log4J-LogTarget instead.
|
||||
org.jfree.base.NoDefaultDebug=false
|
||||
|
||||
#
|
||||
# Which ClassLoader to use for loading external resources and classes.
|
||||
# One of "ThreadContext" or "CallerContext".
|
||||
org.jfree.ClassLoader=ThreadContext
|
||||
|
||||
#
|
||||
# Applies a workaround to fix a JDK bug. When the value is set to auto,
|
||||
# This is enabled if the JDK is not version 1.4 or higher.
|
||||
org.jfree.text.UseDrawRotatedStringWorkaround=auto
|
||||
|
||||
#
|
||||
# Applies a workaround to fix a JDK bug. When the value is set to auto,
|
||||
# This is disabled if the JDK is not version 1.4 or higher.
|
||||
org.jfree.text.UseFontMetricsGetStringBounds=auto
|
||||
|
||||
|
||||
#
|
||||
# Known extra modules. Do not edit and do not delete the following lines.
|
||||
#
|
||||
# That module loading mechanism is not really extensible. A better
|
||||
# implementation might solve that at a later time.
|
||||
org.jfree.jcommon.modules.logger.Log4J.Module=org.jfree.logger.java14.Java14LogModule
|
||||
org.jfree.jcommon.modules.logger.Java14Logging.Module=org.jfree.logger.log4j.Log4JLogModule
|
||||
org.jfree.jcommon.modules.logger.JakartaLogging.Module=org.jfree.logger.jcl.JakartaLogModule
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
package org.jfree.base.log;
|
||||
|
||||
import org.jfree.util.Log;
|
||||
import org.jfree.util.LogTarget;
|
||||
import org.jfree.util.PrintStreamLogTarget;
|
||||
|
||||
public class DefaultLog extends Log {
|
||||
private static final PrintStreamLogTarget DEFAULT_LOG_TARGET = new PrintStreamLogTarget();
|
||||
|
||||
private static final DefaultLog defaultLogInstance = new DefaultLog();
|
||||
|
||||
static {
|
||||
defaultLogInstance.addTarget(DEFAULT_LOG_TARGET);
|
||||
try {
|
||||
String property = System.getProperty("org.jfree.DebugDefault", "false");
|
||||
if (Boolean.valueOf(property).booleanValue()) {
|
||||
defaultLogInstance.setDebuglevel(3);
|
||||
} else {
|
||||
defaultLogInstance.setDebuglevel(1);
|
||||
}
|
||||
} catch (SecurityException se) {
|
||||
defaultLogInstance.setDebuglevel(1);
|
||||
}
|
||||
}
|
||||
|
||||
public void init() {
|
||||
removeTarget(DEFAULT_LOG_TARGET);
|
||||
String logLevel = LogConfiguration.getLogLevel();
|
||||
if (logLevel.equalsIgnoreCase("error")) {
|
||||
setDebuglevel(0);
|
||||
} else if (logLevel.equalsIgnoreCase("warn")) {
|
||||
setDebuglevel(1);
|
||||
} else if (logLevel.equalsIgnoreCase("info")) {
|
||||
setDebuglevel(2);
|
||||
} else if (logLevel.equalsIgnoreCase("debug")) {
|
||||
setDebuglevel(3);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void addTarget(LogTarget target) {
|
||||
super.addTarget(target);
|
||||
if (target != DEFAULT_LOG_TARGET)
|
||||
removeTarget(DEFAULT_LOG_TARGET);
|
||||
}
|
||||
|
||||
public static DefaultLog getDefaultLog() {
|
||||
return defaultLogInstance;
|
||||
}
|
||||
|
||||
public static void installDefaultLog() {
|
||||
Log.defineLog(defaultLogInstance);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
package org.jfree.base.log;
|
||||
|
||||
import org.jfree.base.modules.AbstractModule;
|
||||
import org.jfree.base.modules.ModuleInitializeException;
|
||||
import org.jfree.base.modules.SubSystem;
|
||||
import org.jfree.util.Log;
|
||||
import org.jfree.util.PrintStreamLogTarget;
|
||||
|
||||
public class DefaultLogModule extends AbstractModule {
|
||||
public DefaultLogModule() throws ModuleInitializeException {
|
||||
loadModuleInfo();
|
||||
}
|
||||
|
||||
public void initialize(SubSystem subSystem) throws ModuleInitializeException {
|
||||
if (LogConfiguration.isDisableLogging())
|
||||
return;
|
||||
if (LogConfiguration.getLogTarget().equals(PrintStreamLogTarget.class.getName())) {
|
||||
DefaultLog.installDefaultLog();
|
||||
Log.getInstance().addTarget(new PrintStreamLogTarget());
|
||||
if ("true".equals(subSystem.getGlobalConfig().getConfigProperty("org.jfree.base.LogAutoInit")))
|
||||
Log.getInstance().init();
|
||||
Log.info("Default log target started ... previous log messages could have been ignored.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
package org.jfree.base.log;
|
||||
|
||||
import org.jfree.base.BaseBoot;
|
||||
import org.jfree.util.PrintStreamLogTarget;
|
||||
|
||||
public class LogConfiguration {
|
||||
public static final String DISABLE_LOGGING_DEFAULT = "false";
|
||||
|
||||
public static final String LOGLEVEL = "org.jfree.base.LogLevel";
|
||||
|
||||
public static final String LOGLEVEL_DEFAULT = "Info";
|
||||
|
||||
public static final String LOGTARGET = "org.jfree.base.LogTarget";
|
||||
|
||||
public static final String LOGTARGET_DEFAULT = PrintStreamLogTarget.class.getName();
|
||||
|
||||
public static final String DISABLE_LOGGING = "org.jfree.base.NoDefaultDebug";
|
||||
|
||||
public static String getLogTarget() {
|
||||
return BaseBoot.getInstance().getGlobalConfig().getConfigProperty("org.jfree.base.LogTarget", LOGTARGET_DEFAULT);
|
||||
}
|
||||
|
||||
public static void setLogTarget(String logTarget) {
|
||||
BaseBoot.getConfiguration().setConfigProperty("org.jfree.base.LogTarget", logTarget);
|
||||
}
|
||||
|
||||
public static String getLogLevel() {
|
||||
return BaseBoot.getInstance().getGlobalConfig().getConfigProperty("org.jfree.base.LogLevel", "Info");
|
||||
}
|
||||
|
||||
public static void setLogLevel(String level) {
|
||||
BaseBoot.getConfiguration().setConfigProperty("org.jfree.base.LogLevel", level);
|
||||
}
|
||||
|
||||
public static boolean isDisableLogging() {
|
||||
return BaseBoot.getInstance().getGlobalConfig().getConfigProperty("org.jfree.base.NoDefaultDebug", "false").equalsIgnoreCase("true");
|
||||
}
|
||||
|
||||
public static void setDisableLogging(boolean disableLogging) {
|
||||
BaseBoot.getConfiguration().setConfigProperty("org.jfree.base.NoDefaultDebug", String.valueOf(disableLogging));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package org.jfree.base.log;
|
||||
|
||||
public class MemoryUsageMessage {
|
||||
private final String message;
|
||||
|
||||
public MemoryUsageMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.message + "Free: " + Runtime.getRuntime().freeMemory() + "; " + "Total: " + Runtime.getRuntime().totalMemory();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
package org.jfree.base.log;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class PadMessage {
|
||||
private final Object text;
|
||||
|
||||
private final int length;
|
||||
|
||||
public PadMessage(Object message, int length) {
|
||||
this.text = message;
|
||||
this.length = length;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer b = new StringBuffer();
|
||||
b.append(this.text);
|
||||
if (b.length() < this.length) {
|
||||
char[] pad = new char[this.length - b.length()];
|
||||
Arrays.fill(pad, ' ');
|
||||
b.append(pad);
|
||||
}
|
||||
return b.toString();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
#
|
||||
# Support for logging.
|
||||
#
|
||||
|
||||
module-info:
|
||||
name: base-logging-module
|
||||
producer: The JFreeChart project - www.jfree.org/jcommon
|
||||
description: Initialializer to configure the log system and to provide
|
||||
a facility for logging to the System.out stream.
|
||||
version.major: 1
|
||||
version.minor: 0
|
||||
version.patchlevel: 0
|
||||
subsystem: logging
|
||||
|
||||
|
|
@ -0,0 +1,362 @@
|
|||
package org.jfree.base.modules;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import org.jfree.util.ObjectUtilities;
|
||||
|
||||
public abstract class AbstractModule extends DefaultModuleInfo implements Module {
|
||||
private ModuleInfo[] requiredModules;
|
||||
|
||||
private ModuleInfo[] optionalModules;
|
||||
|
||||
private String name;
|
||||
|
||||
private String description;
|
||||
|
||||
private String producer;
|
||||
|
||||
private String subsystem;
|
||||
|
||||
private static class ReaderHelper {
|
||||
private String buffer;
|
||||
|
||||
private final BufferedReader reader;
|
||||
|
||||
protected ReaderHelper(BufferedReader reader) {
|
||||
this.reader = reader;
|
||||
}
|
||||
|
||||
public boolean hasNext() throws IOException {
|
||||
if (this.buffer == null)
|
||||
this.buffer = readLine();
|
||||
return (this.buffer != null);
|
||||
}
|
||||
|
||||
public String next() {
|
||||
String line = this.buffer;
|
||||
this.buffer = null;
|
||||
return line;
|
||||
}
|
||||
|
||||
public void pushBack(String line) {
|
||||
this.buffer = line;
|
||||
}
|
||||
|
||||
protected String readLine() throws IOException {
|
||||
String line = this.reader.readLine();
|
||||
while (line != null && (line.length() == 0 || line.startsWith("#")))
|
||||
line = this.reader.readLine();
|
||||
return line;
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
this.reader.close();
|
||||
}
|
||||
}
|
||||
|
||||
public AbstractModule() {
|
||||
setModuleClass(getClass().getName());
|
||||
}
|
||||
|
||||
protected void loadModuleInfo() throws ModuleInitializeException {
|
||||
InputStream in = ObjectUtilities.getResourceRelativeAsStream("module.properties", getClass());
|
||||
if (in == null)
|
||||
throw new ModuleInitializeException("File 'module.properties' not found in module package.");
|
||||
loadModuleInfo(in);
|
||||
}
|
||||
|
||||
protected void loadModuleInfo(InputStream in) throws ModuleInitializeException {
|
||||
if (in == null)
|
||||
throw new NullPointerException("Given InputStream is null.");
|
||||
try {
|
||||
ArrayList optionalModules = new ArrayList();
|
||||
ArrayList dependendModules = new ArrayList();
|
||||
ReaderHelper rh = new ReaderHelper(new BufferedReader(new InputStreamReader(in, "ISO-8859-1")));
|
||||
try {
|
||||
while (rh.hasNext()) {
|
||||
String lastLineRead = rh.next();
|
||||
if (lastLineRead.startsWith("module-info:")) {
|
||||
readModuleInfo(rh);
|
||||
continue;
|
||||
}
|
||||
if (lastLineRead.startsWith("depends:")) {
|
||||
dependendModules.add(readExternalModule(rh));
|
||||
continue;
|
||||
}
|
||||
if (lastLineRead.startsWith("optional:"))
|
||||
optionalModules.add(readExternalModule(rh));
|
||||
}
|
||||
} finally {
|
||||
rh.close();
|
||||
}
|
||||
this.optionalModules = (ModuleInfo[])optionalModules.toArray(new ModuleInfo[optionalModules.size()]);
|
||||
this.requiredModules = (ModuleInfo[])dependendModules.toArray(new ModuleInfo[dependendModules.size()]);
|
||||
} catch (IOException ioe) {
|
||||
throw new ModuleInitializeException("Failed to load properties", ioe);
|
||||
}
|
||||
}
|
||||
|
||||
private String readValue(ReaderHelper reader, String firstLine) throws IOException {
|
||||
StringBuffer b = new StringBuffer(firstLine.trim());
|
||||
boolean newLine = true;
|
||||
while (isNextLineValueLine(reader)) {
|
||||
firstLine = reader.next();
|
||||
String trimedLine = firstLine.trim();
|
||||
if (trimedLine.length() == 0 && !newLine) {
|
||||
b.append("\n");
|
||||
newLine = true;
|
||||
continue;
|
||||
}
|
||||
if (!newLine)
|
||||
b.append(" ");
|
||||
b.append(parseValue(trimedLine));
|
||||
newLine = false;
|
||||
}
|
||||
return b.toString();
|
||||
}
|
||||
|
||||
private boolean isNextLineValueLine(ReaderHelper reader) throws IOException {
|
||||
if (!reader.hasNext())
|
||||
return false;
|
||||
String firstLine = reader.next();
|
||||
if (firstLine == null)
|
||||
return false;
|
||||
if (parseKey(firstLine) != null) {
|
||||
reader.pushBack(firstLine);
|
||||
return false;
|
||||
}
|
||||
reader.pushBack(firstLine);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void readModuleInfo(ReaderHelper reader) throws IOException {
|
||||
while (reader.hasNext()) {
|
||||
String lastLineRead = reader.next();
|
||||
if (!Character.isWhitespace(lastLineRead.charAt(0))) {
|
||||
reader.pushBack(lastLineRead);
|
||||
return;
|
||||
}
|
||||
String line = lastLineRead.trim();
|
||||
String key = parseKey(line);
|
||||
if (key != null) {
|
||||
String b = readValue(reader, parseValue(line.trim()));
|
||||
if ("name".equals(key)) {
|
||||
setName(b);
|
||||
continue;
|
||||
}
|
||||
if ("producer".equals(key)) {
|
||||
setProducer(b);
|
||||
continue;
|
||||
}
|
||||
if ("description".equals(key)) {
|
||||
setDescription(b);
|
||||
continue;
|
||||
}
|
||||
if ("subsystem".equals(key)) {
|
||||
setSubSystem(b);
|
||||
continue;
|
||||
}
|
||||
if ("version.major".equals(key)) {
|
||||
setMajorVersion(b);
|
||||
continue;
|
||||
}
|
||||
if ("version.minor".equals(key)) {
|
||||
setMinorVersion(b);
|
||||
continue;
|
||||
}
|
||||
if ("version.patchlevel".equals(key))
|
||||
setPatchLevel(b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String parseKey(String line) {
|
||||
int idx = line.indexOf(':');
|
||||
if (idx == -1)
|
||||
return null;
|
||||
return line.substring(0, idx);
|
||||
}
|
||||
|
||||
private String parseValue(String line) {
|
||||
int idx = line.indexOf(':');
|
||||
if (idx == -1)
|
||||
return line;
|
||||
if (idx + 1 == line.length())
|
||||
return "";
|
||||
return line.substring(idx + 1);
|
||||
}
|
||||
|
||||
private DefaultModuleInfo readExternalModule(ReaderHelper reader) throws IOException {
|
||||
DefaultModuleInfo mi = new DefaultModuleInfo();
|
||||
while (reader.hasNext()) {
|
||||
String lastLineRead = reader.next();
|
||||
if (!Character.isWhitespace(lastLineRead.charAt(0))) {
|
||||
reader.pushBack(lastLineRead);
|
||||
return mi;
|
||||
}
|
||||
String line = lastLineRead.trim();
|
||||
String key = parseKey(line);
|
||||
if (key != null) {
|
||||
String b = readValue(reader, parseValue(line));
|
||||
if ("module".equals(key)) {
|
||||
mi.setModuleClass(b);
|
||||
continue;
|
||||
}
|
||||
if ("version.major".equals(key)) {
|
||||
mi.setMajorVersion(b);
|
||||
continue;
|
||||
}
|
||||
if ("version.minor".equals(key)) {
|
||||
mi.setMinorVersion(b);
|
||||
continue;
|
||||
}
|
||||
if ("version.patchlevel".equals(key))
|
||||
mi.setPatchLevel(b);
|
||||
}
|
||||
}
|
||||
return mi;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
protected void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return this.description;
|
||||
}
|
||||
|
||||
protected void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getProducer() {
|
||||
return this.producer;
|
||||
}
|
||||
|
||||
protected void setProducer(String producer) {
|
||||
this.producer = producer;
|
||||
}
|
||||
|
||||
public ModuleInfo[] getRequiredModules() {
|
||||
ModuleInfo[] retval = new ModuleInfo[this.requiredModules.length];
|
||||
System.arraycopy(this.requiredModules, 0, retval, 0, this.requiredModules.length);
|
||||
return retval;
|
||||
}
|
||||
|
||||
public ModuleInfo[] getOptionalModules() {
|
||||
ModuleInfo[] retval = new ModuleInfo[this.optionalModules.length];
|
||||
System.arraycopy(this.optionalModules, 0, retval, 0, this.optionalModules.length);
|
||||
return retval;
|
||||
}
|
||||
|
||||
protected void setRequiredModules(ModuleInfo[] requiredModules) {
|
||||
this.requiredModules = new ModuleInfo[requiredModules.length];
|
||||
System.arraycopy(requiredModules, 0, this.requiredModules, 0, requiredModules.length);
|
||||
}
|
||||
|
||||
public void setOptionalModules(ModuleInfo[] optionalModules) {
|
||||
this.optionalModules = new ModuleInfo[optionalModules.length];
|
||||
System.arraycopy(optionalModules, 0, this.optionalModules, 0, optionalModules.length);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("Module : ");
|
||||
buffer.append(getName());
|
||||
buffer.append("\n");
|
||||
buffer.append("ModuleClass : ");
|
||||
buffer.append(getModuleClass());
|
||||
buffer.append("\n");
|
||||
buffer.append("Version: ");
|
||||
buffer.append(getMajorVersion());
|
||||
buffer.append(".");
|
||||
buffer.append(getMinorVersion());
|
||||
buffer.append(".");
|
||||
buffer.append(getPatchLevel());
|
||||
buffer.append("\n");
|
||||
buffer.append("Producer: ");
|
||||
buffer.append(getProducer());
|
||||
buffer.append("\n");
|
||||
buffer.append("Description: ");
|
||||
buffer.append(getDescription());
|
||||
buffer.append("\n");
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
protected static boolean isClassLoadable(String name) {
|
||||
try {
|
||||
ClassLoader loader = ObjectUtilities.getClassLoader(AbstractModule.class);
|
||||
if (loader == null)
|
||||
return false;
|
||||
loader.loadClass(name);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected static boolean isClassLoadable(String name, Class context) {
|
||||
try {
|
||||
ObjectUtilities.getClassLoader(context).loadClass(name);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void configure(SubSystem subSystem) {
|
||||
InputStream in = ObjectUtilities.getResourceRelativeAsStream("configuration.properties", getClass());
|
||||
if (in == null)
|
||||
return;
|
||||
try {
|
||||
subSystem.getPackageManager().getPackageConfiguration().load(in);
|
||||
} finally {
|
||||
try {
|
||||
in.close();
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
}
|
||||
|
||||
protected void performExternalInitialize(String classname) throws ModuleInitializeException {
|
||||
try {
|
||||
ModuleInitializer mi = (ModuleInitializer)ObjectUtilities.loadAndInstantiate(classname, AbstractModule.class, ModuleInitializer.class);
|
||||
if (mi == null)
|
||||
throw new ModuleInitializeException("Failed to load specified initializer class.");
|
||||
mi.performInit();
|
||||
} catch (ModuleInitializeException mie) {
|
||||
throw mie;
|
||||
} catch (Exception e) {
|
||||
throw new ModuleInitializeException("Failed to load specified initializer class.", e);
|
||||
}
|
||||
}
|
||||
|
||||
protected void performExternalInitialize(String classname, Class context) throws ModuleInitializeException {
|
||||
try {
|
||||
ModuleInitializer mi = (ModuleInitializer)ObjectUtilities.loadAndInstantiate(classname, context, ModuleInitializer.class);
|
||||
if (mi == null)
|
||||
throw new ModuleInitializeException("Failed to load specified initializer class.");
|
||||
mi.performInit();
|
||||
} catch (ModuleInitializeException mie) {
|
||||
throw mie;
|
||||
} catch (Exception e) {
|
||||
throw new ModuleInitializeException("Failed to load specified initializer class.", e);
|
||||
}
|
||||
}
|
||||
|
||||
public String getSubSystem() {
|
||||
if (this.subsystem == null)
|
||||
return getName();
|
||||
return this.subsystem;
|
||||
}
|
||||
|
||||
protected void setSubSystem(String name) {
|
||||
this.subsystem = name;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,93 @@
|
|||
package org.jfree.base.modules;
|
||||
|
||||
public class DefaultModuleInfo implements ModuleInfo {
|
||||
private String moduleClass;
|
||||
|
||||
private String majorVersion;
|
||||
|
||||
private String minorVersion;
|
||||
|
||||
private String patchLevel;
|
||||
|
||||
public DefaultModuleInfo() {}
|
||||
|
||||
public DefaultModuleInfo(String moduleClass, String majorVersion, String minorVersion, String patchLevel) {
|
||||
if (moduleClass == null)
|
||||
throw new NullPointerException("Module class must not be null.");
|
||||
this.moduleClass = moduleClass;
|
||||
this.majorVersion = majorVersion;
|
||||
this.minorVersion = minorVersion;
|
||||
this.patchLevel = patchLevel;
|
||||
}
|
||||
|
||||
public String getModuleClass() {
|
||||
return this.moduleClass;
|
||||
}
|
||||
|
||||
public void setModuleClass(String moduleClass) {
|
||||
if (moduleClass == null)
|
||||
throw new NullPointerException();
|
||||
this.moduleClass = moduleClass;
|
||||
}
|
||||
|
||||
public String getMajorVersion() {
|
||||
return this.majorVersion;
|
||||
}
|
||||
|
||||
public void setMajorVersion(String majorVersion) {
|
||||
this.majorVersion = majorVersion;
|
||||
}
|
||||
|
||||
public String getMinorVersion() {
|
||||
return this.minorVersion;
|
||||
}
|
||||
|
||||
public void setMinorVersion(String minorVersion) {
|
||||
this.minorVersion = minorVersion;
|
||||
}
|
||||
|
||||
public String getPatchLevel() {
|
||||
return this.patchLevel;
|
||||
}
|
||||
|
||||
public void setPatchLevel(String patchLevel) {
|
||||
this.patchLevel = patchLevel;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
return true;
|
||||
if (!(o instanceof DefaultModuleInfo))
|
||||
return false;
|
||||
ModuleInfo defaultModuleInfo = (ModuleInfo)o;
|
||||
if (!this.moduleClass.equals(defaultModuleInfo.getModuleClass()))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int result = this.moduleClass.hashCode();
|
||||
return result;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append(getClass().getName());
|
||||
buffer.append("={ModuleClass=");
|
||||
buffer.append(getModuleClass());
|
||||
if (getMajorVersion() != null) {
|
||||
buffer.append("; Version=");
|
||||
buffer.append(getMajorVersion());
|
||||
if (getMinorVersion() != null) {
|
||||
buffer.append("-");
|
||||
buffer.append(getMinorVersion());
|
||||
if (getPatchLevel() != null) {
|
||||
buffer.append("_");
|
||||
buffer.append(getPatchLevel());
|
||||
}
|
||||
}
|
||||
}
|
||||
buffer.append("}");
|
||||
return buffer.toString();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package org.jfree.base.modules;
|
||||
|
||||
public interface Module extends ModuleInfo {
|
||||
ModuleInfo[] getRequiredModules();
|
||||
|
||||
ModuleInfo[] getOptionalModules();
|
||||
|
||||
void initialize(SubSystem paramSubSystem) throws ModuleInitializeException;
|
||||
|
||||
void configure(SubSystem paramSubSystem);
|
||||
|
||||
String getDescription();
|
||||
|
||||
String getProducer();
|
||||
|
||||
String getName();
|
||||
|
||||
String getSubSystem();
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
package org.jfree.base.modules;
|
||||
|
||||
public interface ModuleInfo {
|
||||
String getModuleClass();
|
||||
|
||||
String getMajorVersion();
|
||||
|
||||
String getMinorVersion();
|
||||
|
||||
String getPatchLevel();
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package org.jfree.base.modules;
|
||||
|
||||
import org.jfree.util.StackableException;
|
||||
|
||||
public class ModuleInitializeException extends StackableException {
|
||||
public ModuleInitializeException() {}
|
||||
|
||||
public ModuleInitializeException(String s, Exception e) {
|
||||
super(s, e);
|
||||
}
|
||||
|
||||
public ModuleInitializeException(String s) {
|
||||
super(s);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
package org.jfree.base.modules;
|
||||
|
||||
public interface ModuleInitializer {
|
||||
void performInit() throws ModuleInitializeException;
|
||||
}
|
||||
|
|
@ -0,0 +1,308 @@
|
|||
package org.jfree.base.modules;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import org.jfree.base.AbstractBoot;
|
||||
import org.jfree.base.config.HierarchicalConfiguration;
|
||||
import org.jfree.base.config.PropertyFileConfiguration;
|
||||
import org.jfree.base.log.PadMessage;
|
||||
import org.jfree.util.Configuration;
|
||||
import org.jfree.util.Log;
|
||||
import org.jfree.util.ObjectUtilities;
|
||||
|
||||
public final class PackageManager {
|
||||
private static final int RETURN_MODULE_LOADED = 0;
|
||||
|
||||
private static final int RETURN_MODULE_UNKNOWN = 1;
|
||||
|
||||
private static final int RETURN_MODULE_ERROR = 2;
|
||||
|
||||
private final PackageConfiguration packageConfiguration;
|
||||
|
||||
private final ArrayList modules;
|
||||
|
||||
private final ArrayList initSections;
|
||||
|
||||
private AbstractBoot booter;
|
||||
|
||||
private static HashMap instances;
|
||||
|
||||
public static class PackageConfiguration extends PropertyFileConfiguration {
|
||||
public void insertConfiguration(HierarchicalConfiguration config) {
|
||||
super.insertConfiguration(config);
|
||||
}
|
||||
}
|
||||
|
||||
public static PackageManager createInstance(AbstractBoot booter) {
|
||||
if (instances == null) {
|
||||
instances = new HashMap();
|
||||
PackageManager packageManager = new PackageManager(booter);
|
||||
instances.put(booter, packageManager);
|
||||
return packageManager;
|
||||
}
|
||||
PackageManager manager = (PackageManager)instances.get(booter);
|
||||
if (manager == null) {
|
||||
manager = new PackageManager(booter);
|
||||
instances.put(booter, manager);
|
||||
}
|
||||
return manager;
|
||||
}
|
||||
|
||||
private PackageManager(AbstractBoot booter) {
|
||||
if (booter == null)
|
||||
throw new NullPointerException();
|
||||
this.booter = booter;
|
||||
this.packageConfiguration = new PackageConfiguration();
|
||||
this.modules = new ArrayList();
|
||||
this.initSections = new ArrayList();
|
||||
}
|
||||
|
||||
public boolean isModuleAvailable(ModuleInfo moduleDescription) {
|
||||
PackageState[] packageStates = (PackageState[])this.modules.toArray(new PackageState[this.modules.size()]);
|
||||
for (int i = 0; i < packageStates.length; i++) {
|
||||
PackageState state = packageStates[i];
|
||||
if (state.getModule().getModuleClass().equals(moduleDescription.getModuleClass()))
|
||||
return (state.getState() == 2);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void load(String modulePrefix) {
|
||||
if (this.initSections.contains(modulePrefix))
|
||||
return;
|
||||
this.initSections.add(modulePrefix);
|
||||
Configuration config = this.booter.getGlobalConfig();
|
||||
Iterator it = config.findPropertyKeys(modulePrefix);
|
||||
int count = 0;
|
||||
while (it.hasNext()) {
|
||||
String key = (String)it.next();
|
||||
if (key.endsWith(".Module")) {
|
||||
String moduleClass = config.getConfigProperty(key);
|
||||
if (moduleClass != null && moduleClass.length() > 0) {
|
||||
addModule(moduleClass);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
Log.debug("Loaded a total of " + count + " modules under prefix: " + modulePrefix);
|
||||
}
|
||||
|
||||
public synchronized void initializeModules() {
|
||||
PackageSorter.sort(this.modules);
|
||||
for (int j = 0; j < this.modules.size(); j++) {
|
||||
PackageState mod = (PackageState)this.modules.get(j);
|
||||
if (mod.configure(this.booter))
|
||||
Log.debug(new Log.SimpleMessage("Conf: ", new PadMessage(mod.getModule().getModuleClass(), 70), " [", mod.getModule().getSubSystem(), "]"));
|
||||
}
|
||||
for (int i = 0; i < this.modules.size(); i++) {
|
||||
PackageState mod = (PackageState)this.modules.get(i);
|
||||
if (mod.initialize(this.booter))
|
||||
Log.debug(new Log.SimpleMessage("Init: ", new PadMessage(mod.getModule().getModuleClass(), 70), " [", mod.getModule().getSubSystem(), "]"));
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void addModule(String modClass) {
|
||||
ArrayList loadModules = new ArrayList();
|
||||
ModuleInfo modInfo = new DefaultModuleInfo(modClass, null, null, null);
|
||||
if (loadModule(modInfo, new ArrayList(), loadModules, false))
|
||||
for (int i = 0; i < loadModules.size(); i++) {
|
||||
Module mod = (Module)loadModules.get(i);
|
||||
this.modules.add(new PackageState(mod));
|
||||
}
|
||||
}
|
||||
|
||||
private int containsModule(ArrayList tempModules, ModuleInfo module) {
|
||||
if (tempModules != null) {
|
||||
ModuleInfo[] mods = (ModuleInfo[])tempModules.toArray(new ModuleInfo[tempModules.size()]);
|
||||
for (int j = 0; j < mods.length; j++) {
|
||||
if (mods[j].getModuleClass().equals(module.getModuleClass()))
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
PackageState[] packageStates = (PackageState[])this.modules.toArray(new PackageState[this.modules.size()]);
|
||||
for (int i = 0; i < packageStates.length; i++) {
|
||||
if (packageStates[i].getModule().getModuleClass().equals(module.getModuleClass())) {
|
||||
if (packageStates[i].getState() == -2)
|
||||
return 2;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
private void dropFailedModule(PackageState state) {
|
||||
if (!this.modules.contains(state))
|
||||
this.modules.add(state);
|
||||
}
|
||||
|
||||
private boolean loadModule(ModuleInfo moduleInfo, ArrayList incompleteModules, ArrayList modules, boolean fatal) {
|
||||
try {
|
||||
Class c = ObjectUtilities.getClassLoader(getClass()).loadClass(moduleInfo.getModuleClass());
|
||||
Module module = (Module)c.newInstance();
|
||||
if (!acceptVersion(moduleInfo, module)) {
|
||||
Log.warn("Module " + module.getName() + ": required version: " + moduleInfo + ", but found Version: \n" + module);
|
||||
PackageState state = new PackageState(module, -2);
|
||||
dropFailedModule(state);
|
||||
return false;
|
||||
}
|
||||
int moduleContained = containsModule(modules, module);
|
||||
if (moduleContained == 2) {
|
||||
Log.debug("Indicated failure for module: " + module.getModuleClass());
|
||||
PackageState state = new PackageState(module, -2);
|
||||
dropFailedModule(state);
|
||||
return false;
|
||||
}
|
||||
if (moduleContained == 1) {
|
||||
if (incompleteModules.contains(module)) {
|
||||
Log.error(new Log.SimpleMessage("Circular module reference: This module definition is invalid: ", module.getClass()));
|
||||
PackageState state = new PackageState(module, -2);
|
||||
dropFailedModule(state);
|
||||
return false;
|
||||
}
|
||||
incompleteModules.add(module);
|
||||
ModuleInfo[] required = module.getRequiredModules();
|
||||
for (int i = 0; i < required.length; i++) {
|
||||
if (!loadModule(required[i], incompleteModules, modules, true)) {
|
||||
Log.debug("Indicated failure for module: " + module.getModuleClass());
|
||||
PackageState state = new PackageState(module, -2);
|
||||
dropFailedModule(state);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
ModuleInfo[] optional = module.getOptionalModules();
|
||||
for (int j = 0; j < optional.length; j++) {
|
||||
if (!loadModule(optional[j], incompleteModules, modules, true))
|
||||
Log.debug(new Log.SimpleMessage("Optional module: ", optional[j].getModuleClass(), " was not loaded."));
|
||||
}
|
||||
if (containsModule(modules, module) == 1)
|
||||
modules.add(module);
|
||||
incompleteModules.remove(module);
|
||||
}
|
||||
return true;
|
||||
} catch (ClassNotFoundException cnfe) {
|
||||
if (fatal)
|
||||
Log.warn(new Log.SimpleMessage("Unresolved dependency for package: ", moduleInfo.getModuleClass()));
|
||||
Log.debug(new Log.SimpleMessage("ClassNotFound: ", cnfe.getMessage()));
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
Log.warn(new Log.SimpleMessage("Exception while loading module: ", moduleInfo), e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean acceptVersion(ModuleInfo moduleRequirement, Module module) {
|
||||
if (moduleRequirement.getMajorVersion() == null)
|
||||
return true;
|
||||
if (module.getMajorVersion() == null) {
|
||||
Log.warn("Module " + module.getName() + " does not define a major version.");
|
||||
} else {
|
||||
int compare = acceptVersion(moduleRequirement.getMajorVersion(), module.getMajorVersion());
|
||||
if (compare > 0)
|
||||
return false;
|
||||
if (compare < 0)
|
||||
return true;
|
||||
}
|
||||
if (moduleRequirement.getMinorVersion() == null)
|
||||
return true;
|
||||
if (module.getMinorVersion() == null) {
|
||||
Log.warn("Module " + module.getName() + " does not define a minor version.");
|
||||
} else {
|
||||
int compare = acceptVersion(moduleRequirement.getMinorVersion(), module.getMinorVersion());
|
||||
if (compare > 0)
|
||||
return false;
|
||||
if (compare < 0)
|
||||
return true;
|
||||
}
|
||||
if (moduleRequirement.getPatchLevel() == null)
|
||||
return true;
|
||||
if (module.getPatchLevel() == null) {
|
||||
Log.debug("Module " + module.getName() + " does not define a patch level.");
|
||||
} else if (acceptVersion(moduleRequirement.getPatchLevel(), module.getPatchLevel()) > 0) {
|
||||
Log.debug("Did not accept patchlevel: " + moduleRequirement.getPatchLevel() + " - " + module.getPatchLevel());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private int acceptVersion(String modVer, String depModVer) {
|
||||
char[] modVerArray, depVerArray;
|
||||
int mLength = Math.max(modVer.length(), depModVer.length());
|
||||
if (modVer.length() > depModVer.length()) {
|
||||
modVerArray = modVer.toCharArray();
|
||||
depVerArray = new char[mLength];
|
||||
int delta = modVer.length() - depModVer.length();
|
||||
Arrays.fill(depVerArray, 0, delta, ' ');
|
||||
System.arraycopy(depVerArray, delta, depModVer.toCharArray(), 0, depModVer.length());
|
||||
} else if (modVer.length() < depModVer.length()) {
|
||||
depVerArray = depModVer.toCharArray();
|
||||
modVerArray = new char[mLength];
|
||||
char[] b1 = new char[mLength];
|
||||
int delta = depModVer.length() - modVer.length();
|
||||
Arrays.fill(b1, 0, delta, ' ');
|
||||
System.arraycopy(b1, delta, modVer.toCharArray(), 0, modVer.length());
|
||||
} else {
|
||||
depVerArray = depModVer.toCharArray();
|
||||
modVerArray = modVer.toCharArray();
|
||||
}
|
||||
return new String(modVerArray).compareTo(new String(depVerArray));
|
||||
}
|
||||
|
||||
public PackageConfiguration getPackageConfiguration() {
|
||||
return this.packageConfiguration;
|
||||
}
|
||||
|
||||
public Module[] getAllModules() {
|
||||
Module[] mods = new Module[this.modules.size()];
|
||||
for (int i = 0; i < this.modules.size(); i++) {
|
||||
PackageState state = (PackageState)this.modules.get(i);
|
||||
mods[i] = state.getModule();
|
||||
}
|
||||
return mods;
|
||||
}
|
||||
|
||||
public Module[] getActiveModules() {
|
||||
ArrayList mods = new ArrayList();
|
||||
for (int i = 0; i < this.modules.size(); i++) {
|
||||
PackageState state = (PackageState)this.modules.get(i);
|
||||
if (state.getState() == 2)
|
||||
mods.add(state.getModule());
|
||||
}
|
||||
return (Module[])mods.toArray(new Module[mods.size()]);
|
||||
}
|
||||
|
||||
public void printUsedModules(PrintStream p) {
|
||||
Module[] allMods = getAllModules();
|
||||
ArrayList activeModules = new ArrayList();
|
||||
ArrayList failedModules = new ArrayList();
|
||||
for (int j = 0; j < allMods.length; j++) {
|
||||
if (isModuleAvailable(allMods[j])) {
|
||||
activeModules.add(allMods[j]);
|
||||
} else {
|
||||
failedModules.add(allMods[j]);
|
||||
}
|
||||
}
|
||||
p.print("Active modules: ");
|
||||
p.println(activeModules.size());
|
||||
p.println("----------------------------------------------------------");
|
||||
for (int i = 0; i < activeModules.size(); i++) {
|
||||
Module mod = (Module)activeModules.get(i);
|
||||
p.print(new PadMessage(mod.getModuleClass(), 70));
|
||||
p.print(" [");
|
||||
p.print(mod.getSubSystem());
|
||||
p.println("]");
|
||||
p.print(" Version: ");
|
||||
p.print(mod.getMajorVersion());
|
||||
p.print("-");
|
||||
p.print(mod.getMinorVersion());
|
||||
p.print("-");
|
||||
p.print(mod.getPatchLevel());
|
||||
p.print(" Producer: ");
|
||||
p.println(mod.getProducer());
|
||||
p.print(" Description: ");
|
||||
p.println(mod.getDescription());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,177 @@
|
|||
package org.jfree.base.modules;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import org.jfree.util.Log;
|
||||
|
||||
public final class PackageSorter {
|
||||
private static class SortModule implements Comparable {
|
||||
private int position;
|
||||
|
||||
private final PackageState state;
|
||||
|
||||
private ArrayList dependSubsystems;
|
||||
|
||||
public SortModule(PackageState state) {
|
||||
this.position = -1;
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public ArrayList getDependSubsystems() {
|
||||
return this.dependSubsystems;
|
||||
}
|
||||
|
||||
public void setDependSubsystems(ArrayList dependSubsystems) {
|
||||
this.dependSubsystems = dependSubsystems;
|
||||
}
|
||||
|
||||
public int getPosition() {
|
||||
return this.position;
|
||||
}
|
||||
|
||||
public void setPosition(int position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public PackageState getState() {
|
||||
return this.state;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("SortModule: ");
|
||||
buffer.append(this.position);
|
||||
buffer.append(" ");
|
||||
buffer.append(this.state.getModule().getName());
|
||||
buffer.append(" ");
|
||||
buffer.append(this.state.getModule().getModuleClass());
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
public int compareTo(Object o) {
|
||||
SortModule otherModule = (SortModule)o;
|
||||
if (this.position > otherModule.position)
|
||||
return 1;
|
||||
if (this.position < otherModule.position)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static void sort(List modules) {
|
||||
HashMap moduleMap = new HashMap();
|
||||
ArrayList errorModules = new ArrayList();
|
||||
ArrayList weightModules = new ArrayList();
|
||||
for (int i = 0; i < modules.size(); i++) {
|
||||
PackageState state = (PackageState)modules.get(i);
|
||||
if (state.getState() == -2) {
|
||||
errorModules.add(state);
|
||||
} else {
|
||||
SortModule mod = new SortModule(state);
|
||||
weightModules.add(mod);
|
||||
moduleMap.put(state.getModule().getModuleClass(), mod);
|
||||
}
|
||||
}
|
||||
SortModule[] weigths = (SortModule[])weightModules.toArray(new SortModule[weightModules.size()]);
|
||||
for (int j = 0; j < weigths.length; j++) {
|
||||
SortModule sortMod = weigths[j];
|
||||
sortMod.setDependSubsystems(collectSubsystemModules(sortMod.getState().getModule(), moduleMap));
|
||||
}
|
||||
boolean doneWork = true;
|
||||
while (doneWork) {
|
||||
doneWork = false;
|
||||
for (int n = 0; n < weigths.length; n++) {
|
||||
SortModule mod = weigths[n];
|
||||
int position = searchModulePosition(mod, moduleMap);
|
||||
if (position != mod.getPosition()) {
|
||||
mod.setPosition(position);
|
||||
doneWork = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Arrays.sort(weigths);
|
||||
modules.clear();
|
||||
for (int m = 0; m < weigths.length; m++)
|
||||
modules.add(weigths[m].getState());
|
||||
for (int k = 0; k < errorModules.size(); k++)
|
||||
modules.add(errorModules.get(k));
|
||||
}
|
||||
|
||||
private static int searchModulePosition(SortModule smodule, HashMap moduleMap) {
|
||||
Module module = smodule.getState().getModule();
|
||||
int position = 0;
|
||||
ModuleInfo[] modInfo = module.getOptionalModules();
|
||||
for (int i = 0; i < modInfo.length; i++) {
|
||||
String moduleName = modInfo[i].getModuleClass();
|
||||
SortModule reqMod = (SortModule)moduleMap.get(moduleName);
|
||||
if (reqMod != null)
|
||||
if (reqMod.getPosition() >= position)
|
||||
position = reqMod.getPosition() + 1;
|
||||
}
|
||||
modInfo = module.getRequiredModules();
|
||||
for (int modPos = 0; modPos < modInfo.length; modPos++) {
|
||||
String moduleName = modInfo[modPos].getModuleClass();
|
||||
SortModule reqMod = (SortModule)moduleMap.get(moduleName);
|
||||
if (reqMod == null) {
|
||||
Log.warn("Invalid state: Required dependency of '" + moduleName + "' had an error.");
|
||||
} else if (reqMod.getPosition() >= position) {
|
||||
position = reqMod.getPosition() + 1;
|
||||
}
|
||||
}
|
||||
String subSystem = module.getSubSystem();
|
||||
Iterator it = moduleMap.values().iterator();
|
||||
while (it.hasNext()) {
|
||||
SortModule mod = (SortModule)it.next();
|
||||
if (mod.getState().getModule() == module)
|
||||
continue;
|
||||
Module subSysMod = mod.getState().getModule();
|
||||
if (subSystem.equals(subSysMod.getSubSystem()))
|
||||
continue;
|
||||
if (smodule.getDependSubsystems().contains(subSysMod.getSubSystem()))
|
||||
if (!isBaseModule(subSysMod, module))
|
||||
if (mod.getPosition() >= position)
|
||||
position = mod.getPosition() + 1;
|
||||
}
|
||||
return position;
|
||||
}
|
||||
|
||||
private static boolean isBaseModule(Module mod, ModuleInfo mi) {
|
||||
ModuleInfo[] info = mod.getRequiredModules();
|
||||
for (int j = 0; j < info.length; j++) {
|
||||
if (info[j].getModuleClass().equals(mi.getModuleClass()))
|
||||
return true;
|
||||
}
|
||||
info = mod.getOptionalModules();
|
||||
for (int i = 0; i < info.length; i++) {
|
||||
if (info[i].getModuleClass().equals(mi.getModuleClass()))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static ArrayList collectSubsystemModules(Module childMod, HashMap moduleMap) {
|
||||
ArrayList collector = new ArrayList();
|
||||
ModuleInfo[] info = childMod.getRequiredModules();
|
||||
for (int j = 0; j < info.length; j++) {
|
||||
SortModule dependentModule = (SortModule)moduleMap.get(info[j].getModuleClass());
|
||||
if (dependentModule == null) {
|
||||
Log.warn(new Log.SimpleMessage("A dependent module was not found in the list of known modules.", info[j].getModuleClass()));
|
||||
} else {
|
||||
collector.add(dependentModule.getState().getModule().getSubSystem());
|
||||
}
|
||||
}
|
||||
info = childMod.getOptionalModules();
|
||||
for (int i = 0; i < info.length; i++) {
|
||||
Module dependentModule = (Module)moduleMap.get(info[i].getModuleClass());
|
||||
if (dependentModule == null) {
|
||||
Log.warn("A dependent module was not found in the list of known modules.");
|
||||
} else {
|
||||
collector.add(dependentModule.getSubSystem());
|
||||
}
|
||||
}
|
||||
return collector;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,100 @@
|
|||
package org.jfree.base.modules;
|
||||
|
||||
import org.jfree.util.Log;
|
||||
|
||||
public class PackageState {
|
||||
public static final int STATE_NEW = 0;
|
||||
|
||||
public static final int STATE_CONFIGURED = 1;
|
||||
|
||||
public static final int STATE_INITIALIZED = 2;
|
||||
|
||||
public static final int STATE_ERROR = -2;
|
||||
|
||||
private final Module module;
|
||||
|
||||
private int state;
|
||||
|
||||
public PackageState(Module module) {
|
||||
this(module, 0);
|
||||
}
|
||||
|
||||
public PackageState(Module module, int state) {
|
||||
if (module == null)
|
||||
throw new NullPointerException("Module must not be null.");
|
||||
if (state != 1 && state != -2 && state != 2 && state != 0)
|
||||
throw new IllegalArgumentException("State is not valid");
|
||||
this.module = module;
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public boolean configure(SubSystem subSystem) {
|
||||
if (this.state == 0)
|
||||
try {
|
||||
this.module.configure(subSystem);
|
||||
this.state = 1;
|
||||
return true;
|
||||
} catch (NoClassDefFoundError noClassDef) {
|
||||
Log.warn(new Log.SimpleMessage("Unable to load module classes for ", this.module.getName(), ":", noClassDef.getMessage()));
|
||||
this.state = -2;
|
||||
} catch (Exception e) {
|
||||
if (Log.isDebugEnabled()) {
|
||||
Log.warn("Unable to configure the module " + this.module.getName(), e);
|
||||
} else if (Log.isWarningEnabled()) {
|
||||
Log.warn("Unable to configure the module " + this.module.getName());
|
||||
}
|
||||
this.state = -2;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Module getModule() {
|
||||
return this.module;
|
||||
}
|
||||
|
||||
public int getState() {
|
||||
return this.state;
|
||||
}
|
||||
|
||||
public boolean initialize(SubSystem subSystem) {
|
||||
if (this.state == 1)
|
||||
try {
|
||||
this.module.initialize(subSystem);
|
||||
this.state = 2;
|
||||
return true;
|
||||
} catch (NoClassDefFoundError noClassDef) {
|
||||
Log.warn(new Log.SimpleMessage("Unable to load module classes for ", this.module.getName(), ":", noClassDef.getMessage()));
|
||||
this.state = -2;
|
||||
} catch (ModuleInitializeException me) {
|
||||
if (Log.isDebugEnabled()) {
|
||||
Log.warn("Unable to initialize the module " + this.module.getName(), me);
|
||||
} else if (Log.isWarningEnabled()) {
|
||||
Log.warn("Unable to initialize the module " + this.module.getName());
|
||||
}
|
||||
this.state = -2;
|
||||
} catch (Exception e) {
|
||||
if (Log.isDebugEnabled()) {
|
||||
Log.warn("Unable to initialize the module " + this.module.getName(), e);
|
||||
} else if (Log.isWarningEnabled()) {
|
||||
Log.warn("Unable to initialize the module " + this.module.getName());
|
||||
}
|
||||
this.state = -2;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
return true;
|
||||
if (!(o instanceof PackageState))
|
||||
return false;
|
||||
PackageState packageState = (PackageState)o;
|
||||
if (!this.module.getModuleClass().equals(packageState.module.getModuleClass()))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return this.module.hashCode();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
package org.jfree.base.modules;
|
||||
|
||||
import org.jfree.util.Configuration;
|
||||
import org.jfree.util.ExtendedConfiguration;
|
||||
|
||||
public interface SubSystem {
|
||||
Configuration getGlobalConfig();
|
||||
|
||||
ExtendedConfiguration getExtendedConfig();
|
||||
|
||||
PackageManager getPackageManager();
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package org.jfree.date;
|
||||
|
||||
public abstract class AnnualDateRule implements Cloneable {
|
||||
public abstract SerialDate getDate(int paramInt);
|
||||
|
||||
public Object clone() throws CloneNotSupportedException {
|
||||
return super.clone();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package org.jfree.date;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
public class DateUtilities {
|
||||
private static final Calendar CALENDAR = Calendar.getInstance();
|
||||
|
||||
public static synchronized Date createDate(int yyyy, int month, int day) {
|
||||
CALENDAR.clear();
|
||||
CALENDAR.set(yyyy, month - 1, day);
|
||||
return CALENDAR.getTime();
|
||||
}
|
||||
|
||||
public static synchronized Date createDate(int yyyy, int month, int day, int hour, int min) {
|
||||
CALENDAR.clear();
|
||||
CALENDAR.set(yyyy, month - 1, day, hour, min);
|
||||
return CALENDAR.getTime();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
package org.jfree.date;
|
||||
|
||||
public class DayAndMonthRule extends AnnualDateRule {
|
||||
private int dayOfMonth;
|
||||
|
||||
private int month;
|
||||
|
||||
public DayAndMonthRule() {
|
||||
this(1, 1);
|
||||
}
|
||||
|
||||
public DayAndMonthRule(int dayOfMonth, int month) {
|
||||
setMonth(month);
|
||||
setDayOfMonth(dayOfMonth);
|
||||
}
|
||||
|
||||
public int getDayOfMonth() {
|
||||
return this.dayOfMonth;
|
||||
}
|
||||
|
||||
public void setDayOfMonth(int dayOfMonth) {
|
||||
if (dayOfMonth < 1 || dayOfMonth > SerialDate.LAST_DAY_OF_MONTH[this.month])
|
||||
throw new IllegalArgumentException("DayAndMonthRule(): dayOfMonth outside valid range.");
|
||||
this.dayOfMonth = dayOfMonth;
|
||||
}
|
||||
|
||||
public int getMonth() {
|
||||
return this.month;
|
||||
}
|
||||
|
||||
public void setMonth(int month) {
|
||||
if (!SerialDate.isValidMonthCode(month))
|
||||
throw new IllegalArgumentException("DayAndMonthRule(): month code not valid.");
|
||||
this.month = month;
|
||||
}
|
||||
|
||||
public SerialDate getDate(int yyyy) {
|
||||
return SerialDate.createInstance(this.dayOfMonth, this.month, yyyy);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
package org.jfree.date;
|
||||
|
||||
public class DayOfWeekInMonthRule extends AnnualDateRule {
|
||||
private int count;
|
||||
|
||||
private int dayOfWeek;
|
||||
|
||||
private int month;
|
||||
|
||||
public DayOfWeekInMonthRule() {
|
||||
this(1, 2, 1);
|
||||
}
|
||||
|
||||
public DayOfWeekInMonthRule(int count, int dayOfWeek, int month) {
|
||||
this.count = count;
|
||||
this.dayOfWeek = dayOfWeek;
|
||||
this.month = month;
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return this.count;
|
||||
}
|
||||
|
||||
public void setCount(int count) {
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
public int getDayOfWeek() {
|
||||
return this.dayOfWeek;
|
||||
}
|
||||
|
||||
public void setDayOfWeek(int dayOfWeek) {
|
||||
this.dayOfWeek = dayOfWeek;
|
||||
}
|
||||
|
||||
public int getMonth() {
|
||||
return this.month;
|
||||
}
|
||||
|
||||
public void setMonth(int month) {
|
||||
this.month = month;
|
||||
}
|
||||
|
||||
public SerialDate getDate(int year) {
|
||||
SerialDate result;
|
||||
if (this.count != 0) {
|
||||
result = SerialDate.createInstance(1, this.month, year);
|
||||
while (result.getDayOfWeek() != this.dayOfWeek)
|
||||
result = SerialDate.addDays(1, result);
|
||||
result = SerialDate.addDays(7 * (this.count - 1), result);
|
||||
} else {
|
||||
result = SerialDate.createInstance(1, this.month, year);
|
||||
result = result.getEndOfCurrentMonth(result);
|
||||
while (result.getDayOfWeek() != this.dayOfWeek)
|
||||
result = SerialDate.addDays(-1, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package org.jfree.date;
|
||||
|
||||
public class EasterSundayRule extends AnnualDateRule {
|
||||
public SerialDate getDate(int year) {
|
||||
int g = year % 19;
|
||||
int c = year / 100;
|
||||
int h = (c - c / 4 - (8 * c + 13) / 25 + 19 * g + 15) % 30;
|
||||
int i = h - h / 28 * (1 - h / 28 * 29 / (h + 1) * (21 - g) / 11);
|
||||
int j = (year + year / 4 + i + 2 - c + c / 4) % 7;
|
||||
int l = i - j;
|
||||
int month = 3 + (l + 40) / 44;
|
||||
int day = l + 28 - 31 * month / 4;
|
||||
return SerialDate.createInstance(day, month, year);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
package org.jfree.date;
|
||||
|
||||
public interface MonthConstants {
|
||||
public static final int JANUARY = 1;
|
||||
|
||||
public static final int FEBRUARY = 2;
|
||||
|
||||
public static final int MARCH = 3;
|
||||
|
||||
public static final int APRIL = 4;
|
||||
|
||||
public static final int MAY = 5;
|
||||
|
||||
public static final int JUNE = 6;
|
||||
|
||||
public static final int JULY = 7;
|
||||
|
||||
public static final int AUGUST = 8;
|
||||
|
||||
public static final int SEPTEMBER = 9;
|
||||
|
||||
public static final int OCTOBER = 10;
|
||||
|
||||
public static final int NOVEMBER = 11;
|
||||
|
||||
public static final int DECEMBER = 12;
|
||||
}
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
package org.jfree.date;
|
||||
|
||||
public class RelativeDayOfWeekRule extends AnnualDateRule {
|
||||
private AnnualDateRule subrule;
|
||||
|
||||
private int dayOfWeek;
|
||||
|
||||
private int relative;
|
||||
|
||||
public RelativeDayOfWeekRule() {
|
||||
this(new DayAndMonthRule(), 2, 1);
|
||||
}
|
||||
|
||||
public RelativeDayOfWeekRule(AnnualDateRule subrule, int dayOfWeek, int relative) {
|
||||
this.subrule = subrule;
|
||||
this.dayOfWeek = dayOfWeek;
|
||||
this.relative = relative;
|
||||
}
|
||||
|
||||
public AnnualDateRule getSubrule() {
|
||||
return this.subrule;
|
||||
}
|
||||
|
||||
public void setSubrule(AnnualDateRule subrule) {
|
||||
this.subrule = subrule;
|
||||
}
|
||||
|
||||
public int getDayOfWeek() {
|
||||
return this.dayOfWeek;
|
||||
}
|
||||
|
||||
public void setDayOfWeek(int dayOfWeek) {
|
||||
this.dayOfWeek = dayOfWeek;
|
||||
}
|
||||
|
||||
public int getRelative() {
|
||||
return this.relative;
|
||||
}
|
||||
|
||||
public void setRelative(int relative) {
|
||||
this.relative = relative;
|
||||
}
|
||||
|
||||
public Object clone() throws CloneNotSupportedException {
|
||||
RelativeDayOfWeekRule duplicate = (RelativeDayOfWeekRule)super.clone();
|
||||
duplicate.subrule = (AnnualDateRule)duplicate.getSubrule().clone();
|
||||
return duplicate;
|
||||
}
|
||||
|
||||
public SerialDate getDate(int year) {
|
||||
if (year < 1900 || year > 9999)
|
||||
throw new IllegalArgumentException("RelativeDayOfWeekRule.getDate(): year outside valid range.");
|
||||
SerialDate result = null;
|
||||
SerialDate base = this.subrule.getDate(year);
|
||||
if (base != null)
|
||||
switch (this.relative) {
|
||||
case -1:
|
||||
result = SerialDate.getPreviousDayOfWeek(this.dayOfWeek, base);
|
||||
break;
|
||||
case 0:
|
||||
result = SerialDate.getNearestDayOfWeek(this.dayOfWeek, base);
|
||||
break;
|
||||
case 1:
|
||||
result = SerialDate.getFollowingDayOfWeek(this.dayOfWeek, base);
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,403 @@
|
|||
package org.jfree.date;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.text.DateFormatSymbols;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
|
||||
public abstract class SerialDate implements Comparable, Serializable, MonthConstants {
|
||||
private static final long serialVersionUID = -293716040467423637L;
|
||||
|
||||
public static final DateFormatSymbols DATE_FORMAT_SYMBOLS = new SimpleDateFormat().getDateFormatSymbols();
|
||||
|
||||
public static final int SERIAL_LOWER_BOUND = 2;
|
||||
|
||||
public static final int SERIAL_UPPER_BOUND = 2958465;
|
||||
|
||||
public static final int MINIMUM_YEAR_SUPPORTED = 1900;
|
||||
|
||||
public static final int MAXIMUM_YEAR_SUPPORTED = 9999;
|
||||
|
||||
public static final int MONDAY = 2;
|
||||
|
||||
public static final int TUESDAY = 3;
|
||||
|
||||
public static final int WEDNESDAY = 4;
|
||||
|
||||
public static final int THURSDAY = 5;
|
||||
|
||||
public static final int FRIDAY = 6;
|
||||
|
||||
public static final int SATURDAY = 7;
|
||||
|
||||
public static final int SUNDAY = 1;
|
||||
|
||||
static final int[] LAST_DAY_OF_MONTH = new int[] {
|
||||
0, 31, 28, 31, 30, 31, 30, 31, 31, 30,
|
||||
31, 30, 31 };
|
||||
|
||||
static final int[] AGGREGATE_DAYS_TO_END_OF_MONTH = new int[] {
|
||||
0, 31, 59, 90, 120, 151, 181, 212, 243, 273,
|
||||
304, 334, 365 };
|
||||
|
||||
static final int[] AGGREGATE_DAYS_TO_END_OF_PRECEDING_MONTH = new int[] {
|
||||
0, 0, 31, 59, 90, 120, 151, 181, 212, 243,
|
||||
273, 304, 334, 365 };
|
||||
|
||||
static final int[] LEAP_YEAR_AGGREGATE_DAYS_TO_END_OF_MONTH = new int[] {
|
||||
0, 31, 60, 91, 121, 152, 182, 213, 244, 274,
|
||||
305, 335, 366 };
|
||||
|
||||
static final int[] LEAP_YEAR_AGGREGATE_DAYS_TO_END_OF_PRECEDING_MONTH = new int[] {
|
||||
0, 0, 31, 60, 91, 121, 152, 182, 213, 244,
|
||||
274, 305, 335, 366 };
|
||||
|
||||
public static final int FIRST_WEEK_IN_MONTH = 1;
|
||||
|
||||
public static final int SECOND_WEEK_IN_MONTH = 2;
|
||||
|
||||
public static final int THIRD_WEEK_IN_MONTH = 3;
|
||||
|
||||
public static final int FOURTH_WEEK_IN_MONTH = 4;
|
||||
|
||||
public static final int LAST_WEEK_IN_MONTH = 0;
|
||||
|
||||
public static final int INCLUDE_NONE = 0;
|
||||
|
||||
public static final int INCLUDE_FIRST = 1;
|
||||
|
||||
public static final int INCLUDE_SECOND = 2;
|
||||
|
||||
public static final int INCLUDE_BOTH = 3;
|
||||
|
||||
public static final int PRECEDING = -1;
|
||||
|
||||
public static final int NEAREST = 0;
|
||||
|
||||
public static final int FOLLOWING = 1;
|
||||
|
||||
private String description;
|
||||
|
||||
public static boolean isValidWeekdayCode(int code) {
|
||||
switch (code) {
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
case 6:
|
||||
case 7:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static int stringToWeekdayCode(String s) {
|
||||
String[] shortWeekdayNames = DATE_FORMAT_SYMBOLS.getShortWeekdays();
|
||||
String[] weekDayNames = DATE_FORMAT_SYMBOLS.getWeekdays();
|
||||
int result = -1;
|
||||
s = s.trim();
|
||||
for (int i = 0; i < weekDayNames.length; i++) {
|
||||
if (s.equals(shortWeekdayNames[i])) {
|
||||
result = i;
|
||||
break;
|
||||
}
|
||||
if (s.equals(weekDayNames[i])) {
|
||||
result = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String weekdayCodeToString(int weekday) {
|
||||
String[] weekdays = DATE_FORMAT_SYMBOLS.getWeekdays();
|
||||
return weekdays[weekday];
|
||||
}
|
||||
|
||||
public static String[] getMonths() {
|
||||
return getMonths(false);
|
||||
}
|
||||
|
||||
public static String[] getMonths(boolean shortened) {
|
||||
if (shortened)
|
||||
return DATE_FORMAT_SYMBOLS.getShortMonths();
|
||||
return DATE_FORMAT_SYMBOLS.getMonths();
|
||||
}
|
||||
|
||||
public static boolean isValidMonthCode(int code) {
|
||||
switch (code) {
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
case 6:
|
||||
case 7:
|
||||
case 8:
|
||||
case 9:
|
||||
case 10:
|
||||
case 11:
|
||||
case 12:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static int monthCodeToQuarter(int code) {
|
||||
switch (code) {
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
return 1;
|
||||
case 4:
|
||||
case 5:
|
||||
case 6:
|
||||
return 2;
|
||||
case 7:
|
||||
case 8:
|
||||
case 9:
|
||||
return 3;
|
||||
case 10:
|
||||
case 11:
|
||||
case 12:
|
||||
return 4;
|
||||
}
|
||||
throw new IllegalArgumentException("SerialDate.monthCodeToQuarter: invalid month code.");
|
||||
}
|
||||
|
||||
public static String monthCodeToString(int month) {
|
||||
return monthCodeToString(month, false);
|
||||
}
|
||||
|
||||
public static String monthCodeToString(int month, boolean shortened) {
|
||||
String[] months;
|
||||
if (!isValidMonthCode(month))
|
||||
throw new IllegalArgumentException("SerialDate.monthCodeToString: month outside valid range.");
|
||||
if (shortened) {
|
||||
months = DATE_FORMAT_SYMBOLS.getShortMonths();
|
||||
} else {
|
||||
months = DATE_FORMAT_SYMBOLS.getMonths();
|
||||
}
|
||||
return months[month - 1];
|
||||
}
|
||||
|
||||
public static int stringToMonthCode(String s) {
|
||||
String[] shortMonthNames = DATE_FORMAT_SYMBOLS.getShortMonths();
|
||||
String[] monthNames = DATE_FORMAT_SYMBOLS.getMonths();
|
||||
int result = -1;
|
||||
s = s.trim();
|
||||
try {
|
||||
result = Integer.parseInt(s);
|
||||
} catch (NumberFormatException e) {}
|
||||
if (result < 1 || result > 12)
|
||||
for (int i = 0; i < monthNames.length; i++) {
|
||||
if (s.equals(shortMonthNames[i])) {
|
||||
result = i + 1;
|
||||
break;
|
||||
}
|
||||
if (s.equals(monthNames[i])) {
|
||||
result = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean isValidWeekInMonthCode(int code) {
|
||||
switch (code) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isLeapYear(int yyyy) {
|
||||
if (yyyy % 4 != 0)
|
||||
return false;
|
||||
if (yyyy % 400 == 0)
|
||||
return true;
|
||||
if (yyyy % 100 == 0)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static int leapYearCount(int yyyy) {
|
||||
int leap4 = (yyyy - 1896) / 4;
|
||||
int leap100 = (yyyy - 1800) / 100;
|
||||
int leap400 = (yyyy - 1600) / 400;
|
||||
return leap4 - leap100 + leap400;
|
||||
}
|
||||
|
||||
public static int lastDayOfMonth(int month, int yyyy) {
|
||||
int result = LAST_DAY_OF_MONTH[month];
|
||||
if (month != 2)
|
||||
return result;
|
||||
if (isLeapYear(yyyy))
|
||||
return result + 1;
|
||||
return result;
|
||||
}
|
||||
|
||||
public static SerialDate addDays(int days, SerialDate base) {
|
||||
int serialDayNumber = base.toSerial() + days;
|
||||
return createInstance(serialDayNumber);
|
||||
}
|
||||
|
||||
public static SerialDate addMonths(int months, SerialDate base) {
|
||||
int yy = (12 * base.getYYYY() + base.getMonth() + months - 1) / 12;
|
||||
int mm = (12 * base.getYYYY() + base.getMonth() + months - 1) % 12 + 1;
|
||||
int dd = Math.min(base.getDayOfMonth(), lastDayOfMonth(mm, yy));
|
||||
return createInstance(dd, mm, yy);
|
||||
}
|
||||
|
||||
public static SerialDate addYears(int years, SerialDate base) {
|
||||
int baseY = base.getYYYY();
|
||||
int baseM = base.getMonth();
|
||||
int baseD = base.getDayOfMonth();
|
||||
int targetY = baseY + years;
|
||||
int targetD = Math.min(baseD, lastDayOfMonth(baseM, targetY));
|
||||
return createInstance(targetD, baseM, targetY);
|
||||
}
|
||||
|
||||
public static SerialDate getPreviousDayOfWeek(int targetWeekday, SerialDate base) {
|
||||
int adjust;
|
||||
if (!isValidWeekdayCode(targetWeekday))
|
||||
throw new IllegalArgumentException("Invalid day-of-the-week code.");
|
||||
int baseDOW = base.getDayOfWeek();
|
||||
if (baseDOW > targetWeekday) {
|
||||
adjust = Math.min(0, targetWeekday - baseDOW);
|
||||
} else {
|
||||
adjust = -7 + Math.max(0, targetWeekday - baseDOW);
|
||||
}
|
||||
return addDays(adjust, base);
|
||||
}
|
||||
|
||||
public static SerialDate getFollowingDayOfWeek(int targetWeekday, SerialDate base) {
|
||||
int adjust;
|
||||
if (!isValidWeekdayCode(targetWeekday))
|
||||
throw new IllegalArgumentException("Invalid day-of-the-week code.");
|
||||
int baseDOW = base.getDayOfWeek();
|
||||
if (baseDOW > targetWeekday) {
|
||||
adjust = 7 + Math.min(0, targetWeekday - baseDOW);
|
||||
} else {
|
||||
adjust = Math.max(0, targetWeekday - baseDOW);
|
||||
}
|
||||
return addDays(adjust, base);
|
||||
}
|
||||
|
||||
public static SerialDate getNearestDayOfWeek(int targetDOW, SerialDate base) {
|
||||
if (!isValidWeekdayCode(targetDOW))
|
||||
throw new IllegalArgumentException("Invalid day-of-the-week code.");
|
||||
int baseDOW = base.getDayOfWeek();
|
||||
int adjust = -Math.abs(targetDOW - baseDOW);
|
||||
if (adjust >= 4)
|
||||
adjust = 7 - adjust;
|
||||
if (adjust <= -4)
|
||||
adjust = 7 + adjust;
|
||||
return addDays(adjust, base);
|
||||
}
|
||||
|
||||
public SerialDate getEndOfCurrentMonth(SerialDate base) {
|
||||
int last = lastDayOfMonth(base.getMonth(), base.getYYYY());
|
||||
return createInstance(last, base.getMonth(), base.getYYYY());
|
||||
}
|
||||
|
||||
public static String weekInMonthToString(int count) {
|
||||
switch (count) {
|
||||
case 1:
|
||||
return "First";
|
||||
case 2:
|
||||
return "Second";
|
||||
case 3:
|
||||
return "Third";
|
||||
case 4:
|
||||
return "Fourth";
|
||||
case 0:
|
||||
return "Last";
|
||||
}
|
||||
return "SerialDate.weekInMonthToString(): invalid code.";
|
||||
}
|
||||
|
||||
public static String relativeToString(int relative) {
|
||||
switch (relative) {
|
||||
case -1:
|
||||
return "Preceding";
|
||||
case 0:
|
||||
return "Nearest";
|
||||
case 1:
|
||||
return "Following";
|
||||
}
|
||||
return "ERROR : Relative To String";
|
||||
}
|
||||
|
||||
public static SerialDate createInstance(int day, int month, int yyyy) {
|
||||
return new SpreadsheetDate(day, month, yyyy);
|
||||
}
|
||||
|
||||
public static SerialDate createInstance(int serial) {
|
||||
return new SpreadsheetDate(serial);
|
||||
}
|
||||
|
||||
public static SerialDate createInstance(Date date) {
|
||||
GregorianCalendar calendar = new GregorianCalendar();
|
||||
calendar.setTime(date);
|
||||
return new SpreadsheetDate(calendar.get(5), calendar.get(2) + 1, calendar.get(1));
|
||||
}
|
||||
|
||||
public abstract int toSerial();
|
||||
|
||||
public abstract Date toDate();
|
||||
|
||||
public String getDescription() {
|
||||
return this.description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return getDayOfMonth() + "-" + monthCodeToString(getMonth()) + "-" + getYYYY();
|
||||
}
|
||||
|
||||
public abstract int getYYYY();
|
||||
|
||||
public abstract int getMonth();
|
||||
|
||||
public abstract int getDayOfMonth();
|
||||
|
||||
public abstract int getDayOfWeek();
|
||||
|
||||
public abstract int compare(SerialDate paramSerialDate);
|
||||
|
||||
public abstract boolean isOn(SerialDate paramSerialDate);
|
||||
|
||||
public abstract boolean isBefore(SerialDate paramSerialDate);
|
||||
|
||||
public abstract boolean isOnOrBefore(SerialDate paramSerialDate);
|
||||
|
||||
public abstract boolean isAfter(SerialDate paramSerialDate);
|
||||
|
||||
public abstract boolean isOnOrAfter(SerialDate paramSerialDate);
|
||||
|
||||
public abstract boolean isInRange(SerialDate paramSerialDate1, SerialDate paramSerialDate2);
|
||||
|
||||
public abstract boolean isInRange(SerialDate paramSerialDate1, SerialDate paramSerialDate2, int paramInt);
|
||||
|
||||
public SerialDate getPreviousDayOfWeek(int targetDOW) {
|
||||
return getPreviousDayOfWeek(targetDOW, this);
|
||||
}
|
||||
|
||||
public SerialDate getFollowingDayOfWeek(int targetDOW) {
|
||||
return getFollowingDayOfWeek(targetDOW, this);
|
||||
}
|
||||
|
||||
public SerialDate getNearestDayOfWeek(int targetDOW) {
|
||||
return getNearestDayOfWeek(targetDOW, this);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,136 @@
|
|||
package org.jfree.date;
|
||||
|
||||
import java.text.DateFormatSymbols;
|
||||
|
||||
public class SerialDateUtilities {
|
||||
private DateFormatSymbols dateFormatSymbols = new DateFormatSymbols();
|
||||
|
||||
private String[] weekdays = this.dateFormatSymbols.getWeekdays();
|
||||
|
||||
private String[] months = this.dateFormatSymbols.getMonths();
|
||||
|
||||
public String[] getWeekdays() {
|
||||
return this.weekdays;
|
||||
}
|
||||
|
||||
public String[] getMonths() {
|
||||
return this.months;
|
||||
}
|
||||
|
||||
public int stringToWeekday(String s) {
|
||||
if (s.equals(this.weekdays[7]))
|
||||
return 7;
|
||||
if (s.equals(this.weekdays[1]))
|
||||
return 1;
|
||||
if (s.equals(this.weekdays[2]))
|
||||
return 2;
|
||||
if (s.equals(this.weekdays[3]))
|
||||
return 3;
|
||||
if (s.equals(this.weekdays[4]))
|
||||
return 4;
|
||||
if (s.equals(this.weekdays[5]))
|
||||
return 5;
|
||||
return 6;
|
||||
}
|
||||
|
||||
public static int dayCountActual(SerialDate start, SerialDate end) {
|
||||
return end.compare(start);
|
||||
}
|
||||
|
||||
public static int dayCount30(SerialDate start, SerialDate end) {
|
||||
if (start.isBefore(end)) {
|
||||
int d1 = start.getDayOfMonth();
|
||||
int m1 = start.getMonth();
|
||||
int y1 = start.getYYYY();
|
||||
int d2 = end.getDayOfMonth();
|
||||
int m2 = end.getMonth();
|
||||
int y2 = end.getYYYY();
|
||||
return 360 * (y2 - y1) + 30 * (m2 - m1) + d2 - d1;
|
||||
}
|
||||
return -dayCount30(end, start);
|
||||
}
|
||||
|
||||
public static int dayCount30ISDA(SerialDate start, SerialDate end) {
|
||||
if (start.isBefore(end)) {
|
||||
int d1 = start.getDayOfMonth();
|
||||
int m1 = start.getMonth();
|
||||
int y1 = start.getYYYY();
|
||||
if (d1 == 31)
|
||||
d1 = 30;
|
||||
int d2 = end.getDayOfMonth();
|
||||
int m2 = end.getMonth();
|
||||
int y2 = end.getYYYY();
|
||||
if (d2 == 31 && d1 == 30)
|
||||
d2 = 30;
|
||||
return 360 * (y2 - y1) + 30 * (m2 - m1) + d2 - d1;
|
||||
}
|
||||
if (start.isAfter(end))
|
||||
return -dayCount30ISDA(end, start);
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static int dayCount30PSA(SerialDate start, SerialDate end) {
|
||||
if (start.isOnOrBefore(end)) {
|
||||
int d1 = start.getDayOfMonth();
|
||||
int m1 = start.getMonth();
|
||||
int y1 = start.getYYYY();
|
||||
if (isLastDayOfFebruary(start))
|
||||
d1 = 30;
|
||||
if (d1 == 31 || isLastDayOfFebruary(start))
|
||||
d1 = 30;
|
||||
int d2 = end.getDayOfMonth();
|
||||
int m2 = end.getMonth();
|
||||
int y2 = end.getYYYY();
|
||||
if (d2 == 31 && d1 == 30)
|
||||
d2 = 30;
|
||||
return 360 * (y2 - y1) + 30 * (m2 - m1) + d2 - d1;
|
||||
}
|
||||
return -dayCount30PSA(end, start);
|
||||
}
|
||||
|
||||
public static int dayCount30E(SerialDate start, SerialDate end) {
|
||||
if (start.isBefore(end)) {
|
||||
int d1 = start.getDayOfMonth();
|
||||
int m1 = start.getMonth();
|
||||
int y1 = start.getYYYY();
|
||||
if (d1 == 31)
|
||||
d1 = 30;
|
||||
int d2 = end.getDayOfMonth();
|
||||
int m2 = end.getMonth();
|
||||
int y2 = end.getYYYY();
|
||||
if (d2 == 31)
|
||||
d2 = 30;
|
||||
return 360 * (y2 - y1) + 30 * (m2 - m1) + d2 - d1;
|
||||
}
|
||||
if (start.isAfter(end))
|
||||
return -dayCount30E(end, start);
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static boolean isLastDayOfFebruary(SerialDate d) {
|
||||
if (d.getMonth() == 2) {
|
||||
int dom = d.getDayOfMonth();
|
||||
if (SerialDate.isLeapYear(d.getYYYY()))
|
||||
return (dom == 29);
|
||||
return (dom == 28);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static int countFeb29s(SerialDate start, SerialDate end) {
|
||||
int count = 0;
|
||||
if (start.isBefore(end)) {
|
||||
int y1 = start.getYYYY();
|
||||
int y2 = end.getYYYY();
|
||||
for (int year = y1; year == y2; year++) {
|
||||
if (SerialDate.isLeapYear(year)) {
|
||||
SerialDate feb29 = SerialDate.createInstance(29, 2, year);
|
||||
if (feb29.isInRange(start, end, 2))
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
return countFeb29s(end, start);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,165 @@
|
|||
package org.jfree.date;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
public class SpreadsheetDate extends SerialDate {
|
||||
private static final long serialVersionUID = -2039586705374454461L;
|
||||
|
||||
private final int serial;
|
||||
|
||||
private final int day;
|
||||
|
||||
private final int month;
|
||||
|
||||
private final int year;
|
||||
|
||||
public SpreadsheetDate(int day, int month, int year) {
|
||||
if (year >= 1900 && year <= 9999) {
|
||||
this.year = year;
|
||||
} else {
|
||||
throw new IllegalArgumentException("The 'year' argument must be in range 1900 to 9999.");
|
||||
}
|
||||
if (month >= 1 && month <= 12) {
|
||||
this.month = month;
|
||||
} else {
|
||||
throw new IllegalArgumentException("The 'month' argument must be in the range 1 to 12.");
|
||||
}
|
||||
if (day >= 1 && day <= SerialDate.lastDayOfMonth(month, year)) {
|
||||
this.day = day;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Invalid 'day' argument.");
|
||||
}
|
||||
this.serial = calcSerial(day, month, year);
|
||||
}
|
||||
|
||||
public SpreadsheetDate(int serial) {
|
||||
if (serial >= 2 && serial <= 2958465) {
|
||||
this.serial = serial;
|
||||
} else {
|
||||
throw new IllegalArgumentException("SpreadsheetDate: Serial must be in range 2 to 2958465.");
|
||||
}
|
||||
int days = this.serial - 2;
|
||||
int overestimatedYYYY = 1900 + days / 365;
|
||||
int leaps = SerialDate.leapYearCount(overestimatedYYYY);
|
||||
int nonleapdays = days - leaps;
|
||||
int underestimatedYYYY = 1900 + nonleapdays / 365;
|
||||
if (underestimatedYYYY == overestimatedYYYY) {
|
||||
this.year = underestimatedYYYY;
|
||||
} else {
|
||||
int ss1 = calcSerial(1, 1, underestimatedYYYY);
|
||||
while (ss1 <= this.serial) {
|
||||
underestimatedYYYY++;
|
||||
ss1 = calcSerial(1, 1, underestimatedYYYY);
|
||||
}
|
||||
this.year = underestimatedYYYY - 1;
|
||||
}
|
||||
int ss2 = calcSerial(1, 1, this.year);
|
||||
int[] daysToEndOfPrecedingMonth = AGGREGATE_DAYS_TO_END_OF_PRECEDING_MONTH;
|
||||
if (isLeapYear(this.year))
|
||||
daysToEndOfPrecedingMonth = LEAP_YEAR_AGGREGATE_DAYS_TO_END_OF_PRECEDING_MONTH;
|
||||
int mm = 1;
|
||||
int sss = ss2 + daysToEndOfPrecedingMonth[mm] - 1;
|
||||
while (sss < this.serial) {
|
||||
mm++;
|
||||
sss = ss2 + daysToEndOfPrecedingMonth[mm] - 1;
|
||||
}
|
||||
this.month = mm - 1;
|
||||
this.day = this.serial - ss2 - daysToEndOfPrecedingMonth[this.month] + 1;
|
||||
}
|
||||
|
||||
public int toSerial() {
|
||||
return this.serial;
|
||||
}
|
||||
|
||||
public Date toDate() {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.set(getYYYY(), getMonth() - 1, getDayOfMonth(), 0, 0, 0);
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
public int getYYYY() {
|
||||
return this.year;
|
||||
}
|
||||
|
||||
public int getMonth() {
|
||||
return this.month;
|
||||
}
|
||||
|
||||
public int getDayOfMonth() {
|
||||
return this.day;
|
||||
}
|
||||
|
||||
public int getDayOfWeek() {
|
||||
return (this.serial + 6) % 7 + 1;
|
||||
}
|
||||
|
||||
public boolean equals(Object object) {
|
||||
if (object instanceof SerialDate) {
|
||||
SerialDate s = (SerialDate)object;
|
||||
return (s.toSerial() == toSerial());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return toSerial();
|
||||
}
|
||||
|
||||
public int compare(SerialDate other) {
|
||||
return this.serial - other.toSerial();
|
||||
}
|
||||
|
||||
public int compareTo(Object other) {
|
||||
return compare((SerialDate)other);
|
||||
}
|
||||
|
||||
public boolean isOn(SerialDate other) {
|
||||
return (this.serial == other.toSerial());
|
||||
}
|
||||
|
||||
public boolean isBefore(SerialDate other) {
|
||||
return (this.serial < other.toSerial());
|
||||
}
|
||||
|
||||
public boolean isOnOrBefore(SerialDate other) {
|
||||
return (this.serial <= other.toSerial());
|
||||
}
|
||||
|
||||
public boolean isAfter(SerialDate other) {
|
||||
return (this.serial > other.toSerial());
|
||||
}
|
||||
|
||||
public boolean isOnOrAfter(SerialDate other) {
|
||||
return (this.serial >= other.toSerial());
|
||||
}
|
||||
|
||||
public boolean isInRange(SerialDate d1, SerialDate d2) {
|
||||
return isInRange(d1, d2, 3);
|
||||
}
|
||||
|
||||
public boolean isInRange(SerialDate d1, SerialDate d2, int include) {
|
||||
int s1 = d1.toSerial();
|
||||
int s2 = d2.toSerial();
|
||||
int start = Math.min(s1, s2);
|
||||
int end = Math.max(s1, s2);
|
||||
int s = toSerial();
|
||||
if (include == 3)
|
||||
return (s >= start && s <= end);
|
||||
if (include == 1)
|
||||
return (s >= start && s < end);
|
||||
if (include == 2)
|
||||
return (s > start && s <= end);
|
||||
return (s > start && s < end);
|
||||
}
|
||||
|
||||
private int calcSerial(int d, int m, int y) {
|
||||
int yy = (y - 1900) * 365 + SerialDate.leapYearCount(y - 1);
|
||||
int mm = SerialDate.AGGREGATE_DAYS_TO_END_OF_PRECEDING_MONTH[m];
|
||||
if (m > 2 &&
|
||||
SerialDate.isLeapYear(y))
|
||||
mm++;
|
||||
int dd = d;
|
||||
return yy + mm + dd + 1;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
package org.jfree.io;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
public class FileUtilities {
|
||||
public static File findFileOnClassPath(String name) {
|
||||
String classpath = System.getProperty("java.class.path");
|
||||
String pathSeparator = System.getProperty("path.separator");
|
||||
StringTokenizer tokenizer = new StringTokenizer(classpath, pathSeparator);
|
||||
while (tokenizer.hasMoreTokens()) {
|
||||
String pathElement = tokenizer.nextToken();
|
||||
File directoryOrJar = new File(pathElement);
|
||||
File absoluteDirectoryOrJar = directoryOrJar.getAbsoluteFile();
|
||||
if (absoluteDirectoryOrJar.isFile()) {
|
||||
File file = new File(absoluteDirectoryOrJar.getParent(), name);
|
||||
if (file.exists())
|
||||
return file;
|
||||
continue;
|
||||
}
|
||||
File target = new File(directoryOrJar, name);
|
||||
if (target.exists())
|
||||
return target;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
203
rus/WEB-INF/lib/jcommon-1.0.12_src/org/jfree/io/IOUtils.java
Normal file
203
rus/WEB-INF/lib/jcommon-1.0.12_src/org/jfree/io/IOUtils.java
Normal file
|
|
@ -0,0 +1,203 @@
|
|||
package org.jfree.io;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
public class IOUtils {
|
||||
private static IOUtils instance;
|
||||
|
||||
public static IOUtils getInstance() {
|
||||
if (instance == null)
|
||||
instance = new IOUtils();
|
||||
return instance;
|
||||
}
|
||||
|
||||
private boolean isFileStyleProtocol(URL url) {
|
||||
if (url.getProtocol().equals("http"))
|
||||
return true;
|
||||
if (url.getProtocol().equals("https"))
|
||||
return true;
|
||||
if (url.getProtocol().equals("ftp"))
|
||||
return true;
|
||||
if (url.getProtocol().equals("file"))
|
||||
return true;
|
||||
if (url.getProtocol().equals("jar"))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private List parseName(String name) {
|
||||
ArrayList list = new ArrayList();
|
||||
StringTokenizer strTok = new StringTokenizer(name, "/");
|
||||
while (strTok.hasMoreElements()) {
|
||||
String s = (String)strTok.nextElement();
|
||||
if (s.length() != 0)
|
||||
list.add(s);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private String formatName(List name, String query) {
|
||||
StringBuffer b = new StringBuffer();
|
||||
Iterator it = name.iterator();
|
||||
while (it.hasNext()) {
|
||||
b.append(it.next());
|
||||
if (it.hasNext())
|
||||
b.append("/");
|
||||
}
|
||||
if (query != null) {
|
||||
b.append('?');
|
||||
b.append(query);
|
||||
}
|
||||
return b.toString();
|
||||
}
|
||||
|
||||
private int startsWithUntil(List baseName, List urlName) {
|
||||
int minIdx = Math.min(urlName.size(), baseName.size());
|
||||
for (int i = 0; i < minIdx; i++) {
|
||||
String baseToken = (String)baseName.get(i);
|
||||
String urlToken = (String)urlName.get(i);
|
||||
if (!baseToken.equals(urlToken))
|
||||
return i;
|
||||
}
|
||||
return minIdx;
|
||||
}
|
||||
|
||||
private boolean isSameService(URL url, URL baseUrl) {
|
||||
if (!url.getProtocol().equals(baseUrl.getProtocol()))
|
||||
return false;
|
||||
if (!url.getHost().equals(baseUrl.getHost()))
|
||||
return false;
|
||||
if (url.getPort() != baseUrl.getPort())
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public String createRelativeURL(URL url, URL baseURL) {
|
||||
if (url == null)
|
||||
throw new NullPointerException("content url must not be null.");
|
||||
if (baseURL == null)
|
||||
throw new NullPointerException("baseURL must not be null.");
|
||||
if (isFileStyleProtocol(url) && isSameService(url, baseURL)) {
|
||||
List urlName = parseName(getPath(url));
|
||||
List baseName = parseName(getPath(baseURL));
|
||||
String query = getQuery(url);
|
||||
if (!isPath(baseURL))
|
||||
baseName.remove(baseName.size() - 1);
|
||||
if (url.equals(baseURL))
|
||||
return (String)urlName.get(urlName.size() - 1);
|
||||
int commonIndex = startsWithUntil(urlName, baseName);
|
||||
if (commonIndex == 0)
|
||||
return url.toExternalForm();
|
||||
if (commonIndex == urlName.size())
|
||||
commonIndex--;
|
||||
ArrayList retval = new ArrayList();
|
||||
if (baseName.size() >= urlName.size()) {
|
||||
int levels = baseName.size() - commonIndex;
|
||||
for (int i = 0; i < levels; i++)
|
||||
retval.add("..");
|
||||
}
|
||||
retval.addAll(urlName.subList(commonIndex, urlName.size()));
|
||||
return formatName(retval, query);
|
||||
}
|
||||
return url.toExternalForm();
|
||||
}
|
||||
|
||||
private boolean isPath(URL baseURL) {
|
||||
if (getPath(baseURL).endsWith("/"))
|
||||
return true;
|
||||
if (baseURL.getProtocol().equals("file")) {
|
||||
File f = new File(getPath(baseURL));
|
||||
try {
|
||||
if (f.isDirectory())
|
||||
return true;
|
||||
} catch (SecurityException se) {}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private String getQuery(URL url) {
|
||||
String file = url.getFile();
|
||||
int queryIndex = file.indexOf('?');
|
||||
if (queryIndex == -1)
|
||||
return null;
|
||||
return file.substring(queryIndex + 1);
|
||||
}
|
||||
|
||||
private String getPath(URL url) {
|
||||
String file = url.getFile();
|
||||
int queryIndex = file.indexOf('?');
|
||||
if (queryIndex == -1)
|
||||
return file;
|
||||
return file.substring(0, queryIndex);
|
||||
}
|
||||
|
||||
public void copyStreams(InputStream in, OutputStream out) throws IOException {
|
||||
copyStreams(in, out, 4096);
|
||||
}
|
||||
|
||||
public void copyStreams(InputStream in, OutputStream out, int buffersize) throws IOException {
|
||||
byte[] bytes = new byte[buffersize];
|
||||
int bytesRead = in.read(bytes);
|
||||
while (bytesRead > -1) {
|
||||
out.write(bytes, 0, bytesRead);
|
||||
bytesRead = in.read(bytes);
|
||||
}
|
||||
}
|
||||
|
||||
public void copyWriter(Reader in, Writer out) throws IOException {
|
||||
copyWriter(in, out, 4096);
|
||||
}
|
||||
|
||||
public void copyWriter(Reader in, Writer out, int buffersize) throws IOException {
|
||||
char[] bytes = new char[buffersize];
|
||||
int bytesRead = in.read(bytes);
|
||||
while (bytesRead > -1) {
|
||||
out.write(bytes, 0, bytesRead);
|
||||
bytesRead = in.read(bytes);
|
||||
}
|
||||
}
|
||||
|
||||
public String getFileName(URL url) {
|
||||
String file = url.getFile();
|
||||
int last = file.lastIndexOf("/");
|
||||
if (last < 0)
|
||||
return file;
|
||||
return file.substring(last);
|
||||
}
|
||||
|
||||
public String stripFileExtension(String file) {
|
||||
int idx = file.lastIndexOf(".");
|
||||
if (idx < 1)
|
||||
return file;
|
||||
return file.substring(0, idx);
|
||||
}
|
||||
|
||||
public String getFileExtension(String file) {
|
||||
int idx = file.lastIndexOf(".");
|
||||
if (idx < 1)
|
||||
return "";
|
||||
return file.substring(idx);
|
||||
}
|
||||
|
||||
public boolean isSubDirectory(File base, File child) throws IOException {
|
||||
base = base.getCanonicalFile();
|
||||
child = child.getCanonicalFile();
|
||||
File parentFile = child;
|
||||
while (parentFile != null) {
|
||||
if (base.equals(parentFile))
|
||||
return true;
|
||||
parentFile = parentFile.getParentFile();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,325 @@
|
|||
package org.jfree.io;
|
||||
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.GradientPaint;
|
||||
import java.awt.Paint;
|
||||
import java.awt.Shape;
|
||||
import java.awt.Stroke;
|
||||
import java.awt.geom.Arc2D;
|
||||
import java.awt.geom.Ellipse2D;
|
||||
import java.awt.geom.GeneralPath;
|
||||
import java.awt.geom.Line2D;
|
||||
import java.awt.geom.PathIterator;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.text.AttributedCharacterIterator;
|
||||
import java.text.AttributedString;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class SerialUtilities {
|
||||
public static boolean isSerializable(Class c) {
|
||||
return Serializable.class.isAssignableFrom(c);
|
||||
}
|
||||
|
||||
public static Paint readPaint(ObjectInputStream stream) throws IOException, ClassNotFoundException {
|
||||
if (stream == null)
|
||||
throw new IllegalArgumentException("Null 'stream' argument.");
|
||||
Paint result = null;
|
||||
boolean isNull = stream.readBoolean();
|
||||
if (!isNull) {
|
||||
Class c = (Class)stream.readObject();
|
||||
if (isSerializable(c)) {
|
||||
result = (Paint)stream.readObject();
|
||||
} else if (c.equals(GradientPaint.class)) {
|
||||
float x1 = stream.readFloat();
|
||||
float y1 = stream.readFloat();
|
||||
Color c1 = (Color)stream.readObject();
|
||||
float x2 = stream.readFloat();
|
||||
float y2 = stream.readFloat();
|
||||
Color c2 = (Color)stream.readObject();
|
||||
boolean isCyclic = stream.readBoolean();
|
||||
result = new GradientPaint(x1, y1, c1, x2, y2, c2, isCyclic);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void writePaint(Paint paint, ObjectOutputStream stream) throws IOException {
|
||||
if (stream == null)
|
||||
throw new IllegalArgumentException("Null 'stream' argument.");
|
||||
if (paint != null) {
|
||||
stream.writeBoolean(false);
|
||||
stream.writeObject(paint.getClass());
|
||||
if (paint instanceof Serializable) {
|
||||
stream.writeObject(paint);
|
||||
} else if (paint instanceof GradientPaint) {
|
||||
GradientPaint gp = (GradientPaint)paint;
|
||||
stream.writeFloat((float)gp.getPoint1().getX());
|
||||
stream.writeFloat((float)gp.getPoint1().getY());
|
||||
stream.writeObject(gp.getColor1());
|
||||
stream.writeFloat((float)gp.getPoint2().getX());
|
||||
stream.writeFloat((float)gp.getPoint2().getY());
|
||||
stream.writeObject(gp.getColor2());
|
||||
stream.writeBoolean(gp.isCyclic());
|
||||
}
|
||||
} else {
|
||||
stream.writeBoolean(true);
|
||||
}
|
||||
}
|
||||
|
||||
public static Stroke readStroke(ObjectInputStream stream) throws IOException, ClassNotFoundException {
|
||||
if (stream == null)
|
||||
throw new IllegalArgumentException("Null 'stream' argument.");
|
||||
Stroke result = null;
|
||||
boolean isNull = stream.readBoolean();
|
||||
if (!isNull) {
|
||||
Class c = (Class)stream.readObject();
|
||||
if (c.equals(BasicStroke.class)) {
|
||||
float width = stream.readFloat();
|
||||
int cap = stream.readInt();
|
||||
int join = stream.readInt();
|
||||
float miterLimit = stream.readFloat();
|
||||
float[] dash = (float[])stream.readObject();
|
||||
float dashPhase = stream.readFloat();
|
||||
result = new BasicStroke(width, cap, join, miterLimit, dash, dashPhase);
|
||||
} else {
|
||||
result = (Stroke)stream.readObject();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void writeStroke(Stroke stroke, ObjectOutputStream stream) throws IOException {
|
||||
if (stream == null)
|
||||
throw new IllegalArgumentException("Null 'stream' argument.");
|
||||
if (stroke != null) {
|
||||
stream.writeBoolean(false);
|
||||
if (stroke instanceof BasicStroke) {
|
||||
BasicStroke s = (BasicStroke)stroke;
|
||||
stream.writeObject(BasicStroke.class);
|
||||
stream.writeFloat(s.getLineWidth());
|
||||
stream.writeInt(s.getEndCap());
|
||||
stream.writeInt(s.getLineJoin());
|
||||
stream.writeFloat(s.getMiterLimit());
|
||||
stream.writeObject(s.getDashArray());
|
||||
stream.writeFloat(s.getDashPhase());
|
||||
} else {
|
||||
stream.writeObject(stroke.getClass());
|
||||
stream.writeObject(stroke);
|
||||
}
|
||||
} else {
|
||||
stream.writeBoolean(true);
|
||||
}
|
||||
}
|
||||
|
||||
public static Shape readShape(ObjectInputStream stream) throws IOException, ClassNotFoundException {
|
||||
if (stream == null)
|
||||
throw new IllegalArgumentException("Null 'stream' argument.");
|
||||
Shape result = null;
|
||||
boolean isNull = stream.readBoolean();
|
||||
if (!isNull) {
|
||||
Class c = (Class)stream.readObject();
|
||||
if (c.equals(Line2D.class)) {
|
||||
double x1 = stream.readDouble();
|
||||
double y1 = stream.readDouble();
|
||||
double x2 = stream.readDouble();
|
||||
double y2 = stream.readDouble();
|
||||
result = new Line2D.Double(x1, y1, x2, y2);
|
||||
} else if (c.equals(Rectangle2D.class)) {
|
||||
double x = stream.readDouble();
|
||||
double y = stream.readDouble();
|
||||
double w = stream.readDouble();
|
||||
double h = stream.readDouble();
|
||||
result = new Rectangle2D.Double(x, y, w, h);
|
||||
} else if (c.equals(Ellipse2D.class)) {
|
||||
double x = stream.readDouble();
|
||||
double y = stream.readDouble();
|
||||
double w = stream.readDouble();
|
||||
double h = stream.readDouble();
|
||||
result = new Ellipse2D.Double(x, y, w, h);
|
||||
} else if (c.equals(Arc2D.class)) {
|
||||
double x = stream.readDouble();
|
||||
double y = stream.readDouble();
|
||||
double w = stream.readDouble();
|
||||
double h = stream.readDouble();
|
||||
double as = stream.readDouble();
|
||||
double ae = stream.readDouble();
|
||||
int at = stream.readInt();
|
||||
result = new Arc2D.Double(x, y, w, h, as, ae, at);
|
||||
} else if (c.equals(GeneralPath.class)) {
|
||||
GeneralPath gp = new GeneralPath();
|
||||
float[] args = new float[6];
|
||||
boolean hasNext = stream.readBoolean();
|
||||
while (!hasNext) {
|
||||
int type = stream.readInt();
|
||||
for (int i = 0; i < 6; i++)
|
||||
args[i] = stream.readFloat();
|
||||
switch (type) {
|
||||
case 0:
|
||||
gp.moveTo(args[0], args[1]);
|
||||
break;
|
||||
case 1:
|
||||
gp.lineTo(args[0], args[1]);
|
||||
break;
|
||||
case 3:
|
||||
gp.curveTo(args[0], args[1], args[2], args[3], args[4], args[5]);
|
||||
break;
|
||||
case 2:
|
||||
gp.quadTo(args[0], args[1], args[2], args[3]);
|
||||
break;
|
||||
case 4:
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("JFreeChart - No path exists");
|
||||
}
|
||||
gp.setWindingRule(stream.readInt());
|
||||
hasNext = stream.readBoolean();
|
||||
}
|
||||
result = gp;
|
||||
} else {
|
||||
result = (Shape)stream.readObject();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void writeShape(Shape shape, ObjectOutputStream stream) throws IOException {
|
||||
if (stream == null)
|
||||
throw new IllegalArgumentException("Null 'stream' argument.");
|
||||
if (shape != null) {
|
||||
stream.writeBoolean(false);
|
||||
if (shape instanceof Line2D) {
|
||||
Line2D line = (Line2D)shape;
|
||||
stream.writeObject(Line2D.class);
|
||||
stream.writeDouble(line.getX1());
|
||||
stream.writeDouble(line.getY1());
|
||||
stream.writeDouble(line.getX2());
|
||||
stream.writeDouble(line.getY2());
|
||||
} else if (shape instanceof Rectangle2D) {
|
||||
Rectangle2D rectangle = (Rectangle2D)shape;
|
||||
stream.writeObject(Rectangle2D.class);
|
||||
stream.writeDouble(rectangle.getX());
|
||||
stream.writeDouble(rectangle.getY());
|
||||
stream.writeDouble(rectangle.getWidth());
|
||||
stream.writeDouble(rectangle.getHeight());
|
||||
} else if (shape instanceof Ellipse2D) {
|
||||
Ellipse2D ellipse = (Ellipse2D)shape;
|
||||
stream.writeObject(Ellipse2D.class);
|
||||
stream.writeDouble(ellipse.getX());
|
||||
stream.writeDouble(ellipse.getY());
|
||||
stream.writeDouble(ellipse.getWidth());
|
||||
stream.writeDouble(ellipse.getHeight());
|
||||
} else if (shape instanceof Arc2D) {
|
||||
Arc2D arc = (Arc2D)shape;
|
||||
stream.writeObject(Arc2D.class);
|
||||
stream.writeDouble(arc.getX());
|
||||
stream.writeDouble(arc.getY());
|
||||
stream.writeDouble(arc.getWidth());
|
||||
stream.writeDouble(arc.getHeight());
|
||||
stream.writeDouble(arc.getAngleStart());
|
||||
stream.writeDouble(arc.getAngleExtent());
|
||||
stream.writeInt(arc.getArcType());
|
||||
} else if (shape instanceof GeneralPath) {
|
||||
stream.writeObject(GeneralPath.class);
|
||||
PathIterator pi = shape.getPathIterator(null);
|
||||
float[] args = new float[6];
|
||||
stream.writeBoolean(pi.isDone());
|
||||
while (!pi.isDone()) {
|
||||
int type = pi.currentSegment(args);
|
||||
stream.writeInt(type);
|
||||
for (int i = 0; i < 6; i++)
|
||||
stream.writeFloat(args[i]);
|
||||
stream.writeInt(pi.getWindingRule());
|
||||
pi.next();
|
||||
stream.writeBoolean(pi.isDone());
|
||||
}
|
||||
} else {
|
||||
stream.writeObject(shape.getClass());
|
||||
stream.writeObject(shape);
|
||||
}
|
||||
} else {
|
||||
stream.writeBoolean(true);
|
||||
}
|
||||
}
|
||||
|
||||
public static Point2D readPoint2D(ObjectInputStream stream) throws IOException {
|
||||
if (stream == null)
|
||||
throw new IllegalArgumentException("Null 'stream' argument.");
|
||||
Point2D result = null;
|
||||
boolean isNull = stream.readBoolean();
|
||||
if (!isNull) {
|
||||
double x = stream.readDouble();
|
||||
double y = stream.readDouble();
|
||||
result = new Point2D.Double(x, y);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void writePoint2D(Point2D p, ObjectOutputStream stream) throws IOException {
|
||||
if (stream == null)
|
||||
throw new IllegalArgumentException("Null 'stream' argument.");
|
||||
if (p != null) {
|
||||
stream.writeBoolean(false);
|
||||
stream.writeDouble(p.getX());
|
||||
stream.writeDouble(p.getY());
|
||||
} else {
|
||||
stream.writeBoolean(true);
|
||||
}
|
||||
}
|
||||
|
||||
public static AttributedString readAttributedString(ObjectInputStream stream) throws IOException, ClassNotFoundException {
|
||||
if (stream == null)
|
||||
throw new IllegalArgumentException("Null 'stream' argument.");
|
||||
AttributedString result = null;
|
||||
boolean isNull = stream.readBoolean();
|
||||
if (!isNull) {
|
||||
String plainStr = (String)stream.readObject();
|
||||
result = new AttributedString(plainStr);
|
||||
char c = stream.readChar();
|
||||
int start = 0;
|
||||
while (c != Character.MAX_VALUE) {
|
||||
int limit = stream.readInt();
|
||||
Map atts = (Map)stream.readObject();
|
||||
result.addAttributes(atts, start, limit);
|
||||
start = limit;
|
||||
c = stream.readChar();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void writeAttributedString(AttributedString as, ObjectOutputStream stream) throws IOException {
|
||||
if (stream == null)
|
||||
throw new IllegalArgumentException("Null 'stream' argument.");
|
||||
if (as != null) {
|
||||
stream.writeBoolean(false);
|
||||
AttributedCharacterIterator aci = as.getIterator();
|
||||
StringBuffer plainStr = new StringBuffer();
|
||||
char current = aci.first();
|
||||
while (current != Character.MAX_VALUE) {
|
||||
plainStr = plainStr.append(current);
|
||||
current = aci.next();
|
||||
}
|
||||
stream.writeObject(plainStr.toString());
|
||||
current = aci.first();
|
||||
int begin = aci.getBeginIndex();
|
||||
while (current != Character.MAX_VALUE) {
|
||||
stream.writeChar(current);
|
||||
int limit = aci.getRunLimit();
|
||||
stream.writeInt(limit - begin);
|
||||
Map atts = new HashMap(aci.getAttributes());
|
||||
stream.writeObject(atts);
|
||||
current = aci.setIndex(limit);
|
||||
}
|
||||
stream.writeChar(65535);
|
||||
} else {
|
||||
stream.writeBoolean(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
package org.jfree.layout;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Container;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Insets;
|
||||
import java.awt.LayoutManager;
|
||||
import java.io.Serializable;
|
||||
|
||||
public class CenterLayout implements LayoutManager, Serializable {
|
||||
private static final long serialVersionUID = 469319532333015042L;
|
||||
|
||||
public Dimension preferredLayoutSize(Container parent) {
|
||||
synchronized (parent.getTreeLock()) {
|
||||
Insets insets = parent.getInsets();
|
||||
if (parent.getComponentCount() > 0) {
|
||||
Component component = parent.getComponent(0);
|
||||
Dimension d = component.getPreferredSize();
|
||||
return new Dimension((int)d.getWidth() + insets.left + insets.right, (int)d.getHeight() + insets.top + insets.bottom);
|
||||
}
|
||||
return new Dimension(insets.left + insets.right, insets.top + insets.bottom);
|
||||
}
|
||||
}
|
||||
|
||||
public Dimension minimumLayoutSize(Container parent) {
|
||||
synchronized (parent.getTreeLock()) {
|
||||
Insets insets = parent.getInsets();
|
||||
if (parent.getComponentCount() > 0) {
|
||||
Component component = parent.getComponent(0);
|
||||
Dimension d = component.getMinimumSize();
|
||||
return new Dimension(d.width + insets.left + insets.right, d.height + insets.top + insets.bottom);
|
||||
}
|
||||
return new Dimension(insets.left + insets.right, insets.top + insets.bottom);
|
||||
}
|
||||
}
|
||||
|
||||
public void layoutContainer(Container parent) {
|
||||
synchronized (parent.getTreeLock()) {
|
||||
if (parent.getComponentCount() > 0) {
|
||||
Insets insets = parent.getInsets();
|
||||
Dimension parentSize = parent.getSize();
|
||||
Component component = parent.getComponent(0);
|
||||
Dimension componentSize = component.getPreferredSize();
|
||||
int xx = insets.left + Math.max((parentSize.width - insets.left - insets.right - componentSize.width) / 2, 0);
|
||||
int yy = insets.top + Math.max((parentSize.height - insets.top - insets.bottom - componentSize.height) / 2, 0);
|
||||
component.setBounds(xx, yy, componentSize.width, componentSize.height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addLayoutComponent(Component comp) {}
|
||||
|
||||
public void removeLayoutComponent(Component comp) {}
|
||||
|
||||
public void addLayoutComponent(String name, Component comp) {}
|
||||
|
||||
public void removeLayoutComponent(String name, Component comp) {}
|
||||
}
|
||||
|
|
@ -0,0 +1,497 @@
|
|||
package org.jfree.layout;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Container;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Insets;
|
||||
import java.awt.LayoutManager;
|
||||
import java.io.Serializable;
|
||||
|
||||
public class FormatLayout implements LayoutManager, Serializable {
|
||||
private static final long serialVersionUID = 2866692886323930722L;
|
||||
|
||||
public static final int C = 1;
|
||||
|
||||
public static final int LC = 2;
|
||||
|
||||
public static final int LCB = 3;
|
||||
|
||||
public static final int LCLC = 4;
|
||||
|
||||
public static final int LCLCB = 5;
|
||||
|
||||
public static final int LCBLC = 6;
|
||||
|
||||
public static final int LCBLCB = 7;
|
||||
|
||||
private int[] rowFormats;
|
||||
|
||||
private int rowGap;
|
||||
|
||||
private int[] columnGaps;
|
||||
|
||||
private int[] rowHeights;
|
||||
|
||||
private int totalHeight;
|
||||
|
||||
private int[] columnWidths;
|
||||
|
||||
private int totalWidth;
|
||||
|
||||
private int columns1and2Width;
|
||||
|
||||
private int columns4and5Width;
|
||||
|
||||
private int columns1to4Width;
|
||||
|
||||
private int columns1to5Width;
|
||||
|
||||
private int columns0to5Width;
|
||||
|
||||
public FormatLayout(int rowCount, int[] rowFormats) {
|
||||
this.rowFormats = rowFormats;
|
||||
this.rowGap = 2;
|
||||
this.columnGaps = new int[5];
|
||||
this.columnGaps[0] = 10;
|
||||
this.columnGaps[1] = 5;
|
||||
this.columnGaps[2] = 5;
|
||||
this.columnGaps[3] = 10;
|
||||
this.columnGaps[4] = 5;
|
||||
this.rowHeights = new int[rowCount];
|
||||
this.columnWidths = new int[6];
|
||||
}
|
||||
|
||||
public Dimension preferredLayoutSize(Container parent) {
|
||||
synchronized (parent.getTreeLock()) {
|
||||
Insets insets = parent.getInsets();
|
||||
int componentIndex = 0;
|
||||
int rowCount = this.rowHeights.length;
|
||||
for (int i = 0; i < this.columnWidths.length; i++)
|
||||
this.columnWidths[i] = 0;
|
||||
this.columns1and2Width = 0;
|
||||
this.columns4and5Width = 0;
|
||||
this.columns1to4Width = 0;
|
||||
this.columns1to5Width = 0;
|
||||
this.columns0to5Width = 0;
|
||||
this.totalHeight = 0;
|
||||
for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) {
|
||||
Component c0, c1, c2, c3, c4, c5;
|
||||
int format = this.rowFormats[rowIndex % this.rowFormats.length];
|
||||
switch (format) {
|
||||
case 1:
|
||||
c0 = parent.getComponent(componentIndex);
|
||||
updateC(rowIndex, c0.getPreferredSize());
|
||||
componentIndex++;
|
||||
break;
|
||||
case 2:
|
||||
c0 = parent.getComponent(componentIndex);
|
||||
c1 = parent.getComponent(componentIndex + 1);
|
||||
updateLC(rowIndex, c0.getPreferredSize(), c1.getPreferredSize());
|
||||
componentIndex += 2;
|
||||
break;
|
||||
case 3:
|
||||
c0 = parent.getComponent(componentIndex);
|
||||
c1 = parent.getComponent(componentIndex + 1);
|
||||
c2 = parent.getComponent(componentIndex + 2);
|
||||
updateLCB(rowIndex, c0.getPreferredSize(), c1.getPreferredSize(), c2.getPreferredSize());
|
||||
componentIndex += 3;
|
||||
break;
|
||||
case 4:
|
||||
c0 = parent.getComponent(componentIndex);
|
||||
c1 = parent.getComponent(componentIndex + 1);
|
||||
c2 = parent.getComponent(componentIndex + 2);
|
||||
c3 = parent.getComponent(componentIndex + 3);
|
||||
updateLCLC(rowIndex, c0.getPreferredSize(), c1.getPreferredSize(), c2.getPreferredSize(), c3.getPreferredSize());
|
||||
componentIndex += 4;
|
||||
break;
|
||||
case 6:
|
||||
c0 = parent.getComponent(componentIndex);
|
||||
c1 = parent.getComponent(componentIndex + 1);
|
||||
c2 = parent.getComponent(componentIndex + 2);
|
||||
c3 = parent.getComponent(componentIndex + 3);
|
||||
c4 = parent.getComponent(componentIndex + 4);
|
||||
updateLCBLC(rowIndex, c0.getPreferredSize(), c1.getPreferredSize(), c2.getPreferredSize(), c3.getPreferredSize(), c4.getPreferredSize());
|
||||
componentIndex += 5;
|
||||
break;
|
||||
case 5:
|
||||
c0 = parent.getComponent(componentIndex);
|
||||
c1 = parent.getComponent(componentIndex + 1);
|
||||
c2 = parent.getComponent(componentIndex + 2);
|
||||
c3 = parent.getComponent(componentIndex + 3);
|
||||
c4 = parent.getComponent(componentIndex + 4);
|
||||
updateLCLCB(rowIndex, c0.getPreferredSize(), c1.getPreferredSize(), c2.getPreferredSize(), c3.getPreferredSize(), c4.getPreferredSize());
|
||||
componentIndex += 5;
|
||||
break;
|
||||
case 7:
|
||||
c0 = parent.getComponent(componentIndex);
|
||||
c1 = parent.getComponent(componentIndex + 1);
|
||||
c2 = parent.getComponent(componentIndex + 2);
|
||||
c3 = parent.getComponent(componentIndex + 3);
|
||||
c4 = parent.getComponent(componentIndex + 4);
|
||||
c5 = parent.getComponent(componentIndex + 5);
|
||||
updateLCBLCB(rowIndex, c0.getPreferredSize(), c1.getPreferredSize(), c2.getPreferredSize(), c3.getPreferredSize(), c4.getPreferredSize(), c5.getPreferredSize());
|
||||
componentIndex += 6;
|
||||
break;
|
||||
}
|
||||
}
|
||||
complete();
|
||||
return new Dimension(this.totalWidth + insets.left + insets.right, this.totalHeight + (rowCount - 1) * this.rowGap + insets.top + insets.bottom);
|
||||
}
|
||||
}
|
||||
|
||||
public Dimension minimumLayoutSize(Container parent) {
|
||||
synchronized (parent.getTreeLock()) {
|
||||
Insets insets = parent.getInsets();
|
||||
int componentIndex = 0;
|
||||
int rowCount = this.rowHeights.length;
|
||||
for (int i = 0; i < this.columnWidths.length; i++)
|
||||
this.columnWidths[i] = 0;
|
||||
this.columns1and2Width = 0;
|
||||
this.columns4and5Width = 0;
|
||||
this.columns1to4Width = 0;
|
||||
this.columns1to5Width = 0;
|
||||
this.columns0to5Width = 0;
|
||||
int totalHeight = 0;
|
||||
for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) {
|
||||
Component c0, c1, c2, c3, c4, c5;
|
||||
int format = this.rowFormats[rowIndex % this.rowFormats.length];
|
||||
switch (format) {
|
||||
case 1:
|
||||
c0 = parent.getComponent(componentIndex);
|
||||
this.columns0to5Width = Math.max(this.columns0to5Width, (c0.getMinimumSize()).width);
|
||||
componentIndex++;
|
||||
break;
|
||||
case 2:
|
||||
c0 = parent.getComponent(componentIndex);
|
||||
c1 = parent.getComponent(componentIndex + 1);
|
||||
updateLC(rowIndex, c0.getMinimumSize(), c1.getMinimumSize());
|
||||
componentIndex += 2;
|
||||
break;
|
||||
case 3:
|
||||
c0 = parent.getComponent(componentIndex);
|
||||
c1 = parent.getComponent(componentIndex + 1);
|
||||
c2 = parent.getComponent(componentIndex + 2);
|
||||
updateLCB(rowIndex, c0.getMinimumSize(), c1.getMinimumSize(), c2.getMinimumSize());
|
||||
componentIndex += 3;
|
||||
break;
|
||||
case 4:
|
||||
c0 = parent.getComponent(componentIndex);
|
||||
c1 = parent.getComponent(componentIndex + 1);
|
||||
c2 = parent.getComponent(componentIndex + 2);
|
||||
c3 = parent.getComponent(componentIndex + 3);
|
||||
updateLCLC(rowIndex, c0.getMinimumSize(), c1.getMinimumSize(), c2.getMinimumSize(), c3.getMinimumSize());
|
||||
componentIndex += 3;
|
||||
break;
|
||||
case 6:
|
||||
c0 = parent.getComponent(componentIndex);
|
||||
c1 = parent.getComponent(componentIndex + 1);
|
||||
c2 = parent.getComponent(componentIndex + 2);
|
||||
c3 = parent.getComponent(componentIndex + 3);
|
||||
c4 = parent.getComponent(componentIndex + 4);
|
||||
updateLCBLC(rowIndex, c0.getMinimumSize(), c1.getMinimumSize(), c2.getMinimumSize(), c3.getMinimumSize(), c4.getMinimumSize());
|
||||
componentIndex += 4;
|
||||
break;
|
||||
case 5:
|
||||
c0 = parent.getComponent(componentIndex);
|
||||
c1 = parent.getComponent(componentIndex + 1);
|
||||
c2 = parent.getComponent(componentIndex + 2);
|
||||
c3 = parent.getComponent(componentIndex + 3);
|
||||
c4 = parent.getComponent(componentIndex + 4);
|
||||
updateLCLCB(rowIndex, c0.getMinimumSize(), c1.getMinimumSize(), c2.getMinimumSize(), c3.getMinimumSize(), c4.getMinimumSize());
|
||||
componentIndex += 4;
|
||||
break;
|
||||
case 7:
|
||||
c0 = parent.getComponent(componentIndex);
|
||||
c1 = parent.getComponent(componentIndex + 1);
|
||||
c2 = parent.getComponent(componentIndex + 2);
|
||||
c3 = parent.getComponent(componentIndex + 3);
|
||||
c4 = parent.getComponent(componentIndex + 4);
|
||||
c5 = parent.getComponent(componentIndex + 5);
|
||||
updateLCBLCB(rowIndex, c0.getMinimumSize(), c1.getMinimumSize(), c2.getMinimumSize(), c3.getMinimumSize(), c4.getMinimumSize(), c5.getMinimumSize());
|
||||
componentIndex += 5;
|
||||
break;
|
||||
}
|
||||
}
|
||||
complete();
|
||||
return new Dimension(this.totalWidth + insets.left + insets.right, 0 + (rowCount - 1) * this.rowGap + insets.top + insets.bottom);
|
||||
}
|
||||
}
|
||||
|
||||
public void layoutContainer(Container parent) {
|
||||
synchronized (parent.getTreeLock()) {
|
||||
Insets insets = parent.getInsets();
|
||||
int componentIndex = 0;
|
||||
int rowCount = this.rowHeights.length;
|
||||
for (int i = 0; i < this.columnWidths.length; i++)
|
||||
this.columnWidths[i] = 0;
|
||||
this.columns1and2Width = 0;
|
||||
this.columns4and5Width = 0;
|
||||
this.columns1to4Width = 0;
|
||||
this.columns1to5Width = 0;
|
||||
this.columns0to5Width = (parent.getBounds()).width - insets.left - insets.right;
|
||||
this.totalHeight = 0;
|
||||
for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) {
|
||||
Component c0, c1, c2, c3, c4, c5;
|
||||
int format = this.rowFormats[rowIndex % this.rowFormats.length];
|
||||
switch (format) {
|
||||
case 1:
|
||||
c0 = parent.getComponent(componentIndex);
|
||||
updateC(rowIndex, c0.getPreferredSize());
|
||||
componentIndex++;
|
||||
break;
|
||||
case 2:
|
||||
c0 = parent.getComponent(componentIndex);
|
||||
c1 = parent.getComponent(componentIndex + 1);
|
||||
updateLC(rowIndex, c0.getPreferredSize(), c1.getPreferredSize());
|
||||
componentIndex += 2;
|
||||
break;
|
||||
case 3:
|
||||
c0 = parent.getComponent(componentIndex);
|
||||
c1 = parent.getComponent(componentIndex + 1);
|
||||
c2 = parent.getComponent(componentIndex + 2);
|
||||
updateLCB(rowIndex, c0.getPreferredSize(), c1.getPreferredSize(), c2.getPreferredSize());
|
||||
componentIndex += 3;
|
||||
break;
|
||||
case 4:
|
||||
c0 = parent.getComponent(componentIndex);
|
||||
c1 = parent.getComponent(componentIndex + 1);
|
||||
c2 = parent.getComponent(componentIndex + 2);
|
||||
c3 = parent.getComponent(componentIndex + 3);
|
||||
updateLCLC(rowIndex, c0.getPreferredSize(), c1.getPreferredSize(), c2.getPreferredSize(), c3.getPreferredSize());
|
||||
componentIndex += 4;
|
||||
break;
|
||||
case 6:
|
||||
c0 = parent.getComponent(componentIndex);
|
||||
c1 = parent.getComponent(componentIndex + 1);
|
||||
c2 = parent.getComponent(componentIndex + 2);
|
||||
c3 = parent.getComponent(componentIndex + 3);
|
||||
c4 = parent.getComponent(componentIndex + 4);
|
||||
updateLCBLC(rowIndex, c0.getPreferredSize(), c1.getPreferredSize(), c2.getPreferredSize(), c3.getPreferredSize(), c4.getPreferredSize());
|
||||
componentIndex += 5;
|
||||
break;
|
||||
case 5:
|
||||
c0 = parent.getComponent(componentIndex);
|
||||
c1 = parent.getComponent(componentIndex + 1);
|
||||
c2 = parent.getComponent(componentIndex + 2);
|
||||
c3 = parent.getComponent(componentIndex + 3);
|
||||
c4 = parent.getComponent(componentIndex + 4);
|
||||
updateLCLCB(rowIndex, c0.getPreferredSize(), c1.getPreferredSize(), c2.getPreferredSize(), c3.getPreferredSize(), c4.getPreferredSize());
|
||||
componentIndex += 5;
|
||||
break;
|
||||
case 7:
|
||||
c0 = parent.getComponent(componentIndex);
|
||||
c1 = parent.getComponent(componentIndex + 1);
|
||||
c2 = parent.getComponent(componentIndex + 2);
|
||||
c3 = parent.getComponent(componentIndex + 3);
|
||||
c4 = parent.getComponent(componentIndex + 4);
|
||||
c5 = parent.getComponent(componentIndex + 5);
|
||||
updateLCBLCB(rowIndex, c0.getPreferredSize(), c1.getPreferredSize(), c2.getPreferredSize(), c3.getPreferredSize(), c4.getPreferredSize(), c5.getPreferredSize());
|
||||
componentIndex += 6;
|
||||
break;
|
||||
}
|
||||
}
|
||||
complete();
|
||||
componentIndex = 0;
|
||||
int rowY = insets.top;
|
||||
int[] rowX = new int[6];
|
||||
rowX[0] = insets.left;
|
||||
rowX[1] = rowX[0] + this.columnWidths[0] + this.columnGaps[0];
|
||||
rowX[2] = rowX[1] + this.columnWidths[1] + this.columnGaps[1];
|
||||
rowX[3] = rowX[2] + this.columnWidths[2] + this.columnGaps[2];
|
||||
rowX[4] = rowX[3] + this.columnWidths[3] + this.columnGaps[3];
|
||||
rowX[5] = rowX[4] + this.columnWidths[4] + this.columnGaps[4];
|
||||
int w1to2 = this.columnWidths[1] + this.columnGaps[1] + this.columnWidths[2];
|
||||
int w4to5 = this.columnWidths[4] + this.columnGaps[4] + this.columnWidths[5];
|
||||
int w1to4 = w1to2 + this.columnGaps[2] + this.columnWidths[3] + this.columnGaps[3] + this.columnWidths[4];
|
||||
int w1to5 = w1to4 + this.columnGaps[4] + this.columnWidths[5];
|
||||
int w0to5 = w1to5 + this.columnWidths[0] + this.columnGaps[0];
|
||||
for (int j = 0; j < rowCount; j++) {
|
||||
Component c0, c1, c2, c3, c4, c5;
|
||||
int format = this.rowFormats[j % this.rowFormats.length];
|
||||
switch (format) {
|
||||
case 1:
|
||||
c0 = parent.getComponent(componentIndex);
|
||||
c0.setBounds(rowX[0], rowY, w0to5, (c0.getPreferredSize()).height);
|
||||
componentIndex++;
|
||||
break;
|
||||
case 2:
|
||||
c0 = parent.getComponent(componentIndex);
|
||||
c0.setBounds(rowX[0], rowY + (this.rowHeights[j] - (c0.getPreferredSize()).height) / 2, this.columnWidths[0], (c0.getPreferredSize()).height);
|
||||
c1 = parent.getComponent(componentIndex + 1);
|
||||
c1.setBounds(rowX[1], rowY + (this.rowHeights[j] - (c1.getPreferredSize()).height) / 2, w1to5, (c1.getPreferredSize()).height);
|
||||
componentIndex += 2;
|
||||
break;
|
||||
case 3:
|
||||
c0 = parent.getComponent(componentIndex);
|
||||
c0.setBounds(rowX[0], rowY + (this.rowHeights[j] - (c0.getPreferredSize()).height) / 2, this.columnWidths[0], (c0.getPreferredSize()).height);
|
||||
c1 = parent.getComponent(componentIndex + 1);
|
||||
c1.setBounds(rowX[1], rowY + (this.rowHeights[j] - (c1.getPreferredSize()).height) / 2, w1to4, (c1.getPreferredSize()).height);
|
||||
c2 = parent.getComponent(componentIndex + 2);
|
||||
c2.setBounds(rowX[5], rowY + (this.rowHeights[j] - (c2.getPreferredSize()).height) / 2, this.columnWidths[5], (c2.getPreferredSize()).height);
|
||||
componentIndex += 3;
|
||||
break;
|
||||
case 4:
|
||||
c0 = parent.getComponent(componentIndex);
|
||||
c0.setBounds(rowX[0], rowY + (this.rowHeights[j] - (c0.getPreferredSize()).height) / 2, this.columnWidths[0], (c0.getPreferredSize()).height);
|
||||
c1 = parent.getComponent(componentIndex + 1);
|
||||
c1.setBounds(rowX[1], rowY + (this.rowHeights[j] - (c1.getPreferredSize()).height) / 2, w1to2, (c1.getPreferredSize()).height);
|
||||
c2 = parent.getComponent(componentIndex + 2);
|
||||
c2.setBounds(rowX[3], rowY + (this.rowHeights[j] - (c2.getPreferredSize()).height) / 2, this.columnWidths[3], (c2.getPreferredSize()).height);
|
||||
c3 = parent.getComponent(componentIndex + 3);
|
||||
c3.setBounds(rowX[4], rowY + (this.rowHeights[j] - (c3.getPreferredSize()).height) / 2, w4to5, (c3.getPreferredSize()).height);
|
||||
componentIndex += 4;
|
||||
break;
|
||||
case 6:
|
||||
c0 = parent.getComponent(componentIndex);
|
||||
c0.setBounds(rowX[0], rowY + (this.rowHeights[j] - (c0.getPreferredSize()).height) / 2, this.columnWidths[0], (c0.getPreferredSize()).height);
|
||||
c1 = parent.getComponent(componentIndex + 1);
|
||||
c1.setBounds(rowX[1], rowY + (this.rowHeights[j] - (c1.getPreferredSize()).height) / 2, this.columnWidths[1], (c1.getPreferredSize()).height);
|
||||
c2 = parent.getComponent(componentIndex + 2);
|
||||
c2.setBounds(rowX[2], rowY + (this.rowHeights[j] - (c2.getPreferredSize()).height) / 2, this.columnWidths[2], (c2.getPreferredSize()).height);
|
||||
c3 = parent.getComponent(componentIndex + 3);
|
||||
c3.setBounds(rowX[3], rowY + (this.rowHeights[j] - (c3.getPreferredSize()).height) / 2, this.columnWidths[3], (c3.getPreferredSize()).height);
|
||||
c4 = parent.getComponent(componentIndex + 4);
|
||||
c4.setBounds(rowX[4], rowY + (this.rowHeights[j] - (c4.getPreferredSize()).height) / 2, w4to5, (c4.getPreferredSize()).height);
|
||||
componentIndex += 5;
|
||||
break;
|
||||
case 5:
|
||||
c0 = parent.getComponent(componentIndex);
|
||||
c0.setBounds(rowX[0], rowY + (this.rowHeights[j] - (c0.getPreferredSize()).height) / 2, this.columnWidths[0], (c0.getPreferredSize()).height);
|
||||
c1 = parent.getComponent(componentIndex + 1);
|
||||
c1.setBounds(rowX[1], rowY + (this.rowHeights[j] - (c1.getPreferredSize()).height) / 2, w1to2, (c1.getPreferredSize()).height);
|
||||
c2 = parent.getComponent(componentIndex + 2);
|
||||
c2.setBounds(rowX[3], rowY + (this.rowHeights[j] - (c2.getPreferredSize()).height) / 2, this.columnWidths[3], (c2.getPreferredSize()).height);
|
||||
c3 = parent.getComponent(componentIndex + 3);
|
||||
c3.setBounds(rowX[4], rowY + (this.rowHeights[j] - (c3.getPreferredSize()).height) / 2, this.columnWidths[4], (c3.getPreferredSize()).height);
|
||||
c4 = parent.getComponent(componentIndex + 4);
|
||||
c4.setBounds(rowX[5], rowY + (this.rowHeights[j] - (c4.getPreferredSize()).height) / 2, this.columnWidths[5], (c4.getPreferredSize()).height);
|
||||
componentIndex += 5;
|
||||
break;
|
||||
case 7:
|
||||
c0 = parent.getComponent(componentIndex);
|
||||
c0.setBounds(rowX[0], rowY + (this.rowHeights[j] - (c0.getPreferredSize()).height) / 2, this.columnWidths[0], (c0.getPreferredSize()).height);
|
||||
c1 = parent.getComponent(componentIndex + 1);
|
||||
c1.setBounds(rowX[1], rowY + (this.rowHeights[j] - (c1.getPreferredSize()).height) / 2, this.columnWidths[1], (c1.getPreferredSize()).height);
|
||||
c2 = parent.getComponent(componentIndex + 2);
|
||||
c2.setBounds(rowX[2], rowY + (this.rowHeights[j] - (c2.getPreferredSize()).height) / 2, this.columnWidths[2], (c2.getPreferredSize()).height);
|
||||
c3 = parent.getComponent(componentIndex + 3);
|
||||
c3.setBounds(rowX[3], rowY + (this.rowHeights[j] - (c3.getPreferredSize()).height) / 2, this.columnWidths[3], (c3.getPreferredSize()).height);
|
||||
c4 = parent.getComponent(componentIndex + 4);
|
||||
c4.setBounds(rowX[4], rowY + (this.rowHeights[j] - (c4.getPreferredSize()).height) / 2, this.columnWidths[4], (c4.getPreferredSize()).height);
|
||||
c5 = parent.getComponent(componentIndex + 5);
|
||||
c5.setBounds(rowX[5], rowY + (this.rowHeights[j] - (c5.getPreferredSize()).height) / 2, this.columnWidths[5], (c5.getPreferredSize()).height);
|
||||
componentIndex += 6;
|
||||
break;
|
||||
}
|
||||
rowY = rowY + this.rowHeights[j] + this.rowGap;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void updateC(int rowIndex, Dimension d0) {
|
||||
this.rowHeights[rowIndex] = d0.height;
|
||||
this.totalHeight += this.rowHeights[rowIndex];
|
||||
this.columns0to5Width = Math.max(this.columns0to5Width, d0.width);
|
||||
}
|
||||
|
||||
protected void updateLC(int rowIndex, Dimension d0, Dimension d1) {
|
||||
this.rowHeights[rowIndex] = Math.max(d0.height, d1.height);
|
||||
this.totalHeight += this.rowHeights[rowIndex];
|
||||
this.columnWidths[0] = Math.max(this.columnWidths[0], d0.width);
|
||||
this.columns1to5Width = Math.max(this.columns1to5Width, d1.width);
|
||||
}
|
||||
|
||||
protected void updateLCB(int rowIndex, Dimension d0, Dimension d1, Dimension d2) {
|
||||
this.rowHeights[rowIndex] = Math.max(d0.height, Math.max(d1.height, d2.height));
|
||||
this.totalHeight += this.rowHeights[rowIndex];
|
||||
this.columnWidths[0] = Math.max(this.columnWidths[0], d0.width);
|
||||
this.columns1to4Width = Math.max(this.columns1to4Width, d1.width);
|
||||
this.columnWidths[5] = Math.max(this.columnWidths[5], d2.width);
|
||||
}
|
||||
|
||||
protected void updateLCLC(int rowIndex, Dimension d0, Dimension d1, Dimension d2, Dimension d3) {
|
||||
this.rowHeights[rowIndex] = Math.max(Math.max(d0.height, d1.height), Math.max(d2.height, d3.height));
|
||||
this.totalHeight += this.rowHeights[rowIndex];
|
||||
this.columnWidths[0] = Math.max(this.columnWidths[0], d0.width);
|
||||
this.columns1and2Width = Math.max(this.columns1and2Width, d1.width);
|
||||
this.columnWidths[3] = Math.max(this.columnWidths[3], d2.width);
|
||||
this.columns4and5Width = Math.max(this.columns4and5Width, d3.width);
|
||||
}
|
||||
|
||||
protected void updateLCBLC(int rowIndex, Dimension d0, Dimension d1, Dimension d2, Dimension d3, Dimension d4) {
|
||||
this.rowHeights[rowIndex] = Math.max(d0.height, Math.max(Math.max(d1.height, d2.height), Math.max(d3.height, d4.height)));
|
||||
this.totalHeight += this.rowHeights[rowIndex];
|
||||
this.columnWidths[0] = Math.max(this.columnWidths[0], d0.width);
|
||||
this.columnWidths[1] = Math.max(this.columnWidths[1], d1.width);
|
||||
this.columnWidths[2] = Math.max(this.columnWidths[2], d2.width);
|
||||
this.columnWidths[3] = Math.max(this.columnWidths[3], d3.width);
|
||||
this.columns4and5Width = Math.max(this.columns4and5Width, d4.width);
|
||||
}
|
||||
|
||||
protected void updateLCLCB(int rowIndex, Dimension d0, Dimension d1, Dimension d2, Dimension d3, Dimension d4) {
|
||||
this.rowHeights[rowIndex] = Math.max(d0.height, Math.max(Math.max(d1.height, d2.height), Math.max(d3.height, d4.height)));
|
||||
this.totalHeight += this.rowHeights[rowIndex];
|
||||
this.columnWidths[0] = Math.max(this.columnWidths[0], d0.width);
|
||||
this.columns1and2Width = Math.max(this.columns1and2Width, d1.width);
|
||||
this.columnWidths[3] = Math.max(this.columnWidths[3], d2.width);
|
||||
this.columnWidths[4] = Math.max(this.columnWidths[4], d3.width);
|
||||
this.columnWidths[5] = Math.max(this.columnWidths[5], d4.width);
|
||||
}
|
||||
|
||||
protected void updateLCBLCB(int rowIndex, Dimension d0, Dimension d1, Dimension d2, Dimension d3, Dimension d4, Dimension d5) {
|
||||
this.rowHeights[rowIndex] = Math.max(Math.max(d0.height, d1.height), Math.max(Math.max(d2.height, d3.height), Math.max(d4.height, d5.height)));
|
||||
this.totalHeight += this.rowHeights[rowIndex];
|
||||
this.columnWidths[0] = Math.max(this.columnWidths[0], d0.width);
|
||||
this.columnWidths[1] = Math.max(this.columnWidths[1], d1.width);
|
||||
this.columnWidths[2] = Math.max(this.columnWidths[2], d2.width);
|
||||
this.columnWidths[3] = Math.max(this.columnWidths[3], d3.width);
|
||||
this.columnWidths[4] = Math.max(this.columnWidths[4], d4.width);
|
||||
this.columnWidths[5] = Math.max(this.columnWidths[5], d5.width);
|
||||
}
|
||||
|
||||
public void complete() {
|
||||
this.columnWidths[1] = Math.max(this.columnWidths[1], this.columns1and2Width - this.columnGaps[1] - this.columnWidths[2]);
|
||||
this.columnWidths[4] = Math.max(this.columnWidths[4], Math.max(this.columns4and5Width - this.columnGaps[4] - this.columnWidths[5], Math.max(this.columns1to4Width - this.columnGaps[1] - this.columnGaps[2] - this.columnGaps[3] - this.columnWidths[1] - this.columnWidths[2] - this.columnWidths[3], this.columns1to5Width - this.columnGaps[1] - this.columnGaps[2] - this.columnGaps[3] - this.columnWidths[1] - this.columnWidths[2] - this.columnWidths[3] - this.columnGaps[4])));
|
||||
int leftWidth = this.columnWidths[0] + this.columnGaps[0] + this.columnWidths[1] + this.columnGaps[1] + this.columnWidths[2];
|
||||
int rightWidth = this.columnWidths[3] + this.columnGaps[3] + this.columnWidths[4] + this.columnGaps[4] + this.columnWidths[5];
|
||||
if (splitLayout())
|
||||
if (leftWidth > rightWidth) {
|
||||
int mismatch = leftWidth - rightWidth;
|
||||
this.columnWidths[4] = this.columnWidths[4] + mismatch;
|
||||
rightWidth += mismatch;
|
||||
} else {
|
||||
int mismatch = rightWidth - leftWidth;
|
||||
this.columnWidths[1] = this.columnWidths[1] + mismatch;
|
||||
leftWidth += mismatch;
|
||||
}
|
||||
this.totalWidth = leftWidth + this.columnGaps[2] + rightWidth;
|
||||
if (this.columns0to5Width > this.totalWidth) {
|
||||
int spaceToAdd = this.columns0to5Width - this.totalWidth;
|
||||
if (splitLayout()) {
|
||||
int halfSpaceToAdd = spaceToAdd / 2;
|
||||
this.columnWidths[1] = this.columnWidths[1] + halfSpaceToAdd;
|
||||
this.columnWidths[4] = this.columnWidths[4] + spaceToAdd - halfSpaceToAdd;
|
||||
this.totalWidth += spaceToAdd;
|
||||
} else {
|
||||
this.columnWidths[1] = this.columnWidths[1] + spaceToAdd;
|
||||
this.totalWidth += spaceToAdd;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean splitLayout() {
|
||||
for (int i = 0; i < this.rowFormats.length; i++) {
|
||||
if (this.rowFormats[i] > 3)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void addLayoutComponent(Component comp) {}
|
||||
|
||||
public void removeLayoutComponent(Component comp) {}
|
||||
|
||||
public void addLayoutComponent(String name, Component comp) {}
|
||||
|
||||
public void removeLayoutComponent(String name, Component comp) {}
|
||||
}
|
||||
|
|
@ -0,0 +1,130 @@
|
|||
package org.jfree.layout;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Container;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Insets;
|
||||
import java.awt.LayoutManager;
|
||||
import java.io.Serializable;
|
||||
|
||||
public class LCBLayout implements LayoutManager, Serializable {
|
||||
private static final long serialVersionUID = -2531780832406163833L;
|
||||
|
||||
private static final int COLUMNS = 3;
|
||||
|
||||
private int[] colWidth;
|
||||
|
||||
private int[] rowHeight;
|
||||
|
||||
private int labelGap;
|
||||
|
||||
private int buttonGap;
|
||||
|
||||
private int vGap;
|
||||
|
||||
public LCBLayout(int maxrows) {
|
||||
this.labelGap = 10;
|
||||
this.buttonGap = 6;
|
||||
this.vGap = 2;
|
||||
this.colWidth = new int[3];
|
||||
this.rowHeight = new int[maxrows];
|
||||
}
|
||||
|
||||
public Dimension preferredLayoutSize(Container parent) {
|
||||
synchronized (parent.getTreeLock()) {
|
||||
Insets insets = parent.getInsets();
|
||||
int ncomponents = parent.getComponentCount();
|
||||
int nrows = ncomponents / 3;
|
||||
for (int c = 0; c < 3; c++) {
|
||||
for (int i = 0; i < nrows; i++) {
|
||||
Component component = parent.getComponent(i * 3 + c);
|
||||
Dimension d = component.getPreferredSize();
|
||||
if (this.colWidth[c] < d.width)
|
||||
this.colWidth[c] = d.width;
|
||||
if (this.rowHeight[i] < d.height)
|
||||
this.rowHeight[i] = d.height;
|
||||
}
|
||||
}
|
||||
int totalHeight = this.vGap * (nrows - 1);
|
||||
for (int r = 0; r < nrows; r++)
|
||||
totalHeight += this.rowHeight[r];
|
||||
int totalWidth = this.colWidth[0] + this.labelGap + this.colWidth[1] + this.buttonGap + this.colWidth[2];
|
||||
return new Dimension(insets.left + insets.right + totalWidth + this.labelGap + this.buttonGap, insets.top + insets.bottom + totalHeight + this.vGap);
|
||||
}
|
||||
}
|
||||
|
||||
public Dimension minimumLayoutSize(Container parent) {
|
||||
synchronized (parent.getTreeLock()) {
|
||||
Insets insets = parent.getInsets();
|
||||
int ncomponents = parent.getComponentCount();
|
||||
int nrows = ncomponents / 3;
|
||||
for (int c = 0; c < 3; c++) {
|
||||
for (int i = 0; i < nrows; i++) {
|
||||
Component component = parent.getComponent(i * 3 + c);
|
||||
Dimension d = component.getMinimumSize();
|
||||
if (this.colWidth[c] < d.width)
|
||||
this.colWidth[c] = d.width;
|
||||
if (this.rowHeight[i] < d.height)
|
||||
this.rowHeight[i] = d.height;
|
||||
}
|
||||
}
|
||||
int totalHeight = this.vGap * (nrows - 1);
|
||||
for (int r = 0; r < nrows; r++)
|
||||
totalHeight += this.rowHeight[r];
|
||||
int totalWidth = this.colWidth[0] + this.labelGap + this.colWidth[1] + this.buttonGap + this.colWidth[2];
|
||||
return new Dimension(insets.left + insets.right + totalWidth + this.labelGap + this.buttonGap, insets.top + insets.bottom + totalHeight + this.vGap);
|
||||
}
|
||||
}
|
||||
|
||||
public void layoutContainer(Container parent) {
|
||||
synchronized (parent.getTreeLock()) {
|
||||
Insets insets = parent.getInsets();
|
||||
int ncomponents = parent.getComponentCount();
|
||||
int nrows = ncomponents / 3;
|
||||
for (int c = 0; c < 3; c++) {
|
||||
for (int j = 0; j < nrows; j++) {
|
||||
Component component = parent.getComponent(j * 3 + c);
|
||||
Dimension d = component.getPreferredSize();
|
||||
if (this.colWidth[c] < d.width)
|
||||
this.colWidth[c] = d.width;
|
||||
if (this.rowHeight[j] < d.height)
|
||||
this.rowHeight[j] = d.height;
|
||||
}
|
||||
}
|
||||
int totalHeight = this.vGap * (nrows - 1);
|
||||
for (int r = 0; r < nrows; r++)
|
||||
totalHeight += this.rowHeight[r];
|
||||
int totalWidth = this.colWidth[0] + this.colWidth[1] + this.colWidth[2];
|
||||
int available = parent.getWidth() - insets.left - insets.right - this.labelGap - this.buttonGap;
|
||||
this.colWidth[1] = this.colWidth[1] + available - totalWidth;
|
||||
int x = insets.left;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
int y = insets.top;
|
||||
for (int j = 0; j < nrows; j++) {
|
||||
int k = j * 3 + i;
|
||||
if (k < ncomponents) {
|
||||
Component component = parent.getComponent(k);
|
||||
Dimension d = component.getPreferredSize();
|
||||
int h = d.height;
|
||||
int adjust = (this.rowHeight[j] - h) / 2;
|
||||
parent.getComponent(k).setBounds(x, y + adjust, this.colWidth[i], h);
|
||||
}
|
||||
y = y + this.rowHeight[j] + this.vGap;
|
||||
}
|
||||
x += this.colWidth[i];
|
||||
if (i == 0)
|
||||
x += this.labelGap;
|
||||
if (i == 1)
|
||||
x += this.buttonGap;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addLayoutComponent(Component comp) {}
|
||||
|
||||
public void removeLayoutComponent(Component comp) {}
|
||||
|
||||
public void addLayoutComponent(String name, Component comp) {}
|
||||
|
||||
public void removeLayoutComponent(String name, Component comp) {}
|
||||
}
|
||||
|
|
@ -0,0 +1,138 @@
|
|||
package org.jfree.layout;
|
||||
|
||||
import java.awt.Checkbox;
|
||||
import java.awt.Component;
|
||||
import java.awt.Container;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Insets;
|
||||
import java.awt.LayoutManager;
|
||||
import java.awt.Panel;
|
||||
import java.io.Serializable;
|
||||
|
||||
public class RadialLayout implements LayoutManager, Serializable {
|
||||
private static final long serialVersionUID = -7582156799248315534L;
|
||||
|
||||
private int minWidth = 0;
|
||||
|
||||
private int minHeight = 0;
|
||||
|
||||
private int maxCompWidth = 0;
|
||||
|
||||
private int maxCompHeight = 0;
|
||||
|
||||
private int preferredWidth = 0;
|
||||
|
||||
private int preferredHeight = 0;
|
||||
|
||||
private boolean sizeUnknown = true;
|
||||
|
||||
public void addLayoutComponent(Component comp) {}
|
||||
|
||||
public void removeLayoutComponent(Component comp) {}
|
||||
|
||||
public void addLayoutComponent(String name, Component comp) {}
|
||||
|
||||
public void removeLayoutComponent(String name, Component comp) {}
|
||||
|
||||
private void setSizes(Container parent) {
|
||||
int nComps = parent.getComponentCount();
|
||||
this.preferredWidth = 0;
|
||||
this.preferredHeight = 0;
|
||||
this.minWidth = 0;
|
||||
this.minHeight = 0;
|
||||
for (int i = 0; i < nComps; i++) {
|
||||
Component c = parent.getComponent(i);
|
||||
if (c.isVisible()) {
|
||||
Dimension d = c.getPreferredSize();
|
||||
if (this.maxCompWidth < d.width)
|
||||
this.maxCompWidth = d.width;
|
||||
if (this.maxCompHeight < d.height)
|
||||
this.maxCompHeight = d.height;
|
||||
this.preferredWidth += d.width;
|
||||
this.preferredHeight += d.height;
|
||||
}
|
||||
}
|
||||
this.preferredWidth /= 2;
|
||||
this.preferredHeight /= 2;
|
||||
this.minWidth = this.preferredWidth;
|
||||
this.minHeight = this.preferredHeight;
|
||||
}
|
||||
|
||||
public Dimension preferredLayoutSize(Container parent) {
|
||||
Dimension dim = new Dimension(0, 0);
|
||||
setSizes(parent);
|
||||
Insets insets = parent.getInsets();
|
||||
dim.width = this.preferredWidth + insets.left + insets.right;
|
||||
dim.height = this.preferredHeight + insets.top + insets.bottom;
|
||||
this.sizeUnknown = false;
|
||||
return dim;
|
||||
}
|
||||
|
||||
public Dimension minimumLayoutSize(Container parent) {
|
||||
Dimension dim = new Dimension(0, 0);
|
||||
Insets insets = parent.getInsets();
|
||||
dim.width = this.minWidth + insets.left + insets.right;
|
||||
dim.height = this.minHeight + insets.top + insets.bottom;
|
||||
this.sizeUnknown = false;
|
||||
return dim;
|
||||
}
|
||||
|
||||
public void layoutContainer(Container parent) {
|
||||
Insets insets = parent.getInsets();
|
||||
int maxWidth = (parent.getSize()).width - (insets.left + insets.right);
|
||||
int maxHeight = (parent.getSize()).height - (insets.top + insets.bottom);
|
||||
int nComps = parent.getComponentCount();
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
if (this.sizeUnknown)
|
||||
setSizes(parent);
|
||||
if (nComps < 2) {
|
||||
Component c = parent.getComponent(0);
|
||||
if (c.isVisible()) {
|
||||
Dimension d = c.getPreferredSize();
|
||||
c.setBounds(x, y, d.width, d.height);
|
||||
}
|
||||
} else {
|
||||
double radialCurrent = Math.toRadians(90.0D);
|
||||
double radialIncrement = 6.283185307179586D / (double)nComps;
|
||||
int midX = maxWidth / 2;
|
||||
int midY = maxHeight / 2;
|
||||
int a = midX - this.maxCompWidth;
|
||||
int b = midY - this.maxCompHeight;
|
||||
for (int i = 0; i < nComps; i++) {
|
||||
Component c = parent.getComponent(i);
|
||||
if (c.isVisible()) {
|
||||
Dimension d = c.getPreferredSize();
|
||||
x = (int)((double)midX - (double)a * Math.cos(radialCurrent) - d.getWidth() / 2.0D + (double)insets.left);
|
||||
y = (int)((double)midY - (double)b * Math.sin(radialCurrent) - d.getHeight() / 2.0D + (double)insets.top);
|
||||
c.setBounds(x, y, d.width, d.height);
|
||||
}
|
||||
radialCurrent += radialIncrement;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return getClass().getName();
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
Frame frame = new Frame();
|
||||
Panel panel = new Panel();
|
||||
panel.setLayout(new RadialLayout());
|
||||
panel.add(new Checkbox("One"));
|
||||
panel.add(new Checkbox("Two"));
|
||||
panel.add(new Checkbox("Three"));
|
||||
panel.add(new Checkbox("Four"));
|
||||
panel.add(new Checkbox("Five"));
|
||||
panel.add(new Checkbox("One"));
|
||||
panel.add(new Checkbox("Two"));
|
||||
panel.add(new Checkbox("Three"));
|
||||
panel.add(new Checkbox("Four"));
|
||||
panel.add(new Checkbox("Five"));
|
||||
frame.add(panel);
|
||||
frame.setSize(300, 500);
|
||||
frame.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
package org.jfree.resources;
|
||||
|
||||
import java.util.ListResourceBundle;
|
||||
|
||||
public class JCommonResources extends ListResourceBundle {
|
||||
public Object[][] getContents() {
|
||||
return CONTENTS;
|
||||
}
|
||||
|
||||
private static final Object[][] CONTENTS = new Object[][] { new Object[] { "project.name", "JCommon" }, new Object[] { "project.version", "1.0.12" }, new Object[] { "project.info", "http://www.jfree.org/jcommon/" }, new Object[] { "project.copyright", "(C)opyright 2000-2007, by Object Refinery Limited and Contributors" } };
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package org.jfree.text;
|
||||
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
public class G2TextMeasurer implements TextMeasurer {
|
||||
private Graphics2D g2;
|
||||
|
||||
public G2TextMeasurer(Graphics2D g2) {
|
||||
this.g2 = g2;
|
||||
}
|
||||
|
||||
public float getStringWidth(String text, int start, int end) {
|
||||
FontMetrics fm = this.g2.getFontMetrics();
|
||||
Rectangle2D bounds = TextUtilities.getTextBounds(text.substring(start, end), this.g2, fm);
|
||||
float result = (float)bounds.getWidth();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
133
rus/WEB-INF/lib/jcommon-1.0.12_src/org/jfree/text/TextBlock.java
Normal file
133
rus/WEB-INF/lib/jcommon-1.0.12_src/org/jfree/text/TextBlock.java
Normal file
|
|
@ -0,0 +1,133 @@
|
|||
package org.jfree.text;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Paint;
|
||||
import java.awt.Shape;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import org.jfree.ui.HorizontalAlignment;
|
||||
import org.jfree.ui.Size2D;
|
||||
import org.jfree.ui.TextAnchor;
|
||||
import org.jfree.util.ShapeUtilities;
|
||||
|
||||
public class TextBlock implements Serializable {
|
||||
private static final long serialVersionUID = -4333175719424385526L;
|
||||
|
||||
private List lines = new ArrayList();
|
||||
|
||||
private HorizontalAlignment lineAlignment = HorizontalAlignment.CENTER;
|
||||
|
||||
public HorizontalAlignment getLineAlignment() {
|
||||
return this.lineAlignment;
|
||||
}
|
||||
|
||||
public void setLineAlignment(HorizontalAlignment alignment) {
|
||||
if (alignment == null)
|
||||
throw new IllegalArgumentException("Null 'alignment' argument.");
|
||||
this.lineAlignment = alignment;
|
||||
}
|
||||
|
||||
public void addLine(String text, Font font, Paint paint) {
|
||||
addLine(new TextLine(text, font, paint));
|
||||
}
|
||||
|
||||
public void addLine(TextLine line) {
|
||||
this.lines.add(line);
|
||||
}
|
||||
|
||||
public TextLine getLastLine() {
|
||||
TextLine last = null;
|
||||
int index = this.lines.size() - 1;
|
||||
if (index >= 0)
|
||||
last = (TextLine)this.lines.get(index);
|
||||
return last;
|
||||
}
|
||||
|
||||
public List getLines() {
|
||||
return Collections.unmodifiableList(this.lines);
|
||||
}
|
||||
|
||||
public Size2D calculateDimensions(Graphics2D g2) {
|
||||
double width = 0.0D;
|
||||
double height = 0.0D;
|
||||
Iterator iterator = this.lines.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
TextLine line = (TextLine)iterator.next();
|
||||
Size2D dimension = line.calculateDimensions(g2);
|
||||
width = Math.max(width, dimension.getWidth());
|
||||
height += dimension.getHeight();
|
||||
}
|
||||
return new Size2D(width, height);
|
||||
}
|
||||
|
||||
public Shape calculateBounds(Graphics2D g2, float anchorX, float anchorY, TextBlockAnchor anchor, float rotateX, float rotateY, double angle) {
|
||||
Size2D d = calculateDimensions(g2);
|
||||
float[] offsets = calculateOffsets(anchor, d.getWidth(), d.getHeight());
|
||||
Rectangle2D bounds = new Rectangle2D.Double((double)(anchorX + offsets[0]), (double)(anchorY + offsets[1]), d.getWidth(), d.getHeight());
|
||||
Shape rotatedBounds = ShapeUtilities.rotateShape(bounds, angle, rotateX, rotateY);
|
||||
return rotatedBounds;
|
||||
}
|
||||
|
||||
public void draw(Graphics2D g2, float x, float y, TextBlockAnchor anchor) {
|
||||
draw(g2, x, y, anchor, 0.0F, 0.0F, 0.0D);
|
||||
}
|
||||
|
||||
public void draw(Graphics2D g2, float anchorX, float anchorY, TextBlockAnchor anchor, float rotateX, float rotateY, double angle) {
|
||||
Size2D d = calculateDimensions(g2);
|
||||
float[] offsets = calculateOffsets(anchor, d.getWidth(), d.getHeight());
|
||||
Iterator iterator = this.lines.iterator();
|
||||
float yCursor = 0.0F;
|
||||
while (iterator.hasNext()) {
|
||||
TextLine line = (TextLine)iterator.next();
|
||||
Size2D dimension = line.calculateDimensions(g2);
|
||||
float lineOffset = 0.0F;
|
||||
if (this.lineAlignment == HorizontalAlignment.CENTER) {
|
||||
lineOffset = (float)(d.getWidth() - dimension.getWidth()) / 2.0F;
|
||||
} else if (this.lineAlignment == HorizontalAlignment.RIGHT) {
|
||||
lineOffset = (float)(d.getWidth() - dimension.getWidth());
|
||||
}
|
||||
line.draw(g2, anchorX + offsets[0] + lineOffset, anchorY + offsets[1] + yCursor, TextAnchor.TOP_LEFT, rotateX, rotateY, angle);
|
||||
yCursor += (float)dimension.getHeight();
|
||||
}
|
||||
}
|
||||
|
||||
private float[] calculateOffsets(TextBlockAnchor anchor, double width, double height) {
|
||||
float[] result = new float[2];
|
||||
float xAdj = 0.0F;
|
||||
float yAdj = 0.0F;
|
||||
if (anchor == TextBlockAnchor.TOP_CENTER || anchor == TextBlockAnchor.CENTER || anchor == TextBlockAnchor.BOTTOM_CENTER) {
|
||||
xAdj = (float)-width / 2.0F;
|
||||
} else if (anchor == TextBlockAnchor.TOP_RIGHT || anchor == TextBlockAnchor.CENTER_RIGHT || anchor == TextBlockAnchor.BOTTOM_RIGHT) {
|
||||
xAdj = (float)-width;
|
||||
}
|
||||
if (anchor == TextBlockAnchor.TOP_LEFT || anchor == TextBlockAnchor.TOP_CENTER || anchor == TextBlockAnchor.TOP_RIGHT) {
|
||||
yAdj = 0.0F;
|
||||
} else if (anchor == TextBlockAnchor.CENTER_LEFT || anchor == TextBlockAnchor.CENTER || anchor == TextBlockAnchor.CENTER_RIGHT) {
|
||||
yAdj = (float)-height / 2.0F;
|
||||
} else if (anchor == TextBlockAnchor.BOTTOM_LEFT || anchor == TextBlockAnchor.BOTTOM_CENTER || anchor == TextBlockAnchor.BOTTOM_RIGHT) {
|
||||
yAdj = (float)-height;
|
||||
}
|
||||
result[0] = xAdj;
|
||||
result[1] = yAdj;
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == this)
|
||||
return true;
|
||||
if (obj instanceof TextBlock) {
|
||||
TextBlock block = (TextBlock)obj;
|
||||
return this.lines.equals(block.lines);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return (this.lines != null) ? this.lines.hashCode() : 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
package org.jfree.text;
|
||||
|
||||
import java.io.ObjectStreamException;
|
||||
import java.io.Serializable;
|
||||
|
||||
public final class TextBlockAnchor implements Serializable {
|
||||
private static final long serialVersionUID = -3045058380983401544L;
|
||||
|
||||
public static final TextBlockAnchor TOP_LEFT = new TextBlockAnchor("TextBlockAnchor.TOP_LEFT");
|
||||
|
||||
public static final TextBlockAnchor TOP_CENTER = new TextBlockAnchor("TextBlockAnchor.TOP_CENTER");
|
||||
|
||||
public static final TextBlockAnchor TOP_RIGHT = new TextBlockAnchor("TextBlockAnchor.TOP_RIGHT");
|
||||
|
||||
public static final TextBlockAnchor CENTER_LEFT = new TextBlockAnchor("TextBlockAnchor.CENTER_LEFT");
|
||||
|
||||
public static final TextBlockAnchor CENTER = new TextBlockAnchor("TextBlockAnchor.CENTER");
|
||||
|
||||
public static final TextBlockAnchor CENTER_RIGHT = new TextBlockAnchor("TextBlockAnchor.CENTER_RIGHT");
|
||||
|
||||
public static final TextBlockAnchor BOTTOM_LEFT = new TextBlockAnchor("TextBlockAnchor.BOTTOM_LEFT");
|
||||
|
||||
public static final TextBlockAnchor BOTTOM_CENTER = new TextBlockAnchor("TextBlockAnchor.BOTTOM_CENTER");
|
||||
|
||||
public static final TextBlockAnchor BOTTOM_RIGHT = new TextBlockAnchor("TextBlockAnchor.BOTTOM_RIGHT");
|
||||
|
||||
private String name;
|
||||
|
||||
private TextBlockAnchor(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
return true;
|
||||
if (!(o instanceof TextBlockAnchor))
|
||||
return false;
|
||||
TextBlockAnchor other = (TextBlockAnchor)o;
|
||||
if (!this.name.equals(other.name))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return this.name.hashCode();
|
||||
}
|
||||
|
||||
private Object readResolve() throws ObjectStreamException {
|
||||
if (equals(TOP_CENTER))
|
||||
return TOP_CENTER;
|
||||
if (equals(TOP_LEFT))
|
||||
return TOP_LEFT;
|
||||
if (equals(TOP_RIGHT))
|
||||
return TOP_RIGHT;
|
||||
if (equals(CENTER))
|
||||
return CENTER;
|
||||
if (equals(CENTER_LEFT))
|
||||
return CENTER_LEFT;
|
||||
if (equals(CENTER_RIGHT))
|
||||
return CENTER_RIGHT;
|
||||
if (equals(BOTTOM_CENTER))
|
||||
return BOTTOM_CENTER;
|
||||
if (equals(BOTTOM_LEFT))
|
||||
return BOTTOM_LEFT;
|
||||
if (equals(BOTTOM_RIGHT))
|
||||
return BOTTOM_RIGHT;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
208
rus/WEB-INF/lib/jcommon-1.0.12_src/org/jfree/text/TextBox.java
Normal file
208
rus/WEB-INF/lib/jcommon-1.0.12_src/org/jfree/text/TextBox.java
Normal file
|
|
@ -0,0 +1,208 @@
|
|||
package org.jfree.text;
|
||||
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Paint;
|
||||
import java.awt.Stroke;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
import org.jfree.io.SerialUtilities;
|
||||
import org.jfree.ui.RectangleAnchor;
|
||||
import org.jfree.ui.RectangleInsets;
|
||||
import org.jfree.ui.Size2D;
|
||||
import org.jfree.util.ObjectUtilities;
|
||||
|
||||
public class TextBox implements Serializable {
|
||||
private static final long serialVersionUID = 3360220213180203706L;
|
||||
|
||||
private transient Paint outlinePaint;
|
||||
|
||||
private transient Stroke outlineStroke;
|
||||
|
||||
private RectangleInsets interiorGap;
|
||||
|
||||
private transient Paint backgroundPaint;
|
||||
|
||||
private transient Paint shadowPaint;
|
||||
|
||||
private double shadowXOffset = 2.0D;
|
||||
|
||||
private double shadowYOffset = 2.0D;
|
||||
|
||||
private TextBlock textBlock;
|
||||
|
||||
public TextBox() {
|
||||
this((TextBlock)null);
|
||||
}
|
||||
|
||||
public TextBox(String text) {
|
||||
this((TextBlock)null);
|
||||
if (text != null) {
|
||||
this.textBlock = new TextBlock();
|
||||
this.textBlock.addLine(text, new Font("SansSerif", 0, 10), Color.black);
|
||||
}
|
||||
}
|
||||
|
||||
public TextBox(TextBlock block) {
|
||||
this.outlinePaint = Color.black;
|
||||
this.outlineStroke = new BasicStroke(1.0F);
|
||||
this.interiorGap = new RectangleInsets(1.0D, 3.0D, 1.0D, 3.0D);
|
||||
this.backgroundPaint = new Color(255, 255, 192);
|
||||
this.shadowPaint = Color.gray;
|
||||
this.shadowXOffset = 2.0D;
|
||||
this.shadowYOffset = 2.0D;
|
||||
this.textBlock = block;
|
||||
}
|
||||
|
||||
public Paint getOutlinePaint() {
|
||||
return this.outlinePaint;
|
||||
}
|
||||
|
||||
public void setOutlinePaint(Paint paint) {
|
||||
this.outlinePaint = paint;
|
||||
}
|
||||
|
||||
public Stroke getOutlineStroke() {
|
||||
return this.outlineStroke;
|
||||
}
|
||||
|
||||
public void setOutlineStroke(Stroke stroke) {
|
||||
this.outlineStroke = stroke;
|
||||
}
|
||||
|
||||
public RectangleInsets getInteriorGap() {
|
||||
return this.interiorGap;
|
||||
}
|
||||
|
||||
public void setInteriorGap(RectangleInsets gap) {
|
||||
this.interiorGap = gap;
|
||||
}
|
||||
|
||||
public Paint getBackgroundPaint() {
|
||||
return this.backgroundPaint;
|
||||
}
|
||||
|
||||
public void setBackgroundPaint(Paint paint) {
|
||||
this.backgroundPaint = paint;
|
||||
}
|
||||
|
||||
public Paint getShadowPaint() {
|
||||
return this.shadowPaint;
|
||||
}
|
||||
|
||||
public void setShadowPaint(Paint paint) {
|
||||
this.shadowPaint = paint;
|
||||
}
|
||||
|
||||
public double getShadowXOffset() {
|
||||
return this.shadowXOffset;
|
||||
}
|
||||
|
||||
public void setShadowXOffset(double offset) {
|
||||
this.shadowXOffset = offset;
|
||||
}
|
||||
|
||||
public double getShadowYOffset() {
|
||||
return this.shadowYOffset;
|
||||
}
|
||||
|
||||
public void setShadowYOffset(double offset) {
|
||||
this.shadowYOffset = offset;
|
||||
}
|
||||
|
||||
public TextBlock getTextBlock() {
|
||||
return this.textBlock;
|
||||
}
|
||||
|
||||
public void setTextBlock(TextBlock block) {
|
||||
this.textBlock = block;
|
||||
}
|
||||
|
||||
public void draw(Graphics2D g2, float x, float y, RectangleAnchor anchor) {
|
||||
Size2D d1 = this.textBlock.calculateDimensions(g2);
|
||||
double w = this.interiorGap.extendWidth(d1.getWidth());
|
||||
double h = this.interiorGap.extendHeight(d1.getHeight());
|
||||
Size2D d2 = new Size2D(w, h);
|
||||
Rectangle2D bounds = RectangleAnchor.createRectangle(d2, (double)x, (double)y, anchor);
|
||||
if (this.shadowPaint != null) {
|
||||
Rectangle2D shadow = new Rectangle2D.Double(bounds.getX() + this.shadowXOffset, bounds.getY() + this.shadowYOffset, bounds.getWidth(), bounds.getHeight());
|
||||
g2.setPaint(this.shadowPaint);
|
||||
g2.fill(shadow);
|
||||
}
|
||||
if (this.backgroundPaint != null) {
|
||||
g2.setPaint(this.backgroundPaint);
|
||||
g2.fill(bounds);
|
||||
}
|
||||
if (this.outlinePaint != null && this.outlineStroke != null) {
|
||||
g2.setPaint(this.outlinePaint);
|
||||
g2.setStroke(this.outlineStroke);
|
||||
g2.draw(bounds);
|
||||
}
|
||||
this.textBlock.draw(g2, (float)bounds.getCenterX(), (float)bounds.getCenterY(), TextBlockAnchor.CENTER);
|
||||
}
|
||||
|
||||
public double getHeight(Graphics2D g2) {
|
||||
Size2D d = this.textBlock.calculateDimensions(g2);
|
||||
return this.interiorGap.extendHeight(d.getHeight());
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == this)
|
||||
return true;
|
||||
if (!(obj instanceof TextBox))
|
||||
return false;
|
||||
TextBox that = (TextBox)obj;
|
||||
if (!ObjectUtilities.equal(this.outlinePaint, that.outlinePaint))
|
||||
return false;
|
||||
if (!ObjectUtilities.equal(this.outlineStroke, that.outlineStroke))
|
||||
return false;
|
||||
if (!ObjectUtilities.equal(this.interiorGap, that.interiorGap))
|
||||
return false;
|
||||
if (!ObjectUtilities.equal(this.backgroundPaint, that.backgroundPaint))
|
||||
return false;
|
||||
if (!ObjectUtilities.equal(this.shadowPaint, that.shadowPaint))
|
||||
return false;
|
||||
if (this.shadowXOffset != that.shadowXOffset)
|
||||
return false;
|
||||
if (this.shadowYOffset != that.shadowYOffset)
|
||||
return false;
|
||||
if (!ObjectUtilities.equal(this.textBlock, that.textBlock))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int result = (this.outlinePaint != null) ? this.outlinePaint.hashCode() : 0;
|
||||
result = 29 * result + ((this.outlineStroke != null) ? this.outlineStroke.hashCode() : 0);
|
||||
result = 29 * result + ((this.interiorGap != null) ? this.interiorGap.hashCode() : 0);
|
||||
result = 29 * result + ((this.backgroundPaint != null) ? this.backgroundPaint.hashCode() : 0);
|
||||
result = 29 * result + ((this.shadowPaint != null) ? this.shadowPaint.hashCode() : 0);
|
||||
long temp = (this.shadowXOffset != 0.0D) ? Double.doubleToLongBits(this.shadowXOffset) : 0L;
|
||||
result = 29 * result + (int)(temp ^ temp >>> 32L);
|
||||
temp = (this.shadowYOffset != 0.0D) ? Double.doubleToLongBits(this.shadowYOffset) : 0L;
|
||||
result = 29 * result + (int)(temp ^ temp >>> 32L);
|
||||
result = 29 * result + ((this.textBlock != null) ? this.textBlock.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
private void writeObject(ObjectOutputStream stream) throws IOException {
|
||||
stream.defaultWriteObject();
|
||||
SerialUtilities.writePaint(this.outlinePaint, stream);
|
||||
SerialUtilities.writeStroke(this.outlineStroke, stream);
|
||||
SerialUtilities.writePaint(this.backgroundPaint, stream);
|
||||
SerialUtilities.writePaint(this.shadowPaint, stream);
|
||||
}
|
||||
|
||||
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
|
||||
stream.defaultReadObject();
|
||||
this.outlinePaint = SerialUtilities.readPaint(stream);
|
||||
this.outlineStroke = SerialUtilities.readStroke(stream);
|
||||
this.backgroundPaint = SerialUtilities.readPaint(stream);
|
||||
this.shadowPaint = SerialUtilities.readPaint(stream);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,137 @@
|
|||
package org.jfree.text;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Paint;
|
||||
import java.awt.font.LineMetrics;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
import org.jfree.io.SerialUtilities;
|
||||
import org.jfree.ui.Size2D;
|
||||
import org.jfree.ui.TextAnchor;
|
||||
import org.jfree.util.Log;
|
||||
import org.jfree.util.LogContext;
|
||||
|
||||
public class TextFragment implements Serializable {
|
||||
private static final long serialVersionUID = 4465945952903143262L;
|
||||
|
||||
public static final Font DEFAULT_FONT = new Font("Serif", 0, 12);
|
||||
|
||||
public static final Paint DEFAULT_PAINT = Color.black;
|
||||
|
||||
private String text;
|
||||
|
||||
private Font font;
|
||||
|
||||
private transient Paint paint;
|
||||
|
||||
private float baselineOffset;
|
||||
|
||||
protected static final LogContext logger = Log.createContext(TextFragment.class);
|
||||
|
||||
public TextFragment(String text) {
|
||||
this(text, DEFAULT_FONT, DEFAULT_PAINT);
|
||||
}
|
||||
|
||||
public TextFragment(String text, Font font) {
|
||||
this(text, font, DEFAULT_PAINT);
|
||||
}
|
||||
|
||||
public TextFragment(String text, Font font, Paint paint) {
|
||||
this(text, font, paint, 0.0F);
|
||||
}
|
||||
|
||||
public TextFragment(String text, Font font, Paint paint, float baselineOffset) {
|
||||
if (text == null)
|
||||
throw new IllegalArgumentException("Null 'text' argument.");
|
||||
if (font == null)
|
||||
throw new IllegalArgumentException("Null 'font' argument.");
|
||||
if (paint == null)
|
||||
throw new IllegalArgumentException("Null 'paint' argument.");
|
||||
this.text = text;
|
||||
this.font = font;
|
||||
this.paint = paint;
|
||||
this.baselineOffset = baselineOffset;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return this.text;
|
||||
}
|
||||
|
||||
public Font getFont() {
|
||||
return this.font;
|
||||
}
|
||||
|
||||
public Paint getPaint() {
|
||||
return this.paint;
|
||||
}
|
||||
|
||||
public float getBaselineOffset() {
|
||||
return this.baselineOffset;
|
||||
}
|
||||
|
||||
public void draw(Graphics2D g2, float anchorX, float anchorY, TextAnchor anchor, float rotateX, float rotateY, double angle) {
|
||||
g2.setFont(this.font);
|
||||
g2.setPaint(this.paint);
|
||||
TextUtilities.drawRotatedString(this.text, g2, anchorX, anchorY + this.baselineOffset, anchor, angle, rotateX, rotateY);
|
||||
}
|
||||
|
||||
public Size2D calculateDimensions(Graphics2D g2) {
|
||||
FontMetrics fm = g2.getFontMetrics(this.font);
|
||||
Rectangle2D bounds = TextUtilities.getTextBounds(this.text, g2, fm);
|
||||
Size2D result = new Size2D(bounds.getWidth(), bounds.getHeight());
|
||||
return result;
|
||||
}
|
||||
|
||||
public float calculateBaselineOffset(Graphics2D g2, TextAnchor anchor) {
|
||||
float result = 0.0F;
|
||||
FontMetrics fm = g2.getFontMetrics(this.font);
|
||||
LineMetrics lm = fm.getLineMetrics("ABCxyz", g2);
|
||||
if (anchor == TextAnchor.TOP_LEFT || anchor == TextAnchor.TOP_CENTER || anchor == TextAnchor.TOP_RIGHT) {
|
||||
result = lm.getAscent();
|
||||
} else if (anchor == TextAnchor.BOTTOM_LEFT || anchor == TextAnchor.BOTTOM_CENTER || anchor == TextAnchor.BOTTOM_RIGHT) {
|
||||
result = -lm.getDescent() - lm.getLeading();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (obj == this)
|
||||
return true;
|
||||
if (obj instanceof TextFragment) {
|
||||
TextFragment tf = (TextFragment)obj;
|
||||
if (!this.text.equals(tf.text))
|
||||
return false;
|
||||
if (!this.font.equals(tf.font))
|
||||
return false;
|
||||
if (!this.paint.equals(tf.paint))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int result = (this.text != null) ? this.text.hashCode() : 0;
|
||||
result = 29 * result + ((this.font != null) ? this.font.hashCode() : 0);
|
||||
result = 29 * result + ((this.paint != null) ? this.paint.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
private void writeObject(ObjectOutputStream stream) throws IOException {
|
||||
stream.defaultWriteObject();
|
||||
SerialUtilities.writePaint(this.paint, stream);
|
||||
}
|
||||
|
||||
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
|
||||
stream.defaultReadObject();
|
||||
this.paint = SerialUtilities.readPaint(stream);
|
||||
}
|
||||
}
|
||||
116
rus/WEB-INF/lib/jcommon-1.0.12_src/org/jfree/text/TextLine.java
Normal file
116
rus/WEB-INF/lib/jcommon-1.0.12_src/org/jfree/text/TextLine.java
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
package org.jfree.text;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Paint;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import org.jfree.ui.Size2D;
|
||||
import org.jfree.ui.TextAnchor;
|
||||
|
||||
public class TextLine implements Serializable {
|
||||
private static final long serialVersionUID = 7100085690160465444L;
|
||||
|
||||
private List fragments;
|
||||
|
||||
public TextLine() {
|
||||
this.fragments = new ArrayList();
|
||||
}
|
||||
|
||||
public TextLine(String text) {
|
||||
this(text, TextFragment.DEFAULT_FONT);
|
||||
}
|
||||
|
||||
public TextLine(String text, Font font) {
|
||||
this.fragments = new ArrayList();
|
||||
TextFragment fragment = new TextFragment(text, font);
|
||||
this.fragments.add(fragment);
|
||||
}
|
||||
|
||||
public TextLine(String text, Font font, Paint paint) {
|
||||
if (text == null)
|
||||
throw new IllegalArgumentException("Null 'text' argument.");
|
||||
if (font == null)
|
||||
throw new IllegalArgumentException("Null 'font' argument.");
|
||||
if (paint == null)
|
||||
throw new IllegalArgumentException("Null 'paint' argument.");
|
||||
this.fragments = new ArrayList();
|
||||
TextFragment fragment = new TextFragment(text, font, paint);
|
||||
this.fragments.add(fragment);
|
||||
}
|
||||
|
||||
public void addFragment(TextFragment fragment) {
|
||||
this.fragments.add(fragment);
|
||||
}
|
||||
|
||||
public void removeFragment(TextFragment fragment) {
|
||||
this.fragments.remove(fragment);
|
||||
}
|
||||
|
||||
public void draw(Graphics2D g2, float anchorX, float anchorY, TextAnchor anchor, float rotateX, float rotateY, double angle) {
|
||||
float x = anchorX;
|
||||
float yOffset = calculateBaselineOffset(g2, anchor);
|
||||
Iterator iterator = this.fragments.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
TextFragment fragment = (TextFragment)iterator.next();
|
||||
Size2D d = fragment.calculateDimensions(g2);
|
||||
fragment.draw(g2, x, anchorY + yOffset, TextAnchor.BASELINE_LEFT, rotateX, rotateY, angle);
|
||||
x += (float)d.getWidth();
|
||||
}
|
||||
}
|
||||
|
||||
public Size2D calculateDimensions(Graphics2D g2) {
|
||||
double width = 0.0D;
|
||||
double height = 0.0D;
|
||||
Iterator iterator = this.fragments.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
TextFragment fragment = (TextFragment)iterator.next();
|
||||
Size2D dimension = fragment.calculateDimensions(g2);
|
||||
width += dimension.getWidth();
|
||||
height = Math.max(height, dimension.getHeight());
|
||||
}
|
||||
return new Size2D(width, height);
|
||||
}
|
||||
|
||||
public TextFragment getFirstTextFragment() {
|
||||
TextFragment result = null;
|
||||
if (this.fragments.size() > 0)
|
||||
result = (TextFragment)this.fragments.get(0);
|
||||
return result;
|
||||
}
|
||||
|
||||
public TextFragment getLastTextFragment() {
|
||||
TextFragment result = null;
|
||||
if (this.fragments.size() > 0)
|
||||
result = (TextFragment)this.fragments.get(this.fragments.size() - 1);
|
||||
return result;
|
||||
}
|
||||
|
||||
private float calculateBaselineOffset(Graphics2D g2, TextAnchor anchor) {
|
||||
float result = 0.0F;
|
||||
Iterator iterator = this.fragments.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
TextFragment fragment = (TextFragment)iterator.next();
|
||||
result = Math.max(result, fragment.calculateBaselineOffset(g2, anchor));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (obj == this)
|
||||
return true;
|
||||
if (obj instanceof TextLine) {
|
||||
TextLine line = (TextLine)obj;
|
||||
return this.fragments.equals(line.fragments);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return (this.fragments != null) ? this.fragments.hashCode() : 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
package org.jfree.text;
|
||||
|
||||
public interface TextMeasurer {
|
||||
float getStringWidth(String paramString, int paramInt1, int paramInt2);
|
||||
}
|
||||
|
|
@ -0,0 +1,347 @@
|
|||
package org.jfree.text;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Paint;
|
||||
import java.awt.Shape;
|
||||
import java.awt.font.FontRenderContext;
|
||||
import java.awt.font.LineMetrics;
|
||||
import java.awt.font.TextLayout;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.text.BreakIterator;
|
||||
import org.jfree.base.BaseBoot;
|
||||
import org.jfree.ui.TextAnchor;
|
||||
import org.jfree.util.Log;
|
||||
import org.jfree.util.LogContext;
|
||||
import org.jfree.util.ObjectUtilities;
|
||||
|
||||
public class TextUtilities {
|
||||
protected static final LogContext logger = Log.createContext(TextUtilities.class);
|
||||
|
||||
private static boolean useDrawRotatedStringWorkaround;
|
||||
|
||||
private static boolean useFontMetricsGetStringBounds;
|
||||
|
||||
static {
|
||||
boolean isJava14 = ObjectUtilities.isJDK14();
|
||||
String configRotatedStringWorkaround = BaseBoot.getInstance().getGlobalConfig().getConfigProperty("org.jfree.text.UseDrawRotatedStringWorkaround", "auto");
|
||||
if (configRotatedStringWorkaround.equals("auto")) {
|
||||
useDrawRotatedStringWorkaround = !isJava14;
|
||||
} else {
|
||||
useDrawRotatedStringWorkaround = configRotatedStringWorkaround.equals("true");
|
||||
}
|
||||
String configFontMetricsStringBounds = BaseBoot.getInstance().getGlobalConfig().getConfigProperty("org.jfree.text.UseFontMetricsGetStringBounds", "auto");
|
||||
if (configFontMetricsStringBounds.equals("auto")) {
|
||||
useFontMetricsGetStringBounds = (isJava14 == true);
|
||||
} else {
|
||||
useFontMetricsGetStringBounds = configFontMetricsStringBounds.equals("true");
|
||||
}
|
||||
}
|
||||
|
||||
public static TextBlock createTextBlock(String text, Font font, Paint paint) {
|
||||
if (text == null)
|
||||
throw new IllegalArgumentException("Null 'text' argument.");
|
||||
TextBlock result = new TextBlock();
|
||||
String input = text;
|
||||
boolean moreInputToProcess = (text.length() > 0);
|
||||
int start = 0;
|
||||
while (moreInputToProcess) {
|
||||
int index = input.indexOf("\n");
|
||||
if (index > 0) {
|
||||
String line = input.substring(0, index);
|
||||
if (index < input.length() - 1) {
|
||||
result.addLine(line, font, paint);
|
||||
input = input.substring(index + 1);
|
||||
continue;
|
||||
}
|
||||
moreInputToProcess = false;
|
||||
continue;
|
||||
}
|
||||
if (index == 0) {
|
||||
if (index < input.length() - 1) {
|
||||
input = input.substring(index + 1);
|
||||
continue;
|
||||
}
|
||||
moreInputToProcess = false;
|
||||
continue;
|
||||
}
|
||||
result.addLine(input, font, paint);
|
||||
moreInputToProcess = false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static TextBlock createTextBlock(String text, Font font, Paint paint, float maxWidth, TextMeasurer measurer) {
|
||||
return createTextBlock(text, font, paint, maxWidth, Integer.MAX_VALUE, measurer);
|
||||
}
|
||||
|
||||
public static TextBlock createTextBlock(String text, Font font, Paint paint, float maxWidth, int maxLines, TextMeasurer measurer) {
|
||||
TextBlock result = new TextBlock();
|
||||
BreakIterator iterator = BreakIterator.getLineInstance();
|
||||
iterator.setText(text);
|
||||
int current = 0;
|
||||
int lines = 0;
|
||||
int length = text.length();
|
||||
while (current < length && lines < maxLines) {
|
||||
int next = nextLineBreak(text, current, maxWidth, iterator, measurer);
|
||||
if (next == -1) {
|
||||
result.addLine(text.substring(current), font, paint);
|
||||
return result;
|
||||
}
|
||||
result.addLine(text.substring(current, next), font, paint);
|
||||
lines++;
|
||||
current = next;
|
||||
while (current < text.length() && text.charAt(current) == '\n')
|
||||
current++;
|
||||
}
|
||||
if (current < length) {
|
||||
TextLine lastLine = result.getLastLine();
|
||||
TextFragment lastFragment = lastLine.getLastTextFragment();
|
||||
String oldStr = lastFragment.getText();
|
||||
String newStr = "...";
|
||||
if (oldStr.length() > 3)
|
||||
newStr = oldStr.substring(0, oldStr.length() - 3) + "...";
|
||||
lastLine.removeFragment(lastFragment);
|
||||
TextFragment newFragment = new TextFragment(newStr, lastFragment.getFont(), lastFragment.getPaint());
|
||||
lastLine.addFragment(newFragment);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static int nextLineBreak(String text, int start, float width, BreakIterator iterator, TextMeasurer measurer) {
|
||||
int current = start;
|
||||
float x = 0.0F;
|
||||
boolean firstWord = true;
|
||||
int newline = text.indexOf('\n', start);
|
||||
if (newline < 0)
|
||||
newline = Integer.MAX_VALUE;
|
||||
int end;
|
||||
while ((end = iterator.next()) != -1) {
|
||||
if (end > newline)
|
||||
return newline;
|
||||
x += measurer.getStringWidth(text, current, end);
|
||||
if (x > width) {
|
||||
if (firstWord) {
|
||||
while (measurer.getStringWidth(text, start, end) > width) {
|
||||
end--;
|
||||
if (end <= start)
|
||||
return end;
|
||||
}
|
||||
return end;
|
||||
}
|
||||
end = iterator.previous();
|
||||
return end;
|
||||
}
|
||||
firstWord = false;
|
||||
current = end;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static Rectangle2D getTextBounds(String text, Graphics2D g2, FontMetrics fm) {
|
||||
Rectangle2D bounds;
|
||||
if (useFontMetricsGetStringBounds) {
|
||||
bounds = fm.getStringBounds(text, g2);
|
||||
LineMetrics lm = fm.getFont().getLineMetrics(text, g2.getFontRenderContext());
|
||||
bounds.setRect(bounds.getX(), bounds.getY(), bounds.getWidth(), (double)lm.getHeight());
|
||||
} else {
|
||||
double width = (double)fm.stringWidth(text);
|
||||
double height = (double)fm.getHeight();
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Height = " + height);
|
||||
bounds = new Rectangle2D.Double(0.0D, (double)-fm.getAscent(), width, height);
|
||||
}
|
||||
return bounds;
|
||||
}
|
||||
|
||||
public static Rectangle2D drawAlignedString(String text, Graphics2D g2, float x, float y, TextAnchor anchor) {
|
||||
Rectangle2D textBounds = new Rectangle2D.Double();
|
||||
float[] adjust = deriveTextBoundsAnchorOffsets(g2, text, anchor, textBounds);
|
||||
textBounds.setRect((double)(x + adjust[0]), (double)(y + adjust[1] + adjust[2]), textBounds.getWidth(), textBounds.getHeight());
|
||||
g2.drawString(text, x + adjust[0], y + adjust[1]);
|
||||
return textBounds;
|
||||
}
|
||||
|
||||
private static float[] deriveTextBoundsAnchorOffsets(Graphics2D g2, String text, TextAnchor anchor, Rectangle2D textBounds) {
|
||||
float[] result = new float[3];
|
||||
FontRenderContext frc = g2.getFontRenderContext();
|
||||
Font f = g2.getFont();
|
||||
FontMetrics fm = g2.getFontMetrics(f);
|
||||
Rectangle2D bounds = getTextBounds(text, g2, fm);
|
||||
LineMetrics metrics = f.getLineMetrics(text, frc);
|
||||
float ascent = metrics.getAscent();
|
||||
result[2] = -ascent;
|
||||
float halfAscent = ascent / 2.0F;
|
||||
float descent = metrics.getDescent();
|
||||
float leading = metrics.getLeading();
|
||||
float xAdj = 0.0F;
|
||||
float yAdj = 0.0F;
|
||||
if (anchor == TextAnchor.TOP_CENTER || anchor == TextAnchor.CENTER || anchor == TextAnchor.BOTTOM_CENTER || anchor == TextAnchor.BASELINE_CENTER || anchor == TextAnchor.HALF_ASCENT_CENTER) {
|
||||
xAdj = (float)-bounds.getWidth() / 2.0F;
|
||||
} else if (anchor == TextAnchor.TOP_RIGHT || anchor == TextAnchor.CENTER_RIGHT || anchor == TextAnchor.BOTTOM_RIGHT || anchor == TextAnchor.BASELINE_RIGHT || anchor == TextAnchor.HALF_ASCENT_RIGHT) {
|
||||
xAdj = (float)-bounds.getWidth();
|
||||
}
|
||||
if (anchor == TextAnchor.TOP_LEFT || anchor == TextAnchor.TOP_CENTER || anchor == TextAnchor.TOP_RIGHT) {
|
||||
yAdj = -descent - leading + (float)bounds.getHeight();
|
||||
} else if (anchor == TextAnchor.HALF_ASCENT_LEFT || anchor == TextAnchor.HALF_ASCENT_CENTER || anchor == TextAnchor.HALF_ASCENT_RIGHT) {
|
||||
yAdj = halfAscent;
|
||||
} else if (anchor == TextAnchor.CENTER_LEFT || anchor == TextAnchor.CENTER || anchor == TextAnchor.CENTER_RIGHT) {
|
||||
yAdj = -descent - leading + (float)(bounds.getHeight() / 2.0D);
|
||||
} else if (anchor == TextAnchor.BASELINE_LEFT || anchor == TextAnchor.BASELINE_CENTER || anchor == TextAnchor.BASELINE_RIGHT) {
|
||||
yAdj = 0.0F;
|
||||
} else if (anchor == TextAnchor.BOTTOM_LEFT || anchor == TextAnchor.BOTTOM_CENTER || anchor == TextAnchor.BOTTOM_RIGHT) {
|
||||
yAdj = -metrics.getDescent() - metrics.getLeading();
|
||||
}
|
||||
if (textBounds != null)
|
||||
textBounds.setRect(bounds);
|
||||
result[0] = xAdj;
|
||||
result[1] = yAdj;
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void setUseDrawRotatedStringWorkaround(boolean use) {
|
||||
useDrawRotatedStringWorkaround = use;
|
||||
}
|
||||
|
||||
public static void drawRotatedString(String text, Graphics2D g2, double angle, float x, float y) {
|
||||
drawRotatedString(text, g2, x, y, angle, x, y);
|
||||
}
|
||||
|
||||
public static void drawRotatedString(String text, Graphics2D g2, float textX, float textY, double angle, float rotateX, float rotateY) {
|
||||
if (text == null || text.equals(""))
|
||||
return;
|
||||
AffineTransform saved = g2.getTransform();
|
||||
AffineTransform rotate = AffineTransform.getRotateInstance(angle, (double)rotateX, (double)rotateY);
|
||||
g2.transform(rotate);
|
||||
if (useDrawRotatedStringWorkaround) {
|
||||
TextLayout tl = new TextLayout(text, g2.getFont(), g2.getFontRenderContext());
|
||||
tl.draw(g2, textX, textY);
|
||||
} else {
|
||||
g2.drawString(text, textX, textY);
|
||||
}
|
||||
g2.setTransform(saved);
|
||||
}
|
||||
|
||||
public static void drawRotatedString(String text, Graphics2D g2, float x, float y, TextAnchor textAnchor, double angle, float rotationX, float rotationY) {
|
||||
if (text == null || text.equals(""))
|
||||
return;
|
||||
float[] textAdj = deriveTextBoundsAnchorOffsets(g2, text, textAnchor);
|
||||
drawRotatedString(text, g2, x + textAdj[0], y + textAdj[1], angle, rotationX, rotationY);
|
||||
}
|
||||
|
||||
public static void drawRotatedString(String text, Graphics2D g2, float x, float y, TextAnchor textAnchor, double angle, TextAnchor rotationAnchor) {
|
||||
if (text == null || text.equals(""))
|
||||
return;
|
||||
float[] textAdj = deriveTextBoundsAnchorOffsets(g2, text, textAnchor);
|
||||
float[] rotateAdj = deriveRotationAnchorOffsets(g2, text, rotationAnchor);
|
||||
drawRotatedString(text, g2, x + textAdj[0], y + textAdj[1], angle, x + textAdj[0] + rotateAdj[0], y + textAdj[1] + rotateAdj[1]);
|
||||
}
|
||||
|
||||
public static Shape calculateRotatedStringBounds(String text, Graphics2D g2, float x, float y, TextAnchor textAnchor, double angle, TextAnchor rotationAnchor) {
|
||||
if (text == null || text.equals(""))
|
||||
return null;
|
||||
float[] textAdj = deriveTextBoundsAnchorOffsets(g2, text, textAnchor);
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("TextBoundsAnchorOffsets = " + textAdj[0] + ", " + textAdj[1]);
|
||||
float[] rotateAdj = deriveRotationAnchorOffsets(g2, text, rotationAnchor);
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("RotationAnchorOffsets = " + rotateAdj[0] + ", " + rotateAdj[1]);
|
||||
Shape result = calculateRotatedStringBounds(text, g2, x + textAdj[0], y + textAdj[1], angle, x + textAdj[0] + rotateAdj[0], y + textAdj[1] + rotateAdj[1]);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static float[] deriveTextBoundsAnchorOffsets(Graphics2D g2, String text, TextAnchor anchor) {
|
||||
float[] result = new float[2];
|
||||
FontRenderContext frc = g2.getFontRenderContext();
|
||||
Font f = g2.getFont();
|
||||
FontMetrics fm = g2.getFontMetrics(f);
|
||||
Rectangle2D bounds = getTextBounds(text, g2, fm);
|
||||
LineMetrics metrics = f.getLineMetrics(text, frc);
|
||||
float ascent = metrics.getAscent();
|
||||
float halfAscent = ascent / 2.0F;
|
||||
float descent = metrics.getDescent();
|
||||
float leading = metrics.getLeading();
|
||||
float xAdj = 0.0F;
|
||||
float yAdj = 0.0F;
|
||||
if (anchor == TextAnchor.TOP_CENTER || anchor == TextAnchor.CENTER || anchor == TextAnchor.BOTTOM_CENTER || anchor == TextAnchor.BASELINE_CENTER || anchor == TextAnchor.HALF_ASCENT_CENTER) {
|
||||
xAdj = (float)-bounds.getWidth() / 2.0F;
|
||||
} else if (anchor == TextAnchor.TOP_RIGHT || anchor == TextAnchor.CENTER_RIGHT || anchor == TextAnchor.BOTTOM_RIGHT || anchor == TextAnchor.BASELINE_RIGHT || anchor == TextAnchor.HALF_ASCENT_RIGHT) {
|
||||
xAdj = (float)-bounds.getWidth();
|
||||
}
|
||||
if (anchor == TextAnchor.TOP_LEFT || anchor == TextAnchor.TOP_CENTER || anchor == TextAnchor.TOP_RIGHT) {
|
||||
yAdj = -descent - leading + (float)bounds.getHeight();
|
||||
} else if (anchor == TextAnchor.HALF_ASCENT_LEFT || anchor == TextAnchor.HALF_ASCENT_CENTER || anchor == TextAnchor.HALF_ASCENT_RIGHT) {
|
||||
yAdj = halfAscent;
|
||||
} else if (anchor == TextAnchor.CENTER_LEFT || anchor == TextAnchor.CENTER || anchor == TextAnchor.CENTER_RIGHT) {
|
||||
yAdj = -descent - leading + (float)(bounds.getHeight() / 2.0D);
|
||||
} else if (anchor == TextAnchor.BASELINE_LEFT || anchor == TextAnchor.BASELINE_CENTER || anchor == TextAnchor.BASELINE_RIGHT) {
|
||||
yAdj = 0.0F;
|
||||
} else if (anchor == TextAnchor.BOTTOM_LEFT || anchor == TextAnchor.BOTTOM_CENTER || anchor == TextAnchor.BOTTOM_RIGHT) {
|
||||
yAdj = -metrics.getDescent() - metrics.getLeading();
|
||||
}
|
||||
result[0] = xAdj;
|
||||
result[1] = yAdj;
|
||||
return result;
|
||||
}
|
||||
|
||||
private static float[] deriveRotationAnchorOffsets(Graphics2D g2, String text, TextAnchor anchor) {
|
||||
float[] result = new float[2];
|
||||
FontRenderContext frc = g2.getFontRenderContext();
|
||||
LineMetrics metrics = g2.getFont().getLineMetrics(text, frc);
|
||||
FontMetrics fm = g2.getFontMetrics();
|
||||
Rectangle2D bounds = getTextBounds(text, g2, fm);
|
||||
float ascent = metrics.getAscent();
|
||||
float halfAscent = ascent / 2.0F;
|
||||
float descent = metrics.getDescent();
|
||||
float leading = metrics.getLeading();
|
||||
float xAdj = 0.0F;
|
||||
float yAdj = 0.0F;
|
||||
if (anchor == TextAnchor.TOP_LEFT || anchor == TextAnchor.CENTER_LEFT || anchor == TextAnchor.BOTTOM_LEFT || anchor == TextAnchor.BASELINE_LEFT || anchor == TextAnchor.HALF_ASCENT_LEFT) {
|
||||
xAdj = 0.0F;
|
||||
} else if (anchor == TextAnchor.TOP_CENTER || anchor == TextAnchor.CENTER || anchor == TextAnchor.BOTTOM_CENTER || anchor == TextAnchor.BASELINE_CENTER || anchor == TextAnchor.HALF_ASCENT_CENTER) {
|
||||
xAdj = (float)bounds.getWidth() / 2.0F;
|
||||
} else if (anchor == TextAnchor.TOP_RIGHT || anchor == TextAnchor.CENTER_RIGHT || anchor == TextAnchor.BOTTOM_RIGHT || anchor == TextAnchor.BASELINE_RIGHT || anchor == TextAnchor.HALF_ASCENT_RIGHT) {
|
||||
xAdj = (float)bounds.getWidth();
|
||||
}
|
||||
if (anchor == TextAnchor.TOP_LEFT || anchor == TextAnchor.TOP_CENTER || anchor == TextAnchor.TOP_RIGHT) {
|
||||
yAdj = descent + leading - (float)bounds.getHeight();
|
||||
} else if (anchor == TextAnchor.CENTER_LEFT || anchor == TextAnchor.CENTER || anchor == TextAnchor.CENTER_RIGHT) {
|
||||
yAdj = descent + leading - (float)(bounds.getHeight() / 2.0D);
|
||||
} else if (anchor == TextAnchor.HALF_ASCENT_LEFT || anchor == TextAnchor.HALF_ASCENT_CENTER || anchor == TextAnchor.HALF_ASCENT_RIGHT) {
|
||||
yAdj = -halfAscent;
|
||||
} else if (anchor == TextAnchor.BASELINE_LEFT || anchor == TextAnchor.BASELINE_CENTER || anchor == TextAnchor.BASELINE_RIGHT) {
|
||||
yAdj = 0.0F;
|
||||
} else if (anchor == TextAnchor.BOTTOM_LEFT || anchor == TextAnchor.BOTTOM_CENTER || anchor == TextAnchor.BOTTOM_RIGHT) {
|
||||
yAdj = metrics.getDescent() + metrics.getLeading();
|
||||
}
|
||||
result[0] = xAdj;
|
||||
result[1] = yAdj;
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Shape calculateRotatedStringBounds(String text, Graphics2D g2, float textX, float textY, double angle, float rotateX, float rotateY) {
|
||||
if (text == null || text.equals(""))
|
||||
return null;
|
||||
FontMetrics fm = g2.getFontMetrics();
|
||||
Rectangle2D bounds = getTextBounds(text, g2, fm);
|
||||
AffineTransform translate = AffineTransform.getTranslateInstance((double)textX, (double)textY);
|
||||
Shape translatedBounds = translate.createTransformedShape(bounds);
|
||||
AffineTransform rotate = AffineTransform.getRotateInstance(angle, (double)rotateX, (double)rotateY);
|
||||
Shape result = rotate.createTransformedShape(translatedBounds);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean getUseFontMetricsGetStringBounds() {
|
||||
return useFontMetricsGetStringBounds;
|
||||
}
|
||||
|
||||
public static void setUseFontMetricsGetStringBounds(boolean use) {
|
||||
useFontMetricsGetStringBounds = use;
|
||||
}
|
||||
|
||||
public static boolean isUseDrawRotatedStringWorkaround() {
|
||||
return useDrawRotatedStringWorkaround;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,111 @@
|
|||
package org.jfree.threads;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class ReaderWriterLock {
|
||||
private static class ReaderWriterNode {
|
||||
protected static final int READER = 0;
|
||||
|
||||
protected static final int WRITER = 1;
|
||||
|
||||
protected Thread t;
|
||||
|
||||
protected int state;
|
||||
|
||||
protected int nAcquires;
|
||||
|
||||
ReaderWriterNode(Thread x0, int x1, ReaderWriterLock.null x2) {
|
||||
this(x0, x1);
|
||||
}
|
||||
|
||||
private ReaderWriterNode(Thread t, int state) {
|
||||
this.t = t;
|
||||
this.state = state;
|
||||
this.nAcquires = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private ArrayList waiters = new ArrayList();
|
||||
|
||||
public synchronized void lockRead() {
|
||||
ReaderWriterNode node;
|
||||
Thread me = Thread.currentThread();
|
||||
int index = getIndex(me);
|
||||
if (index == -1) {
|
||||
node = new ReaderWriterNode(me, 0);
|
||||
this.waiters.add(node);
|
||||
} else {
|
||||
node = (ReaderWriterNode)this.waiters.get(index);
|
||||
}
|
||||
while (getIndex(me) > firstWriter()) {
|
||||
try {
|
||||
wait();
|
||||
} catch (Exception e) {
|
||||
System.err.println("ReaderWriterLock.lockRead(): exception.");
|
||||
System.err.print(e.getMessage());
|
||||
}
|
||||
}
|
||||
node.nAcquires++;
|
||||
}
|
||||
|
||||
public synchronized void lockWrite() {
|
||||
ReaderWriterNode node;
|
||||
Thread me = Thread.currentThread();
|
||||
int index = getIndex(me);
|
||||
if (index == -1) {
|
||||
node = new ReaderWriterNode(me, 1);
|
||||
this.waiters.add(node);
|
||||
} else {
|
||||
node = (ReaderWriterNode)this.waiters.get(index);
|
||||
if (node.state == 0)
|
||||
throw new IllegalArgumentException("Upgrade lock");
|
||||
node.state = 1;
|
||||
}
|
||||
while (getIndex(me) != 0) {
|
||||
try {
|
||||
wait();
|
||||
} catch (Exception e) {
|
||||
System.err.println("ReaderWriterLock.lockWrite(): exception.");
|
||||
System.err.print(e.getMessage());
|
||||
}
|
||||
}
|
||||
node.nAcquires++;
|
||||
}
|
||||
|
||||
public synchronized void unlock() {
|
||||
Thread me = Thread.currentThread();
|
||||
int index = getIndex(me);
|
||||
if (index > firstWriter())
|
||||
throw new IllegalArgumentException("Lock not held");
|
||||
ReaderWriterNode node = (ReaderWriterNode)this.waiters.get(index);
|
||||
node.nAcquires--;
|
||||
if (node.nAcquires == 0)
|
||||
this.waiters.remove(index);
|
||||
notifyAll();
|
||||
}
|
||||
|
||||
private int firstWriter() {
|
||||
Iterator e = this.waiters.iterator();
|
||||
int index = 0;
|
||||
while (e.hasNext()) {
|
||||
ReaderWriterNode node = (ReaderWriterNode)e.next();
|
||||
if (node.state == 1)
|
||||
return index;
|
||||
index++;
|
||||
}
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
private int getIndex(Thread t) {
|
||||
Iterator e = this.waiters.iterator();
|
||||
int index = 0;
|
||||
while (e.hasNext()) {
|
||||
ReaderWriterNode node = (ReaderWriterNode)e.next();
|
||||
if (node.t == t)
|
||||
return index;
|
||||
index++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
65
rus/WEB-INF/lib/jcommon-1.0.12_src/org/jfree/ui/Align.java
Normal file
65
rus/WEB-INF/lib/jcommon-1.0.12_src/org/jfree/ui/Align.java
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
package org.jfree.ui;
|
||||
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
public final class Align {
|
||||
public static final int CENTER = 0;
|
||||
|
||||
public static final int TOP = 1;
|
||||
|
||||
public static final int BOTTOM = 2;
|
||||
|
||||
public static final int LEFT = 4;
|
||||
|
||||
public static final int RIGHT = 8;
|
||||
|
||||
public static final int TOP_LEFT = 5;
|
||||
|
||||
public static final int TOP_RIGHT = 9;
|
||||
|
||||
public static final int BOTTOM_LEFT = 6;
|
||||
|
||||
public static final int BOTTOM_RIGHT = 10;
|
||||
|
||||
public static final int FIT_HORIZONTAL = 12;
|
||||
|
||||
public static final int FIT_VERTICAL = 3;
|
||||
|
||||
public static final int FIT = 15;
|
||||
|
||||
public static final int NORTH = 1;
|
||||
|
||||
public static final int SOUTH = 2;
|
||||
|
||||
public static final int WEST = 4;
|
||||
|
||||
public static final int EAST = 8;
|
||||
|
||||
public static final int NORTH_WEST = 5;
|
||||
|
||||
public static final int NORTH_EAST = 9;
|
||||
|
||||
public static final int SOUTH_WEST = 6;
|
||||
|
||||
public static final int SOUTH_EAST = 10;
|
||||
|
||||
public static void align(Rectangle2D rect, Rectangle2D frame, int align) {
|
||||
double x = frame.getCenterX() - rect.getWidth() / 2.0D;
|
||||
double y = frame.getCenterY() - rect.getHeight() / 2.0D;
|
||||
double w = rect.getWidth();
|
||||
double h = rect.getHeight();
|
||||
if ((align & 0x3) == 3)
|
||||
h = frame.getHeight();
|
||||
if ((align & 0xC) == 12)
|
||||
w = frame.getWidth();
|
||||
if ((align & 0x1) == 1)
|
||||
y = frame.getMinY();
|
||||
if ((align & 0x2) == 2)
|
||||
y = frame.getMaxY() - h;
|
||||
if ((align & 0x4) == 4)
|
||||
x = frame.getX();
|
||||
if ((align & 0x8) == 8)
|
||||
x = frame.getMaxX() - w;
|
||||
rect.setRect(x, y, w, h);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
package org.jfree.ui;
|
||||
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.event.WindowListener;
|
||||
import javax.swing.JFrame;
|
||||
|
||||
public class ApplicationFrame extends JFrame implements WindowListener {
|
||||
public ApplicationFrame(String title) {
|
||||
super(title);
|
||||
addWindowListener(this);
|
||||
}
|
||||
|
||||
public void windowClosing(WindowEvent event) {
|
||||
if (event.getWindow() == this) {
|
||||
dispose();
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
public void windowClosed(WindowEvent event) {}
|
||||
|
||||
public void windowActivated(WindowEvent event) {}
|
||||
|
||||
public void windowDeactivated(WindowEvent event) {}
|
||||
|
||||
public void windowDeiconified(WindowEvent event) {}
|
||||
|
||||
public void windowIconified(WindowEvent event) {}
|
||||
|
||||
public void windowOpened(WindowEvent event) {}
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
package org.jfree.ui;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Insets;
|
||||
import java.awt.Polygon;
|
||||
import java.awt.Shape;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class ArrowPanel extends JPanel {
|
||||
public static final int UP = 0;
|
||||
|
||||
public static final int DOWN = 1;
|
||||
|
||||
private int type = 0;
|
||||
|
||||
private Rectangle2D available = new Rectangle2D.Float();
|
||||
|
||||
public ArrowPanel(int type) {
|
||||
this.type = type;
|
||||
setPreferredSize(new Dimension(14, 9));
|
||||
}
|
||||
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
Graphics2D g2 = (Graphics2D)g;
|
||||
Dimension size = getSize();
|
||||
Insets insets = getInsets();
|
||||
this.available.setRect((double)insets.left, (double)insets.top, size.getWidth() - (double)insets.left - (double)insets.right, size.getHeight() - (double)insets.top - (double)insets.bottom);
|
||||
g2.translate(insets.left, insets.top);
|
||||
g2.fill(getArrow(this.type));
|
||||
}
|
||||
|
||||
private Shape getArrow(int t) {
|
||||
switch (t) {
|
||||
case 0:
|
||||
return getUpArrow();
|
||||
case 1:
|
||||
return getDownArrow();
|
||||
}
|
||||
return getUpArrow();
|
||||
}
|
||||
|
||||
private Shape getUpArrow() {
|
||||
Polygon result = new Polygon();
|
||||
result.addPoint(7, 2);
|
||||
result.addPoint(2, 7);
|
||||
result.addPoint(12, 7);
|
||||
return result;
|
||||
}
|
||||
|
||||
private Shape getDownArrow() {
|
||||
Polygon result = new Polygon();
|
||||
result.addPoint(7, 7);
|
||||
result.addPoint(2, 2);
|
||||
result.addPoint(12, 2);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,129 @@
|
|||
package org.jfree.ui;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Graphics;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.UIManager;
|
||||
|
||||
public class BevelArrowIcon implements Icon {
|
||||
public static final int UP = 0;
|
||||
|
||||
public static final int DOWN = 1;
|
||||
|
||||
private static final int DEFAULT_SIZE = 11;
|
||||
|
||||
private Color edge1;
|
||||
|
||||
private Color edge2;
|
||||
|
||||
private Color fill;
|
||||
|
||||
private int size;
|
||||
|
||||
private int direction;
|
||||
|
||||
public BevelArrowIcon(int direction, boolean isRaisedView, boolean isPressedView) {
|
||||
if (isRaisedView) {
|
||||
if (isPressedView) {
|
||||
init(UIManager.getColor("controlLtHighlight"), UIManager.getColor("controlDkShadow"), UIManager.getColor("controlShadow"), 11, direction);
|
||||
} else {
|
||||
init(UIManager.getColor("controlHighlight"), UIManager.getColor("controlShadow"), UIManager.getColor("control"), 11, direction);
|
||||
}
|
||||
} else if (isPressedView) {
|
||||
init(UIManager.getColor("controlDkShadow"), UIManager.getColor("controlLtHighlight"), UIManager.getColor("controlShadow"), 11, direction);
|
||||
} else {
|
||||
init(UIManager.getColor("controlShadow"), UIManager.getColor("controlHighlight"), UIManager.getColor("control"), 11, direction);
|
||||
}
|
||||
}
|
||||
|
||||
public BevelArrowIcon(Color edge1, Color edge2, Color fill, int size, int direction) {
|
||||
init(edge1, edge2, fill, size, direction);
|
||||
}
|
||||
|
||||
public void paintIcon(Component c, Graphics g, int x, int y) {
|
||||
switch (this.direction) {
|
||||
case 1:
|
||||
drawDownArrow(g, x, y);
|
||||
break;
|
||||
case 0:
|
||||
drawUpArrow(g, x, y);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public int getIconWidth() {
|
||||
return this.size;
|
||||
}
|
||||
|
||||
public int getIconHeight() {
|
||||
return this.size;
|
||||
}
|
||||
|
||||
private void init(Color edge1, Color edge2, Color fill, int size, int direction) {
|
||||
this.edge1 = edge1;
|
||||
this.edge2 = edge2;
|
||||
this.fill = fill;
|
||||
this.size = size;
|
||||
this.direction = direction;
|
||||
}
|
||||
|
||||
private void drawDownArrow(Graphics g, int xo, int yo) {
|
||||
g.setColor(this.edge1);
|
||||
g.drawLine(xo, yo, xo + this.size - 1, yo);
|
||||
g.drawLine(xo, yo + 1, xo + this.size - 3, yo + 1);
|
||||
g.setColor(this.edge2);
|
||||
g.drawLine(xo + this.size - 2, yo + 1, xo + this.size - 1, yo + 1);
|
||||
int x = xo + 1;
|
||||
int y = yo + 2;
|
||||
int dx = this.size - 6;
|
||||
while (y + 1 < yo + this.size) {
|
||||
g.setColor(this.edge1);
|
||||
g.drawLine(x, y, x + 1, y);
|
||||
g.drawLine(x, y + 1, x + 1, y + 1);
|
||||
if (0 < dx) {
|
||||
g.setColor(this.fill);
|
||||
g.drawLine(x + 2, y, x + 1 + dx, y);
|
||||
g.drawLine(x + 2, y + 1, x + 1 + dx, y + 1);
|
||||
}
|
||||
g.setColor(this.edge2);
|
||||
g.drawLine(x + dx + 2, y, x + dx + 3, y);
|
||||
g.drawLine(x + dx + 2, y + 1, x + dx + 3, y + 1);
|
||||
x++;
|
||||
y += 2;
|
||||
dx -= 2;
|
||||
}
|
||||
g.setColor(this.edge1);
|
||||
g.drawLine(xo + this.size / 2, yo + this.size - 1, xo + this.size / 2, yo + this.size - 1);
|
||||
}
|
||||
|
||||
private void drawUpArrow(Graphics g, int xo, int yo) {
|
||||
g.setColor(this.edge1);
|
||||
int x = xo + this.size / 2;
|
||||
g.drawLine(x, yo, x, yo);
|
||||
x--;
|
||||
int y = yo + 1;
|
||||
int dx = 0;
|
||||
while (y + 3 < yo + this.size) {
|
||||
g.setColor(this.edge1);
|
||||
g.drawLine(x, y, x + 1, y);
|
||||
g.drawLine(x, y + 1, x + 1, y + 1);
|
||||
if (0 < dx) {
|
||||
g.setColor(this.fill);
|
||||
g.drawLine(x + 2, y, x + 1 + dx, y);
|
||||
g.drawLine(x + 2, y + 1, x + 1 + dx, y + 1);
|
||||
}
|
||||
g.setColor(this.edge2);
|
||||
g.drawLine(x + dx + 2, y, x + dx + 3, y);
|
||||
g.drawLine(x + dx + 2, y + 1, x + dx + 3, y + 1);
|
||||
x--;
|
||||
y += 2;
|
||||
dx += 2;
|
||||
}
|
||||
g.setColor(this.edge1);
|
||||
g.drawLine(xo, yo + this.size - 3, xo + 1, yo + this.size - 3);
|
||||
g.setColor(this.edge2);
|
||||
g.drawLine(xo + 2, yo + this.size - 2, xo + this.size - 1, yo + this.size - 2);
|
||||
g.drawLine(xo, yo + this.size - 1, xo + this.size, yo + this.size - 1);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
package org.jfree.ui;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.text.DateFormat;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.table.DefaultTableCellRenderer;
|
||||
|
||||
public class DateCellRenderer extends DefaultTableCellRenderer {
|
||||
private DateFormat formatter;
|
||||
|
||||
public DateCellRenderer() {
|
||||
this(DateFormat.getDateTimeInstance());
|
||||
}
|
||||
|
||||
public DateCellRenderer(DateFormat formatter) {
|
||||
this.formatter = formatter;
|
||||
setHorizontalAlignment(0);
|
||||
}
|
||||
|
||||
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
|
||||
setFont(null);
|
||||
if (value != null) {
|
||||
setText(this.formatter.format(value));
|
||||
} else {
|
||||
setText("");
|
||||
}
|
||||
if (isSelected) {
|
||||
setBackground(table.getSelectionBackground());
|
||||
} else {
|
||||
setBackground(null);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,267 @@
|
|||
package org.jfree.ui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.Insets;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.text.DateFormatSymbols;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.UIManager;
|
||||
import org.jfree.date.SerialDate;
|
||||
|
||||
public class DateChooserPanel extends JPanel implements ActionListener {
|
||||
private Calendar chosenDate;
|
||||
|
||||
private Color chosenDateButtonColor;
|
||||
|
||||
private Color chosenMonthButtonColor;
|
||||
|
||||
private Color chosenOtherButtonColor;
|
||||
|
||||
private int firstDayOfWeek;
|
||||
|
||||
private int yearSelectionRange = 20;
|
||||
|
||||
private Font dateFont = new Font("SansSerif", 0, 10);
|
||||
|
||||
private JComboBox monthSelector;
|
||||
|
||||
private JComboBox yearSelector;
|
||||
|
||||
private JButton todayButton;
|
||||
|
||||
private JButton[] buttons;
|
||||
|
||||
private boolean refreshing = false;
|
||||
|
||||
private int[] WEEK_DAYS;
|
||||
|
||||
public DateChooserPanel() {
|
||||
this(Calendar.getInstance(), false);
|
||||
}
|
||||
|
||||
public DateChooserPanel(Calendar calendar, boolean controlPanel) {
|
||||
super(new BorderLayout());
|
||||
this.chosenDateButtonColor = UIManager.getColor("textHighlight");
|
||||
this.chosenMonthButtonColor = UIManager.getColor("control");
|
||||
this.chosenOtherButtonColor = UIManager.getColor("controlShadow");
|
||||
this.chosenDate = calendar;
|
||||
this.firstDayOfWeek = calendar.getFirstDayOfWeek();
|
||||
this.WEEK_DAYS = new int[7];
|
||||
for (int i = 0; i < 7; i++)
|
||||
this.WEEK_DAYS[i] = (this.firstDayOfWeek + i - 1) % 7 + 1;
|
||||
add(constructSelectionPanel(), "North");
|
||||
add(getCalendarPanel(), "Center");
|
||||
if (controlPanel)
|
||||
add(constructControlPanel(), "South");
|
||||
setDate(calendar.getTime());
|
||||
}
|
||||
|
||||
public void setDate(Date theDate) {
|
||||
this.chosenDate.setTime(theDate);
|
||||
this.monthSelector.setSelectedIndex(this.chosenDate.get(2));
|
||||
refreshYearSelector();
|
||||
refreshButtons();
|
||||
}
|
||||
|
||||
public Date getDate() {
|
||||
return this.chosenDate.getTime();
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (e.getActionCommand().equals("monthSelectionChanged")) {
|
||||
JComboBox c = (JComboBox)e.getSource();
|
||||
int dayOfMonth = this.chosenDate.get(5);
|
||||
this.chosenDate.set(5, 1);
|
||||
this.chosenDate.set(2, c.getSelectedIndex());
|
||||
int maxDayOfMonth = this.chosenDate.getActualMaximum(5);
|
||||
this.chosenDate.set(5, Math.min(dayOfMonth, maxDayOfMonth));
|
||||
refreshButtons();
|
||||
} else if (e.getActionCommand().equals("yearSelectionChanged")) {
|
||||
if (!this.refreshing) {
|
||||
JComboBox c = (JComboBox)e.getSource();
|
||||
Integer y = (Integer)c.getSelectedItem();
|
||||
int dayOfMonth = this.chosenDate.get(5);
|
||||
this.chosenDate.set(5, 1);
|
||||
this.chosenDate.set(1, y.intValue());
|
||||
int maxDayOfMonth = this.chosenDate.getActualMaximum(5);
|
||||
this.chosenDate.set(5, Math.min(dayOfMonth, maxDayOfMonth));
|
||||
refreshYearSelector();
|
||||
refreshButtons();
|
||||
}
|
||||
} else if (e.getActionCommand().equals("todayButtonClicked")) {
|
||||
setDate(new Date());
|
||||
} else if (e.getActionCommand().equals("dateButtonClicked")) {
|
||||
JButton b = (JButton)e.getSource();
|
||||
int i = Integer.parseInt(b.getName());
|
||||
Calendar cal = getFirstVisibleDate();
|
||||
cal.add(5, i);
|
||||
setDate(cal.getTime());
|
||||
}
|
||||
}
|
||||
|
||||
private JPanel getCalendarPanel() {
|
||||
JPanel p = new JPanel(new GridLayout(7, 7));
|
||||
DateFormatSymbols dateFormatSymbols = new DateFormatSymbols();
|
||||
String[] weekDays = dateFormatSymbols.getShortWeekdays();
|
||||
for (int j = 0; j < this.WEEK_DAYS.length; j++)
|
||||
p.add(new JLabel(weekDays[this.WEEK_DAYS[j]], 0));
|
||||
this.buttons = new JButton[42];
|
||||
for (int i = 0; i < 42; i++) {
|
||||
JButton b = new JButton("");
|
||||
b.setMargin(new Insets(1, 1, 1, 1));
|
||||
b.setName(Integer.toString(i));
|
||||
b.setFont(this.dateFont);
|
||||
b.setFocusPainted(false);
|
||||
b.setActionCommand("dateButtonClicked");
|
||||
b.addActionListener(this);
|
||||
this.buttons[i] = b;
|
||||
p.add(b);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
private Color getButtonColor(Calendar theDate) {
|
||||
if (equalDates(theDate, this.chosenDate))
|
||||
return this.chosenDateButtonColor;
|
||||
if (theDate.get(2) == this.chosenDate.get(2))
|
||||
return this.chosenMonthButtonColor;
|
||||
return this.chosenOtherButtonColor;
|
||||
}
|
||||
|
||||
private boolean equalDates(Calendar c1, Calendar c2) {
|
||||
if (c1.get(5) == c2.get(5) && c1.get(2) == c2.get(2) && c1.get(1) == c2.get(1))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private Calendar getFirstVisibleDate() {
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.set(this.chosenDate.get(1), this.chosenDate.get(2), 1);
|
||||
c.add(5, -1);
|
||||
while (c.get(7) != getFirstDayOfWeek())
|
||||
c.add(5, -1);
|
||||
return c;
|
||||
}
|
||||
|
||||
private int getFirstDayOfWeek() {
|
||||
return this.firstDayOfWeek;
|
||||
}
|
||||
|
||||
private void refreshButtons() {
|
||||
Calendar c = getFirstVisibleDate();
|
||||
for (int i = 0; i < 42; i++) {
|
||||
JButton b = this.buttons[i];
|
||||
b.setText(Integer.toString(c.get(5)));
|
||||
b.setBackground(getButtonColor(c));
|
||||
c.add(5, 1);
|
||||
}
|
||||
}
|
||||
|
||||
private void refreshYearSelector() {
|
||||
if (!this.refreshing) {
|
||||
this.refreshing = true;
|
||||
this.yearSelector.removeAllItems();
|
||||
Integer[] years = getYears(this.chosenDate.get(1));
|
||||
for (int i = 0; i < years.length; i++)
|
||||
this.yearSelector.addItem(years[i]);
|
||||
this.yearSelector.setSelectedItem(new Integer(this.chosenDate.get(1)));
|
||||
this.refreshing = false;
|
||||
}
|
||||
}
|
||||
|
||||
private Integer[] getYears(int chosenYear) {
|
||||
int size = this.yearSelectionRange * 2 + 1;
|
||||
int start = chosenYear - this.yearSelectionRange;
|
||||
Integer[] years = new Integer[size];
|
||||
for (int i = 0; i < size; i++)
|
||||
years[i] = new Integer(i + start);
|
||||
return years;
|
||||
}
|
||||
|
||||
private JPanel constructSelectionPanel() {
|
||||
JPanel p = new JPanel();
|
||||
int minMonth = this.chosenDate.getMinimum(2);
|
||||
int maxMonth = this.chosenDate.getMaximum(2);
|
||||
String[] months = new String[maxMonth - minMonth + 1];
|
||||
System.arraycopy(SerialDate.getMonths(), minMonth, months, 0, months.length);
|
||||
this.monthSelector = new JComboBox(months);
|
||||
this.monthSelector.addActionListener(this);
|
||||
this.monthSelector.setActionCommand("monthSelectionChanged");
|
||||
p.add(this.monthSelector);
|
||||
this.yearSelector = new JComboBox(getYears(0));
|
||||
this.yearSelector.addActionListener(this);
|
||||
this.yearSelector.setActionCommand("yearSelectionChanged");
|
||||
p.add(this.yearSelector);
|
||||
return p;
|
||||
}
|
||||
|
||||
private JPanel constructControlPanel() {
|
||||
JPanel p = new JPanel();
|
||||
p.setBorder(BorderFactory.createEmptyBorder(2, 5, 2, 5));
|
||||
this.todayButton = new JButton("Today");
|
||||
this.todayButton.addActionListener(this);
|
||||
this.todayButton.setActionCommand("todayButtonClicked");
|
||||
p.add(this.todayButton);
|
||||
return p;
|
||||
}
|
||||
|
||||
public Color getChosenDateButtonColor() {
|
||||
return this.chosenDateButtonColor;
|
||||
}
|
||||
|
||||
public void setChosenDateButtonColor(Color chosenDateButtonColor) {
|
||||
if (chosenDateButtonColor == null)
|
||||
throw new NullPointerException("UIColor must not be null.");
|
||||
Color oldValue = this.chosenDateButtonColor;
|
||||
this.chosenDateButtonColor = chosenDateButtonColor;
|
||||
refreshButtons();
|
||||
firePropertyChange("chosenDateButtonColor", oldValue, chosenDateButtonColor);
|
||||
}
|
||||
|
||||
public Color getChosenMonthButtonColor() {
|
||||
return this.chosenMonthButtonColor;
|
||||
}
|
||||
|
||||
public void setChosenMonthButtonColor(Color chosenMonthButtonColor) {
|
||||
if (chosenMonthButtonColor == null)
|
||||
throw new NullPointerException("UIColor must not be null.");
|
||||
Color oldValue = this.chosenMonthButtonColor;
|
||||
this.chosenMonthButtonColor = chosenMonthButtonColor;
|
||||
refreshButtons();
|
||||
firePropertyChange("chosenMonthButtonColor", oldValue, chosenMonthButtonColor);
|
||||
}
|
||||
|
||||
public Color getChosenOtherButtonColor() {
|
||||
return this.chosenOtherButtonColor;
|
||||
}
|
||||
|
||||
public void setChosenOtherButtonColor(Color chosenOtherButtonColor) {
|
||||
if (chosenOtherButtonColor == null)
|
||||
throw new NullPointerException("UIColor must not be null.");
|
||||
Color oldValue = this.chosenOtherButtonColor;
|
||||
this.chosenOtherButtonColor = chosenOtherButtonColor;
|
||||
refreshButtons();
|
||||
firePropertyChange("chosenOtherButtonColor", oldValue, chosenOtherButtonColor);
|
||||
}
|
||||
|
||||
public int getYearSelectionRange() {
|
||||
return this.yearSelectionRange;
|
||||
}
|
||||
|
||||
public void setYearSelectionRange(int yearSelectionRange) {
|
||||
int oldYearSelectionRange = this.yearSelectionRange;
|
||||
this.yearSelectionRange = yearSelectionRange;
|
||||
refreshYearSelector();
|
||||
firePropertyChange("yearSelectionRange", oldYearSelectionRange, yearSelectionRange);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
package org.jfree.ui;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
public interface Drawable {
|
||||
void draw(Graphics2D paramGraphics2D, Rectangle2D paramRectangle2D);
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
package org.jfree.ui;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class DrawablePanel extends JPanel {
|
||||
private Drawable drawable;
|
||||
|
||||
public DrawablePanel() {
|
||||
setOpaque(false);
|
||||
}
|
||||
|
||||
public Drawable getDrawable() {
|
||||
return this.drawable;
|
||||
}
|
||||
|
||||
public void setDrawable(Drawable drawable) {
|
||||
this.drawable = drawable;
|
||||
revalidate();
|
||||
repaint();
|
||||
}
|
||||
|
||||
public Dimension getPreferredSize() {
|
||||
if (this.drawable instanceof ExtendedDrawable) {
|
||||
ExtendedDrawable ed = (ExtendedDrawable)this.drawable;
|
||||
return ed.getPreferredSize();
|
||||
}
|
||||
return super.getPreferredSize();
|
||||
}
|
||||
|
||||
public Dimension getMinimumSize() {
|
||||
if (this.drawable instanceof ExtendedDrawable) {
|
||||
ExtendedDrawable ed = (ExtendedDrawable)this.drawable;
|
||||
return ed.getPreferredSize();
|
||||
}
|
||||
return super.getMinimumSize();
|
||||
}
|
||||
|
||||
public boolean isOpaque() {
|
||||
if (this.drawable == null)
|
||||
return false;
|
||||
return super.isOpaque();
|
||||
}
|
||||
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
if (this.drawable == null)
|
||||
return;
|
||||
Graphics2D g2 = (Graphics2D)g.create(0, 0, getWidth(), getHeight());
|
||||
this.drawable.draw(g2, new Rectangle2D.Double(0.0D, 0.0D, (double)getWidth(), (double)getHeight()));
|
||||
g2.dispose();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package org.jfree.ui;
|
||||
|
||||
import java.awt.Dimension;
|
||||
|
||||
public interface ExtendedDrawable extends Drawable {
|
||||
Dimension getPreferredSize();
|
||||
|
||||
boolean isPreserveAspectRatio();
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
package org.jfree.ui;
|
||||
|
||||
import java.io.File;
|
||||
import javax.swing.filechooser.FileFilter;
|
||||
|
||||
public class ExtensionFileFilter extends FileFilter {
|
||||
private String description;
|
||||
|
||||
private String extension;
|
||||
|
||||
public ExtensionFileFilter(String description, String extension) {
|
||||
this.description = description;
|
||||
this.extension = extension;
|
||||
}
|
||||
|
||||
public boolean accept(File file) {
|
||||
if (file.isDirectory())
|
||||
return true;
|
||||
String name = file.getName().toLowerCase();
|
||||
if (name.endsWith(this.extension))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return this.description;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
package org.jfree.ui;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import javax.swing.filechooser.FileFilter;
|
||||
|
||||
public class FilesystemFilter extends FileFilter implements FilenameFilter {
|
||||
private String[] fileext;
|
||||
|
||||
private String descr;
|
||||
|
||||
private boolean accDirs;
|
||||
|
||||
public FilesystemFilter(String fileext, String descr) {
|
||||
this(fileext, descr, true);
|
||||
}
|
||||
|
||||
public FilesystemFilter(String fileext, String descr, boolean accDirs) {
|
||||
this(new String[] { fileext }, descr, accDirs);
|
||||
}
|
||||
|
||||
public FilesystemFilter(String[] fileext, String descr, boolean accDirs) {
|
||||
this.fileext = (String[])fileext.clone();
|
||||
this.descr = descr;
|
||||
this.accDirs = accDirs;
|
||||
}
|
||||
|
||||
public boolean accept(File dir, String name) {
|
||||
File f = new File(dir, name);
|
||||
if (f.isDirectory() && acceptsDirectories())
|
||||
return true;
|
||||
for (int i = 0; i < this.fileext.length; i++) {
|
||||
if (name.endsWith(this.fileext[i]))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean accept(File dir) {
|
||||
if (dir.isDirectory() && acceptsDirectories())
|
||||
return true;
|
||||
for (int i = 0; i < this.fileext.length; i++) {
|
||||
if (dir.getName().endsWith(this.fileext[i]))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return this.descr;
|
||||
}
|
||||
|
||||
public void acceptDirectories(boolean b) {
|
||||
this.accDirs = b;
|
||||
}
|
||||
|
||||
public boolean acceptsDirectories() {
|
||||
return this.accDirs;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
package org.jfree.ui;
|
||||
|
||||
import java.awt.geom.Dimension2D;
|
||||
import java.io.Serializable;
|
||||
|
||||
public class FloatDimension extends Dimension2D implements Serializable {
|
||||
private static final long serialVersionUID = 5367882923248086744L;
|
||||
|
||||
private float width;
|
||||
|
||||
private float height;
|
||||
|
||||
public FloatDimension() {
|
||||
this.width = 0.0F;
|
||||
this.height = 0.0F;
|
||||
}
|
||||
|
||||
public FloatDimension(FloatDimension fd) {
|
||||
this.width = fd.width;
|
||||
this.height = fd.height;
|
||||
}
|
||||
|
||||
public FloatDimension(float width, float height) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public double getWidth() {
|
||||
return (double)this.width;
|
||||
}
|
||||
|
||||
public double getHeight() {
|
||||
return (double)this.height;
|
||||
}
|
||||
|
||||
public void setWidth(double width) {
|
||||
this.width = (float)width;
|
||||
}
|
||||
|
||||
public void setHeight(double height) {
|
||||
this.height = (float)height;
|
||||
}
|
||||
|
||||
public void setSize(double width, double height) {
|
||||
setHeight((double)(float)height);
|
||||
setWidth((double)(float)width);
|
||||
}
|
||||
|
||||
public Object clone() {
|
||||
return super.clone();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return getClass().getName() + ":={width=" + getWidth() + ", height=" + getHeight() + "}";
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
return true;
|
||||
if (!(o instanceof FloatDimension))
|
||||
return false;
|
||||
FloatDimension floatDimension = (FloatDimension)o;
|
||||
if (this.height != floatDimension.height)
|
||||
return false;
|
||||
if (this.width != floatDimension.width)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int result = Float.floatToIntBits(this.width);
|
||||
result = 29 * result + Float.floatToIntBits(this.height);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
package org.jfree.ui;
|
||||
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import javax.swing.AbstractButton;
|
||||
|
||||
public final class FloatingButtonEnabler extends MouseAdapter {
|
||||
private static FloatingButtonEnabler singleton;
|
||||
|
||||
public static FloatingButtonEnabler getInstance() {
|
||||
if (singleton == null)
|
||||
singleton = new FloatingButtonEnabler();
|
||||
return singleton;
|
||||
}
|
||||
|
||||
public void addButton(AbstractButton button) {
|
||||
button.addMouseListener(this);
|
||||
button.setBorderPainted(false);
|
||||
}
|
||||
|
||||
public void removeButton(AbstractButton button) {
|
||||
button.addMouseListener(this);
|
||||
button.setBorderPainted(true);
|
||||
}
|
||||
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
if (e.getSource() instanceof AbstractButton) {
|
||||
AbstractButton button = (AbstractButton)e.getSource();
|
||||
if (button.isEnabled())
|
||||
button.setBorderPainted(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void mouseExited(MouseEvent e) {
|
||||
if (e.getSource() instanceof AbstractButton) {
|
||||
AbstractButton button = (AbstractButton)e.getSource();
|
||||
button.setBorderPainted(false);
|
||||
if (button.getParent() != null)
|
||||
button.getParent().repaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
package org.jfree.ui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Dialog;
|
||||
import java.awt.Font;
|
||||
import java.awt.Frame;
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class FontChooserDialog extends StandardDialog {
|
||||
private FontChooserPanel fontChooserPanel;
|
||||
|
||||
public FontChooserDialog(Dialog owner, String title, boolean modal, Font font) {
|
||||
super(owner, title, modal);
|
||||
setContentPane(createContent(font));
|
||||
}
|
||||
|
||||
public FontChooserDialog(Frame owner, String title, boolean modal, Font font) {
|
||||
super(owner, title, modal);
|
||||
setContentPane(createContent(font));
|
||||
}
|
||||
|
||||
public Font getSelectedFont() {
|
||||
return this.fontChooserPanel.getSelectedFont();
|
||||
}
|
||||
|
||||
private JPanel createContent(Font font) {
|
||||
JPanel content = new JPanel(new BorderLayout());
|
||||
content.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
|
||||
if (font == null)
|
||||
font = new Font("Dialog", 10, 0);
|
||||
this.fontChooserPanel = new FontChooserPanel(font);
|
||||
content.add(this.fontChooserPanel);
|
||||
JPanel buttons = createButtonPanel();
|
||||
buttons.setBorder(BorderFactory.createEmptyBorder(4, 0, 0, 0));
|
||||
content.add(buttons, "South");
|
||||
return content;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,109 @@
|
|||
package org.jfree.ui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Font;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.GridLayout;
|
||||
import java.util.ResourceBundle;
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.ListModel;
|
||||
|
||||
public class FontChooserPanel extends JPanel {
|
||||
public static final String[] SIZES = new String[] {
|
||||
"9", "10", "11", "12", "14", "16", "18", "20", "22", "24",
|
||||
"28", "36", "48", "72" };
|
||||
|
||||
private JList fontlist;
|
||||
|
||||
private JList sizelist;
|
||||
|
||||
private JCheckBox bold;
|
||||
|
||||
private JCheckBox italic;
|
||||
|
||||
protected static ResourceBundle localizationResources = ResourceBundle.getBundle("org.jfree.ui.LocalizationBundle");
|
||||
|
||||
public FontChooserPanel(Font font) {
|
||||
GraphicsEnvironment g = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
String[] fonts = g.getAvailableFontFamilyNames();
|
||||
setLayout(new BorderLayout());
|
||||
JPanel right = new JPanel(new BorderLayout());
|
||||
JPanel fontPanel = new JPanel(new BorderLayout());
|
||||
fontPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), localizationResources.getString("Font")));
|
||||
this.fontlist = new JList(fonts);
|
||||
JScrollPane fontpane = new JScrollPane(this.fontlist);
|
||||
fontpane.setBorder(BorderFactory.createEtchedBorder());
|
||||
fontPanel.add(fontpane);
|
||||
add(fontPanel);
|
||||
JPanel sizePanel = new JPanel(new BorderLayout());
|
||||
sizePanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), localizationResources.getString("Size")));
|
||||
this.sizelist = new JList(SIZES);
|
||||
JScrollPane sizepane = new JScrollPane(this.sizelist);
|
||||
sizepane.setBorder(BorderFactory.createEtchedBorder());
|
||||
sizePanel.add(sizepane);
|
||||
JPanel attributes = new JPanel(new GridLayout(1, 2));
|
||||
this.bold = new JCheckBox(localizationResources.getString("Bold"));
|
||||
this.italic = new JCheckBox(localizationResources.getString("Italic"));
|
||||
attributes.add(this.bold);
|
||||
attributes.add(this.italic);
|
||||
attributes.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), localizationResources.getString("Attributes")));
|
||||
right.add(sizePanel, "Center");
|
||||
right.add(attributes, "South");
|
||||
add(right, "East");
|
||||
setSelectedFont(font);
|
||||
}
|
||||
|
||||
public Font getSelectedFont() {
|
||||
return new Font(getSelectedName(), getSelectedStyle(), getSelectedSize());
|
||||
}
|
||||
|
||||
public String getSelectedName() {
|
||||
return (String)this.fontlist.getSelectedValue();
|
||||
}
|
||||
|
||||
public int getSelectedStyle() {
|
||||
if (this.bold.isSelected() && this.italic.isSelected())
|
||||
return 3;
|
||||
if (this.bold.isSelected())
|
||||
return 1;
|
||||
if (this.italic.isSelected())
|
||||
return 2;
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getSelectedSize() {
|
||||
String selected = (String)this.sizelist.getSelectedValue();
|
||||
if (selected != null)
|
||||
return Integer.parseInt(selected);
|
||||
return 10;
|
||||
}
|
||||
|
||||
public void setSelectedFont(Font font) {
|
||||
if (font == null)
|
||||
throw new NullPointerException();
|
||||
this.bold.setSelected(font.isBold());
|
||||
this.italic.setSelected(font.isItalic());
|
||||
String fontName = font.getName();
|
||||
ListModel model = this.fontlist.getModel();
|
||||
this.fontlist.clearSelection();
|
||||
for (int i = 0; i < model.getSize(); i++) {
|
||||
if (fontName.equals(model.getElementAt(i))) {
|
||||
this.fontlist.setSelectedIndex(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
String fontSize = String.valueOf(font.getSize());
|
||||
model = this.sizelist.getModel();
|
||||
this.sizelist.clearSelection();
|
||||
for (int j = 0; j < model.getSize(); j++) {
|
||||
if (fontSize.equals(model.getElementAt(j))) {
|
||||
this.sizelist.setSelectedIndex(j);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
package org.jfree.ui;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.util.ResourceBundle;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class FontDisplayField extends JTextField {
|
||||
private Font displayFont;
|
||||
|
||||
protected static final ResourceBundle localizationResources = ResourceBundle.getBundle("org.jfree.ui.LocalizationBundle");
|
||||
|
||||
public FontDisplayField(Font font) {
|
||||
super("");
|
||||
setDisplayFont(font);
|
||||
setEnabled(false);
|
||||
}
|
||||
|
||||
public Font getDisplayFont() {
|
||||
return this.displayFont;
|
||||
}
|
||||
|
||||
public void setDisplayFont(Font font) {
|
||||
this.displayFont = font;
|
||||
setText(fontToString(this.displayFont));
|
||||
}
|
||||
|
||||
private String fontToString(Font font) {
|
||||
if (font != null)
|
||||
return font.getFontName() + ", " + font.getSize();
|
||||
return localizationResources.getString("No_Font_Selected");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
package org.jfree.ui;
|
||||
|
||||
import java.io.ObjectStreamException;
|
||||
import java.io.Serializable;
|
||||
|
||||
public final class GradientPaintTransformType implements Serializable {
|
||||
private static final long serialVersionUID = 8331561784933982450L;
|
||||
|
||||
public static final GradientPaintTransformType VERTICAL = new GradientPaintTransformType("GradientPaintTransformType.VERTICAL");
|
||||
|
||||
public static final GradientPaintTransformType HORIZONTAL = new GradientPaintTransformType("GradientPaintTransformType.HORIZONTAL");
|
||||
|
||||
public static final GradientPaintTransformType CENTER_VERTICAL = new GradientPaintTransformType("GradientPaintTransformType.CENTER_VERTICAL");
|
||||
|
||||
public static final GradientPaintTransformType CENTER_HORIZONTAL = new GradientPaintTransformType("GradientPaintTransformType.CENTER_HORIZONTAL");
|
||||
|
||||
private String name;
|
||||
|
||||
private GradientPaintTransformType(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
return true;
|
||||
if (!(o instanceof GradientPaintTransformType))
|
||||
return false;
|
||||
GradientPaintTransformType t = (GradientPaintTransformType)o;
|
||||
if (!this.name.equals(t.name))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return this.name.hashCode();
|
||||
}
|
||||
|
||||
private Object readResolve() throws ObjectStreamException {
|
||||
GradientPaintTransformType result = null;
|
||||
if (equals(HORIZONTAL)) {
|
||||
result = HORIZONTAL;
|
||||
} else if (equals(VERTICAL)) {
|
||||
result = VERTICAL;
|
||||
} else if (equals(CENTER_HORIZONTAL)) {
|
||||
result = CENTER_HORIZONTAL;
|
||||
} else if (equals(CENTER_VERTICAL)) {
|
||||
result = CENTER_VERTICAL;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
package org.jfree.ui;
|
||||
|
||||
import java.awt.GradientPaint;
|
||||
import java.awt.Shape;
|
||||
|
||||
public interface GradientPaintTransformer {
|
||||
GradientPaint transform(GradientPaint paramGradientPaint, Shape paramShape);
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
package org.jfree.ui;
|
||||
|
||||
import java.io.ObjectStreamException;
|
||||
import java.io.Serializable;
|
||||
|
||||
public final class HorizontalAlignment implements Serializable {
|
||||
private static final long serialVersionUID = -8249740987565309567L;
|
||||
|
||||
public static final HorizontalAlignment LEFT = new HorizontalAlignment("HorizontalAlignment.LEFT");
|
||||
|
||||
public static final HorizontalAlignment RIGHT = new HorizontalAlignment("HorizontalAlignment.RIGHT");
|
||||
|
||||
public static final HorizontalAlignment CENTER = new HorizontalAlignment("HorizontalAlignment.CENTER");
|
||||
|
||||
private String name;
|
||||
|
||||
private HorizontalAlignment(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (!(obj instanceof HorizontalAlignment))
|
||||
return false;
|
||||
HorizontalAlignment that = (HorizontalAlignment)obj;
|
||||
if (!this.name.equals(that.name))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return this.name.hashCode();
|
||||
}
|
||||
|
||||
private Object readResolve() throws ObjectStreamException {
|
||||
HorizontalAlignment result = null;
|
||||
if (equals(LEFT)) {
|
||||
result = LEFT;
|
||||
} else if (equals(RIGHT)) {
|
||||
result = RIGHT;
|
||||
} else if (equals(CENTER)) {
|
||||
result = CENTER;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
package org.jfree.ui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.Insets;
|
||||
import java.util.ResourceBundle;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.border.TitledBorder;
|
||||
|
||||
public class InsetsChooserPanel extends JPanel {
|
||||
private JTextField topValueEditor;
|
||||
|
||||
private JTextField leftValueEditor;
|
||||
|
||||
private JTextField bottomValueEditor;
|
||||
|
||||
private JTextField rightValueEditor;
|
||||
|
||||
protected static ResourceBundle localizationResources = ResourceBundle.getBundle("org.jfree.ui.LocalizationBundle");
|
||||
|
||||
public InsetsChooserPanel() {
|
||||
this(new Insets(0, 0, 0, 0));
|
||||
}
|
||||
|
||||
public InsetsChooserPanel(Insets current) {
|
||||
current = (current == null) ? new Insets(0, 0, 0, 0) : current;
|
||||
this.topValueEditor = new JTextField(new IntegerDocument(), "" + current.top, 0);
|
||||
this.leftValueEditor = new JTextField(new IntegerDocument(), "" + current.left, 0);
|
||||
this.bottomValueEditor = new JTextField(new IntegerDocument(), "" + current.bottom, 0);
|
||||
this.rightValueEditor = new JTextField(new IntegerDocument(), "" + current.right, 0);
|
||||
JPanel panel = new JPanel(new GridBagLayout());
|
||||
panel.setBorder(new TitledBorder(localizationResources.getString("Insets")));
|
||||
panel.add(new JLabel(localizationResources.getString("Top")), new GridBagConstraints(1, 0, 3, 1, 0.0D, 0.0D, 10, 0, new Insets(0, 0, 0, 0), 0, 0));
|
||||
panel.add(new JLabel(" "), new GridBagConstraints(1, 1, 1, 1, 0.0D, 0.0D, 10, 1, new Insets(0, 12, 0, 12), 8, 0));
|
||||
panel.add(this.topValueEditor, new GridBagConstraints(2, 1, 1, 1, 0.0D, 0.0D, 10, 2, new Insets(0, 0, 0, 0), 0, 0));
|
||||
panel.add(new JLabel(" "), new GridBagConstraints(3, 1, 1, 1, 0.0D, 0.0D, 10, 1, new Insets(0, 12, 0, 11), 8, 0));
|
||||
panel.add(new JLabel(localizationResources.getString("Left")), new GridBagConstraints(0, 2, 1, 1, 0.0D, 0.0D, 10, 1, new Insets(0, 4, 0, 4), 0, 0));
|
||||
panel.add(this.leftValueEditor, new GridBagConstraints(1, 2, 1, 1, 0.0D, 0.0D, 10, 1, new Insets(0, 0, 0, 0), 0, 0));
|
||||
panel.add(new JLabel(" "), new GridBagConstraints(2, 2, 1, 1, 0.0D, 0.0D, 10, 0, new Insets(0, 12, 0, 12), 8, 0));
|
||||
panel.add(this.rightValueEditor, new GridBagConstraints(3, 2, 1, 1, 0.0D, 0.0D, 10, 2, new Insets(0, 0, 0, 0), 0, 0));
|
||||
panel.add(new JLabel(localizationResources.getString("Right")), new GridBagConstraints(4, 2, 1, 1, 0.0D, 0.0D, 10, 0, new Insets(0, 4, 0, 4), 0, 0));
|
||||
panel.add(this.bottomValueEditor, new GridBagConstraints(2, 3, 1, 1, 0.0D, 0.0D, 10, 2, new Insets(0, 0, 0, 0), 0, 0));
|
||||
panel.add(new JLabel(localizationResources.getString("Bottom")), new GridBagConstraints(1, 4, 3, 1, 0.0D, 0.0D, 10, 0, new Insets(0, 0, 0, 0), 0, 0));
|
||||
setLayout(new BorderLayout());
|
||||
add(panel, "Center");
|
||||
}
|
||||
|
||||
public Insets getInsetsValue() {
|
||||
return new Insets(Math.abs(stringToInt(this.topValueEditor.getText())), Math.abs(stringToInt(this.leftValueEditor.getText())), Math.abs(stringToInt(this.bottomValueEditor.getText())), Math.abs(stringToInt(this.rightValueEditor.getText())));
|
||||
}
|
||||
|
||||
protected int stringToInt(String value) {
|
||||
value = value.trim();
|
||||
if (value.length() == 0)
|
||||
return 0;
|
||||
try {
|
||||
return Integer.parseInt(value);
|
||||
} catch (NumberFormatException e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void removeNotify() {
|
||||
super.removeNotify();
|
||||
removeAll();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
package org.jfree.ui;
|
||||
|
||||
import java.awt.Insets;
|
||||
import java.util.ResourceBundle;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class InsetsTextField extends JTextField {
|
||||
protected static ResourceBundle localizationResources = ResourceBundle.getBundle("org.jfree.ui.LocalizationBundle");
|
||||
|
||||
public InsetsTextField(Insets insets) {
|
||||
setInsets(insets);
|
||||
setEnabled(false);
|
||||
}
|
||||
|
||||
public String formatInsetsString(Insets insets) {
|
||||
insets = (insets == null) ? new Insets(0, 0, 0, 0) : insets;
|
||||
return localizationResources.getString("T") + insets.top + ", " + localizationResources.getString("L") + insets.left + ", " + localizationResources.getString("B") + insets.bottom + ", " + localizationResources.getString("R") + insets.right;
|
||||
}
|
||||
|
||||
public void setInsets(Insets insets) {
|
||||
setText(formatInsetsString(insets));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package org.jfree.ui;
|
||||
|
||||
import javax.swing.text.AttributeSet;
|
||||
import javax.swing.text.BadLocationException;
|
||||
import javax.swing.text.PlainDocument;
|
||||
|
||||
public class IntegerDocument extends PlainDocument {
|
||||
public void insertString(int i, String s, AttributeSet attributes) throws BadLocationException {
|
||||
super.insertString(i, s, attributes);
|
||||
if (s != null && (!s.equals("-") || i != 0 || s.length() >= 2))
|
||||
try {
|
||||
Integer.parseInt(getText(0, getLength()));
|
||||
} catch (NumberFormatException e) {
|
||||
remove(i, s.length());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
package org.jfree.ui;
|
||||
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.awt.event.FocusListener;
|
||||
import javax.swing.text.JTextComponent;
|
||||
|
||||
public final class JTextObserver implements FocusListener {
|
||||
private static JTextObserver singleton;
|
||||
|
||||
public static JTextObserver getInstance() {
|
||||
if (singleton == null)
|
||||
singleton = new JTextObserver();
|
||||
return singleton;
|
||||
}
|
||||
|
||||
public void focusGained(FocusEvent e) {
|
||||
if (e.getSource() instanceof JTextComponent) {
|
||||
JTextComponent tex = (JTextComponent)e.getSource();
|
||||
tex.selectAll();
|
||||
}
|
||||
}
|
||||
|
||||
public void focusLost(FocusEvent e) {
|
||||
if (e.getSource() instanceof JTextComponent) {
|
||||
JTextComponent tex = (JTextComponent)e.getSource();
|
||||
tex.select(0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public static void addTextComponent(JTextComponent t) {
|
||||
if (singleton == null)
|
||||
singleton = new JTextObserver();
|
||||
t.addFocusListener(singleton);
|
||||
}
|
||||
|
||||
public static void removeTextComponent(JTextComponent t) {
|
||||
if (singleton == null)
|
||||
singleton = new JTextObserver();
|
||||
t.removeFocusListener(singleton);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,211 @@
|
|||
package org.jfree.ui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import javax.swing.ComboBoxModel;
|
||||
import javax.swing.event.ListDataEvent;
|
||||
import javax.swing.event.ListDataListener;
|
||||
|
||||
public class KeyedComboBoxModel implements ComboBoxModel {
|
||||
private int selectedItemIndex;
|
||||
|
||||
private Object selectedItemValue;
|
||||
|
||||
private ArrayList data;
|
||||
|
||||
private ArrayList listdatalistener;
|
||||
|
||||
private transient ListDataListener[] tempListeners;
|
||||
|
||||
private boolean allowOtherValue;
|
||||
|
||||
private static class ComboBoxItemPair {
|
||||
private Object key;
|
||||
|
||||
private Object value;
|
||||
|
||||
public ComboBoxItemPair(Object key, Object value) {
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Object getKey() {
|
||||
return this.key;
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public void setValue(Object value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public KeyedComboBoxModel() {
|
||||
this.data = new ArrayList();
|
||||
this.listdatalistener = new ArrayList();
|
||||
}
|
||||
|
||||
public KeyedComboBoxModel(Object[] keys, Object[] values) {
|
||||
this();
|
||||
setData(keys, values);
|
||||
}
|
||||
|
||||
public void setData(Object[] keys, Object[] values) {
|
||||
if (values.length != keys.length)
|
||||
throw new IllegalArgumentException("Values and text must have the same length.");
|
||||
this.data.clear();
|
||||
this.data.ensureCapacity(keys.length);
|
||||
for (int i = 0; i < values.length; i++)
|
||||
add(keys[i], values[i]);
|
||||
this.selectedItemIndex = -1;
|
||||
ListDataEvent evt = new ListDataEvent(this, 0, 0, this.data.size() - 1);
|
||||
fireListDataEvent(evt);
|
||||
}
|
||||
|
||||
protected synchronized void fireListDataEvent(ListDataEvent evt) {
|
||||
if (this.tempListeners == null)
|
||||
this.tempListeners = (ListDataListener[])this.listdatalistener.toArray(new ListDataListener[this.listdatalistener.size()]);
|
||||
ListDataListener[] listeners = this.tempListeners;
|
||||
for (int i = 0; i < listeners.length; i++) {
|
||||
ListDataListener l = listeners[i];
|
||||
l.contentsChanged(evt);
|
||||
}
|
||||
}
|
||||
|
||||
public Object getSelectedItem() {
|
||||
return this.selectedItemValue;
|
||||
}
|
||||
|
||||
public void setSelectedKey(Object anItem) {
|
||||
if (anItem == null) {
|
||||
this.selectedItemIndex = -1;
|
||||
this.selectedItemValue = null;
|
||||
} else {
|
||||
int newSelectedItem = findDataElementIndex(anItem);
|
||||
if (newSelectedItem == -1) {
|
||||
this.selectedItemIndex = -1;
|
||||
this.selectedItemValue = null;
|
||||
} else {
|
||||
this.selectedItemIndex = newSelectedItem;
|
||||
this.selectedItemValue = getElementAt(this.selectedItemIndex);
|
||||
}
|
||||
}
|
||||
fireListDataEvent(new ListDataEvent(this, 0, -1, -1));
|
||||
}
|
||||
|
||||
public void setSelectedItem(Object anItem) {
|
||||
if (anItem == null) {
|
||||
this.selectedItemIndex = -1;
|
||||
this.selectedItemValue = null;
|
||||
} else {
|
||||
int newSelectedItem = findElementIndex(anItem);
|
||||
if (newSelectedItem == -1) {
|
||||
if (isAllowOtherValue()) {
|
||||
this.selectedItemIndex = -1;
|
||||
this.selectedItemValue = anItem;
|
||||
} else {
|
||||
this.selectedItemIndex = -1;
|
||||
this.selectedItemValue = null;
|
||||
}
|
||||
} else {
|
||||
this.selectedItemIndex = newSelectedItem;
|
||||
this.selectedItemValue = getElementAt(this.selectedItemIndex);
|
||||
}
|
||||
}
|
||||
fireListDataEvent(new ListDataEvent(this, 0, -1, -1));
|
||||
}
|
||||
|
||||
private boolean isAllowOtherValue() {
|
||||
return this.allowOtherValue;
|
||||
}
|
||||
|
||||
public void setAllowOtherValue(boolean allowOtherValue) {
|
||||
this.allowOtherValue = allowOtherValue;
|
||||
}
|
||||
|
||||
public synchronized void addListDataListener(ListDataListener l) {
|
||||
if (l == null)
|
||||
throw new NullPointerException();
|
||||
this.listdatalistener.add(l);
|
||||
this.tempListeners = null;
|
||||
}
|
||||
|
||||
public Object getElementAt(int index) {
|
||||
if (index >= this.data.size())
|
||||
return null;
|
||||
ComboBoxItemPair datacon = (ComboBoxItemPair)this.data.get(index);
|
||||
if (datacon == null)
|
||||
return null;
|
||||
return datacon.getValue();
|
||||
}
|
||||
|
||||
public Object getKeyAt(int index) {
|
||||
if (index >= this.data.size())
|
||||
return null;
|
||||
if (index < 0)
|
||||
return null;
|
||||
ComboBoxItemPair datacon = (ComboBoxItemPair)this.data.get(index);
|
||||
if (datacon == null)
|
||||
return null;
|
||||
return datacon.getKey();
|
||||
}
|
||||
|
||||
public Object getSelectedKey() {
|
||||
return getKeyAt(this.selectedItemIndex);
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return this.data.size();
|
||||
}
|
||||
|
||||
public void removeListDataListener(ListDataListener l) {
|
||||
this.listdatalistener.remove(l);
|
||||
this.tempListeners = null;
|
||||
}
|
||||
|
||||
private int findDataElementIndex(Object anItem) {
|
||||
if (anItem == null)
|
||||
throw new NullPointerException("Item to find must not be null");
|
||||
for (int i = 0; i < this.data.size(); i++) {
|
||||
ComboBoxItemPair datacon = (ComboBoxItemPair)this.data.get(i);
|
||||
if (anItem.equals(datacon.getKey()))
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int findElementIndex(Object key) {
|
||||
if (key == null)
|
||||
throw new NullPointerException("Item to find must not be null");
|
||||
for (int i = 0; i < this.data.size(); i++) {
|
||||
ComboBoxItemPair datacon = (ComboBoxItemPair)this.data.get(i);
|
||||
if (key.equals(datacon.getValue()))
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void removeDataElement(Object key) {
|
||||
int idx = findDataElementIndex(key);
|
||||
if (idx == -1)
|
||||
return;
|
||||
this.data.remove(idx);
|
||||
ListDataEvent evt = new ListDataEvent(this, 2, idx, idx);
|
||||
fireListDataEvent(evt);
|
||||
}
|
||||
|
||||
public void add(Object key, Object cbitem) {
|
||||
ComboBoxItemPair con = new ComboBoxItemPair(key, cbitem);
|
||||
this.data.add(con);
|
||||
ListDataEvent evt = new ListDataEvent(this, 1, this.data.size() - 2, this.data.size() - 2);
|
||||
fireListDataEvent(evt);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
int size = getSize();
|
||||
this.data.clear();
|
||||
ListDataEvent evt = new ListDataEvent(this, 2, 0, size - 1);
|
||||
fireListDataEvent(evt);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
package org.jfree.ui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class L1R1ButtonPanel extends JPanel {
|
||||
private JButton left;
|
||||
|
||||
private JButton right;
|
||||
|
||||
public L1R1ButtonPanel(String leftLabel, String rightLabel) {
|
||||
setLayout(new BorderLayout());
|
||||
this.left = new JButton(leftLabel);
|
||||
this.right = new JButton(rightLabel);
|
||||
add(this.left, "West");
|
||||
add(this.right, "East");
|
||||
}
|
||||
|
||||
public JButton getLeftButton() {
|
||||
return this.left;
|
||||
}
|
||||
|
||||
public JButton getRightButton() {
|
||||
return this.right;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
package org.jfree.ui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.GridLayout;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class L1R2ButtonPanel extends JPanel {
|
||||
private JButton left;
|
||||
|
||||
private JButton right1;
|
||||
|
||||
private JButton right2;
|
||||
|
||||
public L1R2ButtonPanel(String label1, String label2, String label3) {
|
||||
setLayout(new BorderLayout());
|
||||
this.left = new JButton(label1);
|
||||
JPanel rightButtonPanel = new JPanel(new GridLayout(1, 2));
|
||||
this.right1 = new JButton(label2);
|
||||
this.right2 = new JButton(label3);
|
||||
rightButtonPanel.add(this.right1);
|
||||
rightButtonPanel.add(this.right2);
|
||||
add(this.left, "West");
|
||||
add(rightButtonPanel, "East");
|
||||
}
|
||||
|
||||
public JButton getLeftButton() {
|
||||
return this.left;
|
||||
}
|
||||
|
||||
public JButton getRightButton1() {
|
||||
return this.right1;
|
||||
}
|
||||
|
||||
public JButton getRightButton2() {
|
||||
return this.right2;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
package org.jfree.ui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class L1R3ButtonPanel extends JPanel {
|
||||
private JButton left;
|
||||
|
||||
private JButton right1;
|
||||
|
||||
private JButton right2;
|
||||
|
||||
private JButton right3;
|
||||
|
||||
public L1R3ButtonPanel(String label1, String label2, String label3, String label4) {
|
||||
setLayout(new BorderLayout());
|
||||
JPanel panel = new JPanel(new BorderLayout());
|
||||
JPanel panel2 = new JPanel(new BorderLayout());
|
||||
this.left = new JButton(label1);
|
||||
this.right1 = new JButton(label2);
|
||||
this.right2 = new JButton(label3);
|
||||
this.right3 = new JButton(label4);
|
||||
panel.add(this.left, "West");
|
||||
panel2.add(this.right1, "East");
|
||||
panel.add(panel2, "Center");
|
||||
panel.add(this.right2, "East");
|
||||
add(panel, "Center");
|
||||
add(this.right3, "East");
|
||||
}
|
||||
|
||||
public JButton getLeftButton() {
|
||||
return this.left;
|
||||
}
|
||||
|
||||
public JButton getRightButton1() {
|
||||
return this.right1;
|
||||
}
|
||||
|
||||
public JButton getRightButton2() {
|
||||
return this.right2;
|
||||
}
|
||||
|
||||
public JButton getRightButton3() {
|
||||
return this.right3;
|
||||
}
|
||||
}
|
||||
47
rus/WEB-INF/lib/jcommon-1.0.12_src/org/jfree/ui/Layer.java
Normal file
47
rus/WEB-INF/lib/jcommon-1.0.12_src/org/jfree/ui/Layer.java
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
package org.jfree.ui;
|
||||
|
||||
import java.io.ObjectStreamException;
|
||||
import java.io.Serializable;
|
||||
|
||||
public final class Layer implements Serializable {
|
||||
private static final long serialVersionUID = -1470104570733183430L;
|
||||
|
||||
public static final Layer FOREGROUND = new Layer("Layer.FOREGROUND");
|
||||
|
||||
public static final Layer BACKGROUND = new Layer("Layer.BACKGROUND");
|
||||
|
||||
private String name;
|
||||
|
||||
private Layer(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
return true;
|
||||
if (!(o instanceof Layer))
|
||||
return false;
|
||||
Layer layer = (Layer)o;
|
||||
if (!this.name.equals(layer.name))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return this.name.hashCode();
|
||||
}
|
||||
|
||||
private Object readResolve() throws ObjectStreamException {
|
||||
Layer result = null;
|
||||
if (equals(FOREGROUND)) {
|
||||
result = FOREGROUND;
|
||||
} else if (equals(BACKGROUND)) {
|
||||
result = BACKGROUND;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
package org.jfree.ui;
|
||||
|
||||
import java.io.ObjectStreamException;
|
||||
import java.io.Serializable;
|
||||
|
||||
public final class LengthAdjustmentType implements Serializable {
|
||||
private static final long serialVersionUID = -6097408511380545010L;
|
||||
|
||||
public static final LengthAdjustmentType NO_CHANGE = new LengthAdjustmentType("NO_CHANGE");
|
||||
|
||||
public static final LengthAdjustmentType EXPAND = new LengthAdjustmentType("EXPAND");
|
||||
|
||||
public static final LengthAdjustmentType CONTRACT = new LengthAdjustmentType("CONTRACT");
|
||||
|
||||
private String name;
|
||||
|
||||
private LengthAdjustmentType(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == this)
|
||||
return true;
|
||||
if (!(obj instanceof LengthAdjustmentType))
|
||||
return false;
|
||||
LengthAdjustmentType that = (LengthAdjustmentType)obj;
|
||||
if (!this.name.equals(that.name))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return this.name.hashCode();
|
||||
}
|
||||
|
||||
private Object readResolve() throws ObjectStreamException {
|
||||
if (equals(NO_CHANGE))
|
||||
return NO_CHANGE;
|
||||
if (equals(EXPAND))
|
||||
return EXPAND;
|
||||
if (equals(CONTRACT))
|
||||
return CONTRACT;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
package org.jfree.ui;
|
||||
|
||||
import javax.swing.text.AttributeSet;
|
||||
import javax.swing.text.BadLocationException;
|
||||
import javax.swing.text.PlainDocument;
|
||||
|
||||
public class LengthLimitingDocument extends PlainDocument {
|
||||
private int maxlen;
|
||||
|
||||
public LengthLimitingDocument() {
|
||||
this(-1);
|
||||
}
|
||||
|
||||
public LengthLimitingDocument(int maxlen) {
|
||||
this.maxlen = maxlen;
|
||||
}
|
||||
|
||||
public void setMaxLength(int maxlen) {
|
||||
this.maxlen = maxlen;
|
||||
}
|
||||
|
||||
public int getMaxLength() {
|
||||
return this.maxlen;
|
||||
}
|
||||
|
||||
public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
|
||||
if (str == null)
|
||||
return;
|
||||
if (this.maxlen < 0)
|
||||
super.insertString(offs, str, a);
|
||||
char[] numeric = str.toCharArray();
|
||||
StringBuffer b = new StringBuffer();
|
||||
b.append(numeric, 0, Math.min(this.maxlen, numeric.length));
|
||||
super.insertString(offs, b.toString(), a);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
# org.jfree.ui.ui ResourceBundle properties file
|
||||
#
|
||||
# Changes (from 31-Aug-2003)
|
||||
# --------------------------
|
||||
# 31-Aug-2003 : Initial version (AL);
|
||||
#
|
||||
|
||||
Attributes=Attributes:
|
||||
B=B:
|
||||
Bold=Bold
|
||||
Bottom=Bottom
|
||||
Font=Font:
|
||||
Insets=Insets:
|
||||
Italic=Italic
|
||||
L=L:
|
||||
Left=Left
|
||||
No_Font_Selected=No font selected.
|
||||
R=R:
|
||||
Right=Right
|
||||
Size=Size:
|
||||
T=T:
|
||||
Top=Top
|
||||
Help=Help
|
||||
OK=OK
|
||||
Cancel=Cancel
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
# org.jfree.ui.ui ResourceBundle properties file - german version
|
||||
#
|
||||
# Changes (from 31-Aug-2003)
|
||||
# --------------------------
|
||||
# 15-Mar-2004 : Initial version (Christian W. Zuckschwerdt);
|
||||
#
|
||||
|
||||
Attributes=Attribute:
|
||||
B=U:
|
||||
Bold=Fett
|
||||
Bottom=Unten
|
||||
Font=Schrift:
|
||||
Insets=R\u00e4nder:
|
||||
Italic=Kursiv
|
||||
L=L:
|
||||
Left=Links
|
||||
No_Font_Selected=Keine Schrift gew\u00e4hlt.
|
||||
R=R:
|
||||
Right=Rechts
|
||||
Size=Gr\u00f6\u00dfe:
|
||||
T=O:
|
||||
Top=Oben
|
||||
Help=Hilfe
|
||||
OK=OK
|
||||
Cancel=Abbrechen
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
# org.jfree.ui.ui ResourceBundle properties file spanish
|
||||
#
|
||||
# Changes (from 31-Aug-2003)
|
||||
# --------------------------
|
||||
# 14-Oct-2004 : Initial version: Leopoldo Federico Pértile (Grupo de Procesamiento Digital de Imágenes)
|
||||
# Universidad Tecnológica Nacional - Facultad Regional Resistencia, Argentina
|
||||
|
||||
Attributes=Atributos:
|
||||
B=Inf:
|
||||
Bold=Negrita
|
||||
Bottom=Inferior
|
||||
Font=Fuente:
|
||||
Insets=Márgenes:
|
||||
Italic=Cursiva
|
||||
L=Izq:
|
||||
Left=Izquierda
|
||||
No_Font_Selected=No se seleccion\00F3 ninguna fuente.
|
||||
R=Der:
|
||||
Right=Derecha
|
||||
Size=Tama\u00f1o:
|
||||
T=Sup:
|
||||
Top=Superior
|
||||
Help=Ayuda
|
||||
OK=Aceptar
|
||||
Cancel=Cancelar
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
# org.jfree.ui.ui ResourceBundle properties file - french version
|
||||
#
|
||||
# Changes (from 31-Aug-2003)
|
||||
# --------------------------
|
||||
# 31-Aug-2003 : Initial version (AL);
|
||||
#
|
||||
|
||||
Attributes=Attributs :
|
||||
B=B :
|
||||
Bold=Gras
|
||||
Bottom=Bas
|
||||
Font=Police :
|
||||
Insets=Position :
|
||||
Italic=Italique
|
||||
L=G :
|
||||
Left=Gauche
|
||||
No_Font_Selected=Aucune police n'a \u00E9t\u00E9 s\u00E9lectionn\u00E9e.
|
||||
R=D :
|
||||
Right=Droite
|
||||
Size=Taille :
|
||||
T=H :
|
||||
Top=Haut
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
# org.jfree.chart.ChartPanel ResourceBundle properties file - portuguese version
|
||||
#
|
||||
# Changes (from 09-Set-2003)
|
||||
# --------------------------
|
||||
# 09-Set-2003 : Initial version (Eduardo Ramalho);
|
||||
#
|
||||
|
||||
Attributes=Atributos:
|
||||
B=B:
|
||||
Bold=Negrito
|
||||
Bottom=Fundo
|
||||
Font=Fonte:
|
||||
Insets=Posi\u00e7\u00e3o:
|
||||
Italic=It\u00e1lico
|
||||
L=E:
|
||||
Left=Esquerda
|
||||
No_Font_Selected=Nenhuma fonte est\u00e1 seleccionada.
|
||||
R=D:
|
||||
Right=Direita
|
||||
Size=Tamanho:
|
||||
T=T:
|
||||
Top=Topo
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
package org.jfree.ui;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.text.NumberFormat;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.table.DefaultTableCellRenderer;
|
||||
|
||||
public class NumberCellRenderer extends DefaultTableCellRenderer {
|
||||
public NumberCellRenderer() {
|
||||
setHorizontalAlignment(4);
|
||||
}
|
||||
|
||||
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
|
||||
setFont(null);
|
||||
NumberFormat nf = NumberFormat.getNumberInstance();
|
||||
if (value != null) {
|
||||
setText(nf.format(value));
|
||||
} else {
|
||||
setText("");
|
||||
}
|
||||
if (isSelected) {
|
||||
setBackground(table.getSelectionBackground());
|
||||
} else {
|
||||
setBackground(null);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
package org.jfree.ui;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Container;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Insets;
|
||||
import java.awt.LayoutManager;
|
||||
import java.awt.Rectangle;
|
||||
|
||||
public final class OverlayLayout implements LayoutManager {
|
||||
private boolean ignoreInvisible;
|
||||
|
||||
public OverlayLayout(boolean ignoreInvisible) {
|
||||
this.ignoreInvisible = ignoreInvisible;
|
||||
}
|
||||
|
||||
public OverlayLayout() {}
|
||||
|
||||
public void addLayoutComponent(String name, Component comp) {}
|
||||
|
||||
public void removeLayoutComponent(Component comp) {}
|
||||
|
||||
public void layoutContainer(Container parent) {
|
||||
synchronized (parent.getTreeLock()) {
|
||||
Insets ins = parent.getInsets();
|
||||
Rectangle bounds = parent.getBounds();
|
||||
int width = bounds.width - ins.left - ins.right;
|
||||
int height = bounds.height - ins.top - ins.bottom;
|
||||
Component[] comps = parent.getComponents();
|
||||
for (int i = 0; i < comps.length; i++) {
|
||||
Component c = comps[i];
|
||||
if (comps[i].isVisible() || !this.ignoreInvisible)
|
||||
c.setBounds(ins.left, ins.top, width, height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Dimension minimumLayoutSize(Container parent) {
|
||||
synchronized (parent.getTreeLock()) {
|
||||
Insets ins = parent.getInsets();
|
||||
Component[] comps = parent.getComponents();
|
||||
int height = 0;
|
||||
int width = 0;
|
||||
for (int i = 0; i < comps.length; i++) {
|
||||
if (comps[i].isVisible() || !this.ignoreInvisible) {
|
||||
Dimension pref = comps[i].getMinimumSize();
|
||||
if (pref.height > height)
|
||||
height = pref.height;
|
||||
if (pref.width > width)
|
||||
width = pref.width;
|
||||
}
|
||||
}
|
||||
return new Dimension(width + ins.left + ins.right, height + ins.top + ins.bottom);
|
||||
}
|
||||
}
|
||||
|
||||
public Dimension preferredLayoutSize(Container parent) {
|
||||
synchronized (parent.getTreeLock()) {
|
||||
Insets ins = parent.getInsets();
|
||||
Component[] comps = parent.getComponents();
|
||||
int height = 0;
|
||||
int width = 0;
|
||||
for (int i = 0; i < comps.length; i++) {
|
||||
if (comps[i].isVisible() || !this.ignoreInvisible) {
|
||||
Dimension pref = comps[i].getPreferredSize();
|
||||
if (pref.height > height)
|
||||
height = pref.height;
|
||||
if (pref.width > width)
|
||||
width = pref.width;
|
||||
}
|
||||
}
|
||||
return new Dimension(width + ins.left + ins.right, height + ins.top + ins.bottom);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
package org.jfree.ui;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Insets;
|
||||
import java.awt.Paint;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import javax.swing.JComponent;
|
||||
|
||||
public class PaintSample extends JComponent {
|
||||
private Paint paint;
|
||||
|
||||
private Dimension preferredSize;
|
||||
|
||||
public PaintSample(Paint paint) {
|
||||
this.paint = paint;
|
||||
this.preferredSize = new Dimension(80, 12);
|
||||
}
|
||||
|
||||
public Paint getPaint() {
|
||||
return this.paint;
|
||||
}
|
||||
|
||||
public void setPaint(Paint paint) {
|
||||
this.paint = paint;
|
||||
repaint();
|
||||
}
|
||||
|
||||
public Dimension getPreferredSize() {
|
||||
return this.preferredSize;
|
||||
}
|
||||
|
||||
public void paintComponent(Graphics g) {
|
||||
Graphics2D g2 = (Graphics2D)g;
|
||||
Dimension size = getSize();
|
||||
Insets insets = getInsets();
|
||||
double xx = (double)insets.left;
|
||||
double yy = (double)insets.top;
|
||||
double ww = size.getWidth() - (double)insets.left - (double)insets.right - 1.0D;
|
||||
double hh = size.getHeight() - (double)insets.top - (double)insets.bottom - 1.0D;
|
||||
Rectangle2D area = new Rectangle2D.Double(xx, yy, ww, hh);
|
||||
g2.setPaint(this.paint);
|
||||
g2.fill(area);
|
||||
g2.setPaint(Color.black);
|
||||
g2.draw(area);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,127 @@
|
|||
package org.jfree.ui;
|
||||
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.io.ObjectStreamException;
|
||||
import java.io.Serializable;
|
||||
|
||||
public final class RectangleAnchor implements Serializable {
|
||||
private static final long serialVersionUID = -2457494205644416327L;
|
||||
|
||||
public static final RectangleAnchor CENTER = new RectangleAnchor("RectangleAnchor.CENTER");
|
||||
|
||||
public static final RectangleAnchor TOP = new RectangleAnchor("RectangleAnchor.TOP");
|
||||
|
||||
public static final RectangleAnchor TOP_LEFT = new RectangleAnchor("RectangleAnchor.TOP_LEFT");
|
||||
|
||||
public static final RectangleAnchor TOP_RIGHT = new RectangleAnchor("RectangleAnchor.TOP_RIGHT");
|
||||
|
||||
public static final RectangleAnchor BOTTOM = new RectangleAnchor("RectangleAnchor.BOTTOM");
|
||||
|
||||
public static final RectangleAnchor BOTTOM_LEFT = new RectangleAnchor("RectangleAnchor.BOTTOM_LEFT");
|
||||
|
||||
public static final RectangleAnchor BOTTOM_RIGHT = new RectangleAnchor("RectangleAnchor.BOTTOM_RIGHT");
|
||||
|
||||
public static final RectangleAnchor LEFT = new RectangleAnchor("RectangleAnchor.LEFT");
|
||||
|
||||
public static final RectangleAnchor RIGHT = new RectangleAnchor("RectangleAnchor.RIGHT");
|
||||
|
||||
private String name;
|
||||
|
||||
private RectangleAnchor(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (!(obj instanceof RectangleAnchor))
|
||||
return false;
|
||||
RectangleAnchor order = (RectangleAnchor)obj;
|
||||
if (!this.name.equals(order.name))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return this.name.hashCode();
|
||||
}
|
||||
|
||||
public static Point2D coordinates(Rectangle2D rectangle, RectangleAnchor anchor) {
|
||||
Point2D result = new Point2D.Double();
|
||||
if (anchor == CENTER) {
|
||||
result.setLocation(rectangle.getCenterX(), rectangle.getCenterY());
|
||||
} else if (anchor == TOP) {
|
||||
result.setLocation(rectangle.getCenterX(), rectangle.getMinY());
|
||||
} else if (anchor == BOTTOM) {
|
||||
result.setLocation(rectangle.getCenterX(), rectangle.getMaxY());
|
||||
} else if (anchor == LEFT) {
|
||||
result.setLocation(rectangle.getMinX(), rectangle.getCenterY());
|
||||
} else if (anchor == RIGHT) {
|
||||
result.setLocation(rectangle.getMaxX(), rectangle.getCenterY());
|
||||
} else if (anchor == TOP_LEFT) {
|
||||
result.setLocation(rectangle.getMinX(), rectangle.getMinY());
|
||||
} else if (anchor == TOP_RIGHT) {
|
||||
result.setLocation(rectangle.getMaxX(), rectangle.getMinY());
|
||||
} else if (anchor == BOTTOM_LEFT) {
|
||||
result.setLocation(rectangle.getMinX(), rectangle.getMaxY());
|
||||
} else if (anchor == BOTTOM_RIGHT) {
|
||||
result.setLocation(rectangle.getMaxX(), rectangle.getMaxY());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Rectangle2D createRectangle(Size2D dimensions, double anchorX, double anchorY, RectangleAnchor anchor) {
|
||||
Rectangle2D result = null;
|
||||
double w = dimensions.getWidth();
|
||||
double h = dimensions.getHeight();
|
||||
if (anchor == CENTER) {
|
||||
result = new Rectangle2D.Double(anchorX - w / 2.0D, anchorY - h / 2.0D, w, h);
|
||||
} else if (anchor == TOP) {
|
||||
result = new Rectangle2D.Double(anchorX - w / 2.0D, anchorY - h / 2.0D, w, h);
|
||||
} else if (anchor == BOTTOM) {
|
||||
result = new Rectangle2D.Double(anchorX - w / 2.0D, anchorY - h / 2.0D, w, h);
|
||||
} else if (anchor == LEFT) {
|
||||
result = new Rectangle2D.Double(anchorX, anchorY - h / 2.0D, w, h);
|
||||
} else if (anchor == RIGHT) {
|
||||
result = new Rectangle2D.Double(anchorX - w, anchorY - h / 2.0D, w, h);
|
||||
} else if (anchor == TOP_LEFT) {
|
||||
result = new Rectangle2D.Double(anchorX - w / 2.0D, anchorY - h / 2.0D, w, h);
|
||||
} else if (anchor == TOP_RIGHT) {
|
||||
result = new Rectangle2D.Double(anchorX - w / 2.0D, anchorY - h / 2.0D, w, h);
|
||||
} else if (anchor == BOTTOM_LEFT) {
|
||||
result = new Rectangle2D.Double(anchorX - w / 2.0D, anchorY - h / 2.0D, w, h);
|
||||
} else if (anchor == BOTTOM_RIGHT) {
|
||||
result = new Rectangle2D.Double(anchorX - w / 2.0D, anchorY - h / 2.0D, w, h);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private Object readResolve() throws ObjectStreamException {
|
||||
RectangleAnchor result = null;
|
||||
if (equals(CENTER)) {
|
||||
result = CENTER;
|
||||
} else if (equals(TOP)) {
|
||||
result = TOP;
|
||||
} else if (equals(BOTTOM)) {
|
||||
result = BOTTOM;
|
||||
} else if (equals(LEFT)) {
|
||||
result = LEFT;
|
||||
} else if (equals(RIGHT)) {
|
||||
result = RIGHT;
|
||||
} else if (equals(TOP_LEFT)) {
|
||||
result = TOP_LEFT;
|
||||
} else if (equals(TOP_RIGHT)) {
|
||||
result = TOP_RIGHT;
|
||||
} else if (equals(BOTTOM_LEFT)) {
|
||||
result = BOTTOM_LEFT;
|
||||
} else if (equals(BOTTOM_RIGHT)) {
|
||||
result = BOTTOM_RIGHT;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
package org.jfree.ui;
|
||||
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.io.ObjectStreamException;
|
||||
import java.io.Serializable;
|
||||
|
||||
public final class RectangleEdge implements Serializable {
|
||||
private static final long serialVersionUID = -7400988293691093548L;
|
||||
|
||||
public static final RectangleEdge TOP = new RectangleEdge("RectangleEdge.TOP");
|
||||
|
||||
public static final RectangleEdge BOTTOM = new RectangleEdge("RectangleEdge.BOTTOM");
|
||||
|
||||
public static final RectangleEdge LEFT = new RectangleEdge("RectangleEdge.LEFT");
|
||||
|
||||
public static final RectangleEdge RIGHT = new RectangleEdge("RectangleEdge.RIGHT");
|
||||
|
||||
private String name;
|
||||
|
||||
private RectangleEdge(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
return true;
|
||||
if (!(o instanceof RectangleEdge))
|
||||
return false;
|
||||
RectangleEdge order = (RectangleEdge)o;
|
||||
if (!this.name.equals(order.name))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return this.name.hashCode();
|
||||
}
|
||||
|
||||
public static boolean isTopOrBottom(RectangleEdge edge) {
|
||||
return (edge == TOP || edge == BOTTOM);
|
||||
}
|
||||
|
||||
public static boolean isLeftOrRight(RectangleEdge edge) {
|
||||
return (edge == LEFT || edge == RIGHT);
|
||||
}
|
||||
|
||||
public static RectangleEdge opposite(RectangleEdge edge) {
|
||||
RectangleEdge result = null;
|
||||
if (edge == TOP) {
|
||||
result = BOTTOM;
|
||||
} else if (edge == BOTTOM) {
|
||||
result = TOP;
|
||||
} else if (edge == LEFT) {
|
||||
result = RIGHT;
|
||||
} else if (edge == RIGHT) {
|
||||
result = LEFT;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static double coordinate(Rectangle2D rectangle, RectangleEdge edge) {
|
||||
double result = 0.0D;
|
||||
if (edge == TOP) {
|
||||
result = rectangle.getMinY();
|
||||
} else if (edge == BOTTOM) {
|
||||
result = rectangle.getMaxY();
|
||||
} else if (edge == LEFT) {
|
||||
result = rectangle.getMinX();
|
||||
} else if (edge == RIGHT) {
|
||||
result = rectangle.getMaxX();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private Object readResolve() throws ObjectStreamException {
|
||||
RectangleEdge result = null;
|
||||
if (equals(TOP)) {
|
||||
result = TOP;
|
||||
} else if (equals(BOTTOM)) {
|
||||
result = BOTTOM;
|
||||
} else if (equals(LEFT)) {
|
||||
result = LEFT;
|
||||
} else if (equals(RIGHT)) {
|
||||
result = RIGHT;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,249 @@
|
|||
package org.jfree.ui;
|
||||
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.io.Serializable;
|
||||
import org.jfree.util.UnitType;
|
||||
|
||||
public class RectangleInsets implements Serializable {
|
||||
private static final long serialVersionUID = 1902273207559319996L;
|
||||
|
||||
public static final RectangleInsets ZERO_INSETS = new RectangleInsets(UnitType.ABSOLUTE, 0.0D, 0.0D, 0.0D, 0.0D);
|
||||
|
||||
private UnitType unitType;
|
||||
|
||||
private double top;
|
||||
|
||||
private double left;
|
||||
|
||||
private double bottom;
|
||||
|
||||
private double right;
|
||||
|
||||
public RectangleInsets() {
|
||||
this(1.0D, 1.0D, 1.0D, 1.0D);
|
||||
}
|
||||
|
||||
public RectangleInsets(double top, double left, double bottom, double right) {
|
||||
this(UnitType.ABSOLUTE, top, left, bottom, right);
|
||||
}
|
||||
|
||||
public RectangleInsets(UnitType unitType, double top, double left, double bottom, double right) {
|
||||
if (unitType == null)
|
||||
throw new IllegalArgumentException("Null 'unitType' argument.");
|
||||
this.unitType = unitType;
|
||||
this.top = top;
|
||||
this.bottom = bottom;
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
public UnitType getUnitType() {
|
||||
return this.unitType;
|
||||
}
|
||||
|
||||
public double getTop() {
|
||||
return this.top;
|
||||
}
|
||||
|
||||
public double getBottom() {
|
||||
return this.bottom;
|
||||
}
|
||||
|
||||
public double getLeft() {
|
||||
return this.left;
|
||||
}
|
||||
|
||||
public double getRight() {
|
||||
return this.right;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == this)
|
||||
return true;
|
||||
if (!(obj instanceof RectangleInsets))
|
||||
return false;
|
||||
RectangleInsets that = (RectangleInsets)obj;
|
||||
if (that.unitType != this.unitType)
|
||||
return false;
|
||||
if (this.left != that.left)
|
||||
return false;
|
||||
if (this.right != that.right)
|
||||
return false;
|
||||
if (this.top != that.top)
|
||||
return false;
|
||||
if (this.bottom != that.bottom)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int result = (this.unitType != null) ? this.unitType.hashCode() : 0;
|
||||
long temp = (this.top != 0.0D) ? Double.doubleToLongBits(this.top) : 0L;
|
||||
result = 29 * result + (int)(temp ^ temp >>> 32L);
|
||||
temp = (this.bottom != 0.0D) ? Double.doubleToLongBits(this.bottom) : 0L;
|
||||
result = 29 * result + (int)(temp ^ temp >>> 32L);
|
||||
temp = (this.left != 0.0D) ? Double.doubleToLongBits(this.left) : 0L;
|
||||
result = 29 * result + (int)(temp ^ temp >>> 32L);
|
||||
temp = (this.right != 0.0D) ? Double.doubleToLongBits(this.right) : 0L;
|
||||
result = 29 * result + (int)(temp ^ temp >>> 32L);
|
||||
return result;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "RectangleInsets[t=" + this.top + ",l=" + this.left + ",b=" + this.bottom + ",r=" + this.right + "]";
|
||||
}
|
||||
|
||||
public Rectangle2D createAdjustedRectangle(Rectangle2D base, LengthAdjustmentType horizontal, LengthAdjustmentType vertical) {
|
||||
if (base == null)
|
||||
throw new IllegalArgumentException("Null 'base' argument.");
|
||||
double x = base.getX();
|
||||
double y = base.getY();
|
||||
double w = base.getWidth();
|
||||
double h = base.getHeight();
|
||||
if (horizontal == LengthAdjustmentType.EXPAND) {
|
||||
double leftOutset = calculateLeftOutset(w);
|
||||
x -= leftOutset;
|
||||
w = w + leftOutset + calculateRightOutset(w);
|
||||
} else if (horizontal == LengthAdjustmentType.CONTRACT) {
|
||||
double leftMargin = calculateLeftInset(w);
|
||||
x += leftMargin;
|
||||
w = w - leftMargin - calculateRightInset(w);
|
||||
}
|
||||
if (vertical == LengthAdjustmentType.EXPAND) {
|
||||
double topMargin = calculateTopOutset(h);
|
||||
y -= topMargin;
|
||||
h = h + topMargin + calculateBottomOutset(h);
|
||||
} else if (vertical == LengthAdjustmentType.CONTRACT) {
|
||||
double topMargin = calculateTopInset(h);
|
||||
y += topMargin;
|
||||
h = h - topMargin - calculateBottomInset(h);
|
||||
}
|
||||
return new Rectangle2D.Double(x, y, w, h);
|
||||
}
|
||||
|
||||
public Rectangle2D createInsetRectangle(Rectangle2D base) {
|
||||
return createInsetRectangle(base, true, true);
|
||||
}
|
||||
|
||||
public Rectangle2D createInsetRectangle(Rectangle2D base, boolean horizontal, boolean vertical) {
|
||||
if (base == null)
|
||||
throw new IllegalArgumentException("Null 'base' argument.");
|
||||
double topMargin = 0.0D;
|
||||
double bottomMargin = 0.0D;
|
||||
if (vertical) {
|
||||
topMargin = calculateTopInset(base.getHeight());
|
||||
bottomMargin = calculateBottomInset(base.getHeight());
|
||||
}
|
||||
double leftMargin = 0.0D;
|
||||
double rightMargin = 0.0D;
|
||||
if (horizontal) {
|
||||
leftMargin = calculateLeftInset(base.getWidth());
|
||||
rightMargin = calculateRightInset(base.getWidth());
|
||||
}
|
||||
return new Rectangle2D.Double(base.getX() + leftMargin, base.getY() + topMargin, base.getWidth() - leftMargin - rightMargin, base.getHeight() - topMargin - bottomMargin);
|
||||
}
|
||||
|
||||
public Rectangle2D createOutsetRectangle(Rectangle2D base) {
|
||||
return createOutsetRectangle(base, true, true);
|
||||
}
|
||||
|
||||
public Rectangle2D createOutsetRectangle(Rectangle2D base, boolean horizontal, boolean vertical) {
|
||||
if (base == null)
|
||||
throw new IllegalArgumentException("Null 'base' argument.");
|
||||
double topMargin = 0.0D;
|
||||
double bottomMargin = 0.0D;
|
||||
if (vertical) {
|
||||
topMargin = calculateTopOutset(base.getHeight());
|
||||
bottomMargin = calculateBottomOutset(base.getHeight());
|
||||
}
|
||||
double leftMargin = 0.0D;
|
||||
double rightMargin = 0.0D;
|
||||
if (horizontal) {
|
||||
leftMargin = calculateLeftOutset(base.getWidth());
|
||||
rightMargin = calculateRightOutset(base.getWidth());
|
||||
}
|
||||
return new Rectangle2D.Double(base.getX() - leftMargin, base.getY() - topMargin, base.getWidth() + leftMargin + rightMargin, base.getHeight() + topMargin + bottomMargin);
|
||||
}
|
||||
|
||||
public double calculateTopInset(double height) {
|
||||
double result = this.top;
|
||||
if (this.unitType == UnitType.RELATIVE)
|
||||
result = this.top * height;
|
||||
return result;
|
||||
}
|
||||
|
||||
public double calculateTopOutset(double height) {
|
||||
double result = this.top;
|
||||
if (this.unitType == UnitType.RELATIVE)
|
||||
result = height / (1.0D - this.top - this.bottom) * this.top;
|
||||
return result;
|
||||
}
|
||||
|
||||
public double calculateBottomInset(double height) {
|
||||
double result = this.bottom;
|
||||
if (this.unitType == UnitType.RELATIVE)
|
||||
result = this.bottom * height;
|
||||
return result;
|
||||
}
|
||||
|
||||
public double calculateBottomOutset(double height) {
|
||||
double result = this.bottom;
|
||||
if (this.unitType == UnitType.RELATIVE)
|
||||
result = height / (1.0D - this.top - this.bottom) * this.bottom;
|
||||
return result;
|
||||
}
|
||||
|
||||
public double calculateLeftInset(double width) {
|
||||
double result = this.left;
|
||||
if (this.unitType == UnitType.RELATIVE)
|
||||
result = this.left * width;
|
||||
return result;
|
||||
}
|
||||
|
||||
public double calculateLeftOutset(double width) {
|
||||
double result = this.left;
|
||||
if (this.unitType == UnitType.RELATIVE)
|
||||
result = width / (1.0D - this.left - this.right) * this.left;
|
||||
return result;
|
||||
}
|
||||
|
||||
public double calculateRightInset(double width) {
|
||||
double result = this.right;
|
||||
if (this.unitType == UnitType.RELATIVE)
|
||||
result = this.right * width;
|
||||
return result;
|
||||
}
|
||||
|
||||
public double calculateRightOutset(double width) {
|
||||
double result = this.right;
|
||||
if (this.unitType == UnitType.RELATIVE)
|
||||
result = width / (1.0D - this.left - this.right) * this.right;
|
||||
return result;
|
||||
}
|
||||
|
||||
public double trimWidth(double width) {
|
||||
return width - calculateLeftInset(width) - calculateRightInset(width);
|
||||
}
|
||||
|
||||
public double extendWidth(double width) {
|
||||
return width + calculateLeftOutset(width) + calculateRightOutset(width);
|
||||
}
|
||||
|
||||
public double trimHeight(double height) {
|
||||
return height - calculateTopInset(height) - calculateBottomInset(height);
|
||||
}
|
||||
|
||||
public double extendHeight(double height) {
|
||||
return height + calculateTopOutset(height) + calculateBottomOutset(height);
|
||||
}
|
||||
|
||||
public void trim(Rectangle2D area) {
|
||||
double w = area.getWidth();
|
||||
double h = area.getHeight();
|
||||
double l = calculateLeftInset(w);
|
||||
double r = calculateRightInset(w);
|
||||
double t = calculateTopInset(h);
|
||||
double b = calculateBottomInset(h);
|
||||
area.setRect(area.getX() + l, area.getY() + t, w - l - r, h - t - b);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,117 @@
|
|||
package org.jfree.ui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Container;
|
||||
import java.awt.Dialog;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.Window;
|
||||
import java.lang.reflect.Method;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.table.TableColumn;
|
||||
import javax.swing.table.TableModel;
|
||||
|
||||
public class RefineryUtilities {
|
||||
public static Point getCenterPoint() {
|
||||
GraphicsEnvironment localGraphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
try {
|
||||
Method method = GraphicsEnvironment.class.getMethod("getCenterPoint", null);
|
||||
return (Point)method.invoke(localGraphicsEnvironment, null);
|
||||
} catch (Exception e) {
|
||||
Dimension s = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
return new Point(s.width / 2, s.height / 2);
|
||||
}
|
||||
}
|
||||
|
||||
public static Rectangle getMaximumWindowBounds() {
|
||||
GraphicsEnvironment localGraphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
try {
|
||||
Method method = GraphicsEnvironment.class.getMethod("getMaximumWindowBounds", null);
|
||||
return (Rectangle)method.invoke(localGraphicsEnvironment, null);
|
||||
} catch (Exception e) {
|
||||
Dimension s = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
return new Rectangle(0, 0, s.width, s.height);
|
||||
}
|
||||
}
|
||||
|
||||
public static void centerFrameOnScreen(Window frame) {
|
||||
positionFrameOnScreen(frame, 0.5D, 0.5D);
|
||||
}
|
||||
|
||||
public static void positionFrameOnScreen(Window frame, double horizontalPercent, double verticalPercent) {
|
||||
Rectangle s = getMaximumWindowBounds();
|
||||
Dimension f = frame.getSize();
|
||||
int w = Math.max(s.width - f.width, 0);
|
||||
int h = Math.max(s.height - f.height, 0);
|
||||
int x = (int)(horizontalPercent * (double)w) + s.x;
|
||||
int y = (int)(verticalPercent * (double)h) + s.y;
|
||||
frame.setBounds(x, y, f.width, f.height);
|
||||
}
|
||||
|
||||
public static void positionFrameRandomly(Window frame) {
|
||||
positionFrameOnScreen(frame, Math.random(), Math.random());
|
||||
}
|
||||
|
||||
public static void centerDialogInParent(Dialog dialog) {
|
||||
positionDialogRelativeToParent(dialog, 0.5D, 0.5D);
|
||||
}
|
||||
|
||||
public static void positionDialogRelativeToParent(Dialog dialog, double horizontalPercent, double verticalPercent) {
|
||||
Dimension d = dialog.getSize();
|
||||
Container parent = dialog.getParent();
|
||||
Dimension p = parent.getSize();
|
||||
int baseX = parent.getX() - d.width;
|
||||
int baseY = parent.getY() - d.height;
|
||||
int w = d.width + p.width;
|
||||
int h = d.height + p.height;
|
||||
int x = baseX + (int)(horizontalPercent * (double)w);
|
||||
int y = baseY + (int)(verticalPercent * (double)h);
|
||||
Rectangle s = getMaximumWindowBounds();
|
||||
x = Math.min(x, s.width - d.width);
|
||||
x = Math.max(x, 0);
|
||||
y = Math.min(y, s.height - d.height);
|
||||
y = Math.max(y, 0);
|
||||
dialog.setBounds(x + s.x, y + s.y, d.width, d.height);
|
||||
}
|
||||
|
||||
public static JPanel createTablePanel(TableModel model) {
|
||||
JPanel panel = new JPanel(new BorderLayout());
|
||||
JTable table = new JTable(model);
|
||||
for (int columnIndex = 0; columnIndex < model.getColumnCount(); columnIndex++) {
|
||||
TableColumn column = table.getColumnModel().getColumn(columnIndex);
|
||||
Class c = model.getColumnClass(columnIndex);
|
||||
if (c.equals(Number.class))
|
||||
column.setCellRenderer(new NumberCellRenderer());
|
||||
}
|
||||
panel.add(new JScrollPane(table));
|
||||
return panel;
|
||||
}
|
||||
|
||||
public static JLabel createJLabel(String text, Font font) {
|
||||
JLabel result = new JLabel(text);
|
||||
result.setFont(font);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static JLabel createJLabel(String text, Font font, Color color) {
|
||||
JLabel result = new JLabel(text);
|
||||
result.setFont(font);
|
||||
result.setForeground(color);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static JButton createJButton(String label, Font font) {
|
||||
JButton result = new JButton(label);
|
||||
result.setFont(font);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue