Browse Source

无JIRA任务,给CustomChooserPanel.java 调整缩进

master
plough 8 years ago
parent
commit
87b8d6266c
  1. 281
      designer_base/src/com/fr/design/style/color/CustomChooserPanel.java

281
designer_base/src/com/fr/design/style/color/CustomChooserPanel.java

@ -42,72 +42,111 @@ import com.fr.general.Inter;
/**
* 颜色选择器自定义面板
* @author focus
*
* @author focus
*/
class CustomChooserPanel extends AbstractColorChooserPanel {
/**
* The gradient image displayed.
*/
class CustomChooserPanel extends AbstractColorChooserPanel
{
/** The gradient image displayed. */
private transient Image gradientImage;
/** The Panel that holds the gradient image. */
/**
* The Panel that holds the gradient image.
*/
private transient JPanel gradientPanel;
/** The track gradient image. */
/**
* The track gradient image.
*/
private transient Image trackImage;
/** The panel that holds the track. */
/**
* The panel that holds the track.
*/
private transient JPanel trackPanel;
/** The slider for the locked HSB value. */
/**
* The slider for the locked HSB value.
*/
private transient UISlider slider;
/** The RadioButton that controls the Hue. */
/**
* The RadioButton that controls the Hue.
*/
private transient UIRadioButton hRadio;
/** The RadioButton that controls the Saturation. */
/**
* The RadioButton that controls the Saturation.
*/
private transient UIRadioButton sRadio;
/** The RadioButton that controls the Brightness. */
/**
* The RadioButton that controls the Brightness.
*/
private transient UIRadioButton bRadio;
/** The UIBasicSpinner that controls the Hue. */
/**
* The UIBasicSpinner that controls the Hue.
*/
private transient UIBasicSpinner hSpinner;
/** The UIBasicSpinner that controls the Saturation. */
/**
* The UIBasicSpinner that controls the Saturation.
*/
private transient UIBasicSpinner sSpinner;
/** The UIBasicSpinner that controls the Brightness. */
/**
* The UIBasicSpinner that controls the Brightness.
*/
private transient UIBasicSpinner bSpinner;
/** The UIBasicSpinner that controls the Red. */
/**
* The UIBasicSpinner that controls the Red.
*/
private transient UIBasicSpinner rSpinner;
/** The UIBasicSpinner that controls the Green. */
/**
* The UIBasicSpinner that controls the Green.
*/
private transient UIBasicSpinner gSpinner;
/** The UIBasicSpinner that controls the Blue. */
/**
* The UIBasicSpinner that controls the Blue.
*/
private transient UIBasicSpinner bbSpinner;
private transient UITextField field;
/** The default width of the gradient image. */
/**
* The default width of the gradient image.
*/
private static final int IMG_WIDTH = 200;
/** The default height of the gradient image. */
/**
* The default height of the gradient image.
*/
private static final int IMG_HEIGHT = 205;
/** The default width of the track gradient. */
/**
* The default width of the track gradient.
*/
private static final int TRACK_WIDTH = 20;
/** The UILabel for Red. */
/**
* The UILabel for Red.
*/
private static final UILabel R = new UILabel("R");
/** The UILabel for Green. */
/**
* The UILabel for Green.
*/
private static final UILabel G = new UILabel("G");
/** The UILabel for Blue. */
/**
* The UILabel for Blue.
*/
private static final UILabel B = new UILabel("B");
private static final int H_MAX = 365;
@ -131,7 +170,9 @@ class CustomChooserPanel extends AbstractColorChooserPanel
private ImageRGBScrollListener rgbScroll = new ImageRGBScrollListener();
/** The point that is displayed in the gradient image. */
/**
* The point that is displayed in the gradient image.
*/
private transient Point gradientPoint = new Point();
/**
@ -140,19 +181,29 @@ class CustomChooserPanel extends AbstractColorChooserPanel
*/
private transient boolean internalChange = false;
/** This indicates that the change to the spinner is triggered internally. */
/**
* This indicates that the change to the spinner is triggered internally.
*/
private transient boolean spinnerTrigger = false;
/** This int identifies which spinner is currently locked. */
/**
* This int identifies which spinner is currently locked.
*/
private transient int locked = -1;
/** This value indicates that the Hue spinner is locked. */
/**
* This value indicates that the Hue spinner is locked.
*/
static final int HLOCKED = 0;
/** This value indicates that the Saturation spinner is locked. */
/**
* This value indicates that the Saturation spinner is locked.
*/
static final int SLOCKED = 1;
/** This value indicates that the Brightness spinner is locked. */
/**
* This value indicates that the Brightness spinner is locked.
*/
static final int BLOCKED = 2;
/**
@ -168,6 +219,7 @@ class CustomChooserPanel extends AbstractColorChooserPanel
private static final String HEX_PATTERN = "([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$";
private Pattern pattern;
private Matcher matcher;
@Override
public void insertUpdate(DocumentEvent e) {
Document doc = e.getDocument();
@ -205,16 +257,14 @@ class CustomChooserPanel extends AbstractColorChooserPanel
* This helper class handles mouse events on the gradient image.
*/
class MainGradientMouseListener extends MouseAdapter
implements MouseMotionListener
{
implements MouseMotionListener {
/**
* This method is called when the mouse is pressed over the gradient
* image. The JColorChooser is then updated with new HSB values.
*
* @param e The MouseEvent.
*/
public void mousePressed(MouseEvent e)
{
public void mousePressed(MouseEvent e) {
gradientPoint = e.getPoint();
update(e.getPoint());
}
@ -225,8 +275,7 @@ class CustomChooserPanel extends AbstractColorChooserPanel
*
* @param e The MouseEvent.
*/
public void mouseDragged(MouseEvent e)
{
public void mouseDragged(MouseEvent e) {
Point p = e.getPoint();
if (isMouseOutOfImage(p)) {
return;
@ -245,8 +294,7 @@ class CustomChooserPanel extends AbstractColorChooserPanel
*
* @param e The MouseEvent.
*/
public void mouseMoved(MouseEvent e)
{
public void mouseMoved(MouseEvent e) {
// Do nothing.
}
@ -255,8 +303,7 @@ class CustomChooserPanel extends AbstractColorChooserPanel
*
* @param p The Point where the MouseEvent occurred.
*/
private void update(Point p)
{
private void update(Point p) {
handlingMouse = true;
if (hSpinner.isEnabled()) {
updateH(p);
@ -273,8 +320,7 @@ class CustomChooserPanel extends AbstractColorChooserPanel
*
* @param p The point where the MouseEvent occurred.
*/
private void updateH(Point p)
{
private void updateH(Point p) {
float s = (IMG_WIDTH - p.x * 1f) / IMG_WIDTH;
float b = (IMG_HEIGHT - p.y * 1f) / IMG_HEIGHT;
@ -292,8 +338,7 @@ class CustomChooserPanel extends AbstractColorChooserPanel
*
* @param p The point where the MouseEvent occurred.
*/
private void updateS(Point p)
{
private void updateS(Point p) {
float h = p.x * 1f / IMG_WIDTH;
float b = (IMG_HEIGHT - p.y * 1f) / IMG_HEIGHT;
@ -310,8 +355,7 @@ class CustomChooserPanel extends AbstractColorChooserPanel
*
* @param p The point where the MouseEvent occurred.
*/
private void updateB(Point p)
{
private void updateB(Point p) {
float h = p.x * 1f / IMG_WIDTH;
float s = (IMG_HEIGHT - p.y * 1f) / IMG_HEIGHT;
@ -327,16 +371,14 @@ class CustomChooserPanel extends AbstractColorChooserPanel
/**
* This method listens for slider value changes.
*/
class SliderChangeListener implements ChangeListener
{
class SliderChangeListener implements ChangeListener {
/**
* This method is called when the slider value changes. It should change
* the color of the JColorChooser.
*
* @param e The ChangeEvent.
*/
public void stateChanged(ChangeEvent e)
{
public void stateChanged(ChangeEvent e) {
if (internalChange) {
return;
}
@ -344,8 +386,7 @@ class CustomChooserPanel extends AbstractColorChooserPanel
Integer value = new Integer(slider.getValue());
switch (locked)
{
switch (locked) {
case HLOCKED:
hSpinner.setValue(value);
break;
@ -364,29 +405,22 @@ class CustomChooserPanel extends AbstractColorChooserPanel
* This helper class determines the active UIBasicSpinner.
*/
class RadioStateListener extends MouseAdapter
implements MouseMotionListener
{
implements MouseMotionListener {
/**
* This method is called when there is a new UIRadioButton that was
* selected. As a result, it should activate the associated UIBasicSpinner.
*
* @param e The ChangeEvent.
*/
public void mousePressed(MouseEvent e)
{
public void mousePressed(MouseEvent e) {
UIBasicSpinner change;
if (e.getSource() == hRadio)
{
if (e.getSource() == hRadio) {
locked = HLOCKED;
change = hSpinner;
}
else if (e.getSource() == sRadio)
{
} else if (e.getSource() == sRadio) {
locked = SLOCKED;
change = sSpinner;
}
else
{
} else {
locked = BLOCKED;
change = bSpinner;
}
@ -406,16 +440,14 @@ class CustomChooserPanel extends AbstractColorChooserPanel
/**
* hsl 监听
*/
class ImageScrollListener implements ChangeListener
{
class ImageScrollListener implements ChangeListener {
/**
* This method is called whenever one of the UIBasicSpinner values change. The
* JColorChooser should be updated with the new HSB values.
*
* @param e The ChangeEvent.
*/
public void stateChanged(ChangeEvent e)
{
public void stateChanged(ChangeEvent e) {
if (internalChange) {
return;
}
@ -427,16 +459,14 @@ class CustomChooserPanel extends AbstractColorChooserPanel
/**
* rgb 监听
*/
class ImageRGBScrollListener implements ChangeListener
{
class ImageRGBScrollListener implements ChangeListener {
/**
* This method is called whenever one of the UIBasicSpinner values change. The
* JColorChooser should be updated with the new HSB values.
*
* @param e The ChangeEvent.
*/
public void stateChanged(ChangeEvent e)
{
public void stateChanged(ChangeEvent e) {
if (internalChange) {
return;
}
@ -458,8 +488,7 @@ class CustomChooserPanel extends AbstractColorChooserPanel
/**
* Creates a new DefaultHSBChooserPanel object.
*/
CustomChooserPanel()
{
CustomChooserPanel() {
super();
}
@ -469,8 +498,7 @@ class CustomChooserPanel extends AbstractColorChooserPanel
*
* @return The name displayed in the JColorChooser tab.
*/
public String getDisplayName()
{
public String getDisplayName() {
return Inter.getLocText("FR-Designer_Custom");
}
@ -479,8 +507,7 @@ class CustomChooserPanel extends AbstractColorChooserPanel
* UIBasicSpinners, the JSlider, and the gradient image point) with updated
* values when the JColorChooser color value changes.
*/
public void updateChooser()
{
public void updateChooser() {
Color c = getColorSelectionModel().getSelectedColor();
float[] hsbVals = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(),
null);
@ -502,20 +529,17 @@ class CustomChooserPanel extends AbstractColorChooserPanel
}
private void adjustHSLValue(float[] hsbVals) {
if (! spinnerTrigger)
{
if (!spinnerTrigger) {
hSpinner.setValue(new Integer((int) (hsbVals[0] * HSPINNER_VALUE)));
sSpinner.setValue(new Integer((int) (hsbVals[1] * SSPINNER_VALUE)));
bSpinner.setValue(new Integer((int) (hsbVals[2] * LSPINNER_VALUE)));
}
switch (locked)
{
switch (locked) {
case HLOCKED:
if (slider != null) {
slider.setValue(((Number) hSpinner.getValue()).intValue());
}
if (! handlingMouse)
{
if (!handlingMouse) {
gradientPoint.x = (int) ((1
- ((Number) sSpinner.getValue()).intValue() / SSPINNER_VALUE) * IMG_WIDTH);
gradientPoint.y = (int) ((1
@ -526,8 +550,7 @@ class CustomChooserPanel extends AbstractColorChooserPanel
if (slider != null) {
slider.setValue(((Number) sSpinner.getValue()).intValue());
}
if (! handlingMouse)
{
if (!handlingMouse) {
gradientPoint.x = (int) (((Number) hSpinner.getValue()).intValue() / HSPINNER_VALUE * IMG_WIDTH);
gradientPoint.y = (int) ((1
- ((Number) bSpinner.getValue()).intValue() / LSPINNER_VALUE) * IMG_HEIGHT);
@ -537,8 +560,7 @@ class CustomChooserPanel extends AbstractColorChooserPanel
if (slider != null) {
slider.setValue(((Number) bSpinner.getValue()).intValue());
}
if (! handlingMouse)
{
if (!handlingMouse) {
gradientPoint.x = (int) (((Number) hSpinner.getValue()).intValue() / HSPINNER_VALUE * IMG_WIDTH);
gradientPoint.y = (int) ((1
- ((Number) sSpinner.getValue()).intValue() / SSPINNER_VALUE) * IMG_HEIGHT);
@ -556,8 +578,7 @@ class CustomChooserPanel extends AbstractColorChooserPanel
getColorSelectionModel().setSelectedColor(new Color(Color.HSBtoRGB(h, s, b)));
spinnerTrigger = false;
if (! handlingMouse && slider != null && ! slider.getValueIsAdjusting())
{
if (!handlingMouse && slider != null && !slider.getValueIsAdjusting()) {
updateImage();
updateTrack();
}
@ -569,8 +590,7 @@ class CustomChooserPanel extends AbstractColorChooserPanel
/**
* This method builds the DefaultHSBChooserPanel.
*/
protected void buildChooser()
{
protected void buildChooser() {
setLayout(new BorderLayout());
add(buildRightPanel(), BorderLayout.EAST);
JPanel container = new JPanel();
@ -604,15 +624,12 @@ class CustomChooserPanel extends AbstractColorChooserPanel
}
private JPanel createGradientPanel() {
return new JPanel()
{
public Dimension getPreferredSize()
{
return new JPanel() {
public Dimension getPreferredSize() {
return new Dimension(IMG_WIDTH, IMG_HEIGHT);
}
public void paint(Graphics g)
{
public void paint(Graphics g) {
if (gradientImage != null) {
g.drawImage(gradientImage, 0, 0, this);
}
@ -626,15 +643,12 @@ class CustomChooserPanel extends AbstractColorChooserPanel
}
private JPanel createTrackPanel() {
return new JPanel()
{
public Dimension getPreferredSize()
{
return new JPanel() {
public Dimension getPreferredSize() {
return new Dimension(TRACK_WIDTH, IMG_HEIGHT);
}
public void paint(Graphics g)
{
public void paint(Graphics g) {
if (trackImage != null) {
g.drawImage(trackImage, 0, 0, this);
}
@ -648,8 +662,7 @@ class CustomChooserPanel extends AbstractColorChooserPanel
*
* @param chooser The JColorChooser to remove this panel from.
*/
public void uninstallChooserPanel(JColorChooser chooser)
{
public void uninstallChooserPanel(JColorChooser chooser) {
trackImage = null;
gradientImage = null;
gradientPanel = null;
@ -673,8 +686,7 @@ class CustomChooserPanel extends AbstractColorChooserPanel
*
* @return The right side panel.
*/
private Container buildRightPanel()
{
private Container buildRightPanel() {
JPanel container = new JPanel();
container.setLayout(new FlowLayout(FlowLayout.RIGHT));
@ -802,8 +814,7 @@ class CustomChooserPanel extends AbstractColorChooserPanel
*
* @return The small display icon.
*/
public Icon getSmallDisplayIcon()
{
public Icon getSmallDisplayIcon() {
return null;
}
@ -812,8 +823,7 @@ class CustomChooserPanel extends AbstractColorChooserPanel
*
* @return The large display icon.
*/
public Icon getLargeDisplayIcon()
{
public Icon getLargeDisplayIcon() {
return null;
}
@ -821,14 +831,12 @@ class CustomChooserPanel extends AbstractColorChooserPanel
* This method updates the gradient image with a new one taking the Hue
* value as the constant.
*/
private void updateHLockImage()
{
private void updateHLockImage() {
int index = 0;
int[] pix = new int[IMG_WIDTH * IMG_HEIGHT];
float hValue = ((Number) hSpinner.getValue()).intValue() / HSPINNER_VALUE;
for (int j = 0; j < IMG_HEIGHT; j++)
{
for (int j = 0; j < IMG_HEIGHT; j++) {
for (int i = 0; i < IMG_WIDTH; i++) {
pix[index++] = Color.HSBtoRGB(hValue, (IMG_WIDTH - i * 1f) / IMG_WIDTH,
(IMG_HEIGHT - j * 1f) / IMG_HEIGHT) | (BINARY_FOR_EIGHT << TWENTY_FOUR);
@ -843,8 +851,7 @@ class CustomChooserPanel extends AbstractColorChooserPanel
* This method updates the gradient image with a new one taking the
* Brightness value as the constant.
*/
private void updateBLockImage()
{
private void updateBLockImage() {
int[] pix = new int[IMG_WIDTH * IMG_HEIGHT];
float bValue = ((Number) bSpinner.getValue()).intValue() / LSPINNER_VALUE;
@ -864,8 +871,7 @@ class CustomChooserPanel extends AbstractColorChooserPanel
* This method updates the gradient image with a new one taking the
* Saturation value as the constant.
*/
private void updateSLockImage()
{
private void updateSLockImage() {
int[] pix = new int[IMG_WIDTH * IMG_HEIGHT];
float sValue = ((Number) sSpinner.getValue()).intValue() / SSPINNER_VALUE;
@ -885,10 +891,8 @@ class CustomChooserPanel extends AbstractColorChooserPanel
* This method calls the appropriate method to update the gradient image
* depending on which HSB value is constant.
*/
private void updateImage()
{
switch (locked)
{
private void updateImage() {
switch (locked) {
case HLOCKED:
updateHLockImage();
break;
@ -904,8 +908,7 @@ class CustomChooserPanel extends AbstractColorChooserPanel
/**
* This method updates the TextFields with the correct RGB values.
*/
private void updateTextFields()
{
private void updateTextFields() {
int c = getColorSelectionModel().getSelectedColor().getRGB();
removeRGBSpinnerChangeLisener();
@ -929,8 +932,7 @@ class CustomChooserPanel extends AbstractColorChooserPanel
bbSpinner.addChangeListener(rgbScroll);
}
private void updateHexFields()
{
private void updateHexFields() {
Color color = getColorSelectionModel().getSelectedColor();
String R = Integer.toHexString(color.getRed());
@ -953,23 +955,19 @@ class CustomChooserPanel extends AbstractColorChooserPanel
* This method updates the slider in response to making a different HSB
* property the constant.
*/
private void updateSlider()
{
private void updateSlider() {
if (slider == null) {
return;
}
slider.setMinimum(0);
if (locked == HLOCKED)
{
if (locked == HLOCKED) {
internalChange = true;
slider.setValue(((Number) hSpinner.getValue()).intValue());
slider.setMaximum(359);
internalChange = false;
slider.setInverted(true);
}
else
{
} else {
slider.setInverted(false);
if (locked == SLOCKED) {
slider.setValue(((Number) sSpinner.getValue()).intValue());
@ -986,10 +984,8 @@ class CustomChooserPanel extends AbstractColorChooserPanel
* This method updates the track gradient image depending on which HSB
* property is constant.
*/
private void updateTrack()
{
switch (locked)
{
private void updateTrack() {
switch (locked) {
case HLOCKED:
updateHTrack();
break;
@ -1006,8 +1002,7 @@ class CustomChooserPanel extends AbstractColorChooserPanel
* This method updates the track gradient image if the Hue value is allowed
* to change (according to the UIRadioButtons).
*/
private void updateHTrack()
{
private void updateHTrack() {
int trackIndex = 0;
int[] trackPix = new int[TRACK_WIDTH * IMG_HEIGHT];
@ -1026,8 +1021,7 @@ class CustomChooserPanel extends AbstractColorChooserPanel
* This method updates the track gradient image if the Saturation value is
* allowed to change (according to the UIRadioButtons).
*/
private void updateSTrack()
{
private void updateSTrack() {
int[] trackPix = new int[TRACK_WIDTH * IMG_HEIGHT];
float hValue = ((Number) hSpinner.getValue()).intValue() / HSPINNER_VALUE;
@ -1050,8 +1044,7 @@ class CustomChooserPanel extends AbstractColorChooserPanel
* This method updates the track gradient image if the Brightness value is
* allowed to change (according to the UIRadioButtons).
*/
private void updateBTrack()
{
private void updateBTrack() {
int[] trackPix = new int[TRACK_WIDTH * IMG_HEIGHT];
float hValue = ((Number) hSpinner.getValue()).intValue() / HSPINNER_VALUE;

Loading…
Cancel
Save