lookandfeel.java.svn-base
来自「j2me设计的界面包」· SVN-BASE 代码 · 共 613 行 · 第 1/2 页
SVN-BASE
613 行
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.lwuit.plaf;
import com.sun.lwuit.geom.Dimension;
import com.sun.lwuit.*;
import com.sun.lwuit.animations.Transition;
import com.sun.lwuit.geom.Rectangle;
/**
* Allows a UI developer to completely customize the look of the application by
* overriding drawing/sizing methods appropriately.
*
* @author Chen Fishbein
*/
public abstract class LookAndFeel {
/**
* Tint color is set when a form is partially covered be it by a menu or by a
* dialog. A look and feel can override this default value.
*/
private int defaultFormTintColor = 0x7f000000;
/**
* This color is used to paint disable mode.
*/
private int disableColor = 0xcccccc;
/**
* This member allows us to define a default animation that will draw the transition for
* entering a form
*/
private Transition defaultFormTransitionIn;
/**
* This member allows us to define a default animation that will draw the transition for
* exiting a form
*/
private Transition defaultFormTransitionOut;
/**
* This member allows us to define a default animation that will draw the transition for
* entering a menu
*/
private Transition defaultMenuTransitionIn;
/**
* This member allows us to define a default animation that will draw the transition for
* exiting a menu
*/
private Transition defaultMenuTransitionOut;
/**
* This member allows us to define a default animation that will draw the transition for
* entering a dialog
*/
private Transition defaultDialogTransitionIn;
/**
* This member allows us to define a default animation that will draw the transition for
* exiting a form
*/
private Transition defaultDialogTransitionOut;
/**
* Indicates whether lists and containers should have smooth scrolling by default
*/
private boolean defaultSmoothScrolling = true;
/**
* Indicates the default speed for smooth scrolling
*/
private int defaultSmoothScrollingSpeed = 150;
/**
* Indicates whether softbuttons should be reversed from their default orientation
*/
private boolean reverseSoftButtons;
/**
* Every component binds itself to the look and feel thus allowing the look
* and feel to customize the component. Binding occurs at the end of the
* constructor when the component is in a valid state and ready to be used.
* Notice that a component might be bound twice or more and it is the
* responsibility of the LookAndFeel to protect against that.
*
* @param cmp component instance that may be customized by the look and feel
*/
public void bind(Component cmp) {
}
/**
* Invoked when a look and feel is removed, allows a look and feel to release
* resources related to binding components.
*
* @see #bind(Component)
*/
public void uninstall() {}
/**
* Invoked for drawing a button widget
*/
public abstract void drawButton(Graphics g, Button b);
/**
* Invoked for drawing a checkbox widget
*/
public abstract void drawCheckBox(Graphics g, CheckBox cb);
/**
* Invoked for drawing a combo box widget
*/
public abstract void drawComboBox(Graphics g, ComboBox cb);
/**
* Invoked for drawing a label widget
*/
public abstract void drawLabel(Graphics g, Label l);
/**
* Invoked for drawing a list widget
*/
public abstract void drawList(Graphics g, List l);
/**
* Invoked for drawing a month view widget
*/
public abstract void drawMonthView(Graphics g, Calendar cal, Component mv);
/**
* Returns the day of the month in the month view at the given relative
* component X/Y offsets. This is important for touch screen interaction
*/
public abstract long findDayAt(int x, int y, Calendar cal, Component mv);
/**
* Invoked for drawing the radio button widget
*/
public abstract void drawRadioButton(Graphics g, RadioButton rb);
public abstract void drawTextArea(Graphics g, TextArea ta);
/**
* Draws the text field without its cursor which is drawn in a separate method
* input mode indication can also be drawn using this method.
*/
public abstract void drawTextField(Graphics g, TextField ta);
/**
* Draws the cursor of the text field, blinking is handled simply by avoiding
* a call to this method.
*/
public abstract void drawTextFieldCursor(Graphics g, TextField ta);
/**
* Invoked for drawing the Tab Pane widget
*/
public abstract void drawTabbedPane(Graphics g, TabbedPane tp);
/**
* @return the preferred size for the radio button
*/
public abstract Dimension getButtonPreferredSize(Button b);
/**
* @return the preferred size for the checkbox
*/
public abstract Dimension getCheckBoxPreferredSize(CheckBox cb);
/**
* @return the preferred size for the label
*/
public abstract Dimension getLabelPreferredSize(Label l);
/**
* @return the preferred size for the list
*/
public abstract Dimension getListPreferredSize(List l);
/**
* @return the preferred size for the month view
*/
public abstract Dimension getMonthViewPreferredSize(Component mv);
/**
* @return the preferred size for the radio button
*/
public abstract Dimension getRadioButtonPreferredSize(RadioButton rb);
//public abstract Dimension getSpinnerPreferredSize(Spinner sp);
/**
* Returns the preferred size of the text area
*
* @return the preferred size for the text area
*/
public abstract Dimension getTextAreaPreferredSize(TextArea ta);
/**
* Returns the preferred size of the text field
*
* @return the preferred size for the text field
*/
public abstract Dimension getTextFieldPreferredSize(TextField ta);
/**
* @return the preferred size for the combo box
*/
public abstract Dimension getComboBoxPreferredSize(ComboBox box);
/**
* Draws a vertical scoll bar in the given component
*/
public void drawVerticalScroll(Graphics g, Component c, float offsetRatio, float blockSizeRatio) {
int x = c.getX() + c.getWidth() - getVerticalScrollWidth();
int y = c.getY();
int height = c.getHeight();
Style s = UIManager.getInstance().getComponentStyle("Scroll");
Style st = UIManager.getInstance().getComponentStyle("ScrollThumb");
g.setColor(s.getFgColor());
int width = getVerticalScrollWidth();
// take margin into consideration when positioning the scroll
int marginLeft = s.getMargin(Component.LEFT);
int marginTop = s.getMargin(Component.TOP);
x += marginLeft;
width -= (marginLeft + s.getMargin(Component.RIGHT));
y += marginTop;
height -= (marginTop + s.getMargin(Component.BOTTOM));
if(s.getBgImage() != null) {
drawBackgroundImage(g, s, x, y, width, height);
} else {
g.fillRect(x, y, width, height, s.getBgTransparency());
g.setColor(s.getBgColor());
g.fillRoundRect(x, y + 1, width, height - 2, 10, 10);
}
marginLeft = st.getMargin(Component.LEFT);
marginTop = st.getMargin(Component.TOP);
x += marginLeft;
width -= (marginLeft + st.getMargin(Component.RIGHT));
y += marginTop;
height -= (marginTop + st.getMargin(Component.BOTTOM));
int offset = (int)(height * offsetRatio);
int blockSize = (int)(height * blockSizeRatio);
if(st.getBgImage() != null) {
drawBackgroundImage(g, st, x, y + offset ,width , blockSize);
} else {
g.setColor(st.getFgColor());
g.fillRoundRect(x, y + offset , width, blockSize, 10, 10);
}
}
private void drawBackgroundImage(Graphics g, Style s, int x, int y, int width, int height) {
Image bgImage = s.getBgImage();
if(bgImage != null) {
if (s.isScaleImage()) {
if (bgImage.getWidth() != width || bgImage.getHeight() != height) {
bgImage = bgImage.scaled(width, height);
}
g.drawImage(bgImage, x, y);
} else {
int iW = bgImage.getWidth();
int iH = bgImage.getHeight();
for (int xPos = 0; xPos < width; xPos += iW) {
for (int yPos = 0; yPos < height; yPos += iH) {
g.drawImage(bgImage, x + xPos, y + yPos);
}
}
}
}
}
/**
* Draws a horizontal scoll bar in the given component
*/
public void drawHorizontalScroll(Graphics g, Component c, float offsetRatio, float blockSizeRatio) {
int x = c.getX();
int y = c.getY() + c.getHeight() - getHorizontalScrollHeight();
int width = c.getWidth();
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?