Java源码示例:org.pushingpixels.substance.api.SubstanceLookAndFeel
示例1
public static void main(String... args) {
SwingUtilities.invokeLater(() -> {
JDialog.setDefaultLookAndFeelDecorated(true);
SubstanceCortex.GlobalScope.setSkin(new BusinessSkin());
SimpleDialog sd = new SimpleDialog();
if (UIManager.getLookAndFeel() instanceof SubstanceLookAndFeel) {
sd.setIconImage(RadianceLogo.getLogoImage(
SubstanceCortex.ComponentScope.getCurrentSkin(sd.getRootPane())
.getColorScheme(DecorationAreaType.PRIMARY_TITLE_PANE,
ColorSchemeAssociationKind.FILL, ComponentState.ENABLED)));
}
sd.setModal(false);
sd.pack();
sd.setLocationRelativeTo(null);
sd.setVisible(true);
sd.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
});
}
示例2
public static void changeLocale(JFrame frame, String countryCode, String langCode) {
LookAndFeel currLaf = UIManager.getLookAndFeel();
Locale newLocale = new Locale(langCode, countryCode);
Locale.setDefault(newLocale);
frame.applyComponentOrientation(
ComponentOrientation.getOrientation(Locale.getDefault()));
if (currLaf instanceof SubstanceLookAndFeel) {
SubstanceCortex.GlobalScope.resetLabelBundle();
if ("CN".equals(countryCode)) {
final FontSet currFontSet = SubstanceCortex.GlobalScope.getFontPolicy()
.getFontSet();
SubstanceCortex.GlobalScope.setFontPolicy(
() -> new DialogFontSet(currFontSet));
} else {
SubstanceCortex.GlobalScope.setFontPolicy(null);
}
}
try {
UIManager.setLookAndFeel(currLaf.getClass().getName());
} catch (Exception exc) {
}
SwingUtilities.updateComponentTreeUI(frame);
}
示例3
protected void synchronize() {
SwingUtilities.invokeLater(() -> {
if (UIManager.getLookAndFeel() instanceof SubstanceLookAndFeel) {
SampleFrame.this
.setIconImage(RadianceLogo.getLogoImage(SubstanceCortex.ComponentScope
.getCurrentSkin(SampleFrame.this.getRootPane())
.getColorScheme(DecorationAreaType.PRIMARY_TITLE_PANE,
ColorSchemeAssociationKind.FILL, ComponentState.ENABLED)));
}
});
}
示例4
/**
* Synchronizes the frame icon with the current theme.
*/
protected void synchronize() {
SwingUtilities.invokeLater(() -> {
if (UIManager.getLookAndFeel() instanceof SubstanceLookAndFeel) {
SubstanceSkin currentSkin = SubstanceCortex.ComponentScope
.getCurrentSkin(getRootPane());
setFrameIcon(RadianceLogo.getLogoIcon(
currentSkin.getColorScheme(DecorationAreaType.SECONDARY_TITLE_PANE,
ColorSchemeAssociationKind.FILL, ComponentState.ENABLED)));
setTitle(currentSkin.getDisplayName());
}
});
}
示例5
public TestFrame() {
super("Substance skeleton");
if (UIManager.getLookAndFeel() instanceof SubstanceLookAndFeel) {
setIconImage(RadianceLogo
.getLogoImage(SubstanceCortex.ComponentScope.getCurrentSkin(this.getRootPane())
.getColorScheme(DecorationAreaType.PRIMARY_TITLE_PANE,
ColorSchemeAssociationKind.FILL, ComponentState.ENABLED)));
}
SubstanceCortex.GlobalScope.registerSkinChangeListener(() -> SwingUtilities.invokeLater(
() -> setIconImage(RadianceLogo.getLogoImage(SubstanceCortex.ComponentScope
.getCurrentSkin(TestFrame.this.getRootPane())
.getColorScheme(DecorationAreaType.PRIMARY_TITLE_PANE,
ColorSchemeAssociationKind.FILL, ComponentState.ENABLED)))));
setLayout(new BorderLayout());
toolbar = Check.getToolbar("", 22, false);
this.add(toolbar, BorderLayout.NORTH);
JPanel statusBar = getStatusBar();
this.add(statusBar, BorderLayout.SOUTH);
setPreferredSize(new Dimension(400, 400));
this.setSize(getPreferredSize());
setMinimumSize(getPreferredSize());
// sample menu bar
JMenuBar jmb = new JMenuBar();
jmb.add(new JMenu("File"));
jmb.add(new JMenu("Edit"));
jmb.add(new JMenu("Source"));
jmb.add(new JMenu("Refactor"));
jmb.add(new JMenu("Navigate"));
jmb.add(new JMenu("Search"));
jmb.add(new JMenu("Project"));
setJMenuBar(jmb);
}
示例6
private static void tryLoadSubstanceLookAndFeel() {
if (!StringUtils.isNotBlank(System.getProperty("swing.defaultlaf", ""))) {//NON-NLS
try {
SubstanceLookAndFeel lookAndFeel = new SubstanceModerateLookAndFeel();
UIManager.setLookAndFeel(lookAndFeel);
} catch (UnsupportedLookAndFeelException e) {
LOGGER.info("Can't change look and feel: ", e);//NON-NLS
}
} else {
LOGGER.info("swing.defaultlaf is set, do not switching to Substance LF");//NON-NLS
}
}
示例7
public static Color getDefaultBackgroundColor() {
if (Configuration.useRibbonInterface.get()) {
return SubstanceLookAndFeel.getCurrentSkin().getColorScheme(DecorationAreaType.GENERAL, ColorSchemeAssociationKind.FILL, ComponentState.ENABLED).getBackgroundFillColor();
} else {
return SystemColor.control;
}
}
示例8
public static Color getSelectedColor() {
if (Configuration.useRibbonInterface.get()) {
return SubstanceLookAndFeel.getCurrentSkin().getColorScheme(DecorationAreaType.GENERAL, ColorSchemeAssociationKind.FILL, ComponentState.ROLLOVER_SELECTED).getBackgroundFillColor();
} else {
return SystemColor.textHighlight;
}
}
示例9
private static Color getControlColor() {
if (Configuration.useRibbonInterface.get()) {
return SubstanceLookAndFeel.getCurrentSkin().getColorScheme(DecorationAreaType.GENERAL, ColorSchemeAssociationKind.FILL, ComponentState.ENABLED).getBackgroundFillColor();
} else {
return SystemColor.control;
}
}
示例10
public static Color getBackgroundColor() {
if (Configuration.useRibbonInterface.get()) {
return SubstanceLookAndFeel.getCurrentSkin().getColorScheme(DecorationAreaType.GENERAL, ColorSchemeAssociationKind.FILL, ComponentState.ENABLED).getBackgroundFillColor();
} else {
return SystemColor.control;
}
}
示例11
@Override
protected void paintComponent(Graphics g) {
int w = this.getWidth();
int h = this.getHeight();
Graphics2D graphics = (Graphics2D) g.create();
if ((UIManager.getLookAndFeel() instanceof SubstanceLookAndFeel)
&& SubstanceCortex.ComponentScope.getCurrentSkin(this)
.getActiveColorScheme(
ComponentOrParentChainScope.getDecorationType(this))
.isDark())
graphics.setColor(Color.black);
else
graphics.setColor(Color.white);
graphics.fillRect(0, 0, w, h);
graphics.setComposite(AlphaComposite.SrcOver.derive(0.6f));
graphics.setColor(this.getBackground());
graphics.fillRect(0, 0, w, h);
graphics.setComposite(AlphaComposite.SrcOver);
if ((UIManager.getLookAndFeel() instanceof SubstanceLookAndFeel)
&& SubstanceCortex.ComponentScope.getCurrentSkin(this)
.getActiveColorScheme(
ComponentOrParentChainScope.getDecorationType(this))
.isDark())
graphics.setColor(Color.white);
else
graphics.setColor(Color.black);
int size = Math.min(60, Math.min(w, h) / 2);
graphics.setFont(new Font("Arial", Font.BOLD, size));
graphics.drawString("" + number, (w - size) / 2, (h / 2 + size) / 2);
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");
String currDate = sdf.format(new Date());
int size2 = Math.min(50, Math.min(w, h) / 3);
graphics.setFont(new Font("Arial", Font.BOLD, size2));
int timeLen = graphics.getFontMetrics().stringWidth(currDate);
graphics.drawString(currDate, (w - timeLen) / 2, (h + size) / 2);
graphics.dispose();
}
示例12
@Override
public void paint(Graphics g) {
super.paint(g);
repaintQueued = false;
Rectangle r = getVisibleRect();
int width = getWidth();
int cols = width / CELL_WIDTH;
int rows = (int) Math.ceil(items.size() / (float) cols);
int height = rows * CELL_HEIGHT;
int start_y = r.y / CELL_HEIGHT;
JLabel l = new JLabel();
Font f = l.getFont().deriveFont(AffineTransform.getScaleInstance(0.8, 0.8));
int finish_y = (int) Math.ceil((r.y + r.height) / (float) CELL_HEIGHT);
Color color;
Color selectedColor;
Color selectedTextColor;
Color borderColor;
Color textColor;
if (Configuration.useRibbonInterface.get()) {
SubstanceSkin skin = SubstanceLookAndFeel.getCurrentSkin();
color = skin.getColorScheme(DecorationAreaType.GENERAL, ColorSchemeAssociationKind.FILL, ComponentState.ENABLED).getBackgroundFillColor();
selectedColor = skin.getColorScheme(DecorationAreaType.GENERAL, ColorSchemeAssociationKind.FILL, ComponentState.ROLLOVER_SELECTED).getBackgroundFillColor();
borderColor = skin.getColorScheme(DecorationAreaType.GENERAL, ColorSchemeAssociationKind.BORDER, ComponentState.ROLLOVER_SELECTED).getUltraDarkColor();
textColor = skin.getColorScheme(DecorationAreaType.GENERAL, ColorSchemeAssociationKind.FILL, ComponentState.ENABLED).getForegroundColor();
selectedTextColor = skin.getColorScheme(DecorationAreaType.GENERAL, ColorSchemeAssociationKind.FILL, ComponentState.ROLLOVER_SELECTED).getForegroundColor();
} else {
color = SystemColor.control;
selectedColor = SystemColor.textHighlight;
borderColor = SystemColor.controlShadow;
textColor = SystemColor.controlText;
selectedTextColor = SystemColor.textHighlightText;
}
//g.setColor(SubstanceLookAndFeel.getCurrentSkin().getColorScheme(DecorationAreaType.GENERAL, ColorSchemeAssociationKind.FILL, ComponentState.ENABLED));
for (int y = start_y; y <= finish_y; y++) {
for (int x = 0; x < cols; x++) {
int index = y * cols + x;
if (index < items.size()) {
g.setColor(color);
if (selectedItems.containsKey(index)) {
g.setColor(selectedColor);
}
g.fillRect(x * CELL_WIDTH, y * CELL_HEIGHT, CELL_WIDTH, CELL_HEIGHT);
if (cachedPreviews.contains(index)) {
SerializableImage sImg = cachedPreviews.get(index);
if (sImg != null) {
BufferedImage img = cachedPreviews.get(index).getBufferedImage();
g.drawImage(img, x * CELL_WIDTH + BORDER_SIZE + PREVIEW_SIZE / 2 - img.getWidth() / 2, y * CELL_HEIGHT + BORDER_SIZE + PREVIEW_SIZE / 2 - img.getHeight() / 2, null);
}
} else {
cachedPreviews.put(index, noImage);
renderImageTask(index, items.get(index));
}
String s;
TreeItem treeItem = items.get(index);
if (treeItem instanceof Tag) {
s = ((Tag) treeItem).getTagName();
if (treeItem instanceof CharacterTag) {
s = s + " (" + ((CharacterTag) treeItem).getCharacterId() + ")";
}
} else {
s = treeItem.toString();
}
g.setFont(f);
g.setColor(borderColor);
g.drawLine(x * CELL_WIDTH, y * CELL_HEIGHT + BORDER_SIZE + PREVIEW_SIZE, x * CELL_WIDTH + CELL_WIDTH, y * CELL_HEIGHT + BORDER_SIZE + PREVIEW_SIZE);
g.drawRect(x * CELL_WIDTH, y * CELL_HEIGHT, CELL_WIDTH, CELL_HEIGHT);
g.setColor(textColor);
if (selectedItems.containsKey(index)) {
g.setColor(selectedTextColor);
}
g.drawString(s, x * CELL_WIDTH + BORDER_SIZE, y * CELL_HEIGHT + BORDER_SIZE + PREVIEW_SIZE + LABEL_HEIGHT);
}
}
}
if (lastWidth != width || lastHeight != height) {
lastWidth = width;
lastHeight = height;
setSize(new Dimension(width, height));
}
}
示例13
public JPanelConfigGeneral() {
initComponents();
jtxtMachineHostname.getDocument().addDocumentListener(dirty);
jcboLAF.addActionListener(dirty);
jcboFontFamilyName.addActionListener(dirty);
jtxtFontSize.addActionListener(dirty);
jcboMachineScreenmode.addActionListener(dirty);
jcboMachineLeftPanel.addActionListener(dirty);
jcboTicketsBag.addActionListener(dirty);
jcboLAF.addItem(new LAFInfo("System", UIManager.getSystemLookAndFeelClassName()));
// Installed skins
LookAndFeelInfo[] lafs = UIManager.getInstalledLookAndFeels();
for (LookAndFeelInfo laf : lafs) {
jcboLAF.addItem(new LAFInfo(laf.getName(), laf.getClassName()));
}
// Substance skins
// new SubstanceLookAndFeel(); // TODO: Remove in Substance 5.0. Workaround for Substance 4.3 to initialize static variables
Map<String, SkinInfo> skins = SubstanceLookAndFeel.getAllSkins();
for (SkinInfo skin : skins.values()) {
jcboLAF.addItem(new LAFInfo(skin.getDisplayName(), skin.getClassName()));
}
jcboLAF.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
changeLAF();
}
});
for (String fontName : GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames()) {
jcboFontFamilyName.addItem(fontName);
}
jcboMachineScreenmode.addItem("window");
jcboMachineScreenmode.addItem("fullscreen");
jcboMachineLeftPanel.addItem("open");
jcboMachineLeftPanel.addItem("hide");
jcboTicketsBag.addItem("simple");
jcboTicketsBag.addItem("standard");
jcboTicketsBag.addItem("restaurant");
jcboTicketsBag.addItem("geomap");
}