|
|
@ -1,89 +1,81 @@ |
|
|
|
package com.fr.design.gui.ibutton; |
|
|
|
package com.fr.design.gui.ibutton; |
|
|
|
|
|
|
|
|
|
|
|
import java.awt.Dimension; |
|
|
|
import com.fr.base.BaseUtils; |
|
|
|
import java.awt.Graphics; |
|
|
|
import com.fr.design.constants.UIConstants; |
|
|
|
import java.awt.Graphics2D; |
|
|
|
import com.fr.design.utils.gui.GUICoreUtils; |
|
|
|
import java.awt.GridLayout; |
|
|
|
|
|
|
|
|
|
|
|
import javax.swing.*; |
|
|
|
|
|
|
|
import java.awt.*; |
|
|
|
import java.awt.event.MouseAdapter; |
|
|
|
import java.awt.event.MouseAdapter; |
|
|
|
import java.awt.event.MouseEvent; |
|
|
|
import java.awt.event.MouseEvent; |
|
|
|
import java.awt.event.MouseListener; |
|
|
|
import java.awt.event.MouseListener; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
import javax.swing.BorderFactory; |
|
|
|
public class UIHeadGroup extends JPanel { |
|
|
|
import javax.swing.Icon; |
|
|
|
protected List<UIToggleButton> labelButtonList; |
|
|
|
import javax.swing.JFrame; |
|
|
|
private boolean isNeedLeftRightOutLine = true; |
|
|
|
import javax.swing.JPanel; |
|
|
|
protected int selectedIndex = -1; |
|
|
|
|
|
|
|
|
|
|
|
import com.fr.base.BaseUtils; |
|
|
|
protected void tabChanged(int newSelectedIndex) { |
|
|
|
import com.fr.design.constants.UIConstants; |
|
|
|
|
|
|
|
import com.fr.design.utils.gui.GUICoreUtils; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class UIHeadGroup extends JPanel{ |
|
|
|
} |
|
|
|
protected List<UIToggleButton> labelButtonList; |
|
|
|
|
|
|
|
private boolean isNeedLeftRightOutLine = true; |
|
|
|
public UIHeadGroup(String[] textArray) { |
|
|
|
protected int selectedIndex = -1; |
|
|
|
labelButtonList = new ArrayList<UIToggleButton>(textArray.length); |
|
|
|
|
|
|
|
this.setBackground(UIConstants.NORMAL_BACKGROUND); |
|
|
|
protected void tabChanged(int newSelectedIndex) { |
|
|
|
this.setLayout(new GridLayout(0, textArray.length, 1, 0)); |
|
|
|
|
|
|
|
// this.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
|
|
|
|
} |
|
|
|
for (int i = 0; i < textArray.length; i++) { |
|
|
|
|
|
|
|
final int index = i; |
|
|
|
public UIHeadGroup(String[] textArray) { |
|
|
|
String text = textArray[i]; |
|
|
|
labelButtonList = new ArrayList<UIToggleButton>(textArray.length); |
|
|
|
final UIToggleButton labelButton = new UIToggleButton(text) { |
|
|
|
this.setBackground(UIConstants.NORMAL_BACKGROUND); |
|
|
|
@Override |
|
|
|
this.setLayout(new GridLayout(0, textArray.length, 1, 0)); |
|
|
|
protected MouseListener getMouseListener() { |
|
|
|
this.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); |
|
|
|
return new MouseAdapter() { |
|
|
|
for(int i = 0; i < textArray.length; i++) { |
|
|
|
@Override |
|
|
|
final int index = i; |
|
|
|
public void mousePressed(MouseEvent e) { |
|
|
|
String text = textArray[i]; |
|
|
|
setSelectedIndex(index); |
|
|
|
final UIToggleButton labelButton = new UIToggleButton(text) { |
|
|
|
UIHeadGroup.this.repaint(); |
|
|
|
@Override |
|
|
|
} |
|
|
|
protected MouseListener getMouseListener() { |
|
|
|
}; |
|
|
|
return new MouseAdapter() { |
|
|
|
} |
|
|
|
@Override |
|
|
|
}; |
|
|
|
public void mousePressed(MouseEvent e) { |
|
|
|
initButton(labelButton); |
|
|
|
setSelectedIndex(index); |
|
|
|
} |
|
|
|
UIHeadGroup.this.repaint(); |
|
|
|
setSelectedIndex(0); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
public UIHeadGroup(Icon[] iconArray) { |
|
|
|
}; |
|
|
|
labelButtonList = new ArrayList<UIToggleButton>(iconArray.length); |
|
|
|
initButton(labelButton); |
|
|
|
this.setBackground(UIConstants.NORMAL_BACKGROUND); |
|
|
|
} |
|
|
|
this.setLayout(new GridLayout(0, iconArray.length, 1, 0)); |
|
|
|
setSelectedIndex(0); |
|
|
|
// this.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
|
|
|
|
} |
|
|
|
for (int i = 0; i < iconArray.length; i++) { |
|
|
|
|
|
|
|
final int index = i; |
|
|
|
public UIHeadGroup(Icon[] iconArray) { |
|
|
|
Icon icon = iconArray[i]; |
|
|
|
labelButtonList = new ArrayList<UIToggleButton>(iconArray.length); |
|
|
|
final UIToggleButton labelButton = new UIToggleButton(icon) { |
|
|
|
this.setBackground(UIConstants.NORMAL_BACKGROUND); |
|
|
|
@Override |
|
|
|
this.setLayout(new GridLayout(0, iconArray.length, 1, 0)); |
|
|
|
protected MouseListener getMouseListener() { |
|
|
|
this.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); |
|
|
|
return new MouseAdapter() { |
|
|
|
for(int i = 0; i < iconArray.length; i++) { |
|
|
|
@Override |
|
|
|
final int index = i; |
|
|
|
public void mousePressed(MouseEvent e) { |
|
|
|
Icon icon = iconArray[i]; |
|
|
|
setSelectedIndex(index); |
|
|
|
final UIToggleButton labelButton = new UIToggleButton(icon) { |
|
|
|
UIHeadGroup.this.repaint(); |
|
|
|
@Override |
|
|
|
} |
|
|
|
protected MouseListener getMouseListener() { |
|
|
|
}; |
|
|
|
return new MouseAdapter() { |
|
|
|
} |
|
|
|
@Override |
|
|
|
}; |
|
|
|
public void mousePressed(MouseEvent e) { |
|
|
|
initButton(labelButton); |
|
|
|
setSelectedIndex(index); |
|
|
|
} |
|
|
|
UIHeadGroup.this.repaint(); |
|
|
|
setSelectedIndex(0); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
initButton(labelButton); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
setSelectedIndex(0); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public UIHeadGroup(Icon[] iconArray, String[] textArray) { |
|
|
|
public UIHeadGroup(Icon[] iconArray, String[] textArray) { |
|
|
|
labelButtonList = new ArrayList<UIToggleButton>(Math.min(textArray.length, iconArray.length)); |
|
|
|
labelButtonList = new ArrayList<UIToggleButton>(Math.min(textArray.length, iconArray.length)); |
|
|
|
this.setBackground(UIConstants.NORMAL_BACKGROUND); |
|
|
|
this.setBackground(UIConstants.NORMAL_BACKGROUND); |
|
|
|
this.setLayout(new GridLayout(0, textArray.length, 1, 0)); |
|
|
|
this.setLayout(new GridLayout(0, textArray.length, 1, 0)); |
|
|
|
this.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); |
|
|
|
for (int i = 0; i < textArray.length; i++) { |
|
|
|
for(int i = 0; i < textArray.length; i++) { |
|
|
|
|
|
|
|
final int index = i; |
|
|
|
final int index = i; |
|
|
|
String text = textArray[i]; |
|
|
|
String text = textArray[i]; |
|
|
|
Icon icon = iconArray[i]; |
|
|
|
Icon icon = iconArray[i]; |
|
|
@ -104,15 +96,15 @@ public class UIHeadGroup extends JPanel{ |
|
|
|
setSelectedIndex(0); |
|
|
|
setSelectedIndex(0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Dimension getPreferredSize() { |
|
|
|
public Dimension getPreferredSize() { |
|
|
|
Dimension dim = super.getPreferredSize(); |
|
|
|
Dimension dim = super.getPreferredSize(); |
|
|
|
dim.height = 25; |
|
|
|
dim.height = 25; |
|
|
|
return dim; |
|
|
|
return dim; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected void paintBorder(Graphics g) { |
|
|
|
protected void paintBorder(Graphics g) { |
|
|
|
// Graphics2D g2d = (Graphics2D)g;
|
|
|
|
// Graphics2D g2d = (Graphics2D)g;
|
|
|
|
// g2d.setColor(UIConstants.LINE_COLOR);
|
|
|
|
// g2d.setColor(UIConstants.LINE_COLOR);
|
|
|
|
//
|
|
|
|
//
|
|
|
@ -135,56 +127,56 @@ public class UIHeadGroup extends JPanel{ |
|
|
|
// g2d.setColor(UIConstants.NORMAL_BACKGROUND);
|
|
|
|
// g2d.setColor(UIConstants.NORMAL_BACKGROUND);
|
|
|
|
// UIToggleButton headButton = labelButtonList.get(selectedIndex);
|
|
|
|
// UIToggleButton headButton = labelButtonList.get(selectedIndex);
|
|
|
|
// g2d.drawLine(headButton.getX(), headButton.getHeight() + 1, headButton.getX() + headButton.getWidth() - 1, headButton.getHeight() + 1);
|
|
|
|
// g2d.drawLine(headButton.getX(), headButton.getHeight() + 1, headButton.getX() + headButton.getWidth() - 1, headButton.getHeight() + 1);
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void initButton(UIToggleButton labelButton) { |
|
|
|
private void initButton(UIToggleButton labelButton) { |
|
|
|
labelButton.setRoundBorder(false); |
|
|
|
labelButton.setRoundBorder(false); |
|
|
|
labelButton.setBorderPainted(false); |
|
|
|
labelButton.setBorderPainted(false); |
|
|
|
labelButton.setPressedPainted(false); |
|
|
|
labelButton.setPressedPainted(false); |
|
|
|
labelButtonList.add(labelButton); |
|
|
|
labelButtonList.add(labelButton); |
|
|
|
this.add(labelButton); |
|
|
|
this.add(labelButton); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setSelectedIndex(int newSelectedIndex) { |
|
|
|
public void setSelectedIndex(int newSelectedIndex) { |
|
|
|
selectedIndex = newSelectedIndex; |
|
|
|
selectedIndex = newSelectedIndex; |
|
|
|
for (int i = 0; i < labelButtonList.size(); i++) { |
|
|
|
for (int i = 0; i < labelButtonList.size(); i++) { |
|
|
|
UIToggleButton button = labelButtonList.get(i); |
|
|
|
UIToggleButton button = labelButtonList.get(i); |
|
|
|
if(i == selectedIndex) { |
|
|
|
if (i == selectedIndex) { |
|
|
|
button.setNormalPainted(false); |
|
|
|
button.setNormalPainted(false); |
|
|
|
button.setOpaque(true); |
|
|
|
button.setBackground(new Color(240, 240, 243)); |
|
|
|
button.setBackground(null); |
|
|
|
button.setOpaque(true); |
|
|
|
button.setSelected(true); |
|
|
|
button.setSelected(true); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
button.setOpaque(false); |
|
|
|
button.setOpaque(false); |
|
|
|
button.setNormalPainted(true); |
|
|
|
button.setNormalPainted(true); |
|
|
|
button.setSelected(false); |
|
|
|
button.setSelected(false); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
tabChanged(newSelectedIndex); |
|
|
|
tabChanged(newSelectedIndex); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setNeedLeftRightOutLine(boolean isNeedLeftRightOutLine) { |
|
|
|
public void setNeedLeftRightOutLine(boolean isNeedLeftRightOutLine) { |
|
|
|
this.isNeedLeftRightOutLine = isNeedLeftRightOutLine; |
|
|
|
this.isNeedLeftRightOutLine = isNeedLeftRightOutLine; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public int getSelectedIndex() { |
|
|
|
public int getSelectedIndex() { |
|
|
|
return selectedIndex; |
|
|
|
return selectedIndex; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void main(String... args) { |
|
|
|
public static void main(String... args) { |
|
|
|
JFrame jf = new JFrame("test"); |
|
|
|
JFrame jf = new JFrame("test"); |
|
|
|
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
|
|
|
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
|
|
|
JPanel content = (JPanel)jf.getContentPane(); |
|
|
|
JPanel content = (JPanel) jf.getContentPane(); |
|
|
|
content.setLayout(null); |
|
|
|
content.setLayout(null); |
|
|
|
Icon[] a1 = {BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_left_normal.png"), BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_center_normal.png"), |
|
|
|
Icon[] a1 = {BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_left_normal.png"), BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_center_normal.png"), |
|
|
|
BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_right_normal.png")}; |
|
|
|
BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_right_normal.png")}; |
|
|
|
UIHeadGroup bb = new UIHeadGroup(a1); |
|
|
|
UIHeadGroup bb = new UIHeadGroup(a1); |
|
|
|
bb.setBounds(20, 20, bb.getPreferredSize().width, bb.getPreferredSize().height); |
|
|
|
bb.setBounds(20, 20, bb.getPreferredSize().width, bb.getPreferredSize().height); |
|
|
|
bb.setSelectedIndex(0); |
|
|
|
bb.setSelectedIndex(0); |
|
|
|
content.add(bb); |
|
|
|
content.add(bb); |
|
|
|
GUICoreUtils.centerWindow(jf); |
|
|
|
GUICoreUtils.centerWindow(jf); |
|
|
|
jf.setSize(400, 400); |
|
|
|
jf.setSize(400, 400); |
|
|
|
jf.setVisible(true); |
|
|
|
jf.setVisible(true); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |