/*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
*
* - Neither the name of Oracle nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* This source code is provided to illustrate the usage of a given feature
* or technique and has been deliberately simplified. Additional steps
* required for a production-quality application, such as security checks,
* input validation and proper error handling, might not be present in
* this sample code.
*/
package transparentruler;
/**
* This sample demonstrates shaped and translucent window feature.
* @author Alexander Kouznetsov
*/
@SuppressWarnings("serial")
private static final int W = 70;
private static boolean translucencySupported;
private static boolean transparencySupported;
}
int h = getHeight();
int w = getWidth();
return path;
}
/**
* Applies the shape to window. It is recommended to apply shape in
* componentResized() method
*/
public void componentResized(ComponentEvent e) {
// We do apply shape only if PERPIXEL_TRANSPARENT is supported
if (transparencySupported) {
setShape(buildShape());
}
}
};
{
}
public void actionPerformed(ActionEvent e) {
}
};
{
// To avoid popup cutting by main window shape forbid light-weight popups
jPopupMenu.setLightWeightPopupEnabled(false);
}
/**
* Implements mouse-related behavior: window dragging and popup menu
* invocation
*/
int x, y;
public void mousePressed(MouseEvent e) {
x = e.getX();
y = e.getY();
}
}
public void mouseDragged(MouseEvent e) {
}
}
public void mouseReleased(MouseEvent e) {
if (e.isPopupTrigger()) {
}
}
};
/**
* Implements keyboard navigation. Arrows move by 5 pixels, Ctrl + arrows
* move by 50 pixels, Alt + arrows move by 1 pixel.
* Esc exits the application.
*/
public void keyPressed(KeyEvent e) {
switch (e.getKeyCode()) {
break;
break;
break;
break;
}
}
};
public Ruler() {
setUndecorated(true);
// Enables perpixel translucency
setContentPane(new JPanel() {
protected void paintComponent(Graphics g) {
int w = getWidth();
int h = getHeight();
// This is an approach to apply shape when PERPIXEL_TRANSPARENT
// isn't supported
if (!transparencySupported) {
}
for (int x = 0; x < w * (h - 8) / h - 5; x += 5) {
if (hi) {
}
}
}
});
setLocationByPlatform(true);
}
/**
* @param args the command line arguments are ignored
*/
public void run() {
if (!translucencySupported) {
+ "'PERPIXEL_TRANSLUCENT' translucency mode to "
+ "be supported.");
}
ruler.setVisible(true);
}
});
}
}