|
|
@ -1,28 +1,44 @@ |
|
|
|
package com.fr.design.gui.itree.checkboxtree; |
|
|
|
package com.fr.design.gui.itree.checkboxtree; |
|
|
|
|
|
|
|
|
|
|
|
import java.awt.event.ActionEvent; |
|
|
|
import com.fr.design.constants.UIConstants; |
|
|
|
import java.awt.event.ActionListener; |
|
|
|
import com.fr.design.gui.icheckbox.UICheckBox; |
|
|
|
import java.awt.event.ItemListener; |
|
|
|
import com.fr.design.utils.gui.GUIPaintUtils; |
|
|
|
import java.awt.event.MouseAdapter; |
|
|
|
import com.fr.stable.Constants; |
|
|
|
import java.awt.event.MouseEvent; |
|
|
|
import sun.swing.SwingUtilities2; |
|
|
|
import java.awt.event.MouseListener; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.swing.AbstractAction; |
|
|
|
import javax.swing.AbstractAction; |
|
|
|
|
|
|
|
import javax.swing.AbstractButton; |
|
|
|
import javax.swing.ActionMap; |
|
|
|
import javax.swing.ActionMap; |
|
|
|
import javax.swing.ButtonGroup; |
|
|
|
import javax.swing.ButtonGroup; |
|
|
|
import javax.swing.ButtonModel; |
|
|
|
import javax.swing.ButtonModel; |
|
|
|
import javax.swing.Icon; |
|
|
|
import javax.swing.Icon; |
|
|
|
|
|
|
|
import javax.swing.JComponent; |
|
|
|
import javax.swing.SwingUtilities; |
|
|
|
import javax.swing.SwingUtilities; |
|
|
|
import javax.swing.event.ChangeListener; |
|
|
|
import javax.swing.event.ChangeListener; |
|
|
|
import javax.swing.plaf.ActionMapUIResource; |
|
|
|
import javax.swing.plaf.ActionMapUIResource; |
|
|
|
|
|
|
|
import javax.swing.plaf.basic.BasicHTML; |
|
|
|
import com.fr.design.gui.icheckbox.UICheckBox; |
|
|
|
import javax.swing.plaf.metal.MetalCheckBoxUI; |
|
|
|
|
|
|
|
import javax.swing.text.View; |
|
|
|
|
|
|
|
import java.awt.Dimension; |
|
|
|
|
|
|
|
import java.awt.Font; |
|
|
|
|
|
|
|
import java.awt.FontMetrics; |
|
|
|
|
|
|
|
import java.awt.Graphics; |
|
|
|
|
|
|
|
import java.awt.Graphics2D; |
|
|
|
|
|
|
|
import java.awt.Insets; |
|
|
|
|
|
|
|
import java.awt.Rectangle; |
|
|
|
|
|
|
|
import java.awt.RenderingHints; |
|
|
|
|
|
|
|
import java.awt.event.ActionEvent; |
|
|
|
|
|
|
|
import java.awt.event.ActionListener; |
|
|
|
|
|
|
|
import java.awt.event.ItemListener; |
|
|
|
|
|
|
|
import java.awt.event.MouseAdapter; |
|
|
|
|
|
|
|
import java.awt.event.MouseEvent; |
|
|
|
|
|
|
|
import java.awt.event.MouseListener; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Maintenance tip - There were some tricks to getting this code |
|
|
|
* Maintenance tip - There were some tricks to getting this code |
|
|
|
* working: |
|
|
|
* working: |
|
|
|
* <p/> |
|
|
|
* <p/> |
|
|
|
* 1. You have to overwite addMouseListener() to do nothing |
|
|
|
* 1. You have to overwrite addMouseListener() to do nothing |
|
|
|
* 2. You have to add a mouse event on mousePressed by calling |
|
|
|
* 2. You have to add a mouse event on mousePressed by calling |
|
|
|
* super.addMouseListener() |
|
|
|
* super.addMouseListener() |
|
|
|
* 3. You have to replace the UIActionMap for the keyboard event |
|
|
|
* 3. You have to replace the UIActionMap for the keyboard event |
|
|
@ -41,21 +57,30 @@ public class TristateCheckBox extends UICheckBox { |
|
|
|
* This is a type-safe enumerated type |
|
|
|
* This is a type-safe enumerated type |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static class State { |
|
|
|
public static class State { |
|
|
|
private State() { |
|
|
|
private String type; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private State(String type) { |
|
|
|
|
|
|
|
this.type = type; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public String toString() { |
|
|
|
|
|
|
|
return this.type; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static final State NOT_SELECTED = new State(); |
|
|
|
public static final State NOT_SELECTED = new State("NOT_SELECTED"); |
|
|
|
public static final State SELECTED = new State(); |
|
|
|
public static final State SELECTED = new State("SELECTED"); |
|
|
|
public static final State DONT_CARE = new State(); |
|
|
|
public static final State DO_NOT_CARE = new State("DO_NOT_CARE"); |
|
|
|
|
|
|
|
|
|
|
|
private final TristateDecorator model; |
|
|
|
private final TristateDecorator model; |
|
|
|
|
|
|
|
|
|
|
|
public TristateCheckBox(String text, Icon icon, State initial) { |
|
|
|
public TristateCheckBox(String text, Icon icon, State initial) { |
|
|
|
super(text, icon); |
|
|
|
super(text, icon); |
|
|
|
|
|
|
|
setUI(new TristateCheckBoxUI()); |
|
|
|
// Add a listener for when the mouse is pressed
|
|
|
|
// Add a listener for when the mouse is pressed
|
|
|
|
super.addMouseListener(new MouseAdapter() { |
|
|
|
super.addMouseListener(new MouseAdapter() { |
|
|
|
// @Override
|
|
|
|
@Override |
|
|
|
public void mousePressed(MouseEvent e) { |
|
|
|
public void mousePressed(MouseEvent e) { |
|
|
|
grabFocus(); |
|
|
|
grabFocus(); |
|
|
|
model.setState(getNextState(model.getState())); |
|
|
|
model.setState(getNextState(model.getState())); |
|
|
@ -64,6 +89,7 @@ public class TristateCheckBox extends UICheckBox { |
|
|
|
// Reset the keyboard action map
|
|
|
|
// Reset the keyboard action map
|
|
|
|
ActionMap map = new ActionMapUIResource(); |
|
|
|
ActionMap map = new ActionMapUIResource(); |
|
|
|
map.put("pressed", new AbstractAction() { |
|
|
|
map.put("pressed", new AbstractAction() { |
|
|
|
|
|
|
|
@Override |
|
|
|
public void actionPerformed(ActionEvent e) { |
|
|
|
public void actionPerformed(ActionEvent e) { |
|
|
|
grabFocus(); |
|
|
|
grabFocus(); |
|
|
|
model.setState(getNextState(model.getState())); |
|
|
|
model.setState(getNextState(model.getState())); |
|
|
@ -79,26 +105,29 @@ public class TristateCheckBox extends UICheckBox { |
|
|
|
|
|
|
|
|
|
|
|
public TristateCheckBox(String text, State initial) { |
|
|
|
public TristateCheckBox(String text, State initial) { |
|
|
|
this(text, null, initial); |
|
|
|
this(text, null, initial); |
|
|
|
|
|
|
|
setUI(new TristateCheckBoxUI()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public TristateCheckBox(String text) { |
|
|
|
public TristateCheckBox(String text) { |
|
|
|
this(text, DONT_CARE); |
|
|
|
this(text, DO_NOT_CARE); |
|
|
|
|
|
|
|
setUI(new TristateCheckBoxUI()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public TristateCheckBox() { |
|
|
|
public TristateCheckBox() { |
|
|
|
this(null); |
|
|
|
this(null); |
|
|
|
|
|
|
|
setUI(new TristateCheckBoxUI()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* No one may add mouse listeners, not even Swing! |
|
|
|
* No one may add mouse listeners, not even Swing! |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
// @Override
|
|
|
|
@Override |
|
|
|
public void addMouseListener(MouseListener l) { |
|
|
|
public void addMouseListener(MouseListener l) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Set the new state to either SELECTED, NOT_SELECTED or |
|
|
|
* Set the new state to either SELECTED, NOT_SELECTED or |
|
|
|
* DONT_CARE. If state == null, it is treated as DONT_CARE. |
|
|
|
* DO_NOT_CARE. If state == null, it is treated as DO_NOT_CARE. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void setState(State state) { |
|
|
|
public void setState(State state) { |
|
|
|
model.setState(state); |
|
|
|
model.setState(state); |
|
|
@ -112,15 +141,6 @@ public class TristateCheckBox extends UICheckBox { |
|
|
|
return model.getState(); |
|
|
|
return model.getState(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// @Override
|
|
|
|
|
|
|
|
public void setSelected(boolean b) { |
|
|
|
|
|
|
|
if (b) { |
|
|
|
|
|
|
|
setState(SELECTED); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
setState(NOT_SELECTED); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Exactly which Design Pattern is this? Is it an Adapter, |
|
|
|
* Exactly which Design Pattern is this? Is it an Adapter, |
|
|
@ -140,13 +160,13 @@ public class TristateCheckBox extends UICheckBox { |
|
|
|
other.setArmed(false); |
|
|
|
other.setArmed(false); |
|
|
|
setPressed(false); |
|
|
|
setPressed(false); |
|
|
|
setSelected(false); |
|
|
|
setSelected(false); |
|
|
|
} |
|
|
|
} else if (state == SELECTED) { |
|
|
|
else if (state == SELECTED) { |
|
|
|
|
|
|
|
other.setArmed(false); |
|
|
|
other.setArmed(false); |
|
|
|
setPressed(false); |
|
|
|
setPressed(false); |
|
|
|
setSelected(true); |
|
|
|
setSelected(true); |
|
|
|
} |
|
|
|
} |
|
|
|
else { // either "null" or DONT_CARE
|
|
|
|
// either "null" or DO_NOT_CARE
|
|
|
|
|
|
|
|
else { |
|
|
|
other.setArmed(true); |
|
|
|
other.setArmed(true); |
|
|
|
setPressed(true); |
|
|
|
setPressed(true); |
|
|
|
setSelected(true); |
|
|
|
setSelected(true); |
|
|
@ -158,7 +178,7 @@ public class TristateCheckBox extends UICheckBox { |
|
|
|
* state of the model. |
|
|
|
* state of the model. |
|
|
|
* <p/> |
|
|
|
* <p/> |
|
|
|
* We return the SELECTED state when the checkbox is selected |
|
|
|
* We return the SELECTED state when the checkbox is selected |
|
|
|
* but not armed, DONT_CARE state when the checkbox is |
|
|
|
* but not armed, DO_NOT_CARE state when the checkbox is |
|
|
|
* selected and armed (grey) and NOT_SELECTED when the |
|
|
|
* selected and armed (grey) and NOT_SELECTED when the |
|
|
|
* checkbox is deselected. |
|
|
|
* checkbox is deselected. |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -166,12 +186,10 @@ public class TristateCheckBox extends UICheckBox { |
|
|
|
if (isSelected() && !isArmed()) { |
|
|
|
if (isSelected() && !isArmed()) { |
|
|
|
// normal black tick
|
|
|
|
// normal black tick
|
|
|
|
return SELECTED; |
|
|
|
return SELECTED; |
|
|
|
} |
|
|
|
} else if (isSelected() && isArmed()) { |
|
|
|
else if (isSelected() && isArmed()) { |
|
|
|
|
|
|
|
// don't care grey tick
|
|
|
|
// don't care grey tick
|
|
|
|
return DONT_CARE; |
|
|
|
return DO_NOT_CARE; |
|
|
|
} |
|
|
|
} else { |
|
|
|
else { |
|
|
|
|
|
|
|
// normal deselected
|
|
|
|
// normal deselected
|
|
|
|
return NOT_SELECTED; |
|
|
|
return NOT_SELECTED; |
|
|
|
} |
|
|
|
} |
|
|
@ -180,6 +198,7 @@ public class TristateCheckBox extends UICheckBox { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Filter: No one may change the armed status except us. |
|
|
|
* Filter: No one may change the armed status except us. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
@Override |
|
|
|
public void setArmed(boolean b) { |
|
|
|
public void setArmed(boolean b) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -187,6 +206,7 @@ public class TristateCheckBox extends UICheckBox { |
|
|
|
* We disable focusing on the component when it is not |
|
|
|
* We disable focusing on the component when it is not |
|
|
|
* enabled. |
|
|
|
* enabled. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
@Override |
|
|
|
public void setEnabled(boolean b) { |
|
|
|
public void setEnabled(boolean b) { |
|
|
|
setFocusable(b); |
|
|
|
setFocusable(b); |
|
|
|
other.setEnabled(b); |
|
|
|
other.setEnabled(b); |
|
|
@ -196,89 +216,109 @@ public class TristateCheckBox extends UICheckBox { |
|
|
|
* All these methods simply delegate to the "other" model |
|
|
|
* All these methods simply delegate to the "other" model |
|
|
|
* that is being decorated. |
|
|
|
* that is being decorated. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
@Override |
|
|
|
public boolean isArmed() { |
|
|
|
public boolean isArmed() { |
|
|
|
return other.isArmed(); |
|
|
|
return other.isArmed(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public boolean isSelected() { |
|
|
|
public boolean isSelected() { |
|
|
|
return other.isSelected(); |
|
|
|
return other.isSelected(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public boolean isEnabled() { |
|
|
|
public boolean isEnabled() { |
|
|
|
return other.isEnabled(); |
|
|
|
return other.isEnabled(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public boolean isPressed() { |
|
|
|
public boolean isPressed() { |
|
|
|
return other.isPressed(); |
|
|
|
return other.isPressed(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public boolean isRollover() { |
|
|
|
public boolean isRollover() { |
|
|
|
return other.isRollover(); |
|
|
|
return other.isRollover(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public void setSelected(boolean b) { |
|
|
|
public void setSelected(boolean b) { |
|
|
|
other.setSelected(b); |
|
|
|
other.setSelected(b); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public void setPressed(boolean b) { |
|
|
|
public void setPressed(boolean b) { |
|
|
|
other.setPressed(b); |
|
|
|
other.setPressed(b); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public void setRollover(boolean b) { |
|
|
|
public void setRollover(boolean b) { |
|
|
|
other.setRollover(b); |
|
|
|
other.setRollover(b); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public void setMnemonic(int key) { |
|
|
|
public void setMnemonic(int key) { |
|
|
|
other.setMnemonic(key); |
|
|
|
other.setMnemonic(key); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public int getMnemonic() { |
|
|
|
public int getMnemonic() { |
|
|
|
return other.getMnemonic(); |
|
|
|
return other.getMnemonic(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public void setActionCommand(String s) { |
|
|
|
public void setActionCommand(String s) { |
|
|
|
other.setActionCommand(s); |
|
|
|
other.setActionCommand(s); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public String getActionCommand() { |
|
|
|
public String getActionCommand() { |
|
|
|
return other.getActionCommand(); |
|
|
|
return other.getActionCommand(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public void setGroup(ButtonGroup group) { |
|
|
|
public void setGroup(ButtonGroup group) { |
|
|
|
other.setGroup(group); |
|
|
|
other.setGroup(group); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public void addActionListener(ActionListener l) { |
|
|
|
public void addActionListener(ActionListener l) { |
|
|
|
other.addActionListener(l); |
|
|
|
other.addActionListener(l); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public void removeActionListener(ActionListener l) { |
|
|
|
public void removeActionListener(ActionListener l) { |
|
|
|
other.removeActionListener(l); |
|
|
|
other.removeActionListener(l); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public void addItemListener(ItemListener l) { |
|
|
|
public void addItemListener(ItemListener l) { |
|
|
|
other.addItemListener(l); |
|
|
|
other.addItemListener(l); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public void removeItemListener(ItemListener l) { |
|
|
|
public void removeItemListener(ItemListener l) { |
|
|
|
other.removeItemListener(l); |
|
|
|
other.removeItemListener(l); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public void addChangeListener(ChangeListener l) { |
|
|
|
public void addChangeListener(ChangeListener l) { |
|
|
|
other.addChangeListener(l); |
|
|
|
other.addChangeListener(l); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public void removeChangeListener(ChangeListener l) { |
|
|
|
public void removeChangeListener(ChangeListener l) { |
|
|
|
other.removeChangeListener(l); |
|
|
|
other.removeChangeListener(l); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public Object[] getSelectedObjects() { |
|
|
|
public Object[] getSelectedObjects() { |
|
|
|
return other.getSelectedObjects(); |
|
|
|
return other.getSelectedObjects(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* We rotate between NOT_SELECTED, SELECTED and DONT_CARE. Subclass can |
|
|
|
* We rotate between NOT_SELECTED, SELECTED and DO_NOT_CARE. Subclass can |
|
|
|
* override this method to tell the check box what next state is. Here is |
|
|
|
* override this method to tell the check box what next state is. Here is |
|
|
|
* the default implementation. |
|
|
|
* the default implementation. |
|
|
|
* <code><pre> |
|
|
|
* <code><pre> |
|
|
@ -286,7 +326,7 @@ public class TristateCheckBox extends UICheckBox { |
|
|
|
* return SELECTED; |
|
|
|
* return SELECTED; |
|
|
|
* } |
|
|
|
* } |
|
|
|
* else if (current == SELECTED) { |
|
|
|
* else if (current == SELECTED) { |
|
|
|
* return DONT_CARE; |
|
|
|
* return DO_NOT_CARE; |
|
|
|
* } |
|
|
|
* } |
|
|
|
* else { |
|
|
|
* else { |
|
|
|
* return NOT_SELECTED; |
|
|
|
* return NOT_SELECTED; |
|
|
@ -296,12 +336,91 @@ public class TristateCheckBox extends UICheckBox { |
|
|
|
protected State getNextState(State current) { |
|
|
|
protected State getNextState(State current) { |
|
|
|
if (current == NOT_SELECTED) { |
|
|
|
if (current == NOT_SELECTED) { |
|
|
|
return SELECTED; |
|
|
|
return SELECTED; |
|
|
|
|
|
|
|
} else if (current == SELECTED) { |
|
|
|
|
|
|
|
return DO_NOT_CARE; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return NOT_SELECTED; |
|
|
|
} |
|
|
|
} |
|
|
|
else if (current == SELECTED) { |
|
|
|
|
|
|
|
return DONT_CARE; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
else /*if (current == DONT_CARE)*/ { |
|
|
|
|
|
|
|
return NOT_SELECTED; |
|
|
|
private class TristateCheckBoxUI extends MetalCheckBoxUI { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void paint(Graphics g, JComponent c) { |
|
|
|
|
|
|
|
synchronized (this) { |
|
|
|
|
|
|
|
AbstractButton b = (AbstractButton) c; |
|
|
|
|
|
|
|
ButtonModel model = b.getModel(); |
|
|
|
|
|
|
|
Dimension size = c.getSize(); |
|
|
|
|
|
|
|
Font f = c.getFont(); |
|
|
|
|
|
|
|
g.setFont(f); |
|
|
|
|
|
|
|
FontMetrics fm = SwingUtilities2.getFontMetrics(c, g, f); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Rectangle viewRect = new Rectangle(size); |
|
|
|
|
|
|
|
Rectangle iconRect = new Rectangle(); |
|
|
|
|
|
|
|
Rectangle textRect = new Rectangle(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Insets i = c.getInsets(); |
|
|
|
|
|
|
|
viewRect.x += i.left; |
|
|
|
|
|
|
|
viewRect.y += i.top; |
|
|
|
|
|
|
|
viewRect.width -= (i.right + viewRect.x); |
|
|
|
|
|
|
|
viewRect.height -= (i.bottom + viewRect.y); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Icon altIcon = b.getIcon(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String text = SwingUtilities.layoutCompoundLabel( |
|
|
|
|
|
|
|
c, fm, b.getText(), altIcon != null ? altIcon : getDefaultIcon(), |
|
|
|
|
|
|
|
b.getVerticalAlignment(), b.getHorizontalAlignment(), |
|
|
|
|
|
|
|
b.getVerticalTextPosition(), b.getHorizontalTextPosition(), |
|
|
|
|
|
|
|
viewRect, iconRect, textRect, b.getIconTextGap()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// fill background
|
|
|
|
|
|
|
|
if (c.isOpaque()) { |
|
|
|
|
|
|
|
g.setColor(b.getBackground()); |
|
|
|
|
|
|
|
g.fillRect(0, 0, size.width, size.height); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Graphics2D g2d = (Graphics2D) g; |
|
|
|
|
|
|
|
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); |
|
|
|
|
|
|
|
if (SELECTED.equals(getState())) { |
|
|
|
|
|
|
|
GUIPaintUtils.fillPaint(g2d, iconRect.x, iconRect.y, iconRect.width, iconRect.height, false, Constants.NULL, |
|
|
|
|
|
|
|
model.isEnabled() ? UIConstants.CHECKBOX_HOVER_SELECTED : UIConstants.DISABLED_ICON_COLOR, 0); |
|
|
|
|
|
|
|
} else if (model.isRollover() && !SELECTED.equals(getState())) { |
|
|
|
|
|
|
|
g.setColor(UIConstants.CHECKBOX_HOVER_SELECTED); |
|
|
|
|
|
|
|
g2d.drawRoundRect(iconRect.x, iconRect.y, iconRect.width - 1, iconRect.height - 1, UIConstants.ARC, UIConstants.ARC); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
g.setColor(UIConstants.LINE_COLOR); |
|
|
|
|
|
|
|
g2d.drawRoundRect(iconRect.x, iconRect.y, iconRect.width - 1, iconRect.height - 1, UIConstants.ARC, UIConstants.ARC); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (SELECTED.equals(getState())) { |
|
|
|
|
|
|
|
UIConstants.YES_ICON.paintIcon(c, g, iconRect.x + 2, iconRect.y + 2); |
|
|
|
|
|
|
|
} else if (DO_NOT_CARE.equals(getState())) { |
|
|
|
|
|
|
|
g.setColor(UIConstants.CHECKBOX_HOVER_SELECTED); |
|
|
|
|
|
|
|
g2d.fillRoundRect(iconRect.x + 2, iconRect.y + 2, iconRect.width - 4, iconRect.height - 4, UIConstants.ARC, UIConstants.ARC); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Draw the Text
|
|
|
|
|
|
|
|
drawLine(text, g, b, c, textRect, fm); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void drawLine(String text, Graphics g, AbstractButton b, JComponent c, Rectangle textRect, FontMetrics fm) { |
|
|
|
|
|
|
|
if (text != null) { |
|
|
|
|
|
|
|
View v = (View) c.getClientProperty(BasicHTML.propertyKey); |
|
|
|
|
|
|
|
if (v != null) { |
|
|
|
|
|
|
|
v.paint(g, textRect); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
int mnemIndex = b.getDisplayedMnemonicIndex(); |
|
|
|
|
|
|
|
if (model.isEnabled()) { |
|
|
|
|
|
|
|
g.setColor(b.getForeground()); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
g.setColor(getDisabledTextColor()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
SwingUtilities2.drawStringUnderlineCharAt(c, g, text, |
|
|
|
|
|
|
|
mnemIndex, textRect.x, textRect.y + fm.getAscent()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |