From 045bfacdd1d02f5f848efb559e05e5918d2f1028 Mon Sep 17 00:00:00 2001 From: Yana Stamcheva Date: Tue, 31 Jul 2007 07:57:15 +0000 Subject: [PATCH] toggle button ui --- .../lookandfeel/SIPCommToggleButtonUI.java | 96 +- .../gui/resources/lookandfeel/button3.png | Bin 0 -> 909 bytes .../gui/resources/lookandfeel/button4.png | Bin 0 -> 782 bytes .../gui/resources/lookandfeel/src/button.svg | 923 ++++++++++++++++++ .../impl/gui/utils/ImageLoader.java | 12 + .../impl/gui/utils/images.properties | 2 + 6 files changed, 987 insertions(+), 46 deletions(-) create mode 100644 src/net/java/sip/communicator/impl/gui/resources/lookandfeel/button3.png create mode 100644 src/net/java/sip/communicator/impl/gui/resources/lookandfeel/button4.png create mode 100755 src/net/java/sip/communicator/impl/gui/resources/lookandfeel/src/button.svg diff --git a/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommToggleButtonUI.java b/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommToggleButtonUI.java index 541b88b50..e85eb1435 100644 --- a/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommToggleButtonUI.java +++ b/src/net/java/sip/communicator/impl/gui/lookandfeel/SIPCommToggleButtonUI.java @@ -7,15 +7,23 @@ package net.java.sip.communicator.impl.gui.lookandfeel; import java.awt.*; +import java.awt.image.*; import javax.swing.*; import javax.swing.plaf.*; -import javax.swing.plaf.metal.*; +import javax.swing.plaf.basic.*; + +import net.java.sip.communicator.impl.gui.utils.*; public class SIPCommToggleButtonUI - extends MetalToggleButtonUI + extends BasicToggleButtonUI { - + private final static BufferedImage buttonBG + = ImageLoader.getImage(ImageLoader.BUTTON); + + private final static BufferedImage buttonPressedBG + = ImageLoader.getImage(ImageLoader.TOGGLE_BUTTON_PRESSED); + // ******************************** // Create PLAF // ******************************** @@ -31,8 +39,7 @@ public void installDefaults(AbstractButton b) { b.setOpaque(false); b.setBorderPainted(false); - b.setFocusPainted(true); - b.setRolloverEnabled(true); + b.setFocusPainted(true); } public void uninstallDefaults(AbstractButton b) { @@ -40,52 +47,49 @@ public void uninstallDefaults(AbstractButton b) { b.setBorderPainted(true); b.setFocusPainted(false); - b.setOpaque(true); - b.setRolloverEnabled(false); + b.setOpaque(true); } - protected void paintFocus(Graphics g, AbstractButton b, - Rectangle viewRect, Rectangle textRect, Rectangle iconRect){ + public void paint(Graphics g, JComponent c) + { + AntialiasingManager.activateAntialiasing(g); - Graphics2D g2 = (Graphics2D)g; + AbstractButton button = (AbstractButton)c; + ButtonModel model = button.getModel(); - Rectangle focusRect = new Rectangle(); - String text = b.getText(); - boolean isIcon = b.getIcon() != null; + BufferedImage leftImg; + BufferedImage middleImg; + BufferedImage rightImg; - // If there is text - if ( text != null && !text.equals( "" ) ) { - if ( !isIcon ) { - focusRect.setBounds( textRect ); - } - else { - focusRect.setBounds( iconRect.union( textRect ) ); - } - } - // If there is an icon and no text - else if ( isIcon ) { - focusRect.setBounds( iconRect ); + int imgWidth; + int imgHeight; + int indentWidth = 10; + + if (model.isArmed() && model.isPressed() || model.isSelected()) + { + imgWidth = buttonPressedBG.getWidth(); + imgHeight = buttonPressedBG.getHeight(); + + leftImg = buttonPressedBG.getSubimage(0, 0, 10, imgHeight); + middleImg = buttonPressedBG.getSubimage(10, 0, imgWidth-20, imgHeight); + rightImg = buttonPressedBG.getSubimage(imgWidth-10, 0, 10, imgHeight); } - - g2.setStroke(new BasicStroke(0.5f,// Width - BasicStroke.CAP_ROUND, // End cap - BasicStroke.JOIN_ROUND, // Join style - 10.0f, // Miter limit - new float[] {1.0f,1.0f},// Dash pattern - 2.0f)); - g2.setColor(Color.GRAY); - g2.drawRoundRect((focusRect.x-3), (focusRect.y-3), - focusRect.width+4, focusRect.height+4, 5, 5); - } - - /** - * Overriden to draw a round rectangle. - */ - protected void paintButtonPressed(Graphics g, AbstractButton b){ - if ( b.isContentAreaFilled() ) { - Dimension size = b.getSize(); - g.setColor(getSelectColor()); - g.fillRoundRect(0, 0, size.width, size.height, 5, 5); + else + { + imgWidth = buttonBG.getWidth(); + imgHeight = buttonBG.getHeight(); + + leftImg = buttonBG.getSubimage(0, 0, 10, imgHeight); + middleImg = buttonBG.getSubimage(10, 0, imgWidth-20, imgHeight); + rightImg = buttonBG.getSubimage(imgWidth-10, 0, 10, imgHeight); } - } + + g.drawImage(leftImg, 0, 0, indentWidth, c.getHeight(), null); + g.drawImage(middleImg, indentWidth, 0, + c.getWidth()-2*indentWidth, c.getHeight(), null); + g.drawImage(rightImg, c.getWidth()-indentWidth, 0, + indentWidth, c.getHeight(), null); + + super.paint(g, c); + } } diff --git a/src/net/java/sip/communicator/impl/gui/resources/lookandfeel/button3.png b/src/net/java/sip/communicator/impl/gui/resources/lookandfeel/button3.png new file mode 100644 index 0000000000000000000000000000000000000000..f31ceafb32e8020cd45a467fd012e4ebe486d79f GIT binary patch literal 909 zcmV;819JR{P)G0F`c2Cu`IRGi!w!zF`W;mby+VY(=;KlsL-mT9)HmD82&SWzEey?Zl?e3<{+uJpI zzp?T2+uq)*c~#9ZGp??#aC38m!C>H8u@GWpPzd3|oL@#h6Or$G=X{c!Utb~uGo#z> z!Zb~&s@gA?O2+4%o%6)Y<>i%mRqZk}j*gCSa&iJ9f)FC`4#T5jlK8kWxm*sdRtuMx zmq}IAQkjK?w~11@JP#n*Y&LOxeC%t;dk4Lbi;c6F&1R9!X3=OghJ|8L6^fz&02zi6 z%g{qfgpCWcmrkd_%tS;GQdh&_a3X?ny&DyC#gvSC831t!P9mo$bGm|9dfFMa(;yKg zPQoxJ&p^^qKkqa=AA|v*5ot;Mv2{DCroA|3t?5Y}!px&1ge$d8s@rK|_j2&}^i%6L zY))TK&oa}+$-40F9<$PBoJBh{O)hyji9eNY$9a9E234O-C{G&_$24Cw&|F>@myTBuvvTc{u<3J+*Gb#s!}8rm5Sw zNoJJBy`B!5@G*5e$)YXG0yE!f`o6)MraifC!?1e24kBV^hNxa&_k<8;GMPj^pMMsK z#EVs{Ra{(LU~zGA&ZyP8iSyIbKZ>HfRulz=LIJ5%3Y|{Jm2jlqy}z;|WZU-0n6r-z zZf7p==7pfS0l=~>G#U+@ot+_{&-Xj+w%IbxQ`)RlR*I$4;fJlQfs#nf4F&@>tgPkS z*ZppZ`<1}L`ZF{6^(P`r*LADiZkylt_tkc*wMMc43E)eAeF5@6dMx%dK{S9P00000NkvXXu0mjfW81W5 literal 0 HcmV?d00001 diff --git a/src/net/java/sip/communicator/impl/gui/resources/lookandfeel/button4.png b/src/net/java/sip/communicator/impl/gui/resources/lookandfeel/button4.png new file mode 100644 index 0000000000000000000000000000000000000000..80a1fe983d0973df822167f76abd245ccb873993 GIT binary patch literal 782 zcmV+p1M&QcP)K0UeTd&5&O~rc|BM zC25Cr&C;mqKgh=Kh}1Fd5UFcK#uP#=qZS$*Iri;POpGyBXh?C6bR@qo`QG#HyYJ}| zGvn3v_HzIq3&rBgN~Mxh6a_Ou6x}_0#e-p4*0tH~o&tDx+-#oFPNT7|vib54k5(&XF)LYxG(tqP!JKAd8*HMUR71(a=D-H_xHc0@=|W(G|e$h zQ{CFyLbX~2GcTOJlk?K^JOF^}x^P`rSzTM(P%4Izy}G(`R#sL}tJM~wS`;4Qu;Vzs z1F~AHWt7pjkgn^GqVOU~L?ncOGKw8erBX{VWS*TGAKJ$WhWldG@fGiNb2PhMAU<6=}O**Q`flXc}q7c zjzWk#rAI-|{eJ(yZ}~isQUUH0MyM2=y z^!s1z;c!(-DO;_US}K*0&*u>?jrnixr~?~Uya`vG!kHin{+JK~g+c+vVi81y8{76; z=jUH(r_orKg~G|3y}jRRCL;%ffeJvGRkDg|2TNeHI6g!X^TK_>_GsO;Jsdh84i7Wm zFE2NV`K|!@OxIr+hM~n4ApaF{%El~XX7ns;*lD* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/net/java/sip/communicator/impl/gui/utils/ImageLoader.java b/src/net/java/sip/communicator/impl/gui/utils/ImageLoader.java index 7fa0cf8bd..977446d17 100644 --- a/src/net/java/sip/communicator/impl/gui/utils/ImageLoader.java +++ b/src/net/java/sip/communicator/impl/gui/utils/ImageLoader.java @@ -52,6 +52,18 @@ public class ImageLoader { public static final ImageID BUTTON_ROLLOVER = new ImageID("BUTTON_ROLLOVER"); + /** + * The pressed toggle button background image. + */ + public static final ImageID TOGGLE_BUTTON_PRESSED + = new ImageID("TOGGLE_BUTTON_PRESSED"); + + /** + * The toggle button background image. + */ + public static final ImageID TOGGLE_BUTTON + = new ImageID("TOGGLE_BUTTON"); + /** * The image used for a horizontal split. */ diff --git a/src/net/java/sip/communicator/impl/gui/utils/images.properties b/src/net/java/sip/communicator/impl/gui/utils/images.properties index 865209da3..f579b0309 100644 --- a/src/net/java/sip/communicator/impl/gui/utils/images.properties +++ b/src/net/java/sip/communicator/impl/gui/utils/images.properties @@ -167,6 +167,8 @@ CLOSABLE_TAB_BG=net/java/sip/communicator/impl/gui/resources/lookandfeel/closabl BUTTON=net/java/sip/communicator/impl/gui/resources/lookandfeel/button1.png BUTTON_ROLLOVER=net/java/sip/communicator/impl/gui/resources/lookandfeel/button2.png +TOGGLE_BUTTON_PRESSED=net/java/sip/communicator/impl/gui/resources/lookandfeel/button3.png +TOGGLE_BUTTON=net/java/sip/communicator/impl/gui/resources/lookandfeel/button4.png SPLITPANE_HORIZONTAL=net/java/sip/communicator/impl/gui/resources/lookandfeel/splitpaneHorizontal.png SPLITPANE_VERTICAL=net/java/sip/communicator/impl/gui/resources/lookandfeel/splitpaneVertical.png