/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
//The check mark is less common than a plain "depressed" button,
//so don't use the checkmark.
// The checkmark shape:
new int[] {1, 25,56,124,124,85, 64}, // X-coords
new int[] {59,35,67, 0, 12,66,123}, // Y-coords
7);
private boolean pressed;
private boolean armed;
private boolean selected;
private int checkBoxSize;
private int cbX;
private int cbY;
super(target);
pressed = false;
armed = false;
label = "";
}
}
// Put this here so it is executed before layout() is called from
// setFont() in XComponent.postInit()
}
public boolean isFocusable() { return true; }
// TODO: only need to paint the focus bit
super.focusGained(e);
repaint();
}
// TODO: only need to paint the focus bit?
super.focusLost(e);
repaint();
}
int i = e.getID();
switch (i) {
case KeyEvent.KEY_PRESSED:
keyPressed(e);
break;
case KeyEvent.KEY_RELEASED:
keyReleased(e);
break;
keyTyped(e);
break;
}
}
{
//pressed=true;
//armed=true;
//selected=!selected;
//repaint(); // Gets the repaint from action()
}
}
this.label = "";
} else {
}
layout();
repaint();
}
super.handleJavaMouseEvent(e);
int i = e.getID();
switch (i) {
case MouseEvent.MOUSE_PRESSED:
mousePressed(e);
break;
case MouseEvent.MOUSE_RELEASED:
mouseReleased(e);
break;
case MouseEvent.MOUSE_ENTERED:
mouseEntered(e);
break;
case MouseEvent.MOUSE_EXITED:
mouseExited(e);
break;
case MouseEvent.MOUSE_CLICKED:
mouseClicked(e);
break;
}
}
if (XToolkit.isLeftMouseButton(e)) {
log.finer("mousePressed() on " + target.getName() + " : armed = " + armed + ", pressed = " + pressed
}
if (!isEnabled()) {
// Disabled buttons ignore all input...
return;
}
if (!armed) {
armed = true;
}
pressed = true;
repaint();
}
}
}
log.finer("mouseReleased() on " + target.getName() + ": armed = " + armed + ", pressed = " + pressed
}
boolean sendEvent = false;
if (XToolkit.isLeftMouseButton(e)) {
// TODO: Multiclick Threshold? - see BasicButtonListener.java
if (armed) {
//selected = !selected;
// send action event
//action(e.getWhen(),e.getModifiers());
sendEvent = true;
}
pressed = false;
armed = false;
if (sendEvent) {
}
else {
repaint();
}
}
}
}
if (pressed) {
armed = true;
repaint();
}
}
}
if (armed) {
armed = false;
repaint();
}
}
/*
* Spacing (number of pixels between check mark and label text) is
* currently set to 0, but in case it ever changes we have to add
* it. 8 is a heuristic number. Indicator size depends on font
* height, so we don't need to include it in checkbox's height
* calculation.
*/
}
// the motif way of sizing is a bit inscutible, but this
// is a fair approximation
}
super.setBackground(c);
}
/*
*/
public void layout() {
Font f = getPeerFont();
// Note - Motif appears to use an left inset that is slightly
// FIXME: will need to account for alignment?
// FIXME: call layout() on alignment changes
//textRect.width = fm.stringWidth(text);
double fsize = (double) checkBoxSize;
myCheckMark = AffineTransform.getScaleInstance(fsize / MASTER_SIZE, fsize / MASTER_SIZE).createTransformedShape(MASTER_CHECKMARK);
}
if (g != null) {
//layout();
Font f = getPeerFont();
flush();
g.setFont(f);
}
if (hasFocus()) {
paintFocus(g,
focusRect.x,
focusRect.y,
}
// Paint the checkbox or radio button
if (checkBoxGroup == null) {
}
else {
}
}
flush();
}
// You'll note this looks suspiciously like paintBorder
int x, int y, int w, int h) {
boolean useBufferedImage = false;
int rx = x;
int ry = y;
if (!(g instanceof Graphics2D)) {
// Fix for 5045936. While printing, g is an instance of
// sun.print.ProxyPrintGraphics which extends Graphics. So
// we use a separate buffered image and its graphics is
// always Graphics2D instance
useBufferedImage = true;
rx = 0;
ry = 0;
}
else {
g2 = (Graphics2D)g;
}
try {
// then paint the check
//Paint the check
// FIXME: is this the right color?
}
} finally {
if (useBufferedImage) {
}
}
if (useBufferedImage) {
}
}
super.setFont(f);
}
g.setColor(selectColor);
}
}
int mnemonicIndex = -1;
if(isEnabled()) {
/*** paint the text normally */
g.setColor(getPeerForeground());
BasicGraphicsUtils.drawStringUnderlineCharAt(g,text,mnemonicIndex , textRect.x , textRect.y + fm.getAscent() );
}
else {
/*** paint the text disabled ***/
}
}
// TODO: copied directly from XButtonPeer. Should probabaly be shared
g.setColor(focusColor);
g.drawRect(x,y,w,h);
}
repaint();
}
}
checkBoxGroup = g;
repaint();
}
// NOTE: This method is called by privileged threads.
// DO NOT INVOKE CLIENT CODE ON THIS THREAD!
// From MCheckboxPeer
public void run() {
// Bugid 4039594. If this is the current Checkbox in
// a CheckboxGroup, then return to prevent deselection.
// Otherwise, it's logical state will be turned off,
// but it will appear on.
//inUpCall = false;
return;
}
// All clear - set the new state
}
});
}
postEvent(e);
}
}