Update of /cvsroot/squirrel-sql/mavenize/thirdparty-non-maven/tinylaf-1_4_0/src/de/muntjak/tinylookandfeel/util
In directory sfp-cvsdas-3.v30.ch3.sourceforge.com:/tmp/cvs-serv29130/thirdparty-non-maven/tinylaf-1_4_0/src/de/muntjak/tinylookandfeel/util
Added Files:
IntReference.java package.html ColoredFont.java
BooleanReference.java SBReference.java HSBReference.java
ColorRoutines.java DrawRoutines.java
Log Message:
Source for thirdparty dependency. Maven central requires a valid source code repository for artifacts that it hosts. This project has none, so we host it here for the time being.
--- NEW FILE: ColoredFont.java ---
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* This file is part of the Tiny Look and Feel *
* Copyright 2003 - 2008 Hans Bickel *
* *
* For licensing information and credits, please refer to the *
* comment in file de.muntjak.tinylookandfeel.TinyLookAndFeel *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
package de.muntjak.tinylookandfeel.util;
import java.awt.*;
import java.io.*;
import java.util.Vector;
import javax.swing.plaf.*;
import de.muntjak.tinylookandfeel.Theme;
/**
* ColoredFont describes a (mutable) font and an optional (text) color.
* The class is used to specify, for example, the font and text color
* used by buttons.
*
*
* @version 1.0
* @author Hans Bickel
*/
public class ColoredFont {
private SBReference sbReference;
private FontUIResource font;
private boolean isPlainFont, isBoldFont;
/**
* Copy constructor.
* @param other
*/
public ColoredFont(ColoredFont other) {
font = new FontUIResource(other.font);
if(other.sbReference != null) {
sbReference = new SBReference(other.sbReference);
}
isPlainFont = other.isPlainFont;
isBoldFont = other.isBoldFont;
}
/**
* Constructs a new ColoredFont using the passed arguments.
* @param fontFamily
* @param style
* @param size
*/
public ColoredFont(String fontFamily, int style, int size) {
font = new FontUIResource(Theme.getPlatformFont(fontFamily), style, size);
}
/**
* Construcor for Plain Fonts without a color reference.
*
*/
public ColoredFont() {
font = new FontUIResource(Theme.getPlatformFont("Tahoma"), Font.PLAIN, 11);
isPlainFont = true;
}
/**
* Construcor for Plain Fonts.
* @param ref the color reference of this font
*
*/
public ColoredFont(SBReference ref) {
this("Tahoma", Font.PLAIN, 11, ref);
isPlainFont = true;
}
private ColoredFont(String fontFamily, int style, int size, SBReference sbReference) {
font = new FontUIResource(Theme.getPlatformFont(fontFamily), style, size);
this.sbReference = sbReference;
}
public void update(String fontFamily, int style, int size) {
font = new FontUIResource(Theme.getPlatformFont(fontFamily), style, size);
}
/**
* Updates a ColoredFont to be a Plain Font,
* @param sbReference
*/
public void update(SBReference sbReference) {
font = new FontUIResource(Theme.getPlatformFont("Tahoma"), Font.PLAIN, 11);
this.sbReference = sbReference;
isPlainFont = true;
}
/**
* Sets up this ColoredFont to be identical to argument.
* @param other
*/
public void update(ColoredFont other) {
font = new FontUIResource(other.font);
isPlainFont = other.isPlainFont;
isBoldFont = other.isBoldFont;
if(other.sbReference != null) {
sbReference.setBrightness(other.sbReference.getBrightness());
sbReference.setLocked(other.sbReference.isLocked());
sbReference.setReference(other.sbReference.getReference());
sbReference.setSaturation(other.sbReference.getSaturation());
sbReference.setColor(other.sbReference.getColor());
}
}
public void update(ColoredFont other, Vector referenceColors) {
font = new FontUIResource(other.font);
isPlainFont = other.isPlainFont;
isBoldFont = other.isBoldFont;
if(other.sbReference != null) {
sbReference.update(other.sbReference, referenceColors);
}
}
public void setPlainFont(boolean b) {
isPlainFont = b;
if(b) isBoldFont = false;
}
public void setBoldFont(boolean b) {
isBoldFont = b;
if(b) isPlainFont = false;
}
public boolean isPlainFont() {
return isPlainFont;
}
public boolean isBoldFont() {
return isBoldFont;
}
public void setFont(String fontFamily, int style, int size) {
font = new FontUIResource(fontFamily, style, size);
}
public void setFont(Font font) {
this.font = new FontUIResource(font);
}
public void setFont(FontUIResource font) {
this.font = font;
}
public FontUIResource getFont() {
if(isPlainFont) {
return Theme.plainFont.font;
}
if(isBoldFont) {
return Theme.boldFont.font;
}
return font;
}
public SBReference getSBReference() {
return sbReference;
}
public void setSBReference(SBReference sbReference) {
this.sbReference = sbReference;
}
public void save(DataOutputStream out) throws IOException {
out.writeUTF(font.getFamily());
out.writeBoolean(font.isBold());
out.writeInt(font.getSize());
out.writeBoolean(isPlainFont);
out.writeBoolean(isBoldFont);
}
public void load(DataInputStream in) throws IOException {
font = new FontUIResource(Theme.getPlatformFont(in.readUTF()),
(in.readBoolean() ? Font.BOLD : Font.PLAIN),
in.readInt());
isPlainFont = in.readBoolean();
isBoldFont = in.readBoolean();
}
public static void loadDummyData(DataInputStream in) throws IOException {
in.readUTF();
in.readBoolean();
in.readInt();
in.readBoolean();
in.readBoolean();
}
public String toString() {
return "ColoredFont[ref=" +
(sbReference == null ? "null" : sbReference.toString()) +
",font=" + font + "]";
}
}
--- NEW FILE: DrawRoutines.java ---
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* This file is part of the Tiny Look and Feel *
* Copyright 2003 - 2008 Hans Bickel *
* *
* For licensing information and credits, please refer to the *
* comment in file de.muntjak.tinylookandfeel.TinyLookAndFeel *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
package de.muntjak.tinylookandfeel.util;
import java.awt.*;
import java.awt.image.*;
import javax.swing.*;
import de.muntjak.tinylookandfeel.Theme;
import de.muntjak.tinylookandfeel.TinyLookAndFeel;
import de.muntjak.tinylookandfeel.controlpanel.SBChooser;
/**
* DrawRoutines is a collection of static methods related
* to drawing.
*
* @version 1.0
* @author Hans Bickel
*/
public class DrawRoutines {
static final int[][] checkA = {
{53, 66, 78, 99, 115, 136, 144, 156, 165, 177, 189},
{66, 78, 99, 115, 136, 144, 156, 165, 177, 189, 202},
{78, 99, 0, 0, 0, 0, 0, 0, 0, 202, 210},
{99, 115, 0, 0, 0, 0, 0, 0, 0, 210, 214},
{115, 136, 0, 0, 0, 0, 0, 0, 0, 214, 226},
{136, 144, 0, 0, 0, 0, 0, 0, 0, 226, 230},
{144, 156, 0, 0, 0, 0, 0, 0, 0, 230, 239},
{156, 165, 0, 0, 0, 0, 0, 0, 0, 239, 243},
{165, 177, 0, 0, 0, 0, 0, 0, 0, 243, 247},
{177, 189, 202, 210, 214, 226, 230, 239, 243, 247, 251},
{189, 202, 210, 214, 226, 230, 239, 243, 247, 251, 255}
};
static final int[][] radioA = {
{0, 0, 78, 99, 115, 136, 144, 156, 165, 0, 0},
{0, 78, 99, 115, 136, 144, 156, 165, 177, 189, 0},
{78, 99, 115, 136, 92, 48, 92, 177, 189, 202, 210},
{99, 115, 136, 0, 0, 0, 0, 0, 202, 210, 214},
{115, 136, 92, 0, 0, 0, 0, 0, 128, 214, 226},
{136, 144, 48, 0, 0, 0, 0, 0, 64, 226, 230},
{144, 156, 92, 0, 0, 0, 0, 0, 128, 230, 239},
{156, 165, 177, 0, 0, 0, 0, 0, 230, 239, 243},
{165, 177, 189, 202, 128, 64, 128, 230, 239, 243, 247},
{0, 189, 202, 210, 214, 226, 230, 239, 243, 247, 0},
{0, 0, 210, 214, 226, 230, 239, 243, 247, 0, 0}
};
static GraphicsConfiguration graphicsConfiguration;
static {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
graphicsConfiguration = ge.getDefaultScreenDevice().getDefaultConfiguration();
}
public static void drawBorder(Graphics g, Color c, int x, int y, int w, int h) {
g.setColor(c);
g.drawRect(x, y, w - 1, h - 1);
}
public static void drawEditableComboBorder(
Graphics g, Color c, int x, int y, int w, int h)
{
// changed this in 1.3 so the border paints like a
// rounded border without a right side
g.setColor(c);
// rect - no right side
g.drawLine(x, y + 3, x, h - 4); // left
g.drawLine(x + 3, y, w - 1, y); // top
g.drawLine(x + 3, h - 1, w - 1, h - 1); // bottom
// edges verlängerungen 1
Color c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), 216);
g.setColor(c2);
// oben
g.drawLine(x + 2, y, x + 2, y);
g.drawLine(x + w - 3, y, x + w - 3, y);
// links
g.drawLine(x, y + 2, x, y + 2);
g.drawLine(x, y + h - 3, x, y + h - 3);
// unten
g.drawLine(x + 2, y + h - 1, x + 2, y + h - 1);
g.drawLine(x + w - 3, y + h - 1, x + w - 3, y + h - 1);
// edges verlängerungen 2
c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), 130);
g.setColor(c2);
// oben
g.drawLine(x + 1, y, x + 1, y);
// links
g.drawLine(x, y + 1, x, y + 1);
g.drawLine(x, y + h - 2, x, y + h - 2);
// unten
g.drawLine(x + 1, y + h - 1, x + 1, y + h - 1);
// edges aussen
c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), 24);
g.setColor(c2);
// lo
g.drawLine(x, y, x, y);
// lu
g.drawLine(x, y + h - 1, x, y + h - 1);
// edges innen
c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), 112);
g.setColor(c2);
// lo
g.drawLine(x + 1, y + 1, x + 1, y + 1);
c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), 104);
g.setColor(c2);
// lu
g.drawLine(x + 1, y + h - 2, x + 1, y + h - 2);
}
public static void drawRoundedBorder(Graphics g, Color c, int x, int y, int w, int h) {
g.setColor(c);
// rect
g.drawLine(x + 3, y, x + w - 4, y); // top
g.drawLine(x + 3, y + h - 1, x + w - 4, y + h - 1); // bottom
g.drawLine(x, y + 3, x, y + h - 4); // left
g.drawLine(x + w - 1, y + 3, x + w - 1, y + h - 4); // right
// edges verlängerungen 1
Color c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), 216);
g.setColor(c2);
// oben
g.drawLine(x + 2, y, x + 2, y);
g.drawLine(x + w - 3, y, x + w - 3, y);
// links
g.drawLine(x, y + 2, x, y + 2);
g.drawLine(x, y + h - 3, x, y + h - 3);
// unten
g.drawLine(x + 2, y + h - 1, x + 2, y + h - 1);
g.drawLine(x + w - 3, y + h - 1, x + w - 3, y + h - 1);
// rechts
g.drawLine(x + w - 1, y + 2, x + w - 1, y + 2);
g.drawLine(x + w - 1, y + h - 3, x + w - 1, y + h - 3);
// edges verlängerungen 2
c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), 130);
g.setColor(c2);
// oben
g.drawLine(x + 1, y, x + 1, y);
g.drawLine(x + w - 2, y, x + w - 2, y);
// links
g.drawLine(x, y + 1, x, y + 1);
g.drawLine(x, y + h - 2, x, y + h - 2);
// unten
g.drawLine(x + 1, y + h - 1, x + 1, y + h - 1);
g.drawLine(x + w - 2, y + h - 1, x + w - 2, y + h - 1);
// rechts
g.drawLine(x + w - 1, y + 1, x + w - 1, y + 1);
g.drawLine(x + w - 1, y + h - 2, x + w - 1, y + h - 2);
// edges aussen
c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), 24);
g.setColor(c2);
// lo
g.drawLine(x, y, x, y);
// ro
g.drawLine(x + w - 1, y, x + w - 1, y);
// lu
g.drawLine(x, y + h - 1, x, y + h - 1);
// ru
g.drawLine(x + w - 1, y + h - 1, x + w - 1, y + h - 1);
// edges innen
c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), 112);
g.setColor(c2);
// lo
g.drawLine(x + 1, y + 1, x + 1, y + 1);
// ro
g.drawLine(x + w - 2, y + 1, x + w - 2, y + 1);
c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), 104);
g.setColor(c2);
// lu
g.drawLine(x + 1, y + h - 2, x + 1, y + h - 2);
// ru
g.drawLine(x + w - 2, y + h - 2, x + w - 2, y + h - 2);
}
public static void drawWindowButtonBorder(Graphics g, Color c, int x, int y, int w, int h) {
g.setColor(c);
// rect
g.drawLine(x + 2, y, x + w - 3, y); // top
g.drawLine(x + 2, y + h - 1, x + w - 3, y + h - 1); // bottom
g.drawLine(x, y + 2, x, y + h - 3); // left
g.drawLine(x + w - 1, y + 2, x + w - 1, y + h - 3); // right
// edges verlängerungen
Color c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), 100);
g.setColor(c2);
// oben
g.drawLine(x + 1, y, x + 1, y);
g.drawLine(x + w - 2, y, x + w - 2, y);
// links
g.drawLine(x, y + 1, x, y + 1);
g.drawLine(x, y + h - 2, x, y + h - 2);
// unten
g.drawLine(x + 1, y + h - 1, x + 1, y + h - 1);
g.drawLine(x + w - 2, y + h - 1, x + w - 2, y + h - 1);
// rechts
g.drawLine(x + w - 1, y + 1, x + w - 1, y + 1);
g.drawLine(x + w - 1, y + h - 2, x + w - 1, y + h - 2);
// edges innen
c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), 216);
g.setColor(c2);
// lo
g.drawLine(x + 1, y + 1, x + 1, y + 1);
// ro
g.drawLine(x + w - 2, y + 1, x + w - 2, y + 1);
// lu
g.drawLine(x + 1, y + h - 2, x + 1, y + h - 2);
// ru
g.drawLine(x + w - 2, y + h - 2, x + w - 2, y + h - 2);
}
public static synchronized void drawProgressBarBorder(
Graphics g, Color c, int x, int y, int w, int h)
{
g.setColor(c);
// rect
g.drawLine(x + 1, y, x + w - 2, y);
g.drawLine(x + 1, y + h - 1, x + w - 2, y + h - 1);
g.drawLine(x, y + 1, x, y + h - 2);
g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 2);
// edges innen
// lo
g.drawLine(x + 1, y + 1, x + 1, y + 1);
// ro
g.drawLine(x + w - 2, y + 1, x + w - 2, y + 1);
// lu
g.drawLine(x + 1, y + h - 2, x + 1, y + h - 2);
// ru
g.drawLine(x + w - 2, y + h - 2, x + w - 2, y + h - 2);
}
/**
* changed in 1.3
*/
public static void drawRolloverBorder(Graphics g, Color c, int x, int y, int w, int h) {
// lowest row
g.setColor(ColorRoutines.darken(c, 10));
g.drawLine(x + 2, y + h - 2, x + w - 3, y + h - 2);
// lowest row - 1
g.setColor(c);
g.drawLine(x + 1, y + h - 3, x + w - 2, y + h - 3);
// highest row + 1
g.setColor(new Color(c.getRed(), c.getGreen(), c.getBlue(), 144));
g.drawLine(x + 2, y + 2, x + w - 3, y + 2);
// highest row
g.setColor(new Color(c.getRed(), c.getGreen(), c.getBlue(), 64));
g.drawLine(x + 2, y + 1, x + w - 3, y + 1);
// Was a bug before 1.4.0 (JDK 1.6 only)
if(h <= 6) return;
// outer left and right
// both paint a gradient from c.alpha 255 to c.alpha 64
int inc = (255 - 64) / (h - 5); // distance to paint
int val = 64 + inc;
for(int i = y + 2; i < y + h - 3; i++) {
g.setColor(new Color(c.getRed(), c.getGreen(), c.getBlue(), val));
g.drawLine(x + 1, i, x + 1, i);
g.drawLine(x + w - 2, i, x + w - 2, i);
val += inc;
}
// inner left and right
// both paint a gradient from c.alpha 255 to c.alpha 144
inc = (255 - 144) / (h - 6); // distance to paint
val = 144 + inc;
for(int i = y + 3; i < y + h - 3; i++) {
g.setColor(new Color(c.getRed(), c.getGreen(), c.getBlue(), val));
g.drawLine(x + 2, i, x + 2, i);
g.drawLine(x + w - 3, i, x + w - 3, i);
val += inc;
}
}
public static void drawRolloverCheckBorder(Graphics g, Color c, int x, int y, int w, int h) {
g.translate(x, y);
Color color;
for (int row = 0; row < 11; row++) {
for (int col = 0; col < 11; col++) {
if(checkA[row][col] > 0) {
color = new Color(c.getRed(), c.getGreen(), c.getBlue(), checkA[row][col]);
g.setColor(color);
g.drawLine(col + 1, row + 1, col + 1, row + 1);
}
}
}
g.translate(-x, -y);
}
public static void drawSelectedXpTabBorder(
Graphics g, Color c, int x, int y, int w, int h, int tabPlacement)
{
Color c2 = ColorRoutines.getAdjustedColor(
Theme.tabRolloverColor.getColor(), 20, -30);
g.setColor(c2);
Color c3 = ColorRoutines.getAverage(Theme.backColor.getColor(), c2);
switch (tabPlacement) {
case SwingConstants.LEFT:
h -= 1;
g.drawLine(x, y + 2, x, y + h - 3);
// edges
g.drawLine(x + 1, y + 1, x + 1, y + 1);
g.drawLine(x + 1, y + h - 2, x + 1, y + h - 2);
g.drawLine(x + 2, y, x + 2, y);
g.drawLine(x + 2, y + h - 1, x + 2, y + h - 1);
g.setColor(Theme.tabRolloverColor.getColor());
g.drawLine(x + 1, y + 2, x + 1, y + h - 3);
g.drawLine(x + 2, y + 1, x + 2, y + h - 2);
// edges
g.setColor(c3);
// lo
g.drawLine(x, y + 1, x, y + 1);
g.drawLine(x + 1, y, x + 1, y);
// lu
g.drawLine(x, y + h - 2, x, y + h - 2);
g.drawLine(x + 1, y + h - 1, x + 1, y + h - 1);
// seiten
g.setColor(c);
// Was bug until 1.4.0 - lines were 1 px too short
g.drawLine(x + 3, y, x + w - 1, y);
g.drawLine(x + 3, y + h - 1, x + w - 1, y + h - 1);
break;
case SwingConstants.RIGHT:
h -= 1;
x -= 2;
g.drawLine(x + w - 1, y + 2, x + w - 1, y + h - 3);
// edges
g.drawLine(x + w - 2, y + 1, x + w - 2, y + 1);
g.drawLine(x + w - 2, y + h - 2, x + w - 2, y + h - 2);
g.drawLine(x + w - 3, y, x + w - 3, y);
g.drawLine(x + w - 3, y + h - 1, x + w - 3, y + h - 1);
g.setColor(Theme.tabRolloverColor.getColor());
g.drawLine(x + w - 2, y + 2, x + w - 2, y + h - 3);
g.drawLine(x + w - 3, y + 1, x + w - 3, y + h - 2);
// edges
g.setColor(c3);
// ro
g.drawLine(x + w - 1, y + 1, x + w - 1, y + 1);
g.drawLine(x + w - 2, y, x + w - 2, y);
// ru
g.drawLine(x + w - 1, y + h - 2, x + w - 1, y + h - 2);
g.drawLine(x + w - 2, y + h - 1, x + w - 2, y + h - 1);
// seiten
g.setColor(c);
g.drawLine(x, y, x + w - 4, y);
g.drawLine(x, y + h - 1, x + w - 4, y + h - 1);
break;
case SwingConstants.BOTTOM:
w -= 1;
y -= 2;
g.drawLine(x + 2, y + h - 1, x + w - 3, y + h - 1);
// edges
g.drawLine(x + 1, y + h - 2, x + 1, y + h - 2);
g.drawLine(x + w - 2, y + h - 2, x + w - 2, y + h - 2);
g.drawLine(x, y + h - 3, x, y + h - 3);
g.drawLine(x + w - 1, y + h - 3, x + w - 1, y + h - 3);
g.setColor(Theme.tabRolloverColor.getColor());
g.drawLine(x + 2, y + h - 2, x + w - 3, y + h - 2);
g.drawLine(x + 1, y + h - 3, x + w - 2, y + h - 3);
// seiten
g.setColor(c);
g.drawLine(x, y, x, y + h - 4);
g.drawLine(x + w - 1, y, x + w - 1, y + h - 4);
// edges
g.setColor(c3);
// lu
g.drawLine(x + 1, y + h - 1, x + 1, y + h - 1);
g.drawLine(x, y + h - 2, x, y + h - 2);
// ru
g.drawLine(x + w - 2, y + h - 1, x + w - 2, y + h - 1);
g.drawLine(x + w - 1, y + h - 2, x + w - 1, y + h - 2);
break;
case SwingConstants.TOP:
default :
w -= 1;
g.drawLine(x + 2, y, x + w - 3, y);
// edges
g.drawLine(x + 1, y + 1, x + 1, y + 1);
g.drawLine(x + w - 2, y + 1, x + w - 2, y + 1);
g.drawLine(x, y + 2, x, y + 2);
g.drawLine(x + w - 1, y + 2, x + w - 1, y + 2);
g.setColor(Theme.tabRolloverColor.getColor());
g.drawLine(x + 2, y + 1, x + w - 3, y + 1);
g.drawLine(x + 1, y + 2, x + w - 2, y + 2);
// edges
g.setColor(c3);
// lo
g.drawLine(x + 1, y, x + 1, y);
g.drawLine(x, y + 1, x, y + 1);
// ro
g.drawLine(x + w - 2, y, x + w - 2, y);
g.drawLine(x + w - 1, y + 1, x + w - 1, y + 1);
// seiten
g.setColor(c);
g.drawLine(x, y + 3, x, y + h - 1);
g.drawLine(x + w - 1, y + 3, x + w - 1, y + h - 1);
}
}
public static void drawXpTabBorder(
Graphics g, Color c, int x, int y, int w, int h, int tabPlacement)
{
Color c2 = null;
g.setColor(c);
switch (tabPlacement){
case SwingConstants.LEFT:
h -= 1;
g.drawLine(x + 2, y, x + w - 1, y);
g.drawLine(x + 2, y + h - 1, x + w - 1, y + h - 1);
g.drawLine(x, y + 2, x, y + h - 3);
// edges
c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), 56);
g.setColor(c2);
// lo
g.drawLine(x, y, x, y);
// lu
g.drawLine(x, y + h - 1, x, y + h - 1);
// edges verlängerungen
c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), 183);
g.setColor(c2);
// oben
g.drawLine(x + 1, y, x + 1, y);
// links
g.drawLine(x, y + 1, x, y + 1);
g.drawLine(x, y + h - 2, x, y + h - 2);
// unten
g.drawLine(x + 1, y + h - 1, x + 1, y + h - 1);
// edges innen
c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), 76);
g.setColor(c2);
// lo
g.drawLine(x + 1, y + 1, x + 1, y + 1);
// lu
g.drawLine(x + 1, y + h - 2, x + 1, y + h - 2);
break;
case SwingConstants.RIGHT:
h -= 1;
x -= 2;
g.drawLine(x, y, x + w - 3, y);
g.drawLine(x, y + h - 1, x + w - 3, y + h - 1);
g.drawLine(x + w - 1, y + 2, x + w - 1, y + h - 3);
// edges
c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), 56);
g.setColor(c2);
// ro
g.drawLine(x + w - 1, y, x + w - 1, y);
// ru
g.drawLine(x + w - 1, y + h - 1, x + w - 1, y + h - 1);
// edges verlängerungen
c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), 183);
g.setColor(c2);
// oben
g.drawLine(x + w - 2, y, x + w - 2, y);
// unten
g.drawLine(x + w - 2, y + h - 1, x + w - 2, y + h - 1);
// rechts
g.drawLine(x + w - 1, y + 1, x + w - 1, y + 1);
g.drawLine(x + w - 1, y + h - 2, x + w - 1, y + h - 2);
// edges innen
c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), 76);
g.setColor(c2);
// ro
g.drawLine(x + w - 2, y + 1, x + w - 2, y + 1);
// ru
g.drawLine(x + w - 2, y + h - 2, x + w - 2, y + h - 2);
break;
case SwingConstants.BOTTOM:
w -= 1;
y -= 2;
g.drawLine(x + 2, y + h - 1, x + w - 3, y + h - 1);
g.drawLine(x, y, x, y + h - 3);
g.drawLine(x + w - 1, y, x + w - 1, y + h - 3);
// edges
c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), 56);
g.setColor(c2);
// lu
g.drawLine(x, y + h - 1, x, y + h - 1);
// ru
g.drawLine(x + w - 1, y + h - 1, x + w - 1, y + h - 1);
// edges verlängerungen
c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), 183);
g.setColor(c2);
// links
g.drawLine(x, y + h - 2, x, y + h - 2);
// unten
g.drawLine(x + 1, y + h - 1, x + 1, y + h - 1);
g.drawLine(x + w - 2, y + h - 1, x + w - 2, y + h - 1);
// rechts
g.drawLine(x + w - 1, y + h - 2, x + w - 1, y + h - 2);
// edges innen
c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), 76);
g.setColor(c2);
// lu
g.drawLine(x + 1, y + h - 2, x + 1, y + h - 2);
// ru
g.drawLine(x + w - 2, y + h - 2, x + w - 2, y + h - 2);
break;
case SwingConstants.TOP:
default:
w -= 1;
g.drawLine(x + 2, y, x + w - 3, y);
g.drawLine(x, y + 2, x, y + h - 1);
g.drawLine(x + w - 1, y + 2, x + w - 1, y + h - 1);
// edges
c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), 56);
g.setColor(c2);
// lo
g.drawLine(x, y, x, y);
// ro
g.drawLine(x + w - 1, y, x + w - 1, y);
// edges verlängerungen
c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), 183);
g.setColor(c2);
// oben
g.drawLine(x + 1, y, x + 1, y);
g.drawLine(x + w - 2, y, x + w - 2, y);
// links
g.drawLine(x, y + 1, x, y + 1);
// rechts
g.drawLine(x + w - 1, y + 1, x + w - 1, y + 1);
// edges innen
c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), 76);
g.setColor(c2);
// lo
g.drawLine(x + 1, y + 1, x + 1, y + 1);
// ro
g.drawLine(x + w - 2, y + 1, x + w - 2, y + 1);
}
}
public static void drawXpRadioRolloverBorder(Graphics g, Color c,
int x, int y, int w, int h)
{
g.translate(x, y);
Color color;
for (int row = 0; row < 11; row++) {
for (int col = 0; col < 11; col++) {
if(radioA[row][col] > 0) {
color = new Color(c.getRed(), c.getGreen(), c.getBlue(), radioA[row][col]);
g.setColor(color);
g.drawLine(col + 1, row + 1, col + 1, row + 1);
}
}
}
g.translate(-x, -y);
}
public static void drawXpRadioBorder(Graphics g, Color c, int x, int y, int w, int h) {
g.setColor(c);
g.drawLine(x + 6, y, x + 6, y);
g.drawLine(x + 3, y + 1, x + 3, y + 1);
g.drawLine(x + 9, y + 1, x + 9, y + 1);
g.drawLine(x + 1, y + 3, x + 1, y + 3);
g.drawLine(x + 11, y + 3, x + 11, y + 3);
g.drawLine(x, y + 6, x, y + 6);
g.drawLine(x + 12, y + 6, x + 12, y + 6);
g.drawLine(x + 1, y + 9, x + 1, y + 9);
g.drawLine(x + 11, y + 9, x + 11, y + 9);
g.drawLine(x + 3, y + 11, x + 3, y + 11);
g.drawLine(x + 9, y + 11, x + 9, y + 11);
g.drawLine(x + 6, y + 12, x + 6, y + 12);
// changed alpha value from 193 to 168 in 1.3.05
g.setColor(ColorRoutines.getAlphaColor(c, 168));
g.drawLine(x + 5, y, x + 5, y);
g.drawLine(x + 7, y, x + 7, y);
g.drawLine(x + 4, y + 1, x + 4, y + 1);
g.drawLine(x + 8, y + 1, x + 8, y + 1);
g.drawLine(x + 2, y + 2, x + 2, y + 2);
g.drawLine(x + 10, y + 2, x + 10, y + 2);
g.drawLine(x + 1, y + 4, x + 1, y + 4);
g.drawLine(x + 11, y + 4, x + 11, y + 4);
g.drawLine(x, y + 5, x, y + 5);
g.drawLine(x + 12, y + 5, x + 12, y + 5);
g.drawLine(x, y + 7, x, y + 7);
g.drawLine(x + 12, y + 7, x + 12, y + 7);
g.drawLine(x + 1, y + 8, x + 1, y + 8);
g.drawLine(x + 11, y + 8, x + 11, y + 8);
g.drawLine(x + 2, y + 10, x + 2, y + 10);
g.drawLine(x + 10, y + 10, x + 10, y + 10);
g.drawLine(x + 4, y + 11, x + 4, y + 11);
g.drawLine(x + 8, y + 11, x + 8, y + 11);
g.drawLine(x + 5, y + 12, x + 5, y + 12);
g.drawLine(x + 7, y + 12, x + 7, y + 12);
g.setColor(ColorRoutines.getAlphaColor(c, 64));
g.drawLine(x + 4, y, x + 4, y);
g.drawLine(x + 8, y, x + 8, y);
g.drawLine(x + 2, y + 1, x + 2, y + 1);
g.drawLine(x + 2, y + 3, x + 2, y + 3);
g.drawLine(x + 10, y + 1, x + 10, y + 1);
g.drawLine(x + 10, y + 3, x + 10, y + 3);
g.drawLine(x + 5, y + 1, x + 5, y + 1);
g.drawLine(x + 7, y + 1, x + 7, y + 1);
g.drawLine(x + 1, y + 2, x + 1, y + 2);
g.drawLine(x + 1, y + 5, x + 1, y + 5);
g.drawLine(x + 1, y + 7, x + 1, y + 7);
g.drawLine(x + 11, y + 2, x + 11, y + 2);
g.drawLine(x + 3, y + 2, x + 3, y + 2);
g.drawLine(x + 9, y + 2, x + 9, y + 2);
g.drawLine(x, y + 4, x, y + 4);
g.drawLine(x + 12, y + 4, x + 12, y + 4);
g.drawLine(x, y + 8, x, y + 8);
g.drawLine(x + 12, y + 8, x + 12, y + 8);
g.drawLine(x + 2, y + 9, x + 2, y + 9);
g.drawLine(x + 10, y + 9, x + 10, y + 9);
g.drawLine(x + 1, y + 10, x + 1, y + 10);
g.drawLine(x + 11, y + 5, x + 11, y + 5);
g.drawLine(x + 11, y + 7, x + 11, y + 7);
g.drawLine(x + 11, y + 10, x + 11, y + 10);
g.drawLine(x + 3, y + 10, x + 3, y + 10);
g.drawLine(x + 9, y + 10, x + 9, y + 10);
g.drawLine(x + 2, y + 11, x + 2, y + 11);
g.drawLine(x + 10, y + 11, x + 10, y + 11);
g.drawLine(x + 5, y + 11, x + 5, y + 11);
g.drawLine(x + 7, y + 11, x + 7, y + 11);
g.drawLine(x + 4, y + 12, x + 4, y + 12);
g.drawLine(x + 8, y + 12, x + 8, y + 12);
// changed alpha value from 43 to 16 in 1.3.05
g.setColor(ColorRoutines.getAlphaColor(c, 16));
g.drawLine(x + 3, y, x + 3, y);
g.drawLine(x + 9, y, x + 9, y);
g.drawLine(x, y + 3, x, y + 3);
g.drawLine(x + 12, y + 3, x + 12, y + 3);
g.drawLine(x, y + 9, x, y + 9);
g.drawLine(x + 12, y + 9, x + 12, y + 9);
g.drawLine(x + 3, y + 12, x + 3, y + 12);
g.drawLine(x + 9, y + 12, x + 9, y + 12);
}
public static ImageIcon colorizeIcon(Image img, HSBReference hsbRef) {
ColorRoutines nc = new ColorRoutines(hsbRef);
// long t = System.nanoTime();
int w = img.getWidth(null);
int h = img.getHeight(null);
BufferedImage bufferedImg =
graphicsConfiguration.createCompatibleImage(w, h, Transparency.TRANSLUCENT);
int[] pixels = new int[w * h];
PixelGrabber grabber = new PixelGrabber(img, 0, 0, w, h, pixels, 0, w);
try {
grabber.grabPixels();
} catch (InterruptedException e) {
System.err.println("PixelGrabber interrupted waiting for pixels");
}
if((grabber.getStatus() & ImageObserver.ABORT) != 0) {
System.err.println("Image fetch aborted or errored.");
}
else {
for(int y = 0; y < h; y++) {
for(int x = 0; x < w; x++) {
bufferedImg.setRGB(x, y, colorizePixel(pixels[y * w + x], nc));
}
}
// t = System.nanoTime() - t;
// System.out.println(w + " x " + h + " : " + t + " Nano-sec. (" +
// (double)(t / 1000000000.0) + ")");
}
return new ImageIcon(bufferedImg);
}
private static int colorizePixel(int px, ColorRoutines nc) {
int a = (px >> 24) & 0xff;
if(a == 0) return px;
int r = (px >> 16) & 0xff;
int g = (px >> 8) & 0xff;
int b = px & 0xff;
return nc.colorize(r, g, b, a);
}
}
--- NEW FILE: IntReference.java ---
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* This file is part of the Tiny Look and Feel *
* Copyright 2003 - 2008 Hans Bickel *
* *
* For licensing information and credits, please refer to the *
* comment in file de.muntjak.tinylookandfeel.TinyLookAndFeel *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
package de.muntjak.tinylookandfeel.util;
/**
* A (mutable) int wrapper.
* @author Hans Bickel
*
*/
public class IntReference {
private int value;
public IntReference(int value) {
this.value = value;
}
public int getValue() {
return value;
}
public void setValue(int value) {
this.value = value;
}
}
--- NEW FILE: HSBReference.java ---
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* This file is part of the Tiny Look and Feel *
* Copyright 2003 - 2008 Hans Bickel *
* *
* For licensing information and credits, please refer to the *
* comment in file de.muntjak.tinylookandfeel.TinyLookAndFeel *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
package de.muntjak.tinylookandfeel.util;
import java.awt.*;
import java.io.*;
import java.util.Vector;
import javax.swing.plaf.ColorUIResource;
/**
* HSBReference describes a (mutable) color, specified
* by a reference color and values for brightness, hue
* and saturation.
*
* @version 1.0
* @author Hans Bickel
*/
public class HSBReference extends SBReference {
protected int hue;
protected boolean preserveGrey;
/**
* Constructor for icon colorizers.
* @param hue
* @param sat
* @param bri
* @param ref
*/
public HSBReference(int hue, int sat, int bri, int ref) {
super();
this.hue = hue;
this.sat = sat;
this.bri = bri;
this.ref = ref;
preserveGrey = true;
}
/**
* Copy-constructor.
* @param other
*/
public HSBReference(HSBReference other) {
super(false);
color = new ColorUIResource(other.color);
hue = other.hue;
sat = other.sat;
bri = other.bri;
ref = other.ref;
preserveGrey = other.preserveGrey;
}
public void update(HSBReference other) {
color = new ColorUIResource(other.color);
hue = other.hue;
sat = other.sat;
bri = other.bri;
ref = other.ref;
preserveGrey = other.preserveGrey;
}
public void update(HSBReference other, Vector referenceColors) {
color = new ColorUIResource(other.color);
hue = other.hue;
sat = other.sat;
bri = other.bri;
ref = other.ref;
preserveGrey = other.preserveGrey;
}
public int getHue() {
return hue;
}
public void setHue(int newHue) {
hue = newHue;
}
public void load(DataInputStream in) throws IOException {
try {
hue = in.readInt();
sat = in.readInt();
bri = in.readInt();
ref = in.readInt();
preserveGrey = in.readBoolean();
} catch(Exception ex) {
throw new IOException("HSBReference.load() : " + ex.getMessage());
}
}
public void save(DataOutputStream out) throws IOException {
out.writeInt(hue);
out.writeInt(sat);
out.writeInt(bri);
out.writeInt(ref);
out.writeBoolean(preserveGrey);
}
public boolean isPreserveGrey() {
return preserveGrey;
}
public void setPreserveGrey(boolean b) {
preserveGrey = b;
}
public String toString() {
return "HSBReference[bri=" + bri + ",sat=" + sat +
",hue=" + hue + ",ref=" + ref + ",c=(" + color.getRed() + "," +
color.getGreen() + "," + color.getBlue() + ")]";
}
}
--- NEW FILE: BooleanReference.java ---
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* This file is part of the Tiny Look and Feel *
* Copyright 2003 - 2008 Hans Bickel *
* *
* For licensing information and credits, please refer to the *
* comment in file de.muntjak.tinylookandfeel.TinyLookAndFeel *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
package de.muntjak.tinylookandfeel.util;
/**
* A (mutable) boolean wrapper.
* @author Hans Bickel
*
*/
public class BooleanReference {
private boolean value;
public BooleanReference(boolean value) {
this.value = value;
}
public boolean getValue() {
return value;
}
public void setValue(boolean value) {
this.value = value;
}
}
--- NEW FILE: SBReference.java ---
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* This file is part of the Tiny Look and Feel *
* Copyright 2003 - 2008 Hans Bickel *
* *
* For licensing information and credits, please refer to the *
* comment in file de.muntjak.tinylookandfeel.TinyLookAndFeel *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
package de.muntjak.tinylookandfeel.util;
import java.awt.*;
import java.io.*;
import java.util.Iterator;
import java.util.Vector;
import javax.swing.*;
import javax.swing.plaf.ColorUIResource;
import de.muntjak.tinylookandfeel.Theme;
import de.muntjak.tinylookandfeel.controlpanel.ControlPanel;
import de.muntjak.tinylookandfeel.controlpanel.SBChooser;
import de.muntjak.tinylookandfeel.controlpanel.SBControl;
/**
* SBReference describes a (mutable) color, specified
* by a reference color and values for brightness and
* saturation.
*
* @version 1.0
* @author Hans Bickel
*/
public class SBReference {
// ref values
public static final int ABS_COLOR = 1;
public static final int MAIN_COLOR = 2;
public static final int BACK_COLOR = 3;
public static final int DIS_COLOR = 4;
public static final int FRAME_COLOR = 5;
public static final int SUB1_COLOR = 6;
public static final int SUB2_COLOR = 7;
public static final int SUB3_COLOR = 8;
public static final int SUB4_COLOR = 9;
public static final int SUB5_COLOR = 10;
public static final int SUB6_COLOR = 11;
public static final int SUB7_COLOR = 12;
public static final int SUB8_COLOR = 13;
// instances stores all created SBReferences so
// we can calculate the number of references for
// derived colors
private static final Vector instances = new Vector();
protected ColorUIResource color;
protected ColorUIResource referenceColor;
protected int sat = 0, bri = 0;
protected int ref;
protected boolean locked;
protected ColorIcon icon;
protected static ColorIcon absoluteIcon;
/**
* Constructor for font colors and super constructor for
* HSBReferences. SBReference will be added to
* instances vector.
*
*/
public SBReference() {
color = new ColorUIResource(Color.BLACK);
ref = ABS_COLOR;
instances.add(this);
}
/**
* Super constructor for HSBReference copy constructor.
* This SBReference will not be added to instances vector.
*
* @param dummy ignored
*/
public SBReference(boolean dummy) {
color = new ColorUIResource(Color.BLACK);
ref = ABS_COLOR;
}
/**
* Called from Theme.initData()
* @param c
* @param sat
* @param bri
* @param ref
*/
public SBReference(Color c, int sat, int bri, int ref) {
color = new ColorUIResource(c);
this.sat = sat;
this.bri = bri;
this.ref = ref;
instances.add(this);
}
/**
* Constructor for our 4 locked color references.
* @param c
* @param sat
* @param bri
* @param ref
* @param locked
*/
public SBReference(Color c, int sat, int bri, int ref, boolean locked) {
color = new ColorUIResource(c);
this.sat = sat;
this.bri = bri;
this.ref = ref;
this.locked = locked;
// cannot be a reference, so don't add to instances
}
/**
* Copy constructor.
* @param other
*/
public SBReference(SBReference other) {
color = new ColorUIResource(other.color);
sat = other.sat;
bri = other.bri;
ref = other.ref;
locked = other.locked;
// ! do not add to instances !
}
/**
* Returns a copy of this SBReference and additionally
* stores the color reference (if any).
* Called if user copies parameters via Copy-Paste popup.
* @return
*/
public SBReference copy() {
SBReference retVal = new SBReference(this);
if(!isAbsoluteColor()) {
retVal.referenceColor = getReferenceColor();
}
return retVal;
}
public static int getNumReferences(int ref) {
int n = 0;
Iterator ii = instances.iterator();
while(ii.hasNext()) {
if(ref == ((SBReference)ii.next()).ref) {
n ++;
}
}
// System.out.println("instances=" + instances.size() +
// " references=" + n);
return n;
}
public static void printReferences(int ref) {
Iterator ii = instances.iterator();
while(ii.hasNext()) {
SBReference sb = (SBReference)ii.next();
if(ref == sb.ref) {
System.out.println(sb);
}
}
}
public void update(Color c, int sat, int bri, int ref) {
color = new ColorUIResource(c);
this.sat = sat;
this.bri = bri;
this.ref = ref;
}
/**
* Called if user pastes parameters via Copy-Paste popup.
* @param cr
*/
public void update(SBReference sb) {
// System.out.println("update: " + sb + "\n " + sb.referenceColor);
if(sb.isAbsoluteColor() || sb.referenceColor == null) {
color = new ColorUIResource(sb.color);
sat = sb.sat;
bri = sb.bri;
ref = sb.ref;
}
else {
update(sb, sb.referenceColor);
}
}
/**
* Updates this SBReference from values of <code>other</code>
* argument. If the current reference color differs from the
* one stored in <code>referenceColors</code> vector, this
* SBReference will switch to absolute color mode.
* @param other
* @param referenceColors
*/
public void update(SBReference other, Vector referenceColors) {
if(other.isAbsoluteColor()) {
color = new ColorUIResource(other.color);
sat = other.sat;
bri = other.bri;
ref = other.ref;
}
else {
update(other, (ColorUIResource)referenceColors.get(other.ref - 2));
}
}
/**
*
* @param sb
* @param cr
*/
private void update(SBReference sb, ColorUIResource cr) {
// sb is not an absolute color and cr is non-null
// System.out.println("update: " + sb + "\n " + cr);
if(!sb.getReferenceColor().equals(cr)) {
// first look for another reference color which is
// equal to the stored reference color
int newRef = getRefForColor(cr);
// System.out.println("1) newRef=" + newRef + " (" + ref + ")");
if(newRef != -1) {
ref = newRef;
sat = sb.sat;
bri = sb.bri;
return; // we are through
}
// now look for a reference color without references
// (so it can be changed) - start with last color
newRef = getEmptyReferenceColor();
// System.out.println("2) newRef=" + newRef + " (" + ref + ")");
if(newRef != -1) {
ref = newRef;
SBControl control = ControlPanel.instance.getSBControlFromRef(ref);
control.getSBReference().setReference(ABS_COLOR);
control.getSBReference().setSaturation(0);
control.getSBReference().setBrightness(0);
control.getSBReference().setColor(cr);
control.update();
sat = sb.sat;
bri = sb.bri;
return; // we are through
}
// change to absolute color
color = new ColorUIResource(sb.getColor());
sat = 0;
bri = 0;
ref = ABS_COLOR;
// System.out.println("Change to absolute: " + this);
return;
}
color = new ColorUIResource(sb.color);
sat = sb.sat;
bri = sb.bri;
ref = sb.ref;
// System.out.println("Simply updated: " + this);
}
/**
* If one of reference colors sub1 to sub8 has
* no references, returns its ref value, returns -1 if
* no empty reference color was found.
* @return
*/
private int getEmptyReferenceColor() {
for(int i = SUB1_COLOR; i <= SUB8_COLOR; i++) {
if(getNumReferences(i) == 0) {
return i;
}
}
return -1;
}
private int getRefForColor(ColorUIResource cr) {
if(Theme.mainColor.getColor().equals(cr)) {
return MAIN_COLOR;
}
else if(Theme.backColor.getColor().equals(cr)) {
return BACK_COLOR;
}
else if(Theme.disColor.getColor().equals(cr)) {
return DIS_COLOR;
}
else if(Theme.frameColor.getColor().equals(cr)) {
return FRAME_COLOR;
}
else if(Theme.sub1Color.getColor().equals(cr)) {
return SUB1_COLOR;
}
else if(Theme.sub2Color.getColor().equals(cr)) {
return SUB2_COLOR;
}
else if(Theme.sub3Color.getColor().equals(cr)) {
return SUB3_COLOR;
}
else if(Theme.sub4Color.getColor().equals(cr)) {
return SUB4_COLOR;
}
else if(Theme.sub5Color.getColor().equals(cr)) {
return SUB5_COLOR;
}
else if(Theme.sub6Color.getColor().equals(cr)) {
return SUB6_COLOR;
}
else if(Theme.sub7Color.getColor().equals(cr)) {
return SUB7_COLOR;
}
else if(Theme.sub8Color.getColor().equals(cr)) {
return SUB8_COLOR;
}
return -1;
}
public void update(Color c) {
color = new ColorUIResource(c);
sat = 0;
bri = 0;
ref = ABS_COLOR;
}
public void reset() {
sat = 0;
bri = 0;
}
public ColorUIResource getColor() {
return color;
}
public int getSaturation() { return sat; }
public int getBrightness() { return bri; }
public int getReference() { return ref; }
public ColorUIResource getReferenceColor() {
return getReferencedColor(ref);
}
public static ColorUIResource getReferencedColor(int ref) {
switch(ref) {
case MAIN_COLOR:
return Theme.mainColor.getColor();
case BACK_COLOR:
return Theme.backColor.getColor();
case DIS_COLOR:
return Theme.disColor.getColor();
case FRAME_COLOR:
return Theme.frameColor.getColor();
case SUB1_COLOR:
return Theme.sub1Color.getColor();
case SUB2_COLOR:
return Theme.sub2Color.getColor();
case SUB3_COLOR:
return Theme.sub3Color.getColor();
case SUB4_COLOR:
return Theme.sub4Color.getColor();
case SUB5_COLOR:
return Theme.sub5Color.getColor();
case SUB6_COLOR:
return Theme.sub6Color.getColor();
case SUB7_COLOR:
return Theme.sub7Color.getColor();
case SUB8_COLOR:
return Theme.sub8Color.getColor();
default:
return null;
}
}
public String getReferenceString() {
switch(ref) {
case MAIN_COLOR:
return "Main Color";
case BACK_COLOR:
return "Back Color";
case DIS_COLOR:
return "Disabled Color";
case FRAME_COLOR:
return "Frame Color";
case SUB1_COLOR:
return "Sub1 Color";
case SUB2_COLOR:
return "Sub2 Color";
case SUB3_COLOR:
return "Sub3 Color";
case SUB4_COLOR:
return "Sub4 Color";
case SUB5_COLOR:
return "Sub5 Color";
case SUB6_COLOR:
return "Sub6 Color";
case SUB7_COLOR:
return "Sub7 Color";
case SUB8_COLOR:
return "Sub8 Color";
default:
return "";
}
}
public void setColor(Color newColor) {
color = new ColorUIResource(newColor);
}
public void setSaturation(int newSat) {
sat = newSat;
}
public void setBrightness(int newBri) {
bri = newBri;
}
public void setReference(int newRef) {
ref = newRef;
}
public void setColor(int sat, int bri) {
if(isAbsoluteColor()) return;
this.sat = sat;
this.bri = bri;
updateColor();
}
private void updateColor() {
switch(ref) {
case MAIN_COLOR:
color = new ColorUIResource(
ColorRoutines.getAdjustedColor(
Theme.mainColor.getColor(), sat, bri));
break;
case BACK_COLOR:
color = new ColorUIResource(
ColorRoutines.getAdjustedColor(
Theme.backColor.getColor(), sat, bri));
break;
case DIS_COLOR:
color = new ColorUIResource(
ColorRoutines.getAdjustedColor(
Theme.disColor.getColor(), sat, bri));
break;
case FRAME_COLOR:
color = new ColorUIResource(
ColorRoutines.getAdjustedColor(
Theme.frameColor.getColor(), sat, bri));
break;
case SUB1_COLOR:
color = new ColorUIResource(
ColorRoutines.getAdjustedColor(
Theme.sub1Color.getColor(), sat, bri));
break;
case SUB2_COLOR:
color = new ColorUIResource(
ColorRoutines.getAdjustedColor(
Theme.sub2Color.getColor(), sat, bri));
break;
case SUB3_COLOR:
color = new ColorUIResource(
ColorRoutines.getAdjustedColor(
Theme.sub3Color.getColor(), sat, bri));
break;
case SUB4_COLOR:
color = new ColorUIResource(
ColorRoutines.getAdjustedColor(
Theme.sub4Color.getColor(), sat, bri));
break;
case SUB5_COLOR:
color = new ColorUIResource(
ColorRoutines.getAdjustedColor(
Theme.sub5Color.getColor(), sat, bri));
break;
case SUB6_COLOR:
color = new ColorUIResource(
ColorRoutines.getAdjustedColor(
Theme.sub6Color.getColor(), sat, bri));
break;
case SUB7_COLOR:
color = new ColorUIResource(
ColorRoutines.getAdjustedColor(
Theme.sub7Color.getColor(), sat, bri));
break;
case SUB8_COLOR:
color = new ColorUIResource(
ColorRoutines.getAdjustedColor(
Theme.sub8Color.getColor(), sat, bri));
break;
}
}
public ColorUIResource update() {
if(isAbsoluteColor()) return color;
updateColor();
return color;
}
public boolean isAbsoluteColor() {
return (ref == ABS_COLOR);
}
public boolean isReferenceColor() {
return locked ||
this.equals(Theme.sub1Color) ||
this.equals(Theme.sub2Color) ||
this.equals(Theme.sub3Color) ||
this.equals(Theme.sub4Color) ||
this.equals(Theme.sub5Color) ||
this.equals(Theme.sub6Color) ||
this.equals(Theme.sub7Color) ||
this.equals(Theme.sub8Color);
}
public void setLocked(boolean newLocked) {
locked = newLocked;
}
public boolean isLocked() {
return locked;
}
public String toString() {
return "SBReference[bri=" + bri + ",sat=" + sat +
",ref=" + ref + ",c=(" + color.getRed() + "," +
color.getGreen() + "," + color.getBlue() + ")]";
}
public Icon getIcon() {
if(icon == null) {
icon = new ColorIcon(false);
}
return icon;
}
public Icon getAbsoluteIcon() {
if(absoluteIcon == null) {
absoluteIcon = new ColorIcon(true);
}
return absoluteIcon;
}
public void save(DataOutputStream out) throws IOException {
out.writeInt(color.getRGB());
out.writeInt(sat);
out.writeInt(bri);
out.writeInt(ref);
out.writeBoolean(locked);
}
public void load(DataInputStream in) throws IOException {
try {
if(Theme.fileID >= Theme.FILE_ID_3A) {
color = new ColorUIResource(in.readInt());
}
else {
color = new ColorUIResource(in.readInt(), in.readInt(), in.readInt());
}
sat = in.readInt();
bri = in.readInt();
ref = in.readInt();
locked = in.readBoolean();
} catch(Exception ex) {
throw new IOException("SBReference.load() : " + ex);
}
}
public static void loadDummyData(DataInputStream in) throws IOException {
try {
if(Theme.fileID >= Theme.FILE_ID_3A) {
in.readInt();
}
else {
in.readInt();
in.readInt();
in.readInt();
}
in.readInt();
in.readInt();
in.readInt();
in.readBoolean();
} catch(Exception ex) {
throw new IOException("SBReference.loadDummyData() : " + ex.getMessage());
}
}
class ColorIcon implements Icon {
private boolean paintGradients;
ColorIcon(boolean paintGradients) {
this.paintGradients = paintGradients;
}
public int getIconHeight() {
return 16;
}
public int getIconWidth() {
return 16;
}
public void paintIcon(Component comp, Graphics g, int x, int y) {
Color tempCol = g.getColor();
g.setColor(Color.GRAY);
g.drawRect(x, y, getIconWidth(), getIconHeight());
if(paintGradients) {
float hue = 0.0f;
for(int i = 0; i < 15; i++) {
g.setColor(Color.getHSBColor(hue, 0.5f, 1.0f));
g.drawLine(x + 1 + i, y + 1, x + 1 + i, y + getIconHeight() - 1);
hue += 1.0 / 16.0;
}
}
else {
g.setColor(color);
g.fillRect(x + 1, y + 1, getIconWidth() - 1, getIconHeight() - 1);
}
// draw arrow
if(comp instanceof AbstractButton) {
if(((AbstractButton)comp).isSelected()) {
g.setColor(Color.WHITE);
drawArrow(g, x + 1, y + 1);
g.setColor(Color.BLACK);
drawArrow(g, x, y);
}
}
g.setColor(tempCol);
}
private void drawArrow(Graphics g, int x, int y) {
g.drawLine(x + 3, y + 5, x + 3, y + 7);
g.drawLine(x + 4, y + 6, x + 4, y + 8);
g.drawLine(x + 5, y + 7, x + 5, y + 9);
g.drawLine(x + 6, y + 6, x + 6, y + 8);
g.drawLine(x + 7, y + 5, x + 7, y + 7);
g.drawLine(x + 8, y + 4, x + 8, y + 6);
g.drawLine(x + 9, y + 3, x + 9, y + 5);
}
}
}
--- NEW FILE: package.html ---
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<LINK REL ="stylesheet" TYPE="text/css" HREF="../../../stylesheet.css" TITLE="Style">
</HEAD>
<BODY>
This package contains some utility classes. Documentation is provided because most classes are used as data structures in
{@link de.muntjak.tinylookandfeel.Theme TinyLaF themes}.
</BODY>
</HTML>
--- NEW FILE: ColorRoutines.java ---
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* This file is part of the Tiny Look and Feel *
* Copyright 2003 - 2008 Hans Bickel *
* *
* For licensing information and credits, please refer to the *
* comment in file de.muntjak.tinylookandfeel.TinyLookAndFeel *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
package de.muntjak.tinylookandfeel.util;
import java.awt.*;
/**
* ColorRoutines is a collection of static utility methods related
* to color calculations.
*
* @version 1.0
* @author Hans Bickel
*/
public class ColorRoutines {
private static final int RGB = 1;
private static final int RBG = 2;
private static final int GBR = 3;
private static final int GRB = 4;
private static final int BRG = 5;
private static final int BGR = 6;
private static float hsb[] = new float[3];
private boolean preserveGrey;
private int chue, csat, cbri;
private int fr, fg, fb;
private int hi, lo, md;
private boolean hiIsR, hiIsG, hiIsB;
private boolean mdIsR, mdIsG, mdIsB;
private boolean loIsR, loIsG, loIsB;
ColorRoutines(HSBReference hsbRef) {
chue = hsbRef.hue;
csat = hsbRef.getSaturation();
cbri = hsbRef.getBrightness();
preserveGrey = hsbRef.isPreserveGrey();
Color c = Color.getHSBColor((float) ((double)chue / 360.0), 1.0f, 1.0f);
fr = c.getRed();
fg = c.getGreen();
fb = c.getBlue();
// sort colors - 6 options
if(fr >= fg && fg >= fb) {
hi = fr;
md = fg;
lo = fb;
hiIsR = true;
mdIsG = true;
loIsB = true;
}
else if(fr >= fb && fb >= fg) {
hi = fr;
md = fb;
lo = fg;
hiIsR = true;
mdIsB = true;
loIsG = true;
}
else if(fg >= fr && fr >= fb) {
hi = fg;
md = fr;
lo = fb;
hiIsG = true;
mdIsR = true;
loIsB = true;
}
else if(fg >= fb && fb >= fr) {
hi = fg;
md = fb;
lo = fr;
hiIsG = true;
mdIsB = true;
loIsR = true;
}
else if(fb >= fg && fg >= fr) {
hi = fb;
md = fg;
lo = fr;
hiIsB = true;
mdIsG = true;
loIsR = true;
}
else if(fb >= fr && fr >= fg) {
hi = fb;
md = fr;
lo = fg;
hiIsB = true;
mdIsR = true;
loIsG = true;
}
}
private void setHSB(int r, int g, int b) {
chue = getHue(r, g, b);
csat = getSaturation(r, g, b);
cbri = getBrightness(r, g, b);
}
public static Color getAverage(Color c1, Color c2) {
int r = (int)Math.round((c1.getRed() + c2.getRed()) / 2.0);
int g = (int)Math.round((c1.getGreen() + c2.getGreen()) / 2.0);
int b = (int)Math.round((c1.getBlue() + c2.getBlue()) / 2.0);
return new Color(r, g, b);
}
// i >= 0 <= d
// c1 ist Einblendfarbe
// c2 ist Hintergrundfarbe
public static Color getGradient(Color c1, Color c2, int d, int i) {
if(i == 0)
return c1;
if(i == d)
return c2;
double d2 = i * 1.1 / d;
double d1 = 1.0 - d2;
int r = (int)Math.round(c1.getRed() * d1 + c2.getRed() * d2);
int g = (int)Math.round(c1.getGreen() * d1 + c2.getGreen() * d2);
int b = (int)Math.round(c1.getBlue() * d1 + c2.getBlue() * d2);
return new Color(r, g, b);
}
private static Color getMaxSaturation(Color c, int memH) {
int r = c.getRed();
int g = c.getGreen();
int b = c.getBlue();
if(r == g && r == b)
return c;
int ta = 0, tb = 0, tc = 0;
int mapping = RGB;
if(r >= g && r >= b) {
tc = r;
if(g == b) {
ta = g;
tb = b;
mapping = RGB;
}
else if(g > b) {
ta = g;
tb = b;
mapping = RGB;
}
else {
tb = g;
ta = b;
mapping = RBG;
}
}
else if(g >= r && g >= b) {
tc = g;
if(r == b) {
ta = r;
tb = b;
mapping = GRB;
}
else if(r > b) {
ta = r;
tb = b;
mapping = GRB;
}
else {
tb = r;
ta = b;
mapping = GBR;
}
}
else if(b >= r && b >= g) {
tc = b;
if(r == g) {
ta = r;
tb = g;
mapping = BRG;
}
else if(r > g) {
ta = r;
tb = g;
mapping = BRG;
}
else {
tb = r;
ta = g;
mapping = BGR;
}
}
if(tb == 0) {
return c;
}
int nc = Math.min(255, tc + tb);
int nb = Math.max(0, tc + tb - 255);
int na = ta;
int h = 0, mh = 0;
int ba = 0, delta = 360;
Color rc = null;
switch (mapping) {
case RGB :
h = getHue(nc, na, nb);
mh = h;
while (h != memH && na < 256) {
h = getHue(nc, ++na, nb);
if(na == 256)
break;
if(h == memH) {
return new Color(nc, na, nb);
}
else if((mh < memH && h > memH) || (mh > memH && h < memH)) {
return new Color(nc, na, nb);
}
else if(Math.abs(h - memH) < delta) {
delta = Math.abs(h - memH);
ba = na;
}
mh = h;
}
if(h != memH) {
h = getHue(nc, na, nb);
mh = h;
na = ta;
while (h != memH && na >= 0) {
h = getHue(nc, --na, nb);
if(na == -1)
break;
if(h == memH) {
return new Color(nc, na, nb);
}
else if((mh < memH && h > memH) || (mh > memH && h < memH)) {
return new Color(nc, na, nb);
}
else if(Math.abs(h - memH) < delta) {
delta = Math.abs(h - memH);
ba = na;
}
mh = h;
}
}
if(na == 256 | na == -1) {
na = ba;
}
rc = new Color(nc, na, nb);
break;
case RBG :
h = getHue(nc, nb, na);
mh = h;
while (h != memH && na < 256) {
h = getHue(nc, nb, ++na);
if(na == 256)
break;
if(h == memH) {
return new Color(nc, nb, na);
}
else if((mh < memH && h > memH) || (mh > memH && h < memH)) {
return new Color(nc, nb, na);
}
else if(Math.abs(h - memH) < delta) {
delta = Math.abs(h - memH);
ba = na;
}
mh = h;
}
if(h != memH) {
h = getHue(nc, na, nb);
mh = h;
na = ta;
while (h != memH && na >= 0) {
h = getHue(nc, nb, --na);
if(na == -1)
break;
if(h == memH) {
return new Color(nc, nb, na);
}
else if((mh < memH && h > memH) || (mh > memH && h < memH)) {
return new Color(nc, nb, na);
}
else if(Math.abs(h - memH) < delta) {
delta = Math.abs(h - memH);
ba = na;
}
mh = h;
}
}
if(na == 256 | na == -1) {
na = ba;
}
rc = new Color(nc, nb, na);
break;
case GBR :
h = getHue(nb, nc, na);
mh = h;
while (h != memH && na < 256) {
h = getHue(nb, nc, ++na);
if(na == 256)
break;
if(h == memH) {
return new Color(nb, nc, na);
}
else if((mh < memH && h > memH) || (mh > memH && h < memH)) {
return new Color(nb, nc, na);
}
else if(Math.abs(h - memH) < delta) {
delta = Math.abs(h - memH);
ba = na;
}
mh = h;
}
if(h != memH) {
h = getHue(nc, na, nb);
mh = h;
na = ta;
while (h != memH && na >= 0) {
h = getHue(nb, nc, --na);
if(na == -1)
break;
if(h == memH) {
return new Color(nb, nc, na);
}
else if((mh < memH && h > memH) || (mh > memH && h < memH)) {
return new Color(nb, nc, na);
}
else if(Math.abs(h - memH) < delta) {
delta = Math.abs(h - memH);
ba = na;
}
mh = h;
}
}
if(na == 256 | na == -1) {
na = ba;
}
rc = new Color(nb, nc, na);
break;
case GRB :
h = getHue(na, nc, nb);
mh = h;
while (h != memH && na < 256) {
h = getHue(++na, nc, nb);
if(na == 256)
break;
if(h == memH) {
return new Color(na, nc, nb);
}
else if((mh < memH && h > memH) || (mh > memH && h < memH)) {
return new Color(na, nc, nb);
}
else if(Math.abs(h - memH) < delta) {
delta = Math.abs(h - memH);
ba = na;
}
mh = h;
}
if(h != memH) {
h = getHue(nc, na, nb);
mh = h;
na = ta;
while (h != memH && na >= 0) {
h = getHue(--na, nc, nb);
if(na == -1)
break;
if(h == memH) {
return new Color(na, nc, nb);
}
else if((mh < memH && h > memH) || (mh > memH && h < memH)) {
return new Color(na, nc, nb);
}
else if(Math.abs(h - memH) < delta) {
delta = Math.abs(h - memH);
ba = na;
}
mh = h;
}
}
if(na == 256 | na == -1) {
na = ba;
}
rc = new Color(na, nc, nb);
break;
case BRG :
h = getHue(na, nb, nc);
mh = h;
while (h != memH && na < 256) {
h = getHue(++na, nb, nc);
if(na == 256)
break;
if(h == memH) {
return new Color(na, nb, nc);
}
else if((mh < memH && h > memH) || (mh > memH && h < memH)) {
return new Color(na, nb, nc);
}
else if(Math.abs(h - memH) < delta) {
delta = Math.abs(h - memH);
ba = na;
}
mh = h;
}
if(h != memH) {
h = getHue(nc, na, nb);
mh = h;
na = ta;
while (h != memH && na >= 0) {
h = getHue(--na, nb, nc);
if(na == -1)
break;
if(h == memH) {
return new Color(na, nb, nc);
}
else if((mh < memH && h > memH) || (mh > memH && h < memH)) {
return new Color(na, nb, nc);
}
else if(Math.abs(h - memH) < delta) {
delta = Math.abs(h - memH);
ba = na;
}
mh = h;
}
}
if(na == 256 | na == -1) {
na = ba;
}
rc = new Color(na, nb, nc);
break;
case BGR :
h = getHue(nb, na, nc);
mh = h;
while (h != memH && na < 256) {
h = getHue(nb, ++na, nc);
if(na == 256)
break;
if(h == memH) {
return new Color(nb, na, nc);
}
else if((mh < memH && h > memH) || (...
[truncated message content] |