|
|
@@ -1,344 +0,0 @@
|
|
|
-/*
|
|
|
- * @author Ranides Atterwim <ranides@gmail.com>
|
|
|
- * @copyright Ranides Atterwim
|
|
|
- * @license WTFPL
|
|
|
- * @url http://ranides.net/projects/assira
|
|
|
- */
|
|
|
-
|
|
|
-package net.ranides.assira.swing;
|
|
|
-
|
|
|
-import java.awt.*;
|
|
|
-import java.awt.event.MouseAdapter;
|
|
|
-import java.awt.event.MouseEvent;
|
|
|
-import javax.swing.BorderFactory;
|
|
|
-import javax.swing.JComponent;
|
|
|
-import javax.swing.JPanel;
|
|
|
-import javax.swing.border.Border;
|
|
|
-import net.ranides.assira.swing.QButtonManager.ButtonEntry;
|
|
|
-import net.ranides.assira.time.AutoTimerFrame;
|
|
|
-import net.ranides.assira.time.AutoTimerTask;
|
|
|
-import net.ranides.assira.time.TimeUtils;
|
|
|
-
|
|
|
-/**
|
|
|
- *
|
|
|
- * @author ranides
|
|
|
- */
|
|
|
-@SuppressWarnings({"PMD.TooManyDifferentMethods","PMD.TooManyFields"})
|
|
|
-public class QPanel extends JPanel {
|
|
|
-
|
|
|
- private static final long serialVersionUID = 1L;
|
|
|
-
|
|
|
- private transient AutoTimerTask<QPanel> animation;
|
|
|
- private final QButtonManager buttons;
|
|
|
-
|
|
|
- private boolean rolled = false;
|
|
|
- private int expanded = 0;
|
|
|
-
|
|
|
- protected int titleSize = 20;
|
|
|
- protected int animFrames = 10;
|
|
|
- protected int animInterval = 25;
|
|
|
- protected int animJump = 150;
|
|
|
- protected Border outsideBorder = BorderFactory.createEmptyBorder();
|
|
|
- protected Border insideBorder = BorderFactory.createEmptyBorder();
|
|
|
- protected int margin = 2;
|
|
|
- protected Color titleBack = new Color(64,96,160);
|
|
|
- protected MouseHandler handler = new MouseHandler();
|
|
|
- protected boolean cmove = false;
|
|
|
- protected boolean croll = true;
|
|
|
- protected int cclicks = 2;
|
|
|
-
|
|
|
-
|
|
|
-/* ************************************************************************** */
|
|
|
-
|
|
|
- class AnimationUp extends AutoTimerFrame<QPanel> {
|
|
|
-
|
|
|
- private final int target;
|
|
|
-
|
|
|
- public AnimationUp() {
|
|
|
- this.target = getRolledSize();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void run(QPanel panel, int now, int max) {
|
|
|
- float i = expanded - ((now+1.0f)/max)*(expanded-target);
|
|
|
- animStep( (int)i, true);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void started(QPanel panel) {
|
|
|
- rolled = true;
|
|
|
- setMinimumSize(null);
|
|
|
- setMaximumSize(null);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void finished(QPanel panel) {
|
|
|
- animStep(target, true);
|
|
|
- panel.repaint();
|
|
|
- animation = null;
|
|
|
-
|
|
|
- TimeUtils.runAfter(animJump, new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- Container parent = getParent();
|
|
|
- if(parent instanceof JComponent) { ((JComponent)parent).revalidate(); }
|
|
|
- parent.doLayout();
|
|
|
- parent.repaint();
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void canceled(QPanel panel) {
|
|
|
- animation = null;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- class AnimationDn extends AutoTimerFrame<QPanel> {
|
|
|
-
|
|
|
- private final int target;
|
|
|
-
|
|
|
- public AnimationDn() {
|
|
|
- this.target = getRolledSize();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void run(QPanel panel, int now, int max) {
|
|
|
- float i = target + ((now+1.0f)/max)*(expanded-target);
|
|
|
- animStep( (int)i, false);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void started(QPanel panel) {
|
|
|
- panel.rolled = false;
|
|
|
- panel.setMinimumSize(null);
|
|
|
- panel.setMaximumSize(null);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void finished(QPanel panel) {
|
|
|
- animStep(expanded, false);
|
|
|
-
|
|
|
- TimeUtils.runAfter(animJump, new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- Container parent = getParent();
|
|
|
- animation = null;
|
|
|
-
|
|
|
- if(parent instanceof JComponent) { ((JComponent)parent).revalidate(); }
|
|
|
- parent.doLayout();
|
|
|
- parent.repaint();
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void canceled(QPanel panel) {
|
|
|
- animation = null;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-/* ************************************************************************** */
|
|
|
-
|
|
|
- protected class MouseHandler extends MouseAdapter {
|
|
|
-
|
|
|
- private Point drag = null;
|
|
|
-
|
|
|
- @Override
|
|
|
- public void mouseDragged(MouseEvent event) {
|
|
|
- if( null == drag ) { return; }
|
|
|
- getTopLevelAncestor().setLocation(
|
|
|
- event.getXOnScreen() + drag.x,
|
|
|
- event.getYOnScreen() + drag.y
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void mouseClicked(MouseEvent event) {
|
|
|
- if(buttons.hitTest(event) && croll && event.getClickCount()>=cclicks) { toggleRolled(); }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void mouseReleased(MouseEvent event) {
|
|
|
- buttons.hitRelease(event);
|
|
|
- drag = null;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void mousePressed(MouseEvent event) {
|
|
|
- if( !buttons.hitTest(event) ) { return; }
|
|
|
- if(cmove) {
|
|
|
- Point point = getTopLevelAncestor().getLocation();
|
|
|
- drag = new Point(point.x - event.getXOnScreen(), point.y - event.getYOnScreen() );
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-/* ************************************************************************** */
|
|
|
-
|
|
|
- private void animStep(int height, boolean lock) {
|
|
|
- Dimension size = new Dimension(getWidth(), height );
|
|
|
- setSize(size);
|
|
|
- setPreferredSize(size);
|
|
|
- setMinimumSize(size);
|
|
|
- if(lock) { setMaximumSize(size); }
|
|
|
- }
|
|
|
-
|
|
|
- private int getRolledSize() {
|
|
|
- Insets insets = getBorder().getBorderInsets(this);
|
|
|
- return titleSize + insets.bottom + insets.top;
|
|
|
- }
|
|
|
-
|
|
|
-/* ************************************************************************** */
|
|
|
-
|
|
|
- public QPanel() {
|
|
|
- this.setBackground(new java.awt.Color(192, 224, 255));
|
|
|
- this.addMouseMotionListener(handler);
|
|
|
- this.addMouseListener(handler);
|
|
|
- buttons = new QButtonManager(this);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void paint(Graphics jcanvas) {
|
|
|
- super.paint(jcanvas);
|
|
|
- Graphics2D canvas = (Graphics2D)jcanvas;
|
|
|
- Insets insets = getBorder().getBorderInsets(this);
|
|
|
- int x = insets.left;
|
|
|
- int y = insets.top;
|
|
|
- int w = getWidth()-insets.left-insets.right;
|
|
|
- int h = getHeight()-insets.top-insets.bottom - titleSize;
|
|
|
-
|
|
|
- canvas.setColor( titleBack );
|
|
|
- canvas.fillRect(x, y, w, titleSize);
|
|
|
- if( null != insideBorder && (!rolled || null!=animation) ) {
|
|
|
- insideBorder.paintBorder(this, jcanvas, x, y+titleSize, w, h);
|
|
|
- }
|
|
|
- buttons.doLayout(insets.top, insets.right, -titleSize, insets.left);
|
|
|
- buttons.draw(canvas);
|
|
|
- }
|
|
|
-
|
|
|
-/* ************************************************************************** */
|
|
|
-
|
|
|
- public void setRolled(boolean rolled) {
|
|
|
- if(rolled == this.rolled) { return; }
|
|
|
-
|
|
|
- if(null == animation) {
|
|
|
- if(rolled) { expanded = getHeight(); }
|
|
|
- } else {
|
|
|
- animation.cancel();
|
|
|
- }
|
|
|
-
|
|
|
- animation = TimeUtils.runRepeat(animFrames, animInterval, this, rolled ? new AnimationUp() : new AnimationDn());
|
|
|
- }
|
|
|
-
|
|
|
- public boolean getRolled() {
|
|
|
- return rolled;
|
|
|
- }
|
|
|
-
|
|
|
- public boolean toggleRolled() {
|
|
|
- setRolled(!rolled);
|
|
|
- return rolled;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Border getBorder() {
|
|
|
- return outsideBorder;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void setBorder(Border border) {
|
|
|
- outsideBorder = border;
|
|
|
- super.setBorder(BorderFactory.createCompoundBorder(
|
|
|
- outsideBorder,
|
|
|
- BorderFactory.createEmptyBorder(titleSize+margin, margin, margin, margin)
|
|
|
- ));
|
|
|
- }
|
|
|
-
|
|
|
- public Border getInsideBorder() {
|
|
|
- return insideBorder;
|
|
|
- }
|
|
|
-
|
|
|
- public void setInsideBorder(Border insideBorder) {
|
|
|
- this.insideBorder = insideBorder;
|
|
|
- }
|
|
|
-
|
|
|
- public int getMarginSize() {
|
|
|
- return margin;
|
|
|
- }
|
|
|
-
|
|
|
- public void setMarginSize(int margin) {
|
|
|
- this.margin = margin;
|
|
|
- setBorder(getBorder());
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- public int getAnimFrames() {
|
|
|
- return animFrames;
|
|
|
- }
|
|
|
-
|
|
|
- public void setAnimFrames(int animFrames) {
|
|
|
- this.animFrames = animFrames;
|
|
|
- }
|
|
|
-
|
|
|
- public int getAnimFPS() {
|
|
|
- return Math.round(1000.0f / animInterval);
|
|
|
- }
|
|
|
-
|
|
|
- public void setAnimFPS(int animInterval) {
|
|
|
- this.animInterval = Math.round(1000.0f / animInterval);
|
|
|
- }
|
|
|
-
|
|
|
- public int getAnimJump() {
|
|
|
- return animJump;
|
|
|
- }
|
|
|
-
|
|
|
- public void setAnimJump(int animJump) {
|
|
|
- this.animJump = animJump;
|
|
|
- }
|
|
|
-
|
|
|
- public Color getTitleBackground() {
|
|
|
- return titleBack;
|
|
|
- }
|
|
|
-
|
|
|
- public void setTitleBackground(Color titleBack) {
|
|
|
- this.titleBack = titleBack;
|
|
|
- repaint();
|
|
|
- }
|
|
|
-
|
|
|
- public boolean isCaptionDrag() {
|
|
|
- return cmove;
|
|
|
- }
|
|
|
-
|
|
|
- public void setCaptionDrag(boolean cmove) {
|
|
|
- this.cmove = cmove;
|
|
|
- }
|
|
|
-
|
|
|
- public boolean isCaptionRoll() {
|
|
|
- return croll;
|
|
|
- }
|
|
|
-
|
|
|
- public void setCaptionRoll(boolean croll) {
|
|
|
- this.croll = croll;
|
|
|
- }
|
|
|
-
|
|
|
- public int getCaptionClicks() {
|
|
|
- return cclicks;
|
|
|
- }
|
|
|
-
|
|
|
- public void setCaptionClicks(int cclicks) {
|
|
|
- this.cclicks = cclicks;
|
|
|
- }
|
|
|
-
|
|
|
- public void addCaptionButton(ButtonEntry value) {
|
|
|
- buttons.add(value);
|
|
|
- }
|
|
|
-
|
|
|
- public void removeCaptionButton(int index) {
|
|
|
- buttons.remove(index);
|
|
|
- }
|
|
|
-
|
|
|
-};
|