Update of /cvsroot/squirrel-sql/mavenize/thirdparty-non-maven/tinylaf-1_4_0/src/de/muntjak/tinylookandfeel/controlpanel
In directory sfp-cvsdas-3.v30.ch3.sourceforge.com:/tmp/cvs-serv29130/thirdparty-non-maven/tinylaf-1_4_0/src/de/muntjak/tinylookandfeel/controlpanel
Added Files:
SBChooser.java ControlPanel.java NonSortableTableModel.java
ParameterSetGenerator.java Selectable.java
NumericTextField.java IconRenderer.java
CheckForUpdatesDialog.java TinyTableModel.java
PlainDialog.java SBControl.java HelpDialog.java
ParameterSet.java InsetsControl.java IntControl.java
Selection.java PSColorChooser.java HSBChooser.java
UndoManager.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: Selectable.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.controlpanel;
/**
* Selectable
* @author Hans Bickel
*
*/
public interface Selectable {
public boolean isSelected();
public void setSelected(boolean selected);
}
--- NEW FILE: PlainDialog.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.controlpanel;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
* PlainDialog is a non-modal dialog for showing
* dialog decoration.
*
* @version 1.0
* @author Hans Bickel
*/
public class PlainDialog extends JDialog {
private static int count = 1;
PlainDialog(Frame owner) {
super(owner, "JDialog " + (count++), false);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
JPanel p = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 12));
JLabel l = new JLabel("<html><center>" +
"A <font color=\"#0000ff\">JDialog</font> for testing<br>" +
"dialog decoration.");
p.add(l);
getContentPane().add(p, BorderLayout.CENTER);
p = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 12));
JButton b = new JButton("Close");
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
PlainDialog.this.dispose();
}
});
p.add(b);
getContentPane().add(p, BorderLayout.SOUTH);
pack();
int w = Math.max(240, getWidth() + 32), h = getHeight();
Point loc = new Point(
owner.getLocationOnScreen().x + (owner.getWidth() - w) / 2,
owner.getLocationOnScreen().y + (owner.getHeight() - w) * 2 / 3);
setSize(w, h);
setLocation(loc);
setVisible(true);
}
}
--- NEW FILE: NumericTextField.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.controlpanel;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
/**
* NumericTextField
*
* @version 1.0
* @author Hans Bickel
*/
public class NumericTextField extends JTextField {
private Vector listeners;
private ActionEvent actionEvent;
private int min, max, columns;
private boolean resistUpdate;
public NumericTextField(int columns, int value, int min, int max) {
super(columns);
this.columns = columns;
this.min = min;
this.max = max;
setHorizontalAlignment(JTextField.RIGHT);
setText("" + value);
addKeyListener(new ArrowKeyAction(this, min, max));
actionEvent = new ActionEvent(this, Event.ACTION_EVENT, "");
}
public int getValue() {
if(getText().length() == 0) return 0;
return Integer.parseInt(getText());
}
public void setValue(int newValue) {
if(resistUpdate) return;
setText(String.valueOf(newValue));
}
public void addActionListener(ActionListener l) {
if(listeners == null) {
listeners = new Vector();
}
if(listeners.contains(l)) return;
listeners.add(l);
}
public void removeActionListener(ActionListener l) {
if(listeners == null) return;
if(!listeners.contains(l)) return;
listeners.remove(l);
}
public void notifyActionListeners() {
if(listeners == null) return;
resistUpdate = true;
Iterator ii = listeners.iterator();
while(ii.hasNext()) {
((ActionListener)ii.next()).actionPerformed(actionEvent);
}
resistUpdate = false;
}
protected Document createDefaultModel() {
return new NumericDocument();
}
protected class NumericDocument extends PlainDocument {
NumericDocument() {
addDocumentListener(new KeyInputListener());
}
public void insertString(
int offs,
String str,
AttributeSet a) throws BadLocationException
{
if(str == null || str.length() == 0) return;
if(getLength() + str.length() > columns) return;
if(!checkInput(str)) {
Toolkit.getDefaultToolkit().beep();
return;
}
String text = getText(0, getLength());
if(offs == 0) {
text = str + text;
}
else if(offs >= text.length()) {
text += str;
}
else {
text = text.substring(0, offs) + str + text.substring(offs);
}
int val = Integer.parseInt(text);
boolean correct = false;
if(val < min) {
val = min;
correct = true;
}
else if(val > max) {
val = max;
correct = true;
}
if(correct) {
remove(0, getLength());
super.insertString(0, String.valueOf(val), a);
}
else {
super.insertString(offs, str, a);
}
}
private boolean checkInput(String s) {
for(int i = 0; i < s.length(); i++) {
if(!Character.isDigit(s.charAt(i))) {
return false;
}
}
return true;
}
}
class ArrowKeyAction extends KeyAdapter implements ActionListener {
private JTextField theField;
private javax.swing.Timer keyTimer;
private int step;
ArrowKeyAction(JTextField field, int min, int max) {
theField = field;
keyTimer = new javax.swing.Timer(20, this);
}
public void keyPressed(KeyEvent e) {
if(e.getKeyCode() == 38) { // up => decrease
step = 1;
if(e.getModifiers() == KeyEvent.SHIFT_MASK) {
step = 10;
}
changeVal();
keyTimer.setInitialDelay(300);
keyTimer.start();
}
else if(e.getKeyCode() == 40) { // up => increase
step = -1;
if(e.getModifiers() == KeyEvent.SHIFT_MASK) {
step = -10;
}
changeVal();
keyTimer.setInitialDelay(300);
keyTimer.start();
}
}
public void keyReleased(KeyEvent e) {
keyTimer.stop();
}
// the keyTimer action
public void actionPerformed(ActionEvent e) {
changeVal();
}
private void changeVal() {
int val = Integer.parseInt(theField.getText()) + step;
if(val > max) val = max;
else if(val < min) val = min;
// this should trigger insertUpdate()
theField.setText("" + val);
}
}
class KeyInputListener implements DocumentListener {
public void changedUpdate(DocumentEvent e) {
}
public void insertUpdate(DocumentEvent e) {
notifyActionListeners();
}
public void removeUpdate(DocumentEvent e) {
notifyActionListeners();
}
}
}
--- NEW FILE: IconRenderer.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.controlpanel;
import java.awt.Component;
import javax.swing.Icon;
import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;
/**
* Renders the icon column of the example table.
* @author Hans Bickel
*/
public class IconRenderer extends DefaultTableCellRenderer {
public IconRenderer() {
setHorizontalAlignment(SwingConstants.CENTER);
}
public void setValue(Object value) {
setIcon((value instanceof Icon) ? (Icon)value : null);
}
}
--- NEW FILE: HelpDialog.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.controlpanel;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Frame;
import java.io.IOException;
import java.net.URL;
import javax.swing.JDialog;
import javax.swing.JEditorPane;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
public class HelpDialog extends JDialog implements HyperlinkListener {
private static HelpDialog instance;
private static JEditorPane editor;
private static URL helpURL;
private HelpDialog(Frame owner) {
super(owner, "Control Panel Help", false);
setDefaultCloseOperation(HIDE_ON_CLOSE);
helpURL = getClass().getResource("/help/help.html");
if(helpURL != null) {
try {
editor = new JEditorPane(helpURL);
}
catch(IOException ex) {
System.err.println(ex.toString());
helpURL = null;
}
}
if(helpURL == null) {
String html = "<html><body><center><h2><font color=\"#FF0000\">" +
"Couldn't set up the online help." +
"</h2></body></html>";
editor = new JEditorPane("text/html", html);
}
editor.setBackground(new Color(237, 237, 237));
editor.setEditable(false);
editor.addHyperlinkListener(this);
setupUI(owner);
}
public static void showDialog(Frame owner) {
if(instance == null) {
instance = new HelpDialog(owner);
}
instance.setVisible(true);
}
public static void updateUI() {
if(instance == null) return;
SwingUtilities.updateComponentTreeUI(instance);
}
public void setupUI(Frame frame) {
JScrollPane sp = new JScrollPane(editor);
getContentPane().add(sp);
pack();
setSize(800, 600);
setLocation(frame.getLocationOnScreen().x +
(frame.getWidth() - getSize().width) / 2,
frame.getLocationOnScreen().y +
(frame.getHeight() - getSize().height) / 2);
}
public void hyperlinkUpdate(HyperlinkEvent e) {
if(e.getEventType() != HyperlinkEvent.EventType.ACTIVATED) return;
try {
editor.setPage(e.getURL());
}
catch(IOException ex) {
System.err.println(ex.toString());
}
}
}
--- NEW FILE: ControlPanel.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.controlpanel;
import java.awt.AWTEvent;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.ComponentOrientation;
import java.awt.Container;
import java.awt.Dimension;
[...10150 lines suppressed...]
hue += 360 / 15;
}
public int getIconHeight() {
return iconSize.height;
}
public int getIconWidth() {
return iconSize.width;
}
public void paintIcon(Component comp, Graphics g, int x, int y) {
g.setColor(color);
g.fillRect(x + 1, y + 1, getIconWidth() - 2, getIconHeight() - 2);
g.setColor(Color.BLACK);
g.drawRect(x, y, getIconWidth() - 1, getIconHeight() - 1);
}
}
}
--- NEW FILE: SBChooser.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.controlpanel;
import java.util.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;
import javax.swing.plaf.metal.MetalSliderUI;
import javax.swing.text.*;
import de.muntjak.tinylookandfeel.controlpanel.*;
import de.muntjak.tinylookandfeel.util.ColorRoutines;
/**
* SBChooser
*
* @version 1.0
* @author Hans Bickel
*/
public class SBChooser extends JDialog {
private static SBChooser myInstance;
private static int sat, bri;
private Color reference, outColor;
private JSlider satSlider, briSlider;
private JTextField satField, briField;
private JTextField redField, greenField, blueField;
private TwoColorField twoColorField;
private ColorField referenceField;
private boolean keyInput = false;
private boolean valueIsAdjusting = false;
public SBChooser(Frame frame) {
super(frame, "Saturation/Brightness", true);
setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
setupUI(frame);
}
private void setupUI(Frame frame) {
ChangeListener sliderAction = new SliderAction();
JPanel p1 = new JPanel(new BorderLayout(12, 0));
p1.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 0));
JPanel p2 = new JPanel(new GridLayout(2, 1, 0, 8));
JPanel p3 = new JPanel(new FlowLayout(FlowLayout.LEFT, 2, 4));
JPanel p4 = new JPanel(new BorderLayout(4, 0));
// sliders
JPanel p5 = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
p4.add(new JLabel("Saturation"), BorderLayout.NORTH);
satSlider = new JSlider(-100, 100, sat);
satSlider.addChangeListener(sliderAction);
satSlider.setMajorTickSpacing(100);
satSlider.setPaintTicks(true);
p4.add(satSlider, BorderLayout.CENTER);
satField = new JTextField("" + satSlider.getValue(), 4);
satField.getDocument().addDocumentListener(new SatInputListener());
satField.addKeyListener(new ArrowKeyAction(satField, -100, 100));
satField.setHorizontalAlignment(JTextField.CENTER);
p5.add(satField);
p4.add(p5, BorderLayout.EAST);
p2.add(p4);
p5 = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
p4 = new JPanel(new BorderLayout(4, 0));
p4.add(new JLabel("Brightness"), BorderLayout.NORTH);
briSlider = new JSlider(-100, 100, bri);
briSlider.addChangeListener(sliderAction);
briSlider.setMajorTickSpacing(100);
briSlider.setPaintTicks(true);
p4.add(briSlider, BorderLayout.CENTER);
briField = new JTextField("" + briSlider.getValue(), 4);
briField.getDocument().addDocumentListener(new BriInputListener());
briField.addKeyListener(new ArrowKeyAction(briField, -100, 100));
briField.setHorizontalAlignment(JTextField.CENTER);
p5.add(briField);
p4.add(p5, BorderLayout.EAST);
p2.add(p4);
p3.add(p2);
p1.add(p3, BorderLayout.CENTER);
// color panel
p2 = new JPanel(new BorderLayout(0, 6));
p3 = new JPanel(new FlowLayout(FlowLayout.LEFT, 4, 4));
twoColorField = new TwoColorField(reference);
p2.add(twoColorField, BorderLayout.NORTH);
referenceField = new ColorField(reference);
p2.add(referenceField, BorderLayout.CENTER);
p3.add(p2);
p1.add(p3, BorderLayout.EAST);
// RGB fields
p3 = new JPanel(new FlowLayout(FlowLayout.LEFT, 3, 8));
p3.add(new JLabel("R:"));
redField = new JTextField(4);
redField.setHorizontalAlignment(JTextField.CENTER);
redField.setEditable(false);
p3.add(redField);
p3.add(new JLabel(" G:"));
greenField = new JTextField(4);
greenField.setHorizontalAlignment(JTextField.CENTER);
greenField.setEditable(false);
p3.add(greenField);
p3.add(new JLabel(" B:"));
blueField = new JTextField(4);
blueField.setHorizontalAlignment(JTextField.CENTER);
blueField.setEditable(false);
p3.add(blueField);
p1.add(p3, BorderLayout.SOUTH);
getContentPane().add(p1, BorderLayout.CENTER);
// buttons
p3 = new JPanel(new FlowLayout(FlowLayout.RIGHT, 8, 4));
p3.setBorder(new EtchedBorder());
JButton b = new JButton("Cancel");
b.setMnemonic(KeyEvent.VK_C);
b.addActionListener(new CancelAction());
p3.add(b);
b = new JButton("OK");
b.setMnemonic(KeyEvent.VK_O);
getRootPane().setDefaultButton(b);
b.addActionListener(new OKAction());
p3.add(b);
getContentPane().add(p3, BorderLayout.SOUTH);
pack();
Dimension size = getSize();
setLocation(frame.getLocationOnScreen().x +
(frame.getWidth() - getSize().width) / 2,
frame.getLocationOnScreen().y +
(frame.getHeight() - getSize().height) / 2);
}
public static Color showSBChooser(Frame frame, Color ref, Color inColor, int s, int b) {
if(myInstance == null) {
myInstance = new SBChooser(frame);
}
myInstance.setColor(ref, inColor, s, b);
myInstance.setVisible(true);
return myInstance.outColor;
}
public static Color showSBChooser(Frame frame, SBControl hsb) {
if(myInstance == null) {
myInstance = new SBChooser(frame);
}
myInstance.setColor(hsb);
myInstance.setVisible(true);
return myInstance.outColor;
}
public static void deleteInstance() {
myInstance = null;
}
public void setColor(SBControl hsb) {
reference = hsb.getSBReference().getReferenceColor();
outColor = hsb.getBackground();
sat = hsb.getSBReference().getSaturation();
bri = hsb.getSBReference().getBrightness();
valueIsAdjusting = true;
satSlider.setValue(sat);
briSlider.setValue(bri);
valueIsAdjusting = false;
referenceField.setBackground(reference);
twoColorField.setLowerColor(outColor);
adjustColor();
}
public void setColor(Color ref, Color inColor, int s, int b) {
reference = ref;
outColor = inColor;
sat = s;
bri = b;
valueIsAdjusting = true;
satSlider.setValue(sat);
briSlider.setValue(bri);
valueIsAdjusting = false;
referenceField.setBackground(reference);
twoColorField.setLowerColor(inColor);
adjustColor();
}
private void showColor(int s, int b) {
sat = s;
bri = b;
adjustColor();
}
private void adjustColor() {
outColor = ColorRoutines.getAdjustedColor(reference, sat, bri);
twoColorField.setUpperColor(outColor);
}
public static int getSaturation() { return sat; }
public static int getBrightness() { return bri; }
class TwoColorField extends JPanel {
private Dimension size = new Dimension(60, 68);
private Color upperColor, lowerColor;
TwoColorField(Color c) {
setBorder(new LineBorder(Color.BLACK, 1));
upperColor = outColor;
lowerColor = c;
}
public Dimension getPreferredSize() {
return size;
}
void setUpperColor(Color c) {
upperColor = c;
redField.setText("" + c.getRed());
greenField.setText("" + c.getGreen());
blueField.setText("" + c.getBlue());
repaint(0);
}
void setLowerColor(Color c) {
lowerColor = c;
repaint(0);
}
public void paint(Graphics g) {
super.paintBorder(g);
g.setColor(upperColor);
g.fillRect(1, 1, 58, 33);
g.setColor(lowerColor);
g.fillRect(1, 34, 58, 33);
}
}
class ColorField extends JPanel {
private Dimension size = new Dimension(60, 38);
ColorField(Color c) {
setBorder(new LineBorder(Color.GRAY, 1));
setBackground(c);
}
public Dimension getPreferredSize() {
return size;
}
}
class SliderAction implements ChangeListener {
public void stateChanged(ChangeEvent e) {
if(!keyInput) {
if(e.getSource().equals(satSlider)) {
satField.setText("" + satSlider.getValue());
}
else {
briField.setText("" + briSlider.getValue());
}
}
if(valueIsAdjusting) return;
showColor(satSlider.getValue(), briSlider.getValue());
}
}
class SatInputListener implements DocumentListener {
public void changedUpdate(DocumentEvent e) {
}
public void insertUpdate(DocumentEvent e) {
update(e);
}
public void removeUpdate(DocumentEvent e) {
update(e);
}
private void update(DocumentEvent e) {
Document doc = e.getDocument();
try {
String text = doc.getText(0, doc.getLength());
try {
int val = Integer.parseInt(text);
keyInput = true;
satSlider.setValue(val);
keyInput = false;
} catch(NumberFormatException ignore) {}
} catch (BadLocationException ignore) {}
}
}
class BriInputListener implements DocumentListener {
public void changedUpdate(DocumentEvent e) {
}
public void insertUpdate(DocumentEvent e) {
update(e);
}
public void removeUpdate(DocumentEvent e) {
update(e);
}
private void update(DocumentEvent e) {
Document doc = e.getDocument();
try {
String text = doc.getText(0, doc.getLength());
try {
int val = Integer.parseInt(text);
keyInput = true;
briSlider.setValue(val);
keyInput = false;
} catch(NumberFormatException ignore) {}
} catch (BadLocationException ignore) {}
}
}
class ArrowKeyAction extends KeyAdapter implements ActionListener {
private JTextField theField;
private javax.swing.Timer keyTimer;
private int step, min, max;
ArrowKeyAction(JTextField field, int min, int max) {
theField = field;
this.min = min;
this.max = max;
keyTimer = new javax.swing.Timer(20, this);
}
public void keyPressed(KeyEvent e) {
if(e.getKeyCode() == 38) { // up => decrease
step = 1;
if(e.getModifiers() == KeyEvent.SHIFT_MASK) {
step = 10;
}
changeVal();
keyTimer.setInitialDelay(300);
keyTimer.start();
}
else if(e.getKeyCode() == 40) { // up => increase
step = -1;
if(e.getModifiers() == KeyEvent.SHIFT_MASK) {
step = -10;
}
changeVal();
keyTimer.setInitialDelay(300);
keyTimer.start();
}
}
public void keyReleased(KeyEvent e) {
keyTimer.stop();
}
public void actionPerformed(ActionEvent e) {
changeVal();
}
private void changeVal() {
int val = Integer.parseInt(theField.getText()) + step;
if(val > max) val = max;
else if(val < min) val = min;
theField.setText("" + val);
}
}
class OKAction implements ActionListener {
public void actionPerformed(ActionEvent e) {
setVisible(false);
}
}
class CancelAction implements ActionListener {
public void actionPerformed(ActionEvent e) {
outColor = null;
setVisible(false);
}
}
}
--- NEW FILE: ParameterSet.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.controlpanel;
import java.awt.Insets;
import java.util.Vector;
import javax.swing.plaf.InsetsUIResource;
import de.muntjak.tinylookandfeel.Theme;
import de.muntjak.tinylookandfeel.controlpanel.ControlPanel.HSBControl;
import de.muntjak.tinylookandfeel.controlpanel.ControlPanel.SpreadControl;
import de.muntjak.tinylookandfeel.util.BooleanReference;
import de.muntjak.tinylookandfeel.util.ColoredFont;
import de.muntjak.tinylookandfeel.util.HSBReference;
import de.muntjak.tinylookandfeel.util.IntReference;
import de.muntjak.tinylookandfeel.util.SBReference;
/**
* ParameterSet
* @author Hans Bickel
*
*/
public class ParameterSet {
static ControlPanel controlPanel;
private ParameterSetGenerator generator;
private Vector references;
private Vector values;
private Vector referenceColors;
private String name;
/**
* Creates a new ParameterSet, either from the current
* selection or from an entire CP.
* @param generator
* @param name
*/
ParameterSet(ParameterSetGenerator generator, String name) {
this.generator = generator;
this.name = name;
values = new Vector();
references = new Vector();
referenceColors = getReferenceColors();
}
/**
* Gets vector of ColorUIResources.
* @return
*/
private Vector getReferenceColors() {
Vector v = new Vector();
v.add(Theme.mainColor.getColor());
v.add(Theme.backColor.getColor());
v.add(Theme.disColor.getColor());
v.add(Theme.frameColor.getColor());
v.add(Theme.sub1Color.getColor());
v.add(Theme.sub2Color.getColor());
v.add(Theme.sub3Color.getColor());
v.add(Theme.sub4Color.getColor());
v.add(Theme.sub5Color.getColor());
v.add(Theme.sub6Color.getColor());
v.add(Theme.sub7Color.getColor());
v.add(Theme.sub8Color.getColor());
return v;
}
/**
* Stores current reference colors.
*
*/
public void updateReferenceColors() {
referenceColors = getReferenceColors();
}
/**
* Copy constructor.
* @param ps
*/
public ParameterSet(ParameterSet ps) {
generator = ps.generator;
name = ps.name;
references = (Vector)ps.references.clone();
values = (Vector)ps.values.clone();
// Note: It's essential to retrieve the
// current colors (and not copy from argument)
referenceColors = getReferenceColors();
}
public ParameterSetGenerator getGenerator() {
return generator;
}
public String getUndoString() {
return "Paste " + name + " Parameters";
}
/**
* Clones argument's value vector.
* @param other
*/
public void updateValues(ParameterSet other) {
values = (Vector)other.values.clone();
}
/**
* Sets all values to the current value of the reference.
* This allows for doing a redo after an undo
* (or vice versa). Changes values only.
*
*/
public void updateValues() {
Vector temp = new Vector(values.size());
int end = values.size();
for(int i = 0; i < end; i++) {
Object value = values.get(i);
Object reference = references.get(i);
if(reference instanceof BooleanReference) {
// value is Boolean
temp.add(new Boolean(((BooleanReference)reference).getValue()));
}
// because HSBReference *is a* SBReference,
// it must come before SBReference
else if(reference instanceof HSBReference) {
// value is HSBReference
temp.add(new HSBReference((HSBReference)reference));
}
else if(reference instanceof SBReference) {
// value is SBReference
temp.add(new SBReference((SBReference)reference));
}
else if(reference instanceof IntReference) {
// value is Integer
temp.add(new Integer(((IntReference)reference).getValue()));
}
else if(reference instanceof InsetsUIResource) {
// value is Insets
InsetsUIResource r = (InsetsUIResource)reference;
temp.add(new Insets(r.top, r.left, r.bottom, r.right));
}
else if(reference instanceof ColoredFont) {
// value is ColoredFont
temp.add(new ColoredFont((ColoredFont)reference));
}
}
values = temp;
}
void addParameter(boolean value, BooleanReference reference) {
values.add(new Boolean(value));
// reference is BooleanReference
references.add(reference);
}
void addParameter(SBControl control) {
if(control.getSBReference().isReferenceColor()) {
// reference colors must be inserted at the beginning
if(control.getSBReference().isAbsoluteColor()) {
values.add(0, new SBReference(control.getSBReference()));
// reference is SBReference
references.add(0, control.getSBReference());
}
else { // not an absolute color
// find index to insert
int end = values.size();
int index = 0;
for(int i = 0; i < end; i++) {
Object value = values.get(i);
if(value instanceof SBReference) {
if(!((SBReference)value).isReferenceColor()) {
index = i;
break;
}
}
else {
index = i;
break;
}
}
values.add(index, new SBReference(control.getSBReference()));
// reference is SBReference
references.add(index, control.getSBReference());
}
}
else {
values.add(new SBReference(control.getSBReference()));
// reference is SBReference
references.add(control.getSBReference());
}
}
void addParameter(SpreadControl control) {
values.add(new Integer(control.getValue()));
// reference is IntReference
references.add(control.getIntReference());
}
void addParameter(IntControl control) {
values.add(control.getValue());
// reference is IntReference
references.add(control.getIntReference());
}
void addParameter(Insets value, InsetsUIResource reference) {
values.add(value);
// reference is InsetsUIResource
references.add(reference);
}
void addParameter(HSBControl control) {
values.add(new HSBReference(control.getHSBReference()));
// reference is HSBReference
references.add(control.getHSBReference());
}
void addParameter(ColoredFont cf) {
values.add(new ColoredFont(cf));
// reference is ColoredFont
references.add(cf);
}
/**
* Sets the values of all references to the current
* values stored.
* @param storeUndoData
*/
public void pasteParameters(boolean storeUndoData) {
if(storeUndoData) ControlPanel.instance.storeUndoData(this);
// set all references to stored value
int end = values.size();
for(int i = 0; i < end; i++) {
Object value = values.get(i);
Object reference = references.get(i);
if(reference instanceof BooleanReference) {
// value is Boolean
((BooleanReference)reference).setValue(
((Boolean)value).booleanValue());
}
// because HSBReference *is a* SBReference,
// it must come before SBReference
else if(reference instanceof HSBReference) {
// value is HSBReference
((HSBReference)reference).update(
(HSBReference)value, referenceColors);
}
else if(reference instanceof SBReference) {
// value is SBReference
((SBReference)reference).update(
(SBReference)value, referenceColors);
}
else if(reference instanceof IntReference) {
// value is Integer
((IntReference)reference).setValue(
((Integer)value).intValue());
}
else if(reference instanceof InsetsUIResource) {
// value is Insets
InsetsUIResource r = (InsetsUIResource)reference;
Insets v = (Insets)value;
r.top = v.top;
r.left = v.left;
r.bottom = v.bottom;
r.right = v.right;
}
else if(reference instanceof ColoredFont) {
// value is SBReference
((ColoredFont)reference).update(
(ColoredFont)value, referenceColors);
}
}
generator.init(true); // not called from setTheme() sequence
ControlPanel.instance.initPanels();
ControlPanel.instance.setTheme();
}
public String toString() {
StringBuffer buff = new StringBuffer("ParameterSet:");
int end = values.size();
for(int i = 0; i < end; i++) {
Object value = values.get(i);
Object reference = references.get(i);
buff.append("\n reference: " + reference);
buff.append("\n value: " + value);
}
return buff.toString();
}
}
--- NEW FILE: CheckForUpdatesDialog.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.controlpanel;
import java.awt.BorderLayout;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.ConnectException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.UnknownHostException;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.border.EmptyBorder;
import de.muntjak.tinylookandfeel.TinyLookAndFeel;
public class CheckForUpdatesDialog extends JDialog {
// local - resolves to D:\\htdocs\tinylaf\...
// private static final String CHECK_UPDATES_URL =
// "http://localhost:8080/tinylaf/checkforupdate.html";
// web
private static final String CHECK_UPDATES_URL =
"http://www.muntjak.de/hans/java/tinylaf/checkforupdate.html";
private CheckForUpdatesDialog(Frame parent) {
super(parent, "Check for Updates", true);
setupUI(parent);
}
static void showDialog(Frame parent) {
new CheckForUpdatesDialog(parent);
}
private void setupUI(Frame frame) {
getContentPane().setLayout(new BorderLayout(0, 0));
JPanel p = new JPanel(new BorderLayout(0, 12));
JLabel l = new JLabel("<html>" +
"When checking for updates, TinyLaF will connect to <b>muntjak.de</b>" +
"<br>via HTTP. No personal data will be transmitted.");
l.setBorder(new EmptyBorder(8, 8, 0, 8));
p.add(l, BorderLayout.NORTH);
JButton b = new JButton("Check for updates now");
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String msg = checkForUpdates();
int index = msg.indexOf("Exception was: ");
if(index != -1) {
String title = msg.substring(index + 15);
JOptionPane.showMessageDialog(
CheckForUpdatesDialog.this, msg,
title, JOptionPane.PLAIN_MESSAGE);
}
else {
if(msg.startsWith("No ")) {
JOptionPane.showMessageDialog(
CheckForUpdatesDialog.this, msg,
"Update Information",
JOptionPane.PLAIN_MESSAGE);
}
else {
new UpdateDialog(CheckForUpdatesDialog.this, msg);
}
}
}
});
JPanel flow = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 8));
flow.add(b);
p.add(flow, BorderLayout.CENTER);
p.add(new JSeparator(), BorderLayout.SOUTH);
getContentPane().add(p, BorderLayout.CENTER);
b = new JButton("Close");
getRootPane().setDefaultButton(b);
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
}
});
flow = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 8));
flow.add(b);
getContentPane().add(flow, BorderLayout.SOUTH);
pack();
Dimension size = getSize();
setLocation(frame.getLocationOnScreen().x +
(frame.getWidth() - size.width) / 2,
frame.getLocationOnScreen().y +
(frame.getHeight() - size.height) / 2);
setVisible(true);
}
private String checkForUpdates() {
// The string we expect is in format:
// TinyLaF v.v.v (yyyy/m/d)
// where v, m and d represent one or more numbers
// and yyyy must be a 4-digit year
// String answer = "TinyLaF 1.4.0 (2008/8/25)";
String answer = checkForUpdate();
if(answer.indexOf("Exception") != -1) return answer;
if(!answer.matches("TinyLaF \\d+\\.\\d+\\.\\d+\\s\\(\\d\\d\\d\\d/\\d+/\\d+\\)")) {
System.out.println("? Invalid response format: '" + answer + "'");
return "An exception occured while checking for updates." +
"\n\nException was: Invalid response.";
}
String version = answer.substring(8);
String expectedVersion = TinyLookAndFeel.VERSION_STRING + " (" + TinyLookAndFeel.DATE_STRING + ")";
if(!version.equals(expectedVersion)) {
return answer;
}
else {
return "No updated version of TinyLaF available.";
}
}
private String checkForUpdate() {
InputStream is = null;
try {
URL url = new URL(CHECK_UPDATES_URL);
try {
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setRequestProperty("User-Agent", "TinyLaF");
Object content = conn.getContent();
if(!(content instanceof InputStream)) {
return "An exception occured while checking for updates." +
"\n\nException was: Content is no InputStream";
}
is = (InputStream)content;
}
catch (IOException ex) {
// ex.printStackTrace();
return "An exception occured while checking for updates." +
"\n\nException was: " + ex.getClass().getName();
}
}
catch(MalformedURLException ex) {
// ex.printStackTrace();
return "An exception occured while checking for updates." +
"\n\nException was: " + ex.getClass().getName();
}
// read message returned from muntjak server
try {
BufferedReader in = new BufferedReader(
new InputStreamReader(is));
StringBuffer buff = new StringBuffer();
String line;
while((line = in.readLine()) != null) {
buff.append(line);
}
in.close();
return buff.toString();
}
catch (IOException ex) {
// ex.printStackTrace();
return "An exception occured while checking for updates." +
"\n\nException was: " + ex.getClass().getName();
}
}
private class UpdateDialog extends JDialog {
UpdateDialog(Dialog owner, String version) {
super(CheckForUpdatesDialog.this, "Update Information", true);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
getContentPane().setLayout(new BorderLayout());
String msg = "<html>" +
"An updated version of TinyLaF is available:<br>" +
version + "<br>" +
"It can be downloaded at www.muntjak.de/hans/java/tinylaf/.";
JPanel p = new JPanel(new FlowLayout(FlowLayout.CENTER, 12, 8));
p.add(new JLabel(msg));
getContentPane().add(p, BorderLayout.CENTER);
p = new JPanel(new FlowLayout(FlowLayout.CENTER, 8, 10));
JButton b = new JButton("Copy Link");
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
if(cb == null) {
JOptionPane.showMessageDialog(UpdateDialog.this,
"System Clipboard not available.",
"Error",
JOptionPane.ERROR_MESSAGE);
}
else {
StringSelection ss = new StringSelection(
"http://www.muntjak.de/hans/java/tinylaf/");
cb.setContents(ss, ss);
}
}
});
p.add(b);
b = new JButton("Close");
getRootPane().setDefaultButton(b);
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
UpdateDialog.this.dispose();
}
});
p.add(b);
getContentPane().add(p, BorderLayout.SOUTH);
pack();
Point loc = owner.getLocationOnScreen();
loc.x += (owner.getWidth() - getWidth()) / 2;
loc.y += (owner.getHeight() - getHeight()) / 2;
setLocation(loc);
setVisible(true);
}
}
}
--- NEW FILE: SBControl.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.controlpanel;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JPanel;
import de.muntjak.tinylookandfeel.Theme;
import de.muntjak.tinylookandfeel.util.SBReference;
/**
* SBControl is a controller component used to specify
* a color by a reference color, a brightness value and
* a saturation value.
* @author Hans Bickel
*
*/
public class SBControl extends JPanel implements Selectable {
protected static final ControlPanel cp = ControlPanel.instance;
protected final int cpSize = 10;
protected boolean forceUpdate = false;
protected Dimension size = new Dimension(64, 20);
protected SBReference sbReference;
protected int controlMode = ControlPanel.CONTROLS_ALL;
private boolean selected = false;
SBControl(SBReference ref, int controlMode) {
this(ref, false, controlMode);
}
SBControl(SBReference ref, boolean forceUpdate, int controlMode) {
this.sbReference = ref;
this.forceUpdate = forceUpdate;
this.controlMode = controlMode;
if(ref == null) return;
update();
addMouseListener(new Mousey());
}
/**
* Constructor for the following fields:
* mainColor, backColor, disColor, frameColor
* @param ref
* @param height
*/
SBControl(SBReference ref) {
this.sbReference = ref;
forceUpdate = true;
size.height = 24;
if(ref == null) return;
update();
addMouseListener(new Mousey());
}
public SBReference getSBReference() {
return sbReference;
}
public Color getColor() {
return sbReference.getColor();
}
public boolean isLocked() {
return (sbReference != null && sbReference.isLocked());
}
public void setBackground(Color bg) {
if(sbReference == null) {
super.setBackground(bg);
}
else {
super.setBackground(sbReference.getColor());
}
}
public void update() {
if(sbReference != null) {
setBackground(sbReference.update());
}
repaint();
updateTTT();
}
public void updateTTT() {
if(sbReference == null) {
setToolTipText(null);
return;
}
Color c = sbReference.getColor();
StringBuffer buff = new StringBuffer("<html>");
if(sbReference.isAbsoluteColor()) {
buff.append("R:" + c.getRed());
buff.append(" G:" + c.getGreen());
buff.append(" B:" + c.getBlue());
}
else {
buff.append("S:" + sbReference.getSaturation());
buff.append(" B:" + sbReference.getBrightness());
buff.append(" (" + sbReference.getReferenceString() + ")");
buff.append(" R:" + c.getRed());
buff.append(" G:" + c.getGreen());
buff.append(" B:" + c.getBlue());
}
if(sbReference.equals(Theme.mainColor)) {
buff.append("<br>References: " +
SBReference.getNumReferences(SBReference.MAIN_COLOR));
}
else if(sbReference.equals(Theme.backColor)) {
buff.append("<br>References: " +
SBReference.getNumReferences(SBReference.BACK_COLOR));
}
else if(sbReference.equals(Theme.disColor)) {
buff.append("<br>References: " +
SBReference.getNumReferences(SBReference.DIS_COLOR));
}
else if(sbReference.equals(Theme.frameColor)) {
buff.append("<br>References: " +
SBReference.getNumReferences(SBReference.FRAME_COLOR));
}
else if(sbReference.equals(Theme.sub1Color)) {
buff.append("<br>References: " +
SBReference.getNumReferences(SBReference.SUB1_COLOR));
}
else if(sbReference.equals(Theme.sub2Color)) {
buff.append("<br>References: " +
SBReference.getNumReferences(SBReference.SUB2_COLOR));
}
else if(sbReference.equals(Theme.sub3Color)) {
buff.append("<br>References: " +
SBReference.getNumReferences(SBReference.SUB3_COLOR));
}
else if(sbReference.equals(Theme.sub4Color)) {
buff.append("<br>References: " +
SBReference.getNumReferences(SBReference.SUB4_COLOR));
}
else if(sbReference.equals(Theme.sub5Color)) {
buff.append("<br>References: " +
SBReference.getNumReferences(SBReference.SUB5_COLOR));
}
else if(sbReference.equals(Theme.sub6Color)) {
buff.append("<br>References: " +
SBReference.getNumReferences(SBReference.SUB6_COLOR));
}
else if(sbReference.equals(Theme.sub7Color)) {
buff.append("<br>References: " +
SBReference.getNumReferences(SBReference.SUB7_COLOR));
}
else if(sbReference.equals(Theme.sub8Color)) {
buff.append("<br>References: " +
SBReference.getNumReferences(SBReference.SUB8_COLOR));
}
setToolTipText(buff.toString());
}
public void setSBReference(SBReference ref) {
this.sbReference = ref;
update();
}
public Dimension getPreferredSize() {
return size;
}
public void paint(Graphics g) {
// With colored fonts, sbReference can be null
if(sbReference == null) {
g.setColor(Theme.backColor.getColor());
g.fillRect(0, 0, getWidth(), getHeight());
return;
}
// fill with background
g.setColor(getBackground());
g.fillRect(2, 2, getWidth() - 3, getHeight() - 3);
// paint border
if(selected) {
g.setColor(Color.DARK_GRAY);
g.drawRect(1, 1, getWidth() - 3, getHeight() - 3);
g.setColor(Color.RED);
g.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
}
else {
g.setColor(Color.DARK_GRAY);
g.drawRect(1, 1, getWidth() - 3, getHeight() - 3);
g.setColor(Theme.backColor.getColor());
g.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
}
if(sbReference == null || sbReference.isLocked()) return;
// paint left rectangle
g.setColor(Color.LIGHT_GRAY);
g.fillRect(2, 2, cpSize, getHeight() - 4);
g.setColor(Color.BLACK);
g.fillRect(cpSize + 2, 2, 1, getHeight() - 4);
// paint gradient boxes
if(sbReference.isAbsoluteColor()) {
int x = getWidth() - 20;
float hue = 0.0f;
g.drawLine(x - 1, 2, x - 1, getHeight() - 3);
for(int i = 0; i < 18; i++) {
g.setColor(Color.getHSBColor(hue, 0.5f, 1.0f));
g.drawLine(x + i, 2, x + i, getHeight() - 3);
hue += 1.0 / 19.0;
}
}
else {
int x = getWidth() - 20;
int grey = 255;
g.drawLine(x - 1, 2, x - 1, getHeight() - 3);
for(int i = 0; i < 18; i++) {
g.setColor(new Color(grey, grey, grey));
g.drawLine(x + i, 2, x + i, getHeight() - 3);
grey -= 255 / 18;
}
}
}
class Mousey extends MouseAdapter {
public void mouseReleased(MouseEvent e) {
if(e.isPopupTrigger() && !sbReference.isLocked()) {
if(e.getX() <= cpSize) {
cp.showCPSBPopup(SBControl.this);
}
else {
cp.showSBPopup(SBControl.this);
}
}
}
public void mousePressed(MouseEvent e) {
if(sbReference == null) return;
requestFocusInWindow();
if(e.isControlDown()) {
if(!selected) {
cp.selection.add(SBControl.this);
}
return;
}
else if(e.isAltDown()) {
if(selected) {
cp.selection.remove(SBControl.this);
}
return;
}
if(e.getX() <= cpSize) {
cp.showCPSBPopup(SBControl.this);
return;
}
if(e.isPopupTrigger() && !sbReference.isLocked()) {
cp.showSBPopup(SBControl.this);
return;
}
if(e.getX() > getWidth() - 19 && !sbReference.isLocked()) {
cp.showSBPopup(SBControl.this);
return;
}
if(e.getButton() != MouseEvent.BUTTON1) return;
Color newColor = null;
if(sbReference.isAbsoluteColor()) {
newColor =
PSColorChooser.showColorChooser(cp.theFrame, getColor());
if(newColor == null) return; // cancelled
if(newColor.equals(sbReference.getColor())) return; // unchanged
cp.storeUndoData(SBControl.this);
sbReference.setColor(newColor);
}
else {
newColor = SBChooser.showSBChooser(cp.theFrame, SBControl.this);
if(newColor == null) return; // cancelled
if(sbReference.getBrightness() == SBChooser.getBrightness() &&
sbReference.getSaturation() == SBChooser.getSaturation()) return; // unchanged
cp.storeUndoData(SBControl.this);
sbReference.setColor(SBChooser.getSaturation(), SBChooser.getBrightness());
}
update();
cp.initPanels(); // update all derived colors...
updateTargets(true);
}
}
void updateTargets(boolean activateApplyButton) {
if(forceUpdate) {
if(activateApplyButton) {
cp.examplePanel.update(true);
}
else {
cp.initPanels(); // update all derived colors...
cp.setTheme();
}
}
else {
cp.repaintTargets(controlMode);
}
}
public String toString() {
return "SBField[ref=" + sbReference + "]";
}
public boolean isSelected() {
return selected;
}
public void setSelected(boolean selected) {
if(this.selected == selected) return;
this.selected = selected;
repaint();
}
}
--- NEW FILE: IntControl.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.controlpanel;
import java.util.Iterator;
import java.util.Vector;
import javax.swing.JSpinner;
import javax.swing.SpinnerModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import de.muntjak.tinylookandfeel.util.IntReference;
/**
* IntControl controls one single int value.
*
* @author Hans Bickel
* @since 1.4.0
*
*/
public class IntControl extends JSpinner implements ChangeListener {
private static final Vector armedControls = new Vector();
private IntReference ref;
private boolean forceUpdate;
private String description;
private int oldValue;
private boolean changeState = true;
/**
*
* @param model
* @param ref
* @param forceUpdate if true, applySettingsButton will be enabled each
* time the value changes
*/
IntControl(SpinnerModel model, IntReference ref, boolean forceUpdate,
String description)
{
super(model);
this.ref = ref;
this.forceUpdate = forceUpdate;
this.description = description;
oldValue = ((Integer)model.getValue()).intValue();
addChangeListener(this);
}
public IntReference getIntReference() {
return ref;
}
public String getDescription() {
return description;
}
/**
* Sets the argument as the current value and immediately
* updates the IntReference.
* @param value
*/
public void commitValue(int value) {
changeState = false;
oldValue = value;
super.setValue(new Integer(value));
ref.setValue(value);
changeState = true;
}
/**
* Should be called after 'Apply Settings' button was clicked.
*
*/
static void confirmChanges() {
if(armedControls.isEmpty()) return;
Iterator ii = armedControls.iterator();
while(ii.hasNext()) {
((IntControl)ii.next()).confirmChange();
}
armedControls.clear();
}
private void confirmChange() {
UndoManager.storeUndoData(this, oldValue);
oldValue = ((Integer)getValue()).intValue();
ref.setValue(oldValue);
}
public boolean equals(Object o) {
if(o == null || !(o instanceof IntControl)) return false;
if(description == null) {
return (((IntControl)o).description == null);
}
return description.equals(((IntControl)o).description);
}
// ChangeListener impl
public void stateChanged(ChangeEvent e) {
if(!changeState) return;
if(!armedControls.contains(this)) {
armedControls.add(this);
}
if(!ControlPanel.instance.applySettingsButton.isEnabled()) {
ControlPanel.instance.applySettingsButton.setEnabled(true);
}
}
}
--- NEW FILE: ParameterSetGenerator.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.controlpanel;
/**
* ParameterSetGenerator
* @author Hans Bickel
*
*/
public interface ParameterSetGenerator {
public void init(boolean always);
public ParameterSet getParameterSet();
}
--- NEW FILE: PSColorChooser.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.controlpanel;
import java.net.URL;
import java.util.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;
import de.muntjak.tinylookandfeel.*;
import de.muntjak.tinylookandfeel.util.ColorRoutines;
/**
* PSColorChooser
*
* @version 1.0
* @author Hans Bickel
*/
public class PSColorChooser extends JDialog {
private Color inColor, outColor;
private static PSColorChooser instance;
private ColorSelector colorSelector;
private HueSelector hueSelector;
private TwoColorField twoColorField;
private NumericTextField redField, greenField, blueField;
private NumericTextField satField, briField, hueField;
private JButton ok;
private boolean spinnerUpdate = false;
private static Cursor cs_cursor;
private static BufferedImage brightmask;
private static GraphicsConfiguration conf;
static {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
conf = ge.getDefaultScreenDevice().getDefaultConfiguration();
brightmask = loadBrightmask();
cs_cursor = loadCursor();
}
private static Cursor loadCursor() {
ImageIcon img = null;
Cursor c = null;
Dimension size = Toolkit.getDefaultToolkit().getBestCursorSize(16, 16);
if(size.width == 32) {
img = loadImageIcon("/de/muntjak/tinylookandfeel/cp_icons/cs32.gif");
c = Toolkit.getDefaultToolkit().createCustomCursor(
img.getImage(), new Point(15, 15), "cs_cursor");
}
else if(size.width == 16) {
img = loadImageIcon("/de/muntjak/tinylookandfeel/cp_icons/cs16.gif");
c = Toolkit.getDefaultToolkit().createCustomCursor(
img.getImage(), new Point(7, 7), "cs_cursor");
}
return c;
}
private static BufferedImage loadBrightmask() {
ImageIcon img = loadImageIcon("/de/muntjak/tinylookandfeel/cp_icons/brightmask.png");
BufferedImage bimg = conf.createCompatibleImage(256, 256, Transparency.TRANSLUCENT);
Graphics g = bimg.getGraphics();
g.drawImage(img.getImage(), 0, 0, 256, 256, 0, 0, 1, 256, null);
return bimg;
}
protected static ImageIcon loadImageIcon(String fn) {
return new ImageIcon(PSColorChooser.class.getResource(fn));
}
private PSColorChooser(Frame frame, Color inColor) {
super(frame, "Color Chooser", true);
setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
this.inColor = inColor;
outColor = inColor;
setupUI(frame, inColor);
}
public static Color showColorChooser(Frame frame, Color inColor) {
if(instance == null) {
instance = new PSColorChooser(frame, inColor);
}
instance.setColor(inColor);
instance.setVisible(true);
return instance.outColor;
}
public static void deleteInstance() {
instance = null;
}
public void setColor(Color c) {
spinnerUpdate = true;
inColor = c;
outColor = inColor;
int hue = ColorRoutines.getHue(c);
int sat = ColorRoutines.getSaturation(c);
int bri = ColorRoutines.getBrightness(c);
satField.setValue(sat);
briField.setValue(bri);
hueField.setValue(hue);
redField.setValue(c.getRed());
greenField.setValue(c.getGreen());
blueField.setValue(c.getBlue());
colorSelector.setColor(c);
hueSelector.setHue(hue);
twoColorField.setUpperColor(c);
twoColorField.setLowerColor(c);
spinnerUpdate = false;
}
private void colorChanged(Color c) {
spinnerUpdate = true;
int hue = ColorRoutines.getHue(c);
int sat = ColorRoutines.getSaturation(c);
int bri = ColorRoutines.getBrightness(c);
satField.setValue(sat);
briField.setValue(bri);
hueField.setValue(hue);
redField.setValue(c.getRed());
greenField.setValue(c.getGreen());
blueField.setValue(c.getBlue());
twoColorField.setUpperColor(c);
spinnerUpdate = false;
}
private void hueChanged(int hue) {
spinnerUpdate = true;
int sat = satField.getValue();
int bri = briField.getValue();
hueField.setValue(hue);
Color c = Color.getHSBColor(
(float)(hue / 360.0f), (float)(sat / 100.0f), (float)(bri / 100.0f));
redField.setValue(c.getRed());
greenField.setValue(c.getGreen());
blueField.setValue(c.getBlue());
twoColorField.setUpperColor(c);
colorSelec...
[truncated message content] |