17 |
ilm |
1 |
/*
|
|
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
|
|
3 |
*
|
182 |
ilm |
4 |
* Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
|
17 |
ilm |
5 |
*
|
|
|
6 |
* The contents of this file are subject to the terms of the GNU General Public License Version 3
|
|
|
7 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
|
|
|
8 |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
|
|
|
9 |
* language governing permissions and limitations under the License.
|
|
|
10 |
*
|
|
|
11 |
* When distributing the software, include this License Header Notice in each file.
|
|
|
12 |
*/
|
|
|
13 |
|
|
|
14 |
/*
|
|
|
15 |
* Created on 21 mai 2005
|
|
|
16 |
*
|
|
|
17 |
* To change the template for this generated file go to
|
|
|
18 |
* Window>Preferences>Java>Code Generation>Code and Comments
|
|
|
19 |
*/
|
|
|
20 |
package org.openconcerto.laf;
|
|
|
21 |
|
|
|
22 |
import java.awt.BasicStroke;
|
|
|
23 |
import java.awt.Color;
|
|
|
24 |
import java.awt.Dimension;
|
|
|
25 |
import java.awt.Font;
|
|
|
26 |
import java.awt.Graphics;
|
|
|
27 |
import java.awt.Graphics2D;
|
|
|
28 |
import java.awt.Rectangle;
|
|
|
29 |
import java.beans.PropertyChangeEvent;
|
|
|
30 |
import java.beans.PropertyChangeListener;
|
|
|
31 |
|
|
|
32 |
import javax.swing.AbstractButton;
|
|
|
33 |
import javax.swing.JButton;
|
|
|
34 |
import javax.swing.JComponent;
|
|
|
35 |
import javax.swing.JToggleButton;
|
|
|
36 |
import javax.swing.plaf.ComponentUI;
|
|
|
37 |
import javax.swing.plaf.metal.MetalButtonUI;
|
|
|
38 |
|
|
|
39 |
public class IButtonUI extends MetalButtonUI {
|
|
|
40 |
|
|
|
41 |
public static final boolean HINT_DO_NOT_PAINT_TOOLBARBUTTON_IF_NO_MOUSE_OVER = true;
|
|
|
42 |
/**
|
|
|
43 |
* The Cached UI delegate.
|
|
|
44 |
*/
|
|
|
45 |
private static final IButtonUI buttonUI = new IButtonUI();
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
/** the stroke for the fcouse */
|
|
|
49 |
static BasicStroke focusStroke=new BasicStroke(1.0f,BasicStroke.CAP_BUTT,BasicStroke.JOIN_BEVEL,1.0f, new float[] {1.0f, 1.0f}, 1.0f);
|
|
|
50 |
|
|
|
51 |
public IButtonUI() {
|
|
|
52 |
|
|
|
53 |
// timer=TimerFactory.getTimer();
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
protected void paintFocus(Graphics g, AbstractButton b, Rectangle viewRect, Rectangle textRect, Rectangle iconRect) {
|
|
|
57 |
Graphics2D g2d=(Graphics2D)g;
|
|
|
58 |
Rectangle focusRect = b.getBounds();
|
|
|
59 |
|
|
|
60 |
|
|
|
61 |
/*g.setColor(Color.black);
|
|
|
62 |
g2d.setStroke(focusStroke);
|
|
|
63 |
|
|
|
64 |
g2d.drawLine(2 , 2, 2 + focusRect.width - 5, 2);
|
|
|
65 |
g2d.drawLine(2, 2+focusRect.height - 5, 2 + focusRect.width - 5, 2+focusRect.height - 5);
|
|
|
66 |
g2d.drawLine(2 , 2, 2 , 2+focusRect.height - 5);
|
|
|
67 |
g2d.drawLine(2 + focusRect.width - 5, 2, 2+ focusRect.width - 5 , 2+focusRect.height - 5);
|
|
|
68 |
*/
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
/**
|
|
|
72 |
* Creates the UI delegate for the given component.
|
|
|
73 |
*
|
|
|
74 |
* @param c The component to create its UI delegate.
|
|
|
75 |
* @return The UI delegate for the given component.
|
|
|
76 |
*/
|
|
|
77 |
public static ComponentUI createUI(final JComponent c) {
|
|
|
78 |
if (c instanceof JButton) {
|
|
|
79 |
JButton b = (JButton) c;
|
|
|
80 |
b.setRolloverEnabled(true);
|
|
|
81 |
} else if (c instanceof JToggleButton) {
|
|
|
82 |
JToggleButton b = (JToggleButton) c;
|
|
|
83 |
b.setRolloverEnabled(true);
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
// If we used an transparent toolbutton skin we would have to add:
|
|
|
87 |
c.setOpaque(false);
|
|
|
88 |
c.addPropertyChangeListener("opaque",new PropertyChangeListener() {
|
|
|
89 |
public void propertyChange(PropertyChangeEvent evt) {
|
|
|
90 |
c.setOpaque(false);
|
|
|
91 |
}
|
|
|
92 |
});
|
|
|
93 |
return buttonUI;
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
/**
|
|
|
97 |
* We don't want to paint the pressed state here - the skin does it for us.
|
|
|
98 |
* @see javax.swing.plaf.basic.BasicButtonUI#paintButtonPressed(Graphics, AbstractButton)
|
|
|
99 |
*/
|
|
|
100 |
protected void paintButtonPressed(Graphics g, AbstractButton b) {
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
private static Color bordure=new Color(140,140,121);
|
|
|
104 |
|
|
|
105 |
|
|
|
106 |
public void paint(Graphics g, JComponent c) {
|
|
|
107 |
|
|
|
108 |
AbstractButton button = (AbstractButton) c;
|
|
|
109 |
|
|
|
110 |
Rectangle rect=button.getBounds();
|
|
|
111 |
rect.setLocation(1,1);
|
|
|
112 |
rect.height-=3;
|
|
|
113 |
rect.width-=3;
|
|
|
114 |
|
|
|
115 |
|
|
|
116 |
//g.setColor(Color.RED);
|
|
|
117 |
//g.fillRect(rect.x,rect.y,rect.width,rect.height);
|
|
|
118 |
/*g.setColor(bordure);
|
|
|
119 |
g.drawLine(rect.x+1,rect.y,rect.x+rect.width-1,rect.y);
|
|
|
120 |
g.drawLine(rect.x+1,rect.y+rect.height,rect.x+rect.width-1,rect.y+rect.height);
|
|
|
121 |
g.drawLine(rect.x,rect.y+1,rect.x,rect.y+rect.height-1);
|
|
|
122 |
g.drawLine(rect.x+rect.width,rect.y+1,rect.x+rect.width,rect.y+rect.height-1);
|
|
|
123 |
rect.grow(-1,-1);*/
|
|
|
124 |
g.setColor(new Color(254,254,254));
|
|
|
125 |
|
|
|
126 |
g.fillRect(rect.x,rect.y,rect.width,rect.height);
|
|
|
127 |
|
|
|
128 |
if (button.getClientProperty("JToolBar.isToolbarButton") == Boolean.TRUE) {
|
|
|
129 |
// toolbarIndexModel.setButton(button);
|
|
|
130 |
// int index=toolbarIndexModel.getIndexForState();
|
|
|
131 |
// getSkinToolbar().draw(g, index, button.getWidth(), button.getHeight());
|
|
|
132 |
// }
|
|
|
133 |
} else {
|
|
|
134 |
|
|
|
135 |
// buttonIndexModel.setButton(button);
|
|
|
136 |
// buttonIndexModel.setCheckForDefaultButton(button instanceof JButton);
|
|
|
137 |
// int index=buttonIndexModel.getIndexForState();
|
|
|
138 |
// getSkinButton().draw(g, index, button.getWidth(), button.getHeight());
|
|
|
139 |
}
|
|
|
140 |
|
|
|
141 |
|
|
|
142 |
super.paint(g, c);
|
|
|
143 |
|
|
|
144 |
// double el=timer.stop();
|
|
|
145 |
// System.out.println("Painting took "+el+" [msec] ");
|
|
|
146 |
}
|
|
|
147 |
|
|
|
148 |
|
|
|
149 |
|
|
|
150 |
public void update(Graphics g, JComponent c) {
|
|
|
151 |
paint(g, c);
|
|
|
152 |
}
|
|
|
153 |
|
|
|
154 |
/* (non-Javadoc)
|
|
|
155 |
* @see javax.swing.plaf.basic.BasicButtonUI#getMinimumSize(javax.swing.JComponent)
|
|
|
156 |
*/
|
|
|
157 |
public Dimension getMinimumSize(JComponent c) {
|
|
|
158 |
// TODO Auto-generated method stub
|
|
|
159 |
return super.getMinimumSize(c);
|
|
|
160 |
}
|
|
|
161 |
|
|
|
162 |
/* (non-Javadoc)
|
|
|
163 |
* @see javax.swing.plaf.basic.BasicButtonUI#getPreferredSize(javax.swing.JComponent)
|
|
|
164 |
*/
|
|
|
165 |
public Dimension getPreferredSize(JComponent c) {
|
|
|
166 |
AbstractButton b = (AbstractButton)c;
|
|
|
167 |
if( b.getIcon()!=null)
|
|
|
168 |
return new Dimension(super.getPreferredSize(c).width,super.getPreferredSize(c).height);
|
|
|
169 |
else{
|
|
|
170 |
return new Dimension(super.getPreferredSize(c).width,super.getPreferredSize(c).height-6);
|
|
|
171 |
|
|
|
172 |
|
|
|
173 |
}
|
|
|
174 |
}
|
|
|
175 |
|
|
|
176 |
|
|
|
177 |
/* (non-Javadoc)
|
|
|
178 |
* @see javax.swing.plaf.metal.MetalButtonUI#paintText(java.awt.Graphics, javax.swing.JComponent, java.awt.Rectangle, java.lang.String)
|
|
|
179 |
*/
|
|
|
180 |
protected void paintText(Graphics g, JComponent c, Rectangle textRect, String text) {
|
|
|
181 |
|
|
|
182 |
g.setFont(new Font("Tahoma",Font.PLAIN,10));
|
|
|
183 |
textRect.translate(0,1);
|
|
|
184 |
super.paintText(g, c, textRect, text);
|
|
|
185 |
}
|
|
|
186 |
}
|
|
|
187 |
|