📄 descriptionwindow.java
字号:
/*******************************************************************************
* Copyright (c) 2004 Berthold Daum. All rights reserved. This program and the
* accompanying materials are made available under the terms of the Common
* Public License v1.0 which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors: Berthold Daum
******************************************************************************/
package com.bdaum.jukebox;
import java.util.StringTokenizer;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class DescriptionWindow extends Window {
// The browser widget responsible for displaying the text
private Browser browser;
// The playlist model
private IPlaylist model;
// The current display
private Display display;
/**
* Constructor.
*
* @param parent -
* the containing shell
* @param model -
* the player model
*/
public DescriptionWindow(Shell parent, IPlaylist model) {
super(parent);
display = parent.getDisplay();
this.model = model;
}
/**
* This method is called form superclass Window.
* It constructs the window contents.
*/
protected Control createContents(Composite parent) {
parent.setLayout(new FillLayout());
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new FillLayout());
// Create a browser widget
browser = new Browser(composite, SWT.NONE);
GridData data = new GridData(GridData.FILL_BOTH);
browser.setLayoutData(data);
return composite;
}
/**
* Prepare HTML-text and display it Browser widget
*/
public void update() {
String description = model.getFeature(Player.DESCRIPTION);
if (description == null)
browser.setText("");
else {
// Coloring for keywords
StringBuffer html = new StringBuffer(
"<html><small><font color='green'>");
StringTokenizer tokenizer = new StringTokenizer(
description, "<> \n\t", true);
while (tokenizer.hasMoreTokens()) {
String token = tokenizer.nextToken();
if (token.length() == 1) {
html.append(token);
} else if (token.startsWith("$")) {
html.append("<font color='red'>");
html.append(token.substring(1));
html.append("</font>");
} else
html.append(token);
}
html.append("</font></small></html>");
// Display in browser
browser.setText(html.toString());
}
}
/**
* Override open() method of superclass Window to
* update the displayed text.
*/
public int open() {
update();
return super.open();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -