sparktoaster.java.svn-base
来自「开源项目openfire的完整源程序」· SVN-BASE 代码 · 共 682 行 · 第 1/2 页
SVN-BASE
682 行
maxToaster = 0;
}
}
currentNumberOfToaster++;
maxToaster++;
animateVertically(posx, startYPosition, stopYPosition);
Thread.sleep(displayTime);
animateVertically(posx, stopYPosition, startYPosition);
currentNumberOfToaster--;
toaster.setVisible(false);
toaster.dispose();
}
catch (Exception e) {
Log.error(e);
}
}
}
/**
* Show a toaster with the specified message and the associated icon.
*/
public void showToaster(Icon icon, String msg) {
SingleToaster singleToaster = new SingleToaster();
final JScrollPane pane = new JScrollPane(singleToaster.message);
pane.setOpaque(false);
pane.setBorder(BorderFactory.createEmptyBorder());
pane.getViewport().setBackground(Color.white);
mainPanel.add(pane, new GridBagConstraints(1, 2, 3, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(2, 5, 2, 5), 0, 0));
if (icon != null) {
titleLabel.setIcon(icon);
}
singleToaster.message.setText(msg);
singleToaster.message.setCaretPosition(0);
singleToaster.animate();
window = singleToaster;
}
/**
* Show a toaster with the specified message and the associated icon.
*/
public void showToaster(String title, Component comp) {
SingleToaster singleToaster = new SingleToaster();
mainPanel.add(comp, new GridBagConstraints(1, 2, 3, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(2, 0, 0, 0), 0, 0));
titleLabel.setTitle(title);
singleToaster.animate();
window = singleToaster;
}
public void showToaster(Icon icon) {
SingleToaster singleToaster = new SingleToaster();
if (icon != null) {
titleLabel.setIcon(icon);
}
singleToaster.animate();
window = singleToaster;
}
public void showToaster() {
SingleToaster singleToaster = new SingleToaster();
singleToaster.animate();
window = singleToaster;
}
/**
* Show a toaster with the specified message.
*/
public void showToaster(String msg) {
showToaster(null, msg);
}
/**
* @return Returns the font
*/
public Font getToasterMessageFont() {
// TODO Auto-generated method stub
return font;
}
/**
* Set the font for the message
*/
public void setToasterMessageFont(Font f) {
font = f;
}
/**
* @return Returns the borderColor.
*/
public Color getBorderColor() {
return borderColor;
}
/**
* @param borderColor The borderColor to set.
*/
public void setBorderColor(Color borderColor) {
this.borderColor = borderColor;
}
/**
* @return Returns the displayTime.
*/
public int getDisplayTime() {
return displayTime;
}
/**
* @param displayTime The displayTime to set.
*/
public void setDisplayTime(int displayTime) {
this.displayTime = displayTime;
}
/**
* @return Returns the margin.
*/
public int getMargin() {
return margin;
}
/**
* @param margin The margin to set.
*/
public void setMargin(int margin) {
this.margin = margin;
}
/**
* @return Returns the messageColor.
*/
public Color getMessageColor() {
return messageColor;
}
/**
* @param messageColor The messageColor to set.
*/
public void setMessageColor(Color messageColor) {
this.messageColor = messageColor;
}
/**
* @return Returns the step.
*/
public int getStep() {
return step;
}
/**
* @param step The step to set.
*/
public void setStep(int step) {
this.step = step;
}
/**
* @return Returns the stepTime.
*/
public int getStepTime() {
return stepTime;
}
/**
* @param stepTime The stepTime to set.
*/
public void setStepTime(int stepTime) {
this.stepTime = stepTime;
}
/**
* @return Returns the toasterColor.
*/
public Color getToasterColor() {
return toasterColor;
}
/**
* @param toasterColor The toasterColor to set.
*/
public void setToasterColor(Color toasterColor) {
this.toasterColor = toasterColor;
}
/**
* @return Returns the toasterHeight.
*/
public int getToasterHeight() {
return toasterHeight;
}
/**
* @param toasterHeight The toasterHeight to set.
*/
public void setToasterHeight(int toasterHeight) {
this.toasterHeight = toasterHeight;
}
/**
* @return Returns the toasterWidth.
*/
public int getToasterWidth() {
return toasterWidth;
}
/**
* @param toasterWidth The toasterWidth to set.
*/
public void setToasterWidth(int toasterWidth) {
this.toasterWidth = toasterWidth;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public Border getBorder() {
return border;
}
public void setBorder(Border border) {
this.border = border;
}
public void setCustomAction(Action action) {
this.customAction = action;
}
public void setComponent(Component comp) {
mainPanel.add(comp, new GridBagConstraints(1, 2, 3, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(2, 5, 2, 5), 0, 0));
}
public void close() {
if (window != null) {
window.dispose();
}
}
public Window getWindow() {
return window;
}
public void hideTitle() {
titleLabel.setVisible(false);
}
class TitleLabel extends JPanel {
private JLabel label;
private RolloverButton closeButton;
public TitleLabel(String text, boolean showCloseIcon) {
setLayout(new GridBagLayout());
label = new JLabel(text);
label.setFont(new Font("Dialog", Font.BOLD, 11));
label.setHorizontalTextPosition(JLabel.LEFT);
label.setHorizontalAlignment(JLabel.LEFT);
add(label, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
closeButton = new RolloverButton(SparkRes.getImageIcon(SparkRes.CLOSE_IMAGE));
if (showCloseIcon) {
add(closeButton, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
}
setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.lightGray));
}
public void setIcon(Icon icon) {
label.setIcon(icon);
}
public RolloverButton getCloseButton() {
return closeButton;
}
public void setTitle(String title) {
label.setText(title);
}
public void paintComponent(Graphics g) {
final Image backgroundImage = Default.getImageIcon(Default.TOP_BOTTOM_BACKGROUND_IMAGE).getImage();
double scaleX = getWidth() / (double)backgroundImage.getWidth(null);
double scaleY = getHeight() / (double)backgroundImage.getHeight(null);
AffineTransform xform = AffineTransform.getScaleInstance(scaleX, scaleY);
((Graphics2D)g).drawImage(backgroundImage, xform, this);
}
}
public void setHidable(boolean hideable) {
this.hideable = hideable;
}
/**
* Simple Example...
*/
public static void main(String[] args) {
SparkToaster toaster = new SparkToaster();
toaster.setDisplayTime(30000);
toaster.setBorder(BorderFactory.createBevelBorder(0));
toaster.setTitle(Res.getString("title.notification"));
JButton button = new JButton("DDD");
toaster.hideTitle();
toaster.showToaster("HELLO", button);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?